@iveri/contracts 0.94.0 → 0.95.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/dist/api/billing/billing-invoice-status.enum.d.ts +6 -0
- package/dist/api/billing/billing-invoice-status.enum.js +7 -0
- package/dist/api/billing/index.d.ts +2 -0
- package/dist/api/billing/index.js +2 -0
- package/dist/api/billing/usage.type.d.ts +103 -0
- package/dist/api/billing/usage.type.js +5 -0
- package/dist/api/chat/chat-refusal.enum.d.ts +7 -1
- package/dist/api/chat/chat-refusal.enum.js +6 -0
- package/dist/api/chat/chat-usage.type.d.ts +24 -0
- package/dist/api/chat/chat-usage.type.js +13 -0
- package/dist/api/chat/index.d.ts +1 -0
- package/dist/api/chat/index.js +1 -0
- package/dist/enum/user-permission.enum.d.ts +15 -0
- package/dist/enum/user-permission.enum.js +17 -0
- package/package.json +5 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Where an invoice stands. An invoice is a snapshot: its lines never change after it is issued. */
|
|
2
|
+
export var BillingInvoiceStatus;
|
|
3
|
+
(function (BillingInvoiceStatus) {
|
|
4
|
+
BillingInvoiceStatus["OPEN"] = "open";
|
|
5
|
+
BillingInvoiceStatus["PAID"] = "paid";
|
|
6
|
+
BillingInvoiceStatus["VOID"] = "void";
|
|
7
|
+
})(BillingInvoiceStatus || (BillingInvoiceStatus = {}));
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { IsoDateTime } from '../../type/iso-date-time.type.js';
|
|
2
|
+
import type { Nullable } from '../../type/nil.type.js';
|
|
3
|
+
import type { UUID } from '../../type/uuid.type.js';
|
|
4
|
+
import type { IveriProduct } from '../platform/iveri-product.enum.js';
|
|
5
|
+
import type { BillingInvoiceStatus } from './billing-invoice-status.enum.js';
|
|
6
|
+
/**
|
|
7
|
+
* A plan's limits for one calendar month in UTC: a metric's name to the most the plan allows, or null for no limit. A
|
|
8
|
+
* metric the plan does not name is not limited by it. Limits are data on the plan, edited like its price.
|
|
9
|
+
*/
|
|
10
|
+
export type UsageLimits = Record<string, Nullable<number>>;
|
|
11
|
+
/** A plan Iveri sells for a product, as a company reads it against its usage. */
|
|
12
|
+
export interface UsagePlan {
|
|
13
|
+
id: UUID;
|
|
14
|
+
code: string;
|
|
15
|
+
name: string;
|
|
16
|
+
product: IveriProduct;
|
|
17
|
+
/** The price for one month, in the currency's minor unit. */
|
|
18
|
+
amountMinor: number;
|
|
19
|
+
currency: string;
|
|
20
|
+
/**
|
|
21
|
+
* True while the price and the limits are placeholders nobody has decided. Every screen that shows the plan says so
|
|
22
|
+
* while it is true.
|
|
23
|
+
*/
|
|
24
|
+
isPlaceholder: boolean;
|
|
25
|
+
limits: UsageLimits;
|
|
26
|
+
}
|
|
27
|
+
/** One metric this month against the plan. */
|
|
28
|
+
export interface UsageMetricSummary {
|
|
29
|
+
metric: string;
|
|
30
|
+
quantity: number;
|
|
31
|
+
/** The plan's limit, or null when the plan does not limit it. */
|
|
32
|
+
limit: Nullable<number>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `GET /billing/usage/summary?product=` (a company's own) or `?tenantId=&product=` (behind `billing:usage:read-any`).
|
|
36
|
+
* The period is the current calendar month in UTC, its end exclusive. `plan` is null when nothing is on sale for the
|
|
37
|
+
* product, and then nothing is limited.
|
|
38
|
+
*/
|
|
39
|
+
export interface UsageSummary {
|
|
40
|
+
tenantId: UUID;
|
|
41
|
+
product: IveriProduct;
|
|
42
|
+
periodStart: IsoDateTime;
|
|
43
|
+
periodEnd: IsoDateTime;
|
|
44
|
+
plan: Nullable<UsagePlan>;
|
|
45
|
+
metrics: UsageMetricSummary[];
|
|
46
|
+
}
|
|
47
|
+
/** One line of an invoice, as it was when the invoice was issued. */
|
|
48
|
+
export interface UsageInvoiceLine {
|
|
49
|
+
description: string;
|
|
50
|
+
quantity: number;
|
|
51
|
+
unitAmountMinor: number;
|
|
52
|
+
amountMinor: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* An invoice as a company reads it. One built from a month's usage carries that month as its period; an invoice made
|
|
56
|
+
* by hand carries none.
|
|
57
|
+
*/
|
|
58
|
+
export interface UsageInvoice {
|
|
59
|
+
id: UUID;
|
|
60
|
+
number: string;
|
|
61
|
+
status: BillingInvoiceStatus;
|
|
62
|
+
currency: string;
|
|
63
|
+
totalMinor: number;
|
|
64
|
+
periodStart: Nullable<IsoDateTime>;
|
|
65
|
+
periodEnd: Nullable<IsoDateTime>;
|
|
66
|
+
issuedAt: IsoDateTime;
|
|
67
|
+
lines: UsageInvoiceLine[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `POST /billing/usage`. `tenantId` names the company the usage is for, and is refused with a 403 unless the token
|
|
71
|
+
* holds `billing:usage:record-any` and comes from Iveri's operator workspace. Without it the usage is the token's own
|
|
72
|
+
* company's. The `Idempotency-Key` header is unique per company the usage is for.
|
|
73
|
+
*/
|
|
74
|
+
export interface RecordUsageRequest {
|
|
75
|
+
tenantId?: UUID;
|
|
76
|
+
metric: string;
|
|
77
|
+
periodStart: IsoDateTime;
|
|
78
|
+
periodEnd: IsoDateTime;
|
|
79
|
+
quantity: number;
|
|
80
|
+
source: string;
|
|
81
|
+
}
|
|
82
|
+
/** `PUT /platform/usage-plans/:tenantId`: the plan a company is on for a product, from the next request on. */
|
|
83
|
+
export interface AssignUsagePlanRequest {
|
|
84
|
+
product: IveriProduct;
|
|
85
|
+
planCode: string;
|
|
86
|
+
}
|
|
87
|
+
/** Which plan a company is on for a product, and whether an operator chose it or it is the product's default. */
|
|
88
|
+
export interface UsagePlanAssignment {
|
|
89
|
+
tenantId: UUID;
|
|
90
|
+
product: IveriProduct;
|
|
91
|
+
plan: UsagePlan;
|
|
92
|
+
isDefault: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Carried in the `details` of the 403 a product answers when a plan's limit refuses something, beside the product's
|
|
96
|
+
* own reason, so a client can say which limit was reached.
|
|
97
|
+
*/
|
|
98
|
+
export declare const USAGE_LIMIT_REACHED_REASON = "usage-limit-reached";
|
|
99
|
+
export interface UsageLimitReachedDetails {
|
|
100
|
+
reason: typeof USAGE_LIMIT_REACHED_REASON;
|
|
101
|
+
metric: string;
|
|
102
|
+
limit: number;
|
|
103
|
+
}
|
|
@@ -15,5 +15,11 @@ export declare enum ChatRefusal {
|
|
|
15
15
|
INVITATION_EXPIRED = "invitation-expired",
|
|
16
16
|
SUSPENDED = "suspended",
|
|
17
17
|
ATTACHMENT_REFUSED = "attachment-refused",
|
|
18
|
-
REQUEST_PENDING = "request-pending"
|
|
18
|
+
REQUEST_PENDING = "request-pending",
|
|
19
|
+
/**
|
|
20
|
+
* The app's plan does not allow it this month: a new user over the monthly-active-user limit, or a message over the
|
|
21
|
+
* message limit. The value is `USAGE_LIMIT_REACHED_REASON` from `@iveri/contracts/billing`, and the details name the
|
|
22
|
+
* metric and the limit.
|
|
23
|
+
*/
|
|
24
|
+
USAGE_LIMIT = "usage-limit-reached"
|
|
19
25
|
}
|
|
@@ -17,4 +17,10 @@ export var ChatRefusal;
|
|
|
17
17
|
ChatRefusal["SUSPENDED"] = "suspended";
|
|
18
18
|
ChatRefusal["ATTACHMENT_REFUSED"] = "attachment-refused";
|
|
19
19
|
ChatRefusal["REQUEST_PENDING"] = "request-pending";
|
|
20
|
+
/**
|
|
21
|
+
* The app's plan does not allow it this month: a new user over the monthly-active-user limit, or a message over the
|
|
22
|
+
* message limit. The value is `USAGE_LIMIT_REACHED_REASON` from `@iveri/contracts/billing`, and the details name the
|
|
23
|
+
* metric and the limit.
|
|
24
|
+
*/
|
|
25
|
+
ChatRefusal["USAGE_LIMIT"] = "usage-limit-reached";
|
|
20
26
|
})(ChatRefusal || (ChatRefusal = {}));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Nullable } from '../../type/nil.type.js';
|
|
2
|
+
import type { UUID } from '../../type/uuid.type.js';
|
|
3
|
+
import type { UsageInvoice, UsageSummary } from '../billing/usage.type.js';
|
|
4
|
+
/**
|
|
5
|
+
* What Baasi meters for each app, as the metric names billing stores and a plan's limits name. A month is a calendar
|
|
6
|
+
* month in UTC. Iveri's own product tenants, which are not apps, are not metered.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum ChatUsageMetric {
|
|
9
|
+
/** People who used the app at least once this month, each counted once. */
|
|
10
|
+
MONTHLY_ACTIVE_USERS = "chat.monthly-active-users",
|
|
11
|
+
/** Messages somebody wrote this month. A product's or a group's own notices are not counted. */
|
|
12
|
+
MESSAGES = "chat.messages",
|
|
13
|
+
/** Bytes of attachments stored this month. */
|
|
14
|
+
STORED_BYTES = "chat.stored-bytes"
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `GET /apps/:appId/usage`: the app's month against its plan, and the invoices built from its usage. `summary` is null
|
|
18
|
+
* when billing could not be asked, which the console says rather than showing zeroes.
|
|
19
|
+
*/
|
|
20
|
+
export interface ChatAppUsage {
|
|
21
|
+
appId: UUID;
|
|
22
|
+
summary: Nullable<UsageSummary>;
|
|
23
|
+
invoices: UsageInvoice[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Baasi meters for each app, as the metric names billing stores and a plan's limits name. A month is a calendar
|
|
3
|
+
* month in UTC. Iveri's own product tenants, which are not apps, are not metered.
|
|
4
|
+
*/
|
|
5
|
+
export var ChatUsageMetric;
|
|
6
|
+
(function (ChatUsageMetric) {
|
|
7
|
+
/** People who used the app at least once this month, each counted once. */
|
|
8
|
+
ChatUsageMetric["MONTHLY_ACTIVE_USERS"] = "chat.monthly-active-users";
|
|
9
|
+
/** Messages somebody wrote this month. A product's or a group's own notices are not counted. */
|
|
10
|
+
ChatUsageMetric["MESSAGES"] = "chat.messages";
|
|
11
|
+
/** Bytes of attachments stored this month. */
|
|
12
|
+
ChatUsageMetric["STORED_BYTES"] = "chat.stored-bytes";
|
|
13
|
+
})(ChatUsageMetric || (ChatUsageMetric = {}));
|
package/dist/api/chat/index.d.ts
CHANGED
|
@@ -28,5 +28,6 @@ export * from './chat-realtime.type.js';
|
|
|
28
28
|
export * from './chat-refusal.enum.js';
|
|
29
29
|
export * from './chat-report-reason.enum.js';
|
|
30
30
|
export * from './chat-report-target.enum.js';
|
|
31
|
+
export * from './chat-usage.type.js';
|
|
31
32
|
export * from './chat-webhook-delivery-status.enum.js';
|
|
32
33
|
export * from './chat-webhook-event.enum.js';
|
package/dist/api/chat/index.js
CHANGED
|
@@ -28,5 +28,6 @@ export * from './chat-realtime.type.js';
|
|
|
28
28
|
export * from './chat-refusal.enum.js';
|
|
29
29
|
export * from './chat-report-reason.enum.js';
|
|
30
30
|
export * from './chat-report-target.enum.js';
|
|
31
|
+
export * from './chat-usage.type.js';
|
|
31
32
|
export * from './chat-webhook-delivery-status.enum.js';
|
|
32
33
|
export * from './chat-webhook-event.enum.js';
|
|
@@ -238,6 +238,18 @@ export declare enum UserPermission {
|
|
|
238
238
|
BILLING_USAGE_READ = "billing:usage:read",
|
|
239
239
|
/** Record billable usage on behalf of a tenant service. */
|
|
240
240
|
BILLING_USAGE_RECORD = "billing:usage:record",
|
|
241
|
+
/**
|
|
242
|
+
* Record usage for a company the request names in `tenantId`, rather than the token's own. A platform permission:
|
|
243
|
+
* held only by a service credential in Iveri's operator workspace, so `chat-api` can meter each app it hosts
|
|
244
|
+
* without a key in every app's tenant. The request is authorized and audited as acting for the company it names.
|
|
245
|
+
*/
|
|
246
|
+
BILLING_USAGE_RECORD_ANY = "billing:usage:record-any",
|
|
247
|
+
/**
|
|
248
|
+
* Read a company the request names in `tenantId`: its usage this month against its plan, and the invoices billed
|
|
249
|
+
* from that usage. A platform permission, like `record-any`: `chat-api` holds it to enforce an app's limits and to
|
|
250
|
+
* show the app's owner the app's usage.
|
|
251
|
+
*/
|
|
252
|
+
BILLING_USAGE_READ_ANY = "billing:usage:read-any",
|
|
241
253
|
/** Read payment sessions and their provider-neutral status. */
|
|
242
254
|
BILLING_PAYMENT_READ = "billing:payment:read",
|
|
243
255
|
/**
|
|
@@ -637,6 +649,9 @@ export declare enum UserPermission {
|
|
|
637
649
|
* The permissions that act across companies. They are granted only inside Iveri's own operator workspace, which each
|
|
638
650
|
* service knows as `PLATFORM_TENANT_ID`, and a service honours one only from that workspace: identity refuses them on
|
|
639
651
|
* any other workspace's role or key, and a route that uses one also checks where the token came from.
|
|
652
|
+
*
|
|
653
|
+
* Two shapes: `platform:*`, the operator console's own, and a service's `*-any`, where a request names the company it
|
|
654
|
+
* acts for in an explicit `tenantId` (option D of `iveri-infra/docs/cross-tenant-service-credential-decision.md`).
|
|
640
655
|
*/
|
|
641
656
|
export declare const PLATFORM_PERMISSIONS: readonly UserPermission[];
|
|
642
657
|
/** Whether a permission acts across companies, and so may only be held in Iveri's operator workspace. */
|
|
@@ -285,6 +285,18 @@ export var UserPermission;
|
|
|
285
285
|
UserPermission["BILLING_USAGE_READ"] = "billing:usage:read";
|
|
286
286
|
/** Record billable usage on behalf of a tenant service. */
|
|
287
287
|
UserPermission["BILLING_USAGE_RECORD"] = "billing:usage:record";
|
|
288
|
+
/**
|
|
289
|
+
* Record usage for a company the request names in `tenantId`, rather than the token's own. A platform permission:
|
|
290
|
+
* held only by a service credential in Iveri's operator workspace, so `chat-api` can meter each app it hosts
|
|
291
|
+
* without a key in every app's tenant. The request is authorized and audited as acting for the company it names.
|
|
292
|
+
*/
|
|
293
|
+
UserPermission["BILLING_USAGE_RECORD_ANY"] = "billing:usage:record-any";
|
|
294
|
+
/**
|
|
295
|
+
* Read a company the request names in `tenantId`: its usage this month against its plan, and the invoices billed
|
|
296
|
+
* from that usage. A platform permission, like `record-any`: `chat-api` holds it to enforce an app's limits and to
|
|
297
|
+
* show the app's owner the app's usage.
|
|
298
|
+
*/
|
|
299
|
+
UserPermission["BILLING_USAGE_READ_ANY"] = "billing:usage:read-any";
|
|
288
300
|
// ── Payment ────────────────────────────────────────────────────────────
|
|
289
301
|
/** Read payment sessions and their provider-neutral status. */
|
|
290
302
|
UserPermission["BILLING_PAYMENT_READ"] = "billing:payment:read";
|
|
@@ -704,6 +716,9 @@ export var UserPermission;
|
|
|
704
716
|
* The permissions that act across companies. They are granted only inside Iveri's own operator workspace, which each
|
|
705
717
|
* service knows as `PLATFORM_TENANT_ID`, and a service honours one only from that workspace: identity refuses them on
|
|
706
718
|
* any other workspace's role or key, and a route that uses one also checks where the token came from.
|
|
719
|
+
*
|
|
720
|
+
* Two shapes: `platform:*`, the operator console's own, and a service's `*-any`, where a request names the company it
|
|
721
|
+
* acts for in an explicit `tenantId` (option D of `iveri-infra/docs/cross-tenant-service-credential-decision.md`).
|
|
707
722
|
*/
|
|
708
723
|
export const PLATFORM_PERMISSIONS = Object.freeze([
|
|
709
724
|
UserPermission.PLATFORM_TENANT_READ,
|
|
@@ -712,6 +727,8 @@ export const PLATFORM_PERMISSIONS = Object.freeze([
|
|
|
712
727
|
UserPermission.PLATFORM_LICENCE_MANAGE,
|
|
713
728
|
UserPermission.PLATFORM_LICENCE_CHECK,
|
|
714
729
|
UserPermission.PLATFORM_BACKOFFICE_READ,
|
|
730
|
+
UserPermission.BILLING_USAGE_RECORD_ANY,
|
|
731
|
+
UserPermission.BILLING_USAGE_READ_ANY,
|
|
715
732
|
]);
|
|
716
733
|
/** Whether a permission acts across companies, and so may only be held in Iveri's operator workspace. */
|
|
717
734
|
export function isPlatformPermission(permission) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iveri/contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.95.0",
|
|
4
4
|
"description": "Wire contracts shared by every Iveri backend and frontend. Zero runtime dependencies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -84,6 +84,10 @@
|
|
|
84
84
|
"types": "./dist/api/taxi/index.d.ts",
|
|
85
85
|
"default": "./dist/api/taxi/index.js"
|
|
86
86
|
},
|
|
87
|
+
"./billing": {
|
|
88
|
+
"types": "./dist/api/billing/index.d.ts",
|
|
89
|
+
"default": "./dist/api/billing/index.js"
|
|
90
|
+
},
|
|
87
91
|
"./package.json": "./package.json"
|
|
88
92
|
},
|
|
89
93
|
"sideEffects": false,
|