arky-sdk 0.7.133 → 0.7.134

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 CHANGED
@@ -42,21 +42,30 @@ const arkyStore = createArkyStore({
42
42
  storeId: 'your-store-id',
43
43
  market: 'us',
44
44
  locale: 'en',
45
+ marketForLocale: (locale) => locale === 'it' ? 'ita' : 'us',
45
46
  })
46
47
 
47
- await arkyStore.initialize({ hydrate_cart: true, load_website: true })
48
+ const { cart } = await arkyStore.setup({
49
+ locale: 'en',
50
+ hydrateCart: true,
51
+ })
52
+
53
+ const websiteNode = await arkyStore.cms.node.get({
54
+ key: 'website',
55
+ locale: 'en',
56
+ })
48
57
  ```
49
58
 
50
59
  ### 2. Browse Products
51
60
 
52
61
  ```typescript
53
62
  // List products (like on arky.io/products)
54
- const { items: products } = await arkyStore.eshop.product.find({
63
+ const { items: products } = await arkyStore.eshop.product.list({
55
64
  limit: 20
56
65
  });
57
66
 
58
67
  // Get product details (like arky.io/products/guitar)
59
- const product = await arkyStore.eshop.product.get({ id: 'prod_123' });
68
+ const product = await arkyStore.eshop.product.loadDetail({ id: 'prod_123' });
60
69
 
61
70
  // Format price (uses currency from price object)
62
71
  const formatted = arkyStore.utils.formatPrice(product.variants[0].prices); // "$29.99"
@@ -65,272 +74,143 @@ const formatted = arkyStore.utils.formatPrice(product.variants[0].prices); // "$
65
74
  ### 3. Shop & Checkout
66
75
 
67
76
  ```typescript
68
- const product = await arkyStore.eshop.product.get({ id: 'prod_123' })
77
+ const product = await arkyStore.eshop.product.loadDetail({ id: 'prod_123' })
69
78
  const variant = product.variants[0]
70
79
 
71
- await arkyStore.eshop.cart.actions.addProduct(product, variant, 2)
80
+ await arkyStore.eshop.cart.addProduct(product, variant, 2)
72
81
 
73
- const quote = await arkyStore.eshop.cart.actions.quote()
82
+ const quote = await arkyStore.eshop.cart.quote()
74
83
 
75
- const order = await arkyStore.eshop.cart.actions.checkout({
84
+ const order = await arkyStore.eshop.cart.checkout({
76
85
  payment_method_id: 'credit_card',
77
86
  })
78
87
  ```
79
88
 
80
89
  ### Framework-Agnostic Store
81
90
 
82
- The storefront store is framework-agnostic and built on Nano Stores. UI frameworks can subscribe to atoms directly, while app code calls actions:
91
+ The storefront store is framework-agnostic and built on Nano Stores. UI frameworks can subscribe to atoms directly, while app code calls direct store methods:
83
92
 
84
93
  ```typescript
94
+ await arkyStore.setup({
95
+ locale: 'en',
96
+ hydrateCart: true,
97
+ track: {
98
+ type: 'page_view',
99
+ payload: { url: location.pathname },
100
+ },
101
+ })
102
+
85
103
  const unsubscribe = arkyStore.eshop.cart.snapshot.subscribe((snapshot) => {
86
104
  console.log(snapshot.item_count, snapshot.cart?.id)
87
105
  });
88
106
 
89
- await arkyStore.eshop.cart.actions.ensure();
90
- await arkyStore.eshop.cart.actions.clear();
107
+ await arkyStore.eshop.cart.ensure();
108
+ await arkyStore.eshop.cart.clear();
91
109
 
92
110
  unsubscribe();
93
111
  ```
94
112
 
113
+ For content-heavy pages, a website node load can be a single context-aware call:
114
+
115
+ ```typescript
116
+ const website = await arkyStore.cms.node.get({ key: "website", locale: 'en' })
117
+ const info = website.blocks.find((block) => block.key === 'info')
118
+ ```
119
+
95
120
  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`.
96
121
 
97
122
  ### 4. Sell Scheduled Services
98
123
 
99
124
  ```typescript
100
125
  // Browse services (like arky.io/services)
101
- const { items: services } = await arkyStore.eshop.service.find({});
126
+ const { items: services } = await arkyStore.eshop.service.list({});
102
127
  const service = services[0];
103
128
 
104
- await arkyStore.eshop.serviceOrder.actions.initialize();
105
- await arkyStore.eshop.serviceOrder.actions.setService(service);
106
- arkyStore.eshop.serviceOrder.actions.findFirstAvailable();
129
+ await arkyStore.eshop.service.initialize();
130
+ await arkyStore.eshop.service.select(service);
131
+ arkyStore.eshop.service.findFirstAvailable();
107
132
 
108
- const state = arkyStore.eshop.serviceOrder.state.get();
133
+ const state = arkyStore.eshop.service.state.get();
109
134
  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();
135
+ arkyStore.eshop.service.selectTimeSlot(state.slots[0]);
136
+ arkyStore.eshop.service.nextStep();
137
+ await arkyStore.eshop.service.addToCart();
113
138
  }
114
139
 
115
- const order = await arkyStore.eshop.serviceOrder.actions.checkout('cash');
116
- ```
117
-
118
- ### 5. Subscribe to Newsletter
119
-
120
- ```typescript
121
- // Subscribe to updates (like arky.io/newsletters)
122
- await arky.cms.subscribeToCollection({
123
- collectionId: 'newsletter_weekly',
124
- email: 'user@example.com',
125
- planId: 'plan_free'
126
- });
127
- ```
128
-
129
- ### 6. Read Content
130
-
131
- ```typescript
132
- // Fetch blog posts or content
133
- const { items: posts } = await arky.cms.getCollectionEntries({
134
- collectionId: 'blog',
135
- limit: 10
140
+ const order = await arkyStore.eshop.cart.checkout({
141
+ payment_method_id: 'cash',
136
142
  });
137
-
138
- // Extract content from blocks
139
- const title = arky.utils.getBlockTextValue(
140
- posts[0].blocks.find(b => b.key === 'title'),
141
- 'en'
142
- );
143
- const imageUrl = arky.utils.getImageUrl(
144
- posts[0].blocks.find(b => b.key === 'featured_image')
145
- );
146
- ```
147
-
148
- ## API Methods
149
-
150
- The SDK provides the following API modules:
151
-
152
- ### User Management
153
- ```typescript
154
- // Authentication
155
- await arky.user.loginUser({ email, password })
156
- await arky.user.registerUser({ email, password, name })
157
- await arky.user.getMe()
158
- await arky.user.logout()
159
-
160
- // Profile
161
- await arky.user.updateUser({ name, phoneNumber, addresses })
162
- await arky.user.resetPassword({ oldPassword, newPassword })
163
143
  ```
164
144
 
165
- ### Store
166
- ```typescript
167
- // Store CRUD
168
- await arky.store.createStore({ name, slug })
169
- await arky.store.getStore()
170
- await arky.store.updateStore({ id, name })
171
- await arky.store.deleteStore({ id })
172
-
173
- // Subscriptions
174
- await arky.store.createSubscription({ planId })
175
- await arky.store.getSubscription()
176
- await arky.store.cancelSubscription({ immediately: true })
177
- ```
145
+ ### 5. Read Content And Submit Forms
178
146
 
179
- ### CMS & Newsletters
180
147
  ```typescript
181
- // Collections
182
- await arky.cms.createCollection({ name, slug, type: 'NEWSLETTER' })
183
- await arky.cms.getCollections({ type: 'NEWSLETTER' })
184
- await arky.cms.getCollection({ id })
185
- await arky.cms.updateCollection({ id, name })
186
- await arky.cms.deleteCollection({ id })
187
-
188
- // Entries (Content)
189
- await arky.cms.createCollectionEntry({ collectionId, blocks })
190
- await arky.cms.getCollectionEntries({ collectionId })
191
- await arky.cms.updateCollectionEntry({ id, blocks })
192
- await arky.cms.sendEntry({ entryId, scheduledAt })
193
-
194
- // Newsletter Subscriptions
195
- await arky.cms.subscribeToCollection({
196
- collectionId: 'newsletter_id',
197
- email: 'user@example.com',
198
- planId: 'plan_free', // Required
148
+ const website = await arkyStore.cms.node.get({ key: "website", locale: 'en' })
149
+ const titleBlock = website.blocks.find((block) => block.key === 'title')
150
+ const title = arkyStore.utils.getBlockTextValue(titleBlock, 'en')
151
+
152
+ await arkyStore.cms.form.submitByKey({
153
+ key: 'contact',
154
+ entries: [
155
+ { key: 'email', value: 'customer@example.com' },
156
+ { key: 'message', value: 'Hello from the storefront' },
157
+ ],
199
158
  })
200
- await arky.cms.getCollectionSubscribers({ id: 'newsletter_id' })
201
159
  ```
202
160
 
203
- ### E-shop
204
- ```typescript
205
- // Products
206
- await arkyStore.eshop.product.find({ limit: 20, cursor: null })
207
- await arkyStore.eshop.product.get({ id })
208
-
209
- // Carts and orders
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 })
215
-
216
- // Quote
217
- await arkyStore.eshop.cart.actions.quote()
218
- ```
161
+ ## Storefront Modules
219
162
 
220
- ### Services
221
- ```typescript
222
- // Services
223
- await arky.eshop.service.create({ name, duration, price })
224
- await arky.eshop.service.find({})
225
- await arky.eshop.service.getAvailability({ service_id, provider_id, from, to })
226
-
227
- // Providers
228
- await arky.eshop.provider.create({ name })
229
- await arky.eshop.provider.find({})
230
-
231
- // Service cart checkout
232
- await arky.eshop.order.getQuote({ items, payment_method })
233
- await arky.eshop.cart.checkout({ id: cart.id, payment_method_id })
234
- await arky.eshop.order.find({})
235
- ```
163
+ The store-shaped API is the preferred surface for websites:
236
164
 
237
- ### Media
238
165
  ```typescript
239
- // Upload files
240
- const media = await arky.media.uploadStoreMedia({
241
- files: [file1, file2],
242
- urls: ['https://example.com/image.jpg'],
243
- })
166
+ await arkyStore.setup({ hydrateCart: true })
244
167
 
245
- // List media
246
- const { items } = await arky.media.getStoreMedia({ limit: 20 })
168
+ await arkyStore.cms.node.get({ key: "website", locale: 'en' })
169
+ await arkyStore.cms.form.submitByKey({ key: 'contact', entries: [] })
247
170
 
248
- // Delete media
249
- await arky.media.deleteStoreMedia({ id: storeId, mediaId })
250
- ```
251
-
252
- ### Notifications
253
- ```typescript
254
- // Get notifications
255
- const notifications = await arky.notification.getNotifications({
256
- limit: 20,
257
- previous_id: null,
258
- })
171
+ await arkyStore.eshop.product.list({ limit: 20 })
172
+ await arkyStore.eshop.cart.ensure()
173
+ await arkyStore.eshop.cart.quote()
174
+ await arkyStore.eshop.cart.checkout({ payment_method_id: 'cash' })
259
175
 
260
- // Mark as seen
261
- await arky.notification.updateNotifications({})
176
+ await arkyStore.eshop.service.list({ limit: 20 })
177
+ await arkyStore.eshop.service.initialize()
262
178
 
263
- // Delivery stats
264
- const stats = await arky.notification.getDeliveryStats({})
179
+ await arkyStore.activity.pageView({ path: location.pathname })
265
180
  ```
266
181
 
267
- ### Roles & Permissions
268
- ```typescript
269
- await arky.role.createRole({ name, permissions })
270
- await arky.role.getRoles({ action: 'READ' })
271
- await arky.role.updateRole({ id, permissions })
272
- await arky.user.setRole({ userId, roleId })
273
- ```
182
+ ## Low-Level Client
274
183
 
275
- ## Utility Functions
184
+ The underlying SDK remains available for admin tools or uncommon integrations:
276
185
 
277
- The SDK includes helpful utilities accessible via `arky.utils`:
278
-
279
- ### Block Utilities
280
186
  ```typescript
281
- // Get image URL from block
282
- const url = arky.utils.getImageUrl(imageBlock)
283
-
284
- // Get block value
285
- const value = arky.utils.getBlockValue(entry, 'title')
187
+ const sdk = arkyStore.client
286
188
 
287
- // Format blocks
288
- const formatted = arky.utils.formatBlockValue(block)
289
- const forSubmit = arky.utils.prepareBlocksForSubmission(blocks)
189
+ await sdk.eshop.product.find({ limit: 20 })
190
+ await sdk.eshop.cart.current({ market: arkyStore.getMarket() })
191
+ await sdk.eshop.order.find({})
192
+ await sdk.cms.node.get({ key: 'website' })
290
193
  ```
291
194
 
292
- ### Price Utilities
293
- ```typescript
294
- // Format prices
295
- const formatted = arky.utils.formatMinor(999, 'usd') // "$9.99"
296
- const payment = arky.utils.formatPayment(paymentObject)
297
-
298
- // Format prices from array
299
- const formatted = arky.utils.formatPrice(prices) // "$9.99"
300
- const amount = arky.utils.getPriceAmount(prices, 'US')
301
- ```
302
-
303
- ### Text Utilities
304
- ```typescript
305
- const slug = arky.utils.slugify('Hello World') // "hello-world"
306
- const title = arky.utils.humanize('hello-world') // "Hello World"
307
- const category = arky.utils.categorify('hello-world') // "HELLO WORLD"
308
- const date = arky.utils.formatDate(timestamp, 'en')
309
- ```
195
+ ## Utility Functions
310
196
 
311
- ### Validation
312
- ```typescript
313
- const result = arky.utils.validatePhoneNumber('+1234567890')
314
- // { isValid: true } or { isValid: false, error: "..." }
315
- ```
197
+ The SDK includes helpful utilities accessible through `arkyStore.utils`:
316
198
 
317
- ### SVG Utilities
318
199
  ```typescript
319
- // Fetch SVG content
320
- const svgString = await arky.utils.fetchSvgContent(mediaBlock)
321
-
322
- // For Astro
323
- const svg = await arky.utils.getSvgContentForAstro(mediaBlock)
324
-
325
- // Inject into element
326
- await arky.utils.injectSvgIntoElement(mediaBlock, element, 'custom-class')
200
+ const title = arkyStore.utils.getBlockTextValue(block, 'en')
201
+ const imageUrl = arkyStore.utils.getImageUrl(imageBlock)
202
+ const price = arkyStore.utils.formatPrice(prices)
203
+ const payment = arkyStore.utils.formatPayment(paymentObject)
204
+ const slug = arkyStore.utils.slugify('Hello World')
205
+ const date = arkyStore.utils.formatDate(Date.now(), 'en')
206
+ const phone = arkyStore.utils.validatePhoneNumber('+1234567890')
327
207
  ```
328
208
 
329
209
  ## What Can You Build?
330
210
 
331
211
  - 🏪 **E-commerce shops** - Product catalogs, shopping carts, checkout
332
212
  - 📰 **Content websites** - Blogs, documentation, marketing sites
333
- - 📅 **Service businesses** - Appointment scheduling, service orders
213
+ - 📅 **Service businesses** - Appointment scheduling, service scheduling
334
214
  - 📬 **Newsletter platforms** - Subscriber management, email campaigns
335
215
  - 🏢 **SaaS products** - Multi-tenant apps with user auth and billing
336
216
  - 🛍️ **Marketplaces** - Multi-vendor platforms with payments
@@ -342,16 +222,14 @@ createArkyStore({
342
222
  // Required
343
223
  baseUrl: string, // API URL
344
224
  storeId: string, // Your store ID
345
- market: string, // Market code (e.g., 'us', 'eu')
346
225
 
347
226
  // Optional
227
+ market?: string, // Market key (e.g., 'us', 'eu')
348
228
  locale?: string, // Storefront locale (default: SDK/client locale)
349
- storageUrl?: string, // Storage URL (default: https://storage.arky.io/dev)
350
- autoGuest?: boolean, // Auto-create guest token (default: true)
351
- logout?: () => void, // Logout callback
352
- isAuthenticated?: () => boolean,
229
+ apiToken?: string, // Trusted server-side API token
230
+ marketForLocale?: (locale: string) => string | null,
353
231
  navigate?: (path: string) => void,
354
- notify?: (notification: { message: string; type: string }) => void,
232
+ loginFallbackPath?: string,
355
233
  })
356
234
  ```
357
235