@stackbe/sdk 0.6.3 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -0
- package/dist/index.d.mts +332 -1
- package/dist/index.d.ts +332 -1
- package/dist/index.js +288 -0
- package/dist/index.mjs +285 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1123,6 +1123,285 @@ var AuthClient = class {
|
|
|
1123
1123
|
}
|
|
1124
1124
|
};
|
|
1125
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
|
+
|
|
1302
|
+
// src/plans.ts
|
|
1303
|
+
var PlansClient = class {
|
|
1304
|
+
constructor(http) {
|
|
1305
|
+
this.http = http;
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* List all plans for the app.
|
|
1309
|
+
*
|
|
1310
|
+
* @example
|
|
1311
|
+
* ```typescript
|
|
1312
|
+
* // List all plans
|
|
1313
|
+
* const plans = await stackbe.plans.list();
|
|
1314
|
+
*
|
|
1315
|
+
* // Filter by product
|
|
1316
|
+
* const plans = await stackbe.plans.list({ productId: 'prod_123' });
|
|
1317
|
+
*
|
|
1318
|
+
* // Display in pricing page
|
|
1319
|
+
* plans.forEach(plan => {
|
|
1320
|
+
* console.log(`${plan.name}: $${plan.priceCents / 100}/${plan.interval}`);
|
|
1321
|
+
* });
|
|
1322
|
+
* ```
|
|
1323
|
+
*/
|
|
1324
|
+
async list(options) {
|
|
1325
|
+
const params = new URLSearchParams();
|
|
1326
|
+
if (options?.productId) {
|
|
1327
|
+
params.set("productId", options.productId);
|
|
1328
|
+
}
|
|
1329
|
+
const query = params.toString();
|
|
1330
|
+
return this.http.get(`/v1/plans${query ? `?${query}` : ""}`);
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Get a plan by ID.
|
|
1334
|
+
*
|
|
1335
|
+
* @example
|
|
1336
|
+
* ```typescript
|
|
1337
|
+
* const plan = await stackbe.plans.get('plan_123');
|
|
1338
|
+
* console.log(plan.name, plan.priceCents, plan.entitlements);
|
|
1339
|
+
* ```
|
|
1340
|
+
*/
|
|
1341
|
+
async get(planId) {
|
|
1342
|
+
return this.http.get(`/v1/plans/${planId}`);
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Get active plans only (excludes archived plans).
|
|
1346
|
+
*
|
|
1347
|
+
* @example
|
|
1348
|
+
* ```typescript
|
|
1349
|
+
* const activePlans = await stackbe.plans.getActive();
|
|
1350
|
+
* ```
|
|
1351
|
+
*/
|
|
1352
|
+
async getActive(options) {
|
|
1353
|
+
const plans = await this.list(options);
|
|
1354
|
+
return plans.filter((p) => p.status === "active");
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Get plans sorted by price (ascending).
|
|
1358
|
+
*
|
|
1359
|
+
* @example
|
|
1360
|
+
* ```typescript
|
|
1361
|
+
* const plans = await stackbe.plans.listByPrice();
|
|
1362
|
+
* // [Free, Starter, Pro, Enterprise]
|
|
1363
|
+
* ```
|
|
1364
|
+
*/
|
|
1365
|
+
async listByPrice(options) {
|
|
1366
|
+
const plans = await this.getActive(options);
|
|
1367
|
+
return plans.sort((a, b) => a.priceCents - b.priceCents);
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
var ProductsClient = class {
|
|
1371
|
+
constructor(http, appId) {
|
|
1372
|
+
this.http = http;
|
|
1373
|
+
this.appId = appId;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* List all products for the app.
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1379
|
+
* ```typescript
|
|
1380
|
+
* const products = await stackbe.products.list();
|
|
1381
|
+
* products.forEach(product => {
|
|
1382
|
+
* console.log(product.name, product.plans?.length, 'plans');
|
|
1383
|
+
* });
|
|
1384
|
+
* ```
|
|
1385
|
+
*/
|
|
1386
|
+
async list(options) {
|
|
1387
|
+
const params = new URLSearchParams();
|
|
1388
|
+
params.set("appId", options?.appId ?? this.appId);
|
|
1389
|
+
return this.http.get(`/v1/products?${params.toString()}`);
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Get a product by ID.
|
|
1393
|
+
*
|
|
1394
|
+
* @example
|
|
1395
|
+
* ```typescript
|
|
1396
|
+
* const product = await stackbe.products.get('prod_123');
|
|
1397
|
+
* console.log(product.name, product.description);
|
|
1398
|
+
* ```
|
|
1399
|
+
*/
|
|
1400
|
+
async get(productId) {
|
|
1401
|
+
return this.http.get(`/v1/products/${productId}`);
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1126
1405
|
// src/client.ts
|
|
1127
1406
|
var DEFAULT_BASE_URL = "https://api.stackbe.io";
|
|
1128
1407
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -1182,6 +1461,9 @@ var StackBE = class {
|
|
|
1182
1461
|
sessionCacheTTL: config.sessionCacheTTL,
|
|
1183
1462
|
devCallbackUrl: config.devCallbackUrl
|
|
1184
1463
|
});
|
|
1464
|
+
this.organizations = new OrganizationsClient(this.http, config.appId);
|
|
1465
|
+
this.plans = new PlansClient(this.http);
|
|
1466
|
+
this.products = new ProductsClient(this.http, config.appId);
|
|
1185
1467
|
}
|
|
1186
1468
|
/**
|
|
1187
1469
|
* Create a middleware for Express that tracks usage automatically.
|
|
@@ -1318,6 +1600,9 @@ export {
|
|
|
1318
1600
|
CheckoutClient,
|
|
1319
1601
|
CustomersClient,
|
|
1320
1602
|
EntitlementsClient,
|
|
1603
|
+
OrganizationsClient,
|
|
1604
|
+
PlansClient,
|
|
1605
|
+
ProductsClient,
|
|
1321
1606
|
StackBE,
|
|
1322
1607
|
StackBEError,
|
|
1323
1608
|
SubscriptionsClient,
|
package/package.json
CHANGED