@eldrajs/sdk 0.3.2 → 0.4.1

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.
@@ -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.1",
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",
@@ -55,6 +55,10 @@
55
55
  "types": "./dist/format/display-names.d.ts",
56
56
  "import": "./dist/format/display-names.js"
57
57
  },
58
+ "./format/intl": {
59
+ "types": "./dist/format/intl.d.ts",
60
+ "import": "./dist/format/intl.js"
61
+ },
58
62
  "./package.json": "./package.json"
59
63
  },
60
64
  "publishConfig": {