@omnicross/contracts 0.1.2 → 0.1.4
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 +21 -21
- package/README.md +15 -15
- package/dist/account-tokens-types.d.cts +157 -1
- package/dist/account-tokens-types.d.ts +157 -1
- package/dist/audit-types.cjs +36 -0
- package/dist/audit-types.d.cts +98 -0
- package/dist/audit-types.d.ts +98 -0
- package/dist/audit-types.js +11 -0
- package/dist/billing-types.cjs +33 -0
- package/dist/billing-types.d.cts +98 -0
- package/dist/billing-types.d.ts +98 -0
- package/dist/billing-types.js +8 -0
- package/dist/canonical-models.d.cts +1 -1
- package/dist/canonical-models.d.ts +1 -1
- package/dist/endpoint-resolver.d.cts +1 -1
- package/dist/endpoint-resolver.d.ts +1 -1
- package/dist/health-logging-types.cjs +32 -0
- package/dist/health-logging-types.d.cts +68 -0
- package/dist/health-logging-types.d.ts +68 -0
- package/dist/health-logging-types.js +7 -0
- package/dist/index.cjs +63 -0
- package/dist/index.d.cts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +55 -0
- package/dist/{llm-config-D1jKQLVp.d.ts → llm-config-CKOaFFdy.d.ts} +8 -1
- package/dist/{llm-config-CQjOimv2.d.cts → llm-config-DeWNx1ig.d.cts} +8 -1
- package/dist/llm-config.d.cts +1 -1
- package/dist/llm-config.d.ts +1 -1
- package/dist/provider-presets/index.d.cts +2 -2
- package/dist/provider-presets/index.d.ts +2 -2
- package/dist/subscription-model-catalog.cjs +40 -0
- package/dist/subscription-model-catalog.d.cts +34 -0
- package/dist/subscription-model-catalog.d.ts +34 -0
- package/dist/subscription-model-catalog.js +14 -0
- package/dist/thinking-config.d.cts +1 -1
- package/dist/thinking-config.d.ts +1 -1
- package/dist/usage-stats-types.d.cts +22 -1
- package/dist/usage-stats-types.d.ts +22 -1
- package/dist/voucher-types.cjs +32 -0
- package/dist/voucher-types.d.cts +153 -0
- package/dist/voucher-types.d.ts +153 -0
- package/dist/voucher-types.js +7 -0
- package/dist/webhook-types.cjs +40 -0
- package/dist/webhook-types.d.cts +122 -0
- package/dist/webhook-types.d.ts +122 -0
- package/dist/webhook-types.js +14 -0
- package/package.json +156 -126
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voucher (redemption-card) contracts (voucher-redemption #9, design D2/D8).
|
|
3
|
+
*
|
|
4
|
+
* A voucher is a redeemable credit/renewal card layered on top of the outbound
|
|
5
|
+
* key-policy (#4): an admin generates a card (`CC_<entropy>`), a key-holder
|
|
6
|
+
* redeems it to raise their key's `totalCostLimitUsd` (credit) or extend its
|
|
7
|
+
* `expiresAt` (renewal). Dependency-light shapes shared across `@omnicross/*`:
|
|
8
|
+
*
|
|
9
|
+
* - `VoucherRecord` — the FROZEN stored card. It is a CREDENTIAL RECORD but holds
|
|
10
|
+
* NO plaintext code: only the sha256 `codeHash` (the redeem lookup key) + a
|
|
11
|
+
* short display `codePrefix`. The plaintext `CC_…` is returned ONCE at
|
|
12
|
+
* generation and NEVER persisted or logged. A secret-scan test asserts no
|
|
13
|
+
* `CC_` plaintext survives in a written record.
|
|
14
|
+
* - `VoucherGrant` — the ABSOLUTE target recorded on the card at redeem time so
|
|
15
|
+
* the apply step (`outboundApiKeysSetPolicy`) is idempotently re-appliable
|
|
16
|
+
* after a crash between the CAS flip and the apply (design D4).
|
|
17
|
+
* - `VoucherInfo` — the admin-safe DTO (prefix + status + value + caps only,
|
|
18
|
+
* NEVER the `codeHash`).
|
|
19
|
+
* - `VoucherConfig` — the `voucher` config segment. `enabled` default OFF ⇒ the
|
|
20
|
+
* redeem endpoint is inert + no key is ever mutated ⇒ byte-identical zero
|
|
21
|
+
* regression, purely additive on #4.
|
|
22
|
+
*
|
|
23
|
+
* @module voucher-types
|
|
24
|
+
*/
|
|
25
|
+
/** A card either adds USD credit or extends the key's lifetime. */
|
|
26
|
+
type VoucherType = 'credit' | 'renewal';
|
|
27
|
+
/** Card lifecycle. A card leaves `unredeemed` exactly once (CAS, design D4). */
|
|
28
|
+
type VoucherStatus = 'unredeemed' | 'redeemed' | 'revoked';
|
|
29
|
+
/**
|
|
30
|
+
* The ABSOLUTE grant a redemption applies to a key (design D4/D5). Recorded on
|
|
31
|
+
* the voucher AT the CAS flip so re-applying it after an interrupted redeem is a
|
|
32
|
+
* no-op (idempotent to the absolute value → never double-spends). A `credit`
|
|
33
|
+
* card records `totalCostLimitUsd`; a `renewal` card records `expiresAt`.
|
|
34
|
+
*/
|
|
35
|
+
interface VoucherGrant {
|
|
36
|
+
/** Absolute new `totalCostLimitUsd` for the key (credit cards). */
|
|
37
|
+
totalCostLimitUsd?: number;
|
|
38
|
+
/** Absolute new `expiresAt` (epoch ms) for the key (renewal cards). */
|
|
39
|
+
expiresAt?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One stored redemption card (design D2, FROZEN). Holds a HASH of the code
|
|
43
|
+
* (never the plaintext) + a display prefix. The `granted*` fields are the
|
|
44
|
+
* absolute target recorded at redeem time (idempotent re-apply, design D4).
|
|
45
|
+
*/
|
|
46
|
+
interface VoucherRecord {
|
|
47
|
+
/** Card id (independent of the code). */
|
|
48
|
+
id: string;
|
|
49
|
+
/** sha256 of the `CC_<entropy>` code — the redeem lookup key. NEVER plaintext. */
|
|
50
|
+
codeHash: string;
|
|
51
|
+
/** Short display prefix for the admin list (e.g. `CC_AB…`). NEVER the full code. */
|
|
52
|
+
codePrefix: string;
|
|
53
|
+
/** Credit (adds USD) or renewal (extends expiry). */
|
|
54
|
+
type: VoucherType;
|
|
55
|
+
/** `credit`: USD added to the key's `totalCostLimitUsd`. */
|
|
56
|
+
creditUsd?: number;
|
|
57
|
+
/** `renewal`: days added to the key's `expiresAt`. */
|
|
58
|
+
renewalDays?: number;
|
|
59
|
+
/** Anti-abuse cap on the RESULTING key `totalCostLimitUsd` (design D5). */
|
|
60
|
+
maxTotalCostLimitUsd?: number;
|
|
61
|
+
/** Anti-abuse cap on the RESULTING key lifetime, in days from now (design D5). */
|
|
62
|
+
maxExpiryDays?: number;
|
|
63
|
+
/** Lifecycle status. */
|
|
64
|
+
status: VoucherStatus;
|
|
65
|
+
/** Epoch ms the card was generated. */
|
|
66
|
+
createdAt: number;
|
|
67
|
+
/** Epoch ms the card was redeemed (set on the CAS flip). */
|
|
68
|
+
redeemedAt?: number;
|
|
69
|
+
/** The key id that redeemed the card (single-key binding). */
|
|
70
|
+
redeemedByKeyId?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the grant has been APPLIED to the key (design D4, revised). The CAS
|
|
73
|
+
* flip sets this `false`; the apply sets it `true` after a successful
|
|
74
|
+
* `outboundApiKeysSetPolicy`. `redeemed && grantApplied !== true` means "flipped
|
|
75
|
+
* but not (yet) applied" — the apply (of the recorded ABSOLUTE below) re-runs on
|
|
76
|
+
* the next redeem for the key, before that redeem computes anything. It is
|
|
77
|
+
* `grantApplied` that says "no work left"; the apply itself is idempotent
|
|
78
|
+
* (re-applying the same absolute is a no-op), so a crash between the apply and
|
|
79
|
+
* this mark never double-credits.
|
|
80
|
+
*/
|
|
81
|
+
grantApplied?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The recorded ABSOLUTE `totalCostLimitUsd` target (the intended final key
|
|
84
|
+
* value), computed at flip time from the CURRENT policy read INSIDE the per-key
|
|
85
|
+
* mutex. This is the AUTHORITATIVE apply source on BOTH the first pass and the
|
|
86
|
+
* reconcile/replay path — re-applying it is idempotent (never double-credits).
|
|
87
|
+
* Because redemptions for a key are serialized and a stranded card is reconciled
|
|
88
|
+
* before the next card computes, the recorded absolute is never stale.
|
|
89
|
+
*/
|
|
90
|
+
grantedTotalCostLimitUsd?: number;
|
|
91
|
+
/** The recorded ABSOLUTE `expiresAt` target (see `grantedTotalCostLimitUsd`). */
|
|
92
|
+
grantedExpiresAt?: number;
|
|
93
|
+
/** Epoch ms the card was revoked. */
|
|
94
|
+
revokedAt?: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The admin-safe voucher DTO (design D2). NEVER carries the `codeHash` — the
|
|
98
|
+
* admin sees the display prefix + status + value + caps only. This is the ONLY
|
|
99
|
+
* projection an admin GET returns.
|
|
100
|
+
*/
|
|
101
|
+
interface VoucherInfo {
|
|
102
|
+
id: string;
|
|
103
|
+
codePrefix: string;
|
|
104
|
+
type: VoucherType;
|
|
105
|
+
creditUsd?: number;
|
|
106
|
+
renewalDays?: number;
|
|
107
|
+
maxTotalCostLimitUsd?: number;
|
|
108
|
+
maxExpiryDays?: number;
|
|
109
|
+
status: VoucherStatus;
|
|
110
|
+
createdAt: number;
|
|
111
|
+
redeemedAt?: number;
|
|
112
|
+
redeemedByKeyId?: string;
|
|
113
|
+
grantApplied?: boolean;
|
|
114
|
+
grantedTotalCostLimitUsd?: number;
|
|
115
|
+
grantedExpiresAt?: number;
|
|
116
|
+
revokedAt?: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The one-time create result: `plaintextOnce` (the `CC_…` code) is shown exactly
|
|
120
|
+
* once at generation and never again — only its hash is stored (design D3).
|
|
121
|
+
*/
|
|
122
|
+
interface VoucherCreated {
|
|
123
|
+
id: string;
|
|
124
|
+
codePrefix: string;
|
|
125
|
+
type: VoucherType;
|
|
126
|
+
createdAt: number;
|
|
127
|
+
/** The plaintext `CC_…` code — the ONLY time it crosses the wire. */
|
|
128
|
+
plaintextOnce: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The result a successful redeem returns to the key-holder (design D2). Reveals
|
|
132
|
+
* ONLY this key's own new balance/expiry — never any other card or key.
|
|
133
|
+
*/
|
|
134
|
+
interface VoucherRedeemResult {
|
|
135
|
+
type: VoucherType;
|
|
136
|
+
/** The key's new absolute `totalCostLimitUsd` (credit cards). */
|
|
137
|
+
totalCostLimitUsd?: number;
|
|
138
|
+
/** The key's new absolute `expiresAt` (epoch ms) (renewal cards). */
|
|
139
|
+
expiresAt?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The `voucher` config segment (design D8), normalized like `audit`/`billing`.
|
|
143
|
+
* `enabled` default FALSE ⇒ the redeem endpoint rejects + no admin generate ⇒ no
|
|
144
|
+
* key is ever mutated ⇒ byte-identical zero regression, purely additive on #4.
|
|
145
|
+
*/
|
|
146
|
+
interface VoucherConfig {
|
|
147
|
+
/** Master switch; default FALSE (zero regression, inert product). */
|
|
148
|
+
enabled: boolean;
|
|
149
|
+
}
|
|
150
|
+
/** Frozen defaults for the `voucher` segment (SSOT). */
|
|
151
|
+
declare const DEFAULT_VOUCHER_CONFIG: VoucherConfig;
|
|
152
|
+
|
|
153
|
+
export { DEFAULT_VOUCHER_CONFIG, type VoucherConfig, type VoucherCreated, type VoucherGrant, type VoucherInfo, type VoucherRecord, type VoucherRedeemResult, type VoucherStatus, type VoucherType };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voucher (redemption-card) contracts (voucher-redemption #9, design D2/D8).
|
|
3
|
+
*
|
|
4
|
+
* A voucher is a redeemable credit/renewal card layered on top of the outbound
|
|
5
|
+
* key-policy (#4): an admin generates a card (`CC_<entropy>`), a key-holder
|
|
6
|
+
* redeems it to raise their key's `totalCostLimitUsd` (credit) or extend its
|
|
7
|
+
* `expiresAt` (renewal). Dependency-light shapes shared across `@omnicross/*`:
|
|
8
|
+
*
|
|
9
|
+
* - `VoucherRecord` — the FROZEN stored card. It is a CREDENTIAL RECORD but holds
|
|
10
|
+
* NO plaintext code: only the sha256 `codeHash` (the redeem lookup key) + a
|
|
11
|
+
* short display `codePrefix`. The plaintext `CC_…` is returned ONCE at
|
|
12
|
+
* generation and NEVER persisted or logged. A secret-scan test asserts no
|
|
13
|
+
* `CC_` plaintext survives in a written record.
|
|
14
|
+
* - `VoucherGrant` — the ABSOLUTE target recorded on the card at redeem time so
|
|
15
|
+
* the apply step (`outboundApiKeysSetPolicy`) is idempotently re-appliable
|
|
16
|
+
* after a crash between the CAS flip and the apply (design D4).
|
|
17
|
+
* - `VoucherInfo` — the admin-safe DTO (prefix + status + value + caps only,
|
|
18
|
+
* NEVER the `codeHash`).
|
|
19
|
+
* - `VoucherConfig` — the `voucher` config segment. `enabled` default OFF ⇒ the
|
|
20
|
+
* redeem endpoint is inert + no key is ever mutated ⇒ byte-identical zero
|
|
21
|
+
* regression, purely additive on #4.
|
|
22
|
+
*
|
|
23
|
+
* @module voucher-types
|
|
24
|
+
*/
|
|
25
|
+
/** A card either adds USD credit or extends the key's lifetime. */
|
|
26
|
+
type VoucherType = 'credit' | 'renewal';
|
|
27
|
+
/** Card lifecycle. A card leaves `unredeemed` exactly once (CAS, design D4). */
|
|
28
|
+
type VoucherStatus = 'unredeemed' | 'redeemed' | 'revoked';
|
|
29
|
+
/**
|
|
30
|
+
* The ABSOLUTE grant a redemption applies to a key (design D4/D5). Recorded on
|
|
31
|
+
* the voucher AT the CAS flip so re-applying it after an interrupted redeem is a
|
|
32
|
+
* no-op (idempotent to the absolute value → never double-spends). A `credit`
|
|
33
|
+
* card records `totalCostLimitUsd`; a `renewal` card records `expiresAt`.
|
|
34
|
+
*/
|
|
35
|
+
interface VoucherGrant {
|
|
36
|
+
/** Absolute new `totalCostLimitUsd` for the key (credit cards). */
|
|
37
|
+
totalCostLimitUsd?: number;
|
|
38
|
+
/** Absolute new `expiresAt` (epoch ms) for the key (renewal cards). */
|
|
39
|
+
expiresAt?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One stored redemption card (design D2, FROZEN). Holds a HASH of the code
|
|
43
|
+
* (never the plaintext) + a display prefix. The `granted*` fields are the
|
|
44
|
+
* absolute target recorded at redeem time (idempotent re-apply, design D4).
|
|
45
|
+
*/
|
|
46
|
+
interface VoucherRecord {
|
|
47
|
+
/** Card id (independent of the code). */
|
|
48
|
+
id: string;
|
|
49
|
+
/** sha256 of the `CC_<entropy>` code — the redeem lookup key. NEVER plaintext. */
|
|
50
|
+
codeHash: string;
|
|
51
|
+
/** Short display prefix for the admin list (e.g. `CC_AB…`). NEVER the full code. */
|
|
52
|
+
codePrefix: string;
|
|
53
|
+
/** Credit (adds USD) or renewal (extends expiry). */
|
|
54
|
+
type: VoucherType;
|
|
55
|
+
/** `credit`: USD added to the key's `totalCostLimitUsd`. */
|
|
56
|
+
creditUsd?: number;
|
|
57
|
+
/** `renewal`: days added to the key's `expiresAt`. */
|
|
58
|
+
renewalDays?: number;
|
|
59
|
+
/** Anti-abuse cap on the RESULTING key `totalCostLimitUsd` (design D5). */
|
|
60
|
+
maxTotalCostLimitUsd?: number;
|
|
61
|
+
/** Anti-abuse cap on the RESULTING key lifetime, in days from now (design D5). */
|
|
62
|
+
maxExpiryDays?: number;
|
|
63
|
+
/** Lifecycle status. */
|
|
64
|
+
status: VoucherStatus;
|
|
65
|
+
/** Epoch ms the card was generated. */
|
|
66
|
+
createdAt: number;
|
|
67
|
+
/** Epoch ms the card was redeemed (set on the CAS flip). */
|
|
68
|
+
redeemedAt?: number;
|
|
69
|
+
/** The key id that redeemed the card (single-key binding). */
|
|
70
|
+
redeemedByKeyId?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Whether the grant has been APPLIED to the key (design D4, revised). The CAS
|
|
73
|
+
* flip sets this `false`; the apply sets it `true` after a successful
|
|
74
|
+
* `outboundApiKeysSetPolicy`. `redeemed && grantApplied !== true` means "flipped
|
|
75
|
+
* but not (yet) applied" — the apply (of the recorded ABSOLUTE below) re-runs on
|
|
76
|
+
* the next redeem for the key, before that redeem computes anything. It is
|
|
77
|
+
* `grantApplied` that says "no work left"; the apply itself is idempotent
|
|
78
|
+
* (re-applying the same absolute is a no-op), so a crash between the apply and
|
|
79
|
+
* this mark never double-credits.
|
|
80
|
+
*/
|
|
81
|
+
grantApplied?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The recorded ABSOLUTE `totalCostLimitUsd` target (the intended final key
|
|
84
|
+
* value), computed at flip time from the CURRENT policy read INSIDE the per-key
|
|
85
|
+
* mutex. This is the AUTHORITATIVE apply source on BOTH the first pass and the
|
|
86
|
+
* reconcile/replay path — re-applying it is idempotent (never double-credits).
|
|
87
|
+
* Because redemptions for a key are serialized and a stranded card is reconciled
|
|
88
|
+
* before the next card computes, the recorded absolute is never stale.
|
|
89
|
+
*/
|
|
90
|
+
grantedTotalCostLimitUsd?: number;
|
|
91
|
+
/** The recorded ABSOLUTE `expiresAt` target (see `grantedTotalCostLimitUsd`). */
|
|
92
|
+
grantedExpiresAt?: number;
|
|
93
|
+
/** Epoch ms the card was revoked. */
|
|
94
|
+
revokedAt?: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The admin-safe voucher DTO (design D2). NEVER carries the `codeHash` — the
|
|
98
|
+
* admin sees the display prefix + status + value + caps only. This is the ONLY
|
|
99
|
+
* projection an admin GET returns.
|
|
100
|
+
*/
|
|
101
|
+
interface VoucherInfo {
|
|
102
|
+
id: string;
|
|
103
|
+
codePrefix: string;
|
|
104
|
+
type: VoucherType;
|
|
105
|
+
creditUsd?: number;
|
|
106
|
+
renewalDays?: number;
|
|
107
|
+
maxTotalCostLimitUsd?: number;
|
|
108
|
+
maxExpiryDays?: number;
|
|
109
|
+
status: VoucherStatus;
|
|
110
|
+
createdAt: number;
|
|
111
|
+
redeemedAt?: number;
|
|
112
|
+
redeemedByKeyId?: string;
|
|
113
|
+
grantApplied?: boolean;
|
|
114
|
+
grantedTotalCostLimitUsd?: number;
|
|
115
|
+
grantedExpiresAt?: number;
|
|
116
|
+
revokedAt?: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The one-time create result: `plaintextOnce` (the `CC_…` code) is shown exactly
|
|
120
|
+
* once at generation and never again — only its hash is stored (design D3).
|
|
121
|
+
*/
|
|
122
|
+
interface VoucherCreated {
|
|
123
|
+
id: string;
|
|
124
|
+
codePrefix: string;
|
|
125
|
+
type: VoucherType;
|
|
126
|
+
createdAt: number;
|
|
127
|
+
/** The plaintext `CC_…` code — the ONLY time it crosses the wire. */
|
|
128
|
+
plaintextOnce: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The result a successful redeem returns to the key-holder (design D2). Reveals
|
|
132
|
+
* ONLY this key's own new balance/expiry — never any other card or key.
|
|
133
|
+
*/
|
|
134
|
+
interface VoucherRedeemResult {
|
|
135
|
+
type: VoucherType;
|
|
136
|
+
/** The key's new absolute `totalCostLimitUsd` (credit cards). */
|
|
137
|
+
totalCostLimitUsd?: number;
|
|
138
|
+
/** The key's new absolute `expiresAt` (epoch ms) (renewal cards). */
|
|
139
|
+
expiresAt?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The `voucher` config segment (design D8), normalized like `audit`/`billing`.
|
|
143
|
+
* `enabled` default FALSE ⇒ the redeem endpoint rejects + no admin generate ⇒ no
|
|
144
|
+
* key is ever mutated ⇒ byte-identical zero regression, purely additive on #4.
|
|
145
|
+
*/
|
|
146
|
+
interface VoucherConfig {
|
|
147
|
+
/** Master switch; default FALSE (zero regression, inert product). */
|
|
148
|
+
enabled: boolean;
|
|
149
|
+
}
|
|
150
|
+
/** Frozen defaults for the `voucher` segment (SSOT). */
|
|
151
|
+
declare const DEFAULT_VOUCHER_CONFIG: VoucherConfig;
|
|
152
|
+
|
|
153
|
+
export { DEFAULT_VOUCHER_CONFIG, type VoucherConfig, type VoucherCreated, type VoucherGrant, type VoucherInfo, type VoucherRecord, type VoucherRedeemResult, type VoucherStatus, type VoucherType };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/webhook-types.ts
|
|
21
|
+
var webhook_types_exports = {};
|
|
22
|
+
__export(webhook_types_exports, {
|
|
23
|
+
WEBHOOK_DESTINATION_TYPES: () => WEBHOOK_DESTINATION_TYPES,
|
|
24
|
+
WEBHOOK_EVENT_KINDS: () => WEBHOOK_EVENT_KINDS
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(webhook_types_exports);
|
|
27
|
+
var WEBHOOK_EVENT_KINDS = [
|
|
28
|
+
"account.recovery",
|
|
29
|
+
"account.anomaly",
|
|
30
|
+
"key.quotaWarning",
|
|
31
|
+
"key.quotaExceeded",
|
|
32
|
+
"server.error",
|
|
33
|
+
"test"
|
|
34
|
+
];
|
|
35
|
+
var WEBHOOK_DESTINATION_TYPES = ["custom", "feishu"];
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
WEBHOOK_DESTINATION_TYPES,
|
|
39
|
+
WEBHOOK_EVENT_KINDS
|
|
40
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook notification contracts (webhook-notifications, design D1).
|
|
3
|
+
*
|
|
4
|
+
* Two small, dependency-light shapes shared across the `@omnicross/*` packages:
|
|
5
|
+
* - `WebhookEvent` — the FROZEN discriminated union of operational signals a
|
|
6
|
+
* relay can deliver out-of-band (account recovery/anomaly, key quota
|
|
7
|
+
* warning/exceeded, server error, and a config-UI `test`). Every payload is
|
|
8
|
+
* SECRET-FREE BY CONSTRUCTION: it carries only opaque provider/account ids, a
|
|
9
|
+
* key id (NEVER key material or a hash), a coarse state, limit/spend numbers,
|
|
10
|
+
* and a sanitized message. Nothing here can hold a token, secret, or hash.
|
|
11
|
+
* - `WebhookDestination` / `WebhookConfig` — the destination config schema. A
|
|
12
|
+
* destination's `secret` (its HMAC signing key) is the ONLY secret; it is
|
|
13
|
+
* encrypted at rest, masked in admin views, and used ONLY to sign an outgoing
|
|
14
|
+
* request — it is NEVER placed in a payload or a log line.
|
|
15
|
+
*
|
|
16
|
+
* The union is FROZEN: the emit port (core), the dispatcher (daemon), and the
|
|
17
|
+
* sources (#2 health / #4 quota / server-error) all agree on this one shape.
|
|
18
|
+
* Adding a destination `type` is additive behind the dispatcher's formatter.
|
|
19
|
+
*
|
|
20
|
+
* @module webhook-types
|
|
21
|
+
*/
|
|
22
|
+
/** The coarse anomaly state an account transitioned into (secret-free). */
|
|
23
|
+
type WebhookAnomalyState = 'blocked' | 'unauthorized' | 'rate_limited' | 'overloaded';
|
|
24
|
+
/** The cost-limit scope a key quota event refers to. */
|
|
25
|
+
type WebhookQuotaScope = 'daily' | 'weekly' | 'total';
|
|
26
|
+
/**
|
|
27
|
+
* The FROZEN webhook event union (design D1). EVERY field is non-secret:
|
|
28
|
+
* opaque provider/account ids, a key id (NOT key material/hash), a coarse state,
|
|
29
|
+
* numbers, and a sanitized message. A test asserts no token/secret/hash string
|
|
30
|
+
* can appear in any serialized payload.
|
|
31
|
+
*/
|
|
32
|
+
type WebhookEvent = {
|
|
33
|
+
kind: 'account.recovery';
|
|
34
|
+
at: number;
|
|
35
|
+
providerId: string;
|
|
36
|
+
accountId: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'account.anomaly';
|
|
39
|
+
at: number;
|
|
40
|
+
providerId: string;
|
|
41
|
+
accountId: string;
|
|
42
|
+
state: WebhookAnomalyState;
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'key.quotaWarning';
|
|
45
|
+
at: number;
|
|
46
|
+
keyId: string;
|
|
47
|
+
scope: WebhookQuotaScope;
|
|
48
|
+
limitUsd: number;
|
|
49
|
+
spentUsd: number;
|
|
50
|
+
} | {
|
|
51
|
+
kind: 'key.quotaExceeded';
|
|
52
|
+
at: number;
|
|
53
|
+
keyId: string;
|
|
54
|
+
scope: WebhookQuotaScope;
|
|
55
|
+
limitUsd: number;
|
|
56
|
+
spentUsd: number;
|
|
57
|
+
} | {
|
|
58
|
+
kind: 'server.error';
|
|
59
|
+
at: number;
|
|
60
|
+
message: string;
|
|
61
|
+
} | {
|
|
62
|
+
kind: 'test';
|
|
63
|
+
at: number;
|
|
64
|
+
};
|
|
65
|
+
/** The event discriminator — the value a destination `events` filter matches. */
|
|
66
|
+
type WebhookEventKind = WebhookEvent['kind'];
|
|
67
|
+
/** All event kinds (SSOT for validation + the admin UI's filter checklist). */
|
|
68
|
+
declare const WEBHOOK_EVENT_KINDS: readonly WebhookEventKind[];
|
|
69
|
+
/** The v1 destination types (dingtalk/slack/… are additive later). */
|
|
70
|
+
type WebhookDestinationType = 'custom' | 'feishu';
|
|
71
|
+
/** All destination types (SSOT for validation + the admin UI's type select). */
|
|
72
|
+
declare const WEBHOOK_DESTINATION_TYPES: readonly WebhookDestinationType[];
|
|
73
|
+
/**
|
|
74
|
+
* One webhook destination (design D5). `secret` is the OPTIONAL HMAC signing key
|
|
75
|
+
* (a SECRET — encrypted at rest, masked in views, never in a payload/log). An
|
|
76
|
+
* absent/empty `events` filter matches ALL event kinds.
|
|
77
|
+
*/
|
|
78
|
+
interface WebhookDestination {
|
|
79
|
+
/** Stable id (the admin CRUD key + the test-button target). */
|
|
80
|
+
id: string;
|
|
81
|
+
/** The formatter/signing scheme to use. */
|
|
82
|
+
type: WebhookDestinationType;
|
|
83
|
+
/** The POST target URL. */
|
|
84
|
+
url: string;
|
|
85
|
+
/** OPTIONAL HMAC signing key (SECRET; may be an `enc:`/`$ENV` envelope at rest). */
|
|
86
|
+
secret?: string;
|
|
87
|
+
/** OPTIONAL event-kind filter; absent/empty ⇒ receive ALL kinds. */
|
|
88
|
+
events?: WebhookEventKind[];
|
|
89
|
+
/** Whether this destination receives events. */
|
|
90
|
+
enabled: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The `webhook` config segment (design D5). Absent/`enabled:false` ⇒ inert (no
|
|
94
|
+
* dispatcher wiring, emit is a no-op — byte-identical zero regression).
|
|
95
|
+
*/
|
|
96
|
+
interface WebhookConfig {
|
|
97
|
+
/** Master switch; false/absent ⇒ webhooks are inert. */
|
|
98
|
+
enabled: boolean;
|
|
99
|
+
/** Configured destinations (each independently enable-able + filterable). */
|
|
100
|
+
destinations: WebhookDestination[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Secret-free projection of a destination for admin GET views: the signing
|
|
104
|
+
* `secret` is replaced by a `hasSecret` presence flag — the plaintext never
|
|
105
|
+
* leaves the daemon.
|
|
106
|
+
*/
|
|
107
|
+
interface SanitizedWebhookDestination {
|
|
108
|
+
id: string;
|
|
109
|
+
type: WebhookDestinationType;
|
|
110
|
+
url: string;
|
|
111
|
+
/** Whether a signing secret is configured (the value itself never leaves). */
|
|
112
|
+
hasSecret: boolean;
|
|
113
|
+
events?: WebhookEventKind[];
|
|
114
|
+
enabled: boolean;
|
|
115
|
+
}
|
|
116
|
+
/** Secret-free projection of the whole webhook segment (admin GET view). */
|
|
117
|
+
interface SanitizedWebhookConfig {
|
|
118
|
+
enabled: boolean;
|
|
119
|
+
destinations: SanitizedWebhookDestination[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { type SanitizedWebhookConfig, type SanitizedWebhookDestination, WEBHOOK_DESTINATION_TYPES, WEBHOOK_EVENT_KINDS, type WebhookAnomalyState, type WebhookConfig, type WebhookDestination, type WebhookDestinationType, type WebhookEvent, type WebhookEventKind, type WebhookQuotaScope };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook notification contracts (webhook-notifications, design D1).
|
|
3
|
+
*
|
|
4
|
+
* Two small, dependency-light shapes shared across the `@omnicross/*` packages:
|
|
5
|
+
* - `WebhookEvent` — the FROZEN discriminated union of operational signals a
|
|
6
|
+
* relay can deliver out-of-band (account recovery/anomaly, key quota
|
|
7
|
+
* warning/exceeded, server error, and a config-UI `test`). Every payload is
|
|
8
|
+
* SECRET-FREE BY CONSTRUCTION: it carries only opaque provider/account ids, a
|
|
9
|
+
* key id (NEVER key material or a hash), a coarse state, limit/spend numbers,
|
|
10
|
+
* and a sanitized message. Nothing here can hold a token, secret, or hash.
|
|
11
|
+
* - `WebhookDestination` / `WebhookConfig` — the destination config schema. A
|
|
12
|
+
* destination's `secret` (its HMAC signing key) is the ONLY secret; it is
|
|
13
|
+
* encrypted at rest, masked in admin views, and used ONLY to sign an outgoing
|
|
14
|
+
* request — it is NEVER placed in a payload or a log line.
|
|
15
|
+
*
|
|
16
|
+
* The union is FROZEN: the emit port (core), the dispatcher (daemon), and the
|
|
17
|
+
* sources (#2 health / #4 quota / server-error) all agree on this one shape.
|
|
18
|
+
* Adding a destination `type` is additive behind the dispatcher's formatter.
|
|
19
|
+
*
|
|
20
|
+
* @module webhook-types
|
|
21
|
+
*/
|
|
22
|
+
/** The coarse anomaly state an account transitioned into (secret-free). */
|
|
23
|
+
type WebhookAnomalyState = 'blocked' | 'unauthorized' | 'rate_limited' | 'overloaded';
|
|
24
|
+
/** The cost-limit scope a key quota event refers to. */
|
|
25
|
+
type WebhookQuotaScope = 'daily' | 'weekly' | 'total';
|
|
26
|
+
/**
|
|
27
|
+
* The FROZEN webhook event union (design D1). EVERY field is non-secret:
|
|
28
|
+
* opaque provider/account ids, a key id (NOT key material/hash), a coarse state,
|
|
29
|
+
* numbers, and a sanitized message. A test asserts no token/secret/hash string
|
|
30
|
+
* can appear in any serialized payload.
|
|
31
|
+
*/
|
|
32
|
+
type WebhookEvent = {
|
|
33
|
+
kind: 'account.recovery';
|
|
34
|
+
at: number;
|
|
35
|
+
providerId: string;
|
|
36
|
+
accountId: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'account.anomaly';
|
|
39
|
+
at: number;
|
|
40
|
+
providerId: string;
|
|
41
|
+
accountId: string;
|
|
42
|
+
state: WebhookAnomalyState;
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'key.quotaWarning';
|
|
45
|
+
at: number;
|
|
46
|
+
keyId: string;
|
|
47
|
+
scope: WebhookQuotaScope;
|
|
48
|
+
limitUsd: number;
|
|
49
|
+
spentUsd: number;
|
|
50
|
+
} | {
|
|
51
|
+
kind: 'key.quotaExceeded';
|
|
52
|
+
at: number;
|
|
53
|
+
keyId: string;
|
|
54
|
+
scope: WebhookQuotaScope;
|
|
55
|
+
limitUsd: number;
|
|
56
|
+
spentUsd: number;
|
|
57
|
+
} | {
|
|
58
|
+
kind: 'server.error';
|
|
59
|
+
at: number;
|
|
60
|
+
message: string;
|
|
61
|
+
} | {
|
|
62
|
+
kind: 'test';
|
|
63
|
+
at: number;
|
|
64
|
+
};
|
|
65
|
+
/** The event discriminator — the value a destination `events` filter matches. */
|
|
66
|
+
type WebhookEventKind = WebhookEvent['kind'];
|
|
67
|
+
/** All event kinds (SSOT for validation + the admin UI's filter checklist). */
|
|
68
|
+
declare const WEBHOOK_EVENT_KINDS: readonly WebhookEventKind[];
|
|
69
|
+
/** The v1 destination types (dingtalk/slack/… are additive later). */
|
|
70
|
+
type WebhookDestinationType = 'custom' | 'feishu';
|
|
71
|
+
/** All destination types (SSOT for validation + the admin UI's type select). */
|
|
72
|
+
declare const WEBHOOK_DESTINATION_TYPES: readonly WebhookDestinationType[];
|
|
73
|
+
/**
|
|
74
|
+
* One webhook destination (design D5). `secret` is the OPTIONAL HMAC signing key
|
|
75
|
+
* (a SECRET — encrypted at rest, masked in views, never in a payload/log). An
|
|
76
|
+
* absent/empty `events` filter matches ALL event kinds.
|
|
77
|
+
*/
|
|
78
|
+
interface WebhookDestination {
|
|
79
|
+
/** Stable id (the admin CRUD key + the test-button target). */
|
|
80
|
+
id: string;
|
|
81
|
+
/** The formatter/signing scheme to use. */
|
|
82
|
+
type: WebhookDestinationType;
|
|
83
|
+
/** The POST target URL. */
|
|
84
|
+
url: string;
|
|
85
|
+
/** OPTIONAL HMAC signing key (SECRET; may be an `enc:`/`$ENV` envelope at rest). */
|
|
86
|
+
secret?: string;
|
|
87
|
+
/** OPTIONAL event-kind filter; absent/empty ⇒ receive ALL kinds. */
|
|
88
|
+
events?: WebhookEventKind[];
|
|
89
|
+
/** Whether this destination receives events. */
|
|
90
|
+
enabled: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The `webhook` config segment (design D5). Absent/`enabled:false` ⇒ inert (no
|
|
94
|
+
* dispatcher wiring, emit is a no-op — byte-identical zero regression).
|
|
95
|
+
*/
|
|
96
|
+
interface WebhookConfig {
|
|
97
|
+
/** Master switch; false/absent ⇒ webhooks are inert. */
|
|
98
|
+
enabled: boolean;
|
|
99
|
+
/** Configured destinations (each independently enable-able + filterable). */
|
|
100
|
+
destinations: WebhookDestination[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Secret-free projection of a destination for admin GET views: the signing
|
|
104
|
+
* `secret` is replaced by a `hasSecret` presence flag — the plaintext never
|
|
105
|
+
* leaves the daemon.
|
|
106
|
+
*/
|
|
107
|
+
interface SanitizedWebhookDestination {
|
|
108
|
+
id: string;
|
|
109
|
+
type: WebhookDestinationType;
|
|
110
|
+
url: string;
|
|
111
|
+
/** Whether a signing secret is configured (the value itself never leaves). */
|
|
112
|
+
hasSecret: boolean;
|
|
113
|
+
events?: WebhookEventKind[];
|
|
114
|
+
enabled: boolean;
|
|
115
|
+
}
|
|
116
|
+
/** Secret-free projection of the whole webhook segment (admin GET view). */
|
|
117
|
+
interface SanitizedWebhookConfig {
|
|
118
|
+
enabled: boolean;
|
|
119
|
+
destinations: SanitizedWebhookDestination[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { type SanitizedWebhookConfig, type SanitizedWebhookDestination, WEBHOOK_DESTINATION_TYPES, WEBHOOK_EVENT_KINDS, type WebhookAnomalyState, type WebhookConfig, type WebhookDestination, type WebhookDestinationType, type WebhookEvent, type WebhookEventKind, type WebhookQuotaScope };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/webhook-types.ts
|
|
2
|
+
var WEBHOOK_EVENT_KINDS = [
|
|
3
|
+
"account.recovery",
|
|
4
|
+
"account.anomaly",
|
|
5
|
+
"key.quotaWarning",
|
|
6
|
+
"key.quotaExceeded",
|
|
7
|
+
"server.error",
|
|
8
|
+
"test"
|
|
9
|
+
];
|
|
10
|
+
var WEBHOOK_DESTINATION_TYPES = ["custom", "feishu"];
|
|
11
|
+
export {
|
|
12
|
+
WEBHOOK_DESTINATION_TYPES,
|
|
13
|
+
WEBHOOK_EVENT_KINDS
|
|
14
|
+
};
|