devflare 1.0.0-next.22 → 1.0.0-next.23
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/LLM.md +144 -5
- package/dist/account-j8nfggg4.js +475 -0
- package/dist/account-qhe8vtds.js +475 -0
- package/dist/bridge/miniflare.d.ts +1 -1
- package/dist/bridge/miniflare.d.ts.map +1 -1
- package/dist/browser.d.ts +13 -13
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +4 -2
- package/dist/build-vy95gy3f.js +54 -0
- package/dist/build-yzx0gsaj.js +54 -0
- package/dist/cli/commands/build-artifacts.d.ts.map +1 -1
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/type-generation/generator.d.ts +4 -2
- package/dist/cli/commands/type-generation/generator.d.ts.map +1 -1
- package/dist/cli/commands/types.d.ts.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/config/compiler/types.d.ts +1 -1
- package/dist/config/compiler/types.d.ts.map +1 -1
- package/dist/config/define.d.ts +7 -4
- package/dist/config/define.d.ts.map +1 -1
- package/dist/config/env-vars.d.ts +309 -0
- package/dist/config/env-vars.d.ts.map +1 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/local-dev-vars.d.ts +2 -2
- package/dist/config/local-dev-vars.d.ts.map +1 -1
- package/dist/config/schema-env.d.ts +6 -6
- package/dist/config/schema-types-bindings-platform.d.ts +378 -0
- package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
- package/dist/config/schema-types-bindings-resources.d.ts +551 -0
- package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
- package/dist/config/schema-types-bindings.d.ts +254 -0
- package/dist/config/schema-types-bindings.d.ts.map +1 -0
- package/dist/config/schema-types-build.d.ts +86 -0
- package/dist/config/schema-types-build.d.ts.map +1 -0
- package/dist/config/schema-types-runtime.d.ts +882 -0
- package/dist/config/schema-types-runtime.d.ts.map +1 -0
- package/dist/config/schema-types.d.ts +377 -0
- package/dist/config/schema-types.d.ts.map +1 -0
- package/dist/config/schema.d.ts +14 -15
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config-entry.d.ts +2 -0
- package/dist/config-entry.d.ts.map +1 -1
- package/dist/config-entry.js +3 -1
- package/dist/config-gq5jh4cx.js +105 -0
- package/dist/config-vec13050.js +105 -0
- package/dist/deploy-01j0ep5n.js +1055 -0
- package/dist/deploy-tjypkhg7.js +1055 -0
- package/dist/dev-bh581ew3.js +2597 -0
- package/dist/dev-gn5y93z9.js +2597 -0
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/doctor-h5q28qt1.js +259 -0
- package/dist/doctor-khk550tw.js +259 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/index-0bv2qjs1.js +1555 -0
- package/dist/index-3tkzn06q.js +413 -0
- package/dist/index-8fyz6gcm.js +699 -0
- package/dist/index-97z629zr.js +109 -0
- package/dist/index-b28c4yr4.js +1205 -0
- package/dist/index-c8p4njqy.js +479 -0
- package/dist/index-cr06zrgw.js +1033 -0
- package/dist/index-cwjjdtgn.js +74 -0
- package/dist/index-dref9ecb.js +476 -0
- package/dist/index-e151t4ge.js +895 -0
- package/dist/index-e7kakw0j.js +1033 -0
- package/dist/index-f1g5jdm8.js +1426 -0
- package/dist/index-f46984zs.js +1554 -0
- package/dist/index-grk8pzhr.js +185 -0
- package/dist/index-hzmpecq9.js +52 -0
- package/dist/index-j1csb7gb.js +581 -0
- package/dist/index-j7x7f72h.js +185 -0
- package/dist/index-jkqbjwt2.js +476 -0
- package/dist/index-mh5renra.js +895 -0
- package/dist/index-p9xq83p7.js +147 -0
- package/dist/index-q15nj71j.js +52 -0
- package/dist/index-qqp65pyv.js +699 -0
- package/dist/index-s0fmwxbk.js +74 -0
- package/dist/index-stzx8nc4.js +111 -0
- package/dist/index-th4vrnbk.js +1205 -0
- package/dist/index-vtcmsgaf.js +581 -0
- package/dist/index-x2k3awjs.js +147 -0
- package/dist/index-x8x547tz.js +1426 -0
- package/dist/index-xxxd0mvw.js +109 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/login-280p2cm9.js +77 -0
- package/dist/login-4n266whq.js +77 -0
- package/dist/previews-3m3ffpaw.js +1337 -0
- package/dist/previews-tr8sm03d.js +1337 -0
- package/dist/productions-62y489ff.js +505 -0
- package/dist/productions-cgn3fz7d.js +505 -0
- package/dist/runtime/exports.d.ts +23 -0
- package/dist/runtime/exports.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -3
- package/dist/secrets-4050kqf5.js +91 -0
- package/dist/secrets-p112cajt.js +91 -0
- package/dist/sveltekit/index.js +4 -4
- package/dist/test/index.js +23 -11
- package/dist/test/resolve-service-bindings.d.ts +1 -1
- package/dist/test/resolve-service-bindings.d.ts.map +1 -1
- package/dist/test/simple-context-lifecycle.d.ts.map +1 -1
- package/dist/types-apmt10yj.js +705 -0
- package/dist/types-ttrrgdfj.js +705 -0
- package/dist/vite/index.js +5 -5
- package/dist/vite/plugin-context.d.ts.map +1 -1
- package/dist/vite/plugin-programmatic.d.ts.map +1 -1
- package/dist/worker-2k1jyr6p.js +513 -0
- package/dist/worker-jqgn6jyj.js +513 -0
- package/package.json +1 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeSecretsStoreBinding
|
|
3
|
+
} from "./index-0bv2qjs1.js";
|
|
4
|
+
|
|
5
|
+
// src/secrets/local-secrets.ts
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
var LOCAL_SECRETS_PATH = join(".devflare", "secrets.local.json");
|
|
9
|
+
var LOCAL_SECRET_WRAPPED_BINDING_SCRIPT = `
|
|
10
|
+
class LocalSecretsStoreSecret {
|
|
11
|
+
constructor(env) {
|
|
12
|
+
this.value = env.value
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async get() {
|
|
16
|
+
return this.value
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function makeBinding(env) {
|
|
21
|
+
return new LocalSecretsStoreSecret(env)
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
function createEmptyLocalSecretsFile() {
|
|
25
|
+
return {
|
|
26
|
+
version: 1,
|
|
27
|
+
stores: {}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function getLocalSecretsFilePath(cwd) {
|
|
31
|
+
return join(cwd, LOCAL_SECRETS_PATH);
|
|
32
|
+
}
|
|
33
|
+
function parseLocalSecretsFile(raw) {
|
|
34
|
+
const parsed = JSON.parse(raw);
|
|
35
|
+
if (parsed.version !== 1 || !parsed.stores || typeof parsed.stores !== "object") {
|
|
36
|
+
return createEmptyLocalSecretsFile();
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
version: 1,
|
|
40
|
+
stores: parsed.stores
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function readLocalSecretsFile(cwd) {
|
|
44
|
+
const filePath = getLocalSecretsFilePath(cwd);
|
|
45
|
+
if (!existsSync(filePath)) {
|
|
46
|
+
return createEmptyLocalSecretsFile();
|
|
47
|
+
}
|
|
48
|
+
return parseLocalSecretsFile(readFileSync(filePath, "utf8"));
|
|
49
|
+
}
|
|
50
|
+
function writeLocalSecretsFile(cwd, file) {
|
|
51
|
+
const filePath = getLocalSecretsFilePath(cwd);
|
|
52
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
53
|
+
writeFileSync(filePath, `${JSON.stringify(file, null, "\t")}
|
|
54
|
+
`, {
|
|
55
|
+
encoding: "utf8",
|
|
56
|
+
mode: 384
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function writeLocalSecret({ cwd, storeId, name, value }) {
|
|
60
|
+
const file = readLocalSecretsFile(cwd);
|
|
61
|
+
file.stores[storeId] ??= {};
|
|
62
|
+
file.stores[storeId][name] = {
|
|
63
|
+
value,
|
|
64
|
+
updatedAt: new Date().toISOString()
|
|
65
|
+
};
|
|
66
|
+
writeLocalSecretsFile(cwd, file);
|
|
67
|
+
}
|
|
68
|
+
function readLocalSecret({ cwd, storeId, name }) {
|
|
69
|
+
return readLocalSecretsFile(cwd).stores[storeId]?.[name]?.value;
|
|
70
|
+
}
|
|
71
|
+
function deleteLocalSecret({ cwd, storeId, name }) {
|
|
72
|
+
const file = readLocalSecretsFile(cwd);
|
|
73
|
+
const store = file.stores[storeId];
|
|
74
|
+
if (!store || !(name in store)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
delete store[name];
|
|
78
|
+
if (Object.keys(store).length === 0) {
|
|
79
|
+
delete file.stores[storeId];
|
|
80
|
+
}
|
|
81
|
+
writeLocalSecretsFile(cwd, file);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
function listLocalSecrets({ cwd, storeId }) {
|
|
85
|
+
const file = readLocalSecretsFile(cwd);
|
|
86
|
+
const stores = storeId ? { [storeId]: file.stores[storeId] ?? {} } : file.stores;
|
|
87
|
+
return Object.entries(stores).flatMap(([currentStoreId, secrets]) => Object.entries(secrets).map(([name, secret]) => ({
|
|
88
|
+
storeId: currentStoreId,
|
|
89
|
+
name,
|
|
90
|
+
hasValue: typeof secret.value === "string",
|
|
91
|
+
updatedAt: secret.updatedAt
|
|
92
|
+
})));
|
|
93
|
+
}
|
|
94
|
+
function resolveLocalSecretValuesForBindings(config, cwd) {
|
|
95
|
+
const values = {};
|
|
96
|
+
for (const [bindingName, binding] of Object.entries(config.bindings?.secretsStore ?? {})) {
|
|
97
|
+
const normalized = normalizeSecretsStoreBinding(binding, config.secretsStoreId, bindingName);
|
|
98
|
+
const value = readLocalSecret({
|
|
99
|
+
cwd,
|
|
100
|
+
storeId: normalized.storeId,
|
|
101
|
+
name: normalized.secretName
|
|
102
|
+
});
|
|
103
|
+
if (value !== undefined) {
|
|
104
|
+
values[bindingName] = value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return values;
|
|
108
|
+
}
|
|
109
|
+
function toLocalSecretWorkerName(bindingName, index) {
|
|
110
|
+
const slug = bindingName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "secret";
|
|
111
|
+
return `devflare-local-secret-${index}-${slug}`;
|
|
112
|
+
}
|
|
113
|
+
function buildLocalSecretWrappedBindingConfig(config, cwd) {
|
|
114
|
+
const values = resolveLocalSecretValuesForBindings(config, cwd);
|
|
115
|
+
const entries = Object.entries(values);
|
|
116
|
+
return {
|
|
117
|
+
localBindingNames: entries.map(([bindingName]) => bindingName),
|
|
118
|
+
wrappedBindings: Object.fromEntries(entries.map(([bindingName, value], index) => {
|
|
119
|
+
const scriptName = toLocalSecretWorkerName(bindingName, index);
|
|
120
|
+
return [
|
|
121
|
+
bindingName,
|
|
122
|
+
{
|
|
123
|
+
scriptName,
|
|
124
|
+
bindings: { value }
|
|
125
|
+
}
|
|
126
|
+
];
|
|
127
|
+
})),
|
|
128
|
+
workers: entries.map(([bindingName], index) => ({
|
|
129
|
+
name: toLocalSecretWorkerName(bindingName, index),
|
|
130
|
+
modules: true,
|
|
131
|
+
script: LOCAL_SECRET_WRAPPED_BINDING_SCRIPT
|
|
132
|
+
}))
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function buildLocalSecretNodeBindings(config, cwd) {
|
|
136
|
+
const values = resolveLocalSecretValuesForBindings(config, cwd);
|
|
137
|
+
return Object.fromEntries(Object.entries(values).map(([bindingName, value]) => [
|
|
138
|
+
bindingName,
|
|
139
|
+
{
|
|
140
|
+
async get() {
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
]));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { writeLocalSecret, deleteLocalSecret, listLocalSecrets, resolveLocalSecretValuesForBindings, buildLocalSecretWrappedBindingConfig, buildLocalSecretNodeBindings };
|