flingit 0.0.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/README.md +84 -0
- package/dist/cli/commands/db.d.ts +9 -0
- package/dist/cli/commands/db.d.ts.map +1 -0
- package/dist/cli/commands/db.js +215 -0
- package/dist/cli/commands/db.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +6 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +145 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/feedback.d.ts +6 -0
- package/dist/cli/commands/feedback.d.ts.map +1 -0
- package/dist/cli/commands/feedback.js +116 -0
- package/dist/cli/commands/feedback.js.map +1 -0
- package/dist/cli/commands/init.d.ts +6 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +161 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/launch.d.ts +12 -0
- package/dist/cli/commands/launch.d.ts.map +1 -0
- package/dist/cli/commands/launch.js +176 -0
- package/dist/cli/commands/launch.js.map +1 -0
- package/dist/cli/commands/login.d.ts +6 -0
- package/dist/cli/commands/login.d.ts.map +1 -0
- package/dist/cli/commands/login.js +90 -0
- package/dist/cli/commands/login.js.map +1 -0
- package/dist/cli/commands/logout.d.ts +6 -0
- package/dist/cli/commands/logout.d.ts.map +1 -0
- package/dist/cli/commands/logout.js +32 -0
- package/dist/cli/commands/logout.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +12 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +261 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/onboard.d.ts +22 -0
- package/dist/cli/commands/onboard.d.ts.map +1 -0
- package/dist/cli/commands/onboard.js +244 -0
- package/dist/cli/commands/onboard.js.map +1 -0
- package/dist/cli/commands/project.d.ts +6 -0
- package/dist/cli/commands/project.d.ts.map +1 -0
- package/dist/cli/commands/project.js +142 -0
- package/dist/cli/commands/project.js.map +1 -0
- package/dist/cli/commands/push.d.ts +6 -0
- package/dist/cli/commands/push.d.ts.map +1 -0
- package/dist/cli/commands/push.js +351 -0
- package/dist/cli/commands/push.js.map +1 -0
- package/dist/cli/commands/register.d.ts +6 -0
- package/dist/cli/commands/register.d.ts.map +1 -0
- package/dist/cli/commands/register.js +115 -0
- package/dist/cli/commands/register.js.map +1 -0
- package/dist/cli/commands/secret.d.ts +11 -0
- package/dist/cli/commands/secret.d.ts.map +1 -0
- package/dist/cli/commands/secret.js +124 -0
- package/dist/cli/commands/secret.js.map +1 -0
- package/dist/cli/commands/whoami.d.ts +6 -0
- package/dist/cli/commands/whoami.d.ts.map +1 -0
- package/dist/cli/commands/whoami.js +54 -0
- package/dist/cli/commands/whoami.js.map +1 -0
- package/dist/cli/deploy/assets.d.ts +73 -0
- package/dist/cli/deploy/assets.d.ts.map +1 -0
- package/dist/cli/deploy/assets.js +167 -0
- package/dist/cli/deploy/assets.js.map +1 -0
- package/dist/cli/deploy/base64-stream.d.ts +16 -0
- package/dist/cli/deploy/base64-stream.d.ts.map +1 -0
- package/dist/cli/deploy/base64-stream.js +44 -0
- package/dist/cli/deploy/base64-stream.js.map +1 -0
- package/dist/cli/deploy/bucket-stream.d.ts +18 -0
- package/dist/cli/deploy/bucket-stream.d.ts.map +1 -0
- package/dist/cli/deploy/bucket-stream.js +63 -0
- package/dist/cli/deploy/bucket-stream.js.map +1 -0
- package/dist/cli/deploy/bundler.d.ts +22 -0
- package/dist/cli/deploy/bundler.d.ts.map +1 -0
- package/dist/cli/deploy/bundler.js +131 -0
- package/dist/cli/deploy/bundler.js.map +1 -0
- package/dist/cli/deploy/worker-entry.d.ts +14 -0
- package/dist/cli/deploy/worker-entry.d.ts.map +1 -0
- package/dist/cli/deploy/worker-entry.js +60 -0
- package/dist/cli/deploy/worker-entry.js.map +1 -0
- package/dist/cli/deploy/wrangler-config.d.ts +20 -0
- package/dist/cli/deploy/wrangler-config.d.ts.map +1 -0
- package/dist/cli/deploy/wrangler-config.js +54 -0
- package/dist/cli/deploy/wrangler-config.js.map +1 -0
- package/dist/cli/index.d.ts +10 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +72 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/config.d.ts +39 -0
- package/dist/cli/utils/config.d.ts.map +1 -0
- package/dist/cli/utils/config.js +105 -0
- package/dist/cli/utils/config.js.map +1 -0
- package/dist/cli/utils/duration.d.ts +21 -0
- package/dist/cli/utils/duration.d.ts.map +1 -0
- package/dist/cli/utils/duration.js +44 -0
- package/dist/cli/utils/duration.js.map +1 -0
- package/dist/cli/utils/environment.d.ts +17 -0
- package/dist/cli/utils/environment.d.ts.map +1 -0
- package/dist/cli/utils/environment.js +27 -0
- package/dist/cli/utils/environment.js.map +1 -0
- package/dist/cli/utils/project.d.ts +24 -0
- package/dist/cli/utils/project.d.ts.map +1 -0
- package/dist/cli/utils/project.js +47 -0
- package/dist/cli/utils/project.js.map +1 -0
- package/dist/cli/utils/registry.d.ts +34 -0
- package/dist/cli/utils/registry.d.ts.map +1 -0
- package/dist/cli/utils/registry.js +94 -0
- package/dist/cli/utils/registry.js.map +1 -0
- package/dist/cli/utils/token.d.ts +12 -0
- package/dist/cli/utils/token.d.ts.map +1 -0
- package/dist/cli/utils/token.js +27 -0
- package/dist/cli/utils/token.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/cron.d.ts +50 -0
- package/dist/runtime/cron.d.ts.map +1 -0
- package/dist/runtime/cron.js +80 -0
- package/dist/runtime/cron.js.map +1 -0
- package/dist/runtime/db.d.ts +93 -0
- package/dist/runtime/db.d.ts.map +1 -0
- package/dist/runtime/db.js +137 -0
- package/dist/runtime/db.js.map +1 -0
- package/dist/runtime/http.d.ts +33 -0
- package/dist/runtime/http.d.ts.map +1 -0
- package/dist/runtime/http.js +36 -0
- package/dist/runtime/http.js.map +1 -0
- package/dist/runtime/log.d.ts +90 -0
- package/dist/runtime/log.d.ts.map +1 -0
- package/dist/runtime/log.js +211 -0
- package/dist/runtime/log.js.map +1 -0
- package/dist/runtime/migrate.d.ts +54 -0
- package/dist/runtime/migrate.d.ts.map +1 -0
- package/dist/runtime/migrate.js +130 -0
- package/dist/runtime/migrate.js.map +1 -0
- package/dist/runtime/secrets.d.ts +36 -0
- package/dist/runtime/secrets.d.ts.map +1 -0
- package/dist/runtime/secrets.js +75 -0
- package/dist/runtime/secrets.js.map +1 -0
- package/dist/worker-runtime/index.d.ts +79 -0
- package/dist/worker-runtime/index.d.ts.map +1 -0
- package/dist/worker-runtime/index.js +203 -0
- package/dist/worker-runtime/index.js.map +1 -0
- package/package.json +81 -0
- package/templates/default/.nvmrc +1 -0
- package/templates/default/CLAUDE.md +197 -0
- package/templates/default/index.html +13 -0
- package/templates/default/package.json +25 -0
- package/templates/default/public/vite.svg +1 -0
- package/templates/default/skills/fling/API.md +335 -0
- package/templates/default/skills/fling/EXAMPLES.md +204 -0
- package/templates/default/skills/fling/FEEDBACK.md +73 -0
- package/templates/default/skills/fling/SKILL.md +159 -0
- package/templates/default/src/react-app/App.css +34 -0
- package/templates/default/src/react-app/App.tsx +27 -0
- package/templates/default/src/react-app/index.css +15 -0
- package/templates/default/src/react-app/main.tsx +10 -0
- package/templates/default/src/react-app/vite-env.d.ts +1 -0
- package/templates/default/src/worker/index.ts +27 -0
- package/templates/default/tsconfig.app.json +22 -0
- package/templates/default/tsconfig.json +7 -0
- package/templates/default/tsconfig.worker.json +11 -0
- package/templates/default/vite.config.ts +21 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle user code for deployment to the platform.
|
|
3
|
+
* Uses esbuild to create a single file with all dependencies.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Bundle user's app.ts for platform deployment.
|
|
7
|
+
*
|
|
8
|
+
* This creates a worker entry that:
|
|
9
|
+
* 1. Initializes the environment from bindings
|
|
10
|
+
* 2. Imports the user's app
|
|
11
|
+
* 3. Exports fetch handler
|
|
12
|
+
*
|
|
13
|
+
* Note: Static assets are served directly by Cloudflare without invoking the worker
|
|
14
|
+
* (default `run_worker_first = false`). SPA navigation is handled by Cloudflare's
|
|
15
|
+
* `not_found_handling: "single-page-application"` config. No fallback code is needed.
|
|
16
|
+
*
|
|
17
|
+
* @param projectDir - The project directory containing src/app.ts
|
|
18
|
+
* @param verbose - Enable verbose logging
|
|
19
|
+
* @returns The bundled code as a string
|
|
20
|
+
*/
|
|
21
|
+
export declare function bundleForPlatform(projectDir: string, verbose?: boolean): Promise<string>;
|
|
22
|
+
//# sourceMappingURL=bundler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../../../src/cli/deploy/bundler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,UAAQ,GACd,OAAO,CAAC,MAAM,CAAC,CA2GjB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle user code for deployment to the platform.
|
|
3
|
+
* Uses esbuild to create a single file with all dependencies.
|
|
4
|
+
*/
|
|
5
|
+
import { build } from "esbuild";
|
|
6
|
+
import { join, dirname } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { existsSync } from "node:fs";
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
/**
|
|
11
|
+
* Get the path to the worker runtime entry.
|
|
12
|
+
* The worker runtime is at fling/worker-runtime when deployed.
|
|
13
|
+
*/
|
|
14
|
+
function getWorkerRuntimePath() {
|
|
15
|
+
// From dist/cli/deploy/ -> dist/worker-runtime/index.js
|
|
16
|
+
return join(__dirname, "..", "..", "worker-runtime", "index.js");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Bundle user's app.ts for platform deployment.
|
|
20
|
+
*
|
|
21
|
+
* This creates a worker entry that:
|
|
22
|
+
* 1. Initializes the environment from bindings
|
|
23
|
+
* 2. Imports the user's app
|
|
24
|
+
* 3. Exports fetch handler
|
|
25
|
+
*
|
|
26
|
+
* Note: Static assets are served directly by Cloudflare without invoking the worker
|
|
27
|
+
* (default `run_worker_first = false`). SPA navigation is handled by Cloudflare's
|
|
28
|
+
* `not_found_handling: "single-page-application"` config. No fallback code is needed.
|
|
29
|
+
*
|
|
30
|
+
* @param projectDir - The project directory containing src/app.ts
|
|
31
|
+
* @param verbose - Enable verbose logging
|
|
32
|
+
* @returns The bundled code as a string
|
|
33
|
+
*/
|
|
34
|
+
export async function bundleForPlatform(projectDir, verbose = false) {
|
|
35
|
+
const appPath = join(projectDir, "src", "worker", "index.ts");
|
|
36
|
+
const workerRuntimePath = getWorkerRuntimePath();
|
|
37
|
+
if (!existsSync(appPath)) {
|
|
38
|
+
throw new Error("Worker entry point not found: src/worker/index.ts\n\n" +
|
|
39
|
+
"This file is your backend API entry point.\n" +
|
|
40
|
+
"Run 'fling init' to create a new project with the correct structure.");
|
|
41
|
+
}
|
|
42
|
+
if (verbose) {
|
|
43
|
+
console.log("[verbose] bundler __dirname:", __dirname);
|
|
44
|
+
console.log("[verbose] appPath:", appPath);
|
|
45
|
+
console.log("[verbose] workerRuntimePath:", workerRuntimePath);
|
|
46
|
+
}
|
|
47
|
+
// Create the worker entry code that wraps the user's app
|
|
48
|
+
const entryCode = `
|
|
49
|
+
import { __initEnv, __getApp, __runMigrations } from "${workerRuntimePath}";
|
|
50
|
+
|
|
51
|
+
let initialized = false;
|
|
52
|
+
let initError = null;
|
|
53
|
+
|
|
54
|
+
async function ensureInit(env) {
|
|
55
|
+
// If initialization previously failed, throw the same error
|
|
56
|
+
if (initError) {
|
|
57
|
+
throw initError;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!initialized) {
|
|
61
|
+
__initEnv(env);
|
|
62
|
+
try {
|
|
63
|
+
await import("${appPath}");
|
|
64
|
+
await __runMigrations();
|
|
65
|
+
initialized = true;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Log the error clearly before re-throwing
|
|
68
|
+
console.error("=".repeat(60));
|
|
69
|
+
console.error("WORKER INITIALIZATION FAILED");
|
|
70
|
+
console.error("=".repeat(60));
|
|
71
|
+
console.error("Error:", error instanceof Error ? error.message : String(error));
|
|
72
|
+
if (error instanceof Error && error.stack) {
|
|
73
|
+
console.error("Stack:", error.stack);
|
|
74
|
+
}
|
|
75
|
+
console.error("=".repeat(60));
|
|
76
|
+
|
|
77
|
+
// Store the error so subsequent requests also fail clearly
|
|
78
|
+
initError = error;
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default {
|
|
85
|
+
async fetch(request, env, ctx) {
|
|
86
|
+
await ensureInit(env);
|
|
87
|
+
return __getApp().fetch(request, env, ctx);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
`;
|
|
91
|
+
if (verbose) {
|
|
92
|
+
console.log("[verbose] entryCode:", entryCode);
|
|
93
|
+
console.log("[verbose] Calling esbuild.build()...");
|
|
94
|
+
}
|
|
95
|
+
// Bundle with esbuild
|
|
96
|
+
const result = await build({
|
|
97
|
+
stdin: {
|
|
98
|
+
contents: entryCode,
|
|
99
|
+
resolveDir: projectDir,
|
|
100
|
+
loader: "ts",
|
|
101
|
+
},
|
|
102
|
+
bundle: true,
|
|
103
|
+
format: "esm",
|
|
104
|
+
target: "esnext",
|
|
105
|
+
platform: "browser", // Workers are browser-like, not Node
|
|
106
|
+
minify: false, // Keep readable for debugging
|
|
107
|
+
write: false,
|
|
108
|
+
external: [], // Bundle everything
|
|
109
|
+
alias: {
|
|
110
|
+
// Redirect 'fling' imports to worker runtime
|
|
111
|
+
fling: workerRuntimePath,
|
|
112
|
+
},
|
|
113
|
+
define: {
|
|
114
|
+
"process.env.NODE_ENV": '"production"',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
if (verbose) {
|
|
118
|
+
console.log("[verbose] esbuild completed, errors:", result.errors.length);
|
|
119
|
+
console.log("[verbose] output files:", result.outputFiles.length);
|
|
120
|
+
}
|
|
121
|
+
const firstError = result.errors[0];
|
|
122
|
+
if (firstError) {
|
|
123
|
+
throw new Error(`Bundle failed: ${firstError.text}`);
|
|
124
|
+
}
|
|
125
|
+
const outputFile = result.outputFiles[0];
|
|
126
|
+
if (!outputFile) {
|
|
127
|
+
throw new Error("Bundle produced no output");
|
|
128
|
+
}
|
|
129
|
+
return outputFile.text;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=bundler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler.js","sourceRoot":"","sources":["../../../src/cli/deploy/bundler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D;;;GAGG;AACH,SAAS,oBAAoB;IAC3B,wDAAwD;IACxD,OAAO,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,UAAkB,EAClB,OAAO,GAAG,KAAK;IAEf,MAAM,OAAO,GAAG,IAA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AsB,EAAE,cAAc;SACvC;KACF,CAAC,CAAC;IAEH,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,CAAC,sCAAsC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1E,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACzC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,UAAU,CAAC,IAAI,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate the _worker.ts entry point for Cloudflare Workers
|
|
3
|
+
*
|
|
4
|
+
* This creates a wrapper that:
|
|
5
|
+
* 1. Initializes the Worker environment (bindings)
|
|
6
|
+
* 2. Dynamically imports the user's app code (after env is ready)
|
|
7
|
+
* 3. Exports fetch and scheduled handlers
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Generate the _worker.ts content for deployment.
|
|
11
|
+
* Includes both HTTP fetch and cron scheduled handlers.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateWorkerEntry(): string;
|
|
14
|
+
//# sourceMappingURL=worker-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-entry.d.ts","sourceRoot":"","sources":["../../../src/cli/deploy/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CA8C5C"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate the _worker.ts entry point for Cloudflare Workers
|
|
3
|
+
*
|
|
4
|
+
* This creates a wrapper that:
|
|
5
|
+
* 1. Initializes the Worker environment (bindings)
|
|
6
|
+
* 2. Dynamically imports the user's app code (after env is ready)
|
|
7
|
+
* 3. Exports fetch and scheduled handlers
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Generate the _worker.ts content for deployment.
|
|
11
|
+
* Includes both HTTP fetch and cron scheduled handlers.
|
|
12
|
+
*/
|
|
13
|
+
export function generateWorkerEntry() {
|
|
14
|
+
return `/**
|
|
15
|
+
* CLIde Worker Entry Point
|
|
16
|
+
* Generated by clide push - do not edit manually
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { __initEnv, __getApp, __getCronHandlers, __runMigrations } from "clide/worker-runtime";
|
|
20
|
+
|
|
21
|
+
let initialized = false;
|
|
22
|
+
|
|
23
|
+
async function ensureInit(env) {
|
|
24
|
+
if (!initialized) {
|
|
25
|
+
__initEnv(env);
|
|
26
|
+
await import("./src/app.ts");
|
|
27
|
+
await __runMigrations();
|
|
28
|
+
initialized = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default {
|
|
33
|
+
async fetch(request, env, ctx) {
|
|
34
|
+
await ensureInit(env);
|
|
35
|
+
return __getApp().fetch(request, env, ctx);
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
async scheduled(event, env, ctx) {
|
|
39
|
+
await ensureInit(env);
|
|
40
|
+
const handlers = __getCronHandlers();
|
|
41
|
+
|
|
42
|
+
// Find handler matching this schedule
|
|
43
|
+
for (const [name, { schedule, handler }] of handlers) {
|
|
44
|
+
if (schedule === event.cron) {
|
|
45
|
+
console.log(\`[cron] Running "\${name}" (schedule: \${event.cron})\`);
|
|
46
|
+
try {
|
|
47
|
+
await handler();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(\`[cron:\${name}] Error:\`, error);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.warn(\`[cron] No handler found for schedule: \${event.cron}\`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=worker-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-entry.js","sourceRoot":"","sources":["../../../src/cli/deploy/worker-entry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CR,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate wrangler.toml configuration for Cloudflare Workers
|
|
3
|
+
*/
|
|
4
|
+
export interface WranglerConfigOptions {
|
|
5
|
+
projectDir: string;
|
|
6
|
+
accountId?: string | undefined;
|
|
7
|
+
compatibilityDate?: string;
|
|
8
|
+
d1DatabaseId?: string | undefined;
|
|
9
|
+
cronSchedules?: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Generate wrangler.toml content for deployment.
|
|
13
|
+
* Includes D1 binding if database ID is provided.
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateWranglerConfig(options: WranglerConfigOptions): string;
|
|
16
|
+
/**
|
|
17
|
+
* Get the worker name for a project directory.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getWorkerName(projectDir: string): string;
|
|
20
|
+
//# sourceMappingURL=wrangler-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler-config.d.ts","sourceRoot":"","sources":["../../../src/cli/deploy/wrangler-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAYD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,CAgC7E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate wrangler.toml configuration for Cloudflare Workers
|
|
3
|
+
*/
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { basename } from "node:path";
|
|
6
|
+
/**
|
|
7
|
+
* Generate a unique worker name from the project directory.
|
|
8
|
+
* Uses the directory basename plus a short hash for uniqueness.
|
|
9
|
+
*/
|
|
10
|
+
function generateWorkerName(projectDir) {
|
|
11
|
+
const base = basename(projectDir).toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
12
|
+
const hash = createHash("sha256").update(projectDir).digest("hex").slice(0, 6);
|
|
13
|
+
return `clide-${base}-${hash}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generate wrangler.toml content for deployment.
|
|
17
|
+
* Includes D1 binding if database ID is provided.
|
|
18
|
+
*/
|
|
19
|
+
export function generateWranglerConfig(options) {
|
|
20
|
+
const workerName = generateWorkerName(options.projectDir);
|
|
21
|
+
const compatibilityDate = options.compatibilityDate ?? "2024-01-01";
|
|
22
|
+
const accountLine = options.accountId ? `account_id = "${options.accountId}"\n` : "";
|
|
23
|
+
let config = `# CLIde Wrangler Configuration
|
|
24
|
+
# Generated by clide push - do not edit manually
|
|
25
|
+
|
|
26
|
+
name = "${workerName}"
|
|
27
|
+
${accountLine}main = "_worker.ts"
|
|
28
|
+
compatibility_date = "${compatibilityDate}"
|
|
29
|
+
compatibility_flags = ["nodejs_compat"]
|
|
30
|
+
`;
|
|
31
|
+
if (options.d1DatabaseId) {
|
|
32
|
+
config += `
|
|
33
|
+
[[d1_databases]]
|
|
34
|
+
binding = "DB"
|
|
35
|
+
database_name = "${workerName}-db"
|
|
36
|
+
database_id = "${options.d1DatabaseId}"
|
|
37
|
+
`;
|
|
38
|
+
}
|
|
39
|
+
if (options.cronSchedules && options.cronSchedules.length > 0) {
|
|
40
|
+
const schedules = options.cronSchedules.map((s) => `"${s}"`).join(", ");
|
|
41
|
+
config += `
|
|
42
|
+
[triggers]
|
|
43
|
+
crons = [${schedules}]
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
return config;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get the worker name for a project directory.
|
|
50
|
+
*/
|
|
51
|
+
export function getWorkerName(projectDir) {
|
|
52
|
+
return generateWorkerName(projectDir);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=wrangler-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler-config.js","sourceRoot":"","sources":["../../../src/cli/deploy/wrangler-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAUrC;;;GAGG;AACH,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IAC5E,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/E,OAAO,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA8B;IACnE,MAAM,UAAU,GAAG,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC1D,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,IAAI,YAAY,CAAC;IACpE,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,OAAO,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAErF,IAAI,MAAM,GAAG;;;UAGL,UAAU;EAClB,WAAW;wBACW,iBAAiB;;CAExC,CAAC;IAEA,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QACzB,MAAM,IAAI;;;mBAGK,UAAU;iBACZ,OAAO,CAAC,YAAY;CACpC,CAAC;IACA,CAAC;IAED,IAAI,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxE,MAAM,IAAI;;WAEH,SAAS;CACnB,CAAC;IACA,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB;IAC9C,OAAO,kBAAkB,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fling CLI - Command interface for Claude to operate the platform
|
|
4
|
+
*
|
|
5
|
+
* Running `fling` with no arguments launches the default experience:
|
|
6
|
+
* - Inside a Fling project: shows Commander help
|
|
7
|
+
* - Otherwise: shows project selector or create-new flow
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fling CLI - Command interface for Claude to operate the platform
|
|
4
|
+
*
|
|
5
|
+
* Running `fling` with no arguments launches the default experience:
|
|
6
|
+
* - Inside a Fling project: shows Commander help
|
|
7
|
+
* - Otherwise: shows project selector or create-new flow
|
|
8
|
+
*/
|
|
9
|
+
import { Command } from "commander";
|
|
10
|
+
import { initCommand } from "./commands/init.js";
|
|
11
|
+
import { devCommand } from "./commands/dev.js";
|
|
12
|
+
import { dbCommand } from "./commands/db.js";
|
|
13
|
+
import { secretCommand } from "./commands/secret.js";
|
|
14
|
+
import { logsCommand } from "./commands/logs.js";
|
|
15
|
+
import { pushCommand } from "./commands/push.js";
|
|
16
|
+
import { loginCommand } from "./commands/login.js";
|
|
17
|
+
import { logoutCommand } from "./commands/logout.js";
|
|
18
|
+
import { whoamiCommand } from "./commands/whoami.js";
|
|
19
|
+
import { registerCommand } from "./commands/register.js";
|
|
20
|
+
import { onboardCommand } from "./commands/onboard.js";
|
|
21
|
+
import { feedbackCommand } from "./commands/feedback.js";
|
|
22
|
+
import { projectCommand } from "./commands/project.js";
|
|
23
|
+
import { launch } from "./commands/launch.js";
|
|
24
|
+
const program = new Command();
|
|
25
|
+
program
|
|
26
|
+
.name("fling")
|
|
27
|
+
.description("Fling - Build and deploy personal tools to Cloudflare Workers")
|
|
28
|
+
.version("0.0.1")
|
|
29
|
+
.option("--prod", "Target production environment instead of local")
|
|
30
|
+
.addHelpText("after", `
|
|
31
|
+
Environment:
|
|
32
|
+
Most commands operate on local development by default.
|
|
33
|
+
Use --prod to target your deployed production environment.
|
|
34
|
+
|
|
35
|
+
Getting started:
|
|
36
|
+
fling init Create a new project in the current directory
|
|
37
|
+
npm install Install dependencies
|
|
38
|
+
fling dev Start local development server
|
|
39
|
+
fling login Log in to deploy
|
|
40
|
+
fling push Deploy to production
|
|
41
|
+
|
|
42
|
+
Common workflows:
|
|
43
|
+
Development: fling dev
|
|
44
|
+
Deployment: fling push
|
|
45
|
+
View logs: fling logs (local) or fling --prod logs (deployed)
|
|
46
|
+
Run SQL: fling db sql "SELECT * FROM users"
|
|
47
|
+
`);
|
|
48
|
+
program.addCommand(initCommand);
|
|
49
|
+
program.addCommand(devCommand);
|
|
50
|
+
program.addCommand(dbCommand);
|
|
51
|
+
program.addCommand(secretCommand);
|
|
52
|
+
program.addCommand(logsCommand);
|
|
53
|
+
program.addCommand(pushCommand);
|
|
54
|
+
program.addCommand(loginCommand);
|
|
55
|
+
program.addCommand(logoutCommand);
|
|
56
|
+
program.addCommand(registerCommand);
|
|
57
|
+
program.addCommand(onboardCommand);
|
|
58
|
+
program.addCommand(whoamiCommand);
|
|
59
|
+
program.addCommand(feedbackCommand);
|
|
60
|
+
program.addCommand(projectCommand);
|
|
61
|
+
// If no command specified, run the default launch action
|
|
62
|
+
if (process.argv.length === 2) {
|
|
63
|
+
launch(program).catch((error) => {
|
|
64
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
65
|
+
console.error("Error:", message);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
program.parse();
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC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AAC,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAClC,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AACpC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AACnC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAClC,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AACpC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;AAEnC,yDAAyD;AACzD,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC9B,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACvC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform configuration utilities.
|
|
3
|
+
* Stores token and API URL in ~/.fling/ (or FLING_CONFIG_DIR if set)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get the stored API token, or null if not logged in.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getToken(): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Store the API token.
|
|
11
|
+
*/
|
|
12
|
+
export declare function setToken(token: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Remove the stored token.
|
|
15
|
+
*/
|
|
16
|
+
export declare function clearToken(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Check if logged in to the platform.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isLoggedIn(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if the config directory exists (indicates previous setup).
|
|
23
|
+
*/
|
|
24
|
+
export declare function configDirExists(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Get the API URL.
|
|
27
|
+
* Priority: FLING_API_URL env var > ~/.fling/api-url file > default
|
|
28
|
+
*/
|
|
29
|
+
export declare function getApiUrl(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Set the API URL (for development/testing).
|
|
32
|
+
*/
|
|
33
|
+
export declare function setApiUrl(url: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Make an authenticated request to the platform API.
|
|
36
|
+
* Content-Type is NOT set automatically - caller must set it if needed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function platformFetch(path: string, options?: RequestInit): Promise<Response>;
|
|
39
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiCH;;GAEG;AACH,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAKxC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAG5C;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAIjC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAEpC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CASlC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAG3C;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,QAAQ,CAAC,CAcnB"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform configuration utilities.
|
|
3
|
+
* Stores token and API URL in ~/.fling/ (or FLING_CONFIG_DIR if set)
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
/**
|
|
9
|
+
* Get the configuration directory.
|
|
10
|
+
* Uses FLING_CONFIG_DIR environment variable if set, otherwise ~/.fling
|
|
11
|
+
*/
|
|
12
|
+
function getConfigDir() {
|
|
13
|
+
const envDir = process.env["FLING_CONFIG_DIR"];
|
|
14
|
+
if (envDir) {
|
|
15
|
+
return envDir;
|
|
16
|
+
}
|
|
17
|
+
return join(homedir(), ".fling");
|
|
18
|
+
}
|
|
19
|
+
const CONFIG_DIR = getConfigDir();
|
|
20
|
+
const TOKEN_FILE = join(CONFIG_DIR, "token");
|
|
21
|
+
const API_URL_FILE = join(CONFIG_DIR, "api-url");
|
|
22
|
+
const DEFAULT_API_URL = "https://api.justdeployit.dev";
|
|
23
|
+
/**
|
|
24
|
+
* Ensure the config directory exists.
|
|
25
|
+
*/
|
|
26
|
+
function ensureConfigDir() {
|
|
27
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
28
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the stored API token, or null if not logged in.
|
|
33
|
+
*/
|
|
34
|
+
export function getToken() {
|
|
35
|
+
if (!existsSync(TOKEN_FILE)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return readFileSync(TOKEN_FILE, "utf-8").trim();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Store the API token.
|
|
42
|
+
*/
|
|
43
|
+
export function setToken(token) {
|
|
44
|
+
ensureConfigDir();
|
|
45
|
+
writeFileSync(TOKEN_FILE, token, { mode: 0o600 });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Remove the stored token.
|
|
49
|
+
*/
|
|
50
|
+
export function clearToken() {
|
|
51
|
+
if (existsSync(TOKEN_FILE)) {
|
|
52
|
+
unlinkSync(TOKEN_FILE);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Check if logged in to the platform.
|
|
57
|
+
*/
|
|
58
|
+
export function isLoggedIn() {
|
|
59
|
+
return getToken() !== null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if the config directory exists (indicates previous setup).
|
|
63
|
+
*/
|
|
64
|
+
export function configDirExists() {
|
|
65
|
+
return existsSync(CONFIG_DIR);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get the API URL.
|
|
69
|
+
* Priority: FLING_API_URL env var > ~/.fling/api-url file > default
|
|
70
|
+
*/
|
|
71
|
+
export function getApiUrl() {
|
|
72
|
+
const envUrl = process.env["FLING_API_URL"];
|
|
73
|
+
if (envUrl) {
|
|
74
|
+
return envUrl;
|
|
75
|
+
}
|
|
76
|
+
if (existsSync(API_URL_FILE)) {
|
|
77
|
+
return readFileSync(API_URL_FILE, "utf-8").trim();
|
|
78
|
+
}
|
|
79
|
+
return DEFAULT_API_URL;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Set the API URL (for development/testing).
|
|
83
|
+
*/
|
|
84
|
+
export function setApiUrl(url) {
|
|
85
|
+
ensureConfigDir();
|
|
86
|
+
writeFileSync(API_URL_FILE, url);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Make an authenticated request to the platform API.
|
|
90
|
+
* Content-Type is NOT set automatically - caller must set it if needed.
|
|
91
|
+
*/
|
|
92
|
+
export async function platformFetch(path, options = {}) {
|
|
93
|
+
const token = getToken();
|
|
94
|
+
if (!token) {
|
|
95
|
+
throw new Error("Not logged in. Run 'fling login' first.");
|
|
96
|
+
}
|
|
97
|
+
const url = `${getApiUrl()}${path}`;
|
|
98
|
+
const headers = new Headers(options.headers);
|
|
99
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
100
|
+
return fetch(url, {
|
|
101
|
+
...options,
|
|
102
|
+
headers,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/cli/utils/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;GAGG;AACH,SAAS,YAAY;IACnB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC/C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,GAAG,YAAY,EAAE,CAAC;AAClC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAC7C,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AAEjD,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAEvD;;GAEG;AACH,SAAS,eAAe;IACtB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ;IACtB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,QAAQ,EAAE,CAAC;IACzB,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,SAAS,EAAE,GAAG,IAAI,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;IAEhD,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,GAAG,OAAO;QACV,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duration parsing utility
|
|
3
|
+
*
|
|
4
|
+
* Parses human-readable duration strings like "1h", "30m", "2d" into milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parse a duration string into milliseconds
|
|
8
|
+
*
|
|
9
|
+
* @param duration - Duration string (e.g., "1h", "30m", "2d", "1w")
|
|
10
|
+
* @returns Duration in milliseconds
|
|
11
|
+
* @throws Error if format is invalid
|
|
12
|
+
*
|
|
13
|
+
* Supported units:
|
|
14
|
+
* - s: seconds
|
|
15
|
+
* - m: minutes
|
|
16
|
+
* - h: hours
|
|
17
|
+
* - d: days
|
|
18
|
+
* - w: weeks
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseDuration(duration: string): number;
|
|
21
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/duration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAyBtD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duration parsing utility
|
|
3
|
+
*
|
|
4
|
+
* Parses human-readable duration strings like "1h", "30m", "2d" into milliseconds.
|
|
5
|
+
*/
|
|
6
|
+
const MULTIPLIERS = {
|
|
7
|
+
s: 1000,
|
|
8
|
+
m: 60 * 1000,
|
|
9
|
+
h: 60 * 60 * 1000,
|
|
10
|
+
d: 24 * 60 * 60 * 1000,
|
|
11
|
+
w: 7 * 24 * 60 * 60 * 1000,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Parse a duration string into milliseconds
|
|
15
|
+
*
|
|
16
|
+
* @param duration - Duration string (e.g., "1h", "30m", "2d", "1w")
|
|
17
|
+
* @returns Duration in milliseconds
|
|
18
|
+
* @throws Error if format is invalid
|
|
19
|
+
*
|
|
20
|
+
* Supported units:
|
|
21
|
+
* - s: seconds
|
|
22
|
+
* - m: minutes
|
|
23
|
+
* - h: hours
|
|
24
|
+
* - d: days
|
|
25
|
+
* - w: weeks
|
|
26
|
+
*/
|
|
27
|
+
export function parseDuration(duration) {
|
|
28
|
+
const match = duration.match(/^(\d+)(s|m|h|d|w)$/);
|
|
29
|
+
if (!match) {
|
|
30
|
+
throw new Error(`Invalid duration format: "${duration}". Use format like 1h, 30m, 2d, 1w`);
|
|
31
|
+
}
|
|
32
|
+
const valueStr = match[1];
|
|
33
|
+
const unit = match[2];
|
|
34
|
+
if (!valueStr || !unit) {
|
|
35
|
+
throw new Error(`Invalid duration format: "${duration}". Use format like 1h, 30m, 2d, 1w`);
|
|
36
|
+
}
|
|
37
|
+
const value = parseInt(valueStr, 10);
|
|
38
|
+
const multiplier = MULTIPLIERS[unit];
|
|
39
|
+
if (!multiplier) {
|
|
40
|
+
throw new Error(`Unknown duration unit: "${unit}"`);
|
|
41
|
+
}
|
|
42
|
+
return value * multiplier;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../../../src/cli/utils/duration.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,GAA2B;IAC1C,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,EAAE,GAAG,IAAI;IACZ,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACjB,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACtB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;CAC3B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,6BAA6B,QAAQ,oCAAoC,CAC1E,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAEtB,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,6BAA6B,QAAQ,oCAAoC,CAC1E,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAErC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,KAAK,GAAG,UAAU,CAAC;AAC5B,CAAC"}
|