alchemy 0.69.1 → 0.70.1
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/bin/alchemy.js +3883 -3906
- package/bin/alchemy.ts +2 -0
- package/bin/commands/telemetry.ts +33 -0
- package/bin/services/execute-alchemy.ts +7 -0
- package/bin/trpc.ts +4 -9
- package/lib/alchemy.d.ts +7 -3
- package/lib/alchemy.d.ts.map +1 -1
- package/lib/alchemy.js +3 -15
- package/lib/alchemy.js.map +1 -1
- package/lib/apply.js +24 -9
- package/lib/apply.js.map +1 -1
- package/lib/aws/utils.d.ts +2 -1
- package/lib/aws/utils.d.ts.map +1 -1
- package/lib/aws/utils.js.map +1 -1
- package/lib/clickhouse/api/client.gen.d.ts +13 -0
- package/lib/clickhouse/api/client.gen.d.ts.map +1 -0
- package/lib/clickhouse/api/client.gen.js +7 -0
- package/lib/clickhouse/api/client.gen.js.map +1 -0
- package/lib/clickhouse/api/sdk.gen.d.ts +322 -0
- package/lib/clickhouse/api/sdk.gen.d.ts.map +1 -0
- package/lib/clickhouse/api/sdk.gen.js +683 -0
- package/lib/clickhouse/api/sdk.gen.js.map +1 -0
- package/lib/clickhouse/api/types.gen.d.ts +5030 -0
- package/lib/clickhouse/api/types.gen.d.ts.map +1 -0
- package/lib/clickhouse/api/types.gen.js +2 -0
- package/lib/clickhouse/api/types.gen.js.map +1 -0
- package/lib/clickhouse/api-key.d.ts +29 -0
- package/lib/clickhouse/api-key.d.ts.map +1 -0
- package/lib/clickhouse/api-key.js +83 -0
- package/lib/clickhouse/api-key.js.map +1 -0
- package/lib/clickhouse/api.d.ts +36 -0
- package/lib/clickhouse/api.d.ts.map +1 -0
- package/lib/clickhouse/api.js +48 -0
- package/lib/clickhouse/api.js.map +1 -0
- package/lib/clickhouse/index.d.ts +4 -0
- package/lib/clickhouse/index.d.ts.map +1 -0
- package/lib/clickhouse/index.js +4 -0
- package/lib/clickhouse/index.js.map +1 -0
- package/lib/clickhouse/organization.d.ts +16 -0
- package/lib/clickhouse/organization.d.ts.map +1 -0
- package/lib/clickhouse/organization.js +21 -0
- package/lib/clickhouse/organization.js.map +1 -0
- package/lib/clickhouse/service.d.ts +275 -0
- package/lib/clickhouse/service.d.ts.map +1 -0
- package/lib/clickhouse/service.js +274 -0
- package/lib/clickhouse/service.js.map +1 -0
- package/lib/cloudflare/account-api-token.d.ts.map +1 -1
- package/lib/cloudflare/account-api-token.js +1 -1
- package/lib/cloudflare/account-api-token.js.map +1 -1
- package/lib/cloudflare/api.d.ts.map +1 -1
- package/lib/cloudflare/api.js +2 -0
- package/lib/cloudflare/api.js.map +1 -1
- package/lib/cloudflare/bun-spa/bun-spa.d.ts +13 -0
- package/lib/cloudflare/bun-spa/bun-spa.d.ts.map +1 -0
- package/lib/cloudflare/bun-spa/bun-spa.js +95 -0
- package/lib/cloudflare/bun-spa/bun-spa.js.map +1 -0
- package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
- package/lib/cloudflare/compatibility-date.gen.js +1 -1
- package/lib/cloudflare/container.d.ts +11 -1
- package/lib/cloudflare/container.d.ts.map +1 -1
- package/lib/cloudflare/container.js.map +1 -1
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/miniflare/build-worker-options.d.ts.map +1 -1
- package/lib/cloudflare/miniflare/build-worker-options.js +33 -6
- package/lib/cloudflare/miniflare/build-worker-options.js.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-controller.d.ts.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-controller.js +2 -0
- package/lib/cloudflare/miniflare/miniflare-controller.js.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.d.ts +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.d.ts.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.js +36 -49
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.js.map +1 -1
- package/lib/cloudflare/permission-groups.d.ts +2 -3
- package/lib/cloudflare/permission-groups.d.ts.map +1 -1
- package/lib/cloudflare/permission-groups.js +10 -15
- package/lib/cloudflare/permission-groups.js.map +1 -1
- package/lib/cloudflare/redwood/redwood.d.ts +1 -1
- package/lib/cloudflare/redwood/redwood.js +1 -1
- package/lib/cloudflare/util/filter-env-bindings.d.ts +62 -0
- package/lib/cloudflare/util/filter-env-bindings.d.ts.map +1 -0
- package/lib/cloudflare/util/filter-env-bindings.js +81 -0
- package/lib/cloudflare/util/filter-env-bindings.js.map +1 -0
- package/lib/cloudflare/website.d.ts +2 -2
- package/lib/cloudflare/website.d.ts.map +1 -1
- package/lib/cloudflare/website.js +6 -18
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker-metadata.d.ts +1 -0
- package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
- package/lib/cloudflare/worker-metadata.js +1 -0
- package/lib/cloudflare/worker-metadata.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +11 -1
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.d.ts +8 -0
- package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
- package/lib/cloudflare/wrangler.json.js +3 -4
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/coinbase/client.d.ts +54 -0
- package/lib/coinbase/client.d.ts.map +1 -0
- package/lib/coinbase/client.js +89 -0
- package/lib/coinbase/client.js.map +1 -0
- package/lib/coinbase/evm-account.d.ts +118 -0
- package/lib/coinbase/evm-account.d.ts.map +1 -0
- package/lib/coinbase/evm-account.js +198 -0
- package/lib/coinbase/evm-account.js.map +1 -0
- package/lib/coinbase/evm-smart-account.d.ts +122 -0
- package/lib/coinbase/evm-smart-account.d.ts.map +1 -0
- package/lib/coinbase/evm-smart-account.js +213 -0
- package/lib/coinbase/evm-smart-account.js.map +1 -0
- package/lib/coinbase/faucet.d.ts +11 -0
- package/lib/coinbase/faucet.d.ts.map +1 -0
- package/lib/coinbase/faucet.js +146 -0
- package/lib/coinbase/faucet.js.map +1 -0
- package/lib/coinbase/index.d.ts +4 -0
- package/lib/coinbase/index.d.ts.map +1 -0
- package/lib/coinbase/index.js +4 -0
- package/lib/coinbase/index.js.map +1 -0
- package/lib/coinbase/types.d.ts +28 -0
- package/lib/coinbase/types.d.ts.map +1 -0
- package/lib/coinbase/types.js +4 -0
- package/lib/{util/telemetry → coinbase}/types.js.map +1 -1
- package/lib/coinbase/utils.d.ts +13 -0
- package/lib/coinbase/utils.d.ts.map +1 -0
- package/lib/coinbase/utils.js +17 -0
- package/lib/coinbase/utils.js.map +1 -0
- package/lib/neon/api/types.gen.d.ts +7 -2
- package/lib/neon/api/types.gen.d.ts.map +1 -1
- package/lib/planetscale/api/types.gen.d.ts +20 -4
- package/lib/planetscale/api/types.gen.d.ts.map +1 -1
- package/lib/planetscale/api.d.ts.map +1 -1
- package/lib/planetscale/api.js +1 -0
- package/lib/planetscale/api.js.map +1 -1
- package/lib/planetscale/password.d.ts.map +1 -1
- package/lib/planetscale/password.js +1 -13
- package/lib/planetscale/password.js.map +1 -1
- package/lib/resource.d.ts.map +1 -1
- package/lib/resource.js +7 -3
- package/lib/resource.js.map +1 -1
- package/lib/scope.d.ts +9 -9
- package/lib/scope.d.ts.map +1 -1
- package/lib/scope.js +18 -37
- package/lib/scope.js.map +1 -1
- package/lib/state/instrumented-state-store.d.ts +1 -3
- package/lib/state/instrumented-state-store.d.ts.map +1 -1
- package/lib/state/instrumented-state-store.js +19 -21
- package/lib/state/instrumented-state-store.js.map +1 -1
- package/lib/test/bun.d.ts.map +1 -1
- package/lib/test/bun.js +1 -2
- package/lib/test/bun.js.map +1 -1
- package/lib/test/vitest.d.ts.map +1 -1
- package/lib/test/vitest.js +1 -2
- package/lib/test/vitest.js.map +1 -1
- package/lib/util/diff.d.ts +5 -0
- package/lib/util/diff.d.ts.map +1 -0
- package/lib/util/diff.js +14 -0
- package/lib/util/diff.js.map +1 -0
- package/lib/util/idempotent-spawn.js +1 -1
- package/lib/util/idempotent-spawn.js.map +1 -1
- package/lib/util/telemetry.d.ts +53 -0
- package/lib/util/telemetry.d.ts.map +1 -0
- package/lib/util/telemetry.js +215 -0
- package/lib/util/telemetry.js.map +1 -0
- package/package.json +19 -1
- package/src/alchemy.ts +10 -20
- package/src/apply.ts +29 -12
- package/src/aws/utils.ts +2 -1
- package/src/clickhouse/api/client.gen.ts +28 -0
- package/src/clickhouse/api/sdk.gen.ts +1286 -0
- package/src/clickhouse/api/types.gen.ts +5898 -0
- package/src/clickhouse/api-key.ts +136 -0
- package/src/clickhouse/api.ts +84 -0
- package/src/clickhouse/index.ts +3 -0
- package/src/clickhouse/organization.ts +31 -0
- package/src/clickhouse/service.ts +668 -0
- package/src/cloudflare/account-api-token.ts +1 -4
- package/src/cloudflare/api.ts +2 -0
- package/src/cloudflare/bun-spa/bun-spa.ts +136 -0
- package/src/cloudflare/compatibility-date.gen.ts +1 -1
- package/src/cloudflare/container.ts +20 -1
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/miniflare/build-worker-options.ts +38 -8
- package/src/cloudflare/miniflare/miniflare-controller.ts +2 -0
- package/src/cloudflare/miniflare/miniflare-worker-proxy.ts +41 -58
- package/src/cloudflare/permission-groups.ts +21 -49
- package/src/cloudflare/redwood/redwood.ts +1 -1
- package/src/cloudflare/util/filter-env-bindings.ts +96 -0
- package/src/cloudflare/website.ts +11 -24
- package/src/cloudflare/worker-metadata.ts +2 -0
- package/src/cloudflare/worker.ts +12 -1
- package/src/cloudflare/wrangler.json.ts +12 -8
- package/src/coinbase/client.ts +146 -0
- package/src/coinbase/evm-account.ts +317 -0
- package/src/coinbase/evm-smart-account.ts +339 -0
- package/src/coinbase/faucet.ts +173 -0
- package/src/coinbase/index.ts +3 -0
- package/src/coinbase/types.ts +33 -0
- package/src/coinbase/utils.ts +19 -0
- package/src/neon/api/types.gen.ts +13 -1
- package/src/planetscale/api/types.gen.ts +22 -2
- package/src/planetscale/api.ts +1 -0
- package/src/planetscale/password.ts +1 -14
- package/src/resource.ts +11 -4
- package/src/scope.ts +29 -45
- package/src/state/instrumented-state-store.ts +27 -26
- package/src/test/bun.ts +1 -2
- package/src/test/vitest.ts +1 -2
- package/src/util/diff.ts +14 -0
- package/src/util/idempotent-spawn.ts +1 -1
- package/src/util/telemetry.ts +328 -0
- package/templates/tanstack-start/package.json +2 -2
- package/workers/tunnel-proxy.js +1 -1
- package/lib/util/telemetry/client.d.ts +0 -31
- package/lib/util/telemetry/client.d.ts.map +0 -1
- package/lib/util/telemetry/client.js +0 -121
- package/lib/util/telemetry/client.js.map +0 -1
- package/lib/util/telemetry/constants.d.ts +0 -5
- package/lib/util/telemetry/constants.d.ts.map +0 -1
- package/lib/util/telemetry/constants.js +0 -8
- package/lib/util/telemetry/constants.js.map +0 -1
- package/lib/util/telemetry/context.d.ts +0 -15
- package/lib/util/telemetry/context.d.ts.map +0 -1
- package/lib/util/telemetry/context.js +0 -128
- package/lib/util/telemetry/context.js.map +0 -1
- package/lib/util/telemetry/index.d.ts +0 -3
- package/lib/util/telemetry/index.d.ts.map +0 -1
- package/lib/util/telemetry/index.js +0 -3
- package/lib/util/telemetry/index.js.map +0 -1
- package/lib/util/telemetry/types.d.ts +0 -68
- package/lib/util/telemetry/types.d.ts.map +0 -1
- package/lib/util/telemetry/types.js +0 -1
- package/src/util/telemetry/client.ts +0 -156
- package/src/util/telemetry/constants.ts +0 -13
- package/src/util/telemetry/context.ts +0 -154
- package/src/util/telemetry/index.ts +0 -2
- package/src/util/telemetry/types.ts +0 -105
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import envPaths from "env-paths";
|
|
2
|
+
import { exec } from "node:child_process";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "pathe";
|
|
6
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
7
|
+
import type { Phase } from "../alchemy.ts";
|
|
8
|
+
import { Scope } from "../scope.ts";
|
|
9
|
+
import { logger } from "./logger.ts";
|
|
10
|
+
import { memoize } from "./memoize.ts";
|
|
11
|
+
|
|
12
|
+
const ALCHEMY_DIR = path.join(os.homedir(), ".alchemy");
|
|
13
|
+
const ID_PATH = path.join(ALCHEMY_DIR, "id");
|
|
14
|
+
const ID_PATH_LEGACY = path.join(
|
|
15
|
+
envPaths("alchemy", { suffix: "" }).config,
|
|
16
|
+
"id",
|
|
17
|
+
);
|
|
18
|
+
const DISABLED_PATH = path.join(ALCHEMY_DIR, "telemetry-disabled");
|
|
19
|
+
|
|
20
|
+
export const TELEMETRY_DISABLED =
|
|
21
|
+
!!process.env.ALCHEMY_TELEMETRY_DISABLED || !!process.env.DO_NOT_TRACK;
|
|
22
|
+
|
|
23
|
+
export const TELEMETRY_API_URL =
|
|
24
|
+
process.env.ALCHEMY_TELEMETRY_API_URL ?? "https://telemetry.alchemy.run";
|
|
25
|
+
export const SUPPRESS_TELEMETRY_ERRORS =
|
|
26
|
+
!!process.env.ALCHEMY_TELEMETRY_SUPPRESS_ERRORS;
|
|
27
|
+
|
|
28
|
+
export const getGlobalTelemetryDisabled = memoize(async () => {
|
|
29
|
+
const disabled = await fs
|
|
30
|
+
.readFile(DISABLED_PATH, "utf-8")
|
|
31
|
+
.then((data) => data.trim() === "true")
|
|
32
|
+
.catch(() => false);
|
|
33
|
+
return disabled;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export async function setGlobalTelemetryDisabled() {
|
|
37
|
+
await fs.mkdir(ALCHEMY_DIR, { recursive: true });
|
|
38
|
+
await fs.writeFile(DISABLED_PATH, "true");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function setGlobalTelemetryEnabled() {
|
|
42
|
+
await fs.rm(DISABLED_PATH, { force: true });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function getOrCreateUserId() {
|
|
46
|
+
async function readUserId(path: string) {
|
|
47
|
+
try {
|
|
48
|
+
return (await fs.readFile(path, "utf-8")).trim();
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const id = await readUserId(ID_PATH);
|
|
55
|
+
if (id) {
|
|
56
|
+
return id;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const legacyId = await readUserId(ID_PATH_LEGACY);
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const id = legacyId ?? crypto.randomUUID();
|
|
63
|
+
await fs.mkdir(ALCHEMY_DIR, { recursive: true });
|
|
64
|
+
await fs.writeFile(ID_PATH, id);
|
|
65
|
+
if (!legacyId) {
|
|
66
|
+
console.warn(
|
|
67
|
+
[
|
|
68
|
+
"Attention: To help improve Alchemy, we collect anonymous usage, performance, and error data.",
|
|
69
|
+
"You can opt out by setting the ALCHEMY_TELEMETRY_DISABLED or DO_NOT_TRACK environment variable to a truthy value.",
|
|
70
|
+
].join("\n"),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return id;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function getRootCommitHash() {
|
|
80
|
+
return new Promise<string | null>((resolve) => {
|
|
81
|
+
const command =
|
|
82
|
+
process.platform === "win32"
|
|
83
|
+
? `git rev-list --max-parents=0 HEAD | ForEach-Object { if (-not (git cat-file -p $_ | Select-String "^parent ")) { $_ } }`
|
|
84
|
+
: `git rev-list --max-parents=0 HEAD | xargs -r -I{} sh -c 'git cat-file -p {} | grep -q "^parent " || echo {}'`;
|
|
85
|
+
exec(command, (err, stdout) => {
|
|
86
|
+
if (err) {
|
|
87
|
+
resolve(null);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
resolve(stdout.trim());
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function getGitOriginUrlHash() {
|
|
96
|
+
return new Promise<string | null>((resolve) => {
|
|
97
|
+
exec("git config --get remote.origin.url", (err, stdout) => {
|
|
98
|
+
if (err) {
|
|
99
|
+
resolve(null);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
resolve(hashString(stdout.trim()));
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function getBranchName() {
|
|
108
|
+
return new Promise<string | null>((resolve) => {
|
|
109
|
+
exec("git rev-parse --abbrev-ref HEAD", (err, stdout) => {
|
|
110
|
+
if (err) {
|
|
111
|
+
resolve(null);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
resolve(stdout.trim());
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getRuntime() {
|
|
120
|
+
if (globalThis.Bun) return { name: "bun", version: Bun.version };
|
|
121
|
+
// @ts-expect-error
|
|
122
|
+
if (globalThis.Deno)
|
|
123
|
+
// @ts-expect-error
|
|
124
|
+
return { name: "deno", version: Deno.version?.deno ?? null };
|
|
125
|
+
// @ts-expect-error
|
|
126
|
+
if (globalThis.EdgeRuntime) return { name: "workerd", version: null };
|
|
127
|
+
if (globalThis.process?.versions?.node)
|
|
128
|
+
return { name: "node", version: process.versions.node };
|
|
129
|
+
return { name: null, version: null };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const PROVIDERS = [
|
|
133
|
+
{ env: "GITHUB_ACTIONS", provider: "GitHub Actions", isCI: true },
|
|
134
|
+
{ env: "GITLAB_CI", provider: "GitLab CI", isCI: true },
|
|
135
|
+
{ env: "CIRCLECI", provider: "CircleCI", isCI: true },
|
|
136
|
+
{ env: "JENKINS_URL", provider: "Jenkins", isCI: true },
|
|
137
|
+
{ env: "TRAVIS", provider: "Travis CI", isCI: true },
|
|
138
|
+
{ env: "NOW_BUILDER", provider: "Vercel", isCI: true },
|
|
139
|
+
{ env: "VERCEL", provider: "Vercel", isCI: false },
|
|
140
|
+
] as const;
|
|
141
|
+
|
|
142
|
+
function getEnvironment() {
|
|
143
|
+
for (const provider of PROVIDERS) {
|
|
144
|
+
if (process.env[provider.env]) {
|
|
145
|
+
return {
|
|
146
|
+
provider: provider.provider,
|
|
147
|
+
isCI: provider.isCI,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
provider: null,
|
|
153
|
+
isCI: !!process.env.CI,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export const collectData = memoize(async (): Promise<GenericTelemetryData> => {
|
|
158
|
+
const [
|
|
159
|
+
userId,
|
|
160
|
+
rootCommitHash,
|
|
161
|
+
gitOriginUrlHash,
|
|
162
|
+
branchHash,
|
|
163
|
+
runtime,
|
|
164
|
+
environment,
|
|
165
|
+
] = await Promise.all([
|
|
166
|
+
getOrCreateUserId(),
|
|
167
|
+
getRootCommitHash(),
|
|
168
|
+
getGitOriginUrlHash(),
|
|
169
|
+
getBranchName().then(hashString),
|
|
170
|
+
getRuntime(),
|
|
171
|
+
getEnvironment(),
|
|
172
|
+
]);
|
|
173
|
+
return {
|
|
174
|
+
userId: userId ?? "",
|
|
175
|
+
sessionId: crypto.randomUUID(),
|
|
176
|
+
platform: os.platform(),
|
|
177
|
+
osVersion: os.release(),
|
|
178
|
+
arch: os.arch(),
|
|
179
|
+
cpus: os.cpus().length,
|
|
180
|
+
memory: Math.round(os.totalmem() / 1024 / 1024),
|
|
181
|
+
rootCommitHash: rootCommitHash ?? "",
|
|
182
|
+
gitOriginUrl: gitOriginUrlHash ?? "",
|
|
183
|
+
gitBranchHash: branchHash ?? "",
|
|
184
|
+
runtime: runtime.name ?? "",
|
|
185
|
+
runtimeVersion: runtime.version ?? "",
|
|
186
|
+
ciProvider: environment.provider ?? "",
|
|
187
|
+
isCI: environment.isCI,
|
|
188
|
+
alchemyVersion: pkg.version,
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
export type GenericTelemetryData = {
|
|
193
|
+
userId: string;
|
|
194
|
+
sessionId: string;
|
|
195
|
+
platform: string;
|
|
196
|
+
osVersion: string;
|
|
197
|
+
arch: string;
|
|
198
|
+
cpus: number;
|
|
199
|
+
memory: number;
|
|
200
|
+
rootCommitHash: string;
|
|
201
|
+
gitOriginUrl: string;
|
|
202
|
+
gitBranchHash: string;
|
|
203
|
+
runtime: string;
|
|
204
|
+
runtimeVersion: string;
|
|
205
|
+
ciProvider: string;
|
|
206
|
+
isCI: boolean;
|
|
207
|
+
alchemyVersion: string;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export type ErrorData = {
|
|
211
|
+
errorTag: string;
|
|
212
|
+
errorMessage: string;
|
|
213
|
+
errorStack: string;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export type CliTelemetryData = {
|
|
217
|
+
command: string;
|
|
218
|
+
event: "cli.start" | "cli.success" | "cli.error";
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export type ResourceTelemetryData = {
|
|
222
|
+
phase: Phase;
|
|
223
|
+
event:
|
|
224
|
+
| "resource.start"
|
|
225
|
+
| "resource.success"
|
|
226
|
+
| "resource.error"
|
|
227
|
+
| "resource.skip"
|
|
228
|
+
| "resource.read";
|
|
229
|
+
resource: string;
|
|
230
|
+
status:
|
|
231
|
+
| "creating"
|
|
232
|
+
| "created"
|
|
233
|
+
| "updating"
|
|
234
|
+
| "updated"
|
|
235
|
+
| "deleting"
|
|
236
|
+
| "deleted"
|
|
237
|
+
| "unknown";
|
|
238
|
+
duration: number;
|
|
239
|
+
replaced: boolean;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export type StateStoreTelemetryData = {
|
|
243
|
+
event:
|
|
244
|
+
| "statestore.init"
|
|
245
|
+
| "statestore.deinit"
|
|
246
|
+
| "statestore.list"
|
|
247
|
+
| "statestore.count"
|
|
248
|
+
| "statestore.get"
|
|
249
|
+
| "statestore.getBatch"
|
|
250
|
+
| "statestore.all"
|
|
251
|
+
| "statestore.set"
|
|
252
|
+
| "statestore.delete";
|
|
253
|
+
stateStore: string;
|
|
254
|
+
duration: number;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export type AlchemyTelemetryData = {
|
|
258
|
+
event: "alchemy.start" | "alchemy.success" | "alchemy.error";
|
|
259
|
+
duration: number;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
async function isTelemetryDisabled() {
|
|
263
|
+
return (
|
|
264
|
+
Scope.getScope()?.noTrack ||
|
|
265
|
+
TELEMETRY_DISABLED ||
|
|
266
|
+
(await getGlobalTelemetryDisabled())
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export async function createAndSendEvent(
|
|
271
|
+
data:
|
|
272
|
+
| CliTelemetryData
|
|
273
|
+
| ResourceTelemetryData
|
|
274
|
+
| StateStoreTelemetryData
|
|
275
|
+
| AlchemyTelemetryData,
|
|
276
|
+
error?: Error,
|
|
277
|
+
) {
|
|
278
|
+
if (await isTelemetryDisabled()) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
const eventData = {
|
|
283
|
+
...data,
|
|
284
|
+
...("duration" in data
|
|
285
|
+
? { duration: Math.round(data.duration * 1000) }
|
|
286
|
+
: {}),
|
|
287
|
+
...(await collectData()),
|
|
288
|
+
...serializeError(error),
|
|
289
|
+
};
|
|
290
|
+
await fetch(TELEMETRY_API_URL, {
|
|
291
|
+
method: "POST",
|
|
292
|
+
headers: {
|
|
293
|
+
"Content-Type": "application/json",
|
|
294
|
+
},
|
|
295
|
+
body: JSON.stringify(eventData),
|
|
296
|
+
});
|
|
297
|
+
} catch (error) {
|
|
298
|
+
if (!SUPPRESS_TELEMETRY_ERRORS) {
|
|
299
|
+
logger.warn("Failed to send telemetry event:", error);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function hashString(input: string | null): Promise<string | null> {
|
|
305
|
+
if (input == null) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
const data = new TextEncoder().encode(input);
|
|
309
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
310
|
+
return Array.from(new Uint8Array(hashBuffer), (byte) =>
|
|
311
|
+
byte.toString(16).padStart(2, "0"),
|
|
312
|
+
).join("");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function serializeError(error: Error | undefined) {
|
|
316
|
+
if (error instanceof Error) {
|
|
317
|
+
return {
|
|
318
|
+
errorTag: error.name ?? "",
|
|
319
|
+
errorMessage: error.message?.replaceAll(os.homedir(), "~") ?? "", // redact home directory
|
|
320
|
+
errorStack: error.stack?.replaceAll(os.homedir(), "~") ?? "",
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
errorTag: "",
|
|
325
|
+
errorMessage: "",
|
|
326
|
+
errorStack: "",
|
|
327
|
+
};
|
|
328
|
+
}
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"vite-tsconfig-paths": "^5.1.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@cloudflare/vite-plugin": "
|
|
28
|
-
"@cloudflare/workers-types": "
|
|
27
|
+
"@cloudflare/vite-plugin": "^1.11.6",
|
|
28
|
+
"@cloudflare/workers-types": "^4.20250805.0",
|
|
29
29
|
"@testing-library/dom": "^10.4.0",
|
|
30
30
|
"@testing-library/react": "^16.2.0",
|
|
31
31
|
"@types/node": "^22.10.2",
|
package/workers/tunnel-proxy.js
CHANGED
|
@@ -34,7 +34,7 @@ var h={async fetch(e,r){let n=new URL(e.url);n.host=r.TUNNEL_HOST;let l=new Head
|
|
|
34
34
|
Alchemy</a>.</p>
|
|
35
35
|
</div>
|
|
36
36
|
<div class="bg-slate-200 px-5 py-3 flex flex-col w-full max-w-lg">
|
|
37
|
-
<p class="text-sm text-slate-500">Alchemy 0.
|
|
37
|
+
<p class="text-sm text-slate-500">Alchemy 0.70.1</p>
|
|
38
38
|
</div>
|
|
39
39
|
</div>
|
|
40
40
|
</body>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Phase } from "../../alchemy.ts";
|
|
2
|
-
import type { Telemetry } from "./types.ts";
|
|
3
|
-
export interface TelemetryClientOptions {
|
|
4
|
-
sessionId: string;
|
|
5
|
-
phase?: Phase;
|
|
6
|
-
enabled: boolean;
|
|
7
|
-
quiet: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface ITelemetryClient {
|
|
10
|
-
ready: Promise<unknown>;
|
|
11
|
-
record(event: Telemetry.EventInput): void;
|
|
12
|
-
finalize(): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export declare class NoopTelemetryClient implements ITelemetryClient {
|
|
15
|
-
ready: Promise<void>;
|
|
16
|
-
record(_: Telemetry.EventInput): void;
|
|
17
|
-
finalize(): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
export declare class TelemetryClient implements ITelemetryClient {
|
|
20
|
-
readonly options: TelemetryClientOptions;
|
|
21
|
-
private context;
|
|
22
|
-
private events;
|
|
23
|
-
constructor(options: TelemetryClientOptions);
|
|
24
|
-
get ready(): Promise<Telemetry.Context>;
|
|
25
|
-
record(event: Telemetry.EventInput, timestamp?: number): void;
|
|
26
|
-
private serializeError;
|
|
27
|
-
finalize(): Promise<void>;
|
|
28
|
-
private send;
|
|
29
|
-
static create({ phase, enabled, quiet, }: Omit<TelemetryClientOptions, "sessionId">): ITelemetryClient;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/util/telemetry/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAO9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACxB,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC;IAC1C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,KAAK,gBAAqB;IAC1B,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,UAAU;IAC9B,QAAQ;CAGT;AAED,qBAAa,eAAgB,YAAW,gBAAgB;IAI1C,QAAQ,CAAC,OAAO,EAAE,sBAAsB;IAHpD,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,MAAM,CAAyB;gBAElB,OAAO,EAAE,sBAAsB;IAUpD,IAAI,KAAK,+BAER;IAED,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,SAAa;IAS1D,OAAO,CAAC,cAAc;IAiBhB,QAAQ;YAQA,IAAI;IAsDlB,MAAM,CAAC,MAAM,CAAC,EACZ,KAAK,EACL,OAAO,EACP,KAAK,GACN,EAAE,IAAI,CAAC,sBAAsB,EAAE,WAAW,CAAC,GAAG,gBAAgB;CAchE"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import os from "node:os";
|
|
2
|
-
import { POSTHOG_CLIENT_API_HOST, POSTHOG_PROJECT_ID, TELEMETRY_DISABLED, } from "./constants.js";
|
|
3
|
-
import { context } from "./context.js";
|
|
4
|
-
export class NoopTelemetryClient {
|
|
5
|
-
ready = Promise.resolve();
|
|
6
|
-
record(_) { }
|
|
7
|
-
finalize() {
|
|
8
|
-
return Promise.resolve();
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export class TelemetryClient {
|
|
12
|
-
options;
|
|
13
|
-
context;
|
|
14
|
-
events = [];
|
|
15
|
-
constructor(options) {
|
|
16
|
-
this.options = options;
|
|
17
|
-
this.context = context({
|
|
18
|
-
sessionId: this.options.sessionId,
|
|
19
|
-
phase: this.options.phase,
|
|
20
|
-
});
|
|
21
|
-
this.record({
|
|
22
|
-
event: "app.start",
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
get ready() {
|
|
26
|
-
return this.context;
|
|
27
|
-
}
|
|
28
|
-
record(event, timestamp = Date.now()) {
|
|
29
|
-
const payload = {
|
|
30
|
-
...event,
|
|
31
|
-
error: this.serializeError(event.error),
|
|
32
|
-
timestamp,
|
|
33
|
-
};
|
|
34
|
-
this.events.push(payload);
|
|
35
|
-
}
|
|
36
|
-
serializeError(error) {
|
|
37
|
-
if (!error) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
if (error instanceof Error) {
|
|
41
|
-
return {
|
|
42
|
-
...error, // include additional properties from error object
|
|
43
|
-
name: error.name,
|
|
44
|
-
message: error.message?.replaceAll(os.homedir(), "~"), // redact home directory
|
|
45
|
-
stack: error.stack?.replaceAll(os.homedir(), "~"),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return error;
|
|
49
|
-
}
|
|
50
|
-
async finalize() {
|
|
51
|
-
await this.send(this.events).catch((error) => {
|
|
52
|
-
if (!this.options.quiet) {
|
|
53
|
-
console.warn(error);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
async send(events) {
|
|
58
|
-
if (events.length === 0) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const { userId, projectId, ...context } = await this.context;
|
|
62
|
-
const safeProjectId = projectId ?? `temp_${userId}`;
|
|
63
|
-
const groupResponse = await fetch(`${POSTHOG_CLIENT_API_HOST}/i/v0/e/`, {
|
|
64
|
-
method: "POST",
|
|
65
|
-
headers: {
|
|
66
|
-
"Content-Type": "application/json",
|
|
67
|
-
},
|
|
68
|
-
body: JSON.stringify({
|
|
69
|
-
api_key: POSTHOG_PROJECT_ID,
|
|
70
|
-
event: "$groupidentify",
|
|
71
|
-
distinct_id: "project-identify",
|
|
72
|
-
properties: {
|
|
73
|
-
$group_type: "project",
|
|
74
|
-
$group_key: safeProjectId,
|
|
75
|
-
},
|
|
76
|
-
}),
|
|
77
|
-
});
|
|
78
|
-
if (!groupResponse.ok) {
|
|
79
|
-
throw new Error(`Failed to send group identify: ${groupResponse.status} ${groupResponse.statusText} - ${await groupResponse.text()}`);
|
|
80
|
-
}
|
|
81
|
-
const response = await fetch(`${POSTHOG_CLIENT_API_HOST}/batch`, {
|
|
82
|
-
method: "POST",
|
|
83
|
-
headers: {
|
|
84
|
-
"Content-Type": "application/json",
|
|
85
|
-
},
|
|
86
|
-
body: JSON.stringify({
|
|
87
|
-
api_key: POSTHOG_PROJECT_ID,
|
|
88
|
-
historical_migration: false,
|
|
89
|
-
batch: events.map(({ event, timestamp, ...properties }) => ({
|
|
90
|
-
event,
|
|
91
|
-
properties: {
|
|
92
|
-
distinct_id: userId,
|
|
93
|
-
...context,
|
|
94
|
-
...properties,
|
|
95
|
-
projectId: safeProjectId,
|
|
96
|
-
$groups: { project: safeProjectId },
|
|
97
|
-
},
|
|
98
|
-
timestamp: new Date(timestamp).toISOString(),
|
|
99
|
-
})),
|
|
100
|
-
}),
|
|
101
|
-
});
|
|
102
|
-
if (!response.ok) {
|
|
103
|
-
throw new Error(`Failed to send telemetry: ${response.status} ${response.statusText} - ${await response.text()}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
static create({ phase, enabled, quiet, }) {
|
|
107
|
-
if (!enabled || TELEMETRY_DISABLED) {
|
|
108
|
-
if (!quiet) {
|
|
109
|
-
console.warn("[Alchemy] Telemetry is disabled.");
|
|
110
|
-
}
|
|
111
|
-
return new NoopTelemetryClient();
|
|
112
|
-
}
|
|
113
|
-
return new TelemetryClient({
|
|
114
|
-
sessionId: crypto.randomUUID(),
|
|
115
|
-
phase,
|
|
116
|
-
enabled,
|
|
117
|
-
quiet,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/util/telemetry/client.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/util/telemetry/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA6C,CAAC;AAErE,eAAO,MAAM,kBAAkB,SACyC,CAAC;AAGzE,eAAO,MAAM,uBAAuB,QACqC,CAAC;AAC1E,eAAO,MAAM,kBAAkB,QAEoB,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import envPaths from "env-paths";
|
|
2
|
-
export const CONFIG_DIR = envPaths("alchemy", { suffix: "" }).config;
|
|
3
|
-
export const TELEMETRY_DISABLED = !!process.env.ALCHEMY_TELEMETRY_DISABLED || !!process.env.DO_NOT_TRACK;
|
|
4
|
-
// TODO(sam): replace with permanent URL
|
|
5
|
-
export const POSTHOG_CLIENT_API_HOST = process.env.ALCHEMY_POSTHOG_CLIENT_API_HOST ?? "https://ph.alchemy.run";
|
|
6
|
-
export const POSTHOG_PROJECT_ID = process.env.ALCHEMY_POSTHOG_PROJECT_ID ??
|
|
7
|
-
"phc_A51Mi7Q63TvnNrvRMgvBxE1il0DAL66rVg4LdWPRsfK";
|
|
8
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/util/telemetry/constants.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC;AAErE,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;AAEzE,wCAAwC;AACxC,MAAM,CAAC,MAAM,uBAAuB,GAClC,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,wBAAwB,CAAC;AAC1E,MAAM,CAAC,MAAM,kBAAkB,GAC7B,OAAO,CAAC,GAAG,CAAC,0BAA0B;IACtC,iDAAiD,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Phase } from "../../alchemy.ts";
|
|
2
|
-
import type { Telemetry } from "./types.ts";
|
|
3
|
-
declare global {
|
|
4
|
-
var Deno: {
|
|
5
|
-
version: {
|
|
6
|
-
deno: string;
|
|
7
|
-
};
|
|
8
|
-
} | undefined;
|
|
9
|
-
var EdgeRuntime: Record<string, unknown> | undefined;
|
|
10
|
-
}
|
|
11
|
-
export declare function context(input: {
|
|
12
|
-
sessionId: string;
|
|
13
|
-
phase?: Phase;
|
|
14
|
-
}): Promise<Telemetry.Context>;
|
|
15
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/util/telemetry/context.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAmD5C,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,IAAI,EACJ;QACE,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;KACH,GACD,SAAS,CAAC;IACd,IAAI,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CACtD;AAiED,wBAAsB,OAAO,CAAC,KAAK,EAAE;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAkB7B"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { exec } from "node:child_process";
|
|
2
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import pkg from "../../../package.json" with { type: "json" };
|
|
6
|
-
import { CONFIG_DIR } from "./constants.js";
|
|
7
|
-
async function userId() {
|
|
8
|
-
const path = join(CONFIG_DIR, "id");
|
|
9
|
-
try {
|
|
10
|
-
return (await readFile(path, "utf-8")).trim();
|
|
11
|
-
}
|
|
12
|
-
catch { }
|
|
13
|
-
try {
|
|
14
|
-
await mkdir(CONFIG_DIR, { recursive: true });
|
|
15
|
-
}
|
|
16
|
-
catch { }
|
|
17
|
-
const id = crypto.randomUUID();
|
|
18
|
-
try {
|
|
19
|
-
await writeFile(path, id);
|
|
20
|
-
console.warn([
|
|
21
|
-
"Attention: To help improve Alchemy, we now collect anonymous usage, performance, and error data.",
|
|
22
|
-
"You can opt out by setting the ALCHEMY_TELEMETRY_DISABLED or DO_NOT_TRACK environment variable to a truthy value.",
|
|
23
|
-
].join("\n"));
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return id;
|
|
29
|
-
}
|
|
30
|
-
function projectId() {
|
|
31
|
-
return new Promise((resolve) => {
|
|
32
|
-
exec("git rev-list --max-parents=0 HEAD", (err, stdout) => {
|
|
33
|
-
if (err) {
|
|
34
|
-
resolve(null);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
resolve(stdout.trim());
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function system() {
|
|
42
|
-
return {
|
|
43
|
-
platform: os.platform(),
|
|
44
|
-
osVersion: os.release(),
|
|
45
|
-
arch: os.arch(),
|
|
46
|
-
cpus: os.cpus().length,
|
|
47
|
-
memory: os.totalmem() / 1024 / 1024,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const RUNTIMES = [
|
|
51
|
-
{
|
|
52
|
-
name: "bun",
|
|
53
|
-
detect: () => !!globalThis.Bun,
|
|
54
|
-
version: () => globalThis.Bun?.version,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
name: "deno",
|
|
58
|
-
detect: () => !!globalThis.Deno,
|
|
59
|
-
version: () => globalThis.Deno?.version?.deno,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: "workerd",
|
|
63
|
-
detect: () => !!globalThis.EdgeRuntime,
|
|
64
|
-
version: () => null,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "node",
|
|
68
|
-
detect: () => !!globalThis.process?.versions?.node,
|
|
69
|
-
version: () => process.versions.node,
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
function runtime() {
|
|
73
|
-
for (const runtime of RUNTIMES) {
|
|
74
|
-
if (runtime.detect()) {
|
|
75
|
-
return {
|
|
76
|
-
name: runtime.name,
|
|
77
|
-
version: runtime.version() ?? null,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
name: null,
|
|
83
|
-
version: null,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
const PROVIDERS = [
|
|
87
|
-
{ env: "GITHUB_ACTIONS", provider: "GitHub Actions", isCI: true },
|
|
88
|
-
{ env: "GITLAB_CI", provider: "GitLab CI", isCI: true },
|
|
89
|
-
{ env: "CIRCLECI", provider: "CircleCI", isCI: true },
|
|
90
|
-
{ env: "JENKINS_URL", provider: "Jenkins", isCI: true },
|
|
91
|
-
{ env: "TRAVIS", provider: "Travis CI", isCI: true },
|
|
92
|
-
{ env: "NOW_BUILDER", provider: "Vercel", isCI: true },
|
|
93
|
-
{ env: "VERCEL", provider: "Vercel", isCI: false },
|
|
94
|
-
];
|
|
95
|
-
function environment() {
|
|
96
|
-
for (const provider of PROVIDERS) {
|
|
97
|
-
if (process.env[provider.env]) {
|
|
98
|
-
return {
|
|
99
|
-
provider: provider.provider,
|
|
100
|
-
isCI: provider.isCI,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
provider: null,
|
|
106
|
-
isCI: !!process.env.CI,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
export async function context(input) {
|
|
110
|
-
const env = environment();
|
|
111
|
-
const [uid, pid] = await Promise.all([
|
|
112
|
-
env.isCI ? null : userId(),
|
|
113
|
-
projectId(),
|
|
114
|
-
]);
|
|
115
|
-
return {
|
|
116
|
-
userId: uid,
|
|
117
|
-
projectId: pid,
|
|
118
|
-
sessionId: input.sessionId,
|
|
119
|
-
system: system(),
|
|
120
|
-
runtime: runtime(),
|
|
121
|
-
environment: env,
|
|
122
|
-
alchemy: {
|
|
123
|
-
version: pkg.version,
|
|
124
|
-
phase: input.phase,
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=context.js.map
|