@serve.zone/interfaces 32.122.0 → 32.124.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.
Files changed (47) hide show
  1. package/changelog.md +14 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/backupmx.d.ts +135 -0
  4. package/dist_ts/data/backupmx.js +128 -0
  5. package/dist_ts/data/corestoredata.d.ts +87 -0
  6. package/dist_ts/data/corestoredata.js +164 -0
  7. package/dist_ts/data/delegatedadmintoken.d.ts +7 -1
  8. package/dist_ts/data/delegatedadmintoken.js +17 -2
  9. package/dist_ts/data/gateway.d.ts +5 -0
  10. package/dist_ts/data/gateway.js +1 -1
  11. package/dist_ts/data/gatewayarearows.d.ts +2 -1
  12. package/dist_ts/data/gatewayarearows.js +1 -1
  13. package/dist_ts/data/gatewayareas.d.ts +19 -0
  14. package/dist_ts/data/gatewayareas.js +1 -1
  15. package/dist_ts/data/gatewayareas.validation.js +37 -5
  16. package/dist_ts/data/hetzner.d.ts +177 -0
  17. package/dist_ts/data/hetzner.js +253 -0
  18. package/dist_ts/data/index.d.ts +4 -0
  19. package/dist_ts/data/index.js +5 -1
  20. package/dist_ts/data/palletworkspace.d.ts +59 -0
  21. package/dist_ts/data/palletworkspace.js +39 -0
  22. package/dist_ts/requests/backupmx.d.ts +209 -0
  23. package/dist_ts/requests/backupmx.js +2 -0
  24. package/dist_ts/requests/corestore.d.ts +75 -0
  25. package/dist_ts/requests/corestore.js +1 -1
  26. package/dist_ts/requests/hetzner.d.ts +216 -0
  27. package/dist_ts/requests/hetzner.js +2 -0
  28. package/dist_ts/requests/index.d.ts +3 -1
  29. package/dist_ts/requests/index.js +4 -2
  30. package/dist_ts/requests/runtimesession.d.ts +38 -0
  31. package/package.json +17 -1
  32. package/ts/00_commitinfo_data.ts +1 -1
  33. package/ts/data/backupmx.ts +252 -0
  34. package/ts/data/corestoredata.ts +255 -0
  35. package/ts/data/delegatedadmintoken.ts +16 -1
  36. package/ts/data/gateway.ts +5 -0
  37. package/ts/data/gatewayarearows.ts +2 -0
  38. package/ts/data/gatewayareas.ts +20 -0
  39. package/ts/data/gatewayareas.validation.ts +40 -4
  40. package/ts/data/hetzner.ts +419 -0
  41. package/ts/data/index.ts +4 -0
  42. package/ts/data/palletworkspace.ts +90 -0
  43. package/ts/requests/backupmx.ts +275 -0
  44. package/ts/requests/corestore.ts +100 -0
  45. package/ts/requests/hetzner.ts +276 -0
  46. package/ts/requests/index.ts +4 -0
  47. package/ts/requests/runtimesession.ts +53 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serve.zone/interfaces",
3
- "version": "32.122.0",
3
+ "version": "32.124.0",
4
4
  "private": false,
5
5
  "description": "Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.",
6
6
  "exports": {
@@ -20,6 +20,14 @@
20
20
  "types": "./dist_ts/data/backup/index.d.ts",
21
21
  "default": "./dist_ts/data/backup/index.js"
22
22
  },
23
+ "./data/backupmx": {
24
+ "types": "./dist_ts/data/backupmx.d.ts",
25
+ "default": "./dist_ts/data/backupmx.js"
26
+ },
27
+ "./data/hetzner": {
28
+ "types": "./dist_ts/data/hetzner.d.ts",
29
+ "default": "./dist_ts/data/hetzner.js"
30
+ },
23
31
  "./data/controlledtakeover": {
24
32
  "types": "./dist_ts/data/controlledtakeover.d.ts",
25
33
  "default": "./dist_ts/data/controlledtakeover.js"
@@ -80,6 +88,14 @@
80
88
  "types": "./dist_ts/requests/backup.d.ts",
81
89
  "default": "./dist_ts/requests/backup.js"
82
90
  },
91
+ "./requests/backupmx": {
92
+ "types": "./dist_ts/requests/backupmx.d.ts",
93
+ "default": "./dist_ts/requests/backupmx.js"
94
+ },
95
+ "./requests/hetzner": {
96
+ "types": "./dist_ts/requests/hetzner.d.ts",
97
+ "default": "./dist_ts/requests/hetzner.js"
98
+ },
83
99
  "./requests/controlledtakeover": {
84
100
  "types": "./dist_ts/requests/controlledtakeover.d.ts",
85
101
  "default": "./dist_ts/requests/controlledtakeover.js"
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@serve.zone/interfaces',
6
- version: '32.122.0',
6
+ version: '32.124.0',
7
7
  description: 'Shared TypeScript interfaces and TypedRequest contracts for the serve.zone ecosystem.'
8
8
  }
@@ -0,0 +1,252 @@
1
+ import { compareWireTokens } from '../private/canonicaljson.js';
2
+ import { parseCanonicalIpAddress } from '../private/ipaddress.js';
3
+ import { validateManagedHetznerFqdn } from './hetzner.js';
4
+
5
+ export const backupMxContract = Object.freeze({
6
+ typedSocketPath: '/backupmx-socket',
7
+ defaultMxPriority: 30,
8
+ minimumMxPriority: 21,
9
+ maximumMxPriority: 65535,
10
+ maximumDomains: 1024,
11
+ maximumRecipientsPerDomain: 10_000,
12
+ maximumMessageSizeBytes: 50 * 1024 * 1024,
13
+ defaultMaxAgeMs: 5 * 24 * 60 * 60 * 1000,
14
+ defaultDsnMaxAgeMs: 2 * 24 * 60 * 60 * 1000,
15
+ defaultInitialRetryMs: 60_000,
16
+ defaultMaxRetryMs: 4 * 60 * 60 * 1000,
17
+ defaultScanIntervalMs: 15_000,
18
+ defaultMaxConcurrentDeliveries: 4,
19
+ maximumQueuePageLimit: 200,
20
+ credentialRandomBytes: 32,
21
+ } as const);
22
+
23
+ export const backupMxRefusals = Object.freeze([
24
+ 'request-invalid',
25
+ 'credential-invalid',
26
+ 'controller-mismatch',
27
+ 'controller-epoch-older',
28
+ 'config-epoch-stale',
29
+ 'instance-not-found',
30
+ 'instance-disconnected',
31
+ 'instance-queue-not-empty',
32
+ 'queue-item-not-found',
33
+ 'queue-item-not-dead',
34
+ ] as const);
35
+
36
+ export type TBackupMxRefusalCode = typeof backupMxRefusals[number];
37
+
38
+ export type TBackupMxRecipientPolicy =
39
+ | {
40
+ mode: 'allow-list';
41
+ /** Lowercase canonical `local@domain` addresses sorted ascending (`compareWireTokens`). */
42
+ recipients: string[];
43
+ }
44
+ | {
45
+ /** Reflects a Cloudly/DcRouter managed domain whose inbound policy is catch-all store. */
46
+ mode: 'domain-catchall';
47
+ };
48
+
49
+ export interface IBackupMxManagedDomain {
50
+ /** Lowercase ASCII FQDN of a Cloudly/DcRouter-managed mail domain. */
51
+ domain: string;
52
+ /** Hostnames belonging to this Backup MX (loop guard — MX >= self are excluded). */
53
+ selfMxHostnames: string[];
54
+ /** Canonical IPv4/IPv6 addresses belonging to this Backup MX (additional loop guard). */
55
+ selfMxIps: string[];
56
+ recipientPolicy: TBackupMxRecipientPolicy;
57
+ }
58
+
59
+ export interface IBackupMxQueuePolicy {
60
+ maxAgeMs: number;
61
+ dsnMaxAgeMs: number;
62
+ initialRetryMs: number;
63
+ maxRetryMs: number;
64
+ jitter: number;
65
+ scanIntervalMs: number;
66
+ maxConcurrentDeliveries: number;
67
+ maxMessageSizeBytes: number;
68
+ }
69
+
70
+ export interface IBackupMxInboundTls {
71
+ certificatePem: string;
72
+ privateKeyPem: string;
73
+ fingerprintSha256: string;
74
+ expiresAt: number;
75
+ }
76
+
77
+ /**
78
+ * Canonical desired-state snapshot pushed by Cloudly to a Backup MX daemon over TypedSocket.
79
+ * Persisted locally on the Backup MX host so restarts during a Cloudly outage remain autonomous.
80
+ */
81
+ export interface IBackupMxDesiredState {
82
+ configEpoch: number;
83
+ hostname: string;
84
+ listenPorts: number[];
85
+ domains: IBackupMxManagedDomain[];
86
+ queuePolicy: IBackupMxQueuePolicy;
87
+ inboundTls: IBackupMxInboundTls | null;
88
+ }
89
+
90
+ export interface IBackupMxDomainStatus {
91
+ domain: string;
92
+ pendingCount: number;
93
+ deadCount: number;
94
+ circuitBlockedUntil: number | null;
95
+ lastDeliveredAt: number | null;
96
+ lastError: string | null;
97
+ }
98
+
99
+ export interface IBackupMxStatus {
100
+ instanceId: string;
101
+ hostname: string;
102
+ version: string;
103
+ bridgeState: string;
104
+ appliedConfigEpoch: number;
105
+ checkedAt: number;
106
+ queue: {
107
+ pending: number;
108
+ dead: number;
109
+ };
110
+ counters: {
111
+ acceptedTotal: number;
112
+ deliveredTotal: number;
113
+ retriedTotal: number;
114
+ permanentlyFailedTotal: number;
115
+ rejectedRecipientsTotal: number;
116
+ deliveryAttemptsTotal: number;
117
+ };
118
+ tlsCertificate: {
119
+ configured: boolean;
120
+ fingerprintSha256: string | null;
121
+ expiresAt: number | null;
122
+ };
123
+ domains: IBackupMxDomainStatus[];
124
+ }
125
+
126
+ export interface IBackupMxQueueItemSummary {
127
+ id: string;
128
+ queue: 'pending' | 'dead';
129
+ kind: 'relay' | 'dsn';
130
+ destinationDomain: string;
131
+ envelopeFrom: string;
132
+ recipients: string[];
133
+ sizeBytes: number;
134
+ createdAt: number;
135
+ attempts: number;
136
+ nextAttemptAt: number;
137
+ deadlineAt: number;
138
+ lastAttemptAt: number | null;
139
+ lastError: string | null;
140
+ deadAt: number | null;
141
+ }
142
+
143
+ export interface IBackupMxInstance {
144
+ id: string;
145
+ name: string;
146
+ hostname: string;
147
+ mxPriority: number;
148
+ ipv4: string | null;
149
+ ipv6: string | null;
150
+ hetznerHostId: string | null;
151
+ enabled: boolean;
152
+ connected: boolean;
153
+ desiredConfigEpoch: number;
154
+ appliedConfigEpoch: number;
155
+ /** Managed domain names currently assigned to this Backup MX. */
156
+ managedDomains: string[];
157
+ observedStatus: IBackupMxStatus | null;
158
+ lastConnectedAt: number | null;
159
+ createdAt: number;
160
+ updatedAt: number;
161
+ }
162
+
163
+ export function validateBackupMxHostname(hostnameArg: string): boolean {
164
+ return validateManagedHetznerFqdn(hostnameArg);
165
+ }
166
+
167
+ export function validateBackupMxDesiredState(stateArg: IBackupMxDesiredState): string[] {
168
+ const errors: string[] = [];
169
+ if (!Number.isSafeInteger(stateArg.configEpoch) || stateArg.configEpoch < 1) {
170
+ errors.push('configEpoch must be a positive safe integer');
171
+ }
172
+ if (!validateBackupMxHostname(stateArg.hostname)) {
173
+ errors.push('hostname must be a lowercase FQDN');
174
+ }
175
+ if (!Array.isArray(stateArg.listenPorts) || stateArg.listenPorts.length === 0) {
176
+ errors.push('listenPorts must be a non-empty array of valid ports');
177
+ } else {
178
+ for (const port of stateArg.listenPorts) {
179
+ if (!Number.isSafeInteger(port) || port < 1 || port > 65535) {
180
+ errors.push(`invalid listenPort: ${port}`);
181
+ }
182
+ }
183
+ }
184
+ if (!Array.isArray(stateArg.domains) || stateArg.domains.length > backupMxContract.maximumDomains) {
185
+ errors.push(`domains must be an array of at most ${backupMxContract.maximumDomains} entries`);
186
+ } else {
187
+ let prevDomain: string | null = null;
188
+ for (const entry of stateArg.domains) {
189
+ if (!validateBackupMxHostname(entry.domain)) {
190
+ errors.push(`invalid domain: ${entry.domain}`);
191
+ }
192
+ if (prevDomain !== null && compareWireTokens(prevDomain, entry.domain) >= 0) {
193
+ errors.push(`domains must be strictly ascending: ${entry.domain}`);
194
+ }
195
+ prevDomain = entry.domain;
196
+
197
+ if (!Array.isArray(entry.selfMxHostnames) || !entry.selfMxHostnames.includes(stateArg.hostname)) {
198
+ errors.push(`domain ${entry.domain} selfMxHostnames must include ${stateArg.hostname}`);
199
+ }
200
+ for (const ip of entry.selfMxIps) {
201
+ if (!parseCanonicalIpAddress(ip)) {
202
+ errors.push(`domain ${entry.domain} has non-canonical selfMxIp: ${ip}`);
203
+ }
204
+ }
205
+ if (entry.recipientPolicy.mode === 'allow-list') {
206
+ if (entry.recipientPolicy.recipients.length > backupMxContract.maximumRecipientsPerDomain) {
207
+ errors.push(`domain ${entry.domain} exceeds recipient allow-list limit`);
208
+ }
209
+ let prevRcpt: string | null = null;
210
+ for (const rcpt of entry.recipientPolicy.recipients) {
211
+ const at = rcpt.lastIndexOf('@');
212
+ if (at <= 0 || rcpt.slice(at + 1) !== entry.domain || rcpt !== rcpt.toLowerCase()) {
213
+ errors.push(`domain ${entry.domain} invalid recipient in allow-list: ${rcpt}`);
214
+ }
215
+ if (prevRcpt !== null && compareWireTokens(prevRcpt, rcpt) >= 0) {
216
+ errors.push(`domain ${entry.domain} recipients must be strictly ascending`);
217
+ }
218
+ prevRcpt = rcpt;
219
+ }
220
+ } else if (entry.recipientPolicy.mode !== 'domain-catchall') {
221
+ errors.push(`domain ${entry.domain} has invalid recipientPolicy mode`);
222
+ }
223
+ }
224
+ }
225
+
226
+ const qp = stateArg.queuePolicy;
227
+ if (!qp || typeof qp !== 'object') {
228
+ errors.push('queuePolicy is required');
229
+ } else {
230
+ if (!Number.isSafeInteger(qp.maxAgeMs) || qp.maxAgeMs < 60_000) errors.push('invalid queuePolicy.maxAgeMs');
231
+ if (!Number.isSafeInteger(qp.dsnMaxAgeMs) || qp.dsnMaxAgeMs < 60_000) errors.push('invalid queuePolicy.dsnMaxAgeMs');
232
+ if (!Number.isSafeInteger(qp.initialRetryMs) || qp.initialRetryMs < 1_000) errors.push('invalid queuePolicy.initialRetryMs');
233
+ if (!Number.isSafeInteger(qp.maxRetryMs) || qp.maxRetryMs < qp.initialRetryMs) errors.push('invalid queuePolicy.maxRetryMs');
234
+ if (typeof qp.jitter !== 'number' || !Number.isFinite(qp.jitter) || qp.jitter < 0 || qp.jitter > 0.5) errors.push('invalid queuePolicy.jitter');
235
+ if (!Number.isSafeInteger(qp.scanIntervalMs) || qp.scanIntervalMs < 1_000) errors.push('invalid queuePolicy.scanIntervalMs');
236
+ if (!Number.isSafeInteger(qp.maxConcurrentDeliveries) || qp.maxConcurrentDeliveries < 1 || qp.maxConcurrentDeliveries > 64) {
237
+ errors.push('invalid queuePolicy.maxConcurrentDeliveries');
238
+ }
239
+ if (!Number.isSafeInteger(qp.maxMessageSizeBytes) || qp.maxMessageSizeBytes < 1024 || qp.maxMessageSizeBytes > backupMxContract.maximumMessageSizeBytes) {
240
+ errors.push('invalid queuePolicy.maxMessageSizeBytes');
241
+ }
242
+ }
243
+
244
+ if (stateArg.inboundTls !== null) {
245
+ if (!stateArg.inboundTls.certificatePem.includes('BEGIN CERTIFICATE')
246
+ || !stateArg.inboundTls.privateKeyPem.includes('BEGIN ')) {
247
+ errors.push('inboundTls must contain PEM certificate and private key');
248
+ }
249
+ }
250
+
251
+ return errors;
252
+ }
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Read-only, bounded inspection contracts for Corestore-managed service databases
3
+ * and object storage buckets routed through Cloudly and the cluster relay.
4
+ *
5
+ * Credentials never leave Corestore; every query is strictly read-only and bounded
6
+ * in execution time, row count, and serialized byte size.
7
+ */
8
+ export const corestoreDataInspectionContract = Object.freeze({
9
+ databaseInspectPath: '/control/data/database/inspect',
10
+ objectStorageInspectPath: '/control/data/objectstorage/inspect',
11
+ maxCollections: 500,
12
+ defaultQueryLimit: 25,
13
+ maxQueryLimit: 100,
14
+ maxSkip: 10_000,
15
+ defaultObjectLimit: 50,
16
+ maxObjectLimit: 100,
17
+ maxPayloadBytes: 512 * 1024,
18
+ queryTimeoutMs: 5_000,
19
+ maxFilterDepth: 12,
20
+ maxCollectionNameLength: 200,
21
+ maxPrefixLength: 1_024,
22
+ } as const);
23
+
24
+ export type TCorestoreDatabaseInspectOperation = 'collections' | 'find' | 'count';
25
+
26
+ export interface ICorestoreDatabaseCollectionSummary {
27
+ name: string;
28
+ estimatedCount: number;
29
+ }
30
+
31
+ export interface ICorestoreDatabaseInspectRequest {
32
+ serviceId: string;
33
+ operation: TCorestoreDatabaseInspectOperation;
34
+ collection?: string;
35
+ filter?: Record<string, unknown>;
36
+ projection?: Record<string, 0 | 1>;
37
+ sort?: Record<string, 1 | -1>;
38
+ limit?: number;
39
+ skip?: number;
40
+ }
41
+
42
+ export type TCorestoreDatabaseInspectResult =
43
+ | {
44
+ operation: 'collections';
45
+ serviceId: string;
46
+ databaseName: string;
47
+ collections: ICorestoreDatabaseCollectionSummary[];
48
+ }
49
+ | {
50
+ operation: 'find';
51
+ serviceId: string;
52
+ databaseName: string;
53
+ collection: string;
54
+ documents: Record<string, unknown>[];
55
+ returnedCount: number;
56
+ totalMatchedCount: number;
57
+ hasMore: boolean;
58
+ truncated: boolean;
59
+ }
60
+ | {
61
+ operation: 'count';
62
+ serviceId: string;
63
+ databaseName: string;
64
+ collection: string;
65
+ count: number;
66
+ };
67
+
68
+ export interface ICorestoreObjectStorageEntry {
69
+ key: string;
70
+ size: number;
71
+ etag: string;
72
+ lastModified?: string;
73
+ }
74
+
75
+ export interface ICorestoreObjectStorageInspectRequest {
76
+ serviceId: string;
77
+ prefix?: string;
78
+ startAfter?: string;
79
+ limit?: number;
80
+ }
81
+
82
+ export interface ICorestoreObjectStorageInspectResult {
83
+ serviceId: string;
84
+ bucketName: string;
85
+ prefix: string;
86
+ entries: ICorestoreObjectStorageEntry[];
87
+ hasMore: boolean;
88
+ nextStartAfter?: string;
89
+ }
90
+
91
+ const serviceIdPattern = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,199}$/;
92
+ const forbiddenFilterOperators = new Set(['$where', '$function', '$accumulator']);
93
+
94
+ const isPlainRecord = (valueArg: unknown): valueArg is Record<string, unknown> => (
95
+ Boolean(valueArg)
96
+ && typeof valueArg === 'object'
97
+ && !Array.isArray(valueArg)
98
+ && (Object.getPrototypeOf(valueArg) === Object.prototype
99
+ || Object.getPrototypeOf(valueArg) === null)
100
+ );
101
+
102
+ /**
103
+ * Validates that a MongoDB/NoSQLDB read filter contains no server-side JavaScript
104
+ * execution operators (`$where`, `$function`, `$accumulator`) and stays within
105
+ * bounded nesting depth.
106
+ */
107
+ export const validateCorestoreQueryFilter = (
108
+ valueArg: unknown,
109
+ pathArg = 'filter',
110
+ depthArg = 0,
111
+ ): string[] => {
112
+ if (depthArg > corestoreDataInspectionContract.maxFilterDepth) {
113
+ return [`${pathArg} exceeds maximum nesting depth of ${corestoreDataInspectionContract.maxFilterDepth}`];
114
+ }
115
+ if (Array.isArray(valueArg)) {
116
+ const errors: string[] = [];
117
+ for (const [index, entry] of valueArg.entries()) {
118
+ errors.push(...validateCorestoreQueryFilter(entry, `${pathArg}[${index}]`, depthArg + 1));
119
+ }
120
+ return errors;
121
+ }
122
+ if (!isPlainRecord(valueArg)) {
123
+ if (depthArg === 0) {
124
+ return [`${pathArg} must be a JSON object`];
125
+ }
126
+ return [];
127
+ }
128
+ const errors: string[] = [];
129
+ for (const [key, nested] of Object.entries(valueArg)) {
130
+ if (forbiddenFilterOperators.has(key)) {
131
+ errors.push(`${pathArg}.${key} is not permitted in read-only inspection queries`);
132
+ continue;
133
+ }
134
+ if (key.includes('\0')) {
135
+ errors.push(`${pathArg} contains an invalid null byte in key`);
136
+ continue;
137
+ }
138
+ errors.push(...validateCorestoreQueryFilter(nested, `${pathArg}.${key}`, depthArg + 1));
139
+ }
140
+ return errors;
141
+ };
142
+
143
+ export const validateCorestoreDatabaseInspectRequest = (
144
+ valueArg: unknown,
145
+ ): string[] => {
146
+ if (!isPlainRecord(valueArg)) {
147
+ return ['database inspect request must be an object'];
148
+ }
149
+ const errors: string[] = [];
150
+ if (typeof valueArg.serviceId !== 'string' || !serviceIdPattern.test(valueArg.serviceId)) {
151
+ errors.push('serviceId must be a valid bounded identifier');
152
+ }
153
+ const op = valueArg.operation;
154
+ if (op !== 'collections' && op !== 'find' && op !== 'count') {
155
+ errors.push('operation must be collections, find, or count');
156
+ return errors;
157
+ }
158
+ if (op === 'find' || op === 'count') {
159
+ if (
160
+ typeof valueArg.collection !== 'string'
161
+ || valueArg.collection.trim().length === 0
162
+ || valueArg.collection.length > corestoreDataInspectionContract.maxCollectionNameLength
163
+ || valueArg.collection.includes('\0')
164
+ || valueArg.collection.includes('$')
165
+ ) {
166
+ errors.push('collection must be a valid non-empty collection name');
167
+ }
168
+ if (valueArg.filter !== undefined) {
169
+ errors.push(...validateCorestoreQueryFilter(valueArg.filter, 'filter'));
170
+ }
171
+ }
172
+ if (op === 'find') {
173
+ if (valueArg.projection !== undefined) {
174
+ if (!isPlainRecord(valueArg.projection)) {
175
+ errors.push('projection must be an object');
176
+ } else {
177
+ for (const [field, flag] of Object.entries(valueArg.projection)) {
178
+ if (!field || field.includes('\0') || (flag !== 0 && flag !== 1)) {
179
+ errors.push(`projection.${field} must be 0 or 1`);
180
+ }
181
+ }
182
+ }
183
+ }
184
+ if (valueArg.sort !== undefined) {
185
+ if (!isPlainRecord(valueArg.sort)) {
186
+ errors.push('sort must be an object');
187
+ } else {
188
+ for (const [field, dir] of Object.entries(valueArg.sort)) {
189
+ if (!field || field.includes('\0') || (dir !== 1 && dir !== -1)) {
190
+ errors.push(`sort.${field} must be 1 or -1`);
191
+ }
192
+ }
193
+ }
194
+ }
195
+ if (valueArg.limit !== undefined) {
196
+ if (
197
+ !Number.isSafeInteger(valueArg.limit)
198
+ || (valueArg.limit as number) < 1
199
+ || (valueArg.limit as number) > corestoreDataInspectionContract.maxQueryLimit
200
+ ) {
201
+ errors.push(`limit must be an integer between 1 and ${corestoreDataInspectionContract.maxQueryLimit}`);
202
+ }
203
+ }
204
+ if (valueArg.skip !== undefined) {
205
+ if (
206
+ !Number.isSafeInteger(valueArg.skip)
207
+ || (valueArg.skip as number) < 0
208
+ || (valueArg.skip as number) > corestoreDataInspectionContract.maxSkip
209
+ ) {
210
+ errors.push(`skip must be an integer between 0 and ${corestoreDataInspectionContract.maxSkip}`);
211
+ }
212
+ }
213
+ }
214
+ return errors;
215
+ };
216
+
217
+ export const validateCorestoreObjectStorageInspectRequest = (
218
+ valueArg: unknown,
219
+ ): string[] => {
220
+ if (!isPlainRecord(valueArg)) {
221
+ return ['object storage inspect request must be an object'];
222
+ }
223
+ const errors: string[] = [];
224
+ if (typeof valueArg.serviceId !== 'string' || !serviceIdPattern.test(valueArg.serviceId)) {
225
+ errors.push('serviceId must be a valid bounded identifier');
226
+ }
227
+ if (valueArg.prefix !== undefined) {
228
+ if (
229
+ typeof valueArg.prefix !== 'string'
230
+ || valueArg.prefix.length > corestoreDataInspectionContract.maxPrefixLength
231
+ || valueArg.prefix.includes('\0')
232
+ ) {
233
+ errors.push('prefix must be a bounded UTF-8 string without null bytes');
234
+ }
235
+ }
236
+ if (valueArg.startAfter !== undefined) {
237
+ if (
238
+ typeof valueArg.startAfter !== 'string'
239
+ || valueArg.startAfter.length > corestoreDataInspectionContract.maxPrefixLength
240
+ || valueArg.startAfter.includes('\0')
241
+ ) {
242
+ errors.push('startAfter must be a bounded UTF-8 string without null bytes');
243
+ }
244
+ }
245
+ if (valueArg.limit !== undefined) {
246
+ if (
247
+ !Number.isSafeInteger(valueArg.limit)
248
+ || (valueArg.limit as number) < 1
249
+ || (valueArg.limit as number) > corestoreDataInspectionContract.maxObjectLimit
250
+ ) {
251
+ errors.push(`limit must be an integer between 1 and ${corestoreDataInspectionContract.maxObjectLimit}`);
252
+ }
253
+ }
254
+ return errors;
255
+ };
@@ -48,9 +48,15 @@ export const delegatedAdminTokenContract = Object.freeze({
48
48
  * inspect, ensure, rotate and revoke it.
49
49
  * - `serviceAdminTokens`: mint short-lived, scope-limited Ed25519 Service Admin Tokens for hosted
50
50
  * services (`getServiceAdminAuthorityStatus`, `mintServiceAdminToken`).
51
+ * - `databaseRead`: bounded read-only inspection of Corestore-managed service databases and object
52
+ * storage buckets (`getCorestoreInventory`, `inspectServiceDatabase`, `inspectServiceObjectStorage`).
53
+ * - `workspace`: run commands, read/write files, and open interactive shells inside running
54
+ * deployment containers (`deploymentWorkspace*`, `deploymentShell*`).
51
55
  * - `monitor`: read clusters, nodes, services, deployments, runtime log attempts and assignment logs.
52
56
  */
53
- export const delegatedAdminTokenScopes = ['secrets', 'serviceCredentials', 'serviceAdminTokens', 'monitor'] as const;
57
+ export const delegatedAdminTokenScopes = [
58
+ 'secrets', 'serviceCredentials', 'serviceAdminTokens', 'databaseRead', 'workspace', 'monitor',
59
+ ] as const;
54
60
 
55
61
  export type TDelegatedAdminTokenScope = typeof delegatedAdminTokenScopes[number];
56
62
 
@@ -62,6 +68,15 @@ export const delegatedAdminTokenScopeRequests = Object.freeze({
62
68
  ] as const),
63
69
  serviceCredentials: Object.freeze(['getServiceMachineCredential', 'mutateServiceMachineCredential'] as const),
64
70
  serviceAdminTokens: Object.freeze(['getServiceAdminAuthorityStatus', 'mintServiceAdminToken'] as const),
71
+ databaseRead: Object.freeze([
72
+ 'getCorestoreInventory', 'inspectServiceDatabase', 'inspectServiceObjectStorage',
73
+ ] as const),
74
+ workspace: Object.freeze([
75
+ 'deploymentWorkspaceReadFile', 'deploymentWorkspaceWriteFile', 'deploymentWorkspaceReadDir',
76
+ 'deploymentWorkspaceMkdir', 'deploymentWorkspaceRm', 'deploymentWorkspaceExists',
77
+ 'deploymentWorkspaceExec', 'deploymentShellGetCommand', 'deploymentShellStart',
78
+ 'deploymentShellInput', 'deploymentShellKill',
79
+ ] as const),
65
80
  monitor: Object.freeze([
66
81
  'getClusters', 'getNodes', 'getServices', 'getDeployments', 'getServiceRuntimeLogAttempts',
67
82
  'getRuntimeAssignmentLogs',
@@ -335,6 +335,11 @@ export interface IGatewayCapabilities {
335
335
  * means unsupported.
336
336
  */
337
337
  observations?: boolean;
338
+ /**
339
+ * The mail area accepts `backupMxTargets` and `domains[].backupMxEnabled`. Cloudly may send
340
+ * those members only when the gateway advertises this flag.
341
+ */
342
+ backupMxTargets?: true;
338
343
  };
339
344
  remoteIngress: {
340
345
  enabled: boolean;
@@ -36,6 +36,7 @@ import type {
36
36
  IGatewayBlockRuleRow,
37
37
  IGatewayCoreMailCredentialVerifier,
38
38
  IGatewayCoreMailPeerRow,
39
+ IGatewayMailBackupMxTargetRow,
39
40
  IGatewayDnsClientHostnameRow,
40
41
  IGatewayDnsDomainRow,
41
42
  IGatewayDnsProtectedHostnameRow,
@@ -205,6 +206,7 @@ export interface IGatewayAreaRowWrites {
205
206
  smtpAccounts: IGatewaySmtpAccountRowWrite;
206
207
  identities: IGatewayMailIdentityRowWrite;
207
208
  coreMailPeers: IGatewayCoreMailPeerRowWrite;
209
+ backupMxTargets?: IGatewayMailBackupMxTargetRow;
208
210
  };
209
211
  edges: {
210
212
  hub: IGatewayEdgeHubSettings;
@@ -897,6 +897,11 @@ export interface IGatewayMailDomainRow {
897
897
  rateLimits: IGatewayMailDomainRateLimits | null;
898
898
  /** A set of edge ids or tags; empty reaches every mail edge (the gateway reads absent as empty). */
899
899
  edgeFilter: string[];
900
+ /**
901
+ * Optional opt-in to publish managed Backup MX records (e.g. `MX 30 backupmx.*`) for this domain.
902
+ * Sent only when the gateway advertises `email.backupMxTargets`.
903
+ */
904
+ backupMxEnabled?: boolean;
900
905
  }
901
906
 
902
907
  /** One SMTP submission account. */
@@ -968,6 +973,16 @@ export interface IGatewayCoreMailPeerRow {
968
973
  credentials: IGatewayCoreMailCredentialVerifier[];
969
974
  }
970
975
 
976
+ /** One managed Backup MX target published as a lower-priority MX record behind RemoteIngress mail edges. */
977
+ export interface IGatewayMailBackupMxTargetRow {
978
+ id: string;
979
+ hostname: string;
980
+ priority: number;
981
+ ipv4: string | null;
982
+ ipv6: string | null;
983
+ enabled: boolean;
984
+ }
985
+
971
986
  /** The `mail` area. */
972
987
  export interface IGatewayMailArea {
973
988
  /**
@@ -982,6 +997,11 @@ export interface IGatewayMailArea {
982
997
  smtpAccounts: IGatewaySmtpAccountRow[];
983
998
  identities: IGatewayMailIdentityRow[];
984
999
  coreMailPeers: IGatewayCoreMailPeerRow[];
1000
+ /**
1001
+ * Optional Backup MX targets for managed mail DNS reconciliation. Sent only when the gateway
1002
+ * advertises `email.backupMxTargets`.
1003
+ */
1004
+ backupMxTargets?: IGatewayMailBackupMxTargetRow[];
985
1005
  }
986
1006
 
987
1007
  // ---------------------------------------------------------------------------------------------