scribase 0.1.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/README.md +220 -0
- package/dist/cli/credentials.d.ts +35 -0
- package/dist/cli/credentials.d.ts.map +1 -0
- package/dist/cli/credentials.js +125 -0
- package/dist/cli/credentials.js.map +1 -0
- package/dist/cli/envfile.d.ts +20 -0
- package/dist/cli/envfile.d.ts.map +1 -0
- package/dist/cli/envfile.js +86 -0
- package/dist/cli/envfile.js.map +1 -0
- package/dist/cli/framework.d.ts +45 -0
- package/dist/cli/framework.d.ts.map +1 -0
- package/dist/cli/framework.js +107 -0
- package/dist/cli/framework.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +239 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +118 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +455 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/login.d.ts +104 -0
- package/dist/cli/login.d.ts.map +1 -0
- package/dist/cli/login.js +306 -0
- package/dist/cli/login.js.map +1 -0
- package/dist/cli/pow.d.ts +9 -0
- package/dist/cli/pow.d.ts.map +1 -0
- package/dist/cli/pow.js +31 -0
- package/dist/cli/pow.js.map +1 -0
- package/dist/cli/vercel.d.ts +92 -0
- package/dist/cli/vercel.d.ts.map +1 -0
- package/dist/cli/vercel.js +230 -0
- package/dist/cli/vercel.js.map +1 -0
- package/dist/client.d.ts +137 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +311 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +79 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +139 -0
- package/dist/errors.js.map +1 -0
- package/dist/evidence.d.ts +78 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +36 -0
- package/dist/evidence.js.map +1 -0
- package/dist/idempotency.d.ts +24 -0
- package/dist/idempotency.d.ts.map +1 -0
- package/dist/idempotency.js +59 -0
- package/dist/idempotency.js.map +1 -0
- package/dist/importers/firebase.d.ts +101 -0
- package/dist/importers/firebase.d.ts.map +1 -0
- package/dist/importers/firebase.js +251 -0
- package/dist/importers/firebase.js.map +1 -0
- package/dist/importers/index.d.ts +11 -0
- package/dist/importers/index.d.ts.map +1 -0
- package/dist/importers/index.js +9 -0
- package/dist/importers/index.js.map +1 -0
- package/dist/importers/instantdb.d.ts +76 -0
- package/dist/importers/instantdb.d.ts.map +1 -0
- package/dist/importers/instantdb.js +152 -0
- package/dist/importers/instantdb.js.map +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/pagination.d.ts +33 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +68 -0
- package/dist/pagination.js.map +1 -0
- package/dist/resources/account.d.ts +156 -0
- package/dist/resources/account.d.ts.map +1 -0
- package/dist/resources/account.js +114 -0
- package/dist/resources/account.js.map +1 -0
- package/dist/resources/audit.d.ts +26 -0
- package/dist/resources/audit.d.ts.map +1 -0
- package/dist/resources/audit.js +43 -0
- package/dist/resources/audit.js.map +1 -0
- package/dist/resources/auth.d.ts +149 -0
- package/dist/resources/auth.d.ts.map +1 -0
- package/dist/resources/auth.js +70 -0
- package/dist/resources/auth.js.map +1 -0
- package/dist/resources/backups.d.ts +117 -0
- package/dist/resources/backups.d.ts.map +1 -0
- package/dist/resources/backups.js +92 -0
- package/dist/resources/backups.js.map +1 -0
- package/dist/resources/branches.d.ts +151 -0
- package/dist/resources/branches.d.ts.map +1 -0
- package/dist/resources/branches.js +62 -0
- package/dist/resources/branches.js.map +1 -0
- package/dist/resources/database.d.ts +107 -0
- package/dist/resources/database.d.ts.map +1 -0
- package/dist/resources/database.js +54 -0
- package/dist/resources/database.js.map +1 -0
- package/dist/resources/environments.d.ts +106 -0
- package/dist/resources/environments.d.ts.map +1 -0
- package/dist/resources/environments.js +131 -0
- package/dist/resources/environments.js.map +1 -0
- package/dist/resources/export.d.ts +101 -0
- package/dist/resources/export.d.ts.map +1 -0
- package/dist/resources/export.js +89 -0
- package/dist/resources/export.js.map +1 -0
- package/dist/resources/functions.d.ts +75 -0
- package/dist/resources/functions.d.ts.map +1 -0
- package/dist/resources/functions.js +58 -0
- package/dist/resources/functions.js.map +1 -0
- package/dist/resources/imports.d.ts +183 -0
- package/dist/resources/imports.d.ts.map +1 -0
- package/dist/resources/imports.js +168 -0
- package/dist/resources/imports.js.map +1 -0
- package/dist/resources/insights.d.ts +50 -0
- package/dist/resources/insights.d.ts.map +1 -0
- package/dist/resources/insights.js +21 -0
- package/dist/resources/insights.js.map +1 -0
- package/dist/resources/metrics.d.ts +61 -0
- package/dist/resources/metrics.d.ts.map +1 -0
- package/dist/resources/metrics.js +23 -0
- package/dist/resources/metrics.js.map +1 -0
- package/dist/resources/migrations.d.ts +24 -0
- package/dist/resources/migrations.d.ts.map +1 -0
- package/dist/resources/migrations.js +29 -0
- package/dist/resources/migrations.js.map +1 -0
- package/dist/resources/operations.d.ts +37 -0
- package/dist/resources/operations.d.ts.map +1 -0
- package/dist/resources/operations.js +81 -0
- package/dist/resources/operations.js.map +1 -0
- package/dist/resources/organizations.d.ts +171 -0
- package/dist/resources/organizations.d.ts.map +1 -0
- package/dist/resources/organizations.js +180 -0
- package/dist/resources/organizations.js.map +1 -0
- package/dist/resources/previews.d.ts +49 -0
- package/dist/resources/previews.d.ts.map +1 -0
- package/dist/resources/previews.js +62 -0
- package/dist/resources/previews.js.map +1 -0
- package/dist/resources/projects.d.ts +73 -0
- package/dist/resources/projects.d.ts.map +1 -0
- package/dist/resources/projects.js +84 -0
- package/dist/resources/projects.js.map +1 -0
- package/dist/resources/queues.d.ts +100 -0
- package/dist/resources/queues.d.ts.map +1 -0
- package/dist/resources/queues.js +77 -0
- package/dist/resources/queues.js.map +1 -0
- package/dist/resources/realtime.d.ts +37 -0
- package/dist/resources/realtime.d.ts.map +1 -0
- package/dist/resources/realtime.js +23 -0
- package/dist/resources/realtime.js.map +1 -0
- package/dist/resources/restores.d.ts +67 -0
- package/dist/resources/restores.d.ts.map +1 -0
- package/dist/resources/restores.js +90 -0
- package/dist/resources/restores.js.map +1 -0
- package/dist/resources/storage.d.ts +50 -0
- package/dist/resources/storage.d.ts.map +1 -0
- package/dist/resources/storage.js +38 -0
- package/dist/resources/storage.js.map +1 -0
- package/dist/resources/usage.d.ts +85 -0
- package/dist/resources/usage.d.ts.map +1 -0
- package/dist/resources/usage.js +37 -0
- package/dist/resources/usage.js.map +1 -0
- package/dist/types.gen.d.ts +473 -0
- package/dist/types.gen.d.ts.map +1 -0
- package/dist/types.gen.js +8 -0
- package/dist/types.gen.js.map +1 -0
- package/package.json +53 -0
package/dist/evidence.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification evidence — the shared trust model behind the product's two
|
|
3
|
+
* money surfaces: the restore-evidence viewer and the export/import report.
|
|
4
|
+
*
|
|
5
|
+
* "Verified restore" and "runnable export" are only worth anything if the
|
|
6
|
+
* client can render *proof*: row counts that match, checksums that match,
|
|
7
|
+
* every RLS policy accounted for, and a real login that succeeded. These types
|
|
8
|
+
* carry that proof to the console verbatim; they are intentionally rich so the
|
|
9
|
+
* UI never has to guess what passed and what needs a human.
|
|
10
|
+
*
|
|
11
|
+
* These planned surfaces are not yet in `openapi.yaml`; they follow BUILDOUT
|
|
12
|
+
* §9 and ROADMAP §3-4 and mirror the contract's naming (epoch-second integers,
|
|
13
|
+
* portable identifiers, additive-only optional fields).
|
|
14
|
+
*/
|
|
15
|
+
/** True only when the summary is fully verified with no failed check. */
|
|
16
|
+
export function isFullyVerified(summary) {
|
|
17
|
+
return (summary.state === 'verified' &&
|
|
18
|
+
summary.checks.every((check) => check.status !== 'failed') &&
|
|
19
|
+
summary.row_counts.every((diff) => diff.matched) &&
|
|
20
|
+
summary.checksums.every((match) => match.matched) &&
|
|
21
|
+
summary.policy_parity.every((parity) => parity.matched) &&
|
|
22
|
+
summary.login_proof.every((proof) => proof.succeeded));
|
|
23
|
+
}
|
|
24
|
+
/** Count checks by status for a compact headline in the evidence viewer. */
|
|
25
|
+
export function summarizeChecks(summary) {
|
|
26
|
+
const tally = {
|
|
27
|
+
passed: 0,
|
|
28
|
+
failed: 0,
|
|
29
|
+
skipped: 0,
|
|
30
|
+
};
|
|
31
|
+
for (const check of summary.checks) {
|
|
32
|
+
tally[check.status] += 1;
|
|
33
|
+
}
|
|
34
|
+
return tally;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=evidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence.js","sourceRoot":"","sources":["../src/evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAqEH,yEAAyE;AACzE,MAAM,UAAU,eAAe,CAAC,OAA4B;IAC1D,OAAO,CACL,OAAO,CAAC,KAAK,KAAK,UAAU;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC;QAC1D,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;QAChD,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;QACjD,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC;QACvD,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CACtD,CAAC;AACJ,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,eAAe,CAC7B,OAA4B;IAE5B,MAAM,KAAK,GAA4C;QACrD,MAAM,EAAE,CAAC;QACT,MAAM,EAAE,CAAC;QACT,OAAO,EAAE,CAAC;KACX,CAAC;IACF,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotency keys. Every mutating /v1 endpoint requires an `Idempotency-Key`
|
|
3
|
+
* header (1..128 chars) so a retried request replays the first outcome instead
|
|
4
|
+
* of duplicating work. The client mints one automatically when a caller does
|
|
5
|
+
* not supply their own; agents are encouraged to pass a stable, meaningful key
|
|
6
|
+
* (e.g. derived from a plan step) so a re-run is a no-op.
|
|
7
|
+
*/
|
|
8
|
+
/** Contract bound from `parameters.IdempotencyKey`. */
|
|
9
|
+
export declare const MAX_IDEMPOTENCY_KEY_LENGTH = 128;
|
|
10
|
+
export declare const MIN_IDEMPOTENCY_KEY_LENGTH = 1;
|
|
11
|
+
/**
|
|
12
|
+
* Generate a fresh RFC 4122 v4 idempotency key. Uses the platform
|
|
13
|
+
* `crypto.randomUUID` (Node >= 22 and every modern runtime expose it globally),
|
|
14
|
+
* falling back to `crypto.getRandomValues` if a host stubs the former out.
|
|
15
|
+
*/
|
|
16
|
+
export declare function newIdempotencyKey(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Validate a caller-supplied key against the contract bounds. Returns the key
|
|
19
|
+
* unchanged so it can be used inline; throws {@link RangeError} otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export declare function assertIdempotencyKey(key: string): string;
|
|
22
|
+
/** Resolve an effective key: validate an explicit one, or mint a new one. */
|
|
23
|
+
export declare function resolveIdempotencyKey(explicit?: string): string;
|
|
24
|
+
//# sourceMappingURL=idempotency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idempotency.d.ts","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,uDAAuD;AACvD,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAW1C;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUxD;AAED,6EAA6E;AAC7E,wBAAgB,qBAAqB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAI/D"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotency keys. Every mutating /v1 endpoint requires an `Idempotency-Key`
|
|
3
|
+
* header (1..128 chars) so a retried request replays the first outcome instead
|
|
4
|
+
* of duplicating work. The client mints one automatically when a caller does
|
|
5
|
+
* not supply their own; agents are encouraged to pass a stable, meaningful key
|
|
6
|
+
* (e.g. derived from a plan step) so a re-run is a no-op.
|
|
7
|
+
*/
|
|
8
|
+
/** Contract bound from `parameters.IdempotencyKey`. */
|
|
9
|
+
export const MAX_IDEMPOTENCY_KEY_LENGTH = 128;
|
|
10
|
+
export const MIN_IDEMPOTENCY_KEY_LENGTH = 1;
|
|
11
|
+
/**
|
|
12
|
+
* Generate a fresh RFC 4122 v4 idempotency key. Uses the platform
|
|
13
|
+
* `crypto.randomUUID` (Node >= 22 and every modern runtime expose it globally),
|
|
14
|
+
* falling back to `crypto.getRandomValues` if a host stubs the former out.
|
|
15
|
+
*/
|
|
16
|
+
export function newIdempotencyKey() {
|
|
17
|
+
const c = globalThis.crypto;
|
|
18
|
+
if (c && typeof c.randomUUID === 'function') {
|
|
19
|
+
return c.randomUUID();
|
|
20
|
+
}
|
|
21
|
+
if (c && typeof c.getRandomValues === 'function') {
|
|
22
|
+
return uuidFromRandomBytes(c);
|
|
23
|
+
}
|
|
24
|
+
throw new Error('no Web Crypto available to generate an idempotency key; pass an explicit `idempotencyKey`');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validate a caller-supplied key against the contract bounds. Returns the key
|
|
28
|
+
* unchanged so it can be used inline; throws {@link RangeError} otherwise.
|
|
29
|
+
*/
|
|
30
|
+
export function assertIdempotencyKey(key) {
|
|
31
|
+
if (key.length < MIN_IDEMPOTENCY_KEY_LENGTH ||
|
|
32
|
+
key.length > MAX_IDEMPOTENCY_KEY_LENGTH) {
|
|
33
|
+
throw new RangeError(`idempotency key must be ${MIN_IDEMPOTENCY_KEY_LENGTH}..${MAX_IDEMPOTENCY_KEY_LENGTH} characters, got ${key.length}`);
|
|
34
|
+
}
|
|
35
|
+
return key;
|
|
36
|
+
}
|
|
37
|
+
/** Resolve an effective key: validate an explicit one, or mint a new one. */
|
|
38
|
+
export function resolveIdempotencyKey(explicit) {
|
|
39
|
+
return explicit === undefined
|
|
40
|
+
? newIdempotencyKey()
|
|
41
|
+
: assertIdempotencyKey(explicit);
|
|
42
|
+
}
|
|
43
|
+
function uuidFromRandomBytes(c) {
|
|
44
|
+
const bytes = new Uint8Array(16);
|
|
45
|
+
c.getRandomValues(bytes);
|
|
46
|
+
// Set version (4) and variant (10xx) bits per RFC 4122 §4.4.
|
|
47
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
48
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
49
|
+
const hex = [];
|
|
50
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
51
|
+
hex.push(bytes[i].toString(16).padStart(2, '0'));
|
|
52
|
+
}
|
|
53
|
+
return (`${hex[0]}${hex[1]}${hex[2]}${hex[3]}-` +
|
|
54
|
+
`${hex[4]}${hex[5]}-` +
|
|
55
|
+
`${hex[6]}${hex[7]}-` +
|
|
56
|
+
`${hex[8]}${hex[9]}-` +
|
|
57
|
+
`${hex[10]}${hex[11]}${hex[12]}${hex[13]}${hex[14]}${hex[15]}`);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=idempotency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,uDAAuD;AACvD,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,CAAC,GAAuB,UAAU,CAAC,MAAM,CAAC;IAChD,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC5C,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;IACxB,CAAC;IACD,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;QACjD,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IACD,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,IACE,GAAG,CAAC,MAAM,GAAG,0BAA0B;QACvC,GAAG,CAAC,MAAM,GAAG,0BAA0B,EACvC,CAAC;QACD,MAAM,IAAI,UAAU,CAClB,2BAA2B,0BAA0B,KAAK,0BAA0B,oBAAoB,GAAG,CAAC,MAAM,EAAE,CACrH,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,qBAAqB,CAAC,QAAiB;IACrD,OAAO,QAAQ,KAAK,SAAS;QAC3B,CAAC,CAAC,iBAAiB,EAAE;QACrB,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,mBAAmB,CAAC,CAAS;IACpC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EA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out `POST /v1/imports` reads
|
|
3
|
+
* with `source: 'firebase'`:
|
|
4
|
+
*
|
|
5
|
+
* ```text
|
|
6
|
+
* <dir>/firestore.ndjson one Firestore REST Document per line
|
|
7
|
+
* <dir>/auth.json copy of `firebase auth:export auth.json --format=JSON`
|
|
8
|
+
* <dir>/hash-config.json the console's password hash parameters (optional)
|
|
9
|
+
* <dir>/storage/<bucket>/… every Cloud Storage object
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Only Google's public REST APIs are used (Firestore v1, Cloud Storage JSON v1,
|
|
13
|
+
* OAuth 2.0 JWT bearer), with the runtime's `fetch` and WebCrypto — no Google
|
|
14
|
+
* SDK dependency. Auth users are exported with the Firebase CLI because their
|
|
15
|
+
* password hashes are only available through it.
|
|
16
|
+
*/
|
|
17
|
+
/** The fields of a Google service-account key file this module uses. */
|
|
18
|
+
export interface GoogleServiceAccount {
|
|
19
|
+
client_email: string;
|
|
20
|
+
private_key: string;
|
|
21
|
+
token_uri?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface FirebaseAccess {
|
|
24
|
+
/** Firebase / Google Cloud project id. */
|
|
25
|
+
projectId: string;
|
|
26
|
+
/** A service-account key with Firestore and Storage read access. */
|
|
27
|
+
serviceAccount?: GoogleServiceAccount;
|
|
28
|
+
/** Or a ready OAuth access token, e.g. from `gcloud auth print-access-token`. */
|
|
29
|
+
accessToken?: string;
|
|
30
|
+
/** Firestore database id. Defaults to `(default)`. */
|
|
31
|
+
databaseId?: string;
|
|
32
|
+
/** Injected for tests; defaults to the global `fetch`. */
|
|
33
|
+
fetch?: typeof fetch;
|
|
34
|
+
}
|
|
35
|
+
/** One Firestore REST `Document`, exactly as the API returns it. */
|
|
36
|
+
export interface FirestoreDocument {
|
|
37
|
+
name: string;
|
|
38
|
+
fields?: Record<string, unknown>;
|
|
39
|
+
createTime?: string;
|
|
40
|
+
updateTime?: string;
|
|
41
|
+
}
|
|
42
|
+
/** A failure talking to a Google API. The message never includes tokens or keys. */
|
|
43
|
+
export declare class FirebaseExportError extends Error {
|
|
44
|
+
readonly status: number;
|
|
45
|
+
constructor(message: string, status?: number);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Exchanges a service-account key for an OAuth access token (RFC 7523 JWT
|
|
49
|
+
* bearer grant), signing the assertion with WebCrypto RS256.
|
|
50
|
+
*/
|
|
51
|
+
export declare function googleAccessToken(account: GoogleServiceAccount, fetchImpl?: typeof fetch): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Streams every Firestore document — every collection and every nested
|
|
54
|
+
* subcollection — in the REST `Document` shape the importer reads.
|
|
55
|
+
*/
|
|
56
|
+
export declare function exportFirestoreDocuments(access: FirebaseAccess): AsyncGenerator<FirestoreDocument>;
|
|
57
|
+
/** One Cloud Storage object's metadata. */
|
|
58
|
+
export interface StorageObjectInfo {
|
|
59
|
+
name: string;
|
|
60
|
+
size: number;
|
|
61
|
+
contentType?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Lists every object in a Cloud Storage bucket. */
|
|
64
|
+
export declare function listStorageObjects(access: FirebaseAccess, bucket: string): Promise<StorageObjectInfo[]>;
|
|
65
|
+
export interface WriteFirebaseExportOptions extends FirebaseAccess {
|
|
66
|
+
/** Destination folder; created if missing. */
|
|
67
|
+
directory: string;
|
|
68
|
+
/** Path to the file written by `firebase auth:export auth.json --format=JSON`. */
|
|
69
|
+
authExportPath?: string;
|
|
70
|
+
/** The console's password hash parameters, written to hash-config.json. */
|
|
71
|
+
hashConfig?: {
|
|
72
|
+
base64_signer_key: string;
|
|
73
|
+
base64_salt_separator: string;
|
|
74
|
+
rounds: number;
|
|
75
|
+
mem_cost: number;
|
|
76
|
+
};
|
|
77
|
+
/** Buckets to copy, e.g. `my-app.appspot.com` or `my-app.firebasestorage.app`. */
|
|
78
|
+
buckets?: string[];
|
|
79
|
+
/** Progress callback. */
|
|
80
|
+
onProgress?: (event: {
|
|
81
|
+
phase: 'firestore' | 'storage';
|
|
82
|
+
count: number;
|
|
83
|
+
detail?: string;
|
|
84
|
+
}) => void;
|
|
85
|
+
}
|
|
86
|
+
/** Summary of what {@link writeFirebaseExport} wrote. */
|
|
87
|
+
export interface FirebaseExportSummary {
|
|
88
|
+
directory: string;
|
|
89
|
+
documents: number;
|
|
90
|
+
objects: number;
|
|
91
|
+
bytes: number;
|
|
92
|
+
auth: boolean;
|
|
93
|
+
hashConfig: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Writes a complete Firebase export folder (Node only). Place the folder in the
|
|
97
|
+
* control plane's `SCRIBASE_IMPORT_EXPORTS_DIR`, then import it with
|
|
98
|
+
* `scribase.imports.createFrom({ source: 'firebase', sourceExportDir: '<folder>', … })`.
|
|
99
|
+
*/
|
|
100
|
+
export declare function writeFirebaseExport(options: WriteFirebaseExportOptions): Promise<FirebaseExportSummary>;
|
|
101
|
+
//# sourceMappingURL=firebase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase.d.ts","sourceRoot":"","sources":["../../src/importers/firebase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAWH,wEAAwE;AACxE,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,oEAAoE;AACpE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE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AS,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAClG;AAED,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;CACrB;AAYD;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAqEhC"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Export a Firebase project into the folder layout `POST /v1/imports` reads
|
|
3
|
+
* with `source: 'firebase'`:
|
|
4
|
+
*
|
|
5
|
+
* ```text
|
|
6
|
+
* <dir>/firestore.ndjson one Firestore REST Document per line
|
|
7
|
+
* <dir>/auth.json copy of `firebase auth:export auth.json --format=JSON`
|
|
8
|
+
* <dir>/hash-config.json the console's password hash parameters (optional)
|
|
9
|
+
* <dir>/storage/<bucket>/… every Cloud Storage object
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Only Google's public REST APIs are used (Firestore v1, Cloud Storage JSON v1,
|
|
13
|
+
* OAuth 2.0 JWT bearer), with the runtime's `fetch` and WebCrypto — no Google
|
|
14
|
+
* SDK dependency. Auth users are exported with the Firebase CLI because their
|
|
15
|
+
* password hashes are only available through it.
|
|
16
|
+
*/
|
|
17
|
+
const FIRESTORE_API = 'https://firestore.googleapis.com/v1';
|
|
18
|
+
const STORAGE_API = 'https://storage.googleapis.com/storage/v1';
|
|
19
|
+
const DEFAULT_TOKEN_URI = 'https://oauth2.googleapis.com/token';
|
|
20
|
+
const SCOPES = [
|
|
21
|
+
'https://www.googleapis.com/auth/datastore',
|
|
22
|
+
'https://www.googleapis.com/auth/devstorage.read_only',
|
|
23
|
+
].join(' ');
|
|
24
|
+
const PAGE_SIZE = 300;
|
|
25
|
+
/** A failure talking to a Google API. The message never includes tokens or keys. */
|
|
26
|
+
export class FirebaseExportError extends Error {
|
|
27
|
+
status;
|
|
28
|
+
constructor(message, status = 0) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = 'FirebaseExportError';
|
|
31
|
+
this.status = status;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function base64Url(bytes) {
|
|
35
|
+
const buffer = typeof bytes === 'string' ? new TextEncoder().encode(bytes) : bytes;
|
|
36
|
+
let binary = '';
|
|
37
|
+
for (const byte of buffer) {
|
|
38
|
+
binary += String.fromCharCode(byte);
|
|
39
|
+
}
|
|
40
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
41
|
+
}
|
|
42
|
+
function pemToDer(pem) {
|
|
43
|
+
const body = pem
|
|
44
|
+
.replace(/-----BEGIN [^-]+-----/, '')
|
|
45
|
+
.replace(/-----END [^-]+-----/, '')
|
|
46
|
+
.replace(/\\n/g, '')
|
|
47
|
+
.replace(/\s+/g, '');
|
|
48
|
+
const binary = atob(body);
|
|
49
|
+
const bytes = new Uint8Array(binary.length);
|
|
50
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
51
|
+
bytes[index] = binary.charCodeAt(index);
|
|
52
|
+
}
|
|
53
|
+
return bytes.buffer;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Exchanges a service-account key for an OAuth access token (RFC 7523 JWT
|
|
57
|
+
* bearer grant), signing the assertion with WebCrypto RS256.
|
|
58
|
+
*/
|
|
59
|
+
export async function googleAccessToken(account, fetchImpl = fetch) {
|
|
60
|
+
if (!account.client_email || !account.private_key) {
|
|
61
|
+
throw new FirebaseExportError('the service account needs client_email and private_key');
|
|
62
|
+
}
|
|
63
|
+
const tokenUri = account.token_uri ?? DEFAULT_TOKEN_URI;
|
|
64
|
+
const now = Math.floor(Date.now() / 1000);
|
|
65
|
+
const header = base64Url(JSON.stringify({ alg: 'RS256', typ: 'JWT' }));
|
|
66
|
+
const claims = base64Url(JSON.stringify({ iss: account.client_email, scope: SCOPES, aud: tokenUri, iat: now, exp: now + 3600 }));
|
|
67
|
+
const key = await crypto.subtle.importKey('pkcs8', pemToDer(account.private_key), { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, false, ['sign']);
|
|
68
|
+
const signature = new Uint8Array(await crypto.subtle.sign('RSASSA-PKCS1-v1_5', key, new TextEncoder().encode(`${header}.${claims}`)));
|
|
69
|
+
const response = await fetchImpl(tokenUri, {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
72
|
+
body: new URLSearchParams({
|
|
73
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
74
|
+
assertion: `${header}.${claims}.${base64Url(signature)}`,
|
|
75
|
+
}).toString(),
|
|
76
|
+
});
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
throw new FirebaseExportError('Google rejected the service-account token request', response.status);
|
|
79
|
+
}
|
|
80
|
+
const body = (await response.json());
|
|
81
|
+
if (!body.access_token) {
|
|
82
|
+
throw new FirebaseExportError('Google returned no access token');
|
|
83
|
+
}
|
|
84
|
+
return body.access_token;
|
|
85
|
+
}
|
|
86
|
+
async function resolveToken(access, fetchImpl) {
|
|
87
|
+
if (access.accessToken) {
|
|
88
|
+
return access.accessToken;
|
|
89
|
+
}
|
|
90
|
+
if (access.serviceAccount) {
|
|
91
|
+
return googleAccessToken(access.serviceAccount, fetchImpl);
|
|
92
|
+
}
|
|
93
|
+
throw new FirebaseExportError('provide serviceAccount or accessToken');
|
|
94
|
+
}
|
|
95
|
+
async function googleJson(fetchImpl, token, url, init = {}) {
|
|
96
|
+
const response = await fetchImpl(url, {
|
|
97
|
+
method: init.method ?? 'GET',
|
|
98
|
+
headers: {
|
|
99
|
+
authorization: `Bearer ${token}`,
|
|
100
|
+
...(init.body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
101
|
+
},
|
|
102
|
+
...(init.body !== undefined ? { body: JSON.stringify(init.body) } : {}),
|
|
103
|
+
});
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
throw new FirebaseExportError(`Google API request failed (${response.status}) for ${new URL(url).pathname}`, response.status);
|
|
106
|
+
}
|
|
107
|
+
return (await response.json());
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Streams every Firestore document — every collection and every nested
|
|
111
|
+
* subcollection — in the REST `Document` shape the importer reads.
|
|
112
|
+
*/
|
|
113
|
+
export async function* exportFirestoreDocuments(access) {
|
|
114
|
+
const fetchImpl = access.fetch ?? fetch;
|
|
115
|
+
const token = await resolveToken(access, fetchImpl);
|
|
116
|
+
const database = encodeURIComponent(access.databaseId ?? '(default)');
|
|
117
|
+
const root = `projects/${encodeURIComponent(access.projectId)}/databases/${database}/documents`;
|
|
118
|
+
const listCollectionIds = async (parent) => {
|
|
119
|
+
const ids = [];
|
|
120
|
+
let pageToken;
|
|
121
|
+
do {
|
|
122
|
+
const page = await googleJson(fetchImpl, token, `${FIRESTORE_API}/${parent}:listCollectionIds`, { method: 'POST', body: { pageSize: PAGE_SIZE, ...(pageToken ? { pageToken } : {}) } });
|
|
123
|
+
ids.push(...(page.collectionIds ?? []));
|
|
124
|
+
pageToken = page.nextPageToken;
|
|
125
|
+
} while (pageToken);
|
|
126
|
+
return ids;
|
|
127
|
+
};
|
|
128
|
+
// Depth-first over (parent document path, collection id). `showMissing`
|
|
129
|
+
// surfaces documents that exist only as parents of subcollections; they are
|
|
130
|
+
// walked but not emitted, because they have no fields of their own.
|
|
131
|
+
const pending = (await listCollectionIds(root)).map((id) => `${root}/${encodeURIComponent(id)}`);
|
|
132
|
+
while (pending.length > 0) {
|
|
133
|
+
const collection = pending.pop();
|
|
134
|
+
let pageToken;
|
|
135
|
+
do {
|
|
136
|
+
const query = new URLSearchParams({ pageSize: String(PAGE_SIZE), showMissing: 'true' });
|
|
137
|
+
if (pageToken) {
|
|
138
|
+
query.set('pageToken', pageToken);
|
|
139
|
+
}
|
|
140
|
+
const page = await googleJson(fetchImpl, token, `${FIRESTORE_API}/${collection}?${query.toString()}`);
|
|
141
|
+
for (const document of page.documents ?? []) {
|
|
142
|
+
if (document.createTime) {
|
|
143
|
+
yield document;
|
|
144
|
+
}
|
|
145
|
+
for (const child of await listCollectionIds(document.name)) {
|
|
146
|
+
pending.push(`${document.name}/${encodeURIComponent(child)}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
pageToken = page.nextPageToken;
|
|
150
|
+
} while (pageToken);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Lists every object in a Cloud Storage bucket. */
|
|
154
|
+
export async function listStorageObjects(access, bucket) {
|
|
155
|
+
const fetchImpl = access.fetch ?? fetch;
|
|
156
|
+
const token = await resolveToken(access, fetchImpl);
|
|
157
|
+
const objects = [];
|
|
158
|
+
let pageToken;
|
|
159
|
+
do {
|
|
160
|
+
const query = new URLSearchParams({ maxResults: '1000', fields: 'items(name,size,contentType),nextPageToken' });
|
|
161
|
+
if (pageToken) {
|
|
162
|
+
query.set('pageToken', pageToken);
|
|
163
|
+
}
|
|
164
|
+
const page = await googleJson(fetchImpl, token, `${STORAGE_API}/b/${encodeURIComponent(bucket)}/o?${query.toString()}`);
|
|
165
|
+
for (const item of page.items ?? []) {
|
|
166
|
+
if (item.name.endsWith('/')) {
|
|
167
|
+
continue; // folder placeholder objects hold no data
|
|
168
|
+
}
|
|
169
|
+
objects.push({
|
|
170
|
+
name: item.name,
|
|
171
|
+
size: Number(item.size),
|
|
172
|
+
...(item.contentType ? { contentType: item.contentType } : {}),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
pageToken = page.nextPageToken;
|
|
176
|
+
} while (pageToken);
|
|
177
|
+
return objects;
|
|
178
|
+
}
|
|
179
|
+
function safeObjectPath(name) {
|
|
180
|
+
return (name.length > 0 &&
|
|
181
|
+
!name.startsWith('/') &&
|
|
182
|
+
!name.includes('\\') &&
|
|
183
|
+
!name.includes('\0') &&
|
|
184
|
+
name.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..'));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Writes a complete Firebase export folder (Node only). Place the folder in the
|
|
188
|
+
* control plane's `SCRIBASE_IMPORT_EXPORTS_DIR`, then import it with
|
|
189
|
+
* `scribase.imports.createFrom({ source: 'firebase', sourceExportDir: '<folder>', … })`.
|
|
190
|
+
*/
|
|
191
|
+
export async function writeFirebaseExport(options) {
|
|
192
|
+
const fs = await import('node:fs/promises');
|
|
193
|
+
const path = await import('node:path');
|
|
194
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
195
|
+
const token = await resolveToken(options, fetchImpl);
|
|
196
|
+
const access = { ...options, accessToken: token };
|
|
197
|
+
await fs.mkdir(options.directory, { recursive: true });
|
|
198
|
+
const firestore = await fs.open(path.join(options.directory, 'firestore.ndjson'), 'w');
|
|
199
|
+
let documents = 0;
|
|
200
|
+
try {
|
|
201
|
+
for await (const document of exportFirestoreDocuments(access)) {
|
|
202
|
+
await firestore.write(`${JSON.stringify(document)}\n`);
|
|
203
|
+
documents += 1;
|
|
204
|
+
if (documents % 500 === 0) {
|
|
205
|
+
options.onProgress?.({ phase: 'firestore', count: documents });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
await firestore.close();
|
|
211
|
+
}
|
|
212
|
+
options.onProgress?.({ phase: 'firestore', count: documents });
|
|
213
|
+
if (options.authExportPath) {
|
|
214
|
+
await fs.copyFile(options.authExportPath, path.join(options.directory, 'auth.json'));
|
|
215
|
+
}
|
|
216
|
+
if (options.hashConfig) {
|
|
217
|
+
await fs.writeFile(path.join(options.directory, 'hash-config.json'), JSON.stringify({ algorithm: 'SCRYPT', ...options.hashConfig }, null, 2), { mode: 0o600 });
|
|
218
|
+
}
|
|
219
|
+
let objects = 0;
|
|
220
|
+
let bytes = 0;
|
|
221
|
+
for (const bucket of options.buckets ?? []) {
|
|
222
|
+
if (!/^[a-z0-9][a-z0-9._-]{1,220}[a-z0-9]$/.test(bucket) || bucket.includes('..')) {
|
|
223
|
+
throw new FirebaseExportError(`"${bucket}" is not a valid Cloud Storage bucket name`);
|
|
224
|
+
}
|
|
225
|
+
for (const object of await listStorageObjects(access, bucket)) {
|
|
226
|
+
if (!safeObjectPath(object.name)) {
|
|
227
|
+
throw new FirebaseExportError(`refusing unsafe object path in bucket ${bucket}`);
|
|
228
|
+
}
|
|
229
|
+
const response = await fetchImpl(`${STORAGE_API}/b/${encodeURIComponent(bucket)}/o/${encodeURIComponent(object.name)}?alt=media`, { headers: { authorization: `Bearer ${token}` } });
|
|
230
|
+
if (!response.ok) {
|
|
231
|
+
throw new FirebaseExportError(`could not download an object from ${bucket}`, response.status);
|
|
232
|
+
}
|
|
233
|
+
const target = path.join(options.directory, 'storage', bucket, ...object.name.split('/'));
|
|
234
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
235
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
236
|
+
await fs.writeFile(target, data);
|
|
237
|
+
objects += 1;
|
|
238
|
+
bytes += data.byteLength;
|
|
239
|
+
options.onProgress?.({ phase: 'storage', count: objects, detail: `${bucket}/${object.name}` });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
directory: options.directory,
|
|
244
|
+
documents,
|
|
245
|
+
objects,
|
|
246
|
+
bytes,
|
|
247
|
+
auth: Boolean(options.authExportPath),
|
|
248
|
+
hashConfig: Boolean(options.hashConfig),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=firebase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../../src/importers/firebase.ts"],"names":[],"mappings":"AAAA;;;;;;;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,UAAU,KAAK,EAAE,EAAE,EAAE,CAClD,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,mBAAmB,CAAC,qCAAqC,MAAM,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YAChG,CAAC;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1F,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1D,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;YAC1D,MAAM,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACjC,OAAO,IAAI,CAAC,CAAC;YACb,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC;YACzB,OAAO,CAAC,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;IAED,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,SAAS;QACT,OAAO;QACP,KAAK;QACL,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC;QACrC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `scribase/importers` — build export folders for `POST /v1/imports` from
|
|
3
|
+
* sources that have no Postgres to connect to: Firebase (Firestore, Auth,
|
|
4
|
+
* Cloud Storage) and InstantDB. Kept off the main entry because the folder
|
|
5
|
+
* writers use Node's filesystem.
|
|
6
|
+
*/
|
|
7
|
+
export { exportFirestoreDocuments, googleAccessToken, listStorageObjects, writeFirebaseExport, FirebaseExportError, } from './firebase.js';
|
|
8
|
+
export type { FirebaseAccess, FirebaseExportSummary, FirestoreDocument, GoogleServiceAccount, StorageObjectInfo, WriteFirebaseExportOptions, } from './firebase.js';
|
|
9
|
+
export { exportInstantApp, writeInstantExport, InstantExportError } from './instantdb.js';
|
|
10
|
+
export type { InstantAccess, InstantExportDocument, InstantExportOptions, InstantExportSummary, WriteInstantExportOptions, } from './instantdb.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/importers/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC1F,YAAY,EACV,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `scribase/importers` — build export folders for `POST /v1/imports` from
|
|
3
|
+
* sources that have no Postgres to connect to: Firebase (Firestore, Auth,
|
|
4
|
+
* Cloud Storage) and InstantDB. Kept off the main entry because the folder
|
|
5
|
+
* writers use Node's filesystem.
|
|
6
|
+
*/
|
|
7
|
+
export { exportFirestoreDocuments, googleAccessToken, listStorageObjects, writeFirebaseExport, FirebaseExportError, } from './firebase.js';
|
|
8
|
+
export { exportInstantApp, writeInstantExport, InstantExportError } from './instantdb.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/importers/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAUvB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Export an InstantDB app into the layout `POST /v1/imports` reads with
|
|
3
|
+
* `source: 'instantdb'`:
|
|
4
|
+
*
|
|
5
|
+
* ```text
|
|
6
|
+
* <dir>/instant-export.json { appId, exportedAt, namespaces, users, files }
|
|
7
|
+
* <dir>/files/<path> the bytes of every $files entity
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Instant's hosted cloud shuts down on 2027-08-31. This uses Instant's admin
|
|
11
|
+
* HTTP API (`POST /admin/query`, the same endpoint `@instantdb/admin` calls)
|
|
12
|
+
* with your app id and admin token, so no Instant SDK is required.
|
|
13
|
+
*/
|
|
14
|
+
export interface InstantAccess {
|
|
15
|
+
/** The Instant app id (a UUID). */
|
|
16
|
+
appId: string;
|
|
17
|
+
/** The app's admin token (Instant dashboard → Admin). Never logged. */
|
|
18
|
+
adminToken: string;
|
|
19
|
+
/** Override for self-hosted Instant. */
|
|
20
|
+
apiUrl?: string;
|
|
21
|
+
/** Injected for tests; defaults to the global `fetch`. */
|
|
22
|
+
fetch?: typeof fetch;
|
|
23
|
+
}
|
|
24
|
+
export interface InstantExportOptions extends InstantAccess {
|
|
25
|
+
/** Namespaces to export, e.g. `['todos', 'projects']`. `$users`/`$files` are always included. */
|
|
26
|
+
namespaces: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Links to flatten per namespace, e.g. `{ todos: ['owner', 'tags'] }`. Each
|
|
29
|
+
* link is stored on the entity as an array of linked ids under the label.
|
|
30
|
+
*/
|
|
31
|
+
links?: Record<string, string[]>;
|
|
32
|
+
}
|
|
33
|
+
/** The `instant-export.json` document. */
|
|
34
|
+
export interface InstantExportDocument {
|
|
35
|
+
appId: string;
|
|
36
|
+
exportedAt: string;
|
|
37
|
+
namespaces: Record<string, Record<string, unknown>[]>;
|
|
38
|
+
users: Record<string, unknown>[];
|
|
39
|
+
files: {
|
|
40
|
+
id: string;
|
|
41
|
+
path: string;
|
|
42
|
+
url?: string;
|
|
43
|
+
contentType?: string;
|
|
44
|
+
}[];
|
|
45
|
+
}
|
|
46
|
+
/** A failure talking to Instant. The message never includes the admin token. */
|
|
47
|
+
export declare class InstantExportError extends Error {
|
|
48
|
+
readonly status: number;
|
|
49
|
+
constructor(message: string, status?: number);
|
|
50
|
+
}
|
|
51
|
+
/** Reads every requested namespace plus `$users` and `$files`. */
|
|
52
|
+
export declare function exportInstantApp(options: InstantExportOptions): Promise<InstantExportDocument>;
|
|
53
|
+
export interface WriteInstantExportOptions extends InstantExportOptions {
|
|
54
|
+
/** Destination folder; created if missing. */
|
|
55
|
+
directory: string;
|
|
56
|
+
onProgress?: (event: {
|
|
57
|
+
phase: 'data' | 'files';
|
|
58
|
+
count: number;
|
|
59
|
+
detail?: string;
|
|
60
|
+
}) => void;
|
|
61
|
+
}
|
|
62
|
+
export interface InstantExportSummary {
|
|
63
|
+
directory: string;
|
|
64
|
+
namespaces: number;
|
|
65
|
+
entities: number;
|
|
66
|
+
users: number;
|
|
67
|
+
files: number;
|
|
68
|
+
bytes: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Writes a complete Instant export folder, downloading every `$files` object
|
|
72
|
+
* (Node only). Import it with
|
|
73
|
+
* `scribase.imports.createFrom({ source: 'instantdb', sourceExportDir: '<folder>', … })`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function writeInstantExport(options: WriteInstantExportOptions): Promise<InstantExportSummary>;
|
|
76
|
+
//# sourceMappingURL=instantdb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instantdb.d.ts","sourceRoot":"","sources":["../../src/importers/instantdb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD,iGAAiG;IACjG,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAClC;AAED,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACtD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACjC,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC3E;AAED,gFAAgF;AAChF,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,MAAM,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