@viu/emporix-sdk 1.0.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 +407 -0
- package/LICENSE +21 -0
- package/README.md +115 -0
- package/dist/cart.cjs +214 -0
- package/dist/cart.cjs.map +1 -0
- package/dist/cart.d.cts +1807 -0
- package/dist/cart.d.ts +1807 -0
- package/dist/cart.js +4 -0
- package/dist/cart.js.map +1 -0
- package/dist/category.cjs +97 -0
- package/dist/category.cjs.map +1 -0
- package/dist/category.d.cts +313 -0
- package/dist/category.d.ts +313 -0
- package/dist/category.js +4 -0
- package/dist/category.js.map +1 -0
- package/dist/checkout.cjs +98 -0
- package/dist/checkout.cjs.map +1 -0
- package/dist/checkout.d.cts +252 -0
- package/dist/checkout.d.ts +252 -0
- package/dist/checkout.js +4 -0
- package/dist/checkout.js.map +1 -0
- package/dist/chunk-4BJUCCKJ.js +86 -0
- package/dist/chunk-4BJUCCKJ.js.map +1 -0
- package/dist/chunk-6UNFMCHZ.js +95 -0
- package/dist/chunk-6UNFMCHZ.js.map +1 -0
- package/dist/chunk-B56JZNI7.js +49 -0
- package/dist/chunk-B56JZNI7.js.map +1 -0
- package/dist/chunk-BFQ732VZ.js +11 -0
- package/dist/chunk-BFQ732VZ.js.map +1 -0
- package/dist/chunk-F3WAQH2E.js +120 -0
- package/dist/chunk-F3WAQH2E.js.map +1 -0
- package/dist/chunk-GWJ2U2CP.js +14 -0
- package/dist/chunk-GWJ2U2CP.js.map +1 -0
- package/dist/chunk-HEO34WLO.js +47 -0
- package/dist/chunk-HEO34WLO.js.map +1 -0
- package/dist/chunk-HKPZI7Y5.js +30 -0
- package/dist/chunk-HKPZI7Y5.js.map +1 -0
- package/dist/chunk-IEZHGU7F.js +171 -0
- package/dist/chunk-IEZHGU7F.js.map +1 -0
- package/dist/chunk-KTODT6DV.js +86 -0
- package/dist/chunk-KTODT6DV.js.map +1 -0
- package/dist/chunk-NM7VDXBR.js +57 -0
- package/dist/chunk-NM7VDXBR.js.map +1 -0
- package/dist/chunk-OMYVOOSX.js +57 -0
- package/dist/chunk-OMYVOOSX.js.map +1 -0
- package/dist/chunk-QDABAMVN.js +89 -0
- package/dist/chunk-QDABAMVN.js.map +1 -0
- package/dist/chunk-RXVVFNYN.js +56 -0
- package/dist/chunk-RXVVFNYN.js.map +1 -0
- package/dist/chunk-SKX7KCMH.js +23 -0
- package/dist/chunk-SKX7KCMH.js.map +1 -0
- package/dist/chunk-TLH6SLAF.js +215 -0
- package/dist/chunk-TLH6SLAF.js.map +1 -0
- package/dist/chunk-Z6PNI5VT.js +142 -0
- package/dist/chunk-Z6PNI5VT.js.map +1 -0
- package/dist/companies.cjs +58 -0
- package/dist/companies.cjs.map +1 -0
- package/dist/companies.d.cts +31 -0
- package/dist/companies.d.ts +31 -0
- package/dist/companies.js +3 -0
- package/dist/companies.js.map +1 -0
- package/dist/contacts.cjs +51 -0
- package/dist/contacts.cjs.map +1 -0
- package/dist/contacts.d.cts +28 -0
- package/dist/contacts.d.ts +28 -0
- package/dist/contacts.js +3 -0
- package/dist/contacts.js.map +1 -0
- package/dist/context-vKgzZ-5f.d.cts +329 -0
- package/dist/context-vKgzZ-5f.d.ts +329 -0
- package/dist/customer-groups.cjs +25 -0
- package/dist/customer-groups.cjs.map +1 -0
- package/dist/customer-groups.d.cts +36 -0
- package/dist/customer-groups.d.ts +36 -0
- package/dist/customer-groups.js +3 -0
- package/dist/customer-groups.js.map +1 -0
- package/dist/customer.cjs +262 -0
- package/dist/customer.cjs.map +1 -0
- package/dist/customer.d.cts +386 -0
- package/dist/customer.d.ts +386 -0
- package/dist/customer.js +5 -0
- package/dist/customer.js.map +1 -0
- package/dist/index.cjs +2075 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +218 -0
- package/dist/index.d.ts +218 -0
- package/dist/index.js +791 -0
- package/dist/index.js.map +1 -0
- package/dist/locations.cjs +59 -0
- package/dist/locations.cjs.map +1 -0
- package/dist/locations.d.cts +30 -0
- package/dist/locations.d.ts +30 -0
- package/dist/locations.js +3 -0
- package/dist/locations.js.map +1 -0
- package/dist/media.cjs +123 -0
- package/dist/media.cjs.map +1 -0
- package/dist/media.d.cts +219 -0
- package/dist/media.d.ts +219 -0
- package/dist/media.js +3 -0
- package/dist/media.js.map +1 -0
- package/dist/orders.cjs +98 -0
- package/dist/orders.cjs.map +1 -0
- package/dist/orders.d.cts +167 -0
- package/dist/orders.d.ts +167 -0
- package/dist/orders.js +3 -0
- package/dist/orders.js.map +1 -0
- package/dist/payment.cjs +77 -0
- package/dist/payment.cjs.map +1 -0
- package/dist/payment.d.cts +110 -0
- package/dist/payment.d.ts +110 -0
- package/dist/payment.js +5 -0
- package/dist/payment.js.map +1 -0
- package/dist/price.cjs +88 -0
- package/dist/price.cjs.map +1 -0
- package/dist/price.d.cts +445 -0
- package/dist/price.d.ts +445 -0
- package/dist/price.js +4 -0
- package/dist/price.js.map +1 -0
- package/dist/product.cjs +100 -0
- package/dist/product.cjs.map +1 -0
- package/dist/product.d.cts +400 -0
- package/dist/product.d.ts +400 -0
- package/dist/product.js +4 -0
- package/dist/product.js.map +1 -0
- package/dist/segment.cjs +189 -0
- package/dist/segment.cjs.map +1 -0
- package/dist/segment.d.cts +241 -0
- package/dist/segment.d.ts +241 -0
- package/dist/segment.js +5 -0
- package/dist/segment.js.map +1 -0
- package/dist/types.gen-D1QuqPLs.d.cts +166 -0
- package/dist/types.gen-D1QuqPLs.d.ts +166 -0
- package/package.json +141 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/media.ts"],"names":[],"mappings":";AAkBA,IAAM,OAAA,GAAuB,EAAE,IAAA,EAAM,SAAA,EAAU;AAE/C,SAAS,YAAA,CAAa,GAAe,SAAA,EAA4B;AAC/D,EAAA,OAAO,CAAA,CAAE,IAAA,KAAS,SAAA,IAAa,CAAA,CAAE,EAAA,KAAO,SAAA;AAC1C;AAMO,IAAM,eAAN,MAA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A,EAAG,OAAO,CAAA;AAC3D,IAAA,MAAM,IAAA,GAAqB,CAAC,GAAG,MAAA,EAAQ,EAAE,IAAA,EAAM,SAAA,EAAW,EAAA,EAAI,SAAA,EAAW,CAAA;AAGzE,IAAA,MAAM,QAAQ,EAAE,IAAA,EAAM,CAAA,CAAE,IAAA,EAAM,QAAQ,IAAA,EAAK;AAC3C,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,OAAA,EAAS,KAAA,EAAO,IAAI,CAAA;AAAA,EACzC;AAAA;AAAA,EAGA,MAAM,iBAAA,CACJ,OAAA,EACA,SAAA,EACA,OAAoB,OAAA,EACJ;AAChB,IAAA,MAAM,CAAA,GAAI,MAAM,IAAA,CAAK,GAAA,CAAI,SAAS,IAAI,CAAA;AACtC,IAAA,MAAM,MAAA,GAAuB,CAAA,CAAE,MAAA,IAAU,EAAC;AAC1C,IAAA,MAAM,IAAA,GAAO,OAAO,MAAA,CAAO,CAAC,MAAM,CAAC,YAAA,CAAa,CAAA,EAAG,SAAS,CAAC,CAAA;AAC7D,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,MAAA,CAAO,MAAA,EAAQ,OAAO,CAAA;AAC1C,IAAA,MAAM,QAAQ,EAAE,IAAA,EAAM,CAAA,CAAE,IAAA,EAAM,QAAQ,IAAA,EAAK;AAC3C,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,OAAA,EAAS,KAAA,EAAO,IAAI,CAAA;AAAA,EACzC;AAAA;AAAA,EAGA,MAAM,cAAA,CAAe,SAAA,EAAmB,IAAA,GAAoB,OAAA,EAA2B;AACrF,IAAA,OAAO,KAAK,IAAA,CAAK,EAAE,WAAA,EAAa,SAAA,IAAa,IAAI,CAAA;AAAA,EACnD;AACF;AAIO,IAAM,cAAA,GAAiB,EAAE,YAAA","file":"chunk-F3WAQH2E.js","sourcesContent":["import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport type {\n AssetCreateBlob,\n AssetCreateLink,\n AssetUpdateBlob,\n AssetUpdateLink,\n GetAsset,\n RefId,\n} from \"../generated/media\";\n\n/** Generated media types (caller sends the exact wire shape). */\nexport type AssetCreateBlobInput = AssetCreateBlob;\nexport type AssetCreateLinkInput = AssetCreateLink;\nexport type AssetUpdateInput = AssetUpdateBlob | AssetUpdateLink;\nexport type Asset = GetAsset;\nexport type AssetRefId = RefId;\n\nconst SERVICE: AuthContext = { kind: \"service\" };\n\nfunction isProductRef(r: AssetRefId, productId: string): boolean {\n return r.type === \"PRODUCT\" && r.id === productId;\n}\n\n/**\n * Media assets (BLOB/LINK). All endpoints require a backend-only scope\n * (`media.asset_manage` / `media.asset_read`) — default auth: service.\n */\nexport class MediaService {\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/media/${this.ctx.tenant}/assets`;\n }\n\n /** Create an asset. BLOB uploads via multipart; LINK via JSON. */\n async create(\n input:\n | { kind: \"blob\"; file: Blob; body: AssetCreateBlobInput }\n | { kind: \"link\"; body: AssetCreateLinkInput },\n auth: AuthContext = SERVICE,\n ): Promise<{ id: string }> {\n if (input.kind === \"blob\") {\n const fd = new FormData();\n fd.set(\"file\", input.file);\n fd.set(\"body\", JSON.stringify(input.body));\n return this.ctx.http.request<{ id: string }>({\n method: \"POST\",\n path: this.base(),\n auth,\n body: fd,\n });\n }\n return this.ctx.http.request<{ id: string }>({\n method: \"POST\",\n path: this.base(),\n auth,\n body: input.body,\n });\n }\n\n /** List assets. Optional `query` is passed through to Emporix verbatim. */\n async list(\n query?: Record<string, string | number | undefined>,\n auth: AuthContext = SERVICE,\n ): Promise<Asset[]> {\n return this.ctx.http.request<Asset[]>({\n method: \"GET\",\n path: this.base(),\n auth,\n ...(query ? { query } : {}),\n });\n }\n\n /** Fetch an asset by id. */\n async get(assetId: string, auth: AuthContext = SERVICE): Promise<Asset> {\n return this.ctx.http.request<Asset>({\n method: \"GET\",\n path: `${this.base()}/${assetId}`,\n auth,\n });\n }\n\n /** Update an asset (e.g. swap `refIds` or `access`). */\n async update(\n assetId: string,\n patch: AssetUpdateInput,\n auth: AuthContext = SERVICE,\n ): Promise<Asset> {\n return this.ctx.http.request<Asset>({\n method: \"PUT\",\n path: `${this.base()}/${assetId}`,\n auth,\n body: patch,\n });\n }\n\n /** Remove an asset. */\n async remove(assetId: string, auth: AuthContext = SERVICE): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `${this.base()}/${assetId}`,\n auth,\n });\n }\n\n /** Multipart upload sugar: builds `AssetCreateBlob` from input. */\n async uploadFile(\n input: {\n file: Blob;\n productId?: string;\n filename?: string;\n mimeType?: string;\n access?: \"PUBLIC\" | \"PRIVATE\";\n },\n auth: AuthContext = SERVICE,\n ): Promise<{ id: string }> {\n const body: AssetCreateBlobInput = {\n type: \"BLOB\",\n access: input.access ?? \"PUBLIC\",\n ...(input.productId\n ? { refIds: [{ type: \"PRODUCT\", id: input.productId }] }\n : {}),\n ...(input.filename || input.mimeType\n ? {\n details: {\n ...(input.filename ? { filename: input.filename } : {}),\n ...(input.mimeType ? { mimeType: input.mimeType } : {}),\n },\n }\n : {}),\n };\n return this.create({ kind: \"blob\", file: input.file, body }, auth);\n }\n\n /** External-URL sugar: builds `AssetCreateLink`. */\n async link(\n input: { url: string; productId?: string; access?: \"PUBLIC\" | \"PRIVATE\" },\n auth: AuthContext = SERVICE,\n ): Promise<{ id: string }> {\n const body: AssetCreateLinkInput = {\n type: \"LINK\",\n access: input.access ?? \"PUBLIC\",\n url: input.url,\n ...(input.productId\n ? { refIds: [{ type: \"PRODUCT\", id: input.productId }] }\n : {}),\n };\n return this.create({ kind: \"link\", body }, auth);\n }\n\n /** Idempotently add a PRODUCT refId to an asset. */\n async attachToProduct(\n assetId: string,\n productId: string,\n auth: AuthContext = SERVICE,\n ): Promise<Asset> {\n const a = await this.get(assetId, auth);\n const refIds: AssetRefId[] = a.refIds ?? [];\n if (refIds.some((r) => isProductRef(r, productId))) return a;\n const next: AssetRefId[] = [...refIds, { type: \"PRODUCT\", id: productId }];\n // Preserve the asset's type discriminator so the update body satisfies\n // the AssetUpdateBlob | AssetUpdateLink union.\n const patch = { type: a.type, refIds: next } as unknown as AssetUpdateInput;\n return this.update(assetId, patch, auth);\n }\n\n /** Remove a PRODUCT refId from an asset (no-op if absent). */\n async detachFromProduct(\n assetId: string,\n productId: string,\n auth: AuthContext = SERVICE,\n ): Promise<Asset> {\n const a = await this.get(assetId, auth);\n const refIds: AssetRefId[] = a.refIds ?? [];\n const next = refIds.filter((r) => !isProductRef(r, productId));\n if (next.length === refIds.length) return a;\n const patch = { type: a.type, refIds: next } as unknown as AssetUpdateInput;\n return this.update(assetId, patch, auth);\n }\n\n /** Convenience: list assets attached to a product (server-side filter). */\n async listForProduct(productId: string, auth: AuthContext = SERVICE): Promise<Asset[]> {\n return this.list({ \"refIds.id\": productId }, auth);\n }\n}\n\n// Re-export so consumers can `import { isProductRef } from \"@viu/emporix-sdk/media\"`?\n// Internal helper — kept module-private; convenience methods in Task 4 use it.\nexport const _internalMedia = { isProductRef };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/core/context.ts
|
|
2
|
+
async function* iterateAll(fetchPage, start = 1) {
|
|
3
|
+
let p = start;
|
|
4
|
+
for (; ; ) {
|
|
5
|
+
const page = await fetchPage(p);
|
|
6
|
+
for (const it of page.items) yield it;
|
|
7
|
+
if (!page.hasNextPage) return;
|
|
8
|
+
p += 1;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { iterateAll };
|
|
13
|
+
//# sourceMappingURL=chunk-GWJ2U2CP.js.map
|
|
14
|
+
//# sourceMappingURL=chunk-GWJ2U2CP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/context.ts"],"names":[],"mappings":";AAkCA,gBAAuB,UAAA,CACrB,SAAA,EACA,KAAA,GAAQ,CAAA,EACU;AAClB,EAAA,IAAI,CAAA,GAAI,KAAA;AACR,EAAA,WAAS;AACP,IAAA,MAAM,IAAA,GAAO,MAAM,SAAA,CAAU,CAAC,CAAA;AAC9B,IAAA,KAAA,MAAW,EAAA,IAAM,IAAA,CAAK,KAAA,EAAO,MAAM,EAAA;AACnC,IAAA,IAAI,CAAC,KAAK,WAAA,EAAa;AACvB,IAAA,CAAA,IAAK,CAAA;AAAA,EACP;AACF","file":"chunk-GWJ2U2CP.js","sourcesContent":["import type { HttpClient } from \"./http\";\nimport type { TokenProvider, AuthContext } from \"./auth\";\nimport type { Logger } from \"./logger\";\n\n/** Shared dependencies every service facade receives. */\nexport interface ClientContext {\n tenant: string;\n http: HttpClient;\n tokenProvider: TokenProvider;\n logger: Logger;\n}\n\n/**\n * A cursor-paged collection — `pageNumber`/`pageSize` indexing with a\n * `hasNextPage` signal driven by the source page being full. Used by all\n * paginated services and hooks across the SDK.\n */\nexport interface PaginatedItems<T> {\n items: T[];\n pageNumber: number;\n pageSize: number;\n hasNextPage: boolean;\n}\n\n/** Default `AuthContext` applied by a service when the caller passes none. */\nexport type DefaultAuth = AuthContext | undefined;\n\n/**\n * Async-iterates every item across pages of a `PaginatedItems<T>` source.\n * Stops when the source reports `hasNextPage: false`.\n *\n * @param fetchPage - given a 1-based page number, returns the page.\n * @param start - first page to fetch (default `1`).\n */\nexport async function* iterateAll<T>(\n fetchPage: (pageNumber: number) => Promise<PaginatedItems<T>>,\n start = 1,\n): AsyncIterable<T> {\n let p = start;\n for (;;) {\n const page = await fetchPage(p);\n for (const it of page.items) yield it;\n if (!page.hasNextPage) return;\n p += 1;\n }\n}\n\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EmporixAuthError } from './chunk-KTODT6DV.js';
|
|
2
|
+
|
|
3
|
+
// src/services/price.ts
|
|
4
|
+
var ANON = { kind: "anonymous" };
|
|
5
|
+
var SERVICE = { kind: "service" };
|
|
6
|
+
function requireContextAuth(auth) {
|
|
7
|
+
const a = auth ?? ANON;
|
|
8
|
+
if (a.kind === "anonymous" || a.kind === "customer" || a.kind === "raw") return a;
|
|
9
|
+
throw new EmporixAuthError(
|
|
10
|
+
"match-prices-by-context requires an anonymous, customer, or raw AuthContext"
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
var PriceService = class {
|
|
14
|
+
constructor(ctx) {
|
|
15
|
+
this.ctx = ctx;
|
|
16
|
+
}
|
|
17
|
+
ctx;
|
|
18
|
+
/**
|
|
19
|
+
* Resolves prices using the session context bound to the bearer token
|
|
20
|
+
* (currency/site/country were set at anonymous-login time). Default auth:
|
|
21
|
+
* anonymous; pass a customer/raw context for personalized pricing.
|
|
22
|
+
*/
|
|
23
|
+
async matchByContext(input, auth) {
|
|
24
|
+
return this.ctx.http.request({
|
|
25
|
+
method: "POST",
|
|
26
|
+
path: `/price/${this.ctx.tenant}/match-prices-by-context`,
|
|
27
|
+
auth: requireContextAuth(auth),
|
|
28
|
+
body: input
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolves prices from an explicit context. Default auth: service
|
|
33
|
+
* (requires `price.price_read` / `price.price_manage`).
|
|
34
|
+
*/
|
|
35
|
+
async match(input, auth = SERVICE) {
|
|
36
|
+
return this.ctx.http.request({
|
|
37
|
+
method: "POST",
|
|
38
|
+
path: `/price/${this.ctx.tenant}/match-prices`,
|
|
39
|
+
auth,
|
|
40
|
+
body: input
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { PriceService };
|
|
46
|
+
//# sourceMappingURL=chunk-HEO34WLO.js.map
|
|
47
|
+
//# sourceMappingURL=chunk-HEO34WLO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/price.ts"],"names":[],"mappings":";;;AAcA,IAAM,IAAA,GAAoB,EAAE,IAAA,EAAM,WAAA,EAAY;AAC9C,IAAM,OAAA,GAAuB,EAAE,IAAA,EAAM,SAAA,EAAU;AAE/C,SAAS,mBAAmB,IAAA,EAA4C;AACtE,EAAA,MAAM,IAAI,IAAA,IAAQ,IAAA;AAClB,EAAA,IAAI,CAAA,CAAE,SAAS,WAAA,IAAe,CAAA,CAAE,SAAS,UAAA,IAAc,CAAA,CAAE,IAAA,KAAS,KAAA,EAAO,OAAO,CAAA;AAChF,EAAA,MAAM,IAAI,gBAAA;AAAA,IACR;AAAA,GACF;AACF;AAOO,IAAM,eAAN,MAAmB;AAAA,EACxB,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7B,MAAM,cAAA,CACJ,KAAA,EACA,IAAA,EACuB;AACvB,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAsB;AAAA,MACzC,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,CAAA,OAAA,EAAU,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,wBAAA,CAAA;AAAA,MAC/B,IAAA,EAAM,mBAAmB,IAAI,CAAA;AAAA,MAC7B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,KAAA,CAAM,KAAA,EAAwB,IAAA,GAAoB,OAAA,EAAgC;AACtF,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAsB;AAAA,MACzC,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,CAAA,OAAA,EAAU,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,aAAA,CAAA;AAAA,MAC/B,IAAA;AAAA,MACA,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"chunk-HEO34WLO.js","sourcesContent":["import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixAuthError } from \"../core/errors\";\nimport type { Match, MatchByContext, MatchResponse } from \"../generated/price\";\n\n/** Session-context match request body (generated). */\nexport type PriceMatchByContextInput = MatchByContext;\n\n/** Explicit-context match request body (generated). */\nexport type PriceMatchInput = Match;\n\n/** A resolved price (full generated match-response schema). */\nexport type PriceMatch = MatchResponse;\n\nconst ANON: AuthContext = { kind: \"anonymous\" };\nconst SERVICE: AuthContext = { kind: \"service\" };\n\nfunction requireContextAuth(auth: AuthContext | undefined): AuthContext {\n const a = auth ?? ANON;\n if (a.kind === \"anonymous\" || a.kind === \"customer\" || a.kind === \"raw\") return a;\n throw new EmporixAuthError(\n \"match-prices-by-context requires an anonymous, customer, or raw AuthContext\",\n );\n}\n\n/**\n * Price matching. The Cart service does not resolve prices — call this\n * explicitly before rendering money and again right before placing an order.\n * The SDK is stateless: it never caches or revalidates prices.\n */\nexport class PriceService {\n constructor(private readonly ctx: ClientContext) {}\n\n /**\n * Resolves prices using the session context bound to the bearer token\n * (currency/site/country were set at anonymous-login time). Default auth:\n * anonymous; pass a customer/raw context for personalized pricing.\n */\n async matchByContext(\n input: PriceMatchByContextInput,\n auth?: AuthContext,\n ): Promise<PriceMatch[]> {\n return this.ctx.http.request<PriceMatch[]>({\n method: \"POST\",\n path: `/price/${this.ctx.tenant}/match-prices-by-context`,\n auth: requireContextAuth(auth),\n body: input,\n });\n }\n\n /**\n * Resolves prices from an explicit context. Default auth: service\n * (requires `price.price_read` / `price.price_manage`).\n */\n async match(input: PriceMatchInput, auth: AuthContext = SERVICE): Promise<PriceMatch[]> {\n return this.ctx.http.request<PriceMatch[]>({\n method: \"POST\",\n path: `/price/${this.ctx.tenant}/match-prices`,\n auth,\n body: input,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { requireCustomer } from './chunk-BFQ732VZ.js';
|
|
2
|
+
|
|
3
|
+
// src/services/payment.ts
|
|
4
|
+
var PaymentGatewayService = class {
|
|
5
|
+
constructor(ctx) {
|
|
6
|
+
this.ctx = ctx;
|
|
7
|
+
}
|
|
8
|
+
ctx;
|
|
9
|
+
/** Lists configured frontend payment modes. */
|
|
10
|
+
async listPaymentModes(auth) {
|
|
11
|
+
return this.ctx.http.request({
|
|
12
|
+
method: "GET",
|
|
13
|
+
path: `/payment-gateway/${this.ctx.tenant}/paymentmodes/frontend`,
|
|
14
|
+
auth: requireCustomer(auth)
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/** Authorizes a post-checkout (deferred) payment for an existing order. */
|
|
18
|
+
async authorize(input, auth) {
|
|
19
|
+
return this.ctx.http.request({
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: `/payment-gateway/${this.ctx.tenant}/payment/frontend/authorize`,
|
|
22
|
+
auth: requireCustomer(auth),
|
|
23
|
+
body: input
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { PaymentGatewayService };
|
|
29
|
+
//# sourceMappingURL=chunk-HKPZI7Y5.js.map
|
|
30
|
+
//# sourceMappingURL=chunk-HKPZI7Y5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/payment.ts"],"names":[],"mappings":";;;AA2BO,IAAM,wBAAN,MAA4B;AAAA,EACjC,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA;AAAA,EAG7B,MAAM,iBAAiB,IAAA,EAA4C;AACjE,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAuB;AAAA,MAC1C,MAAA,EAAQ,KAAA;AAAA,MACR,IAAA,EAAM,CAAA,iBAAA,EAAoB,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,sBAAA,CAAA;AAAA,MACzC,IAAA,EAAM,gBAAgB,IAAI;AAAA,KAC3B,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,SAAA,CACJ,KAAA,EACA,IAAA,EACiC;AACjC,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAgC;AAAA,MACnD,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,CAAA,iBAAA,EAAoB,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,2BAAA,CAAA;AAAA,MACzC,IAAA,EAAM,gBAAgB,IAAI,CAAA;AAAA,MAC1B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"chunk-HKPZI7Y5.js","sourcesContent":["import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixAuthError } from \"../core/errors\";\nimport { requireCustomer } from \"../core/require-customer\";\nimport type {\n PaymentModeFrontendResponse,\n AuthorizePaymentRequest,\n} from \"../generated/payment\";\n\n/** A frontend payment mode (generated). */\nexport type PaymentMode = PaymentModeFrontendResponse;\n\n/** Post-checkout authorize request (generated; caller sends the exact wire shape). */\nexport type AuthorizePaymentInput = AuthorizePaymentRequest;\n\n/** Post-checkout authorize result. */\nexport interface AuthorizePaymentResult {\n successful: boolean;\n paymentTransactionId?: string;\n authorizationToken?: string;\n requiresExternalPayment?: boolean;\n externalPaymentRedirectURL?: string;\n externalPaymentHttpMethod?: string;\n [k: string]: unknown;\n}\n\n/** Payment-Gateway: list frontend payment modes, authorize deferred payments. */\nexport class PaymentGatewayService {\n constructor(private readonly ctx: ClientContext) {}\n\n /** Lists configured frontend payment modes. */\n async listPaymentModes(auth?: AuthContext): Promise<PaymentMode[]> {\n return this.ctx.http.request<PaymentMode[]>({\n method: \"GET\",\n path: `/payment-gateway/${this.ctx.tenant}/paymentmodes/frontend`,\n auth: requireCustomer(auth),\n });\n }\n\n /** Authorizes a post-checkout (deferred) payment for an existing order. */\n async authorize(\n input: AuthorizePaymentInput,\n auth?: AuthContext,\n ): Promise<AuthorizePaymentResult> {\n return this.ctx.http.request<AuthorizePaymentResult>({\n method: \"POST\",\n path: `/payment-gateway/${this.ctx.tenant}/payment/frontend/authorize`,\n auth: requireCustomer(auth),\n body: input,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { EmporixNotFoundError, EmporixValidationError } from './chunk-KTODT6DV.js';
|
|
2
|
+
|
|
3
|
+
// src/services/cart.ts
|
|
4
|
+
function requireCartAuth(auth) {
|
|
5
|
+
if (auth && (auth.kind === "customer" || auth.kind === "anonymous")) return auth;
|
|
6
|
+
throw new EmporixValidationError(
|
|
7
|
+
"CartService requires an explicit { kind: 'customer' } or { kind: 'anonymous' } AuthContext"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
function requireCustomerAuth(auth) {
|
|
11
|
+
if (auth && auth.kind === "customer") return auth;
|
|
12
|
+
throw new EmporixValidationError("cart.merge requires a { kind: 'customer' } AuthContext");
|
|
13
|
+
}
|
|
14
|
+
var CartService = class {
|
|
15
|
+
constructor(ctx) {
|
|
16
|
+
this.ctx = ctx;
|
|
17
|
+
}
|
|
18
|
+
ctx;
|
|
19
|
+
base() {
|
|
20
|
+
return `/cart/${this.ctx.tenant}/carts`;
|
|
21
|
+
}
|
|
22
|
+
/** Creates a cart. */
|
|
23
|
+
async create(input, auth) {
|
|
24
|
+
return this.ctx.http.request({
|
|
25
|
+
method: "POST",
|
|
26
|
+
path: this.base(),
|
|
27
|
+
auth: requireCartAuth(auth),
|
|
28
|
+
body: input ?? {}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Fetches a cart by id. */
|
|
32
|
+
async get(cartId, auth) {
|
|
33
|
+
return this.ctx.http.request({
|
|
34
|
+
method: "GET",
|
|
35
|
+
path: `${this.base()}/${cartId}`,
|
|
36
|
+
auth: requireCartAuth(auth)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Returns the current cart for the session, or null if none. */
|
|
40
|
+
/**
|
|
41
|
+
* Get the customer / anonymous cart matching the given criteria. Per Emporix:
|
|
42
|
+
* uniqueness is defined by `siteCode` + `type` + `legalEntityId` +
|
|
43
|
+
* (`customerId` derived from a customer token, or `sessionId` derived from an
|
|
44
|
+
* anonymous token). With `create: true`, Emporix creates a new cart if none
|
|
45
|
+
* matches.
|
|
46
|
+
*
|
|
47
|
+
* Returns `null` on 404 (no cart found and `create` was not set). All other
|
|
48
|
+
* errors are propagated.
|
|
49
|
+
*/
|
|
50
|
+
async getCurrent(auth, opts) {
|
|
51
|
+
const query = { siteCode: opts.siteCode };
|
|
52
|
+
if (opts.type !== void 0) query.type = opts.type;
|
|
53
|
+
if (opts.legalEntityId !== void 0) query.legalEntityId = opts.legalEntityId;
|
|
54
|
+
if (opts.create) query.create = "true";
|
|
55
|
+
try {
|
|
56
|
+
return await this.ctx.http.request({
|
|
57
|
+
method: "GET",
|
|
58
|
+
path: this.base(),
|
|
59
|
+
query,
|
|
60
|
+
auth: requireCartAuth(auth)
|
|
61
|
+
});
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (e instanceof EmporixNotFoundError) return null;
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Adds an item. */
|
|
68
|
+
async addItem(cartId, item, auth) {
|
|
69
|
+
return this.ctx.http.request({
|
|
70
|
+
method: "POST",
|
|
71
|
+
path: `${this.base()}/${cartId}/items`,
|
|
72
|
+
auth: requireCartAuth(auth),
|
|
73
|
+
body: item
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Adds multiple items in a single request via `POST /carts/{id}/itemsBatch`.
|
|
78
|
+
* Server-side limit is 200 entries per call — callers handling larger sets
|
|
79
|
+
* must chunk. The response carries a per-entry `status` (HTTP-style: 201
|
|
80
|
+
* for added, 4xx/5xx for failed) and `index` matching the input position;
|
|
81
|
+
* partial failures do **not** throw — inspect `status` per entry.
|
|
82
|
+
*/
|
|
83
|
+
async addItemsBatch(cartId, items, auth) {
|
|
84
|
+
return this.ctx.http.request({
|
|
85
|
+
method: "POST",
|
|
86
|
+
path: `${this.base()}/${cartId}/itemsBatch`,
|
|
87
|
+
auth: requireCartAuth(auth),
|
|
88
|
+
body: items
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** Updates an item. */
|
|
92
|
+
async updateItem(cartId, itemId, patch, auth) {
|
|
93
|
+
return this.ctx.http.request({
|
|
94
|
+
method: "PUT",
|
|
95
|
+
path: `${this.base()}/${cartId}/items/${itemId}`,
|
|
96
|
+
auth: requireCartAuth(auth),
|
|
97
|
+
body: patch
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/** Removes an item. */
|
|
101
|
+
async removeItem(cartId, itemId, auth) {
|
|
102
|
+
return this.ctx.http.request({
|
|
103
|
+
method: "DELETE",
|
|
104
|
+
path: `${this.base()}/${cartId}/items/${itemId}`,
|
|
105
|
+
auth: requireCartAuth(auth)
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/** Empties the cart. */
|
|
109
|
+
async clear(cartId, auth) {
|
|
110
|
+
return this.ctx.http.request({
|
|
111
|
+
method: "DELETE",
|
|
112
|
+
path: `${this.base()}/${cartId}/items`,
|
|
113
|
+
auth: requireCartAuth(auth)
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** Applies a coupon. */
|
|
117
|
+
async applyCoupon(cartId, code, auth) {
|
|
118
|
+
return this.ctx.http.request({
|
|
119
|
+
method: "POST",
|
|
120
|
+
path: `${this.base()}/${cartId}/coupons`,
|
|
121
|
+
auth: requireCartAuth(auth),
|
|
122
|
+
body: { code }
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/** Removes a coupon. */
|
|
126
|
+
async removeCoupon(cartId, code, auth) {
|
|
127
|
+
return this.ctx.http.request({
|
|
128
|
+
method: "DELETE",
|
|
129
|
+
path: `${this.base()}/${cartId}/coupons/${code}`,
|
|
130
|
+
auth: requireCartAuth(auth)
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/** Sets the shipping address. */
|
|
134
|
+
async setShippingAddress(cartId, address, auth) {
|
|
135
|
+
return this.ctx.http.request({
|
|
136
|
+
method: "PUT",
|
|
137
|
+
path: `${this.base()}/${cartId}/shipping-address`,
|
|
138
|
+
auth: requireCartAuth(auth),
|
|
139
|
+
body: address
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/** Sets the billing address. */
|
|
143
|
+
async setBillingAddress(cartId, address, auth) {
|
|
144
|
+
return this.ctx.http.request({
|
|
145
|
+
method: "PUT",
|
|
146
|
+
path: `${this.base()}/${cartId}/billing-address`,
|
|
147
|
+
auth: requireCartAuth(auth),
|
|
148
|
+
body: address
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Merges one or more anonymous carts into the specified customer cart.
|
|
153
|
+
* Per Emporix: the target cart in the path **must belong to the logged-in
|
|
154
|
+
* customer**, and each id in `anonymousCartIds` must belong to an anonymous
|
|
155
|
+
* customer. Anonymous carts go `CLOSED` on success.
|
|
156
|
+
*
|
|
157
|
+
* Requires a customer `AuthContext`.
|
|
158
|
+
*/
|
|
159
|
+
async merge(customerCartId, anonymousCartIds, auth) {
|
|
160
|
+
return this.ctx.http.request({
|
|
161
|
+
method: "POST",
|
|
162
|
+
path: `${this.base()}/${customerCartId}/merge`,
|
|
163
|
+
auth: requireCustomerAuth(auth),
|
|
164
|
+
body: { carts: anonymousCartIds }
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export { CartService };
|
|
170
|
+
//# sourceMappingURL=chunk-IEZHGU7F.js.map
|
|
171
|
+
//# sourceMappingURL=chunk-IEZHGU7F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/cart.ts"],"names":[],"mappings":";;;AAiCA,SAAS,gBAAgB,IAAA,EAA4C;AACnE,EAAA,IAAI,SAAS,IAAA,CAAK,IAAA,KAAS,cAAc,IAAA,CAAK,IAAA,KAAS,cAAc,OAAO,IAAA;AAC5E,EAAA,MAAM,IAAI,sBAAA;AAAA,IACR;AAAA,GACF;AACF;AAEA,SA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BAAgB,IAAI,CAAA;AAAA,MAC1B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,KAAA,CACJ,cAAA,EACA,gBAAA,EACA,IAAA,EACe;AACf,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,MACjC,MAAA,EAAQ,MAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,cAAc,CAAA,MAAA,CAAA;AAAA,MACtC,IAAA,EAAM,oBAAoB,IAAI,CAAA;AAAA,MAC9B,IAAA,EAAM,EAAE,KAAA,EAAO,gBAAA;AAAiB,KACjC,CAAA;AAAA,EACH;AACF","file":"chunk-IEZHGU7F.js","sourcesContent":["import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixNotFoundError, EmporixValidationError } from \"../core/errors\";\nimport type {\n Cart as GeneratedCart,\n CreateCart,\n CreatedCart,\n CartItemRequest,\n UpdateCartItem,\n AddressRequest,\n BatchResponse as GeneratedBatchResponse,\n SingleBatchResponse as GeneratedSingleBatchResponse,\n} from \"../generated/cart\";\n\n/** A cart as returned by the Cart service (all generated fields). */\nexport type Cart = GeneratedCart;\n\n/** The cart-create response (`{ cartId, yrn }`, generated). */\nexport type CartCreated = CreatedCart;\n\n/** Generated request bodies (caller sends the exact wire shape). */\nexport type CreateCartInput = CreateCart;\nexport type CartItemInput = CartItemRequest;\nexport type CartItemUpdate = UpdateCartItem;\n\n/** Per-entry result of `addItemsBatch`. `status` is HTTP-style per entry (e.g. 201 = added, 4xx = failed). */\nexport type CartItemBatchEntry = GeneratedSingleBatchResponse;\n/** Response shape of `addItemsBatch` — one entry per input item, matching by `index`. */\nexport type CartItemsBatchResponse = GeneratedBatchResponse;\n\n/** An address payload for cart shipping/billing (generated). */\nexport type CartAddress = AddressRequest;\n\nfunction requireCartAuth(auth: AuthContext | undefined): AuthContext {\n if (auth && (auth.kind === \"customer\" || auth.kind === \"anonymous\")) return auth;\n throw new EmporixValidationError(\n \"CartService requires an explicit { kind: 'customer' } or { kind: 'anonymous' } AuthContext\",\n );\n}\n\nfunction requireCustomerAuth(auth: AuthContext | undefined): AuthContext {\n if (auth && auth.kind === \"customer\") return auth;\n throw new EmporixValidationError(\"cart.merge requires a { kind: 'customer' } AuthContext\");\n}\n\n/** Cart operations. Every method requires an explicit customer/anonymous context. */\nexport class CartService {\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/cart/${this.ctx.tenant}/carts`;\n }\n\n /** Creates a cart. */\n async create(\n input: CreateCartInput | undefined,\n auth: AuthContext,\n ): Promise<CartCreated> {\n return this.ctx.http.request<CartCreated>({\n method: \"POST\",\n path: this.base(),\n auth: requireCartAuth(auth),\n body: input ?? {},\n });\n }\n\n /** Fetches a cart by id. */\n async get(cartId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"GET\",\n path: `${this.base()}/${cartId}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Returns the current cart for the session, or null if none. */\n /**\n * Get the customer / anonymous cart matching the given criteria. Per Emporix:\n * uniqueness is defined by `siteCode` + `type` + `legalEntityId` +\n * (`customerId` derived from a customer token, or `sessionId` derived from an\n * anonymous token). With `create: true`, Emporix creates a new cart if none\n * matches.\n *\n * Returns `null` on 404 (no cart found and `create` was not set). All other\n * errors are propagated.\n */\n async getCurrent(\n auth: AuthContext,\n opts: { siteCode: string; type?: string; legalEntityId?: string; create?: boolean },\n ): Promise<Cart | null> {\n const query: Record<string, string | number> = { siteCode: opts.siteCode };\n if (opts.type !== undefined) query.type = opts.type;\n if (opts.legalEntityId !== undefined) query.legalEntityId = opts.legalEntityId;\n if (opts.create) query.create = \"true\";\n try {\n return await this.ctx.http.request<Cart>({\n method: \"GET\",\n path: this.base(),\n query,\n auth: requireCartAuth(auth),\n });\n } catch (e) {\n if (e instanceof EmporixNotFoundError) return null;\n throw e;\n }\n }\n\n /** Adds an item. */\n async addItem(\n cartId: string,\n item: CartItemInput,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/items`,\n auth: requireCartAuth(auth),\n body: item,\n });\n }\n\n /**\n * Adds multiple items in a single request via `POST /carts/{id}/itemsBatch`.\n * Server-side limit is 200 entries per call — callers handling larger sets\n * must chunk. The response carries a per-entry `status` (HTTP-style: 201\n * for added, 4xx/5xx for failed) and `index` matching the input position;\n * partial failures do **not** throw — inspect `status` per entry.\n */\n async addItemsBatch(\n cartId: string,\n items: CartItemInput[],\n auth: AuthContext,\n ): Promise<CartItemsBatchResponse> {\n return this.ctx.http.request<CartItemsBatchResponse>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/itemsBatch`,\n auth: requireCartAuth(auth),\n body: items,\n });\n }\n\n /** Updates an item. */\n async updateItem(\n cartId: string,\n itemId: string,\n patch: CartItemUpdate,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/items/${itemId}`,\n auth: requireCartAuth(auth),\n body: patch,\n });\n }\n\n /** Removes an item. */\n async removeItem(cartId: string, itemId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/items/${itemId}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Empties the cart. */\n async clear(cartId: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/items`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Applies a coupon. */\n async applyCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"POST\",\n path: `${this.base()}/${cartId}/coupons`,\n auth: requireCartAuth(auth),\n body: { code },\n });\n }\n\n /** Removes a coupon. */\n async removeCoupon(cartId: string, code: string, auth: AuthContext): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"DELETE\",\n path: `${this.base()}/${cartId}/coupons/${code}`,\n auth: requireCartAuth(auth),\n });\n }\n\n /** Sets the shipping address. */\n async setShippingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/shipping-address`,\n auth: requireCartAuth(auth),\n body: address,\n });\n }\n\n /** Sets the billing address. */\n async setBillingAddress(\n cartId: string,\n address: CartAddress,\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"PUT\",\n path: `${this.base()}/${cartId}/billing-address`,\n auth: requireCartAuth(auth),\n body: address,\n });\n }\n\n /**\n * Merges one or more anonymous carts into the specified customer cart.\n * Per Emporix: the target cart in the path **must belong to the logged-in\n * customer**, and each id in `anonymousCartIds` must belong to an anonymous\n * customer. Anonymous carts go `CLOSED` on success.\n *\n * Requires a customer `AuthContext`.\n */\n async merge(\n customerCartId: string,\n anonymousCartIds: string[],\n auth: AuthContext,\n ): Promise<Cart> {\n return this.ctx.http.request<Cart>({\n method: \"POST\",\n path: `${this.base()}/${customerCartId}/merge`,\n auth: requireCustomerAuth(auth),\n body: { carts: anonymousCartIds },\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/core/errors.ts
|
|
2
|
+
var REDACTED_BODY_KEYS = /* @__PURE__ */ new Set([
|
|
3
|
+
"access_token",
|
|
4
|
+
"refresh_token",
|
|
5
|
+
"token",
|
|
6
|
+
"customertoken",
|
|
7
|
+
"saastoken",
|
|
8
|
+
"secret",
|
|
9
|
+
"client_secret",
|
|
10
|
+
"authorization",
|
|
11
|
+
"password"
|
|
12
|
+
]);
|
|
13
|
+
function scrub(body) {
|
|
14
|
+
if (Array.isArray(body)) return body.map(scrub);
|
|
15
|
+
if (body && typeof body === "object") {
|
|
16
|
+
const out = {};
|
|
17
|
+
for (const [k, v] of Object.entries(body)) {
|
|
18
|
+
out[k] = REDACTED_BODY_KEYS.has(k.toLowerCase()) ? "***redacted***" : scrub(v);
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
return body;
|
|
23
|
+
}
|
|
24
|
+
var EmporixError = class extends Error {
|
|
25
|
+
status;
|
|
26
|
+
body;
|
|
27
|
+
constructor(message, status, body) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = new.target.name;
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.body = body;
|
|
32
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
33
|
+
}
|
|
34
|
+
/** Safe serialisation — token-like body fields are redacted. */
|
|
35
|
+
toJSON() {
|
|
36
|
+
return { name: this.name, message: this.message, status: this.status, body: scrub(this.body) };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var EmporixAuthError = class extends EmporixError {
|
|
40
|
+
};
|
|
41
|
+
var EmporixForbiddenError = class extends EmporixError {
|
|
42
|
+
};
|
|
43
|
+
var EmporixNotFoundError = class extends EmporixError {
|
|
44
|
+
};
|
|
45
|
+
var EmporixValidationError = class extends EmporixError {
|
|
46
|
+
};
|
|
47
|
+
var EmporixServerError = class extends EmporixError {
|
|
48
|
+
};
|
|
49
|
+
var EmporixInsufficientScopeError = class extends EmporixForbiddenError {
|
|
50
|
+
requiredScope;
|
|
51
|
+
constructor(message, status, body, requiredScope) {
|
|
52
|
+
super(message, status, body);
|
|
53
|
+
this.requiredScope = requiredScope;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var SCOPE_HINT_RE = /missing scope[: ]+([a-z0-9._-]+)/i;
|
|
57
|
+
function extractRequiredScope(body) {
|
|
58
|
+
if (body && typeof body === "object" && "details" in body) {
|
|
59
|
+
const details = body.details;
|
|
60
|
+
if (Array.isArray(details)) {
|
|
61
|
+
for (const d of details) {
|
|
62
|
+
if (typeof d === "string") {
|
|
63
|
+
const m = d.match(SCOPE_HINT_RE);
|
|
64
|
+
if (m) return m[1];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
function errorFromResponse(status, message, body) {
|
|
72
|
+
if (status === 401) return new EmporixAuthError(message, status, body);
|
|
73
|
+
if (status === 403) {
|
|
74
|
+
const scope = extractRequiredScope(body);
|
|
75
|
+
if (scope) return new EmporixInsufficientScopeError(message, status, body, scope);
|
|
76
|
+
return new EmporixForbiddenError(message, status, body);
|
|
77
|
+
}
|
|
78
|
+
if (status === 404) return new EmporixNotFoundError(message, status, body);
|
|
79
|
+
if (status === 400 || status === 422) return new EmporixValidationError(message, status, body);
|
|
80
|
+
if (status >= 500) return new EmporixServerError(message, status, body);
|
|
81
|
+
return new EmporixError(message, status, body);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { EmporixAuthError, EmporixError, EmporixForbiddenError, EmporixInsufficientScopeError, EmporixNotFoundError, EmporixServerError, EmporixValidationError, errorFromResponse };
|
|
85
|
+
//# sourceMappingURL=chunk-KTODT6DV.js.map
|
|
86
|
+
//# sourceMappingURL=chunk-KTODT6DV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/errors.ts"],"names":[],"mappings":";AACA,IAAM,kBAAA,uBAAyB,GAAA,CAAI;AAAA,EACjC,cAAA;AAAA,EAAgB,eAAA;AAAA,EAAiB,OAAA;AAAA,EAAS,eAAA;AAAA,EAAiB,WAAA;AAAA,EAC3D,QAAA;AAAA,EAAU,eAAA;AAAA,EAAiB,eAAA;AAAA,EAAiB;AAC9C,CAAC,CAAA;AAED,SAAS,MAAM,IAAA,EAAwB;AACrC,EAAA,IAAI,MAAM,OAAA,CAAQ,IAAI,GAAG,OAAO,IAAA,CAAK,IAAI,KAAK,CAAA;AAC9C,EAAA,IAAI,IAAA,IAAQ,OAAO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AAQ,IAAI,CAAA;AAAA,EACxD;AACA,EAAA,IAAI,WAAW,GAAA,EAAK,OAAO,IAAI,oBAAA,CAAqB,OAAA,EAAS,QAAQ,IAAI,CAAA;AACzE,EAAA,IAAI,MAAA,KAAW,OAAO,MAAA,KAAW,GAAA,SAAY,IAAI,sBAAA,CAAuB,OAAA,EAAS,MAAA,EAAQ,IAAI,CAAA;AAC7F,EAAA,IAAI,UAAU,GAAA,EAAK,OAAO,IAAI,kBAAA,CAAmB,OAAA,EAAS,QAAQ,IAAI,CAAA;AACtE,EAAA,OAAO,IAAI,YAAA,CAAa,OAAA,EAAS,MAAA,EAAQ,IAAI,CAAA;AAC/C","file":"chunk-KTODT6DV.js","sourcesContent":["/** Keys whose values are stripped from any serialised error body. */\nconst REDACTED_BODY_KEYS = new Set([\n \"access_token\", \"refresh_token\", \"token\", \"customertoken\", \"saastoken\",\n \"secret\", \"client_secret\", \"authorization\", \"password\",\n]);\n\nfunction scrub(body: unknown): unknown {\n if (Array.isArray(body)) return body.map(scrub);\n if (body && typeof body === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(body as Record<string, unknown>)) {\n out[k] = REDACTED_BODY_KEYS.has(k.toLowerCase()) ? \"***redacted***\" : scrub(v);\n }\n return out;\n }\n return body;\n}\n\n/** Base class for every error thrown by the SDK. */\nexport class EmporixError extends Error {\n readonly status: number | undefined;\n readonly body: unknown;\n constructor(message: string, status?: number, body?: unknown) {\n super(message);\n this.name = new.target.name;\n this.status = status;\n this.body = body;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n /** Safe serialisation — token-like body fields are redacted. */\n toJSON(): Record<string, unknown> {\n return { name: this.name, message: this.message, status: this.status, body: scrub(this.body) };\n }\n}\n\n/** 401 — authentication failed or token expired. */\nexport class EmporixAuthError extends EmporixError {}\n/** 403 — authenticated but not permitted. */\nexport class EmporixForbiddenError extends EmporixError {}\n/** 404 — resource not found. */\nexport class EmporixNotFoundError extends EmporixError {}\n/** 400/422 — request validation failed. */\nexport class EmporixValidationError extends EmporixError {}\n/** 5xx — server-side failure. */\nexport class EmporixServerError extends EmporixError {}\n\n/**\n * 403 with a `missing scope: <name>` hint in the body's `details` array.\n * Subclasses {@link EmporixForbiddenError} so existing 403 catches still work.\n */\nexport class EmporixInsufficientScopeError extends EmporixForbiddenError {\n readonly requiredScope: string | undefined;\n constructor(message: string, status: number, body: unknown, requiredScope?: string) {\n super(message, status, body);\n this.requiredScope = requiredScope;\n }\n}\n\nconst SCOPE_HINT_RE = /missing scope[: ]+([a-z0-9._-]+)/i;\n\nfunction extractRequiredScope(body: unknown): string | undefined {\n if (body && typeof body === \"object\" && \"details\" in body) {\n const details = (body as { details?: unknown }).details;\n if (Array.isArray(details)) {\n for (const d of details) {\n if (typeof d === \"string\") {\n const m = d.match(SCOPE_HINT_RE);\n if (m) return m[1];\n }\n }\n }\n }\n return undefined;\n}\n\n/** Maps an HTTP status to the matching {@link EmporixError} subclass. */\nexport function errorFromResponse(status: number, message: string, body: unknown): EmporixError {\n if (status === 401) return new EmporixAuthError(message, status, body);\n if (status === 403) {\n const scope = extractRequiredScope(body);\n if (scope) return new EmporixInsufficientScopeError(message, status, body, scope);\n return new EmporixForbiddenError(message, status, body);\n }\n if (status === 404) return new EmporixNotFoundError(message, status, body);\n if (status === 400 || status === 422) return new EmporixValidationError(message, status, body);\n if (status >= 500) return new EmporixServerError(message, status, body);\n return new EmporixError(message, status, body);\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/services/locations.ts
|
|
2
|
+
var LocationsService = class {
|
|
3
|
+
constructor(ctx) {
|
|
4
|
+
this.ctx = ctx;
|
|
5
|
+
}
|
|
6
|
+
ctx;
|
|
7
|
+
base() {
|
|
8
|
+
return `/customer-management/${this.ctx.tenant}/locations`;
|
|
9
|
+
}
|
|
10
|
+
/** Lists locations owned by one legal entity. */
|
|
11
|
+
async listForCompany(legalEntityId, auth) {
|
|
12
|
+
return this.ctx.http.request({
|
|
13
|
+
method: "GET",
|
|
14
|
+
path: this.base(),
|
|
15
|
+
query: { legalEntityId },
|
|
16
|
+
auth
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/** Fetches one location by id. */
|
|
20
|
+
async get(locationId, auth) {
|
|
21
|
+
return this.ctx.http.request({
|
|
22
|
+
method: "GET",
|
|
23
|
+
path: `${this.base()}/${locationId}`,
|
|
24
|
+
auth
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** Creates a location for a legal entity. */
|
|
28
|
+
async create(input, auth) {
|
|
29
|
+
return this.ctx.http.request({
|
|
30
|
+
method: "POST",
|
|
31
|
+
path: this.base(),
|
|
32
|
+
auth,
|
|
33
|
+
body: input
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Patches a location. */
|
|
37
|
+
async update(locationId, patch, auth) {
|
|
38
|
+
return this.ctx.http.request({
|
|
39
|
+
method: "PATCH",
|
|
40
|
+
path: `${this.base()}/${locationId}`,
|
|
41
|
+
auth,
|
|
42
|
+
body: patch
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** Deletes a location. */
|
|
46
|
+
async delete(locationId, auth) {
|
|
47
|
+
await this.ctx.http.request({
|
|
48
|
+
method: "DELETE",
|
|
49
|
+
path: `${this.base()}/${locationId}`,
|
|
50
|
+
auth
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { LocationsService };
|
|
56
|
+
//# sourceMappingURL=chunk-NM7VDXBR.js.map
|
|
57
|
+
//# sourceMappingURL=chunk-NM7VDXBR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/locations.ts"],"names":[],"mappings":";AAeO,IAAM,mBAAN,MAAuB;AAAA,EAC5B,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA,EAErB,IAAA,GAAe;AACrB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AAAA,EACH;AAAA;AAAA,EAGA,MAAM,MAAA,CAAO,UAAA,EAAoB,IAAA,EAAkC;AACjE,IAAA,MAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAc;AAAA,MAChC,MAAA,EAAQ,QAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,UAAU,CAAA,CAAA;AAAA,MAClC;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-NM7VDXBR.js","sourcesContent":["import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport type {\n Location,\n LocationCreate,\n LocationUpdate,\n} from \"../generated/customer-management\";\n\n/**\n * Manages locations owned by a legal entity. Three types are supported:\n * HEADQUARTER, WAREHOUSE, OFFICE.\n *\n * Reads require `customermanagement.location_read`; mutations require\n * `_manage`.\n */\nexport class LocationsService {\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/customer-management/${this.ctx.tenant}/locations`;\n }\n\n /** Lists locations owned by one legal entity. */\n async listForCompany(legalEntityId: string, auth: AuthContext): Promise<Location[]> {\n return this.ctx.http.request<Location[]>({\n method: \"GET\",\n path: this.base(),\n query: { legalEntityId },\n auth,\n });\n }\n\n /** Fetches one location by id. */\n async get(locationId: string, auth: AuthContext): Promise<Location> {\n return this.ctx.http.request<Location>({\n method: \"GET\",\n path: `${this.base()}/${locationId}`,\n auth,\n });\n }\n\n /** Creates a location for a legal entity. */\n async create(input: LocationCreate, auth: AuthContext): Promise<{ id: string }> {\n return this.ctx.http.request<{ id: string }>({\n method: \"POST\",\n path: this.base(),\n auth,\n body: input,\n });\n }\n\n /** Patches a location. */\n async update(\n locationId: string,\n patch: LocationUpdate,\n auth: AuthContext,\n ): Promise<Location> {\n return this.ctx.http.request<Location>({\n method: \"PATCH\",\n path: `${this.base()}/${locationId}`,\n auth,\n body: patch,\n });\n }\n\n /** Deletes a location. */\n async delete(locationId: string, auth: AuthContext): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `${this.base()}/${locationId}`,\n auth,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EmporixAuthError } from './chunk-KTODT6DV.js';
|
|
2
|
+
|
|
3
|
+
// src/services/checkout.ts
|
|
4
|
+
function isGuest(customer) {
|
|
5
|
+
return customer?.guest === true;
|
|
6
|
+
}
|
|
7
|
+
function resolveAuth(auth, guest) {
|
|
8
|
+
if (auth && (auth.kind === "customer" || auth.kind === "raw")) return auth;
|
|
9
|
+
if (guest && auth && auth.kind === "anonymous") return auth;
|
|
10
|
+
throw new EmporixAuthError(
|
|
11
|
+
"checkout requires a customer/raw AuthContext (or anonymous for a guest checkout)"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
var CheckoutService = class {
|
|
15
|
+
constructor(ctx) {
|
|
16
|
+
this.ctx = ctx;
|
|
17
|
+
}
|
|
18
|
+
ctx;
|
|
19
|
+
headers(opts, guest) {
|
|
20
|
+
if (guest || !opts.saasToken) return void 0;
|
|
21
|
+
return { "saas-token": opts.saasToken };
|
|
22
|
+
}
|
|
23
|
+
query(opts) {
|
|
24
|
+
return opts.siteCode ? { siteCode: opts.siteCode } : void 0;
|
|
25
|
+
}
|
|
26
|
+
/** Checkout from a cart. Requires customer/raw auth (or anonymous for guest). */
|
|
27
|
+
async placeOrder(input, auth, opts = {}) {
|
|
28
|
+
const guest = isGuest(input.customer);
|
|
29
|
+
const headers = this.headers(opts, guest);
|
|
30
|
+
const query = this.query(opts);
|
|
31
|
+
return this.ctx.http.request({
|
|
32
|
+
method: "POST",
|
|
33
|
+
path: `/checkout/${this.ctx.tenant}/checkouts/order`,
|
|
34
|
+
auth: resolveAuth(auth, guest),
|
|
35
|
+
...query ? { query } : {},
|
|
36
|
+
...headers ? { headers } : {},
|
|
37
|
+
body: input
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Checkout from a quote. */
|
|
41
|
+
async placeOrderFromQuote(input, auth, opts = {}) {
|
|
42
|
+
const headers = this.headers(opts, false);
|
|
43
|
+
const query = this.query(opts);
|
|
44
|
+
return this.ctx.http.request({
|
|
45
|
+
method: "POST",
|
|
46
|
+
path: `/checkout/${this.ctx.tenant}/checkouts/order`,
|
|
47
|
+
auth: resolveAuth(auth, false),
|
|
48
|
+
...query ? { query } : {},
|
|
49
|
+
...headers ? { headers } : {},
|
|
50
|
+
body: input
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { CheckoutService };
|
|
56
|
+
//# sourceMappingURL=chunk-OMYVOOSX.js.map
|
|
57
|
+
//# sourceMappingURL=chunk-OMYVOOSX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/checkout.ts"],"names":[],"mappings":";;;AA2BA,SAAS,QAAQ,QAAA,EAA6C;AAC5D,EAAA,OAAO,UAAU,KAAA,KAAU,IAAA;AAC7B;AAEA,SAAS,WAAA,CAAY,MAA+B,KAAA,EAA6B;AAC/E,EAAA,IAAI,SAAS,IAAA,CAAK,IAAA,KAAS,cAAc,IAAA,CAAK,IAAA,KAAS,QAAQ,OAAO,IAAA;AACtE,EAAA,IAAI,KAAA,IAAS,IAAA,IAAQ,IAAA,CAAK,IAAA,KAAS,aAAa,OAAO,IAAA;AACvD,EAAA,MAAM,IAAI,gBAAA;AAAA,IACR;AAAA,GACF;AACF;AAGO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA,EAErB,OAAA,CAAQ,MAAuB,KAAA,EAAoD;AACzF,IAAA,IAAI,KAAA,IAAS,CAAC,IAAA,CAAK,SAAA,EAAW,OAAO,MAAA;AACrC,IAAA,OAAO,EAAE,YAAA,EAAc,IAAA,CAAK,SAAA,EAAU;AAAA,EACxC;AAAA,EAEQ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CAAA,gBAAA,CAAA;AAAA,MAClC,IAAA,EAAM,WAAA,CAAY,IAAA,EAAM,KAAK,CAAA;AAAA,MAC7B,GAAI,KAAA,GAAQ,EAAE,KAAA,KAAU,EAAC;AAAA,MACzB,GAAI,OAAA,GAAU,EAAE,OAAA,KAAY,EAAC;AAAA,MAC7B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"chunk-OMYVOOSX.js","sourcesContent":["import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixAuthError } from \"../core/errors\";\nimport type {\n ResponseCheckout,\n RequestCheckout,\n RequestFromQuoteCheckout,\n CustomerJson,\n} from \"../generated/checkout\";\n\n/** `requestCheckout` body (cart-based, generated). */\nexport type CheckoutInput = RequestCheckout;\n\n/** `requestFromQuoteCheckout` body (quote-based, generated). */\nexport type QuoteCheckoutInput = RequestFromQuoteCheckout;\n\n/** `responseCheckout` — the full generated checkout response. */\nexport type CheckoutResult = ResponseCheckout;\n\n/** Options for a checkout call. */\nexport interface CheckoutOptions {\n /** Customer `saasToken` from `customers.login()` — required for logged-in checkout. */\n saasToken?: string;\n /** Site code (`?siteCode=`). */\n siteCode?: string;\n}\n\nfunction isGuest(customer: CustomerJson | undefined): boolean {\n return customer?.guest === true;\n}\n\nfunction resolveAuth(auth: AuthContext | undefined, guest: boolean): AuthContext {\n if (auth && (auth.kind === \"customer\" || auth.kind === \"raw\")) return auth;\n if (guest && auth && auth.kind === \"anonymous\") return auth;\n throw new EmporixAuthError(\n \"checkout requires a customer/raw AuthContext (or anonymous for a guest checkout)\",\n );\n}\n\n/** Triggers Emporix checkout (atomic: validate → order → payment → close cart). */\nexport class CheckoutService {\n constructor(private readonly ctx: ClientContext) {}\n\n private headers(opts: CheckoutOptions, guest: boolean): Record<string, string> | undefined {\n if (guest || !opts.saasToken) return undefined;\n return { \"saas-token\": opts.saasToken };\n }\n\n private query(opts: CheckoutOptions): Record<string, string> | undefined {\n return opts.siteCode ? { siteCode: opts.siteCode } : undefined;\n }\n\n /** Checkout from a cart. Requires customer/raw auth (or anonymous for guest). */\n async placeOrder(\n input: CheckoutInput,\n auth?: AuthContext,\n opts: CheckoutOptions = {},\n ): Promise<CheckoutResult> {\n const guest = isGuest(input.customer);\n const headers = this.headers(opts, guest);\n const query = this.query(opts);\n return this.ctx.http.request<CheckoutResult>({\n method: \"POST\",\n path: `/checkout/${this.ctx.tenant}/checkouts/order`,\n auth: resolveAuth(auth, guest),\n ...(query ? { query } : {}),\n ...(headers ? { headers } : {}),\n body: input,\n });\n }\n\n /** Checkout from a quote. */\n async placeOrderFromQuote(\n input: QuoteCheckoutInput,\n auth?: AuthContext,\n opts: CheckoutOptions = {},\n ): Promise<CheckoutResult> {\n const headers = this.headers(opts, false);\n const query = this.query(opts);\n return this.ctx.http.request<CheckoutResult>({\n method: \"POST\",\n path: `/checkout/${this.ctx.tenant}/checkouts/order`,\n auth: resolveAuth(auth, false),\n ...(query ? { query } : {}),\n ...(headers ? { headers } : {}),\n body: input,\n });\n }\n}\n"]}
|