flaghoist 0.3.0 → 0.3.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/dist/{chunk-HOSNPNBP.js → chunk-HSDDPXCM.js} +1 -0
- package/dist/index.js +23 -75
- package/dist/lib.d.ts +2 -2
- package/dist/lib.js +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
containerStorageDefault,
|
|
8
8
|
parseConfig,
|
|
9
9
|
serializeConfig
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-HSDDPXCM.js";
|
|
11
11
|
|
|
12
12
|
// src/index.ts
|
|
13
13
|
import { spawnSync } from "child_process";
|
|
@@ -17,87 +17,23 @@ import { createInterface } from "readline/promises";
|
|
|
17
17
|
import { parseArgs } from "util";
|
|
18
18
|
|
|
19
19
|
// src/admin.ts
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const path = (key) => `${api}/flags/${encodeURIComponent(key)}`;
|
|
28
|
-
return {
|
|
29
|
-
async list() {
|
|
30
|
-
const res = await doFetch(`${api}/flags`, { headers });
|
|
31
|
-
if (!res.ok) throw new Error(`Failed to list flags (${res.status})`);
|
|
32
|
-
return (await res.json()).flags;
|
|
33
|
-
},
|
|
34
|
-
async get(key) {
|
|
35
|
-
const res = await doFetch(path(key), { headers });
|
|
36
|
-
if (res.status === 404) return null;
|
|
37
|
-
if (!res.ok) throw new Error(`Failed to read flag "${key}" (${res.status})`);
|
|
38
|
-
return await res.json();
|
|
39
|
-
},
|
|
40
|
-
async put(key, input) {
|
|
41
|
-
const res = await doFetch(path(key), { method: "PUT", headers, body: JSON.stringify(input) });
|
|
42
|
-
if (!res.ok)
|
|
43
|
-
throw new Error(`Failed to save flag "${key}" (${res.status}): ${await res.text()}`);
|
|
44
|
-
return await res.json();
|
|
45
|
-
},
|
|
46
|
-
async delete(key) {
|
|
47
|
-
const res = await doFetch(path(key), { method: "DELETE", headers });
|
|
48
|
-
if (!res.ok && res.status !== 404)
|
|
49
|
-
throw new Error(`Failed to delete flag "${key}" (${res.status})`);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function requireFlag(flag, key) {
|
|
54
|
-
if (!flag) throw new Error(`Flag "${key}" not found`);
|
|
55
|
-
return flag;
|
|
56
|
-
}
|
|
57
|
-
function createFlag(client, key, opts) {
|
|
58
|
-
return client.put(key, {
|
|
59
|
-
enabled: opts.enabled ?? false,
|
|
60
|
-
rollout: { percentage: opts.percentage ?? 0 },
|
|
61
|
-
rules: [],
|
|
62
|
-
description: opts.description ?? ""
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
async function toggleFlag(client, key, to) {
|
|
66
|
-
const flag = requireFlag(await client.get(key), key);
|
|
67
|
-
const enabled = to === "flip" ? !flag.enabled : to;
|
|
68
|
-
return client.put(key, {
|
|
69
|
-
enabled,
|
|
70
|
-
rollout: flag.rollout,
|
|
71
|
-
rules: flag.rules,
|
|
72
|
-
description: flag.description
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async function setRollout(client, key, percentage) {
|
|
76
|
-
const flag = requireFlag(await client.get(key), key);
|
|
77
|
-
return client.put(key, {
|
|
78
|
-
enabled: flag.enabled,
|
|
79
|
-
rollout: { percentage },
|
|
80
|
-
rules: flag.rules,
|
|
81
|
-
description: flag.description
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
async function setRules(client, key, rules) {
|
|
85
|
-
const flag = requireFlag(await client.get(key), key);
|
|
86
|
-
return client.put(key, {
|
|
87
|
-
enabled: flag.enabled,
|
|
88
|
-
rollout: flag.rollout,
|
|
89
|
-
rules,
|
|
90
|
-
description: flag.description
|
|
91
|
-
});
|
|
92
|
-
}
|
|
20
|
+
import {
|
|
21
|
+
createAdminClient,
|
|
22
|
+
createFlag,
|
|
23
|
+
setRollout,
|
|
24
|
+
setRules,
|
|
25
|
+
toggleFlag
|
|
26
|
+
} from "@flaghoist/admin-client";
|
|
93
27
|
|
|
94
28
|
// src/generate-container.ts
|
|
95
29
|
var CONTAINER_DEPS = {
|
|
96
30
|
"@flaghoist/adapter-memory": "^0.1.2",
|
|
97
31
|
"@flaghoist/adapter-postgres": "^0.1.2",
|
|
98
32
|
"@flaghoist/adapter-redis": "^0.1.2",
|
|
33
|
+
"@flaghoist/adapter-sqlite": "^0.1.0",
|
|
99
34
|
"@flaghoist/server": "^0.3.0",
|
|
100
35
|
"@hono/node-server": "^2.1.1",
|
|
36
|
+
"better-sqlite3": "^11.0.0",
|
|
101
37
|
ioredis: "^5.4.0",
|
|
102
38
|
pg: "^8.13.0"
|
|
103
39
|
};
|
|
@@ -117,6 +53,7 @@ function generateNodeEntry(config) {
|
|
|
117
53
|
`import { memoryAdapter } from '@flaghoist/adapter-memory'`,
|
|
118
54
|
`import { initPostgres, postgresAdapter } from '@flaghoist/adapter-postgres'`,
|
|
119
55
|
`import { redisAdapter } from '@flaghoist/adapter-redis'`,
|
|
56
|
+
`import { initSqlite, sqliteAdapter } from '@flaghoist/adapter-sqlite'`,
|
|
120
57
|
`import { ${serverImports.join(", ")} } from '@flaghoist/server'`,
|
|
121
58
|
...config.dashboard ? [`import { dashboardHtml } from '@flaghoist/server/dashboard'`] : [],
|
|
122
59
|
`import { serve } from '@hono/node-server'`
|
|
@@ -150,12 +87,19 @@ async function makeStorage() {
|
|
|
150
87
|
return redisAdapter(new Redis(env.REDIS_URL), { hashKey: env.FLAGS_HASH_KEY ?? 'flaghoist:flags' })
|
|
151
88
|
}
|
|
152
89
|
|
|
90
|
+
if (kind === 'sqlite') {
|
|
91
|
+
const { default: Database } = await import('better-sqlite3')
|
|
92
|
+
const db = new Database(env.DATABASE_PATH ?? '/data/flags.db')
|
|
93
|
+
initSqlite(db)
|
|
94
|
+
return sqliteAdapter(db)
|
|
95
|
+
}
|
|
96
|
+
|
|
153
97
|
if (kind === 'memory') {
|
|
154
98
|
console.warn('[flaghoist] FLAGS_STORAGE=memory: flags are in-process and are lost on restart.')
|
|
155
99
|
return memoryAdapter()
|
|
156
100
|
}
|
|
157
101
|
|
|
158
|
-
throw new Error(\`Unknown FLAGS_STORAGE "\${kind}". Use postgres, redis, or memory.\`)
|
|
102
|
+
throw new Error(\`Unknown FLAGS_STORAGE "\${kind}". Use postgres, redis, sqlite, or memory.\`)
|
|
159
103
|
}
|
|
160
104
|
|
|
161
105
|
const app = createFlagServer({
|
|
@@ -253,6 +197,10 @@ function storageSnippet(storage) {
|
|
|
253
197
|
expr: "memoryAdapter()",
|
|
254
198
|
pkg: "@flaghoist/adapter-memory"
|
|
255
199
|
};
|
|
200
|
+
case "sqlite":
|
|
201
|
+
throw new Error(
|
|
202
|
+
'SQLite storage requires a Node or container deployment. Use `npx flaghoist deploy` and pick "Another platform".'
|
|
203
|
+
);
|
|
256
204
|
}
|
|
257
205
|
}
|
|
258
206
|
function adminExpr2(admin) {
|
package/dist/lib.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type StorageKind = 'cloudflare-kv' | 'redis' | 'postgres' | 'memory';
|
|
1
|
+
type StorageKind = 'cloudflare-kv' | 'redis' | 'postgres' | 'sqlite' | 'memory';
|
|
2
2
|
type AdminAuthKind = 'bearer-token' | 'oidc';
|
|
3
3
|
/**
|
|
4
4
|
* The shape of project `flaghoist deploy`/`eject` scaffolds. `cloudflare` is a Worker plus a
|
|
@@ -26,7 +26,7 @@ declare const STORAGE_KINDS: readonly StorageKind[];
|
|
|
26
26
|
/** Every deploy shape selectable by name in `flaghoist.toml`. */
|
|
27
27
|
declare const PLATFORM_KINDS: readonly PlatformKind[];
|
|
28
28
|
/** The stores a container can reach. Cloudflare KV is a Worker binding, so it is not one of them. */
|
|
29
|
-
type ContainerStorage = 'postgres' | 'redis' | 'memory';
|
|
29
|
+
type ContainerStorage = 'postgres' | 'redis' | 'sqlite' | 'memory';
|
|
30
30
|
/**
|
|
31
31
|
* The storage a container project uses. Cloudflare KV cannot be reached off Workers, so a config
|
|
32
32
|
* that still names it (the scaffolding default) becomes postgres, the store every container deploy
|
package/dist/lib.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flaghoist",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Scaffold, deploy, and manage your Flaghoist feature-flag service from the terminal.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"node": ">=20"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"smol-toml": "^1.8.0"
|
|
26
|
+
"smol-toml": "^1.8.0",
|
|
27
|
+
"@flaghoist/admin-client": "0.2.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@flaghoist/adapter-memory": "0.1.2",
|