@firebase/data-connect 0.2.0 → 0.3.0-20250205191324

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.
@@ -107,6 +107,31 @@ function logError(msg) {
107
107
  logger.error(`DataConnect (${SDK_VERSION}): ${msg}`);
108
108
  }
109
109
 
110
+ /**
111
+ * @license
112
+ * Copyright 2024 Google LLC
113
+ *
114
+ * Licensed under the Apache License, Version 2.0 (the "License");
115
+ * you may not use this file except in compliance with the License.
116
+ * You may obtain a copy of the License at
117
+ *
118
+ * http://www.apache.org/licenses/LICENSE-2.0
119
+ *
120
+ * Unless required by applicable law or agreed to in writing, software
121
+ * distributed under the License is distributed on an "AS IS" BASIS,
122
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123
+ * See the License for the specific language governing permissions and
124
+ * limitations under the License.
125
+ */
126
+ const CallerSdkTypeEnum = {
127
+ Base: 'Base', // Core JS SDK
128
+ Generated: 'Generated', // Generated JS SDK
129
+ TanstackReactCore: 'TanstackReactCore', // Tanstack non-generated React SDK
130
+ GeneratedReact: 'GeneratedReact', // Tanstack non-generated Angular SDK
131
+ TanstackAngularCore: 'TanstackAngularCore', // Tanstack non-generated Angular SDK
132
+ GeneratedAngular: 'GeneratedAngular' // Generated Angular SDK
133
+ };
134
+
110
135
  /**
111
136
  * @license
112
137
  * Copyright 2024 Google LLC
@@ -127,20 +152,24 @@ let connectFetch = globalThis.fetch;
127
152
  function initializeFetch(fetchImpl) {
128
153
  connectFetch = fetchImpl;
129
154
  }
130
- function getGoogApiClientValue(_isUsingGen) {
155
+ function getGoogApiClientValue(_isUsingGen, _callerSdkType) {
131
156
  let str = 'gl-js/ fire/' + SDK_VERSION;
132
- if (_isUsingGen) {
157
+ if (_callerSdkType !== CallerSdkTypeEnum.Base &&
158
+ _callerSdkType !== CallerSdkTypeEnum.Generated) {
159
+ str += ' js/' + _callerSdkType.toLowerCase();
160
+ }
161
+ else if (_isUsingGen || _callerSdkType === CallerSdkTypeEnum.Generated) {
133
162
  str += ' js/gen';
134
163
  }
135
164
  return str;
136
165
  }
137
- function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen) {
166
+ function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen, _callerSdkType) {
138
167
  if (!connectFetch) {
139
168
  throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
140
169
  }
141
170
  const headers = {
142
171
  'Content-Type': 'application/json',
143
- 'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen)
172
+ 'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen, _callerSdkType)
144
173
  };
145
174
  if (accessToken) {
146
175
  headers['X-Firebase-Auth-Token'] = accessToken;
@@ -197,7 +226,7 @@ function getMessage(obj) {
197
226
  }
198
227
 
199
228
  const name = "@firebase/data-connect";
200
- const version = "0.2.0";
229
+ const version = "0.3.0-20250205191324";
201
230
 
202
231
  /**
203
232
  * @license
@@ -220,15 +249,20 @@ const version = "0.2.0";
220
249
  * Abstraction around AppCheck's token fetching capabilities.
221
250
  */
222
251
  class AppCheckTokenProvider {
223
- constructor(appName_, appCheckProvider) {
224
- this.appName_ = appName_;
252
+ constructor(app$1, appCheckProvider) {
225
253
  this.appCheckProvider = appCheckProvider;
254
+ if (app._isFirebaseServerApp(app$1) && app$1.settings.appCheckToken) {
255
+ this.serverAppAppCheckToken = app$1.settings.appCheckToken;
256
+ }
226
257
  this.appCheck = appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.getImmediate({ optional: true });
227
258
  if (!this.appCheck) {
228
259
  void (appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(appCheck => (this.appCheck = appCheck)).catch());
229
260
  }
230
261
  }
231
- getToken(forceRefresh) {
262
+ getToken() {
263
+ if (this.serverAppAppCheckToken) {
264
+ return Promise.resolve({ token: this.serverAppAppCheckToken });
265
+ }
232
266
  if (!this.appCheck) {
233
267
  return new Promise((resolve, reject) => {
234
268
  // Support delayed initialization of FirebaseAppCheck. This allows our
@@ -237,7 +271,7 @@ class AppCheckTokenProvider {
237
271
  // becomes available before the timoeout below expires.
238
272
  setTimeout(() => {
239
273
  if (this.appCheck) {
240
- this.getToken(forceRefresh).then(resolve, reject);
274
+ this.getToken().then(resolve, reject);
241
275
  }
242
276
  else {
243
277
  resolve(null);
@@ -245,7 +279,7 @@ class AppCheckTokenProvider {
245
279
  }, 0);
246
280
  });
247
281
  }
248
- return this.appCheck.getToken(forceRefresh);
282
+ return this.appCheck.getToken();
249
283
  }
250
284
  addTokenChangeListener(listener) {
251
285
  var _a;
@@ -584,13 +618,14 @@ function addToken(url, apiKey) {
584
618
  * limitations under the License.
585
619
  */
586
620
  class RESTTransport {
587
- constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false) {
621
+ constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false, _callerSdkType = CallerSdkTypeEnum.Base) {
588
622
  var _a, _b;
589
623
  this.apiKey = apiKey;
590
624
  this.appId = appId;
591
625
  this.authProvider = authProvider;
592
626
  this.appCheckProvider = appCheckProvider;
593
627
  this._isUsingGen = _isUsingGen;
628
+ this._callerSdkType = _callerSdkType;
594
629
  this._host = '';
595
630
  this._location = 'l';
596
631
  this._connectorName = '';
@@ -607,7 +642,7 @@ class RESTTransport {
607
642
  name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
608
643
  operationName: queryName,
609
644
  variables: body
610
- }, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen));
645
+ }, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen, this._callerSdkType));
611
646
  return withAuth;
612
647
  };
613
648
  this.invokeMutation = (mutationName, body) => {
@@ -617,7 +652,7 @@ class RESTTransport {
617
652
  name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
618
653
  operationName: mutationName,
619
654
  variables: body
620
- }, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen);
655
+ }, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen, this._callerSdkType);
621
656
  });
622
657
  return taskResult;
623
658
  };
@@ -718,6 +753,9 @@ class RESTTransport {
718
753
  throw err;
719
754
  });
720
755
  }
756
+ _setCallerSdkType(callerSdkType) {
757
+ this._callerSdkType = callerSdkType;
758
+ }
721
759
  }
722
760
 
723
761
  /**
@@ -827,6 +865,7 @@ class DataConnect {
827
865
  this.isEmulator = false;
828
866
  this._initialized = false;
829
867
  this._isUsingGeneratedSdk = false;
868
+ this._callerSdkType = CallerSdkTypeEnum.Base;
830
869
  if (typeof process !== 'undefined' && process.env) {
831
870
  const host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
832
871
  if (host) {
@@ -842,6 +881,12 @@ class DataConnect {
842
881
  this._isUsingGeneratedSdk = true;
843
882
  }
844
883
  }
884
+ _setCallerSdkType(callerSdkType) {
885
+ this._callerSdkType = callerSdkType;
886
+ if (this._initialized) {
887
+ this._transport._setCallerSdkType(callerSdkType);
888
+ }
889
+ }
845
890
  _delete() {
846
891
  app._removeServiceInstance(this.app, 'data-connect', JSON.stringify(this.getSettings()));
847
892
  return Promise.resolve();
@@ -865,10 +910,10 @@ class DataConnect {
865
910
  this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
866
911
  }
867
912
  if (this._appCheckProvider) {
868
- this._appCheckTokenProvider = new AppCheckTokenProvider(this.app.name, this._appCheckProvider);
913
+ this._appCheckTokenProvider = new AppCheckTokenProvider(this.app, this._appCheckProvider);
869
914
  }
870
915
  this._initialized = true;
871
- this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk);
916
+ this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk, this._callerSdkType);
872
917
  if (this._transportOptions) {
873
918
  this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
874
919
  }
@@ -1043,7 +1088,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
1043
1088
  dataConnect: dcInstance,
1044
1089
  refType: QUERY_STR,
1045
1090
  name: queryName,
1046
- variables: variables
1091
+ variables
1047
1092
  };
1048
1093
  }
1049
1094
  /**
@@ -1173,6 +1218,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
1173
1218
  initializeFetch(fetch);
1174
1219
  registerDataConnect('node');
1175
1220
 
1221
+ exports.CallerSdkTypeEnum = CallerSdkTypeEnum;
1176
1222
  exports.DataConnect = DataConnect;
1177
1223
  exports.MUTATION_STR = MUTATION_STR;
1178
1224
  exports.MutationManager = MutationManager;