@disconetwork/core 0.0.4 → 0.0.5

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.
@@ -0,0 +1,369 @@
1
+ "use client";
2
+ import { a as DiscoApiError, c as DiscoValidationError, f as zRecommendationsResponse2, i as remap, l as isAbortError, o as DiscoError, r as transformResponse, s as DiscoNetworkError, t as TrackingManager, u as envFromApiKey } from "./TrackingManager-LjaX_R2V.js";
3
+ import * as z$1 from "zod/v4";
4
+ import { ZodError } from "zod/v4";
5
+ import * as z from "zod/v3";
6
+ //#region src/lib/http.ts
7
+ /**
8
+ * Best-effort read of a non-2xx response body: try JSON, fall back to text,
9
+ * then give up with `undefined`. Used by both clients to populate
10
+ * `DiscoApiError.body` without ever throwing from the error path.
11
+ */
12
+ async function safeReadBody(response) {
13
+ try {
14
+ return await response.clone().json();
15
+ } catch {
16
+ try {
17
+ return await response.text();
18
+ } catch {
19
+ return;
20
+ }
21
+ }
22
+ }
23
+ //#endregion
24
+ //#region src/internal/recommendationsMapper.ts
25
+ /**
26
+ * Maps the proxy `/recommendations` response into the public, denormalized
27
+ * `RecommendationsResponse` (`mapRecommendationsResponse`).
28
+ *
29
+ * The proxy response is the external `/recommendations` response **verbatim plus
30
+ * a few extra top-level fields** (`layout_id`, `publisher_customization`, the
31
+ * `widget_*` markers, …). So this reuses the external machinery — the generated
32
+ * zod validator (`zRecommendationsResponse2`) and the external `transformResponse`
33
+ * mapper — and only layers on the denormalization (the join into
34
+ * `RecommendationGroup[]`) and the proxy extras.
35
+ *
36
+ * Validation is zod-backed: the external-wire part is validated by the generated
37
+ * `zRecommendationsResponse2` and the proxy extras by a small local schema, so a
38
+ * malformed server response surfaces as a `DiscoValidationError` rather than an
39
+ * opaque `undefined`-access crash deep in the join.
40
+ */
41
+ const zProxyExtras = z$1.object({
42
+ layout_id: z$1.string().optional(),
43
+ publisher_customization: z$1.record(z$1.string(), z$1.record(z$1.string(), z$1.string())).nullish()
44
+ });
45
+ /**
46
+ * Validate the proxy recommendations response and denormalize it into the
47
+ * public `RecommendationsResponse`.
48
+ *
49
+ * The proxy payload is the external wire response plus extras, so this reuses
50
+ * the external machinery: validate the wire part with the generated
51
+ * `zRecommendationsResponse2` and the extras with `zProxyExtras`, recase via
52
+ * the external `transformResponse`, then denormalize the resulting maps into
53
+ * `RecommendationGroup[]` (the internal value-add) and assemble the response
54
+ * with the proxy extras layered on.
55
+ *
56
+ * Throws `DiscoValidationError` if the server payload doesn't match the
57
+ * expected shape.
58
+ *
59
+ * @internal Built into `InternalDiscoClient.getRecommendations`; not part of
60
+ * the public API. The wire shape is encapsulated by the client on purpose.
61
+ */
62
+ function mapRecommendationsResponse(raw) {
63
+ let wire;
64
+ let extras;
65
+ try {
66
+ wire = zRecommendationsResponse2.parse(raw);
67
+ extras = zProxyExtras.parse(raw);
68
+ } catch (error) {
69
+ if (error instanceof ZodError) throw new DiscoValidationError("Failed to validate recommendations response", error, raw);
70
+ throw error;
71
+ }
72
+ const normalized = transformResponse(wire);
73
+ const recommendationGroups = denormalize(normalized);
74
+ return {
75
+ sessionId: normalized.sessionId,
76
+ layoutId: extras.layout_id ?? "SHOPIFY_NATIVE_ESSENTIAL",
77
+ recommendationGroups,
78
+ footer: normalized.footer,
79
+ publisherCustomization: extras.publisher_customization ?? null
80
+ };
81
+ }
82
+ /**
83
+ * Join the external normalized maps into ordered `RecommendationGroup[]`.
84
+ *
85
+ * Preserves the original denormalization semantics: order groups by the numeric
86
+ * suffix of their key (`group_0` before `group_10`), skip groups missing their
87
+ * entry list or display properties, skip entries whose `offerId` isn't in the
88
+ * recommendations map, and set each `Recommendation.id` to the offer's id and
89
+ * `insertionId` from the group entry.
90
+ */
91
+ function denormalize(normalized) {
92
+ const recommendations = normalized.recommendations;
93
+ const groupEntries = normalized.recommendationGroups;
94
+ const groupProps = normalized.recommendationGroupProperties ?? {};
95
+ const orderedKeys = Object.keys(groupEntries).sort((a, b) => numericSuffix(a) - numericSuffix(b));
96
+ const recommendationGroups = [];
97
+ for (const key of orderedKeys) {
98
+ const entries = groupEntries[key];
99
+ const props = groupProps[key];
100
+ if (!entries || !props) continue;
101
+ const recs = [];
102
+ for (const entry of entries) {
103
+ const rec = recommendations[entry.offerId];
104
+ if (!rec) continue;
105
+ recs.push({
106
+ id: rec.offer.id,
107
+ insertionId: entry.insertionId,
108
+ advertiser: rec.advertiser,
109
+ offer: rec.offer
110
+ });
111
+ }
112
+ recommendationGroups.push({
113
+ heading: props.heading ?? null,
114
+ slotContext: props.slotContext,
115
+ recommendations: recs
116
+ });
117
+ }
118
+ return recommendationGroups;
119
+ }
120
+ function numericSuffix(value) {
121
+ const suffix = value.split("_").pop() ?? "";
122
+ const parsed = Number.parseInt(suffix, 10);
123
+ return Number.isNaN(parsed) ? Number.POSITIVE_INFINITY : parsed;
124
+ }
125
+ //#endregion
126
+ //#region src/lib/schemas.ts
127
+ /**
128
+ * Thin wrappers around Zod parsing that convert a thrown `ZodError` into a
129
+ * `DiscoValidationError`, so validation failures surface as a Disco error type
130
+ * rather than leaking Zod's internals to consumers. Modeled on the equivalent
131
+ * helpers in Speakeasy-generated SDKs.
132
+ */
133
+ /**
134
+ * Run `fn` (typically a `schema.parse`) and, if it throws a `ZodError`, rethrow
135
+ * it as a `DiscoValidationError`. Any non-Zod error propagates untouched.
136
+ */
137
+ function parse(rawValue, fn, errorMessage) {
138
+ try {
139
+ return fn(rawValue);
140
+ } catch (err) {
141
+ if (err instanceof z.ZodError) throw new DiscoValidationError(errorMessage, err, rawValue);
142
+ throw err;
143
+ }
144
+ }
145
+ //#endregion
146
+ //#region src/internal/recommendationsRequestMapper.ts
147
+ /**
148
+ * Wire types for the recommendations *request* and `transformRequest`, which
149
+ * builds the snake_case wire body from the public `RecommendationsRequest`.
150
+ *
151
+ * `InternalDiscoClient.getRecommendations` calls `transformRequest` to map the
152
+ * camelCase request into the wire body before POSTing it.
153
+ *
154
+ * The mapping is Zod-backed: `RecommendationsRequest$outboundSchema` validates
155
+ * the public request before the `.transform()` reshapes it into the wire body,
156
+ * so a malformed request surfaces as a `DiscoValidationError` *before* it hits
157
+ * the network. This mirrors how Speakeasy-generated SDKs use an
158
+ * `$outboundSchema` per model.
159
+ */
160
+ const UserDetails$outboundSchema = z.object({
161
+ email: z.string().optional(),
162
+ firstName: z.string().optional(),
163
+ lastName: z.string().optional(),
164
+ phone: z.string().optional()
165
+ }).transform((v) => remap(v, {
166
+ firstName: "first_name",
167
+ lastName: "last_name"
168
+ }));
169
+ const PlacementDetails$outboundSchema = z.object({
170
+ displayMode: z.string().optional(),
171
+ view: z.string().optional()
172
+ }).transform((v) => remap(v, { displayMode: "display_mode" }));
173
+ const OrderDetails$outboundSchema = z.object({
174
+ id: z.string().optional(),
175
+ amount: z.union([z.number(), z.string()]).optional(),
176
+ currencyCode: z.string().optional()
177
+ }).transform((v) => ({
178
+ order_id: v.id,
179
+ cost_details: v.amount !== void 0 || v.currencyCode !== void 0 ? {
180
+ amount: v.amount,
181
+ currency_code: v.currencyCode
182
+ } : void 0
183
+ }));
184
+ const Purchase$outboundSchema = z.object({
185
+ name: z.string().optional(),
186
+ type: z.string().optional(),
187
+ variant: z.string().optional(),
188
+ quantity: z.number().optional(),
189
+ productId: z.string().optional(),
190
+ amount: z.number().optional(),
191
+ currencyCode: z.string().optional()
192
+ }).transform((v) => ({
193
+ name: v.name,
194
+ type: v.type,
195
+ variant: v.variant,
196
+ quantity: v.quantity,
197
+ product_id: v.productId,
198
+ cost_details: v.amount !== void 0 || v.currencyCode !== void 0 ? {
199
+ amount: v.amount,
200
+ currency_code: v.currencyCode
201
+ } : void 0
202
+ }));
203
+ const RunningExperiment$outboundSchema = z.object({
204
+ id: z.string(),
205
+ variant: z.string()
206
+ });
207
+ /**
208
+ * Validates the public request and reshapes it into the raw wire body: nest
209
+ * fields under `recommendations_data`, fold monetary fields into `cost_details`,
210
+ * convert camelCase to snake_case, and spread `extras` at the top level
211
+ * untransformed.
212
+ */
213
+ const RecommendationsRequest$outboundSchema = z.object({
214
+ user: UserDetails$outboundSchema.optional(),
215
+ placement: PlacementDetails$outboundSchema.optional(),
216
+ order: OrderDetails$outboundSchema.optional(),
217
+ purchases: z.array(Purchase$outboundSchema).optional(),
218
+ experiments: z.array(RunningExperiment$outboundSchema).optional(),
219
+ attributes: z.record(z.unknown()).optional(),
220
+ extras: z.record(z.unknown()).optional()
221
+ }).transform((v) => ({
222
+ recommendations_data: {
223
+ user_details: v.user,
224
+ placement_details: v.placement,
225
+ order_details: v.order,
226
+ purchases: v.purchases
227
+ },
228
+ running_experiments: v.experiments,
229
+ attributes: v.attributes,
230
+ ...v.extras
231
+ }));
232
+ /**
233
+ * Build the raw request body from the public `RecommendationsRequest`: nest
234
+ * fields under `recommendations_data`, fold monetary fields into `cost_details`
235
+ * (omitted entirely when no amount/currency is present), and convert camelCase
236
+ * to snake_case. `extras` is spread at the top level untransformed.
237
+ *
238
+ * Validates the input first and throws `DiscoValidationError` if the request
239
+ * doesn't match the expected shape.
240
+ *
241
+ * @internal Built into `DiscoClient.getRecommendations`; not part of the public
242
+ * API. The wire shape is encapsulated by the client on purpose.
243
+ */
244
+ function transformRequest(req) {
245
+ return parse(req, (value) => RecommendationsRequest$outboundSchema.parse(value), "Failed to validate recommendations request");
246
+ }
247
+ //#endregion
248
+ //#region src/internal/InternalDiscoClient.ts
249
+ /**
250
+ * Per-environment base URL for the internal/proxy backend — the legacy server
251
+ * that orchestrates and forwards to the downstream services. Both the
252
+ * recommendations and tracking endpoints sit under this origin, routed by path
253
+ * (the client appends `/core/recommendations/…` and `/track/partners_event/`).
254
+ */
255
+ const INTERNAL_BASE_URL = {
256
+ production: "https://consumer.disconetwork.com",
257
+ staging: "https://consumer.disconetwork-staging.com"
258
+ };
259
+ /**
260
+ * Internal client for the legacy **proxy** recommendations endpoint
261
+ * (`/core/recommendations/` on the backend), which orchestrates placement,
262
+ * experiments, layout, and `publisher_customization` server-side and supports
263
+ * `shopGid` auth for first-party surfaces (e.g. the Shopify checkout
264
+ * extension).
265
+ *
266
+ * First-party / legacy only — exported from `@disconetwork/core/internal`.
267
+ * External partners use the `DiscoClient` from the package root, which talks
268
+ * directly to `disco-recommendations-api`.
269
+ *
270
+ * Renderer-agnostic: this class makes plain HTTP calls and has no React
271
+ * dependency.
272
+ */
273
+ var InternalDiscoClient = class {
274
+ #env;
275
+ #url;
276
+ #headers;
277
+ #fetch;
278
+ constructor(config) {
279
+ this.#fetch = config.fetch ?? globalThis.fetch.bind(globalThis);
280
+ if ("apiKey" in config) {
281
+ this.#env = envFromApiKey(config.apiKey);
282
+ this.#url = `${INTERNAL_BASE_URL[this.#env]}/core/recommendations/`;
283
+ this.#headers = {
284
+ "x-api-key": config.apiKey,
285
+ "Content-Type": "application/json"
286
+ };
287
+ } else {
288
+ this.#env = config.env;
289
+ const shopId = stripShopGid(config.shopGid);
290
+ this.#url = `${INTERNAL_BASE_URL[this.#env]}/core/recommendations/shop_gid/${encodeURIComponent(shopId)}/`;
291
+ this.#headers = { "Content-Type": "application/json" };
292
+ }
293
+ }
294
+ /**
295
+ * Fetch recommendations for the given request.
296
+ *
297
+ * Validates and transforms the friendly camelCase `request` into the wire
298
+ * body, POSTs it, then validates and denormalizes the response into the
299
+ * friendly `RecommendationsResponse`. The snake_case wire format is fully
300
+ * encapsulated — callers never see it.
301
+ *
302
+ * Throws `DiscoValidationError` if the request or response fails schema
303
+ * validation, `DiscoApiError` on non-2xx responses, and `DiscoNetworkError`
304
+ * if the request can't reach the server (an abort rejects with the native
305
+ * `AbortError`). Parse failures propagate as-is.
306
+ */
307
+ getRecommendations = async (request, options) => {
308
+ const body = JSON.stringify(transformRequest(request));
309
+ let response;
310
+ try {
311
+ response = await this.#fetch(this.#url, {
312
+ method: "POST",
313
+ headers: this.#headers,
314
+ body,
315
+ signal: options?.signal
316
+ });
317
+ } catch (error) {
318
+ if (isAbortError(error)) throw error;
319
+ throw new DiscoNetworkError("Recommendations request failed to reach the server", error);
320
+ }
321
+ if (!response.ok) {
322
+ const body = await safeReadBody(response);
323
+ throw new DiscoApiError(`Recommendations request failed: ${response.status} ${response.statusText}`, {
324
+ status: response.status,
325
+ statusText: response.statusText,
326
+ body
327
+ });
328
+ }
329
+ return mapRecommendationsResponse(await response.json());
330
+ };
331
+ /**
332
+ * Fetch recommendations and create a session-bound tracker in one call.
333
+ *
334
+ * Composition convenience over `getRecommendations` + `createTrackingManager`:
335
+ * it derives the tracker's session from the response so callers don't have to
336
+ * thread the session id through themselves (and can't bind a tracker to the
337
+ * wrong session). The returned `data` is the mapped `RecommendationsResponse`.
338
+ *
339
+ * Throws `DiscoValidationError` / `DiscoApiError` the same as
340
+ * `getRecommendations`.
341
+ */
342
+ getRecommendationsWithTracker = async (request, options) => {
343
+ const data = await this.getRecommendations(request, { signal: options?.signal });
344
+ return {
345
+ data,
346
+ tracker: this.createTrackingManager(data.sessionId, { fetch: options?.fetch })
347
+ };
348
+ };
349
+ /**
350
+ * Create an event tracker bound to a recommendations session (the `sessionId`
351
+ * from a `getRecommendations` response).
352
+ *
353
+ * The tracker uses the same API-key-derived environment as the
354
+ * recommendations call, so sandbox recommendations cannot accidentally emit
355
+ * production tracking events.
356
+ */
357
+ createTrackingManager = (sessionId, options) => new TrackingManager({
358
+ sessionId,
359
+ endpoint: `${INTERNAL_BASE_URL[this.#env]}/track/partners_event/`,
360
+ fetch: options?.fetch ?? this.#fetch
361
+ });
362
+ };
363
+ function stripShopGid(shopGid) {
364
+ return shopGid.replace("gid://shopify/Shop/", "");
365
+ }
366
+ //#endregion
367
+ export { DiscoApiError, DiscoError, DiscoNetworkError, DiscoValidationError, InternalDiscoClient, TrackingManager, envFromApiKey };
368
+
369
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","names":["z","#env","#url","#headers","#fetch"],"sources":["../src/lib/http.ts","../src/internal/recommendationsMapper.ts","../src/lib/schemas.ts","../src/internal/recommendationsRequestMapper.ts","../src/internal/InternalDiscoClient.ts"],"sourcesContent":["/**\n * Best-effort read of a non-2xx response body: try JSON, fall back to text,\n * then give up with `undefined`. Used by both clients to populate\n * `DiscoApiError.body` without ever throwing from the error path.\n */\nexport async function safeReadBody(response: Response): Promise<unknown> {\n try {\n return await response.clone().json();\n } catch {\n try {\n return await response.text();\n } catch {\n return undefined;\n }\n }\n}\n","/**\n * Maps the proxy `/recommendations` response into the public, denormalized\n * `RecommendationsResponse` (`mapRecommendationsResponse`).\n *\n * The proxy response is the external `/recommendations` response **verbatim plus\n * a few extra top-level fields** (`layout_id`, `publisher_customization`, the\n * `widget_*` markers, …). So this reuses the external machinery — the generated\n * zod validator (`zRecommendationsResponse2`) and the external `transformResponse`\n * mapper — and only layers on the denormalization (the join into\n * `RecommendationGroup[]`) and the proxy extras.\n *\n * Validation is zod-backed: the external-wire part is validated by the generated\n * `zRecommendationsResponse2` and the proxy extras by a small local schema, so a\n * malformed server response surfaces as a `DiscoValidationError` rather than an\n * opaque `undefined`-access crash deep in the join.\n */\n\nimport { ZodError } from \"zod/v4\";\nimport { zRecommendationsResponse2 } from \"../api/generated/recommendations/zod.gen.js\";\nimport type { RecommendationsResponse as RecommendationsWireResponse } from \"../api/generated/recommendations/types.gen.js\";\nimport { transformResponse } from \"../external/recommendationsTransforms.js\";\nimport { DiscoValidationError } from \"../errors.js\";\nimport * as z from \"zod/v4\";\nimport type {\n Recommendation,\n RecommendationGroup,\n RecommendationsResponse,\n PublisherCustomization,\n} from \"./recommendations.js\";\n\n// ─── Validation of the proxy extras ──────────────────────────────────────────\n//\n// The external-wire part is validated by the generated `zRecommendationsResponse2`\n// (which STRIPS unknown keys — so the proxy extras won't survive it). The few\n// extra top-level fields the proxy adds are validated separately by this small\n// schema, run against the same raw payload. zod/v4 — to match the generated\n// validator and so its `ZodError` is caught by the `zod/v4` import above.\nconst zProxyExtras = z.object({\n layout_id: z.string().optional(),\n publisher_customization: z\n .record(z.string(), z.record(z.string(), z.string()))\n .nullish(),\n});\n\n// ─── Mapper ───────────────────────────────────────────────────────────────────\n\n/**\n * Validate the proxy recommendations response and denormalize it into the\n * public `RecommendationsResponse`.\n *\n * The proxy payload is the external wire response plus extras, so this reuses\n * the external machinery: validate the wire part with the generated\n * `zRecommendationsResponse2` and the extras with `zProxyExtras`, recase via\n * the external `transformResponse`, then denormalize the resulting maps into\n * `RecommendationGroup[]` (the internal value-add) and assemble the response\n * with the proxy extras layered on.\n *\n * Throws `DiscoValidationError` if the server payload doesn't match the\n * expected shape.\n *\n * @internal Built into `InternalDiscoClient.getRecommendations`; not part of\n * the public API. The wire shape is encapsulated by the client on purpose.\n */\nexport function mapRecommendationsResponse(\n raw: unknown,\n): RecommendationsResponse {\n let wire: RecommendationsWireResponse;\n let extras: z.infer<typeof zProxyExtras>;\n try {\n // The generated validator pins the external-wire shape; cast its (inferred)\n // output to the wire type `transformResponse` consumes — both describe the\n // same spec shape.\n wire = zRecommendationsResponse2.parse(raw) as RecommendationsWireResponse;\n extras = zProxyExtras.parse(raw);\n } catch (error) {\n if (error instanceof ZodError) {\n throw new DiscoValidationError(\n \"Failed to validate recommendations response\",\n error,\n raw,\n );\n }\n throw error;\n }\n\n // Reuse the external mapper for the leaf types + casing (free), then join the\n // normalized maps into the denormalized groups (the internal value-add).\n const normalized = transformResponse(wire);\n const recommendationGroups = denormalize(normalized);\n\n return {\n sessionId: normalized.sessionId,\n layoutId: extras.layout_id ?? \"SHOPIFY_NATIVE_ESSENTIAL\",\n recommendationGroups,\n footer: normalized.footer,\n publisherCustomization:\n (extras.publisher_customization as PublisherCustomization | null) ?? null,\n };\n}\n\n/**\n * Join the external normalized maps into ordered `RecommendationGroup[]`.\n *\n * Preserves the original denormalization semantics: order groups by the numeric\n * suffix of their key (`group_0` before `group_10`), skip groups missing their\n * entry list or display properties, skip entries whose `offerId` isn't in the\n * recommendations map, and set each `Recommendation.id` to the offer's id and\n * `insertionId` from the group entry.\n */\nfunction denormalize(\n normalized: ReturnType<typeof transformResponse>,\n): RecommendationGroup[] {\n const recommendations = normalized.recommendations;\n const groupEntries = normalized.recommendationGroups;\n const groupProps = normalized.recommendationGroupProperties ?? {};\n\n const orderedKeys = Object.keys(groupEntries).sort(\n (a, b) => numericSuffix(a) - numericSuffix(b),\n );\n\n const recommendationGroups: RecommendationGroup[] = [];\n for (const key of orderedKeys) {\n const entries = groupEntries[key];\n const props = groupProps[key];\n // Skip groups missing their entry list or display properties.\n if (!entries || !props) continue;\n\n const recs: Recommendation[] = [];\n for (const entry of entries) {\n const rec = recommendations[entry.offerId];\n if (!rec) continue; // entry references an absent recommendation\n recs.push({\n id: rec.offer.id,\n insertionId: entry.insertionId,\n advertiser: rec.advertiser,\n offer: rec.offer,\n });\n }\n\n recommendationGroups.push({\n heading: props.heading ?? null,\n slotContext: props.slotContext,\n recommendations: recs,\n });\n }\n\n return recommendationGroups;\n}\n\nfunction numericSuffix(value: string): number {\n const suffix = value.split(\"_\").pop() ?? \"\";\n const parsed = Number.parseInt(suffix, 10);\n return Number.isNaN(parsed) ? Number.POSITIVE_INFINITY : parsed;\n}\n","/**\n * Thin wrappers around Zod parsing that convert a thrown `ZodError` into a\n * `DiscoValidationError`, so validation failures surface as a Disco error type\n * rather than leaking Zod's internals to consumers. Modeled on the equivalent\n * helpers in Speakeasy-generated SDKs.\n */\n\nimport * as z from \"zod/v3\";\nimport { DiscoValidationError } from \"../errors.js\";\n\n/**\n * Run `fn` (typically a `schema.parse`) and, if it throws a `ZodError`, rethrow\n * it as a `DiscoValidationError`. Any non-Zod error propagates untouched.\n */\nexport function parse<Inp, Out>(\n rawValue: Inp,\n fn: (value: Inp) => Out,\n errorMessage: string,\n): Out {\n try {\n return fn(rawValue);\n } catch (err) {\n if (err instanceof z.ZodError) {\n throw new DiscoValidationError(errorMessage, err, rawValue);\n }\n throw err;\n }\n}\n","/**\n * Wire types for the recommendations *request* and `transformRequest`, which\n * builds the snake_case wire body from the public `RecommendationsRequest`.\n *\n * `InternalDiscoClient.getRecommendations` calls `transformRequest` to map the\n * camelCase request into the wire body before POSTing it.\n *\n * The mapping is Zod-backed: `RecommendationsRequest$outboundSchema` validates\n * the public request before the `.transform()` reshapes it into the wire body,\n * so a malformed request surfaces as a `DiscoValidationError` *before* it hits\n * the network. This mirrors how Speakeasy-generated SDKs use an\n * `$outboundSchema` per model.\n */\n\nimport * as z from \"zod/v3\";\nimport { parse } from \"../lib/schemas.js\";\nimport { remap } from \"../lib/primitives.js\";\nimport type {\n OrderDetails,\n PlacementDetails,\n Purchase,\n RecommendationsRequest,\n RunningExperiment,\n UserDetails,\n} from \"./recommendations.js\";\n\n// ─── Raw wire shape ──────────────────────────────────────────────────────────\n//\n// The endpoint nests most request fields under `recommendations_data`, with\n// monetary fields tucked into a `cost_details` sub-object, while experiments\n// and attributes sit at the top level. The public `RecommendationsRequest` is\n// a flatter façade over this; the outbound schema bridges the two.\n\ntype RawCostDetails = {\n amount?: number | string;\n currency_code?: string;\n};\n\ntype RawUserDetails = {\n email?: string;\n first_name?: string;\n last_name?: string;\n phone?: string;\n};\n\ntype RawPlacementDetails = {\n display_mode?: string;\n view?: string;\n};\n\ntype RawOrderDetails = {\n order_id?: string;\n cost_details?: RawCostDetails;\n};\n\ntype RawPurchase = {\n name?: string;\n type?: string;\n variant?: string;\n quantity?: number;\n product_id?: string;\n cost_details?: RawCostDetails;\n};\n\ntype RawRunningExperiment = {\n id: string;\n variant: string;\n};\n\ntype RawRecommendationsData = {\n user_details?: RawUserDetails;\n placement_details?: RawPlacementDetails;\n order_details?: RawOrderDetails;\n purchases?: RawPurchase[];\n};\n\ntype RawRecommendationsRequest = {\n recommendations_data?: RawRecommendationsData;\n running_experiments?: RawRunningExperiment[];\n attributes?: Record<string, unknown>;\n /**\n * Platform-specific top-level fields passed through untransformed\n * (e.g. `shopify_checkout_token`). The public type funnels these through\n * `extras`; on the raw body they're just additional keys.\n */\n [key: string]: unknown;\n};\n\n// ─── Outbound schemas ──────────────────────────────────────────────────────────\n//\n// Each schema validates a slice of the public (camelCase) request and\n// `.transform()`s it into the snake_case wire shape. Simple field renames go\n// through `remap`; the monetary fields fold into a `cost_details` sub-object\n// that's omitted entirely when no amount/currency is present. The\n// `z.ZodType<RawX, ZodTypeDef, PublicX>` annotation pins input and output types\n// to the hand-written shapes so they can't drift.\n\nconst UserDetails$outboundSchema: z.ZodType<\n RawUserDetails,\n z.ZodTypeDef,\n UserDetails\n> = z\n .object({\n email: z.string().optional(),\n firstName: z.string().optional(),\n lastName: z.string().optional(),\n phone: z.string().optional(),\n })\n .transform((v) =>\n remap(v, { firstName: \"first_name\", lastName: \"last_name\" }),\n );\n\nconst PlacementDetails$outboundSchema: z.ZodType<\n RawPlacementDetails,\n z.ZodTypeDef,\n PlacementDetails\n> = z\n .object({\n displayMode: z.string().optional(),\n view: z.string().optional(),\n })\n .transform((v) => remap(v, { displayMode: \"display_mode\" }));\n\nconst OrderDetails$outboundSchema: z.ZodType<\n RawOrderDetails,\n z.ZodTypeDef,\n OrderDetails\n> = z\n .object({\n id: z.string().optional(),\n amount: z.union([z.number(), z.string()]).optional(),\n currencyCode: z.string().optional(),\n })\n .transform((v) => ({\n order_id: v.id,\n cost_details:\n v.amount !== undefined || v.currencyCode !== undefined\n ? { amount: v.amount, currency_code: v.currencyCode }\n : undefined,\n }));\n\nconst Purchase$outboundSchema: z.ZodType<RawPurchase, z.ZodTypeDef, Purchase> =\n z\n .object({\n name: z.string().optional(),\n type: z.string().optional(),\n variant: z.string().optional(),\n quantity: z.number().optional(),\n productId: z.string().optional(),\n amount: z.number().optional(),\n currencyCode: z.string().optional(),\n })\n .transform((v) => ({\n name: v.name,\n type: v.type,\n variant: v.variant,\n quantity: v.quantity,\n product_id: v.productId,\n cost_details:\n v.amount !== undefined || v.currencyCode !== undefined\n ? { amount: v.amount, currency_code: v.currencyCode }\n : undefined,\n }));\n\nconst RunningExperiment$outboundSchema: z.ZodType<\n RawRunningExperiment,\n z.ZodTypeDef,\n RunningExperiment\n> = z.object({\n id: z.string(),\n variant: z.string(),\n});\n\n/**\n * Validates the public request and reshapes it into the raw wire body: nest\n * fields under `recommendations_data`, fold monetary fields into `cost_details`,\n * convert camelCase to snake_case, and spread `extras` at the top level\n * untransformed.\n */\nconst RecommendationsRequest$outboundSchema: z.ZodType<\n RawRecommendationsRequest,\n z.ZodTypeDef,\n RecommendationsRequest\n> = z\n .object({\n user: UserDetails$outboundSchema.optional(),\n placement: PlacementDetails$outboundSchema.optional(),\n order: OrderDetails$outboundSchema.optional(),\n purchases: z.array(Purchase$outboundSchema).optional(),\n experiments: z.array(RunningExperiment$outboundSchema).optional(),\n attributes: z.record(z.unknown()).optional(),\n extras: z.record(z.unknown()).optional(),\n })\n .transform((v) => ({\n recommendations_data: {\n user_details: v.user,\n placement_details: v.placement,\n order_details: v.order,\n purchases: v.purchases,\n },\n running_experiments: v.experiments,\n attributes: v.attributes,\n ...v.extras,\n }));\n\n// ─── Mapper ───────────────────────────────────────────────────────────────────\n\n/**\n * Build the raw request body from the public `RecommendationsRequest`: nest\n * fields under `recommendations_data`, fold monetary fields into `cost_details`\n * (omitted entirely when no amount/currency is present), and convert camelCase\n * to snake_case. `extras` is spread at the top level untransformed.\n *\n * Validates the input first and throws `DiscoValidationError` if the request\n * doesn't match the expected shape.\n *\n * @internal Built into `DiscoClient.getRecommendations`; not part of the public\n * API. The wire shape is encapsulated by the client on purpose.\n */\nexport function transformRequest(\n req: RecommendationsRequest,\n): RawRecommendationsRequest {\n return parse(\n req,\n (value) => RecommendationsRequest$outboundSchema.parse(value),\n \"Failed to validate recommendations request\",\n );\n}\n","import { envFromApiKey, type DiscoEnv } from \"../env.js\";\nimport { DiscoApiError, DiscoNetworkError, isAbortError } from \"../errors.js\";\nimport { safeReadBody } from \"../lib/http.js\";\nimport { TrackingManager, type EventTracker } from \"../TrackingManager.js\";\nimport type {\n RecommendationsRequest,\n RecommendationsResponse,\n} from \"./recommendations.js\";\nimport { mapRecommendationsResponse } from \"./recommendationsMapper.js\";\nimport { transformRequest } from \"./recommendationsRequestMapper.js\";\n\n/**\n * Per-environment base URL for the internal/proxy backend — the legacy server\n * that orchestrates and forwards to the downstream services. Both the\n * recommendations and tracking endpoints sit under this origin, routed by path\n * (the client appends `/core/recommendations/…` and `/track/partners_event/`).\n */\nexport const INTERNAL_BASE_URL = {\n production: \"https://consumer.disconetwork.com\",\n staging: \"https://consumer.disconetwork-staging.com\",\n} as const satisfies Record<DiscoEnv, string>;\n\n/**\n * Authenticate with a scoped public API key. Sent as the `x-api-key`\n * header against the unified `/core/recommendations/` endpoint. The key\n * prefix (`disco_pk_live_` / `disco_pk_sandbox_`) determines the\n * environment, so there is no separate `env` to set.\n *\n * Use this from partner apps and server-side code that hold a key.\n */\nexport type ApiKeyConfig = {\n apiKey: string;\n fetch?: typeof fetch;\n};\n\n/**\n * Authenticate by Shopify shop — for surfaces that must not embed a key,\n * notably the App-Store-deployed checkout extension. The request hits the\n * `/core/recommendations/shop_gid/<id>/` proxy with **no** API key; the\n * backend resolves the publisher from the shop and injects the key\n * server-side.\n *\n * `env` is required here because, unlike `ApiKeyConfig`, there is no key\n * to derive it from. `shopGid` may be a full `gid://shopify/Shop/<id>` or\n * the bare id.\n */\nexport type ShopGidConfig = {\n shopGid: string;\n env: DiscoEnv;\n fetch?: typeof fetch;\n};\n\nexport type DiscoClientConfig = ApiKeyConfig | ShopGidConfig;\n\nexport type GetRecommendationsOptions = {\n /** Forwarded to `fetch` so consumers can cancel in-flight requests. */\n signal?: AbortSignal;\n};\n\nexport type CreateTrackingManagerOptions = {\n /**\n * Override the fetch implementation used by the tracker. Defaults to the\n * same fetch implementation configured on the client.\n */\n fetch?: typeof fetch;\n};\n\n/**\n * Result of `getRecommendationsWithTracker`: the mapped recommendations\n * response plus a tracker already bound to its session.\n */\nexport type RecommendationsWithTracker = {\n /**\n * The mapped, denormalized recommendations response — the same friendly\n * camelCase shape `getRecommendations` returns.\n */\n data: RecommendationsResponse;\n /** Event tracker bound to this response's session. */\n tracker: EventTracker;\n};\n\n/**\n * Internal client for the legacy **proxy** recommendations endpoint\n * (`/core/recommendations/` on the backend), which orchestrates placement,\n * experiments, layout, and `publisher_customization` server-side and supports\n * `shopGid` auth for first-party surfaces (e.g. the Shopify checkout\n * extension).\n *\n * First-party / legacy only — exported from `@disconetwork/core/internal`.\n * External partners use the `DiscoClient` from the package root, which talks\n * directly to `disco-recommendations-api`.\n *\n * Renderer-agnostic: this class makes plain HTTP calls and has no React\n * dependency.\n */\nexport class InternalDiscoClient {\n readonly #env: DiscoEnv;\n readonly #url: string;\n readonly #headers: Record<string, string>;\n readonly #fetch: typeof fetch;\n\n constructor(config: DiscoClientConfig) {\n this.#fetch = config.fetch ?? globalThis.fetch.bind(globalThis);\n\n if (\"apiKey\" in config) {\n this.#env = envFromApiKey(config.apiKey);\n this.#url = `${INTERNAL_BASE_URL[this.#env]}/core/recommendations/`;\n this.#headers = {\n \"x-api-key\": config.apiKey,\n \"Content-Type\": \"application/json\",\n };\n } else {\n this.#env = config.env;\n const shopId = stripShopGid(config.shopGid);\n this.#url = `${INTERNAL_BASE_URL[this.#env]}/core/recommendations/shop_gid/${encodeURIComponent(shopId)}/`;\n // No x-api-key: the backend resolves auth from the shop_gid.\n this.#headers = { \"Content-Type\": \"application/json\" };\n }\n }\n\n /**\n * Fetch recommendations for the given request.\n *\n * Validates and transforms the friendly camelCase `request` into the wire\n * body, POSTs it, then validates and denormalizes the response into the\n * friendly `RecommendationsResponse`. The snake_case wire format is fully\n * encapsulated — callers never see it.\n *\n * Throws `DiscoValidationError` if the request or response fails schema\n * validation, `DiscoApiError` on non-2xx responses, and `DiscoNetworkError`\n * if the request can't reach the server (an abort rejects with the native\n * `AbortError`). Parse failures propagate as-is.\n */\n getRecommendations = async (\n request: RecommendationsRequest,\n options?: GetRecommendationsOptions,\n ): Promise<RecommendationsResponse> => {\n // `transformRequest` validates the request and builds the wire body; its\n // `DiscoValidationError` must propagate, so it runs *before* the fetch try\n // (otherwise the catch below would mis-wrap it as a `DiscoNetworkError`).\n const body = JSON.stringify(transformRequest(request));\n let response: Response;\n try {\n response = await this.#fetch(this.#url, {\n method: \"POST\",\n headers: this.#headers,\n body,\n signal: options?.signal,\n });\n } catch (error) {\n // A cancellation propagates as-is; any other transport failure is wrapped.\n if (isAbortError(error)) throw error;\n throw new DiscoNetworkError(\n \"Recommendations request failed to reach the server\",\n error,\n );\n }\n\n if (!response.ok) {\n const body = await safeReadBody(response);\n throw new DiscoApiError(\n `Recommendations request failed: ${response.status} ${response.statusText}`,\n { status: response.status, statusText: response.statusText, body },\n );\n }\n\n return mapRecommendationsResponse(await response.json());\n };\n\n /**\n * Fetch recommendations and create a session-bound tracker in one call.\n *\n * Composition convenience over `getRecommendations` + `createTrackingManager`:\n * it derives the tracker's session from the response so callers don't have to\n * thread the session id through themselves (and can't bind a tracker to the\n * wrong session). The returned `data` is the mapped `RecommendationsResponse`.\n *\n * Throws `DiscoValidationError` / `DiscoApiError` the same as\n * `getRecommendations`.\n */\n getRecommendationsWithTracker = async (\n request: RecommendationsRequest,\n options?: GetRecommendationsOptions & CreateTrackingManagerOptions,\n ): Promise<RecommendationsWithTracker> => {\n const data = await this.getRecommendations(request, {\n signal: options?.signal,\n });\n const tracker = this.createTrackingManager(data.sessionId, {\n fetch: options?.fetch,\n });\n return { data, tracker };\n };\n\n /**\n * Create an event tracker bound to a recommendations session (the `sessionId`\n * from a `getRecommendations` response).\n *\n * The tracker uses the same API-key-derived environment as the\n * recommendations call, so sandbox recommendations cannot accidentally emit\n * production tracking events.\n */\n createTrackingManager = (\n sessionId: string,\n options?: CreateTrackingManagerOptions,\n ): EventTracker =>\n new TrackingManager({\n sessionId,\n endpoint: `${INTERNAL_BASE_URL[this.#env]}/track/partners_event/`,\n fetch: options?.fetch ?? this.#fetch,\n });\n}\n\nfunction stripShopGid(shopGid: string): string {\n return shopGid.replace(\"gid://shopify/Shop/\", \"\");\n}\n"],"mappings":";;;;;;;;;;;AAKA,eAAsB,aAAa,UAAsC;CACvE,IAAI;EACF,OAAO,MAAM,SAAS,MAAM,EAAE,KAAK;CACrC,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AY;GAAK,CACnE;EACF;EAEA,OAAO,2BAA2B,MAAM,SAAS,KAAK,CAAC;CACzD;;;;;;;;;;;;CAaA,gCAAgC,OAC9B,SACA,YACwC;EACxC,MAAM,OAAO,MAAM,KAAK,mBAAmB,SAAS,EAClD,QAAQ,SAAS,OACnB,CAAC;EAID,OAAO;GAAE;GAAM,SAHC,KAAK,sBAAsB,KAAK,WAAW,EACzD,OAAO,SAAS,MAClB,CACqB;EAAE;CACzB;;;;;;;;;CAUA,yBACE,WACA,YAEA,IAAI,gBAAgB;EAClB;EACA,UAAU,GAAG,kBAAkB,KAAKF,MAAM;EAC1C,OAAO,SAAS,SAAS,KAAKG;CAChC,CAAC;AACL;AAEA,SAAS,aAAa,SAAyB;CAC7C,OAAO,QAAQ,QAAQ,uBAAuB,EAAE;AAClD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@disconetwork/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Core package for disco-js.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -11,6 +11,10 @@
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
13
  "default": "./dist/index.js"
14
+ },
15
+ "./internal": {
16
+ "types": "./dist/internal.d.ts",
17
+ "default": "./dist/internal.js"
14
18
  }
15
19
  },
16
20
  "files": [
@@ -23,6 +27,7 @@
23
27
  "node": ">=20"
24
28
  },
25
29
  "devDependencies": {
30
+ "@hey-api/openapi-ts": "^0.98.1",
26
31
  "@types/node": "^22.15.3",
27
32
  "eslint": "^9.39.1",
28
33
  "tsdown": "^0.22.0",
@@ -31,6 +36,9 @@
31
36
  "@repo/eslint-config": "0.0.0",
32
37
  "@repo/typescript-config": "0.0.0"
33
38
  },
39
+ "dependencies": {
40
+ "zod": "^3.25.0 || ^4.0.0"
41
+ },
34
42
  "scripts": {
35
43
  "build": "tsdown",
36
44
  "dev": "tsdown --watch",
@@ -38,6 +46,7 @@
38
46
  "lint": "eslint . --max-warnings 0",
39
47
  "test": "vitest run",
40
48
  "test:watch": "vitest",
41
- "clean": "rm -rf dist"
49
+ "clean": "rm -rf dist",
50
+ "generate:sdk": "openapi-ts"
42
51
  }
43
52
  }