@firebase/data-connect 0.0.2-dataconnect-preview.388b61c7e → 0.0.3-canary.beaa4dffb

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 (36) hide show
  1. package/dist/index.cjs.js +246 -52
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.esm2017.js +245 -51
  4. package/dist/index.esm2017.js.map +1 -1
  5. package/dist/index.esm5.js +265 -50
  6. package/dist/index.esm5.js.map +1 -1
  7. package/dist/index.node.cjs.js +266 -51
  8. package/dist/index.node.cjs.js.map +1 -1
  9. package/dist/internal.d.ts +59 -33
  10. package/dist/node-esm/index.node.esm.js +245 -51
  11. package/dist/node-esm/index.node.esm.js.map +1 -1
  12. package/dist/node-esm/src/api/DataConnect.d.ts +14 -3
  13. package/dist/node-esm/src/api/index.d.ts +1 -0
  14. package/dist/node-esm/src/api/query.d.ts +1 -1
  15. package/dist/node-esm/src/core/AppCheckTokenProvider.d.ts +30 -0
  16. package/dist/node-esm/src/core/FirebaseAuthProvider.d.ts +1 -1
  17. package/dist/node-esm/src/core/QueryManager.d.ts +1 -1
  18. package/dist/node-esm/src/core/error.d.ts +2 -1
  19. package/dist/node-esm/src/network/fetch.d.ts +1 -1
  20. package/dist/node-esm/src/network/transport/index.d.ts +8 -10
  21. package/dist/node-esm/src/network/transport/rest.d.ts +24 -10
  22. package/dist/node-esm/src/util/validateArgs.d.ts +33 -0
  23. package/dist/private.d.ts +27 -45
  24. package/dist/public.d.ts +8 -38
  25. package/dist/src/api/DataConnect.d.ts +14 -3
  26. package/dist/src/api/index.d.ts +1 -0
  27. package/dist/src/api/query.d.ts +1 -1
  28. package/dist/src/core/AppCheckTokenProvider.d.ts +30 -0
  29. package/dist/src/core/FirebaseAuthProvider.d.ts +1 -1
  30. package/dist/src/core/QueryManager.d.ts +1 -1
  31. package/dist/src/core/error.d.ts +2 -1
  32. package/dist/src/network/fetch.d.ts +1 -1
  33. package/dist/src/network/transport/index.d.ts +8 -10
  34. package/dist/src/network/transport/rest.d.ts +24 -10
  35. package/dist/src/util/validateArgs.d.ts +33 -0
  36. package/package.json +11 -7
@@ -5,7 +5,7 @@ import { FirebaseError } from '@firebase/util';
5
5
  import { Logger } from '@firebase/logger';
6
6
 
7
7
  var name = "@firebase/data-connect";
8
- var version = "0.0.2-dataconnect-preview.388b61c7e";
8
+ var version = "0.0.3-canary.beaa4dffb";
9
9
 
10
10
  /**
11
11
  * @license
@@ -33,6 +33,63 @@ function setSDKVersion(version) {
33
33
  SDK_VERSION = version;
34
34
  }
35
35
 
36
+ /**
37
+ * @license
38
+ * Copyright 2024 Google LLC
39
+ *
40
+ * Licensed under the Apache License, Version 2.0 (the "License");
41
+ * you may not use this file except in compliance with the License.
42
+ * You may obtain a copy of the License at
43
+ *
44
+ * http://www.apache.org/licenses/LICENSE-2.0
45
+ *
46
+ * Unless required by applicable law or agreed to in writing, software
47
+ * distributed under the License is distributed on an "AS IS" BASIS,
48
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
+ * See the License for the specific language governing permissions and
50
+ * limitations under the License.
51
+ */
52
+ /**
53
+ * @internal
54
+ * Abstraction around AppCheck's token fetching capabilities.
55
+ */
56
+ var AppCheckTokenProvider = /** @class */ (function () {
57
+ function AppCheckTokenProvider(appName_, appCheckProvider) {
58
+ var _this = this;
59
+ this.appName_ = appName_;
60
+ this.appCheckProvider = appCheckProvider;
61
+ this.appCheck = appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.getImmediate({ optional: true });
62
+ if (!this.appCheck) {
63
+ void (appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(function (appCheck) { return (_this.appCheck = appCheck); }).catch());
64
+ }
65
+ }
66
+ AppCheckTokenProvider.prototype.getToken = function (forceRefresh) {
67
+ var _this = this;
68
+ if (!this.appCheck) {
69
+ return new Promise(function (resolve, reject) {
70
+ // Support delayed initialization of FirebaseAppCheck. This allows our
71
+ // customers to initialize the RTDB SDK before initializing Firebase
72
+ // AppCheck and ensures that all requests are authenticated if a token
73
+ // becomes available before the timoeout below expires.
74
+ setTimeout(function () {
75
+ if (_this.appCheck) {
76
+ _this.getToken(forceRefresh).then(resolve, reject);
77
+ }
78
+ else {
79
+ resolve(null);
80
+ }
81
+ }, 0);
82
+ });
83
+ }
84
+ return this.appCheck.getToken(forceRefresh);
85
+ };
86
+ AppCheckTokenProvider.prototype.addTokenChangeListener = function (listener) {
87
+ var _a;
88
+ void ((_a = this.appCheckProvider) === null || _a === void 0 ? void 0 : _a.get().then(function (appCheck) { return appCheck.addTokenListener(listener); }));
89
+ };
90
+ return AppCheckTokenProvider;
91
+ }());
92
+
36
93
  /**
37
94
  * @license
38
95
  * Copyright 2024 Google LLC
@@ -55,7 +112,8 @@ var Code = {
55
112
  NOT_INITIALIZED: 'not-initialized',
56
113
  NOT_SUPPORTED: 'not-supported',
57
114
  INVALID_ARGUMENT: 'invalid-argument',
58
- PARTIAL_ERROR: 'partial-error'
115
+ PARTIAL_ERROR: 'partial-error',
116
+ UNAUTHORIZED: 'unauthorized'
59
117
  };
60
118
  /** An error returned by a DataConnect operation. */
61
119
  var DataConnectError = /** @class */ (function (_super) {
@@ -125,6 +183,7 @@ function logError(msg) {
125
183
  * See the License for the specific language governing permissions and
126
184
  * limitations under the License.
127
185
  */
186
+ // @internal
128
187
  var FirebaseAuthProvider = /** @class */ (function () {
129
188
  function FirebaseAuthProvider(_appName, _options, _authProvider) {
130
189
  var _this = this;
@@ -169,7 +228,8 @@ var FirebaseAuthProvider = /** @class */ (function () {
169
228
  FirebaseAuthProvider.prototype.removeTokenChangeListener = function (listener) {
170
229
  this._authProvider
171
230
  .get()
172
- .then(function (auth) { return auth.removeAuthTokenListener(listener); });
231
+ .then(function (auth) { return auth.removeAuthTokenListener(listener); })
232
+ .catch(function (err) { return logError(err); });
173
233
  };
174
234
  return FirebaseAuthProvider;
175
235
  }());
@@ -412,7 +472,7 @@ function urlBuilder(projectConfig, transportOptions) {
412
472
  logError('Port type is of an invalid type');
413
473
  throw new DataConnectError(Code.INVALID_ARGUMENT, 'Incorrect type for port passed in!');
414
474
  }
415
- return "".concat(baseUrl, "/v1alpha/projects/").concat(project, "/locations/").concat(location, "/services/").concat(service, "/connectors/").concat(connector);
475
+ return "".concat(baseUrl, "/v1beta/projects/").concat(project, "/locations/").concat(location, "/services/").concat(service, "/connectors/").concat(connector);
416
476
  }
417
477
  function addToken(url, apiKey) {
418
478
  if (!apiKey) {
@@ -440,18 +500,32 @@ function addToken(url, apiKey) {
440
500
  * limitations under the License.
441
501
  */
442
502
  var connectFetch = globalThis.fetch;
443
- function dcFetch(url, body, _a, accessToken) {
503
+ function getGoogApiClientValue(_isUsingGen) {
504
+ var str = 'gl-js/ fire/' + SDK_VERSION;
505
+ if (_isUsingGen) {
506
+ str += ' web/gen';
507
+ }
508
+ return str;
509
+ }
510
+ function dcFetch(url, body, _a, appId, accessToken, appCheckToken, _isUsingGen) {
444
511
  var _this = this;
445
512
  var signal = _a.signal;
446
513
  if (!connectFetch) {
447
514
  throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
448
515
  }
449
516
  var headers = {
450
- 'Content-Type': 'application/json'
517
+ 'Content-Type': 'application/json',
518
+ 'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen)
451
519
  };
452
520
  if (accessToken) {
453
521
  headers['X-Firebase-Auth-Token'] = accessToken;
454
522
  }
523
+ if (appId) {
524
+ headers['x-firebase-gmpid'] = appId;
525
+ }
526
+ if (appCheckToken) {
527
+ headers['X-Firebase-AppCheck'] = appCheckToken;
528
+ }
455
529
  var bodyStr = JSON.stringify(body);
456
530
  logDebug("Making request out to ".concat(url, " with body: ").concat(bodyStr));
457
531
  return connectFetch(url, {
@@ -459,11 +533,12 @@ function dcFetch(url, body, _a, accessToken) {
459
533
  method: 'POST',
460
534
  headers: headers,
461
535
  signal: signal
462
- }).catch(function (err) {
463
- throw new DataConnectError(Code.OTHER, "Failed to fetch: " + JSON.stringify(err));
536
+ })
537
+ .catch(function (err) {
538
+ throw new DataConnectError(Code.OTHER, 'Failed to fetch: ' + JSON.stringify(err));
464
539
  })
465
540
  .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
466
- var jsonResponse, e_1;
541
+ var jsonResponse, e_1, message;
467
542
  return __generator(this, function (_a) {
468
543
  switch (_a.label) {
469
544
  case 0:
@@ -479,9 +554,13 @@ function dcFetch(url, body, _a, accessToken) {
479
554
  e_1 = _a.sent();
480
555
  throw new DataConnectError(Code.OTHER, JSON.stringify(e_1));
481
556
  case 4:
557
+ message = getMessage(jsonResponse);
482
558
  if (response.status >= 400) {
483
559
  logError('Error while performing request: ' + JSON.stringify(jsonResponse));
484
- throw new DataConnectError(Code.OTHER, JSON.stringify(jsonResponse));
560
+ if (response.status === 401) {
561
+ throw new DataConnectError(Code.UNAUTHORIZED, message);
562
+ }
563
+ throw new DataConnectError(Code.OTHER, message);
485
564
  }
486
565
  return [2 /*return*/, jsonResponse];
487
566
  }
@@ -495,6 +574,12 @@ function dcFetch(url, body, _a, accessToken) {
495
574
  }
496
575
  return res;
497
576
  });
577
+ }
578
+ function getMessage(obj) {
579
+ if ('message' in obj) {
580
+ return obj.message;
581
+ }
582
+ return JSON.stringify(obj);
498
583
  }
499
584
 
500
585
  /**
@@ -514,42 +599,48 @@ function dcFetch(url, body, _a, accessToken) {
514
599
  * limitations under the License.
515
600
  */
516
601
  var RESTTransport = /** @class */ (function () {
517
- function RESTTransport(options, apiKey, authProvider, transportOptions) {
602
+ function RESTTransport(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen) {
603
+ if (_isUsingGen === void 0) { _isUsingGen = false; }
518
604
  var _this = this;
519
- var _a;
605
+ var _a, _b;
520
606
  this.apiKey = apiKey;
607
+ this.appId = appId;
521
608
  this.authProvider = authProvider;
609
+ this.appCheckProvider = appCheckProvider;
610
+ this._isUsingGen = _isUsingGen;
522
611
  this._host = '';
523
612
  this._location = 'l';
524
613
  this._connectorName = '';
525
614
  this._secure = true;
526
615
  this._project = 'p';
527
616
  this._accessToken = null;
528
- this._authInitialized = false;
617
+ this._appCheckToken = null;
618
+ this._lastToken = null;
529
619
  // TODO(mtewani): Update U to include shape of body defined in line 13.
530
620
  this.invokeQuery = function (queryName, body) {
531
621
  var abortController = new AbortController();
532
622
  // TODO(mtewani): Update to proper value
533
- var withAuth = _this.getWithAuth().then(function () {
623
+ var withAuth = _this.withRetry(function () {
534
624
  return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
535
625
  name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
536
626
  operationName: queryName,
537
627
  variables: body
538
628
  }, // TODO(mtewani): This is a patch, fix this.
539
- abortController, _this._accessToken);
629
+ abortController, _this.appId, _this._accessToken, _this._appCheckToken, _this._isUsingGen);
540
630
  });
541
631
  return {
542
- then: withAuth.then.bind(withAuth)
632
+ then: withAuth.then.bind(withAuth),
633
+ catch: withAuth.catch.bind(withAuth)
543
634
  };
544
635
  };
545
636
  this.invokeMutation = function (mutationName, body) {
546
637
  var abortController = new AbortController();
547
- var taskResult = _this.getWithAuth().then(function () {
638
+ var taskResult = _this.withRetry(function () {
548
639
  return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
549
640
  name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
550
641
  operationName: mutationName,
551
642
  variables: body
552
- }, abortController, _this._accessToken);
643
+ }, abortController, _this.appId, _this._accessToken, _this._appCheckToken, _this._isUsingGen);
553
644
  });
554
645
  return {
555
646
  then: taskResult.then.bind(taskResult),
@@ -583,6 +674,11 @@ var RESTTransport = /** @class */ (function () {
583
674
  logDebug("New Token Available: ".concat(token));
584
675
  _this._accessToken = token;
585
676
  });
677
+ (_b = this.appCheckProvider) === null || _b === void 0 ? void 0 : _b.addTokenChangeListener(function (result) {
678
+ var token = result.token;
679
+ logDebug("New App Check Token Available: ".concat(token));
680
+ _this._appCheckToken = token;
681
+ });
586
682
  }
587
683
  Object.defineProperty(RESTTransport.prototype, "endpointUrl", {
588
684
  get: function () {
@@ -608,28 +704,69 @@ var RESTTransport = /** @class */ (function () {
608
704
  RESTTransport.prototype.onTokenChanged = function (newToken) {
609
705
  this._accessToken = newToken;
610
706
  };
611
- RESTTransport.prototype.getWithAuth = function () {
612
- var _this = this;
613
- var starterPromise = new Promise(function (resolve) {
614
- return resolve(_this._accessToken);
707
+ RESTTransport.prototype.getWithAuth = function (forceToken) {
708
+ var _a;
709
+ if (forceToken === void 0) { forceToken = false; }
710
+ return __awaiter(this, void 0, void 0, function () {
711
+ var starterPromise, _b;
712
+ var _this = this;
713
+ return __generator(this, function (_c) {
714
+ switch (_c.label) {
715
+ case 0:
716
+ starterPromise = new Promise(function (resolve) {
717
+ return resolve(_this._accessToken);
718
+ });
719
+ if (!this.appCheckProvider) return [3 /*break*/, 2];
720
+ _b = this;
721
+ return [4 /*yield*/, this.appCheckProvider.getToken()];
722
+ case 1:
723
+ _b._appCheckToken = (_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.token;
724
+ _c.label = 2;
725
+ case 2:
726
+ if (this.authProvider) {
727
+ starterPromise = this.authProvider
728
+ .getToken(/*forceToken=*/ forceToken)
729
+ .then(function (data) {
730
+ if (!data) {
731
+ return null;
732
+ }
733
+ _this._accessToken = data.accessToken;
734
+ return _this._accessToken;
735
+ });
736
+ }
737
+ else {
738
+ starterPromise = new Promise(function (resolve) { return resolve(''); });
739
+ }
740
+ return [2 /*return*/, starterPromise];
741
+ }
742
+ });
615
743
  });
616
- if (!this._authInitialized) {
617
- if (this.authProvider) {
618
- starterPromise = this.authProvider
619
- .getToken(/*forceToken=*/ false)
620
- .then(function (data) {
621
- if (!data) {
622
- return null;
623
- }
624
- _this._accessToken = data.accessToken;
625
- return _this._accessToken;
626
- });
627
- }
628
- else {
629
- starterPromise = new Promise(function (resolve) { return resolve(''); });
744
+ };
745
+ RESTTransport.prototype._setLastToken = function (lastToken) {
746
+ this._lastToken = lastToken;
747
+ };
748
+ RESTTransport.prototype.withRetry = function (promiseFactory, retry) {
749
+ var _this = this;
750
+ if (retry === void 0) { retry = false; }
751
+ var isNewToken = false;
752
+ return this.getWithAuth(retry)
753
+ .then(function (res) {
754
+ isNewToken = _this._lastToken !== res;
755
+ _this._lastToken = res;
756
+ return res;
757
+ })
758
+ .then(promiseFactory)
759
+ .catch(function (err) {
760
+ // Only retry if the result is unauthorized and the last token isn't the same as the new one.
761
+ if ('code' in err &&
762
+ err.code === Code.UNAUTHORIZED &&
763
+ !retry &&
764
+ isNewToken) {
765
+ logDebug('Retrying due to unauthorized');
766
+ return _this.withRetry(promiseFactory, true);
630
767
  }
631
- }
632
- return starterPromise;
768
+ throw err;
769
+ });
633
770
  };
634
771
  return RESTTransport;
635
772
  }());
@@ -734,14 +871,17 @@ function parseOptions(fullHost) {
734
871
  * Class representing Firebase Data Connect
735
872
  */
736
873
  var DataConnect = /** @class */ (function () {
874
+ // @internal
737
875
  function DataConnect(app,
738
876
  // TODO(mtewani): Replace with _dataConnectOptions in the future
739
- dataConnectOptions, _authProvider) {
877
+ dataConnectOptions, _authProvider, _appCheckProvider) {
740
878
  this.app = app;
741
879
  this.dataConnectOptions = dataConnectOptions;
742
880
  this._authProvider = _authProvider;
881
+ this._appCheckProvider = _appCheckProvider;
743
882
  this.isEmulator = false;
744
- this.initialized = false;
883
+ this._initialized = false;
884
+ this._isUsingGeneratedSdk = false;
745
885
  if (typeof process !== 'undefined' && process.env) {
746
886
  var host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
747
887
  if (host) {
@@ -751,17 +891,25 @@ var DataConnect = /** @class */ (function () {
751
891
  }
752
892
  }
753
893
  }
894
+ // @internal
895
+ DataConnect.prototype._useGeneratedSdk = function () {
896
+ if (!this._isUsingGeneratedSdk) {
897
+ this._isUsingGeneratedSdk = true;
898
+ }
899
+ };
754
900
  DataConnect.prototype._delete = function () {
755
901
  _removeServiceInstance(this.app, 'data-connect', JSON.stringify(this.getSettings()));
756
902
  return Promise.resolve();
757
903
  };
904
+ // @internal
758
905
  DataConnect.prototype.getSettings = function () {
759
906
  var copy = JSON.parse(JSON.stringify(this.dataConnectOptions));
760
907
  delete copy.projectId;
761
908
  return copy;
762
909
  };
910
+ // @internal
763
911
  DataConnect.prototype.setInitialized = function () {
764
- if (this.initialized) {
912
+ if (this._initialized) {
765
913
  return;
766
914
  }
767
915
  if (this._transportClass === undefined) {
@@ -771,16 +919,20 @@ var DataConnect = /** @class */ (function () {
771
919
  if (this._authProvider) {
772
920
  this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
773
921
  }
774
- this.initialized = true;
775
- this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this._authTokenProvider);
922
+ if (this._appCheckProvider) {
923
+ this._appCheckTokenProvider = new AppCheckTokenProvider(this.app.name, this._appCheckProvider);
924
+ }
925
+ this._initialized = true;
926
+ this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk);
776
927
  if (this._transportOptions) {
777
928
  this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
778
929
  }
779
930
  this._queryManager = new QueryManager(this._transport);
780
931
  this._mutationManager = new MutationManager(this._transport);
781
932
  };
933
+ // @internal
782
934
  DataConnect.prototype.enableEmulator = function (transportOptions) {
783
- if (this.initialized) {
935
+ if (this._initialized) {
784
936
  logError('enableEmulator called after initialization');
785
937
  throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
786
938
  }
@@ -811,7 +963,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
811
963
  dcOptions = optionalOptions;
812
964
  app = appOrOptions;
813
965
  }
814
- if (!app) {
966
+ if (!app || Object.keys(app).length === 0) {
815
967
  app = getApp();
816
968
  }
817
969
  var provider = _getProvider(app, 'data-connect');
@@ -825,9 +977,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
825
977
  return dcInstance;
826
978
  }
827
979
  }
828
- if (!dcOptions) {
829
- throw new DataConnectError(Code.INVALID_ARGUMENT, 'DC Option Required');
830
- }
980
+ validateDCOptions(dcOptions);
831
981
  logDebug('Creating new DataConnect instance');
832
982
  // Initialize with options.
833
983
  return provider.initialize({
@@ -835,6 +985,24 @@ function getDataConnect(appOrOptions, optionalOptions) {
835
985
  options: dcOptions
836
986
  });
837
987
  }
988
+ /**
989
+ *
990
+ * @param dcOptions
991
+ * @returns {void}
992
+ * @internal
993
+ */
994
+ function validateDCOptions(dcOptions) {
995
+ var fields = ['connector', 'location', 'service'];
996
+ if (!dcOptions) {
997
+ throw new DataConnectError(Code.INVALID_ARGUMENT, 'DC Option Required');
998
+ }
999
+ fields.forEach(function (field) {
1000
+ if (dcOptions[field] === null || dcOptions[field] === undefined) {
1001
+ throw new DataConnectError(Code.INVALID_ARGUMENT, "".concat(field, " Required"));
1002
+ }
1003
+ });
1004
+ return true;
1005
+ }
838
1006
  /**
839
1007
  * Delete DataConnect instance
840
1008
  * @param dataConnect DataConnect instance
@@ -851,11 +1019,15 @@ function registerDataConnect(variant) {
851
1019
  var settings = _a.instanceIdentifier, options = _a.options;
852
1020
  var app = container.getProvider('app').getImmediate();
853
1021
  var authProvider = container.getProvider('auth-internal');
1022
+ var appCheckProvider = container.getProvider('app-check-internal');
854
1023
  var newOpts = options;
855
1024
  if (settings) {
856
1025
  newOpts = JSON.parse(settings);
857
1026
  }
858
- return new DataConnect(app, __assign(__assign({}, newOpts), { projectId: app.options.projectId }), authProvider);
1027
+ if (!app.options.projectId) {
1028
+ throw new DataConnectError(Code.INVALID_ARGUMENT, 'Project ID must be provided. Did you pass in a proper projectId to initializeApp?');
1029
+ }
1030
+ return new DataConnect(app, __assign(__assign({}, newOpts), { projectId: app.options.projectId }), authProvider, appCheckProvider);
859
1031
  }, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
860
1032
  registerVersion(name, version, variant);
861
1033
  // BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
@@ -914,6 +1086,49 @@ function toQueryRef(serializedRef) {
914
1086
  return queryRef(getDataConnect(connectorConfig), name, variables);
915
1087
  }
916
1088
 
1089
+ /**
1090
+ * @license
1091
+ * Copyright 2024 Google LLC
1092
+ *
1093
+ * Licensed under the Apache License, Version 2.0 (the "License");
1094
+ * you may not use this file except in compliance with the License.
1095
+ * You may obtain a copy of the License at
1096
+ *
1097
+ * http://www.apache.org/licenses/LICENSE-2.0
1098
+ *
1099
+ * Unless required by applicable law or agreed to in writing, software
1100
+ * distributed under the License is distributed on an "AS IS" BASIS,
1101
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1102
+ * See the License for the specific language governing permissions and
1103
+ * limitations under the License.
1104
+ */
1105
+ /**
1106
+ * The generated SDK will allow the user to pass in either the variable or the data connect instance with the variable,
1107
+ * and this function validates the variables and returns back the DataConnect instance and variables based on the arguments passed in.
1108
+ * @param connectorConfig
1109
+ * @param dcOrVars
1110
+ * @param vars
1111
+ * @param validateVars
1112
+ * @returns {DataConnect} and {Variables} instance
1113
+ * @internal
1114
+ */
1115
+ function validateArgs(connectorConfig, dcOrVars, vars, validateVars) {
1116
+ var dcInstance;
1117
+ var realVars;
1118
+ if (dcOrVars && 'enableEmulator' in dcOrVars) {
1119
+ dcInstance = dcOrVars;
1120
+ realVars = vars;
1121
+ }
1122
+ else {
1123
+ dcInstance = getDataConnect(connectorConfig);
1124
+ realVars = dcOrVars;
1125
+ }
1126
+ if (!dcInstance || (!realVars && validateVars)) {
1127
+ throw new DataConnectError(Code.INVALID_ARGUMENT, 'Variables required.');
1128
+ }
1129
+ return { dc: dcInstance, vars: realVars };
1130
+ }
1131
+
917
1132
  /**
918
1133
  * @license
919
1134
  * Copyright 2024 Google LLC
@@ -976,5 +1191,5 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
976
1191
  */
977
1192
  registerDataConnect();
978
1193
 
979
- export { DataConnect, FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR, FirebaseAuthProvider, MUTATION_STR, MutationManager, QUERY_STR, SOURCE_CACHE, SOURCE_SERVER, connectDataConnectEmulator, executeMutation, executeQuery, getDataConnect, mutationRef, parseOptions, queryRef, setLogLevel, subscribe, terminate, toQueryRef };
1194
+ export { DataConnect, MUTATION_STR, MutationManager, QUERY_STR, SOURCE_CACHE, SOURCE_SERVER, connectDataConnectEmulator, executeMutation, executeQuery, getDataConnect, mutationRef, parseOptions, queryRef, setLogLevel, subscribe, terminate, toQueryRef, validateArgs, validateDCOptions };
980
1195
  //# sourceMappingURL=index.esm5.js.map