@auxiora/cloud 1.0.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/LICENSE +191 -0
- package/dist/billing.d.ts +48 -0
- package/dist/billing.d.ts.map +1 -0
- package/dist/billing.js +115 -0
- package/dist/billing.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/isolation.d.ts +36 -0
- package/dist/isolation.d.ts.map +1 -0
- package/dist/isolation.js +47 -0
- package/dist/isolation.js.map +1 -0
- package/dist/plans.d.ts +6 -0
- package/dist/plans.d.ts.map +1 -0
- package/dist/plans.js +79 -0
- package/dist/plans.js.map +1 -0
- package/dist/quotas.d.ts +40 -0
- package/dist/quotas.d.ts.map +1 -0
- package/dist/quotas.js +87 -0
- package/dist/quotas.js.map +1 -0
- package/dist/tenant.d.ts +21 -0
- package/dist/tenant.d.ts.map +1 -0
- package/dist/tenant.js +121 -0
- package/dist/tenant.js.map +1 -0
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -0
- package/src/billing.ts +142 -0
- package/src/index.ts +21 -0
- package/src/isolation.ts +69 -0
- package/src/plans.ts +84 -0
- package/src/quotas.ts +103 -0
- package/src/tenant.ts +140 -0
- package/src/types.ts +114 -0
- package/tests/billing.test.ts +126 -0
- package/tests/isolation.test.ts +95 -0
- package/tests/plans.test.ts +70 -0
- package/tests/quotas.test.ts +115 -0
- package/tests/tenant.test.ts +149 -0
- package/tsconfig.json +13 -0
- package/tsconfig.tsbuildinfo +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 Auxiora Contributors
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { BillingInfo, StripeClient, TenantPlan } from './types.js';
|
|
2
|
+
import type { TenantManager } from './tenant.js';
|
|
3
|
+
export interface BillingManagerOptions {
|
|
4
|
+
tenantManager: TenantManager;
|
|
5
|
+
stripe?: StripeClient;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* BillingManager handles Stripe integration for subscription management.
|
|
9
|
+
* Uses dependency injection for the Stripe SDK to enable easy testing.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BillingManager {
|
|
12
|
+
private tenantManager;
|
|
13
|
+
private stripe?;
|
|
14
|
+
constructor(options: BillingManagerOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Create a Stripe customer for a tenant.
|
|
17
|
+
*/
|
|
18
|
+
createCustomer(tenantId: string): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a subscription for a tenant.
|
|
21
|
+
*/
|
|
22
|
+
createSubscription(tenantId: string, plan: TenantPlan): Promise<{
|
|
23
|
+
subscriptionId: string;
|
|
24
|
+
status: string;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Cancel a tenant's subscription.
|
|
28
|
+
*/
|
|
29
|
+
cancelSubscription(tenantId: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Get billing info for a tenant.
|
|
32
|
+
*/
|
|
33
|
+
getBillingInfo(tenantId: string): Promise<BillingInfo>;
|
|
34
|
+
/**
|
|
35
|
+
* Get invoices for a tenant.
|
|
36
|
+
*/
|
|
37
|
+
getInvoices(tenantId: string): Promise<Array<{
|
|
38
|
+
id: string;
|
|
39
|
+
amount: number;
|
|
40
|
+
status: string;
|
|
41
|
+
created: string;
|
|
42
|
+
}>>;
|
|
43
|
+
/**
|
|
44
|
+
* Handle a Stripe webhook event.
|
|
45
|
+
*/
|
|
46
|
+
handleWebhookEvent(eventType: string, data: Record<string, unknown>): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=billing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,MAAM,CAAC,CAAe;gBAElB,OAAO,EAAE,qBAAqB;IAK1C;;OAEG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBvD;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAwBjH;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAczD;;OAEG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAW5D;;OAEG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAapH;;OAEG;IACG,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAuB1F"}
|
package/dist/billing.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { getPlanDefinition } from './plans.js';
|
|
2
|
+
/**
|
|
3
|
+
* BillingManager handles Stripe integration for subscription management.
|
|
4
|
+
* Uses dependency injection for the Stripe SDK to enable easy testing.
|
|
5
|
+
*/
|
|
6
|
+
export class BillingManager {
|
|
7
|
+
tenantManager;
|
|
8
|
+
stripe;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.tenantManager = options.tenantManager;
|
|
11
|
+
this.stripe = options.stripe;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a Stripe customer for a tenant.
|
|
15
|
+
*/
|
|
16
|
+
async createCustomer(tenantId) {
|
|
17
|
+
if (!this.stripe) {
|
|
18
|
+
throw new Error('Stripe not configured');
|
|
19
|
+
}
|
|
20
|
+
const tenant = await this.tenantManager.get(tenantId);
|
|
21
|
+
const customer = await this.stripe.createCustomer(tenant.email, tenant.name);
|
|
22
|
+
await this.tenantManager.update(tenantId, {});
|
|
23
|
+
// Store stripeCustomerId directly
|
|
24
|
+
const updated = await this.tenantManager.get(tenantId);
|
|
25
|
+
updated.stripeCustomerId = customer.id;
|
|
26
|
+
return customer.id;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a subscription for a tenant.
|
|
30
|
+
*/
|
|
31
|
+
async createSubscription(tenantId, plan) {
|
|
32
|
+
if (!this.stripe) {
|
|
33
|
+
throw new Error('Stripe not configured');
|
|
34
|
+
}
|
|
35
|
+
const tenant = await this.tenantManager.get(tenantId);
|
|
36
|
+
if (!tenant.stripeCustomerId) {
|
|
37
|
+
throw new Error('No Stripe customer ID. Call createCustomer first.');
|
|
38
|
+
}
|
|
39
|
+
const planDef = getPlanDefinition(plan);
|
|
40
|
+
const priceId = `price_${plan}_monthly`;
|
|
41
|
+
const subscription = await this.stripe.createSubscription(tenant.stripeCustomerId, priceId);
|
|
42
|
+
// Update tenant plan
|
|
43
|
+
await this.tenantManager.update(tenantId, { plan });
|
|
44
|
+
return {
|
|
45
|
+
subscriptionId: subscription.id,
|
|
46
|
+
status: subscription.status,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Cancel a tenant's subscription.
|
|
51
|
+
*/
|
|
52
|
+
async cancelSubscription(tenantId) {
|
|
53
|
+
if (!this.stripe) {
|
|
54
|
+
throw new Error('Stripe not configured');
|
|
55
|
+
}
|
|
56
|
+
const tenant = await this.tenantManager.get(tenantId);
|
|
57
|
+
if (!tenant.stripeSubscriptionId) {
|
|
58
|
+
throw new Error('No active subscription');
|
|
59
|
+
}
|
|
60
|
+
await this.stripe.cancelSubscription(tenant.stripeSubscriptionId);
|
|
61
|
+
await this.tenantManager.update(tenantId, { plan: 'free' });
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get billing info for a tenant.
|
|
65
|
+
*/
|
|
66
|
+
async getBillingInfo(tenantId) {
|
|
67
|
+
const tenant = await this.tenantManager.get(tenantId);
|
|
68
|
+
return {
|
|
69
|
+
tenantId,
|
|
70
|
+
plan: tenant.plan,
|
|
71
|
+
stripeCustomerId: tenant.stripeCustomerId,
|
|
72
|
+
stripeSubscriptionId: tenant.stripeSubscriptionId,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get invoices for a tenant.
|
|
77
|
+
*/
|
|
78
|
+
async getInvoices(tenantId) {
|
|
79
|
+
if (!this.stripe) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
const tenant = await this.tenantManager.get(tenantId);
|
|
83
|
+
if (!tenant.stripeCustomerId) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
return this.stripe.getInvoices(tenant.stripeCustomerId);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Handle a Stripe webhook event.
|
|
90
|
+
*/
|
|
91
|
+
async handleWebhookEvent(eventType, data) {
|
|
92
|
+
switch (eventType) {
|
|
93
|
+
case 'customer.subscription.deleted': {
|
|
94
|
+
const customerId = data.customer;
|
|
95
|
+
// Find tenant by customer ID and downgrade
|
|
96
|
+
const tenants = await this.tenantManager.list();
|
|
97
|
+
const tenant = tenants.find(t => t.stripeCustomerId === customerId);
|
|
98
|
+
if (tenant) {
|
|
99
|
+
await this.tenantManager.update(tenant.id, { plan: 'free' });
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case 'invoice.payment_failed': {
|
|
104
|
+
const customerId = data.customer;
|
|
105
|
+
const tenants = await this.tenantManager.list();
|
|
106
|
+
const tenant = tenants.find(t => t.stripeCustomerId === customerId);
|
|
107
|
+
if (tenant) {
|
|
108
|
+
await this.tenantManager.suspend(tenant.id, 'Payment failed');
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAO/C;;;GAGG;AACH,MAAM,OAAO,cAAc;IACjB,aAAa,CAAgB;IAC7B,MAAM,CAAgB;IAE9B,YAAY,OAA8B;QACxC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc,CAAC,QAAgB;QACnC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;QAE7E,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,E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C,QAAkB,CAAC;gBAC3C,2CAA2C;gBAC3C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;gBAChD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,KAAK,UAAU,CAAC,CAAC;gBACpE,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC/D,CAAC;gBACD,MAAM;YACR,CAAC;YACD,KAAK,wBAAwB,CAAC,CAAC,CAAC;gBAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,QAAkB,CAAC;gBAC3C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;gBAChD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,KAAK,UAAU,CAAC,CAAC;gBACpE,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,gBAAgB,CAAC,CAAC;gBAChE,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { TenantManager, type TenantManagerOptions } from './tenant.js';
|
|
2
|
+
export { TenantIsolation, type TenantContext, type IsolationOptions } from './isolation.js';
|
|
3
|
+
export { QuotaEnforcer, type QuotaEnforcerOptions } from './quotas.js';
|
|
4
|
+
export { BillingManager, type BillingManagerOptions } from './billing.js';
|
|
5
|
+
export { getPlanDefinition, getPlanQuotas, getAllPlans, isValidPlan } from './plans.js';
|
|
6
|
+
export type { Tenant, TenantPlan, TenantStatus, TenantQuotas, UsageRecord, BillingInfo, CloudConfig, PlanDefinition, StripeClient, } from './types.js';
|
|
7
|
+
export { QuotaExceededError, TenantNotFoundError, TenantSuspendedError, } from './types.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxF,YAAY,EACV,MAAM,EACN,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,EACd,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { TenantManager } from './tenant.js';
|
|
2
|
+
export { TenantIsolation } from './isolation.js';
|
|
3
|
+
export { QuotaEnforcer } from './quotas.js';
|
|
4
|
+
export { BillingManager } from './billing.js';
|
|
5
|
+
export { getPlanDefinition, getPlanQuotas, getAllPlans, isValidPlan } from './plans.js';
|
|
6
|
+
export { QuotaExceededError, TenantNotFoundError, TenantSuspendedError, } from './types.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA6B,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,eAAe,EAA6C,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,aAAa,EAA6B,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,cAAc,EAA8B,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAYxF,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Tenant, CloudConfig } from './types.js';
|
|
2
|
+
import type { TenantManager } from './tenant.js';
|
|
3
|
+
export interface TenantContext {
|
|
4
|
+
tenantId: string;
|
|
5
|
+
tenant: Tenant;
|
|
6
|
+
}
|
|
7
|
+
export interface IsolationOptions {
|
|
8
|
+
tenantManager: TenantManager;
|
|
9
|
+
config: CloudConfig;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* TenantIsolation provides middleware-like extraction of tenant context
|
|
13
|
+
* from JWT tokens and scoping of all operations to the tenant's data.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TenantIsolation {
|
|
16
|
+
private tenantManager;
|
|
17
|
+
constructor(options: IsolationOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Extract tenant context from a JWT payload.
|
|
20
|
+
* Validates the tenant exists and is active.
|
|
21
|
+
*/
|
|
22
|
+
extractTenant(jwtPayload: {
|
|
23
|
+
tenantId?: string;
|
|
24
|
+
sub?: string;
|
|
25
|
+
}): Promise<TenantContext>;
|
|
26
|
+
/**
|
|
27
|
+
* Scope a file path to the tenant's data directory.
|
|
28
|
+
* Prevents path traversal outside the tenant's sandbox.
|
|
29
|
+
*/
|
|
30
|
+
scopePath(tenant: Tenant, relativePath: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Validate that a tenant can access a given resource.
|
|
33
|
+
*/
|
|
34
|
+
validateAccess(context: TenantContext, resourceTenantId: string): boolean;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=isolation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isolation.d.ts","sourceRoot":"","sources":["../src/isolation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,OAAO,EAAE,gBAAgB;IAIrC;;;OAGG;IACG,aAAa,CAAC,UAAU,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAmB5F;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;IAUvD;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO;CAG1E"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TenantNotFoundError, TenantSuspendedError } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* TenantIsolation provides middleware-like extraction of tenant context
|
|
4
|
+
* from JWT tokens and scoping of all operations to the tenant's data.
|
|
5
|
+
*/
|
|
6
|
+
export class TenantIsolation {
|
|
7
|
+
tenantManager;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.tenantManager = options.tenantManager;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Extract tenant context from a JWT payload.
|
|
13
|
+
* Validates the tenant exists and is active.
|
|
14
|
+
*/
|
|
15
|
+
async extractTenant(jwtPayload) {
|
|
16
|
+
const tenantId = jwtPayload.tenantId || jwtPayload.sub;
|
|
17
|
+
if (!tenantId) {
|
|
18
|
+
throw new TenantNotFoundError('unknown');
|
|
19
|
+
}
|
|
20
|
+
const tenant = await this.tenantManager.get(tenantId);
|
|
21
|
+
if (tenant.status === 'suspended') {
|
|
22
|
+
throw new TenantSuspendedError(tenantId);
|
|
23
|
+
}
|
|
24
|
+
if (tenant.status === 'deleted') {
|
|
25
|
+
throw new TenantNotFoundError(tenantId);
|
|
26
|
+
}
|
|
27
|
+
return { tenantId, tenant };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Scope a file path to the tenant's data directory.
|
|
31
|
+
* Prevents path traversal outside the tenant's sandbox.
|
|
32
|
+
*/
|
|
33
|
+
scopePath(tenant, relativePath) {
|
|
34
|
+
const resolved = new URL(relativePath, `file://${tenant.dataDir}/`).pathname;
|
|
35
|
+
if (!resolved.startsWith(tenant.dataDir)) {
|
|
36
|
+
throw new Error('Path traversal attempt detected');
|
|
37
|
+
}
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate that a tenant can access a given resource.
|
|
42
|
+
*/
|
|
43
|
+
validateAccess(context, resourceTenantId) {
|
|
44
|
+
return context.tenantId === resourceTenantId;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=isolation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isolation.js","sourceRoot":"","sources":["../src/isolation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAavE;;;GAGG;AACH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 +1,6 @@
|
|
|
1
|
+
import type { PlanDefinition, TenantPlan, TenantQuotas } from './types.js';
|
|
2
|
+
export declare function getPlanDefinition(plan: TenantPlan): PlanDefinition;
|
|
3
|
+
export declare function getPlanQuotas(plan: TenantPlan): TenantQuotas;
|
|
4
|
+
export declare function getAllPlans(): PlanDefinition[];
|
|
5
|
+
export declare function isValidPlan(plan: string): plan is TenantPlan;
|
|
6
|
+
//# sourceMappingURL=plans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAqE3E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAElE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAE5D;AAED,wBAAgB,WAAW,IAAI,cAAc,EAAE,CAE9C;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,UAAU,CAE5D"}
|
package/dist/plans.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const PLAN_DEFINITIONS = {
|
|
2
|
+
free: {
|
|
3
|
+
plan: 'free',
|
|
4
|
+
name: 'Free',
|
|
5
|
+
priceMonthly: 0,
|
|
6
|
+
priceYearly: 0,
|
|
7
|
+
quotas: {
|
|
8
|
+
maxMessages: 100,
|
|
9
|
+
maxSessions: 3,
|
|
10
|
+
maxStorageMb: 50,
|
|
11
|
+
maxPlugins: 2,
|
|
12
|
+
maxBehaviors: 5,
|
|
13
|
+
maxChannels: 1,
|
|
14
|
+
maxAgents: 1,
|
|
15
|
+
},
|
|
16
|
+
features: ['Single channel', 'Basic vault', 'Community support'],
|
|
17
|
+
},
|
|
18
|
+
pro: {
|
|
19
|
+
plan: 'pro',
|
|
20
|
+
name: 'Pro',
|
|
21
|
+
priceMonthly: 19,
|
|
22
|
+
priceYearly: 190,
|
|
23
|
+
quotas: {
|
|
24
|
+
maxMessages: 5000,
|
|
25
|
+
maxSessions: 20,
|
|
26
|
+
maxStorageMb: 1024,
|
|
27
|
+
maxPlugins: 20,
|
|
28
|
+
maxBehaviors: 50,
|
|
29
|
+
maxChannels: 5,
|
|
30
|
+
maxAgents: 3,
|
|
31
|
+
},
|
|
32
|
+
features: ['Multi-channel', 'Cloud vault', 'Priority support', 'Custom behaviors'],
|
|
33
|
+
},
|
|
34
|
+
team: {
|
|
35
|
+
plan: 'team',
|
|
36
|
+
name: 'Team',
|
|
37
|
+
priceMonthly: 49,
|
|
38
|
+
priceYearly: 490,
|
|
39
|
+
quotas: {
|
|
40
|
+
maxMessages: 25000,
|
|
41
|
+
maxSessions: 100,
|
|
42
|
+
maxStorageMb: 5120,
|
|
43
|
+
maxPlugins: 50,
|
|
44
|
+
maxBehaviors: 200,
|
|
45
|
+
maxChannels: 20,
|
|
46
|
+
maxAgents: 10,
|
|
47
|
+
},
|
|
48
|
+
features: ['All Pro features', 'Team collaboration', 'Orchestration', 'Audit logs'],
|
|
49
|
+
},
|
|
50
|
+
enterprise: {
|
|
51
|
+
plan: 'enterprise',
|
|
52
|
+
name: 'Enterprise',
|
|
53
|
+
priceMonthly: 199,
|
|
54
|
+
priceYearly: 1990,
|
|
55
|
+
quotas: {
|
|
56
|
+
maxMessages: -1, // unlimited
|
|
57
|
+
maxSessions: -1,
|
|
58
|
+
maxStorageMb: -1,
|
|
59
|
+
maxPlugins: -1,
|
|
60
|
+
maxBehaviors: -1,
|
|
61
|
+
maxChannels: -1,
|
|
62
|
+
maxAgents: -1,
|
|
63
|
+
},
|
|
64
|
+
features: ['All Team features', 'Unlimited usage', 'SLA', 'Dedicated support', 'SSO'],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
export function getPlanDefinition(plan) {
|
|
68
|
+
return PLAN_DEFINITIONS[plan];
|
|
69
|
+
}
|
|
70
|
+
export function getPlanQuotas(plan) {
|
|
71
|
+
return PLAN_DEFINITIONS[plan].quotas;
|
|
72
|
+
}
|
|
73
|
+
export function getAllPlans() {
|
|
74
|
+
return Object.values(PLAN_DEFINITIONS);
|
|
75
|
+
}
|
|
76
|
+
export function isValidPlan(plan) {
|
|
77
|
+
return plan in PLAN_DEFINITIONS;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=plans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.js","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAuC;IAC3D,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,YAAY,EAAE,CAAC;QACf,WAAW,EAAE,CAAC;QACd,MAAM,EAAE;YACN,WAAW,EAAE,GAAG;YAChB,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,CAAC;YACb,YAAY,EAAE,CAAC;YACf,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,CAAC;SACb;QACD,QAAQ,EAAE,CAAC,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,CAAC;KACjE;IACD,GAAG,EAAE;QACH,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,KAAK;QACX,YAAY,EAAE,EAAE;QAChB,WAAW,EAAE,GAAG;QAChB,MAAM,EAAE;YACN,WAAW,EAAE,IAAI;YACjB,WAAW,EAAE,EAAE;YACf,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,EAAE;YACd,YAAY,EAAE,EAAE;YAChB,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,CAAC;SACb;QACD,QAAQ,EAAE,CAAC,eAAe,EAAE,aAAa,EAAE,kBAAkB,EAAE,kBAAkB,CAAC;KACnF;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,YAAY,EAAE,EAAE;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|
2
|
+
import type { TenantManager } from './tenant.js';
|
|
3
|
+
export interface QuotaEnforcerOptions {
|
|
4
|
+
tenantManager: TenantManager;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* QuotaEnforcer tracks usage against plan limits
|
|
8
|
+
* and throws QuotaExceededError when limits are breached.
|
|
9
|
+
*/
|
|
10
|
+
export declare class QuotaEnforcer {
|
|
11
|
+
private usage;
|
|
12
|
+
private tenantManager;
|
|
13
|
+
constructor(options: QuotaEnforcerOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Check whether a metric increment would exceed the quota.
|
|
16
|
+
* Throws QuotaExceededError if the limit would be breached.
|
|
17
|
+
*/
|
|
18
|
+
check(tenantId: string, metric: keyof TenantQuotas, increment?: number): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Record usage for a metric.
|
|
21
|
+
*/
|
|
22
|
+
record(tenantId: string, metric: string, value?: number): UsageRecord;
|
|
23
|
+
/**
|
|
24
|
+
* Get current usage for a specific metric.
|
|
25
|
+
*/
|
|
26
|
+
getUsage(tenantId: string, metric: string): number;
|
|
27
|
+
/**
|
|
28
|
+
* Get all usage for a tenant.
|
|
29
|
+
*/
|
|
30
|
+
getAllUsage(tenantId: string): Record<string, number>;
|
|
31
|
+
/**
|
|
32
|
+
* Reset usage for a tenant (e.g., at billing period start).
|
|
33
|
+
*/
|
|
34
|
+
resetUsage(tenantId: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get usage as a percentage of the quota limit.
|
|
37
|
+
*/
|
|
38
|
+
getUsagePercentage(tenantId: string, metric: keyof TenantQuotas): Promise<number>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=quotas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotas.d.ts","sourceRoot":"","sources":["../src/quotas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAA0C;IACvD,OAAO,CAAC,aAAa,CAAgB;gBAEzB,OAAO,EAAE,oBAAoB;IAIzC;;;OAGG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,EAAE,SAAS,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAcvF;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,WAAW;IAkBhE;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAIlD;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAWrD;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIlC;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;CAWxF"}
|