@cancia/astro 0.2.1 → 0.3.0
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-52URFK5Y.js +580 -0
- package/dist/{chunk-7MPOERVU.js → chunk-AIPRCBJM.js} +16 -3
- package/dist/{chunk-ST44VULL.js → chunk-L2VKQJPY.js} +9 -4
- package/dist/chunk-PIDFNJME.js +19 -0
- package/dist/{chunk-337LJIKX.js → chunk-UR5WC3RA.js} +1 -1
- package/dist/endpoints/publish.js +23 -17
- package/dist/git-backed-DFAB0tzf.d.ts +98 -0
- package/dist/index.d.ts +33 -1
- package/dist/index.js +53 -23
- package/dist/loader/index.js +2 -2
- package/dist/runtime.d.ts +17 -0
- package/dist/runtime.js +3 -3
- package/dist/storage/index.d.ts +13 -84
- package/dist/storage/index.js +13 -5
- package/package.json +1 -1
- package/dist/chunk-5ELSN6LI.js +0 -244
|
@@ -1,33 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
firePublish
|
|
3
|
+
} from "../chunk-PIDFNJME.js";
|
|
4
|
+
|
|
1
5
|
// src/endpoints/publish.ts
|
|
2
6
|
import { getCanciaRuntime } from "virtual:cancia/runtime";
|
|
3
7
|
async function POST({ request }) {
|
|
4
|
-
const { deployHook, secret } = getCanciaRuntime();
|
|
8
|
+
const { deployHook, deployHookToken, deployHookMethod, deployHookHeaders, secret } = getCanciaRuntime();
|
|
5
9
|
if (secret) {
|
|
6
10
|
const token = request.headers.get("Authorization")?.replace("Bearer ", "").trim();
|
|
7
11
|
if (token !== secret)
|
|
8
12
|
return new Response(JSON.stringify({ error: "Unauthorized" }), { status: 401 });
|
|
9
13
|
}
|
|
10
14
|
const hook = deployHook ?? process.env.CANCIA_DEPLOY_HOOK;
|
|
11
|
-
|
|
15
|
+
const result = await firePublish(hook, {
|
|
16
|
+
token: deployHookToken,
|
|
17
|
+
method: deployHookMethod,
|
|
18
|
+
headers: deployHookHeaders
|
|
19
|
+
});
|
|
20
|
+
if (result.ok)
|
|
21
|
+
return new Response(JSON.stringify({ ok: true }), {
|
|
22
|
+
headers: { "Content-Type": "application/json" }
|
|
23
|
+
});
|
|
24
|
+
if (result.kind === "no-hook")
|
|
12
25
|
return new Response(
|
|
13
26
|
JSON.stringify({ error: "No deploy hook configured. Set CANCIA_DEPLOY_HOOK." }),
|
|
14
27
|
{ status: 503 }
|
|
15
28
|
);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
headers: { "Content-Type": "application/json" }
|
|
25
|
-
});
|
|
26
|
-
} catch {
|
|
27
|
-
return new Response(JSON.stringify({ error: "Failed to reach deploy hook" }), {
|
|
28
|
-
status: 502
|
|
29
|
-
});
|
|
30
|
-
}
|
|
29
|
+
if (result.kind === "bad-response")
|
|
30
|
+
return new Response(
|
|
31
|
+
JSON.stringify({ error: `Deploy hook responded with ${result.status}` }),
|
|
32
|
+
{ status: 502 }
|
|
33
|
+
);
|
|
34
|
+
return new Response(JSON.stringify({ error: "Failed to reach deploy hook" }), {
|
|
35
|
+
status: 502
|
|
36
|
+
});
|
|
31
37
|
}
|
|
32
38
|
export {
|
|
33
39
|
POST
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { C as CanciaStorage, a as CanciaStorageV2 } from './types-BMlLS-OS.js';
|
|
2
|
+
import { G as GitHubCommitter, a as GitHubClient, F as FetchLike } from './github-client-BAZ1pW24.js';
|
|
3
|
+
|
|
4
|
+
declare function createJsonFileAdapter(filePath?: string): CanciaStorage;
|
|
5
|
+
|
|
6
|
+
interface JsonFileV2Options {
|
|
7
|
+
/** Project root. Defaults to process.cwd(). */
|
|
8
|
+
projectRoot?: string;
|
|
9
|
+
/** Override the KV file path. Defaults to <root>/cancia-content.json. */
|
|
10
|
+
kvPath?: string;
|
|
11
|
+
/** Override the pages file path. Defaults to <root>/.cancia/pages.json. */
|
|
12
|
+
pagesPath?: string;
|
|
13
|
+
/** Override the lists directory. Defaults to <root>/.cancia/lists. */
|
|
14
|
+
listsDir?: string;
|
|
15
|
+
}
|
|
16
|
+
declare function createJsonFileAdapterV2(opts?: JsonFileV2Options): CanciaStorageV2;
|
|
17
|
+
|
|
18
|
+
declare function createSQLiteAdapter(dbPath?: string): CanciaStorage;
|
|
19
|
+
|
|
20
|
+
interface SqliteV2Options {
|
|
21
|
+
/** Absolute path to the .db file. Defaults to <projectRoot>/cancia.db. */
|
|
22
|
+
dbPath?: string;
|
|
23
|
+
/** Project root. Defaults to process.cwd(). Used to derive dbPath. */
|
|
24
|
+
projectRoot?: string;
|
|
25
|
+
}
|
|
26
|
+
declare function createSqliteAdapterV2(opts?: SqliteV2Options): CanciaStorageV2;
|
|
27
|
+
/**
|
|
28
|
+
* Close and forget the cached connection for a db path (or all connections
|
|
29
|
+
* when no path is given). The store interface has no lifecycle hook, so this
|
|
30
|
+
* is the seam for graceful shutdown and for tests that need to release the
|
|
31
|
+
* file handle before deleting the .db (Windows keeps WAL files locked while
|
|
32
|
+
* the connection is open). No-op if the path was never opened.
|
|
33
|
+
*/
|
|
34
|
+
declare function closeSqliteAdapterV2(dbPath?: string): void;
|
|
35
|
+
|
|
36
|
+
interface GitBackedContentPaths {
|
|
37
|
+
/** KV file path. Default <projectRoot>/cancia-content.json. */
|
|
38
|
+
kvPath?: string;
|
|
39
|
+
/** Pages file path. Default <projectRoot>/.cancia/pages.json. */
|
|
40
|
+
pagesPath?: string;
|
|
41
|
+
/** Lists directory. Default <projectRoot>/.cancia/lists. */
|
|
42
|
+
listsDir?: string;
|
|
43
|
+
}
|
|
44
|
+
interface GitBackedOptions {
|
|
45
|
+
/** The wrapped local adapter — the on-disk source of truth. */
|
|
46
|
+
local: CanciaStorageV2;
|
|
47
|
+
/** "owner/name" of the GitHub repo whose builds carry the content. */
|
|
48
|
+
repo: string;
|
|
49
|
+
/** Branch to commit onto. Default "main". */
|
|
50
|
+
branch?: string;
|
|
51
|
+
/**
|
|
52
|
+
* GitHub PAT. Reads CANCIA_GITHUB_TOKEN if omitted. When absent entirely the
|
|
53
|
+
* adapter runs in local-only mode (disk writes only; no commits) + warns once.
|
|
54
|
+
*/
|
|
55
|
+
token?: string;
|
|
56
|
+
/** Optional committer identity for commits. */
|
|
57
|
+
committer?: GitHubCommitter;
|
|
58
|
+
/**
|
|
59
|
+
* Project root the local adapter writes under — needed to turn absolute
|
|
60
|
+
* on-disk paths into repo-relative commit paths. Default process.cwd().
|
|
61
|
+
*/
|
|
62
|
+
projectRoot?: string;
|
|
63
|
+
/** Override where the local adapter's content lives (must match `local`). */
|
|
64
|
+
contentPaths?: GitBackedContentPaths;
|
|
65
|
+
/** Quiet window (ms) before a flush fires. Default 3000. */
|
|
66
|
+
debounceMs?: number;
|
|
67
|
+
/** Commit message for content updates. */
|
|
68
|
+
commitMessage?: string;
|
|
69
|
+
/** Injected GitHub client (tests pass a mock). Overrides token/fetch. */
|
|
70
|
+
client?: GitHubClient;
|
|
71
|
+
/** Injected fetch, forwarded to the default GitHub client. */
|
|
72
|
+
fetch?: FetchLike;
|
|
73
|
+
/** API base override, forwarded to the default GitHub client (tests). */
|
|
74
|
+
apiBase?: string;
|
|
75
|
+
/** Warn sink (tests capture). Default console.warn. */
|
|
76
|
+
warn?: (msg: string) => void;
|
|
77
|
+
/** Error sink for push failures (tests capture). Default console.error. */
|
|
78
|
+
onError?: (msg: string, err: unknown) => void;
|
|
79
|
+
}
|
|
80
|
+
/** The extra control surface the git adapter adds on top of CanciaStorageV2. */
|
|
81
|
+
interface GitBackedControls {
|
|
82
|
+
/**
|
|
83
|
+
* Force any pending dirty files to commit now, bypassing the debounce.
|
|
84
|
+
* Resolves once the flush completes (or rejects if the push failed — the
|
|
85
|
+
* files stay dirty for the next flush). For tests + graceful shutdown.
|
|
86
|
+
*/
|
|
87
|
+
flush(): Promise<void>;
|
|
88
|
+
/** True if git commits are active (token present). */
|
|
89
|
+
readonly gitEnabled: boolean;
|
|
90
|
+
/** Snapshot of currently-dirty repo-relative paths (for tests/inspection). */
|
|
91
|
+
pendingPaths(): string[];
|
|
92
|
+
}
|
|
93
|
+
type GitBackedStorage = CanciaStorageV2 & {
|
|
94
|
+
git: GitBackedControls;
|
|
95
|
+
};
|
|
96
|
+
declare function createGitBackedAdapter(opts: GitBackedOptions): GitBackedStorage;
|
|
97
|
+
|
|
98
|
+
export { type GitBackedContentPaths as G, type SqliteV2Options as S, type GitBackedControls as a, type GitBackedOptions as b, type GitBackedStorage as c, closeSqliteAdapterV2 as d, createGitBackedAdapter as e, createJsonFileAdapter as f, createJsonFileAdapterV2 as g, createSQLiteAdapter as h, createSqliteAdapterV2 as i };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { m as makeLocalUploadHandler } from './upload-DwCGjXbz.js';
|
|
|
6
6
|
import { G as GitHubCommitter } from './github-client-BAZ1pW24.js';
|
|
7
7
|
export { CanciaLoaderOptions, canciaLoader } from './loader/index.js';
|
|
8
8
|
export { FieldDescription, FieldMeta, FieldMetaBase, FieldWidget, ListDescription, ListSchema, SchemasModule, defineField, defineList, describeList } from './schema/index.js';
|
|
9
|
-
export { GitBackedContentPaths, GitBackedControls, GitBackedOptions, GitBackedStorage, createGitBackedAdapter, createJsonFileAdapter, createJsonFileAdapterV2, createSQLiteAdapter } from './
|
|
9
|
+
export { G as GitBackedContentPaths, a as GitBackedControls, b as GitBackedOptions, c as GitBackedStorage, S as SqliteV2Options, d as closeSqliteAdapterV2, e as createGitBackedAdapter, f as createJsonFileAdapter, g as createJsonFileAdapterV2, h as createSQLiteAdapter, i as createSqliteAdapterV2 } from './git-backed-DFAB0tzf.js';
|
|
10
10
|
export { z } from 'zod';
|
|
11
11
|
import 'astro/loaders';
|
|
12
12
|
import './portable-text-BikSqS9T.js';
|
|
@@ -48,6 +48,17 @@ interface CanciaIntegrationOptions {
|
|
|
48
48
|
accentColor?: string;
|
|
49
49
|
/** Deploy hook URL. Reads CANCIA_DEPLOY_HOOK env var if not set. */
|
|
50
50
|
deployHook?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Auth token for the deploy hook (e.g. Coolify's "auth required" hook).
|
|
53
|
+
* When set, the publish POST sends `Authorization: Bearer <token>`.
|
|
54
|
+
* SECRET — prefer the CANCIA_DEPLOY_HOOK_TOKEN env var (read at runtime,
|
|
55
|
+
* never baked into the build). This option is a dev/testing convenience.
|
|
56
|
+
*/
|
|
57
|
+
deployHookToken?: string;
|
|
58
|
+
/** Optional HTTP method for the deploy hook. Default: "POST". */
|
|
59
|
+
deployHookMethod?: string;
|
|
60
|
+
/** Optional extra headers merged into the deploy-hook request. */
|
|
61
|
+
deployHookHeaders?: Record<string, string>;
|
|
51
62
|
/**
|
|
52
63
|
* Custom storage adapter.
|
|
53
64
|
* Default: SQLite (cancia.db in project root) — works anywhere with Node.
|
|
@@ -90,6 +101,27 @@ interface CanciaIntegrationOptions {
|
|
|
90
101
|
* (named or default) — a record of list name → defineList() output.
|
|
91
102
|
*/
|
|
92
103
|
schemasPath?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Declarative v2 storage backend — bakes SERIALISABLY into the runtime
|
|
106
|
+
* descriptor so a fresh production SSR server reconstructs the same adapter
|
|
107
|
+
* from config + `process.cwd()` (no live object crosses the build→deploy
|
|
108
|
+
* boundary). Prefer this over a live `storageV2` object for production.
|
|
109
|
+
*
|
|
110
|
+
* - `{ kind: "sqlite" }` (recommended) — the everything-store: KV + pages +
|
|
111
|
+
* lists in ONE `.db` per site (default `<root>/cancia.db`; override with
|
|
112
|
+
* `path`, relative paths resolve against the project root). Gitignore the
|
|
113
|
+
* `.db` for webhook-publish sites — it is NOT committed (contrast the
|
|
114
|
+
* git-backed model).
|
|
115
|
+
* - `{ kind: "json-file" }` — the JSON-file v2 default (files under
|
|
116
|
+
* `<root>/.cancia/`).
|
|
117
|
+
*
|
|
118
|
+
* Ignored when `git` is set (git-backed wins) or `storageV2` is passed as a
|
|
119
|
+
* live object (dev uses that eagerly).
|
|
120
|
+
*/
|
|
121
|
+
db?: {
|
|
122
|
+
kind: "sqlite" | "json-file";
|
|
123
|
+
path?: string;
|
|
124
|
+
};
|
|
93
125
|
/**
|
|
94
126
|
* Git-backed storage, described SERIALISABLY so a production SSR server can
|
|
95
127
|
* reconstruct the adapter in its own (fresh) process from this config + the
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
firePublish
|
|
3
|
+
} from "./chunk-PIDFNJME.js";
|
|
1
4
|
import {
|
|
2
5
|
makeListsRoutes
|
|
3
6
|
} from "./chunk-22DJVJBR.js";
|
|
@@ -10,7 +13,7 @@ import {
|
|
|
10
13
|
makeR2UploadHandler,
|
|
11
14
|
makeUploadRoute,
|
|
12
15
|
setCanciaRuntime
|
|
13
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-AIPRCBJM.js";
|
|
14
17
|
import {
|
|
15
18
|
defineField,
|
|
16
19
|
defineList,
|
|
@@ -19,17 +22,19 @@ import {
|
|
|
19
22
|
} from "./chunk-MCHQV6Y7.js";
|
|
20
23
|
import {
|
|
21
24
|
canciaLoader
|
|
22
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-UR5WC3RA.js";
|
|
23
26
|
import {
|
|
24
27
|
createSQLiteAdapter
|
|
25
28
|
} from "./chunk-AE4SIY24.js";
|
|
26
29
|
import {
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
closeSqliteAdapterV2,
|
|
31
|
+
createGitBackedAdapter,
|
|
32
|
+
createSqliteAdapterV2
|
|
33
|
+
} from "./chunk-52URFK5Y.js";
|
|
29
34
|
import {
|
|
30
35
|
createJsonFileAdapter,
|
|
31
36
|
createJsonFileAdapterV2
|
|
32
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-L2VKQJPY.js";
|
|
33
38
|
import {
|
|
34
39
|
RevConflictError
|
|
35
40
|
} from "./chunk-7IA5B5CF.js";
|
|
@@ -39,6 +44,7 @@ import "./chunk-5IPHDIC6.js";
|
|
|
39
44
|
// src/integration.ts
|
|
40
45
|
import { loadEnv } from "vite";
|
|
41
46
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
47
|
+
import { isAbsolute, join as join2 } from "path";
|
|
42
48
|
|
|
43
49
|
// src/routes/content.ts
|
|
44
50
|
function makeContentRoute(storage, secret) {
|
|
@@ -87,7 +93,7 @@ function makeContentRoute(storage, secret) {
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
// src/routes/publish.ts
|
|
90
|
-
function makePublishRoute(deployHook, secret) {
|
|
96
|
+
function makePublishRoute(deployHook, secret, hookOptions) {
|
|
91
97
|
return async ({ request }) => {
|
|
92
98
|
if (secret) {
|
|
93
99
|
const token = request.headers.get("Authorization")?.replace("Bearer ", "").trim();
|
|
@@ -96,26 +102,25 @@ function makePublishRoute(deployHook, secret) {
|
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
104
|
const hook = deployHook ?? process.env.CANCIA_DEPLOY_HOOK;
|
|
99
|
-
|
|
105
|
+
const result = await firePublish(hook, hookOptions);
|
|
106
|
+
if (result.ok) {
|
|
107
|
+
return new Response(JSON.stringify({ ok: true }), {
|
|
108
|
+
headers: { "Content-Type": "application/json" }
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (result.kind === "no-hook") {
|
|
100
112
|
return new Response(
|
|
101
113
|
JSON.stringify({ error: "No deploy hook configured. Set CANCIA_DEPLOY_HOOK." }),
|
|
102
114
|
{ status: 503 }
|
|
103
115
|
);
|
|
104
116
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{ status: 502 }
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
return new Response(JSON.stringify({ ok: true }), {
|
|
114
|
-
headers: { "Content-Type": "application/json" }
|
|
115
|
-
});
|
|
116
|
-
} catch {
|
|
117
|
-
return new Response(JSON.stringify({ error: "Failed to reach deploy hook" }), { status: 502 });
|
|
117
|
+
if (result.kind === "bad-response") {
|
|
118
|
+
return new Response(
|
|
119
|
+
JSON.stringify({ error: `Deploy hook responded with ${result.status}` }),
|
|
120
|
+
{ status: 502 }
|
|
121
|
+
);
|
|
118
122
|
}
|
|
123
|
+
return new Response(JSON.stringify({ error: "Failed to reach deploy hook" }), { status: 502 });
|
|
119
124
|
};
|
|
120
125
|
}
|
|
121
126
|
|
|
@@ -205,6 +210,13 @@ CANCIA_TOKEN=${token}
|
|
|
205
210
|
}
|
|
206
211
|
|
|
207
212
|
// src/integration.ts
|
|
213
|
+
function buildDefaultV2Store(opts, projectRoot) {
|
|
214
|
+
if (opts.db?.kind === "sqlite") {
|
|
215
|
+
const path = opts.db.path ? isAbsolute(opts.db.path) ? opts.db.path : join2(projectRoot, opts.db.path) : join2(projectRoot, "cancia.db");
|
|
216
|
+
return createSqliteAdapterV2({ dbPath: path });
|
|
217
|
+
}
|
|
218
|
+
return createJsonFileAdapterV2({ projectRoot });
|
|
219
|
+
}
|
|
208
220
|
function canciaIntegration(opts = {}) {
|
|
209
221
|
let storage;
|
|
210
222
|
let resolvedToken = "";
|
|
@@ -255,6 +267,8 @@ function canciaIntegration(opts = {}) {
|
|
|
255
267
|
};
|
|
256
268
|
} else if (opts.storageV2 === null) {
|
|
257
269
|
storageDescriptor = void 0;
|
|
270
|
+
} else if (opts.db?.kind === "sqlite") {
|
|
271
|
+
storageDescriptor = { kind: "sqlite-v2", dbPath: opts.db.path };
|
|
258
272
|
} else {
|
|
259
273
|
storageDescriptor = { kind: "json-file", dbPath: opts.dbPath };
|
|
260
274
|
}
|
|
@@ -276,6 +290,8 @@ function canciaIntegration(opts = {}) {
|
|
|
276
290
|
maxUploadMB: opts.maxUploadMB ?? 10,
|
|
277
291
|
public: opts.public ?? false,
|
|
278
292
|
hasDeployHook,
|
|
293
|
+
deployHookMethod: opts.deployHookMethod,
|
|
294
|
+
deployHookHeaders: opts.deployHookHeaders,
|
|
279
295
|
storage: storageDescriptor,
|
|
280
296
|
r2: r2Baked
|
|
281
297
|
};
|
|
@@ -335,6 +351,7 @@ function canciaIntegration(opts = {}) {
|
|
|
335
351
|
storage = opts.storage ?? createJsonFileAdapter(opts.dbPath);
|
|
336
352
|
const secret = resolvedToken;
|
|
337
353
|
const deployHook = opts.deployHook ?? process.env.CANCIA_DEPLOY_HOOK;
|
|
354
|
+
const deployHookToken = process.env.CANCIA_DEPLOY_HOOK_TOKEN || opts.deployHookToken;
|
|
338
355
|
let uploadHandler;
|
|
339
356
|
if (opts.r2) {
|
|
340
357
|
const serverEnv = loadEnv(process.env.NODE_ENV ?? "development", resolvedRootPath, "");
|
|
@@ -354,7 +371,7 @@ function canciaIntegration(opts = {}) {
|
|
|
354
371
|
const routeSecret = opts.public ? void 0 : secret || void 0;
|
|
355
372
|
resolvedUploadHandler = uploadHandler;
|
|
356
373
|
resolvedDeployHook = deployHook;
|
|
357
|
-
const storageV2 = opts.storageV2 === null ? void 0 : opts.storageV2 ??
|
|
374
|
+
const storageV2 = opts.storageV2 === null ? void 0 : opts.storageV2 ?? buildDefaultV2Store(opts, resolvedRootPath);
|
|
358
375
|
setCanciaRuntime({
|
|
359
376
|
storage,
|
|
360
377
|
storageV2,
|
|
@@ -365,11 +382,18 @@ function canciaIntegration(opts = {}) {
|
|
|
365
382
|
secret: routeSecret,
|
|
366
383
|
uploadHandler,
|
|
367
384
|
deployHook,
|
|
385
|
+
deployHookToken,
|
|
386
|
+
deployHookMethod: opts.deployHookMethod,
|
|
387
|
+
deployHookHeaders: opts.deployHookHeaders,
|
|
368
388
|
maxUploadMB: opts.maxUploadMB ?? 10
|
|
369
389
|
});
|
|
370
390
|
const contentRoutes = makeContentRoute(storage, routeSecret);
|
|
371
391
|
const uploadRoute = makeUploadRoute(uploadHandler, routeSecret, opts.maxUploadMB);
|
|
372
|
-
const publishRoute = makePublishRoute(deployHook, routeSecret
|
|
392
|
+
const publishRoute = makePublishRoute(deployHook, routeSecret, {
|
|
393
|
+
token: deployHookToken,
|
|
394
|
+
method: opts.deployHookMethod,
|
|
395
|
+
headers: opts.deployHookHeaders
|
|
396
|
+
});
|
|
373
397
|
const authRoute = makeAuthRoute(secret);
|
|
374
398
|
const listsRoutes = makeListsRoutes({
|
|
375
399
|
storageV2,
|
|
@@ -501,7 +525,8 @@ function canciaIntegration(opts = {}) {
|
|
|
501
525
|
uploadHandler = opts.uploadHandler ?? makeLocalUploadHandler({ maxMB: opts.maxUploadMB });
|
|
502
526
|
}
|
|
503
527
|
const deployHook = opts.deployHook ?? process.env.CANCIA_DEPLOY_HOOK;
|
|
504
|
-
const
|
|
528
|
+
const deployHookToken = process.env.CANCIA_DEPLOY_HOOK_TOKEN || opts.deployHookToken;
|
|
529
|
+
const storageV2 = opts.storageV2 === null ? void 0 : opts.storageV2 ?? buildDefaultV2Store(opts, resolvedRootPath);
|
|
505
530
|
setCanciaRuntime({
|
|
506
531
|
storage,
|
|
507
532
|
storageV2,
|
|
@@ -512,6 +537,9 @@ function canciaIntegration(opts = {}) {
|
|
|
512
537
|
secret: routeSecret,
|
|
513
538
|
uploadHandler,
|
|
514
539
|
deployHook,
|
|
540
|
+
deployHookToken,
|
|
541
|
+
deployHookMethod: opts.deployHookMethod,
|
|
542
|
+
deployHookHeaders: opts.deployHookHeaders,
|
|
515
543
|
maxUploadMB: opts.maxUploadMB ?? 10
|
|
516
544
|
});
|
|
517
545
|
}
|
|
@@ -552,10 +580,12 @@ export {
|
|
|
552
580
|
RevConflictError,
|
|
553
581
|
canciaIntegration,
|
|
554
582
|
canciaLoader,
|
|
583
|
+
closeSqliteAdapterV2,
|
|
555
584
|
createGitBackedAdapter,
|
|
556
585
|
createJsonFileAdapter,
|
|
557
586
|
createJsonFileAdapterV2,
|
|
558
587
|
createSQLiteAdapter,
|
|
588
|
+
createSqliteAdapterV2,
|
|
559
589
|
canciaIntegration as default,
|
|
560
590
|
defineField,
|
|
561
591
|
defineList,
|
package/dist/loader/index.js
CHANGED
package/dist/runtime.d.ts
CHANGED
|
@@ -27,12 +27,25 @@ interface CanciaRuntime {
|
|
|
27
27
|
secret: string | undefined;
|
|
28
28
|
uploadHandler: UploadHandler;
|
|
29
29
|
deployHook: string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Auth token for the deploy hook (e.g. Coolify's "auth required" hook).
|
|
32
|
+
* SECRET — read from CANCIA_DEPLOY_HOOK_TOKEN at runtime, never baked. When
|
|
33
|
+
* set the publish POST sends `Authorization: Bearer <token>`.
|
|
34
|
+
*/
|
|
35
|
+
deployHookToken: string | undefined;
|
|
36
|
+
/** Optional HTTP method for the hook (default POST). Non-secret, baked. */
|
|
37
|
+
deployHookMethod: string | undefined;
|
|
38
|
+
/** Optional extra headers merged into the hook request. Non-secret, baked. */
|
|
39
|
+
deployHookHeaders: Record<string, string> | undefined;
|
|
30
40
|
maxUploadMB: number;
|
|
31
41
|
}
|
|
32
42
|
/** Describes which storage adapter to build lazily in the server process. */
|
|
33
43
|
type BakedStorageDescriptor = {
|
|
34
44
|
kind: "json-file";
|
|
35
45
|
dbPath?: string;
|
|
46
|
+
} | {
|
|
47
|
+
kind: "sqlite-v2";
|
|
48
|
+
dbPath?: string;
|
|
36
49
|
} | {
|
|
37
50
|
kind: "git-backed";
|
|
38
51
|
repo: string;
|
|
@@ -58,6 +71,10 @@ interface BakedConfig {
|
|
|
58
71
|
public: boolean;
|
|
59
72
|
/** Whether a deploy hook exists — the value itself is read from env. */
|
|
60
73
|
hasDeployHook: boolean;
|
|
74
|
+
/** Optional deploy-hook HTTP method (default POST). Non-secret. */
|
|
75
|
+
deployHookMethod: string | undefined;
|
|
76
|
+
/** Optional deploy-hook extra headers. Non-secret (the token stays in env). */
|
|
77
|
+
deployHookHeaders: Record<string, string> | undefined;
|
|
61
78
|
/** How to build the v2 storage adapter at runtime. Absent = no v2 storage. */
|
|
62
79
|
storage: BakedStorageDescriptor | undefined;
|
|
63
80
|
/** When set, build an R2 upload handler; secrets come from env at runtime. */
|
package/dist/runtime.js
CHANGED
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
getCanciaRuntime,
|
|
3
3
|
setBakedConfig,
|
|
4
4
|
setCanciaRuntime
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-AIPRCBJM.js";
|
|
6
|
+
import "./chunk-52URFK5Y.js";
|
|
7
|
+
import "./chunk-L2VKQJPY.js";
|
|
8
8
|
import "./chunk-7IA5B5CF.js";
|
|
9
9
|
import "./chunk-5IPHDIC6.js";
|
|
10
10
|
export {
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,84 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as CanciaKVStore, c as CanciaListStore, d as CanciaPageStore, L as ListEntry, P as PageMeta, e as PageRecord, f as PageSEO,
|
|
3
|
-
|
|
4
|
-
export { C as CommitFile, b as GitHubClientOptions, c as createGitHubClient } from '../github-client-BAZ1pW24.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
pagesPath?: string;
|
|
15
|
-
/** Override the lists directory. Defaults to <root>/.cancia/lists. */
|
|
16
|
-
listsDir?: string;
|
|
17
|
-
}
|
|
18
|
-
declare function createJsonFileAdapterV2(opts?: JsonFileV2Options): CanciaStorageV2;
|
|
19
|
-
|
|
20
|
-
declare function createSQLiteAdapter(dbPath?: string): CanciaStorage;
|
|
21
|
-
|
|
22
|
-
interface GitBackedContentPaths {
|
|
23
|
-
/** KV file path. Default <projectRoot>/cancia-content.json. */
|
|
24
|
-
kvPath?: string;
|
|
25
|
-
/** Pages file path. Default <projectRoot>/.cancia/pages.json. */
|
|
26
|
-
pagesPath?: string;
|
|
27
|
-
/** Lists directory. Default <projectRoot>/.cancia/lists. */
|
|
28
|
-
listsDir?: string;
|
|
29
|
-
}
|
|
30
|
-
interface GitBackedOptions {
|
|
31
|
-
/** The wrapped local adapter — the on-disk source of truth. */
|
|
32
|
-
local: CanciaStorageV2;
|
|
33
|
-
/** "owner/name" of the GitHub repo whose builds carry the content. */
|
|
34
|
-
repo: string;
|
|
35
|
-
/** Branch to commit onto. Default "main". */
|
|
36
|
-
branch?: string;
|
|
37
|
-
/**
|
|
38
|
-
* GitHub PAT. Reads CANCIA_GITHUB_TOKEN if omitted. When absent entirely the
|
|
39
|
-
* adapter runs in local-only mode (disk writes only; no commits) + warns once.
|
|
40
|
-
*/
|
|
41
|
-
token?: string;
|
|
42
|
-
/** Optional committer identity for commits. */
|
|
43
|
-
committer?: GitHubCommitter;
|
|
44
|
-
/**
|
|
45
|
-
* Project root the local adapter writes under — needed to turn absolute
|
|
46
|
-
* on-disk paths into repo-relative commit paths. Default process.cwd().
|
|
47
|
-
*/
|
|
48
|
-
projectRoot?: string;
|
|
49
|
-
/** Override where the local adapter's content lives (must match `local`). */
|
|
50
|
-
contentPaths?: GitBackedContentPaths;
|
|
51
|
-
/** Quiet window (ms) before a flush fires. Default 3000. */
|
|
52
|
-
debounceMs?: number;
|
|
53
|
-
/** Commit message for content updates. */
|
|
54
|
-
commitMessage?: string;
|
|
55
|
-
/** Injected GitHub client (tests pass a mock). Overrides token/fetch. */
|
|
56
|
-
client?: GitHubClient;
|
|
57
|
-
/** Injected fetch, forwarded to the default GitHub client. */
|
|
58
|
-
fetch?: FetchLike;
|
|
59
|
-
/** API base override, forwarded to the default GitHub client (tests). */
|
|
60
|
-
apiBase?: string;
|
|
61
|
-
/** Warn sink (tests capture). Default console.warn. */
|
|
62
|
-
warn?: (msg: string) => void;
|
|
63
|
-
/** Error sink for push failures (tests capture). Default console.error. */
|
|
64
|
-
onError?: (msg: string, err: unknown) => void;
|
|
65
|
-
}
|
|
66
|
-
/** The extra control surface the git adapter adds on top of CanciaStorageV2. */
|
|
67
|
-
interface GitBackedControls {
|
|
68
|
-
/**
|
|
69
|
-
* Force any pending dirty files to commit now, bypassing the debounce.
|
|
70
|
-
* Resolves once the flush completes (or rejects if the push failed — the
|
|
71
|
-
* files stay dirty for the next flush). For tests + graceful shutdown.
|
|
72
|
-
*/
|
|
73
|
-
flush(): Promise<void>;
|
|
74
|
-
/** True if git commits are active (token present). */
|
|
75
|
-
readonly gitEnabled: boolean;
|
|
76
|
-
/** Snapshot of currently-dirty repo-relative paths (for tests/inspection). */
|
|
77
|
-
pendingPaths(): string[];
|
|
78
|
-
}
|
|
79
|
-
type GitBackedStorage = CanciaStorageV2 & {
|
|
80
|
-
git: GitBackedControls;
|
|
81
|
-
};
|
|
82
|
-
declare function createGitBackedAdapter(opts: GitBackedOptions): GitBackedStorage;
|
|
83
|
-
|
|
84
|
-
export { CanciaStorage, CanciaStorageV2, type GitBackedContentPaths, type GitBackedControls, type GitBackedOptions, type GitBackedStorage, GitHubClient, GitHubCommitter, createGitBackedAdapter, createJsonFileAdapter, createJsonFileAdapterV2, createSQLiteAdapter };
|
|
1
|
+
import { R as Rev } from '../types-BMlLS-OS.js';
|
|
2
|
+
export { b as CanciaKVStore, c as CanciaListStore, d as CanciaPageStore, C as CanciaStorage, a as CanciaStorageV2, L as ListEntry, P as PageMeta, e as PageRecord, f as PageSEO, g as RevConflictError } from '../types-BMlLS-OS.js';
|
|
3
|
+
export { G as GitBackedContentPaths, a as GitBackedControls, b as GitBackedOptions, c as GitBackedStorage, S as SqliteV2Options, d as closeSqliteAdapterV2, e as createGitBackedAdapter, f as createJsonFileAdapter, g as createJsonFileAdapterV2, h as createSQLiteAdapter, i as createSqliteAdapterV2 } from '../git-backed-DFAB0tzf.js';
|
|
4
|
+
export { C as CommitFile, a as GitHubClient, b as GitHubClientOptions, G as GitHubCommitter, c as createGitHubClient } from '../github-client-BAZ1pW24.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Canonical JSON: keys sorted alphabetically at every level. Two values that
|
|
8
|
+
* are logically equal hash to the same _rev regardless of insertion order.
|
|
9
|
+
*/
|
|
10
|
+
declare function canonicalize(value: unknown): string;
|
|
11
|
+
declare function hashRev(value: unknown): Rev;
|
|
12
|
+
|
|
13
|
+
export { Rev, canonicalize, hashRev };
|
package/dist/storage/index.js
CHANGED
|
@@ -2,21 +2,29 @@ import {
|
|
|
2
2
|
createSQLiteAdapter
|
|
3
3
|
} from "../chunk-AE4SIY24.js";
|
|
4
4
|
import {
|
|
5
|
+
closeSqliteAdapterV2,
|
|
5
6
|
createGitBackedAdapter,
|
|
6
|
-
createGitHubClient
|
|
7
|
-
|
|
7
|
+
createGitHubClient,
|
|
8
|
+
createSqliteAdapterV2
|
|
9
|
+
} from "../chunk-52URFK5Y.js";
|
|
8
10
|
import {
|
|
11
|
+
canonicalize,
|
|
9
12
|
createJsonFileAdapter,
|
|
10
|
-
createJsonFileAdapterV2
|
|
11
|
-
|
|
13
|
+
createJsonFileAdapterV2,
|
|
14
|
+
hashRev
|
|
15
|
+
} from "../chunk-L2VKQJPY.js";
|
|
12
16
|
import {
|
|
13
17
|
RevConflictError
|
|
14
18
|
} from "../chunk-7IA5B5CF.js";
|
|
15
19
|
export {
|
|
16
20
|
RevConflictError,
|
|
21
|
+
canonicalize,
|
|
22
|
+
closeSqliteAdapterV2,
|
|
17
23
|
createGitBackedAdapter,
|
|
18
24
|
createGitHubClient,
|
|
19
25
|
createJsonFileAdapter,
|
|
20
26
|
createJsonFileAdapterV2,
|
|
21
|
-
createSQLiteAdapter
|
|
27
|
+
createSQLiteAdapter,
|
|
28
|
+
createSqliteAdapterV2,
|
|
29
|
+
hashRev
|
|
22
30
|
};
|