@disconetwork/core 0.0.6 → 0.0.8
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/dist/{errors-C-xomnpl.d.ts → errors-BygGBn_U.d.ts} +28 -63
- package/dist/errors-BygGBn_U.d.ts.map +1 -0
- package/dist/index.d.ts +21 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1030 -51
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +84 -18
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +158 -45
- package/dist/internal.js.map +1 -1
- package/dist/{TrackingManager-_IENEPuL.js → recommendationsTransforms-BDrxhOzv.js} +2 -109
- package/dist/recommendationsTransforms-BDrxhOzv.js.map +1 -0
- package/package.json +3 -3
- package/dist/TrackingManager-_IENEPuL.js.map +0 -1
- package/dist/errors-C-xomnpl.d.ts.map +0 -1
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
//#region src/env.d.ts
|
|
2
|
+
type DiscoEnv = "production" | "staging";
|
|
3
|
+
/**
|
|
4
|
+
* Derive the environment from a Disco public API key.
|
|
5
|
+
*
|
|
6
|
+
* Public keys are prefixed `disco_pk_<env>_…`, where `<env>` is `live`
|
|
7
|
+
* (→ production) or `sandbox` (→ staging). The key is the single source
|
|
8
|
+
* of truth for which backend the SDK talks to — there is no separate
|
|
9
|
+
* `env` to pass or keep in sync, and a `live` key can't be pointed at
|
|
10
|
+
* staging (or vice versa).
|
|
11
|
+
*
|
|
12
|
+
* Throws on anything that isn't a recognized public key — including a
|
|
13
|
+
* secret (`disco_sk_…`) key, which must never be used in browser code.
|
|
14
|
+
*/
|
|
15
|
+
declare function envFromApiKey(apiKey: string): DiscoEnv;
|
|
16
|
+
//#endregion
|
|
1
17
|
//#region src/api/generated/recommendations/types.gen.d.ts
|
|
2
18
|
/**
|
|
3
19
|
* DisplayMode
|
|
@@ -262,6 +278,16 @@ type EventPlacementDetails = {
|
|
|
262
278
|
* service) and the internal/proxy client — the proxy forwards events verbatim,
|
|
263
279
|
* so the contract is identical.
|
|
264
280
|
*/
|
|
281
|
+
/**
|
|
282
|
+
* Renderer-agnostic handle for emitting Disco events. Both the SDK-backed
|
|
283
|
+
* external tracker (`DiscoClient.createTrackingManager`) and the proxy
|
|
284
|
+
* `TrackingManager` implement this same interface, so consumers (and the React
|
|
285
|
+
* layer) depend on the interface, not the implementation. `track` is a closure,
|
|
286
|
+
* so it's safe to destructure.
|
|
287
|
+
*/
|
|
288
|
+
type EventTracker = {
|
|
289
|
+
track: (event: EventPayload) => void;
|
|
290
|
+
};
|
|
265
291
|
type EventPayload = {
|
|
266
292
|
type: WidgetEventType;
|
|
267
293
|
placement?: EventPlacementDetails;
|
|
@@ -289,67 +315,6 @@ type EventPayload = {
|
|
|
289
315
|
placement?: EventPlacementDetails;
|
|
290
316
|
};
|
|
291
317
|
//#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
318
|
//#region src/errors.d.ts
|
|
354
319
|
/**
|
|
355
320
|
* Base class for every error thrown by the Disco clients. Catch this to handle
|
|
@@ -404,5 +369,5 @@ declare class DiscoNetworkError extends DiscoError {
|
|
|
404
369
|
constructor(message: string, cause: unknown);
|
|
405
370
|
}
|
|
406
371
|
//#endregion
|
|
407
|
-
export {
|
|
408
|
-
//# sourceMappingURL=errors-
|
|
372
|
+
export { DisplayMode as A, OfferMetadata as C, RecommendationsRequest as D, RecommendationGroupProperty as E, View as F, DiscoEnv as I, envFromApiKey as L, 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 };
|
|
373
|
+
//# sourceMappingURL=errors-BygGBn_U.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-BygGBn_U.d.ts","names":[],"sources":["../src/env.ts","../src/api/generated/recommendations/types.gen.ts","../src/external/recommendations.ts","../src/types.ts","../src/errors.ts"],"mappings":";KAAY,QAAA;AAAZ;;;;AAAoB;AAcpB;;;;AAAuD;;;AAdvD,iBAcgB,aAAA,CAAc,MAAA,WAAiB,QAAQ;;;;;;KCgd3C,WAAA;;;;KAyKA,MAAA;;;;KAgMA,YAAA;;;;;;KAiTA,OAAA;;;;KAUA,KAAA;;;;;;KAyBA,IAAA;;;;AA7rBZ;;;;KChcY,iBAAA;EACV,IAAA,UDwmBgB;ECtmBhB,OAAO;AAAA;ADsyBT;;;;AAAA,KCrxBK,UAAA;EACH,SAAA;EACA,eAAA;EACA,sBAAA;EACA,SAAA;EACA,aAAA;EACA,YAAA,GAAe,YAAY,ED0kCZ;ECxkCf,QAAA;EACA,UAAA;AAAA;AAAA,KAGG,WAAA;EACH,KAAA,GAAQ,KAAA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ED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as DisplayMode, C as OfferMetadata, D as RecommendationsRequest, E as RecommendationGroupProperty, F as View, I as DiscoEnv, 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-BygGBn_U.js";
|
|
2
2
|
|
|
3
3
|
//#region src/external/DiscoClient.d.ts
|
|
4
4
|
/**
|
|
@@ -44,6 +44,7 @@ type RecommendationsWithTracker = {
|
|
|
44
44
|
*/
|
|
45
45
|
declare class DiscoClient {
|
|
46
46
|
#private;
|
|
47
|
+
get env(): DiscoEnv;
|
|
47
48
|
constructor(config: DiscoClientConfig);
|
|
48
49
|
/**
|
|
49
50
|
* Fetch recommendations for the given request.
|
|
@@ -64,10 +65,27 @@ declare class DiscoClient {
|
|
|
64
65
|
/**
|
|
65
66
|
* Create an events tracker bound to a recommendations session (the
|
|
66
67
|
* `sessionId` from a `getRecommendations` response). Posts to the external
|
|
67
|
-
* `/events` endpoint with this client's `x-api-key
|
|
68
|
+
* `/events` endpoint with this client's `x-api-key`, via the generated events
|
|
69
|
+
* SDK (`eventsPost`).
|
|
70
|
+
*
|
|
71
|
+
* This is the **raw** tracker — it sends every call, fire-and-forget (never
|
|
72
|
+
* throws; failures are logged). Impression dedup is a render-lifecycle policy
|
|
73
|
+
* applied a layer up (the React layer wraps this with `withImpressionDedupe`),
|
|
74
|
+
* not baked into the core client.
|
|
68
75
|
*/
|
|
69
76
|
createTrackingManager: (sessionId: string, options?: CreateTrackingManagerOptions) => EventTracker;
|
|
70
77
|
}
|
|
71
78
|
//#endregion
|
|
72
|
-
|
|
79
|
+
//#region src/events/dedupe.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Wrap an {@link EventTracker} so repeat impressions are suppressed within the
|
|
82
|
+
* session: a given (event type, insertionId) is forwarded once, then dropped.
|
|
83
|
+
*
|
|
84
|
+
* Dedup is a delivery *policy*, not transport — kept as an explicit, opt-in
|
|
85
|
+
* decorator so suppression is never a surprise. State (the seen-set) lives in
|
|
86
|
+
* the wrapper; create one per session-bound tracker to scope dedup per session.
|
|
87
|
+
*/
|
|
88
|
+
declare function withImpressionDedupe(inner: EventTracker): EventTracker;
|
|
89
|
+
//#endregion
|
|
90
|
+
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
91
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/external/DiscoClient.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/external/DiscoClient.ts","../src/events/dedupe.ts"],"mappings":";;;AAiCA;;;;;AAAA,KAAY,iBAAA;EACV,MAAA;EAMe;;AAAK;AAGtB;EAJE,UAAA;EACA,KAAA,UAAe,KAAK;AAAA;AAAA,KAGV,yBAAA;EAKA,uEAHV,MAAA,GAAS,WAAW;AAAA;AAAA,KAGV,4BAAA;EAEU,8EAApB,KAAA,UAAe,KAAK;AAAA;;;;;KAOV,0BAAA;EACV,IAAA,EAAM,uBAAA;EACN,OAAA,EAAS,YAAY;AAAA;AAgBvB;;;;;;;;;;;;;AAAA,cAAa,WAAA;EAAA;MAMP,GAAA,CAAA,GAAO,QAAA;cAIC,MAAA,EAAQ,iBAAA;EA4GL;;;;;;;;;;EA/Ef,kBAAA,GACE,OAAA,EAAS,sBAAA,EACT,OAAA,GAAU,yBAAA,KACT,OAAA,CAAQ,uBAAA;EADT;;;;EAkDF,6BAAA,GACE,OAAA,EAAS,sBAAA,EACT,OAAA,GAAU,yBAAA,GAA4B,4BAAA,KACrC,OAAA,CAAQ,0BAAA;EAFT;;;;;;;;;;;EAuBF,qBAAA,GACE,SAAA,UACA,OAAA,GAAU,4BAAA,KACT,YAAA;AAAA;;;;;AAhKL;;;;;;iBCZgB,oBAAA,CAAqB,KAAA,EAAO,YAAA,GAAe,YAAY"}
|