@baukit/suite-client 0.11.3 → 0.12.1
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/platform.d.ts +98 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +27 -0
- package/dist/platform.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/platform.test.ts +95 -0
- package/src/platform.ts +117 -0
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Platform event types without the hub's configured prefix, in catalog order. */
|
|
2
|
+
export declare const PLATFORM_EVENT_TYPES: readonly ["entitlements.changed", "account.updated", "account.erasure_requested", "preferences.changed", "onboarding.shared", "family.membership_changed", "organization.membership_changed", "seat.changed", "organization.updated", "credits.changed"];
|
|
3
|
+
export type PlatformEventType = (typeof PLATFORM_EVENT_TYPES)[number];
|
|
4
|
+
export interface SubjectRevision {
|
|
5
|
+
readonly suiteSubject: string;
|
|
6
|
+
readonly revision: number;
|
|
7
|
+
}
|
|
8
|
+
export interface PlatformEventPayloads {
|
|
9
|
+
readonly 'entitlements.changed': SubjectRevision & {
|
|
10
|
+
readonly product: string;
|
|
11
|
+
};
|
|
12
|
+
readonly 'account.updated': SubjectRevision;
|
|
13
|
+
readonly 'account.erasure_requested': {
|
|
14
|
+
readonly suiteSubject: string;
|
|
15
|
+
readonly erasureId: string;
|
|
16
|
+
};
|
|
17
|
+
readonly 'preferences.changed': SubjectRevision;
|
|
18
|
+
readonly 'onboarding.shared': SubjectRevision & {
|
|
19
|
+
readonly profileVersion: number;
|
|
20
|
+
};
|
|
21
|
+
readonly 'family.membership_changed': SubjectRevision & {
|
|
22
|
+
readonly familyId: string;
|
|
23
|
+
readonly status: 'active' | 'removed' | 'left';
|
|
24
|
+
readonly familyRole: 'organizer' | 'member';
|
|
25
|
+
};
|
|
26
|
+
readonly 'organization.membership_changed': {
|
|
27
|
+
readonly organizationId: string;
|
|
28
|
+
readonly suiteSubject: string;
|
|
29
|
+
readonly status: 'active' | 'suspended' | 'removed';
|
|
30
|
+
readonly accountRole: 'owner' | 'admin' | 'billing' | 'member';
|
|
31
|
+
};
|
|
32
|
+
readonly 'seat.changed': {
|
|
33
|
+
readonly organizationId: string;
|
|
34
|
+
readonly product: string;
|
|
35
|
+
readonly suiteSubject: string;
|
|
36
|
+
readonly assigned: boolean;
|
|
37
|
+
};
|
|
38
|
+
/** The envelope `userId` is the organization ID. */
|
|
39
|
+
readonly 'organization.updated': {
|
|
40
|
+
readonly organizationId: string;
|
|
41
|
+
readonly revision: number;
|
|
42
|
+
};
|
|
43
|
+
readonly 'credits.changed': SubjectRevision & {
|
|
44
|
+
readonly wallet: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export type CreditReservationStatus = 'pending' | 'settled' | 'released' | 'expired';
|
|
48
|
+
export interface CreditReservation {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly wallet: string;
|
|
51
|
+
readonly amount: number;
|
|
52
|
+
readonly charged: number | null;
|
|
53
|
+
readonly status: CreditReservationStatus;
|
|
54
|
+
/** Unix seconds. */
|
|
55
|
+
readonly expiresAt: number;
|
|
56
|
+
}
|
|
57
|
+
export interface CreditPool {
|
|
58
|
+
/** `family` or `organization`. */
|
|
59
|
+
readonly ownerKind: string;
|
|
60
|
+
readonly available: number;
|
|
61
|
+
}
|
|
62
|
+
export interface CreditGrant {
|
|
63
|
+
readonly granted: number;
|
|
64
|
+
readonly used: number;
|
|
65
|
+
readonly available: number;
|
|
66
|
+
}
|
|
67
|
+
export interface CreditPack {
|
|
68
|
+
readonly remaining: number;
|
|
69
|
+
/** Unix seconds. */
|
|
70
|
+
readonly expiresAt: number;
|
|
71
|
+
}
|
|
72
|
+
export interface CreditBalance {
|
|
73
|
+
readonly suiteSubject: string;
|
|
74
|
+
readonly wallet: string;
|
|
75
|
+
readonly available: number;
|
|
76
|
+
/** Counts `credits.changed` events for this wallet. */
|
|
77
|
+
readonly revision: number;
|
|
78
|
+
readonly pools: readonly CreditPool[];
|
|
79
|
+
readonly grant: CreditGrant;
|
|
80
|
+
readonly packs: readonly CreditPack[];
|
|
81
|
+
}
|
|
82
|
+
export type OrganizationStatus = 'active' | 'suspended';
|
|
83
|
+
export interface OrganizationSummary {
|
|
84
|
+
readonly organizationId: string;
|
|
85
|
+
readonly status: OrganizationStatus;
|
|
86
|
+
readonly productId: string;
|
|
87
|
+
readonly tier: string;
|
|
88
|
+
readonly features: readonly string[];
|
|
89
|
+
/** `null` for a per-organization plan without a seat limit. */
|
|
90
|
+
readonly paidQuantity: number | null;
|
|
91
|
+
readonly assignedSeats: number;
|
|
92
|
+
/** Matches the latest `organization.updated` event, or 0 before the first. */
|
|
93
|
+
readonly revision: number;
|
|
94
|
+
}
|
|
95
|
+
/** Hub error codes the Rust credits port maps to typed errors. */
|
|
96
|
+
export declare const PLATFORM_CREDIT_ERROR_CODES: readonly ["account_inactive", "credits_amount_invalid", "credits_idempotency_conflict", "credits_idempotency_key_invalid", "credits_insufficient", "credits_reservation_expired", "credits_reservation_not_found", "credits_wallet_unknown", "platform_credits_unavailable", "platform_subject_not_found"];
|
|
97
|
+
export type PlatformCreditErrorCode = (typeof PLATFORM_CREDIT_ERROR_CODES)[number];
|
|
98
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,eAAO,MAAM,oBAAoB,0PAWvB,CAAC;AACX,MAAM,MAAM,iBAAiB,G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,aAAa;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;CACvC;AAED,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,WAAW,CAAC;AACxD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,+DAA+D;IAC/D,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,kEAAkE;AAClE,eAAO,MAAM,2BAA2B,4SAW9B,CAAC;AACX,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Platform event types without the hub's configured prefix, in catalog order. */
|
|
2
|
+
export const PLATFORM_EVENT_TYPES = [
|
|
3
|
+
'entitlements.changed',
|
|
4
|
+
'account.updated',
|
|
5
|
+
'account.erasure_requested',
|
|
6
|
+
'preferences.changed',
|
|
7
|
+
'onboarding.shared',
|
|
8
|
+
'family.membership_changed',
|
|
9
|
+
'organization.membership_changed',
|
|
10
|
+
'seat.changed',
|
|
11
|
+
'organization.updated',
|
|
12
|
+
'credits.changed',
|
|
13
|
+
];
|
|
14
|
+
/** Hub error codes the Rust credits port maps to typed errors. */
|
|
15
|
+
export const PLATFORM_CREDIT_ERROR_CODES = [
|
|
16
|
+
'account_inactive',
|
|
17
|
+
'credits_amount_invalid',
|
|
18
|
+
'credits_idempotency_conflict',
|
|
19
|
+
'credits_idempotency_key_invalid',
|
|
20
|
+
'credits_insufficient',
|
|
21
|
+
'credits_reservation_expired',
|
|
22
|
+
'credits_reservation_not_found',
|
|
23
|
+
'credits_wallet_unknown',
|
|
24
|
+
'platform_credits_unavailable',
|
|
25
|
+
'platform_subject_not_found',
|
|
26
|
+
];
|
|
27
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,sBAAsB;IACtB,iBAAiB;IACjB,2BAA2B;IAC3B,qBAAqB;IACrB,mBAAmB;IACnB,2BAA2B;IAC3B,iCAAiC;IACjC,cAAc;IACd,sBAAsB;IACtB,iBAAiB;CACT,CAAC;AA2FX,kEAAkE;AAClE,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,kBAAkB;IAClB,wBAAwB;IACxB,8BAA8B;IAC9B,iCAAiC;IACjC,sBAAsB;IACtB,6BAA6B;IAC7B,+BAA+B;IAC/B,wBAAwB;IACxB,8BAA8B;IAC9B,4BAA4B;CACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baukit/suite-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Headless suite linking, authorization state and connected app clients.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrick Koss",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"vitest": "5.0.3"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@baukit/integrations-client": "^0.
|
|
73
|
-
"@baukit/localization-core": "^0.
|
|
72
|
+
"@baukit/integrations-client": "^0.12.1",
|
|
73
|
+
"@baukit/localization-core": "^0.12.1"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@noble/curves": "1.9.7"
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
import {
|
|
4
|
+
PLATFORM_CREDIT_ERROR_CODES,
|
|
5
|
+
PLATFORM_EVENT_TYPES,
|
|
6
|
+
type CreditBalance,
|
|
7
|
+
type CreditReservation,
|
|
8
|
+
type OrganizationSummary,
|
|
9
|
+
type PlatformEventPayloads,
|
|
10
|
+
} from './index.js';
|
|
11
|
+
|
|
12
|
+
function fixture(path: string): unknown {
|
|
13
|
+
return JSON.parse(readFileSync(new URL(`../../../../fixtures/${path}`, import.meta.url), 'utf8'));
|
|
14
|
+
}
|
|
15
|
+
interface Catalog {
|
|
16
|
+
types: { type: string; fields: { name: string }[] }[];
|
|
17
|
+
}
|
|
18
|
+
interface Envelope {
|
|
19
|
+
type: string;
|
|
20
|
+
payload: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
interface Recorded {
|
|
23
|
+
responses: Record<string, { status: number; body: unknown }>;
|
|
24
|
+
}
|
|
25
|
+
const catalog = fixture('platform-events/v1/catalog.json') as Catalog;
|
|
26
|
+
const envelopes = fixture('platform-events/v1/envelopes.json') as Envelope[];
|
|
27
|
+
const recorded = fixture('platform-api/v1/responses.json') as Recorded;
|
|
28
|
+
const suffix = (type: string): string => type.slice(type.indexOf('.') + 1);
|
|
29
|
+
const body = (name: string): unknown => recorded.responses[name]?.body;
|
|
30
|
+
|
|
31
|
+
it('lists every platform catalog event type', () => {
|
|
32
|
+
expect(catalog.types.map((entry) => suffix(entry.type))).toEqual(PLATFORM_EVENT_TYPES);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('types the new event payloads with the catalog fields', () => {
|
|
36
|
+
const organization: PlatformEventPayloads['organization.updated'] = {
|
|
37
|
+
organizationId: '018f1234-5678-7abc-8def-012345678901',
|
|
38
|
+
revision: 7,
|
|
39
|
+
};
|
|
40
|
+
const credits: PlatformEventPayloads['credits.changed'] = {
|
|
41
|
+
suiteSubject: 'suite|person-123',
|
|
42
|
+
wallet: 'hebkit',
|
|
43
|
+
revision: 4,
|
|
44
|
+
};
|
|
45
|
+
for (const [type, payload] of [
|
|
46
|
+
['organization.updated', organization],
|
|
47
|
+
['credits.changed', credits],
|
|
48
|
+
] as const) {
|
|
49
|
+
const entry = catalog.types.find((candidate) => suffix(candidate.type) === type);
|
|
50
|
+
expect(Object.keys(payload).sort()).toEqual(entry?.fields.map((field) => field.name).sort());
|
|
51
|
+
expect(envelopes.find((envelope) => suffix(envelope.type) === type)?.payload).toEqual(payload);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('matches recorded hub credit and organization responses', () => {
|
|
56
|
+
const balance: CreditBalance = {
|
|
57
|
+
suiteSubject: 'suite-dev|alice',
|
|
58
|
+
wallet: 'hebkit',
|
|
59
|
+
available: 10,
|
|
60
|
+
revision: 0,
|
|
61
|
+
pools: [],
|
|
62
|
+
grant: { granted: 0, used: 0, available: 0 },
|
|
63
|
+
packs: [{ remaining: 10, expiresAt: 1795392000 }],
|
|
64
|
+
};
|
|
65
|
+
const pending: CreditReservation = {
|
|
66
|
+
id: '018f1234-5678-7abc-8def-012345678901',
|
|
67
|
+
wallet: 'hebkit',
|
|
68
|
+
amount: 4,
|
|
69
|
+
charged: null,
|
|
70
|
+
status: 'pending',
|
|
71
|
+
expiresAt: 1792800900,
|
|
72
|
+
};
|
|
73
|
+
const summary: OrganizationSummary = {
|
|
74
|
+
organizationId: '018f1234-5678-7abc-8def-012345678901',
|
|
75
|
+
status: 'active',
|
|
76
|
+
productId: 'runtime_analyzer',
|
|
77
|
+
tier: 'professional',
|
|
78
|
+
features: [],
|
|
79
|
+
paidQuantity: 4,
|
|
80
|
+
assignedSeats: 1,
|
|
81
|
+
revision: 1,
|
|
82
|
+
};
|
|
83
|
+
expect(body('creditBalance')).toEqual(balance);
|
|
84
|
+
expect(body('reservationPending')).toEqual(pending);
|
|
85
|
+
expect(body('reservationSettled')).toEqual({ ...pending, charged: 4, status: 'settled' });
|
|
86
|
+
expect(body('organizationSummary')).toEqual(summary);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('lists the recorded credit error codes', () => {
|
|
90
|
+
const codes = Object.values(recorded.responses)
|
|
91
|
+
.map((entry) => (entry.body as { error?: { code: string } }).error?.code)
|
|
92
|
+
.filter((code): code is string => code !== undefined);
|
|
93
|
+
for (const code of PLATFORM_CREDIT_ERROR_CODES) expect(codes).toContain(code);
|
|
94
|
+
expect([...PLATFORM_CREDIT_ERROR_CODES].sort()).toEqual(PLATFORM_CREDIT_ERROR_CODES);
|
|
95
|
+
});
|
package/src/platform.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Platform event types without the hub's configured prefix, in catalog order. */
|
|
2
|
+
export const PLATFORM_EVENT_TYPES = [
|
|
3
|
+
'entitlements.changed',
|
|
4
|
+
'account.updated',
|
|
5
|
+
'account.erasure_requested',
|
|
6
|
+
'preferences.changed',
|
|
7
|
+
'onboarding.shared',
|
|
8
|
+
'family.membership_changed',
|
|
9
|
+
'organization.membership_changed',
|
|
10
|
+
'seat.changed',
|
|
11
|
+
'organization.updated',
|
|
12
|
+
'credits.changed',
|
|
13
|
+
] as const;
|
|
14
|
+
export type PlatformEventType = (typeof PLATFORM_EVENT_TYPES)[number];
|
|
15
|
+
|
|
16
|
+
export interface SubjectRevision {
|
|
17
|
+
readonly suiteSubject: string;
|
|
18
|
+
readonly revision: number;
|
|
19
|
+
}
|
|
20
|
+
export interface PlatformEventPayloads {
|
|
21
|
+
readonly 'entitlements.changed': SubjectRevision & { readonly product: string };
|
|
22
|
+
readonly 'account.updated': SubjectRevision;
|
|
23
|
+
readonly 'account.erasure_requested': {
|
|
24
|
+
readonly suiteSubject: string;
|
|
25
|
+
readonly erasureId: string;
|
|
26
|
+
};
|
|
27
|
+
readonly 'preferences.changed': SubjectRevision;
|
|
28
|
+
readonly 'onboarding.shared': SubjectRevision & { readonly profileVersion: number };
|
|
29
|
+
readonly 'family.membership_changed': SubjectRevision & {
|
|
30
|
+
readonly familyId: string;
|
|
31
|
+
readonly status: 'active' | 'removed' | 'left';
|
|
32
|
+
readonly familyRole: 'organizer' | 'member';
|
|
33
|
+
};
|
|
34
|
+
readonly 'organization.membership_changed': {
|
|
35
|
+
readonly organizationId: string;
|
|
36
|
+
readonly suiteSubject: string;
|
|
37
|
+
readonly status: 'active' | 'suspended' | 'removed';
|
|
38
|
+
readonly accountRole: 'owner' | 'admin' | 'billing' | 'member';
|
|
39
|
+
};
|
|
40
|
+
readonly 'seat.changed': {
|
|
41
|
+
readonly organizationId: string;
|
|
42
|
+
readonly product: string;
|
|
43
|
+
readonly suiteSubject: string;
|
|
44
|
+
readonly assigned: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** The envelope `userId` is the organization ID. */
|
|
47
|
+
readonly 'organization.updated': {
|
|
48
|
+
readonly organizationId: string;
|
|
49
|
+
readonly revision: number;
|
|
50
|
+
};
|
|
51
|
+
readonly 'credits.changed': SubjectRevision & { readonly wallet: string };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type CreditReservationStatus = 'pending' | 'settled' | 'released' | 'expired';
|
|
55
|
+
export interface CreditReservation {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly wallet: string;
|
|
58
|
+
readonly amount: number;
|
|
59
|
+
readonly charged: number | null;
|
|
60
|
+
readonly status: CreditReservationStatus;
|
|
61
|
+
/** Unix seconds. */
|
|
62
|
+
readonly expiresAt: number;
|
|
63
|
+
}
|
|
64
|
+
export interface CreditPool {
|
|
65
|
+
/** `family` or `organization`. */
|
|
66
|
+
readonly ownerKind: string;
|
|
67
|
+
readonly available: number;
|
|
68
|
+
}
|
|
69
|
+
export interface CreditGrant {
|
|
70
|
+
readonly granted: number;
|
|
71
|
+
readonly used: number;
|
|
72
|
+
readonly available: number;
|
|
73
|
+
}
|
|
74
|
+
export interface CreditPack {
|
|
75
|
+
readonly remaining: number;
|
|
76
|
+
/** Unix seconds. */
|
|
77
|
+
readonly expiresAt: number;
|
|
78
|
+
}
|
|
79
|
+
export interface CreditBalance {
|
|
80
|
+
readonly suiteSubject: string;
|
|
81
|
+
readonly wallet: string;
|
|
82
|
+
readonly available: number;
|
|
83
|
+
/** Counts `credits.changed` events for this wallet. */
|
|
84
|
+
readonly revision: number;
|
|
85
|
+
readonly pools: readonly CreditPool[];
|
|
86
|
+
readonly grant: CreditGrant;
|
|
87
|
+
readonly packs: readonly CreditPack[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type OrganizationStatus = 'active' | 'suspended';
|
|
91
|
+
export interface OrganizationSummary {
|
|
92
|
+
readonly organizationId: string;
|
|
93
|
+
readonly status: OrganizationStatus;
|
|
94
|
+
readonly productId: string;
|
|
95
|
+
readonly tier: string;
|
|
96
|
+
readonly features: readonly string[];
|
|
97
|
+
/** `null` for a per-organization plan without a seat limit. */
|
|
98
|
+
readonly paidQuantity: number | null;
|
|
99
|
+
readonly assignedSeats: number;
|
|
100
|
+
/** Matches the latest `organization.updated` event, or 0 before the first. */
|
|
101
|
+
readonly revision: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Hub error codes the Rust credits port maps to typed errors. */
|
|
105
|
+
export const PLATFORM_CREDIT_ERROR_CODES = [
|
|
106
|
+
'account_inactive',
|
|
107
|
+
'credits_amount_invalid',
|
|
108
|
+
'credits_idempotency_conflict',
|
|
109
|
+
'credits_idempotency_key_invalid',
|
|
110
|
+
'credits_insufficient',
|
|
111
|
+
'credits_reservation_expired',
|
|
112
|
+
'credits_reservation_not_found',
|
|
113
|
+
'credits_wallet_unknown',
|
|
114
|
+
'platform_credits_unavailable',
|
|
115
|
+
'platform_subject_not_found',
|
|
116
|
+
] as const;
|
|
117
|
+
export type PlatformCreditErrorCode = (typeof PLATFORM_CREDIT_ERROR_CODES)[number];
|