devflare 1.0.0-next.39 → 1.0.0-next.40
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/dist/_chunks/account-BtWcv3X9.js +462 -0
- package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
- package/dist/_chunks/ai-CBEuLdoP.js +322 -0
- package/dist/_chunks/api-TzdliH-6.js +568 -0
- package/dist/_chunks/build-3T6O4uIg.js +24 -0
- package/dist/_chunks/build-artifacts-8TqBSQkG.js +483 -0
- package/dist/_chunks/cli-BTF1X4SG.js +1128 -0
- package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
- package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
- package/dist/_chunks/command-utils-BsfkmTqh.js +45 -0
- package/dist/_chunks/compiler-uoyAQ8zW.js +424 -0
- package/dist/_chunks/config-D5u-bEkn.js +78 -0
- package/dist/_chunks/config-path-DCPto4XB.js +42 -0
- package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
- package/dist/_chunks/decorators-QmV57ixr.js +19 -0
- package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
- package/dist/_chunks/deploy-DMTr6JeR.js +915 -0
- package/dist/_chunks/dev-CvRHmRFZ.js +3456 -0
- package/dist/_chunks/doctor-DIG8DoFU.js +219 -0
- package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
- package/dist/_chunks/env-S0_nMVz1.js +125 -0
- package/dist/_chunks/family-DXC5SdFK.js +143 -0
- package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
- package/dist/_chunks/glob-CmQOvunB.js +56 -0
- package/dist/_chunks/init-3moXTgpb.js +165 -0
- package/dist/_chunks/loader-DLXO60RO.js +1153 -0
- package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
- package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
- package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
- package/dist/_chunks/local-secrets-DMmEOygL.js +123 -0
- package/dist/_chunks/local-workflow-entrypoints-Wip3o1u8.js +90 -0
- package/dist/_chunks/login-BmnDzDlH.js +51 -0
- package/dist/_chunks/package-metadata-DAuCkyvK.js +39 -0
- package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
- package/dist/_chunks/preview-BhqDmq8I.js +456 -0
- package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
- package/dist/_chunks/preview-resources-DdXj8LMM.js +358 -0
- package/dist/_chunks/previews-Dlr13x5M.js +1134 -0
- package/dist/_chunks/productions-D3AnOHac.js +411 -0
- package/dist/_chunks/ref-CYJNAAe_.js +178 -0
- package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
- package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
- package/dist/_chunks/resolve-package-Y84HB3Nt.js +133 -0
- package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
- package/dist/_chunks/routes-C3FqES2W.js +796 -0
- package/dist/_chunks/runtime-FvXvfuZ2.js +550 -0
- package/dist/_chunks/schema-normalization-DWVleVxo.js +477 -0
- package/dist/_chunks/secrets-70eN0Q6C.js +95 -0
- package/dist/_chunks/token-kguIDmej.js +333 -0
- package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
- package/dist/_chunks/types-OrLbzv4I.js +476 -0
- package/dist/_chunks/ui-BUoZApvE.js +103 -0
- package/dist/_chunks/usage-BBTGzjon.js +272 -0
- package/dist/_chunks/vite-CsI0E-uV.js +1235 -0
- package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
- package/dist/_chunks/worker-CS1jgNFE.js +410 -0
- package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
- package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
- package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
- package/dist/bridge/index.d.ts +6 -6
- package/dist/bridge/miniflare.d.ts +2 -2
- package/dist/bridge/proxy.d.ts +1 -1
- package/dist/bridge/v2/body-streams.d.ts +1 -1
- package/dist/bridge/v2/codec.d.ts +4 -4
- package/dist/bridge/v2/index.d.ts +10 -10
- package/dist/bridge/v2/serialization.d.ts +1 -1
- package/dist/bridge/v2/value-codec.d.ts +1 -1
- package/dist/bridge/v2/value-serialization.d.ts.map +1 -1
- package/dist/bridge/v2/ws-relay.d.ts +3 -3
- package/dist/browser-shim/index.d.ts +2 -2
- package/dist/browser.d.ts +70 -70
- package/dist/browser.js +74 -2462
- package/dist/bundler/do-bundler.d.ts +1 -1
- package/dist/bundler/index.d.ts +3 -3
- package/dist/bundler/rolldown-shared.d.ts +1 -1
- package/dist/bundler/worker-bundler.d.ts +1 -1
- package/dist/cli/build-manifest.d.ts +1 -1
- package/dist/cli/command-utils.d.ts +1 -1
- package/dist/cli/commands/account.d.ts +1 -1
- package/dist/cli/commands/ai.d.ts +1 -1
- package/dist/cli/commands/build-artifacts.d.ts +5 -5
- package/dist/cli/commands/build.d.ts +1 -1
- package/dist/cli/commands/config.d.ts +1 -1
- package/dist/cli/commands/deploy/prepare.d.ts +2 -2
- package/dist/cli/commands/deploy/runtime.d.ts +1 -1
- package/dist/cli/commands/deploy/verification.d.ts +1 -1
- package/dist/cli/commands/deploy.d.ts +1 -1
- package/dist/cli/commands/dev.d.ts +1 -1
- package/dist/cli/commands/doctor.d.ts +1 -1
- package/dist/cli/commands/init.d.ts +1 -1
- package/dist/cli/commands/login.d.ts +1 -1
- package/dist/cli/commands/previews-support/cleanup.d.ts +1 -1
- package/dist/cli/commands/previews-support/family.d.ts +3 -3
- package/dist/cli/commands/previews-support/render.d.ts +3 -3
- package/dist/cli/commands/previews-support/theme.d.ts +2 -2
- package/dist/cli/commands/previews-support/types.d.ts +2 -2
- package/dist/cli/commands/previews.d.ts +1 -1
- package/dist/cli/commands/productions.d.ts +1 -1
- package/dist/cli/commands/remote.d.ts +1 -1
- package/dist/cli/commands/secrets.d.ts +1 -1
- package/dist/cli/commands/token.d.ts +1 -1
- package/dist/cli/commands/type-generation/discovery.d.ts +2 -2
- package/dist/cli/commands/type-generation/generator.d.ts +3 -3
- package/dist/cli/commands/type-generation/models.d.ts +1 -1
- package/dist/cli/commands/types.d.ts +1 -1
- package/dist/cli/commands/worker.d.ts +1 -1
- package/dist/cli/deploy-strategy.d.ts +1 -1
- package/dist/cli/deploy-target.d.ts +1 -1
- package/dist/cli/help-pages/pages/account.d.ts +1 -1
- package/dist/cli/help-pages/pages/core.d.ts +1 -1
- package/dist/cli/help-pages/pages/index.d.ts +1 -1
- package/dist/cli/help-pages/pages/misc.d.ts +1 -1
- package/dist/cli/help-pages/pages/previews.d.ts +1 -1
- package/dist/cli/help-pages/pages/productions.d.ts +1 -1
- package/dist/cli/help-pages/render.d.ts +2 -2
- package/dist/cli/help-pages/shared.d.ts +1 -1
- package/dist/cli/help.d.ts +2 -2
- package/dist/cli/index.js +2 -1383
- package/dist/cli/preview-bindings.d.ts +3 -3
- package/dist/cli/preview.d.ts +1 -1
- package/dist/cli/wrangler-auth.d.ts +1 -1
- package/dist/cloudflare/account-core.d.ts +2 -2
- package/dist/cloudflare/account-resources.d.ts +2 -2
- package/dist/cloudflare/account-status.d.ts +1 -1
- package/dist/cloudflare/account-workers.d.ts +2 -2
- package/dist/cloudflare/account.d.ts +7 -7
- package/dist/cloudflare/auth.d.ts +1 -1
- package/dist/cloudflare/index.d.ts +13 -13
- package/dist/cloudflare/index.js +4 -59
- package/dist/cloudflare/kv-namespace.d.ts +1 -1
- package/dist/cloudflare/preview-registry-cache.d.ts +1 -1
- package/dist/cloudflare/preview-registry-inference.d.ts +2 -2
- package/dist/cloudflare/preview-registry-records.d.ts +3 -3
- package/dist/cloudflare/preview-registry-shape.d.ts +2 -2
- package/dist/cloudflare/preview-registry-store.d.ts +3 -3
- package/dist/cloudflare/preview-registry-transport.d.ts +2 -2
- package/dist/cloudflare/preview-registry-types.d.ts +2 -2
- package/dist/cloudflare/preview-registry.d.ts +5 -5
- package/dist/cloudflare/tokens.d.ts +2 -2
- package/dist/cloudflare/usage.d.ts +2 -2
- package/dist/config/binding-resolution-helpers.d.ts +1 -1
- package/dist/config/compiler/bindings.d.ts +2 -2
- package/dist/config/compiler/core-helpers.d.ts +2 -2
- package/dist/config/compiler/do-workers.d.ts +2 -2
- package/dist/config/compiler/paths.d.ts +1 -1
- package/dist/config/compiler.d.ts +6 -6
- package/dist/config/define.d.ts +2 -2
- package/dist/config/deploy-resources.d.ts +5 -5
- package/dist/config/env-vars.d.ts +1 -1
- package/dist/config/framework-providers.d.ts +1 -1
- package/dist/config/index.d.ts +12 -12
- package/dist/config/loader.d.ts +2 -2
- package/dist/config/local-dev-vars.d.ts +1 -1
- package/dist/config/preview-resources.d.ts +4 -4
- package/dist/config/preview.d.ts +1 -1
- package/dist/config/ref.d.ts +2 -2
- package/dist/config/resolve-phased.d.ts +4 -4
- package/dist/config/resolve.d.ts +1 -1
- package/dist/config/resource-resolution.d.ts +6 -6
- package/dist/config/schema-env.d.ts +20 -20
- package/dist/config/schema-normalization.d.ts +1 -1
- package/dist/config/schema-types-bindings.d.ts +4 -4
- package/dist/config/schema-types-build.d.ts +1 -1
- package/dist/config/schema-types.d.ts +7 -7
- package/dist/config/schema.d.ts +46 -46
- package/dist/config/service-bindings-validation.d.ts +1 -1
- package/dist/config-entry.d.ts +6 -6
- package/dist/config-entry.js +3 -8
- package/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -9
- package/dist/dev-server/d1-migrations.d.ts +1 -1
- package/dist/dev-server/dev-server-state.d.ts +6 -6
- package/dist/dev-server/gateway-script.d.ts +1 -1
- package/dist/dev-server/index.d.ts +1 -1
- package/dist/dev-server/miniflare-bindings.d.ts +1 -1
- package/dist/dev-server/miniflare-dev-config.d.ts +5 -5
- package/dist/dev-server/miniflare-worker-config.d.ts +3 -3
- package/dist/dev-server/server-startup-helpers.d.ts +6 -6
- package/dist/dev-server/worker-surface-paths.d.ts +2 -2
- package/dist/index.d.ts +8 -8
- package/dist/index.js +9 -22
- package/dist/runtime/context-events.d.ts +1 -1
- package/dist/runtime/context.d.ts +3 -3
- package/dist/runtime/exports.d.ts +2 -2
- package/dist/runtime/index.d.ts +10 -10
- package/dist/runtime/index.js +5 -57
- package/dist/runtime/middleware.d.ts +1 -1
- package/dist/runtime/router/index.d.ts +3 -3
- package/dist/runtime/validation.d.ts +1 -1
- package/dist/secrets/local-secrets.d.ts +1 -1
- package/dist/shims/local-media-bindings.d.ts +1 -1
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/index.js +327 -9
- package/dist/sveltekit/local-bindings.d.ts +1 -1
- package/dist/sveltekit/platform.d.ts +1 -1
- package/dist/test/binding-hints.d.ts +2 -2
- package/dist/test/cf.d.ts +19 -19
- package/dist/test/index.d.ts +18 -18
- package/dist/test/index.js +4495 -46
- package/dist/test/offline-bindings.d.ts +3 -3
- package/dist/test/resolve-service-bindings.d.ts +1 -1
- package/dist/test/simple-context-bindings.d.ts +1 -1
- package/dist/test/simple-context-durable-objects.d.ts +1 -1
- package/dist/test/simple-context-env.d.ts +2 -2
- package/dist/test/simple-context-handlers.d.ts +2 -2
- package/dist/test/simple-context-lifecycle.d.ts +2 -2
- package/dist/test/simple-context-mfconfig.d.ts +1 -1
- package/dist/test/simple-context-multi-worker.d.ts +2 -2
- package/dist/test/simple-context-runtime.d.ts +1 -1
- package/dist/test/simple-context-startup.d.ts +1 -1
- package/dist/test/simple-context.d.ts +1 -1
- package/dist/test/utilities/env.d.ts +3 -3
- package/dist/test/utilities.d.ts +10 -10
- package/dist/test/worker.d.ts +1 -1
- package/dist/transform/index.d.ts +2 -2
- package/dist/utils/send-email.js +163 -19
- package/dist/vite/config-file.d.ts +2 -2
- package/dist/vite/index.d.ts +3 -3
- package/dist/vite/index.js +2 -31
- package/dist/vite/plugin-config-hook.d.ts +1 -1
- package/dist/vite/plugin-context.d.ts +3 -3
- package/dist/vite/plugin-durable-objects.d.ts +2 -2
- package/dist/vite/plugin-programmatic.d.ts +1 -1
- package/dist/vite/plugin-service-bindings.d.ts +2 -2
- package/dist/vite/plugin.d.ts +3 -3
- package/dist/worker-entry/composed-worker.d.ts +1 -1
- package/dist/worker-entry/routes.d.ts +2 -2
- package/dist/worker-entry/surface-paths.d.ts +1 -1
- package/dist/workflows/local-workflow-entrypoints.d.ts +1 -1
- package/package.json +5 -3
- package/dist/account-4tgh03a8.js +0 -484
- package/dist/ai-r3zqmxan.js +0 -261
- package/dist/api-6z01z734.js +0 -33
- package/dist/build-kw625v84.js +0 -51
- package/dist/config-ghk2bxj3.js +0 -102
- package/dist/deploy-9kee65n9.js +0 -1062
- package/dist/dev-x8zr249a.js +0 -3569
- package/dist/doctor-0ng5qrr1.js +0 -258
- package/dist/durable-object-0ybmg08a.js +0 -13
- package/dist/index-04wh9bxx.js +0 -514
- package/dist/index-0cc05hzv.js +0 -74
- package/dist/index-2yv7w548.js +0 -185
- package/dist/index-37x76zdn.js +0 -4
- package/dist/index-3cpzsr47.js +0 -125
- package/dist/index-3t6rypgc.js +0 -13
- package/dist/index-4mmpccrb.js +0 -309
- package/dist/index-5dkjffqz.js +0 -25
- package/dist/index-5hy7jmv3.js +0 -890
- package/dist/index-627srx16.js +0 -45
- package/dist/index-7m557715.js +0 -283
- package/dist/index-a8pnvg3r.js +0 -52
- package/dist/index-aabgympv.js +0 -39
- package/dist/index-atwc3csp.js +0 -256
- package/dist/index-cv4cvrxe.js +0 -2046
- package/dist/index-h7r11y4a.js +0 -539
- package/dist/index-hvtd936d.js +0 -1229
- package/dist/index-kcp7y951.js +0 -136
- package/dist/index-maw0jjnn.js +0 -147
- package/dist/index-mek9msfv.js +0 -705
- package/dist/index-n4xkaymm.js +0 -236
- package/dist/index-nkk59p3y.js +0 -579
- package/dist/index-phcrvs6d.js +0 -342
- package/dist/index-se4kw8tm.js +0 -460
- package/dist/index-x8s9rwfh.js +0 -2020
- package/dist/index-y7w3x9p1.js +0 -18
- package/dist/index-z9gy8w6b.js +0 -57
- package/dist/index-zdd0d9qa.js +0 -199
- package/dist/init-tb8jqgvr.js +0 -180
- package/dist/login-4h1sfsed.js +0 -75
- package/dist/previews-qr7c5j8h.js +0 -1336
- package/dist/productions-xpmd6bw8.js +0 -505
- package/dist/remote-kqcvhnfx.js +0 -192
- package/dist/secrets-6wbdsdek.js +0 -89
- package/dist/token-yp1qa70y.js +0 -419
- package/dist/types-15yv4cj3.js +0 -701
- package/dist/worker-1yg72jxg.js +0 -510
- package/dist/worker-entrypoint-y8s9kdcx.js +0 -15
package/dist/index-627srx16.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// src/cli/package-metadata.ts
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { dirname, resolve } from "pathe";
|
|
5
|
-
var packageMetadataPromise = null;
|
|
6
|
-
async function loadPackageMetadata() {
|
|
7
|
-
let currentDir = dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
while (true) {
|
|
9
|
-
const packageJsonPath = resolve(currentDir, "package.json");
|
|
10
|
-
try {
|
|
11
|
-
const packageJson = await readFile(packageJsonPath, "utf8");
|
|
12
|
-
const metadata = JSON.parse(packageJson);
|
|
13
|
-
if (metadata.name === "devflare") {
|
|
14
|
-
return metadata;
|
|
15
|
-
}
|
|
16
|
-
} catch {}
|
|
17
|
-
const parentDir = dirname(currentDir);
|
|
18
|
-
if (parentDir === currentDir) {
|
|
19
|
-
throw new Error("Could not resolve the devflare package.json file");
|
|
20
|
-
}
|
|
21
|
-
currentDir = parentDir;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async function getPackageMetadata() {
|
|
25
|
-
if (!packageMetadataPromise) {
|
|
26
|
-
packageMetadataPromise = loadPackageMetadata();
|
|
27
|
-
}
|
|
28
|
-
return packageMetadataPromise;
|
|
29
|
-
}
|
|
30
|
-
async function getPackageVersion() {
|
|
31
|
-
return (await getPackageMetadata()).version ?? "0.0.0";
|
|
32
|
-
}
|
|
33
|
-
async function getInitDependencyVersions() {
|
|
34
|
-
const metadata = await getPackageMetadata();
|
|
35
|
-
const dependencies = metadata.dependencies ?? {};
|
|
36
|
-
const devDependencies = metadata.devDependencies ?? {};
|
|
37
|
-
return {
|
|
38
|
-
devflare: `^${metadata.version ?? "0.0.0"}`,
|
|
39
|
-
typescript: devDependencies.typescript ?? "^5.7.0",
|
|
40
|
-
wrangler: dependencies.wrangler ?? devDependencies.wrangler ?? "^4.85.0",
|
|
41
|
-
workersTypes: devDependencies["@cloudflare/workers-types"] ?? "^4.20250109.0"
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { getPackageVersion, getInitDependencyVersions };
|
package/dist/index-7m557715.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
// src/transform/worker-entrypoint.ts
|
|
2
|
-
import MagicString from "magic-string";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
|
|
5
|
-
// src/worker-entry/extensions.ts
|
|
6
|
-
var SUPPORTED_WORKER_EXTENSIONS = [
|
|
7
|
-
".ts",
|
|
8
|
-
".tsx",
|
|
9
|
-
".mts",
|
|
10
|
-
".mjs",
|
|
11
|
-
".cts",
|
|
12
|
-
".cjs",
|
|
13
|
-
".js",
|
|
14
|
-
".jsx"
|
|
15
|
-
];
|
|
16
|
-
var TS_WORKER_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts"];
|
|
17
|
-
|
|
18
|
-
// src/transform/worker-entrypoint.ts
|
|
19
|
-
function findExportedFunctions(code) {
|
|
20
|
-
const functions = [];
|
|
21
|
-
const sourceFile = ts.createSourceFile("worker.ts", code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
22
|
-
function visit(node) {
|
|
23
|
-
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
24
|
-
const modifiers = ts.getModifiers(node);
|
|
25
|
-
const isExported = modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
26
|
-
const isDefault = modifiers?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword);
|
|
27
|
-
if (isExported) {
|
|
28
|
-
const isAsync = modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) ?? false;
|
|
29
|
-
const funcName = isDefault ? "fetch" : node.name.text;
|
|
30
|
-
const params = node.parameters.map((p) => code.substring(p.getStart(sourceFile), p.getEnd())).join(", ");
|
|
31
|
-
const returnType = node.type ? code.substring(node.type.getStart(sourceFile), node.type.getEnd()) : undefined;
|
|
32
|
-
functions.push({
|
|
33
|
-
name: funcName,
|
|
34
|
-
isAsync,
|
|
35
|
-
params,
|
|
36
|
-
returnType,
|
|
37
|
-
start: node.getStart(sourceFile),
|
|
38
|
-
end: node.getEnd(),
|
|
39
|
-
isDefault
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (ts.isFunctionDeclaration(node) && !node.name) {
|
|
44
|
-
const modifiers = ts.getModifiers(node);
|
|
45
|
-
const isExported = modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
46
|
-
const isDefault = modifiers?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword);
|
|
47
|
-
if (isExported && isDefault) {
|
|
48
|
-
const isAsync = modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) ?? false;
|
|
49
|
-
const params = node.parameters.map((p) => code.substring(p.getStart(sourceFile), p.getEnd())).join(", ");
|
|
50
|
-
const returnType = node.type ? code.substring(node.type.getStart(sourceFile), node.type.getEnd()) : undefined;
|
|
51
|
-
functions.push({
|
|
52
|
-
name: "fetch",
|
|
53
|
-
isAsync,
|
|
54
|
-
params,
|
|
55
|
-
returnType,
|
|
56
|
-
start: node.getStart(sourceFile),
|
|
57
|
-
end: node.getEnd(),
|
|
58
|
-
isDefault: true
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (ts.isVariableStatement(node)) {
|
|
63
|
-
const modifiers = ts.getModifiers(node);
|
|
64
|
-
const isExported = modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
65
|
-
if (isExported) {
|
|
66
|
-
for (const decl of node.declarationList.declarations) {
|
|
67
|
-
if (ts.isIdentifier(decl.name) && decl.initializer) {
|
|
68
|
-
let funcExpr;
|
|
69
|
-
if (ts.isFunctionExpression(decl.initializer)) {
|
|
70
|
-
funcExpr = decl.initializer;
|
|
71
|
-
} else if (ts.isArrowFunction(decl.initializer)) {
|
|
72
|
-
funcExpr = decl.initializer;
|
|
73
|
-
}
|
|
74
|
-
if (funcExpr) {
|
|
75
|
-
const modifiersArr = ts.getModifiers(funcExpr);
|
|
76
|
-
const isAsync = modifiersArr?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) ?? (ts.isArrowFunction(funcExpr) && funcExpr.modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword)) ?? false;
|
|
77
|
-
const params = funcExpr.parameters.map((p) => code.substring(p.getStart(sourceFile), p.getEnd())).join(", ");
|
|
78
|
-
const returnType = funcExpr.type ? code.substring(funcExpr.type.getStart(sourceFile), funcExpr.type.getEnd()) : undefined;
|
|
79
|
-
functions.push({
|
|
80
|
-
name: decl.name.text,
|
|
81
|
-
isAsync,
|
|
82
|
-
params,
|
|
83
|
-
returnType,
|
|
84
|
-
start: node.getStart(sourceFile),
|
|
85
|
-
end: node.getEnd()
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
ts.forEachChild(node, visit);
|
|
93
|
-
}
|
|
94
|
-
visit(sourceFile);
|
|
95
|
-
return functions;
|
|
96
|
-
}
|
|
97
|
-
function shouldEmitTsSyntax(filename) {
|
|
98
|
-
const lower = filename.toLowerCase();
|
|
99
|
-
return TS_WORKER_EXTENSIONS.some((ext) => lower.endsWith(ext));
|
|
100
|
-
}
|
|
101
|
-
function shouldTransformWorker(code, filePath) {
|
|
102
|
-
const lower = filePath.toLowerCase();
|
|
103
|
-
const isWorkerFile = SUPPORTED_WORKER_EXTENSIONS.some((ext) => lower.endsWith(`worker${ext}`));
|
|
104
|
-
if (!isWorkerFile) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
const functions = findExportedFunctions(code);
|
|
108
|
-
return functions.length > 0;
|
|
109
|
-
}
|
|
110
|
-
function transformWorkerEntrypoint(code, id, options = {}) {
|
|
111
|
-
const className = options.className ?? "Worker";
|
|
112
|
-
const injectContext = options.injectContext ?? true;
|
|
113
|
-
const emitTs = shouldEmitTsSyntax(id);
|
|
114
|
-
const functions = findExportedFunctions(code);
|
|
115
|
-
if (functions.length === 0) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
const fetchFn = functions.find((f) => f.name === "fetch");
|
|
119
|
-
const rpcMethods = functions.filter((f) => f.name !== "fetch");
|
|
120
|
-
const needsFetchHelpers = Boolean(fetchFn);
|
|
121
|
-
const s = new MagicString(code);
|
|
122
|
-
const importStatement = `import { WorkerEntrypoint } from 'cloudflare:workers'
|
|
123
|
-
`;
|
|
124
|
-
if (needsFetchHelpers) {
|
|
125
|
-
const runtimeImports = ["createFetchEvent", "invokeFetchHandler"];
|
|
126
|
-
if (injectContext) {
|
|
127
|
-
runtimeImports.push("runWithEventContext");
|
|
128
|
-
}
|
|
129
|
-
s.prepend(`import { ${runtimeImports.join(", ")} } from 'devflare/runtime'
|
|
130
|
-
`);
|
|
131
|
-
}
|
|
132
|
-
s.prepend(importStatement);
|
|
133
|
-
const sourceFile = ts.createSourceFile("worker.ts", code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
134
|
-
const internalNameFor = (name) => name === "fetch" ? "__originalFetch" : `__original_${name}`;
|
|
135
|
-
function visit(node) {
|
|
136
|
-
if (ts.isFunctionDeclaration(node)) {
|
|
137
|
-
const modifiers = ts.getModifiers(node);
|
|
138
|
-
const exportMod = modifiers?.find((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
139
|
-
const defaultMod = modifiers?.find((m) => m.kind === ts.SyntaxKind.DefaultKeyword);
|
|
140
|
-
const asyncMod = modifiers?.find((m) => m.kind === ts.SyntaxKind.AsyncKeyword);
|
|
141
|
-
if (exportMod) {
|
|
142
|
-
const isDefault = Boolean(defaultMod);
|
|
143
|
-
const logicalName = isDefault ? "fetch" : node.name?.text;
|
|
144
|
-
if (logicalName) {
|
|
145
|
-
const internal = internalNameFor(logicalName);
|
|
146
|
-
if (isDefault && !node.name) {
|
|
147
|
-
const funcKeyword = node.getChildren(sourceFile).find((c) => c.kind === ts.SyntaxKind.FunctionKeyword);
|
|
148
|
-
if (funcKeyword) {
|
|
149
|
-
const asyncKw = asyncMod ? "async " : "";
|
|
150
|
-
s.overwrite(node.getStart(sourceFile), funcKeyword.getStart(sourceFile), `const ${internal} = ${asyncKw}`);
|
|
151
|
-
}
|
|
152
|
-
} else if (node.name) {
|
|
153
|
-
s.remove(exportMod.getStart(sourceFile), exportMod.getEnd());
|
|
154
|
-
if (defaultMod) {
|
|
155
|
-
s.remove(defaultMod.getStart(sourceFile), defaultMod.getEnd());
|
|
156
|
-
}
|
|
157
|
-
s.overwrite(node.name.getStart(sourceFile), node.name.getEnd(), internal);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
} else if (ts.isVariableStatement(node)) {
|
|
162
|
-
const modifiers = ts.getModifiers(node);
|
|
163
|
-
const exportMod = modifiers?.find((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
164
|
-
if (exportMod) {
|
|
165
|
-
let rewroteAny = false;
|
|
166
|
-
for (const decl of node.declarationList.declarations) {
|
|
167
|
-
if (ts.isIdentifier(decl.name) && decl.initializer && (ts.isFunctionExpression(decl.initializer) || ts.isArrowFunction(decl.initializer))) {
|
|
168
|
-
const internal = internalNameFor(decl.name.text);
|
|
169
|
-
s.overwrite(decl.name.getStart(sourceFile), decl.name.getEnd(), internal);
|
|
170
|
-
rewroteAny = true;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (rewroteAny) {
|
|
174
|
-
s.remove(exportMod.getStart(sourceFile), exportMod.getEnd());
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
ts.forEachChild(node, visit);
|
|
179
|
-
}
|
|
180
|
-
visit(sourceFile);
|
|
181
|
-
let classBody = `
|
|
182
|
-
|
|
183
|
-
// ============ Devflare WorkerEntrypoint ============
|
|
184
|
-
class ${className} extends WorkerEntrypoint {
|
|
185
|
-
`;
|
|
186
|
-
if (fetchFn) {
|
|
187
|
-
const fetchSig = emitTs ? "async fetch(request: Request): Promise<Response>" : "async fetch(request)";
|
|
188
|
-
classBody += ` ${fetchSig} {
|
|
189
|
-
`;
|
|
190
|
-
classBody += ` const __devflareEvent = createFetchEvent(request, this.env, this.ctx)
|
|
191
|
-
`;
|
|
192
|
-
if (injectContext) {
|
|
193
|
-
classBody += ` return runWithEventContext(
|
|
194
|
-
`;
|
|
195
|
-
classBody += ` __devflareEvent,
|
|
196
|
-
`;
|
|
197
|
-
classBody += ` () => invokeFetchHandler(__originalFetch, __devflareEvent)
|
|
198
|
-
`;
|
|
199
|
-
classBody += ` )
|
|
200
|
-
`;
|
|
201
|
-
classBody += ` }
|
|
202
|
-
`;
|
|
203
|
-
} else {
|
|
204
|
-
classBody += ` return invokeFetchHandler(__originalFetch, __devflareEvent)
|
|
205
|
-
`;
|
|
206
|
-
classBody += ` }
|
|
207
|
-
`;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
for (const fn of rpcMethods) {
|
|
211
|
-
const asyncPrefix = fn.isAsync ? "async " : "";
|
|
212
|
-
const paramNames = extractParamNames(fn.params);
|
|
213
|
-
const signatureParams = emitTs ? fn.params : paramNames;
|
|
214
|
-
const returnType = emitTs && fn.returnType ? `: ${fn.returnType}` : "";
|
|
215
|
-
classBody += `
|
|
216
|
-
${asyncPrefix}${fn.name}(${signatureParams})${returnType} {
|
|
217
|
-
`;
|
|
218
|
-
classBody += ` return __original_${fn.name}(${paramNames})
|
|
219
|
-
`;
|
|
220
|
-
classBody += ` }
|
|
221
|
-
`;
|
|
222
|
-
}
|
|
223
|
-
classBody += `}
|
|
224
|
-
|
|
225
|
-
`;
|
|
226
|
-
classBody += `export { ${className} }
|
|
227
|
-
`;
|
|
228
|
-
classBody += `export { ${className} as default }
|
|
229
|
-
`;
|
|
230
|
-
classBody += `// ============ End Devflare WorkerEntrypoint ============
|
|
231
|
-
`;
|
|
232
|
-
s.append(classBody);
|
|
233
|
-
return {
|
|
234
|
-
code: s.toString(),
|
|
235
|
-
map: s.generateMap({
|
|
236
|
-
source: id,
|
|
237
|
-
file: id + ".map",
|
|
238
|
-
includeContent: true
|
|
239
|
-
}),
|
|
240
|
-
rpcMethods: rpcMethods.map((fn) => fn.name),
|
|
241
|
-
className
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
function extractParamNames(params) {
|
|
245
|
-
if (!params.trim())
|
|
246
|
-
return "";
|
|
247
|
-
const tempCode = `function f(${params}) {}`;
|
|
248
|
-
const sourceFile = ts.createSourceFile("temp.ts", tempCode, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
249
|
-
const names = [];
|
|
250
|
-
function visit(node) {
|
|
251
|
-
if (ts.isFunctionDeclaration(node)) {
|
|
252
|
-
for (const param of node.parameters) {
|
|
253
|
-
if (ts.isIdentifier(param.name)) {
|
|
254
|
-
names.push(param.name.text);
|
|
255
|
-
} else if (ts.isObjectBindingPattern(param.name) || ts.isArrayBindingPattern(param.name)) {
|
|
256
|
-
names.push(tempCode.substring(param.name.getStart(sourceFile), param.name.getEnd()));
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
ts.forEachChild(node, visit);
|
|
261
|
-
}
|
|
262
|
-
visit(sourceFile);
|
|
263
|
-
return names.join(", ");
|
|
264
|
-
}
|
|
265
|
-
function generateRpcInterface(functions, interfaceName) {
|
|
266
|
-
const rpcMethods = functions.filter((f) => f.name !== "fetch");
|
|
267
|
-
if (rpcMethods.length === 0) {
|
|
268
|
-
return "";
|
|
269
|
-
}
|
|
270
|
-
let output = `export interface ${interfaceName} {
|
|
271
|
-
`;
|
|
272
|
-
for (const fn of rpcMethods) {
|
|
273
|
-
const returnType = fn.returnType ?? "unknown";
|
|
274
|
-
const promiseReturn = returnType.startsWith("Promise<") ? returnType : `Promise<${returnType}>`;
|
|
275
|
-
output += ` ${fn.name}(${fn.params}): ${promiseReturn}
|
|
276
|
-
`;
|
|
277
|
-
}
|
|
278
|
-
output += `}
|
|
279
|
-
`;
|
|
280
|
-
return output;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export { SUPPORTED_WORKER_EXTENSIONS, findExportedFunctions, shouldEmitTsSyntax, shouldTransformWorker, transformWorkerEntrypoint, generateRpcInterface };
|
package/dist/index-a8pnvg3r.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
findFiles
|
|
3
|
-
} from "./index-5dkjffqz.js";
|
|
4
|
-
import {
|
|
5
|
-
resolveConfigPath
|
|
6
|
-
} from "./index-x8s9rwfh.js";
|
|
7
|
-
|
|
8
|
-
// src/cli/config-path.ts
|
|
9
|
-
import { stat } from "node:fs/promises";
|
|
10
|
-
var CONFIG_FILE_EXTENSIONS = [".ts", ".mts", ".js", ".mjs"];
|
|
11
|
-
var SUPPORTED_CONFIG_FILENAMES = CONFIG_FILE_EXTENSIONS.map((extension) => `devflare.config${extension}`);
|
|
12
|
-
function hasKnownConfigExtension(filePath) {
|
|
13
|
-
return CONFIG_FILE_EXTENSIONS.some((extension) => filePath.endsWith(extension));
|
|
14
|
-
}
|
|
15
|
-
async function getExistingFilePath(filePath) {
|
|
16
|
-
try {
|
|
17
|
-
const fileStat = await stat(filePath);
|
|
18
|
-
return fileStat.isFile() ? filePath : null;
|
|
19
|
-
} catch {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
async function resolveConfigCandidatePath(candidatePath) {
|
|
24
|
-
const candidates = [candidatePath];
|
|
25
|
-
if (!hasKnownConfigExtension(candidatePath)) {
|
|
26
|
-
for (const extension of CONFIG_FILE_EXTENSIONS) {
|
|
27
|
-
candidates.push(`${candidatePath}${extension}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
for (const candidate of candidates) {
|
|
31
|
-
const existingFilePath = await getExistingFilePath(candidate);
|
|
32
|
-
if (existingFilePath) {
|
|
33
|
-
return existingFilePath;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return await resolveConfigPath(candidatePath) ?? null;
|
|
37
|
-
}
|
|
38
|
-
async function findConfigPathsUnderDirectory(rootDir) {
|
|
39
|
-
const matches = await findFiles([
|
|
40
|
-
...SUPPORTED_CONFIG_FILENAMES,
|
|
41
|
-
...SUPPORTED_CONFIG_FILENAMES.map((filename) => `**/${filename}`)
|
|
42
|
-
], {
|
|
43
|
-
cwd: rootDir,
|
|
44
|
-
absolute: true
|
|
45
|
-
});
|
|
46
|
-
return [...new Set(matches)].sort((left, right) => left.localeCompare(right));
|
|
47
|
-
}
|
|
48
|
-
function formatSupportedConfigFilenames() {
|
|
49
|
-
return SUPPORTED_CONFIG_FILENAMES.join(", ");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { resolveConfigCandidatePath, findConfigPathsUnderDirectory, formatSupportedConfigFilenames };
|
package/dist/index-aabgympv.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__require
|
|
3
|
-
} from "./index-37x76zdn.js";
|
|
4
|
-
|
|
5
|
-
// src/cli/generated-artifacts.ts
|
|
6
|
-
import { resolve } from "pathe";
|
|
7
|
-
var DEVFLARE_DIR = [".devflare"];
|
|
8
|
-
var DEVFLARE_BUILD_DIR = [".devflare", "build"];
|
|
9
|
-
var WRANGLER_DEPLOY_DIR = [".wrangler", "deploy"];
|
|
10
|
-
function getGeneratedArtifactPaths(cwd) {
|
|
11
|
-
const devflareDir = resolve(cwd, ...DEVFLARE_DIR);
|
|
12
|
-
const buildDir = resolve(cwd, ...DEVFLARE_BUILD_DIR);
|
|
13
|
-
const deployDir = resolve(cwd, ...WRANGLER_DEPLOY_DIR);
|
|
14
|
-
return {
|
|
15
|
-
devflareDir,
|
|
16
|
-
devWranglerConfigPath: resolve(devflareDir, "wrangler.jsonc"),
|
|
17
|
-
buildDir,
|
|
18
|
-
buildWorkerPath: resolve(buildDir, "worker.js"),
|
|
19
|
-
buildWranglerConfigPath: resolve(buildDir, "wrangler.jsonc"),
|
|
20
|
-
deployDir,
|
|
21
|
-
deployRedirectPath: resolve(deployDir, "config.json")
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
async function ensureGeneratedDirectory(dirPath, writeGitignore = false) {
|
|
25
|
-
const fs = await import("node:fs/promises");
|
|
26
|
-
await fs.mkdir(dirPath, { recursive: true });
|
|
27
|
-
if (!writeGitignore) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const gitignorePath = resolve(dirPath, ".gitignore");
|
|
31
|
-
try {
|
|
32
|
-
await fs.access(gitignorePath);
|
|
33
|
-
} catch {
|
|
34
|
-
await fs.writeFile(gitignorePath, `*
|
|
35
|
-
`, "utf-8");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export { getGeneratedArtifactPaths, ensureGeneratedDirectory };
|
package/dist/index-atwc3csp.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
apiDelete,
|
|
3
|
-
apiGetAll,
|
|
4
|
-
apiPost,
|
|
5
|
-
apiPut
|
|
6
|
-
} from "./index-04wh9bxx.js";
|
|
7
|
-
|
|
8
|
-
// src/cloudflare/known-permission-group-ids.generated.ts
|
|
9
|
-
var KNOWN_PERMISSION_GROUP_IDS_DATA = {
|
|
10
|
-
WORKERS_SCRIPTS_WRITE: null,
|
|
11
|
-
WORKERS_SCRIPTS_READ: null,
|
|
12
|
-
ACCOUNT_SETTINGS_READ: null,
|
|
13
|
-
WORKERS_KV_STORAGE_WRITE: null,
|
|
14
|
-
WORKERS_KV_STORAGE_READ: null,
|
|
15
|
-
ACCOUNT_API_TOKENS_WRITE: null,
|
|
16
|
-
ACCOUNT_API_TOKENS_READ: null
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// src/cloudflare/tokens.ts
|
|
20
|
-
var MAX_ACCOUNT_OWNED_TOKEN_PERMISSION_GROUPS = 300;
|
|
21
|
-
var DEVFLARE_MANAGED_TOKEN_PREFIX = "devflare-";
|
|
22
|
-
var ACCOUNT_OWNED_TOKEN_SCOPE = "com.cloudflare.api.account";
|
|
23
|
-
var ACCOUNT_ZONE_OWNED_TOKEN_SCOPE = "com.cloudflare.api.account.zone";
|
|
24
|
-
var ACCOUNT_API_TOKENS_PERMISSION_GROUP_NAME_PATTERN = /^Account API Tokens\b/i;
|
|
25
|
-
var DEVFLARE_MANAGED_TOKEN_NAME_PATTERN = /^devflare-/i;
|
|
26
|
-
var DEVFLARE_PERMISSION_GROUP_NAME_PATTERNS = [
|
|
27
|
-
/^Account Analytics /i,
|
|
28
|
-
/^Account Settings /i,
|
|
29
|
-
/^Account Filter Lists /i,
|
|
30
|
-
/^AI /i,
|
|
31
|
-
/^Analytics /i,
|
|
32
|
-
/^Browser Rendering /i,
|
|
33
|
-
/^Cache Purge\b/i,
|
|
34
|
-
/^D1 /i,
|
|
35
|
-
/^DNS /i,
|
|
36
|
-
/^Email /i,
|
|
37
|
-
/^Hyperdrive /i,
|
|
38
|
-
/^Images /i,
|
|
39
|
-
/^Logs /i,
|
|
40
|
-
/^Logpush /i,
|
|
41
|
-
/^Pages /i,
|
|
42
|
-
/^Queues /i,
|
|
43
|
-
/^R2 /i,
|
|
44
|
-
/^SSL and Certificates /i,
|
|
45
|
-
/^Stream /i,
|
|
46
|
-
/^Vectorize /i,
|
|
47
|
-
/^Workers /i,
|
|
48
|
-
/^Zone Settings /i,
|
|
49
|
-
/^Zone /i
|
|
50
|
-
];
|
|
51
|
-
function deriveKnownPermissionGroupIds(data) {
|
|
52
|
-
const result = {};
|
|
53
|
-
for (const key of Object.keys(data)) {
|
|
54
|
-
const value = data[key];
|
|
55
|
-
result[key] = value === null ? undefined : value;
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
var KNOWN_PERMISSION_GROUP_IDS = deriveKnownPermissionGroupIds(KNOWN_PERMISSION_GROUP_IDS_DATA);
|
|
60
|
-
function dedupePermissionGroups(permissionGroups) {
|
|
61
|
-
const seenIds = new Set;
|
|
62
|
-
return permissionGroups.filter((permissionGroup) => {
|
|
63
|
-
if (seenIds.has(permissionGroup.id)) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
seenIds.add(permissionGroup.id);
|
|
67
|
-
return true;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function dedupePermissionGroupIds(permissionGroupIds) {
|
|
71
|
-
return Array.from(new Set(permissionGroupIds.map((id) => id.trim()).filter(Boolean)));
|
|
72
|
-
}
|
|
73
|
-
function dedupeScopedPermissionGroups(permissionGroups) {
|
|
74
|
-
const seenIds = new Set;
|
|
75
|
-
return permissionGroups.filter((permissionGroup) => {
|
|
76
|
-
const id = permissionGroup.id.trim();
|
|
77
|
-
if (!id || seenIds.has(id)) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
seenIds.add(id);
|
|
81
|
-
return true;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function permissionGroupHasScope(permissionGroup, scope) {
|
|
85
|
-
return permissionGroup.scopes.some((value) => value.trim() === scope);
|
|
86
|
-
}
|
|
87
|
-
function buildCreateTokenPoliciesFromPermissionGroups(accountId, permissionGroups) {
|
|
88
|
-
const dedupedPermissionGroups = dedupeScopedPermissionGroups(permissionGroups);
|
|
89
|
-
const accountPermissionGroupIds = dedupePermissionGroupIds(dedupedPermissionGroups.filter((permissionGroup) => permissionGroupHasScope(permissionGroup, ACCOUNT_OWNED_TOKEN_SCOPE)).map((permissionGroup) => permissionGroup.id));
|
|
90
|
-
const zonePermissionGroupIds = dedupePermissionGroupIds(dedupedPermissionGroups.filter((permissionGroup) => permissionGroupHasScope(permissionGroup, ACCOUNT_ZONE_OWNED_TOKEN_SCOPE)).map((permissionGroup) => permissionGroup.id));
|
|
91
|
-
const policies = [];
|
|
92
|
-
if (accountPermissionGroupIds.length > 0) {
|
|
93
|
-
policies.push({
|
|
94
|
-
effect: "allow",
|
|
95
|
-
resources: {
|
|
96
|
-
[`com.cloudflare.api.account.${accountId}`]: "*"
|
|
97
|
-
},
|
|
98
|
-
permission_groups: accountPermissionGroupIds.map((id) => ({ id }))
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (zonePermissionGroupIds.length > 0) {
|
|
102
|
-
policies.push({
|
|
103
|
-
effect: "allow",
|
|
104
|
-
resources: {
|
|
105
|
-
[`com.cloudflare.api.account.${accountId}`]: {
|
|
106
|
-
[`${ACCOUNT_ZONE_OWNED_TOKEN_SCOPE}.*`]: "*"
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
permission_groups: zonePermissionGroupIds.map((id) => ({ id }))
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return policies;
|
|
113
|
-
}
|
|
114
|
-
function buildCreateTokenPoliciesFromPermissionGroupIds(accountId, permissionGroupIds) {
|
|
115
|
-
const dedupedPermissionGroupIds = dedupePermissionGroupIds(permissionGroupIds);
|
|
116
|
-
if (dedupedPermissionGroupIds.length === 0) {
|
|
117
|
-
return [];
|
|
118
|
-
}
|
|
119
|
-
return [
|
|
120
|
-
{
|
|
121
|
-
effect: "allow",
|
|
122
|
-
resources: {
|
|
123
|
-
[`com.cloudflare.api.account.${accountId}`]: "*"
|
|
124
|
-
},
|
|
125
|
-
permission_groups: dedupedPermissionGroupIds.map((id) => ({ id }))
|
|
126
|
-
}
|
|
127
|
-
];
|
|
128
|
-
}
|
|
129
|
-
function excludeAccountApiTokensPermissionGroups(permissionGroups) {
|
|
130
|
-
return permissionGroups.filter((permissionGroup) => {
|
|
131
|
-
return !ACCOUNT_API_TOKENS_PERMISSION_GROUP_NAME_PATTERN.test(permissionGroup.name);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
function keepAccountOwnedTokenCompatiblePermissionGroups(permissionGroups) {
|
|
135
|
-
return permissionGroups.filter((permissionGroup) => {
|
|
136
|
-
return permissionGroup.scopes.some((scope) => {
|
|
137
|
-
const normalizedScope = scope.trim();
|
|
138
|
-
return normalizedScope === ACCOUNT_OWNED_TOKEN_SCOPE || normalizedScope === ACCOUNT_ZONE_OWNED_TOKEN_SCOPE;
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
function selectReusableAccountOwnedTokenPermissionGroups(permissionGroups) {
|
|
143
|
-
return dedupePermissionGroups(excludeAccountApiTokensPermissionGroups(keepAccountOwnedTokenCompatiblePermissionGroups(permissionGroups)));
|
|
144
|
-
}
|
|
145
|
-
function parseOptionalDate(value) {
|
|
146
|
-
if (!value) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const parsed = new Date(value);
|
|
150
|
-
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
151
|
-
}
|
|
152
|
-
function mapAccountOwnedAPITokenPolicy(policy) {
|
|
153
|
-
return {
|
|
154
|
-
id: policy.id,
|
|
155
|
-
effect: policy.effect,
|
|
156
|
-
permissionGroups: policy.permission_groups?.map((permissionGroup) => ({
|
|
157
|
-
id: permissionGroup.id,
|
|
158
|
-
name: permissionGroup.name
|
|
159
|
-
}))
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function mapAccountOwnedAPIToken(token) {
|
|
163
|
-
return {
|
|
164
|
-
id: token.id,
|
|
165
|
-
name: token.name ?? token.id,
|
|
166
|
-
status: token.status,
|
|
167
|
-
value: token.value,
|
|
168
|
-
issuedOn: parseOptionalDate(token.issued_on),
|
|
169
|
-
modifiedOn: parseOptionalDate(token.modified_on),
|
|
170
|
-
lastUsedOn: parseOptionalDate(token.last_used_on),
|
|
171
|
-
policies: token.policies?.map(mapAccountOwnedAPITokenPolicy)
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function isDevflareManagedTokenName(name) {
|
|
175
|
-
return DEVFLARE_MANAGED_TOKEN_NAME_PATTERN.test(name.trim());
|
|
176
|
-
}
|
|
177
|
-
function normalizeDevflareTokenName(name) {
|
|
178
|
-
const trimmedName = name.trim();
|
|
179
|
-
if (!trimmedName) {
|
|
180
|
-
throw new Error("Devflare token name cannot be empty");
|
|
181
|
-
}
|
|
182
|
-
const suffix = isDevflareManagedTokenName(trimmedName) ? trimmedName.replace(DEVFLARE_MANAGED_TOKEN_NAME_PATTERN, "") : trimmedName;
|
|
183
|
-
if (!suffix) {
|
|
184
|
-
throw new Error("Devflare token name cannot be empty");
|
|
185
|
-
}
|
|
186
|
-
return `${DEVFLARE_MANAGED_TOKEN_PREFIX}${suffix}`;
|
|
187
|
-
}
|
|
188
|
-
function stripDevflareTokenNamePrefix(name) {
|
|
189
|
-
const trimmedName = name.trim();
|
|
190
|
-
if (!trimmedName) {
|
|
191
|
-
return trimmedName;
|
|
192
|
-
}
|
|
193
|
-
const strippedName = trimmedName.replace(DEVFLARE_MANAGED_TOKEN_NAME_PATTERN, "");
|
|
194
|
-
return strippedName || trimmedName;
|
|
195
|
-
}
|
|
196
|
-
function filterDevflareManagedTokens(tokens) {
|
|
197
|
-
return tokens.filter((token) => isDevflareManagedTokenName(token.name));
|
|
198
|
-
}
|
|
199
|
-
function selectDevflarePermissionGroups(permissionGroups) {
|
|
200
|
-
const selectedPermissionGroups = dedupePermissionGroups(selectReusableAccountOwnedTokenPermissionGroups(permissionGroups).filter((permissionGroup) => {
|
|
201
|
-
return DEVFLARE_PERMISSION_GROUP_NAME_PATTERNS.some((pattern) => {
|
|
202
|
-
return pattern.test(permissionGroup.name);
|
|
203
|
-
});
|
|
204
|
-
}));
|
|
205
|
-
if (selectedPermissionGroups.length === 0) {
|
|
206
|
-
throw new Error("Could not map the available Cloudflare permission groups to a Devflare token policy.");
|
|
207
|
-
}
|
|
208
|
-
if (selectedPermissionGroups.length > MAX_ACCOUNT_OWNED_TOKEN_PERMISSION_GROUPS) {
|
|
209
|
-
throw new Error(`Devflare selected ${selectedPermissionGroups.length} permission groups, which exceeds Cloudflare's ${MAX_ACCOUNT_OWNED_TOKEN_PERMISSION_GROUPS}-group limit for account-owned tokens.`);
|
|
210
|
-
}
|
|
211
|
-
return selectedPermissionGroups;
|
|
212
|
-
}
|
|
213
|
-
function selectAllReusablePermissionGroups(permissionGroups) {
|
|
214
|
-
const selectedPermissionGroups = selectReusableAccountOwnedTokenPermissionGroups(permissionGroups);
|
|
215
|
-
if (selectedPermissionGroups.length === 0) {
|
|
216
|
-
throw new Error("Could not find any reusable account/zone-scoped Cloudflare permission groups for this Devflare token.");
|
|
217
|
-
}
|
|
218
|
-
if (selectedPermissionGroups.length > MAX_ACCOUNT_OWNED_TOKEN_PERMISSION_GROUPS) {
|
|
219
|
-
throw new Error(`Devflare selected ${selectedPermissionGroups.length} permission groups, which exceeds Cloudflare's ${MAX_ACCOUNT_OWNED_TOKEN_PERMISSION_GROUPS}-group limit for account-owned tokens.`);
|
|
220
|
-
}
|
|
221
|
-
return selectedPermissionGroups;
|
|
222
|
-
}
|
|
223
|
-
async function listAccountTokenPermissionGroups(accountId, options) {
|
|
224
|
-
const permissionGroups = await apiGetAll(`/accounts/${accountId}/tokens/permission_groups`, options);
|
|
225
|
-
return dedupePermissionGroups(permissionGroups);
|
|
226
|
-
}
|
|
227
|
-
async function listAccountOwnedAPITokens(accountId, options) {
|
|
228
|
-
const tokens = await apiGetAll(`/accounts/${accountId}/tokens`, options);
|
|
229
|
-
return tokens.map(mapAccountOwnedAPIToken);
|
|
230
|
-
}
|
|
231
|
-
async function deleteAccountOwnedAPIToken(accountId, tokenId, options) {
|
|
232
|
-
return apiDelete(`/accounts/${accountId}/tokens/${tokenId}`, options);
|
|
233
|
-
}
|
|
234
|
-
async function rollAccountOwnedAPITokenValue(accountId, tokenId, options) {
|
|
235
|
-
return apiPut(`/accounts/${accountId}/tokens/${tokenId}/value`, {}, options);
|
|
236
|
-
}
|
|
237
|
-
async function createAccountOwnedAPIToken(accountId, options, clientOptions) {
|
|
238
|
-
const permissionGroupIds = dedupePermissionGroupIds(options.permissionGroups?.map((permissionGroup) => permissionGroup.id) ?? options.permissionGroupIds ?? []);
|
|
239
|
-
if (permissionGroupIds.length === 0) {
|
|
240
|
-
throw new Error("Cannot create a Devflare token without any permission groups");
|
|
241
|
-
}
|
|
242
|
-
if (permissionGroupIds.length > MAX_ACCOUNT_OWNED_TOKEN_PERMISSION_GROUPS) {
|
|
243
|
-
throw new Error(`Cannot create a Devflare token with more than ${MAX_ACCOUNT_OWNED_TOKEN_PERMISSION_GROUPS} permission groups.`);
|
|
244
|
-
}
|
|
245
|
-
const policies = options.permissionGroups ? buildCreateTokenPoliciesFromPermissionGroups(accountId, options.permissionGroups) : buildCreateTokenPoliciesFromPermissionGroupIds(accountId, permissionGroupIds);
|
|
246
|
-
if (policies.length === 0) {
|
|
247
|
-
throw new Error("Cannot create a Devflare token without any account- or zone-scoped permission groups");
|
|
248
|
-
}
|
|
249
|
-
const createdToken = await apiPost(`/accounts/${accountId}/tokens`, {
|
|
250
|
-
name: options.name,
|
|
251
|
-
policies
|
|
252
|
-
}, clientOptions);
|
|
253
|
-
return mapAccountOwnedAPIToken(createdToken);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export { normalizeDevflareTokenName, stripDevflareTokenNamePrefix, filterDevflareManagedTokens, selectDevflarePermissionGroups, selectAllReusablePermissionGroups, listAccountTokenPermissionGroups, listAccountOwnedAPITokens, deleteAccountOwnedAPIToken, rollAccountOwnedAPITokenValue, createAccountOwnedAPIToken };
|