Skip to content

Fix date format for serviceBusQueue trigger metadata to ensure ISO8601 compliance #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: v4.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/converters/fromRpcTriggerMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,34 @@ export function fromRpcTriggerMetadata(
} else {
const result: TriggerMetadata = {};
for (const [key, value] of Object.entries(triggerMetadata)) {
result[toCamelCaseKey(key)] = toCamelCaseValue(fromRpcTypedData(value));
const camelCaseKey = toCamelCaseKey(key);
const processedValue = toCamelCaseValue(fromRpcTypedData(value));
result[camelCaseKey] = fixDateFormatForServiceBus(camelCaseKey, processedValue, triggerType);
}
return result;
}
}

/**
* Fix date format for serviceBus triggers to ensure proper timezone information.
* Adds 'Z' suffix to date strings that are missing timezone information.
*/
function fixDateFormatForServiceBus(key: string, value: unknown, triggerType: string): unknown {
// Only apply to serviceBus triggers
if (!triggerType.includes('serviceBus')) {
return value;
}

// Only apply to known date fields
const dateFields = ['enqueuedTimeUtc', 'expiresAtUtc'];
if (!dateFields.includes(key)) {
return value;
}

// Only apply to strings that look like dates without timezone
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/.test(value)) {
return value + 'Z';
}

return value;
}
63 changes: 63 additions & 0 deletions test/converters/fromRpcTriggerMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,67 @@ describe('fromRpcTriggerMetadata', () => {
},
});
});

it('serviceBusTrigger with date fields missing timezone', () => {
const testData: Record<string, RpcTypedDataExtended> = {
ExpiresAtUtc: {
json: '"2025-06-07T14:46:55.145"', // Missing 'Z' timezone info
data: 'json',
http: undefined,
},
EnqueuedTimeUtc: {
json: '"2025-06-07T14:46:55.145"', // Missing 'Z' timezone info
data: 'json',
http: undefined,
},
MessageId: {
string: 'test-message-id',
data: 'string',
http: undefined,
},
};

const result = fromRpcTriggerMetadata(testData, 'serviceBusTrigger');
expect(result).to.deep.equal({
expiresAtUtc: '2025-06-07T14:46:55.145Z',
enqueuedTimeUtc: '2025-06-07T14:46:55.145Z',
messageId: 'test-message-id',
});
});

it('serviceBusTrigger with date fields already having timezone should not be modified', () => {
const testData: Record<string, RpcTypedDataExtended> = {
ExpiresAtUtc: {
json: '"2025-06-07T14:46:55.145Z"', // Already has 'Z' timezone info
data: 'json',
http: undefined,
},
EnqueuedTimeUtc: {
json: '"2025-06-07T14:46:55.145Z"', // Already has 'Z' timezone info
data: 'json',
http: undefined,
},
};

const result = fromRpcTriggerMetadata(testData, 'serviceBusTrigger');
expect(result).to.deep.equal({
expiresAtUtc: '2025-06-07T14:46:55.145Z',
enqueuedTimeUtc: '2025-06-07T14:46:55.145Z',
});
});

it('non-serviceBus triggers should not have date format fixes applied', () => {
const testData: Record<string, RpcTypedDataExtended> = {
SomeDate: {
json: '"2025-06-07T14:46:55.145"', // Missing 'Z' timezone info
data: 'json',
http: undefined,
},
};

const result = fromRpcTriggerMetadata(testData, 'queueTrigger');
expect(result).to.deep.equal({
someDate: '2025-06-07T14:46:55.145', // Should remain unchanged
});
});
});
4 changes: 2 additions & 2 deletions types/InvocationContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface InvocationContextExtraInputs {
* @input the configuration object for this SQL input
*/
get(input: SqlInput): unknown;

/**
* Get a secondary MySql items input for this invocation
* @input the configuration object for this MySql input
Expand Down Expand Up @@ -223,7 +223,7 @@ export interface InvocationContextExtraOutputs {
* @message the output event(s) value
*/
set(output: EventGridOutput, events: EventGridPartialEvent | EventGridPartialEvent[]): void;

/**
* Set a secondary MySql items output for this invocation
* @output the configuration object for this MySql output
Expand Down
2 changes: 1 addition & 1 deletion types/input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import { CosmosDBInput, CosmosDBInputOptions } from './cosmosDB';
import { GenericInputOptions } from './generic';
import { FunctionInput } from './index';
import { MySqlInput, MySqlInputOptions } from './mySql';
import { SqlInput, SqlInputOptions } from './sql';
import { StorageBlobInput, StorageBlobInputOptions } from './storage';
import { TableInput, TableInputOptions } from './table';
import { MySqlInput, MySqlInputOptions } from './mySql';
import {
WebPubSubConnectionInput,
WebPubSubConnectionInputOptions,
Expand Down
2 changes: 1 addition & 1 deletion types/output.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EventHubOutput, EventHubOutputOptions } from './eventHub';
import { GenericOutputOptions } from './generic';
import { HttpOutput, HttpOutputOptions } from './http';
import { FunctionOutput } from './index';
import { MySqlOutput, MySqlOutputOptions } from './mySql';
import {
ServiceBusQueueOutput,
ServiceBusQueueOutputOptions,
Expand All @@ -16,7 +17,6 @@ import {
import { SqlOutput, SqlOutputOptions } from './sql';
import { StorageBlobOutput, StorageBlobOutputOptions, StorageQueueOutput, StorageQueueOutputOptions } from './storage';
import { TableOutput, TableOutputOptions } from './table';
import { MySqlOutput, MySqlOutputOptions } from './mySql';
import { WebPubSubOutput, WebPubSubOutputOptions } from './webpubsub';

/**
Expand Down