@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
package/dist/index.esm2017.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';
|
|
1
|
+
import { _isFirebaseServerApp, _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';
|
|
2
2
|
import { Component } from '@firebase/component';
|
|
3
3
|
import { FirebaseError } from '@firebase/util';
|
|
4
4
|
import { Logger } from '@firebase/logger';
|
|
5
5
|
|
|
6
6
|
const name = "@firebase/data-connect";
|
|
7
|
-
const version = "0.
|
|
7
|
+
const version = "0.3.0-20250205220033";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @license
|
|
@@ -53,15 +53,20 @@ function setSDKVersion(version) {
|
|
|
53
53
|
* Abstraction around AppCheck's token fetching capabilities.
|
|
54
54
|
*/
|
|
55
55
|
class AppCheckTokenProvider {
|
|
56
|
-
constructor(
|
|
57
|
-
this.appName_ = appName_;
|
|
56
|
+
constructor(app, appCheckProvider) {
|
|
58
57
|
this.appCheckProvider = appCheckProvider;
|
|
58
|
+
if (_isFirebaseServerApp(app) && app.settings.appCheckToken) {
|
|
59
|
+
this.serverAppAppCheckToken = app.settings.appCheckToken;
|
|
60
|
+
}
|
|
59
61
|
this.appCheck = appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.getImmediate({ optional: true });
|
|
60
62
|
if (!this.appCheck) {
|
|
61
63
|
void (appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(appCheck => (this.appCheck = appCheck)).catch());
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
|
-
getToken(
|
|
66
|
+
getToken() {
|
|
67
|
+
if (this.serverAppAppCheckToken) {
|
|
68
|
+
return Promise.resolve({ token: this.serverAppAppCheckToken });
|
|
69
|
+
}
|
|
65
70
|
if (!this.appCheck) {
|
|
66
71
|
return new Promise((resolve, reject) => {
|
|
67
72
|
// Support delayed initialization of FirebaseAppCheck. This allows our
|
|
@@ -70,7 +75,7 @@ class AppCheckTokenProvider {
|
|
|
70
75
|
// becomes available before the timoeout below expires.
|
|
71
76
|
setTimeout(() => {
|
|
72
77
|
if (this.appCheck) {
|
|
73
|
-
this.getToken(
|
|
78
|
+
this.getToken().then(resolve, reject);
|
|
74
79
|
}
|
|
75
80
|
else {
|
|
76
81
|
resolve(null);
|
|
@@ -78,7 +83,7 @@ class AppCheckTokenProvider {
|
|
|
78
83
|
}, 0);
|
|
79
84
|
});
|
|
80
85
|
}
|
|
81
|
-
return this.appCheck.getToken(
|
|
86
|
+
return this.appCheck.getToken();
|
|
82
87
|
}
|
|
83
88
|
addTokenChangeListener(listener) {
|
|
84
89
|
var _a;
|
|
@@ -434,6 +439,31 @@ function compareDates(str1, str2) {
|
|
|
434
439
|
return date1.getTime() < date2.getTime();
|
|
435
440
|
}
|
|
436
441
|
|
|
442
|
+
/**
|
|
443
|
+
* @license
|
|
444
|
+
* Copyright 2024 Google LLC
|
|
445
|
+
*
|
|
446
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
447
|
+
* you may not use this file except in compliance with the License.
|
|
448
|
+
* You may obtain a copy of the License at
|
|
449
|
+
*
|
|
450
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
451
|
+
*
|
|
452
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
453
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
454
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
455
|
+
* See the License for the specific language governing permissions and
|
|
456
|
+
* limitations under the License.
|
|
457
|
+
*/
|
|
458
|
+
const CallerSdkTypeEnum = {
|
|
459
|
+
Base: 'Base', // Core JS SDK
|
|
460
|
+
Generated: 'Generated', // Generated JS SDK
|
|
461
|
+
TanstackReactCore: 'TanstackReactCore', // Tanstack non-generated React SDK
|
|
462
|
+
GeneratedReact: 'GeneratedReact', // Tanstack non-generated Angular SDK
|
|
463
|
+
TanstackAngularCore: 'TanstackAngularCore', // Tanstack non-generated Angular SDK
|
|
464
|
+
GeneratedAngular: 'GeneratedAngular' // Generated Angular SDK
|
|
465
|
+
};
|
|
466
|
+
|
|
437
467
|
/**
|
|
438
468
|
* @license
|
|
439
469
|
* Copyright 2024 Google LLC
|
|
@@ -491,20 +521,24 @@ function addToken(url, apiKey) {
|
|
|
491
521
|
* limitations under the License.
|
|
492
522
|
*/
|
|
493
523
|
let connectFetch = globalThis.fetch;
|
|
494
|
-
function getGoogApiClientValue(_isUsingGen) {
|
|
524
|
+
function getGoogApiClientValue(_isUsingGen, _callerSdkType) {
|
|
495
525
|
let str = 'gl-js/ fire/' + SDK_VERSION;
|
|
496
|
-
if (
|
|
526
|
+
if (_callerSdkType !== CallerSdkTypeEnum.Base &&
|
|
527
|
+
_callerSdkType !== CallerSdkTypeEnum.Generated) {
|
|
528
|
+
str += ' js/' + _callerSdkType.toLowerCase();
|
|
529
|
+
}
|
|
530
|
+
else if (_isUsingGen || _callerSdkType === CallerSdkTypeEnum.Generated) {
|
|
497
531
|
str += ' js/gen';
|
|
498
532
|
}
|
|
499
533
|
return str;
|
|
500
534
|
}
|
|
501
|
-
function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen) {
|
|
535
|
+
function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen, _callerSdkType) {
|
|
502
536
|
if (!connectFetch) {
|
|
503
537
|
throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
|
|
504
538
|
}
|
|
505
539
|
const headers = {
|
|
506
540
|
'Content-Type': 'application/json',
|
|
507
|
-
'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen)
|
|
541
|
+
'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen, _callerSdkType)
|
|
508
542
|
};
|
|
509
543
|
if (accessToken) {
|
|
510
544
|
headers['X-Firebase-Auth-Token'] = accessToken;
|
|
@@ -577,13 +611,14 @@ function getMessage(obj) {
|
|
|
577
611
|
* limitations under the License.
|
|
578
612
|
*/
|
|
579
613
|
class RESTTransport {
|
|
580
|
-
constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false) {
|
|
614
|
+
constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false, _callerSdkType = CallerSdkTypeEnum.Base) {
|
|
581
615
|
var _a, _b;
|
|
582
616
|
this.apiKey = apiKey;
|
|
583
617
|
this.appId = appId;
|
|
584
618
|
this.authProvider = authProvider;
|
|
585
619
|
this.appCheckProvider = appCheckProvider;
|
|
586
620
|
this._isUsingGen = _isUsingGen;
|
|
621
|
+
this._callerSdkType = _callerSdkType;
|
|
587
622
|
this._host = '';
|
|
588
623
|
this._location = 'l';
|
|
589
624
|
this._connectorName = '';
|
|
@@ -600,7 +635,7 @@ class RESTTransport {
|
|
|
600
635
|
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
601
636
|
operationName: queryName,
|
|
602
637
|
variables: body
|
|
603
|
-
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen));
|
|
638
|
+
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen, this._callerSdkType));
|
|
604
639
|
return withAuth;
|
|
605
640
|
};
|
|
606
641
|
this.invokeMutation = (mutationName, body) => {
|
|
@@ -610,7 +645,7 @@ class RESTTransport {
|
|
|
610
645
|
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
611
646
|
operationName: mutationName,
|
|
612
647
|
variables: body
|
|
613
|
-
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen);
|
|
648
|
+
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen, this._callerSdkType);
|
|
614
649
|
});
|
|
615
650
|
return taskResult;
|
|
616
651
|
};
|
|
@@ -711,6 +746,9 @@ class RESTTransport {
|
|
|
711
746
|
throw err;
|
|
712
747
|
});
|
|
713
748
|
}
|
|
749
|
+
_setCallerSdkType(callerSdkType) {
|
|
750
|
+
this._callerSdkType = callerSdkType;
|
|
751
|
+
}
|
|
714
752
|
}
|
|
715
753
|
|
|
716
754
|
/**
|
|
@@ -820,6 +858,7 @@ class DataConnect {
|
|
|
820
858
|
this.isEmulator = false;
|
|
821
859
|
this._initialized = false;
|
|
822
860
|
this._isUsingGeneratedSdk = false;
|
|
861
|
+
this._callerSdkType = CallerSdkTypeEnum.Base;
|
|
823
862
|
if (typeof process !== 'undefined' && process.env) {
|
|
824
863
|
const host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
|
|
825
864
|
if (host) {
|
|
@@ -835,6 +874,12 @@ class DataConnect {
|
|
|
835
874
|
this._isUsingGeneratedSdk = true;
|
|
836
875
|
}
|
|
837
876
|
}
|
|
877
|
+
_setCallerSdkType(callerSdkType) {
|
|
878
|
+
this._callerSdkType = callerSdkType;
|
|
879
|
+
if (this._initialized) {
|
|
880
|
+
this._transport._setCallerSdkType(callerSdkType);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
838
883
|
_delete() {
|
|
839
884
|
_removeServiceInstance(this.app, 'data-connect', JSON.stringify(this.getSettings()));
|
|
840
885
|
return Promise.resolve();
|
|
@@ -858,10 +903,10 @@ class DataConnect {
|
|
|
858
903
|
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
859
904
|
}
|
|
860
905
|
if (this._appCheckProvider) {
|
|
861
|
-
this._appCheckTokenProvider = new AppCheckTokenProvider(this.app
|
|
906
|
+
this._appCheckTokenProvider = new AppCheckTokenProvider(this.app, this._appCheckProvider);
|
|
862
907
|
}
|
|
863
908
|
this._initialized = true;
|
|
864
|
-
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk);
|
|
909
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk, this._callerSdkType);
|
|
865
910
|
if (this._transportOptions) {
|
|
866
911
|
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
867
912
|
}
|
|
@@ -1036,7 +1081,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
1036
1081
|
dataConnect: dcInstance,
|
|
1037
1082
|
refType: QUERY_STR,
|
|
1038
1083
|
name: queryName,
|
|
1039
|
-
variables
|
|
1084
|
+
variables
|
|
1040
1085
|
};
|
|
1041
1086
|
}
|
|
1042
1087
|
/**
|
|
@@ -1154,5 +1199,5 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
1154
1199
|
*/
|
|
1155
1200
|
registerDataConnect();
|
|
1156
1201
|
|
|
1157
|
-
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 };
|
|
1202
|
+
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 };
|
|
1158
1203
|
//# sourceMappingURL=index.esm2017.js.map
|