@firebase/installations 0.5.5 → 0.5.6-2022216223411
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 +13 -0
- package/dist/esm/index.esm.js +71 -52
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/index.esm2017.js +49 -36
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/api/on-id-change.d.ts +1 -1
- package/dist/esm/src/functions/create-installation-request.d.ts +2 -2
- package/dist/esm/src/functions/generate-auth-token-request.d.ts +1 -1
- package/dist/esm/src/helpers/get-installation-entry.d.ts +2 -2
- package/dist/esm/src/interfaces/installation-impl.d.ts +1 -1
- package/dist/index.cjs.js +70 -51
- package/dist/index.cjs.js.map +1 -1
- package/dist/installations-public.d.ts +1 -1
- package/dist/installations.d.ts +1 -1
- package/dist/src/api/on-id-change.d.ts +1 -1
- package/dist/src/functions/create-installation-request.d.ts +2 -2
- package/dist/src/functions/generate-auth-token-request.d.ts +1 -1
- package/dist/src/helpers/get-installation-entry.d.ts +2 -2
- package/dist/src/interfaces/installation-impl.d.ts +1 -1
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @firebase/installations
|
|
2
2
|
|
|
3
|
+
## 0.5.6-2022216223411
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2d672cead`](https://github.com/firebase/firebase-js-sdk/commit/2d672cead167187cb714cd89b638c0884ba58f03) [#6061](https://github.com/firebase/firebase-js-sdk/pull/6061) - Remove idb dependency and replace with our own code.
|
|
8
|
+
|
|
9
|
+
* [`ddeff8384`](https://github.com/firebase/firebase-js-sdk/commit/ddeff8384ab8a927f02244e2591db525fd58c7dd) [#5966](https://github.com/firebase/firebase-js-sdk/pull/5966) - Update platform logging code to send to new endpoint.
|
|
10
|
+
|
|
11
|
+
* Updated dependencies [[`2d672cead`](https://github.com/firebase/firebase-js-sdk/commit/2d672cead167187cb714cd89b638c0884ba58f03), [`927c1afc1`](https://github.com/firebase/firebase-js-sdk/commit/927c1afc103e4f9b8a75320d3946a4c840445a2a)]:
|
|
12
|
+
- @firebase/app@0.7.19-2022216223411
|
|
13
|
+
- @firebase/util@1.5.0-2022216223411
|
|
14
|
+
- @firebase/component@0.5.11-2022216223411
|
|
15
|
+
|
|
3
16
|
## 0.5.5
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { getApp, _getProvider, _registerComponent, registerVersion } from '@firebase/app';
|
|
2
2
|
import { Component } from '@firebase/component';
|
|
3
3
|
import { __awaiter, __generator, __spreadArray, __read, __values, __assign } from 'tslib';
|
|
4
|
-
import { ErrorFactory, FirebaseError } from '@firebase/util';
|
|
5
|
-
import { openDb } from 'idb';
|
|
4
|
+
import { ErrorFactory, FirebaseError, openDB } from '@firebase/util';
|
|
6
5
|
|
|
7
6
|
var name = "@firebase/installations";
|
|
8
|
-
var version = "0.5.
|
|
7
|
+
var version = "0.5.6-2022216223411";
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* @license
|
|
@@ -170,15 +169,28 @@ function getAuthorizationHeader(refreshToken) {
|
|
|
170
169
|
* See the License for the specific language governing permissions and
|
|
171
170
|
* limitations under the License.
|
|
172
171
|
*/
|
|
173
|
-
function createInstallationRequest(
|
|
174
|
-
var
|
|
172
|
+
function createInstallationRequest(_a, _b) {
|
|
173
|
+
var appConfig = _a.appConfig, heartbeatServiceProvider = _a.heartbeatServiceProvider;
|
|
174
|
+
var fid = _b.fid;
|
|
175
175
|
return __awaiter(this, void 0, void 0, function () {
|
|
176
|
-
var endpoint, headers, body, request, response, responseValue, registeredInstallationEntry;
|
|
177
|
-
return __generator(this, function (
|
|
178
|
-
switch (
|
|
176
|
+
var endpoint, headers, heartbeatService, heartbeatsHeader, body, request, response, responseValue, registeredInstallationEntry;
|
|
177
|
+
return __generator(this, function (_c) {
|
|
178
|
+
switch (_c.label) {
|
|
179
179
|
case 0:
|
|
180
180
|
endpoint = getInstallationsEndpoint(appConfig);
|
|
181
181
|
headers = getHeaders(appConfig);
|
|
182
|
+
heartbeatService = heartbeatServiceProvider.getImmediate({
|
|
183
|
+
optional: true
|
|
184
|
+
});
|
|
185
|
+
if (!heartbeatService) return [3 /*break*/, 2];
|
|
186
|
+
return [4 /*yield*/, heartbeatService.getHeartbeatsHeader()];
|
|
187
|
+
case 1:
|
|
188
|
+
heartbeatsHeader = _c.sent();
|
|
189
|
+
if (heartbeatsHeader) {
|
|
190
|
+
headers.append('x-firebase-client', heartbeatsHeader);
|
|
191
|
+
}
|
|
192
|
+
_c.label = 2;
|
|
193
|
+
case 2:
|
|
182
194
|
body = {
|
|
183
195
|
fid: fid,
|
|
184
196
|
authVersion: INTERNAL_AUTH_VERSION,
|
|
@@ -191,12 +203,12 @@ function createInstallationRequest(appConfig, _a) {
|
|
|
191
203
|
body: JSON.stringify(body)
|
|
192
204
|
};
|
|
193
205
|
return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];
|
|
194
|
-
case
|
|
195
|
-
response =
|
|
196
|
-
if (!response.ok) return [3 /*break*/,
|
|
206
|
+
case 3:
|
|
207
|
+
response = _c.sent();
|
|
208
|
+
if (!response.ok) return [3 /*break*/, 5];
|
|
197
209
|
return [4 /*yield*/, response.json()];
|
|
198
|
-
case
|
|
199
|
-
responseValue =
|
|
210
|
+
case 4:
|
|
211
|
+
responseValue = _c.sent();
|
|
200
212
|
registeredInstallationEntry = {
|
|
201
213
|
fid: responseValue.fid || fid,
|
|
202
214
|
registrationStatus: 2 /* COMPLETED */,
|
|
@@ -204,8 +216,8 @@ function createInstallationRequest(appConfig, _a) {
|
|
|
204
216
|
authToken: extractAuthTokenInfoFromResponse(responseValue.authToken)
|
|
205
217
|
};
|
|
206
218
|
return [2 /*return*/, registeredInstallationEntry];
|
|
207
|
-
case
|
|
208
|
-
case
|
|
219
|
+
case 5: return [4 /*yield*/, getErrorFromResponse('Create Installation', response)];
|
|
220
|
+
case 6: throw _c.sent();
|
|
209
221
|
}
|
|
210
222
|
});
|
|
211
223
|
});
|
|
@@ -441,15 +453,15 @@ var OBJECT_STORE_NAME = 'firebase-installations-store';
|
|
|
441
453
|
var dbPromise = null;
|
|
442
454
|
function getDbPromise() {
|
|
443
455
|
if (!dbPromise) {
|
|
444
|
-
dbPromise =
|
|
456
|
+
dbPromise = openDB(DATABASE_NAME, DATABASE_VERSION, function (db, oldVersion) {
|
|
445
457
|
// We don't use 'break' in this switch statement, the fall-through
|
|
446
458
|
// behavior is what we want, because if there are multiple versions between
|
|
447
459
|
// the old version and the current version, we want ALL the migrations
|
|
448
460
|
// that correspond to those versions to run, not only the last one.
|
|
449
461
|
// eslint-disable-next-line default-case
|
|
450
|
-
switch (
|
|
462
|
+
switch (oldVersion) {
|
|
451
463
|
case 0:
|
|
452
|
-
|
|
464
|
+
db.createObjectStore(OBJECT_STORE_NAME);
|
|
453
465
|
}
|
|
454
466
|
});
|
|
455
467
|
}
|
|
@@ -470,7 +482,7 @@ function set(appConfig, value) {
|
|
|
470
482
|
objectStore = tx.objectStore(OBJECT_STORE_NAME);
|
|
471
483
|
return [4 /*yield*/, objectStore.get(key)];
|
|
472
484
|
case 2:
|
|
473
|
-
oldValue = _a.sent();
|
|
485
|
+
oldValue = (_a.sent());
|
|
474
486
|
return [4 /*yield*/, objectStore.put(value, key)];
|
|
475
487
|
case 3:
|
|
476
488
|
_a.sent();
|
|
@@ -528,7 +540,7 @@ function update(appConfig, updateFn) {
|
|
|
528
540
|
store = tx.objectStore(OBJECT_STORE_NAME);
|
|
529
541
|
return [4 /*yield*/, store.get(key)];
|
|
530
542
|
case 2:
|
|
531
|
-
oldValue = _a.sent();
|
|
543
|
+
oldValue = (_a.sent());
|
|
532
544
|
newValue = updateFn(oldValue);
|
|
533
545
|
if (!(newValue === undefined)) return [3 /*break*/, 4];
|
|
534
546
|
return [4 /*yield*/, store.delete(key)];
|
|
@@ -571,15 +583,15 @@ function update(appConfig, updateFn) {
|
|
|
571
583
|
* Updates and returns the InstallationEntry from the database.
|
|
572
584
|
* Also triggers a registration request if it is necessary and possible.
|
|
573
585
|
*/
|
|
574
|
-
function getInstallationEntry(
|
|
586
|
+
function getInstallationEntry(installations) {
|
|
575
587
|
return __awaiter(this, void 0, void 0, function () {
|
|
576
588
|
var registrationPromise, installationEntry;
|
|
577
589
|
var _a;
|
|
578
590
|
return __generator(this, function (_b) {
|
|
579
591
|
switch (_b.label) {
|
|
580
|
-
case 0: return [4 /*yield*/, update(appConfig, function (oldEntry) {
|
|
592
|
+
case 0: return [4 /*yield*/, update(installations.appConfig, function (oldEntry) {
|
|
581
593
|
var installationEntry = updateOrCreateInstallationEntry(oldEntry);
|
|
582
|
-
var entryWithPromise = triggerRegistrationIfNecessary(
|
|
594
|
+
var entryWithPromise = triggerRegistrationIfNecessary(installations, installationEntry);
|
|
583
595
|
registrationPromise = entryWithPromise.registrationPromise;
|
|
584
596
|
return entryWithPromise.installationEntry;
|
|
585
597
|
})];
|
|
@@ -617,7 +629,7 @@ function updateOrCreateInstallationEntry(oldEntry) {
|
|
|
617
629
|
* If registrationPromise does not exist, the installationEntry is guaranteed
|
|
618
630
|
* to be registered.
|
|
619
631
|
*/
|
|
620
|
-
function triggerRegistrationIfNecessary(
|
|
632
|
+
function triggerRegistrationIfNecessary(installations, installationEntry) {
|
|
621
633
|
if (installationEntry.registrationStatus === 0 /* NOT_STARTED */) {
|
|
622
634
|
if (!navigator.onLine) {
|
|
623
635
|
// Registration required but app is offline.
|
|
@@ -633,13 +645,13 @@ function triggerRegistrationIfNecessary(appConfig, installationEntry) {
|
|
|
633
645
|
registrationStatus: 1 /* IN_PROGRESS */,
|
|
634
646
|
registrationTime: Date.now()
|
|
635
647
|
};
|
|
636
|
-
var registrationPromise = registerInstallation(
|
|
648
|
+
var registrationPromise = registerInstallation(installations, inProgressEntry);
|
|
637
649
|
return { installationEntry: inProgressEntry, registrationPromise: registrationPromise };
|
|
638
650
|
}
|
|
639
651
|
else if (installationEntry.registrationStatus === 1 /* IN_PROGRESS */) {
|
|
640
652
|
return {
|
|
641
653
|
installationEntry: installationEntry,
|
|
642
|
-
registrationPromise: waitUntilFidRegistration(
|
|
654
|
+
registrationPromise: waitUntilFidRegistration(installations)
|
|
643
655
|
};
|
|
644
656
|
}
|
|
645
657
|
else {
|
|
@@ -647,23 +659,23 @@ function triggerRegistrationIfNecessary(appConfig, installationEntry) {
|
|
|
647
659
|
}
|
|
648
660
|
}
|
|
649
661
|
/** This will be executed only once for each new Firebase Installation. */
|
|
650
|
-
function registerInstallation(
|
|
662
|
+
function registerInstallation(installations, installationEntry) {
|
|
651
663
|
return __awaiter(this, void 0, void 0, function () {
|
|
652
664
|
var registeredInstallationEntry, e_1;
|
|
653
665
|
return __generator(this, function (_a) {
|
|
654
666
|
switch (_a.label) {
|
|
655
667
|
case 0:
|
|
656
668
|
_a.trys.push([0, 2, , 7]);
|
|
657
|
-
return [4 /*yield*/, createInstallationRequest(
|
|
669
|
+
return [4 /*yield*/, createInstallationRequest(installations, installationEntry)];
|
|
658
670
|
case 1:
|
|
659
671
|
registeredInstallationEntry = _a.sent();
|
|
660
|
-
return [2 /*return*/, set(appConfig, registeredInstallationEntry)];
|
|
672
|
+
return [2 /*return*/, set(installations.appConfig, registeredInstallationEntry)];
|
|
661
673
|
case 2:
|
|
662
674
|
e_1 = _a.sent();
|
|
663
675
|
if (!(isServerError(e_1) && e_1.customData.serverCode === 409)) return [3 /*break*/, 4];
|
|
664
676
|
// Server returned a "FID can not be used" error.
|
|
665
677
|
// Generate a new ID next time.
|
|
666
|
-
return [4 /*yield*/, remove(appConfig)];
|
|
678
|
+
return [4 /*yield*/, remove(installations.appConfig)];
|
|
667
679
|
case 3:
|
|
668
680
|
// Server returned a "FID can not be used" error.
|
|
669
681
|
// Generate a new ID next time.
|
|
@@ -671,7 +683,7 @@ function registerInstallation(appConfig, installationEntry) {
|
|
|
671
683
|
return [3 /*break*/, 6];
|
|
672
684
|
case 4:
|
|
673
685
|
// Registration failed. Set FID as not registered.
|
|
674
|
-
return [4 /*yield*/, set(appConfig, {
|
|
686
|
+
return [4 /*yield*/, set(installations.appConfig, {
|
|
675
687
|
fid: installationEntry.fid,
|
|
676
688
|
registrationStatus: 0 /* NOT_STARTED */
|
|
677
689
|
})];
|
|
@@ -686,12 +698,12 @@ function registerInstallation(appConfig, installationEntry) {
|
|
|
686
698
|
});
|
|
687
699
|
}
|
|
688
700
|
/** Call if FID registration is pending in another request. */
|
|
689
|
-
function waitUntilFidRegistration(
|
|
701
|
+
function waitUntilFidRegistration(installations) {
|
|
690
702
|
return __awaiter(this, void 0, void 0, function () {
|
|
691
703
|
var entry, _a, installationEntry, registrationPromise;
|
|
692
704
|
return __generator(this, function (_b) {
|
|
693
705
|
switch (_b.label) {
|
|
694
|
-
case 0: return [4 /*yield*/, updateInstallationRequest(appConfig)];
|
|
706
|
+
case 0: return [4 /*yield*/, updateInstallationRequest(installations.appConfig)];
|
|
695
707
|
case 1:
|
|
696
708
|
entry = _b.sent();
|
|
697
709
|
_b.label = 2;
|
|
@@ -702,13 +714,13 @@ function waitUntilFidRegistration(appConfig) {
|
|
|
702
714
|
case 3:
|
|
703
715
|
// createInstallation request still in progress.
|
|
704
716
|
_b.sent();
|
|
705
|
-
return [4 /*yield*/, updateInstallationRequest(appConfig)];
|
|
717
|
+
return [4 /*yield*/, updateInstallationRequest(installations.appConfig)];
|
|
706
718
|
case 4:
|
|
707
719
|
entry = _b.sent();
|
|
708
720
|
return [3 /*break*/, 2];
|
|
709
721
|
case 5:
|
|
710
722
|
if (!(entry.registrationStatus === 0 /* NOT_STARTED */)) return [3 /*break*/, 7];
|
|
711
|
-
return [4 /*yield*/, getInstallationEntry(
|
|
723
|
+
return [4 /*yield*/, getInstallationEntry(installations)];
|
|
712
724
|
case 6:
|
|
713
725
|
_a = _b.sent(), installationEntry = _a.installationEntry, registrationPromise = _a.registrationPromise;
|
|
714
726
|
if (registrationPromise) {
|
|
@@ -770,23 +782,30 @@ function hasInstallationRequestTimedOut(installationEntry) {
|
|
|
770
782
|
* limitations under the License.
|
|
771
783
|
*/
|
|
772
784
|
function generateAuthTokenRequest(_a, installationEntry) {
|
|
773
|
-
var appConfig = _a.appConfig,
|
|
785
|
+
var appConfig = _a.appConfig, heartbeatServiceProvider = _a.heartbeatServiceProvider;
|
|
774
786
|
return __awaiter(this, void 0, void 0, function () {
|
|
775
|
-
var endpoint, headers,
|
|
787
|
+
var endpoint, headers, heartbeatService, heartbeatsHeader, body, request, response, responseValue, completedAuthToken;
|
|
776
788
|
return __generator(this, function (_b) {
|
|
777
789
|
switch (_b.label) {
|
|
778
790
|
case 0:
|
|
779
791
|
endpoint = getGenerateAuthTokenEndpoint(appConfig, installationEntry);
|
|
780
792
|
headers = getHeadersWithAuth(appConfig, installationEntry);
|
|
781
|
-
|
|
793
|
+
heartbeatService = heartbeatServiceProvider.getImmediate({
|
|
782
794
|
optional: true
|
|
783
795
|
});
|
|
784
|
-
if (
|
|
785
|
-
|
|
796
|
+
if (!heartbeatService) return [3 /*break*/, 2];
|
|
797
|
+
return [4 /*yield*/, heartbeatService.getHeartbeatsHeader()];
|
|
798
|
+
case 1:
|
|
799
|
+
heartbeatsHeader = _b.sent();
|
|
800
|
+
if (heartbeatsHeader) {
|
|
801
|
+
headers.append('x-firebase-client', heartbeatsHeader);
|
|
786
802
|
}
|
|
803
|
+
_b.label = 2;
|
|
804
|
+
case 2:
|
|
787
805
|
body = {
|
|
788
806
|
installation: {
|
|
789
|
-
sdkVersion: PACKAGE_VERSION
|
|
807
|
+
sdkVersion: PACKAGE_VERSION,
|
|
808
|
+
appId: appConfig.appId
|
|
790
809
|
}
|
|
791
810
|
};
|
|
792
811
|
request = {
|
|
@@ -795,16 +814,16 @@ function generateAuthTokenRequest(_a, installationEntry) {
|
|
|
795
814
|
body: JSON.stringify(body)
|
|
796
815
|
};
|
|
797
816
|
return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];
|
|
798
|
-
case
|
|
817
|
+
case 3:
|
|
799
818
|
response = _b.sent();
|
|
800
|
-
if (!response.ok) return [3 /*break*/,
|
|
819
|
+
if (!response.ok) return [3 /*break*/, 5];
|
|
801
820
|
return [4 /*yield*/, response.json()];
|
|
802
|
-
case
|
|
821
|
+
case 4:
|
|
803
822
|
responseValue = _b.sent();
|
|
804
823
|
completedAuthToken = extractAuthTokenInfoFromResponse(responseValue);
|
|
805
824
|
return [2 /*return*/, completedAuthToken];
|
|
806
|
-
case
|
|
807
|
-
case
|
|
825
|
+
case 5: return [4 /*yield*/, getErrorFromResponse('Generate Auth Token', response)];
|
|
826
|
+
case 6: throw _b.sent();
|
|
808
827
|
}
|
|
809
828
|
});
|
|
810
829
|
});
|
|
@@ -1037,7 +1056,7 @@ function getId(installations) {
|
|
|
1037
1056
|
switch (_b.label) {
|
|
1038
1057
|
case 0:
|
|
1039
1058
|
installationsImpl = installations;
|
|
1040
|
-
return [4 /*yield*/, getInstallationEntry(installationsImpl
|
|
1059
|
+
return [4 /*yield*/, getInstallationEntry(installationsImpl)];
|
|
1041
1060
|
case 1:
|
|
1042
1061
|
_a = _b.sent(), installationEntry = _a.installationEntry, registrationPromise = _a.registrationPromise;
|
|
1043
1062
|
if (registrationPromise) {
|
|
@@ -1086,7 +1105,7 @@ function getToken(installations, forceRefresh) {
|
|
|
1086
1105
|
switch (_a.label) {
|
|
1087
1106
|
case 0:
|
|
1088
1107
|
installationsImpl = installations;
|
|
1089
|
-
return [4 /*yield*/, completeInstallationRegistration(installationsImpl
|
|
1108
|
+
return [4 /*yield*/, completeInstallationRegistration(installationsImpl)];
|
|
1090
1109
|
case 1:
|
|
1091
1110
|
_a.sent();
|
|
1092
1111
|
return [4 /*yield*/, refreshAuthToken(installationsImpl, forceRefresh)];
|
|
@@ -1097,12 +1116,12 @@ function getToken(installations, forceRefresh) {
|
|
|
1097
1116
|
});
|
|
1098
1117
|
});
|
|
1099
1118
|
}
|
|
1100
|
-
function completeInstallationRegistration(
|
|
1119
|
+
function completeInstallationRegistration(installations) {
|
|
1101
1120
|
return __awaiter(this, void 0, void 0, function () {
|
|
1102
1121
|
var registrationPromise;
|
|
1103
1122
|
return __generator(this, function (_a) {
|
|
1104
1123
|
switch (_a.label) {
|
|
1105
|
-
case 0: return [4 /*yield*/, getInstallationEntry(
|
|
1124
|
+
case 0: return [4 /*yield*/, getInstallationEntry(installations)];
|
|
1106
1125
|
case 1:
|
|
1107
1126
|
registrationPromise = (_a.sent()).registrationPromise;
|
|
1108
1127
|
if (!registrationPromise) return [3 /*break*/, 3];
|
|
@@ -1363,11 +1382,11 @@ var publicFactory = function (container) {
|
|
|
1363
1382
|
var app = container.getProvider('app').getImmediate();
|
|
1364
1383
|
// Throws if app isn't configured properly.
|
|
1365
1384
|
var appConfig = extractAppConfig(app);
|
|
1366
|
-
var
|
|
1385
|
+
var heartbeatServiceProvider = _getProvider(app, 'heartbeat');
|
|
1367
1386
|
var installationsImpl = {
|
|
1368
1387
|
app: app,
|
|
1369
1388
|
appConfig: appConfig,
|
|
1370
|
-
|
|
1389
|
+
heartbeatServiceProvider: heartbeatServiceProvider,
|
|
1371
1390
|
_delete: function () { return Promise.resolve(); }
|
|
1372
1391
|
};
|
|
1373
1392
|
return installationsImpl;
|