@disconetwork/core 0.0.6 → 0.0.7

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.
@@ -262,6 +262,16 @@ type EventPlacementDetails = {
262
262
  * service) and the internal/proxy client — the proxy forwards events verbatim,
263
263
  * so the contract is identical.
264
264
  */
265
+ /**
266
+ * Renderer-agnostic handle for emitting Disco events. Both the SDK-backed
267
+ * external tracker (`DiscoClient.createTrackingManager`) and the proxy
268
+ * `TrackingManager` implement this same interface, so consumers (and the React
269
+ * layer) depend on the interface, not the implementation. `track` is a closure,
270
+ * so it's safe to destructure.
271
+ */
272
+ type EventTracker = {
273
+ track: (event: EventPayload) => void;
274
+ };
265
275
  type EventPayload = {
266
276
  type: WidgetEventType;
267
277
  placement?: EventPlacementDetails;
@@ -289,67 +299,6 @@ type EventPayload = {
289
299
  placement?: EventPlacementDetails;
290
300
  };
291
301
  //#endregion
292
- //#region src/TrackingManager.d.ts
293
- type TrackingManagerConfig = {
294
- /**
295
- * Session identifier returned by the recommendations API. Stamped onto
296
- * every emitted event as `session_id`. A tracker is meaningless without
297
- * a session, so this is required — instantiate the manager only after
298
- * the recommendations response is in hand.
299
- */
300
- sessionId: string;
301
- /**
302
- * Absolute URL events are POSTed to. The external client points this at the
303
- * events service (`/events`); the internal client at the proxy
304
- * (`/track/partners_event/`). Prefer a client's `createTrackingManager` over
305
- * constructing this directly, so the endpoint and auth stay consistent with
306
- * the recommendations call.
307
- */
308
- endpoint: string;
309
- /**
310
- * Extra request headers — e.g. `{ "x-api-key": key }` for the external
311
- * events service. `Content-Type: application/json` is always sent.
312
- */
313
- headers?: Record<string, string>;
314
- /**
315
- * Override the global `fetch`. Primarily useful in tests and in runtimes
316
- * that provide a non-standard fetch implementation. Defaults to
317
- * `globalThis.fetch`.
318
- */
319
- fetch?: typeof fetch;
320
- };
321
- type EventTracker = {
322
- track: (event: EventPayload) => void;
323
- };
324
- /**
325
- * Renderer-agnostic event tracker for Disco recommendation surfaces.
326
- *
327
- * Owns:
328
- * - the dedup set (so repeated display/view events for the same brand
329
- * don't get re-sent within a session)
330
- * - the network call to the partner-events endpoint
331
- * - payload formatting (snake_case keys, BE-friendly datetime)
332
- *
333
- * Does not know about React. Wrap it in a Provider (`@disconetwork/react`'s
334
- * `DiscoProvider`) when consuming from a React tree, or instantiate it
335
- * directly from any other JS environment.
336
- *
337
- * `track` is implemented as an instance-bound arrow function so consumers
338
- * can safely destructure it without losing `this`.
339
- */
340
- declare class TrackingManager {
341
- #private;
342
- constructor(config: TrackingManagerConfig);
343
- /**
344
- * Send a tracking event. Fire-and-forget — never throws.
345
- * Failures are logged via `console.error`.
346
- *
347
- * Idempotency: `WIDGET_DISPLAY`, `WIDGET_VIEW`, `BRAND_DISPLAY`, and
348
- * `BRAND_VIEW` are deduped per-instance by (event type, insertionId).
349
- */
350
- track: (event: EventPayload) => void;
351
- }
352
- //#endregion
353
302
  //#region src/errors.d.ts
354
303
  /**
355
304
  * Base class for every error thrown by the Disco clients. Catch this to handle
@@ -404,5 +353,5 @@ declare class DiscoNetworkError extends DiscoError {
404
353
  constructor(message: string, cause: unknown);
405
354
  }
406
355
  //#endregion
407
- export { RecommendationsResponse as A, OfferCtaDetails as C, RecommendationGroupEntry as D, Recommendation as E, SubView as F, Title as I, View as L, DisplayMode as M, Gender as N, RecommendationGroupProperty as O, PlatformType as P, OfferAsset as S, OfferMetadata as T, ProductProperties as _, EventTracker as a, Footer as b, BrandClickInitiatingTarget as c, BrandVisibilityEventType as d, ElementClickInitiatingTarget as f, ProductEventType as g, ProductDisplayInitiatingTarget as h, DiscoValidationError as i, RunningExperiment as j, RecommendationsRequest as k, BrandDisplayInitiatingTarget as l, EventPlacementDetails as m, DiscoError as n, TrackingManager as o, EventPayload as p, DiscoNetworkError as r, TrackingManagerConfig as s, DiscoApiError as t, BrandProperties as u, WidgetEventType as v, OfferDisclosureDetails as w, Offer as x, Advertiser as y };
408
- //# sourceMappingURL=errors-C-xomnpl.d.ts.map
356
+ export { DisplayMode as A, OfferMetadata as C, RecommendationsRequest as D, RecommendationGroupProperty as E, View as F, PlatformType as M, SubView as N, RecommendationsResponse as O, Title as P, OfferDisclosureDetails as S, RecommendationGroupEntry as T, Advertiser as _, BrandClickInitiatingTarget as a, OfferAsset as b, BrandVisibilityEventType as c, EventPlacementDetails as d, EventTracker as f, WidgetEventType as g, ProductProperties as h, DiscoValidationError as i, Gender as j, RunningExperiment as k, ElementClickInitiatingTarget as l, ProductEventType as m, DiscoError as n, BrandDisplayInitiatingTarget as o, ProductDisplayInitiatingTarget as p, DiscoNetworkError as r, BrandProperties as s, DiscoApiError as t, EventPayload as u, Footer as v, Recommendation as w, OfferCtaDetails as x, Offer as y };
357
+ //# sourceMappingURL=errors-Dns2-5UC.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-Dns2-5UC.d.ts","names":[],"sources":["../src/api/generated/recommendations/types.gen.ts","../src/external/recommendations.ts","../src/types.ts","../src/errors.ts"],"mappings":";;;;KA8dY,WAAA;;;;KAyKA,MAAA;;;;KAgMA,YAAA;;;;;;KAiTA,OAAA;;;;KAUA,KAAA;;;;;;KAyBA,IAAA;;;;;AApVY;AAiTxB;;KC1lCY,iBAAA;EACV,IAAA,UDylCiB;ECvlCjB,OAAO;AAAA;;ADimCQ;AAyBjB;;KCzmCK,UAAA;EACH,SAAA;EACA,eAAA;EACA,sBAAA;EACA,SAAA;EACA,aAAA;EACA,YAAA,GAAe,YAAY,EA1BA;EA4B3B,QAAA;EACA,UAAA;AAAA;AAAA,KAGG,WAAA;EACH,KAAA,GAAQ,KAAA;EACR,SAAA;EACA,QAAA;EACA,KAAA;EACA,MAAA,GAAS,MAAM,EAdf;EAgBA,GAAA,WAdA;EAgBA,GAAA;AAAA;;;;AAZU;AAAA;KAoBP,WAAA,IACA,WAAA;EAAgB,KAAA;AAAA,MAChB,WAAA;EAAgB,SAAA;AAAA,MAChB,WAAA;EAAgB,YAAA;AAAA,MAChB,WAAA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wBAAA;EACN,KAAA,EAAO,eAAA;EACP,MAAA,EAAQ,4BAAA;EACR,SAAA,GAAY,qBAAA;AAAA;EAGZ,IAAA;EACA,KAAA,EAAO,eAAA;EACP,MAAA,EAAQ,0BAAA;EACR,OAAA;EACA,SAAA,GAAY,qBAAA;AAAA;EAGZ,IAAA;EACA,MAAA,EAAQ,4BAAA;EACR,KAAA,GAAQ,eAAA;EACR,SAAA,GAAY,qBAAA;AAAA;EAGZ,IAAA,EAAM,gBAAA;EACN,OAAA,EAAS,iBAAA;EACT,KAAA,EAAO,eAAA;EACP,MAAA,EAAQ,8BAAA;EACR,SAAA,GAAY,qBAAA;AAAA;;;;AF6WlB;;;;AAAuB;AAyKvB;;uBG/nBsB,UAAA,SAAmB,KAAK;AH+nB5B;AAgMlB;;;;AAhMkB,cGxnBL,aAAA,SAAsB,UAAU;EAAA,SAClC,MAAA;EAAA,SACA,UAAA;EAAA,SACA,IAAA;cAGP,OAAA,UACA,IAAA;IACE,MAAA;IACA,UAAA;IACA,IAAA;EAAA;AAAA;AHymCW;AAyBjB;;;;AAAgB;;;;AC7nChB;;ADomCiB,cGnlCJ,oBAAA,SAA6B,UAAA;EFhBxC;EAAA,SEkBS,KAAA,EAAO,KAAA;EFCb;EAAA,SECM,QAAA;cAEG,OAAA,UAAiB,KAAA,EAAO,KAAA,EAAO,QAAA;AAAA;;;;;;cAahC,iBAAA,SAA0B,UAAU;EFVhC;EAAA,SEYN,KAAA;cAEG,OAAA,UAAiB,KAAA;AAAA"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as RecommendationsResponse, C as OfferCtaDetails, D as RecommendationGroupEntry, E as Recommendation, F as SubView, I as Title, L as View, M as DisplayMode, N as Gender, O as RecommendationGroupProperty, P as PlatformType, S as OfferAsset, T as OfferMetadata, a as EventTracker, b as Footer, i as DiscoValidationError, j as RunningExperiment, k as RecommendationsRequest, n as DiscoError, p as EventPayload, r as DiscoNetworkError, t as DiscoApiError, w as OfferDisclosureDetails, x as Offer, y as Advertiser } from "./errors-C-xomnpl.js";
1
+ import { A as DisplayMode, C as OfferMetadata, D as RecommendationsRequest, E as RecommendationGroupProperty, F as View, M as PlatformType, N as SubView, O as RecommendationsResponse, P as Title, S as OfferDisclosureDetails, T as RecommendationGroupEntry, _ as Advertiser, a as BrandClickInitiatingTarget, b as OfferAsset, d as EventPlacementDetails, f as EventTracker, i as DiscoValidationError, j as Gender, k as RunningExperiment, l as ElementClickInitiatingTarget, n as DiscoError, o as BrandDisplayInitiatingTarget, r as DiscoNetworkError, s as BrandProperties, t as DiscoApiError, u as EventPayload, v as Footer, w as Recommendation, x as OfferCtaDetails, y as Offer } from "./errors-Dns2-5UC.js";
2
2
 
3
3
  //#region src/external/DiscoClient.d.ts
4
4
  /**
@@ -64,10 +64,27 @@ declare class DiscoClient {
64
64
  /**
65
65
  * Create an events tracker bound to a recommendations session (the
66
66
  * `sessionId` from a `getRecommendations` response). Posts to the external
67
- * `/events` endpoint with this client's `x-api-key`.
67
+ * `/events` endpoint with this client's `x-api-key`, via the generated events
68
+ * SDK (`eventsPost`).
69
+ *
70
+ * This is the **raw** tracker — it sends every call, fire-and-forget (never
71
+ * throws; failures are logged). Impression dedup is a render-lifecycle policy
72
+ * applied a layer up (the React layer wraps this with `withImpressionDedupe`),
73
+ * not baked into the core client.
68
74
  */
69
75
  createTrackingManager: (sessionId: string, options?: CreateTrackingManagerOptions) => EventTracker;
70
76
  }
71
77
  //#endregion
72
- export { type Advertiser, DiscoApiError, DiscoClient, type DiscoClientConfig, DiscoError, DiscoNetworkError, DiscoValidationError, type DisplayMode, type EventPayload, type EventTracker, type Footer, type Gender, type Offer, type OfferAsset, type OfferCtaDetails, type OfferDisclosureDetails, type OfferMetadata, type PlatformType, type Recommendation, type RecommendationGroupEntry, type RecommendationGroupProperty, type RecommendationsRequest, type RecommendationsResponse, type RunningExperiment, type SubView, type Title, type View };
78
+ //#region src/events/dedupe.d.ts
79
+ /**
80
+ * Wrap an {@link EventTracker} so repeat impressions are suppressed within the
81
+ * session: a given (event type, insertionId) is forwarded once, then dropped.
82
+ *
83
+ * Dedup is a delivery *policy*, not transport — kept as an explicit, opt-in
84
+ * decorator so suppression is never a surprise. State (the seen-set) lives in
85
+ * the wrapper; create one per session-bound tracker to scope dedup per session.
86
+ */
87
+ declare function withImpressionDedupe(inner: EventTracker): EventTracker;
88
+ //#endregion
89
+ export { type Advertiser, type BrandClickInitiatingTarget, type BrandDisplayInitiatingTarget, type BrandProperties, DiscoApiError, DiscoClient, type DiscoClientConfig, DiscoError, DiscoNetworkError, DiscoValidationError, type DisplayMode, type ElementClickInitiatingTarget, type EventPayload, type EventPlacementDetails, type EventTracker, type Footer, type Gender, type Offer, type OfferAsset, type OfferCtaDetails, type OfferDisclosureDetails, type OfferMetadata, type PlatformType, type Recommendation, type RecommendationGroupEntry, type RecommendationGroupProperty, type RecommendationsRequest, type RecommendationsResponse, type RunningExperiment, type SubView, type Title, type View, withImpressionDedupe };
73
90
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/external/DiscoClient.ts"],"mappings":";;;;AA2BA;;;;KAAY,iBAAA;EACV,MAAA;EAMA;;;AAAoB;EADpB,UAAA;EACA,KAAA,UAAe,KAAK;AAAA;AAAA,KAGV,yBAAA;EAEU,uEAApB,MAAA,GAAS,WAAW;AAAA;AAAA,KAGV,4BAAA;EAEV,8EAAA,KAAA,UAAe,KAAK;AAAA;;;;;KAOV,0BAAA;EACV,IAAA,EAAM,uBAAA;EACN,OAAA,EAAS,YAAY;AAAA;AAAA;AAgBvB;;;;;;;;;;;;AAhBuB,cAgBV,WAAA;EAAA;cAMC,MAAA,EAAQ,iBAAA;EA+FL;;;;;;;;;;EAzEf,kBAAA,GACE,OAAA,EAAS,sBAAA,EACT,OAAA,GAAU,yBAAA,KACT,OAAA,CAAQ,uBAAA;EAAR;;;;EAiDH,6BAAA,GACE,OAAA,EAAS,sBAAA,EAC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