@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.
- package/README.md +6 -14
- package/dist/core/cart/types.d.ts +53 -20
- package/dist/core/cart/types.d.ts.map +1 -1
- package/dist/core/cart/types.js +3 -0
- package/dist/core/image.d.ts +4 -46
- package/dist/core/image.d.ts.map +1 -1
- package/dist/core/image.js +4 -65
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +0 -2
- package/dist/core/operations/cart.d.ts +15 -9
- package/dist/core/operations/cart.d.ts.map +1 -1
- package/dist/core/operations/cart.js +130 -58
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +9 -4
- package/src/__tests__/contract/storefront-api.contract.test.ts +0 -450
- package/src/__tests__/unit/auth-client.test.ts +0 -210
- package/src/__tests__/unit/bot-protection.test.ts +0 -461
- package/src/__tests__/unit/cart-client.test.ts +0 -233
- package/src/__tests__/unit/cart-store.test.ts +0 -349
- package/src/__tests__/unit/create-client.test.ts +0 -356
- package/src/__tests__/unit/helpers.test.ts +0 -377
- package/src/__tests__/unit/middleware.test.ts +0 -374
- package/src/__tests__/unit/test-helpers.ts +0 -103
- package/src/core/auth/auth-client.ts +0 -123
- package/src/core/auth/cookie-config.ts +0 -23
- package/src/core/auth/handlers.ts +0 -168
- package/src/core/auth/routes.ts +0 -26
- package/src/core/auth/token-client.ts +0 -51
- package/src/core/auth/types.ts +0 -54
- package/src/core/bot-protection/abstract-manager.ts +0 -185
- package/src/core/bot-protection/create-manager.ts +0 -37
- package/src/core/bot-protection/eucaptcha-manager.ts +0 -88
- package/src/core/bot-protection/fallback-manager.ts +0 -43
- package/src/core/bot-protection/turnstile-manager.ts +0 -92
- package/src/core/bot-protection/types/eucaptcha.d.ts +0 -28
- package/src/core/bot-protection/types/turnstile.d.ts +0 -33
- package/src/core/cache.ts +0 -102
- package/src/core/cart/cart-client.ts +0 -150
- package/src/core/cart/cookie-config.ts +0 -13
- package/src/core/cart/types.ts +0 -104
- package/src/core/client/compose.ts +0 -15
- package/src/core/client/create-client.ts +0 -129
- package/src/core/client/dedupe.ts +0 -19
- package/src/core/client/execute.ts +0 -70
- package/src/core/client/hash.ts +0 -21
- package/src/core/client/operation-name.ts +0 -12
- package/src/core/client/types.ts +0 -171
- package/src/core/currency/cookie-config.ts +0 -13
- package/src/core/errors.ts +0 -67
- package/src/core/format.ts +0 -254
- package/src/core/helpers/assert-no-user-errors.ts +0 -21
- package/src/core/helpers/normalize-connection.ts +0 -48
- package/src/core/helpers/sanitize-html.ts +0 -42
- package/src/core/image.ts +0 -103
- package/src/core/index.ts +0 -180
- package/src/core/language/cookie-config.ts +0 -13
- package/src/core/middleware/auth.ts +0 -27
- package/src/core/middleware/bot-protection.ts +0 -140
- package/src/core/middleware/currency.ts +0 -27
- package/src/core/middleware/errors.ts +0 -86
- package/src/core/middleware/language.ts +0 -30
- package/src/core/middleware/retry.ts +0 -75
- package/src/core/middleware/timeout.ts +0 -61
- package/src/core/operations/auth.ts +0 -123
- package/src/core/operations/cart.ts +0 -185
- package/src/index.ts +0 -25
- package/src/react/bot-protection/bot-protection-context.ts +0 -17
- package/src/react/bot-protection/bot-protection-widget.tsx +0 -46
- package/src/react/cookies.ts +0 -89
- package/src/react/helpers/create-store-context.ts +0 -56
- package/src/react/hooks/use-auth.ts +0 -218
- package/src/react/hooks/use-bot-protection.ts +0 -31
- package/src/react/hooks/use-cart-manager.ts +0 -236
- package/src/react/hooks/use-currency.ts +0 -23
- package/src/react/hooks/use-debounced-value.ts +0 -30
- package/src/react/hooks/use-hydrated.ts +0 -20
- package/src/react/hooks/use-storefront-client.ts +0 -12
- package/src/react/index.ts +0 -71
- package/src/react/providers/currency-provider.tsx +0 -30
- package/src/react/providers/language-provider.tsx +0 -34
- package/src/react/providers/storefront-client-provider.tsx +0 -107
- package/src/react/providers/storefront-provider.tsx +0 -99
- package/src/react/server/get-storefront-client.ts +0 -60
- package/src/react/server/index.ts +0 -1
- package/src/react/stores/auth.store.ts +0 -112
- package/src/react/stores/cart.context.ts +0 -10
- package/src/react/stores/cart.store.ts +0 -254
- package/src/react/stores/currency.store.ts +0 -93
- package/src/react/stores/index.ts +0 -17
- package/src/react/stores/language.store.ts +0 -90
- package/src/react/stores/store-context.tsx +0 -103
- package/src/react/types/shop-config.ts +0 -22
- package/tsconfig.json +0 -20
- 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
|
-
*
|
|
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
|
-
//
|
|
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 { ...
|
|
19
|
-
subtotalAmount { ...
|
|
20
|
-
totalTaxAmount { ...
|
|
21
|
-
totalDutyAmount { ...
|
|
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
|
|
97
|
+
fragment CartLine on CartLine {
|
|
26
98
|
id
|
|
27
99
|
quantity
|
|
28
|
-
merchandise {
|
|
29
|
-
|
|
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
|
|
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
|
|
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
|
-
...
|
|
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 { ...
|
|
104
|
-
userErrors { ...
|
|
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 { ...
|
|
114
|
-
userErrors { ...
|
|
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 { ...
|
|
124
|
-
userErrors { ...
|
|
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 { ...
|
|
134
|
-
userErrors { ...
|
|
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 { ...
|
|
144
|
-
userErrors { ...
|
|
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 { ...
|
|
154
|
-
userErrors { ...
|
|
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 { ...
|
|
164
|
-
userErrors { ...
|
|
235
|
+
cart { ...Cart }
|
|
236
|
+
userErrors { ...UserError }
|
|
165
237
|
}
|
|
166
238
|
}
|
|
167
239
|
${CART_FRAGMENT}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doswiftly/storefront-sdk",
|
|
3
|
-
"version": "4.
|
|
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": "^
|
|
58
|
+
"next": "^16.0.0",
|
|
54
59
|
"typescript": "^5.7.2",
|
|
55
|
-
"vitest": "^
|
|
60
|
+
"vitest": "^4.1.0",
|
|
56
61
|
"zustand": "^5.0.2",
|
|
57
62
|
"react": "^19.0.0"
|
|
58
63
|
},
|