@amerged/ohmyhost-cli 0.1.58 → 0.1.60

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.
@@ -0,0 +1,507 @@
1
+ /** Private contracts between Control API, Core and the project preview runtime. */
2
+ export type PreviewEnvironment = "dev" | "prod";
3
+ export type PreviewState = "cold" | "starting" | "ready" | "sleeping";
4
+
5
+ /** Assigned by Core at accepted source publication, not inferred from delivery time. */
6
+ export interface SourceVersion {
7
+ readonly sourceConnectionId: string;
8
+ readonly sourceGeneration: number;
9
+ readonly sequence: number;
10
+ readonly commitSha: string;
11
+ }
12
+
13
+ /** Only the trusted Control API handles plaintext labels and the encryption keyring. */
14
+ export interface PreviewCapabilityEnvelope {
15
+ /** SHA-256 of the canonical ASCII token, encoded as lowercase hex. */
16
+ readonly lookupSha256: string;
17
+ /** Base64url AES-GCM ciphertext including authentication tag. */
18
+ readonly ciphertext: string;
19
+ /** Base64url 96-bit AES-GCM nonce. */
20
+ readonly nonce: string;
21
+ readonly keyVersion: number;
22
+ readonly tokenGeneration: number;
23
+ }
24
+
25
+ export interface PreviewDelegation {
26
+ readonly grantId: string;
27
+ readonly clientId: string;
28
+ readonly consentHash: string;
29
+ readonly action: string;
30
+ readonly authorizationRestriction?: Readonly<{
31
+ actions?: readonly string[];
32
+ organizationIds?: readonly string[];
33
+ projectIds?: readonly string[];
34
+ mailDomainIds?: readonly string[];
35
+ }>;
36
+ }
37
+
38
+ export interface PreviewCustomerScope {
39
+ readonly organizationId: string;
40
+ readonly projectId: string;
41
+ readonly environment: PreviewEnvironment;
42
+ readonly principalId: string;
43
+ readonly delegation?: PreviewDelegation;
44
+ }
45
+
46
+ /** Opaque custody stays inside the trusted runtime and never appears in a public response. */
47
+ export interface PreviewBackup {
48
+ readonly handle: string;
49
+ readonly source: SourceVersion;
50
+ readonly expiresAt: string;
51
+ }
52
+
53
+ export interface PreviewRecord {
54
+ readonly previewId: string;
55
+ readonly organizationId: string;
56
+ readonly projectId: string;
57
+ readonly environment: PreviewEnvironment;
58
+ readonly environmentId: string;
59
+ readonly dataEnvironmentId: string;
60
+ readonly assignmentVersion: number;
61
+ readonly billingEpochId: string;
62
+ readonly ownershipVersion: number;
63
+ readonly lifecycleVersion: number;
64
+ readonly region: "eu" | "us";
65
+ readonly rowVersion: number;
66
+ readonly runtimeGeneration: number;
67
+ readonly tokenGeneration: number;
68
+ readonly authGeneration: number;
69
+ readonly state: PreviewState;
70
+ readonly targetSource: SourceVersion | null;
71
+ readonly appliedSource: SourceVersion | null;
72
+ readonly lastActivityAt: string;
73
+ /** Non-null while Dev is entitled; runtime must recheck at this deadline. */
74
+ readonly paidUntil: string | null;
75
+ readonly retirement: "none" | "rotating" | "destroying" | "suspended";
76
+ }
77
+
78
+ /** Returned exclusively to the authorized Control API; never to a guest or a public client. */
79
+ export interface PreviewCustomerRecord {
80
+ readonly preview: PreviewRecord;
81
+ readonly capability: PreviewCapabilityEnvelope;
82
+ }
83
+
84
+ export interface PreparePreviewResult {
85
+ readonly environmentId: string;
86
+ readonly preview: PreviewCustomerRecord | null;
87
+ }
88
+
89
+ export interface EnsurePreviewInput extends PreviewCustomerScope {
90
+ readonly environmentId: string;
91
+ readonly previewId: string;
92
+ readonly capability: PreviewCapabilityEnvelope;
93
+ }
94
+
95
+ export interface RotatePreviewInput extends PreviewCustomerScope {
96
+ readonly previewId: string;
97
+ readonly expectedRowVersion: number;
98
+ readonly expectedTokenGeneration: number;
99
+ readonly requestId: string;
100
+ readonly capability: PreviewCapabilityEnvelope;
101
+ }
102
+
103
+ export interface DestroyPreviewInput extends PreviewCustomerScope {
104
+ readonly previewId: string;
105
+ readonly expectedRowVersion: number;
106
+ readonly requestId: string;
107
+ }
108
+
109
+ export interface PreviewRuntimeFence {
110
+ readonly previewId: string;
111
+ readonly runtimeGeneration: number;
112
+ readonly tokenGeneration: number;
113
+ }
114
+
115
+ export interface PreviewRuntimeRecord extends PreviewRecord {
116
+ readonly backup: PreviewBackup | null;
117
+ }
118
+
119
+ /** Control API's deliberately separate capability, including encrypted recovery custody. */
120
+ export interface ProductApiPreviewRuntime {
121
+ readInitialGithubCandidate(input: PreviewCustomerScope): Promise<PreviewGithubCandidate | null>;
122
+ acceptInitialGithubSource(
123
+ input: PreviewCustomerScope & {
124
+ readonly sourceConnectionId: string;
125
+ readonly sourceGeneration: number;
126
+ readonly expectedSequence: number;
127
+ readonly branchRef: string;
128
+ readonly configGeneration: number | null;
129
+ readonly observedDefaultBranch: string | null;
130
+ readonly observedHead: string;
131
+ },
132
+ ): Promise<{ readonly sequence: number; readonly accepted: boolean }>;
133
+ readGithubCandidates(input: {
134
+ readonly inboxEventId: string;
135
+ readonly claimId: string;
136
+ }): Promise<readonly PreviewGithubCandidate[]>;
137
+ acceptGithubSource(input: {
138
+ readonly inboxEventId: string;
139
+ readonly claimId: string;
140
+ readonly organizationId: string;
141
+ readonly projectId: string;
142
+ readonly sourceConnectionId: string;
143
+ readonly sourceGeneration: number;
144
+ readonly expectedSequence: number;
145
+ readonly branchRef: string;
146
+ readonly configGeneration: number | null;
147
+ readonly observedDefaultBranch: string | null;
148
+ readonly observedHead: string;
149
+ }): Promise<{ readonly sequence: number; readonly accepted: boolean }>;
150
+ prepare(input: PreviewCustomerScope): Promise<PreparePreviewResult>;
151
+ get(input: PreviewCustomerScope): Promise<PreviewCustomerRecord | null>;
152
+ listProjectPendingSources(input: {
153
+ readonly organizationId: string;
154
+ readonly projectId: string;
155
+ }): Promise<readonly { readonly previewId: string; readonly sequence: number }[]>;
156
+ ensure(input: EnsurePreviewInput): Promise<PreviewCustomerRecord>;
157
+ rotate(input: RotatePreviewInput): Promise<PreviewCustomerRecord>;
158
+ confirmRotation(input: PreviewRuntimeFence): Promise<void>;
159
+ destroy(input: DestroyPreviewInput): Promise<PreviewRuntimeRecord>;
160
+ confirmDestroy(input: PreviewRuntimeFence): Promise<void>;
161
+ }
162
+
163
+ /** Only this private capability may operate a preview; no recoverable token is exposed. */
164
+ export interface ProjectPreviewRuntime {
165
+ listPendingNativePreparations(input: {
166
+ readonly limit: number;
167
+ readonly after?: string;
168
+ }): Promise<
169
+ readonly {
170
+ readonly operationId: string;
171
+ readonly previewId: string;
172
+ readonly sourceSequence: number;
173
+ readonly state: "pending" | "running" | "uncertain";
174
+ }[]
175
+ >;
176
+ getNativePreparationCursor(): Promise<string | null>;
177
+ setNativePreparationCursor(input: {
178
+ readonly expected: string | null;
179
+ readonly next: string | null;
180
+ }): Promise<void>;
181
+ queueNativePreparation(input: {
182
+ readonly fence: PreviewRuntimeFence;
183
+ readonly source: SourceVersion;
184
+ readonly buildPlanSha256: string;
185
+ readonly authProvider: "omh-native";
186
+ }): Promise<PreviewNativePreparation>;
187
+ readNativePreparation(input: {
188
+ readonly previewId: string;
189
+ readonly sourceSequence: number;
190
+ }): Promise<PreviewNativePreparation | null>;
191
+ listCleanupCandidates(input: {
192
+ readonly limit: number;
193
+ readonly after?: string;
194
+ }): Promise<readonly PreviewCleanupCandidate[]>;
195
+ claimScopeCleanup(input: {
196
+ readonly previewId: string;
197
+ readonly expectedRowVersion: number;
198
+ }): Promise<PreviewCleanupState>;
199
+ finishScopeCleanup(
200
+ input: PreviewRuntimeFence & { readonly deletedBackupHandle: string | null },
201
+ ): Promise<void>;
202
+ resumeSuspended(input: {
203
+ readonly previewId: string;
204
+ readonly expectedRowVersion: number;
205
+ }): Promise<PreviewCleanupState>;
206
+ getCleanupState(input: { readonly previewId: string }): Promise<PreviewCleanupState | null>;
207
+ confirmRotation(input: PreviewRuntimeFence): Promise<void>;
208
+ confirmDestroy(input: PreviewRuntimeFence): Promise<void>;
209
+ recordStopped(input: PreviewRuntimeFence): Promise<PreviewRuntimeRecord>;
210
+ resolveTokenHash(input: { readonly tokenHash: string }): Promise<PreviewRuntimeRecord | null>;
211
+ authorizeRuntime(input: PreviewRuntimeFence): Promise<PreviewRuntimeRecord | null>;
212
+ authorizeDatabase(input: PreviewRuntimeFence): Promise<{
213
+ readonly preview: PreviewRuntimeRecord;
214
+ readonly binding: PreviewDatabaseRegistration;
215
+ } | null>;
216
+ readSource(input: {
217
+ readonly previewId: string;
218
+ readonly runtimeGeneration: number;
219
+ readonly tokenGeneration: number;
220
+ readonly sequence: number;
221
+ }): Promise<PreviewSourceDescriptor | null>;
222
+ recordState(
223
+ input: PreviewRuntimeFence & {
224
+ readonly expectedRowVersion: number;
225
+ readonly state: PreviewState;
226
+ },
227
+ ): Promise<PreviewRuntimeRecord>;
228
+ recordAppliedSource(
229
+ input: PreviewRuntimeFence & {
230
+ readonly expectedRowVersion: number;
231
+ readonly source: SourceVersion;
232
+ },
233
+ ): Promise<PreviewRuntimeRecord>;
234
+ recordBackup(
235
+ input: PreviewRuntimeFence & {
236
+ readonly expectedRowVersion: number;
237
+ readonly backup: PreviewBackup | null;
238
+ },
239
+ ): Promise<PreviewRuntimeRecord>;
240
+ listBackupCleanup(
241
+ input: PreviewRuntimeFence,
242
+ ): Promise<readonly { readonly cleanupId: string; readonly handle: string }[]>;
243
+ acknowledgeBackupCleanup(
244
+ input: PreviewRuntimeFence & { readonly cleanupId: string; readonly handle: string },
245
+ ): Promise<void>;
246
+ claimExpiredBackup(
247
+ input: PreviewRuntimeFence & { readonly expectedRowVersion: number },
248
+ ): Promise<PreviewRuntimeRecord>;
249
+ renewActivity(
250
+ input: PreviewRuntimeFence & {
251
+ readonly expectedRowVersion: number;
252
+ readonly occurredAt: string;
253
+ },
254
+ ): Promise<PreviewRuntimeRecord>;
255
+ reserveUsage(
256
+ input: PreviewRuntimeFence & {
257
+ readonly expectedRowVersion: number;
258
+ readonly intervalId: string;
259
+ readonly applicationId: string;
260
+ readonly seconds: number;
261
+ readonly holdSequence: number;
262
+ readonly start: boolean;
263
+ },
264
+ ): Promise<PreviewUsageReservation>;
265
+ closeUsage(input: {
266
+ readonly previewId: string;
267
+ readonly runtimeGeneration: number;
268
+ readonly intervalId: string;
269
+ readonly activeMilliseconds: number;
270
+ readonly containerStartAttempted: boolean;
271
+ }): Promise<void>;
272
+
273
+ listPendingSources(input: {
274
+ readonly limit: number;
275
+ }): Promise<readonly { readonly previewId: string; readonly sequence: number }[]>;
276
+ acknowledgeSource(input: {
277
+ readonly previewId: string;
278
+ readonly sequence: number;
279
+ }): Promise<void>;
280
+ }
281
+
282
+ /** Server-selected, current source grant; contains no provider credential. */
283
+ export interface PreviewSourceDescriptor {
284
+ readonly targetSource: SourceVersion;
285
+ readonly provider: "github" | "managed";
286
+ readonly organizationId: string;
287
+ readonly billingEpochId: string;
288
+ readonly projectId: string;
289
+ readonly environmentId: string;
290
+ readonly sourceConnectionId: string;
291
+ readonly region: "eu" | "us";
292
+ readonly repository: Readonly<{ owner: string; name: string; externalRepositoryId: string }>;
293
+ readonly grant: Readonly<{
294
+ status: "approved";
295
+ grantId: string;
296
+ organizationId: string;
297
+ billingEpochId: string;
298
+ projectId: string;
299
+ sourceConnectionId: string;
300
+ installationId: number | null;
301
+ repositoryId: number | string;
302
+ owner: string;
303
+ repository: string;
304
+ permission: "contents:read";
305
+ grantedAt: string;
306
+ revokedAt: null;
307
+ }>;
308
+ }
309
+
310
+ export interface PreviewUsageReservation {
311
+ readonly preview: PreviewRuntimeRecord;
312
+ readonly intervalId: string;
313
+ readonly seconds: number;
314
+ readonly quotedMicros: number;
315
+ }
316
+ export interface PreviewUsageSettlement {
317
+ readonly intervalId: string;
318
+ readonly activeMilliseconds: number;
319
+ readonly cpuMilliseconds: number;
320
+ readonly chargedMicros: number;
321
+ }
322
+
323
+ /** Current PGCF registration; connection credentials remain in the regional database runtime. */
324
+ export interface PreviewDatabaseRegistration {
325
+ readonly provider: "pgcf";
326
+ readonly organizationId: string;
327
+ readonly projectId: string;
328
+ readonly physicalEnvironmentId: string;
329
+ readonly region: "eu" | "us";
330
+ readonly operationId: string;
331
+ readonly registrationVersion: number;
332
+ readonly providerProjectId: string;
333
+ readonly databaseId: string;
334
+ readonly originHost: string;
335
+ readonly originDatabase: string;
336
+ readonly originUser: string;
337
+ readonly authorizedEnvironmentIds: readonly string[];
338
+ readonly status: "active" | "revoked";
339
+ }
340
+
341
+ /** Bound only to the trusted provider metering reader, not the preview actor or guest. */
342
+ export interface PreviewUsageReporterRuntime {
343
+ getReconciliationCursor(): Promise<PreviewUsageCursor | null>;
344
+ setReconciliationCursor(input: {
345
+ readonly expected: PreviewUsageCursor | null;
346
+ readonly next: PreviewUsageCursor | null;
347
+ }): Promise<void>;
348
+ listUsageForReconciliation(input: {
349
+ readonly limit: number;
350
+ readonly now?: string;
351
+ readonly after?: {
352
+ readonly previewId: string;
353
+ readonly runtimeGeneration: number;
354
+ readonly intervalId: string;
355
+ };
356
+ }): Promise<readonly PreviewUsageSnapshot[]>;
357
+ observeUsage(input: {
358
+ readonly previewId: string;
359
+ readonly runtimeGeneration: number;
360
+ readonly intervalId: string;
361
+ readonly cpuMilliseconds: number;
362
+ readonly observedAt: string;
363
+ readonly providerFactId: string;
364
+ }): Promise<PreviewUsageSettlement>;
365
+ }
366
+ export interface PreviewUsageSnapshot extends PreviewAwaitingUsage {
367
+ readonly state: "awaiting_provider" | "settled";
368
+ readonly cpuMilliseconds: number | null;
369
+ readonly providerFactId: string | null;
370
+ readonly observedAt: string | null;
371
+ }
372
+
373
+ export interface PreviewAwaitingUsage {
374
+ readonly previewId: string;
375
+ readonly runtimeGeneration: number;
376
+ readonly intervalId: string;
377
+ readonly applicationId: string;
378
+ readonly organizationId: string;
379
+ readonly projectId: string;
380
+ readonly activeMilliseconds: number;
381
+ readonly startedAt: string;
382
+ readonly closedAt: string;
383
+ }
384
+
385
+ export interface PreviewGithubCandidate {
386
+ readonly organizationId: string;
387
+ readonly projectId: string;
388
+ readonly sourceConnectionId: string;
389
+ readonly sourceGeneration: number;
390
+ readonly expectedSequence: number;
391
+ readonly branchRef: string | null;
392
+ readonly configGeneration: number | null;
393
+ readonly installationId: string;
394
+ readonly repositoryId: string;
395
+ readonly repositoryFullName: string;
396
+ }
397
+
398
+ /** Ciphertext custody is available only to the private Runtime Secret Delivery service. */
399
+ export interface PreviewSecretAuthorityRuntime {
400
+ listCustomerSecretNames(input: {
401
+ readonly fence: PreviewRuntimeFence;
402
+ }): Promise<readonly string[]>;
403
+ readEnvelopes(input: {
404
+ readonly fence: PreviewRuntimeFence;
405
+ readonly names: readonly string[];
406
+ }): Promise<{
407
+ readonly preview: PreviewRuntimeRecord;
408
+ readonly envelopes: readonly PreviewSecretEnvelope[];
409
+ }>;
410
+ }
411
+ export interface PreviewSecretEnvelope {
412
+ readonly organizationId: string;
413
+ readonly projectId: string;
414
+ readonly environmentId: string;
415
+ readonly name: string;
416
+ readonly ciphertext: Uint8Array;
417
+ readonly nonce: Uint8Array;
418
+ readonly valueSha256: Uint8Array;
419
+ readonly keyVersion: number;
420
+ readonly revision: number;
421
+ }
422
+
423
+ export interface PreviewCleanupState {
424
+ readonly previewId: string;
425
+ readonly region: "eu" | "us";
426
+ readonly rowVersion: number;
427
+ readonly runtimeGeneration: number;
428
+ readonly tokenGeneration: number;
429
+ readonly authGeneration: number;
430
+ readonly state: PreviewState;
431
+ readonly retirement: "none" | "rotating" | "destroying" | "suspended";
432
+ readonly hasBackup: boolean;
433
+ readonly backupHandle: string | null;
434
+ readonly backupExpiresAt: string | null;
435
+ }
436
+
437
+ export interface PreviewCleanupCandidate extends PreviewCleanupState {
438
+ readonly reason:
439
+ | "scope"
440
+ | "entitlement"
441
+ | "assignment"
442
+ | "source"
443
+ | "expired"
444
+ | "backup_cleanup"
445
+ | "rotation"
446
+ | "destroy"
447
+ | "resume";
448
+ }
449
+
450
+ export interface PreviewNativePreparation {
451
+ readonly operationId: string;
452
+ readonly claimId: string;
453
+ readonly previewId: string;
454
+ readonly runtimeGeneration: number;
455
+ readonly tokenGeneration: number;
456
+ readonly authGeneration: number;
457
+ readonly state: "pending" | "running" | "uncertain" | "succeeded" | "failed";
458
+ readonly errorCode: string | null;
459
+ }
460
+
461
+ export interface PreviewUsageCursor {
462
+ readonly previewId: string;
463
+ readonly runtimeGeneration: number;
464
+ readonly intervalId: string;
465
+ }
466
+
467
+ export const PREVIEW_NATIVE_POLICY_SCHEMA_VERSION = 1 as const;
468
+ export const PREVIEW_NATIVE_POLICY_SCHEMA_SHA256 =
469
+ "567f5ef1b6adc6d3d02b067d8e7886d44c4700e3236e6cac754462feddf4e5f9" as const;
470
+
471
+ /** Shared source-sync wire types; the framework plan is supplied by the owning platform package. */
472
+ export type PreviewSourceOperation =
473
+ | Readonly<{ kind: "delete"; path: string }>
474
+ | Readonly<{
475
+ kind: "write";
476
+ path: string;
477
+ bytes: Uint8Array;
478
+ sha256: string;
479
+ executable: boolean;
480
+ }>;
481
+ export interface PreviewSourcePatch {
482
+ readonly from: SourceVersion | null;
483
+ readonly to: SourceVersion;
484
+ readonly operations: readonly PreviewSourceOperation[];
485
+ readonly dependenciesChanged: boolean;
486
+ }
487
+ export interface PreviewSourceInstall {
488
+ readonly applicationRoot: string;
489
+ readonly manager: "npm" | "pnpm" | "yarn" | "bun";
490
+ readonly version: string;
491
+ readonly lockfile: string;
492
+ readonly command: string;
493
+ }
494
+ export interface PreviewSourceInspection<FrameworkPlan = unknown> {
495
+ readonly frameworkPlan: FrameworkPlan;
496
+ readonly buildPlanSha256: string;
497
+ readonly companionSource?: Readonly<{
498
+ schemaVersion: "ohmyhost.vite-api-companion/v1" | "ohmyhost.worker-module/v1";
499
+ path: string;
500
+ byteLength: number;
501
+ sha256: string;
502
+ }>;
503
+ }
504
+ export interface PreviewSourceDelta<FrameworkPlan = unknown> extends PreviewSourcePatch {
505
+ readonly install: PreviewSourceInstall | null;
506
+ readonly inspection: PreviewSourceInspection<FrameworkPlan>;
507
+ }
@@ -1,5 +1,12 @@
1
1
  /** Canonical public status, retry policy and recovery text shared by the API and clients. */
2
2
  export const PROBLEM_POLICY = {
3
+ preview_version_conflict: {
4
+ status: 409,
5
+ retryable: true,
6
+ action:
7
+ "Read the preview state, then repeat the original request with the same idempotency key.",
8
+ title: "Preview changed",
9
+ },
3
10
  source_generation_conflict: {
4
11
  status: 409,
5
12
  retryable: false,
@@ -0,0 +1,127 @@
1
+ import { PROBLEM_POLICY } from "./problem-policy.js";
2
+
3
+ /** Minimized, immutable telemetry. Never include request or response payloads. */
4
+ export interface UsageLogRecord {
5
+ schema_version: 1;
6
+ record_id: string;
7
+ invocation_id: string;
8
+ parent_invocation_id: string | null;
9
+ phase: "started" | "finished";
10
+ occurred_at: string;
11
+ started_at: string;
12
+ platform_environment: "development" | "production";
13
+ transport: "remote_mcp" | "rest";
14
+ operation: string;
15
+ account_id: string | null;
16
+ organization_id: string | null;
17
+ project_id: string | null;
18
+ operation_id: string | null;
19
+ operation_status: "queued" | "running" | "succeeded" | "failed" | "cancelled" | null;
20
+ outcome: "started" | "succeeded" | "accepted" | "failed" | "cancelled";
21
+ duration_ms: number | null;
22
+ http_status: number | null;
23
+ error_code: string | null;
24
+ platform_version: string | null;
25
+ }
26
+ const keys = [
27
+ "schema_version",
28
+ "record_id",
29
+ "invocation_id",
30
+ "parent_invocation_id",
31
+ "phase",
32
+ "occurred_at",
33
+ "started_at",
34
+ "platform_environment",
35
+ "transport",
36
+ "operation",
37
+ "account_id",
38
+ "organization_id",
39
+ "project_id",
40
+ "operation_id",
41
+ "operation_status",
42
+ "outcome",
43
+ "duration_ms",
44
+ "http_status",
45
+ "error_code",
46
+ "platform_version",
47
+ ] as const;
48
+ const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
49
+ const ulid = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u;
50
+ const id = (value: unknown, pattern: RegExp) =>
51
+ value === null || (typeof value === "string" && pattern.test(value));
52
+ const iso = (value: unknown) =>
53
+ typeof value === "string" &&
54
+ Number.isFinite(Date.parse(value)) &&
55
+ new Date(value).toISOString() === value;
56
+ const fallbackErrors = new Set(["unknown", "transport_error", "internal_error", "cancelled"]);
57
+ export function safeUsageErrorCode(value: unknown): string {
58
+ return typeof value === "string" &&
59
+ (Object.hasOwn(PROBLEM_POLICY, value) || fallbackErrors.has(value))
60
+ ? value
61
+ : "unknown";
62
+ }
63
+ export function parseUsageLogRecord(input: unknown): UsageLogRecord {
64
+ if (!input || typeof input !== "object" || Array.isArray(input))
65
+ throw new TypeError("usage_record_invalid");
66
+ const v = input as Record<string, unknown>;
67
+ if (
68
+ Object.keys(v).length !== keys.length ||
69
+ keys.some((key) => !Object.hasOwn(v, key)) ||
70
+ v["schema_version"] !== 1 ||
71
+ typeof v["record_id"] !== "string" ||
72
+ !uuid.test(v["record_id"]) ||
73
+ typeof v["invocation_id"] !== "string" ||
74
+ !uuid.test(v["invocation_id"]) ||
75
+ !id(v["parent_invocation_id"], uuid) ||
76
+ !["started", "finished"].includes(v["phase"] as string) ||
77
+ !iso(v["occurred_at"]) ||
78
+ !iso(v["started_at"]) ||
79
+ !["development", "production"].includes(v["platform_environment"] as string) ||
80
+ !["remote_mcp", "rest"].includes(v["transport"] as string) ||
81
+ typeof v["operation"] !== "string" ||
82
+ !/^[A-Za-z][A-Za-z0-9_]{0,127}$/u.test(v["operation"]) ||
83
+ !id(v["account_id"], /^user_[A-Za-z0-9_]{1,123}$/u) ||
84
+ !id(v["organization_id"], ulid) ||
85
+ !id(v["project_id"], ulid) ||
86
+ !id(v["operation_id"], ulid) ||
87
+ !(
88
+ v["operation_status"] === null ||
89
+ ["queued", "running", "succeeded", "failed", "cancelled"].includes(
90
+ v["operation_status"] as string,
91
+ )
92
+ ) ||
93
+ !(
94
+ v["duration_ms"] === null ||
95
+ (Number.isSafeInteger(v["duration_ms"]) &&
96
+ (v["duration_ms"] as number) >= 0 &&
97
+ (v["duration_ms"] as number) <= 604800000)
98
+ ) ||
99
+ !(
100
+ v["http_status"] === null ||
101
+ (Number.isInteger(v["http_status"]) &&
102
+ (v["http_status"] as number) >= 100 &&
103
+ (v["http_status"] as number) <= 599)
104
+ ) ||
105
+ !(
106
+ v["error_code"] === null ||
107
+ (typeof v["error_code"] === "string" &&
108
+ safeUsageErrorCode(v["error_code"]) === v["error_code"])
109
+ ) ||
110
+ !(
111
+ v["platform_version"] === null ||
112
+ (typeof v["platform_version"] === "string" &&
113
+ /^[A-Za-z0-9][A-Za-z0-9._+-]{0,79}$/u.test(v["platform_version"]))
114
+ ) ||
115
+ (v["phase"] === "started"
116
+ ? v["outcome"] !== "started" ||
117
+ v["operation_status"] !== null ||
118
+ v["duration_ms"] !== null ||
119
+ v["http_status"] !== null ||
120
+ v["error_code"] !== null
121
+ : !["succeeded", "accepted", "failed", "cancelled"].includes(v["outcome"] as string) ||
122
+ v["duration_ms"] === null ||
123
+ (v["outcome"] !== "failed" && v["outcome"] !== "cancelled" && v["error_code"] !== null))
124
+ )
125
+ throw new TypeError("usage_record_invalid");
126
+ return Object.fromEntries(keys.map((key) => [key, v[key]])) as unknown as UsageLogRecord;
127
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohmyhost/sdk-ts",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {