@doswiftly/storefront-sdk 4.3.0 → 4.5.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 (96) hide show
  1. package/README.md +6 -14
  2. package/dist/core/cart/types.d.ts +53 -20
  3. package/dist/core/cart/types.d.ts.map +1 -1
  4. package/dist/core/cart/types.js +3 -0
  5. package/dist/core/image.d.ts +4 -46
  6. package/dist/core/image.d.ts.map +1 -1
  7. package/dist/core/image.js +4 -65
  8. package/dist/core/index.d.ts +1 -1
  9. package/dist/core/index.d.ts.map +1 -1
  10. package/dist/core/index.js +0 -2
  11. package/dist/core/operations/cart.d.ts +15 -9
  12. package/dist/core/operations/cart.d.ts.map +1 -1
  13. package/dist/core/operations/cart.js +130 -58
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +1 -1
  16. package/package.json +9 -4
  17. package/src/__tests__/contract/storefront-api.contract.test.ts +0 -450
  18. package/src/__tests__/unit/auth-client.test.ts +0 -210
  19. package/src/__tests__/unit/bot-protection.test.ts +0 -461
  20. package/src/__tests__/unit/cart-client.test.ts +0 -233
  21. package/src/__tests__/unit/cart-store.test.ts +0 -349
  22. package/src/__tests__/unit/create-client.test.ts +0 -356
  23. package/src/__tests__/unit/helpers.test.ts +0 -377
  24. package/src/__tests__/unit/middleware.test.ts +0 -374
  25. package/src/__tests__/unit/test-helpers.ts +0 -103
  26. package/src/core/auth/auth-client.ts +0 -123
  27. package/src/core/auth/cookie-config.ts +0 -23
  28. package/src/core/auth/handlers.ts +0 -168
  29. package/src/core/auth/routes.ts +0 -26
  30. package/src/core/auth/token-client.ts +0 -51
  31. package/src/core/auth/types.ts +0 -54
  32. package/src/core/bot-protection/abstract-manager.ts +0 -185
  33. package/src/core/bot-protection/create-manager.ts +0 -37
  34. package/src/core/bot-protection/eucaptcha-manager.ts +0 -88
  35. package/src/core/bot-protection/fallback-manager.ts +0 -43
  36. package/src/core/bot-protection/turnstile-manager.ts +0 -92
  37. package/src/core/bot-protection/types/eucaptcha.d.ts +0 -28
  38. package/src/core/bot-protection/types/turnstile.d.ts +0 -33
  39. package/src/core/cache.ts +0 -102
  40. package/src/core/cart/cart-client.ts +0 -150
  41. package/src/core/cart/cookie-config.ts +0 -13
  42. package/src/core/cart/types.ts +0 -104
  43. package/src/core/client/compose.ts +0 -15
  44. package/src/core/client/create-client.ts +0 -129
  45. package/src/core/client/dedupe.ts +0 -19
  46. package/src/core/client/execute.ts +0 -70
  47. package/src/core/client/hash.ts +0 -21
  48. package/src/core/client/operation-name.ts +0 -12
  49. package/src/core/client/types.ts +0 -171
  50. package/src/core/currency/cookie-config.ts +0 -13
  51. package/src/core/errors.ts +0 -67
  52. package/src/core/format.ts +0 -254
  53. package/src/core/helpers/assert-no-user-errors.ts +0 -21
  54. package/src/core/helpers/normalize-connection.ts +0 -48
  55. package/src/core/helpers/sanitize-html.ts +0 -42
  56. package/src/core/image.ts +0 -103
  57. package/src/core/index.ts +0 -180
  58. package/src/core/language/cookie-config.ts +0 -13
  59. package/src/core/middleware/auth.ts +0 -27
  60. package/src/core/middleware/bot-protection.ts +0 -140
  61. package/src/core/middleware/currency.ts +0 -27
  62. package/src/core/middleware/errors.ts +0 -86
  63. package/src/core/middleware/language.ts +0 -30
  64. package/src/core/middleware/retry.ts +0 -75
  65. package/src/core/middleware/timeout.ts +0 -61
  66. package/src/core/operations/auth.ts +0 -123
  67. package/src/core/operations/cart.ts +0 -185
  68. package/src/index.ts +0 -25
  69. package/src/react/bot-protection/bot-protection-context.ts +0 -17
  70. package/src/react/bot-protection/bot-protection-widget.tsx +0 -46
  71. package/src/react/cookies.ts +0 -89
  72. package/src/react/helpers/create-store-context.ts +0 -56
  73. package/src/react/hooks/use-auth.ts +0 -218
  74. package/src/react/hooks/use-bot-protection.ts +0 -31
  75. package/src/react/hooks/use-cart-manager.ts +0 -236
  76. package/src/react/hooks/use-currency.ts +0 -23
  77. package/src/react/hooks/use-debounced-value.ts +0 -30
  78. package/src/react/hooks/use-hydrated.ts +0 -20
  79. package/src/react/hooks/use-storefront-client.ts +0 -12
  80. package/src/react/index.ts +0 -71
  81. package/src/react/providers/currency-provider.tsx +0 -30
  82. package/src/react/providers/language-provider.tsx +0 -34
  83. package/src/react/providers/storefront-client-provider.tsx +0 -107
  84. package/src/react/providers/storefront-provider.tsx +0 -99
  85. package/src/react/server/get-storefront-client.ts +0 -60
  86. package/src/react/server/index.ts +0 -1
  87. package/src/react/stores/auth.store.ts +0 -112
  88. package/src/react/stores/cart.context.ts +0 -10
  89. package/src/react/stores/cart.store.ts +0 -254
  90. package/src/react/stores/currency.store.ts +0 -93
  91. package/src/react/stores/index.ts +0 -17
  92. package/src/react/stores/language.store.ts +0 -90
  93. package/src/react/stores/store-context.tsx +0 -103
  94. package/src/react/types/shop-config.ts +0 -22
  95. package/tsconfig.json +0 -20
  96. package/vitest.config.ts +0 -14
@@ -1,11 +1,17 @@
1
1
  /**
2
2
  * Cart GraphQL operations — manual query strings (no codegen).
3
3
  *
4
- * These match the backend storefront-graphql schema exactly.
4
+ * SSOT: packages/backend/src/commerce/storefront-graphql/operations/
5
+ * - fragments.graphql (CartCost, CartLineCost, CartLine, Cart, etc.)
6
+ * - queries.graphql (Cart query)
7
+ * - mutations.graphql (cartCreate, cartLinesAdd, etc.)
8
+ *
9
+ * Validate drift: pnpm test:contract (cart-operations-drift test)
10
+ *
5
11
  * Cart mutations always return full Cart + userErrors.
6
12
  */
7
13
  // ---------------------------------------------------------------------------
8
- // Fragments
14
+ // Shared fragments (matching SSOT fragments.graphql)
9
15
  // ---------------------------------------------------------------------------
10
16
  const MONEY_FRAGMENT = `
11
17
  fragment Money on Money {
@@ -13,74 +19,140 @@ const MONEY_FRAGMENT = `
13
19
  currencyCode
14
20
  }
15
21
  `;
22
+ const PRICE_FRAGMENT = `
23
+ fragment Price on PriceMoney {
24
+ amount
25
+ currencyCode
26
+ }
27
+ `;
28
+ const PRICE_MONEY_FRAGMENT = `
29
+ fragment PriceMoney on PriceMoney {
30
+ ...Price
31
+ baseAmount
32
+ baseCurrencyCode
33
+ exchangeRate
34
+ marginApplied
35
+ rateTimestamp
36
+ isConverted
37
+ }
38
+ ${PRICE_FRAGMENT}
39
+ `;
40
+ const IMAGE_FRAGMENT = `
41
+ fragment Image on Image {
42
+ id
43
+ url
44
+ altText
45
+ width
46
+ height
47
+ }
48
+ `;
49
+ const SELECTED_OPTION_FRAGMENT = `
50
+ fragment SelectedOption on SelectedOption {
51
+ name
52
+ value
53
+ }
54
+ `;
55
+ // ---------------------------------------------------------------------------
56
+ // Cart-specific fragments (matching SSOT fragments.graphql)
57
+ // ---------------------------------------------------------------------------
58
+ const PRODUCT_VARIANT_FRAGMENT = `
59
+ fragment ProductVariant on ProductVariant {
60
+ id
61
+ title
62
+ sku
63
+ price { ...PriceMoney }
64
+ originalPrice { ...Money }
65
+ compareAtPrice { ...PriceMoney }
66
+ originalCompareAtPrice { ...Money }
67
+ available
68
+ quantityAvailable
69
+ image { ...Image }
70
+ selectedOptions { ...SelectedOption }
71
+ barcode
72
+ weight
73
+ position
74
+ }
75
+ ${PRICE_MONEY_FRAGMENT}
76
+ ${MONEY_FRAGMENT}
77
+ ${IMAGE_FRAGMENT}
78
+ ${SELECTED_OPTION_FRAGMENT}
79
+ `;
16
80
  const CART_COST_FRAGMENT = `
17
81
  fragment CartCost on CartCost {
18
- totalAmount { ...Money }
19
- subtotalAmount { ...Money }
20
- totalTaxAmount { ...Money }
21
- totalDutyAmount { ...Money }
82
+ totalAmount { ...PriceMoney }
83
+ subtotalAmount { ...PriceMoney }
84
+ totalTaxAmount { ...PriceMoney }
85
+ totalDutyAmount { ...PriceMoney }
86
+ }
87
+ `;
88
+ const CART_LINE_COST_FRAGMENT = `
89
+ fragment CartLineCost on CartLineCost {
90
+ amountPerQuantity { ...PriceMoney }
91
+ subtotalAmount { ...PriceMoney }
92
+ totalAmount { ...PriceMoney }
93
+ compareAtAmountPerQuantity { ...PriceMoney }
22
94
  }
23
95
  `;
24
96
  const CART_LINE_FRAGMENT = `
25
- fragment CartLineFields on CartLine {
97
+ fragment CartLine on CartLine {
26
98
  id
27
99
  quantity
28
- merchandise {
29
- id
30
- title
31
- sku
32
- image { url altText }
33
- price { ...Money }
34
- compareAtPrice { ...Money }
35
- }
36
- cost {
37
- totalAmount { ...Money }
38
- amountPerQuantity { ...Money }
39
- compareAtAmountPerQuantity { ...Money }
40
- }
100
+ merchandise { ...ProductVariant }
101
+ cost { ...CartLineCost }
41
102
  attributes { key value }
42
103
  productId
43
104
  productTitle
44
105
  productHandle
106
+ productType
107
+ }
108
+ ${CART_LINE_COST_FRAGMENT}
109
+ ${PRODUCT_VARIANT_FRAGMENT}
110
+ `;
111
+ const CART_BUYER_IDENTITY_FRAGMENT = `
112
+ fragment CartBuyerIdentity on CartBuyerIdentity {
113
+ email
114
+ phone
115
+ countryCode
116
+ }
117
+ `;
118
+ const CART_DISCOUNT_CODE_FRAGMENT = `
119
+ fragment CartDiscountCode on CartDiscountCode {
120
+ code
121
+ applicable
122
+ }
123
+ `;
124
+ const CART_DISCOUNT_ALLOCATION_FRAGMENT = `
125
+ fragment CartDiscountAllocation on CartDiscountAllocation {
126
+ discountCode
127
+ amount { ...Money }
45
128
  }
46
129
  `;
47
130
  const CART_FRAGMENT = `
48
- fragment CartFields on Cart {
131
+ fragment Cart on Cart {
49
132
  id
50
133
  checkoutUrl
51
134
  totalQuantity
135
+ cost { ...CartCost }
136
+ lines(first: 100) { ...CartLine }
137
+ buyerIdentity { ...CartBuyerIdentity }
138
+ discountCodes { ...CartDiscountCode }
139
+ discountAllocations { ...CartDiscountAllocation }
52
140
  note
141
+ attributes { key value }
53
142
  createdAt
54
143
  updatedAt
55
- cost { ...CartCost }
56
- lines(first: 100) {
57
- edges {
58
- node { ...CartLineFields }
59
- }
60
- }
61
- buyerIdentity {
62
- email
63
- phone
64
- countryCode
65
- }
66
- discountCodes {
67
- code
68
- applicable
69
- }
70
- discountAllocations {
71
- discountedAmount { ...Money }
72
- }
73
- attributes { key value }
74
144
  }
75
- ${MONEY_FRAGMENT}
76
145
  ${CART_COST_FRAGMENT}
77
146
  ${CART_LINE_FRAGMENT}
147
+ ${CART_BUYER_IDENTITY_FRAGMENT}
148
+ ${CART_DISCOUNT_CODE_FRAGMENT}
149
+ ${CART_DISCOUNT_ALLOCATION_FRAGMENT}
78
150
  `;
79
151
  const USER_ERROR_FRAGMENT = `
80
- fragment UserErrorFields on UserError {
152
+ fragment UserError on UserError {
81
153
  message
82
- field
83
154
  code
155
+ field
84
156
  }
85
157
  `;
86
158
  // ---------------------------------------------------------------------------
@@ -89,7 +161,7 @@ const USER_ERROR_FRAGMENT = `
89
161
  export const CART_QUERY = `
90
162
  query Cart($id: ID!) {
91
163
  cart(id: $id) {
92
- ...CartFields
164
+ ...Cart
93
165
  }
94
166
  }
95
167
  ${CART_FRAGMENT}
@@ -100,8 +172,8 @@ export const CART_QUERY = `
100
172
  export const CART_CREATE = `
101
173
  mutation CartCreate($input: CartCreateInput) {
102
174
  cartCreate(input: $input) {
103
- cart { ...CartFields }
104
- userErrors { ...UserErrorFields }
175
+ cart { ...Cart }
176
+ userErrors { ...UserError }
105
177
  }
106
178
  }
107
179
  ${CART_FRAGMENT}
@@ -110,8 +182,8 @@ export const CART_CREATE = `
110
182
  export const CART_LINES_ADD = `
111
183
  mutation CartLinesAdd($cartId: ID!, $lines: [CartLineInput!]!) {
112
184
  cartLinesAdd(cartId: $cartId, lines: $lines) {
113
- cart { ...CartFields }
114
- userErrors { ...UserErrorFields }
185
+ cart { ...Cart }
186
+ userErrors { ...UserError }
115
187
  }
116
188
  }
117
189
  ${CART_FRAGMENT}
@@ -120,8 +192,8 @@ export const CART_LINES_ADD = `
120
192
  export const CART_LINES_UPDATE = `
121
193
  mutation CartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
122
194
  cartLinesUpdate(cartId: $cartId, lines: $lines) {
123
- cart { ...CartFields }
124
- userErrors { ...UserErrorFields }
195
+ cart { ...Cart }
196
+ userErrors { ...UserError }
125
197
  }
126
198
  }
127
199
  ${CART_FRAGMENT}
@@ -130,8 +202,8 @@ export const CART_LINES_UPDATE = `
130
202
  export const CART_LINES_REMOVE = `
131
203
  mutation CartLinesRemove($cartId: ID!, $lineIds: [ID!]!) {
132
204
  cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {
133
- cart { ...CartFields }
134
- userErrors { ...UserErrorFields }
205
+ cart { ...Cart }
206
+ userErrors { ...UserError }
135
207
  }
136
208
  }
137
209
  ${CART_FRAGMENT}
@@ -140,8 +212,8 @@ export const CART_LINES_REMOVE = `
140
212
  export const CART_DISCOUNT_CODES_UPDATE = `
141
213
  mutation CartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!]!) {
142
214
  cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
143
- cart { ...CartFields }
144
- userErrors { ...UserErrorFields }
215
+ cart { ...Cart }
216
+ userErrors { ...UserError }
145
217
  }
146
218
  }
147
219
  ${CART_FRAGMENT}
@@ -150,8 +222,8 @@ export const CART_DISCOUNT_CODES_UPDATE = `
150
222
  export const CART_NOTE_UPDATE = `
151
223
  mutation CartNoteUpdate($cartId: ID!, $note: String!) {
152
224
  cartNoteUpdate(cartId: $cartId, note: $note) {
153
- cart { ...CartFields }
154
- userErrors { ...UserErrorFields }
225
+ cart { ...Cart }
226
+ userErrors { ...UserError }
155
227
  }
156
228
  }
157
229
  ${CART_FRAGMENT}
@@ -160,8 +232,8 @@ export const CART_NOTE_UPDATE = `
160
232
  export const CART_BUYER_IDENTITY_UPDATE = `
161
233
  mutation CartBuyerIdentityUpdate($cartId: ID!, $buyerIdentity: CartBuyerIdentityInput!) {
162
234
  cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) {
163
- cart { ...CartFields }
164
- userErrors { ...UserErrorFields }
235
+ cart { ...Cart }
236
+ userErrors { ...UserError }
165
237
  }
166
238
  }
167
239
  ${CART_FRAGMENT}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @doswiftly/storefront-sdk v4.0.0
2
+ * @doswiftly/storefront-sdk v4.4.0
3
3
  *
4
4
  * Layered SDK — Hydrogen-aligned architecture.
5
5
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @doswiftly/storefront-sdk v4.0.0
2
+ * @doswiftly/storefront-sdk v4.4.0
3
3
  *
4
4
  * Layered SDK — Hydrogen-aligned architecture.
5
5
  *
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@doswiftly/storefront-sdk",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "description": "Storefront runtime SDK for DoSwiftly Commerce — layered transport, middleware pipeline, React providers, Zustand stores, cache strategies. 0 runtime dependencies in core.",
5
5
  "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "README.md"
9
+ ],
6
10
  "types": "dist/core/index.d.ts",
7
11
  "exports": {
8
12
  ".": {
@@ -30,7 +34,8 @@
30
34
  "test": "vitest run",
31
35
  "test:watch": "vitest",
32
36
  "test:unit": "vitest run src/__tests__/unit/",
33
- "test:contract": "vitest run src/__tests__/contract/"
37
+ "test:contract": "vitest run src/__tests__/contract/",
38
+ "validate:cart": "node scripts/validate-cart-operations.cjs --strict"
34
39
  },
35
40
  "keywords": [
36
41
  "sdk",
@@ -50,9 +55,9 @@
50
55
  "@types/node": "^22.10.2",
51
56
  "@types/react": "^18.3.0 || ^19.0.0",
52
57
  "fast-check": "^3.23.2",
53
- "next": "^15.0.0",
58
+ "next": "^16.0.0",
54
59
  "typescript": "^5.7.2",
55
- "vitest": "^2.1.8",
60
+ "vitest": "^4.1.0",
56
61
  "zustand": "^5.0.2",
57
62
  "react": "^19.0.0"
58
63
  },