@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
|
@@ -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.8.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": [
|
|
@@ -53,6 +58,7 @@
|
|
|
53
58
|
"devDependencies": {
|
|
54
59
|
"@chatarmin/api": "workspace:*",
|
|
55
60
|
"@chatarmin/tsconfig": "workspace:*",
|
|
61
|
+
"@types/node": "^22.10.5",
|
|
56
62
|
"dotenv": "^16.4.5",
|
|
57
63
|
"tsx": "^4.19.0",
|
|
58
64
|
"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,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,wDAAwD;IACxD,aAAa,EAAE,MAAM,CAAA;IACrB,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAA;IACd,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,SAAS,EAAE,OAAO,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAA;IACjB,0CAA0C;IAC1C,iBAAiB,EAAE,MAAM,CAAA;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAA;IACjB,uCAAuC;IACvC,oBAAoB,EAAE,MAAM,CAAA;IAC5B,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB"}
|
|
@@ -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,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"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|