@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/init/index.mjs
CHANGED
|
@@ -6856,14 +6856,67 @@ const createFirestoreStore = ({ firestore, collection, nativePageSize }) => {
|
|
|
6856
6856
|
};
|
|
6857
6857
|
};
|
|
6858
6858
|
//#endregion
|
|
6859
|
+
//#region src/googleCredential.ts
|
|
6860
|
+
const CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
|
|
6861
|
+
/**
|
|
6862
|
+
* Resolves application default credentials as Firestore will, from
|
|
6863
|
+
* GOOGLE_APPLICATION_CREDENTIALS's file or the environment, for the app's
|
|
6864
|
+
* `projectId`, so it neither exchanges a token nor discovers a project
|
|
6865
|
+
* Firestore itself wouldn't. Only `applicationDefault()`'s credential: a
|
|
6866
|
+
* service account's or refresh token's was read from its file already.
|
|
6867
|
+
*/
|
|
6868
|
+
const resolveApplicationDefault = async (credential, projectId) => {
|
|
6869
|
+
if (credential.constructor.name !== "ApplicationDefaultCredential") return;
|
|
6870
|
+
const { GoogleAuth } = await import("google-auth-library");
|
|
6871
|
+
await new GoogleAuth({
|
|
6872
|
+
scopes: [CLOUD_PLATFORM_SCOPE],
|
|
6873
|
+
...projectId === void 0 ? {} : { projectId }
|
|
6874
|
+
}).getClient();
|
|
6875
|
+
};
|
|
6876
|
+
//#endregion
|
|
6859
6877
|
//#region src/firebaseDatabase.ts
|
|
6878
|
+
/**
|
|
6879
|
+
* `store` that loads `credential` before its first call: one that cannot
|
|
6880
|
+
* load, such as GOOGLE_APPLICATION_CREDENTIALS naming a missing file, fails
|
|
6881
|
+
* that call with what is wrong. Firestore's own client would also reject a
|
|
6882
|
+
* promise nobody awaits, which ends a CLI process with a stack trace.
|
|
6883
|
+
*/
|
|
6884
|
+
const withLoadedCredential = (store, credential, projectId) => {
|
|
6885
|
+
let loaded;
|
|
6886
|
+
const load = () => loaded ??= resolveApplicationDefault(credential, projectId).then(() => void 0, (error) => {
|
|
6887
|
+
loaded = void 0;
|
|
6888
|
+
throw new Error(`Could not load the Google credentials for Firestore: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
6889
|
+
});
|
|
6890
|
+
const { deleteConsumed } = store;
|
|
6891
|
+
return {
|
|
6892
|
+
...store,
|
|
6893
|
+
get: async (keys) => {
|
|
6894
|
+
await load();
|
|
6895
|
+
return store.get(keys);
|
|
6896
|
+
},
|
|
6897
|
+
query: async (range) => {
|
|
6898
|
+
await load();
|
|
6899
|
+
return store.query(range);
|
|
6900
|
+
},
|
|
6901
|
+
write: async (ops) => {
|
|
6902
|
+
await load();
|
|
6903
|
+
return store.write(ops);
|
|
6904
|
+
},
|
|
6905
|
+
...deleteConsumed && { deleteConsumed: async (keys) => {
|
|
6906
|
+
await load();
|
|
6907
|
+
return deleteConsumed.call(store, keys);
|
|
6908
|
+
} }
|
|
6909
|
+
};
|
|
6910
|
+
};
|
|
6860
6911
|
const adapterOf = ({ databaseId, collection = FIREBASE_V1_COLLECTION, aggregateBatching: _, ...appOptions }) => {
|
|
6861
6912
|
const app = getApps().length ? getApp() : initializeApp(appOptions);
|
|
6862
6913
|
const firestore = databaseId ? getFirestore(app, databaseId) : getFirestore(app);
|
|
6863
|
-
|
|
6914
|
+
const store = createFirestoreStore({
|
|
6864
6915
|
firestore,
|
|
6865
6916
|
collection
|
|
6866
|
-
})
|
|
6917
|
+
});
|
|
6918
|
+
const credential = app.options.credential;
|
|
6919
|
+
return createKvAdapter({ store: appOptions.credential === void 0 || credential === void 0 || process.env["FIRESTORE_EMULATOR_HOST"] ? store : withLoadedCredential(store, credential, app.options.projectId) });
|
|
6867
6920
|
};
|
|
6868
6921
|
/**
|
|
6869
6922
|
* Writes the schema settings of core and `plugins`, the plugins the server
|
|
@@ -6969,8 +7022,32 @@ const firebaseEngineSettingDocumentId = () => firestoreDocumentId({
|
|
|
6969
7022
|
pk: SETTINGS_TABLE.name,
|
|
6970
7023
|
sk: encodeKvKey([ENGINE_SETTING])
|
|
6971
7024
|
});
|
|
7025
|
+
/**
|
|
7026
|
+
* The Google credential init reads Firestore with, once it loads: the
|
|
7027
|
+
* service account key file `applicationCredentials` names, or the
|
|
7028
|
+
* application default credentials. Before any change, an InitError says
|
|
7029
|
+
* what is wrong with one that does not load, where Firestore's client would
|
|
7030
|
+
* end init with a stack trace.
|
|
7031
|
+
*/
|
|
7032
|
+
const loadGoogleCredential = async (applicationCredentials, projectId) => {
|
|
7033
|
+
const next = "Set GOOGLE_APPLICATION_CREDENTIALS to a service account key file, then rerun init.";
|
|
7034
|
+
let credential;
|
|
7035
|
+
try {
|
|
7036
|
+
credential = applicationCredentials ? cert(JSON.parse(await fs$1.readFile(applicationCredentials, "utf8"))) : applicationDefault();
|
|
7037
|
+
} catch {
|
|
7038
|
+
throw new InitError(`GOOGLE_APPLICATION_CREDENTIALS names ${applicationCredentials}, which is not a readable service account key file. ${next}`);
|
|
7039
|
+
}
|
|
7040
|
+
if (process.env["FIRESTORE_EMULATOR_HOST"]) return credential;
|
|
7041
|
+
try {
|
|
7042
|
+
await resolveApplicationDefault(credential, projectId);
|
|
7043
|
+
} catch (error) {
|
|
7044
|
+
const reason = (error instanceof Error ? error.message : String(error)).split(/(?<=\.)\s/u)[0].replace(/\.$/u, "");
|
|
7045
|
+
throw new InitError(`Could not load Google credentials: ${reason}. ${next}`);
|
|
7046
|
+
}
|
|
7047
|
+
return credential;
|
|
7048
|
+
};
|
|
6972
7049
|
const assertFirebaseInfrastructureCanInitialize = async ({ applicationCredentials, databaseId, projectId }) => {
|
|
6973
|
-
const credential =
|
|
7050
|
+
const credential = await loadGoogleCredential(applicationCredentials, projectId);
|
|
6974
7051
|
const app = initializeApp({
|
|
6975
7052
|
credential,
|
|
6976
7053
|
projectId
|
|
@@ -7816,7 +7893,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7816
7893
|
});
|
|
7817
7894
|
await makeEnv(persistedInputs);
|
|
7818
7895
|
await removeTmpDir();
|
|
7819
|
-
return;
|
|
7896
|
+
return null;
|
|
7820
7897
|
}
|
|
7821
7898
|
const functionsCode = transformEnv(functionsIndexPath, {
|
|
7822
7899
|
REGION: currentRegion,
|
|
@@ -7846,8 +7923,8 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7846
7923
|
}
|
|
7847
7924
|
}]);
|
|
7848
7925
|
await deployFirestore(tmpDir, initializeVariable.databaseId, nonInteractive, cliEnv);
|
|
7849
|
-
const credential =
|
|
7850
|
-
|
|
7926
|
+
const credential = await loadGoogleCredential(applicationCredentials, initializeVariable.projectId);
|
|
7927
|
+
await Promise.all(getApps().map((app) => deleteApp(app)));
|
|
7851
7928
|
const databaseConfig = {
|
|
7852
7929
|
credential,
|
|
7853
7930
|
databaseId: initializeVariable.databaseId,
|
|
@@ -7872,7 +7949,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7872
7949
|
if (clientCredential !== void 0) await makeEnv({ [clientCredential.env]: clientCredential.value });
|
|
7873
7950
|
} finally {
|
|
7874
7951
|
await database.dispose?.();
|
|
7875
|
-
await Promise.all(getApps().
|
|
7952
|
+
await Promise.all(getApps().map((app) => deleteApp(app)));
|
|
7876
7953
|
}
|
|
7877
7954
|
await deployFunctions(tmpDir, nonInteractive, cliEnv);
|
|
7878
7955
|
await p.tasks([{
|
|
@@ -7919,9 +7996,7 @@ const runInit = async ({ build, envFile, secretsEnv }) => {
|
|
|
7919
7996
|
}
|
|
7920
7997
|
await printTemplate(clientCredential, initializeVariable.projectId, currentRegion, server.clientPlugins, cliEnv);
|
|
7921
7998
|
await removeTmpDir();
|
|
7922
|
-
|
|
7923
|
-
if (!applicationCredentials) p.log.message("Next step: Change GOOGLE_APPLICATION_CREDENTIALS=your-credentials.json in .env.hotupdater");
|
|
7924
|
-
p.log.success("Done! 🎉");
|
|
7999
|
+
return { nextSteps: [link("https://hot-updater.dev/docs/managed/firebase#step-3-add-hotupdater-to-your-project"), ...applicationCredentials ? [] : ["Change GOOGLE_APPLICATION_CREDENTIALS=your-credentials.json in .env.hotupdater"]] };
|
|
7925
8000
|
};
|
|
7926
8001
|
//#endregion
|
|
7927
8002
|
export { initProvider, mergeIndexes, runInit, setFirestoreDatabase };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/firebase",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.0-rc.
|
|
4
|
+
"version": "1.2.0-rc.50",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"hono": "4.12.34",
|
|
40
40
|
"google-auth-library": "10.7.0",
|
|
41
|
-
"@hot-updater/
|
|
42
|
-
"@hot-updater/
|
|
43
|
-
"@hot-updater/
|
|
44
|
-
"@hot-updater/
|
|
41
|
+
"@hot-updater/protocol": "1.2.0-rc.50",
|
|
42
|
+
"@hot-updater/cli-tools": "1.2.0-rc.50",
|
|
43
|
+
"@hot-updater/plugin-core": "1.2.0-rc.50",
|
|
44
|
+
"@hot-updater/server": "1.2.0-rc.50"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"firebase-tools": "15.29.0",
|
|
57
57
|
"fkill": "^9.0.0",
|
|
58
58
|
"mime": "^4.0.4",
|
|
59
|
-
"@hot-updater/mock": "1.2.0-rc.
|
|
60
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
59
|
+
"@hot-updater/mock": "1.2.0-rc.50",
|
|
60
|
+
"@hot-updater/test-utils": "1.2.0-rc.50"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"firebase-admin": ">=11.10.0",
|