@c1m-public/channel-client 0.10.0 → 0.11.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 +5 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,13 +17,17 @@ Channel credentials resolve the tenant and scope at the API door (plus the
|
|
|
17
17
|
workspace for workspace-scoped channels), so site URLs never carry those
|
|
18
18
|
identifiers.
|
|
19
19
|
|
|
20
|
+
Managed C1M sites need one deployment secret: `C1M_CHANNEL_TOKEN`. The client
|
|
21
|
+
uses `https://api.saasdash.app` by default. Pass `baseUrl` directly only for
|
|
22
|
+
local development or private C1M infrastructure; it is not part of the normal
|
|
23
|
+
deployment contract.
|
|
24
|
+
|
|
20
25
|
### Next.js
|
|
21
26
|
|
|
22
27
|
```ts
|
|
23
28
|
import { createNextChannelClient } from "@c1m-public/channel-client/next";
|
|
24
29
|
|
|
25
30
|
const channel = createNextChannelClient({
|
|
26
|
-
baseUrl: process.env.C1M_API_URL!,
|
|
27
31
|
token: process.env.C1M_CHANNEL_TOKEN!,
|
|
28
32
|
cache: { revalidate: 60 },
|
|
29
33
|
});
|
|
@@ -49,7 +53,6 @@ const checkout = await channel.checkout.pay(
|
|
|
49
53
|
import { createChannelClient } from "@c1m-public/channel-client";
|
|
50
54
|
|
|
51
55
|
const channel = createChannelClient({
|
|
52
|
-
baseUrl: process.env.C1M_API_URL!,
|
|
53
56
|
token: process.env.C1M_CHANNEL_TOKEN!,
|
|
54
57
|
});
|
|
55
58
|
|
|
@@ -122,7 +125,6 @@ other runtimes must enforce their own server-module boundary.
|
|
|
122
125
|
|
|
123
126
|
```ts
|
|
124
127
|
const channel = createChannelClient({
|
|
125
|
-
baseUrl: process.env.C1M_API_URL!,
|
|
126
128
|
token: process.env.C1M_CHANNEL_TOKEN!,
|
|
127
129
|
observe(event) {
|
|
128
130
|
console.info("c1m.channel", event);
|
|
@@ -191,7 +193,6 @@ price and a stale one at checkout.
|
|
|
191
193
|
```ts
|
|
192
194
|
// A client whose reads are filed under the catalog tag the webhook route busts.
|
|
193
195
|
const catalog = createNextChannelClient({
|
|
194
|
-
baseUrl: process.env.C1M_API_URL!,
|
|
195
196
|
token: process.env.C1M_CHANNEL_TOKEN!,
|
|
196
197
|
cache: { revalidate: 3600, tags: [CHANNEL_CATALOG_CACHE_TAG] },
|
|
197
198
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export * from "./webhooks.js";
|
|
2
2
|
export type * from "./types.js";
|
|
3
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
|
+
export declare const DEFAULT_CHANNEL_API_URL = "https://api.saasdash.app";
|
|
4
5
|
export interface ChannelRetryPolicy {
|
|
5
6
|
attempts?: number;
|
|
6
7
|
maxDelayMs?: number;
|
|
7
8
|
}
|
|
8
9
|
export interface CreateChannelClientOptions {
|
|
9
|
-
|
|
10
|
+
/** Override only for local development or private C1M infrastructure. */
|
|
11
|
+
baseUrl?: string;
|
|
10
12
|
token: string;
|
|
11
13
|
fetch?: typeof globalThis.fetch;
|
|
12
14
|
timeoutMs?: number;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./webhooks.js";
|
|
2
2
|
const CHANNEL_TOKEN_PREFIX = "sk_chan_";
|
|
3
|
+
export const DEFAULT_CHANNEL_API_URL = "https://api.saasdash.app";
|
|
3
4
|
const RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);
|
|
4
5
|
export class ChannelAPIError extends Error {
|
|
5
6
|
status;
|
|
@@ -70,7 +71,9 @@ function isFormDataBody(body) {
|
|
|
70
71
|
return typeof FormData !== "undefined" && body instanceof FormData;
|
|
71
72
|
}
|
|
72
73
|
export function createChannelClient(options) {
|
|
73
|
-
const baseUrl =
|
|
74
|
+
const baseUrl = (options.baseUrl === undefined
|
|
75
|
+
? DEFAULT_CHANNEL_API_URL
|
|
76
|
+
: required(options.baseUrl, "baseUrl")).replace(/\/+$/, "");
|
|
74
77
|
const token = required(options.token, "token");
|
|
75
78
|
if (!token.startsWith(CHANNEL_TOKEN_PREFIX))
|
|
76
79
|
throw new Error("token must start with sk_chan_");
|