@c1m-public/channel-client 0.9.0 → 0.10.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
@@ -13,8 +13,9 @@ transport core.
13
13
  - `@c1m-public/channel-client/webhooks` — framework-neutral webhook events and
14
14
  signature verification.
15
15
 
16
- Channel credentials resolve the tenant and workspace at the API door, so site
17
- URLs never carry either identifier.
16
+ Channel credentials resolve the tenant and scope at the API door (plus the
17
+ workspace for workspace-scoped channels), so site URLs never carry those
18
+ identifiers.
18
19
 
19
20
  ### Next.js
20
21
 
@@ -54,6 +55,11 @@ const channel = createChannelClient({
54
55
 
55
56
  const category = await channel.categories.products("electric-cars");
56
57
 
58
+ // A dash-scoped token exposes the dash's own public site data through the
59
+ // same transport. Workspace-only calls return 404 for this token by design.
60
+ const dash = await channel.dash.init();
61
+ const directory = await channel.dash.directory.list({ region: "london" });
62
+
57
63
  // Customer credentials are request-scoped and never stored on the shared
58
64
  // channel client. Every account read is forced to no-store.
59
65
  const account = channel.withCustomer(customerAccessToken);
@@ -61,6 +67,36 @@ const addresses = await account.addresses.list();
61
67
  const subscriptions = await account.subscriptions.list({ status: "active" });
62
68
  ```
63
69
 
70
+ ### Headless customer OTP
71
+
72
+ Customer OTP is available through the same end-user auth handler used by the
73
+ first-party workspace application. The channel token identifies the app and
74
+ workspace; the returned customer session must remain request-scoped.
75
+
76
+ ```ts
77
+ import { isChannelAPIError } from "@c1m-public/channel-client";
78
+
79
+ await channel.auth.sendCode("customer@example.com");
80
+
81
+ try {
82
+ const session = await channel.auth.verifyCode({
83
+ email: "customer@example.com",
84
+ code: submittedCode,
85
+ });
86
+ // Store tokens in secure, HTTP-only host cookies owned by your application.
87
+ } catch (error) {
88
+ if (isChannelAPIError(error)) {
89
+ // invalid_code (401), too_many_attempts (429), account_disabled (403)
90
+ // are stable recovery states. Unknown failures include requestId for support.
91
+ console.error("customer sign-in failed", error.code, error.requestId);
92
+ }
93
+ }
94
+ ```
95
+
96
+ Do not call Channel API auth directly from a browser: doing so would expose the
97
+ channel credential. Use a server action or route handler and return only safe
98
+ error code, status, and request reference to the UI.
99
+
64
100
  The package must only be imported from server modules. Never expose the token in
65
101
  `NEXT_PUBLIC_*`, Client Components, browser storage, HTML, source maps, logs, or
66
102
  asset requests. The `/next` entry point enforces Next's `server-only` boundary;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from "./webhooks.js";
2
2
  export type * from "./types.js";
3
- import type { CatalogBrand, CatalogCategory, CatalogCollection, CatalogProductsResponse, BlogPostResponse, DiningMenu, GivingEntry, GivingIntentListResponse, AddCartItemInput, CartResponse, CheckoutAddressesInput, CheckoutCustomerInput, CheckoutFulfillmentInput, CheckoutOptions, CheckoutPayInput, CheckoutPayResponse, CheckoutStatusResponse, ChannelPing, CustomerResponse, CustomerSession, CustomerSignupResponse, LeadResponse, LightInitResponse, ListResponse, Order, OrderSummary, MergeCartInput, SendCodeResponse, Product, ProductAsset, PrintIntakeInput, PrintJob, PrintOptionsSelection, PrintQuoteResponse, PrintSettingsResponse, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, MenuResponse, Review, ReviewSummaryResponse, SavedAddress, SavedAddressDefaultKind, SavedAddressInput, SavedAddressResponse, SavedAddressUpdateInput, SavedPaymentMethod, SiteDocument, StartGivingInput, StartGivingResponse, PaymentMethodConfirmInput, PaymentMethodMutationResponse, PaymentMethodSetupInput, PaymentMethodSetupResult, SubscriptionAgreementResponse, SubscriptionInvoiceListResponse, SubscriptionInvoiceResponse, SubscriptionListResponse, SubscriptionSourceResponse, ThemeResponse, UpdateCartItemInput } from "./types.js";
3
+ import type { CatalogBrand, CatalogCategory, CatalogCollection, CatalogProductsResponse, BlogPostResponse, DiningMenu, DashDirectoryEntry, DashDirectoryProfileResponse, DashDirectoryRegion, DashInitResponse, DashLead, DashPlansResponse, DashProfileResponse, GivingEntry, GivingIntentListResponse, AddCartItemInput, CartResponse, CheckoutAddressesInput, CheckoutCustomerInput, CheckoutFulfillmentInput, CheckoutOptions, CheckoutPayInput, CheckoutPayResponse, CheckoutStatusResponse, ChannelPing, CustomerResponse, CustomerSession, CustomerSignupResponse, LeadResponse, LightInitResponse, ListResponse, Order, OrderSummary, MergeCartInput, SendCodeResponse, Product, ProductAsset, PrintIntakeInput, PrintJob, PrintOptionsSelection, PrintQuoteResponse, PrintSettingsResponse, PublicPage, PublicPageSummary, PublicSubmitReviewInput, PublicWorkspaceInit, MenuResponse, Review, ReviewSummaryResponse, SavedAddress, SavedAddressDefaultKind, SavedAddressInput, SavedAddressResponse, SavedAddressUpdateInput, SavedPaymentMethod, SiteDocument, StartGivingInput, StartGivingResponse, PaymentMethodConfirmInput, PaymentMethodMutationResponse, PaymentMethodSetupInput, PaymentMethodSetupResult, SubscriptionAgreementResponse, SubscriptionInvoiceListResponse, SubscriptionInvoiceResponse, SubscriptionListResponse, SubscriptionSourceResponse, ThemeResponse, UpdateCartItemInput } from "./types.js";
4
4
  export interface ChannelRetryPolicy {
5
5
  attempts?: number;
6
6
  maxDelayMs?: number;
@@ -16,7 +16,7 @@ export interface CreateChannelClientOptions {
16
16
  signal?: AbortSignal;
17
17
  }
18
18
  export type ChannelRequestOutcome = "success" | "api_error" | "network_error" | "timeout" | "invalid_response" | "cancelled";
19
- 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.blog.list" | "channel.giving.entries.list" | "channel.giving.entries.get" | "channel.giving.start" | "channel.print.settings" | "channel.print.quote" | "channel.print.intake" | "dining.public.board_menu.channel" | "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.addresses.list" | "channel.account.addresses.create" | "channel.account.addresses.get" | "channel.account.addresses.update" | "channel.account.addresses.delete" | "channel.account.addresses.set_default" | "channel.account.giving.list" | "channel.account.orders.list" | "channel.account.orders.summary" | "channel.account.orders.get" | "channel.account.payment_methods.list" | "channel.account.payment_methods.setup" | "channel.account.payment_methods.confirm" | "channel.account.payment_methods.default" | "channel.account.payment_methods.delete" | "channel.account.subscriptions.list" | "channel.account.subscriptions.get" | "channel.account.subscriptions.source" | "channel.account.subscriptions.cancel" | "channel.account.subscriptions.pause" | "channel.account.subscriptions.resume" | "channel.account.subscriptions.invoices.list" | "channel.account.subscriptions.invoices.get" | "channel.account.subscriptions.invoices.pay_now" | "channel.catalog.brands.list" | "channel.catalog.categories.list" | "channel.catalog.categories.products" | "channel.catalog.collections.list" | "channel.catalog.collections.products" | "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.set" | "channel.checkout.addresses.set" | "channel.checkout.fulfillment.set" | "channel.checkout.pay" | "growth.public_workspace.leads.capture.channel";
19
+ 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.blog.list" | "channel.giving.entries.list" | "channel.giving.entries.get" | "channel.giving.start" | "channel.print.settings" | "channel.print.quote" | "channel.print.intake" | "dining.public.board_menu.channel" | "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.addresses.list" | "channel.account.addresses.create" | "channel.account.addresses.get" | "channel.account.addresses.update" | "channel.account.addresses.delete" | "channel.account.addresses.set_default" | "channel.account.giving.list" | "channel.account.orders.list" | "channel.account.orders.summary" | "channel.account.orders.get" | "channel.account.payment_methods.list" | "channel.account.payment_methods.setup" | "channel.account.payment_methods.confirm" | "channel.account.payment_methods.default" | "channel.account.payment_methods.delete" | "channel.account.subscriptions.list" | "channel.account.subscriptions.get" | "channel.account.subscriptions.source" | "channel.account.subscriptions.cancel" | "channel.account.subscriptions.pause" | "channel.account.subscriptions.resume" | "channel.account.subscriptions.invoices.list" | "channel.account.subscriptions.invoices.get" | "channel.account.subscriptions.invoices.pay_now" | "channel.catalog.brands.list" | "channel.catalog.categories.list" | "channel.catalog.categories.products" | "channel.catalog.collections.list" | "channel.catalog.collections.products" | "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.set" | "channel.checkout.addresses.set" | "channel.checkout.fulfillment.set" | "channel.checkout.pay" | "channel.dash.profile" | "channel.dash.init" | "channel.dash.plans" | "channel.dash.directory.regions" | "channel.dash.directory.browse" | "channel.dash.directory.get" | "channel.dash.leads.capture" | "growth.public_workspace.leads.capture.channel";
20
20
  export interface ChannelRequestObservation {
21
21
  operation: ChannelOperation;
22
22
  method: string;
@@ -53,6 +53,10 @@ export interface ChannelLeadInput {
53
53
  source?: string;
54
54
  meta?: Record<string, unknown>;
55
55
  }
56
+ export interface DashDirectoryListParams extends ChannelListParams {
57
+ category?: string;
58
+ region?: string;
59
+ }
56
60
  export interface ChannelMutationOptions {
57
61
  idempotencyKey?: string;
58
62
  }
@@ -83,11 +87,27 @@ export declare function createChannelClient(options: CreateChannelClientOptions)
83
87
  *
84
88
  * The cheapest call on the door — it does no database work server-side. Use
85
89
  * it as a deployment health check: a 200 means C1M_CHANNEL_TOKEN is right and
86
- * aimed at the workspace you expect. A ChannelAPIError with status 401 means
90
+ * aimed at the scope you expect. A ChannelAPIError with status 401 means
87
91
  * the token is bad, revoked, or the channel is disabled (the door will not
88
92
  * say which). A 503 means C1M is unavailable — NOT that your token is wrong.
89
93
  */
90
94
  readonly ping: () => Promise<ChannelPing>;
95
+ /** Tenant-level data exposed only to a dash-scoped channel token. */
96
+ readonly dash: {
97
+ readonly profile: () => Promise<DashProfileResponse>;
98
+ readonly init: () => Promise<DashInitResponse>;
99
+ readonly plans: () => Promise<DashPlansResponse>;
100
+ readonly directory: {
101
+ readonly regions: () => Promise<ListResponse<DashDirectoryRegion>>;
102
+ readonly list: (params?: DashDirectoryListParams) => Promise<ListResponse<DashDirectoryEntry>>;
103
+ readonly get: (idOrSlug: string) => Promise<DashDirectoryProfileResponse>;
104
+ };
105
+ readonly leads: {
106
+ readonly create: (input: ChannelLeadInput, mutation?: ChannelMutationOptions) => Promise<{
107
+ lead: DashLead;
108
+ }>;
109
+ };
110
+ };
91
111
  readonly assetUrl: (pathOrUrl: string) => string;
92
112
  readonly site: {
93
113
  readonly resolve: (params?: ChannelSiteResolveParams) => Promise<SiteDocument>;
package/dist/index.js CHANGED
@@ -188,11 +188,27 @@ export function createChannelClient(options) {
188
188
  *
189
189
  * The cheapest call on the door — it does no database work server-side. Use
190
190
  * it as a deployment health check: a 200 means C1M_CHANNEL_TOKEN is right and
191
- * aimed at the workspace you expect. A ChannelAPIError with status 401 means
191
+ * aimed at the scope you expect. A ChannelAPIError with status 401 means
192
192
  * the token is bad, revoked, or the channel is disabled (the door will not
193
193
  * say which). A 503 means C1M is unavailable — NOT that your token is wrong.
194
194
  */
195
195
  ping: () => request("channel.ping", "/ping"),
196
+ /** Tenant-level data exposed only to a dash-scoped channel token. */
197
+ dash: {
198
+ profile: () => request("channel.dash.profile", "/dash/profile"),
199
+ init: () => request("channel.dash.init", "/dash/init"),
200
+ plans: () => request("channel.dash.plans", "/dash/plans"),
201
+ directory: {
202
+ regions: () => request("channel.dash.directory.regions", "/dash/directory/regions"),
203
+ list: (params = {}) => request("channel.dash.directory.browse", appendQuery("/dash/directory", params)),
204
+ get: (idOrSlug) => request("channel.dash.directory.get", `/dash/directory/${encodePath(idOrSlug)}`),
205
+ },
206
+ leads: {
207
+ create: (input, mutation) => request("channel.dash.leads.capture", "/dash/leads", {
208
+ method: "POST", headers: mutationHeaders(mutation), body: JSON.stringify(input),
209
+ }),
210
+ },
211
+ },
196
212
  assetUrl: (pathOrUrl) => new URL(required(pathOrUrl, "asset URL"), `${baseUrl}/`).toString(),
197
213
  site: {
198
214
  resolve: (params = {}) => request("channel.site.resolve", appendQuery("/site/resolve", params)),
package/dist/next.d.ts CHANGED
@@ -16,6 +16,21 @@ export interface CreateNextChannelClientOptions extends Omit<CreateChannelClient
16
16
  */
17
17
  export declare function createNextChannelClient(options: CreateNextChannelClientOptions): {
18
18
  readonly ping: () => Promise<import("./types.js").ChannelPing>;
19
+ readonly dash: {
20
+ readonly profile: () => Promise<import("./types.js").DashProfileResponse>;
21
+ readonly init: () => Promise<import("./types.js").DashInitResponse>;
22
+ readonly plans: () => Promise<import("./types.js").DashPlansResponse>;
23
+ readonly directory: {
24
+ readonly regions: () => Promise<import("./types.js").ListResponse<import("./types.js").DashDirectoryRegion>>;
25
+ readonly list: (params?: import("./index.js").DashDirectoryListParams) => Promise<import("./types.js").ListResponse<import("./types.js").DashDirectoryEntry>>;
26
+ readonly get: (idOrSlug: string) => Promise<import("./types.js").DashDirectoryProfileResponse>;
27
+ };
28
+ readonly leads: {
29
+ readonly create: (input: import("./index.js").ChannelLeadInput, mutation?: import("./index.js").ChannelMutationOptions) => Promise<{
30
+ lead: import("./types.js").DashLead;
31
+ }>;
32
+ };
33
+ };
19
34
  readonly assetUrl: (pathOrUrl: string) => string;
20
35
  readonly site: {
21
36
  readonly resolve: (params?: import("./index.js").ChannelSiteResolveParams) => Promise<import("./types.js").SiteDocument>;
package/dist/types.d.ts CHANGED
@@ -40,6 +40,139 @@ export interface LightInitResponse {
40
40
  enabled_features: string[];
41
41
  etag?: string;
42
42
  }
43
+ export interface DashTenantInfo {
44
+ id: string;
45
+ display_name: string;
46
+ managed_domain?: string;
47
+ status: string;
48
+ }
49
+ export interface DashPublicProfileInfo {
50
+ discoverable: boolean;
51
+ category?: string;
52
+ headline?: string;
53
+ short_description?: string;
54
+ about?: string;
55
+ logo_url?: string;
56
+ header_media_url?: string;
57
+ pricing_summary?: string;
58
+ }
59
+ export interface DashInitResponse {
60
+ tenant: DashTenantInfo;
61
+ public_profile: DashPublicProfileInfo;
62
+ }
63
+ export interface DashPublicPage {
64
+ profile: DashPublicProfileInfo & {
65
+ tenant_id: string;
66
+ status: string;
67
+ display_name?: string;
68
+ is_private: boolean;
69
+ allow_free_memberships: boolean;
70
+ primary_color?: string;
71
+ logo_square_url?: string;
72
+ favicon_url?: string;
73
+ cover_url?: string;
74
+ gallery_items?: Array<{
75
+ url: string;
76
+ kind: string;
77
+ alt_text?: string;
78
+ caption?: string;
79
+ }>;
80
+ [key: string]: unknown;
81
+ };
82
+ owner_name?: string;
83
+ user_count: number;
84
+ workspace_counts: Record<string, number>;
85
+ media: Array<{
86
+ kind: string;
87
+ url: string;
88
+ alt_text?: string;
89
+ caption?: string;
90
+ }>;
91
+ }
92
+ export interface DashProfileResponse {
93
+ page: DashPublicPage;
94
+ }
95
+ export interface DashPlanPricing {
96
+ currency: string;
97
+ currency_symbol?: string;
98
+ monthly_price: number;
99
+ yearly_price: number;
100
+ }
101
+ export interface DashPlan {
102
+ id: string;
103
+ name: string;
104
+ description: string;
105
+ level: number;
106
+ is_public: boolean;
107
+ is_free: boolean;
108
+ trial_days?: number;
109
+ highlights: string[];
110
+ limits: Record<string, number>;
111
+ pricing: Record<string, DashPlanPricing>;
112
+ }
113
+ export interface DashPlanRegion {
114
+ code: string;
115
+ name: string;
116
+ currency: string;
117
+ locale: string;
118
+ timezone: string;
119
+ market_code?: string;
120
+ }
121
+ export interface DashPlansResponse {
122
+ plans: DashPlan[];
123
+ regions: DashPlanRegion[];
124
+ default_region: string;
125
+ }
126
+ export interface DashDirectoryRegion {
127
+ code: string;
128
+ label: string;
129
+ country_code?: string;
130
+ sort_order: number;
131
+ count: number;
132
+ }
133
+ export interface DashDirectoryEntry {
134
+ workspace_id: string;
135
+ slug: string;
136
+ name: string;
137
+ tagline?: string;
138
+ category?: string;
139
+ logo_url?: string;
140
+ logo_square_url?: string;
141
+ primary_color?: string;
142
+ review_count: number;
143
+ average_rating: number;
144
+ verified: boolean;
145
+ service_tags: unknown;
146
+ major_region_code?: string;
147
+ major_region_label?: string;
148
+ upcoming_events?: unknown[];
149
+ }
150
+ export interface DashDirectoryProfile extends DashDirectoryEntry {
151
+ display_name?: string;
152
+ description?: string;
153
+ logo_light_url?: string;
154
+ logo_dark_url?: string;
155
+ verified_at?: string;
156
+ created_at: string;
157
+ }
158
+ export interface DashDirectoryProfileResponse {
159
+ profile: DashDirectoryProfile;
160
+ }
161
+ export interface DashLead {
162
+ id: string;
163
+ owner_scope?: string;
164
+ owner_id?: string;
165
+ name?: string;
166
+ email?: string;
167
+ phone?: string;
168
+ message?: string;
169
+ source: string;
170
+ channel_id?: string;
171
+ status: string;
172
+ meta?: Record<string, unknown>;
173
+ created_at: string;
174
+ updated_at: string;
175
+ }
43
176
  export interface PublicPageSummary {
44
177
  id: string;
45
178
  saas_app: string;
@@ -937,5 +1070,6 @@ export interface ChannelPing {
937
1070
  channel_id: string;
938
1071
  workspace_id: string;
939
1072
  saas_app: string;
1073
+ scope: "workspace" | "dash";
940
1074
  api_version: string;
941
1075
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c1m-public/channel-client",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Typed server-side client for the MML headless Channel API",