@cosmoops/connect-sdk 0.40.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/dist/cjs/client/components/access-gate.js +18 -40
  3. package/dist/cjs/client/components/apps-grid.js +11 -3
  4. package/dist/cjs/client/components/ask-ai-errors.js +109 -0
  5. package/dist/cjs/client/components/ask-ai-turns.js +12 -0
  6. package/dist/cjs/client/components/ask-ai.js +75 -8
  7. package/dist/cjs/client/components/call-button.js +398 -0
  8. package/dist/cjs/client/components/plans.js +8 -2
  9. package/dist/cjs/client/components/readiness.js +2 -1
  10. package/dist/cjs/client/components/subscription.js +4 -4
  11. package/dist/cjs/client/components/user-menu.js +16 -11
  12. package/dist/cjs/client/handoff.js +78 -0
  13. package/dist/cjs/client/index.js +15 -7
  14. package/dist/cjs/client/portal-links.js +1 -1
  15. package/dist/cjs/client/provider.js +75 -4
  16. package/dist/cjs/client/use-checkout.js +23 -16
  17. package/dist/cjs/server/client.js +5 -1
  18. package/dist/cjs/server/handler.js +77 -1
  19. package/dist/cjs/server/resources/calls.js +58 -0
  20. package/dist/cjs/server/resources/identity.js +12 -0
  21. package/dist/cjs/server/resources/whatsapp.js +58 -0
  22. package/dist/esm/client/components/access-gate.js +18 -40
  23. package/dist/esm/client/components/apps-grid.js +11 -3
  24. package/dist/esm/client/components/ask-ai-errors.js +102 -0
  25. package/dist/esm/client/components/ask-ai-turns.js +12 -0
  26. package/dist/esm/client/components/ask-ai.js +76 -9
  27. package/dist/esm/client/components/call-button.js +358 -0
  28. package/dist/esm/client/components/plans.js +8 -2
  29. package/dist/esm/client/components/readiness.js +2 -1
  30. package/dist/esm/client/components/subscription.js +4 -4
  31. package/dist/esm/client/components/user-menu.js +16 -11
  32. package/dist/esm/client/handoff.js +72 -0
  33. package/dist/esm/client/index.js +6 -4
  34. package/dist/esm/client/portal-links.js +1 -1
  35. package/dist/esm/client/provider.js +75 -4
  36. package/dist/esm/client/use-checkout.js +23 -16
  37. package/dist/esm/server/client.js +5 -1
  38. package/dist/esm/server/handler.js +77 -1
  39. package/dist/esm/server/resources/calls.js +58 -0
  40. package/dist/esm/server/resources/identity.js +12 -0
  41. package/dist/esm/server/resources/whatsapp.js +54 -0
  42. package/dist/types/client/components/ask-ai-errors.d.ts +41 -0
  43. package/dist/types/client/components/ask-ai-turns.d.ts +5 -0
  44. package/dist/types/client/components/call-button.d.ts +132 -0
  45. package/dist/types/client/handoff.d.ts +62 -0
  46. package/dist/types/client/index.d.ts +5 -1
  47. package/dist/types/client/portal-links.d.ts +1 -1
  48. package/dist/types/client/provider.d.ts +72 -5
  49. package/dist/types/client/use-checkout.d.ts +4 -1
  50. package/dist/types/server/client.d.ts +4 -1
  51. package/dist/types/server/resources/calls.d.ts +32 -1
  52. package/dist/types/server/resources/identity.d.ts +10 -0
  53. package/dist/types/server/resources/whatsapp.d.ts +44 -0
  54. package/dist/types/types.d.ts +152 -1
  55. package/package.json +4 -1
@@ -1269,12 +1269,29 @@ export interface CallCompletedEvent {
1269
1269
  * for presence.
1270
1270
  */
1271
1271
  extraction: Record<string, unknown>;
1272
+ /**
1273
+ * `member` when a person placed this call from a browser - `<ConnectCallButton>`
1274
+ * or Connect's own portal - rather than an agent handling it. Absent on
1275
+ * events sent before member calling existed; treat absent as `agent`.
1276
+ */
1277
+ handler?: CallHandler;
1278
+ /**
1279
+ * The member who placed a `member` call - their Connect user id, the same id
1280
+ * a workspace roster carries. The one to attribute the call to. `null` on an
1281
+ * agent's call.
1282
+ */
1283
+ placedByUserId?: string | null;
1284
+ /** That member's display name, else their email - so the call can be attributed without a roster read. */
1285
+ placedByName?: string | null;
1272
1286
  /** ISO-8601. */
1273
1287
  occurredAt: string;
1274
1288
  }
1275
1289
  /**
1276
1290
  * A call reached a channel and nothing answered it.
1277
1291
  *
1292
+ * Also raised for a call a member placed that the person rang did not pick
1293
+ * up (`handler: "member"`, `direction: "outbound"`) - somebody to try again.
1294
+ *
1278
1295
  * Its own event rather than an `outcome` on the one above, because the action
1279
1296
  * differs in kind: a completed call is something to file, a missed one is
1280
1297
  * somebody to ring back. Treating this as a lead is the right thing to do
@@ -1287,6 +1304,20 @@ export interface CallMissedEvent {
1287
1304
  /** E.164, and the only identity this carries - see `CallCompletedEvent.contactPhone`. */
1288
1305
  contactPhone: string | null;
1289
1306
  direction: ConnectCallDirection;
1307
+ /**
1308
+ * `member` when a person placed this call from a browser - `<ConnectCallButton>`
1309
+ * or Connect's own portal - rather than an agent handling it. Absent on
1310
+ * events sent before member calling existed; treat absent as `agent`.
1311
+ */
1312
+ handler?: CallHandler;
1313
+ /**
1314
+ * The member who placed a `member` call - their Connect user id, the same id
1315
+ * a workspace roster carries. The one to attribute the call to. `null` on an
1316
+ * agent's call.
1317
+ */
1318
+ placedByUserId?: string | null;
1319
+ /** That member's display name, else their email - so the call can be attributed without a roster read. */
1320
+ placedByName?: string | null;
1290
1321
  /** ISO-8601. */
1291
1322
  occurredAt: string;
1292
1323
  }
@@ -2696,8 +2727,16 @@ export type CallDirection = "inbound" | "outbound";
2696
2727
  * `rejected` means Connect never connected it - see `rejectReason`.
2697
2728
  * `answered` is a call still in progress; `completed` is one that ran and
2698
2729
  * ended.
2730
+ *
2731
+ * `dialing` and `unanswered` are an outbound call's: ringing, and nobody
2732
+ * picked up - see `unansweredReason`. A call your `<ConnectCallButton>`
2733
+ * placed passes through `dialing` on its way to one of the other two.
2699
2734
  */
2700
- export type CallStatus = "answered" | "rejected" | "completed";
2735
+ export type CallStatus = "dialing" | "answered" | "rejected" | "unanswered" | "completed";
2736
+ /** Who was on Connect's end of a call: one of the workspace's agents, or a member calling from a browser. */
2737
+ export type CallHandler = "agent" | "member";
2738
+ /** Why an outbound call reached nobody. Widened at its use site like `CallRejectReason`. */
2739
+ export type CallUnansweredReason = "no_answer" | "busy" | "failed" | "cancelled";
2701
2740
  /**
2702
2741
  * Why a call was refused. Widened at the point of use with `(string & {})`,
2703
2742
  * the same way `ReadinessBlocker.code` is: Connect adds reasons as it learns
@@ -2765,6 +2804,76 @@ export interface ConnectCall {
2765
2804
  extraction: Record<string, unknown> | null;
2766
2805
  agentId: string | null;
2767
2806
  agentVersion: number | null;
2807
+ /** `member` for a call a person placed with `<ConnectCallButton>`; such a call has no agent, transcript or recording. */
2808
+ handler: CallHandler;
2809
+ /** The member who placed a `member` call - their Connect user id. */
2810
+ placedByUserId: string | null;
2811
+ /**
2812
+ * How long the person called was on the line, for a `member` call. Read this
2813
+ * rather than `durationSeconds`, which there measures the member's own leg,
2814
+ * ringing included. `null` until the carrier reports it, and for a call
2815
+ * nobody answered.
2816
+ */
2817
+ talkSeconds: number | null;
2818
+ /** Why nobody answered - set only when `status` is `unanswered`. */
2819
+ unansweredReason: CallUnansweredReason | (string & {}) | null;
2820
+ }
2821
+ /**
2822
+ * What the browser needs to place one approved call - see
2823
+ * `calls.startBrowserCall`. `headers` are SIP headers to send with it; they
2824
+ * carry a one-time key, valid for two minutes, that lets the call be placed
2825
+ * once and by nobody else.
2826
+ */
2827
+ export interface StartedBrowserCall {
2828
+ callId: string;
2829
+ /** The number being rung, E.164. */
2830
+ toNumber: string;
2831
+ /** The workspace's own number, which the person called will see. */
2832
+ fromNumber: string;
2833
+ headers: Record<string, string>;
2834
+ }
2835
+ /**
2836
+ * Why a member can or cannot call - see `calls.getCallingAvailability`.
2837
+ *
2838
+ * - `no_permission` - they lack "Make calls". Don't offer calling.
2839
+ * - `no_number` - the workspace has no business number. `offer` says where to
2840
+ * buy one (a "Business number" add-on on one of its subscriptions).
2841
+ * - `number_pending` - one was bought but Connect's pool was empty; an admin
2842
+ * can retry from Connect's Calling page.
2843
+ * - `no_balance` - a number, but not a minute's worth of prepaid minutes.
2844
+ * - `available`.
2845
+ */
2846
+ export type CallingAvailabilityStatus = "available" | "no_permission" | "no_number" | "number_pending" | "no_balance";
2847
+ export interface CallingAvailability {
2848
+ status: CallingAvailabilityStatus;
2849
+ /** The workspace's business number, E.164, when it holds one. */
2850
+ number: string | null;
2851
+ /** Prepaid balance a new call may spend, in paise, pre-tax. */
2852
+ available: number;
2853
+ /** About how many minutes that buys. */
2854
+ availableMinutes: number;
2855
+ ratePaisePerMinute: number;
2856
+ /** Under about 55 minutes - worth a warning. */
2857
+ lowBalance: boolean;
2858
+ /** Whether this member may buy minutes. */
2859
+ canTopUp: boolean;
2860
+ /** Whether this member may add the number add-on or retry a pending number. */
2861
+ canManageNumber: boolean;
2862
+ /** Where a business number can be bought, when the workspace has none. */
2863
+ offer: {
2864
+ subscriptionId: string;
2865
+ applicationId: string;
2866
+ addonId: string;
2867
+ addonName: string;
2868
+ /** Pre-tax, paise, per billing cycle. */
2869
+ price: number;
2870
+ } | null;
2871
+ }
2872
+ /** A carrier access token a member's browser signs in to the phone network with. Valid for an hour. */
2873
+ export interface BrowserCallingToken {
2874
+ token: string;
2875
+ /** ISO-8601. */
2876
+ expiresAt: string;
2768
2877
  }
2769
2878
  /** Who spoke. */
2770
2879
  export type CallTurnRole = "user" | "agent";
@@ -2873,6 +2982,48 @@ export interface ConversationsPage {
2873
2982
  nextCursor: string | null;
2874
2983
  hasMore: boolean;
2875
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
+ }
2876
3027
  /**
2877
3028
  * One notification, to members of one workspace.
2878
3029
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmoops/connect-sdk",
3
- "version": "0.40.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",
@@ -136,5 +136,8 @@
136
136
  "streamdown": {
137
137
  "optional": true
138
138
  }
139
+ },
140
+ "dependencies": {
141
+ "plivo-browser-sdk": "2.2.21"
139
142
  }
140
143
  }