@firebase/firestore 3.3.1 → 3.4.0-2021111174650

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/firestore/src/api/credentials.d.ts +64 -30
  3. package/dist/firestore/src/api/database.d.ts +2 -1
  4. package/dist/firestore/src/api.d.ts +2 -1
  5. package/dist/firestore/src/core/component_provider.d.ts +2 -1
  6. package/dist/firestore/src/core/firestore_client.d.ts +4 -3
  7. package/dist/firestore/src/lite-api/components.d.ts +3 -1
  8. package/dist/firestore/src/lite-api/database.d.ts +4 -2
  9. package/dist/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  10. package/dist/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  11. package/dist/firestore/src/remote/connection.d.ts +3 -3
  12. package/dist/firestore/src/remote/datastore.d.ts +2 -1
  13. package/dist/firestore/src/remote/persistent_stream.d.ts +9 -7
  14. package/dist/firestore/src/remote/rest_connection.d.ts +4 -4
  15. package/dist/firestore/test/integration/remote/stream.test.d.ts +2 -2
  16. package/dist/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  17. package/dist/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.esm2017.js +3398 -3344
  20. package/dist/index.esm2017.js.map +1 -1
  21. package/dist/index.esm5.js +3673 -3624
  22. package/dist/index.esm5.js.map +1 -1
  23. package/dist/index.node.cjs.js +188 -95
  24. package/dist/index.node.cjs.js.map +1 -1
  25. package/dist/index.node.mjs +187 -95
  26. package/dist/index.node.mjs.map +1 -1
  27. package/dist/index.rn.js +3391 -3337
  28. package/dist/index.rn.js.map +1 -1
  29. package/dist/internal.d.ts +34 -20
  30. package/dist/lite/firestore/src/api/credentials.d.ts +64 -30
  31. package/dist/lite/firestore/src/api/database.d.ts +2 -1
  32. package/dist/lite/firestore/src/api.d.ts +2 -1
  33. package/dist/lite/firestore/src/core/component_provider.d.ts +2 -1
  34. package/dist/lite/firestore/src/core/firestore_client.d.ts +4 -3
  35. package/dist/lite/firestore/src/lite-api/components.d.ts +3 -1
  36. package/dist/lite/firestore/src/lite-api/database.d.ts +4 -2
  37. package/dist/lite/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  38. package/dist/lite/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  39. package/dist/lite/firestore/src/remote/connection.d.ts +3 -3
  40. package/dist/lite/firestore/src/remote/datastore.d.ts +2 -1
  41. package/dist/lite/firestore/src/remote/persistent_stream.d.ts +9 -7
  42. package/dist/lite/firestore/src/remote/rest_connection.d.ts +4 -4
  43. package/dist/lite/firestore/test/integration/remote/stream.test.d.ts +2 -2
  44. package/dist/lite/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  45. package/dist/lite/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  46. package/dist/lite/index.browser.esm2017.js +1378 -1364
  47. package/dist/lite/index.browser.esm2017.js.map +1 -1
  48. package/dist/lite/index.browser.esm5.js +933 -924
  49. package/dist/lite/index.browser.esm5.js.map +1 -1
  50. package/dist/lite/index.node.cjs.js +95 -60
  51. package/dist/lite/index.node.cjs.js.map +1 -1
  52. package/dist/lite/index.node.mjs +95 -60
  53. package/dist/lite/index.node.mjs.map +1 -1
  54. package/dist/lite/index.rn.esm2017.js +924 -910
  55. package/dist/lite/index.rn.esm2017.js.map +1 -1
  56. package/dist/lite/internal.d.ts +14 -13
  57. package/dist/lite/packages/firestore/dist/lite/index.browser.esm2017.d.ts +150 -149
  58. package/dist/lite/packages/firestore/src/api/credentials.d.ts +64 -30
  59. package/dist/lite/packages/firestore/src/api/database.d.ts +2 -1
  60. package/dist/lite/packages/firestore/src/api.d.ts +2 -1
  61. package/dist/lite/packages/firestore/src/core/component_provider.d.ts +2 -1
  62. package/dist/lite/packages/firestore/src/core/firestore_client.d.ts +4 -3
  63. package/dist/lite/packages/firestore/src/lite-api/components.d.ts +3 -1
  64. package/dist/lite/packages/firestore/src/lite-api/database.d.ts +4 -2
  65. package/dist/lite/packages/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  66. package/dist/lite/packages/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  67. package/dist/lite/packages/firestore/src/remote/connection.d.ts +3 -3
  68. package/dist/lite/packages/firestore/src/remote/datastore.d.ts +2 -1
  69. package/dist/lite/packages/firestore/src/remote/persistent_stream.d.ts +9 -7
  70. package/dist/lite/packages/firestore/src/remote/rest_connection.d.ts +4 -4
  71. package/dist/lite/packages/firestore/test/integration/remote/stream.test.d.ts +2 -2
  72. package/dist/lite/packages/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  73. package/dist/lite/packages/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  74. package/dist/lite/private.d.ts +14 -13
  75. package/dist/packages/firestore/dist/index.esm2017.d.ts +211 -195
  76. package/dist/packages/firestore/src/api/credentials.d.ts +64 -30
  77. package/dist/packages/firestore/src/api/database.d.ts +2 -1
  78. package/dist/packages/firestore/src/api.d.ts +2 -1
  79. package/dist/packages/firestore/src/core/component_provider.d.ts +2 -1
  80. package/dist/packages/firestore/src/core/firestore_client.d.ts +4 -3
  81. package/dist/packages/firestore/src/lite-api/components.d.ts +3 -1
  82. package/dist/packages/firestore/src/lite-api/database.d.ts +4 -2
  83. package/dist/packages/firestore/src/platform/browser/webchannel_connection.d.ts +1 -1
  84. package/dist/packages/firestore/src/platform/node/grpc_connection.d.ts +3 -3
  85. package/dist/packages/firestore/src/remote/connection.d.ts +3 -3
  86. package/dist/packages/firestore/src/remote/datastore.d.ts +2 -1
  87. package/dist/packages/firestore/src/remote/persistent_stream.d.ts +9 -7
  88. package/dist/packages/firestore/src/remote/rest_connection.d.ts +4 -4
  89. package/dist/packages/firestore/test/integration/remote/stream.test.d.ts +2 -2
  90. package/dist/packages/firestore/test/integration/util/internal_helpers.d.ts +5 -5
  91. package/dist/packages/firestore/test/unit/remote/rest_connection.test.d.ts +1 -1
  92. package/dist/private.d.ts +24 -19
  93. package/package.json +1 -1
@@ -14,7 +14,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
14
14
 
15
15
  var nodeFetch__default = /*#__PURE__*/_interopDefaultLegacy(nodeFetch);
16
16
 
17
- const version$1 = "3.3.1";
17
+ const version$1 = "3.4.0-2021111174650";
18
18
 
19
19
  /**
20
20
  * @license
@@ -67,7 +67,7 @@ User.GOOGLE_CREDENTIALS = new User('google-credentials-uid');
67
67
  User.FIRST_PARTY = new User('first-party-uid');
68
68
  User.MOCK_USER = new User('mock-user');
69
69
 
70
- const version = "9.5.0";
70
+ const version = "9.6.0-2021111174650";
71
71
 
72
72
  /**
73
73
  * @license
@@ -436,16 +436,15 @@ class OAuthToken {
436
436
  constructor(value, user) {
437
437
  this.user = user;
438
438
  this.type = 'OAuth';
439
- this.authHeaders = {};
440
- // Set the headers using Object Literal notation to avoid minification
441
- this.authHeaders['Authorization'] = `Bearer ${value}`;
439
+ this.headers = new Map();
440
+ this.headers.set('Authorization', `Bearer ${value}`);
442
441
  }
443
442
  }
444
443
  /**
445
444
  * A CredentialsProvider that always yields an empty token.
446
445
  * @internal
447
446
  */
448
- class EmptyCredentialsProvider {
447
+ class EmptyAuthCredentialsProvider {
449
448
  getToken() {
450
449
  return Promise.resolve(null);
451
450
  }
@@ -460,7 +459,7 @@ class EmptyCredentialsProvider {
460
459
  * A CredentialsProvider that always returns a constant token. Used for
461
460
  * emulator token mocking.
462
461
  */
463
- class EmulatorCredentialsProvider {
462
+ class EmulatorAuthCredentialsProvider {
464
463
  constructor(token) {
465
464
  this.token = token;
466
465
  /**
@@ -484,7 +483,7 @@ class EmulatorCredentialsProvider {
484
483
  }
485
484
  }
486
485
  /** Credential provider for the Lite SDK. */
487
- class LiteCredentialsProvider {
486
+ class LiteAuthCredentialsProvider {
488
487
  constructor(authProvider) {
489
488
  this.auth = null;
490
489
  authProvider.onInit(auth => {
@@ -518,25 +517,17 @@ class LiteCredentialsProvider {
518
517
  */
519
518
  class FirstPartyToken {
520
519
  constructor(gapi, sessionIndex, iamToken) {
521
- this.gapi = gapi;
522
- this.sessionIndex = sessionIndex;
523
- this.iamToken = iamToken;
524
520
  this.type = 'FirstParty';
525
521
  this.user = User.FIRST_PARTY;
526
- }
527
- get authHeaders() {
528
- const headers = {
529
- 'X-Goog-AuthUser': this.sessionIndex
530
- };
531
- // Use array notation to prevent minification
532
- const authHeader = this.gapi['auth']['getAuthHeaderValueForFirstParty']([]);
522
+ this.headers = new Map();
523
+ this.headers.set('X-Goog-AuthUser', sessionIndex);
524
+ const authHeader = gapi['auth']['getAuthHeaderValueForFirstParty']([]);
533
525
  if (authHeader) {
534
- headers['Authorization'] = authHeader;
526
+ this.headers.set('Authorization', authHeader);
535
527
  }
536
- if (this.iamToken) {
537
- headers['X-Goog-Iam-Authorization-Token'] = this.iamToken;
528
+ if (iamToken) {
529
+ this.headers.set('X-Goog-Iam-Authorization-Token', iamToken);
538
530
  }
539
- return headers;
540
531
  }
541
532
  }
542
533
  /*
@@ -544,7 +535,7 @@ class FirstPartyToken {
544
535
  * to authenticate the user, using technique that is only available
545
536
  * to applications hosted by Google.
546
537
  */
547
- class FirstPartyCredentialsProvider {
538
+ class FirstPartyAuthCredentialsProvider {
548
539
  constructor(gapi, sessionIndex, iamToken) {
549
540
  this.gapi = gapi;
550
541
  this.sessionIndex = sessionIndex;
@@ -560,13 +551,50 @@ class FirstPartyCredentialsProvider {
560
551
  shutdown() { }
561
552
  invalidateToken() { }
562
553
  }
554
+ class AppCheckToken {
555
+ constructor(value) {
556
+ this.value = value;
557
+ this.type = 'AppCheck';
558
+ this.headers = new Map();
559
+ if (value && value.length > 0) {
560
+ this.headers.set('x-firebase-appcheck', this.value);
561
+ }
562
+ }
563
+ }
564
+ /** AppCheck token provider for the Lite SDK. */
565
+ class LiteAppCheckTokenProvider {
566
+ constructor(appCheckProvider) {
567
+ this.appCheckProvider = appCheckProvider;
568
+ this.appCheck = null;
569
+ appCheckProvider.onInit(appCheck => {
570
+ this.appCheck = appCheck;
571
+ });
572
+ }
573
+ getToken() {
574
+ if (!this.appCheck) {
575
+ return Promise.resolve(null);
576
+ }
577
+ return this.appCheck.getToken().then(tokenResult => {
578
+ if (tokenResult) {
579
+ hardAssert(typeof tokenResult.token === 'string');
580
+ return new AppCheckToken(tokenResult.token);
581
+ }
582
+ else {
583
+ return null;
584
+ }
585
+ });
586
+ }
587
+ invalidateToken() { }
588
+ start(asyncQueue, changeListener) { }
589
+ shutdown() { }
590
+ }
563
591
  /**
564
592
  * Builds a CredentialsProvider depending on the type of
565
593
  * the credentials passed in.
566
594
  */
567
- function makeCredentialsProvider(credentials) {
595
+ function makeAuthCredentialsProvider(credentials) {
568
596
  if (!credentials) {
569
- return new EmptyCredentialsProvider();
597
+ return new EmptyAuthCredentialsProvider();
570
598
  }
571
599
  switch (credentials['type']) {
572
600
  case 'gapi':
@@ -576,11 +604,11 @@ function makeCredentialsProvider(credentials) {
576
604
  client !== null &&
577
605
  client['auth'] &&
578
606
  client['auth']['getAuthHeaderValueForFirstParty']));
579
- return new FirstPartyCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
607
+ return new FirstPartyAuthCredentialsProvider(client, credentials['sessionIndex'] || '0', credentials['iamToken'] || null);
580
608
  case 'provider':
581
609
  return credentials['client'];
582
610
  default:
583
- throw new FirestoreError(Code.INVALID_ARGUMENT, 'makeCredentialsProvider failed due to invalid credential type');
611
+ throw new FirestoreError(Code.INVALID_ARGUMENT, 'makeAuthCredentialsProvider failed due to invalid credential type');
584
612
  }
585
613
  }
586
614
 
@@ -1167,11 +1195,11 @@ class RestConnection {
1167
1195
  this.databaseId.database +
1168
1196
  '/documents';
1169
1197
  }
1170
- invokeRPC(rpcName, path, req, token) {
1198
+ invokeRPC(rpcName, path, req, authToken, appCheckToken) {
1171
1199
  const url = this.makeUrl(rpcName, path);
1172
1200
  logDebug(LOG_TAG$3, 'Sending: ', url, req);
1173
1201
  const headers = {};
1174
- this.modifyHeadersForRequest(headers, token);
1202
+ this.modifyHeadersForRequest(headers, authToken, appCheckToken);
1175
1203
  return this.performRPCRequest(rpcName, url, headers, req).then(response => {
1176
1204
  logDebug(LOG_TAG$3, 'Received: ', response);
1177
1205
  return response;
@@ -1180,16 +1208,16 @@ class RestConnection {
1180
1208
  throw err;
1181
1209
  });
1182
1210
  }
1183
- invokeStreamingRPC(rpcName, path, request, token) {
1211
+ invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken) {
1184
1212
  // The REST API automatically aggregates all of the streamed results, so we
1185
1213
  // can just use the normal invoke() method.
1186
- return this.invokeRPC(rpcName, path, request, token);
1214
+ return this.invokeRPC(rpcName, path, request, authToken, appCheckToken);
1187
1215
  }
1188
1216
  /**
1189
1217
  * Modifies the headers for a request, adding any authorization token if
1190
1218
  * present and any additional headers for the request.
1191
1219
  */
1192
- modifyHeadersForRequest(headers, token) {
1220
+ modifyHeadersForRequest(headers, authToken, appCheckToken) {
1193
1221
  headers['X-Goog-Api-Client'] = getGoogApiClientValue();
1194
1222
  // Content-Type: text/plain will avoid preflight requests which might
1195
1223
  // mess with CORS and redirects by proxies. If we add custom headers
@@ -1199,12 +1227,11 @@ class RestConnection {
1199
1227
  if (this.databaseInfo.appId) {
1200
1228
  headers['X-Firebase-GMPID'] = this.databaseInfo.appId;
1201
1229
  }
1202
- if (token) {
1203
- for (const header in token.authHeaders) {
1204
- if (token.authHeaders.hasOwnProperty(header)) {
1205
- headers[header] = token.authHeaders[header];
1206
- }
1207
- }
1230
+ if (authToken) {
1231
+ authToken.headers.forEach((value, key) => (headers[key] = value));
1232
+ }
1233
+ if (appCheckToken) {
1234
+ appCheckToken.headers.forEach((value, key) => (headers[key] = value));
1208
1235
  }
1209
1236
  }
1210
1237
  makeUrl(rpcName, path) {
@@ -4092,9 +4119,10 @@ class Datastore {
4092
4119
  * consumption.
4093
4120
  */
4094
4121
  class DatastoreImpl extends Datastore {
4095
- constructor(credentials, connection, serializer) {
4122
+ constructor(authCredentials, appCheckCredentials, connection, serializer) {
4096
4123
  super();
4097
- this.credentials = credentials;
4124
+ this.authCredentials = authCredentials;
4125
+ this.appCheckCredentials = appCheckCredentials;
4098
4126
  this.connection = connection;
4099
4127
  this.serializer = serializer;
4100
4128
  this.terminated = false;
@@ -4104,18 +4132,21 @@ class DatastoreImpl extends Datastore {
4104
4132
  throw new FirestoreError(Code.FAILED_PRECONDITION, 'The client has already been terminated.');
4105
4133
  }
4106
4134
  }
4107
- /** Gets an auth token and invokes the provided RPC. */
4135
+ /** Invokes the provided RPC with auth and AppCheck tokens. */
4108
4136
  invokeRPC(rpcName, path, request) {
4109
4137
  this.verifyInitialized();
4110
- return this.credentials
4111
- .getToken()
4112
- .then(token => {
4113
- return this.connection.invokeRPC(rpcName, path, request, token);
4138
+ return Promise.all([
4139
+ this.authCredentials.getToken(),
4140
+ this.appCheckCredentials.getToken()
4141
+ ])
4142
+ .then(([authToken, appCheckToken]) => {
4143
+ return this.connection.invokeRPC(rpcName, path, request, authToken, appCheckToken);
4114
4144
  })
4115
4145
  .catch((error) => {
4116
4146
  if (error.name === 'FirebaseError') {
4117
4147
  if (error.code === Code.UNAUTHENTICATED) {
4118
- this.credentials.invalidateToken();
4148
+ this.authCredentials.invalidateToken();
4149
+ this.appCheckCredentials.invalidateToken();
4119
4150
  }
4120
4151
  throw error;
4121
4152
  }
@@ -4124,18 +4155,21 @@ class DatastoreImpl extends Datastore {
4124
4155
  }
4125
4156
  });
4126
4157
  }
4127
- /** Gets an auth token and invokes the provided RPC with streamed results. */
4158
+ /** Invokes the provided RPC with streamed results with auth and AppCheck tokens. */
4128
4159
  invokeStreamingRPC(rpcName, path, request) {
4129
4160
  this.verifyInitialized();
4130
- return this.credentials
4131
- .getToken()
4132
- .then(token => {
4133
- return this.connection.invokeStreamingRPC(rpcName, path, request, token);
4161
+ return Promise.all([
4162
+ this.authCredentials.getToken(),
4163
+ this.appCheckCredentials.getToken()
4164
+ ])
4165
+ .then(([authToken, appCheckToken]) => {
4166
+ return this.connection.invokeStreamingRPC(rpcName, path, request, authToken, appCheckToken);
4134
4167
  })
4135
4168
  .catch((error) => {
4136
4169
  if (error.name === 'FirebaseError') {
4137
4170
  if (error.code === Code.UNAUTHENTICATED) {
4138
- this.credentials.invalidateToken();
4171
+ this.authCredentials.invalidateToken();
4172
+ this.appCheckCredentials.invalidateToken();
4139
4173
  }
4140
4174
  throw error;
4141
4175
  }
@@ -4150,8 +4184,8 @@ class DatastoreImpl extends Datastore {
4150
4184
  }
4151
4185
  // TODO(firestorexp): Make sure there is only one Datastore instance per
4152
4186
  // firestore-exp client.
4153
- function newDatastore(credentials, connection, serializer) {
4154
- return new DatastoreImpl(credentials, connection, serializer);
4187
+ function newDatastore(authCredentials, appCheckCredentials, connection, serializer) {
4188
+ return new DatastoreImpl(authCredentials, appCheckCredentials, connection, serializer);
4155
4189
  }
4156
4190
  async function invokeCommitRpc(datastore, mutations) {
4157
4191
  const datastoreImpl = debugCast(datastore);
@@ -4227,7 +4261,7 @@ function getDatastore(firestore) {
4227
4261
  const databaseInfo = makeDatabaseInfo(firestore._databaseId, firestore.app.options.appId || '', firestore._persistenceKey, firestore._freezeSettings());
4228
4262
  const connection = newConnection(databaseInfo);
4229
4263
  const serializer = newSerializer(firestore._databaseId);
4230
- const datastore = newDatastore(firestore._credentials, connection, serializer);
4264
+ const datastore = newDatastore(firestore._authCredentials, firestore._appCheckCredentials, connection, serializer);
4231
4265
  datastoreInstances.set(firestore, datastore);
4232
4266
  }
4233
4267
  return datastoreInstances.get(firestore);
@@ -4403,8 +4437,9 @@ class FirestoreSettingsImpl {
4403
4437
  */
4404
4438
  class Firestore {
4405
4439
  /** @hideconstructor */
4406
- constructor(databaseIdOrApp, _credentials) {
4407
- this._credentials = _credentials;
4440
+ constructor(databaseIdOrApp, _authCredentials, _appCheckCredentials) {
4441
+ this._authCredentials = _authCredentials;
4442
+ this._appCheckCredentials = _appCheckCredentials;
4408
4443
  /**
4409
4444
  * Whether it's a Firestore or Firestore Lite instance.
4410
4445
  */
@@ -4445,7 +4480,7 @@ class Firestore {
4445
4480
  }
4446
4481
  this._settings = new FirestoreSettingsImpl(settings);
4447
4482
  if (settings.credentials !== undefined) {
4448
- this._credentials = makeCredentialsProvider(settings.credentials);
4483
+ this._authCredentials = makeAuthCredentialsProvider(settings.credentials);
4449
4484
  }
4450
4485
  }
4451
4486
  _getSettings() {
@@ -4556,7 +4591,7 @@ function connectFirestoreEmulator(firestore, host, port, options = {}) {
4556
4591
  }
4557
4592
  user = new User(uid);
4558
4593
  }
4559
- firestore._credentials = new EmulatorCredentialsProvider(new OAuthToken(token, user));
4594
+ firestore._authCredentials = new EmulatorAuthCredentialsProvider(new OAuthToken(token, user));
4560
4595
  }
4561
4596
  }
4562
4597
  /**
@@ -4605,7 +4640,7 @@ function registerFirestore() {
4605
4640
  setSDKVersion(`${app.SDK_VERSION}_lite`);
4606
4641
  app._registerComponent(new component.Component('firestore/lite', (container, { options: settings }) => {
4607
4642
  const app = container.getProvider('app').getImmediate();
4608
- const firestoreInstance = new Firestore(app, new LiteCredentialsProvider(container.getProvider('auth-internal')));
4643
+ const firestoreInstance = new Firestore(app, new LiteAuthCredentialsProvider(container.getProvider('auth-internal')), new LiteAppCheckTokenProvider(container.getProvider('app-check-internal')));
4609
4644
  if (settings) {
4610
4645
  firestoreInstance._setSettings(settings);
4611
4646
  }