@c1m-public/channel-client 0.4.0 → 0.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 CHANGED
@@ -28,6 +28,15 @@ const channel = createNextChannelClient({
28
28
  });
29
29
 
30
30
  const { page } = await channel.pages.get("home");
31
+
32
+ const { order: cart } = await channel.cart.addItem(
33
+ { product_id: "product-id", quantity: 1 },
34
+ { idempotencyKey: crypto.randomUUID() },
35
+ );
36
+ const checkout = await channel.checkout.pay(
37
+ { cart_token: cart.cart_token!, return_url: "https://example.com/checkout/complete" },
38
+ { idempotencyKey: crypto.randomUUID() },
39
+ );
31
40
  ```
32
41
 
33
42
  ### Other server runtimes
@@ -53,6 +62,8 @@ other runtimes must enforce their own server-module boundary.
53
62
  - The Next adapter supports explicit revalidation and tags.
54
63
  - Writes are always `no-store`, are never automatically retried, and accept an
55
64
  explicit idempotency key.
65
+ - Cart and checkout operations use an opaque `cart_token`; the channel token
66
+ continues to resolve tenant and workspace identity at the API door.
56
67
  - Requests time out after 10 seconds by default.
57
68
  - API failures throw `ChannelAPIError` with safe status, code, and request ID.
58
69
  - Assets remain tokenless and are normalized with `assetUrl()`.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from "./webhooks.js";
2
- export type { BlogPost, BlogPostResponse, ChannelPing, Customer, CustomerResponse, CustomerSession, CustomerSignupResponse, LeadResponse, Order, OrderSummary, SendCodeResponse, LightInitResponse, ListResponse, Product, ProductAsset, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, Menu, MenuItem, MenuResponse, Review, ReviewSummaryResponse, SiteDocument, SiteGatedDocument, SiteResolvedDocument, ThemeResponse, } from "./types";
3
- import type { BlogPostResponse, ChannelPing, CustomerResponse, CustomerSession, CustomerSignupResponse, LeadResponse, LightInitResponse, ListResponse, Order, OrderSummary, SendCodeResponse, Product, ProductAsset, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, MenuResponse, Review, ReviewSummaryResponse, SiteDocument, ThemeResponse } from "./types";
2
+ export type { BlogPost, BlogPostResponse, AddCartItemInput, CartResponse, CheckoutAddress, CheckoutAddressesInput, CheckoutCustomerInput, CheckoutFulfillmentInput, CheckoutOptions, CheckoutPayInput, CheckoutPayResponse, CheckoutStatus, CheckoutStatusResponse, ChannelPing, Customer, CustomerResponse, CustomerSession, CustomerSignupResponse, LeadResponse, Order, OrderItem, OrderSummary, MergeCartInput, SendCodeResponse, LightInitResponse, ListResponse, Product, ProductAsset, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, Menu, MenuItem, MenuResponse, Review, ReviewSummaryResponse, PaymentMethodOption, PaymentReadiness, ShippingMethodOption, SiteDocument, SiteGatedDocument, SiteResolvedDocument, ThemeResponse, UpdateCartItemInput, } from "./types";
3
+ import type { BlogPostResponse, AddCartItemInput, CartResponse, CheckoutAddressesInput, CheckoutCustomerInput, CheckoutFulfillmentInput, CheckoutOptions, CheckoutPayInput, CheckoutPayResponse, CheckoutStatusResponse, ChannelPing, CustomerResponse, CustomerSession, CustomerSignupResponse, LeadResponse, LightInitResponse, ListResponse, Order, OrderSummary, MergeCartInput, SendCodeResponse, Product, ProductAsset, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, MenuResponse, Review, ReviewSummaryResponse, SiteDocument, ThemeResponse, UpdateCartItemInput } from "./types";
4
4
  export interface ChannelRetryPolicy {
5
5
  attempts?: number;
6
6
  maxDelayMs?: number;
@@ -14,7 +14,7 @@ export interface CreateChannelClientOptions {
14
14
  observe?: ChannelRequestObserver;
15
15
  }
16
16
  export type ChannelRequestOutcome = "success" | "api_error" | "network_error" | "timeout" | "invalid_response";
17
- export type ChannelOperation = "channel.ping" | "channel.site.resolve" | "channel.init.get" | "channel.init.light" | "content.pages.public.list.channel" | "content.pages.public.get.channel" | "shop.public.products.list.channel" | "shop.public.products.get.channel" | "shop.public.products.media.channel" | "reviews.public.list.channel" | "reviews.public.summary.channel" | "reviews.public.submit.channel" | "channel.theme.get" | "channel.menus.get" | "channel.blog.get" | "channel.auth.check" | "channel.auth.signup" | "channel.auth.send_code" | "channel.auth.verify_code" | "channel.auth.refresh" | "channel.auth.me" | "channel.auth.me.update" | "channel.auth.logout" | "channel.account.orders.list" | "channel.account.orders.summary" | "channel.account.orders.get" | "growth.public_workspace.leads.capture.channel";
17
+ export type ChannelOperation = "channel.ping" | "channel.site.resolve" | "channel.init.get" | "channel.init.light" | "content.pages.public.list.channel" | "content.pages.public.get.channel" | "shop.public.products.list.channel" | "shop.public.products.get.channel" | "shop.public.products.media.channel" | "reviews.public.list.channel" | "reviews.public.summary.channel" | "reviews.public.submit.channel" | "channel.theme.get" | "channel.menus.get" | "channel.blog.get" | "channel.auth.check" | "channel.auth.signup" | "channel.auth.send_code" | "channel.auth.verify_code" | "channel.auth.refresh" | "channel.auth.me" | "channel.auth.me.update" | "channel.auth.logout" | "channel.account.orders.list" | "channel.account.orders.summary" | "channel.account.orders.get" | "channel.cart.get" | "channel.cart.items.add" | "channel.cart.items.update" | "channel.cart.items.remove" | "channel.cart.clear" | "channel.cart.merge" | "channel.checkout.options" | "channel.checkout.status" | "channel.checkout.customer" | "channel.checkout.addresses" | "channel.checkout.fulfillment" | "channel.checkout.pay" | "growth.public_workspace.leads.capture.channel";
18
18
  export interface ChannelRequestObservation {
19
19
  operation: ChannelOperation;
20
20
  method: string;
@@ -50,6 +50,10 @@ export interface ChannelLeadInput {
50
50
  export interface ChannelMutationOptions {
51
51
  idempotencyKey?: string;
52
52
  }
53
+ export interface ChannelCheckoutStatusParams {
54
+ cartToken?: string;
55
+ checkoutSessionId?: string;
56
+ }
53
57
  export declare class ChannelAPIError extends Error {
54
58
  readonly status: number;
55
59
  readonly code: string;
@@ -88,6 +92,22 @@ export declare function createChannelClient(options: CreateChannelClientOptions)
88
92
  }>;
89
93
  readonly media: (slug: string) => Promise<ListResponse<ProductAsset>>;
90
94
  };
95
+ readonly cart: {
96
+ readonly get: (cartToken: string) => Promise<CartResponse>;
97
+ readonly addItem: (input: AddCartItemInput, mutation?: ChannelMutationOptions) => Promise<CartResponse>;
98
+ readonly updateItem: (itemId: string, input: UpdateCartItemInput, mutation?: ChannelMutationOptions) => Promise<CartResponse>;
99
+ readonly removeItem: (itemId: string, cartToken: string, mutation?: ChannelMutationOptions) => Promise<CartResponse>;
100
+ readonly clear: (cartToken: string, mutation?: ChannelMutationOptions) => Promise<CartResponse>;
101
+ readonly merge: (input: MergeCartInput, mutation?: ChannelMutationOptions) => Promise<CartResponse>;
102
+ };
103
+ readonly checkout: {
104
+ readonly options: (cartToken: string) => Promise<CheckoutOptions>;
105
+ readonly status: (params?: ChannelCheckoutStatusParams) => Promise<CheckoutStatusResponse>;
106
+ readonly setCustomer: (input: CheckoutCustomerInput, mutation?: ChannelMutationOptions) => Promise<CartResponse>;
107
+ readonly setAddresses: (input: CheckoutAddressesInput, mutation?: ChannelMutationOptions) => Promise<CartResponse>;
108
+ readonly setFulfillment: (input: CheckoutFulfillmentInput, mutation?: ChannelMutationOptions) => Promise<CartResponse>;
109
+ readonly pay: (input: CheckoutPayInput, mutation?: ChannelMutationOptions) => Promise<CheckoutPayResponse>;
110
+ };
91
111
  readonly reviews: {
92
112
  readonly list: (params?: ChannelListParams) => Promise<ListResponse<Review>>;
93
113
  readonly summary: () => Promise<ReviewSummaryResponse>;
package/dist/index.js CHANGED
@@ -173,6 +173,47 @@ export function createChannelClient(options) {
173
173
  get: (slug) => request("shop.public.products.get.channel", `/products/${encodePath(slug)}`),
174
174
  media: (slug) => request("shop.public.products.media.channel", `/products/${encodePath(slug)}/media`),
175
175
  },
176
+ cart: {
177
+ get: (cartToken) => request("channel.cart.get", appendQuery("/cart", { cart_token: required(cartToken, "cartToken") })),
178
+ addItem: (input, mutation) => request("channel.cart.items.add", "/cart/items", {
179
+ method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
180
+ }),
181
+ updateItem: (itemId, input, mutation) => request("channel.cart.items.update", `/cart/items/${encodePath(itemId)}`, {
182
+ method: "PATCH", headers: mutationHeaders(mutation), body: JSON.stringify(input),
183
+ }),
184
+ removeItem: (itemId, cartToken, mutation) => request("channel.cart.items.remove", appendQuery(`/cart/items/${encodePath(itemId)}`, {
185
+ cart_token: required(cartToken, "cartToken"),
186
+ }), {
187
+ method: "DELETE", headers: mutationHeaders(mutation),
188
+ }),
189
+ clear: (cartToken, mutation) => request("channel.cart.clear", appendQuery("/cart", { cart_token: required(cartToken, "cartToken") }), {
190
+ method: "DELETE", headers: mutationHeaders(mutation),
191
+ }),
192
+ merge: (input, mutation) => request("channel.cart.merge", "/cart/merge", {
193
+ method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
194
+ }),
195
+ },
196
+ checkout: {
197
+ options: (cartToken) => request("channel.checkout.options", appendQuery("/checkout/options", {
198
+ cart_token: required(cartToken, "cartToken"),
199
+ })),
200
+ status: (params = {}) => request("channel.checkout.status", appendQuery("/checkout/status", {
201
+ cart_token: params.cartToken,
202
+ checkout_session_id: params.checkoutSessionId,
203
+ })),
204
+ setCustomer: (input, mutation) => request("channel.checkout.customer", "/checkout/customer", {
205
+ method: "PUT", headers: mutationHeaders(mutation), body: JSON.stringify(input),
206
+ }),
207
+ setAddresses: (input, mutation) => request("channel.checkout.addresses", "/checkout/addresses", {
208
+ method: "PUT", headers: mutationHeaders(mutation), body: JSON.stringify(input),
209
+ }),
210
+ setFulfillment: (input, mutation) => request("channel.checkout.fulfillment", "/checkout/fulfillment", {
211
+ method: "PUT", headers: mutationHeaders(mutation), body: JSON.stringify(input),
212
+ }),
213
+ pay: (input, mutation) => request("channel.checkout.pay", "/checkout/pay", {
214
+ method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
215
+ }),
216
+ },
176
217
  reviews: {
177
218
  list: (params = {}) => request("reviews.public.list.channel", appendQuery("/reviews", params)),
178
219
  summary: () => request("reviews.public.summary.channel", "/reviews/summary"),
package/dist/next.d.ts CHANGED
@@ -37,6 +37,22 @@ export declare function createNextChannelClient(options: CreateNextChannelClient
37
37
  }>;
38
38
  readonly media: (slug: string) => Promise<import("./types.js").ListResponse<import("./types.js").ProductAsset>>;
39
39
  };
40
+ readonly cart: {
41
+ readonly get: (cartToken: string) => Promise<import("./types.js").CartResponse>;
42
+ readonly addItem: (input: import("./types.js").AddCartItemInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
43
+ readonly updateItem: (itemId: string, input: import("./types.js").UpdateCartItemInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
44
+ readonly removeItem: (itemId: string, cartToken: string, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
45
+ readonly clear: (cartToken: string, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
46
+ readonly merge: (input: import("./types.js").MergeCartInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
47
+ };
48
+ readonly checkout: {
49
+ readonly options: (cartToken: string) => Promise<import("./types.js").CheckoutOptions>;
50
+ readonly status: (params?: import("./index.js").ChannelCheckoutStatusParams) => Promise<import("./types.js").CheckoutStatusResponse>;
51
+ readonly setCustomer: (input: import("./types.js").CheckoutCustomerInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
52
+ readonly setAddresses: (input: import("./types.js").CheckoutAddressesInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
53
+ readonly setFulfillment: (input: import("./types.js").CheckoutFulfillmentInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CartResponse>;
54
+ readonly pay: (input: import("./types.js").CheckoutPayInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<import("./types.js").CheckoutPayResponse>;
55
+ };
40
56
  readonly reviews: {
41
57
  readonly list: (params?: import("./index.js").ChannelListParams) => Promise<import("./types.js").ListResponse<import("./types.js").Review>>;
42
58
  readonly summary: () => Promise<import("./types.js").ReviewSummaryResponse>;
package/dist/types.d.ts CHANGED
@@ -267,12 +267,138 @@ export interface CustomerResponse {
267
267
  }
268
268
  export interface Order {
269
269
  id: string;
270
+ workspace_id?: string;
270
271
  order_number: string;
272
+ cart_token?: string;
273
+ channel_id?: string;
271
274
  status: string;
272
275
  payment_status: string;
273
276
  currency: string;
277
+ source?: string;
278
+ customer_email?: string;
279
+ customer_name?: string;
280
+ subtotal_cents?: number;
281
+ shipping_amount_cents?: number;
282
+ tax_amount_cents?: number;
274
283
  total_cents: number;
284
+ items?: OrderItem[];
285
+ version?: number;
275
286
  created_at: string;
287
+ updated_at?: string;
288
+ [key: string]: unknown;
289
+ }
290
+ export interface OrderItem {
291
+ id: string;
292
+ order_id: string;
293
+ product_id?: string;
294
+ variant_id?: string;
295
+ product_slug?: string;
296
+ variant_title?: string;
297
+ thumbnail_url?: string;
298
+ title: string;
299
+ quantity: number;
300
+ unit_price_cents: number;
301
+ line_total_cents: number;
302
+ [key: string]: unknown;
303
+ }
304
+ export interface CartResponse {
305
+ order: Order;
306
+ }
307
+ export interface AddCartItemInput {
308
+ cart_token?: string;
309
+ currency?: string;
310
+ product_id: string;
311
+ variant_id?: string;
312
+ quantity: number;
313
+ }
314
+ export interface UpdateCartItemInput {
315
+ cart_token: string;
316
+ quantity: number;
317
+ }
318
+ export interface MergeCartInput {
319
+ source_cart_token: string;
320
+ target_cart_token: string;
321
+ currency?: string;
322
+ }
323
+ export interface CheckoutCustomerInput {
324
+ cart_token: string;
325
+ email: string;
326
+ name: string;
327
+ }
328
+ export interface CheckoutAddress {
329
+ name?: string;
330
+ phone?: string;
331
+ line1: string;
332
+ line2?: string;
333
+ city: string;
334
+ region?: string;
335
+ postal_code?: string;
336
+ country_code: string;
337
+ }
338
+ export interface CheckoutAddressesInput {
339
+ cart_token: string;
340
+ shipping: CheckoutAddress;
341
+ billing?: CheckoutAddress;
342
+ }
343
+ export interface CheckoutFulfillmentInput {
344
+ cart_token: string;
345
+ method: "shipping" | "pickup";
346
+ shipping_method_id?: string;
347
+ }
348
+ export interface CheckoutPayInput {
349
+ cart_token: string;
350
+ return_url?: string;
351
+ }
352
+ export interface PaymentMethodOption {
353
+ provider: string;
354
+ name: string;
355
+ type: string;
356
+ is_available: boolean;
357
+ [key: string]: unknown;
358
+ }
359
+ export interface PaymentReadiness {
360
+ ready: boolean;
361
+ mode: string;
362
+ reasons?: string[];
363
+ providers_available?: string[];
364
+ connect_required?: boolean;
365
+ connect_configured?: boolean;
366
+ }
367
+ export interface ShippingMethodOption {
368
+ id: string;
369
+ name?: string;
370
+ code?: string;
371
+ amount_cents?: number;
372
+ [key: string]: unknown;
373
+ }
374
+ export interface CheckoutOptions {
375
+ checkout_variant: string;
376
+ order: Order;
377
+ shipping_methods?: ShippingMethodOption[];
378
+ payment_methods?: PaymentMethodOption[];
379
+ payment_ready?: boolean;
380
+ payment_readiness?: PaymentReadiness;
381
+ [key: string]: unknown;
382
+ }
383
+ export type CheckoutStatus = "finalizing" | "completed" | "failed" | "not_found";
384
+ export interface CheckoutStatusResponse {
385
+ status: CheckoutStatus;
386
+ order_status?: string;
387
+ payment_status?: string;
388
+ payment_reference?: string;
389
+ updated_at?: string;
390
+ reasons?: string[];
391
+ [key: string]: unknown;
392
+ }
393
+ export interface CheckoutPayResponse {
394
+ order: Order;
395
+ session?: Record<string, unknown>;
396
+ checkout_variant?: string;
397
+ payment?: Record<string, unknown>;
398
+ status?: string;
399
+ provider_ref?: string;
400
+ checkout_session_id?: string;
401
+ redirect_url?: string;
276
402
  [key: string]: unknown;
277
403
  }
278
404
  export interface OrderSummary {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c1m-public/channel-client",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Typed server-side client for the MML headless Channel API",