@hot-updater/firebase 1.2.0-rc.5 → 1.2.0-rc.50
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/firebase/functions/index.cjs +1750 -353
- package/dist/index.cjs +198 -37
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +198 -37
- package/dist/init/index.cjs +85 -10
- package/dist/init/index.d.cts +2 -2
- package/dist/init/index.d.mts +2 -2
- package/dist/init/index.mjs +85 -10
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -167,14 +167,67 @@ const createFirestoreStore = ({ firestore, collection, nativePageSize }) => {
|
|
|
167
167
|
};
|
|
168
168
|
};
|
|
169
169
|
//#endregion
|
|
170
|
+
//#region src/googleCredential.ts
|
|
171
|
+
const CLOUD_PLATFORM_SCOPE$1 = "https://www.googleapis.com/auth/cloud-platform";
|
|
172
|
+
/**
|
|
173
|
+
* Resolves application default credentials as Firestore will, from
|
|
174
|
+
* GOOGLE_APPLICATION_CREDENTIALS's file or the environment, for the app's
|
|
175
|
+
* `projectId`, so it neither exchanges a token nor discovers a project
|
|
176
|
+
* Firestore itself wouldn't. Only `applicationDefault()`'s credential: a
|
|
177
|
+
* service account's or refresh token's was read from its file already.
|
|
178
|
+
*/
|
|
179
|
+
const resolveApplicationDefault = async (credential, projectId) => {
|
|
180
|
+
if (credential.constructor.name !== "ApplicationDefaultCredential") return;
|
|
181
|
+
const { GoogleAuth } = await import("google-auth-library");
|
|
182
|
+
await new GoogleAuth({
|
|
183
|
+
scopes: [CLOUD_PLATFORM_SCOPE$1],
|
|
184
|
+
...projectId === void 0 ? {} : { projectId }
|
|
185
|
+
}).getClient();
|
|
186
|
+
};
|
|
187
|
+
//#endregion
|
|
170
188
|
//#region src/firebaseDatabase.ts
|
|
189
|
+
/**
|
|
190
|
+
* `store` that loads `credential` before its first call: one that cannot
|
|
191
|
+
* load, such as GOOGLE_APPLICATION_CREDENTIALS naming a missing file, fails
|
|
192
|
+
* that call with what is wrong. Firestore's own client would also reject a
|
|
193
|
+
* promise nobody awaits, which ends a CLI process with a stack trace.
|
|
194
|
+
*/
|
|
195
|
+
const withLoadedCredential = (store, credential, projectId) => {
|
|
196
|
+
let loaded;
|
|
197
|
+
const load = () => loaded ??= resolveApplicationDefault(credential, projectId).then(() => void 0, (error) => {
|
|
198
|
+
loaded = void 0;
|
|
199
|
+
throw new Error(`Could not load the Google credentials for Firestore: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
200
|
+
});
|
|
201
|
+
const { deleteConsumed } = store;
|
|
202
|
+
return {
|
|
203
|
+
...store,
|
|
204
|
+
get: async (keys) => {
|
|
205
|
+
await load();
|
|
206
|
+
return store.get(keys);
|
|
207
|
+
},
|
|
208
|
+
query: async (range) => {
|
|
209
|
+
await load();
|
|
210
|
+
return store.query(range);
|
|
211
|
+
},
|
|
212
|
+
write: async (ops) => {
|
|
213
|
+
await load();
|
|
214
|
+
return store.write(ops);
|
|
215
|
+
},
|
|
216
|
+
...deleteConsumed && { deleteConsumed: async (keys) => {
|
|
217
|
+
await load();
|
|
218
|
+
return deleteConsumed.call(store, keys);
|
|
219
|
+
} }
|
|
220
|
+
};
|
|
221
|
+
};
|
|
171
222
|
const adapterOf = ({ databaseId, collection = FIREBASE_V1_COLLECTION, aggregateBatching: _, ...appOptions }) => {
|
|
172
223
|
const app = (0, firebase_admin_app.getApps)().length ? (0, firebase_admin_app.getApp)() : (0, firebase_admin_app.initializeApp)(appOptions);
|
|
173
224
|
const firestore = databaseId ? (0, firebase_admin_firestore.getFirestore)(app, databaseId) : (0, firebase_admin_firestore.getFirestore)(app);
|
|
174
|
-
|
|
225
|
+
const store = createFirestoreStore({
|
|
175
226
|
firestore,
|
|
176
227
|
collection
|
|
177
|
-
})
|
|
228
|
+
});
|
|
229
|
+
const credential = app.options.credential;
|
|
230
|
+
return (0, _hot_updater_plugin_core.createKvAdapter)({ store: appOptions.credential === void 0 || credential === void 0 || process.env["FIRESTORE_EMULATOR_HOST"] ? store : withLoadedCredential(store, credential, app.options.projectId) });
|
|
178
231
|
};
|
|
179
232
|
/**
|
|
180
233
|
* Writes the schema settings of core and `plugins`, the plugins the server
|
|
@@ -202,11 +255,14 @@ const firebaseDatabase = (config) => ({
|
|
|
202
255
|
//#region src/firebaseStorage.ts
|
|
203
256
|
/** Signed URLs kept per adapter, enough for a few Bundles' assets. */
|
|
204
257
|
const MAX_CACHED_SIGNED_URLS = 1e4;
|
|
258
|
+
/** Objects deleted at once: Cloud Storage deletes one object a request. */
|
|
259
|
+
const DELETE_CONCURRENCY = 16;
|
|
205
260
|
const firebaseStorage = (config) => {
|
|
206
261
|
const app = (0, firebase_admin_app.getApps)().length ? (0, firebase_admin_app.getApp)() : (0, firebase_admin_app.initializeApp)(config);
|
|
207
262
|
let opened;
|
|
208
263
|
const bucket = () => opened ??= (0, firebase_admin_storage.getStorage)(app).bucket(config.storageBucket);
|
|
209
264
|
const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(config.basePath);
|
|
265
|
+
const basePrefix = getStorageKey() ? `${getStorageKey()}/` : "";
|
|
210
266
|
/**
|
|
211
267
|
* Signed URLs by object. Without a private key, as in Cloud Functions, each
|
|
212
268
|
* signature is an IAM signBlob request, and an update check returns a URL
|
|
@@ -295,6 +351,39 @@ const firebaseStorage = (config) => {
|
|
|
295
351
|
const { key } = parseAndValidate(storageUri);
|
|
296
352
|
await bucket().file(key).delete({ ignoreNotFound: true });
|
|
297
353
|
return { deleted: true };
|
|
354
|
+
},
|
|
355
|
+
async listObjects(prefix) {
|
|
356
|
+
const folder = getStorageKey(prefix ?? "");
|
|
357
|
+
const [files] = await bucket().getFiles({
|
|
358
|
+
autoPaginate: true,
|
|
359
|
+
prefix: folder ? `${folder}/` : ""
|
|
360
|
+
});
|
|
361
|
+
const objects = [];
|
|
362
|
+
for (const file of files) {
|
|
363
|
+
if (!file.name.startsWith(basePrefix)) continue;
|
|
364
|
+
let storageUri;
|
|
365
|
+
try {
|
|
366
|
+
storageUri = (0, _hot_updater_plugin_core.createStorageUri)({
|
|
367
|
+
bucket: config.storageBucket,
|
|
368
|
+
key: file.name,
|
|
369
|
+
protocol: "gs"
|
|
370
|
+
});
|
|
371
|
+
} catch {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const { size, updated } = file.metadata;
|
|
375
|
+
objects.push({
|
|
376
|
+
key: file.name.slice(basePrefix.length),
|
|
377
|
+
...updated ? { lastModifiedAt: new Date(updated) } : {},
|
|
378
|
+
size: Number(size ?? 0),
|
|
379
|
+
storageUri
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
return objects;
|
|
383
|
+
},
|
|
384
|
+
async deleteObjects(relativeKeys) {
|
|
385
|
+
const keys = relativeKeys.map((key) => getStorageKey(key));
|
|
386
|
+
for (let offset = 0; offset < keys.length; offset += DELETE_CONCURRENCY) await Promise.all(keys.slice(offset, offset + DELETE_CONCURRENCY).map((key) => bucket().file(key).delete({ ignoreNotFound: true })));
|
|
298
387
|
}
|
|
299
388
|
});
|
|
300
389
|
};
|
|
@@ -356,22 +445,61 @@ const crc32c = (bytes) => {
|
|
|
356
445
|
/** The version IDs the secret's annotation lists. */
|
|
357
446
|
const trackedVersions = (secret) => (secret.annotations?.[VERSIONS_ANNOTATION] ?? "").split(",").map((entry) => entry.trim()).filter((entry) => VERSION_ID_PATTERN.test(entry));
|
|
358
447
|
const versionOf = (name) => typeof name === "string" ? name.slice(name.lastIndexOf("/") + 1) : "";
|
|
359
|
-
|
|
448
|
+
/** An error of one line each, for a terminal. */
|
|
449
|
+
const failure = (lines, cause) => new Error(lines.join("\n"), cause === void 0 ? void 0 : { cause });
|
|
450
|
+
/**
|
|
451
|
+
* The one step that can fix the credentials in use, by the order they're
|
|
452
|
+
* tried: signing in with gcloud changes nothing while a variable comes first.
|
|
453
|
+
*/
|
|
454
|
+
const signInHint = (credentials) => {
|
|
455
|
+
if (credentials) return [`Check the credentials passed to ${ADAPTER_NAME}().`];
|
|
456
|
+
const variable = ACCESS_TOKEN_ENV_NAMES.find((name) => process.env[name]?.trim()) ?? (process.env["GOOGLE_APPLICATION_CREDENTIALS"]?.trim() ? "GOOGLE_APPLICATION_CREDENTIALS" : void 0);
|
|
457
|
+
if (variable) return [`Fix or unset ${variable}.`];
|
|
458
|
+
return process.env["CI"] ? ["Use google-github-actions/auth."] : ["Sign in:", "gcloud auth application-default login"];
|
|
459
|
+
};
|
|
460
|
+
const hint = (response, permission, signIn, projectId) => {
|
|
360
461
|
const { status, error } = response;
|
|
361
|
-
if (error.details?.some((detail) => detail.reason === "SERVICE_DISABLED")) return "
|
|
362
|
-
if (status === 401) return "
|
|
363
|
-
if (status === 403) return `
|
|
364
|
-
if (status === 429) return "
|
|
365
|
-
return
|
|
462
|
+
if (error.details?.some((detail) => detail.reason === "SERVICE_DISABLED")) return ["Enable the Secret Manager API in the project:", `gcloud services enable secretmanager.googleapis.com --project ${projectId}`];
|
|
463
|
+
if (status === 401) return ["Google rejected the access token.", ...signIn];
|
|
464
|
+
if (status === 403) return [`The identity needs ${permission}.`];
|
|
465
|
+
if (status === 429) return ["Secret Manager's quota is exhausted: try again later."];
|
|
466
|
+
return [];
|
|
366
467
|
};
|
|
367
468
|
/**
|
|
368
|
-
* An error for a failed request: the HTTP status,
|
|
369
|
-
*
|
|
469
|
+
* An error for a failed request on `resource`, a line each: the HTTP status,
|
|
470
|
+
* the resource, `notes`, and what to fix, or Google's own status and message,
|
|
471
|
+
* which name resources but never a value, when nothing here says what to fix.
|
|
370
472
|
*/
|
|
371
|
-
const
|
|
473
|
+
const requestErrorOf = (signIn, projectId, action, resource, response, permission, notes = []) => {
|
|
372
474
|
const { status, message } = response.error;
|
|
373
|
-
const
|
|
374
|
-
|
|
475
|
+
const fix = hint(response, permission, signIn, projectId);
|
|
476
|
+
if (response.status === 401 && notes.length === 0) return failure(fix);
|
|
477
|
+
return failure([
|
|
478
|
+
`${ADAPTER_NAME} couldn't ${action} (${response.status}).`,
|
|
479
|
+
resourceLine(resource),
|
|
480
|
+
...notes,
|
|
481
|
+
...fix.length > 0 ? fix : [[status, message?.slice(0, 300)].filter(Boolean).join(": ")]
|
|
482
|
+
]);
|
|
483
|
+
};
|
|
484
|
+
/** The line that names a secret: its resource name is a line's worth. */
|
|
485
|
+
const resourceLine = (secret) => `Secret: ${secret}`;
|
|
486
|
+
let metadataWarningFiltered = false;
|
|
487
|
+
/**
|
|
488
|
+
* Drops the one warning `gcp-metadata` emits when its probe for a Google
|
|
489
|
+
* runtime fails oddly: credentials are about to be reported as missing, and
|
|
490
|
+
* the warning has nothing to act on. It stays filtered for the process, as
|
|
491
|
+
* the library caches the probe; every other warning passes through.
|
|
492
|
+
* `METADATA_SERVER_DETECTION=none` would also silence it, but skips the probe,
|
|
493
|
+
* and with it the credentials of a Google runtime.
|
|
494
|
+
*/
|
|
495
|
+
const filterMetadataWarning = () => {
|
|
496
|
+
if (metadataWarningFiltered) return;
|
|
497
|
+
metadataWarningFiltered = true;
|
|
498
|
+
const emitWarning = process.emitWarning;
|
|
499
|
+
process.emitWarning = ((warning, ...rest) => {
|
|
500
|
+
if (rest[0] === "MetadataLookupWarning") return;
|
|
501
|
+
Reflect.apply(emitWarning, process, [warning, ...rest]);
|
|
502
|
+
});
|
|
375
503
|
};
|
|
376
504
|
/** Masks a value in the CLI's output, which loads `@hot-updater/cli-tools`. */
|
|
377
505
|
const mask = async (value) => {
|
|
@@ -408,10 +536,11 @@ const createAccessToken = (credentials, projectId) => {
|
|
|
408
536
|
throw error;
|
|
409
537
|
});
|
|
410
538
|
const client = await auth;
|
|
539
|
+
filterMetadataWarning();
|
|
411
540
|
try {
|
|
412
541
|
return await client.getAccessToken() ?? void 0;
|
|
413
542
|
} catch (error) {
|
|
414
|
-
throw
|
|
543
|
+
throw failure([`${ADAPTER_NAME} found no Google credentials.`, ...signInHint(void 0)], error);
|
|
415
544
|
}
|
|
416
545
|
};
|
|
417
546
|
return async () => {
|
|
@@ -433,14 +562,19 @@ const createAccessToken = (credentials, projectId) => {
|
|
|
433
562
|
*/
|
|
434
563
|
const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
435
564
|
const accessToken = createAccessToken(credentials, projectId);
|
|
565
|
+
const requestError = (action, resource, response, permission, notes) => requestErrorOf(signInHint(credentials), projectId, action, resource, response, permission, notes);
|
|
436
566
|
const projectPath = () => {
|
|
437
|
-
if (typeof projectId !== "string" || !PROJECT_PATTERN.test(projectId)) throw
|
|
438
|
-
if (!PREFIX_PATTERN.test(prefix)) throw
|
|
567
|
+
if (typeof projectId !== "string" || !PROJECT_PATTERN.test(projectId)) throw failure([`${ADAPTER_NAME} can't use the projectId ${JSON.stringify(projectId)}.`, "Set the Google Cloud project's ID or number."]);
|
|
568
|
+
if (!PREFIX_PATTERN.test(prefix)) throw failure([`${ADAPTER_NAME} can't use the prefix ${JSON.stringify(prefix)}.`, "It takes letters, digits, \"-\", and \"_\"."]);
|
|
439
569
|
return `projects/${projectId}`;
|
|
440
570
|
};
|
|
441
571
|
const secretId = (name) => {
|
|
442
572
|
const id = `${prefix}${name}`;
|
|
443
|
-
if (!SECRET_ID_PATTERN.test(id)) throw
|
|
573
|
+
if (!SECRET_ID_PATTERN.test(id)) throw failure([
|
|
574
|
+
`${ADAPTER_NAME} can't name a secret ${JSON.stringify(name)}.`,
|
|
575
|
+
`Secret: ${id}`,
|
|
576
|
+
"Secret Manager's IDs take up to 255 letters, digits, \"-\", and \"_\"."
|
|
577
|
+
]);
|
|
444
578
|
return id;
|
|
445
579
|
};
|
|
446
580
|
const request = async (token, method, path, body) => {
|
|
@@ -475,14 +609,18 @@ const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
|
475
609
|
const accessLatest = async (token, secret) => {
|
|
476
610
|
const response = await request(token, "GET", `${secret}/versions/latest:access`);
|
|
477
611
|
if (response.status === 404) return void 0;
|
|
478
|
-
if (!response.ok) throw requestError(
|
|
612
|
+
if (!response.ok) throw requestError("read", secret, response, "roles/secretmanager.secretAccessor on the secret");
|
|
479
613
|
const body = isRecord(response.body) ? response.body : void 0;
|
|
480
614
|
const payload = body?.payload;
|
|
481
615
|
const data = isRecord(payload) ? payload.data : void 0;
|
|
482
|
-
if (typeof data !== "string") throw
|
|
616
|
+
if (typeof data !== "string") throw failure([`${ADAPTER_NAME} read no payload.`, resourceLine(secret)]);
|
|
483
617
|
const bytes = Buffer.from(data, "base64");
|
|
484
618
|
const checksum = isRecord(payload) ? payload.dataCrc32c : void 0;
|
|
485
|
-
if (checksum !== void 0 && Number(checksum) !== crc32c(bytes)) throw
|
|
619
|
+
if (checksum !== void 0 && Number(checksum) !== crc32c(bytes)) throw failure([
|
|
620
|
+
`${ADAPTER_NAME} can't trust what it read.`,
|
|
621
|
+
resourceLine(secret),
|
|
622
|
+
"Its checksum doesn't match its payload."
|
|
623
|
+
]);
|
|
486
624
|
const value = bytes.toString("utf8");
|
|
487
625
|
await mask(value);
|
|
488
626
|
return {
|
|
@@ -515,7 +653,7 @@ const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
|
515
653
|
const readSecret = async (token, secret) => {
|
|
516
654
|
const response = await request(token, "GET", secret);
|
|
517
655
|
if (response.status === 404) return void 0;
|
|
518
|
-
if (!response.ok) throw requestError(
|
|
656
|
+
if (!response.ok) throw requestError("read", secret, response, "secretmanager.secrets.get on the secret");
|
|
519
657
|
return response.body;
|
|
520
658
|
};
|
|
521
659
|
const getOrCreateSecret = async (token, parent, id) => {
|
|
@@ -528,14 +666,19 @@ const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
|
528
666
|
const raced = await readSecret(token, secret);
|
|
529
667
|
if (raced) return raced;
|
|
530
668
|
}
|
|
531
|
-
throw requestError(
|
|
669
|
+
throw requestError("create", secret, created, `secretmanager.secrets.create on ${parent}`);
|
|
532
670
|
};
|
|
533
671
|
const assertCanSet = async (token, secret) => {
|
|
534
672
|
const response = await request(token, "POST", `${secret}:testIamPermissions`, { permissions: SET_PERMISSIONS });
|
|
535
|
-
if (!response.ok) throw requestError(
|
|
673
|
+
if (!response.ok) throw requestError("check its permissions", secret, response, SET_PERMISSIONS.join(", "));
|
|
536
674
|
const held = isRecord(response.body) && Array.isArray(response.body.permissions) ? response.body.permissions : [];
|
|
537
675
|
const missing = SET_PERMISSIONS.filter((name) => !held.includes(name));
|
|
538
|
-
if (missing.length > 0) throw
|
|
676
|
+
if (missing.length > 0) throw failure([
|
|
677
|
+
`${ADAPTER_NAME} can't store a value.`,
|
|
678
|
+
resourceLine(secret),
|
|
679
|
+
`The identity lacks ${missing.join(", ")} on it.`,
|
|
680
|
+
"Grant roles/secretmanager.admin."
|
|
681
|
+
]);
|
|
539
682
|
};
|
|
540
683
|
/**
|
|
541
684
|
* Destroys `version` of `secret`: true once it is destroyed, or already
|
|
@@ -568,10 +711,11 @@ const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
|
568
711
|
/**
|
|
569
712
|
* Adds `value` as the secret's newest version, creating the secret when
|
|
570
713
|
* it is missing, and waits until the `latest` alias resolves to it. Then
|
|
571
|
-
* it destroys the
|
|
572
|
-
* `hot-updater-versions` annotation lists
|
|
573
|
-
*
|
|
574
|
-
*
|
|
714
|
+
* it destroys the versions this adapter added before the previous one,
|
|
715
|
+
* which the secret's `hot-updater-versions` annotation lists, keeping
|
|
716
|
+
* the previous value: versions added any other way are never touched.
|
|
717
|
+
* The permissions this needs are checked on the secret, once it exists,
|
|
718
|
+
* before any version is added. A version that could not be destroyed stays
|
|
575
719
|
* listed for the next `set`. The annotation is updated against the
|
|
576
720
|
* secret's etag, so a concurrent `set` loses no listed version. When
|
|
577
721
|
* `latest` does not resolve to the new version in time, or the
|
|
@@ -582,7 +726,7 @@ const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
|
582
726
|
const parent = projectPath();
|
|
583
727
|
const id = secretId(name);
|
|
584
728
|
const secret = `${parent}/secrets/${id}`;
|
|
585
|
-
if (typeof value !== "string" || value === "") throw
|
|
729
|
+
if (typeof value !== "string" || value === "") throw failure([`${ADAPTER_NAME} can't store an empty value.`, resourceLine(secret)]);
|
|
586
730
|
await mask(value);
|
|
587
731
|
const token = await accessToken();
|
|
588
732
|
const current = await getOrCreateSecret(token, parent, id);
|
|
@@ -593,17 +737,20 @@ const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
|
593
737
|
dataCrc32c: String(crc32c(data))
|
|
594
738
|
} });
|
|
595
739
|
const version = versionOf(isRecord(added.body) ? added.body.name : void 0);
|
|
596
|
-
if (!added.ok || !VERSION_ID_PATTERN.test(version)) throw requestError(
|
|
740
|
+
if (!added.ok || !VERSION_ID_PATTERN.test(version)) throw requestError("add a version", secret, added, "secretmanager.versions.add on the secret");
|
|
741
|
+
const own = trackedVersions(current).filter((entry) => Number(entry) < Number(version));
|
|
742
|
+
const previous = own.reduce((newest, entry) => newest === void 0 || Number(entry) > Number(newest) ? entry : newest, void 0);
|
|
597
743
|
const visible = await waitForLatest(token, secret, version);
|
|
598
744
|
const destroyed = /* @__PURE__ */ new Set();
|
|
599
745
|
if (visible) {
|
|
600
|
-
const older =
|
|
746
|
+
const older = own.filter((entry) => entry !== previous);
|
|
601
747
|
const results = await Promise.all(older.map((entry) => destroy(token, secret, entry)));
|
|
602
748
|
older.forEach((entry, index) => {
|
|
603
749
|
if (results[index]) destroyed.add(entry);
|
|
604
750
|
});
|
|
605
751
|
}
|
|
606
|
-
const notListed = `
|
|
752
|
+
const notListed = `record version ${version}, which it stored`;
|
|
753
|
+
const notDestroyed = `The next set won't destroy it: ${VERSIONS_ANNOTATION} misses it.`;
|
|
607
754
|
let base = current;
|
|
608
755
|
let updated;
|
|
609
756
|
try {
|
|
@@ -612,7 +759,11 @@ const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
|
612
759
|
await delay(LATEST_RETRY_DELAYS_MS[attempt - 1] ?? 0);
|
|
613
760
|
base = await readSecret(token, secret) ?? {};
|
|
614
761
|
}
|
|
615
|
-
const listed = [.../* @__PURE__ */ new Set([
|
|
762
|
+
const listed = [.../* @__PURE__ */ new Set([
|
|
763
|
+
version,
|
|
764
|
+
...previous === void 0 ? [] : [previous],
|
|
765
|
+
...trackedVersions(base)
|
|
766
|
+
])].filter((entry) => !destroyed.has(entry));
|
|
616
767
|
updated = await request(token, "PATCH", `${secret}?updateMask=annotations`, {
|
|
617
768
|
...base.etag === void 0 ? {} : { etag: base.etag },
|
|
618
769
|
annotations: {
|
|
@@ -623,14 +774,24 @@ const secretManager = ({ projectId, prefix = "hot-updater-", credentials }) => {
|
|
|
623
774
|
if (updated.error.status !== "FAILED_PRECONDITION") break;
|
|
624
775
|
}
|
|
625
776
|
} catch (error) {
|
|
626
|
-
throw
|
|
777
|
+
throw failure([
|
|
778
|
+
`${ADAPTER_NAME} couldn't ${notListed}.`,
|
|
779
|
+
resourceLine(secret),
|
|
780
|
+
error instanceof Error ? error.message : String(error),
|
|
781
|
+
notDestroyed
|
|
782
|
+
], error);
|
|
627
783
|
}
|
|
628
|
-
if (!updated?.ok) throw requestError(notListed, updated, "secretmanager.secrets.update on the secret");
|
|
629
|
-
if (!visible) throw
|
|
784
|
+
if (!updated?.ok) throw requestError(notListed, secret, updated, "secretmanager.secrets.update on the secret", [notDestroyed]);
|
|
785
|
+
if (!visible) throw failure([
|
|
786
|
+
`${ADAPTER_NAME} stored version ${version}.`,
|
|
787
|
+
resourceLine(secret),
|
|
788
|
+
"Its latest alias doesn't resolve to that version yet.",
|
|
789
|
+
"It kept the versions it added before: the next set destroys them."
|
|
790
|
+
]);
|
|
630
791
|
},
|
|
631
792
|
describe: (name) => {
|
|
632
793
|
const id = `${prefix}${name}`;
|
|
633
|
-
return `
|
|
794
|
+
return `the secret ${JSON.stringify(id)} in Google Secret Manager (https://console.cloud.google.com/security/secret-manager/secret/${encodeURIComponent(id)}/versions?project=${encodeURIComponent(projectId)})`;
|
|
634
795
|
}
|
|
635
796
|
};
|
|
636
797
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -11,9 +11,8 @@ type FirebaseDatabaseConfig = AppOptions & {
|
|
|
11
11
|
readonly collection?: string;
|
|
12
12
|
/**
|
|
13
13
|
* Firestore bills each document write, so Insights' aggregates are
|
|
14
|
-
* batched: through log rows a compaction merges (the default)
|
|
15
|
-
*
|
|
16
|
-
* each event.
|
|
14
|
+
* batched: through log rows a compaction merges (the default). `false` commits
|
|
15
|
+
* them with each event.
|
|
17
16
|
*/
|
|
18
17
|
readonly aggregateBatching?: EngineDatabase["aggregateBatching"] | false;
|
|
19
18
|
};
|
|
@@ -37,7 +36,7 @@ interface FirebaseStorageConfig extends AppOptions {
|
|
|
37
36
|
/** Firebase signed URL lifetime in seconds. @default 3600 */
|
|
38
37
|
signedUrlExpiresIn?: number;
|
|
39
38
|
}
|
|
40
|
-
declare const firebaseStorage: (config: FirebaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete">;
|
|
39
|
+
declare const firebaseStorage: (config: FirebaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete" | "listObjects" | "deleteObjects">;
|
|
41
40
|
//#endregion
|
|
42
41
|
//#region src/secretManager.d.ts
|
|
43
42
|
/**
|
|
@@ -56,7 +55,7 @@ interface SecretManagerOptions {
|
|
|
56
55
|
/** The Google Cloud project ID or number that holds the secrets. */
|
|
57
56
|
readonly projectId: string;
|
|
58
57
|
/**
|
|
59
|
-
* Put before each name to make its secret ID, so `secret
|
|
58
|
+
* Put before each name to make its secret ID, so `secret("asc-api-key")`
|
|
60
59
|
* reads `hot-updater-asc-api-key`. Letters, digits, `-`, and `_`.
|
|
61
60
|
*
|
|
62
61
|
* @default "hot-updater-"
|
package/dist/index.d.mts
CHANGED
|
@@ -11,9 +11,8 @@ type FirebaseDatabaseConfig = AppOptions & {
|
|
|
11
11
|
readonly collection?: string;
|
|
12
12
|
/**
|
|
13
13
|
* Firestore bills each document write, so Insights' aggregates are
|
|
14
|
-
* batched: through log rows a compaction merges (the default)
|
|
15
|
-
*
|
|
16
|
-
* each event.
|
|
14
|
+
* batched: through log rows a compaction merges (the default). `false` commits
|
|
15
|
+
* them with each event.
|
|
17
16
|
*/
|
|
18
17
|
readonly aggregateBatching?: EngineDatabase["aggregateBatching"] | false;
|
|
19
18
|
};
|
|
@@ -37,7 +36,7 @@ interface FirebaseStorageConfig extends AppOptions {
|
|
|
37
36
|
/** Firebase signed URL lifetime in seconds. @default 3600 */
|
|
38
37
|
signedUrlExpiresIn?: number;
|
|
39
38
|
}
|
|
40
|
-
declare const firebaseStorage: (config: FirebaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete">;
|
|
39
|
+
declare const firebaseStorage: (config: FirebaseStorageConfig) => StorageAdapterWith<"put" | "get" | "getDownloadUrl" | "exists" | "delete" | "listObjects" | "deleteObjects">;
|
|
41
40
|
//#endregion
|
|
42
41
|
//#region src/secretManager.d.ts
|
|
43
42
|
/**
|
|
@@ -56,7 +55,7 @@ interface SecretManagerOptions {
|
|
|
56
55
|
/** The Google Cloud project ID or number that holds the secrets. */
|
|
57
56
|
readonly projectId: string;
|
|
58
57
|
/**
|
|
59
|
-
* Put before each name to make its secret ID, so `secret
|
|
58
|
+
* Put before each name to make its secret ID, so `secret("asc-api-key")`
|
|
60
59
|
* reads `hot-updater-asc-api-key`. Letters, digits, `-`, and `_`.
|
|
61
60
|
*
|
|
62
61
|
* @default "hot-updater-"
|