@eldrajs/sdk 0.3.2 → 0.4.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/CHANGELOG.md CHANGED
@@ -9,6 +9,15 @@ platform repository.
9
9
 
10
10
  ## Unreleased
11
11
 
12
+ - **Campaign attribution (WS-546, contract 5.4.0).** `captureCampaignAttribution(url?)` keeps a
13
+ landing URL's `utm_source`, `utm_medium`, `utm_campaign` and `utm_id` (as `campaignId`, only when
14
+ it is a uuid) in `localStorage` for 30 days, replacing an earlier landing whole; nothing else, and
15
+ nothing outside a browser. Each tag loses control characters and is cut to 100 characters; a tag
16
+ holding `@` is dropped, since it may be an email address. `cart.addItem` sends it as `attribution`
17
+ with every add, which needs a gateway on contract 5.4.0 or later. New: `readCampaignAttribution()`,
18
+ `clearCampaignAttribution()`, the `EldraCampaignAttribution` type and the client option
19
+ `campaignAttribution` (`{ storage }`, or `false` to send none). Nothing clears it automatically.
20
+
12
21
  - **Images use the size the API gives them (contract 4.14.0).** `EldraImageSource` accepts the
13
22
  `width` and `height` an image object now carries (its pixels as displayed). `imageSrcset` stops at
14
23
  that width unless `originalWidth` is passed, and `responsiveImage` sets `width`/`height` to the
package/README.md CHANGED
@@ -140,6 +140,75 @@ number rather than under a currency symbol nobody chose. It reads the same organ
140
140
  rest of the group reads, so a caller already holding an `EldraOrganizationDetails` should take
141
141
  `commerce` off it instead of asking again.
142
142
 
143
+ ## Campaign attribution
144
+
145
+ A merchant's campaign mails link to the storefront with `utm_source`, `utm_medium`, `utm_campaign`
146
+ and `utm_id` (the campaign's id). Call `captureCampaignAttribution()` in the browser on the first
147
+ page and after every navigation. When the URL carries any of the four, the kit notes them with the
148
+ time. **It keeps them only once the visitor agrees.** Keeping them in the browser to credit a sale is
149
+ not something the shop needs in order to work, so in Iceland it needs consent (88. gr. 2. mgr. laga
150
+ 70/2022 as Fjarskiptastofa reads it, ákvörðun 14/2024). Your consent tool answers with one call each:
151
+
152
+ ```ts
153
+ import {
154
+ captureCampaignAttribution,
155
+ grantCampaignAttributionConsent,
156
+ withdrawCampaignAttributionConsent,
157
+ } from '@eldrajs/sdk';
158
+
159
+ captureCampaignAttribution(); // reads location.href
160
+ router.afterEach((to, _from, failure) => {
161
+ if (!failure) captureCampaignAttribution(to.fullPath);
162
+ });
163
+ consentTool.onChange((choice) =>
164
+ choice.marketing ? grantCampaignAttributionConsent() : withdrawCampaignAttributionConsent()
165
+ );
166
+ ```
167
+
168
+ - **Before consent** the landing is held in memory for this page load only, and `cart.addItem`
169
+ sends nothing.
170
+ - **On consent** the landing of this page load is kept in `localStorage` (key
171
+ `eldra.campaignAttribution`) for 30 days from when the visitor landed. Later landings are kept as
172
+ they come, a later one replacing the earlier whole. From then on `cart.addItem` sends them as
173
+ `attribution` with every add, and the platform credits the order made from that cart to the
174
+ campaign.
175
+ - **Consent is not stored by the kit.** Call `grantCampaignAttributionConsent()` on every page load
176
+ where it stands, as consent tools report a stored choice on load.
177
+ - **On withdrawal** the kept value is removed, and later carts carry none.
178
+ - A value kept before this version, without consent, is removed at the next capture and never sent.
179
+ - A site with no consent tool keeps nothing. Its orders are still credited by the platform's email
180
+ match, "Orders from recipients" in Studio.
181
+
182
+ A Nuxt theme on `@eldrajs/theme-nuxt` captures by itself and takes the consent answer from the
183
+ window ([Campaign attribution](../../docs/themes.md#campaign-attribution)).
184
+
185
+ **It stores no personal data.** It keeps those four campaign-level tags and nothing else: no click id
186
+ (`gclid`, `fbclid`), no referrer, no visitor id, nothing about the person. `utm_id` is kept as
187
+ `campaignId` only when it is a uuid, as Eldra's campaign ids are. A tag loses its control characters
188
+ and is cut to 100 characters, as the gateway does, and a tag holding an `@` is dropped, since it may be
189
+ an email address. Outside a browser nothing is held, kept or read: a server's `localStorage` (Node's,
190
+ when enabled) is shared by every visitor it serves, so the default there is no storage at all.
191
+
192
+ **Clearing it.** The kit clears it only on withdrawal. Checkout is the platform's, so a storefront
193
+ has no "order placed" moment of its own, and a second order inside the 30 days is still that
194
+ campaign's result. `clearCampaignAttribution()` forgets it, for a storefront that wants one order per
195
+ landing; `readCampaignAttribution()` returns what is kept, or `null` once it has expired or while
196
+ there is no consent.
197
+
198
+ **Options.** `captureCampaignAttribution(url, { storage, maxAgeMs })` takes any
199
+ `getItem`/`setItem`/`removeItem` storage (`null` keeps nothing) and a shorter or longer window in
200
+ milliseconds (one that is not finite keeps the 30 days). Give the consent calls and the client the
201
+ same storage, as `grantCampaignAttributionConsent({ storage })` and
202
+ `createEldraClient({ campaignAttribution: { storage } })`, or
203
+ `campaignAttribution: false` to send none. An `addItem` input that names `attribution` itself is sent
204
+ exactly as given.
205
+
206
+ **Gateway contract 5.4.0 or later.** `attribution` joins the add-items body in public contract 5.4.0;
207
+ an older gateway refuses a body that carries it (`422`), so a client against one passes
208
+ `campaignAttribution: false`. Your generated `EldraAddCartItemInput` names `attribution` once
209
+ `.eldra/web-studio/contract.ts` is regenerated against a 5.4.0 gateway; the SDK adds the field
210
+ itself, so no code changes before or after.
211
+
143
212
  ## Retrying what the gateway refused for now
144
213
 
145
214
  The gateway rate-limits a client by requests per minute, so a static build of a real catalogue —
@@ -1,3 +1,169 @@
1
+ // src/storage.ts
2
+ const DEFAULT_CART_KEY = "eldra.cartId";
3
+ const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
4
+ function browserStorage(name) {
5
+ try {
6
+ return globalThis[name] ?? null;
7
+ } catch {
8
+ return null;
9
+ }
10
+ }
11
+ function safeRead(storage, key) {
12
+ try {
13
+ return storage?.getItem(key) ?? null;
14
+ } catch {
15
+ return null;
16
+ }
17
+ }
18
+ function safeWrite(storage, key, value) {
19
+ try {
20
+ if (value === null) storage?.removeItem(key);
21
+ else storage?.setItem(key, value);
22
+ } catch {}
23
+ }
24
+ /** The cart id a browser holds between visits. Lives in localStorage so the basket survives a closed tab. */
25
+ function createCartSession(options = {}) {
26
+ const storage = options.storage === void 0 ? browserStorage("localStorage") : options.storage;
27
+ const key = options.key ?? DEFAULT_CART_KEY;
28
+ return {
29
+ read: () => safeRead(storage, key),
30
+ remember: (cartId) => safeWrite(storage, key, cartId),
31
+ forget: () => safeWrite(storage, key, null)
32
+ };
33
+ }
34
+ /**
35
+ * The one-time order access token, kept in sessionStorage rather than the return URL so it
36
+ * survives the payment provider's redirect without landing in a URL, a log or a Referer.
37
+ */
38
+ function createOrderAccessTokens(options = {}) {
39
+ const storage = options.storage === void 0 ? browserStorage("sessionStorage") : options.storage;
40
+ const prefix = options.keyPrefix ?? DEFAULT_ORDER_TOKEN_PREFIX;
41
+ return {
42
+ remember: (orderId, token) => {
43
+ if (token) safeWrite(storage, prefix + orderId, token);
44
+ },
45
+ read: (orderId) => safeRead(storage, prefix + orderId)
46
+ };
47
+ }
48
+ // src/attribution.ts
49
+ const STORAGE_KEY = "eldra.campaignAttribution";
50
+ const DEFAULT_MAX_AGE_MS = 2592e6;
51
+ const MAX_TAG_LENGTH = 100;
52
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
53
+ let consented = false;
54
+ let pending = null;
55
+ /**
56
+ * Notes the campaign tags `url` (default `location.href`) carries, replacing any earlier landing; `null` when none.
57
+ * The landing stays in memory until the visitor agrees (`grantCampaignAttributionConsent`), and is kept in storage
58
+ * only from then on.
59
+ */
60
+ function captureCampaignAttribution(url, options = {}) {
61
+ const storage = storageOf(options);
62
+ if (!consented) dropUnconsented(storage);
63
+ const params = searchParamsOf(url ?? currentHref());
64
+ if (params === null) return null;
65
+ const attribution = toAttribution({
66
+ campaignId: params.get("utm_id"),
67
+ utmSource: params.get("utm_source"),
68
+ utmMedium: params.get("utm_medium"),
69
+ utmCampaign: params.get("utm_campaign")
70
+ });
71
+ if (attribution === null) return null;
72
+ const capturedAt = Date.now();
73
+ const maxAgeMs = options.maxAgeMs ?? DEFAULT_MAX_AGE_MS;
74
+ const landing = {
75
+ ...attribution,
76
+ capturedAt,
77
+ expiresAt: capturedAt + (Number.isFinite(maxAgeMs) ? maxAgeMs : DEFAULT_MAX_AGE_MS)
78
+ };
79
+ if (storage === null) return attribution;
80
+ pending = landing;
81
+ if (consented) keep(storage, landing);
82
+ return attribution;
83
+ }
84
+ /**
85
+ * The visitor agreed, through the site's consent tool, to the campaign tags being kept: the landing noted in this
86
+ * page load is kept now, and later landings as they come. Call it on every page load where consent stands.
87
+ */
88
+ function grantCampaignAttributionConsent(options = {}) {
89
+ consented = true;
90
+ const storage = storageOf(options);
91
+ if (pending !== null && Date.now() < pending.expiresAt) keep(storage, pending);
92
+ }
93
+ /** The visitor withdrew or refused consent: the kept landing is removed and carts carry none. */
94
+ function withdrawCampaignAttributionConsent(options = {}) {
95
+ consented = false;
96
+ pending = null;
97
+ safeWrite(storageOf(options), STORAGE_KEY, null);
98
+ }
99
+ function keep(storage, landing) {
100
+ safeWrite(storage, STORAGE_KEY, JSON.stringify({
101
+ ...landing,
102
+ consented: true
103
+ }));
104
+ }
105
+ /** Removes a value kept before the kit asked for consent, so nothing kept without it outlives this release. */
106
+ function dropUnconsented(storage) {
107
+ const raw = safeRead(storage, STORAGE_KEY);
108
+ if (raw !== null && parseStored(raw)?.consented !== true) safeWrite(storage, STORAGE_KEY, null);
109
+ }
110
+ /** The kept landing while the visitor's consent stands, or `null` when there is none, it expired or no consent. */
111
+ function readCampaignAttribution(options = {}) {
112
+ if (!consented) return null;
113
+ const storage = storageOf(options);
114
+ const raw = safeRead(storage, STORAGE_KEY);
115
+ if (raw === null) return null;
116
+ const stored = parseStored(raw);
117
+ const attribution = stored !== null && stored.consented === true && typeof stored.expiresAt === "number" && Date.now() < stored.expiresAt ? toAttribution(stored) : null;
118
+ if (attribution === null) safeWrite(storage, STORAGE_KEY, null);
119
+ return attribution;
120
+ }
121
+ /** Forgets the landing, so later carts carry none until the next tagged landing; consent is unchanged. */
122
+ function clearCampaignAttribution(options = {}) {
123
+ pending = null;
124
+ safeWrite(storageOf(options), STORAGE_KEY, null);
125
+ }
126
+ function storageOf(options) {
127
+ if (options.storage !== void 0) return options.storage;
128
+ return typeof globalThis.document === "undefined" ? null : browserStorage("localStorage");
129
+ }
130
+ function currentHref() {
131
+ const href = globalThis.location?.href;
132
+ return typeof href === "string" ? href : void 0;
133
+ }
134
+ function searchParamsOf(url) {
135
+ if (url === void 0) return null;
136
+ try {
137
+ return new URL(String(url), "http://localhost").searchParams;
138
+ } catch {
139
+ return null;
140
+ }
141
+ }
142
+ function parseStored(raw) {
143
+ try {
144
+ const value = JSON.parse(raw);
145
+ return typeof value === "object" && value !== null ? value : null;
146
+ } catch {
147
+ return null;
148
+ }
149
+ }
150
+ function toAttribution(raw) {
151
+ const campaignId = tag(raw.campaignId);
152
+ const attribution = {
153
+ campaignId: campaignId !== void 0 && UUID.test(campaignId) ? campaignId.toLowerCase() : void 0,
154
+ utmSource: tag(raw.utmSource),
155
+ utmMedium: tag(raw.utmMedium),
156
+ utmCampaign: tag(raw.utmCampaign)
157
+ };
158
+ const present = Object.entries(attribution).filter(([, value]) => value !== void 0);
159
+ return present.length === 0 ? null : Object.fromEntries(present);
160
+ }
161
+ function tag(value) {
162
+ if (typeof value !== "string") return void 0;
163
+ const cleaned = value.replace(/\p{Cc}/gu, "").trim();
164
+ if (cleaned === "" || cleaned.includes("@")) return void 0;
165
+ return Array.from(cleaned).slice(0, MAX_TAG_LENGTH).join("").trim();
166
+ }
1
167
  /** Ceiling on the *computed* backoff. A `Retry-After` is honoured beyond it. */
2
168
  const DEFAULT_RETRY_MAX_DELAY_MS = 5e3;
3
169
  /**
@@ -191,8 +357,7 @@ function abortReason$1(signal) {
191
357
  if (reason !== void 0) return reason;
192
358
  return new DOMException("This operation was aborted", "AbortError");
193
359
  }
194
- //#endregion
195
- //#region src/client.ts
360
+ // src/client.ts
196
361
  const apiBaseUrlEnvKeys = [
197
362
  "ELDRA_API_BASE_URL",
198
363
  "VITE_ELDRA_API_BASE_URL",
@@ -381,12 +546,18 @@ function createEldraClient(options) {
381
546
  })
382
547
  },
383
548
  cart: {
384
- addItem: (input, context) => request({
385
- ...context,
386
- method: "POST",
387
- path: "/shopping-cart/v1/cart/items",
388
- body: input
389
- }),
549
+ addItem: (input, context) => {
550
+ const attribution = options.campaignAttribution === false || "attribution" in input ? null : readCampaignAttribution(options.campaignAttribution);
551
+ return request({
552
+ ...context,
553
+ method: "POST",
554
+ path: "/shopping-cart/v1/cart/items",
555
+ body: attribution === null ? input : {
556
+ ...input,
557
+ attribution
558
+ }
559
+ });
560
+ },
390
561
  get: (cartId, localeOptions, context) => request({
391
562
  ...context,
392
563
  path: `/shopping-cart/v1/cart/${encodeURIComponent(cartId)}`,
@@ -746,5 +917,4 @@ function appendQueryValue(searchParams, key, value) {
746
917
  function isRawBody(body) {
747
918
  return typeof body === "string" || typeof FormData !== "undefined" && body instanceof FormData || typeof URLSearchParams !== "undefined" && body instanceof URLSearchParams || typeof Blob !== "undefined" && body instanceof Blob || body instanceof ArrayBuffer;
748
919
  }
749
- //#endregion
750
- export { initEldraClient as a, getEldraClient as i, EldraHttpError as n, resolveApiBaseUrl as o, createEldraClient as r, resolveOrgId as s, DEFAULT_ELDRA_API_BASE_URL as t };
920
+ export { initEldraClient as a, captureCampaignAttribution as c, readCampaignAttribution as d, withdrawCampaignAttributionConsent as f, getEldraClient as i, clearCampaignAttribution as l, createOrderAccessTokens as m, EldraHttpError as n, resolveApiBaseUrl as o, createCartSession as p, createEldraClient as r, resolveOrgId as s, DEFAULT_ELDRA_API_BASE_URL as t, grantCampaignAttributionConsent as u };
@@ -1,4 +1,2 @@
1
- //#region src/format/date.d.ts
2
1
  /** `new Intl.DateTimeFormat(locale, options)` with the same text everywhere; the time zone defaults to UTC, Iceland's. */
3
- export declare function dateTimeFormat(locale: string, options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
4
- //#endregion
2
+ export declare function dateTimeFormat(locale: string, options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
@@ -1,6 +1,6 @@
1
- import { i as BigDecimal, r as withOurNumberFormat } from "../number-D3Vt6TOL.js";
2
- import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "../locale-DOZdbAbY.js";
3
- //#region ../../node_modules/.pnpm/@formatjs+intl-datetimeformat@7.8.1/node_modules/@formatjs/intl-datetimeformat/index.js
1
+ import { i as BigDecimal, r as withOurNumberFormat } from "../number-nkpzAc71.js";
2
+ import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "../locale-vZLrJAy8.js";
3
+ // ../../node_modules/.pnpm/@formatjs+intl-datetimeformat@7.8.1/node_modules/@formatjs/intl-datetimeformat/index.js
4
4
  const defaultContent = {
5
5
  "aa": ["aa-ET"],
6
6
  "ab": ["ab-GE"],
@@ -2751,8 +2751,7 @@ try {
2751
2751
  configurable: true
2752
2752
  });
2753
2753
  } catch {}
2754
- //#endregion
2755
- //#region src/format/data/date-en.json
2754
+ // src/format/data/date-en.json
2756
2755
  var date_en_default = {
2757
2756
  locale: "en",
2758
2757
  data: {
@@ -7960,8 +7959,7 @@ var date_en_default = {
7960
7959
  }
7961
7960
  }
7962
7961
  };
7963
- //#endregion
7964
- //#region src/format/data/date-is.json
7962
+ // src/format/data/date-is.json
7965
7963
  var date_is_default = {
7966
7964
  locale: "is",
7967
7965
  data: {
@@ -12167,8 +12165,7 @@ var date_is_default = {
12167
12165
  }
12168
12166
  }
12169
12167
  };
12170
- //#endregion
12171
- //#region src/format/date.ts
12168
+ // src/format/date.ts
12172
12169
  const UTC_ZONES = new Set([
12173
12170
  "UTC",
12174
12171
  "Etc/UTC",
@@ -12210,5 +12207,4 @@ function dateTimeFormat(locale, options = {}) {
12210
12207
  }));
12211
12208
  });
12212
12209
  }
12213
- //#endregion
12214
12210
  export { dateTimeFormat };
@@ -1,4 +1,2 @@
1
- //#region src/format/display-names.d.ts
2
1
  /** `new Intl.DisplayNames(locale, options)` with the same names everywhere: `Danmörk`. */
3
- export declare function displayNames(locale: string, options: Intl.DisplayNamesOptions): Intl.DisplayNames;
4
- //#endregion
2
+ export declare function displayNames(locale: string, options: Intl.DisplayNamesOptions): Intl.DisplayNames;
@@ -1,5 +1,5 @@
1
- import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "../locale-DOZdbAbY.js";
2
- //#region ../../node_modules/.pnpm/@formatjs+intl-displaynames@7.3.15/node_modules/@formatjs/intl-displaynames/index.js
1
+ import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "../locale-vZLrJAy8.js";
2
+ // ../../node_modules/.pnpm/@formatjs+intl-displaynames@7.3.15/node_modules/@formatjs/intl-displaynames/index.js
3
3
  const defaultContent = {
4
4
  "aa": ["aa-ET"],
5
5
  "ab": ["ab-GE"],
@@ -749,8 +749,7 @@ function getNameForTypeLanguage(languageDisplay, localeData, style, canonicalCod
749
749
  }
750
750
  } else return name;
751
751
  }
752
- //#endregion
753
- //#region src/format/data/display-names-en.json
752
+ // src/format/data/display-names-en.json
754
753
  var display_names_en_default = {
755
754
  data: {
756
755
  "patterns": { "locale": "{0} ({1})" },
@@ -3038,8 +3037,7 @@ var display_names_en_default = {
3038
3037
  },
3039
3038
  locale: "en"
3040
3039
  };
3041
- //#endregion
3042
- //#region src/format/data/display-names-is.json
3040
+ // src/format/data/display-names-is.json
3043
3041
  var display_names_is_default = {
3044
3042
  data: {
3045
3043
  "patterns": { "locale": "{0} ({1})" },
@@ -4885,8 +4883,7 @@ var display_names_is_default = {
4885
4883
  },
4886
4884
  locale: "is"
4887
4885
  };
4888
- //#endregion
4889
- //#region src/format/display-names.ts
4886
+ // src/format/display-names.ts
4890
4887
  let loaded = false;
4891
4888
  const formats = /* @__PURE__ */ new Map();
4892
4889
  /** `new Intl.DisplayNames(locale, options)` with the same names everywhere: `Danmörk`. */
@@ -4901,5 +4898,4 @@ function displayNames(locale, options) {
4901
4898
  return new DisplayNames(locale, options);
4902
4899
  });
4903
4900
  }
4904
- //#endregion
4905
4901
  export { displayNames };
@@ -1,4 +1,2 @@
1
- //#region src/format/list.d.ts
2
1
  /** `new Intl.ListFormat(locale, options)` with the same text everywhere: `a, b og c`. */
3
- export declare function listFormat(locale: string, options?: Intl.ListFormatOptions): Intl.ListFormat;
4
- //#endregion
2
+ export declare function listFormat(locale: string, options?: Intl.ListFormatOptions): Intl.ListFormat;
@@ -1,5 +1,5 @@
1
- import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "../locale-DOZdbAbY.js";
2
- //#region ../../node_modules/.pnpm/@formatjs+intl-listformat@8.3.15/node_modules/@formatjs/intl-listformat/index.js
1
+ import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "../locale-vZLrJAy8.js";
2
+ // ../../node_modules/.pnpm/@formatjs+intl-listformat@8.3.15/node_modules/@formatjs/intl-listformat/index.js
3
3
  const defaultContent = {
4
4
  "aa": ["aa-ET"],
5
5
  "ab": ["ab-GE"],
@@ -748,8 +748,7 @@ try {
748
748
  configurable: true
749
749
  });
750
750
  } catch {}
751
- //#endregion
752
- //#region src/format/data/list-en.json
751
+ // src/format/data/list-en.json
753
752
  var list_en_default = {
754
753
  data: {
755
754
  "conjunction": {
@@ -815,8 +814,7 @@ var list_en_default = {
815
814
  },
816
815
  locale: "en"
817
816
  };
818
- //#endregion
819
- //#region src/format/data/list-is.json
817
+ // src/format/data/list-is.json
820
818
  var list_is_default = {
821
819
  data: {
822
820
  "conjunction": {
@@ -882,8 +880,7 @@ var list_is_default = {
882
880
  },
883
881
  locale: "is"
884
882
  };
885
- //#endregion
886
- //#region src/format/list.ts
883
+ // src/format/list.ts
887
884
  let loaded = false;
888
885
  const formats = /* @__PURE__ */ new Map();
889
886
  /** `new Intl.ListFormat(locale, options)` with the same text everywhere: `a, b og c`. */
@@ -898,5 +895,4 @@ function listFormat(locale, options = {}) {
898
895
  return new ListFormat(locale, options);
899
896
  });
900
897
  }
901
- //#endregion
902
898
  export { listFormat };
@@ -1,4 +1,2 @@
1
- //#region src/format/relative-time.d.ts
2
1
  /** `new Intl.RelativeTimeFormat(locale, options)` with the same text everywhere: `fyrir 3 dögum`. */
3
- export declare function relativeTimeFormat(locale: string, options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat;
4
- //#endregion
2
+ export declare function relativeTimeFormat(locale: string, options?: Intl.RelativeTimeFormatOptions): Intl.RelativeTimeFormat;
@@ -1,6 +1,6 @@
1
- import { r as withOurNumberFormat } from "../number-D3Vt6TOL.js";
2
- import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "../locale-DOZdbAbY.js";
3
- //#region ../../node_modules/.pnpm/@formatjs+intl-relativetimeformat@12.3.15/node_modules/@formatjs/intl-relativetimeformat/index.js
1
+ import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "../locale-vZLrJAy8.js";
2
+ import { r as withOurNumberFormat } from "../number-nkpzAc71.js";
3
+ // ../../node_modules/.pnpm/@formatjs+intl-relativetimeformat@12.3.15/node_modules/@formatjs/intl-relativetimeformat/index.js
4
4
  const defaultContent = {
5
5
  "aa": ["aa-ET"],
6
6
  "ab": ["ab-GE"],
@@ -758,8 +758,7 @@ try {
758
758
  configurable: true
759
759
  });
760
760
  } catch {}
761
- //#endregion
762
- //#region src/format/data/relative-time-en.json
761
+ // src/format/data/relative-time-en.json
763
762
  var relative_time_en_default = {
764
763
  data: {
765
764
  "day": {
@@ -1139,8 +1138,7 @@ var relative_time_en_default = {
1139
1138
  },
1140
1139
  locale: "en"
1141
1140
  };
1142
- //#endregion
1143
- //#region src/format/data/relative-time-is.json
1141
+ // src/format/data/relative-time-is.json
1144
1142
  var relative_time_is_default = {
1145
1143
  data: {
1146
1144
  "day": {
@@ -1526,8 +1524,7 @@ var relative_time_is_default = {
1526
1524
  },
1527
1525
  locale: "is"
1528
1526
  };
1529
- //#endregion
1530
- //#region src/format/relative-time.ts
1527
+ // src/format/relative-time.ts
1531
1528
  let loaded = false;
1532
1529
  const formats = /* @__PURE__ */ new Map();
1533
1530
  /** `new Intl.RelativeTimeFormat(locale, options)` with the same text everywhere: `fyrir 3 dögum`. */
@@ -1542,5 +1539,4 @@ function relativeTimeFormat(locale, options = {}) {
1542
1539
  return withOurNumberFormat(() => new RelativeTimeFormat(locale, options));
1543
1540
  });
1544
1541
  }
1545
- //#endregion
1546
1542
  export { relativeTimeFormat };
package/dist/format.d.ts CHANGED
@@ -1,12 +1,8 @@
1
- //#region src/format/compare.d.ts
2
1
  /** Icelandic alphabetical order (`Intl.Collator('is')`), for runtimes that ship without it. */
3
2
  export declare function compareIcelandic(a: string, b: string): number;
4
3
  /** A sort comparator for `locale`: Icelandic order from {@link compareIcelandic}, any other from the runtime. */
5
4
  export declare function comparator(locale: string): (a: string, b: string) => number;
6
- //#endregion
7
- //#region src/format/number.d.ts
8
5
  /** `new Intl.NumberFormat(locale, options)` with the same text on every runtime, Chrome and Workers included. */
9
6
  export declare function numberFormat(locale: string, options?: Intl.NumberFormatOptions): Intl.NumberFormat;
10
7
  /** A price in major units, the way every Eldra surface writes it: `12.900 kr.`, `ISK 12,900`. */
11
- export declare function formatPrice(amount: number, currency: string, locale: string): string;
12
- //#endregion
8
+ export declare function formatPrice(amount: number, currency: string, locale: string): string;
package/dist/format.js CHANGED
@@ -1,5 +1,5 @@
1
- import { n as numberFormat, t as formatPrice } from "./number-D3Vt6TOL.js";
2
- //#region src/format/compare.ts
1
+ import { n as numberFormat, t as formatPrice } from "./number-nkpzAc71.js";
2
+ // src/format/compare.ts
3
3
  const PUNCTUATION = " \xA0_-–—,;:!¡?¿.…·'‘’\"“”„«»()[]{}§@*/\\&#%`^°+÷×<=>|~$£€";
4
4
  const LETTERS = "aábcdðeéfghiíjklłmnoópqrstuúvwxyýzþæöå";
5
5
  const IGNORED = /* @__PURE__ */ new Set([
@@ -68,5 +68,4 @@ function comparator(locale) {
68
68
  if ((Intl.getCanonicalLocales(locale)[0] ?? locale).split("-")[0] === "is") return compareIcelandic;
69
69
  return new Intl.Collator(locale).compare;
70
70
  }
71
- //#endregion
72
71
  export { comparator, compareIcelandic, formatPrice, numberFormat };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { $ as EldraOrganizationFeature, A as EldraFeature, At as EldraContractMethod, B as EldraFormSubmitResult, C as EldraCmsResolveEntryListResponse, Ct as EldraStockAvailabilityInput, D as EldraCollectionListOptions, Dt as EldraContract, E as EldraCollectionList, Et as RuntimeValue, F as EldraFormField, Ft as EldraContractResponse, G as EldraInventoryClient, H as EldraFormsClient, I as EldraFormFieldOption, J as EldraOrderLine, K as EldraLocaleOptions, L as EldraFormFieldType, M as EldraFeatureClient, Mt as EldraContractPaths, N as EldraFormActionKind, Nt as EldraContractProp, O as EldraCollectionProductsOptions, Ot as EldraContractBody, P as EldraFormDefinition, Pt as EldraContractQuery, Q as EldraOrganizationDetails, R as EldraFormLocalized, S as EldraCmsResolveEntryListOptions, St as EldraStockAvailability, T as EldraCollection, Tt as RuntimeEnv, U as EldraHttpClient, V as EldraFormTokenResult, W as EldraHttpRequest, X as EldraOrdersClient, Y as EldraOrderReadOptions, Z as EldraOrganizationCommerce, _ as EldraCmsEntryListEntry, _t as EldraRequestContext, a as EldraCartTotals, at as EldraPlatformConfig, b as EldraCmsGetOptions, bt as EldraSearchOptions, c as EldraCatalogListProductsOptions, ct as EldraProductList, d as EldraCheckoutUrlOptions, dt as EldraProductOption, et as EldraOrganizationLocales, f as EldraClient, ft as EldraProductOptionValue, g as EldraCmsEntryListDisplayMode, gt as EldraRecoveredBasketItem, h as EldraCmsEntryList, ht as EldraRecoveredBasket, i as EldraCartItem, it as EldraPlatformClient, j as EldraFeatureCapabilities, jt as EldraContractPath, k as EldraDiscountResult, kt as EldraContractItem, l as EldraCategory, lt as EldraProductListItem, m as EldraCmsClient, mt as EldraProductVariant, n as EldraCart, nt as EldraPageMeta, o as EldraCatalogClient, ot as EldraPlatformReadOptions, p as EldraClientOptions, pt as EldraProductThumbnail, q as EldraOrder, r as EldraCartClient, rt as EldraPaginated, s as EldraCatalogGetProductOptions, st as EldraProductDetails, t as EldraAddCartItemInput, tt as EldraOrganizationOptions, u as EldraCheckoutClient, ut as EldraProductMediaLink, v as EldraCmsEntryListFilterCriterion, vt as EldraRequestOptions, w as EldraCmsResolvedEntryList, wt as EldraStockAvailabilityItem, x as EldraCmsListOptions, xt as EldraSearchResponse, y as EldraCmsGetEntryByUniqueFieldOptions, yt as EldraRetryOptions, z as EldraFormSubmitInput } from "./types-BAYHYEat.js";
2
- //#region src/client.d.ts
1
+ import { $ as EldraOrganizationFeature, A as EldraFeature, At as EldraContractMethod, B as EldraFormSubmitResult, Bt as grantCampaignAttributionConsent, C as EldraCmsResolveEntryListResponse, Ct as EldraStockAvailabilityInput, D as EldraCollectionListOptions, Dt as EldraContract, E as EldraCollectionList, Et as RuntimeValue, F as EldraFormField, Ft as EldraContractResponse, G as EldraInventoryClient, Gt as EldraKeyValueStorage, H as EldraFormsClient, Ht as withdrawCampaignAttributionConsent, I as EldraFormFieldOption, It as EldraCampaignAttribution, J as EldraOrderLine, Jt as createCartSession, K as EldraLocaleOptions, Kt as EldraOrderAccessTokenOptions, L as EldraFormFieldType, Lt as EldraCampaignAttributionOptions, M as EldraFeatureClient, Mt as EldraContractPaths, N as EldraFormActionKind, Nt as EldraContractProp, O as EldraCollectionProductsOptions, Ot as EldraContractBody, P as EldraFormDefinition, Pt as EldraContractQuery, Q as EldraOrganizationDetails, R as EldraFormLocalized, Rt as captureCampaignAttribution, S as EldraCmsResolveEntryListOptions, St as EldraStockAvailability, T as EldraCollection, Tt as RuntimeEnv, U as EldraHttpClient, Ut as EldraCartSession, V as EldraFormTokenResult, Vt as readCampaignAttribution, W as EldraHttpRequest, Wt as EldraCartSessionOptions, X as EldraOrdersClient, Y as EldraOrderReadOptions, Yt as createOrderAccessTokens, Z as EldraOrganizationCommerce, _ as EldraCmsEntryListEntry, _t as EldraRequestContext, a as EldraCartTotals, at as EldraPlatformConfig, b as EldraCmsGetOptions, bt as EldraSearchOptions, c as EldraCatalogListProductsOptions, ct as EldraProductList, d as EldraCheckoutUrlOptions, dt as EldraProductOption, et as EldraOrganizationLocales, f as EldraClient, ft as EldraProductOptionValue, g as EldraCmsEntryListDisplayMode, gt as EldraRecoveredBasketItem, h as EldraCmsEntryList, ht as EldraRecoveredBasket, i as EldraCartItem, it as EldraPlatformClient, j as EldraFeatureCapabilities, jt as EldraContractPath, k as EldraDiscountResult, kt as EldraContractItem, l as EldraCategory, lt as EldraProductListItem, m as EldraCmsClient, mt as EldraProductVariant, n as EldraCart, nt as EldraPageMeta, o as EldraCatalogClient, ot as EldraPlatformReadOptions, p as EldraClientOptions, pt as EldraProductThumbnail, q as EldraOrder, qt as EldraOrderAccessTokens, r as EldraCartClient, rt as EldraPaginated, s as EldraCatalogGetProductOptions, st as EldraProductDetails, t as EldraAddCartItemInput, tt as EldraOrganizationOptions, u as EldraCheckoutClient, ut as EldraProductMediaLink, v as EldraCmsEntryListFilterCriterion, vt as EldraRequestOptions, w as EldraCmsResolvedEntryList, wt as EldraStockAvailabilityItem, x as EldraCmsListOptions, xt as EldraSearchResponse, y as EldraCmsGetEntryByUniqueFieldOptions, yt as EldraRetryOptions, z as EldraFormSubmitInput, zt as clearCampaignAttribution } from "./types-CiA-DRIp.js";
3
2
  export declare const DEFAULT_ELDRA_API_BASE_URL = "https://web.eldra.app/api";
4
3
  export declare class EldraHttpError extends Error {
5
4
  readonly status: number;
@@ -21,39 +20,6 @@ export declare class EldraHttpError extends Error {
21
20
  export declare function initEldraClient(options: EldraClientOptions): EldraClient;
22
21
  export declare function getEldraClient(): EldraClient;
23
22
  export declare function createEldraClient(options: EldraClientOptions): EldraClient;
24
- //#endregion
25
- //#region src/storage.d.ts
26
- interface EldraKeyValueStorage {
27
- getItem(key: string): string | null;
28
- setItem(key: string, value: string): void;
29
- removeItem(key: string): void;
30
- }
31
- interface EldraCartSession {
32
- read(): string | null;
33
- remember(cartId: string): void;
34
- forget(): void;
35
- }
36
- interface EldraOrderAccessTokens {
37
- remember(orderId: string, token: string | undefined): void;
38
- read(orderId: string): string | null;
39
- }
40
- interface EldraCartSessionOptions {
41
- storage?: EldraKeyValueStorage | null;
42
- key?: string;
43
- }
44
- interface EldraOrderAccessTokenOptions {
45
- storage?: EldraKeyValueStorage | null;
46
- keyPrefix?: string;
47
- }
48
- /** The cart id a browser holds between visits. Lives in localStorage so the basket survives a closed tab. */
49
- export declare function createCartSession(options?: EldraCartSessionOptions): EldraCartSession;
50
- /**
51
- * The one-time order access token, kept in sessionStorage rather than the return URL so it
52
- * survives the payment provider's redirect without landing in a URL, a log or a Referer.
53
- */
54
- export declare function createOrderAccessTokens(options?: EldraOrderAccessTokenOptions): EldraOrderAccessTokens;
55
- //#endregion
56
- //#region src/tracker.d.ts
57
23
  interface EldraTrackerScriptOptions extends Pick<EldraClientOptions, 'apiBaseUrl' | 'orgId' | 'env'> {
58
24
  /** Origin that receives events when the script is served through a first-party proxy. */
59
25
  eventOrigin?: string;
@@ -73,8 +39,6 @@ interface EldraTrackerScript {
73
39
  * in builds that should not report at all.
74
40
  */
75
41
  export declare function analyticsTrackerScript(options?: EldraTrackerScriptOptions): EldraTrackerScript | undefined;
76
- //#endregion
77
- //#region src/image.d.ts
78
42
  /** A size the media host serves by path suffix; `original` is the uploaded file, untransformed. */
79
43
  type EldraImageVariant = 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'original';
80
44
  /** The variants the media host resizes, narrowest first. */
@@ -150,5 +114,4 @@ interface EldraResponsiveImage {
150
114
  * as `src` and no `srcset`. Returns `undefined` when there is no URL to render.
151
115
  */
152
116
  export declare function responsiveImage(source: EldraImageSource, options: EldraResponsiveImageOptions): EldraResponsiveImage | undefined;
153
- //#endregion
154
- export type { EldraAddCartItemInput, EldraCart, EldraCartClient, EldraCartItem, EldraCartSession, EldraCartSessionOptions, EldraCartTotals, EldraCatalogClient, EldraCatalogGetProductOptions, EldraCatalogListProductsOptions, EldraCategory, EldraCheckoutClient, EldraCheckoutUrlOptions, EldraClient, EldraClientOptions, EldraCmsClient, EldraCmsEntryList, EldraCmsEntryListDisplayMode, EldraCmsEntryListEntry, EldraCmsEntryListFilterCriterion, EldraCmsGetEntryByUniqueFieldOptions, EldraCmsGetOptions, EldraCmsListOptions, EldraCmsResolveEntryListOptions, EldraCmsResolveEntryListResponse, EldraCmsResolvedEntryList, EldraCollection, EldraCollectionList, EldraCollectionListOptions, EldraCollectionProductsOptions, EldraContract, EldraContractBody, EldraContractItem, EldraContractMethod, EldraContractPath, EldraContractPaths, EldraContractProp, EldraContractQuery, EldraContractResponse, EldraDiscountResult, EldraFeature, EldraFeatureCapabilities, EldraFeatureClient, EldraFormActionKind, EldraFormDefinition, EldraFormField, EldraFormFieldOption, EldraFormFieldType, EldraFormLocalized, EldraFormSubmitInput, EldraFormSubmitResult, EldraFormTokenResult, EldraFormsClient, EldraHttpClient, EldraHttpRequest, EldraImageSource, EldraImageSrcsetOptions, EldraImageVariant, EldraInventoryClient, EldraKeyValueStorage, EldraLocaleOptions, EldraOrder, EldraOrderAccessTokenOptions, EldraOrderAccessTokens, EldraOrderLine, EldraOrderReadOptions, EldraOrdersClient, EldraOrganizationCommerce, EldraOrganizationDetails, EldraOrganizationFeature, EldraOrganizationLocales, EldraOrganizationOptions, EldraPageMeta, EldraPaginated, EldraPlatformClient, EldraPlatformConfig, EldraPlatformReadOptions, EldraProductDetails, EldraProductList, EldraProductListItem, EldraProductMediaLink, EldraProductOption, EldraProductOptionValue, EldraProductThumbnail, EldraProductVariant, EldraRecoveredBasket, EldraRecoveredBasketItem, EldraRequestContext, EldraRequestOptions, EldraResponsiveImage, EldraResponsiveImageOptions, EldraRetryOptions, EldraSearchOptions, EldraSearchResponse, EldraSizedImageVariant, EldraStockAvailability, EldraStockAvailabilityInput, EldraStockAvailabilityItem, EldraTrackerScript, EldraTrackerScriptOptions, RuntimeEnv, RuntimeValue };
117
+ export { type EldraAddCartItemInput, type EldraCampaignAttribution, type EldraCampaignAttributionOptions, type EldraCart, type EldraCartClient, type EldraCartItem, type EldraCartSession, type EldraCartSessionOptions, type EldraCartTotals, type EldraCatalogClient, type EldraCatalogGetProductOptions, type EldraCatalogListProductsOptions, type EldraCategory, type EldraCheckoutClient, type EldraCheckoutUrlOptions, type EldraClient, type EldraClientOptions, type EldraCmsClient, type EldraCmsEntryList, type EldraCmsEntryListDisplayMode, type EldraCmsEntryListEntry, type EldraCmsEntryListFilterCriterion, type EldraCmsGetEntryByUniqueFieldOptions, type EldraCmsGetOptions, type EldraCmsListOptions, type EldraCmsResolveEntryListOptions, type EldraCmsResolveEntryListResponse, type EldraCmsResolvedEntryList, type EldraCollection, type EldraCollectionList, type EldraCollectionListOptions, type EldraCollectionProductsOptions, type EldraContract, type EldraContractBody, type EldraContractItem, type EldraContractMethod, type EldraContractPath, type EldraContractPaths, type EldraContractProp, type EldraContractQuery, type EldraContractResponse, type EldraDiscountResult, type EldraFeature, type EldraFeatureCapabilities, type EldraFeatureClient, type EldraFormActionKind, type EldraFormDefinition, type EldraFormField, type EldraFormFieldOption, type EldraFormFieldType, type EldraFormLocalized, type EldraFormSubmitInput, type EldraFormSubmitResult, type EldraFormTokenResult, type EldraFormsClient, type EldraHttpClient, type EldraHttpRequest, type EldraImageSource, type EldraImageSrcsetOptions, type EldraImageVariant, type EldraInventoryClient, type EldraKeyValueStorage, type EldraLocaleOptions, type EldraOrder, type EldraOrderAccessTokenOptions, type EldraOrderAccessTokens, type EldraOrderLine, type EldraOrderReadOptions, type EldraOrdersClient, type EldraOrganizationCommerce, type EldraOrganizationDetails, type EldraOrganizationFeature, type EldraOrganizationLocales, type EldraOrganizationOptions, type EldraPageMeta, type EldraPaginated, type EldraPlatformClient, type EldraPlatformConfig, type EldraPlatformReadOptions, type EldraProductDetails, type EldraProductList, type EldraProductListItem, type EldraProductMediaLink, type EldraProductOption, type EldraProductOptionValue, type EldraProductThumbnail, type EldraProductVariant, type EldraRecoveredBasket, type EldraRecoveredBasketItem, type EldraRequestContext, type EldraRequestOptions, type EldraResponsiveImage, type EldraResponsiveImageOptions, type EldraRetryOptions, type EldraSearchOptions, type EldraSearchResponse, type EldraSizedImageVariant, type EldraStockAvailability, type EldraStockAvailabilityInput, type EldraStockAvailabilityItem, type EldraTrackerScript, type EldraTrackerScriptOptions, type RuntimeEnv, type RuntimeValue, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createOrderAccessTokens, grantCampaignAttributionConsent, readCampaignAttribution, withdrawCampaignAttributionConsent };
package/dist/index.js CHANGED
@@ -1,53 +1,5 @@
1
- import { a as initEldraClient, i as getEldraClient, n as EldraHttpError, o as resolveApiBaseUrl, r as createEldraClient, s as resolveOrgId, t as DEFAULT_ELDRA_API_BASE_URL } from "./client-Cn3at4Zh.js";
2
- //#region src/storage.ts
3
- const DEFAULT_CART_KEY = "eldra.cartId";
4
- const DEFAULT_ORDER_TOKEN_PREFIX = "eldra.orderAccessToken.";
5
- function browserStorage(name) {
6
- try {
7
- return globalThis[name] ?? null;
8
- } catch {
9
- return null;
10
- }
11
- }
12
- function safeRead(storage, key) {
13
- try {
14
- return storage?.getItem(key) ?? null;
15
- } catch {
16
- return null;
17
- }
18
- }
19
- function safeWrite(storage, key, value) {
20
- try {
21
- if (value === null) storage?.removeItem(key);
22
- else storage?.setItem(key, value);
23
- } catch {}
24
- }
25
- /** The cart id a browser holds between visits. Lives in localStorage so the basket survives a closed tab. */
26
- function createCartSession(options = {}) {
27
- const storage = options.storage === void 0 ? browserStorage("localStorage") : options.storage;
28
- const key = options.key ?? DEFAULT_CART_KEY;
29
- return {
30
- read: () => safeRead(storage, key),
31
- remember: (cartId) => safeWrite(storage, key, cartId),
32
- forget: () => safeWrite(storage, key, null)
33
- };
34
- }
35
- /**
36
- * The one-time order access token, kept in sessionStorage rather than the return URL so it
37
- * survives the payment provider's redirect without landing in a URL, a log or a Referer.
38
- */
39
- function createOrderAccessTokens(options = {}) {
40
- const storage = options.storage === void 0 ? browserStorage("sessionStorage") : options.storage;
41
- const prefix = options.keyPrefix ?? DEFAULT_ORDER_TOKEN_PREFIX;
42
- return {
43
- remember: (orderId, token) => {
44
- if (token) safeWrite(storage, prefix + orderId, token);
45
- },
46
- read: (orderId) => safeRead(storage, prefix + orderId)
47
- };
48
- }
49
- //#endregion
50
- //#region src/tracker.ts
1
+ import { a as initEldraClient, c as captureCampaignAttribution, d as readCampaignAttribution, f as withdrawCampaignAttributionConsent, i as getEldraClient, l as clearCampaignAttribution, m as createOrderAccessTokens, n as EldraHttpError, o as resolveApiBaseUrl, p as createCartSession, r as createEldraClient, s as resolveOrgId, t as DEFAULT_ELDRA_API_BASE_URL, u as grantCampaignAttributionConsent } from "./client-DLMV5fcx.js";
2
+ // src/tracker.ts
51
3
  /**
52
4
  * Builds the tracker `<script>` attributes from the same configuration the client uses, so the
53
5
  * script comes from the gateway the site reads from and reports there, unless `eventOrigin` names a
@@ -66,8 +18,7 @@ function analyticsTrackerScript(options = {}) {
66
18
  if (options.eventOrigin) script["data-api"] = options.eventOrigin;
67
19
  return script;
68
20
  }
69
- //#endregion
70
- //#region src/image.ts
21
+ // src/image.ts
71
22
  /**
72
23
  * The maximum width in pixels of each resized variant. The host scales down only, so an original
73
24
  * narrower than a variant comes back at its own width.
@@ -178,5 +129,4 @@ function responsiveImage(source, options) {
178
129
  }
179
130
  return image;
180
131
  }
181
- //#endregion
182
- export { DEFAULT_ELDRA_API_BASE_URL, ELDRA_IMAGE_VARIANT_WIDTHS, EldraHttpError, analyticsTrackerScript, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, imageSrcset, imageUrl, imageVariantFor, initEldraClient, isEldraImage, responsiveImage };
132
+ export { DEFAULT_ELDRA_API_BASE_URL, ELDRA_IMAGE_VARIANT_WIDTHS, EldraHttpError, analyticsTrackerScript, captureCampaignAttribution, clearCampaignAttribution, createCartSession, createEldraClient, createOrderAccessTokens, getEldraClient, grantCampaignAttributionConsent, imageSrcset, imageUrl, imageVariantFor, initEldraClient, isEldraImage, readCampaignAttribution, responsiveImage, withdrawCampaignAttributionConsent };
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/@formatjs+fast-memoize@3.1.7/node_modules/@formatjs/fast-memoize/index.js
1
+ // ../../node_modules/.pnpm/@formatjs+fast-memoize@3.1.7/node_modules/@formatjs/fast-memoize/index.js
2
2
  function memoize(fn, options) {
3
3
  const cache = options && options.cache ? options.cache : cacheDefault;
4
4
  const serializer = options && options.serializer ? options.serializer : serializerDefault;
@@ -53,8 +53,7 @@ var ObjectWithoutPrototypeCache = class {
53
53
  const cacheDefault = { create: function create() {
54
54
  return new ObjectWithoutPrototypeCache();
55
55
  } };
56
- //#endregion
57
- //#region ../../node_modules/.pnpm/@formatjs+intl-localematcher@0.9.0/node_modules/@formatjs/intl-localematcher/index.js
56
+ // ../../node_modules/.pnpm/@formatjs+intl-localematcher@0.9.0/node_modules/@formatjs/intl-localematcher/index.js
58
57
  const data = { supplemental: { languageMatching: { "written-new": [
59
58
  { paradigmLocales: { _locales: "en en_GB es es_419 pt_BR pt_PT" } },
60
59
  { $enUS: { _value: "AS+CA+GU+MH+MP+PH+PR+UM+US+VI" } },
@@ -3985,8 +3984,7 @@ function LookupSupportedLocales(availableLocales, requestedLocales) {
3985
3984
  }
3986
3985
  return subset;
3987
3986
  }
3988
- //#endregion
3989
- //#region src/format/locale.ts
3987
+ // src/format/locale.ts
3990
3988
  const BUNDLED = /* @__PURE__ */ new Set([
3991
3989
  "is",
3992
3990
  "is-IS",
@@ -4007,5 +4005,4 @@ function cached(cache, locale, options, create) {
4007
4005
  }
4008
4006
  return value;
4009
4007
  }
4010
- //#endregion
4011
4008
  export { ResolveLocale as i, usesBundledData as n, LookupSupportedLocales as r, cached as t };
@@ -1,5 +1,5 @@
1
- import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "./locale-DOZdbAbY.js";
2
- //#region ../../node_modules/.pnpm/@formatjs+bigdecimal@0.2.7/node_modules/@formatjs/bigdecimal/index.js
1
+ import { i as ResolveLocale, n as usesBundledData, r as LookupSupportedLocales, t as cached } from "./locale-vZLrJAy8.js";
2
+ // ../../node_modules/.pnpm/@formatjs+bigdecimal@0.2.7/node_modules/@formatjs/bigdecimal/index.js
3
3
  const DIV_PRECISION = 40;
4
4
  function removeTrailingZeros(mantissa, exponent) {
5
5
  if (mantissa === 0n) return [0n, 0];
@@ -456,8 +456,7 @@ var BigDecimal = class BigDecimal {
456
456
  return BigDecimal._create(0n, 0, 1, false);
457
457
  }
458
458
  };
459
- //#endregion
460
- //#region ../../node_modules/.pnpm/@formatjs+intl-numberformat@9.4.3/node_modules/@formatjs/intl-numberformat/index.js
459
+ // ../../node_modules/.pnpm/@formatjs+intl-numberformat@9.4.3/node_modules/@formatjs/intl-numberformat/index.js
461
460
  const defaultContent = {
462
461
  "aa": ["aa-ET"],
463
462
  "ab": ["ab-GE"],
@@ -3463,8 +3462,7 @@ try {
3463
3462
  value: NumberFormat.prototype
3464
3463
  });
3465
3464
  } catch {}
3466
- //#endregion
3467
- //#region src/format/data/number-en.json
3465
+ // src/format/data/number-en.json
3468
3466
  var number_en_default = {
3469
3467
  data: {
3470
3468
  "currencies": {
@@ -6846,8 +6844,7 @@ var number_en_default = {
6846
6844
  },
6847
6845
  locale: "en"
6848
6846
  };
6849
- //#endregion
6850
- //#region src/format/data/number-is.json
6847
+ // src/format/data/number-is.json
6851
6848
  var number_is_default = {
6852
6849
  data: {
6853
6850
  "currencies": {
@@ -9547,8 +9544,7 @@ var number_is_default = {
9547
9544
  },
9548
9545
  locale: "is"
9549
9546
  };
9550
- //#endregion
9551
- //#region src/format/number.ts
9547
+ // src/format/number.ts
9552
9548
  const RuntimeNumberFormat = Intl.NumberFormat;
9553
9549
  let loaded = false;
9554
9550
  const formats = /* @__PURE__ */ new Map();
@@ -9581,5 +9577,4 @@ function formatPrice(amount, currency, locale) {
9581
9577
  currency
9582
9578
  }).format(amount);
9583
9579
  }
9584
- //#endregion
9585
9580
  export { BigDecimal as i, numberFormat as n, withOurNumberFormat as r, formatPrice as t };
@@ -1,4 +1,63 @@
1
- //#region src/contract.d.ts
1
+ interface EldraKeyValueStorage {
2
+ getItem(key: string): string | null;
3
+ setItem(key: string, value: string): void;
4
+ removeItem(key: string): void;
5
+ }
6
+ interface EldraCartSession {
7
+ read(): string | null;
8
+ remember(cartId: string): void;
9
+ forget(): void;
10
+ }
11
+ interface EldraOrderAccessTokens {
12
+ remember(orderId: string, token: string | undefined): void;
13
+ read(orderId: string): string | null;
14
+ }
15
+ interface EldraCartSessionOptions {
16
+ storage?: EldraKeyValueStorage | null;
17
+ key?: string;
18
+ }
19
+ interface EldraOrderAccessTokenOptions {
20
+ storage?: EldraKeyValueStorage | null;
21
+ keyPrefix?: string;
22
+ }
23
+ /** The cart id a browser holds between visits. Lives in localStorage so the basket survives a closed tab. */
24
+ declare function createCartSession(options?: EldraCartSessionOptions): EldraCartSession;
25
+ /**
26
+ * The one-time order access token, kept in sessionStorage rather than the return URL so it
27
+ * survives the payment provider's redirect without landing in a URL, a log or a Referer.
28
+ */
29
+ declare function createOrderAccessTokens(options?: EldraOrderAccessTokenOptions): EldraOrderAccessTokens;
30
+ /** The campaign a visit landed from: campaign-level tags only, nothing about the visitor. */
31
+ interface EldraCampaignAttribution {
32
+ /** The Eldra campaign's id: the landing URL's `utm_id`, kept only when it is a uuid. */
33
+ campaignId?: string;
34
+ utmSource?: string;
35
+ utmMedium?: string;
36
+ utmCampaign?: string;
37
+ }
38
+ interface EldraCampaignAttributionOptions {
39
+ /** Where the landing is kept. Defaults to `localStorage` in a browser and to nothing elsewhere. */
40
+ storage?: EldraKeyValueStorage | null;
41
+ /** How long a landing counts, in milliseconds from when it is captured. Defaults to 30 days, as does a value that is not finite. */
42
+ maxAgeMs?: number;
43
+ }
44
+ /**
45
+ * Notes the campaign tags `url` (default `location.href`) carries, replacing any earlier landing; `null` when none.
46
+ * The landing stays in memory until the visitor agrees (`grantCampaignAttributionConsent`), and is kept in storage
47
+ * only from then on.
48
+ */
49
+ declare function captureCampaignAttribution(url?: string | URL, options?: EldraCampaignAttributionOptions): EldraCampaignAttribution | null;
50
+ /**
51
+ * The visitor agreed, through the site's consent tool, to the campaign tags being kept: the landing noted in this
52
+ * page load is kept now, and later landings as they come. Call it on every page load where consent stands.
53
+ */
54
+ declare function grantCampaignAttributionConsent(options?: Pick<EldraCampaignAttributionOptions, 'storage'>): void;
55
+ /** The visitor withdrew or refused consent: the kept landing is removed and carts carry none. */
56
+ declare function withdrawCampaignAttributionConsent(options?: Pick<EldraCampaignAttributionOptions, 'storage'>): void;
57
+ /** The kept landing while the visitor's consent stands, or `null` when there is none, it expired or no consent. */
58
+ declare function readCampaignAttribution(options?: Pick<EldraCampaignAttributionOptions, 'storage'>): EldraCampaignAttribution | null;
59
+ /** Forgets the landing, so later carts carry none until the next tagged landing; consent is unchanged. */
60
+ declare function clearCampaignAttribution(options?: Pick<EldraCampaignAttributionOptions, 'storage'>): void;
2
61
  interface EldraContract {}
3
62
  type Paths = EldraContract extends {
4
63
  paths: infer P;
@@ -31,8 +90,6 @@ type EldraContractQuery<Path extends EldraContractPath, Method extends EldraCont
31
90
  } ? NonNullable<Query> : never : Record<string, unknown>;
32
91
  type EldraContractProp<T, K extends PropertyKey> = T extends object ? K extends keyof T ? NonNullable<T[K]> : unknown : unknown;
33
92
  type EldraContractItem<T> = NonNullable<T> extends readonly (infer Item)[] ? Item : unknown;
34
- //#endregion
35
- //#region src/types.d.ts
36
93
  type RuntimeValue<T> = T | (() => T | undefined) | undefined;
37
94
  type RuntimeEnv = Record<string, string | boolean | number | undefined>;
38
95
  interface EldraRequestContext {
@@ -94,6 +151,8 @@ interface EldraClientOptions {
94
151
  fetch?: typeof fetch;
95
152
  /** See `EldraRetryOptions`; defaults documented there. */
96
153
  retry?: EldraRetryOptions;
154
+ /** Where `cart.addItem` reads the landing it sends as `attribution`: browser `localStorage` by default, `false` for none. */
155
+ campaignAttribution?: Pick<EldraCampaignAttributionOptions, 'storage'> | false;
97
156
  }
98
157
  interface EldraPaginationOptions {
99
158
  page?: number;
@@ -488,5 +547,4 @@ interface EldraFormsClient {
488
547
  /** `POST /site/v1/forms/subscriptions/unsubscribe?token=` (a GET of the link is only a page). */
489
548
  unsubscribe(token: string, context?: EldraRequestContext): Promise<EldraFormTokenResult>;
490
549
  }
491
- //#endregion
492
- export { EldraOrganizationFeature as $, EldraFeature as A, EldraContractMethod as At, EldraFormSubmitResult as B, EldraCmsResolveEntryListResponse as C, EldraStockAvailabilityInput as Ct, EldraCollectionListOptions as D, EldraContract as Dt, EldraCollectionList as E, RuntimeValue as Et, EldraFormField as F, EldraContractResponse as Ft, EldraInventoryClient as G, EldraFormsClient as H, EldraFormFieldOption as I, EldraOrderLine as J, EldraLocaleOptions as K, EldraFormFieldType as L, EldraFeatureClient as M, EldraContractPaths as Mt, EldraFormActionKind as N, EldraContractProp as Nt, EldraCollectionProductsOptions as O, EldraContractBody as Ot, EldraFormDefinition as P, EldraContractQuery as Pt, EldraOrganizationDetails as Q, EldraFormLocalized as R, EldraCmsResolveEntryListOptions as S, EldraStockAvailability as St, EldraCollection as T, RuntimeEnv as Tt, EldraHttpClient as U, EldraFormTokenResult as V, EldraHttpRequest as W, EldraOrdersClient as X, EldraOrderReadOptions as Y, EldraOrganizationCommerce as Z, EldraCmsEntryListEntry as _, EldraRequestContext as _t, EldraCartTotals as a, EldraPlatformConfig as at, EldraCmsGetOptions as b, EldraSearchOptions as bt, EldraCatalogListProductsOptions as c, EldraProductList as ct, EldraCheckoutUrlOptions as d, EldraProductOption as dt, EldraOrganizationLocales as et, EldraClient as f, EldraProductOptionValue as ft, EldraCmsEntryListDisplayMode as g, EldraRecoveredBasketItem as gt, EldraCmsEntryList as h, EldraRecoveredBasket as ht, EldraCartItem as i, EldraPlatformClient as it, EldraFeatureCapabilities as j, EldraContractPath as jt, EldraDiscountResult as k, EldraContractItem as kt, EldraCategory as l, EldraProductListItem as lt, EldraCmsClient as m, EldraProductVariant as mt, EldraCart as n, EldraPageMeta as nt, EldraCatalogClient as o, EldraPlatformReadOptions as ot, EldraClientOptions as p, EldraProductThumbnail as pt, EldraOrder as q, EldraCartClient as r, EldraPaginated as rt, EldraCatalogGetProductOptions as s, EldraProductDetails as st, EldraAddCartItemInput as t, EldraOrganizationOptions as tt, EldraCheckoutClient as u, EldraProductMediaLink as ut, EldraCmsEntryListFilterCriterion as v, EldraRequestOptions as vt, EldraCmsResolvedEntryList as w, EldraStockAvailabilityItem as wt, EldraCmsListOptions as x, EldraSearchResponse as xt, EldraCmsGetEntryByUniqueFieldOptions as y, EldraRetryOptions as yt, EldraFormSubmitInput as z };
550
+ export { EldraOrganizationFeature as $, EldraFeature as A, EldraContractMethod as At, EldraFormSubmitResult as B, grantCampaignAttributionConsent as Bt, EldraCmsResolveEntryListResponse as C, EldraStockAvailabilityInput as Ct, EldraCollectionListOptions as D, EldraContract as Dt, EldraCollectionList as E, RuntimeValue as Et, EldraFormField as F, EldraContractResponse as Ft, EldraInventoryClient as G, EldraKeyValueStorage as Gt, EldraFormsClient as H, withdrawCampaignAttributionConsent as Ht, EldraFormFieldOption as I, EldraCampaignAttribution as It, EldraOrderLine as J, createCartSession as Jt, EldraLocaleOptions as K, EldraOrderAccessTokenOptions as Kt, EldraFormFieldType as L, EldraCampaignAttributionOptions as Lt, EldraFeatureClient as M, EldraContractPaths as Mt, EldraFormActionKind as N, EldraContractProp as Nt, EldraCollectionProductsOptions as O, EldraContractBody as Ot, EldraFormDefinition as P, EldraContractQuery as Pt, EldraOrganizationDetails as Q, EldraFormLocalized as R, captureCampaignAttribution as Rt, EldraCmsResolveEntryListOptions as S, EldraStockAvailability as St, EldraCollection as T, RuntimeEnv as Tt, EldraHttpClient as U, EldraCartSession as Ut, EldraFormTokenResult as V, readCampaignAttribution as Vt, EldraHttpRequest as W, EldraCartSessionOptions as Wt, EldraOrdersClient as X, EldraOrderReadOptions as Y, createOrderAccessTokens as Yt, EldraOrganizationCommerce as Z, EldraCmsEntryListEntry as _, EldraRequestContext as _t, EldraCartTotals as a, EldraPlatformConfig as at, EldraCmsGetOptions as b, EldraSearchOptions as bt, EldraCatalogListProductsOptions as c, EldraProductList as ct, EldraCheckoutUrlOptions as d, EldraProductOption as dt, EldraOrganizationLocales as et, EldraClient as f, EldraProductOptionValue as ft, EldraCmsEntryListDisplayMode as g, EldraRecoveredBasketItem as gt, EldraCmsEntryList as h, EldraRecoveredBasket as ht, EldraCartItem as i, EldraPlatformClient as it, EldraFeatureCapabilities as j, EldraContractPath as jt, EldraDiscountResult as k, EldraContractItem as kt, EldraCategory as l, EldraProductListItem as lt, EldraCmsClient as m, EldraProductVariant as mt, EldraCart as n, EldraPageMeta as nt, EldraCatalogClient as o, EldraPlatformReadOptions as ot, EldraClientOptions as p, EldraProductThumbnail as pt, EldraOrder as q, EldraOrderAccessTokens as qt, EldraCartClient as r, EldraPaginated as rt, EldraCatalogGetProductOptions as s, EldraProductDetails as st, EldraAddCartItemInput as t, EldraOrganizationOptions as tt, EldraCheckoutClient as u, EldraProductMediaLink as ut, EldraCmsEntryListFilterCriterion as v, EldraRequestOptions as vt, EldraCmsResolvedEntryList as w, EldraStockAvailabilityItem as wt, EldraCmsListOptions as x, EldraSearchResponse as xt, EldraCmsGetEntryByUniqueFieldOptions as y, EldraRetryOptions as yt, EldraFormSubmitInput as z, clearCampaignAttribution as zt };
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Et as RuntimeValue, Tt as RuntimeEnv } from "./types-BAYHYEat.js";
1
+ import { Et as RuntimeValue, Tt as RuntimeEnv } from "./types-CiA-DRIp.js";
2
2
  import { Plugin } from "vite";
3
- //#region src/vite-plugin.d.ts
4
3
  export interface EldraVitePluginOptions {
5
4
  apiBaseUrl?: RuntimeValue<string>;
6
5
  orgId?: RuntimeValue<string>;
@@ -36,5 +35,4 @@ export declare function generateEldraFiles(root: string, options: EldraVitePlugi
36
35
  export declare function createContractSource(document: unknown, options?: {
37
36
  sdkImport?: string;
38
37
  source?: URL | string;
39
- }): Promise<string>;
40
- //#endregion
38
+ }): Promise<string>;
package/dist/vite.js CHANGED
@@ -1,9 +1,9 @@
1
- import "./client-Cn3at4Zh.js";
1
+ import "./client-DLMV5fcx.js";
2
2
  import { access, mkdir, writeFile } from "node:fs/promises";
3
3
  import { dirname, resolve } from "node:path";
4
4
  import openapiTS, { astToString } from "openapi-typescript";
5
5
  import { loadEnv } from "vite";
6
- //#region src/vite-plugin.ts
6
+ // src/vite-plugin.ts
7
7
  const defaultOutDir = ".eldra/web-studio";
8
8
  const defaultTypesFileName = "cms-types.ts";
9
9
  const defaultContractFileName = "contract.ts";
@@ -243,5 +243,4 @@ function stripTSExtension(path) {
243
243
  function pascalTypeName(value) {
244
244
  return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
245
245
  }
246
- //#endregion
247
246
  export { createContractSource, eldra, generateEldraFiles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/sdk",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Framework-free client for the Eldra Web Studio public storefront API: CMS, catalog, cart, checkout handoff, orders, inventory. Types generated from your gateway's OpenAPI document and CMS schemas at build time.",
5
5
  "keywords": [
6
6
  "cms",