@platform-x-shp/shopify-adapter 0.0.0-stage → 0.3.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 (94) hide show
  1. package/README.md +42 -2
  2. package/dist/src/cart.d.ts +47 -0
  3. package/dist/src/cart.d.ts.map +1 -0
  4. package/dist/src/cart.js +179 -0
  5. package/dist/src/cart.js.map +1 -0
  6. package/dist/src/client.d.ts +13 -0
  7. package/dist/src/client.d.ts.map +1 -0
  8. package/dist/src/client.js +66 -0
  9. package/dist/src/client.js.map +1 -0
  10. package/dist/src/config-provider.d.ts +17 -0
  11. package/dist/src/config-provider.d.ts.map +1 -0
  12. package/dist/src/config-provider.js +54 -0
  13. package/dist/src/config-provider.js.map +1 -0
  14. package/dist/src/customers.d.ts +19 -0
  15. package/dist/src/customers.d.ts.map +1 -0
  16. package/dist/src/customers.js +62 -0
  17. package/dist/src/customers.js.map +1 -0
  18. package/dist/src/errors.d.ts +17 -0
  19. package/dist/src/errors.d.ts.map +1 -0
  20. package/dist/src/errors.js +32 -0
  21. package/dist/src/errors.js.map +1 -0
  22. package/dist/src/extract-site-name.d.ts +15 -0
  23. package/dist/src/extract-site-name.d.ts.map +1 -0
  24. package/dist/src/extract-site-name.js +26 -0
  25. package/dist/src/extract-site-name.js.map +1 -0
  26. package/dist/src/graphql-client.d.ts +16 -0
  27. package/dist/src/graphql-client.d.ts.map +1 -0
  28. package/dist/src/graphql-client.js +58 -0
  29. package/dist/src/graphql-client.js.map +1 -0
  30. package/dist/src/hep-secret-provider.d.ts +18 -0
  31. package/dist/src/hep-secret-provider.d.ts.map +1 -0
  32. package/dist/src/hep-secret-provider.js +29 -0
  33. package/dist/src/hep-secret-provider.js.map +1 -0
  34. package/dist/src/index.d.ts +52 -0
  35. package/dist/src/index.d.ts.map +1 -0
  36. package/dist/src/index.js +98 -0
  37. package/dist/src/index.js.map +1 -0
  38. package/dist/src/keycloak-auth.d.ts +74 -0
  39. package/dist/src/keycloak-auth.d.ts.map +1 -0
  40. package/dist/src/keycloak-auth.js +123 -0
  41. package/dist/src/keycloak-auth.js.map +1 -0
  42. package/dist/src/messaging.d.ts +21 -0
  43. package/dist/src/messaging.d.ts.map +1 -0
  44. package/dist/src/messaging.js +11 -0
  45. package/dist/src/messaging.js.map +1 -0
  46. package/dist/src/orders.d.ts +57 -0
  47. package/dist/src/orders.d.ts.map +1 -0
  48. package/dist/src/orders.js +112 -0
  49. package/dist/src/orders.js.map +1 -0
  50. package/dist/src/platformx-auth.d.ts +51 -0
  51. package/dist/src/platformx-auth.d.ts.map +1 -0
  52. package/dist/src/platformx-auth.js +84 -0
  53. package/dist/src/platformx-auth.js.map +1 -0
  54. package/dist/src/products.d.ts +31 -0
  55. package/dist/src/products.d.ts.map +1 -0
  56. package/dist/src/products.js +92 -0
  57. package/dist/src/products.js.map +1 -0
  58. package/dist/src/redis-connector.d.ts +17 -0
  59. package/dist/src/redis-connector.d.ts.map +1 -0
  60. package/dist/src/redis-connector.js +227 -0
  61. package/dist/src/redis-connector.js.map +1 -0
  62. package/dist/src/resilience.d.ts +40 -0
  63. package/dist/src/resilience.d.ts.map +1 -0
  64. package/dist/src/resilience.js +124 -0
  65. package/dist/src/resilience.js.map +1 -0
  66. package/dist/src/tenant-config.d.ts +34 -0
  67. package/dist/src/tenant-config.d.ts.map +1 -0
  68. package/dist/src/tenant-config.js +285 -0
  69. package/dist/src/tenant-config.js.map +1 -0
  70. package/dist/src/tenant-errors.d.ts +16 -0
  71. package/dist/src/tenant-errors.d.ts.map +1 -0
  72. package/dist/src/tenant-errors.js +41 -0
  73. package/dist/src/tenant-errors.js.map +1 -0
  74. package/dist/src/tenant-types.d.ts +68 -0
  75. package/dist/src/tenant-types.d.ts.map +1 -0
  76. package/dist/src/tenant-types.js +3 -0
  77. package/dist/src/tenant-types.js.map +1 -0
  78. package/dist/src/tls-trust.d.ts +2 -0
  79. package/dist/src/tls-trust.d.ts.map +1 -0
  80. package/dist/src/tls-trust.js +27 -0
  81. package/dist/src/tls-trust.js.map +1 -0
  82. package/dist/src/utils/logger.d.ts +8 -0
  83. package/dist/src/utils/logger.d.ts.map +1 -0
  84. package/dist/src/utils/logger.js +108 -0
  85. package/dist/src/utils/logger.js.map +1 -0
  86. package/dist/src/webhookTopics.d.ts +31 -0
  87. package/dist/src/webhookTopics.d.ts.map +1 -0
  88. package/dist/src/webhookTopics.js +38 -0
  89. package/dist/src/webhookTopics.js.map +1 -0
  90. package/dist/src/webhooks.d.ts +59 -0
  91. package/dist/src/webhooks.d.ts.map +1 -0
  92. package/dist/src/webhooks.js +223 -0
  93. package/dist/src/webhooks.js.map +1 -0
  94. package/package.json +58 -4
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # shopify-adapter
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shopify commerce adapter: a plain Admin API client library plus read-model mappers, consumed by `hep-ecommerce-service`'s outbound adapter layer. No Express app of its own — structured to mirror [`hep-observability`](https://github.com/hcl-x/hep-observability) (flat `src/*.ts` by concern, single `index.ts` barrel, published scoped npm package).
4
+
5
+ Callers pass `siteName` explicitly to every function — unlike the 5 legacy `shp-*` microservices, this library has no request-scoped site context of its own.
6
+
7
+ **Self-contained — does not depend on `@platform-x-shp/shp-auth-client`.** That package is scoped to the 5 legacy microservices; this stack is meant to be fully independent of them. Everything this package needs from it was ported in directly rather than taken as a dependency:
8
+
9
+ - `tenant-config.ts` + `redis-connector.ts` + `config-provider.ts`/`hep-secret-provider.ts` — Redis-cached tenant config, backed by GCP Secret Manager/env (via `hep-secret-access`, same as the legacy services)
10
+ - `keycloak-auth.ts` / `platformx-auth.ts` — the same Keycloak + PlatformX JWT verification `hep-ecommerce-service`'s auth relies on
11
+ - `client.ts` — the resilient GraphQL wrapper (breaker/retry/timeout), now calling the locally-ported `graphql-client.ts` directly instead of an external `resilientGraphqlRequest`
12
+
13
+ Redis cache keys use their own `shopify-adapter:*` prefix (not `shp-auth-client:*`), so this package's cache never collides with the legacy services' — they're independent, even though both may point at the same Redis instance and read the same underlying secrets.
14
+
15
+ 102 tests cover this, including the full ported `shp-auth-client` test suites for tenant-config/keycloak-auth/platformx-auth/config-provider/resilience — not just the Shopify-specific capabilities.
16
+
17
+ ## Status
18
+
19
+ **Products** (Admin API) and **Cart** (Storefront API) are implemented, as the first two vertical slices through the new hexagonal `hep-ecommerce-service` / `shopify-adapter` stack:
20
+
21
+ - `fetchProducts(siteName, first?, after?)`, `fetchProductById(siteName, productId)`, `fetchProductByIdOrThrow(siteName, productId)`
22
+ - `createCart(siteName, lines?)`, `getCart(siteName, cartId)`, `addCartLines`, `updateCartLines`, `removeCartLines`
23
+
24
+ - `listOrders(siteName, opts?)`, `getOrderById(siteName, orderId)`
25
+ - `getCustomerById(siteName, customerId)`, `getCustomerByEmail(siteName, email)`
26
+ - `messaging.ts`: typed event shapes (currently just `CartCreatedEvent`) and a `Publish` function type — no amqplib dependency here; `hep-ecommerce-service` owns the actual RabbitMQ connection and injects a `publish` function.
27
+ - **Order webhooks**: `createShopifyWebhookRouter(onVerified)` — an Express router handling Shopify's `POST /shopify/:siteName` callback (HMAC-SHA256 verified against the tenant's `webhookHmacSecret`, raw-body read manually since the signature covers the exact bytes Shopify sent). No event store or message-bus connection of its own — same "caller decides what to do" shape as `messaging.ts`: `onVerified(event)` is called once per verified webhook, with `event.routingKey` pre-mapped via `shopifyTopicToRoutingKey` (`null` for a non-order topic, still worth recording, just not forwarding). `registerShopifyWebhooks({ siteNames, callbackUrlBase })` idempotently subscribes the order topics via the Admin API; whether/when to call it is the caller's deployment decision, not read from env here.
28
+
29
+ Cart is intentionally smaller than `shp-cart-service`'s original: no `buyerIdentity`, `discountCodes`, `attributes`/`note`, `deleteCart`, or `validateCheckout` yet. Orders has no refunds/fulfillments/transactions yet. Customers has no signup/login/address mutations yet. Webhooks cover only the order topics (`ORDER_WEBHOOK_TOPICS`) — no product/customer/app topics yet. All extend their respective files the same way, following `shp-order-service` / `shp-customer-service` / `shp-auth-service`.
30
+
31
+ ## Scripts
32
+
33
+ - `npm run build` — compile to `dist/`
34
+ - `npm test` — run the Jest suite
35
+ - `npm run lint` — ESLint
36
+
37
+ ## Node
38
+
39
+ Targets Node 22 (current Active LTS) — see the scoping doc for why this doesn't match `hep-api-gateway`/`hep-cx-delivery-api-service`'s current Node 18 pin.
40
+
41
+ ## Secrets / env
42
+
43
+ Reads the same shape of secrets/env vars the legacy services do (`${SITENAME}_SHOPIFY_*` via Secret Manager or `.env`, `KEYCLOCK_HOST`, `REDIS_HOST`/`REDIS_PORT`, `SECRET_MODE`, `GOOGLE_PROJECT_ID` in production) — this is a parallel reader of the same tenant config, not a new provisioning path. `AUTH_TENANTS_INFO` and the `${SITENAME}_SHOPIFY_PLATFORMX_*` keys are shared secrets read by both this package and `shp-auth-client`.
@@ -0,0 +1,47 @@
1
+ export interface ShopifyMoney {
2
+ amount: string;
3
+ currencyCode: string;
4
+ }
5
+ export interface ShopifyCartLine {
6
+ id: string;
7
+ quantity: number;
8
+ merchandiseId: string;
9
+ title?: string;
10
+ productTitle?: string;
11
+ price?: ShopifyMoney;
12
+ }
13
+ export interface ShopifyCart {
14
+ id: string;
15
+ checkoutUrl: string | null;
16
+ totalQuantity: number;
17
+ totalAmount: ShopifyMoney | null;
18
+ lines: ShopifyCartLine[];
19
+ }
20
+ export interface CartLineInput {
21
+ merchandiseId: string;
22
+ quantity: number;
23
+ }
24
+ export interface CartLineUpdateInput {
25
+ id: string;
26
+ quantity: number;
27
+ }
28
+ /** Create a new cart, optionally with initial lines. */
29
+ export declare function createCart(siteName: string, lines?: CartLineInput[]): Promise<ShopifyCart>;
30
+ /** Fetch a cart by ID; `null` if it doesn't exist (expired carts return null from Shopify). */
31
+ export declare function getCart(siteName: string, cartId: string): Promise<ShopifyCart | null>;
32
+ /** Add one or more lines to an existing cart. */
33
+ export declare function addCartLines(siteName: string, cartId: string, lines: CartLineInput[]): Promise<ShopifyCart>;
34
+ /** Update the quantity of existing cart lines. */
35
+ export declare function updateCartLines(siteName: string, cartId: string, lines: CartLineUpdateInput[]): Promise<ShopifyCart>;
36
+ /**
37
+ * Links a cart to a signed-in customer so the resulting order carries their
38
+ * identity. Shopify's own `cartBuyerIdentityUpdate` wants a real Storefront
39
+ * `customerAccessToken`, which a PlatformX/Keycloak bearer isn't — so, same
40
+ * as shp-cart-service's `linkCartToCustomer`, this records it as a
41
+ * `customer_id` cart attribute instead, which carries through onto the
42
+ * resulting order's custom attributes.
43
+ */
44
+ export declare function linkCartToCustomer(siteName: string, cartId: string, customerId: string): Promise<ShopifyCart>;
45
+ /** Remove lines from a cart by line ID. */
46
+ export declare function removeCartLines(siteName: string, cartId: string, lineIds: string[]): Promise<ShopifyCart>;
47
+ //# sourceMappingURL=cart.d.ts.map
@@ -0,0 +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,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,YAAY,GAAG,IAAI,CAAC;IACjC,KAAK,EAAE,eAAe,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CAClB;AAwED,wDAAwD;AACxD,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAoBhG;AAED,+FAA+F;AAC/F,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAU3F;AAED,iDAAiD;AACjD,wBAAsB,YAAY,CAAC,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,2CAA2C;AAC3C,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAqB/G"}
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCart = createCart;
4
+ exports.getCart = getCart;
5
+ exports.addCartLines = addCartLines;
6
+ exports.updateCartLines = updateCartLines;
7
+ exports.linkCartToCustomer = linkCartToCustomer;
8
+ exports.removeCartLines = removeCartLines;
9
+ const client_1 = require("./client");
10
+ const errors_1 = require("./errors");
11
+ // Kept intentionally smaller than shp-cart-service's full fragment (no buyerIdentity,
12
+ // discountCodes, attributes/note) — this is the first Cart slice through the new
13
+ // stack; those extend the same way once ported.
14
+ const CART_FRAGMENT = `
15
+ fragment CartFields on Cart {
16
+ id
17
+ checkoutUrl
18
+ totalQuantity
19
+ cost { totalAmount { amount currencyCode } }
20
+ lines(first: 100) {
21
+ nodes {
22
+ id
23
+ quantity
24
+ merchandise {
25
+ ... on ProductVariant {
26
+ id
27
+ title
28
+ price { amount currencyCode }
29
+ product { title }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ `;
36
+ function mapCart(raw) {
37
+ return {
38
+ id: raw.id,
39
+ checkoutUrl: raw.checkoutUrl ?? null,
40
+ totalQuantity: raw.totalQuantity ?? 0,
41
+ totalAmount: raw.cost?.totalAmount ?? null,
42
+ lines: (raw.lines?.nodes ?? []).map((line) => ({
43
+ id: line.id,
44
+ quantity: line.quantity,
45
+ merchandiseId: line.merchandise?.id ?? '',
46
+ title: line.merchandise?.title,
47
+ productTitle: line.merchandise?.product?.title ?? undefined,
48
+ price: line.merchandise?.price,
49
+ })),
50
+ };
51
+ }
52
+ function ensureNoUserErrors(errors, message) {
53
+ if (errors.length > 0) {
54
+ throw new errors_1.ShopifyUserErrorsError(message, errors);
55
+ }
56
+ }
57
+ /** Create a new cart, optionally with initial lines. */
58
+ async function createCart(siteName, lines) {
59
+ const mutation = `
60
+ ${CART_FRAGMENT}
61
+ mutation CartCreate($input: CartInput) {
62
+ cartCreate(input: $input) {
63
+ cart { ...CartFields }
64
+ userErrors { field message }
65
+ }
66
+ }
67
+ `;
68
+ const data = await (0, client_1.storefrontGraphql)(siteName, mutation, {
69
+ input: lines ? { lines } : undefined,
70
+ });
71
+ ensureNoUserErrors(data.cartCreate.userErrors, 'Failed to create cart');
72
+ if (!data.cartCreate.cart) {
73
+ throw new errors_1.ShopifyUserErrorsError('Failed to create cart', data.cartCreate.userErrors);
74
+ }
75
+ return mapCart(data.cartCreate.cart);
76
+ }
77
+ /** Fetch a cart by ID; `null` if it doesn't exist (expired carts return null from Shopify). */
78
+ async function getCart(siteName, cartId) {
79
+ const query = `
80
+ ${CART_FRAGMENT}
81
+ query GetCart($id: ID!) {
82
+ cart(id: $id) { ...CartFields }
83
+ }
84
+ `;
85
+ const data = await (0, client_1.storefrontGraphql)(siteName, query, { id: cartId });
86
+ return data.cart ? mapCart(data.cart) : null;
87
+ }
88
+ /** Add one or more lines to an existing cart. */
89
+ async function addCartLines(siteName, cartId, lines) {
90
+ const mutation = `
91
+ ${CART_FRAGMENT}
92
+ mutation CartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {
93
+ cartLinesAdd(cartId: $cartId, lines: $lines) {
94
+ cart { ...CartFields }
95
+ userErrors { field message }
96
+ }
97
+ }
98
+ `;
99
+ const data = await (0, client_1.storefrontGraphql)(siteName, mutation, {
100
+ cartId,
101
+ lines,
102
+ });
103
+ ensureNoUserErrors(data.cartLinesAdd.userErrors, 'Failed to add cart lines');
104
+ if (!data.cartLinesAdd.cart) {
105
+ throw new errors_1.ShopifyUserErrorsError('Failed to add cart lines', data.cartLinesAdd.userErrors);
106
+ }
107
+ return mapCart(data.cartLinesAdd.cart);
108
+ }
109
+ /** Update the quantity of existing cart lines. */
110
+ async function updateCartLines(siteName, cartId, lines) {
111
+ const mutation = `
112
+ ${CART_FRAGMENT}
113
+ mutation CartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
114
+ cartLinesUpdate(cartId: $cartId, lines: $lines) {
115
+ cart { ...CartFields }
116
+ userErrors { field message }
117
+ }
118
+ }
119
+ `;
120
+ const data = await (0, client_1.storefrontGraphql)(siteName, mutation, {
121
+ cartId,
122
+ lines,
123
+ });
124
+ ensureNoUserErrors(data.cartLinesUpdate.userErrors, 'Failed to update cart lines');
125
+ if (!data.cartLinesUpdate.cart) {
126
+ throw new errors_1.ShopifyUserErrorsError('Failed to update cart lines', data.cartLinesUpdate.userErrors);
127
+ }
128
+ return mapCart(data.cartLinesUpdate.cart);
129
+ }
130
+ /**
131
+ * Links a cart to a signed-in customer so the resulting order carries their
132
+ * identity. Shopify's own `cartBuyerIdentityUpdate` wants a real Storefront
133
+ * `customerAccessToken`, which a PlatformX/Keycloak bearer isn't — so, same
134
+ * as shp-cart-service's `linkCartToCustomer`, this records it as a
135
+ * `customer_id` cart attribute instead, which carries through onto the
136
+ * resulting order's custom attributes.
137
+ */
138
+ async function linkCartToCustomer(siteName, cartId, customerId) {
139
+ const mutation = `
140
+ ${CART_FRAGMENT}
141
+ mutation CartAttributesUpdate($cartId: ID!, $attributes: [AttributeInput!]!) {
142
+ cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {
143
+ cart { ...CartFields }
144
+ userErrors { field message }
145
+ }
146
+ }
147
+ `;
148
+ const data = await (0, client_1.storefrontGraphql)(siteName, mutation, {
149
+ cartId,
150
+ attributes: [{ key: 'customer_id', value: customerId }],
151
+ });
152
+ ensureNoUserErrors(data.cartAttributesUpdate.userErrors, 'Failed to link cart to customer');
153
+ if (!data.cartAttributesUpdate.cart) {
154
+ throw new errors_1.ShopifyUserErrorsError('Failed to link cart to customer', data.cartAttributesUpdate.userErrors);
155
+ }
156
+ return mapCart(data.cartAttributesUpdate.cart);
157
+ }
158
+ /** Remove lines from a cart by line ID. */
159
+ async function removeCartLines(siteName, cartId, lineIds) {
160
+ const mutation = `
161
+ ${CART_FRAGMENT}
162
+ mutation CartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {
163
+ cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {
164
+ cart { ...CartFields }
165
+ userErrors { field message }
166
+ }
167
+ }
168
+ `;
169
+ const data = await (0, client_1.storefrontGraphql)(siteName, mutation, {
170
+ cartId,
171
+ lineIds,
172
+ });
173
+ ensureNoUserErrors(data.cartLinesRemove.userErrors, 'Failed to remove cart lines');
174
+ if (!data.cartLinesRemove.cart) {
175
+ throw new errors_1.ShopifyUserErrorsError('Failed to remove cart lines', data.cartLinesRemove.userErrors);
176
+ }
177
+ return mapCart(data.cartLinesRemove.cart);
178
+ }
179
+ //# sourceMappingURL=cart.js.map
@@ -0,0 +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,SAAS,OAAO,CAAC,GAAY;IAC3B,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,IAAI;QACpC,aAAa,EAAE,GAAG,CAAC,aAAa,IAAI,CAAC;QACrC,WAAW,EAAE,GAAG,CAAC,IAAI,EAAE,WAAW,IAAI,IAAI;QAC1C,KAAK,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC7C,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,aAAa,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE;YACzC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK;YAC9B,YAAY,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,IAAI,SAAS;YAC3D,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK;SAC/B,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,MAA0B,EAAE,OAAe;IACrE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,+BAAsB,CAAC,OAAO,EAAE,MA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E,CAAC;KACxD,CAAC,CAAC;IAEH,kBAAkB,CAAC,IAAI,CAAC,oBAAoB,CAAC,UAAU,EAAE,iCAAiC,CAAC,CAAC;IAC5F,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC;QACpC,MAAM,IAAI,+BAAsB,CAAC,iCAAiC,EAAE,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAC5G,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;AACjD,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,13 @@
1
+ export type ShopifyApiType = 'admin' | 'storefront';
2
+ /**
3
+ * Runs a Shopify Admin GraphQL query for `siteName`.
4
+ *
5
+ * Unlike the 5 legacy microservices, this library has no request-scoped site
6
+ * context of its own — callers (hep-ecommerce-service) resolve the tenant
7
+ * and pass `siteName` explicitly, since shopify-adapter is a plain client
8
+ * library, not an Express app.
9
+ */
10
+ export declare function adminGraphql<T = unknown>(siteName: string, query: string, variables?: Record<string, unknown>): Promise<T>;
11
+ /** Same as {@link adminGraphql}, against Shopify's Storefront API — used by Cart (and checkout). */
12
+ export declare function storefrontGraphql<T = unknown>(siteName: string, query: string, variables?: Record<string, unknown>): Promise<T>;
13
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,YAAY,CAAC;AAoEpD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,OAAO,EACtC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED,oGAAoG;AACpG,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,EAC3C,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC,CAAC,CAAC,CAEZ"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adminGraphql = adminGraphql;
4
+ exports.storefrontGraphql = storefrontGraphql;
5
+ const graphql_client_1 = require("./graphql-client");
6
+ const errors_1 = require("./errors");
7
+ const resilience_1 = require("./resilience");
8
+ function defaultIsRetryable(err) {
9
+ if (!(err instanceof graphql_client_1.ClientError))
10
+ return true;
11
+ const status = err.response?.status;
12
+ return status === 429 || (status ?? 0) >= 500;
13
+ }
14
+ // One breaker per API type, shared by every tenant this process serves.
15
+ const breakers = {
16
+ admin: new resilience_1.CircuitBreaker(5, 30_000, 'shopify-admin'),
17
+ storefront: new resilience_1.CircuitBreaker(5, 30_000, 'shopify-storefront'),
18
+ };
19
+ /**
20
+ * Runs a Shopify Admin/Storefront GraphQL query or mutation for a tenant via
21
+ * the shared, cached `getGraphQLClient`, guarded by a per-API-type circuit
22
+ * breaker, retry-with-backoff, and an overall timeout.
23
+ *
24
+ * Previously delegated to `@platform-x-shp/shp-auth-client`'s
25
+ * `resilientGraphqlRequest` — ported in directly (along with tenant-config
26
+ * resolution, Redis caching, and Keycloak/PlatformX verification) so this
27
+ * package doesn't depend on shp-auth-client, which is scoped to the 5
28
+ * legacy `shp-*` services.
29
+ */
30
+ async function resilientGraphqlRequest(siteName, apiType, query, variables) {
31
+ const breaker = breakers[apiType];
32
+ return breaker.call(() => (0, resilience_1.withTimeout)(() => (0, resilience_1.withRetry)(async () => {
33
+ const client = await (0, graphql_client_1.getGraphQLClient)(siteName, apiType);
34
+ return client.request(query, variables);
35
+ }, 3, 300, defaultIsRetryable), 15000));
36
+ }
37
+ async function graphql(apiType, siteName, query, variables) {
38
+ try {
39
+ return await resilientGraphqlRequest(siteName, apiType, query, variables);
40
+ }
41
+ catch (err) {
42
+ if (err instanceof graphql_client_1.ClientError) {
43
+ throw new errors_1.ShopifyAdapterError(err.message, {
44
+ status: err.response?.status,
45
+ errors: err.response?.errors,
46
+ });
47
+ }
48
+ throw err instanceof Error ? new errors_1.ShopifyAdapterError(err.message) : err;
49
+ }
50
+ }
51
+ /**
52
+ * Runs a Shopify Admin GraphQL query for `siteName`.
53
+ *
54
+ * Unlike the 5 legacy microservices, this library has no request-scoped site
55
+ * context of its own — callers (hep-ecommerce-service) resolve the tenant
56
+ * and pass `siteName` explicitly, since shopify-adapter is a plain client
57
+ * library, not an Express app.
58
+ */
59
+ function adminGraphql(siteName, query, variables) {
60
+ return graphql('admin', siteName, query, variables);
61
+ }
62
+ /** Same as {@link adminGraphql}, against Shopify's Storefront API — used by Cart (and checkout). */
63
+ function storefrontGraphql(siteName, query, variables) {
64
+ return graphql('storefront', siteName, query, variables);
65
+ }
66
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],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E,SAAS,CAAC,CAAC;IAC/E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,4BAAW,EAAE,CAAC;YAC/B,MAAM,IAAI,4BAAmB,CAAC,GAAG,CAAC,OAAO,EAAE;gBACzC,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM;gBAC5B,MAAM,EAAG,GAAG,CAAC,QAAiC,EAAE,MAAM;aACvD,CAAC,CAAC;QACL,CAAC;QACD,MAAM,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,4BAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1E,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,YAAY,CAC1B,QAAgB,EAChB,KAAa,EACb,SAAmC;IAEnC,OAAO,OAAO,CAAI,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACzD,CAAC;AAED,oGAAoG;AACpG,SAAgB,iBAAiB,CAC/B,QAAgB,EAChB,KAAa,EACb,SAAmC;IAEnC,OAAO,OAAO,CAAI,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { ConfigProvider } from './tenant-types';
2
+ export type ProviderMode = 'secret-manager' | 'env' | 'csi' | 'auto';
3
+ /**
4
+ * Factory to create the appropriate config provider. Secrets are actually
5
+ * resolved by hep-secret-access's secretManager() (env | gsm | csi, chosen via
6
+ * SECRET_MODE — see hep-delivery-service's secret_key.services.ts for the
7
+ * reference usage this mirrors).
8
+ *
9
+ * An explicit mode forces that SECRET_MODE (set just before constructing the
10
+ * provider, then restored) regardless of the ambient value. 'auto' (the
11
+ * default) defers to whatever SECRET_MODE is already set; only when it isn't
12
+ * set at all does this fall back to NODE_ENV-based selection (gsm in
13
+ * production, env otherwise) so deployments that never set SECRET_MODE keep
14
+ * working unchanged.
15
+ */
16
+ export declare function createConfigProvider(mode?: ProviderMode): ConfigProvider;
17
+ //# sourceMappingURL=config-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-provider.d.ts","sourceRoot":"","sources":["../../src/config-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AASrE;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,GAAE,YAAqB,GAAG,cAAc,CAyBhF"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConfigProvider = createConfigProvider;
4
+ const hep_secret_provider_1 = require("./hep-secret-provider");
5
+ /** Our mode names -> hep-secret-access's SECRET_MODE values. */
6
+ const TO_HEP_MODE = {
7
+ env: 'env',
8
+ 'secret-manager': 'gsm',
9
+ csi: 'csi',
10
+ };
11
+ /**
12
+ * Factory to create the appropriate config provider. Secrets are actually
13
+ * resolved by hep-secret-access's secretManager() (env | gsm | csi, chosen via
14
+ * SECRET_MODE — see hep-delivery-service's secret_key.services.ts for the
15
+ * reference usage this mirrors).
16
+ *
17
+ * An explicit mode forces that SECRET_MODE (set just before constructing the
18
+ * provider, then restored) regardless of the ambient value. 'auto' (the
19
+ * default) defers to whatever SECRET_MODE is already set; only when it isn't
20
+ * set at all does this fall back to NODE_ENV-based selection (gsm in
21
+ * production, env otherwise) so deployments that never set SECRET_MODE keep
22
+ * working unchanged.
23
+ */
24
+ function createConfigProvider(mode = 'auto') {
25
+ if (mode !== 'auto') {
26
+ const previous = process.env.SECRET_MODE;
27
+ process.env.SECRET_MODE = TO_HEP_MODE[mode];
28
+ try {
29
+ return new hep_secret_provider_1.HepSecretProvider();
30
+ }
31
+ finally {
32
+ if (previous === undefined)
33
+ delete process.env.SECRET_MODE;
34
+ else
35
+ process.env.SECRET_MODE = previous;
36
+ }
37
+ }
38
+ if (!process.env.SECRET_MODE) {
39
+ if (process.env.NODE_ENV === 'production') {
40
+ // GOOGLE_PROJECT_ID (not GCP_PROJECT_ID) is what hep-secret-access's
41
+ // GoogleSecretManagerProvider actually reads — checking the wrong name
42
+ // here would let this pass while GSM silently falls back to its own
43
+ // default project.
44
+ if (!process.env.GOOGLE_PROJECT_ID)
45
+ throw new Error('GOOGLE_PROJECT_ID is required in production');
46
+ process.env.SECRET_MODE = 'gsm';
47
+ }
48
+ else {
49
+ process.env.SECRET_MODE = 'env';
50
+ }
51
+ }
52
+ return new hep_secret_provider_1.HepSecretProvider();
53
+ }
54
+ //# sourceMappingURL=config-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-provider.js","sourceRoot":"","sources":["../../src/config-provider.ts"],"names":[],"mappings":";;AAyBA,oDAyBC;AAlDD,+DAA0D;AAK1D,gEAAgE;AAChE,MAAM,WAAW,GAAqD;IACpE,GAAG,EAAE,KAAK;IACV,gBAAgB,EAAE,KAAK;IACvB,GAAG,EAAE,KAAK;CACX,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,SAAgB,oBAAoB,CAAC,OAAqB,MAAM;IAC9D,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC;YACH,OAAO,IAAI,uCAAiB,EAAE,CAAC;QACjC,CAAC;gBAAS,CAAC;YACT,IAAI,QAAQ,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;;gBACtD,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,QAAQ,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QAC7B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YAC1C,qEAAqE;YACrE,uEAAuE;YACvE,oEAAoE;YACpE,mBAAmB;YACnB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB;gBAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACnG,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,KAAK,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,KAAK,CAAC;QAClC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,uCAAiB,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,19 @@
1
+ export interface ShopifyCustomer {
2
+ shopifyId: string;
3
+ firstName?: string;
4
+ lastName?: string;
5
+ email?: string;
6
+ phone?: string;
7
+ acceptsMarketing: boolean;
8
+ createdAt?: string;
9
+ updatedAt?: string;
10
+ defaultAddressId?: string;
11
+ }
12
+ /** Fetch a customer by Shopify ID; `null` if missing. */
13
+ export declare function getCustomerById(siteName: string, customerId: string): Promise<ShopifyCustomer | null>;
14
+ /**
15
+ * Resolve a customer by email — used when the only identity available is an
16
+ * auth principal's email claim rather than a Shopify customer GID.
17
+ */
18
+ export declare function getCustomerByEmail(siteName: string, email: string): Promise<ShopifyCustomer | null>;
19
+ //# sourceMappingURL=customers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customers.d.ts","sourceRoot":"","sources":["../../src/customers.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAoCD,yDAAyD;AACzD,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAS3G;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAYzG"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCustomerById = getCustomerById;
4
+ exports.getCustomerByEmail = getCustomerByEmail;
5
+ const client_1 = require("./client");
6
+ const CUSTOMER_FIELDS = `
7
+ id
8
+ firstName
9
+ lastName
10
+ email
11
+ phone
12
+ emailMarketingConsent { marketingState }
13
+ createdAt
14
+ updatedAt
15
+ defaultAddress { id }
16
+ `;
17
+ function toAcceptsMarketing(node) {
18
+ return node.emailMarketingConsent?.marketingState === 'SUBSCRIBED';
19
+ }
20
+ function normalizeCustomerId(customerId) {
21
+ return customerId.startsWith('gid://shopify/Customer/') ? customerId : `gid://shopify/Customer/${customerId}`;
22
+ }
23
+ function mapCustomer(node) {
24
+ return {
25
+ shopifyId: node.id,
26
+ firstName: node.firstName ?? undefined,
27
+ lastName: node.lastName ?? undefined,
28
+ email: node.email ?? undefined,
29
+ phone: node.phone ?? undefined,
30
+ acceptsMarketing: toAcceptsMarketing(node),
31
+ createdAt: node.createdAt,
32
+ updatedAt: node.updatedAt,
33
+ defaultAddressId: node.defaultAddress?.id ?? undefined,
34
+ };
35
+ }
36
+ /** Fetch a customer by Shopify ID; `null` if missing. */
37
+ async function getCustomerById(siteName, customerId) {
38
+ const query = `
39
+ query GetCustomer($id: ID!) {
40
+ customer(id: $id) { ${CUSTOMER_FIELDS} }
41
+ }
42
+ `;
43
+ const data = await (0, client_1.adminGraphql)(siteName, query, { id: normalizeCustomerId(customerId) });
44
+ return data.customer ? mapCustomer(data.customer) : null;
45
+ }
46
+ /**
47
+ * Resolve a customer by email — used when the only identity available is an
48
+ * auth principal's email claim rather than a Shopify customer GID.
49
+ */
50
+ async function getCustomerByEmail(siteName, email) {
51
+ const query = `
52
+ query CustomerByEmail($query: String!) {
53
+ customers(first: 1, query: $query) {
54
+ nodes { ${CUSTOMER_FIELDS} }
55
+ }
56
+ }
57
+ `;
58
+ const data = await (0, client_1.adminGraphql)(siteName, query, { query: `email:${email}` });
59
+ const customer = data.customers.nodes[0];
60
+ return customer ? mapCustomer(customer) : null;
61
+ }
62
+ //# sourceMappingURL=customers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customers.js","sourceRoot":"","sources":["../../src/customers.ts"],"names":[],"mappings":";;AAiDA,0CASC;AAMD,gDAYC;AA5ED,qCAAwC;AAcxC,MAAM,eAAe,GAAG;;;;;;;;;;CAUvB,CAAC;AAEF,SAAS,kBAAkB,CAAC,IAA6D;IACvF,OAAO,IAAI,CAAC,qBAAqB,EAAE,cAAc,KAAK,YAAY,CAAC;AACrE,CAAC;AAED,SAAS,mBAAmB,CAAC,UAAkB;IAC7C,OAAO,UAAU,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,0BAA0B,UAAU,EAAE,CAAC;AAChH,CAAC;AAED,SAAS,WAAW,CAAC,IAAS;IAC5B,OAAO;QACL,SAAS,EAAE,IAAI,CAAC,EAAE;QAClB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,SAAS;QACtC,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,SAAS;QACpC,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,SAAS;QAC9B,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,SAAS;QAC9B,gBAAgB,EAAE,kBAAkB,CAAC,IAAI,CAAC;QAC1C,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,gBAAgB,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,SAAS;KACvD,CAAC;AACJ,CAAC;AAED,yDAAyD;AAClD,KAAK,UAAU,eAAe,CAAC,QAAgB,EAAE,UAAkB;IACxE,MAAM,KAAK,GAAG;;4BAEY,eAAe;;GAExC,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAY,EAAoB,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC7G,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CAAC,QAAgB,EAAE,KAAa;IACtE,MAAM,KAAK,GAAG;;;kBAGE,eAAe;;;GAG9B,CAAC;IAEF,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAY,EAAkC,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/G,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC"}
@@ -0,0 +1,17 @@
1
+ export declare class ShopifyAdapterError extends Error {
2
+ readonly details?: Record<string, unknown> | undefined;
3
+ constructor(message: string, details?: Record<string, unknown> | undefined);
4
+ }
5
+ export declare class ShopifyNotFoundError extends ShopifyAdapterError {
6
+ constructor(message?: string, details?: Record<string, unknown>);
7
+ }
8
+ export interface ShopifyUserError {
9
+ field?: string[];
10
+ message: string;
11
+ }
12
+ /** A Shopify mutation returned field-level `userErrors` (e.g. an invalid merchandiseId). */
13
+ export declare class ShopifyUserErrorsError extends ShopifyAdapterError {
14
+ readonly userErrors: ShopifyUserError[];
15
+ constructor(message: string, userErrors: ShopifyUserError[]);
16
+ }
17
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,KAAK;aAG1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBADjD,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAOpD;AAED,qBAAa,oBAAqB,SAAQ,mBAAmB;gBAC/C,OAAO,SAAc,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIrE;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,4FAA4F;AAC5F,qBAAa,sBAAuB,SAAQ,mBAAmB;aAG3C,UAAU,EAAE,gBAAgB,EAAE;gBAD9C,OAAO,EAAE,MAAM,EACC,UAAU,EAAE,gBAAgB,EAAE;CAKjD"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShopifyUserErrorsError = exports.ShopifyNotFoundError = exports.ShopifyAdapterError = void 0;
4
+ class ShopifyAdapterError extends Error {
5
+ details;
6
+ constructor(message, details) {
7
+ super(message);
8
+ this.details = details;
9
+ this.name = 'ShopifyAdapterError';
10
+ Object.setPrototypeOf(this, new.target.prototype);
11
+ Error.captureStackTrace(this);
12
+ }
13
+ }
14
+ exports.ShopifyAdapterError = ShopifyAdapterError;
15
+ class ShopifyNotFoundError extends ShopifyAdapterError {
16
+ constructor(message = 'Not found', details) {
17
+ super(message, details);
18
+ this.name = 'ShopifyNotFoundError';
19
+ }
20
+ }
21
+ exports.ShopifyNotFoundError = ShopifyNotFoundError;
22
+ /** A Shopify mutation returned field-level `userErrors` (e.g. an invalid merchandiseId). */
23
+ class ShopifyUserErrorsError extends ShopifyAdapterError {
24
+ userErrors;
25
+ constructor(message, userErrors) {
26
+ super(message, { userErrors });
27
+ this.userErrors = userErrors;
28
+ this.name = 'ShopifyUserErrorsError';
29
+ }
30
+ }
31
+ exports.ShopifyUserErrorsError = ShopifyUserErrorsError;
32
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAG1B;IAFlB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,YAAO,GAAP,OAAO,CAA0B;QAGjD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAClD,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACF;AAVD,kDAUC;AAED,MAAa,oBAAqB,SAAQ,mBAAmB;IAC3D,YAAY,OAAO,GAAG,WAAW,EAAE,OAAiC;QAClE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC;AAOD,4FAA4F;AAC5F,MAAa,sBAAuB,SAAQ,mBAAmB;IAG3C;IAFlB,YACE,OAAe,EACC,UAA8B;QAE9C,KAAK,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QAFf,eAAU,GAAV,UAAU,CAAoB;QAG9C,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AARD,wDAQC"}
@@ -0,0 +1,15 @@
1
+ import type { Request } from 'express';
2
+ /**
3
+ * Extracts and normalizes site name from request headers.
4
+ * Priority: sitename > sitehost > hostname
5
+ * Header 'sitename: KIWI' or 'sitehost: kiwi.hcl-x.com' => 'KIWI'
6
+ * Used to build Secret Manager keys: KIWI_SHOPIFY_STORE_DOMAIN
7
+ */
8
+ export declare function extractSiteName(req: Request): string | null;
9
+ /**
10
+ * Builds a Secret Manager secret ID using the convention:
11
+ * ${SITENAME}_${PROVIDER}_${KEY}
12
+ * e.g. buildSecretId('KIWI', 'SHOPIFY', 'STORE_DOMAIN') => 'KIWI_SHOPIFY_STORE_DOMAIN'
13
+ */
14
+ export declare function buildSecretId(siteName: string, provider: string, key: string): string;
15
+ //# sourceMappingURL=extract-site-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-site-name.d.ts","sourceRoot":"","sources":["../../src/extract-site-name.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAO3D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErF"}