arky-sdk 0.7.120 → 0.7.122

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
@@ -94,6 +94,38 @@ const order = await arky.eshop.cart.checkout({
94
94
  });
95
95
  ```
96
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
+
97
129
  ### 4. Sell Scheduled Services
98
130
 
99
131
  ```typescript
package/dist/admin.cjs CHANGED
@@ -1091,6 +1091,73 @@ var createEshopApi = (apiConfig) => {
1091
1091
  options
1092
1092
  );
1093
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
+ },
1094
1161
  async getQuote(params, options) {
1095
1162
  const { location, store_id, items, ...rest } = params;
1096
1163
  const target_store_id = store_id || apiConfig.storeId;
@@ -2284,8 +2351,15 @@ function createAdmin(config) {
2284
2351
  processRefund: eshopApi.processRefund
2285
2352
  },
2286
2353
  cart: {
2354
+ create: eshopApi.createCart,
2355
+ update: eshopApi.updateCart,
2287
2356
  get: eshopApi.getCart,
2288
- find: eshopApi.getCarts
2357
+ find: eshopApi.getCarts,
2358
+ addItem: eshopApi.addCartItem,
2359
+ removeItem: eshopApi.removeCartItem,
2360
+ clear: eshopApi.clearCart,
2361
+ quote: eshopApi.quoteCart,
2362
+ checkout: eshopApi.checkoutCart
2289
2363
  },
2290
2364
  service: {
2291
2365
  create: eshopApi.createService,