@chatarmin/os 1.5.9 → 1.7.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 +31 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- 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 +16 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +14 -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 +9 -2
- 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/chatarmin-os-billing-inputs.js +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/feature-access-list-item.js +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/product-feature-catalog.js +0 -1
- /package/dist/{types/billing-dashboard-context.js → webhooks/types.js} +0 -0
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
- [Subscriptions & Tiers](#subscriptions--tiers)
|
|
31
31
|
- [Links](#links)
|
|
32
32
|
- [Onboarding](#onboarding)
|
|
33
|
+
- [Product Webhooks](#product-webhooks)
|
|
33
34
|
- [Common Patterns](#common-patterns)
|
|
34
35
|
- [TypeScript Support](#typescript-support)
|
|
35
36
|
- [Configuration](#configuration)
|
|
@@ -598,6 +599,36 @@ switch (result.linkStatus) {
|
|
|
598
599
|
|
|
599
600
|
---
|
|
600
601
|
|
|
602
|
+
## Product Webhooks
|
|
603
|
+
|
|
604
|
+
When ChatarminOS pushes company and product-link changes to your app, verify the request with the SDK before handling the payload.
|
|
605
|
+
|
|
606
|
+
```typescript
|
|
607
|
+
import { webhooks } from "@chatarmin/os/webhooks"
|
|
608
|
+
|
|
609
|
+
export async function POST(request: Request) {
|
|
610
|
+
const rawBody = await request.text()
|
|
611
|
+
|
|
612
|
+
const event = webhooks.constructEvent(
|
|
613
|
+
rawBody,
|
|
614
|
+
request.headers,
|
|
615
|
+
process.env.OS_WEBHOOK_SIGNING_SECRET!,
|
|
616
|
+
)
|
|
617
|
+
|
|
618
|
+
switch (`${event.type}.${event.action}`) {
|
|
619
|
+
case "company.updated":
|
|
620
|
+
// event.data, event.webhookId, event.idempotency_key
|
|
621
|
+
break
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
return Response.json({ received: true })
|
|
625
|
+
}
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
Use `ChatarminOS.webhooks.constructEvent` if you already import the main client. Dedupe on `event.webhookId` or `event.idempotency_key`.
|
|
629
|
+
|
|
630
|
+
---
|
|
631
|
+
|
|
601
632
|
## Common Patterns
|
|
602
633
|
|
|
603
634
|
### Feature Gating
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AppRouter } from "@chatarmin/api";
|
|
2
2
|
import { type CompaniesClient } from "./companies";
|
|
3
|
+
export { webhooks, constructProductWebhookEvent, generateTestWebhookHeaders, OsWebhookSignatureVerificationError, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from "./webhooks";
|
|
4
|
+
export type { ConstructProductWebhookEventOptions, ProductWebhookEventPayload, ProductWebhookHeaders, VerifiedProductWebhookEvent, } from "./webhooks";
|
|
3
5
|
export type { CompaniesClient, CompanyAssignee, CompanyAssignees, CreateCompanyInput, CreateCompanyResult, GetCompanyInput, LinkedCompany, ListCompaniesInput, ListCompaniesResult, ListLinkedCompaniesInput, ListLinkedCompaniesResult, ProductCompany, UpdateCompanyResult, } from "./companies";
|
|
4
6
|
/**
|
|
5
7
|
* Configuration options for the ChatarminOS SDK client.
|
|
@@ -413,6 +415,10 @@ export interface OnboardResult {
|
|
|
413
415
|
* @see https://os.chatarmin.com/docs for full documentation
|
|
414
416
|
*/
|
|
415
417
|
export declare class ChatarminOS {
|
|
418
|
+
static webhooks: {
|
|
419
|
+
constructEvent: typeof import("./webhooks").constructProductWebhookEvent;
|
|
420
|
+
generateTestHeaders: typeof import("./webhooks").generateTestWebhookHeaders;
|
|
421
|
+
};
|
|
416
422
|
private client;
|
|
417
423
|
private call;
|
|
418
424
|
/**
|
|
@@ -1101,6 +1107,7 @@ export declare class ChatarminOS {
|
|
|
1101
1107
|
metadata: unknown;
|
|
1102
1108
|
status: string;
|
|
1103
1109
|
company_id: string | null;
|
|
1110
|
+
last_synced_at: Date | null;
|
|
1104
1111
|
stripe_customer_id: string;
|
|
1105
1112
|
link_status: string;
|
|
1106
1113
|
default_currency: string;
|
|
@@ -1116,7 +1123,6 @@ export declare class ChatarminOS {
|
|
|
1116
1123
|
past_due_invoices_count: number;
|
|
1117
1124
|
past_due_amount_cents: number;
|
|
1118
1125
|
max_days_overdue: number;
|
|
1119
|
-
last_synced_at: Date | null;
|
|
1120
1126
|
company_group_id: string | null;
|
|
1121
1127
|
}[];
|
|
1122
1128
|
activeSubscriptions: {
|
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,gBAAgB,CAAA;AAG/C,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG/C,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,aAAa,CAAA;AAGpB,OAAO,EACL,QAAQ,EACR,4BAA4B,EAC5B,0BAA0B,EAC1B,mCAAmC,EACnC,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,YAAY,CAAA;AACnB,YAAY,EACV,mCAAmC,EACnC,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,mBAAmB,GACpB,MAAM,aAAa,CAAA;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ACiB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAK7B;IAMD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,IAAI,KAAK;QAIL;;;;;;;;;;;WAWG;;;;;;;;;;;;;;;;;;;;QAMH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAsCG;wBACa,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAKtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA8BG;0BACe,MAAM,WAAW,cAAc;;;;;MASpD;IAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyFG;IACG,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CA8E3D;AAGD,YAAY,EAAE,SAAS,EAAE,CAAA;AAGzB,eAAe,WAAW,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { TRPCClientError, createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
2
2
|
import superjson from "superjson";
|
|
3
3
|
import { createCompaniesClient, } from "./companies";
|
|
4
|
+
import { webhooks } from "./webhooks";
|
|
5
|
+
export { webhooks, constructProductWebhookEvent, generateTestWebhookHeaders, OsWebhookSignatureVerificationError, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from "./webhooks";
|
|
4
6
|
const INSPECT_SYMBOL = Symbol.for("nodejs.util.inspect.custom");
|
|
5
7
|
export class ChatarminOSError extends Error {
|
|
6
8
|
details;
|
|
@@ -117,6 +119,7 @@ function toChatarminOSError(operation, error) {
|
|
|
117
119
|
* @see https://os.chatarmin.com/docs for full documentation
|
|
118
120
|
*/
|
|
119
121
|
export class ChatarminOS {
|
|
122
|
+
static webhooks = webhooks;
|
|
120
123
|
client;
|
|
121
124
|
async call(operation, action) {
|
|
122
125
|
try {
|
|
@@ -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.js';
|
|
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,YAAY,CAAA;AA0DnB,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.js';
|
|
2
|
+
import { OsWebhookSignatureVerificationError } from './errors.js';
|
|
3
|
+
import { readWebhookHeader } from './read-header.js';
|
|
4
|
+
import { verifyWebhookSignature } from './signing.js';
|
|
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,YAAY,CAAA;AAEjE,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.js';
|
|
2
|
+
import { buildWebhookSignature } from './signing.js';
|
|
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,16 @@
|
|
|
1
|
+
import { constructProductWebhookEvent } from './construct-event.js';
|
|
2
|
+
import { generateTestWebhookHeaders } from './generate-test-headers.js';
|
|
3
|
+
export { DEFAULT_WEBHOOK_TOLERANCE_SECONDS, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from './constants.js';
|
|
4
|
+
export { constructProductWebhookEvent } from './construct-event.js';
|
|
5
|
+
export { OsWebhookSignatureVerificationError } from './errors.js';
|
|
6
|
+
export { generateTestWebhookHeaders } from './generate-test-headers.js';
|
|
7
|
+
export { buildWebhookSignature, buildWebhookSignatureMaterial, verifyWebhookSignature, } from './signing.js';
|
|
8
|
+
export type { ConstructProductWebhookEventOptions, GenerateTestWebhookHeadersInput, ProductWebhookEventPayload, ProductWebhookHeaders, VerifiedProductWebhookEvent, } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Verify inbound OS product webhooks.
|
|
11
|
+
*/
|
|
12
|
+
export declare const webhooks: {
|
|
13
|
+
constructEvent: typeof constructProductWebhookEvent;
|
|
14
|
+
generateTestHeaders: typeof generateTestWebhookHeaders;
|
|
15
|
+
};
|
|
16
|
+
//# 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,sBAAsB,CAAA;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAA;AAEvE,OAAO,EACL,iCAAiC,EACjC,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,cAAc,CAAA;AACrB,YAAY,EACV,mCAAmC,EACnC,+BAA+B,EAC/B,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,YAAY,CAAA;AAEnB;;GAEG;AACH,eAAO,MAAM,QAAQ;;;CAGpB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { constructProductWebhookEvent } from './construct-event.js';
|
|
2
|
+
import { generateTestWebhookHeaders } from './generate-test-headers.js';
|
|
3
|
+
export { DEFAULT_WEBHOOK_TOLERANCE_SECONDS, WEBHOOK_ID_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, } from './constants.js';
|
|
4
|
+
export { constructProductWebhookEvent } from './construct-event.js';
|
|
5
|
+
export { OsWebhookSignatureVerificationError } from './errors.js';
|
|
6
|
+
export { generateTestWebhookHeaders } from './generate-test-headers.js';
|
|
7
|
+
export { buildWebhookSignature, buildWebhookSignatureMaterial, verifyWebhookSignature, } from './signing.js';
|
|
8
|
+
/**
|
|
9
|
+
* Verify inbound OS product webhooks.
|
|
10
|
+
*/
|
|
11
|
+
export const webhooks = {
|
|
12
|
+
constructEvent: constructProductWebhookEvent,
|
|
13
|
+
generateTestHeaders: generateTestWebhookHeaders,
|
|
14
|
+
};
|
|
@@ -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,YAAY,CAAA;AAEvD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,qBAAqB,EAC9B,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,IAAI,CAoBf"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function readWebhookHeader(headers, name) {
|
|
2
|
+
if (headers instanceof Headers) {
|
|
3
|
+
return headers.get(name);
|
|
4
|
+
}
|
|
5
|
+
const lowerName = name.toLowerCase();
|
|
6
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
7
|
+
if (key.toLowerCase() !== lowerName || value == null) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(value)) {
|
|
11
|
+
return value[0] ?? null;
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function buildWebhookSignatureMaterial(timestamp: string, rawBody: string): string;
|
|
2
|
+
export declare function buildWebhookSignature(secret: string, timestamp: string, rawBody: string): string;
|
|
3
|
+
export declare function verifyWebhookSignature(secret: string, timestamp: string, rawBody: string, signature: string): boolean;
|
|
4
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/webhooks/signing.ts"],"names":[],"mappings":"AAEA,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,MAAM,CAER;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,MAAM,CAIR;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAWT"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
export function buildWebhookSignatureMaterial(timestamp, rawBody) {
|
|
3
|
+
return `${timestamp}.${rawBody}`;
|
|
4
|
+
}
|
|
5
|
+
export function buildWebhookSignature(secret, timestamp, rawBody) {
|
|
6
|
+
return createHmac('sha256', secret)
|
|
7
|
+
.update(buildWebhookSignatureMaterial(timestamp, rawBody))
|
|
8
|
+
.digest('hex');
|
|
9
|
+
}
|
|
10
|
+
export function verifyWebhookSignature(secret, timestamp, rawBody, signature) {
|
|
11
|
+
const expected = buildWebhookSignature(secret, timestamp, rawBody);
|
|
12
|
+
if (expected.length !== signature.length) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return timingSafeEqual(Buffer.from(expected, 'utf8'), Buffer.from(signature, 'utf8'));
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ProductWebhookEventPayload {
|
|
2
|
+
type: string;
|
|
3
|
+
action: string;
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
idempotency_key: string;
|
|
6
|
+
occurred_at?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface VerifiedProductWebhookEvent extends ProductWebhookEventPayload {
|
|
9
|
+
webhookId: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ConstructProductWebhookEventOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Maximum age of the webhook timestamp in seconds.
|
|
15
|
+
* Rejects requests older than this to limit replay attacks.
|
|
16
|
+
* Set to 0 to disable the check.
|
|
17
|
+
* @default 300
|
|
18
|
+
*/
|
|
19
|
+
tolerance?: number;
|
|
20
|
+
/** Clock used for tolerance checks */
|
|
21
|
+
now?: Date;
|
|
22
|
+
}
|
|
23
|
+
export type ProductWebhookHeaders = Headers | Readonly<Record<string, string | string[] | undefined | null>>;
|
|
24
|
+
export interface GenerateTestWebhookHeadersInput {
|
|
25
|
+
secret: string;
|
|
26
|
+
payload: string;
|
|
27
|
+
webhookId?: string;
|
|
28
|
+
timestamp?: number;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/webhooks/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,2BAA4B,SAAQ,0BAA0B;IAC7E,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,mCAAmC;IAClD;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,sCAAsC;IACtC,GAAG,CAAC,EAAE,IAAI,CAAA;CACX;AAED,MAAM,MAAM,qBAAqB,GAC7B,OAAO,GACP,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC,CAAA;AAElE,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatarmin/os",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Type-safe SDK for ChatarminOS - Customer & Subscription Management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"import": "./dist/index.js",
|
|
15
15
|
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./webhooks": {
|
|
18
|
+
"types": "./dist/webhooks/index.d.ts",
|
|
19
|
+
"import": "./dist/webhooks/index.js",
|
|
20
|
+
"default": "./dist/webhooks/index.js"
|
|
16
21
|
}
|
|
17
22
|
},
|
|
18
23
|
"files": [
|
|
@@ -20,7 +25,8 @@
|
|
|
20
25
|
"README.md"
|
|
21
26
|
],
|
|
22
27
|
"scripts": {
|
|
23
|
-
"build": "tsc --skipLibCheck",
|
|
28
|
+
"build": "tsc -p tsconfig.webhooks.json --skipLibCheck",
|
|
29
|
+
"build:full": "tsc --skipLibCheck",
|
|
24
30
|
"dev": "tsc --watch --skipLibCheck",
|
|
25
31
|
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
26
32
|
"test": "tsx test-sdk.ts",
|
|
@@ -53,6 +59,7 @@
|
|
|
53
59
|
"devDependencies": {
|
|
54
60
|
"@chatarmin/api": "workspace:*",
|
|
55
61
|
"@chatarmin/tsconfig": "workspace:*",
|
|
62
|
+
"@types/node": "^22.10.5",
|
|
56
63
|
"dotenv": "^16.4.5",
|
|
57
64
|
"tsx": "^4.19.0",
|
|
58
65
|
"typescript": "^5.9.3"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { BillingDashboardContext, GetBillingDashboardContextInput } from './types/billing-dashboard-context.js';
|
|
2
|
-
type DashboardCaller = <T>(operation: string, fn: () => Promise<T>) => Promise<T>;
|
|
3
|
-
type MinimalBillingClient = {
|
|
4
|
-
billing: {
|
|
5
|
-
getDashboardContext: {
|
|
6
|
-
query: (input: GetBillingDashboardContextInput) => Promise<unknown>;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Bound as `ChatarminOS.billing.getDashboardContext`.
|
|
12
|
-
* One call: resolve link by `externalOrgId`, return feature rows with usage, optional billing, `billingDegraded`.
|
|
13
|
-
*/
|
|
14
|
-
export declare function bindBillingGetDashboardContext(call: DashboardCaller, client: MinimalBillingClient): (input: GetBillingDashboardContextInput) => Promise<BillingDashboardContext>;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=billing-get-dashboard-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"billing-get-dashboard-context.d.ts","sourceRoot":"","sources":["../src/billing-get-dashboard-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,+BAA+B,EAChC,MAAM,sCAAsC,CAAA;AAE7C,KAAK,eAAe,GAAG,CAAC,CAAC,EACvB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KACjB,OAAO,CAAC,CAAC,CAAC,CAAA;AAEf,KAAK,oBAAoB,GAAG;IAC1B,OAAO,EAAE;QACP,mBAAmB,EAAE;YACnB,KAAK,EAAE,CAAC,KAAK,EAAE,+BAA+B,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;SACpE,CAAA;KACF,CAAA;CACF,CAAA;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,eAAe,EACrB,MAAM,EAAE,oBAAoB,GAC3B,CACD,KAAK,EAAE,+BAA+B,KACnC,OAAO,CAAC,uBAAuB,CAAC,CAOpC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bound as `ChatarminOS.billing.getDashboardContext`.
|
|
3
|
-
* One call: resolve link by `externalOrgId`, return feature rows with usage, optional billing, `billingDegraded`.
|
|
4
|
-
*/
|
|
5
|
-
export function bindBillingGetDashboardContext(call, client) {
|
|
6
|
-
return (input) => call('billing.getDashboardContext', () => client.billing.getDashboardContext.query(input));
|
|
7
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { AppRouter } from '@chatarmin/api';
|
|
2
|
-
import type { createTRPCClient } from '@trpc/client';
|
|
3
|
-
import type { ClaimCheckoutInput, EnsureFeatureSubscriptionInput, EnsureFeatureSubscriptionResult, LinkSubscriptionInput, RelinkBillingProfileInput, SetUsageInput, SyncCompanyFromStripeInput, SyncCompanyFromStripeResult, UsageResult } from './types/chatarmin-os-billing-inputs.js';
|
|
4
|
-
export type ChatarminOsBillingCall = <T>(operation: string, fn: () => Promise<T>) => Promise<T>;
|
|
5
|
-
export type ChatarminOsTrpcClient = ReturnType<typeof createTRPCClient<AppRouter>>;
|
|
6
|
-
/**
|
|
7
|
-
* Billing, usage tracking, and subscription management (`os.billing`).
|
|
8
|
-
*/
|
|
9
|
-
export declare function createChatarminOsBillingNamespace(call: ChatarminOsBillingCall, client: ChatarminOsTrpcClient): {
|
|
10
|
-
getDashboardContext: (input: import("./index.js").GetBillingDashboardContextInput) => Promise<import("./index.js").BillingDashboardContext>;
|
|
11
|
-
setUsage: (input: SetUsageInput) => Promise<UsageResult>;
|
|
12
|
-
getUsageHistory: (companyId: string, featureCode: string, options?: {
|
|
13
|
-
limit?: number;
|
|
14
|
-
includeDelivered?: boolean;
|
|
15
|
-
eventType?: "increment" | "set" | "adjustment";
|
|
16
|
-
}) => Promise<{
|
|
17
|
-
id: string;
|
|
18
|
-
created_at: Date;
|
|
19
|
-
metadata: unknown;
|
|
20
|
-
event_type: string;
|
|
21
|
-
source: string;
|
|
22
|
-
idempotency_key: string;
|
|
23
|
-
billing_profile_id: string | null;
|
|
24
|
-
subscription_item_id: string | null;
|
|
25
|
-
feature_access_id: string | null;
|
|
26
|
-
meter_code: string;
|
|
27
|
-
quantity: number;
|
|
28
|
-
stripe_price_id: string | null;
|
|
29
|
-
event_time: Date;
|
|
30
|
-
previous_value: number | null;
|
|
31
|
-
adjustment_reason: string | null;
|
|
32
|
-
adjusts_event_id: string | null;
|
|
33
|
-
stripe_delivery_status: string;
|
|
34
|
-
stripe_delivery_attempts: number;
|
|
35
|
-
stripe_last_delivery_attempt_at: Date | null;
|
|
36
|
-
stripe_event_id: string | null;
|
|
37
|
-
stripe_delivery_error: string | null;
|
|
38
|
-
delivered_at: Date | null;
|
|
39
|
-
}[]>;
|
|
40
|
-
claimCheckout: (input: ClaimCheckoutInput) => Promise<{
|
|
41
|
-
success: boolean;
|
|
42
|
-
subscriptionId: string;
|
|
43
|
-
alreadyClaimed: boolean;
|
|
44
|
-
status?: undefined;
|
|
45
|
-
} | {
|
|
46
|
-
success: boolean;
|
|
47
|
-
subscriptionId: string;
|
|
48
|
-
alreadyClaimed: boolean;
|
|
49
|
-
status: import("stripe").Stripe.Subscription.Status;
|
|
50
|
-
}>;
|
|
51
|
-
linkSubscription: (input: LinkSubscriptionInput) => Promise<{
|
|
52
|
-
success: boolean;
|
|
53
|
-
subscriptionId: string;
|
|
54
|
-
alreadyLinked: boolean;
|
|
55
|
-
status?: undefined;
|
|
56
|
-
tierApplied?: undefined;
|
|
57
|
-
featuresApplied?: undefined;
|
|
58
|
-
} | {
|
|
59
|
-
success: boolean;
|
|
60
|
-
subscriptionId: string;
|
|
61
|
-
alreadyLinked: boolean;
|
|
62
|
-
status: import("stripe").Stripe.Subscription.Status;
|
|
63
|
-
tierApplied: boolean;
|
|
64
|
-
featuresApplied: number;
|
|
65
|
-
}>;
|
|
66
|
-
getStatus: (companyId: string) => Promise<{
|
|
67
|
-
hasBillingProfile: boolean;
|
|
68
|
-
stripeCustomerId: string | null;
|
|
69
|
-
billingProfiles: {
|
|
70
|
-
id: string;
|
|
71
|
-
organization_id: string;
|
|
72
|
-
created_at: Date;
|
|
73
|
-
updated_at: Date;
|
|
74
|
-
short_id: string | null;
|
|
75
|
-
name: string;
|
|
76
|
-
metadata: unknown;
|
|
77
|
-
status: string;
|
|
78
|
-
mrr_cents: number;
|
|
79
|
-
mrr_committed_cents: number;
|
|
80
|
-
mrr_usage_cents: number;
|
|
81
|
-
contract_start_at: Date | null;
|
|
82
|
-
contract_end_at: Date | null;
|
|
83
|
-
subscription_status: string;
|
|
84
|
-
max_days_overdue: number;
|
|
85
|
-
company_id: string | null;
|
|
86
|
-
stripe_customer_id: string;
|
|
87
|
-
link_status: string;
|
|
88
|
-
default_currency: string;
|
|
89
|
-
has_payment_method: boolean;
|
|
90
|
-
open_invoices_count: number;
|
|
91
|
-
open_amount_cents: number;
|
|
92
|
-
past_due_invoices_count: number;
|
|
93
|
-
past_due_amount_cents: number;
|
|
94
|
-
last_synced_at: Date | null;
|
|
95
|
-
company_group_id: string | null;
|
|
96
|
-
}[];
|
|
97
|
-
activeSubscriptions: {
|
|
98
|
-
id: string;
|
|
99
|
-
billingProfileId: string;
|
|
100
|
-
status: string;
|
|
101
|
-
stripeSubscriptionId: string | null;
|
|
102
|
-
currentPeriodEnd: Date | null;
|
|
103
|
-
trialEnd: Date | null;
|
|
104
|
-
tier: {
|
|
105
|
-
code: string;
|
|
106
|
-
name: string | null;
|
|
107
|
-
} | null;
|
|
108
|
-
}[];
|
|
109
|
-
enabledFeaturesCount: number;
|
|
110
|
-
}>;
|
|
111
|
-
syncCompanyFromStripe: (input: SyncCompanyFromStripeInput) => Promise<SyncCompanyFromStripeResult>;
|
|
112
|
-
relinkBillingProfile: (input: RelinkBillingProfileInput) => Promise<{
|
|
113
|
-
billingProfileId: string;
|
|
114
|
-
stripeCustomerId: string;
|
|
115
|
-
subscriptionsSynced: number;
|
|
116
|
-
subscriptionItemsSynced: number;
|
|
117
|
-
featuresLinked: number;
|
|
118
|
-
matchedMeters: number;
|
|
119
|
-
}>;
|
|
120
|
-
ensureFeatureSubscription: (input: EnsureFeatureSubscriptionInput) => Promise<EnsureFeatureSubscriptionResult>;
|
|
121
|
-
};
|
|
122
|
-
//# sourceMappingURL=chatarmin-os-billing-namespace.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chatarmin-os-billing-namespace.d.ts","sourceRoot":"","sources":["../src/chatarmin-os-billing-namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,KAAK,EACV,kBAAkB,EAClB,8BAA8B,EAC9B,+BAA+B,EAC/B,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,EACb,0BAA0B,EAC1B,2BAA2B,EAC3B,WAAW,EACZ,MAAM,wCAAwC,CAAA;AAE/C,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,EACrC,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KACjB,OAAO,CAAC,CAAC,CAAC,CAAA;AAEf,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAA;AAElF;;GAEG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,sBAAsB,EAC5B,MAAM,EAAE,qBAAqB;;sBAKT,aAAa,KAAG,OAAO,CAAC,WAAW,CAAC;iCAWzC,MAAM,eACJ,MAAM,YACT;QACR,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,gBAAgB,CAAC,EAAE,OAAO,CAAA;QAC1B,SAAS,CAAC,EAAE,WAAW,GAAG,KAAK,GAAG,YAAY,CAAA;KAC/C;;;;;;;;;;;;;;;;;;;;;;;;2BAUoB,kBAAkB;;;;;;;;;;;8BAKf,qBAAqB;;;;;;;;;;;;;;;2BAKxB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAMpB,0BAA0B,KAChC,OAAO,CAAC,2BAA2B,CAAC;kCAKT,yBAAyB;;;;;;;;uCAM9C,8BAA8B,KACpC,OAAO,CAAC,+BAA+B,CAAC;EAK9C"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { bindBillingGetDashboardContext } from './billing-get-dashboard-context.js';
|
|
2
|
-
/**
|
|
3
|
-
* Billing, usage tracking, and subscription management (`os.billing`).
|
|
4
|
-
*/
|
|
5
|
-
export function createChatarminOsBillingNamespace(call, client) {
|
|
6
|
-
return {
|
|
7
|
-
getDashboardContext: bindBillingGetDashboardContext(call, client),
|
|
8
|
-
setUsage: (input) => call("billing.setUsage", () => client.billing.setUsage.mutate({
|
|
9
|
-
...input,
|
|
10
|
-
source: "api",
|
|
11
|
-
})),
|
|
12
|
-
getUsageHistory: (companyId, featureCode, options) => call("billing.getUsageHistory", () => client.billing.getUsageHistory.query({
|
|
13
|
-
companyId,
|
|
14
|
-
featureCode,
|
|
15
|
-
...options,
|
|
16
|
-
})),
|
|
17
|
-
claimCheckout: (input) => call("billing.claimCheckout", () => client.billing.claimCheckout.mutate(input)),
|
|
18
|
-
linkSubscription: (input) => call("billing.linkSubscription", () => client.billing.linkSubscription.mutate(input)),
|
|
19
|
-
getStatus: (companyId) => call("billing.getStatus", () => client.billing.getStatus.query({ companyId })),
|
|
20
|
-
syncCompanyFromStripe: (input) => call("billing.syncCompanyFromStripe", () => client.billing.syncCompanyFromStripe.mutate(input)),
|
|
21
|
-
relinkBillingProfile: (input) => call("billing.relinkBillingProfile", () => client.billing.relinkBillingProfile.mutate(input)),
|
|
22
|
-
ensureFeatureSubscription: (input) => call("billing.ensureFeatureSubscription", () => client.billing.ensureFeatureSubscription.mutate(input)),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ListProductFeatureCatalogInput, ProductFeatureCatalogItem } from './types/product-feature-catalog.js';
|
|
2
|
-
type ListForProductCaller = <T>(operation: string, fn: () => Promise<T>) => Promise<T>;
|
|
3
|
-
type MinimalFeaturesClient = {
|
|
4
|
-
features: {
|
|
5
|
-
listForProduct: {
|
|
6
|
-
query: (input: {
|
|
7
|
-
includeInactive: boolean;
|
|
8
|
-
}) => Promise<unknown>;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Bound as `ChatarminOSClient.features.listForProduct`.
|
|
14
|
-
* Lists feature definitions for the API key’s product (no company id).
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const defs = await os.features.listForProduct()
|
|
19
|
-
* for (const f of defs) {
|
|
20
|
-
* console.log(`${f.code}: ${f.name}${f.hasQuantity ? ' (metered)' : ''}`)
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare function bindFeaturesListForProduct(call: ListForProductCaller, client: MinimalFeaturesClient): (input?: ListProductFeatureCatalogInput) => Promise<ProductFeatureCatalogItem[]>;
|
|
25
|
-
export {};
|
|
26
|
-
//# sourceMappingURL=features-list-for-product.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"features-list-for-product.d.ts","sourceRoot":"","sources":["../src/features-list-for-product.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,yBAAyB,EAC1B,MAAM,oCAAoC,CAAA;AAE3C,KAAK,oBAAoB,GAAG,CAAC,CAAC,EAC5B,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KACjB,OAAO,CAAC,CAAC,CAAC,CAAA;AAEf,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE;QACR,cAAc,EAAE;YACd,KAAK,EAAE,CAAC,KAAK,EAAE;gBAAE,eAAe,EAAE,OAAO,CAAA;aAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;SACjE,CAAA;KACF,CAAA;CACF,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,oBAAoB,EAC1B,MAAM,EAAE,qBAAqB,GAC5B,CAAC,KAAK,CAAC,EAAE,8BAA8B,KAAK,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAOlF"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bound as `ChatarminOSClient.features.listForProduct`.
|
|
3
|
-
* Lists feature definitions for the API key’s product (no company id).
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* const defs = await os.features.listForProduct()
|
|
8
|
-
* for (const f of defs) {
|
|
9
|
-
* console.log(`${f.code}: ${f.name}${f.hasQuantity ? ' (metered)' : ''}`)
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export function bindFeaturesListForProduct(call, client) {
|
|
14
|
-
return (input) => call('features.listForProduct', () => client.features.listForProduct.query({
|
|
15
|
-
includeInactive: input?.includeInactive ?? false,
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { FeatureAccessBillingState, FeatureAccessCommonFields as ContractFeatureAccessCommonFields } from '@chatarmin/contracts';
|
|
2
|
-
/**
|
|
3
|
-
* Stripe period, price, and subscription status when the API returns expanded billing
|
|
4
|
-
* (`includeBillingDetails` on feature access, or `billing.getDashboardContext`).
|
|
5
|
-
*/
|
|
6
|
-
export type BillingDashboardFeatureBilling = FeatureAccessBillingState;
|
|
7
|
-
/**
|
|
8
|
-
* One feature row for billing/usage dashboards (tenant-scoped, ordered server-side).
|
|
9
|
-
*/
|
|
10
|
-
export type FeatureAccessCommonFields = ContractFeatureAccessCommonFields;
|
|
11
|
-
/**
|
|
12
|
-
* One feature row for billing/usage dashboards (tenant-scoped, ordered server-side).
|
|
13
|
-
*/
|
|
14
|
-
export interface BillingDashboardFeatureRow extends FeatureAccessCommonFields {
|
|
15
|
-
displayOrder: number;
|
|
16
|
-
remaining: number | null;
|
|
17
|
-
isAtLimit: boolean;
|
|
18
|
-
canUse: boolean;
|
|
19
|
-
/** Usage/limits may still apply; Stripe period/price linkage is missing. */
|
|
20
|
-
billingDegraded: boolean;
|
|
21
|
-
}
|
|
22
|
-
/** Input for `ChatarminOS.billing.getDashboardContext`. */
|
|
23
|
-
export interface GetBillingDashboardContextInput {
|
|
24
|
-
externalOrgId: string;
|
|
25
|
-
}
|
|
26
|
-
/** Result of `billing.getDashboardContext` (single round-trip per tenant). */
|
|
27
|
-
export interface BillingDashboardContext {
|
|
28
|
-
companyId: string;
|
|
29
|
-
productLinkId: string;
|
|
30
|
-
externalOrgId: string;
|
|
31
|
-
features: BillingDashboardFeatureRow[];
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=billing-dashboard-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"billing-dashboard-context.d.ts","sourceRoot":"","sources":["../../src/types/billing-dashboard-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,IAAI,iCAAiC,EAC/D,MAAM,sBAAsB,CAAA;AAE7B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,yBAAyB,CAAA;AAEtE;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,iCAAiC,CAAA;AAEzE;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,yBAAyB;IAC3E,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,SAAS,EAAE,OAAO,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;IACf,4EAA4E;IAC5E,eAAe,EAAE,OAAO,CAAA;CACzB;AAED,2DAA2D;AAC3D,MAAM,WAAW,+BAA+B;IAC9C,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,8EAA8E;AAC9E,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,0BAA0B,EAAE,CAAA;CACvC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
export interface SyncCompanyFromStripeInput {
|
|
2
|
-
companyId: string;
|
|
3
|
-
stripeCustomerId?: string;
|
|
4
|
-
forceReassign?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface SyncCompanyFromStripeResult {
|
|
7
|
-
billingProfileId: string;
|
|
8
|
-
stripeCustomerId: string;
|
|
9
|
-
subscriptionsSynced: number;
|
|
10
|
-
subscriptionItemsSynced: number;
|
|
11
|
-
featuresLinked: number;
|
|
12
|
-
matchedMeters: number;
|
|
13
|
-
}
|
|
14
|
-
export interface EnsureFeatureSubscriptionInput {
|
|
15
|
-
companyId: string;
|
|
16
|
-
featureCode: string;
|
|
17
|
-
stripeSubscriptionId?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface RelinkBillingProfileInput {
|
|
20
|
-
companyId: string;
|
|
21
|
-
stripeCustomerId: string;
|
|
22
|
-
}
|
|
23
|
-
export interface EnsureFeatureSubscriptionResult {
|
|
24
|
-
success: boolean;
|
|
25
|
-
subscriptionItemId: string | null;
|
|
26
|
-
stripePriceId: string | null;
|
|
27
|
-
stripeSubscriptionId: string | null;
|
|
28
|
-
action: "already_linked" | "linked_existing" | "created_new" | "failed";
|
|
29
|
-
error?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Input for setting usage to an absolute value.
|
|
33
|
-
* Use for corrections when you know what the total usage SHOULD be.
|
|
34
|
-
*/
|
|
35
|
-
export interface SetUsageInput {
|
|
36
|
-
/** Company ID */
|
|
37
|
-
companyId: string;
|
|
38
|
-
/** Feature code */
|
|
39
|
-
featureCode: string;
|
|
40
|
-
/** The absolute value to set usage to (must be >= 0) */
|
|
41
|
-
absoluteValue: number;
|
|
42
|
-
/** Reason for the set operation (required for audit trail) */
|
|
43
|
-
reason: string;
|
|
44
|
-
/** Admin user who performed the operation */
|
|
45
|
-
performedBy?: string;
|
|
46
|
-
/** Additional metadata (e.g., { ticketId: "SUPPORT-123" }) */
|
|
47
|
-
metadata?: Record<string, unknown>;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Result from usage operations.
|
|
51
|
-
*/
|
|
52
|
-
export interface UsageResult {
|
|
53
|
-
success: boolean;
|
|
54
|
-
featureCode: string;
|
|
55
|
-
previousUsage: number;
|
|
56
|
-
currentUsage: number;
|
|
57
|
-
delta: number;
|
|
58
|
-
quantityLimit: number | null;
|
|
59
|
-
remaining: number | null;
|
|
60
|
-
isAtLimit: boolean;
|
|
61
|
-
includedQuantity: number;
|
|
62
|
-
billableQuantity: number;
|
|
63
|
-
meterId: string;
|
|
64
|
-
eventId: string | null;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Input for claiming a Stripe checkout subscription.
|
|
68
|
-
*/
|
|
69
|
-
export interface ClaimCheckoutInput {
|
|
70
|
-
/** Company ID to link the subscription to */
|
|
71
|
-
companyId: string;
|
|
72
|
-
/** Stripe checkout session ID (cs_xxx) */
|
|
73
|
-
checkoutSessionId: string;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Input for linking an existing Stripe subscription.
|
|
77
|
-
*/
|
|
78
|
-
export interface LinkSubscriptionInput {
|
|
79
|
-
/** Company ID to link the subscription to */
|
|
80
|
-
companyId: string;
|
|
81
|
-
/** Stripe subscription ID (sub_xxx) */
|
|
82
|
-
stripeSubscriptionId: string;
|
|
83
|
-
/** Stripe customer ID (cus_xxx) - fetched from subscription if not provided */
|
|
84
|
-
stripeCustomerId?: string;
|
|
85
|
-
/** Tier code to apply features from (e.g., "free", "pro") */
|
|
86
|
-
tierCode?: string;
|
|
87
|
-
/** Display name for the subscription */
|
|
88
|
-
displayName?: string;
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=chatarmin-os-billing-inputs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chatarmin-os-billing-inputs.d.ts","sourceRoot":"","sources":["../../src/types/chatarmin-os-billing-inputs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,2BAA2B;IAC1C,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;IACxB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,uBAAuB,EAAE,MAAM,CAAA;IAC/B,cAAc,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,8BAA8B;IAC7C,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,+BAA+B;IAC9C,OAAO,EAAE,OAAO,CAAA;IAChB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,GAAG,aAAa,GAAG,QAAQ,CAAA;IACvE,KAAK,CA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C,EAAE,MAAM,CAAA;CACrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { FeatureAccessCommonFields } from './billing-dashboard-context.js';
|
|
2
|
-
/**
|
|
3
|
-
* One row from `features.listAccess` / `getAccess` (no `displayOrder` on the wire).
|
|
4
|
-
* Declared here so the SDK `.d.ts` stays portable — tRPC inference pulls in internal API paths.
|
|
5
|
-
*/
|
|
6
|
-
export type FeatureAccessListItem = FeatureAccessCommonFields;
|
|
7
|
-
//# sourceMappingURL=feature-access-list-item.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"feature-access-list-item.d.ts","sourceRoot":"","sources":["../../src/types/feature-access-list-item.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAE/E;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** Input for `ChatarminOSClient.features.listForProduct`. */
|
|
2
|
-
export interface ListProductFeatureCatalogInput {
|
|
3
|
-
/**
|
|
4
|
-
* Include inactive feature definitions (debug / support).
|
|
5
|
-
* @default false
|
|
6
|
-
*/
|
|
7
|
-
includeInactive?: boolean;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* One feature definition row for the calling product (catalog, not per-company access).
|
|
11
|
-
*/
|
|
12
|
-
export interface ProductFeatureCatalogItem {
|
|
13
|
-
id: string;
|
|
14
|
-
code: string;
|
|
15
|
-
name: string;
|
|
16
|
-
description: string | null;
|
|
17
|
-
hasQuantity: boolean;
|
|
18
|
-
defaultEnabled: boolean;
|
|
19
|
-
defaultQuantity: number | null;
|
|
20
|
-
defaultIncludedQuantity: number | null;
|
|
21
|
-
displayOrder: number;
|
|
22
|
-
isActive: boolean;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=product-feature-catalog.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"product-feature-catalog.d.ts","sourceRoot":"","sources":["../../src/types/product-feature-catalog.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,WAAW,EAAE,OAAO,CAAA;IACpB,cAAc,EAAE,OAAO,CAAA;IACvB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;CAClB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|