@cosmoops/connect-sdk 0.41.0 → 0.42.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/CHANGELOG.md +75 -0
- package/dist/cjs/client/components/access-gate.js +18 -40
- package/dist/cjs/client/components/apps-grid.js +11 -3
- package/dist/cjs/client/components/ask-ai-errors.js +109 -0
- package/dist/cjs/client/components/ask-ai-turns.js +12 -0
- package/dist/cjs/client/components/ask-ai.js +75 -8
- package/dist/cjs/client/components/plans.js +8 -2
- package/dist/cjs/client/components/readiness.js +2 -1
- package/dist/cjs/client/components/subscription.js +4 -4
- package/dist/cjs/client/components/user-menu.js +16 -11
- package/dist/cjs/client/handoff.js +78 -0
- package/dist/cjs/client/index.js +9 -6
- package/dist/cjs/client/provider.js +75 -4
- package/dist/cjs/client/use-checkout.js +23 -16
- package/dist/cjs/server/client.js +5 -1
- package/dist/cjs/server/handler.js +4 -1
- package/dist/cjs/server/resources/identity.js +12 -0
- package/dist/cjs/server/resources/whatsapp.js +58 -0
- package/dist/esm/client/components/access-gate.js +18 -40
- package/dist/esm/client/components/apps-grid.js +11 -3
- package/dist/esm/client/components/ask-ai-errors.js +102 -0
- package/dist/esm/client/components/ask-ai-turns.js +12 -0
- package/dist/esm/client/components/ask-ai.js +76 -9
- package/dist/esm/client/components/plans.js +8 -2
- package/dist/esm/client/components/readiness.js +2 -1
- package/dist/esm/client/components/subscription.js +4 -4
- package/dist/esm/client/components/user-menu.js +16 -11
- package/dist/esm/client/handoff.js +72 -0
- package/dist/esm/client/index.js +4 -3
- package/dist/esm/client/provider.js +75 -4
- package/dist/esm/client/use-checkout.js +23 -16
- package/dist/esm/server/client.js +5 -1
- package/dist/esm/server/handler.js +4 -1
- package/dist/esm/server/resources/identity.js +12 -0
- package/dist/esm/server/resources/whatsapp.js +54 -0
- package/dist/types/client/components/ask-ai-errors.d.ts +41 -0
- package/dist/types/client/components/ask-ai-turns.d.ts +5 -0
- package/dist/types/client/handoff.d.ts +62 -0
- package/dist/types/client/index.d.ts +3 -1
- package/dist/types/client/provider.d.ts +72 -5
- package/dist/types/client/use-checkout.d.ts +4 -1
- package/dist/types/server/client.d.ts +4 -1
- package/dist/types/server/resources/identity.d.ts +10 -0
- package/dist/types/server/resources/whatsapp.d.ts +44 -0
- package/dist/types/types.d.ts +42 -0
- package/package.json +1 -1
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
* change lands identically in all of them.
|
|
12
12
|
*/
|
|
13
13
|
export { ConnectProvider, useConnect, useConnectOptional, useConnectUser, useConnectWorkspaceType, useConnectAudience, useConnectPlatformAccess, useConnectEntitlements, useConnectPlans, useConnectApps, useConnectCompanyProfile, useConnectAddonUsage, useConnectSessions, useConnectIntegrations, useConnectResource, CONNECT_APP_URL, } from "./provider.js";
|
|
14
|
-
export type { ConnectProviderProps, ConnectContextValue, ConnectSession, ConnectOneTapHint, ConnectOneTapFailure, UseConnectResourceOptions, } from "./provider.js";
|
|
14
|
+
export type { ConnectProviderProps, ConnectContextValue, ConnectSession, ConnectOneTapHint, ConnectOneTapFailure, UseConnectResourceOptions, OpenConnectOptions, } from "./provider.js";
|
|
15
|
+
export type { ConnectHandoffMode, ConnectHandoffResult } from "./handoff.js";
|
|
16
|
+
export { CONNECT_HANDOFF_MESSAGE_TYPE, CONNECT_HANDOFF_RESULT_PARAM } from "./handoff.js";
|
|
15
17
|
export { blockingBlockers, normalizePlanFeatures } from "../helpers.js";
|
|
16
18
|
export type { WirePlanFeature } from "../helpers.js";
|
|
17
19
|
export { ConnectError, isConnectError } from "../errors.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import { type ConnectHandoffMode, type ConnectHandoffResult } from "./handoff.js";
|
|
2
3
|
import type { AddonUsageResponse, CompanyProfileResponse, ConnectUser, IntegrationsListResponse, WorkspaceApp, UserWorkspace, ConnectWorkspaceMember, PlansResponse, ReadinessResponse, SessionsListResponse, SessionSubscription, SessionAudience, SubscriptionResponse, WorkspaceType } from "../types.js";
|
|
3
4
|
export declare const CONNECT_APP_URL = "https://connect.cosmoops.com";
|
|
4
5
|
export interface ConnectSession {
|
|
@@ -32,6 +33,13 @@ export interface ConnectSession {
|
|
|
32
33
|
hintUrl: string;
|
|
33
34
|
authorizeUrl: string;
|
|
34
35
|
} | null;
|
|
36
|
+
/**
|
|
37
|
+
* This application's public `client_id`, from the bridge - so `openConnect`
|
|
38
|
+
* can name the application on a hand-off without `clientId` being passed to
|
|
39
|
+
* `<ConnectProvider>` as well. Optional because an older bridge will not
|
|
40
|
+
* send it; the provider's own `clientId` prop wins when both exist.
|
|
41
|
+
*/
|
|
42
|
+
clientId?: string | null;
|
|
35
43
|
}
|
|
36
44
|
/**
|
|
37
45
|
* What Connect says about the visitor, before anything has been signed.
|
|
@@ -68,14 +76,39 @@ export interface ConnectOneTapHint {
|
|
|
68
76
|
export type ConnectOneTapFailure = "unavailable" | "login_required" | "consent_required" | "interaction_required" | "rate_limited" | "failed";
|
|
69
77
|
export interface ConnectContextValue {
|
|
70
78
|
/**
|
|
71
|
-
* Public OAuth client id
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
79
|
+
* Public OAuth client id - the `clientId` passed to `<ConnectProvider>`,
|
|
80
|
+
* else the one your bridge reports on `/session`, else an empty string
|
|
81
|
+
* (an older bridge, before the session read settles). Safe in a browser
|
|
82
|
+
* regardless: it only ever goes into Connect URLs. Most integrations never
|
|
83
|
+
* read this - it exists for the explicit-`redirectUri` flow and for
|
|
84
|
+
* `connectPortalUrl`'s way back.
|
|
75
85
|
*/
|
|
76
86
|
clientId: string;
|
|
77
87
|
/** Connect's own origin, for deep links out to Profile, Billing and the catalog. */
|
|
78
88
|
appUrl: string;
|
|
89
|
+
/** How `openConnect` sends people to Connect - `ConnectProviderProps.handoff`, after defaulting. */
|
|
90
|
+
handoffMode: ConnectHandoffMode;
|
|
91
|
+
/**
|
|
92
|
+
* Sends the visitor to a Connect page for a task, and brings them back when
|
|
93
|
+
* it is done. **Call it from a press handler** - a popup opened after an
|
|
94
|
+
* `await` is what pop-up blockers exist to stop.
|
|
95
|
+
*
|
|
96
|
+
* `target` is a path (`"/billing"`) or an absolute Connect URL, such as a
|
|
97
|
+
* readiness blocker's `resolveUrl`. Anything on another origin throws.
|
|
98
|
+
*
|
|
99
|
+
* - `"popup"` mode opens Connect in a new tab (or a sized window, with
|
|
100
|
+
* `features`), which closes itself when the task is done and tells this
|
|
101
|
+
* page first - every Connect component on it then re-reads. Returns the
|
|
102
|
+
* window, for a caller that wants to watch it.
|
|
103
|
+
* - `"redirect"` mode, or a popup the browser blocked, navigates this tab
|
|
104
|
+
* to Connect, which navigates back with `?connect_result=`. Returns
|
|
105
|
+
* `null`; the page is going away.
|
|
106
|
+
*
|
|
107
|
+
* Either way the way back carries this page's URL and this application's
|
|
108
|
+
* `client_id`, and Connect only honours an origin registered for that
|
|
109
|
+
* client - register your app's origin among its redirect URIs.
|
|
110
|
+
*/
|
|
111
|
+
openConnect(target: string, options?: OpenConnectOptions): Window | null;
|
|
79
112
|
session: ConnectSession | null;
|
|
80
113
|
/** `true` until the first `/session` read settles. Render skeletons, not a Login button. */
|
|
81
114
|
isLoading: boolean;
|
|
@@ -178,6 +211,16 @@ export interface ConnectContextValue {
|
|
|
178
211
|
reason: ConnectOneTapFailure;
|
|
179
212
|
}>;
|
|
180
213
|
}
|
|
214
|
+
export interface OpenConnectOptions {
|
|
215
|
+
/**
|
|
216
|
+
* `window.open` features for a sized pop-up window instead of a tab -
|
|
217
|
+
* checkout uses `"popup,width=520,height=780"`. Must not include
|
|
218
|
+
* `noopener`: the window handle is how Connect reports back and closes.
|
|
219
|
+
*/
|
|
220
|
+
features?: string;
|
|
221
|
+
/** `window.open` target name. A second `openConnect` with the same name reuses that window. */
|
|
222
|
+
name?: string;
|
|
223
|
+
}
|
|
181
224
|
export interface ConnectProviderProps {
|
|
182
225
|
/**
|
|
183
226
|
* This application's public `client_id`, from its Connect client section in Connect.
|
|
@@ -241,6 +284,30 @@ export interface ConnectProviderProps {
|
|
|
241
284
|
* to your own `/signin`, which mints the `state` server-side.
|
|
242
285
|
*/
|
|
243
286
|
silentSignIn?: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* How every Connect button in this package - Billing, Profile, Manage,
|
|
289
|
+
* checkout, a readiness blocker's fix - takes the visitor to Connect.
|
|
290
|
+
*
|
|
291
|
+
* - `"popup"` (the default): Connect opens in a new tab and **closes itself**
|
|
292
|
+
* when the task is done, telling this page first, so the visitor is back
|
|
293
|
+
* where they were with everything repainted. A blocked popup falls back
|
|
294
|
+
* to `"redirect"` rather than leaving them with nothing.
|
|
295
|
+
* - `"redirect"`: this tab goes to Connect and comes back. Prefer it for an
|
|
296
|
+
* installed PWA or an app inside an iframe, where a second tab is a
|
|
297
|
+
* different window the visitor may never find.
|
|
298
|
+
*
|
|
299
|
+
* Both need this app's origin registered among the client's redirect URIs
|
|
300
|
+
* in Connect - an unregistered origin still reaches Connect, it just gets no
|
|
301
|
+
* way back.
|
|
302
|
+
*/
|
|
303
|
+
handoff?: ConnectHandoffMode;
|
|
304
|
+
/**
|
|
305
|
+
* Told how each trip to Connect ended - from the popup's message, or from
|
|
306
|
+
* `?connect_result=` on the way back from a redirect (which the provider
|
|
307
|
+
* then strips from the address bar). The provider already re-reads the
|
|
308
|
+
* session and every Connect resource; this is for your own state.
|
|
309
|
+
*/
|
|
310
|
+
onHandoffResult?: (result: ConnectHandoffResult) => void;
|
|
244
311
|
children: ReactNode;
|
|
245
312
|
}
|
|
246
313
|
/**
|
|
@@ -257,7 +324,7 @@ export interface ConnectProviderProps {
|
|
|
257
324
|
* </ConnectProvider>
|
|
258
325
|
* ```
|
|
259
326
|
*/
|
|
260
|
-
export declare function ConnectProvider({ clientId, basePath, redirectUri, appUrl, fetch: fetchImpl, silentSignIn, children, }: ConnectProviderProps): import("react").JSX.Element;
|
|
327
|
+
export declare function ConnectProvider({ clientId, basePath, redirectUri, appUrl, fetch: fetchImpl, silentSignIn, handoff, onHandoffResult, children, }: ConnectProviderProps): import("react").JSX.Element;
|
|
261
328
|
export declare function useConnect(): ConnectContextValue;
|
|
262
329
|
/**
|
|
263
330
|
* The context when there is one, `null` when there is not.
|
|
@@ -9,7 +9,10 @@ import type { ReadinessResponse, SubscriptionResponse } from "../types.js";
|
|
|
9
9
|
* closing is not one.
|
|
10
10
|
* - `abandoned` - the window closed (or the deadline passed) with the
|
|
11
11
|
* entitlement unchanged.
|
|
12
|
-
* - `blocked` -
|
|
12
|
+
* - `blocked` - **no longer produced.** A blocked window now falls back to a
|
|
13
|
+
* same-tab trip to Connect and back (see `openConnect`), which reaches the
|
|
14
|
+
* same place without asking the customer to click a fallback link. Kept in
|
|
15
|
+
* the union so code that handles it still compiles.
|
|
13
16
|
*/
|
|
14
17
|
export type ConnectCheckoutStatus = "idle" | "waiting" | "completed" | "abandoned" | "blocked";
|
|
15
18
|
export interface ConnectCheckoutState {
|
|
@@ -23,6 +23,7 @@ import { SessionsResource } from "./resources/sessions.js";
|
|
|
23
23
|
import { PlatformResource } from "./resources/platform.js";
|
|
24
24
|
import { VisitorResource } from "./resources/visitor.js";
|
|
25
25
|
import { PushResource } from "./resources/push.js";
|
|
26
|
+
import { WhatsAppResource } from "./resources/whatsapp.js";
|
|
26
27
|
export declare const DEFAULT_BASE_URL = "https://connect.cosmoops.com";
|
|
27
28
|
export interface ConnectClientOptions {
|
|
28
29
|
/**
|
|
@@ -124,6 +125,8 @@ export declare class ConnectClient {
|
|
|
124
125
|
* preferences; you supply a title, a body and a URL. See `PushResource`.
|
|
125
126
|
*/
|
|
126
127
|
readonly push: PushResource;
|
|
128
|
+
/** Your application's own approved WhatsApp templates, to a workspace's customers. */
|
|
129
|
+
readonly whatsapp: WhatsAppResource;
|
|
127
130
|
/**
|
|
128
131
|
* Relays one `/data/*` or `/kv/*` request verbatim - `createConnectHandler`'s
|
|
129
132
|
* store route and nothing else. See `storePassthrough`.
|
|
@@ -138,4 +141,4 @@ export declare class ConnectClient {
|
|
|
138
141
|
constructor(options: ConnectClientOptions);
|
|
139
142
|
}
|
|
140
143
|
/** Kept in step with `package.json` by `sdk.test.ts`. */
|
|
141
|
-
export declare const SDK_VERSION = "0.
|
|
144
|
+
export declare const SDK_VERSION = "0.42.0";
|
|
@@ -77,6 +77,16 @@ export declare class IdentityResource {
|
|
|
77
77
|
hintUrl: string;
|
|
78
78
|
authorizeUrl: string;
|
|
79
79
|
} | null;
|
|
80
|
+
/**
|
|
81
|
+
* This client's public `client_id`, or `null` when none is configured.
|
|
82
|
+
*
|
|
83
|
+
* The bridge hands it to the browser on `/session` so `openConnect` can name
|
|
84
|
+
* the application on every hand-off without the host passing `clientId` to
|
|
85
|
+
* `<ConnectProvider>` too - Connect only honours a `return_to` it can match
|
|
86
|
+
* against *a client's* registered redirect origins. Public by definition:
|
|
87
|
+
* it already rides on every authorize URL.
|
|
88
|
+
*/
|
|
89
|
+
publicClientId(): string | null;
|
|
80
90
|
/** Step 2 - trade the one-time `code` for a session. Server-side only. */
|
|
81
91
|
exchangeCode(input: ExchangeCodeInput): Promise<TokenResponse>;
|
|
82
92
|
/**
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type TransportOptions } from "../http.js";
|
|
2
|
+
import type { SendWhatsAppInput, SendWhatsAppResponse, WhatsAppTemplateState } from "../../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Your application's own WhatsApp templates, sent to a workspace's customers
|
|
5
|
+
* through Connect's WhatsApp sender - no WhatsApp Business account of your
|
|
6
|
+
* own.
|
|
7
|
+
*
|
|
8
|
+
* Templates are written and submitted to Meta in Console under your
|
|
9
|
+
* application; you name them here by slug and Connect resolves
|
|
10
|
+
* `app_<yourApplicationKey>_<slug>` from your key, so a key can never send
|
|
11
|
+
* another application's message or one of Connect's own. There is no free
|
|
12
|
+
* text: outside a customer's 24-hour window WhatsApp permits nothing else.
|
|
13
|
+
*
|
|
14
|
+
* Server-to-server only - there is no browser path, by design.
|
|
15
|
+
*/
|
|
16
|
+
export declare class WhatsAppResource {
|
|
17
|
+
private readonly transport;
|
|
18
|
+
constructor(transport: TransportOptions);
|
|
19
|
+
/**
|
|
20
|
+
* Send one template to one customer.
|
|
21
|
+
*
|
|
22
|
+
* Refusals arrive as a `ConnectError` whose `code` says what to tell the
|
|
23
|
+
* person who pressed Send - `template_not_approved`, `consent_required`,
|
|
24
|
+
* `opted_out`, `not_found`. None of them is a fault worth retrying.
|
|
25
|
+
*
|
|
26
|
+
* An `Idempotency-Key` is always sent, as on `otp.send`: a retried send
|
|
27
|
+
* without one is a second message on somebody's phone. Pass your own -
|
|
28
|
+
* derived from what is being sent, e.g. the quote number - to make a
|
|
29
|
+
* retry from a *later* request safe too.
|
|
30
|
+
*/
|
|
31
|
+
send(input: SendWhatsAppInput, options?: {
|
|
32
|
+
idempotencyKey?: string;
|
|
33
|
+
}): Promise<SendWhatsAppResponse>;
|
|
34
|
+
/**
|
|
35
|
+
* Whether a template would send right now, and the values it needs.
|
|
36
|
+
*
|
|
37
|
+
* Ask before offering WhatsApp on a screen: Meta's approval takes minutes
|
|
38
|
+
* to days, and an approved template can be paused later. A `ConnectError`
|
|
39
|
+
* with `status: 404` means your application has no such template.
|
|
40
|
+
*/
|
|
41
|
+
template(slug: string, options?: {
|
|
42
|
+
language?: string;
|
|
43
|
+
}): Promise<WhatsAppTemplateState>;
|
|
44
|
+
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -2982,6 +2982,48 @@ export interface ConversationsPage {
|
|
|
2982
2982
|
nextCursor: string | null;
|
|
2983
2983
|
hasMore: boolean;
|
|
2984
2984
|
}
|
|
2985
|
+
/**
|
|
2986
|
+
* One of your application's own Meta-approved templates, to one customer.
|
|
2987
|
+
*
|
|
2988
|
+
* Hand-written here like every wire type in this file - see `SendPushInput`.
|
|
2989
|
+
*/
|
|
2990
|
+
export interface SendWhatsAppInput {
|
|
2991
|
+
/** The subscribing workspace this is sent on behalf of. */
|
|
2992
|
+
workspaceId: string;
|
|
2993
|
+
/** The template's slug within your application, e.g. `quote-issued` - never its Meta name. */
|
|
2994
|
+
template: string;
|
|
2995
|
+
/** Meta language code the template was approved in. Defaults to `en`. */
|
|
2996
|
+
language?: string;
|
|
2997
|
+
/** E.164, e.g. `+919876543210`. */
|
|
2998
|
+
to: string;
|
|
2999
|
+
/** One value per template variable, by name. A missing one refuses the send. */
|
|
3000
|
+
values?: Record<string, string>;
|
|
3001
|
+
/**
|
|
3002
|
+
* The opt-in your application collected, recorded only when Connect has
|
|
3003
|
+
* none on file for the number. A number that withdrew stays withdrawn.
|
|
3004
|
+
*/
|
|
3005
|
+
consent?: {
|
|
3006
|
+
collectedVia: string;
|
|
3007
|
+
};
|
|
3008
|
+
}
|
|
3009
|
+
export interface SendWhatsAppResponse {
|
|
3010
|
+
status: "sent";
|
|
3011
|
+
messageId: string;
|
|
3012
|
+
}
|
|
3013
|
+
/** Meta's review state for a template. Only `APPROVED` sends. */
|
|
3014
|
+
export type WhatsAppTemplateReviewStatus = "DRAFT" | "PENDING" | "APPROVED" | "REJECTED" | "PAUSED" | "DISABLED";
|
|
3015
|
+
/** Whether one of your templates would send right now. Branch on `live`. */
|
|
3016
|
+
export interface WhatsAppTemplateState {
|
|
3017
|
+
slug: string;
|
|
3018
|
+
language: string;
|
|
3019
|
+
/** Meta's name for it: `app_<applicationKey>_<slug>`. */
|
|
3020
|
+
name: string;
|
|
3021
|
+
status: WhatsAppTemplateReviewStatus;
|
|
3022
|
+
/** Approved by Meta *and* currently served. */
|
|
3023
|
+
live: boolean;
|
|
3024
|
+
/** The values a send must carry, from the approved content. */
|
|
3025
|
+
variables: string[];
|
|
3026
|
+
}
|
|
2985
3027
|
/**
|
|
2986
3028
|
* One notification, to members of one workspace.
|
|
2987
3029
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmoops/connect-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "Official server-side SDK for the CosmoOps Connect platform API - Login with Connect, entitlements, billing and metering.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "commonjs",
|