@cosmoops/connect-sdk 0.1.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/LICENSE +34 -0
- package/README.md +446 -0
- package/dist/cjs/cli/bin.js +16 -0
- package/dist/cjs/cli/init.js +179 -0
- package/dist/cjs/client/components/account-sessions.js +112 -0
- package/dist/cjs/client/components/apps-grid.js +46 -0
- package/dist/cjs/client/components/auth-buttons.js +42 -0
- package/dist/cjs/client/components/feature-gate.js +61 -0
- package/dist/cjs/client/components/link-button.js +24 -0
- package/dist/cjs/client/components/logo.js +27 -0
- package/dist/cjs/client/components/plan-pricing.js +166 -0
- package/dist/cjs/client/components/plans-page.js +39 -0
- package/dist/cjs/client/components/plans.js +212 -0
- package/dist/cjs/client/components/readiness.js +117 -0
- package/dist/cjs/client/components/subscribe-dialog.js +60 -0
- package/dist/cjs/client/components/subscription.js +189 -0
- package/dist/cjs/client/components/usage-meter.js +68 -0
- package/dist/cjs/client/components/user-menu.js +172 -0
- package/dist/cjs/client/index.js +99 -0
- package/dist/cjs/client/mark.js +16 -0
- package/dist/cjs/client/provider.js +259 -0
- package/dist/cjs/client/use-checkout.js +173 -0
- package/dist/cjs/errors.js +74 -0
- package/dist/cjs/format-relative-time.js +18 -0
- package/dist/cjs/helpers.js +30 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/next/index.js +311 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/server/client.js +114 -0
- package/dist/cjs/server/handler.js +333 -0
- package/dist/cjs/server/http.js +160 -0
- package/dist/cjs/server/index.js +18 -0
- package/dist/cjs/server/resources/access.js +28 -0
- package/dist/cjs/server/resources/ai.js +36 -0
- package/dist/cjs/server/resources/apps.js +30 -0
- package/dist/cjs/server/resources/billing.js +71 -0
- package/dist/cjs/server/resources/drive.js +39 -0
- package/dist/cjs/server/resources/entitlements.js +49 -0
- package/dist/cjs/server/resources/identity.js +194 -0
- package/dist/cjs/server/resources/logs.js +41 -0
- package/dist/cjs/server/resources/otp.js +29 -0
- package/dist/cjs/server/resources/sessions.js +82 -0
- package/dist/cjs/types.js +15 -0
- package/dist/esm/cli/bin.js +13 -0
- package/dist/esm/cli/init.js +174 -0
- package/dist/esm/client/components/account-sessions.js +109 -0
- package/dist/esm/client/components/apps-grid.js +43 -0
- package/dist/esm/client/components/auth-buttons.js +38 -0
- package/dist/esm/client/components/feature-gate.js +57 -0
- package/dist/esm/client/components/link-button.js +21 -0
- package/dist/esm/client/components/logo.js +24 -0
- package/dist/esm/client/components/plan-pricing.js +156 -0
- package/dist/esm/client/components/plans-page.js +36 -0
- package/dist/esm/client/components/plans.js +209 -0
- package/dist/esm/client/components/readiness.js +113 -0
- package/dist/esm/client/components/subscribe-dialog.js +57 -0
- package/dist/esm/client/components/subscription.js +181 -0
- package/dist/esm/client/components/usage-meter.js +65 -0
- package/dist/esm/client/components/user-menu.js +164 -0
- package/dist/esm/client/index.js +47 -0
- package/dist/esm/client/mark.js +13 -0
- package/dist/esm/client/provider.js +247 -0
- package/dist/esm/client/use-checkout.js +168 -0
- package/dist/esm/errors.js +69 -0
- package/dist/esm/format-relative-time.js +15 -0
- package/dist/esm/helpers.js +26 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/next/index.js +279 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/server/client.js +110 -0
- package/dist/esm/server/handler.js +330 -0
- package/dist/esm/server/http.js +156 -0
- package/dist/esm/server/index.js +10 -0
- package/dist/esm/server/resources/access.js +24 -0
- package/dist/esm/server/resources/ai.js +32 -0
- package/dist/esm/server/resources/apps.js +26 -0
- package/dist/esm/server/resources/billing.js +67 -0
- package/dist/esm/server/resources/drive.js +35 -0
- package/dist/esm/server/resources/entitlements.js +45 -0
- package/dist/esm/server/resources/identity.js +189 -0
- package/dist/esm/server/resources/logs.js +37 -0
- package/dist/esm/server/resources/otp.js +25 -0
- package/dist/esm/server/resources/sessions.js +78 -0
- package/dist/esm/types.js +14 -0
- package/dist/theme.css +84 -0
- package/dist/types/cli/bin.d.ts +1 -0
- package/dist/types/cli/init.d.ts +34 -0
- package/dist/types/client/components/account-sessions.d.ts +25 -0
- package/dist/types/client/components/apps-grid.d.ts +20 -0
- package/dist/types/client/components/auth-buttons.d.ts +31 -0
- package/dist/types/client/components/feature-gate.d.ts +57 -0
- package/dist/types/client/components/link-button.d.ts +20 -0
- package/dist/types/client/components/logo.d.ts +35 -0
- package/dist/types/client/components/plan-pricing.d.ts +96 -0
- package/dist/types/client/components/plans-page.d.ts +36 -0
- package/dist/types/client/components/plans.d.ts +34 -0
- package/dist/types/client/components/readiness.d.ts +52 -0
- package/dist/types/client/components/subscribe-dialog.d.ts +34 -0
- package/dist/types/client/components/subscription.d.ts +123 -0
- package/dist/types/client/components/usage-meter.d.ts +24 -0
- package/dist/types/client/components/user-menu.d.ts +86 -0
- package/dist/types/client/index.d.ts +47 -0
- package/dist/types/client/mark.d.ts +11 -0
- package/dist/types/client/provider.d.ts +209 -0
- package/dist/types/client/use-checkout.d.ts +93 -0
- package/dist/types/errors.d.ts +62 -0
- package/dist/types/format-relative-time.d.ts +2 -0
- package/dist/types/helpers.d.ts +33 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/next/index.d.ts +136 -0
- package/dist/types/server/client.d.ts +83 -0
- package/dist/types/server/handler.d.ts +67 -0
- package/dist/types/server/http.d.ts +52 -0
- package/dist/types/server/index.d.ts +15 -0
- package/dist/types/server/resources/access.d.ts +17 -0
- package/dist/types/server/resources/ai.d.ts +24 -0
- package/dist/types/server/resources/apps.d.ts +12 -0
- package/dist/types/server/resources/billing.d.ts +41 -0
- package/dist/types/server/resources/drive.d.ts +26 -0
- package/dist/types/server/resources/entitlements.d.ts +31 -0
- package/dist/types/server/resources/identity.d.ts +76 -0
- package/dist/types/server/resources/logs.d.ts +20 -0
- package/dist/types/server/resources/otp.d.ts +17 -0
- package/dist/types/server/resources/sessions.d.ts +37 -0
- package/dist/types/types.d.ts +434 -0
- package/package.json +102 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types for the `/api/v1/service/*` surface - the service-partner API,
|
|
3
|
+
* and the only thing this SDK covers.
|
|
4
|
+
*
|
|
5
|
+
* Hand-written rather than generated so the published package carries no
|
|
6
|
+
* dependency on Connect's internals. `src/conformance.test.ts` type-checks
|
|
7
|
+
* these against the server's own DTOs, so drift fails the build here instead
|
|
8
|
+
* of surfacing as a runtime surprise in a partner's integration.
|
|
9
|
+
*
|
|
10
|
+
* Dates cross the wire as ISO 8601 strings and are left that way - parsing
|
|
11
|
+
* them into `Date` would be a lossy guess about what the caller wants, and
|
|
12
|
+
* `new Date(value)` is right there.
|
|
13
|
+
*/
|
|
14
|
+
export interface ConnectUser {
|
|
15
|
+
userId: string;
|
|
16
|
+
email: string | null;
|
|
17
|
+
emailVerified: boolean;
|
|
18
|
+
displayName: string | null;
|
|
19
|
+
organizationId: string;
|
|
20
|
+
organizationName: string;
|
|
21
|
+
}
|
|
22
|
+
export type SubscriptionStatus = "created" | "authenticated" | "active" | "paused" | "cancelled";
|
|
23
|
+
/** The compact subscription block returned alongside identity - `null` when the org has never subscribed to this service. */
|
|
24
|
+
export interface SessionSubscription {
|
|
25
|
+
planId: string;
|
|
26
|
+
status: SubscriptionStatus;
|
|
27
|
+
nextBillingDate: string | null;
|
|
28
|
+
/** `status` alone cannot tell trialing from paying; both are `"active"`. */
|
|
29
|
+
isTrialing: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What this member may do on *your* service - resolved for your `client_id`,
|
|
33
|
+
* not their org-wide roles. `role` is `null` when their granted permissions
|
|
34
|
+
* match no single defined role, including when they have no access at all.
|
|
35
|
+
*/
|
|
36
|
+
export interface ServiceRole {
|
|
37
|
+
role: string | null;
|
|
38
|
+
granted: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface TokenResponse {
|
|
41
|
+
idToken: string;
|
|
42
|
+
tokenType: "Bearer";
|
|
43
|
+
/** Seconds until `idToken` expires - about 5 minutes. */
|
|
44
|
+
expiresIn: number;
|
|
45
|
+
/** Opaque, revocable. Store this; it is the only part of the response meant to outlive the callback. */
|
|
46
|
+
sessionToken: string;
|
|
47
|
+
/** Seconds until `sessionToken` expires - about 15 days. */
|
|
48
|
+
sessionTokenExpiresIn: number;
|
|
49
|
+
user: ConnectUser;
|
|
50
|
+
subscription: SessionSubscription | null;
|
|
51
|
+
serviceRole: ServiceRole;
|
|
52
|
+
}
|
|
53
|
+
export interface UserResponse {
|
|
54
|
+
user: ConnectUser;
|
|
55
|
+
subscription: SessionSubscription | null;
|
|
56
|
+
serviceRole: ServiceRole;
|
|
57
|
+
/** ISO 8601. Refresh proactively off this rather than waiting for a 401. */
|
|
58
|
+
sessionExpiresAt: string;
|
|
59
|
+
}
|
|
60
|
+
/** Verified claims from an `idToken`. */
|
|
61
|
+
export interface IdTokenClaims {
|
|
62
|
+
/** Connect user id. */
|
|
63
|
+
sub: string;
|
|
64
|
+
/** Your `client_id`. */
|
|
65
|
+
aud: string;
|
|
66
|
+
iss: string;
|
|
67
|
+
exp: number;
|
|
68
|
+
iat: number;
|
|
69
|
+
org_id: string;
|
|
70
|
+
email?: string | null;
|
|
71
|
+
email_verified?: boolean;
|
|
72
|
+
[claim: string]: unknown;
|
|
73
|
+
}
|
|
74
|
+
export type LogoutScope = "device" | "all";
|
|
75
|
+
export interface UserRolesResponse {
|
|
76
|
+
userId: string;
|
|
77
|
+
organizationId: string;
|
|
78
|
+
role: string | null;
|
|
79
|
+
granted: string[];
|
|
80
|
+
}
|
|
81
|
+
export interface ServicePermission {
|
|
82
|
+
id: string;
|
|
83
|
+
label: string;
|
|
84
|
+
description: string;
|
|
85
|
+
}
|
|
86
|
+
export interface ServiceRoleDefinition {
|
|
87
|
+
key: string;
|
|
88
|
+
name: string;
|
|
89
|
+
description: string;
|
|
90
|
+
permissions: string[];
|
|
91
|
+
}
|
|
92
|
+
export interface RolesResponse {
|
|
93
|
+
serviceId: string;
|
|
94
|
+
serviceKey: string | null;
|
|
95
|
+
permissionCatalog: ServicePermission[];
|
|
96
|
+
roles: ServiceRoleDefinition[];
|
|
97
|
+
}
|
|
98
|
+
export type ReadinessBlockerCode = "subscription_missing" | "subscription_inactive" | "audience_mismatch" | "verification_required" | "verification_pending" | "verification_rejected" | "verification_expired" | "payment_method_missing" | "seat_limit_reached" | "organization_not_found" | "onboarding_approval_pending" | "onboarding_approval_rejected";
|
|
99
|
+
export interface ReadinessBlocker {
|
|
100
|
+
/**
|
|
101
|
+
* Branch on this. Typed as a union for the codes that exist today, widened
|
|
102
|
+
* with `(string & {})` because the server adds codes without a major
|
|
103
|
+
* version - an unrecognised one should be treated as blocking.
|
|
104
|
+
*/
|
|
105
|
+
code: ReadinessBlockerCode | (string & {});
|
|
106
|
+
severity: "blocking" | "advisory";
|
|
107
|
+
/** Human-facing and subject to rewording. Show it, do not parse it. */
|
|
108
|
+
message: string;
|
|
109
|
+
/** Where in Connect the customer resolves this. `null` when nothing they do helps (e.g. a review in progress). */
|
|
110
|
+
resolveUrl: string | null;
|
|
111
|
+
}
|
|
112
|
+
export interface ReadinessResponse {
|
|
113
|
+
organizationId: string;
|
|
114
|
+
serviceId: string;
|
|
115
|
+
/** `false` if any blocker is `"blocking"`. */
|
|
116
|
+
ready: boolean;
|
|
117
|
+
readiness: {
|
|
118
|
+
source: "connect";
|
|
119
|
+
blockers: ReadinessBlocker[];
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export interface PlanSeats {
|
|
123
|
+
model: "unlimited" | "fixed" | "per-seat";
|
|
124
|
+
included: number | null;
|
|
125
|
+
pricePerExtraSeat: number | null;
|
|
126
|
+
}
|
|
127
|
+
export interface PlanStorage {
|
|
128
|
+
model: "unlimited" | "fixed";
|
|
129
|
+
includedBytes: number | null;
|
|
130
|
+
}
|
|
131
|
+
export interface PlanAddonConsumable {
|
|
132
|
+
unit: string;
|
|
133
|
+
includedPerCycle: number;
|
|
134
|
+
carryForward: boolean;
|
|
135
|
+
overagePolicy: "reject" | "bill";
|
|
136
|
+
overagePricePerUnit: number | null;
|
|
137
|
+
maxOverageUnits: number | null;
|
|
138
|
+
}
|
|
139
|
+
export interface PlanAddon {
|
|
140
|
+
id: string;
|
|
141
|
+
name: string;
|
|
142
|
+
/** GST-exclusive, in paise. */
|
|
143
|
+
price: number;
|
|
144
|
+
consumable?: PlanAddonConsumable | null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* A plan feature with its label, as the **catalogue** read reports it.
|
|
148
|
+
*
|
|
149
|
+
* Note the asymmetry with `SubscribedPlan.features`, which is bare
|
|
150
|
+
* `string[]` and stays that way. That field is a gating contract - your
|
|
151
|
+
* backend calls `hasFeature(orgId, "campaign-module")` against it, and
|
|
152
|
+
* `ConnectFeatureGate` matches on it - so turning it into objects would break
|
|
153
|
+
* every check for a label nobody gates on. This one exists to be rendered,
|
|
154
|
+
* and rendering a bare key puts "campaign-module" on a pricing card where it
|
|
155
|
+
* meant "Campaign module".
|
|
156
|
+
*
|
|
157
|
+
* `key` is carried here too, so a component doing both needs no second lookup.
|
|
158
|
+
*/
|
|
159
|
+
export interface PlanFeature {
|
|
160
|
+
/** The same value `SubscribedPlan.features` holds and `hasFeature` gates on. */
|
|
161
|
+
key: string;
|
|
162
|
+
/** Human label. Falls back to `key` for a plan predating the service's feature catalog. */
|
|
163
|
+
name: string;
|
|
164
|
+
/** Empty string when the catalog carries no description. */
|
|
165
|
+
description: string;
|
|
166
|
+
}
|
|
167
|
+
export interface Plan {
|
|
168
|
+
id: string;
|
|
169
|
+
name: string;
|
|
170
|
+
/**
|
|
171
|
+
* The *tier* this plan prices, independent of how often it bills. A tier's
|
|
172
|
+
* monthly and annual plans share one - so `"growth"` covers both the
|
|
173
|
+
* "Growth" monthly row and the "Growth" annual row.
|
|
174
|
+
*
|
|
175
|
+
* This is what `ConnectPlans` groups its cards by. Before it existed the
|
|
176
|
+
* grid paired plans by matching `name`, which Connect neither enforces to be
|
|
177
|
+
* unique nor keeps stable across a rename or a clone - so a catalog could
|
|
178
|
+
* silently split one tier across two cards, or show a saving computed from
|
|
179
|
+
* two plans that had nothing to do with each other.
|
|
180
|
+
*/
|
|
181
|
+
planGroup: string;
|
|
182
|
+
description: string;
|
|
183
|
+
/** GST-exclusive, in paise. */
|
|
184
|
+
price: number;
|
|
185
|
+
currency: "INR";
|
|
186
|
+
billingInterval: "monthly" | "annual";
|
|
187
|
+
gstRate: number;
|
|
188
|
+
addons: PlanAddon[];
|
|
189
|
+
seats: PlanSeats;
|
|
190
|
+
storage: PlanStorage;
|
|
191
|
+
trialDays: number | null;
|
|
192
|
+
/** What this plan unlocks, labelled for display - see `PlanFeature`. */
|
|
193
|
+
features: PlanFeature[];
|
|
194
|
+
}
|
|
195
|
+
export interface PlansResponse {
|
|
196
|
+
plans: Plan[];
|
|
197
|
+
}
|
|
198
|
+
/** The plan as attached to a live subscription - a narrower view than the catalog's `Plan`. */
|
|
199
|
+
export interface SubscribedPlan {
|
|
200
|
+
id: string;
|
|
201
|
+
name: string;
|
|
202
|
+
billingInterval: "monthly" | "annual";
|
|
203
|
+
price: number;
|
|
204
|
+
currency: "INR";
|
|
205
|
+
gstRate: number;
|
|
206
|
+
seats: PlanSeats;
|
|
207
|
+
/**
|
|
208
|
+
* Feature **keys** this plan unlocks. Your backend gates plan-restricted
|
|
209
|
+
* modules on this, and `ConnectFeatureGate` matches on it.
|
|
210
|
+
*
|
|
211
|
+
* Deliberately bare keys, unlike the catalogue's `Plan.features` - see
|
|
212
|
+
* `PlanFeature`. This is a contract, not a label: a key is stable and
|
|
213
|
+
* comparable, a display name is neither.
|
|
214
|
+
*/
|
|
215
|
+
features: string[];
|
|
216
|
+
}
|
|
217
|
+
export interface AppliedDiscount {
|
|
218
|
+
source: "coupon" | "admin";
|
|
219
|
+
/** Display code - `null` for an admin-applied discount with no coupon behind it. */
|
|
220
|
+
code: string | null;
|
|
221
|
+
discountType: "percentage" | "fixed";
|
|
222
|
+
/** 1-90 for `"percentage"`; GST-exclusive paise for `"fixed"`. */
|
|
223
|
+
value: number;
|
|
224
|
+
duration: "once" | "repeating" | "forever";
|
|
225
|
+
/** Decremented each captured cycle. `null` only for `"forever"`. */
|
|
226
|
+
cyclesRemaining: number | null;
|
|
227
|
+
}
|
|
228
|
+
export interface SubscriptionDetail {
|
|
229
|
+
/** Deep-link target: `/billing/subscriptions/{id}` manages this subscription. */
|
|
230
|
+
id: string;
|
|
231
|
+
status: SubscriptionStatus;
|
|
232
|
+
cancelAtPeriodEnd: boolean;
|
|
233
|
+
seatCount: number;
|
|
234
|
+
addons: string[];
|
|
235
|
+
currentBillingCycle: {
|
|
236
|
+
startDate: string;
|
|
237
|
+
endDate: string;
|
|
238
|
+
} | null;
|
|
239
|
+
nextBillingDate: string | null;
|
|
240
|
+
subscribedAt: string;
|
|
241
|
+
/** `null` when no coupon or admin discount is in effect. */
|
|
242
|
+
appliedDiscount: AppliedDiscount | null;
|
|
243
|
+
}
|
|
244
|
+
export interface SubscriptionResponse {
|
|
245
|
+
organizationId: string;
|
|
246
|
+
serviceId: string;
|
|
247
|
+
/** Equivalent to `subscription?.status === "active"`. */
|
|
248
|
+
hasActiveSubscription: boolean;
|
|
249
|
+
subscription: SubscriptionDetail | null;
|
|
250
|
+
/** `null` exactly when `subscription` is. */
|
|
251
|
+
plan: SubscribedPlan | null;
|
|
252
|
+
}
|
|
253
|
+
/** One consumable add-on's remaining balance on an organization's subscription. */
|
|
254
|
+
export interface AddonUsage {
|
|
255
|
+
addonId: string;
|
|
256
|
+
name: string;
|
|
257
|
+
/** What one unit is called - "messages", "credits", "minutes". */
|
|
258
|
+
unit: string;
|
|
259
|
+
/** Units granted at the start of each billing cycle. */
|
|
260
|
+
includedPerCycle: number;
|
|
261
|
+
/**
|
|
262
|
+
* Units left to spend.
|
|
263
|
+
*
|
|
264
|
+
* Can exceed `includedPerCycle` when `carryForward`, and goes negative only
|
|
265
|
+
* when `overagePolicy` is `"bill"` - that is accrued overage, floored at
|
|
266
|
+
* `-maxOverageUnits`.
|
|
267
|
+
*/
|
|
268
|
+
balance: number;
|
|
269
|
+
carryForward: boolean;
|
|
270
|
+
overagePolicy: "reject" | "bill";
|
|
271
|
+
/** GST-exclusive paise per unit past the balance. `null` under `"reject"`. */
|
|
272
|
+
overagePricePerUnit: number | null;
|
|
273
|
+
maxOverageUnits: number | null;
|
|
274
|
+
}
|
|
275
|
+
export interface AddonUsageResponse {
|
|
276
|
+
organizationId: string;
|
|
277
|
+
serviceId: string;
|
|
278
|
+
/**
|
|
279
|
+
* Empty when the organization has no subscription, the plan has no
|
|
280
|
+
* consumable add-ons, or none are selected. All three mean "nothing to
|
|
281
|
+
* meter" and none is an error.
|
|
282
|
+
*
|
|
283
|
+
* Note there is no "used this cycle" figure: with `carryForward` a balance
|
|
284
|
+
* survives the cycle boundary, so `includedPerCycle - balance` can go
|
|
285
|
+
* negative and would render as a meter running backwards. Show `balance`
|
|
286
|
+
* against `includedPerCycle`.
|
|
287
|
+
*/
|
|
288
|
+
addons: AddonUsage[];
|
|
289
|
+
/** ISO 8601. End of the current billing cycle, when balances are re-granted. */
|
|
290
|
+
resetsAt: string | null;
|
|
291
|
+
}
|
|
292
|
+
export interface ConsumeAddonInput {
|
|
293
|
+
organizationId: string;
|
|
294
|
+
addonId: string;
|
|
295
|
+
/** Whole units of the add-on's `unit`. */
|
|
296
|
+
quantity: number;
|
|
297
|
+
description?: string;
|
|
298
|
+
}
|
|
299
|
+
export interface ConsumeAddonResponse {
|
|
300
|
+
addonId: string;
|
|
301
|
+
consumed: number;
|
|
302
|
+
/** Remaining immediately after this call. Negative only when `overagePolicy` is `"bill"`. */
|
|
303
|
+
balance: number;
|
|
304
|
+
overageUnits: number;
|
|
305
|
+
}
|
|
306
|
+
export type OtpChannel = "whatsapp" | "sms";
|
|
307
|
+
export interface SendOtpInput {
|
|
308
|
+
/** E.164, e.g. `+919876543210`. */
|
|
309
|
+
phoneNumber: string;
|
|
310
|
+
channel?: OtpChannel;
|
|
311
|
+
}
|
|
312
|
+
export interface SendOtpResponse {
|
|
313
|
+
verificationId: string;
|
|
314
|
+
status: "pending";
|
|
315
|
+
channel: OtpChannel;
|
|
316
|
+
expiresIn: number;
|
|
317
|
+
/** Test mode only. */
|
|
318
|
+
code?: string;
|
|
319
|
+
}
|
|
320
|
+
export interface VerifyOtpInput {
|
|
321
|
+
verificationId: string;
|
|
322
|
+
/** 6 digits. */
|
|
323
|
+
code: string;
|
|
324
|
+
}
|
|
325
|
+
export interface VerifyOtpResponse {
|
|
326
|
+
verificationId: string;
|
|
327
|
+
status: "pending" | "approved" | "expired" | "max_attempts_exceeded";
|
|
328
|
+
phoneNumber: string;
|
|
329
|
+
}
|
|
330
|
+
export interface UploadedFile {
|
|
331
|
+
id: string;
|
|
332
|
+
fileName: string;
|
|
333
|
+
mimeType: string;
|
|
334
|
+
size: number;
|
|
335
|
+
url: string;
|
|
336
|
+
}
|
|
337
|
+
export type ThumbnailSize = "small" | "medium" | "large";
|
|
338
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
339
|
+
export interface WriteLogInput {
|
|
340
|
+
level?: LogLevel;
|
|
341
|
+
message: string;
|
|
342
|
+
metadata?: Record<string, unknown>;
|
|
343
|
+
/** ISO 8601 or a `Date`. Defaults to now. */
|
|
344
|
+
timestamp?: string | Date;
|
|
345
|
+
/**
|
|
346
|
+
* Attribute this event to an end user, by their opaque Connect
|
|
347
|
+
* `sessionToken` - the same one the token exchange handed you.
|
|
348
|
+
*
|
|
349
|
+
* **There is no `userId` to send, deliberately.** The token is verified and
|
|
350
|
+
* checked to have been minted for *your* service before anything is
|
|
351
|
+
* attributed, exactly as `serviceId` comes from your API key rather than
|
|
352
|
+
* your body. An actor a caller could type is not an actor worth recording.
|
|
353
|
+
*
|
|
354
|
+
* Omit it for genuine server-to-server events with no user behind them.
|
|
355
|
+
*/
|
|
356
|
+
sessionToken?: string;
|
|
357
|
+
}
|
|
358
|
+
export interface WriteLogResponse {
|
|
359
|
+
/** `false` when the write failed - see `LogsResource.write`, which never throws. */
|
|
360
|
+
delivered: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Whether a supplied `sessionToken` resolved to a user.
|
|
363
|
+
*
|
|
364
|
+
* `false` with `delivered: true` means the line was stored unattributed - an
|
|
365
|
+
* expired or revoked token. The event is deliberately kept rather than
|
|
366
|
+
* rejected: losing telemetry because attribution failed is the worse of the
|
|
367
|
+
* two outcomes. Always `false` when no `sessionToken` was sent.
|
|
368
|
+
*/
|
|
369
|
+
attributed: boolean;
|
|
370
|
+
}
|
|
371
|
+
/** One turn of a RAG chat. Matches the AI SDK's `UIMessage` loosely enough to pass one straight through. */
|
|
372
|
+
export interface ChatMessage {
|
|
373
|
+
role: "user" | "assistant" | "system";
|
|
374
|
+
[field: string]: unknown;
|
|
375
|
+
}
|
|
376
|
+
export interface OrganizationApp {
|
|
377
|
+
serviceId: string;
|
|
378
|
+
/** Stable, human-readable key - branch on this, not `serviceId`, which is per-environment. */
|
|
379
|
+
serviceKey: string | null;
|
|
380
|
+
name: string;
|
|
381
|
+
/** Plain text, HTML already stripped server-side. */
|
|
382
|
+
description: string;
|
|
383
|
+
/** Uploaded brand icon. `null` falls back to `icon`. */
|
|
384
|
+
iconUrl: string | null;
|
|
385
|
+
/** A `lucide-react` icon name from Connect's curated set. */
|
|
386
|
+
icon: string;
|
|
387
|
+
/** Where a tile navigates. `null` when the service registered no site. */
|
|
388
|
+
launchUrl: string | null;
|
|
389
|
+
/** True for the service whose API key made the call - render it as the active tile. */
|
|
390
|
+
isCurrent: boolean;
|
|
391
|
+
/** Launchable but not healthy (paused, or cancelling at period end) - badge it, do not hide it. */
|
|
392
|
+
needsAttention: boolean;
|
|
393
|
+
}
|
|
394
|
+
export type SessionDeviceType = "desktop" | "mobile" | "tablet" | "unknown";
|
|
395
|
+
export interface SessionDevice {
|
|
396
|
+
userAgent: string;
|
|
397
|
+
browser: string | null;
|
|
398
|
+
browserVersion: string | null;
|
|
399
|
+
os: string | null;
|
|
400
|
+
osVersion: string | null;
|
|
401
|
+
deviceType: SessionDeviceType;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* One login to the Connect account behind the `sessionToken` you called with -
|
|
405
|
+
* not scoped to this service. A Connect session is one browser's login to
|
|
406
|
+
* Connect itself, and it fans out to every partner service's own session -
|
|
407
|
+
* Connect has no per-service session concept to filter by. `sessions.list()`
|
|
408
|
+
* returns every one of them, exactly like Connect's own account settings
|
|
409
|
+
* page does for the user themselves.
|
|
410
|
+
*/
|
|
411
|
+
export interface ConnectUserSession {
|
|
412
|
+
id: string;
|
|
413
|
+
/** ISO 8601. */
|
|
414
|
+
createdAt: string;
|
|
415
|
+
/** ISO 8601. */
|
|
416
|
+
lastActiveAt: string;
|
|
417
|
+
/** ISO 8601. */
|
|
418
|
+
expiresAt: string;
|
|
419
|
+
device: SessionDevice;
|
|
420
|
+
ip: string | null;
|
|
421
|
+
ipCity: string | null;
|
|
422
|
+
ipCountry: string | null;
|
|
423
|
+
/** Whether this is the session your `sessionToken` was minted from. */
|
|
424
|
+
isCurrent: boolean;
|
|
425
|
+
}
|
|
426
|
+
export interface SessionsListResponse {
|
|
427
|
+
items: ConnectUserSession[];
|
|
428
|
+
}
|
|
429
|
+
export interface RevokeOtherSessionsResponse {
|
|
430
|
+
success: true;
|
|
431
|
+
revokedCount: number;
|
|
432
|
+
}
|
|
433
|
+
/** Host-controlled - the SDK has no theme provider of its own. See `ConnectUserMenuProps.theme`. */
|
|
434
|
+
export type ThemeMode = "light" | "dark" | "system";
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cosmoops/connect-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official server-side SDK for the CosmoOps Connect platform API - Login with Connect, entitlements, billing and metering.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "./dist/cjs/index.js",
|
|
8
|
+
"module": "./dist/esm/index.js",
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"import": "./dist/esm/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./server": {
|
|
17
|
+
"types": "./dist/types/server/index.d.ts",
|
|
18
|
+
"import": "./dist/esm/server/index.js",
|
|
19
|
+
"require": "./dist/cjs/server/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./next": {
|
|
22
|
+
"types": "./dist/types/next/index.d.ts",
|
|
23
|
+
"import": "./dist/esm/next/index.js",
|
|
24
|
+
"require": "./dist/cjs/next/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./client": {
|
|
27
|
+
"types": "./dist/types/client/index.d.ts",
|
|
28
|
+
"import": "./dist/esm/client/index.js",
|
|
29
|
+
"require": "./dist/cjs/client/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./theme.css": "./dist/theme.css",
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"connect-sdk": "dist/cjs/cli/bin.js"
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"keywords": [
|
|
45
|
+
"cosmoops",
|
|
46
|
+
"connect",
|
|
47
|
+
"sso",
|
|
48
|
+
"oauth2",
|
|
49
|
+
"billing",
|
|
50
|
+
"entitlements"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"clean": "rm -rf dist",
|
|
57
|
+
"build": "bun run clean && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.types.json && bun run scripts/finalize-dist.ts",
|
|
58
|
+
"verify:pack": "bun run scripts/verify-pack.ts",
|
|
59
|
+
"prepublishOnly": "bun run build && bun run verify:pack",
|
|
60
|
+
"test": "bun test",
|
|
61
|
+
"storybook": "storybook dev -p 6106",
|
|
62
|
+
"build:storybook": "storybook build -o storybook-static"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@connect/data": "workspace:*",
|
|
66
|
+
"@heroui/react": "^3.2.2",
|
|
67
|
+
"@heroui/styles": "^3.2.2",
|
|
68
|
+
"@storybook/addon-a11y": "^10.5.10",
|
|
69
|
+
"@storybook/react-vite": "^10.5.10",
|
|
70
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
71
|
+
"@types/bun": "^1.3.14",
|
|
72
|
+
"@types/react": "^19",
|
|
73
|
+
"@types/react-dom": "^19",
|
|
74
|
+
"lucide-react": "^0.545.0",
|
|
75
|
+
"react": "19.2.8",
|
|
76
|
+
"react-dom": "19.2.8",
|
|
77
|
+
"storybook": "^10.5.10",
|
|
78
|
+
"tailwindcss": "^4.3.3",
|
|
79
|
+
"typescript": "^5",
|
|
80
|
+
"vite": "^8.2.2"
|
|
81
|
+
},
|
|
82
|
+
"peerDependencies": {
|
|
83
|
+
"@heroui/react": ">=3.2.0",
|
|
84
|
+
"lucide-react": ">=0.400.0",
|
|
85
|
+
"react": ">=18",
|
|
86
|
+
"react-dom": ">=18"
|
|
87
|
+
},
|
|
88
|
+
"peerDependenciesMeta": {
|
|
89
|
+
"@heroui/react": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"lucide-react": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"react": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"react-dom": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|