diff --git a/api-docs/docs/browser-tracker/browser-tracker.api.md b/api-docs/docs/browser-tracker/browser-tracker.api.md index 0aa06992e..477f3f499 100644 --- a/api-docs/docs/browser-tracker/browser-tracker.api.md +++ b/api-docs/docs/browser-tracker/browser-tracker.api.md @@ -143,7 +143,9 @@ export interface ClientSession extends Record { } // @public -export interface CommonEventProperties> { +export interface CommonEventProperties> { context?: Array> | null; // Warning: (ae-forgotten-export) The symbol "Timestamp" needs to be exported by the entry point index.module.d.ts timestamp?: Timestamp | null; @@ -330,7 +332,9 @@ export interface SelfDescribingEvent { } // @public -export type SelfDescribingJson = Record> = { +export type SelfDescribingJson> = { schema: string; data: T; }; diff --git a/api-docs/docs/node-tracker/node-tracker.api.md b/api-docs/docs/node-tracker/node-tracker.api.md index 58b772637..6a1adc5ef 100644 --- a/api-docs/docs/node-tracker/node-tracker.api.md +++ b/api-docs/docs/node-tracker/node-tracker.api.md @@ -299,7 +299,9 @@ export interface SelfDescribingEvent { } // @public -export type SelfDescribingJson = Record> = { +export type SelfDescribingJson> = { schema: string; data: T; }; diff --git a/common/changes/@snowplow/browser-plugin-snowplow-ecommerce/PE-4998-sdjtype_2024-07-17-01-28.json b/common/changes/@snowplow/browser-plugin-snowplow-ecommerce/PE-4998-sdjtype_2024-07-17-01-28.json new file mode 100644 index 000000000..cb4138a3b --- /dev/null +++ b/common/changes/@snowplow/browser-plugin-snowplow-ecommerce/PE-4998-sdjtype_2024-07-17-01-28.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/browser-plugin-snowplow-ecommerce", + "comment": "", + "type": "none" + } + ], + "packageName": "@snowplow/browser-plugin-snowplow-ecommerce" +} \ No newline at end of file diff --git a/common/changes/@snowplow/tracker-core/PE-4998-sdjtype_2024-07-17-01-28.json b/common/changes/@snowplow/tracker-core/PE-4998-sdjtype_2024-07-17-01-28.json new file mode 100644 index 000000000..8ddb6fc27 --- /dev/null +++ b/common/changes/@snowplow/tracker-core/PE-4998-sdjtype_2024-07-17-01-28.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/tracker-core", + "comment": "Fix SelfDescribingJson type to allow optional keys in type parameter", + "type": "none" + } + ], + "packageName": "@snowplow/tracker-core" +} \ No newline at end of file diff --git a/libraries/tracker-core/src/core.ts b/libraries/tracker-core/src/core.ts index eaabf4f7d..f9000fef7 100644 --- a/libraries/tracker-core/src/core.ts +++ b/libraries/tracker-core/src/core.ts @@ -45,7 +45,7 @@ import { LOG } from './logger'; * Export interface for any Self-Describing JSON such as context or Self Describing events * @typeParam T - The type of the data object within a SelfDescribingJson */ -export type SelfDescribingJson = Record> = { +export type SelfDescribingJson> = { /** * The schema string * @example 'iglu:com.snowplowanalytics.snowplow/web_page/jsonschema/1-0-0' @@ -61,7 +61,7 @@ export type SelfDescribingJson = Record = Record> = { +export type SelfDescribingJsonArray> = { /** * The schema string * @example 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-1' @@ -70,7 +70,7 @@ export type SelfDescribingJsonArray = Record< /** * The data array which should conform to the supplied schema */ - data: Array; + data: (T extends SelfDescribingJson ? T : SelfDescribingJson)[]; }; /** @@ -119,7 +119,7 @@ function getTimestamp(timestamp?: Timestamp | null): TimestampPayload { } /** Additional data points to set when tracking an event */ -export interface CommonEventProperties> { +export interface CommonEventProperties> { /** Add context to an event by setting an Array of Self Describing JSON */ context?: Array> | null; /** Set the true timestamp or overwrite the device sent timestamp on an event */ diff --git a/plugins/browser-plugin-snowplow-ecommerce/src/types.ts b/plugins/browser-plugin-snowplow-ecommerce/src/types.ts index c240cc63a..f46908fac 100644 --- a/plugins/browser-plugin-snowplow-ecommerce/src/types.ts +++ b/plugins/browser-plugin-snowplow-ecommerce/src/types.ts @@ -317,7 +317,8 @@ export interface User { email?: string; } -export interface CommonEcommerceEventProperties> extends CommonEventProperties { +export interface CommonEcommerceEventProperties> + extends CommonEventProperties { /** Add context to an event by setting an Array of Self Describing JSON */ context?: Array>; }