@stackbe/sdk 0.6.2 → 0.6.4

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/dist/index.d.mts CHANGED
@@ -251,6 +251,59 @@ interface SessionResponse {
251
251
  /** Feature entitlements */
252
252
  entitlements?: Record<string, boolean | number | string>;
253
253
  }
254
+ interface OrganizationMember {
255
+ id: string;
256
+ customerId: string;
257
+ email: string;
258
+ role: 'owner' | 'admin' | 'member';
259
+ invitedAt: string;
260
+ acceptedAt?: string;
261
+ }
262
+ interface Organization {
263
+ id: string;
264
+ appId: string;
265
+ name: string;
266
+ slug: string;
267
+ logoUrl?: string;
268
+ members: OrganizationMember[];
269
+ memberCount: number;
270
+ createdAt: string;
271
+ updatedAt: string;
272
+ }
273
+ interface CreateOrganizationOptions {
274
+ /** Organization name */
275
+ name: string;
276
+ /** Customer ID to set as owner */
277
+ ownerId: string;
278
+ /** Optional logo URL */
279
+ logoUrl?: string;
280
+ }
281
+ interface UpdateOrganizationOptions {
282
+ /** New organization name */
283
+ name?: string;
284
+ /** New logo URL */
285
+ logoUrl?: string;
286
+ }
287
+ interface AddMemberOptions {
288
+ /** Customer ID to add */
289
+ customerId: string;
290
+ /** Role for the member */
291
+ role?: 'admin' | 'member';
292
+ }
293
+ interface InviteMemberOptions {
294
+ /** Email to invite */
295
+ email: string;
296
+ /** Role for the invited member */
297
+ role?: 'admin' | 'member';
298
+ }
299
+ interface OrganizationInvite {
300
+ id: string;
301
+ organizationId: string;
302
+ email: string;
303
+ role: 'admin' | 'member';
304
+ status: 'pending' | 'accepted' | 'cancelled';
305
+ sentAt: string;
306
+ }
254
307
  interface CreateCheckoutOptions {
255
308
  /** Customer ID or email */
256
309
  customer: string | {
@@ -627,7 +680,8 @@ declare class EntitlementsClient {
627
680
 
628
681
  declare class CustomersClient {
629
682
  private http;
630
- constructor(http: HttpClient);
683
+ private appId;
684
+ constructor(http: HttpClient, appId: string);
631
685
  /**
632
686
  * Get a customer by ID.
633
687
  *
@@ -1049,6 +1103,133 @@ declare class AuthClient {
1049
1103
  isAuthenticated(sessionToken: string): Promise<boolean>;
1050
1104
  }
1051
1105
 
1106
+ declare class OrganizationsClient {
1107
+ private http;
1108
+ private appId;
1109
+ constructor(http: HttpClient, appId: string);
1110
+ /**
1111
+ * Create a new organization with a customer as owner.
1112
+ * Use this for B2B signup flows where you provision everything server-side.
1113
+ *
1114
+ * @example
1115
+ * ```typescript
1116
+ * const customer = await stackbe.customers.getOrCreate({ email: 'user@company.com' });
1117
+ * const org = await stackbe.organizations.create({
1118
+ * name: 'Acme Corp',
1119
+ * ownerId: customer.id
1120
+ * });
1121
+ * ```
1122
+ */
1123
+ create(options: CreateOrganizationOptions): Promise<Organization>;
1124
+ /**
1125
+ * List all organizations for this app.
1126
+ *
1127
+ * @example
1128
+ * ```typescript
1129
+ * const orgs = await stackbe.organizations.list();
1130
+ * ```
1131
+ */
1132
+ list(options?: {
1133
+ limit?: number;
1134
+ offset?: number;
1135
+ search?: string;
1136
+ }): Promise<Organization[]>;
1137
+ /**
1138
+ * Get an organization by ID.
1139
+ *
1140
+ * @example
1141
+ * ```typescript
1142
+ * const org = await stackbe.organizations.get('org_123');
1143
+ * ```
1144
+ */
1145
+ get(orgId: string): Promise<Organization>;
1146
+ /**
1147
+ * Update an organization.
1148
+ *
1149
+ * @example
1150
+ * ```typescript
1151
+ * const org = await stackbe.organizations.update('org_123', {
1152
+ * name: 'New Name'
1153
+ * });
1154
+ * ```
1155
+ */
1156
+ update(orgId: string, options: UpdateOrganizationOptions): Promise<Organization>;
1157
+ /**
1158
+ * Delete an organization.
1159
+ * Note: Organizations with active subscriptions cannot be deleted.
1160
+ *
1161
+ * @example
1162
+ * ```typescript
1163
+ * await stackbe.organizations.delete('org_123');
1164
+ * ```
1165
+ */
1166
+ delete(orgId: string): Promise<void>;
1167
+ /**
1168
+ * Add a customer as a member of an organization.
1169
+ *
1170
+ * @example
1171
+ * ```typescript
1172
+ * await stackbe.organizations.addMember('org_123', {
1173
+ * customerId: 'cust_456',
1174
+ * role: 'member'
1175
+ * });
1176
+ * ```
1177
+ */
1178
+ addMember(orgId: string, options: AddMemberOptions): Promise<OrganizationMember>;
1179
+ /**
1180
+ * Remove a member from an organization.
1181
+ *
1182
+ * @example
1183
+ * ```typescript
1184
+ * await stackbe.organizations.removeMember('org_123', 'member_456');
1185
+ * ```
1186
+ */
1187
+ removeMember(orgId: string, memberId: string): Promise<void>;
1188
+ /**
1189
+ * Update a member's role.
1190
+ *
1191
+ * @example
1192
+ * ```typescript
1193
+ * await stackbe.organizations.updateMember('org_123', 'member_456', {
1194
+ * role: 'admin'
1195
+ * });
1196
+ * ```
1197
+ */
1198
+ updateMember(orgId: string, memberId: string, options: {
1199
+ role: 'admin' | 'member';
1200
+ }): Promise<OrganizationMember>;
1201
+ /**
1202
+ * Send an invite to join an organization.
1203
+ *
1204
+ * @example
1205
+ * ```typescript
1206
+ * await stackbe.organizations.invite('org_123', {
1207
+ * email: 'newuser@company.com',
1208
+ * role: 'member'
1209
+ * });
1210
+ * ```
1211
+ */
1212
+ invite(orgId: string, options: InviteMemberOptions): Promise<OrganizationInvite>;
1213
+ /**
1214
+ * List pending invites for an organization.
1215
+ *
1216
+ * @example
1217
+ * ```typescript
1218
+ * const invites = await stackbe.organizations.listInvites('org_123');
1219
+ * ```
1220
+ */
1221
+ listInvites(orgId: string): Promise<OrganizationInvite[]>;
1222
+ /**
1223
+ * Cancel a pending invite.
1224
+ *
1225
+ * @example
1226
+ * ```typescript
1227
+ * await stackbe.organizations.cancelInvite('org_123', 'invite_456');
1228
+ * ```
1229
+ */
1230
+ cancelInvite(orgId: string, inviteId: string): Promise<void>;
1231
+ }
1232
+
1052
1233
  declare class StackBE {
1053
1234
  private http;
1054
1235
  private appId;
@@ -1064,6 +1245,8 @@ declare class StackBE {
1064
1245
  readonly subscriptions: SubscriptionsClient;
1065
1246
  /** Customer authentication (magic links) */
1066
1247
  readonly auth: AuthClient;
1248
+ /** Organization management (B2B multi-user) */
1249
+ readonly organizations: OrganizationsClient;
1067
1250
  /**
1068
1251
  * Create a new StackBE client.
1069
1252
  *
@@ -1164,4 +1347,4 @@ declare class StackBE {
1164
1347
  }): (req: any, res: any, next: any) => Promise<any>;
1165
1348
  }
1166
1349
 
1167
- export { type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type Customer, type CustomerCreatedEvent, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type MagicLinkOptions, type MagicLinkResponse, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
1350
+ export { type AddMemberOptions, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type InviteMemberOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.d.ts CHANGED
@@ -251,6 +251,59 @@ interface SessionResponse {
251
251
  /** Feature entitlements */
252
252
  entitlements?: Record<string, boolean | number | string>;
253
253
  }
254
+ interface OrganizationMember {
255
+ id: string;
256
+ customerId: string;
257
+ email: string;
258
+ role: 'owner' | 'admin' | 'member';
259
+ invitedAt: string;
260
+ acceptedAt?: string;
261
+ }
262
+ interface Organization {
263
+ id: string;
264
+ appId: string;
265
+ name: string;
266
+ slug: string;
267
+ logoUrl?: string;
268
+ members: OrganizationMember[];
269
+ memberCount: number;
270
+ createdAt: string;
271
+ updatedAt: string;
272
+ }
273
+ interface CreateOrganizationOptions {
274
+ /** Organization name */
275
+ name: string;
276
+ /** Customer ID to set as owner */
277
+ ownerId: string;
278
+ /** Optional logo URL */
279
+ logoUrl?: string;
280
+ }
281
+ interface UpdateOrganizationOptions {
282
+ /** New organization name */
283
+ name?: string;
284
+ /** New logo URL */
285
+ logoUrl?: string;
286
+ }
287
+ interface AddMemberOptions {
288
+ /** Customer ID to add */
289
+ customerId: string;
290
+ /** Role for the member */
291
+ role?: 'admin' | 'member';
292
+ }
293
+ interface InviteMemberOptions {
294
+ /** Email to invite */
295
+ email: string;
296
+ /** Role for the invited member */
297
+ role?: 'admin' | 'member';
298
+ }
299
+ interface OrganizationInvite {
300
+ id: string;
301
+ organizationId: string;
302
+ email: string;
303
+ role: 'admin' | 'member';
304
+ status: 'pending' | 'accepted' | 'cancelled';
305
+ sentAt: string;
306
+ }
254
307
  interface CreateCheckoutOptions {
255
308
  /** Customer ID or email */
256
309
  customer: string | {
@@ -627,7 +680,8 @@ declare class EntitlementsClient {
627
680
 
628
681
  declare class CustomersClient {
629
682
  private http;
630
- constructor(http: HttpClient);
683
+ private appId;
684
+ constructor(http: HttpClient, appId: string);
631
685
  /**
632
686
  * Get a customer by ID.
633
687
  *
@@ -1049,6 +1103,133 @@ declare class AuthClient {
1049
1103
  isAuthenticated(sessionToken: string): Promise<boolean>;
1050
1104
  }
1051
1105
 
1106
+ declare class OrganizationsClient {
1107
+ private http;
1108
+ private appId;
1109
+ constructor(http: HttpClient, appId: string);
1110
+ /**
1111
+ * Create a new organization with a customer as owner.
1112
+ * Use this for B2B signup flows where you provision everything server-side.
1113
+ *
1114
+ * @example
1115
+ * ```typescript
1116
+ * const customer = await stackbe.customers.getOrCreate({ email: 'user@company.com' });
1117
+ * const org = await stackbe.organizations.create({
1118
+ * name: 'Acme Corp',
1119
+ * ownerId: customer.id
1120
+ * });
1121
+ * ```
1122
+ */
1123
+ create(options: CreateOrganizationOptions): Promise<Organization>;
1124
+ /**
1125
+ * List all organizations for this app.
1126
+ *
1127
+ * @example
1128
+ * ```typescript
1129
+ * const orgs = await stackbe.organizations.list();
1130
+ * ```
1131
+ */
1132
+ list(options?: {
1133
+ limit?: number;
1134
+ offset?: number;
1135
+ search?: string;
1136
+ }): Promise<Organization[]>;
1137
+ /**
1138
+ * Get an organization by ID.
1139
+ *
1140
+ * @example
1141
+ * ```typescript
1142
+ * const org = await stackbe.organizations.get('org_123');
1143
+ * ```
1144
+ */
1145
+ get(orgId: string): Promise<Organization>;
1146
+ /**
1147
+ * Update an organization.
1148
+ *
1149
+ * @example
1150
+ * ```typescript
1151
+ * const org = await stackbe.organizations.update('org_123', {
1152
+ * name: 'New Name'
1153
+ * });
1154
+ * ```
1155
+ */
1156
+ update(orgId: string, options: UpdateOrganizationOptions): Promise<Organization>;
1157
+ /**
1158
+ * Delete an organization.
1159
+ * Note: Organizations with active subscriptions cannot be deleted.
1160
+ *
1161
+ * @example
1162
+ * ```typescript
1163
+ * await stackbe.organizations.delete('org_123');
1164
+ * ```
1165
+ */
1166
+ delete(orgId: string): Promise<void>;
1167
+ /**
1168
+ * Add a customer as a member of an organization.
1169
+ *
1170
+ * @example
1171
+ * ```typescript
1172
+ * await stackbe.organizations.addMember('org_123', {
1173
+ * customerId: 'cust_456',
1174
+ * role: 'member'
1175
+ * });
1176
+ * ```
1177
+ */
1178
+ addMember(orgId: string, options: AddMemberOptions): Promise<OrganizationMember>;
1179
+ /**
1180
+ * Remove a member from an organization.
1181
+ *
1182
+ * @example
1183
+ * ```typescript
1184
+ * await stackbe.organizations.removeMember('org_123', 'member_456');
1185
+ * ```
1186
+ */
1187
+ removeMember(orgId: string, memberId: string): Promise<void>;
1188
+ /**
1189
+ * Update a member's role.
1190
+ *
1191
+ * @example
1192
+ * ```typescript
1193
+ * await stackbe.organizations.updateMember('org_123', 'member_456', {
1194
+ * role: 'admin'
1195
+ * });
1196
+ * ```
1197
+ */
1198
+ updateMember(orgId: string, memberId: string, options: {
1199
+ role: 'admin' | 'member';
1200
+ }): Promise<OrganizationMember>;
1201
+ /**
1202
+ * Send an invite to join an organization.
1203
+ *
1204
+ * @example
1205
+ * ```typescript
1206
+ * await stackbe.organizations.invite('org_123', {
1207
+ * email: 'newuser@company.com',
1208
+ * role: 'member'
1209
+ * });
1210
+ * ```
1211
+ */
1212
+ invite(orgId: string, options: InviteMemberOptions): Promise<OrganizationInvite>;
1213
+ /**
1214
+ * List pending invites for an organization.
1215
+ *
1216
+ * @example
1217
+ * ```typescript
1218
+ * const invites = await stackbe.organizations.listInvites('org_123');
1219
+ * ```
1220
+ */
1221
+ listInvites(orgId: string): Promise<OrganizationInvite[]>;
1222
+ /**
1223
+ * Cancel a pending invite.
1224
+ *
1225
+ * @example
1226
+ * ```typescript
1227
+ * await stackbe.organizations.cancelInvite('org_123', 'invite_456');
1228
+ * ```
1229
+ */
1230
+ cancelInvite(orgId: string, inviteId: string): Promise<void>;
1231
+ }
1232
+
1052
1233
  declare class StackBE {
1053
1234
  private http;
1054
1235
  private appId;
@@ -1064,6 +1245,8 @@ declare class StackBE {
1064
1245
  readonly subscriptions: SubscriptionsClient;
1065
1246
  /** Customer authentication (magic links) */
1066
1247
  readonly auth: AuthClient;
1248
+ /** Organization management (B2B multi-user) */
1249
+ readonly organizations: OrganizationsClient;
1067
1250
  /**
1068
1251
  * Create a new StackBE client.
1069
1252
  *
@@ -1164,4 +1347,4 @@ declare class StackBE {
1164
1347
  }): (req: any, res: any, next: any) => Promise<any>;
1165
1348
  }
1166
1349
 
1167
- export { type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type Customer, type CustomerCreatedEvent, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type MagicLinkOptions, type MagicLinkResponse, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
1350
+ export { type AddMemberOptions, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type InviteMemberOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ __export(index_exports, {
24
24
  CheckoutClient: () => CheckoutClient,
25
25
  CustomersClient: () => CustomersClient,
26
26
  EntitlementsClient: () => EntitlementsClient,
27
+ OrganizationsClient: () => OrganizationsClient,
27
28
  StackBE: () => StackBE,
28
29
  StackBEError: () => StackBEError,
29
30
  SubscriptionsClient: () => SubscriptionsClient,
@@ -474,8 +475,9 @@ var EntitlementsClient = class {
474
475
 
475
476
  // src/customers.ts
476
477
  var CustomersClient = class {
477
- constructor(http) {
478
+ constructor(http, appId) {
478
479
  this.http = http;
480
+ this.appId = appId;
479
481
  }
480
482
  /**
481
483
  * Get a customer by ID.
@@ -520,7 +522,10 @@ var CustomersClient = class {
520
522
  * ```
521
523
  */
522
524
  async create(options) {
523
- return this.http.post("/v1/customers", options);
525
+ return this.http.post("/v1/customers", {
526
+ ...options,
527
+ appId: this.appId
528
+ });
524
529
  }
525
530
  /**
526
531
  * Update a customer.
@@ -1152,6 +1157,182 @@ var AuthClient = class {
1152
1157
  }
1153
1158
  };
1154
1159
 
1160
+ // src/organizations.ts
1161
+ var OrganizationsClient = class {
1162
+ constructor(http, appId) {
1163
+ this.http = http;
1164
+ this.appId = appId;
1165
+ }
1166
+ /**
1167
+ * Create a new organization with a customer as owner.
1168
+ * Use this for B2B signup flows where you provision everything server-side.
1169
+ *
1170
+ * @example
1171
+ * ```typescript
1172
+ * const customer = await stackbe.customers.getOrCreate({ email: 'user@company.com' });
1173
+ * const org = await stackbe.organizations.create({
1174
+ * name: 'Acme Corp',
1175
+ * ownerId: customer.id
1176
+ * });
1177
+ * ```
1178
+ */
1179
+ async create(options) {
1180
+ return this.http.post(
1181
+ `/v1/apps/${this.appId}/admin/organizations`,
1182
+ options
1183
+ );
1184
+ }
1185
+ /**
1186
+ * List all organizations for this app.
1187
+ *
1188
+ * @example
1189
+ * ```typescript
1190
+ * const orgs = await stackbe.organizations.list();
1191
+ * ```
1192
+ */
1193
+ async list(options) {
1194
+ const params = new URLSearchParams();
1195
+ if (options?.limit) params.set("limit", String(options.limit));
1196
+ if (options?.offset) params.set("offset", String(options.offset));
1197
+ if (options?.search) params.set("search", options.search);
1198
+ const query = params.toString();
1199
+ const path = `/v1/apps/${this.appId}/admin/organizations${query ? `?${query}` : ""}`;
1200
+ return this.http.get(path);
1201
+ }
1202
+ /**
1203
+ * Get an organization by ID.
1204
+ *
1205
+ * @example
1206
+ * ```typescript
1207
+ * const org = await stackbe.organizations.get('org_123');
1208
+ * ```
1209
+ */
1210
+ async get(orgId) {
1211
+ return this.http.get(
1212
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}`
1213
+ );
1214
+ }
1215
+ /**
1216
+ * Update an organization.
1217
+ *
1218
+ * @example
1219
+ * ```typescript
1220
+ * const org = await stackbe.organizations.update('org_123', {
1221
+ * name: 'New Name'
1222
+ * });
1223
+ * ```
1224
+ */
1225
+ async update(orgId, options) {
1226
+ return this.http.patch(
1227
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}`,
1228
+ options
1229
+ );
1230
+ }
1231
+ /**
1232
+ * Delete an organization.
1233
+ * Note: Organizations with active subscriptions cannot be deleted.
1234
+ *
1235
+ * @example
1236
+ * ```typescript
1237
+ * await stackbe.organizations.delete('org_123');
1238
+ * ```
1239
+ */
1240
+ async delete(orgId) {
1241
+ return this.http.delete(
1242
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}`
1243
+ );
1244
+ }
1245
+ /**
1246
+ * Add a customer as a member of an organization.
1247
+ *
1248
+ * @example
1249
+ * ```typescript
1250
+ * await stackbe.organizations.addMember('org_123', {
1251
+ * customerId: 'cust_456',
1252
+ * role: 'member'
1253
+ * });
1254
+ * ```
1255
+ */
1256
+ async addMember(orgId, options) {
1257
+ return this.http.post(
1258
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/members`,
1259
+ options
1260
+ );
1261
+ }
1262
+ /**
1263
+ * Remove a member from an organization.
1264
+ *
1265
+ * @example
1266
+ * ```typescript
1267
+ * await stackbe.organizations.removeMember('org_123', 'member_456');
1268
+ * ```
1269
+ */
1270
+ async removeMember(orgId, memberId) {
1271
+ return this.http.delete(
1272
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/members/${memberId}`
1273
+ );
1274
+ }
1275
+ /**
1276
+ * Update a member's role.
1277
+ *
1278
+ * @example
1279
+ * ```typescript
1280
+ * await stackbe.organizations.updateMember('org_123', 'member_456', {
1281
+ * role: 'admin'
1282
+ * });
1283
+ * ```
1284
+ */
1285
+ async updateMember(orgId, memberId, options) {
1286
+ return this.http.patch(
1287
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/members/${memberId}`,
1288
+ options
1289
+ );
1290
+ }
1291
+ /**
1292
+ * Send an invite to join an organization.
1293
+ *
1294
+ * @example
1295
+ * ```typescript
1296
+ * await stackbe.organizations.invite('org_123', {
1297
+ * email: 'newuser@company.com',
1298
+ * role: 'member'
1299
+ * });
1300
+ * ```
1301
+ */
1302
+ async invite(orgId, options) {
1303
+ return this.http.post(
1304
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/invites`,
1305
+ options
1306
+ );
1307
+ }
1308
+ /**
1309
+ * List pending invites for an organization.
1310
+ *
1311
+ * @example
1312
+ * ```typescript
1313
+ * const invites = await stackbe.organizations.listInvites('org_123');
1314
+ * ```
1315
+ */
1316
+ async listInvites(orgId) {
1317
+ return this.http.get(
1318
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/invites`
1319
+ );
1320
+ }
1321
+ /**
1322
+ * Cancel a pending invite.
1323
+ *
1324
+ * @example
1325
+ * ```typescript
1326
+ * await stackbe.organizations.cancelInvite('org_123', 'invite_456');
1327
+ * ```
1328
+ */
1329
+ async cancelInvite(orgId, inviteId) {
1330
+ return this.http.delete(
1331
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/invites/${inviteId}`
1332
+ );
1333
+ }
1334
+ };
1335
+
1155
1336
  // src/client.ts
1156
1337
  var DEFAULT_BASE_URL = "https://api.stackbe.io";
1157
1338
  var DEFAULT_TIMEOUT = 3e4;
@@ -1204,13 +1385,14 @@ var StackBE = class {
1204
1385
  });
1205
1386
  this.usage = new UsageClient(this.http);
1206
1387
  this.entitlements = new EntitlementsClient(this.http);
1207
- this.customers = new CustomersClient(this.http);
1388
+ this.customers = new CustomersClient(this.http, config.appId);
1208
1389
  this.checkout = new CheckoutClient(this.http, config.appId);
1209
1390
  this.subscriptions = new SubscriptionsClient(this.http);
1210
1391
  this.auth = new AuthClient(this.http, config.appId, {
1211
1392
  sessionCacheTTL: config.sessionCacheTTL,
1212
1393
  devCallbackUrl: config.devCallbackUrl
1213
1394
  });
1395
+ this.organizations = new OrganizationsClient(this.http, config.appId);
1214
1396
  }
1215
1397
  /**
1216
1398
  * Create a middleware for Express that tracks usage automatically.
@@ -1348,6 +1530,7 @@ var StackBE = class {
1348
1530
  CheckoutClient,
1349
1531
  CustomersClient,
1350
1532
  EntitlementsClient,
1533
+ OrganizationsClient,
1351
1534
  StackBE,
1352
1535
  StackBEError,
1353
1536
  SubscriptionsClient,
package/dist/index.mjs CHANGED
@@ -441,8 +441,9 @@ var EntitlementsClient = class {
441
441
 
442
442
  // src/customers.ts
443
443
  var CustomersClient = class {
444
- constructor(http) {
444
+ constructor(http, appId) {
445
445
  this.http = http;
446
+ this.appId = appId;
446
447
  }
447
448
  /**
448
449
  * Get a customer by ID.
@@ -487,7 +488,10 @@ var CustomersClient = class {
487
488
  * ```
488
489
  */
489
490
  async create(options) {
490
- return this.http.post("/v1/customers", options);
491
+ return this.http.post("/v1/customers", {
492
+ ...options,
493
+ appId: this.appId
494
+ });
491
495
  }
492
496
  /**
493
497
  * Update a customer.
@@ -1119,6 +1123,182 @@ var AuthClient = class {
1119
1123
  }
1120
1124
  };
1121
1125
 
1126
+ // src/organizations.ts
1127
+ var OrganizationsClient = class {
1128
+ constructor(http, appId) {
1129
+ this.http = http;
1130
+ this.appId = appId;
1131
+ }
1132
+ /**
1133
+ * Create a new organization with a customer as owner.
1134
+ * Use this for B2B signup flows where you provision everything server-side.
1135
+ *
1136
+ * @example
1137
+ * ```typescript
1138
+ * const customer = await stackbe.customers.getOrCreate({ email: 'user@company.com' });
1139
+ * const org = await stackbe.organizations.create({
1140
+ * name: 'Acme Corp',
1141
+ * ownerId: customer.id
1142
+ * });
1143
+ * ```
1144
+ */
1145
+ async create(options) {
1146
+ return this.http.post(
1147
+ `/v1/apps/${this.appId}/admin/organizations`,
1148
+ options
1149
+ );
1150
+ }
1151
+ /**
1152
+ * List all organizations for this app.
1153
+ *
1154
+ * @example
1155
+ * ```typescript
1156
+ * const orgs = await stackbe.organizations.list();
1157
+ * ```
1158
+ */
1159
+ async list(options) {
1160
+ const params = new URLSearchParams();
1161
+ if (options?.limit) params.set("limit", String(options.limit));
1162
+ if (options?.offset) params.set("offset", String(options.offset));
1163
+ if (options?.search) params.set("search", options.search);
1164
+ const query = params.toString();
1165
+ const path = `/v1/apps/${this.appId}/admin/organizations${query ? `?${query}` : ""}`;
1166
+ return this.http.get(path);
1167
+ }
1168
+ /**
1169
+ * Get an organization by ID.
1170
+ *
1171
+ * @example
1172
+ * ```typescript
1173
+ * const org = await stackbe.organizations.get('org_123');
1174
+ * ```
1175
+ */
1176
+ async get(orgId) {
1177
+ return this.http.get(
1178
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}`
1179
+ );
1180
+ }
1181
+ /**
1182
+ * Update an organization.
1183
+ *
1184
+ * @example
1185
+ * ```typescript
1186
+ * const org = await stackbe.organizations.update('org_123', {
1187
+ * name: 'New Name'
1188
+ * });
1189
+ * ```
1190
+ */
1191
+ async update(orgId, options) {
1192
+ return this.http.patch(
1193
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}`,
1194
+ options
1195
+ );
1196
+ }
1197
+ /**
1198
+ * Delete an organization.
1199
+ * Note: Organizations with active subscriptions cannot be deleted.
1200
+ *
1201
+ * @example
1202
+ * ```typescript
1203
+ * await stackbe.organizations.delete('org_123');
1204
+ * ```
1205
+ */
1206
+ async delete(orgId) {
1207
+ return this.http.delete(
1208
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}`
1209
+ );
1210
+ }
1211
+ /**
1212
+ * Add a customer as a member of an organization.
1213
+ *
1214
+ * @example
1215
+ * ```typescript
1216
+ * await stackbe.organizations.addMember('org_123', {
1217
+ * customerId: 'cust_456',
1218
+ * role: 'member'
1219
+ * });
1220
+ * ```
1221
+ */
1222
+ async addMember(orgId, options) {
1223
+ return this.http.post(
1224
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/members`,
1225
+ options
1226
+ );
1227
+ }
1228
+ /**
1229
+ * Remove a member from an organization.
1230
+ *
1231
+ * @example
1232
+ * ```typescript
1233
+ * await stackbe.organizations.removeMember('org_123', 'member_456');
1234
+ * ```
1235
+ */
1236
+ async removeMember(orgId, memberId) {
1237
+ return this.http.delete(
1238
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/members/${memberId}`
1239
+ );
1240
+ }
1241
+ /**
1242
+ * Update a member's role.
1243
+ *
1244
+ * @example
1245
+ * ```typescript
1246
+ * await stackbe.organizations.updateMember('org_123', 'member_456', {
1247
+ * role: 'admin'
1248
+ * });
1249
+ * ```
1250
+ */
1251
+ async updateMember(orgId, memberId, options) {
1252
+ return this.http.patch(
1253
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/members/${memberId}`,
1254
+ options
1255
+ );
1256
+ }
1257
+ /**
1258
+ * Send an invite to join an organization.
1259
+ *
1260
+ * @example
1261
+ * ```typescript
1262
+ * await stackbe.organizations.invite('org_123', {
1263
+ * email: 'newuser@company.com',
1264
+ * role: 'member'
1265
+ * });
1266
+ * ```
1267
+ */
1268
+ async invite(orgId, options) {
1269
+ return this.http.post(
1270
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/invites`,
1271
+ options
1272
+ );
1273
+ }
1274
+ /**
1275
+ * List pending invites for an organization.
1276
+ *
1277
+ * @example
1278
+ * ```typescript
1279
+ * const invites = await stackbe.organizations.listInvites('org_123');
1280
+ * ```
1281
+ */
1282
+ async listInvites(orgId) {
1283
+ return this.http.get(
1284
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/invites`
1285
+ );
1286
+ }
1287
+ /**
1288
+ * Cancel a pending invite.
1289
+ *
1290
+ * @example
1291
+ * ```typescript
1292
+ * await stackbe.organizations.cancelInvite('org_123', 'invite_456');
1293
+ * ```
1294
+ */
1295
+ async cancelInvite(orgId, inviteId) {
1296
+ return this.http.delete(
1297
+ `/v1/apps/${this.appId}/admin/organizations/${orgId}/invites/${inviteId}`
1298
+ );
1299
+ }
1300
+ };
1301
+
1122
1302
  // src/client.ts
1123
1303
  var DEFAULT_BASE_URL = "https://api.stackbe.io";
1124
1304
  var DEFAULT_TIMEOUT = 3e4;
@@ -1171,13 +1351,14 @@ var StackBE = class {
1171
1351
  });
1172
1352
  this.usage = new UsageClient(this.http);
1173
1353
  this.entitlements = new EntitlementsClient(this.http);
1174
- this.customers = new CustomersClient(this.http);
1354
+ this.customers = new CustomersClient(this.http, config.appId);
1175
1355
  this.checkout = new CheckoutClient(this.http, config.appId);
1176
1356
  this.subscriptions = new SubscriptionsClient(this.http);
1177
1357
  this.auth = new AuthClient(this.http, config.appId, {
1178
1358
  sessionCacheTTL: config.sessionCacheTTL,
1179
1359
  devCallbackUrl: config.devCallbackUrl
1180
1360
  });
1361
+ this.organizations = new OrganizationsClient(this.http, config.appId);
1181
1362
  }
1182
1363
  /**
1183
1364
  * Create a middleware for Express that tracks usage automatically.
@@ -1314,6 +1495,7 @@ export {
1314
1495
  CheckoutClient,
1315
1496
  CustomersClient,
1316
1497
  EntitlementsClient,
1498
+ OrganizationsClient,
1317
1499
  StackBE,
1318
1500
  StackBEError,
1319
1501
  SubscriptionsClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbe/sdk",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Official JavaScript/TypeScript SDK for StackBE - the billing backend for your side project",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",