@platform-x-shp/shopify-adapter 0.9.0 → 0.11.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 (46) hide show
  1. package/dist/src/cart.d.ts +12 -0
  2. package/dist/src/cart.d.ts.map +1 -1
  3. package/dist/src/cart.js +36 -0
  4. package/dist/src/cart.js.map +1 -1
  5. package/dist/src/customer-account.d.ts +11 -0
  6. package/dist/src/customer-account.d.ts.map +1 -0
  7. package/dist/src/customer-account.js +95 -0
  8. package/dist/src/customer-account.js.map +1 -0
  9. package/dist/src/delivery-sso.d.ts +80 -17
  10. package/dist/src/delivery-sso.d.ts.map +1 -1
  11. package/dist/src/delivery-sso.js +142 -168
  12. package/dist/src/delivery-sso.js.map +1 -1
  13. package/dist/src/errors.d.ts +8 -0
  14. package/dist/src/errors.d.ts.map +1 -1
  15. package/dist/src/errors.js +13 -1
  16. package/dist/src/errors.js.map +1 -1
  17. package/dist/src/gateway-session.d.ts +38 -0
  18. package/dist/src/gateway-session.d.ts.map +1 -0
  19. package/dist/src/gateway-session.js +82 -0
  20. package/dist/src/gateway-session.js.map +1 -0
  21. package/dist/src/index.d.ts +10 -4
  22. package/dist/src/index.d.ts.map +1 -1
  23. package/dist/src/index.js +41 -3
  24. package/dist/src/index.js.map +1 -1
  25. package/dist/src/my-account.d.ts +44 -0
  26. package/dist/src/my-account.d.ts.map +1 -0
  27. package/dist/src/my-account.js +280 -0
  28. package/dist/src/my-account.js.map +1 -0
  29. package/dist/src/redis-connector.d.ts +14 -0
  30. package/dist/src/redis-connector.d.ts.map +1 -1
  31. package/dist/src/redis-connector.js +60 -0
  32. package/dist/src/redis-connector.js.map +1 -1
  33. package/dist/src/shopify-oidc.d.ts +31 -0
  34. package/dist/src/shopify-oidc.d.ts.map +1 -0
  35. package/dist/src/shopify-oidc.js +80 -0
  36. package/dist/src/shopify-oidc.js.map +1 -0
  37. package/dist/src/shopify-session.d.ts +89 -0
  38. package/dist/src/shopify-session.d.ts.map +1 -0
  39. package/dist/src/shopify-session.js +251 -0
  40. package/dist/src/shopify-session.js.map +1 -0
  41. package/dist/src/tenant-config.d.ts.map +1 -1
  42. package/dist/src/tenant-config.js +3 -1
  43. package/dist/src/tenant-config.js.map +1 -1
  44. package/dist/src/tenant-types.d.ts +7 -0
  45. package/dist/src/tenant-types.d.ts.map +1 -1
  46. package/package.json +1 -1
@@ -42,6 +42,18 @@ export declare function updateCartLines(siteName: string, cartId: string, lines:
42
42
  * resulting order's custom attributes.
43
43
  */
44
44
  export declare function linkCartToCustomer(siteName: string, cartId: string, customerId: string): Promise<ShopifyCart>;
45
+ /**
46
+ * Links a cart to the logged-in customer in Shopify itself, with Storefront `cartBuyerIdentityUpdate` and the
47
+ * customer's Customer Account access token passed as `buyerIdentity.customerAccessToken`. The cart's
48
+ * `checkoutUrl` then opens checkout already signed in as that customer.
49
+ *
50
+ * The token must be passed explicitly: it is not picked up from a header. Shopify accepts the Customer Account
51
+ * API token in that field (confirmed on kiwi). For the authoring flow, which has no such token, keep using
52
+ * {@link linkCartToCustomer}.
53
+ *
54
+ * Throws {@link ShopifyCustomerTokenError} when Shopify rejects the token ("Customer is invalid").
55
+ */
56
+ export declare function linkCartToCustomerAccount(siteName: string, cartId: string, customerAccessToken: string): Promise<ShopifyCart>;
45
57
  /** Remove lines from a cart by line ID. */
46
58
  export declare function removeCartLines(siteName: string, cartId: string, lineIds: string[]): Promise<ShopifyCart>;
47
59
  //# sourceMappingURL=cart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cart.d.ts","sourceRoot":"","sources":["../../src/cart.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,KAA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AC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAqBjH;AAED,kDAAkD;AAClD,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,mBAAmB,EAAE,GAC3B,OAAO,CAAC,WAAW,CAAC,CAqBtB;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAqBnH;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,MAAM,GAC1B,OAAO,CAAC,WAAW,CAAC,CAyBtB;AAED,2CAA2C;AAC3C,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAqB/G"}
package/dist/src/cart.js CHANGED
@@ -5,6 +5,7 @@ exports.getCart = getCart;
5
5
  exports.addCartLines = addCartLines;
6
6
  exports.updateCartLines = updateCartLines;
7
7
  exports.linkCartToCustomer = linkCartToCustomer;
8
+ exports.linkCartToCustomerAccount = linkCartToCustomerAccount;
8
9
  exports.removeCartLines = removeCartLines;
9
10
  const client_1 = require("./client");
10
11
  const errors_1 = require("./errors");
@@ -155,6 +156,41 @@ async function linkCartToCustomer(siteName, cartId, customerId) {
155
156
  }
156
157
  return mapCart(data.cartAttributesUpdate.cart);
157
158
  }
159
+ /**
160
+ * Links a cart to the logged-in customer in Shopify itself, with Storefront `cartBuyerIdentityUpdate` and the
161
+ * customer's Customer Account access token passed as `buyerIdentity.customerAccessToken`. The cart's
162
+ * `checkoutUrl` then opens checkout already signed in as that customer.
163
+ *
164
+ * The token must be passed explicitly: it is not picked up from a header. Shopify accepts the Customer Account
165
+ * API token in that field (confirmed on kiwi). For the authoring flow, which has no such token, keep using
166
+ * {@link linkCartToCustomer}.
167
+ *
168
+ * Throws {@link ShopifyCustomerTokenError} when Shopify rejects the token ("Customer is invalid").
169
+ */
170
+ async function linkCartToCustomerAccount(siteName, cartId, customerAccessToken) {
171
+ const mutation = `
172
+ ${CART_FRAGMENT}
173
+ mutation CartBuyerIdentityUpdate($cartId: ID!, $buyerIdentity: CartBuyerIdentityInput!) {
174
+ cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) {
175
+ cart { ...CartFields }
176
+ userErrors { field message code }
177
+ }
178
+ }
179
+ `;
180
+ const data = await (0, client_1.storefrontGraphql)(siteName, mutation, {
181
+ cartId,
182
+ buyerIdentity: { customerAccessToken },
183
+ });
184
+ const { cart, userErrors } = data.cartBuyerIdentityUpdate;
185
+ if (userErrors.some((err) => err.field?.includes('customerAccessToken'))) {
186
+ throw new errors_1.ShopifyCustomerTokenError('Shopify rejected the customer access token for the cart', { userErrors });
187
+ }
188
+ ensureNoUserErrors(userErrors, 'Failed to link cart to customer');
189
+ if (!cart) {
190
+ throw new errors_1.ShopifyUserErrorsError('Failed to link cart to customer', userErrors);
191
+ }
192
+ return mapCart(cart);
193
+ }
158
194
  /** Remove lines from a cart by line ID. */
159
195
  async function removeCartLines(siteName, cartId, lineIds) {
160
196
  const mutation = `
@@ -1 +1 @@
1
- {"version":3,"file":"cart.js","sourceRoot":"","sources":["../../src/cart.ts"],"names":[],"mappings":";;AA0GA,gCAoBC;AAGD,0BAUC;AAGD,oCAqBC;AAGD,0CAyBC;AAUD,gDAqBC;AAGD,0CAqBC;AAtPD,qCAA6C;AAC7C,qCAAyE;AAuDzE,sFAAsF;AACtF,iFAAiF;AACjF,gDAAgD;AAChD,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBrB,CAAC;AAEF,S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GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,kCAAyB,CAAC,yDAAyD,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACjH,CAAC;IACD,kBAAkB,CAAC,UAAU,EAAE,iCAAiC,CAAC,CAAC;IAClE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,+BAAsB,CAAC,iCAAiC,EAAE,UAAU,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC;AAED,2CAA2C;AACpC,KAAK,UAAU,eAAe,CAAC,QAAgB,EAAE,MAAc,EAAE,OAAiB;IACvF,MAAM,QAAQ,GAAG;MACb,aAAa;;;;;;;GAOhB,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,IAAA,0BAAiB,EAA2C,QAAQ,EAAE,QAAQ,EAAE;QACjG,MAAM;QACN,OAAO;KACR,CAAC,CAAC;IAEH,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC;IACnF,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,IAAI,+BAAsB,CAAC,6BAA6B,EAAE,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,11 @@
1
+ import './tls-trust';
2
+ /** `https://shopify.com/{shopId}/account/customer/api/{version}/graphql`, the shop id taken from OIDC discovery. */
3
+ export declare function customerAccountEndpoint(siteName: string): Promise<string>;
4
+ /**
5
+ * Runs a Customer Account API query or mutation as the customer who owns `accessToken`.
6
+ *
7
+ * Throws {@link ShopifyCustomerTokenError} when Shopify rejects the token, and
8
+ * `ShopifyAdapterError` for any other failure, including GraphQL `errors`.
9
+ */
10
+ export declare function customerAccountGraphql<T = unknown>(siteName: string, accessToken: string, query: string, variables?: Record<string, unknown>): Promise<T>;
11
+ //# sourceMappingURL=customer-account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customer-account.d.ts","sourceRoot":"","sources":["../../src/customer-account.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AA4BrB,oHAAoH;AACpH,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAa/E;AA2BD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,GAAG,OAAO,EACtD,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC,CAwBZ"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.customerAccountEndpoint = customerAccountEndpoint;
4
+ exports.customerAccountGraphql = customerAccountGraphql;
5
+ require("./tls-trust");
6
+ const errors_1 = require("./errors");
7
+ const resilience_1 = require("./resilience");
8
+ const shopify_oidc_1 = require("./shopify-oidc");
9
+ const tenant_config_1 = require("./tenant-config");
10
+ /**
11
+ * Client for Shopify's Customer Account API: the logged-in customer's own
12
+ * data (profile, addresses, orders), called with that customer's access token.
13
+ *
14
+ * Unlike `getGraphQLClient`, nothing is cached per token: every call carries
15
+ * the token it was given. The token goes in `Authorization` exactly as
16
+ * Shopify issued it, with no `Bearer` prefix (confirmed against kiwi: a
17
+ * `Bearer`-prefixed token is rejected with "missing prefix shcat_").
18
+ */
19
+ const REQUEST_TIMEOUT_MS = 15_000;
20
+ // Separate from the Admin and Storefront breakers. Only server errors and network
21
+ // failures count against it, never one visitor's rejected token.
22
+ const breaker = new resilience_1.CircuitBreaker(5, 30_000, 'shopify-customer-account');
23
+ /** `https://shopify.com/{shopId}/account/customer/api/{version}/graphql`, the shop id taken from OIDC discovery. */
24
+ async function customerAccountEndpoint(siteName) {
25
+ const { shopify } = await (0, tenant_config_1.getTenantConfig)(siteName);
26
+ let discovery;
27
+ try {
28
+ discovery = await (0, shopify_oidc_1.discoverShopifyEndpoints)(shopify.storeDomain);
29
+ }
30
+ catch (err) {
31
+ if (err instanceof shopify_oidc_1.ShopifyOidcError)
32
+ throw new errors_1.ShopifyAdapterError(err.message, { status: err.status });
33
+ throw err;
34
+ }
35
+ const shopId = discovery.issuer?.split('/').filter(Boolean).pop();
36
+ if (!shopId)
37
+ throw new errors_1.ShopifyAdapterError('Shopify discovery document has no issuer, cannot build the Customer Account API URL');
38
+ const version = process.env.CUSTOMER_ACCOUNT_API_VERSION || shopify.storefrontApiVersion;
39
+ return `https://shopify.com/${shopId}/account/customer/api/${version}/graphql`;
40
+ }
41
+ async function post(url, accessToken, query, variables) {
42
+ let res;
43
+ try {
44
+ res = await fetch(url, {
45
+ method: 'POST',
46
+ headers: { 'Content-Type': 'application/json', Authorization: accessToken },
47
+ body: JSON.stringify({ query, variables }),
48
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
49
+ });
50
+ }
51
+ catch (err) {
52
+ throw new errors_1.ShopifyAdapterError(`Unable to reach the Shopify Customer Account API: ${err instanceof Error ? err.message : String(err)}`);
53
+ }
54
+ // 429 and 5xx are retried and counted by the breaker; anything else is the caller's to interpret.
55
+ if (res.status === 429 || res.status >= 500) {
56
+ throw new errors_1.ShopifyAdapterError(`Shopify Customer Account API returned ${res.status}`, { status: res.status });
57
+ }
58
+ let body;
59
+ try {
60
+ body = (await res.json());
61
+ }
62
+ catch {
63
+ body = undefined;
64
+ }
65
+ return { status: res.status, body };
66
+ }
67
+ /**
68
+ * Runs a Customer Account API query or mutation as the customer who owns `accessToken`.
69
+ *
70
+ * Throws {@link ShopifyCustomerTokenError} when Shopify rejects the token, and
71
+ * `ShopifyAdapterError` for any other failure, including GraphQL `errors`.
72
+ */
73
+ async function customerAccountGraphql(siteName, accessToken, query, variables) {
74
+ const url = await customerAccountEndpoint(siteName);
75
+ const response = await breaker.call(() => (0, resilience_1.withTimeout)(() => (0, resilience_1.withRetry)(() => post(url, accessToken, query, variables), 3, 300, () => true), REQUEST_TIMEOUT_MS * 3));
76
+ if (response.status === 401 || response.status === 403) {
77
+ throw new errors_1.ShopifyCustomerTokenError(undefined, { status: response.status });
78
+ }
79
+ const errors = response.body?.errors;
80
+ if (errors && errors.length > 0) {
81
+ // An ACCESS_DENIED error code means the token is not valid for this call, the same outcome as a 401.
82
+ if (errors.some((err) => err.extensions?.code === 'ACCESS_DENIED' || err.extensions?.code === 'UNAUTHENTICATED')) {
83
+ throw new errors_1.ShopifyCustomerTokenError(undefined, { errors });
84
+ }
85
+ throw new errors_1.ShopifyAdapterError(errors.map((err) => err.message).filter(Boolean).join('; ') || 'Customer Account API error', {
86
+ status: response.status,
87
+ errors,
88
+ });
89
+ }
90
+ if (response.status < 200 || response.status >= 300 || !response.body) {
91
+ throw new errors_1.ShopifyAdapterError(`Shopify Customer Account API returned ${response.status}`, { status: response.status });
92
+ }
93
+ return response.body.data;
94
+ }
95
+ //# sourceMappingURL=customer-account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customer-account.js","sourceRoot":"","sources":["../../src/customer-account.ts"],"names":[],"mappings":";;AA6BA,0DAaC;AAiCD,wDA6BC;AAxGD,uBAAqB;AAErB,qCAA0E;AAC1E,6CAAsE;AACtE,iDAA4E;AAC5E,mDAAkD;AAElD;;;;;;;;GAQG;AAEH,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,kFAAkF;AAClF,iEAAiE;AACjE,MAAM,OAAO,GAAG,IAAI,2BAAc,CAAC,CAAC,EAAE,MAAM,EAAE,0BAA0B,CAAC,CAAC;AAO1E,oHAAoH;AAC7G,KAAK,UAAU,uBAAuB,CAAC,QAAgB;IAC5D,MAAM,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AAI,kCAAyB,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACrC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,qGAAqG;QACrG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,KAAK,eAAe,IAAI,GAAG,CAAC,UAAU,EAAE,IAAI,KAAK,iBAAiB,CAAC,EAAE,CAAC;YACjH,MAAM,IAAI,kCAAyB,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7D,CAAC;QACD,MAAM,IAAI,4BAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,4BAA4B,EAAE;YACzH,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtE,MAAM,IAAI,4BAAmB,CAAC,yCAAyC,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACzH,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAS,CAAC;AACjC,CAAC"}
@@ -1,5 +1,20 @@
1
- import { Router } from 'express';
1
+ import type { NextFunction, Request, Response as ExpressResponse } from 'express';
2
+ export declare const SESSION_TTL_SECONDS: number;
2
3
  export declare const SESSION_COOKIE_NAME = "shp_delivery_sid";
4
+ /**
5
+ * The logged-in website visitor a Shopify session is being created for. When
6
+ * present the callback stores the tokens under the gateway session id and sets
7
+ * no cookie; when absent the legacy cookie flow runs.
8
+ */
9
+ export interface GatewaySessionIdentity {
10
+ /** The gateway's `platform-x-session` id. */
11
+ sessionId: string;
12
+ /** Keycloak `sub` of the logged-in user. */
13
+ sub: string;
14
+ /** Keycloak email, compared with the email Shopify returns. */
15
+ email: string;
16
+ }
17
+ export declare const EMAIL_MISMATCH_ERROR = "delivery_sso_email_mismatch";
3
18
  export interface MintedSession {
4
19
  accessToken: string;
5
20
  expiresIn: number;
@@ -10,35 +25,83 @@ export interface MintedSession {
10
25
  }
11
26
  export interface DeliverySsoConfig {
12
27
  /**
13
- * Public base URL this module's Shopify-callback route is reachable at —
14
- * e.g. `https://dev.hep-ecommerce-service.hcl-x.com/hep-ecommerce-service/delivery/auth`.
15
- * `/shopify/callback` is appended to build the `redirect_uri` sent to
28
+ * Public base URL the shared callback route is reachable at — e.g.
29
+ * `https://dev.hep-ecommerce-service.hcl-x.com/ecommerce/delivery/auth`
30
+ * (or, once fronted by a gateway, that gateway's public host with the same
31
+ * path suffix). `/callback` is appended to build the `redirect_uri` sent to
16
32
  * Shopify, which must exactly match what's registered in the Customer
17
- * Account API app's allowed redirect URIs.
33
+ * Account API app's allowed redirect URIs. This one path is shared across
34
+ * every commerce provider — see the module doc comment above.
18
35
  */
19
36
  callbackBaseUrl: string;
20
37
  /**
21
38
  * Path the router below is mounted at (e.g.
22
- * `/hep-ecommerce-service/delivery/auth`) — used only to scope the session
39
+ * `/ecommerce/delivery/auth`) — used only to scope the session
23
40
  * cookie, so it isn't sent on unrelated routes.
24
41
  */
25
42
  sessionCookiePath: string;
26
43
  /** Allow-list `beginDeliverySso`'s `returnUrl` and the session/logout endpoints' CORS are locked to. */
27
44
  allowedReturnOrigins: string[];
28
45
  }
29
- /** Step 1: validate returnUrl, stash PKCE/nonce under a fresh `state`, and build Shopify's own authorize URL. */
30
- export declare function beginDeliverySso(siteName: string, returnUrl: string, config: DeliverySsoConfig): Promise<{
46
+ export declare class HttpError extends Error {
47
+ readonly statusCode: number;
48
+ readonly details?: Record<string, unknown> | undefined;
49
+ constructor(statusCode: number, message: string, details?: Record<string, unknown> | undefined);
50
+ }
51
+ /**
52
+ * Step 1: validate returnUrl, stash PKCE/nonce under a fresh `state`, and build Shopify's own authorize URL.
53
+ *
54
+ * Pass `gatewaySession` for a logged-in website visitor: the callback then
55
+ * stores the Shopify tokens under that gateway session id and sets no cookie.
56
+ */
57
+ export declare function beginDeliverySso(siteName: string, returnUrl: string, config: DeliverySsoConfig, gatewaySession?: GatewaySessionIdentity): Promise<{
31
58
  authorizeUrl: string;
32
59
  }>;
33
60
  /**
34
- * Express router exposing the 3 HTTP legs of delivery SSO: Shopify's own
35
- * callback (GET `/shopify/callback`), and the SPA's own credentialed calls
36
- * to mint (POST `/session`) and end (POST `/logout`) a bearer. Mount this at
37
- * `config.callbackBaseUrl`'s path (e.g.
38
- * `/hep-ecommerce-service/delivery/auth`) so the routes resolve to exactly
39
- * the URLs `config` describes. `beginDeliverySso` is a plain function, not a
40
- * route here — call it from your own GraphQL/REST mutation, same as every
41
- * other write in this package.
61
+ * Step 2 (Shopify's redirect back to us — the only callback in this flow):
62
+ * exchange `code` + PKCE verifier for a Shopify Customer Account API token
63
+ * pair, resolve the Shopify customer id from the ID token Shopify hands
64
+ * back, and open a new session. For the legacy cookie flow returns the
65
+ * session id (prefixed, same as `state` above) so the caller can set it as an
66
+ * HttpOnly cookie. For a gateway-session flow (see {@link beginDeliverySso})
67
+ * the tokens are stored under the gateway session id and `sessionId` is absent:
68
+ * no cookie is set. If the Shopify email differs from the Keycloak email,
69
+ * nothing is stored and the redirect carries `error=delivery_sso_email_mismatch`.
70
+ *
71
+ * `rawState` is this provider's own unprefixed value — the shared callback
72
+ * route is expected to have already stripped the `"shopify."` prefix off
73
+ * the `state` query param before calling in here.
74
+ */
75
+ export declare function handleShopifyOAuthCallback(code: string, rawState: string, config: DeliverySsoConfig): Promise<{
76
+ redirectUrl: string;
77
+ sessionId?: string;
78
+ }>;
79
+ /**
80
+ * Called right after the callback above (frontend's very first call, to get
81
+ * its initial bearer) and later, on demand, to re-mint the bearer before it
82
+ * expires. Reads the session purely from the opaque `sessionId` (the
83
+ * cookie's value, with the `"shopify."` prefix already stripped by the
84
+ * caller) — no tenant header needed, since `siteName` lives inside the
85
+ * record.
86
+ */
87
+ export declare function mintShopifySession(rawSessionId: string): Promise<MintedSession>;
88
+ /** Idempotent — logging out twice is a no-op the second time. `rawSessionId` is unprefixed, same as {@link mintShopifySession}. */
89
+ export declare function logoutShopifySession(rawSessionId: string): Promise<void>;
90
+ /** Extracts the `returnUrl` an {@link HttpError} thrown by this module may carry, for an error-page redirect. */
91
+ export declare function errorReturnUrl(err: unknown): string | undefined;
92
+ /**
93
+ * Forces a CORS preflight (a custom header can't be set by a simple
94
+ * cross-site form submission, and only an allow-listed origin's own script
95
+ * can set it after that preflight succeeds) — combined with the per-request
96
+ * origin check below and the cookie's `SameSite=None`, this is the
97
+ * session/logout endpoints' CSRF defense.
98
+ */
99
+ export declare function requireCsrfHeader(req: Request, res: ExpressResponse, next: NextFunction): void;
100
+ /**
101
+ * Locks CORS on the session/logout routes to `config.allowedReturnOrigins`,
102
+ * with credentials enabled (the cookie must ride along). No `cors` package
103
+ * dependency — this package stays dependency-light; the allow-list check and
104
+ * preflight response are both this simple.
42
105
  */
43
- export declare function createDeliverySsoRouter(config: DeliverySsoConfig): Router;
106
+ export declare function sessionCors(config: DeliverySsoConfig): (req: Request, res: ExpressResponse, next: NextFunction) => void;
44
107
  //# sourceMappingURL=delivery-sso.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delivery-sso.d.ts","sourceRoot":"","sources":["../../src/delivery-sso.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAqE,MAAM,SAAS,CAAC;AA8CpG,eAAO,MAAM,mBAAmB,qBAAqB,CAAC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