@doswiftly/storefront-sdk 4.4.0 → 4.7.1

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