@firebase/util 1.6.3 → 1.7.0-canary.9799efe9d
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm2017.js +185 -102
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +192 -105
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +194 -104
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.d.ts +1 -0
- package/dist/node-esm/index.d.ts +1 -0
- package/dist/node-esm/index.node.d.ts +1 -0
- package/dist/node-esm/index.node.esm.js +185 -102
- package/dist/node-esm/index.node.esm.js.map +1 -1
- package/dist/node-esm/src/defaults.d.ts +58 -0
- package/dist/src/defaults.d.ts +58 -0
- package/dist/util-public.d.ts +60 -0
- package/dist/util.d.ts +60 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @firebase/util
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`fdd4ab464`](https://github.com/firebase/firebase-js-sdk/commit/fdd4ab464b59a107bdcc195df3f01e32efd89ed4) [#6526](https://github.com/firebase/firebase-js-sdk/pull/6526) - Add functionality to auto-initialize project config and emulator settings from global defaults provided by framework tooling.
|
|
8
|
+
|
|
3
9
|
## 1.6.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from './src/assert';
|
|
|
18
18
|
export * from './src/crypt';
|
|
19
19
|
export * from './src/constants';
|
|
20
20
|
export * from './src/deepCopy';
|
|
21
|
+
export * from './src/defaults';
|
|
21
22
|
export * from './src/deferred';
|
|
22
23
|
export * from './src/emulator';
|
|
23
24
|
export * from './src/environment';
|
package/dist/index.esm2017.js
CHANGED
|
@@ -447,107 +447,6 @@ function isValidKey(key) {
|
|
|
447
447
|
return key !== '__proto__';
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
-
/**
|
|
451
|
-
* @license
|
|
452
|
-
* Copyright 2017 Google LLC
|
|
453
|
-
*
|
|
454
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
455
|
-
* you may not use this file except in compliance with the License.
|
|
456
|
-
* You may obtain a copy of the License at
|
|
457
|
-
*
|
|
458
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
459
|
-
*
|
|
460
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
461
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
462
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
463
|
-
* See the License for the specific language governing permissions and
|
|
464
|
-
* limitations under the License.
|
|
465
|
-
*/
|
|
466
|
-
class Deferred {
|
|
467
|
-
constructor() {
|
|
468
|
-
this.reject = () => { };
|
|
469
|
-
this.resolve = () => { };
|
|
470
|
-
this.promise = new Promise((resolve, reject) => {
|
|
471
|
-
this.resolve = resolve;
|
|
472
|
-
this.reject = reject;
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Our API internals are not promiseified and cannot because our callback APIs have subtle expectations around
|
|
477
|
-
* invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
|
|
478
|
-
* and returns a node-style callback which will resolve or reject the Deferred's promise.
|
|
479
|
-
*/
|
|
480
|
-
wrapCallback(callback) {
|
|
481
|
-
return (error, value) => {
|
|
482
|
-
if (error) {
|
|
483
|
-
this.reject(error);
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
this.resolve(value);
|
|
487
|
-
}
|
|
488
|
-
if (typeof callback === 'function') {
|
|
489
|
-
// Attaching noop handler just in case developer wasn't expecting
|
|
490
|
-
// promises
|
|
491
|
-
this.promise.catch(() => { });
|
|
492
|
-
// Some of our callbacks don't expect a value and our own tests
|
|
493
|
-
// assert that the parameter length is 1
|
|
494
|
-
if (callback.length === 1) {
|
|
495
|
-
callback(error);
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
callback(error, value);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* @license
|
|
507
|
-
* Copyright 2021 Google LLC
|
|
508
|
-
*
|
|
509
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
510
|
-
* you may not use this file except in compliance with the License.
|
|
511
|
-
* You may obtain a copy of the License at
|
|
512
|
-
*
|
|
513
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
514
|
-
*
|
|
515
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
516
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
517
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
518
|
-
* See the License for the specific language governing permissions and
|
|
519
|
-
* limitations under the License.
|
|
520
|
-
*/
|
|
521
|
-
function createMockUserToken(token, projectId) {
|
|
522
|
-
if (token.uid) {
|
|
523
|
-
throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');
|
|
524
|
-
}
|
|
525
|
-
// Unsecured JWTs use "none" as the algorithm.
|
|
526
|
-
const header = {
|
|
527
|
-
alg: 'none',
|
|
528
|
-
type: 'JWT'
|
|
529
|
-
};
|
|
530
|
-
const project = projectId || 'demo-project';
|
|
531
|
-
const iat = token.iat || 0;
|
|
532
|
-
const sub = token.sub || token.user_id;
|
|
533
|
-
if (!sub) {
|
|
534
|
-
throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
|
|
535
|
-
}
|
|
536
|
-
const payload = Object.assign({
|
|
537
|
-
// Set all required fields to decent defaults
|
|
538
|
-
iss: `https://securetoken.google.com/${project}`, aud: project, iat, exp: iat + 3600, auth_time: iat, sub, user_id: sub, firebase: {
|
|
539
|
-
sign_in_provider: 'custom',
|
|
540
|
-
identities: {}
|
|
541
|
-
} }, token);
|
|
542
|
-
// Unsecured JWTs use the empty string as a signature.
|
|
543
|
-
const signature = '';
|
|
544
|
-
return [
|
|
545
|
-
base64urlEncodeWithoutPadding(JSON.stringify(header)),
|
|
546
|
-
base64urlEncodeWithoutPadding(JSON.stringify(payload)),
|
|
547
|
-
signature
|
|
548
|
-
].join('.');
|
|
549
|
-
}
|
|
550
|
-
|
|
551
450
|
/**
|
|
552
451
|
* @license
|
|
553
452
|
* Copyright 2017 Google LLC
|
|
@@ -723,6 +622,190 @@ function getGlobal() {
|
|
|
723
622
|
throw new Error('Unable to locate global object.');
|
|
724
623
|
}
|
|
725
624
|
|
|
625
|
+
/**
|
|
626
|
+
* @license
|
|
627
|
+
* Copyright 2022 Google LLC
|
|
628
|
+
*
|
|
629
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
630
|
+
* you may not use this file except in compliance with the License.
|
|
631
|
+
* You may obtain a copy of the License at
|
|
632
|
+
*
|
|
633
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
634
|
+
*
|
|
635
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
636
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
637
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
638
|
+
* See the License for the specific language governing permissions and
|
|
639
|
+
* limitations under the License.
|
|
640
|
+
*/
|
|
641
|
+
const getDefaultsFromGlobal = () => getGlobal().__FIREBASE_DEFAULTS__;
|
|
642
|
+
/**
|
|
643
|
+
* Attempt to read defaults from a JSON string provided to
|
|
644
|
+
* process.env.__FIREBASE_DEFAULTS__ or a JSON file whose path is in
|
|
645
|
+
* process.env.__FIREBASE_DEFAULTS_PATH__
|
|
646
|
+
*/
|
|
647
|
+
const getDefaultsFromEnvVariable = () => {
|
|
648
|
+
if (typeof process === 'undefined') {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
const defaultsJsonString = process.env.__FIREBASE_DEFAULTS__;
|
|
652
|
+
const defaultsJsonPath = process.env.__FIREBASE_DEFAULTS_PATH__;
|
|
653
|
+
if (defaultsJsonString) {
|
|
654
|
+
if (defaultsJsonPath) {
|
|
655
|
+
console.warn(`Values were provided for both __FIREBASE_DEFAULTS__ ` +
|
|
656
|
+
`and __FIREBASE_DEFAULTS_PATH__. __FIREBASE_DEFAULTS_PATH__ ` +
|
|
657
|
+
`will be ignored.`);
|
|
658
|
+
}
|
|
659
|
+
return JSON.parse(defaultsJsonString);
|
|
660
|
+
}
|
|
661
|
+
if (defaultsJsonPath && typeof require !== 'undefined') {
|
|
662
|
+
try {
|
|
663
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
664
|
+
const json = require(defaultsJsonPath);
|
|
665
|
+
return json;
|
|
666
|
+
}
|
|
667
|
+
catch (e) {
|
|
668
|
+
console.warn(`Unable to read defaults from file provided to ` +
|
|
669
|
+
`__FIREBASE_DEFAULTS_PATH__: ${defaultsJsonPath}`);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
const getDefaultsFromCookie = () => {
|
|
674
|
+
if (typeof document === 'undefined') {
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const match = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
|
|
678
|
+
const decoded = match && base64Decode(match[1]);
|
|
679
|
+
return decoded && JSON.parse(decoded);
|
|
680
|
+
};
|
|
681
|
+
/**
|
|
682
|
+
* Get the __FIREBASE_DEFAULTS__ object. It checks in order:
|
|
683
|
+
* (1) if such an object exists as a property of `globalThis`
|
|
684
|
+
* (2) if such an object was provided on a shell environment variable
|
|
685
|
+
* (3) if such an object exists in a cookie
|
|
686
|
+
*/
|
|
687
|
+
const getDefaults = () => getDefaultsFromGlobal() ||
|
|
688
|
+
getDefaultsFromEnvVariable() ||
|
|
689
|
+
getDefaultsFromCookie();
|
|
690
|
+
/**
|
|
691
|
+
* Returns emulator host stored in the __FIREBASE_DEFAULTS__ object
|
|
692
|
+
* for the given product.
|
|
693
|
+
* @public
|
|
694
|
+
*/
|
|
695
|
+
const getDefaultEmulatorHost = (productName) => { var _a, _b; return (_b = (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.emulatorHosts) === null || _b === void 0 ? void 0 : _b[productName]; };
|
|
696
|
+
/**
|
|
697
|
+
* Returns Firebase app config stored in the __FIREBASE_DEFAULTS__ object.
|
|
698
|
+
* @public
|
|
699
|
+
*/
|
|
700
|
+
const getDefaultAppConfig = () => { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a.config; };
|
|
701
|
+
/**
|
|
702
|
+
* Returns an experimental setting on the __FIREBASE_DEFAULTS__ object (properties
|
|
703
|
+
* prefixed by "_")
|
|
704
|
+
* @public
|
|
705
|
+
*/
|
|
706
|
+
const getExperimentalSetting = (name) => { var _a; return (_a = getDefaults()) === null || _a === void 0 ? void 0 : _a[`_${name}`]; };
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* @license
|
|
710
|
+
* Copyright 2017 Google LLC
|
|
711
|
+
*
|
|
712
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
713
|
+
* you may not use this file except in compliance with the License.
|
|
714
|
+
* You may obtain a copy of the License at
|
|
715
|
+
*
|
|
716
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
717
|
+
*
|
|
718
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
719
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
720
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
721
|
+
* See the License for the specific language governing permissions and
|
|
722
|
+
* limitations under the License.
|
|
723
|
+
*/
|
|
724
|
+
class Deferred {
|
|
725
|
+
constructor() {
|
|
726
|
+
this.reject = () => { };
|
|
727
|
+
this.resolve = () => { };
|
|
728
|
+
this.promise = new Promise((resolve, reject) => {
|
|
729
|
+
this.resolve = resolve;
|
|
730
|
+
this.reject = reject;
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Our API internals are not promiseified and cannot because our callback APIs have subtle expectations around
|
|
735
|
+
* invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
|
|
736
|
+
* and returns a node-style callback which will resolve or reject the Deferred's promise.
|
|
737
|
+
*/
|
|
738
|
+
wrapCallback(callback) {
|
|
739
|
+
return (error, value) => {
|
|
740
|
+
if (error) {
|
|
741
|
+
this.reject(error);
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
this.resolve(value);
|
|
745
|
+
}
|
|
746
|
+
if (typeof callback === 'function') {
|
|
747
|
+
// Attaching noop handler just in case developer wasn't expecting
|
|
748
|
+
// promises
|
|
749
|
+
this.promise.catch(() => { });
|
|
750
|
+
// Some of our callbacks don't expect a value and our own tests
|
|
751
|
+
// assert that the parameter length is 1
|
|
752
|
+
if (callback.length === 1) {
|
|
753
|
+
callback(error);
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
callback(error, value);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* @license
|
|
765
|
+
* Copyright 2021 Google LLC
|
|
766
|
+
*
|
|
767
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
768
|
+
* you may not use this file except in compliance with the License.
|
|
769
|
+
* You may obtain a copy of the License at
|
|
770
|
+
*
|
|
771
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
772
|
+
*
|
|
773
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
774
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
775
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
776
|
+
* See the License for the specific language governing permissions and
|
|
777
|
+
* limitations under the License.
|
|
778
|
+
*/
|
|
779
|
+
function createMockUserToken(token, projectId) {
|
|
780
|
+
if (token.uid) {
|
|
781
|
+
throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');
|
|
782
|
+
}
|
|
783
|
+
// Unsecured JWTs use "none" as the algorithm.
|
|
784
|
+
const header = {
|
|
785
|
+
alg: 'none',
|
|
786
|
+
type: 'JWT'
|
|
787
|
+
};
|
|
788
|
+
const project = projectId || 'demo-project';
|
|
789
|
+
const iat = token.iat || 0;
|
|
790
|
+
const sub = token.sub || token.user_id;
|
|
791
|
+
if (!sub) {
|
|
792
|
+
throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");
|
|
793
|
+
}
|
|
794
|
+
const payload = Object.assign({
|
|
795
|
+
// Set all required fields to decent defaults
|
|
796
|
+
iss: `https://securetoken.google.com/${project}`, aud: project, iat, exp: iat + 3600, auth_time: iat, sub, user_id: sub, firebase: {
|
|
797
|
+
sign_in_provider: 'custom',
|
|
798
|
+
identities: {}
|
|
799
|
+
} }, token);
|
|
800
|
+
// Unsecured JWTs use the empty string as a signature.
|
|
801
|
+
const signature = '';
|
|
802
|
+
return [
|
|
803
|
+
base64urlEncodeWithoutPadding(JSON.stringify(header)),
|
|
804
|
+
base64urlEncodeWithoutPadding(JSON.stringify(payload)),
|
|
805
|
+
signature
|
|
806
|
+
].join('.');
|
|
807
|
+
}
|
|
808
|
+
|
|
726
809
|
/**
|
|
727
810
|
* @license
|
|
728
811
|
* Copyright 2017 Google LLC
|
|
@@ -1950,5 +2033,5 @@ function getModularInstance(service) {
|
|
|
1950
2033
|
}
|
|
1951
2034
|
}
|
|
1952
2035
|
|
|
1953
|
-
export { CONSTANTS, Deferred, ErrorFactory, FirebaseError, MAX_VALUE_MILLIS, RANDOM_FACTOR, Sha1, areCookiesEnabled, assert, assertionError, async, base64, base64Decode, base64Encode, base64urlEncodeWithoutPadding, calculateBackoffMillis, contains, createMockUserToken, createSubscribe, decode, deepCopy, deepEqual, deepExtend, errorPrefix, extractQuerystring, getGlobal, getModularInstance, getUA, isAdmin, isBrowser, isBrowserExtension, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
|
|
2036
|
+
export { CONSTANTS, Deferred, ErrorFactory, FirebaseError, MAX_VALUE_MILLIS, RANDOM_FACTOR, Sha1, areCookiesEnabled, assert, assertionError, async, base64, base64Decode, base64Encode, base64urlEncodeWithoutPadding, calculateBackoffMillis, contains, createMockUserToken, createSubscribe, decode, deepCopy, deepEqual, deepExtend, errorPrefix, extractQuerystring, getDefaultAppConfig, getDefaultEmulatorHost, getExperimentalSetting, getGlobal, getModularInstance, getUA, isAdmin, isBrowser, isBrowserExtension, isElectron, isEmpty, isIE, isIndexedDBAvailable, isMobileCordova, isNode, isNodeSdk, isReactNative, isSafari, isUWP, isValidFormat, isValidTimestamp, issuedAtTime, jsonEval, map, ordinal, promiseWithTimeout, querystring, querystringDecode, safeGet, stringLength, stringToByteArray, stringify, uuidv4, validateArgCount, validateCallback, validateContextObject, validateIndexedDBOpenable, validateNamespace };
|
|
1954
2037
|
//# sourceMappingURL=index.esm2017.js.map
|