@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.
Files changed (132) hide show
  1. package/CHANGELOG.md +407 -0
  2. package/LICENSE +21 -0
  3. package/README.md +115 -0
  4. package/dist/cart.cjs +214 -0
  5. package/dist/cart.cjs.map +1 -0
  6. package/dist/cart.d.cts +1807 -0
  7. package/dist/cart.d.ts +1807 -0
  8. package/dist/cart.js +4 -0
  9. package/dist/cart.js.map +1 -0
  10. package/dist/category.cjs +97 -0
  11. package/dist/category.cjs.map +1 -0
  12. package/dist/category.d.cts +313 -0
  13. package/dist/category.d.ts +313 -0
  14. package/dist/category.js +4 -0
  15. package/dist/category.js.map +1 -0
  16. package/dist/checkout.cjs +98 -0
  17. package/dist/checkout.cjs.map +1 -0
  18. package/dist/checkout.d.cts +252 -0
  19. package/dist/checkout.d.ts +252 -0
  20. package/dist/checkout.js +4 -0
  21. package/dist/checkout.js.map +1 -0
  22. package/dist/chunk-4BJUCCKJ.js +86 -0
  23. package/dist/chunk-4BJUCCKJ.js.map +1 -0
  24. package/dist/chunk-6UNFMCHZ.js +95 -0
  25. package/dist/chunk-6UNFMCHZ.js.map +1 -0
  26. package/dist/chunk-B56JZNI7.js +49 -0
  27. package/dist/chunk-B56JZNI7.js.map +1 -0
  28. package/dist/chunk-BFQ732VZ.js +11 -0
  29. package/dist/chunk-BFQ732VZ.js.map +1 -0
  30. package/dist/chunk-F3WAQH2E.js +120 -0
  31. package/dist/chunk-F3WAQH2E.js.map +1 -0
  32. package/dist/chunk-GWJ2U2CP.js +14 -0
  33. package/dist/chunk-GWJ2U2CP.js.map +1 -0
  34. package/dist/chunk-HEO34WLO.js +47 -0
  35. package/dist/chunk-HEO34WLO.js.map +1 -0
  36. package/dist/chunk-HKPZI7Y5.js +30 -0
  37. package/dist/chunk-HKPZI7Y5.js.map +1 -0
  38. package/dist/chunk-IEZHGU7F.js +171 -0
  39. package/dist/chunk-IEZHGU7F.js.map +1 -0
  40. package/dist/chunk-KTODT6DV.js +86 -0
  41. package/dist/chunk-KTODT6DV.js.map +1 -0
  42. package/dist/chunk-NM7VDXBR.js +57 -0
  43. package/dist/chunk-NM7VDXBR.js.map +1 -0
  44. package/dist/chunk-OMYVOOSX.js +57 -0
  45. package/dist/chunk-OMYVOOSX.js.map +1 -0
  46. package/dist/chunk-QDABAMVN.js +89 -0
  47. package/dist/chunk-QDABAMVN.js.map +1 -0
  48. package/dist/chunk-RXVVFNYN.js +56 -0
  49. package/dist/chunk-RXVVFNYN.js.map +1 -0
  50. package/dist/chunk-SKX7KCMH.js +23 -0
  51. package/dist/chunk-SKX7KCMH.js.map +1 -0
  52. package/dist/chunk-TLH6SLAF.js +215 -0
  53. package/dist/chunk-TLH6SLAF.js.map +1 -0
  54. package/dist/chunk-Z6PNI5VT.js +142 -0
  55. package/dist/chunk-Z6PNI5VT.js.map +1 -0
  56. package/dist/companies.cjs +58 -0
  57. package/dist/companies.cjs.map +1 -0
  58. package/dist/companies.d.cts +31 -0
  59. package/dist/companies.d.ts +31 -0
  60. package/dist/companies.js +3 -0
  61. package/dist/companies.js.map +1 -0
  62. package/dist/contacts.cjs +51 -0
  63. package/dist/contacts.cjs.map +1 -0
  64. package/dist/contacts.d.cts +28 -0
  65. package/dist/contacts.d.ts +28 -0
  66. package/dist/contacts.js +3 -0
  67. package/dist/contacts.js.map +1 -0
  68. package/dist/context-vKgzZ-5f.d.cts +329 -0
  69. package/dist/context-vKgzZ-5f.d.ts +329 -0
  70. package/dist/customer-groups.cjs +25 -0
  71. package/dist/customer-groups.cjs.map +1 -0
  72. package/dist/customer-groups.d.cts +36 -0
  73. package/dist/customer-groups.d.ts +36 -0
  74. package/dist/customer-groups.js +3 -0
  75. package/dist/customer-groups.js.map +1 -0
  76. package/dist/customer.cjs +262 -0
  77. package/dist/customer.cjs.map +1 -0
  78. package/dist/customer.d.cts +386 -0
  79. package/dist/customer.d.ts +386 -0
  80. package/dist/customer.js +5 -0
  81. package/dist/customer.js.map +1 -0
  82. package/dist/index.cjs +2075 -0
  83. package/dist/index.cjs.map +1 -0
  84. package/dist/index.d.cts +218 -0
  85. package/dist/index.d.ts +218 -0
  86. package/dist/index.js +791 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/locations.cjs +59 -0
  89. package/dist/locations.cjs.map +1 -0
  90. package/dist/locations.d.cts +30 -0
  91. package/dist/locations.d.ts +30 -0
  92. package/dist/locations.js +3 -0
  93. package/dist/locations.js.map +1 -0
  94. package/dist/media.cjs +123 -0
  95. package/dist/media.cjs.map +1 -0
  96. package/dist/media.d.cts +219 -0
  97. package/dist/media.d.ts +219 -0
  98. package/dist/media.js +3 -0
  99. package/dist/media.js.map +1 -0
  100. package/dist/orders.cjs +98 -0
  101. package/dist/orders.cjs.map +1 -0
  102. package/dist/orders.d.cts +167 -0
  103. package/dist/orders.d.ts +167 -0
  104. package/dist/orders.js +3 -0
  105. package/dist/orders.js.map +1 -0
  106. package/dist/payment.cjs +77 -0
  107. package/dist/payment.cjs.map +1 -0
  108. package/dist/payment.d.cts +110 -0
  109. package/dist/payment.d.ts +110 -0
  110. package/dist/payment.js +5 -0
  111. package/dist/payment.js.map +1 -0
  112. package/dist/price.cjs +88 -0
  113. package/dist/price.cjs.map +1 -0
  114. package/dist/price.d.cts +445 -0
  115. package/dist/price.d.ts +445 -0
  116. package/dist/price.js +4 -0
  117. package/dist/price.js.map +1 -0
  118. package/dist/product.cjs +100 -0
  119. package/dist/product.cjs.map +1 -0
  120. package/dist/product.d.cts +400 -0
  121. package/dist/product.d.ts +400 -0
  122. package/dist/product.js +4 -0
  123. package/dist/product.js.map +1 -0
  124. package/dist/segment.cjs +189 -0
  125. package/dist/segment.cjs.map +1 -0
  126. package/dist/segment.d.cts +241 -0
  127. package/dist/segment.d.ts +241 -0
  128. package/dist/segment.js +5 -0
  129. package/dist/segment.js.map +1 -0
  130. package/dist/types.gen-D1QuqPLs.d.cts +166 -0
  131. package/dist/types.gen-D1QuqPLs.d.ts +166 -0
  132. package/package.json +141 -0
@@ -0,0 +1,262 @@
1
+ 'use strict';
2
+
3
+ // src/core/errors.ts
4
+ var REDACTED_BODY_KEYS = /* @__PURE__ */ new Set([
5
+ "access_token",
6
+ "refresh_token",
7
+ "token",
8
+ "customertoken",
9
+ "saastoken",
10
+ "secret",
11
+ "client_secret",
12
+ "authorization",
13
+ "password"
14
+ ]);
15
+ function scrub(body) {
16
+ if (Array.isArray(body)) return body.map(scrub);
17
+ if (body && typeof body === "object") {
18
+ const out = {};
19
+ for (const [k, v] of Object.entries(body)) {
20
+ out[k] = REDACTED_BODY_KEYS.has(k.toLowerCase()) ? "***redacted***" : scrub(v);
21
+ }
22
+ return out;
23
+ }
24
+ return body;
25
+ }
26
+ var EmporixError = class extends Error {
27
+ status;
28
+ body;
29
+ constructor(message, status, body) {
30
+ super(message);
31
+ this.name = new.target.name;
32
+ this.status = status;
33
+ this.body = body;
34
+ Object.setPrototypeOf(this, new.target.prototype);
35
+ }
36
+ /** Safe serialisation — token-like body fields are redacted. */
37
+ toJSON() {
38
+ return { name: this.name, message: this.message, status: this.status, body: scrub(this.body) };
39
+ }
40
+ };
41
+ var EmporixAuthError = class extends EmporixError {
42
+ };
43
+
44
+ // src/core/require-customer.ts
45
+ function requireCustomer(auth) {
46
+ if (auth && (auth.kind === "customer" || auth.kind === "raw")) return auth;
47
+ throw new EmporixAuthError("This operation requires a customer or raw AuthContext");
48
+ }
49
+
50
+ // src/services/customer.ts
51
+ var CustomerService = class {
52
+ constructor(ctx) {
53
+ this.ctx = ctx;
54
+ }
55
+ ctx;
56
+ /** Obtains an anonymous storefront session (accessToken + sessionId + refreshToken). */
57
+ async anonymous() {
58
+ return this.ctx.tokenProvider.getAnonymousToken();
59
+ }
60
+ /** Registers a customer. Default auth: anonymous. */
61
+ async signup(input, auth = { kind: "anonymous" }) {
62
+ return this.ctx.http.request({
63
+ method: "POST",
64
+ path: `/customer/${this.ctx.tenant}/signup`,
65
+ auth,
66
+ body: input
67
+ });
68
+ }
69
+ /**
70
+ * Logs a customer in. Threads the anonymous token so the session (and its
71
+ * cart) survives — losing it silently creates a new session per Emporix docs.
72
+ * Wire `accessToken` is mapped to `customerToken`.
73
+ */
74
+ async login(creds, opts = {}, auth = { kind: "anonymous" }) {
75
+ const effective = opts.anonymousToken ? { kind: "raw", token: opts.anonymousToken } : auth;
76
+ const wire = await this.ctx.http.request({
77
+ method: "POST",
78
+ path: `/customer/${this.ctx.tenant}/login`,
79
+ auth: effective,
80
+ body: creds
81
+ });
82
+ return {
83
+ customerToken: wire.access_token ?? wire.accessToken ?? "",
84
+ saasToken: wire.saas_token ?? wire.saasToken ?? "",
85
+ refreshToken: wire.refresh_token ?? wire.refreshToken ?? "",
86
+ sessionId: wire.session_id,
87
+ expiresIn: wire.expires_in
88
+ };
89
+ }
90
+ /**
91
+ * Refreshes an authenticated customer session via its refresh token,
92
+ * preserving the same `sessionId`. Calls
93
+ * `GET /customer/{tenant}/refreshauthtoken?refreshToken=…`, which **must be
94
+ * authorized with an anonymous token** (default auth: anonymous) — not the
95
+ * expired customer token. The refresh response does **not** include a
96
+ * `saas_token`; pass the original `saasToken` to carry it forward (it has
97
+ * its own, independent lifetime).
98
+ */
99
+ async refresh(input, auth = { kind: "anonymous" }) {
100
+ const query = { refreshToken: input.refreshToken };
101
+ if (input.legalEntityId) query.legalEntityId = input.legalEntityId;
102
+ const wire = await this.ctx.http.request({
103
+ method: "GET",
104
+ path: `/customer/${this.ctx.tenant}/refreshauthtoken`,
105
+ query,
106
+ auth
107
+ });
108
+ return {
109
+ customerToken: wire.access_token ?? wire.accessToken ?? "",
110
+ // Refresh does not return a saas_token — carry the original forward.
111
+ saasToken: input.saasToken ?? "",
112
+ refreshToken: wire.refresh_token ?? wire.refreshToken ?? "",
113
+ sessionId: wire.session_id,
114
+ expiresIn: wire.expires_in
115
+ };
116
+ }
117
+ /**
118
+ * Logs the customer out server-side: `GET /customer/{tenant}/logout?
119
+ * accessToken=…` authorized with the customer token. Invalidates the
120
+ * access token (204 No Content). Requires customer/raw auth — the token is
121
+ * sent both as the bearer and the `accessToken` query param (per Emporix).
122
+ */
123
+ async logout(auth) {
124
+ const ctx = requireCustomer(auth);
125
+ const token = ctx.token;
126
+ await this.ctx.http.request({
127
+ method: "GET",
128
+ path: `/customer/${this.ctx.tenant}/logout`,
129
+ query: { accessToken: token },
130
+ auth: ctx
131
+ });
132
+ }
133
+ /**
134
+ * Authorization-Code SSO: exchanges the IdP `code` for an Emporix customer
135
+ * session via `POST /customer/{tenant}/socialLogin`. The browser performs
136
+ * the IdP redirect itself; the SDK only does this Emporix exchange.
137
+ * Default auth: anonymous (Emporix requires an anonymous Bearer). The
138
+ * response has no `session_id` and returns `expires_in` as a string —
139
+ * normalized to a number here.
140
+ */
141
+ async socialLogin(input, auth = { kind: "anonymous" }) {
142
+ const query = {
143
+ code: input.code,
144
+ redirect_uri: input.redirectUri
145
+ };
146
+ if (input.codeVerifier) query.code_verifier = input.codeVerifier;
147
+ const wire = await this.ctx.http.request({
148
+ method: "POST",
149
+ path: `/customer/${this.ctx.tenant}/socialLogin`,
150
+ query,
151
+ auth,
152
+ ...input.sessionId ? { headers: { "session-id": input.sessionId } } : {}
153
+ });
154
+ return {
155
+ customerToken: wire.access_token ?? wire.accessToken ?? "",
156
+ saasToken: wire.saas_token ?? wire.saasToken ?? "",
157
+ refreshToken: wire.refresh_token ?? wire.refreshToken ?? "",
158
+ sessionId: wire.session_id,
159
+ expiresIn: wire.expires_in != null ? Number(wire.expires_in) : void 0,
160
+ ...wire.social_access_token ? { socialAccessToken: wire.social_access_token } : {},
161
+ ...wire.social_id_token ? { socialIdToken: wire.social_id_token } : {}
162
+ };
163
+ }
164
+ /**
165
+ * RFC 8693 token exchange: exchanges an external IdP JWT for an Emporix
166
+ * customer session via `POST /customer/{tenant}/exchangeauthtoken`.
167
+ * Emporix uses a proprietary query-param wire (not the RFC form body).
168
+ * Default auth: anonymous. `config` selects a site-specific IdP config
169
+ * (multi-site); omit for the tenant default. Returns `session_id` and a
170
+ * fresh `saas_token`; `expires_in` is an integer (normalized anyway).
171
+ */
172
+ async exchangeToken(input, auth = { kind: "anonymous" }) {
173
+ const query = { subjectAccessToken: input.subjectToken };
174
+ if (input.config) query.config = input.config;
175
+ const wire = await this.ctx.http.request({
176
+ method: "POST",
177
+ path: `/customer/${this.ctx.tenant}/exchangeauthtoken`,
178
+ query,
179
+ auth
180
+ });
181
+ return {
182
+ customerToken: wire.access_token ?? wire.accessToken ?? "",
183
+ saasToken: wire.saas_token ?? wire.saasToken ?? "",
184
+ refreshToken: wire.refresh_token ?? wire.refreshToken ?? "",
185
+ sessionId: wire.session_id,
186
+ expiresIn: wire.expires_in != null ? Number(wire.expires_in) : void 0
187
+ };
188
+ }
189
+ /** Returns the authenticated customer. Requires customer/raw auth. */
190
+ async me(auth) {
191
+ return this.ctx.http.request({
192
+ method: "GET",
193
+ path: `/customer/${this.ctx.tenant}/me`,
194
+ auth: requireCustomer(auth)
195
+ });
196
+ }
197
+ /** Updates the authenticated customer. Requires customer/raw auth. */
198
+ async update(patch, auth) {
199
+ return this.ctx.http.request({
200
+ method: "PUT",
201
+ path: `/customer/${this.ctx.tenant}/me`,
202
+ auth: requireCustomer(auth),
203
+ body: patch
204
+ });
205
+ }
206
+ /** Changes the password. Requires customer/raw auth. */
207
+ async changePassword(input, auth) {
208
+ await this.ctx.http.request({
209
+ method: "PUT",
210
+ path: `/customer/${this.ctx.tenant}/password`,
211
+ auth: requireCustomer(auth),
212
+ body: input
213
+ });
214
+ }
215
+ /** Requests a password reset email. Default auth: anonymous. */
216
+ async requestPasswordReset(input, auth = { kind: "anonymous" }) {
217
+ await this.ctx.http.request({
218
+ method: "POST",
219
+ path: `/customer/${this.ctx.tenant}/password/reset`,
220
+ auth,
221
+ body: input
222
+ });
223
+ }
224
+ /** Confirms a password reset. Default auth: anonymous. */
225
+ async confirmPasswordReset(input, auth = { kind: "anonymous" }) {
226
+ await this.ctx.http.request({
227
+ method: "POST",
228
+ path: `/customer/${this.ctx.tenant}/password/reset/confirm`,
229
+ auth,
230
+ body: input
231
+ });
232
+ }
233
+ /** Address sub-resource. All operations require customer/raw auth. */
234
+ addresses = {
235
+ list: async (auth) => this.ctx.http.request({
236
+ method: "GET",
237
+ path: `/customer/${this.ctx.tenant}/me/addresses`,
238
+ auth: requireCustomer(auth)
239
+ }),
240
+ add: async (address, auth) => this.ctx.http.request({
241
+ method: "POST",
242
+ path: `/customer/${this.ctx.tenant}/me/addresses`,
243
+ auth: requireCustomer(auth),
244
+ body: address
245
+ }),
246
+ update: async (id, patch, auth) => this.ctx.http.request({
247
+ method: "PUT",
248
+ path: `/customer/${this.ctx.tenant}/me/addresses/${id}`,
249
+ auth: requireCustomer(auth),
250
+ body: patch
251
+ }),
252
+ remove: async (id, auth) => this.ctx.http.request({
253
+ method: "DELETE",
254
+ path: `/customer/${this.ctx.tenant}/me/addresses/${id}`,
255
+ auth: requireCustomer(auth)
256
+ })
257
+ };
258
+ };
259
+
260
+ exports.CustomerService = CustomerService;
261
+ //# sourceMappingURL=customer.cjs.map
262
+ //# sourceMappingURL=customer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/errors.ts","../src/core/require-customer.ts","../src/services/customer.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,IAAA,KAAS,QAAA,EAAU;AACpC,IAAA,MAAM,MAA+B,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A,EAAa,IAAA,CAAK,GAAA,CAAI,MAAM,iBAAiB,EAAE,CAAA,CAAA;AAAA,MACrD,IAAA,EAAM,gBAAgB,IAAI,CAAA;AAAA,MAC1B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,IACH,QAAQ,OAAO,EAAA,EAAY,SACzB,IAAA,CAAK,GAAA,CAAI,KAAK,OAAA,CAAc;AAAA,MAC1B,MAAA,EAAQ,QAAA;AAAA,MACR,MAAM,CAAA,UAAA,EAAa,IAAA,CAAK,GAAA,CAAI,MAAM,iBAAiB,EAAE,CAAA,CAAA;AAAA,MACrD,IAAA,EAAM,gBAAgB,IAAI;AAAA,KAC3B;AAAA,GACL;AACF","file":"customer.cjs","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","import type { AuthContext } from \"./auth\";\nimport { EmporixAuthError } from \"./errors\";\n\n/**\n * Enforces a caller-owned customer or raw token. Throws `EmporixAuthError`\n * for any other `AuthContext` kind (or when `auth` is missing). Shared by\n * services whose endpoints require a customer scope (`/me`, payments,\n * customer-segments…).\n */\nexport function requireCustomer(auth: AuthContext | undefined): AuthContext {\n if (auth && (auth.kind === \"customer\" || auth.kind === \"raw\")) return auth;\n throw new EmporixAuthError(\"This operation requires a customer or raw AuthContext\");\n}\n","import type { ClientContext } from \"../core/context\";\nimport type { AuthContext, AnonymousSession } from \"../core/auth\";\nimport { EmporixAuthError } from \"../core/errors\";\nimport { requireCustomer } from \"../core/require-customer\";\nimport type {\n Customer as GeneratedCustomer,\n Address as GeneratedAddress,\n CustomerSignup,\n CustomerUpdateDto,\n PasswordChangeDto,\n PasswordResetRequestDto,\n PasswordUpdate,\n AddressCreateDto,\n AddressUpdateDto,\n} from \"../generated/customer\";\n\n/**\n * Caller-owned customer session. Maps the Emporix `CustomerToken` wire shape to\n * idiomatic names: `access_token` → `customerToken`, `saas_token` →\n * `saasToken`. `saasToken` is a JWT required for the checkout (`saas-token`\n * header). The wire's `*_token` (snake_case) fields are canonical; the\n * camelCase variants are deprecated in the Emporix spec.\n */\nexport interface CustomerSession {\n customerToken: string;\n /** JWT required for completing checkout (sent as the `saas-token` header). */\n saasToken: string;\n refreshToken: string;\n /** Same session as the anonymous token — preserves the cart across login. */\n sessionId: string | undefined;\n /** Customer access-token lifetime in seconds. */\n expiresIn: number | undefined;\n /** Only set by `socialLogin`: the IdP access token echoed by Emporix. */\n socialAccessToken?: string;\n /** Only set by `socialLogin`: the IdP ID token echoed by Emporix. */\n socialIdToken?: string;\n}\n\n/** Customer profile as returned by the Customer service (all generated fields). */\nexport type Customer = GeneratedCustomer;\n\n/** A customer address as returned by the Customer service (all generated fields). */\nexport type Address = GeneratedAddress;\n\n/** Generated request bodies (caller sends the exact wire shape). */\nexport type CustomerSignupInput = CustomerSignup;\nexport type CustomerUpdateInput = CustomerUpdateDto;\nexport type PasswordChangeInput = PasswordChangeDto;\nexport type PasswordResetRequestInput = PasswordResetRequestDto;\nexport type PasswordResetConfirmInput = PasswordUpdate;\nexport type AddressCreateInput = AddressCreateDto;\nexport type AddressUpdateInput = AddressUpdateDto;\n\n/** Customer signup, session, profile and addresses. */\nexport class CustomerService {\n constructor(private readonly ctx: ClientContext) {}\n\n /** Obtains an anonymous storefront session (accessToken + sessionId + refreshToken). */\n async anonymous(): Promise<AnonymousSession> {\n return this.ctx.tokenProvider.getAnonymousToken();\n }\n\n /** Registers a customer. Default auth: anonymous. */\n async signup(\n input: CustomerSignupInput,\n auth: AuthContext = { kind: \"anonymous\" },\n ): Promise<Customer> {\n return this.ctx.http.request<Customer>({\n method: \"POST\",\n path: `/customer/${this.ctx.tenant}/signup`,\n auth,\n body: input,\n });\n }\n\n /**\n * Logs a customer in. Threads the anonymous token so the session (and its\n * cart) survives — losing it silently creates a new session per Emporix docs.\n * Wire `accessToken` is mapped to `customerToken`.\n */\n async login(\n creds: { email: string; password: string },\n opts: { anonymousToken?: string } = {},\n auth: AuthContext = { kind: \"anonymous\" },\n ): Promise<CustomerSession> {\n const effective: AuthContext = opts.anonymousToken\n ? { kind: \"raw\", token: opts.anonymousToken }\n : auth;\n const wire = await this.ctx.http.request<{\n access_token?: string;\n saas_token?: string;\n refresh_token?: string;\n session_id?: string;\n expires_in?: number;\n // Deprecated camelCase variants (Emporix spec marks these deprecated).\n accessToken?: string;\n saasToken?: string;\n refreshToken?: string;\n }>({\n method: \"POST\",\n path: `/customer/${this.ctx.tenant}/login`,\n auth: effective,\n body: creds,\n });\n // Wire→facade mapping. snake_case is canonical; camelCase is the\n // deprecated fallback (see design §2 — vendored spec is source of truth).\n return {\n customerToken: wire.access_token ?? wire.accessToken ?? \"\",\n saasToken: wire.saas_token ?? wire.saasToken ?? \"\",\n refreshToken: wire.refresh_token ?? wire.refreshToken ?? \"\",\n sessionId: wire.session_id,\n expiresIn: wire.expires_in,\n };\n }\n\n /**\n * Refreshes an authenticated customer session via its refresh token,\n * preserving the same `sessionId`. Calls\n * `GET /customer/{tenant}/refreshauthtoken?refreshToken=…`, which **must be\n * authorized with an anonymous token** (default auth: anonymous) — not the\n * expired customer token. The refresh response does **not** include a\n * `saas_token`; pass the original `saasToken` to carry it forward (it has\n * its own, independent lifetime).\n */\n async refresh(\n input: { refreshToken: string; saasToken?: string; legalEntityId?: string },\n auth: AuthContext = { kind: \"anonymous\" },\n ): Promise<CustomerSession> {\n const query: Record<string, string> = { refreshToken: input.refreshToken };\n if (input.legalEntityId) query.legalEntityId = input.legalEntityId;\n const wire = await this.ctx.http.request<{\n access_token?: string;\n refresh_token?: string;\n session_id?: string;\n expires_in?: number;\n // Deprecated camelCase variants (Emporix spec marks these deprecated).\n accessToken?: string;\n refreshToken?: string;\n }>({\n method: \"GET\",\n path: `/customer/${this.ctx.tenant}/refreshauthtoken`,\n query,\n auth,\n });\n return {\n customerToken: wire.access_token ?? wire.accessToken ?? \"\",\n // Refresh does not return a saas_token — carry the original forward.\n saasToken: input.saasToken ?? \"\",\n refreshToken: wire.refresh_token ?? wire.refreshToken ?? \"\",\n sessionId: wire.session_id,\n expiresIn: wire.expires_in,\n };\n }\n\n /**\n * Logs the customer out server-side: `GET /customer/{tenant}/logout?\n * accessToken=…` authorized with the customer token. Invalidates the\n * access token (204 No Content). Requires customer/raw auth — the token is\n * sent both as the bearer and the `accessToken` query param (per Emporix).\n */\n async logout(auth?: AuthContext): Promise<void> {\n const ctx = requireCustomer(auth);\n const token = (ctx as { token: string }).token;\n await this.ctx.http.request<void>({\n method: \"GET\",\n path: `/customer/${this.ctx.tenant}/logout`,\n query: { accessToken: token },\n auth: ctx,\n });\n }\n\n /**\n * Authorization-Code SSO: exchanges the IdP `code` for an Emporix customer\n * session via `POST /customer/{tenant}/socialLogin`. The browser performs\n * the IdP redirect itself; the SDK only does this Emporix exchange.\n * Default auth: anonymous (Emporix requires an anonymous Bearer). The\n * response has no `session_id` and returns `expires_in` as a string —\n * normalized to a number here.\n */\n async socialLogin(\n input: { code: string; redirectUri: string; codeVerifier?: string; sessionId?: string },\n auth: AuthContext = { kind: \"anonymous\" },\n ): Promise<CustomerSession> {\n const query: Record<string, string> = {\n code: input.code,\n redirect_uri: input.redirectUri,\n };\n if (input.codeVerifier) query.code_verifier = input.codeVerifier;\n const wire = await this.ctx.http.request<{\n social_access_token?: string;\n social_id_token?: string;\n access_token?: string;\n saas_token?: string;\n refresh_token?: string;\n session_id?: string;\n expires_in?: string | number;\n // Deprecated camelCase variants (Emporix spec marks these deprecated).\n accessToken?: string;\n saasToken?: string;\n refreshToken?: string;\n }>({\n method: \"POST\",\n path: `/customer/${this.ctx.tenant}/socialLogin`,\n query,\n auth,\n ...(input.sessionId ? { headers: { \"session-id\": input.sessionId } } : {}),\n });\n return {\n customerToken: wire.access_token ?? wire.accessToken ?? \"\",\n saasToken: wire.saas_token ?? wire.saasToken ?? \"\",\n refreshToken: wire.refresh_token ?? wire.refreshToken ?? \"\",\n sessionId: wire.session_id,\n expiresIn: wire.expires_in != null ? Number(wire.expires_in) : undefined,\n ...(wire.social_access_token ? { socialAccessToken: wire.social_access_token } : {}),\n ...(wire.social_id_token ? { socialIdToken: wire.social_id_token } : {}),\n };\n }\n\n /**\n * RFC 8693 token exchange: exchanges an external IdP JWT for an Emporix\n * customer session via `POST /customer/{tenant}/exchangeauthtoken`.\n * Emporix uses a proprietary query-param wire (not the RFC form body).\n * Default auth: anonymous. `config` selects a site-specific IdP config\n * (multi-site); omit for the tenant default. Returns `session_id` and a\n * fresh `saas_token`; `expires_in` is an integer (normalized anyway).\n */\n async exchangeToken(\n input: { subjectToken: string; config?: string },\n auth: AuthContext = { kind: \"anonymous\" },\n ): Promise<CustomerSession> {\n const query: Record<string, string> = { subjectAccessToken: input.subjectToken };\n if (input.config) query.config = input.config;\n const wire = await this.ctx.http.request<{\n access_token?: string;\n saas_token?: string;\n refresh_token?: string;\n session_id?: string;\n expires_in?: string | number;\n accessToken?: string;\n saasToken?: string;\n refreshToken?: string;\n }>({\n method: \"POST\",\n path: `/customer/${this.ctx.tenant}/exchangeauthtoken`,\n query,\n auth,\n });\n return {\n customerToken: wire.access_token ?? wire.accessToken ?? \"\",\n saasToken: wire.saas_token ?? wire.saasToken ?? \"\",\n refreshToken: wire.refresh_token ?? wire.refreshToken ?? \"\",\n sessionId: wire.session_id,\n expiresIn: wire.expires_in != null ? Number(wire.expires_in) : undefined,\n };\n }\n\n /** Returns the authenticated customer. Requires customer/raw auth. */\n async me(auth?: AuthContext): Promise<Customer> {\n return this.ctx.http.request<Customer>({\n method: \"GET\",\n path: `/customer/${this.ctx.tenant}/me`,\n auth: requireCustomer(auth),\n });\n }\n\n /** Updates the authenticated customer. Requires customer/raw auth. */\n async update(patch: CustomerUpdateInput, auth?: AuthContext): Promise<Customer> {\n return this.ctx.http.request<Customer>({\n method: \"PUT\",\n path: `/customer/${this.ctx.tenant}/me`,\n auth: requireCustomer(auth),\n body: patch,\n });\n }\n\n /** Changes the password. Requires customer/raw auth. */\n async changePassword(input: PasswordChangeInput, auth?: AuthContext): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"PUT\",\n path: `/customer/${this.ctx.tenant}/password`,\n auth: requireCustomer(auth),\n body: input,\n });\n }\n\n /** Requests a password reset email. Default auth: anonymous. */\n async requestPasswordReset(\n input: PasswordResetRequestInput,\n auth: AuthContext = { kind: \"anonymous\" },\n ): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"POST\",\n path: `/customer/${this.ctx.tenant}/password/reset`,\n auth,\n body: input,\n });\n }\n\n /** Confirms a password reset. Default auth: anonymous. */\n async confirmPasswordReset(\n input: PasswordResetConfirmInput,\n auth: AuthContext = { kind: \"anonymous\" },\n ): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"POST\",\n path: `/customer/${this.ctx.tenant}/password/reset/confirm`,\n auth,\n body: input,\n });\n }\n\n /** Address sub-resource. All operations require customer/raw auth. */\n readonly addresses = {\n list: async (auth?: AuthContext): Promise<Address[]> =>\n this.ctx.http.request<Address[]>({\n method: \"GET\",\n path: `/customer/${this.ctx.tenant}/me/addresses`,\n auth: requireCustomer(auth),\n }),\n add: async (address: AddressCreateInput, auth?: AuthContext): Promise<Address> =>\n this.ctx.http.request<Address>({\n method: \"POST\",\n path: `/customer/${this.ctx.tenant}/me/addresses`,\n auth: requireCustomer(auth),\n body: address,\n }),\n update: async (id: string, patch: AddressUpdateInput, auth?: AuthContext): Promise<Address> =>\n this.ctx.http.request<Address>({\n method: \"PUT\",\n path: `/customer/${this.ctx.tenant}/me/addresses/${id}`,\n auth: requireCustomer(auth),\n body: patch,\n }),\n remove: async (id: string, auth?: AuthContext): Promise<void> =>\n this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `/customer/${this.ctx.tenant}/me/addresses/${id}`,\n auth: requireCustomer(auth),\n }),\n };\n}\n"]}