arky-sdk 0.7.130 → 0.7.131
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 +48 -105
- package/dist/storefront-store.cjs +8 -0
- package/dist/storefront-store.cjs.map +1 -1
- package/dist/storefront-store.js +8 -0
- package/dist/storefront-store.js.map +1 -1
- package/dist/storefront.cjs +8 -0
- package/dist/storefront.cjs.map +1 -1
- package/dist/storefront.d.cts +7 -0
- package/dist/storefront.d.ts +7 -0
- package/dist/storefront.js +8 -0
- package/dist/storefront.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,131 +35,84 @@ npm install arky-sdk
|
|
|
35
35
|
### 1. Install & Initialize
|
|
36
36
|
|
|
37
37
|
```typescript
|
|
38
|
-
import {
|
|
38
|
+
import { createArkyStore } from 'arky-sdk/storefront-store'
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const arkyStore = createArkyStore({
|
|
41
41
|
baseUrl: 'https://api.arky.io',
|
|
42
42
|
storeId: 'your-store-id',
|
|
43
43
|
market: 'us',
|
|
44
|
-
|
|
45
|
-
accessToken: localStorage.getItem('accessToken') || '',
|
|
46
|
-
refreshToken: localStorage.getItem('refreshToken') || '',
|
|
47
|
-
provider: 'EMAIL',
|
|
48
|
-
expiresAt: 0,
|
|
49
|
-
}),
|
|
50
|
-
setToken: (tokens) => {
|
|
51
|
-
localStorage.setItem('accessToken', tokens.accessToken);
|
|
52
|
-
localStorage.setItem('refreshToken', tokens.refreshToken);
|
|
53
|
-
},
|
|
54
|
-
logout: () => {
|
|
55
|
-
localStorage.removeItem('accessToken');
|
|
56
|
-
localStorage.removeItem('refreshToken');
|
|
57
|
-
},
|
|
44
|
+
locale: 'en',
|
|
58
45
|
})
|
|
46
|
+
|
|
47
|
+
await arkyStore.initialize({ hydrate_cart: true, load_website: true })
|
|
59
48
|
```
|
|
60
49
|
|
|
61
50
|
### 2. Browse Products
|
|
62
51
|
|
|
63
52
|
```typescript
|
|
64
53
|
// List products (like on arky.io/products)
|
|
65
|
-
const { items: products } = await
|
|
54
|
+
const { items: products } = await arkyStore.eshop.product.find({
|
|
66
55
|
limit: 20
|
|
67
56
|
});
|
|
68
57
|
|
|
69
58
|
// Get product details (like arky.io/products/guitar)
|
|
70
|
-
const product = await
|
|
59
|
+
const product = await arkyStore.eshop.product.get({ id: 'prod_123' });
|
|
71
60
|
|
|
72
61
|
// Format price (uses currency from price object)
|
|
73
|
-
const formatted =
|
|
62
|
+
const formatted = arkyStore.utils.formatPrice(product.variants[0].prices); // "$29.99"
|
|
74
63
|
```
|
|
75
64
|
|
|
76
65
|
### 3. Shop & Checkout
|
|
77
66
|
|
|
78
67
|
```typescript
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
item: {
|
|
84
|
-
type: 'product',
|
|
85
|
-
product_id: 'prod_123',
|
|
86
|
-
variant_id: 'var_456',
|
|
87
|
-
quantity: 2,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
68
|
+
const product = await arkyStore.eshop.product.get({ id: 'prod_123' })
|
|
69
|
+
const variant = product.variants[0]
|
|
70
|
+
|
|
71
|
+
await arkyStore.eshop.cart.actions.addProduct(product, variant, 2)
|
|
90
72
|
|
|
91
|
-
const
|
|
92
|
-
|
|
73
|
+
const quote = await arkyStore.eshop.cart.actions.quote()
|
|
74
|
+
|
|
75
|
+
const order = await arkyStore.eshop.cart.actions.checkout({
|
|
93
76
|
payment_method_id: 'credit_card',
|
|
94
|
-
})
|
|
77
|
+
})
|
|
95
78
|
```
|
|
96
79
|
|
|
97
|
-
### Framework-
|
|
80
|
+
### Framework-Agnostic Store
|
|
98
81
|
|
|
99
|
-
|
|
82
|
+
The storefront store is framework-agnostic and built on Nano Stores. UI frameworks can subscribe to atoms directly, while app code calls actions:
|
|
100
83
|
|
|
101
84
|
```typescript
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
market: 'us',
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const unsubscribe = storefront.cart.subscribe((state) => {
|
|
109
|
-
console.log(state.cart, state.quote, state.loading, state.error)
|
|
110
|
-
})
|
|
85
|
+
const unsubscribe = arkyStore.eshop.cart.snapshot.subscribe((snapshot) => {
|
|
86
|
+
console.log(snapshot.item_count, snapshot.cart?.id)
|
|
87
|
+
});
|
|
111
88
|
|
|
112
|
-
await
|
|
113
|
-
await
|
|
114
|
-
item: {
|
|
115
|
-
type: 'product',
|
|
116
|
-
product_id: 'prod_123',
|
|
117
|
-
variant_id: 'var_456',
|
|
118
|
-
quantity: 1,
|
|
119
|
-
},
|
|
120
|
-
})
|
|
121
|
-
await storefront.cart.quote()
|
|
122
|
-
await storefront.cart.checkout({ payment_method_id: 'credit_card' })
|
|
89
|
+
await arkyStore.eshop.cart.actions.ensure();
|
|
90
|
+
await arkyStore.eshop.cart.actions.clear();
|
|
123
91
|
|
|
124
|
-
unsubscribe()
|
|
92
|
+
unsubscribe();
|
|
125
93
|
```
|
|
126
94
|
|
|
127
|
-
The
|
|
95
|
+
The low-level SDK client is still available as `arkyStore.client` for unusual cases, but normal storefronts should use the store-shaped modules: `cms`, `eshop`, `crm`, `activity`, `automation`, `store`, and `utils`.
|
|
128
96
|
|
|
129
97
|
### 4. Sell Scheduled Services
|
|
130
98
|
|
|
131
99
|
```typescript
|
|
132
100
|
// Browse services (like arky.io/services)
|
|
133
|
-
const { items: services } = await
|
|
134
|
-
|
|
135
|
-
// Check available time slots
|
|
136
|
-
const availability = await arky.eshop.service.getAvailability({
|
|
137
|
-
service_id: 'service_haircut',
|
|
138
|
-
provider_id: 'provider_jane',
|
|
139
|
-
from: Math.floor(Date.now() / 1000),
|
|
140
|
-
to: Math.floor(Date.now() / 1000) + 86400,
|
|
141
|
-
});
|
|
101
|
+
const { items: services } = await arkyStore.eshop.service.find({});
|
|
102
|
+
const service = services[0];
|
|
142
103
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
id: cart.id,
|
|
147
|
-
items: [{
|
|
148
|
-
type: 'booking',
|
|
149
|
-
service_id: 'service_haircut',
|
|
150
|
-
provider_id: 'provider_jane',
|
|
151
|
-
slots: [{
|
|
152
|
-
from: availability.available_slots[0].from,
|
|
153
|
-
to: availability.available_slots[0].to,
|
|
154
|
-
}],
|
|
155
|
-
}],
|
|
156
|
-
forms: [],
|
|
157
|
-
});
|
|
104
|
+
await arkyStore.eshop.serviceOrder.actions.initialize();
|
|
105
|
+
await arkyStore.eshop.serviceOrder.actions.setService(service);
|
|
106
|
+
arkyStore.eshop.serviceOrder.actions.findFirstAvailable();
|
|
158
107
|
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
108
|
+
const state = arkyStore.eshop.serviceOrder.state.get();
|
|
109
|
+
if (state.slots[0]) {
|
|
110
|
+
arkyStore.eshop.serviceOrder.actions.selectTimeSlot(state.slots[0]);
|
|
111
|
+
arkyStore.eshop.serviceOrder.actions.nextStep();
|
|
112
|
+
await arkyStore.eshop.serviceOrder.actions.addToCart();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const order = await arkyStore.eshop.serviceOrder.actions.checkout('cash');
|
|
163
116
|
```
|
|
164
117
|
|
|
165
118
|
### 5. Subscribe to Newsletter
|
|
@@ -250,25 +203,18 @@ await arky.cms.getCollectionSubscribers({ id: 'newsletter_id' })
|
|
|
250
203
|
### E-shop
|
|
251
204
|
```typescript
|
|
252
205
|
// Products
|
|
253
|
-
await
|
|
254
|
-
await
|
|
255
|
-
await arky.eshop.getProduct({ id })
|
|
256
|
-
await arky.eshop.updateProduct({ id, name })
|
|
206
|
+
await arkyStore.eshop.product.find({ limit: 20, cursor: null })
|
|
207
|
+
await arkyStore.eshop.product.get({ id })
|
|
257
208
|
|
|
258
209
|
// Carts and orders
|
|
259
|
-
const cart = await
|
|
260
|
-
await
|
|
261
|
-
await
|
|
262
|
-
await
|
|
263
|
-
await
|
|
264
|
-
await arky.eshop.updateOrderStatus({ id, status: 'SHIPPED' })
|
|
210
|
+
const cart = await arkyStore.eshop.cart.actions.ensure()
|
|
211
|
+
await arkyStore.eshop.cart.actions.sync({ product_items, shipping_method_id })
|
|
212
|
+
await arkyStore.eshop.cart.actions.checkout({ payment_method_id })
|
|
213
|
+
await arkyStore.eshop.order.find({})
|
|
214
|
+
await arkyStore.eshop.order.get({ id })
|
|
265
215
|
|
|
266
216
|
// Quote
|
|
267
|
-
await
|
|
268
|
-
items: [{ productId, variantId, quantity }],
|
|
269
|
-
currency: 'usd',
|
|
270
|
-
paymentMethod: 'CREDIT_CARD',
|
|
271
|
-
})
|
|
217
|
+
await arkyStore.eshop.cart.actions.quote()
|
|
272
218
|
```
|
|
273
219
|
|
|
274
220
|
### Services
|
|
@@ -392,17 +338,14 @@ await arky.utils.injectSvgIntoElement(mediaBlock, element, 'custom-class')
|
|
|
392
338
|
## Configuration Options
|
|
393
339
|
|
|
394
340
|
```typescript
|
|
395
|
-
|
|
341
|
+
createArkyStore({
|
|
396
342
|
// Required
|
|
397
343
|
baseUrl: string, // API URL
|
|
398
344
|
storeId: string, // Your store ID
|
|
399
345
|
market: string, // Market code (e.g., 'us', 'eu')
|
|
400
346
|
|
|
401
|
-
// Token management
|
|
402
|
-
getToken: () => TokenData,
|
|
403
|
-
setToken: (tokens: TokenData) => void,
|
|
404
|
-
|
|
405
347
|
// Optional
|
|
348
|
+
locale?: string, // Storefront locale (default: SDK/client locale)
|
|
406
349
|
storageUrl?: string, // Storage URL (default: https://storage.arky.io/dev)
|
|
407
350
|
autoGuest?: boolean, // Auto-create guest token (default: true)
|
|
408
351
|
logout?: () => void, // Logout callback
|
|
@@ -1990,11 +1990,19 @@ function createArkyStore(config) {
|
|
|
1990
1990
|
id: current.id,
|
|
1991
1991
|
payment_method_id: input.payment_method_id || void 0
|
|
1992
1992
|
});
|
|
1993
|
+
const quoteValue = quote.get();
|
|
1993
1994
|
const stored = {
|
|
1994
1995
|
order_id: response.order_id,
|
|
1995
1996
|
number: response.number,
|
|
1996
1997
|
client_secret: response.client_secret,
|
|
1997
1998
|
payment: response.payment,
|
|
1999
|
+
product_items: input.product_items || product_items.get(),
|
|
2000
|
+
service_items: input.service_items || service_items.get(),
|
|
2001
|
+
shipping_address: input.shipping_address || null,
|
|
2002
|
+
billing_address: input.billing_address || null,
|
|
2003
|
+
total: quoteValue?.payment?.total || quoteValue?.total || response.payment?.total,
|
|
2004
|
+
currency: quoteValue?.payment?.currency || currentCurrency(),
|
|
2005
|
+
payment_method_id: input.payment_method_id || null,
|
|
1998
2006
|
created_at: Date.now()
|
|
1999
2007
|
};
|
|
2000
2008
|
last_order.set(stored);
|