@chatarmin/os 1.5.9 → 1.8.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/README.md +417 -8
- package/dist/billing/client.d.ts +8 -0
- package/dist/billing/client.d.ts.map +1 -0
- package/dist/billing/client.js +46 -0
- package/dist/billing/index.d.ts +3 -0
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/index.js +1 -0
- package/dist/billing/types.d.ts +201 -0
- package/dist/billing/types.d.ts.map +1 -0
- package/dist/billing/usage-breakdown-types.d.ts +132 -0
- package/dist/billing/usage-breakdown-types.d.ts.map +1 -0
- package/dist/companies/client.d.ts +1 -1
- package/dist/companies/client.d.ts.map +1 -1
- package/dist/features/client.d.ts +8 -0
- package/dist/features/client.d.ts.map +1 -0
- package/dist/features/client.js +18 -0
- package/dist/features/index.d.ts +3 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +1 -0
- package/dist/features/types.d.ts +184 -0
- package/dist/features/types.d.ts.map +1 -0
- package/dist/index.d.ts +29 -760
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -361
- package/dist/webhooks/constants.d.ts +5 -0
- package/dist/webhooks/constants.d.ts.map +1 -0
- package/dist/webhooks/constants.js +4 -0
- package/dist/webhooks/construct-event.d.ts +3 -0
- package/dist/webhooks/construct-event.d.ts.map +1 -0
- package/dist/webhooks/construct-event.js +64 -0
- package/dist/webhooks/errors.d.ts +4 -0
- package/dist/webhooks/errors.d.ts.map +1 -0
- package/dist/webhooks/errors.js +6 -0
- package/dist/webhooks/generate-test-headers.d.ts +3 -0
- package/dist/webhooks/generate-test-headers.d.ts.map +1 -0
- package/dist/webhooks/generate-test-headers.js +11 -0
- package/dist/webhooks/index.d.ts +33 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +31 -0
- package/dist/webhooks/read-header.d.ts +3 -0
- package/dist/webhooks/read-header.d.ts.map +1 -0
- package/dist/webhooks/read-header.js +16 -0
- package/dist/webhooks/signing.d.ts +4 -0
- package/dist/webhooks/signing.d.ts.map +1 -0
- package/dist/webhooks/signing.js +16 -0
- package/dist/webhooks/types.d.ts +30 -0
- package/dist/webhooks/types.d.ts.map +1 -0
- package/package.json +7 -1
- package/dist/billing-get-dashboard-context.d.ts +0 -16
- package/dist/billing-get-dashboard-context.d.ts.map +0 -1
- package/dist/billing-get-dashboard-context.js +0 -7
- package/dist/chatarmin-os-billing-namespace.d.ts +0 -122
- package/dist/chatarmin-os-billing-namespace.d.ts.map +0 -1
- package/dist/chatarmin-os-billing-namespace.js +0 -24
- package/dist/features-list-for-product.d.ts +0 -26
- package/dist/features-list-for-product.d.ts.map +0 -1
- package/dist/features-list-for-product.js +0 -17
- package/dist/types/billing-dashboard-context.d.ts +0 -33
- package/dist/types/billing-dashboard-context.d.ts.map +0 -1
- package/dist/types/chatarmin-os-billing-inputs.d.ts +0 -90
- package/dist/types/chatarmin-os-billing-inputs.d.ts.map +0 -1
- package/dist/types/feature-access-list-item.d.ts +0 -7
- package/dist/types/feature-access-list-item.d.ts.map +0 -1
- package/dist/types/product-feature-catalog.d.ts +0 -24
- package/dist/types/product-feature-catalog.d.ts.map +0 -1
- /package/dist/{types/billing-dashboard-context.js → billing/types.js} +0 -0
- /package/dist/{types/chatarmin-os-billing-inputs.js → billing/usage-breakdown-types.js} +0 -0
- /package/dist/{types/feature-access-list-item.js → features/types.js} +0 -0
- /package/dist/{types/product-feature-catalog.js → webhooks/types.js} +0 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAG1D,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A;AAGzB,eAAe,WAAW,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { TRPCClientError, createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
2
2
|
import superjson from "superjson";
|
|
3
3
|
import { createCompaniesClient, } from "./companies";
|
|
4
|
+
import { createBillingClient } from "./billing";
|
|
5
|
+
import { createFeaturesClient } from "./features";
|
|
6
|
+
import { webhooks } from "./webhooks";
|
|
7
|
+
export { webhooks, constructProductWebhookEvent, generateTestWebhookHeaders, OsWebhookSignatureVerificationError, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from "./webhooks";
|
|
4
8
|
const INSPECT_SYMBOL = Symbol.for("nodejs.util.inspect.custom");
|
|
5
9
|
export class ChatarminOSError extends Error {
|
|
6
10
|
details;
|
|
@@ -117,6 +121,7 @@ function toChatarminOSError(operation, error) {
|
|
|
117
121
|
* @see https://os.chatarmin.com/docs for full documentation
|
|
118
122
|
*/
|
|
119
123
|
export class ChatarminOS {
|
|
124
|
+
static webhooks = webhooks;
|
|
120
125
|
client;
|
|
121
126
|
async call(operation, action) {
|
|
122
127
|
try {
|
|
@@ -322,372 +327,14 @@ export class ChatarminOS {
|
|
|
322
327
|
* ```
|
|
323
328
|
*/
|
|
324
329
|
get features() {
|
|
325
|
-
|
|
326
|
-
const call = this.call.bind(this);
|
|
327
|
-
return {
|
|
328
|
-
/**
|
|
329
|
-
* Check if a company has access to a specific feature.
|
|
330
|
-
*
|
|
331
|
-
* Returns detailed access information including whether the feature
|
|
332
|
-
* is enabled, current usage, limits, and whether they can use more.
|
|
333
|
-
*
|
|
334
|
-
* @param input - Check parameters
|
|
335
|
-
* @param input.companyId - Company ID to check
|
|
336
|
-
* @param input.featureCode - Feature code (e.g., "ai_credit")
|
|
337
|
-
* @returns Detailed feature access information
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```typescript
|
|
341
|
-
* const access = await os.features.check({
|
|
342
|
-
* companyId: 'comp_xxx',
|
|
343
|
-
* featureCode: 'ai_credit'
|
|
344
|
-
* })
|
|
345
|
-
*
|
|
346
|
-
* console.log({
|
|
347
|
-
* enabled: access.isEnabled,
|
|
348
|
-
* canUse: access.canUse,
|
|
349
|
-
* usage: access.currentUsage,
|
|
350
|
-
* limit: access.quantityLimit,
|
|
351
|
-
* remaining: access.remaining,
|
|
352
|
-
* included: access.includedQuantity
|
|
353
|
-
* })
|
|
354
|
-
* ```
|
|
355
|
-
*/
|
|
356
|
-
check: (input) => call("features.check", () => client.features.check.query(input)),
|
|
357
|
-
/**
|
|
358
|
-
* List all features and their access status for a company.
|
|
359
|
-
*
|
|
360
|
-
* Returns a complete list of features with their current status,
|
|
361
|
-
* useful for displaying a company's full feature set or building
|
|
362
|
-
* a feature comparison view.
|
|
363
|
-
*
|
|
364
|
-
* @param input - Query parameters
|
|
365
|
-
* @returns Array of feature access records
|
|
366
|
-
*
|
|
367
|
-
* @example Basic usage
|
|
368
|
-
* ```typescript
|
|
369
|
-
* const features = await os.features.listAccess({ companyId: company.id })
|
|
370
|
-
*
|
|
371
|
-
* for (const f of features) {
|
|
372
|
-
* console.log(`${f.featureName}: ${f.isEnabled ? '✓' : '✗'}`)
|
|
373
|
-
* if (f.quantityLimit) {
|
|
374
|
-
* console.log(` Usage: ${f.currentUsage} / ${f.quantityLimit}`)
|
|
375
|
-
* }
|
|
376
|
-
* }
|
|
377
|
-
* ```
|
|
378
|
-
*
|
|
379
|
-
* @example With billing details
|
|
380
|
-
* ```typescript
|
|
381
|
-
* const features = await os.features.listAccess({
|
|
382
|
-
* companyId: company.id,
|
|
383
|
-
* includeBillingDetails: true
|
|
384
|
-
* })
|
|
385
|
-
*
|
|
386
|
-
* for (const f of features) {
|
|
387
|
-
* console.log(`${f.featureName}:`)
|
|
388
|
-
* console.log(` Usage: ${f.currentUsage} / ${f.quantityLimit}`)
|
|
389
|
-
*
|
|
390
|
-
* if (f.billing) {
|
|
391
|
-
* console.log(` Price: ${f.billing.unitAmount / 100} ${f.billing.currency}`)
|
|
392
|
-
* console.log(` Period: ${f.billing.currentPeriodStart} to ${f.billing.currentPeriodEnd}`)
|
|
393
|
-
* console.log(` Status: ${f.billing.subscriptionStatus}`)
|
|
394
|
-
* }
|
|
395
|
-
* }
|
|
396
|
-
* ```
|
|
397
|
-
*/
|
|
398
|
-
listAccess: (input) => call("features.listAccess", () => {
|
|
399
|
-
// Support legacy companyId string param for backward compatibility
|
|
400
|
-
const params = typeof input === "string" ? { companyId: input } : input;
|
|
401
|
-
return client.features.getAccess.query(params);
|
|
402
|
-
}),
|
|
403
|
-
/**
|
|
404
|
-
* Update feature access for a company with partial config merge.
|
|
405
|
-
*
|
|
406
|
-
* This allows you to update individual feature configs without
|
|
407
|
-
* replacing all config values. Only the fields you specify in
|
|
408
|
-
* `config` will be updated - other fields remain unchanged.
|
|
409
|
-
*
|
|
410
|
-
* @param input - Update parameters
|
|
411
|
-
* @returns Updated feature access information
|
|
412
|
-
*
|
|
413
|
-
* @example Update by company ID
|
|
414
|
-
* ```typescript
|
|
415
|
-
* await os.features.setAccess({
|
|
416
|
-
* companyId: 'comp_xxx',
|
|
417
|
-
* featureCode: 'ai_credit',
|
|
418
|
-
* isEnabled: true,
|
|
419
|
-
* config: {
|
|
420
|
-
* included_quantity: 500,
|
|
421
|
-
* max_quantity: 1000
|
|
422
|
-
* }
|
|
423
|
-
* })
|
|
424
|
-
* ```
|
|
425
|
-
*
|
|
426
|
-
* @example Update by your product's external org ID
|
|
427
|
-
* ```typescript
|
|
428
|
-
* await os.features.setAccess({
|
|
429
|
-
* externalOrgId: 'org_abc123',
|
|
430
|
-
* featureCode: 'ai_credit',
|
|
431
|
-
* config: { tier_level: 'premium' }
|
|
432
|
-
* })
|
|
433
|
-
* ```
|
|
434
|
-
*
|
|
435
|
-
* @example Partial config update (only updates specified fields)
|
|
436
|
-
* ```typescript
|
|
437
|
-
* // Existing config: { tier_level: 'basic', max_seats: 5 }
|
|
438
|
-
* await os.features.setAccess({
|
|
439
|
-
* companyId: 'comp_xxx',
|
|
440
|
-
* featureCode: 'team_seats',
|
|
441
|
-
* config: { max_seats: 10 } // tier_level remains 'basic'
|
|
442
|
-
* })
|
|
443
|
-
* // New config: { tier_level: 'basic', max_seats: 10 }
|
|
444
|
-
* ```
|
|
445
|
-
*/
|
|
446
|
-
setAccess: (input) => call("features.setAccess", () => client.features.updateAccess.mutate(input)),
|
|
447
|
-
/**
|
|
448
|
-
* Get all feature access using your product's external org ID.
|
|
449
|
-
*
|
|
450
|
-
* Convenience method when you know the external org ID but not
|
|
451
|
-
* the ChatarminOS company ID.
|
|
452
|
-
*
|
|
453
|
-
* @param externalOrgId - Your product's organization ID
|
|
454
|
-
* @returns All features with their access status and config values
|
|
455
|
-
*
|
|
456
|
-
* @example
|
|
457
|
-
* ```typescript
|
|
458
|
-
* const result = await os.features.getAccessByExternalOrgId('org_abc123')
|
|
459
|
-
*
|
|
460
|
-
* console.log(`Company: ${result.companyId}`)
|
|
461
|
-
* for (const f of result.features) {
|
|
462
|
-
* console.log(`${f.featureCode}: ${f.isEnabled}`)
|
|
463
|
-
* console.log(` Config:`, f.configValues)
|
|
464
|
-
* }
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
getAccessByExternalOrgId: (externalOrgId) => call("features.getAccessByExternalOrgId", () => client.features.getAccessByExternalOrgId.query({ externalOrgId })),
|
|
468
|
-
/**
|
|
469
|
-
* Check specific feature access using your product's external org ID.
|
|
470
|
-
*
|
|
471
|
-
* @param externalOrgId - Your product's organization ID
|
|
472
|
-
* @param featureCode - Feature code to check
|
|
473
|
-
* @returns Detailed feature access including config values
|
|
474
|
-
*
|
|
475
|
-
* @example
|
|
476
|
-
* ```typescript
|
|
477
|
-
* const access = await os.features.checkByExternalOrgId(
|
|
478
|
-
* 'org_abc123',
|
|
479
|
-
* 'ai_credit'
|
|
480
|
-
* )
|
|
481
|
-
*
|
|
482
|
-
* if (access.canUse) {
|
|
483
|
-
* console.log(`Remaining: ${access.remaining}`)
|
|
484
|
-
* console.log(`Config:`, access.configValues)
|
|
485
|
-
* }
|
|
486
|
-
* ```
|
|
487
|
-
*/
|
|
488
|
-
checkByExternalOrgId: (externalOrgId, featureCode) => call("features.checkByExternalOrgId", () => client.features.checkByExternalOrgId.query({
|
|
489
|
-
externalOrgId,
|
|
490
|
-
featureCode,
|
|
491
|
-
})),
|
|
492
|
-
};
|
|
330
|
+
return createFeaturesClient(this.client, this.call.bind(this));
|
|
493
331
|
}
|
|
494
332
|
// ==========================================================================
|
|
495
333
|
// Billing
|
|
496
334
|
// ==========================================================================
|
|
497
|
-
/**
|
|
498
|
-
* Billing, usage tracking, and subscription management.
|
|
499
|
-
*
|
|
500
|
-
* Set feature usage for billing, claim subscriptions from Stripe checkout,
|
|
501
|
-
* or link existing Stripe subscriptions to companies.
|
|
502
|
-
*
|
|
503
|
-
* @example Set Usage
|
|
504
|
-
* ```typescript
|
|
505
|
-
* await os.billing.setUsage({
|
|
506
|
-
* companyId: company.id,
|
|
507
|
-
* featureCode: 'ai_credit',
|
|
508
|
-
* absoluteValue: 42,
|
|
509
|
-
* reason: 'Synced current usage'
|
|
510
|
-
* })
|
|
511
|
-
* ```
|
|
512
|
-
*
|
|
513
|
-
* @example Claim Checkout Subscription
|
|
514
|
-
* ```typescript
|
|
515
|
-
* // After Stripe checkout completes
|
|
516
|
-
* const result = await os.billing.claimCheckout({
|
|
517
|
-
* companyId: company.id,
|
|
518
|
-
* checkoutSessionId: 'cs_xxx'
|
|
519
|
-
* })
|
|
520
|
-
* ```
|
|
521
|
-
*
|
|
522
|
-
* @example Link Existing Subscription
|
|
523
|
-
* ```typescript
|
|
524
|
-
* // When you create subscriptions on your Stripe account
|
|
525
|
-
* const result = await os.billing.linkSubscription({
|
|
526
|
-
* companyId: company.id,
|
|
527
|
-
* stripeSubscriptionId: 'sub_xxx',
|
|
528
|
-
* tierCode: 'pro' // Apply tier features
|
|
529
|
-
* })
|
|
530
|
-
* ```
|
|
531
|
-
*/
|
|
335
|
+
/** Billing, usage tracking, subscriptions, and customer billing surfaces. */
|
|
532
336
|
get billing() {
|
|
533
|
-
|
|
534
|
-
const call = this.call.bind(this);
|
|
535
|
-
return {
|
|
536
|
-
/**
|
|
537
|
-
* Set usage to an absolute value.
|
|
538
|
-
*
|
|
539
|
-
* Use this for corrections when you know what the total usage SHOULD be.
|
|
540
|
-
* Creates a snapshot for audit trail. The delta (difference) is calculated
|
|
541
|
-
* automatically and synced to Stripe.
|
|
542
|
-
*
|
|
543
|
-
* @param input - Set usage parameters
|
|
544
|
-
* @returns Result with previous and new usage values
|
|
545
|
-
*
|
|
546
|
-
* @example Correct usage to 100 (was 150)
|
|
547
|
-
* ```typescript
|
|
548
|
-
* const result = await os.billing.setUsage({
|
|
549
|
-
* companyId: 'comp_xxx',
|
|
550
|
-
* featureCode: 'ai_credit',
|
|
551
|
-
* absoluteValue: 100,
|
|
552
|
-
* reason: 'Corrected after customer support review',
|
|
553
|
-
* performedBy: 'admin@company.com'
|
|
554
|
-
* })
|
|
555
|
-
*
|
|
556
|
-
* console.log({
|
|
557
|
-
* previousUsage: result.previousUsage, // 150
|
|
558
|
-
* currentUsage: result.currentUsage, // 100
|
|
559
|
-
* delta: result.delta // -50
|
|
560
|
-
* })
|
|
561
|
-
* ```
|
|
562
|
-
*/
|
|
563
|
-
setUsage: (input) => call("billing.setUsage", () => client.billing.setUsage.mutate({
|
|
564
|
-
...input,
|
|
565
|
-
source: "api",
|
|
566
|
-
})),
|
|
567
|
-
/**
|
|
568
|
-
* Get usage event history for a feature.
|
|
569
|
-
*
|
|
570
|
-
* Returns the history of usage events including increments, sets,
|
|
571
|
-
* and adjustments. Useful for auditing and debugging.
|
|
572
|
-
*
|
|
573
|
-
* @param companyId - Company ID
|
|
574
|
-
* @param featureCode - Feature code to get history for
|
|
575
|
-
* @param options - Query options
|
|
576
|
-
* @returns Array of usage events
|
|
577
|
-
*
|
|
578
|
-
* @example
|
|
579
|
-
* ```typescript
|
|
580
|
-
* const history = await os.billing.getUsageHistory(
|
|
581
|
-
* 'comp_xxx',
|
|
582
|
-
* 'ai_credit',
|
|
583
|
-
* { limit: 20, eventType: 'adjustment' }
|
|
584
|
-
* )
|
|
585
|
-
*
|
|
586
|
-
* for (const event of history) {
|
|
587
|
-
* console.log(`${event.event_type}: ${event.quantity} at ${event.event_time}`)
|
|
588
|
-
* if (event.adjustment_reason) {
|
|
589
|
-
* console.log(` Reason: ${event.adjustment_reason}`)
|
|
590
|
-
* }
|
|
591
|
-
* }
|
|
592
|
-
* ```
|
|
593
|
-
*/
|
|
594
|
-
getUsageHistory: (companyId, featureCode, options) => call("billing.getUsageHistory", () => client.billing.getUsageHistory.query({
|
|
595
|
-
companyId,
|
|
596
|
-
featureCode,
|
|
597
|
-
...options,
|
|
598
|
-
})),
|
|
599
|
-
/**
|
|
600
|
-
* Claim a subscription from a completed Stripe Checkout Session.
|
|
601
|
-
*
|
|
602
|
-
* Use this after a user completes Stripe checkout in your product.
|
|
603
|
-
* This links the subscription and customer to the company in OS.
|
|
604
|
-
*
|
|
605
|
-
* @param input - Claim parameters
|
|
606
|
-
* @returns Result with subscription ID and claim status
|
|
607
|
-
*
|
|
608
|
-
* @example
|
|
609
|
-
* ```typescript
|
|
610
|
-
* // In your Stripe checkout success handler:
|
|
611
|
-
* const result = await os.billing.claimCheckout({
|
|
612
|
-
* companyId: company.id,
|
|
613
|
-
* checkoutSessionId: session.id // From Stripe callback
|
|
614
|
-
* })
|
|
615
|
-
*
|
|
616
|
-
* if (result.alreadyClaimed) {
|
|
617
|
-
* console.log('Subscription was already claimed')
|
|
618
|
-
* } else {
|
|
619
|
-
* console.log(`Claimed subscription: ${result.subscriptionId}`)
|
|
620
|
-
* }
|
|
621
|
-
* ```
|
|
622
|
-
*/
|
|
623
|
-
claimCheckout: (input) => call("billing.claimCheckout", () => client.billing.claimCheckout.mutate(input)),
|
|
624
|
-
/**
|
|
625
|
-
* Link an existing Stripe subscription to a company.
|
|
626
|
-
*
|
|
627
|
-
* Use this when you create subscriptions on your product's Stripe
|
|
628
|
-
* account and want OS to track them. Optionally applies tier features.
|
|
629
|
-
*
|
|
630
|
-
* @param input - Link parameters
|
|
631
|
-
* @returns Result with subscription ID, link status, and features applied
|
|
632
|
-
*
|
|
633
|
-
* @example
|
|
634
|
-
* ```typescript
|
|
635
|
-
* // After creating subscription on your Stripe account:
|
|
636
|
-
* const result = await os.billing.linkSubscription({
|
|
637
|
-
* companyId: company.id,
|
|
638
|
-
* stripeSubscriptionId: 'sub_xxx',
|
|
639
|
-
* stripeCustomerId: 'cus_xxx', // Optional
|
|
640
|
-
* tierCode: 'pro', // Apply tier features
|
|
641
|
-
* displayName: 'Pro Plan'
|
|
642
|
-
* })
|
|
643
|
-
*
|
|
644
|
-
* console.log({
|
|
645
|
-
* subscriptionId: result.subscriptionId,
|
|
646
|
-
* isNew: !result.alreadyLinked,
|
|
647
|
-
* featuresApplied: result.featuresApplied
|
|
648
|
-
* })
|
|
649
|
-
* ```
|
|
650
|
-
*/
|
|
651
|
-
linkSubscription: (input) => call("billing.linkSubscription", () => client.billing.linkSubscription.mutate(input)),
|
|
652
|
-
/**
|
|
653
|
-
* Get billing status for a company.
|
|
654
|
-
*
|
|
655
|
-
* Quick check for subscription status, active features, and
|
|
656
|
-
* billing profile information.
|
|
657
|
-
*
|
|
658
|
-
* @param companyId - Company ID to check
|
|
659
|
-
* @returns Billing status overview
|
|
660
|
-
*
|
|
661
|
-
* @example
|
|
662
|
-
* ```typescript
|
|
663
|
-
* const status = await os.billing.getStatus(company.id)
|
|
664
|
-
*
|
|
665
|
-
* console.log({
|
|
666
|
-
* hasBilling: status.hasBillingProfile,
|
|
667
|
-
* subscriptions: status.activeSubscriptions.length,
|
|
668
|
-
* features: status.enabledFeaturesCount
|
|
669
|
-
* })
|
|
670
|
-
*
|
|
671
|
-
* // Check active tier
|
|
672
|
-
* if (status.activeSubscriptions[0]?.tier) {
|
|
673
|
-
* console.log(`Current tier: ${status.activeSubscriptions[0].tier.name}`)
|
|
674
|
-
* }
|
|
675
|
-
* ```
|
|
676
|
-
*/
|
|
677
|
-
getStatus: (companyId) => call("billing.getStatus", () => client.billing.getStatus.query({ companyId })),
|
|
678
|
-
/**
|
|
679
|
-
* Sync billing profile, subscriptions, and feature access from Stripe.
|
|
680
|
-
*/
|
|
681
|
-
syncCompanyFromStripe: (input) => call("billing.syncCompanyFromStripe", () => client.billing.syncCompanyFromStripe.mutate(input)),
|
|
682
|
-
/**
|
|
683
|
-
* Relink billing profile to a new Stripe customer (destructive).
|
|
684
|
-
*/
|
|
685
|
-
relinkBillingProfile: (input) => call("billing.relinkBillingProfile", () => client.billing.relinkBillingProfile.mutate(input)),
|
|
686
|
-
/**
|
|
687
|
-
* Ensure a feature is linked to an active Stripe subscription item.
|
|
688
|
-
*/
|
|
689
|
-
ensureFeatureSubscription: (input) => call("billing.ensureFeatureSubscription", () => client.billing.ensureFeatureSubscription.mutate(input)),
|
|
690
|
-
};
|
|
337
|
+
return createBillingClient(this.client, this.call.bind(this));
|
|
691
338
|
}
|
|
692
339
|
// ==========================================================================
|
|
693
340
|
// Links
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const WEBHOOK_SIGNATURE_HEADER = "X-OS-Webhook-Signature";
|
|
2
|
+
export declare const WEBHOOK_TIMESTAMP_HEADER = "X-OS-Webhook-Timestamp";
|
|
3
|
+
export declare const WEBHOOK_ID_HEADER = "X-OS-Webhook-Id";
|
|
4
|
+
export declare const DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
|
|
5
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/webhooks/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,2BAA2B,CAAA;AAChE,eAAO,MAAM,wBAAwB,2BAA2B,CAAA;AAChE,eAAO,MAAM,iBAAiB,oBAAoB,CAAA;AAElD,eAAO,MAAM,iCAAiC,MAAM,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ConstructProductWebhookEventOptions, ProductWebhookHeaders, VerifiedProductWebhookEvent } from './types';
|
|
2
|
+
export declare function constructProductWebhookEvent(rawBody: string, headers: ProductWebhookHeaders, secret: string, options?: ConstructProductWebhookEventOptions): VerifiedProductWebhookEvent;
|
|
3
|
+
//# sourceMappingURL=construct-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"construct-event.d.ts","sourceRoot":"","sources":["../../src/webhooks/construct-event.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,mCAAmC,EAEnC,qBAAqB,EACrB,2BAA2B,EAC5B,MAAM,SAAS,CAAA;AA0DhB,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,mCAAmC,GAC5C,2BAA2B,CAsC7B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DEFAULT_WEBHOOK_TOLERANCE_SECONDS, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from './constants';
|
|
2
|
+
import { OsWebhookSignatureVerificationError } from './errors';
|
|
3
|
+
import { readWebhookHeader } from './read-header';
|
|
4
|
+
import { verifyWebhookSignature } from './signing';
|
|
5
|
+
function assertNonEmpty(value, message) {
|
|
6
|
+
const trimmed = value?.trim();
|
|
7
|
+
if (!trimmed) {
|
|
8
|
+
throw new OsWebhookSignatureVerificationError(message);
|
|
9
|
+
}
|
|
10
|
+
return trimmed;
|
|
11
|
+
}
|
|
12
|
+
function assertTimestampWithinTolerance(timestamp, tolerance, now) {
|
|
13
|
+
if (tolerance <= 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const timestampMs = Number(timestamp);
|
|
17
|
+
if (!Number.isFinite(timestampMs)) {
|
|
18
|
+
throw new OsWebhookSignatureVerificationError('Invalid webhook timestamp');
|
|
19
|
+
}
|
|
20
|
+
const ageSeconds = Math.abs(now.getTime() - timestampMs) / 1000;
|
|
21
|
+
if (ageSeconds > tolerance) {
|
|
22
|
+
throw new OsWebhookSignatureVerificationError('Webhook timestamp outside the tolerance window');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function parseWebhookPayload(rawBody) {
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(rawBody);
|
|
28
|
+
if (typeof parsed !== 'object' ||
|
|
29
|
+
parsed === null ||
|
|
30
|
+
typeof parsed.type !== 'string' ||
|
|
31
|
+
typeof parsed.action !== 'string' ||
|
|
32
|
+
typeof parsed.idempotency_key !== 'string' ||
|
|
33
|
+
typeof parsed.data !== 'object' ||
|
|
34
|
+
parsed.data === null) {
|
|
35
|
+
throw new OsWebhookSignatureVerificationError('Invalid webhook payload shape');
|
|
36
|
+
}
|
|
37
|
+
return parsed;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof OsWebhookSignatureVerificationError) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
throw new OsWebhookSignatureVerificationError('Invalid JSON payload');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function constructProductWebhookEvent(rawBody, headers, secret, options) {
|
|
47
|
+
const signingSecret = secret;
|
|
48
|
+
if (!signingSecret) {
|
|
49
|
+
throw new OsWebhookSignatureVerificationError('Webhook signing secret is required');
|
|
50
|
+
}
|
|
51
|
+
const signature = assertNonEmpty(readWebhookHeader(headers, WEBHOOK_SIGNATURE_HEADER), `Missing ${WEBHOOK_SIGNATURE_HEADER} header`);
|
|
52
|
+
const timestamp = assertNonEmpty(readWebhookHeader(headers, WEBHOOK_TIMESTAMP_HEADER), `Missing ${WEBHOOK_TIMESTAMP_HEADER} header`);
|
|
53
|
+
const webhookId = assertNonEmpty(readWebhookHeader(headers, WEBHOOK_ID_HEADER), `Missing ${WEBHOOK_ID_HEADER} header`);
|
|
54
|
+
assertTimestampWithinTolerance(timestamp, options?.tolerance ?? DEFAULT_WEBHOOK_TOLERANCE_SECONDS, options?.now ?? new Date());
|
|
55
|
+
if (!verifyWebhookSignature(signingSecret, timestamp, rawBody, signature)) {
|
|
56
|
+
throw new OsWebhookSignatureVerificationError('Webhook signature verification failed');
|
|
57
|
+
}
|
|
58
|
+
const event = parseWebhookPayload(rawBody);
|
|
59
|
+
return {
|
|
60
|
+
...event,
|
|
61
|
+
webhookId,
|
|
62
|
+
timestamp,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/webhooks/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,mCAAoC,SAAQ,KAAK;gBAChD,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-test-headers.d.ts","sourceRoot":"","sources":["../../src/webhooks/generate-test-headers.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAA;AAE9D,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,+BAA+B,GACrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAaxB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from './constants';
|
|
2
|
+
import { buildWebhookSignature } from './signing';
|
|
3
|
+
export function generateTestWebhookHeaders(input) {
|
|
4
|
+
const timestamp = (input.timestamp ?? Date.now()).toString();
|
|
5
|
+
const webhookId = input.webhookId ?? 'test_webhook_id';
|
|
6
|
+
return {
|
|
7
|
+
[WEBHOOK_SIGNATURE_HEADER]: buildWebhookSignature(input.secret, timestamp, input.payload),
|
|
8
|
+
[WEBHOOK_TIMESTAMP_HEADER]: timestamp,
|
|
9
|
+
[WEBHOOK_ID_HEADER]: webhookId,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { constructProductWebhookEvent } from './construct-event';
|
|
2
|
+
import { generateTestWebhookHeaders } from './generate-test-headers';
|
|
3
|
+
export { DEFAULT_WEBHOOK_TOLERANCE_SECONDS, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from './constants';
|
|
4
|
+
export { constructProductWebhookEvent } from './construct-event';
|
|
5
|
+
export { OsWebhookSignatureVerificationError } from './errors';
|
|
6
|
+
export { generateTestWebhookHeaders } from './generate-test-headers';
|
|
7
|
+
export { buildWebhookSignature, buildWebhookSignatureMaterial, verifyWebhookSignature, } from './signing';
|
|
8
|
+
export type { ConstructProductWebhookEventOptions, GenerateTestWebhookHeadersInput, ProductWebhookEventPayload, ProductWebhookHeaders, VerifiedProductWebhookEvent, } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Verify inbound OS product webhooks.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { webhooks } from '@chatarmin/os/webhooks'
|
|
15
|
+
*
|
|
16
|
+
* export async function POST(request: Request) {
|
|
17
|
+
* const rawBody = await request.text()
|
|
18
|
+
* const event = webhooks.constructEvent(
|
|
19
|
+
* rawBody,
|
|
20
|
+
* request.headers,
|
|
21
|
+
* process.env.OS_WEBHOOK_SIGNING_SECRET!,
|
|
22
|
+
* )
|
|
23
|
+
*
|
|
24
|
+
* console.log(event.type, event.action, event.webhookId)
|
|
25
|
+
* return Response.json({ received: true })
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const webhooks: {
|
|
30
|
+
constructEvent: typeof constructProductWebhookEvent;
|
|
31
|
+
generateTestHeaders: typeof generateTestWebhookHeaders;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/webhooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AAEpE,OAAO,EACL,iCAAiC,EACjC,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,mCAAmC,EAAE,MAAM,UAAU,CAAA;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AACpE,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,WAAW,CAAA;AAClB,YAAY,EACV,mCAAmC,EACnC,+BAA+B,EAC/B,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,QAAQ;;;CAGpB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { constructProductWebhookEvent } from './construct-event';
|
|
2
|
+
import { generateTestWebhookHeaders } from './generate-test-headers';
|
|
3
|
+
export { DEFAULT_WEBHOOK_TOLERANCE_SECONDS, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from './constants';
|
|
4
|
+
export { constructProductWebhookEvent } from './construct-event';
|
|
5
|
+
export { OsWebhookSignatureVerificationError } from './errors';
|
|
6
|
+
export { generateTestWebhookHeaders } from './generate-test-headers';
|
|
7
|
+
export { buildWebhookSignature, buildWebhookSignatureMaterial, verifyWebhookSignature, } from './signing';
|
|
8
|
+
/**
|
|
9
|
+
* Verify inbound OS product webhooks.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { webhooks } from '@chatarmin/os/webhooks'
|
|
14
|
+
*
|
|
15
|
+
* export async function POST(request: Request) {
|
|
16
|
+
* const rawBody = await request.text()
|
|
17
|
+
* const event = webhooks.constructEvent(
|
|
18
|
+
* rawBody,
|
|
19
|
+
* request.headers,
|
|
20
|
+
* process.env.OS_WEBHOOK_SIGNING_SECRET!,
|
|
21
|
+
* )
|
|
22
|
+
*
|
|
23
|
+
* console.log(event.type, event.action, event.webhookId)
|
|
24
|
+
* return Response.json({ received: true })
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const webhooks = {
|
|
29
|
+
constructEvent: constructProductWebhookEvent,
|
|
30
|
+
generateTestHeaders: generateTestWebhookHeaders,
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-header.d.ts","sourceRoot":"","sources":["../../src/webhooks/read-header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,qBAAqB,EAC9B,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,IAAI,CAoBf"}
|