@ensemblekit/sdk-types 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @ensemblekit/sdk-types
2
2
 
3
3
  TypeScript types for the Ensemble browser SDK wire contract — the
4
- `window.recs` command surface installed by the hosted script tag
4
+ `window.ensemble` command surface installed by the hosted script tag
5
5
  (`{ingest-origin}/sdk/v1.js`).
6
6
 
7
7
  Types only: no runtime, no dependencies. The SDK itself is never installed
@@ -10,16 +10,16 @@ from npm; storefronts load it via the script tag.
10
10
  ## Usage
11
11
 
12
12
  ```ts
13
- import type {RecsCommand, RecsEventPayloads} from '@ensemblekit/sdk-types';
13
+ import type {EnsembleCommand, EnsembleEventPayloads} from '@ensemblekit/sdk-types';
14
14
  ```
15
15
 
16
- To type `window.recs` globally, add one side-effect import (or put
16
+ To type `window.ensemble` globally, add one side-effect import (or put
17
17
  `@ensemblekit/sdk-types/global` in your tsconfig `types`):
18
18
 
19
19
  ```ts
20
20
  import '@ensemblekit/sdk-types/global';
21
21
 
22
- window.recs?.('track', 'product_viewed', {
22
+ window.ensemble?.('track', 'product_viewed', {
23
23
  productId: 'gid://shopify/Product/1',
24
24
  handle: 'slim-cuff-pant',
25
25
  price: 98,
@@ -27,9 +27,9 @@ window.recs?.('track', 'product_viewed', {
27
27
  });
28
28
  ```
29
29
 
30
- Naming note: the product is Ensemble; the wire-level global and command verb
31
- are `recs` by design (the `gtag()` precedent), so type names keep the `Recs`
32
- prefix to match `window.recs`.
30
+ Naming note: the developer-facing surface is the brand `window.ensemble`
31
+ and `Ensemble*` type names. Wire plumbing (the `_recs_vid`/`_recs_sid`
32
+ cookies and the `/v1/events` path) keeps the `recs` working name.
33
33
 
34
34
  ## Contract guarantee
35
35
 
package/dist/global.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { RecsCommand } from './index.js';
1
+ import { EnsembleCommand } from './index.js';
2
2
 
3
3
  /**
4
4
  * Optional global augmentation: `import '@ensemblekit/sdk-types/global'` (or add
5
- * it to tsconfig `types`) to type `window.recs` without hand-declaring it.
5
+ * it to tsconfig `types`) to type `window.ensemble` without hand-declaring it.
6
6
  */
7
7
 
8
8
  declare global {
@@ -12,7 +12,7 @@ declare global {
12
12
  * function; `/sdk/v1.js` replaces it with a live dispatcher that drains
13
13
  * the queue. Absent until one of them has run.
14
14
  */
15
- recs?: RecsCommand & {
15
+ recs?: EnsembleCommand & {
16
16
  q?: unknown[];
17
17
  };
18
18
  }
package/dist/index.d.ts CHANGED
@@ -8,12 +8,12 @@
8
8
  * against the z.infer types, and the workspace typecheck fails on any
9
9
  * mismatch.
10
10
  *
11
- * Naming note: the product is Ensemble; the wire-level global and command
12
- * verb are `recs` by design (the gtag/analytics precedent), so exported
13
- * type names keep the Recs prefix to match `window.recs`.
11
+ * Naming note: the developer-facing surface is the brand `window.ensemble`
12
+ * and Ensemble* type names. Wire plumbing (cookies `_recs_vid`/`_recs_sid`,
13
+ * the /v1/events path, internal package names) keeps the `recs` working name.
14
14
  */
15
15
  /** Cart/order line snapshot shared by cart_viewed, cart_updated, order_completed. */
16
- type RecsLine = {
16
+ type EnsembleLine = {
17
17
  productId: string;
18
18
  variantId: string;
19
19
  qty: number;
@@ -27,7 +27,7 @@ type RecSlotPayload = {
27
27
  modelVersion: string;
28
28
  };
29
29
  /** Payload shapes for the SDK's strict event names, keyed by event name. */
30
- type RecsEventPayloads = {
30
+ type EnsembleEventPayloads = {
31
31
  page_viewed: {
32
32
  pageType: string;
33
33
  path: string;
@@ -44,14 +44,14 @@ type RecsEventPayloads = {
44
44
  productIds: string[];
45
45
  };
46
46
  cart_viewed: {
47
- lines: RecsLine[];
47
+ lines: EnsembleLine[];
48
48
  };
49
49
  search_viewed: {
50
50
  query: string;
51
51
  productIds: string[];
52
52
  };
53
53
  cart_updated: {
54
- lines: RecsLine[];
54
+ lines: EnsembleLine[];
55
55
  };
56
56
  product_added_to_cart: {
57
57
  productId: string;
@@ -69,15 +69,15 @@ type RecsEventPayloads = {
69
69
  orderId: string;
70
70
  total: number;
71
71
  currency: string;
72
- lines: RecsLine[];
72
+ lines: EnsembleLine[];
73
73
  };
74
74
  rec_impression: RecSlotPayload;
75
75
  rec_clicked: RecSlotPayload;
76
76
  };
77
77
  /** The strict event names accepted by `recs('track', ...)`. */
78
- type RecsEventName = keyof RecsEventPayloads;
78
+ type EnsembleEventName = keyof EnsembleEventPayloads;
79
79
  /** Config accepted by `recs('init', ...)`. */
80
- type RecsInitConfig = {
80
+ type EnsembleInitConfig = {
81
81
  storeId: string;
82
82
  /** Absolute URL of the ingest endpoint (POST /v1/events). Derived from the
83
83
  * SDK script's own src origin when omitted. */
@@ -86,17 +86,17 @@ type RecsInitConfig = {
86
86
  debug?: boolean;
87
87
  };
88
88
  /**
89
- * Shape of `window.recs`. Before the SDK script loads it is the bootstrap
89
+ * Shape of `window.ensemble`. Before the SDK script loads it is the bootstrap
90
90
  * command queue; once `/sdk/v1.js` loads it is replaced with a live
91
91
  * dispatcher that drains the queue. Both accept the same six commands.
92
92
  */
93
- interface RecsCommand {
94
- (command: 'init', config: RecsInitConfig): void;
93
+ interface EnsembleCommand {
94
+ (command: 'init', config: EnsembleInitConfig): void;
95
95
  (command: 'consent', state: 'granted' | 'revoked'): void;
96
- <E extends RecsEventName>(command: 'track', name: E, payload: RecsEventPayloads[E]): void;
96
+ <E extends EnsembleEventName>(command: 'track', name: E, payload: EnsembleEventPayloads[E]): void;
97
97
  (command: 'signal', name: string, payload: Record<string, unknown>): void;
98
98
  (command: 'customer', id?: string): void;
99
99
  (command: 'flush'): void;
100
100
  }
101
101
 
102
- export type { RecsCommand, RecsEventName, RecsEventPayloads, RecsInitConfig, RecsLine };
102
+ export type { EnsembleCommand, EnsembleEventName, EnsembleEventPayloads, EnsembleInitConfig, EnsembleLine };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ensemblekit/sdk-types",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "TypeScript types for the Ensemble browser SDK wire contract (the window.recs command surface)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -21,8 +21,8 @@
21
21
  "devDependencies": {
22
22
  "tsup": "^8.5.1",
23
23
  "typescript": "^5.6.0",
24
- "@recs/collector": "0.0.0",
25
- "@recs/core": "0.0.0"
24
+ "@recs/core": "0.0.0",
25
+ "@recs/collector": "0.0.0"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsup src/index.ts src/global.ts --dts-only --format esm --out-dir dist && node scripts/check-self-contained.mjs",