@amerged/ohmyhost-cli 0.1.58 → 0.1.59
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/README.md +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-XFL3XJWI.js → chunk-KBB6XJQ7.js} +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/apps/product-cli/package.json +1 -1
- package/src/packages/contracts/package.json +10 -0
- package/src/packages/contracts/src/growth-events.ts +307 -0
- package/src/packages/contracts/src/usage-log.ts +127 -0
- package/src/packages/sdk-ts/package.json +1 -1
package/README.md
CHANGED
package/dist/bin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createRequire as __ohmyhostCreateRequire } from "node:module"; const require = __ohmyhostCreateRequire(import.meta.url);
|
|
3
3
|
import {
|
|
4
4
|
runProductionCli
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-KBB6XJQ7.js";
|
|
6
6
|
import "./chunk-7D2RFLWM.js";
|
|
7
7
|
|
|
8
8
|
// apps/product-cli/dist/bin.js
|
|
@@ -46389,7 +46389,7 @@ function exact4(v, keys) {
|
|
|
46389
46389
|
// apps/product-cli/package.json
|
|
46390
46390
|
var package_default = {
|
|
46391
46391
|
name: "@ohmyhost/product-cli",
|
|
46392
|
-
version: "0.1.
|
|
46392
|
+
version: "0.1.59",
|
|
46393
46393
|
private: true,
|
|
46394
46394
|
ohmyhost: {
|
|
46395
46395
|
deployment: "production",
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -181,6 +181,16 @@
|
|
|
181
181
|
"source": "./src/managed-sources.ts",
|
|
182
182
|
"types": "./dist/managed-sources.d.ts",
|
|
183
183
|
"import": "./dist/managed-sources.js"
|
|
184
|
+
},
|
|
185
|
+
"./growth-events": {
|
|
186
|
+
"source": "./src/growth-events.ts",
|
|
187
|
+
"types": "./dist/growth-events.d.ts",
|
|
188
|
+
"import": "./dist/growth-events.js"
|
|
189
|
+
},
|
|
190
|
+
"./usage-log": {
|
|
191
|
+
"source": "./src/usage-log.ts",
|
|
192
|
+
"types": "./dist/usage-log.d.ts",
|
|
193
|
+
"import": "./dist/usage-log.js"
|
|
184
194
|
}
|
|
185
195
|
},
|
|
186
196
|
"scripts": {
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/** Closed, minimized records accepted by the private growth measurement plane. */
|
|
2
|
+
export const GROWTH_EVENT_NAMES = [
|
|
3
|
+
"landing_view",
|
|
4
|
+
"cta_clicked",
|
|
5
|
+
"prompt_copy_succeeded",
|
|
6
|
+
"prompt_copy_failed",
|
|
7
|
+
"account_created",
|
|
8
|
+
"account_deleted",
|
|
9
|
+
"provider_auth_succeeded",
|
|
10
|
+
"login_started",
|
|
11
|
+
"callback_received",
|
|
12
|
+
"login_failed",
|
|
13
|
+
"portal_login_succeeded",
|
|
14
|
+
"workspace_ready",
|
|
15
|
+
"product_call_succeeded",
|
|
16
|
+
"product_call_failed",
|
|
17
|
+
"project_created",
|
|
18
|
+
"source_initialized",
|
|
19
|
+
"source_version_saved",
|
|
20
|
+
"deployment_requested",
|
|
21
|
+
"deployment_succeeded",
|
|
22
|
+
"deployment_failed",
|
|
23
|
+
"preview_open_clicked",
|
|
24
|
+
"payment_succeeded",
|
|
25
|
+
"refund_recorded",
|
|
26
|
+
"dispute_recorded",
|
|
27
|
+
] as const;
|
|
28
|
+
export const GROWTH_ERRORS = [
|
|
29
|
+
"invalid_input",
|
|
30
|
+
"invalid_link",
|
|
31
|
+
"login_context_missing",
|
|
32
|
+
"login_state_mismatch",
|
|
33
|
+
"login_expired",
|
|
34
|
+
"provider_denied",
|
|
35
|
+
"provider_unavailable",
|
|
36
|
+
"token_exchange_failed",
|
|
37
|
+
"identity_failed",
|
|
38
|
+
"onboarding_failed",
|
|
39
|
+
"authorization_denied",
|
|
40
|
+
"source_failed",
|
|
41
|
+
"build_failed",
|
|
42
|
+
"health_failed",
|
|
43
|
+
"quota_blocked",
|
|
44
|
+
"unknown",
|
|
45
|
+
] as const;
|
|
46
|
+
export interface GrowthEventV1 {
|
|
47
|
+
schema_version: 1;
|
|
48
|
+
event_id: string;
|
|
49
|
+
event_name: (typeof GROWTH_EVENT_NAMES)[number];
|
|
50
|
+
outcome: "attempted" | "succeeded" | "failed" | "cancelled";
|
|
51
|
+
occurred_at: string;
|
|
52
|
+
received_at: string;
|
|
53
|
+
platform_environment: "development" | "production";
|
|
54
|
+
producer: "website" | "control_api" | "core" | "workos" | "billing";
|
|
55
|
+
evidence_kind: "event" | "snapshot";
|
|
56
|
+
flow_id: string | null;
|
|
57
|
+
account_id: string | null;
|
|
58
|
+
organization_id: string | null;
|
|
59
|
+
project_id: string | null;
|
|
60
|
+
operation_id: string | null;
|
|
61
|
+
deployment_id: string | null;
|
|
62
|
+
transport: "portal" | "remote_mcp" | "rest" | "local_client_reported" | "unknown";
|
|
63
|
+
client_class: "unknown" | "other" | "chatgpt" | "claude" | "codex" | "cursor" | "cli" | "browser";
|
|
64
|
+
client_class_trust: "verified" | "reported" | "unknown";
|
|
65
|
+
error_class: (typeof GROWTH_ERRORS)[number] | null;
|
|
66
|
+
campaign_key: string | null;
|
|
67
|
+
request_country: string | null;
|
|
68
|
+
platform_version?: string | null;
|
|
69
|
+
}
|
|
70
|
+
interface FactBase {
|
|
71
|
+
schema_version: 1;
|
|
72
|
+
fact_id: string;
|
|
73
|
+
source_id: string;
|
|
74
|
+
occurred_at: string | null;
|
|
75
|
+
observed_at: string;
|
|
76
|
+
source_version: string;
|
|
77
|
+
account_id: string | null;
|
|
78
|
+
organization_id: string | null;
|
|
79
|
+
project_id: string | null;
|
|
80
|
+
operation_id: string | null;
|
|
81
|
+
}
|
|
82
|
+
export interface DeploymentFactV1 extends FactBase {
|
|
83
|
+
fact_type: "deployment";
|
|
84
|
+
deployment_id: string;
|
|
85
|
+
environment_id: string;
|
|
86
|
+
target_environment: "dev" | "prod";
|
|
87
|
+
kind: "deploy" | "promotion" | "rollback";
|
|
88
|
+
status: "succeeded" | "failed";
|
|
89
|
+
succeeded_at: string | null;
|
|
90
|
+
health_status: "passed" | "failed" | "unknown";
|
|
91
|
+
health_evidence_id: string | null;
|
|
92
|
+
}
|
|
93
|
+
export interface PaymentFactV1 extends FactBase {
|
|
94
|
+
fact_type: "payment";
|
|
95
|
+
provider_fact_id: string;
|
|
96
|
+
payment_id: string | null;
|
|
97
|
+
amount_minor: number;
|
|
98
|
+
currency: string;
|
|
99
|
+
money_effect: "received" | "refunded" | "withdrawn" | "restored" | "none";
|
|
100
|
+
}
|
|
101
|
+
export type GrowthFactV1 = DeploymentFactV1 | PaymentFactV1;
|
|
102
|
+
export interface GrowthMetricQuery {
|
|
103
|
+
metric: string;
|
|
104
|
+
cohort_start: string;
|
|
105
|
+
cohort_end: string;
|
|
106
|
+
as_of: string;
|
|
107
|
+
platform_environment: "development" | "production";
|
|
108
|
+
segment?: "all" | "test" | "non_test";
|
|
109
|
+
}
|
|
110
|
+
export interface GrowthMetricResult {
|
|
111
|
+
metric: string;
|
|
112
|
+
numerator: number;
|
|
113
|
+
denominator: number;
|
|
114
|
+
mature_count: number;
|
|
115
|
+
pending_count: number;
|
|
116
|
+
as_of: string;
|
|
117
|
+
source_watermarks: Record<string, string | null>;
|
|
118
|
+
evidence_kind: "event" | "snapshot" | "mixed";
|
|
119
|
+
quality_flags: string[];
|
|
120
|
+
}
|
|
121
|
+
export interface MoneyCohortResult {
|
|
122
|
+
currency: string;
|
|
123
|
+
gross_receipts: number;
|
|
124
|
+
refunds: number;
|
|
125
|
+
withdrawn: number;
|
|
126
|
+
restored: number;
|
|
127
|
+
net_receipts: number;
|
|
128
|
+
open_disputes: number;
|
|
129
|
+
as_of: string;
|
|
130
|
+
source_watermarks: Record<string, string | null>;
|
|
131
|
+
quality_flags: string[];
|
|
132
|
+
}
|
|
133
|
+
const eventKeys = [
|
|
134
|
+
"schema_version",
|
|
135
|
+
"event_id",
|
|
136
|
+
"event_name",
|
|
137
|
+
"outcome",
|
|
138
|
+
"occurred_at",
|
|
139
|
+
"received_at",
|
|
140
|
+
"platform_environment",
|
|
141
|
+
"producer",
|
|
142
|
+
"evidence_kind",
|
|
143
|
+
"flow_id",
|
|
144
|
+
"account_id",
|
|
145
|
+
"organization_id",
|
|
146
|
+
"project_id",
|
|
147
|
+
"operation_id",
|
|
148
|
+
"deployment_id",
|
|
149
|
+
"transport",
|
|
150
|
+
"client_class",
|
|
151
|
+
"client_class_trust",
|
|
152
|
+
"error_class",
|
|
153
|
+
"campaign_key",
|
|
154
|
+
"request_country",
|
|
155
|
+
];
|
|
156
|
+
const baseKeys = [
|
|
157
|
+
"schema_version",
|
|
158
|
+
"fact_type",
|
|
159
|
+
"fact_id",
|
|
160
|
+
"source_id",
|
|
161
|
+
"occurred_at",
|
|
162
|
+
"observed_at",
|
|
163
|
+
"source_version",
|
|
164
|
+
"account_id",
|
|
165
|
+
"organization_id",
|
|
166
|
+
"project_id",
|
|
167
|
+
"operation_id",
|
|
168
|
+
];
|
|
169
|
+
const deploymentKeys = [
|
|
170
|
+
...baseKeys,
|
|
171
|
+
"deployment_id",
|
|
172
|
+
"environment_id",
|
|
173
|
+
"target_environment",
|
|
174
|
+
"kind",
|
|
175
|
+
"status",
|
|
176
|
+
"succeeded_at",
|
|
177
|
+
"health_status",
|
|
178
|
+
"health_evidence_id",
|
|
179
|
+
];
|
|
180
|
+
const paymentKeys = [
|
|
181
|
+
...baseKeys,
|
|
182
|
+
"provider_fact_id",
|
|
183
|
+
"payment_id",
|
|
184
|
+
"amount_minor",
|
|
185
|
+
"currency",
|
|
186
|
+
"money_effect",
|
|
187
|
+
];
|
|
188
|
+
function record(
|
|
189
|
+
input: unknown,
|
|
190
|
+
keys: readonly string[],
|
|
191
|
+
optional: readonly string[] = [],
|
|
192
|
+
): Record<string, unknown> {
|
|
193
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
194
|
+
throw new Error("invalid growth record");
|
|
195
|
+
const r = input as Record<string, unknown>;
|
|
196
|
+
if (
|
|
197
|
+
Object.keys(r).some((key) => !keys.includes(key) && !optional.includes(key)) ||
|
|
198
|
+
keys.some((k) => !Object.hasOwn(r, k)) ||
|
|
199
|
+
new TextEncoder().encode(JSON.stringify(r)).length > 4096
|
|
200
|
+
)
|
|
201
|
+
throw new Error("invalid growth fields");
|
|
202
|
+
return r;
|
|
203
|
+
}
|
|
204
|
+
function one(r: Record<string, unknown>, k: string, choices: readonly unknown[]) {
|
|
205
|
+
if (!choices.includes(r[k])) throw new Error(`invalid ${k}`);
|
|
206
|
+
}
|
|
207
|
+
function id(r: Record<string, unknown>, k: string, nullable = false) {
|
|
208
|
+
const v = r[k];
|
|
209
|
+
if (nullable && v === null) return;
|
|
210
|
+
if (typeof v !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_:-]{0,199}$/.test(v))
|
|
211
|
+
throw new Error(`invalid ${k}`);
|
|
212
|
+
}
|
|
213
|
+
function date(r: Record<string, unknown>, k: string, nullable = false) {
|
|
214
|
+
const v = r[k];
|
|
215
|
+
if (nullable && v === null) return;
|
|
216
|
+
if (
|
|
217
|
+
typeof v !== "string" ||
|
|
218
|
+
!/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d{1,6})?Z$/.test(v) ||
|
|
219
|
+
!Number.isFinite(Date.parse(v))
|
|
220
|
+
)
|
|
221
|
+
throw new Error(`invalid ${k}`);
|
|
222
|
+
}
|
|
223
|
+
export function parseGrowthEvent(input: unknown): GrowthEventV1 {
|
|
224
|
+
const r = record(input, eventKeys, ["platform_version"]);
|
|
225
|
+
if (r["platform_version"] !== undefined) id(r, "platform_version", true);
|
|
226
|
+
one(r, "schema_version", [1]);
|
|
227
|
+
one(r, "event_name", GROWTH_EVENT_NAMES);
|
|
228
|
+
one(r, "outcome", ["attempted", "succeeded", "failed", "cancelled"]);
|
|
229
|
+
one(r, "platform_environment", ["development", "production"]);
|
|
230
|
+
one(r, "producer", ["website", "control_api", "core", "workos", "billing"]);
|
|
231
|
+
one(r, "evidence_kind", ["event", "snapshot"]);
|
|
232
|
+
for (const k of ["event_id"]) id(r, k);
|
|
233
|
+
for (const k of [
|
|
234
|
+
"flow_id",
|
|
235
|
+
"account_id",
|
|
236
|
+
"organization_id",
|
|
237
|
+
"project_id",
|
|
238
|
+
"operation_id",
|
|
239
|
+
"deployment_id",
|
|
240
|
+
"campaign_key",
|
|
241
|
+
])
|
|
242
|
+
id(r, k, true);
|
|
243
|
+
date(r, "occurred_at");
|
|
244
|
+
date(r, "received_at");
|
|
245
|
+
one(r, "transport", ["portal", "remote_mcp", "rest", "local_client_reported", "unknown"]);
|
|
246
|
+
one(r, "client_class", [
|
|
247
|
+
"unknown",
|
|
248
|
+
"other",
|
|
249
|
+
"chatgpt",
|
|
250
|
+
"claude",
|
|
251
|
+
"codex",
|
|
252
|
+
"cursor",
|
|
253
|
+
"cli",
|
|
254
|
+
"browser",
|
|
255
|
+
]);
|
|
256
|
+
one(r, "client_class_trust", ["verified", "reported", "unknown"]);
|
|
257
|
+
one(r, "error_class", [null, ...GROWTH_ERRORS]);
|
|
258
|
+
if (
|
|
259
|
+
r["request_country"] !== null &&
|
|
260
|
+
(typeof r["request_country"] !== "string" ||
|
|
261
|
+
!/^[A-Z]{2}$/.test(r["request_country"]) ||
|
|
262
|
+
(r["producer"] !== "website" &&
|
|
263
|
+
!(r["producer"] === "control_api" && r["transport"] === "portal")))
|
|
264
|
+
)
|
|
265
|
+
throw new Error("invalid request_country");
|
|
266
|
+
if (
|
|
267
|
+
r["producer"] === "website" &&
|
|
268
|
+
(r["account_id"] !== null ||
|
|
269
|
+
r["organization_id"] !== null ||
|
|
270
|
+
r["project_id"] !== null ||
|
|
271
|
+
r["operation_id"] !== null ||
|
|
272
|
+
r["deployment_id"] !== null)
|
|
273
|
+
)
|
|
274
|
+
throw new Error("anonymous identity");
|
|
275
|
+
if (r["client_class_trust"] === "verified" && r["transport"] === "local_client_reported")
|
|
276
|
+
throw new Error("unverified client");
|
|
277
|
+
return r as unknown as GrowthEventV1;
|
|
278
|
+
}
|
|
279
|
+
export function parseGrowthFact(input: unknown): GrowthFactV1 {
|
|
280
|
+
const type = (input as { fact_type?: unknown } | null)?.fact_type;
|
|
281
|
+
const r = record(input, type === "deployment" ? deploymentKeys : paymentKeys);
|
|
282
|
+
one(r, "schema_version", [1]);
|
|
283
|
+
one(r, "fact_type", ["deployment", "payment"]);
|
|
284
|
+
for (const k of ["fact_id", "source_id"]) id(r, k);
|
|
285
|
+
for (const k of ["account_id", "organization_id", "project_id", "operation_id"]) id(r, k, true);
|
|
286
|
+
date(r, "occurred_at", true);
|
|
287
|
+
date(r, "observed_at");
|
|
288
|
+
id(r, "source_version");
|
|
289
|
+
if (type === "deployment") {
|
|
290
|
+
for (const k of ["deployment_id", "environment_id"]) id(r, k);
|
|
291
|
+
id(r, "health_evidence_id", true);
|
|
292
|
+
date(r, "succeeded_at", true);
|
|
293
|
+
one(r, "target_environment", ["dev", "prod"]);
|
|
294
|
+
one(r, "kind", ["deploy", "promotion", "rollback"]);
|
|
295
|
+
one(r, "status", ["succeeded", "failed"]);
|
|
296
|
+
one(r, "health_status", ["passed", "failed", "unknown"]);
|
|
297
|
+
} else {
|
|
298
|
+
id(r, "provider_fact_id");
|
|
299
|
+
id(r, "payment_id", true);
|
|
300
|
+
if (!Number.isSafeInteger(r["amount_minor"]) || (r["amount_minor"] as number) < 0)
|
|
301
|
+
throw new Error("invalid amount_minor");
|
|
302
|
+
if (typeof r["currency"] !== "string" || !/^[A-Z]{3}$/.test(r["currency"]))
|
|
303
|
+
throw new Error("invalid currency");
|
|
304
|
+
one(r, "money_effect", ["received", "refunded", "withdrawn", "restored", "none"]);
|
|
305
|
+
}
|
|
306
|
+
return r as unknown as GrowthFactV1;
|
|
307
|
+
}
|
|
@@ -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
|
+
}
|