arky-sdk 0.7.119 → 0.7.121

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
@@ -76,22 +76,56 @@ const formatted = arky.utils.formatPrice(product.variants[0].prices); // "$29.99
76
76
  ### 3. Shop & Checkout
77
77
 
78
78
  ```typescript
79
- // Add to cart and checkout (like arky.io/cart)
80
- const order = await arky.eshop.checkout({
81
- items: [{
82
- productId: 'prod_123',
83
- variantId: 'var_456',
84
- quantity: 2
85
- }],
86
- paymentMethod: 'CREDIT_CARD',
87
- shippingMethodId: 'standard',
88
- blocks: [ // Customer info
89
- { key: 'email', values: ['customer@example.com'] },
90
- { key: 'shipping_address', values: ['123 Main St'] }
91
- ]
79
+ const cart = await arky.eshop.cart.current();
80
+
81
+ await arky.eshop.cart.addItem({
82
+ id: cart.id,
83
+ item: {
84
+ type: 'product',
85
+ product_id: 'prod_123',
86
+ variant_id: 'var_456',
87
+ quantity: 2,
88
+ },
89
+ });
90
+
91
+ const order = await arky.eshop.cart.checkout({
92
+ id: cart.id,
93
+ payment_method_id: 'credit_card',
92
94
  });
93
95
  ```
94
96
 
97
+ ### Framework-agnostic Cart Controller
98
+
99
+ For storefront UI state, use the headless cart controller instead of wiring cart API calls directly into a framework store:
100
+
101
+ ```typescript
102
+ const storefront = createStorefront({
103
+ baseUrl: 'https://api.arky.io',
104
+ storeId: 'your-store-id',
105
+ market: 'us',
106
+ })
107
+
108
+ const unsubscribe = storefront.cart.subscribe((state) => {
109
+ console.log(state.cart, state.quote, state.loading, state.error)
110
+ })
111
+
112
+ await storefront.cart.init()
113
+ await storefront.cart.addItem({
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' })
123
+
124
+ unsubscribe()
125
+ ```
126
+
127
+ The controller exposes `subscribe`, `getState`, `init`, `refresh`, `addItem`, `update`, `removeItem`, `clear`, `quote`, and `checkout`. It is framework-agnostic and uses the existing storefront cart API methods under the hood.
128
+
95
129
  ### 4. Sell Scheduled Services
96
130
 
97
131
  ```typescript
@@ -106,10 +140,12 @@ const availability = await arky.eshop.service.getAvailability({
106
140
  to: Math.floor(Date.now() / 1000) + 86400,
107
141
  });
108
142
 
109
- // Create an order with a service line
110
- const order = await arky.eshop.order.checkout({
143
+ const cart = await arky.eshop.cart.current();
144
+
145
+ await arky.eshop.cart.update({
146
+ id: cart.id,
111
147
  items: [{
112
- type: 'service',
148
+ type: 'booking',
113
149
  service_id: 'service_haircut',
114
150
  provider_id: 'provider_jane',
115
151
  slots: [{
@@ -117,9 +153,13 @@ const order = await arky.eshop.order.checkout({
117
153
  to: availability.available_slots[0].to,
118
154
  }],
119
155
  }],
120
- payment_method: 'cash',
121
156
  forms: [],
122
157
  });
158
+
159
+ const order = await arky.eshop.cart.checkout({
160
+ id: cart.id,
161
+ payment_method_id: 'cash',
162
+ });
123
163
  ```
124
164
 
125
165
  ### 5. Subscribe to Newsletter
@@ -215,8 +255,10 @@ await arky.eshop.getProducts({ limit: 20, cursor: null })
215
255
  await arky.eshop.getProduct({ id })
216
256
  await arky.eshop.updateProduct({ id, name })
217
257
 
218
- // Orders
219
- await arky.eshop.checkout({ items, paymentMethod, shippingMethodId })
258
+ // Carts and orders
259
+ const cart = await arky.eshop.cart.current()
260
+ await arky.eshop.cart.update({ id: cart.id, items, shipping_method_id })
261
+ await arky.eshop.cart.checkout({ id: cart.id, payment_method_id })
220
262
  await arky.eshop.getOrders({})
221
263
  await arky.eshop.getOrder({ id })
222
264
  await arky.eshop.updateOrderStatus({ id, status: 'SHIPPED' })
@@ -240,9 +282,9 @@ await arky.eshop.service.getAvailability({ service_id, provider_id, from, to })
240
282
  await arky.eshop.provider.create({ name })
241
283
  await arky.eshop.provider.find({})
242
284
 
243
- // Service orders
285
+ // Service cart checkout
244
286
  await arky.eshop.order.getQuote({ items, payment_method })
245
- await arky.eshop.order.checkout({ items, payment_method })
287
+ await arky.eshop.cart.checkout({ id: cart.id, payment_method_id })
246
288
  await arky.eshop.order.find({})
247
289
  ```
248
290
 
package/dist/admin.cjs CHANGED
@@ -1042,35 +1042,6 @@ var createEshopApi = (apiConfig) => {
1042
1042
  options
1043
1043
  );
1044
1044
  },
1045
- async createOrder(params, options) {
1046
- const { store_id, items, ...rest } = params;
1047
- const target_store_id = store_id || apiConfig.storeId;
1048
- const payload = {
1049
- ...rest,
1050
- market: rest.market || apiConfig.market,
1051
- items: normalizeOrderCheckoutItems(items)
1052
- };
1053
- return apiConfig.httpClient.post(
1054
- `/v1/stores/${target_store_id}/orders`,
1055
- payload,
1056
- options
1057
- );
1058
- },
1059
- async checkoutOrder(params, options) {
1060
- const { store_id, items, ...rest } = params;
1061
- const target_store_id = store_id || apiConfig.storeId;
1062
- const payload = {
1063
- ...rest,
1064
- store_id: target_store_id,
1065
- market: rest.market || apiConfig.market,
1066
- items: normalizeOrderCheckoutItems(items)
1067
- };
1068
- return apiConfig.httpClient.post(
1069
- `/v1/stores/${target_store_id}/orders/checkout`,
1070
- payload,
1071
- options
1072
- );
1073
- },
1074
1045
  async updateOrder(params, options) {
1075
1046
  const { store_id, items, ...rest } = params;
1076
1047
  const target_store_id = store_id || apiConfig.storeId;
@@ -1102,6 +1073,91 @@ var createEshopApi = (apiConfig) => {
1102
1073
  }
1103
1074
  );
1104
1075
  },
1076
+ async getCarts(params = {}, options) {
1077
+ const { store_id, ...queryParams } = params;
1078
+ const target_store_id = store_id || apiConfig.storeId;
1079
+ return apiConfig.httpClient.get(
1080
+ `/v1/stores/${target_store_id}/carts`,
1081
+ {
1082
+ ...options,
1083
+ params: queryParams
1084
+ }
1085
+ );
1086
+ },
1087
+ async getCart(params, options) {
1088
+ const target_store_id = params.store_id || apiConfig.storeId;
1089
+ return apiConfig.httpClient.get(
1090
+ `/v1/stores/${target_store_id}/carts/${params.id}`,
1091
+ options
1092
+ );
1093
+ },
1094
+ async createCart(params, options) {
1095
+ const { store_id, ...payload } = params;
1096
+ const target_store_id = store_id || apiConfig.storeId;
1097
+ return apiConfig.httpClient.post(
1098
+ `/v1/stores/${target_store_id}/carts`,
1099
+ {
1100
+ ...payload,
1101
+ items: normalizeOrderCheckoutItems(payload.items || [])
1102
+ },
1103
+ options
1104
+ );
1105
+ },
1106
+ async updateCart(params, options) {
1107
+ const { id, store_id, items, ...payload } = params;
1108
+ const target_store_id = store_id || apiConfig.storeId;
1109
+ return apiConfig.httpClient.put(
1110
+ `/v1/stores/${target_store_id}/carts/${id}`,
1111
+ {
1112
+ ...payload,
1113
+ ...items ? { items: normalizeOrderCheckoutItems(items) } : {}
1114
+ },
1115
+ options
1116
+ );
1117
+ },
1118
+ async addCartItem(params, options) {
1119
+ const { id, store_id, item } = params;
1120
+ const target_store_id = store_id || apiConfig.storeId;
1121
+ return apiConfig.httpClient.post(
1122
+ `/v1/stores/${target_store_id}/carts/${id}/items`,
1123
+ { item: normalizeOrderCheckoutItems([item])[0] },
1124
+ options
1125
+ );
1126
+ },
1127
+ async removeCartItem(params, options) {
1128
+ const { id, store_id, ...payload } = params;
1129
+ const target_store_id = store_id || apiConfig.storeId;
1130
+ return apiConfig.httpClient.post(
1131
+ `/v1/stores/${target_store_id}/carts/${id}/items/remove`,
1132
+ payload,
1133
+ options
1134
+ );
1135
+ },
1136
+ async clearCart(params, options) {
1137
+ const target_store_id = params.store_id || apiConfig.storeId;
1138
+ return apiConfig.httpClient.post(
1139
+ `/v1/stores/${target_store_id}/carts/${params.id}/clear`,
1140
+ {},
1141
+ options
1142
+ );
1143
+ },
1144
+ async quoteCart(params, options) {
1145
+ const target_store_id = params.store_id || apiConfig.storeId;
1146
+ return apiConfig.httpClient.post(
1147
+ `/v1/stores/${target_store_id}/carts/${params.id}/quote`,
1148
+ {},
1149
+ options
1150
+ );
1151
+ },
1152
+ async checkoutCart(params, options) {
1153
+ const { id, store_id, ...payload } = params;
1154
+ const target_store_id = store_id || apiConfig.storeId;
1155
+ return apiConfig.httpClient.post(
1156
+ `/v1/stores/${target_store_id}/carts/${id}/checkout`,
1157
+ payload,
1158
+ options
1159
+ );
1160
+ },
1105
1161
  async getQuote(params, options) {
1106
1162
  const { location, store_id, items, ...rest } = params;
1107
1163
  const target_store_id = store_id || apiConfig.storeId;
@@ -1271,6 +1327,8 @@ var createCustomerApi = (apiConfig) => {
1271
1327
  if (params?.query) queryParams.query = params.query;
1272
1328
  if (params?.taxonomy_query) queryParams.taxonomy_query = params.taxonomy_query;
1273
1329
  if (params?.status) queryParams.status = params.status;
1330
+ if (params?.has_activity !== void 0) queryParams.has_activity = params.has_activity;
1331
+ if (params?.has_cart !== void 0) queryParams.has_cart = params.has_cart;
1274
1332
  if (params?.sort_field) queryParams.sort_field = params.sort_field;
1275
1333
  if (params?.sort_direction) queryParams.sort_direction = params.sort_direction;
1276
1334
  return apiConfig.httpClient.get(
@@ -2286,14 +2344,23 @@ function createAdmin(config) {
2286
2344
  find: eshopApi.getProducts
2287
2345
  },
2288
2346
  order: {
2289
- create: eshopApi.createOrder,
2290
2347
  update: eshopApi.updateOrder,
2291
2348
  get: eshopApi.getOrder,
2292
2349
  find: eshopApi.getOrders,
2293
2350
  getQuote: eshopApi.getQuote,
2294
- checkout: eshopApi.checkoutOrder,
2295
2351
  processRefund: eshopApi.processRefund
2296
2352
  },
2353
+ cart: {
2354
+ create: eshopApi.createCart,
2355
+ update: eshopApi.updateCart,
2356
+ get: eshopApi.getCart,
2357
+ find: eshopApi.getCarts,
2358
+ addItem: eshopApi.addCartItem,
2359
+ removeItem: eshopApi.removeCartItem,
2360
+ clear: eshopApi.clearCart,
2361
+ quote: eshopApi.quoteCart,
2362
+ checkout: eshopApi.checkoutCart
2363
+ },
2297
2364
  service: {
2298
2365
  create: eshopApi.createService,
2299
2366
  update: eshopApi.updateService,