-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Include some Snowtype-generated code as tests.
- Loading branch information
1 parent
03664aa
commit 7e8cf49
Showing
10 changed files
with
223 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...nges/@snowplow/browser-plugin-snowplow-ecommerce/fix-sdj-regression_2024-10-04-03-07.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce", | ||
"comment": "", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce" | ||
} |
10 changes: 10 additions & 0 deletions
10
common/changes/@snowplow/tracker-core/fix-sdj-regression_2024-10-04-03-07.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@snowplow/tracker-core", | ||
"comment": "Fix regression in SelfDescribingJson type from #1330", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@snowplow/tracker-core" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
describe('Snowtype compat', () => { | ||
it('pass if this snowtype-generated file passes typechecks', () => {}); | ||
}); | ||
// generated with Snowtype v0.8.4, package import on below line needs to be updated to '../src' | ||
|
||
import { trackSelfDescribingEvent, CommonEventProperties, SelfDescribingJson } from '../src'; | ||
// Automatically generated by Snowtype | ||
|
||
/** | ||
* Schema for an example event | ||
*/ | ||
export type SubscriptionFunnel = { | ||
/** | ||
* the action of the funnel step | ||
*/ | ||
action?: null | string; | ||
/** | ||
* the number of the funnel step | ||
*/ | ||
step: number; | ||
/** | ||
* the type of subscription the user is signing up to | ||
*/ | ||
subscription_type?: null | string; | ||
}; | ||
|
||
/** | ||
* Creates a Snowplow Event Specification entity. | ||
*/ | ||
export function createEventSpecification(eventSpecification: EventSpecification) { | ||
return { | ||
schema: 'iglu:com.snowplowanalytics.snowplow/event_specification/jsonschema/1-0-2', | ||
data: eventSpecification, | ||
}; | ||
} | ||
|
||
/** | ||
* Automatically attached context for event specifications | ||
*/ | ||
interface EventSpecification { | ||
id: string; | ||
name: string; | ||
data_product_id: string; | ||
data_product_name: string; | ||
} | ||
|
||
type ContextsOrTimestamp<T = any> = Omit<CommonEventProperties<T>, 'context'> & { | ||
context?: SelfDescribingJson<T>[] | null | undefined; | ||
}; | ||
/** | ||
* Track a Snowplow event for SubscriptionFunnel. | ||
* Schema for an example event | ||
*/ | ||
export function trackSubscriptionFunnel<T extends {} = any>( | ||
subscriptionFunnel: SubscriptionFunnel & ContextsOrTimestamp<T>, | ||
trackers?: string[] | ||
) { | ||
const { context, timestamp, ...data } = subscriptionFunnel; | ||
const event: SelfDescribingJson<typeof data> = { | ||
schema: 'iglu:com.example/subscription_funnel/jsonschema/1-0-0', | ||
data, | ||
}; | ||
|
||
trackSelfDescribingEvent( | ||
{ | ||
event, | ||
context, | ||
timestamp, | ||
}, | ||
trackers | ||
); | ||
} | ||
|
||
/** | ||
* Creates a Snowplow SubscriptionFunnel entity. | ||
*/ | ||
export function createSubscriptionFunnel(subscriptionFunnel: SubscriptionFunnel) { | ||
return { | ||
schema: 'iglu:com.example/subscription_funnel/jsonschema/1-0-0', | ||
data: subscriptionFunnel, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import test from 'ava'; | ||
test('pass if this snowtype-generated file passes typechecks', () => {}); | ||
// generated with Snowtype v0.8.4, package import on below line needs to be updated to '../src' | ||
|
||
import { buildSelfDescribingEvent, SelfDescribingJson, Timestamp, Tracker } from '../src'; | ||
// Automatically generated by Snowtype | ||
|
||
/** | ||
* Schema for an example event | ||
*/ | ||
export type SubscriptionFunnel = { | ||
/** | ||
* the action of the funnel step | ||
*/ | ||
action?: null | string; | ||
/** | ||
* the number of the funnel step | ||
*/ | ||
step: number; | ||
/** | ||
* the type of subscription the user is signing up to | ||
*/ | ||
subscription_type?: null | string; | ||
}; | ||
|
||
interface CommonEventProperties<T = Record<string, unknown>> { | ||
/** Add context to an event by setting an Array of Self Describing JSON */ | ||
context?: Array<SelfDescribingJson<T>> | null; | ||
/** Set the true timestamp or overwrite the device sent timestamp on an event */ | ||
timestamp?: Timestamp | null; | ||
} | ||
|
||
/** | ||
* Creates a Snowplow Event Specification entity. | ||
*/ | ||
export function createEventSpecification(eventSpecification: EventSpecification) { | ||
return { | ||
schema: 'iglu:com.snowplowanalytics.snowplow/event_specification/jsonschema/1-0-2', | ||
data: eventSpecification, | ||
}; | ||
} | ||
|
||
/** | ||
* Automatically attached context for event specifications | ||
*/ | ||
interface EventSpecification { | ||
id: string; | ||
name: string; | ||
data_product_id: string; | ||
data_product_name: string; | ||
} | ||
|
||
type ContextsOrTimestamp<T = any> = Omit<CommonEventProperties<T>, 'context'> & { | ||
context?: SelfDescribingJson<T>[] | null | undefined; | ||
}; | ||
|
||
/** | ||
* Track a Snowplow event for SubscriptionFunnel. | ||
* Schema for an example event | ||
*/ | ||
export function trackSubscriptionFunnel<T extends {} = any>( | ||
tracker: Tracker, | ||
subscriptionFunnel: SubscriptionFunnel & ContextsOrTimestamp<T> | ||
) { | ||
const { context, timestamp, ...data } = subscriptionFunnel; | ||
tracker.track( | ||
buildSelfDescribingEvent({ | ||
event: { | ||
schema: 'iglu:com.example/subscription_funnel/jsonschema/1-0-0', | ||
data, | ||
}, | ||
}), | ||
context, | ||
timestamp | ||
); | ||
} | ||
|
||
/** | ||
* Creates a Snowplow SubscriptionFunnel entity. | ||
*/ | ||
export function createSubscriptionFunnel(subscriptionFunnel: SubscriptionFunnel) { | ||
return { | ||
schema: 'iglu:com.example/subscription_funnel/jsonschema/1-0-0', | ||
data: subscriptionFunnel, | ||
}; | ||
} |