@firebase/data-connect 0.2.0 → 0.3.0-20250205220033
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/README.md +5 -0
- package/dist/index.cjs.js +62 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +63 -18
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.node.cjs.js +62 -16
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/internal.d.ts +22 -4
- package/dist/node-esm/index.node.esm.js +63 -18
- package/dist/node-esm/index.node.esm.js.map +1 -1
- package/dist/node-esm/src/api/DataConnect.d.ts +3 -0
- package/dist/node-esm/src/core/AppCheckTokenProvider.d.ts +4 -3
- package/dist/node-esm/src/network/fetch.d.ts +2 -1
- package/dist/node-esm/src/network/transport/index.d.ts +15 -1
- package/dist/node-esm/src/network/transport/rest.d.ts +4 -2
- package/dist/private.d.ts +17 -0
- package/dist/public.d.ts +13 -0
- package/dist/src/api/DataConnect.d.ts +3 -0
- package/dist/src/core/AppCheckTokenProvider.d.ts +4 -3
- package/dist/src/network/fetch.d.ts +2 -1
- package/dist/src/network/transport/index.d.ts +15 -1
- package/dist/src/network/transport/rest.d.ts +4 -2
- package/package.json +9 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FirebaseError } from '@firebase/util';
|
|
2
2
|
import { Logger } from '@firebase/logger';
|
|
3
|
-
import { _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';
|
|
3
|
+
import { _isFirebaseServerApp, _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';
|
|
4
4
|
import { Component } from '@firebase/component';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -103,6 +103,31 @@ function logError(msg) {
|
|
|
103
103
|
logger.error(`DataConnect (${SDK_VERSION}): ${msg}`);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* @license
|
|
108
|
+
* Copyright 2024 Google LLC
|
|
109
|
+
*
|
|
110
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
111
|
+
* you may not use this file except in compliance with the License.
|
|
112
|
+
* You may obtain a copy of the License at
|
|
113
|
+
*
|
|
114
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
115
|
+
*
|
|
116
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
117
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
118
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
119
|
+
* See the License for the specific language governing permissions and
|
|
120
|
+
* limitations under the License.
|
|
121
|
+
*/
|
|
122
|
+
const CallerSdkTypeEnum = {
|
|
123
|
+
Base: 'Base', // Core JS SDK
|
|
124
|
+
Generated: 'Generated', // Generated JS SDK
|
|
125
|
+
TanstackReactCore: 'TanstackReactCore', // Tanstack non-generated React SDK
|
|
126
|
+
GeneratedReact: 'GeneratedReact', // Tanstack non-generated Angular SDK
|
|
127
|
+
TanstackAngularCore: 'TanstackAngularCore', // Tanstack non-generated Angular SDK
|
|
128
|
+
GeneratedAngular: 'GeneratedAngular' // Generated Angular SDK
|
|
129
|
+
};
|
|
130
|
+
|
|
106
131
|
/**
|
|
107
132
|
* @license
|
|
108
133
|
* Copyright 2024 Google LLC
|
|
@@ -123,20 +148,24 @@ let connectFetch = globalThis.fetch;
|
|
|
123
148
|
function initializeFetch(fetchImpl) {
|
|
124
149
|
connectFetch = fetchImpl;
|
|
125
150
|
}
|
|
126
|
-
function getGoogApiClientValue(_isUsingGen) {
|
|
151
|
+
function getGoogApiClientValue(_isUsingGen, _callerSdkType) {
|
|
127
152
|
let str = 'gl-js/ fire/' + SDK_VERSION;
|
|
128
|
-
if (
|
|
153
|
+
if (_callerSdkType !== CallerSdkTypeEnum.Base &&
|
|
154
|
+
_callerSdkType !== CallerSdkTypeEnum.Generated) {
|
|
155
|
+
str += ' js/' + _callerSdkType.toLowerCase();
|
|
156
|
+
}
|
|
157
|
+
else if (_isUsingGen || _callerSdkType === CallerSdkTypeEnum.Generated) {
|
|
129
158
|
str += ' js/gen';
|
|
130
159
|
}
|
|
131
160
|
return str;
|
|
132
161
|
}
|
|
133
|
-
function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen) {
|
|
162
|
+
function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen, _callerSdkType) {
|
|
134
163
|
if (!connectFetch) {
|
|
135
164
|
throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
|
|
136
165
|
}
|
|
137
166
|
const headers = {
|
|
138
167
|
'Content-Type': 'application/json',
|
|
139
|
-
'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen)
|
|
168
|
+
'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen, _callerSdkType)
|
|
140
169
|
};
|
|
141
170
|
if (accessToken) {
|
|
142
171
|
headers['X-Firebase-Auth-Token'] = accessToken;
|
|
@@ -193,7 +222,7 @@ function getMessage(obj) {
|
|
|
193
222
|
}
|
|
194
223
|
|
|
195
224
|
const name = "@firebase/data-connect";
|
|
196
|
-
const version = "0.
|
|
225
|
+
const version = "0.3.0-20250205220033";
|
|
197
226
|
|
|
198
227
|
/**
|
|
199
228
|
* @license
|
|
@@ -216,15 +245,20 @@ const version = "0.2.0";
|
|
|
216
245
|
* Abstraction around AppCheck's token fetching capabilities.
|
|
217
246
|
*/
|
|
218
247
|
class AppCheckTokenProvider {
|
|
219
|
-
constructor(
|
|
220
|
-
this.appName_ = appName_;
|
|
248
|
+
constructor(app, appCheckProvider) {
|
|
221
249
|
this.appCheckProvider = appCheckProvider;
|
|
250
|
+
if (_isFirebaseServerApp(app) && app.settings.appCheckToken) {
|
|
251
|
+
this.serverAppAppCheckToken = app.settings.appCheckToken;
|
|
252
|
+
}
|
|
222
253
|
this.appCheck = appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.getImmediate({ optional: true });
|
|
223
254
|
if (!this.appCheck) {
|
|
224
255
|
void (appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(appCheck => (this.appCheck = appCheck)).catch());
|
|
225
256
|
}
|
|
226
257
|
}
|
|
227
|
-
getToken(
|
|
258
|
+
getToken() {
|
|
259
|
+
if (this.serverAppAppCheckToken) {
|
|
260
|
+
return Promise.resolve({ token: this.serverAppAppCheckToken });
|
|
261
|
+
}
|
|
228
262
|
if (!this.appCheck) {
|
|
229
263
|
return new Promise((resolve, reject) => {
|
|
230
264
|
// Support delayed initialization of FirebaseAppCheck. This allows our
|
|
@@ -233,7 +267,7 @@ class AppCheckTokenProvider {
|
|
|
233
267
|
// becomes available before the timoeout below expires.
|
|
234
268
|
setTimeout(() => {
|
|
235
269
|
if (this.appCheck) {
|
|
236
|
-
this.getToken(
|
|
270
|
+
this.getToken().then(resolve, reject);
|
|
237
271
|
}
|
|
238
272
|
else {
|
|
239
273
|
resolve(null);
|
|
@@ -241,7 +275,7 @@ class AppCheckTokenProvider {
|
|
|
241
275
|
}, 0);
|
|
242
276
|
});
|
|
243
277
|
}
|
|
244
|
-
return this.appCheck.getToken(
|
|
278
|
+
return this.appCheck.getToken();
|
|
245
279
|
}
|
|
246
280
|
addTokenChangeListener(listener) {
|
|
247
281
|
var _a;
|
|
@@ -580,13 +614,14 @@ function addToken(url, apiKey) {
|
|
|
580
614
|
* limitations under the License.
|
|
581
615
|
*/
|
|
582
616
|
class RESTTransport {
|
|
583
|
-
constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false) {
|
|
617
|
+
constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false, _callerSdkType = CallerSdkTypeEnum.Base) {
|
|
584
618
|
var _a, _b;
|
|
585
619
|
this.apiKey = apiKey;
|
|
586
620
|
this.appId = appId;
|
|
587
621
|
this.authProvider = authProvider;
|
|
588
622
|
this.appCheckProvider = appCheckProvider;
|
|
589
623
|
this._isUsingGen = _isUsingGen;
|
|
624
|
+
this._callerSdkType = _callerSdkType;
|
|
590
625
|
this._host = '';
|
|
591
626
|
this._location = 'l';
|
|
592
627
|
this._connectorName = '';
|
|
@@ -603,7 +638,7 @@ class RESTTransport {
|
|
|
603
638
|
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
604
639
|
operationName: queryName,
|
|
605
640
|
variables: body
|
|
606
|
-
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen));
|
|
641
|
+
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen, this._callerSdkType));
|
|
607
642
|
return withAuth;
|
|
608
643
|
};
|
|
609
644
|
this.invokeMutation = (mutationName, body) => {
|
|
@@ -613,7 +648,7 @@ class RESTTransport {
|
|
|
613
648
|
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
614
649
|
operationName: mutationName,
|
|
615
650
|
variables: body
|
|
616
|
-
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen);
|
|
651
|
+
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen, this._callerSdkType);
|
|
617
652
|
});
|
|
618
653
|
return taskResult;
|
|
619
654
|
};
|
|
@@ -714,6 +749,9 @@ class RESTTransport {
|
|
|
714
749
|
throw err;
|
|
715
750
|
});
|
|
716
751
|
}
|
|
752
|
+
_setCallerSdkType(callerSdkType) {
|
|
753
|
+
this._callerSdkType = callerSdkType;
|
|
754
|
+
}
|
|
717
755
|
}
|
|
718
756
|
|
|
719
757
|
/**
|
|
@@ -823,6 +861,7 @@ class DataConnect {
|
|
|
823
861
|
this.isEmulator = false;
|
|
824
862
|
this._initialized = false;
|
|
825
863
|
this._isUsingGeneratedSdk = false;
|
|
864
|
+
this._callerSdkType = CallerSdkTypeEnum.Base;
|
|
826
865
|
if (typeof process !== 'undefined' && process.env) {
|
|
827
866
|
const host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
|
|
828
867
|
if (host) {
|
|
@@ -838,6 +877,12 @@ class DataConnect {
|
|
|
838
877
|
this._isUsingGeneratedSdk = true;
|
|
839
878
|
}
|
|
840
879
|
}
|
|
880
|
+
_setCallerSdkType(callerSdkType) {
|
|
881
|
+
this._callerSdkType = callerSdkType;
|
|
882
|
+
if (this._initialized) {
|
|
883
|
+
this._transport._setCallerSdkType(callerSdkType);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
841
886
|
_delete() {
|
|
842
887
|
_removeServiceInstance(this.app, 'data-connect', JSON.stringify(this.getSettings()));
|
|
843
888
|
return Promise.resolve();
|
|
@@ -861,10 +906,10 @@ class DataConnect {
|
|
|
861
906
|
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
862
907
|
}
|
|
863
908
|
if (this._appCheckProvider) {
|
|
864
|
-
this._appCheckTokenProvider = new AppCheckTokenProvider(this.app
|
|
909
|
+
this._appCheckTokenProvider = new AppCheckTokenProvider(this.app, this._appCheckProvider);
|
|
865
910
|
}
|
|
866
911
|
this._initialized = true;
|
|
867
|
-
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk);
|
|
912
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk, this._callerSdkType);
|
|
868
913
|
if (this._transportOptions) {
|
|
869
914
|
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
870
915
|
}
|
|
@@ -1039,7 +1084,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
1039
1084
|
dataConnect: dcInstance,
|
|
1040
1085
|
refType: QUERY_STR,
|
|
1041
1086
|
name: queryName,
|
|
1042
|
-
variables
|
|
1087
|
+
variables
|
|
1043
1088
|
};
|
|
1044
1089
|
}
|
|
1045
1090
|
/**
|
|
@@ -1169,5 +1214,5 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
1169
1214
|
initializeFetch(fetch);
|
|
1170
1215
|
registerDataConnect('node');
|
|
1171
1216
|
|
|
1172
|
-
export { DataConnect, MUTATION_STR, MutationManager, QUERY_STR, SOURCE_CACHE, SOURCE_SERVER, areTransportOptionsEqual, connectDataConnectEmulator, executeMutation, executeQuery, getDataConnect, mutationRef, parseOptions, queryRef, setLogLevel, subscribe, terminate, toQueryRef, validateArgs, validateDCOptions };
|
|
1217
|
+
export { CallerSdkTypeEnum, DataConnect, MUTATION_STR, MutationManager, QUERY_STR, SOURCE_CACHE, SOURCE_SERVER, areTransportOptionsEqual, connectDataConnectEmulator, executeMutation, executeQuery, getDataConnect, mutationRef, parseOptions, queryRef, setLogLevel, subscribe, terminate, toQueryRef, validateArgs, validateDCOptions };
|
|
1173
1218
|
//# sourceMappingURL=index.node.esm.js.map
|