@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/README.md
ADDED
package/dist/index.cjs.js
CHANGED
|
@@ -8,7 +8,7 @@ var util = require('@firebase/util');
|
|
|
8
8
|
var logger$1 = require('@firebase/logger');
|
|
9
9
|
|
|
10
10
|
const name = "@firebase/data-connect";
|
|
11
|
-
const version = "0.
|
|
11
|
+
const version = "0.3.0-20250205220033";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @license
|
|
@@ -57,15 +57,20 @@ function setSDKVersion(version) {
|
|
|
57
57
|
* Abstraction around AppCheck's token fetching capabilities.
|
|
58
58
|
*/
|
|
59
59
|
class AppCheckTokenProvider {
|
|
60
|
-
constructor(
|
|
61
|
-
this.appName_ = appName_;
|
|
60
|
+
constructor(app$1, appCheckProvider) {
|
|
62
61
|
this.appCheckProvider = appCheckProvider;
|
|
62
|
+
if (app._isFirebaseServerApp(app$1) && app$1.settings.appCheckToken) {
|
|
63
|
+
this.serverAppAppCheckToken = app$1.settings.appCheckToken;
|
|
64
|
+
}
|
|
63
65
|
this.appCheck = appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.getImmediate({ optional: true });
|
|
64
66
|
if (!this.appCheck) {
|
|
65
67
|
void (appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(appCheck => (this.appCheck = appCheck)).catch());
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
getToken(
|
|
70
|
+
getToken() {
|
|
71
|
+
if (this.serverAppAppCheckToken) {
|
|
72
|
+
return Promise.resolve({ token: this.serverAppAppCheckToken });
|
|
73
|
+
}
|
|
69
74
|
if (!this.appCheck) {
|
|
70
75
|
return new Promise((resolve, reject) => {
|
|
71
76
|
// Support delayed initialization of FirebaseAppCheck. This allows our
|
|
@@ -74,7 +79,7 @@ class AppCheckTokenProvider {
|
|
|
74
79
|
// becomes available before the timoeout below expires.
|
|
75
80
|
setTimeout(() => {
|
|
76
81
|
if (this.appCheck) {
|
|
77
|
-
this.getToken(
|
|
82
|
+
this.getToken().then(resolve, reject);
|
|
78
83
|
}
|
|
79
84
|
else {
|
|
80
85
|
resolve(null);
|
|
@@ -82,7 +87,7 @@ class AppCheckTokenProvider {
|
|
|
82
87
|
}, 0);
|
|
83
88
|
});
|
|
84
89
|
}
|
|
85
|
-
return this.appCheck.getToken(
|
|
90
|
+
return this.appCheck.getToken();
|
|
86
91
|
}
|
|
87
92
|
addTokenChangeListener(listener) {
|
|
88
93
|
var _a;
|
|
@@ -438,6 +443,31 @@ function compareDates(str1, str2) {
|
|
|
438
443
|
return date1.getTime() < date2.getTime();
|
|
439
444
|
}
|
|
440
445
|
|
|
446
|
+
/**
|
|
447
|
+
* @license
|
|
448
|
+
* Copyright 2024 Google LLC
|
|
449
|
+
*
|
|
450
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
451
|
+
* you may not use this file except in compliance with the License.
|
|
452
|
+
* You may obtain a copy of the License at
|
|
453
|
+
*
|
|
454
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
455
|
+
*
|
|
456
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
457
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
458
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
459
|
+
* See the License for the specific language governing permissions and
|
|
460
|
+
* limitations under the License.
|
|
461
|
+
*/
|
|
462
|
+
const CallerSdkTypeEnum = {
|
|
463
|
+
Base: 'Base', // Core JS SDK
|
|
464
|
+
Generated: 'Generated', // Generated JS SDK
|
|
465
|
+
TanstackReactCore: 'TanstackReactCore', // Tanstack non-generated React SDK
|
|
466
|
+
GeneratedReact: 'GeneratedReact', // Tanstack non-generated Angular SDK
|
|
467
|
+
TanstackAngularCore: 'TanstackAngularCore', // Tanstack non-generated Angular SDK
|
|
468
|
+
GeneratedAngular: 'GeneratedAngular' // Generated Angular SDK
|
|
469
|
+
};
|
|
470
|
+
|
|
441
471
|
/**
|
|
442
472
|
* @license
|
|
443
473
|
* Copyright 2024 Google LLC
|
|
@@ -495,20 +525,24 @@ function addToken(url, apiKey) {
|
|
|
495
525
|
* limitations under the License.
|
|
496
526
|
*/
|
|
497
527
|
let connectFetch = globalThis.fetch;
|
|
498
|
-
function getGoogApiClientValue(_isUsingGen) {
|
|
528
|
+
function getGoogApiClientValue(_isUsingGen, _callerSdkType) {
|
|
499
529
|
let str = 'gl-js/ fire/' + SDK_VERSION;
|
|
500
|
-
if (
|
|
530
|
+
if (_callerSdkType !== CallerSdkTypeEnum.Base &&
|
|
531
|
+
_callerSdkType !== CallerSdkTypeEnum.Generated) {
|
|
532
|
+
str += ' js/' + _callerSdkType.toLowerCase();
|
|
533
|
+
}
|
|
534
|
+
else if (_isUsingGen || _callerSdkType === CallerSdkTypeEnum.Generated) {
|
|
501
535
|
str += ' js/gen';
|
|
502
536
|
}
|
|
503
537
|
return str;
|
|
504
538
|
}
|
|
505
|
-
function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen) {
|
|
539
|
+
function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen, _callerSdkType) {
|
|
506
540
|
if (!connectFetch) {
|
|
507
541
|
throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
|
|
508
542
|
}
|
|
509
543
|
const headers = {
|
|
510
544
|
'Content-Type': 'application/json',
|
|
511
|
-
'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen)
|
|
545
|
+
'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen, _callerSdkType)
|
|
512
546
|
};
|
|
513
547
|
if (accessToken) {
|
|
514
548
|
headers['X-Firebase-Auth-Token'] = accessToken;
|
|
@@ -581,13 +615,14 @@ function getMessage(obj) {
|
|
|
581
615
|
* limitations under the License.
|
|
582
616
|
*/
|
|
583
617
|
class RESTTransport {
|
|
584
|
-
constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false) {
|
|
618
|
+
constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false, _callerSdkType = CallerSdkTypeEnum.Base) {
|
|
585
619
|
var _a, _b;
|
|
586
620
|
this.apiKey = apiKey;
|
|
587
621
|
this.appId = appId;
|
|
588
622
|
this.authProvider = authProvider;
|
|
589
623
|
this.appCheckProvider = appCheckProvider;
|
|
590
624
|
this._isUsingGen = _isUsingGen;
|
|
625
|
+
this._callerSdkType = _callerSdkType;
|
|
591
626
|
this._host = '';
|
|
592
627
|
this._location = 'l';
|
|
593
628
|
this._connectorName = '';
|
|
@@ -604,7 +639,7 @@ class RESTTransport {
|
|
|
604
639
|
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
605
640
|
operationName: queryName,
|
|
606
641
|
variables: body
|
|
607
|
-
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen));
|
|
642
|
+
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen, this._callerSdkType));
|
|
608
643
|
return withAuth;
|
|
609
644
|
};
|
|
610
645
|
this.invokeMutation = (mutationName, body) => {
|
|
@@ -614,7 +649,7 @@ class RESTTransport {
|
|
|
614
649
|
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
|
|
615
650
|
operationName: mutationName,
|
|
616
651
|
variables: body
|
|
617
|
-
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen);
|
|
652
|
+
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen, this._callerSdkType);
|
|
618
653
|
});
|
|
619
654
|
return taskResult;
|
|
620
655
|
};
|
|
@@ -715,6 +750,9 @@ class RESTTransport {
|
|
|
715
750
|
throw err;
|
|
716
751
|
});
|
|
717
752
|
}
|
|
753
|
+
_setCallerSdkType(callerSdkType) {
|
|
754
|
+
this._callerSdkType = callerSdkType;
|
|
755
|
+
}
|
|
718
756
|
}
|
|
719
757
|
|
|
720
758
|
/**
|
|
@@ -824,6 +862,7 @@ class DataConnect {
|
|
|
824
862
|
this.isEmulator = false;
|
|
825
863
|
this._initialized = false;
|
|
826
864
|
this._isUsingGeneratedSdk = false;
|
|
865
|
+
this._callerSdkType = CallerSdkTypeEnum.Base;
|
|
827
866
|
if (typeof process !== 'undefined' && process.env) {
|
|
828
867
|
const host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
|
|
829
868
|
if (host) {
|
|
@@ -839,6 +878,12 @@ class DataConnect {
|
|
|
839
878
|
this._isUsingGeneratedSdk = true;
|
|
840
879
|
}
|
|
841
880
|
}
|
|
881
|
+
_setCallerSdkType(callerSdkType) {
|
|
882
|
+
this._callerSdkType = callerSdkType;
|
|
883
|
+
if (this._initialized) {
|
|
884
|
+
this._transport._setCallerSdkType(callerSdkType);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
842
887
|
_delete() {
|
|
843
888
|
app._removeServiceInstance(this.app, 'data-connect', JSON.stringify(this.getSettings()));
|
|
844
889
|
return Promise.resolve();
|
|
@@ -862,10 +907,10 @@ class DataConnect {
|
|
|
862
907
|
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
863
908
|
}
|
|
864
909
|
if (this._appCheckProvider) {
|
|
865
|
-
this._appCheckTokenProvider = new AppCheckTokenProvider(this.app
|
|
910
|
+
this._appCheckTokenProvider = new AppCheckTokenProvider(this.app, this._appCheckProvider);
|
|
866
911
|
}
|
|
867
912
|
this._initialized = true;
|
|
868
|
-
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk);
|
|
913
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk, this._callerSdkType);
|
|
869
914
|
if (this._transportOptions) {
|
|
870
915
|
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
871
916
|
}
|
|
@@ -1040,7 +1085,7 @@ function queryRef(dcInstance, queryName, variables, initialCache) {
|
|
|
1040
1085
|
dataConnect: dcInstance,
|
|
1041
1086
|
refType: QUERY_STR,
|
|
1042
1087
|
name: queryName,
|
|
1043
|
-
variables
|
|
1088
|
+
variables
|
|
1044
1089
|
};
|
|
1045
1090
|
}
|
|
1046
1091
|
/**
|
|
@@ -1158,6 +1203,7 @@ function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComp
|
|
|
1158
1203
|
*/
|
|
1159
1204
|
registerDataConnect();
|
|
1160
1205
|
|
|
1206
|
+
exports.CallerSdkTypeEnum = CallerSdkTypeEnum;
|
|
1161
1207
|
exports.DataConnect = DataConnect;
|
|
1162
1208
|
exports.MUTATION_STR = MUTATION_STR;
|
|
1163
1209
|
exports.MutationManager = MutationManager;
|