diff --git a/src/cloudevents.ts b/src/cloudevents.ts index 1b9eaa2f..1d28fbe3 100644 --- a/src/cloudevents.ts +++ b/src/cloudevents.ts @@ -47,7 +47,9 @@ export function getBinaryCloudEventContext( const context: CloudEventsContext = {}; for (const name in req.headers) { if (name.startsWith('ce-')) { - const attributeName = name.substr('ce-'.length); + const attributeName = name.substr( + 'ce-'.length + ) as keyof CloudEventsContext; context[attributeName] = req.header(name); } } diff --git a/src/functions.ts b/src/functions.ts index 91f4f6d9..bedf5505 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -40,6 +40,19 @@ export type HandlerFunction = | CloudEventFunction | CloudEventFunctionWithCallback; +/** + * A legacy event. + */ +export interface LegacyEvent { + data: object; + context: CloudFunctionsContext; +} + +interface Data { + data: object; +} +export type LegacyCloudFunctionsContext = CloudFunctionsContext | Data; + /** * The Cloud Functions context object for the event. * @@ -62,7 +75,7 @@ export interface CloudFunctionsContext { /** * The resource that emitted the event. */ - resource?: string; + resource?: string | object; } /** @@ -91,17 +104,28 @@ export interface CloudEventsContext { * Timestamp of when the event happened. */ time?: string; + /** + * Describes the subject of the event in the context of the event producer. + */ + subject?: string; /** * A link to the schema that the event data adheres to. */ - schemaurl?: string; + dataschema?: string; /** * Content type of the event data. */ - contenttype?: string; - - // CloudEvents extension attributes. - [key: string]: any; + datacontenttype?: string; + /** + * The event data. + */ + data?: + | Record + | string + | number + | boolean + | null + | unknown; } export type Context = CloudFunctionsContext | CloudEventsContext;