@firebase/util 1.10.3 → 1.11.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.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { FirebaseDefaults } from './defaults';
18
+ export declare const getDefaultsFromPostinstall: () => FirebaseDefaults | undefined;
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * @license
7
+ * Copyright 2025 Google LLC
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ // This value is retrieved and hardcoded by the NPM postinstall script
22
+ const getDefaultsFromPostinstall = () => undefined;
23
+
24
+ exports.getDefaultsFromPostinstall = getDefaultsFromPostinstall;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ // This value is retrieved and hardcoded by the NPM postinstall script
18
+ const getDefaultsFromPostinstall = () => undefined;
19
+
20
+ export { getDefaultsFromPostinstall };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { FirebaseDefaults } from './defaults';
18
+ export declare const getDefaultsFromPostinstall: () => FirebaseDefaults | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firebase/util",
3
- "version": "1.10.3",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "main": "dist/index.node.cjs.js",
@@ -22,7 +22,8 @@
22
22
  "./package.json": "./package.json"
23
23
  },
24
24
  "files": [
25
- "dist"
25
+ "dist",
26
+ "postinstall.js"
26
27
  ],
27
28
  "scripts": {
28
29
  "lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
@@ -38,15 +39,17 @@
38
39
  "test:node": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* --config ../../config/mocharc.node.js",
39
40
  "trusted-type-check": "tsec -p tsconfig.json --noEmit",
40
41
  "api-report": "api-extractor run --local --verbose",
41
- "typings:public": "node ../../scripts/build/use_typings.js ./dist/util-public.d.ts"
42
+ "typings:public": "node ../../scripts/build/use_typings.js ./dist/util-public.d.ts",
43
+ "postinstall": "node ./postinstall.js"
42
44
  },
43
45
  "license": "Apache-2.0",
44
46
  "dependencies": {
45
47
  "tslib": "^2.1.0"
46
48
  },
47
49
  "devDependencies": {
48
- "rollup": "2.79.1",
49
- "rollup-plugin-typescript2": "0.31.2",
50
+ "@rollup/plugin-replace": "6.0.2",
51
+ "rollup": "2.79.2",
52
+ "rollup-plugin-typescript2": "0.36.0",
50
53
  "typescript": "5.5.4"
51
54
  },
52
55
  "repository": {
package/postinstall.js ADDED
@@ -0,0 +1,153 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ const { writeFile, readFile } = require('node:fs/promises');
19
+ const { pathToFileURL } = require('node:url');
20
+ const { isAbsolute, join } = require('node:path');
21
+
22
+ const ENV_VARIABLE = 'FIREBASE_WEBAPP_CONFIG';
23
+
24
+ async function getPartialConfig() {
25
+ const envVariable = process.env[ENV_VARIABLE]?.trim();
26
+
27
+ if (!envVariable) {
28
+ return undefined;
29
+ }
30
+
31
+ // Like FIREBASE_CONFIG (admin autoinit) FIREBASE_WEBAPP_CONFIG can be
32
+ // either a JSON representation of FirebaseOptions or the path to a filename
33
+ if (envVariable.startsWith('{"')) {
34
+ try {
35
+ return JSON.parse(envVariable);
36
+ } catch (e) {
37
+ console.warn(
38
+ `JSON payload in \$${ENV_VARIABLE} could not be parsed, ignoring.\n`,
39
+ e
40
+ );
41
+ return undefined;
42
+ }
43
+ }
44
+
45
+ const fileURL = pathToFileURL(
46
+ isAbsolute(envVariable) ? envVariable : join(process.cwd(), envVariable)
47
+ );
48
+
49
+ try {
50
+ const fileContents = await readFile(fileURL, 'utf-8');
51
+ return JSON.parse(fileContents);
52
+ } catch (e) {
53
+ console.warn(
54
+ `Contents of "${envVariable}" could not be parsed, ignoring \$${ENV_VARIABLE}.\n`,
55
+ e
56
+ );
57
+ return undefined;
58
+ }
59
+ }
60
+
61
+ async function getFinalConfig(partialConfig) {
62
+ if (!partialConfig) {
63
+ return undefined;
64
+ }
65
+ // In Firebase App Hosting the config provided to the environment variable is up-to-date and
66
+ // "complete" we should not reach out to the webConfig endpoint to freshen it
67
+ if (process.env.X_GOOGLE_TARGET_PLATFORM === 'fah') {
68
+ return partialConfig;
69
+ }
70
+ const projectId = partialConfig.projectId || '-';
71
+ // If the projectId starts with demo- this is an demo project from the firebase emulators
72
+ // treat the config as whole
73
+ if (projectId.startsWith('demo-')) {
74
+ return partialConfig;
75
+ }
76
+ const appId = partialConfig.appId;
77
+ const apiKey = partialConfig.apiKey;
78
+ if (!appId || !apiKey) {
79
+ console.warn(
80
+ `Unable to fetch Firebase config, appId and apiKey are required, ignoring \$${ENV_VARIABLE}.`
81
+ );
82
+ return undefined;
83
+ }
84
+
85
+ const url = `https://firebase.googleapis.com/v1alpha/projects/${projectId}/apps/${appId}/webConfig`;
86
+
87
+ try {
88
+ const response = await fetch(url, {
89
+ headers: { 'x-goog-api-key': apiKey }
90
+ });
91
+ if (!response.ok) {
92
+ console.warn(
93
+ `Unable to fetch Firebase config, ignoring \$${ENV_VARIABLE}.`
94
+ );
95
+ console.warn(
96
+ `${url} returned ${response.statusText} (${response.status})`
97
+ );
98
+ try {
99
+ console.warn((await response.json()).error.message);
100
+ } catch (e) {}
101
+ return undefined;
102
+ }
103
+ const json = await response.json();
104
+ return { ...json, apiKey };
105
+ } catch (e) {
106
+ console.warn(
107
+ `Unable to fetch Firebase config, ignoring \$${ENV_VARIABLE}.\n`,
108
+ e
109
+ );
110
+ return undefined;
111
+ }
112
+ }
113
+
114
+ function handleUnexpectedError(e) {
115
+ console.warn(
116
+ `Unexpected error encountered in @firebase/util postinstall script, ignoring \$${ENV_VARIABLE}.`
117
+ );
118
+ console.warn(e);
119
+ process.exit(0);
120
+ }
121
+
122
+ getPartialConfig()
123
+ .catch(handleUnexpectedError)
124
+ .then(getFinalConfig)
125
+ .catch(handleUnexpectedError)
126
+ .then(async finalConfig => {
127
+ const defaults = finalConfig && {
128
+ config: finalConfig,
129
+ emulatorHosts: {
130
+ firestore: process.env.FIRESTORE_EMULATOR_HOST,
131
+ database: process.env.FIREBASE_DATABASE_EMULATOR_HOST,
132
+ storage: process.env.FIREBASE_STORAGE_EMULATOR_HOST,
133
+ auth: process.env.FIREBASE_AUTH_EMULATOR_HOST
134
+ }
135
+ };
136
+
137
+ await Promise.all([
138
+ writeFile(
139
+ join(__dirname, 'dist', 'postinstall.js'),
140
+ `'use strict';
141
+ Object.defineProperty(exports, '__esModule', { value: true });
142
+ exports.getDefaultsFromPostinstall = () => (${JSON.stringify(defaults)});`
143
+ ),
144
+ writeFile(
145
+ join(__dirname, 'dist', 'postinstall.mjs'),
146
+ `const getDefaultsFromPostinstall = () => (${JSON.stringify(defaults)});
147
+ export { getDefaultsFromPostinstall };`
148
+ )
149
+ ]);
150
+
151
+ process.exit(0);
152
+ })
153
+ .catch(handleUnexpectedError);