@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.
- package/README.md +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-XFL3XJWI.js → chunk-DYRDZNIR.js} +1560 -1397
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/apps/product-cli/package.json +1 -1
- package/src/apps/product-cli/src/cli.ts +38 -1
- package/src/apps/product-cli/src/command.ts +71 -0
- package/src/apps/product-cli/src/product-api.ts +34 -0
- package/src/packages/contracts/package.json +15 -0
- package/src/packages/contracts/src/framework-admission-corpus.ts +11 -11
- package/src/packages/contracts/src/framework-build-script.mjs +5 -4
- package/src/packages/contracts/src/growth-events.ts +307 -0
- package/src/packages/contracts/src/index.ts +2 -0
- package/src/packages/contracts/src/preview-view.ts +49 -0
- package/src/packages/contracts/src/previews.ts +507 -0
- package/src/packages/contracts/src/problem-policy.ts +7 -0
- package/src/packages/contracts/src/usage-log.ts +127 -0
- package/src/packages/sdk-ts/package.json +1 -1
- package/src/packages/sdk-ts/src/generated/index.ts +26 -0
- package/src/packages/sdk-ts/src/generated/sdk.gen.ts +173 -0
- package/src/packages/sdk-ts/src/generated/types.gen.ts +269 -0
|
@@ -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
|
+
}
|
|
@@ -16,6 +16,8 @@ export * from "./browser-capabilities.js";
|
|
|
16
16
|
export * from "./problem-policy.js";
|
|
17
17
|
export * from "./secret-names.js";
|
|
18
18
|
export * from "./project-data-changes.js";
|
|
19
|
+
export * from "./preview-view.js";
|
|
20
|
+
export type * from "./previews.js";
|
|
19
21
|
|
|
20
22
|
export type OhmyhostRuntimeMode = "static" | "edge" | "functions" | "auto";
|
|
21
23
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Public preview response, validated before a CLI or agent presents its private URL. */
|
|
2
|
+
export interface PreviewView {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly project_id: string;
|
|
5
|
+
readonly environment: "dev" | "prod";
|
|
6
|
+
readonly status: "cold" | "starting" | "ready" | "sleeping";
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly source: Readonly<{ sequence: number; commit_sha: string }> | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function parsePreviewView(
|
|
12
|
+
value: unknown,
|
|
13
|
+
scope?: { projectId: string; environment: "dev" | "prod" },
|
|
14
|
+
): PreviewView {
|
|
15
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
16
|
+
throw new TypeError("Invalid preview response");
|
|
17
|
+
const row = value as Record<string, unknown>;
|
|
18
|
+
const ulid = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/u;
|
|
19
|
+
if (
|
|
20
|
+
Object.keys(row).sort().join(",") !== "environment,id,project_id,source,status,url" ||
|
|
21
|
+
typeof row["id"] !== "string" ||
|
|
22
|
+
!ulid.test(row["id"]) ||
|
|
23
|
+
typeof row["project_id"] !== "string" ||
|
|
24
|
+
!ulid.test(row["project_id"]) ||
|
|
25
|
+
(row["environment"] !== "dev" && row["environment"] !== "prod") ||
|
|
26
|
+
!["cold", "starting", "ready", "sleeping"].includes(String(row["status"])) ||
|
|
27
|
+
typeof row["url"] !== "string" ||
|
|
28
|
+
!/^https:\/\/[a-z2-7]{51}[aq]\.preview(?:\.dev)?\.omh\.st$/u.test(row["url"]) ||
|
|
29
|
+
(scope !== undefined &&
|
|
30
|
+
(row["project_id"] !== scope.projectId || row["environment"] !== scope.environment))
|
|
31
|
+
)
|
|
32
|
+
throw new TypeError("Invalid preview response");
|
|
33
|
+
if (row["source"] !== null) {
|
|
34
|
+
const source = row["source"];
|
|
35
|
+
if (!source || typeof source !== "object" || Array.isArray(source))
|
|
36
|
+
throw new TypeError("Invalid preview response");
|
|
37
|
+
const item = source as Record<string, unknown>;
|
|
38
|
+
if (
|
|
39
|
+
Object.keys(item).sort().join(",") !== "commit_sha,sequence" ||
|
|
40
|
+
typeof item["sequence"] !== "number" ||
|
|
41
|
+
!Number.isSafeInteger(item["sequence"]) ||
|
|
42
|
+
item["sequence"] <= 0 ||
|
|
43
|
+
typeof item["commit_sha"] !== "string" ||
|
|
44
|
+
!/^(?!0{40}$)[0-9a-f]{40}$/u.test(item["commit_sha"])
|
|
45
|
+
)
|
|
46
|
+
throw new TypeError("Invalid preview response");
|
|
47
|
+
}
|
|
48
|
+
return value as PreviewView;
|
|
49
|
+
}
|