Skip to content

Commit 819d00e

Browse files
fix(google-cloud-serverless): Make CloudEvent type compatible (#16661)
resolves #16653 As per the google cloud SDK (https://github.com/cloudevents/sdk-javascript/blob/c07afa9b774deefa137a960d2d11adee0bf3674a/src/event/interfaces.ts#L10-L31), `id` and `specversion` should be mandatory. --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent 664461a commit 819d00e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/google-cloud-serverless/src/gcpfunction/general.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export interface CloudFunctionsContext {
2929

3030
export interface CloudEventsContext {
3131
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
32+
id: string;
33+
specversion: string;
3234
type?: string;
33-
specversion?: string;
3435
source?: string;
35-
id?: string;
3636
time?: string;
3737
schemaurl?: string;
3838
contenttype?: string;

packages/google-cloud-serverless/test/gcpfunction/cloud_event.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ describe('wrapCloudEventFunction', () => {
4545
function handleCloudEvent(fn: CloudEventFunctionWithCallback): Promise<any> {
4646
return new Promise((resolve, reject) => {
4747
const context = {
48+
id: 'test-event-id',
49+
specversion: '1.0',
4850
type: 'event.type',
4951
};
5052

@@ -232,6 +234,10 @@ describe('wrapCloudEventFunction', () => {
232234
const handler: CloudEventFunction = _context => 42;
233235
const wrappedHandler = wrapCloudEventFunction(handler);
234236
await handleCloudEvent(wrappedHandler);
235-
expect(mockScope.setContext).toBeCalledWith('gcp.function.context', { type: 'event.type' });
237+
expect(mockScope.setContext).toBeCalledWith('gcp.function.context', {
238+
id: 'test-event-id',
239+
specversion: '1.0',
240+
type: 'event.type',
241+
});
236242
});
237243
});

0 commit comments

Comments
 (0)