@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.
- package/dist/index.cjs.js +246 -52
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +245 -51
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +265 -50
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +266 -51
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/internal.d.ts +59 -33
- package/dist/node-esm/index.node.esm.js +245 -51
- package/dist/node-esm/index.node.esm.js.map +1 -1
- package/dist/node-esm/src/api/DataConnect.d.ts +14 -3
- package/dist/node-esm/src/api/index.d.ts +1 -0
- package/dist/node-esm/src/api/query.d.ts +1 -1
- package/dist/node-esm/src/core/AppCheckTokenProvider.d.ts +30 -0
- package/dist/node-esm/src/core/FirebaseAuthProvider.d.ts +1 -1
- package/dist/node-esm/src/core/QueryManager.d.ts +1 -1
- package/dist/node-esm/src/core/error.d.ts +2 -1
- package/dist/node-esm/src/network/fetch.d.ts +1 -1
- package/dist/node-esm/src/network/transport/index.d.ts +8 -10
- package/dist/node-esm/src/network/transport/rest.d.ts +24 -10
- package/dist/node-esm/src/util/validateArgs.d.ts +33 -0
- package/dist/private.d.ts +27 -45
- package/dist/public.d.ts +8 -38
- package/dist/src/api/DataConnect.d.ts +14 -3
- package/dist/src/api/index.d.ts +1 -0
- package/dist/src/api/query.d.ts +1 -1
- package/dist/src/core/AppCheckTokenProvider.d.ts +30 -0
- package/dist/src/core/FirebaseAuthProvider.d.ts +1 -1
- package/dist/src/core/QueryManager.d.ts +1 -1
- package/dist/src/core/error.d.ts +2 -1
- package/dist/src/network/fetch.d.ts +1 -1
- package/dist/src/network/transport/index.d.ts +8 -10
- package/dist/src/network/transport/rest.d.ts +24 -10
- package/dist/src/util/validateArgs.d.ts +33 -0
- package/package.json +11 -7
package/dist/index.node.cjs.js
CHANGED
|
@@ -30,7 +30,8 @@ var Code = {
|
|
|
30
30
|
NOT_INITIALIZED: 'not-initialized',
|
|
31
31
|
NOT_SUPPORTED: 'not-supported',
|
|
32
32
|
INVALID_ARGUMENT: 'invalid-argument',
|
|
33
|
-
PARTIAL_ERROR: 'partial-error'
|
|
33
|
+
PARTIAL_ERROR: 'partial-error',
|
|
34
|
+
UNAUTHORIZED: 'unauthorized'
|
|
34
35
|
};
|
|
35
36
|
/** An error returned by a DataConnect operation. */
|
|
36
37
|
var DataConnectError = /** @class */ (function (_super) {
|
|
@@ -130,18 +131,32 @@ var connectFetch = globalThis.fetch;
|
|
|
130
131
|
function initializeFetch(fetchImpl) {
|
|
131
132
|
connectFetch = fetchImpl;
|
|
132
133
|
}
|
|
133
|
-
function
|
|
134
|
+
function getGoogApiClientValue(_isUsingGen) {
|
|
135
|
+
var str = 'gl-js/ fire/' + SDK_VERSION;
|
|
136
|
+
if (_isUsingGen) {
|
|
137
|
+
str += ' web/gen';
|
|
138
|
+
}
|
|
139
|
+
return str;
|
|
140
|
+
}
|
|
141
|
+
function dcFetch(url, body, _a, appId, accessToken, appCheckToken, _isUsingGen) {
|
|
134
142
|
var _this = this;
|
|
135
143
|
var signal = _a.signal;
|
|
136
144
|
if (!connectFetch) {
|
|
137
145
|
throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
|
|
138
146
|
}
|
|
139
147
|
var headers = {
|
|
140
|
-
'Content-Type': 'application/json'
|
|
148
|
+
'Content-Type': 'application/json',
|
|
149
|
+
'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen)
|
|
141
150
|
};
|
|
142
151
|
if (accessToken) {
|
|
143
152
|
headers['X-Firebase-Auth-Token'] = accessToken;
|
|
144
153
|
}
|
|
154
|
+
if (appId) {
|
|
155
|
+
headers['x-firebase-gmpid'] = appId;
|
|
156
|
+
}
|
|
157
|
+
if (appCheckToken) {
|
|
158
|
+
headers['X-Firebase-AppCheck'] = appCheckToken;
|
|
159
|
+
}
|
|
145
160
|
var bodyStr = JSON.stringify(body);
|
|
146
161
|
logDebug("Making request out to ".concat(url, " with body: ").concat(bodyStr));
|
|
147
162
|
return connectFetch(url, {
|
|
@@ -149,11 +164,12 @@ function dcFetch(url, body, _a, accessToken) {
|
|
|
149
164
|
method: 'POST',
|
|
150
165
|
headers: headers,
|
|
151
166
|
signal: signal
|
|
152
|
-
})
|
|
153
|
-
|
|
167
|
+
})
|
|
168
|
+
.catch(function (err) {
|
|
169
|
+
throw new DataConnectError(Code.OTHER, 'Failed to fetch: ' + JSON.stringify(err));
|
|
154
170
|
})
|
|
155
171
|
.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
156
|
-
var jsonResponse, e_1;
|
|
172
|
+
var jsonResponse, e_1, message;
|
|
157
173
|
return tslib.__generator(this, function (_a) {
|
|
158
174
|
switch (_a.label) {
|
|
159
175
|
case 0:
|
|
@@ -169,9 +185,13 @@ function dcFetch(url, body, _a, accessToken) {
|
|
|
169
185
|
e_1 = _a.sent();
|
|
170
186
|
throw new DataConnectError(Code.OTHER, JSON.stringify(e_1));
|
|
171
187
|
case 4:
|
|
188
|
+
message = getMessage(jsonResponse);
|
|
172
189
|
if (response.status >= 400) {
|
|
173
190
|
logError('Error while performing request: ' + JSON.stringify(jsonResponse));
|
|
174
|
-
|
|
191
|
+
if (response.status === 401) {
|
|
192
|
+
throw new DataConnectError(Code.UNAUTHORIZED, message);
|
|
193
|
+
}
|
|
194
|
+
throw new DataConnectError(Code.OTHER, message);
|
|
175
195
|
}
|
|
176
196
|
return [2 /*return*/, jsonResponse];
|
|
177
197
|
}
|
|
@@ -185,10 +205,16 @@ function dcFetch(url, body, _a, accessToken) {
|
|
|
185
205
|
}
|
|
186
206
|
return res;
|
|
187
207
|
});
|
|
208
|
+
}
|
|
209
|
+
function getMessage(obj) {
|
|
210
|
+
if ('message' in obj) {
|
|
211
|
+
return obj.message;
|
|
212
|
+
}
|
|
213
|
+
return JSON.stringify(obj);
|
|
188
214
|
}
|
|
189
215
|
|
|
190
216
|
var name = "@firebase/data-connect";
|
|
191
|
-
var version = "0.0.
|
|
217
|
+
var version = "0.0.3-canary.beaa4dffb";
|
|
192
218
|
|
|
193
219
|
/**
|
|
194
220
|
* @license
|
|
@@ -206,6 +232,64 @@ var version = "0.0.2-dataconnect-preview.388b61c7e";
|
|
|
206
232
|
* See the License for the specific language governing permissions and
|
|
207
233
|
* limitations under the License.
|
|
208
234
|
*/
|
|
235
|
+
/**
|
|
236
|
+
* @internal
|
|
237
|
+
* Abstraction around AppCheck's token fetching capabilities.
|
|
238
|
+
*/
|
|
239
|
+
var AppCheckTokenProvider = /** @class */ (function () {
|
|
240
|
+
function AppCheckTokenProvider(appName_, appCheckProvider) {
|
|
241
|
+
var _this = this;
|
|
242
|
+
this.appName_ = appName_;
|
|
243
|
+
this.appCheckProvider = appCheckProvider;
|
|
244
|
+
this.appCheck = appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.getImmediate({ optional: true });
|
|
245
|
+
if (!this.appCheck) {
|
|
246
|
+
void (appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(function (appCheck) { return (_this.appCheck = appCheck); }).catch());
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
AppCheckTokenProvider.prototype.getToken = function (forceRefresh) {
|
|
250
|
+
var _this = this;
|
|
251
|
+
if (!this.appCheck) {
|
|
252
|
+
return new Promise(function (resolve, reject) {
|
|
253
|
+
// Support delayed initialization of FirebaseAppCheck. This allows our
|
|
254
|
+
// customers to initialize the RTDB SDK before initializing Firebase
|
|
255
|
+
// AppCheck and ensures that all requests are authenticated if a token
|
|
256
|
+
// becomes available before the timoeout below expires.
|
|
257
|
+
setTimeout(function () {
|
|
258
|
+
if (_this.appCheck) {
|
|
259
|
+
_this.getToken(forceRefresh).then(resolve, reject);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
resolve(null);
|
|
263
|
+
}
|
|
264
|
+
}, 0);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return this.appCheck.getToken(forceRefresh);
|
|
268
|
+
};
|
|
269
|
+
AppCheckTokenProvider.prototype.addTokenChangeListener = function (listener) {
|
|
270
|
+
var _a;
|
|
271
|
+
void ((_a = this.appCheckProvider) === null || _a === void 0 ? void 0 : _a.get().then(function (appCheck) { return appCheck.addTokenListener(listener); }));
|
|
272
|
+
};
|
|
273
|
+
return AppCheckTokenProvider;
|
|
274
|
+
}());
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @license
|
|
278
|
+
* Copyright 2024 Google LLC
|
|
279
|
+
*
|
|
280
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
281
|
+
* you may not use this file except in compliance with the License.
|
|
282
|
+
* You may obtain a copy of the License at
|
|
283
|
+
*
|
|
284
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
285
|
+
*
|
|
286
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
287
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
288
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
289
|
+
* See the License for the specific language governing permissions and
|
|
290
|
+
* limitations under the License.
|
|
291
|
+
*/
|
|
292
|
+
// @internal
|
|
209
293
|
var FirebaseAuthProvider = /** @class */ (function () {
|
|
210
294
|
function FirebaseAuthProvider(_appName, _options, _authProvider) {
|
|
211
295
|
var _this = this;
|
|
@@ -250,7 +334,8 @@ var FirebaseAuthProvider = /** @class */ (function () {
|
|
|
250
334
|
FirebaseAuthProvider.prototype.removeTokenChangeListener = function (listener) {
|
|
251
335
|
this._authProvider
|
|
252
336
|
.get()
|
|
253
|
-
.then(function (auth) { return auth.removeAuthTokenListener(listener); })
|
|
337
|
+
.then(function (auth) { return auth.removeAuthTokenListener(listener); })
|
|
338
|
+
.catch(function (err) { return logError(err); });
|
|
254
339
|
};
|
|
255
340
|
return FirebaseAuthProvider;
|
|
256
341
|
}());
|
|
@@ -493,7 +578,7 @@ function urlBuilder(projectConfig, transportOptions) {
|
|
|
493
578
|
logError('Port type is of an invalid type');
|
|
494
579
|
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Incorrect type for port passed in!');
|
|
495
580
|
}
|
|
496
|
-
return "".concat(baseUrl, "/
|
|
581
|
+
return "".concat(baseUrl, "/v1beta/projects/").concat(project, "/locations/").concat(location, "/services/").concat(service, "/connectors/").concat(connector);
|
|
497
582
|
}
|
|
498
583
|
function addToken(url, apiKey) {
|
|
499
584
|
if (!apiKey) {
|
|
@@ -521,42 +606,48 @@ function addToken(url, apiKey) {
|
|
|
521
606
|
* limitations under the License.
|
|
522
607
|
*/
|
|
523
608
|
var RESTTransport = /** @class */ (function () {
|
|
524
|
-
function RESTTransport(options, apiKey, authProvider, transportOptions) {
|
|
609
|
+
function RESTTransport(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen) {
|
|
610
|
+
if (_isUsingGen === void 0) { _isUsingGen = false; }
|
|
525
611
|
var _this = this;
|
|
526
|
-
var _a;
|
|
612
|
+
var _a, _b;
|
|
527
613
|
this.apiKey = apiKey;
|
|
614
|
+
this.appId = appId;
|
|
528
615
|
this.authProvider = authProvider;
|
|
616
|
+
this.appCheckProvider = appCheckProvider;
|
|
617
|
+
this._isUsingGen = _isUsingGen;
|
|
529
618
|
this._host = '';
|
|
530
619
|
this._location = 'l';
|
|
531
620
|
this._connectorName = '';
|
|
532
621
|
this._secure = true;
|
|
533
622
|
this._project = 'p';
|
|
534
623
|
this._accessToken = null;
|
|
535
|
-
this.
|
|
624
|
+
this._appCheckToken = null;
|
|
625
|
+
this._lastToken = null;
|
|
536
626
|
// TODO(mtewani): Update U to include shape of body defined in line 13.
|
|
537
627
|
this.invokeQuery = function (queryName, body) {
|
|
538
628
|
var abortController = new AbortController();
|
|
539
629
|
// TODO(mtewani): Update to proper value
|
|
540
|
-
var withAuth = _this.
|
|
630
|
+
var withAuth = _this.withRetry(function () {
|
|
541
631
|
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
|
|
542
632
|
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
|
|
543
633
|
operationName: queryName,
|
|
544
634
|
variables: body
|
|
545
635
|
}, // TODO(mtewani): This is a patch, fix this.
|
|
546
|
-
abortController, _this._accessToken);
|
|
636
|
+
abortController, _this.appId, _this._accessToken, _this._appCheckToken, _this._isUsingGen);
|
|
547
637
|
});
|
|
548
638
|
return {
|
|
549
|
-
then: withAuth.then.bind(withAuth)
|
|
639
|
+
then: withAuth.then.bind(withAuth),
|
|
640
|
+
catch: withAuth.catch.bind(withAuth)
|
|
550
641
|
};
|
|
551
642
|
};
|
|
552
643
|
this.invokeMutation = function (mutationName, body) {
|
|
553
644
|
var abortController = new AbortController();
|
|
554
|
-
var taskResult = _this.
|
|
645
|
+
var taskResult = _this.withRetry(function () {
|
|
555
646
|
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
|
|
556
647
|
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
|
|
557
648
|
operationName: mutationName,
|
|
558
649
|
variables: body
|
|
559
|
-
}, abortController, _this._accessToken);
|
|
650
|
+
}, abortController, _this.appId, _this._accessToken, _this._appCheckToken, _this._isUsingGen);
|
|
560
651
|
});
|
|
561
652
|
return {
|
|
562
653
|
then: taskResult.then.bind(taskResult),
|
|
@@ -590,6 +681,11 @@ var RESTTransport = /** @class */ (function () {
|
|
|
590
681
|
logDebug("New Token Available: ".concat(token));
|
|
591
682
|
_this._accessToken = token;
|
|
592
683
|
});
|
|
684
|
+
(_b = this.appCheckProvider) === null || _b === void 0 ? void 0 : _b.addTokenChangeListener(function (result) {
|
|
685
|
+
var token = result.token;
|
|
686
|
+
logDebug("New App Check Token Available: ".concat(token));
|
|
687
|
+
_this._appCheckToken = token;
|
|
688
|
+
});
|
|
593
689
|
}
|
|
594
690
|
Object.defineProperty(RESTTransport.prototype, "endpointUrl", {
|
|
595
691
|
get: function () {
|
|
@@ -615,28 +711,69 @@ var RESTTransport = /** @class */ (function () {
|
|
|
615
711
|
RESTTransport.prototype.onTokenChanged = function (newToken) {
|
|
616
712
|
this._accessToken = newToken;
|
|
617
713
|
};
|
|
618
|
-
RESTTransport.prototype.getWithAuth = function () {
|
|
619
|
-
var
|
|
620
|
-
|
|
621
|
-
|
|
714
|
+
RESTTransport.prototype.getWithAuth = function (forceToken) {
|
|
715
|
+
var _a;
|
|
716
|
+
if (forceToken === void 0) { forceToken = false; }
|
|
717
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
718
|
+
var starterPromise, _b;
|
|
719
|
+
var _this = this;
|
|
720
|
+
return tslib.__generator(this, function (_c) {
|
|
721
|
+
switch (_c.label) {
|
|
722
|
+
case 0:
|
|
723
|
+
starterPromise = new Promise(function (resolve) {
|
|
724
|
+
return resolve(_this._accessToken);
|
|
725
|
+
});
|
|
726
|
+
if (!this.appCheckProvider) return [3 /*break*/, 2];
|
|
727
|
+
_b = this;
|
|
728
|
+
return [4 /*yield*/, this.appCheckProvider.getToken()];
|
|
729
|
+
case 1:
|
|
730
|
+
_b._appCheckToken = (_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.token;
|
|
731
|
+
_c.label = 2;
|
|
732
|
+
case 2:
|
|
733
|
+
if (this.authProvider) {
|
|
734
|
+
starterPromise = this.authProvider
|
|
735
|
+
.getToken(/*forceToken=*/ forceToken)
|
|
736
|
+
.then(function (data) {
|
|
737
|
+
if (!data) {
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
740
|
+
_this._accessToken = data.accessToken;
|
|
741
|
+
return _this._accessToken;
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
starterPromise = new Promise(function (resolve) { return resolve(''); });
|
|
746
|
+
}
|
|
747
|
+
return [2 /*return*/, starterPromise];
|
|
748
|
+
}
|
|
749
|
+
});
|
|
622
750
|
});
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
751
|
+
};
|
|
752
|
+
RESTTransport.prototype._setLastToken = function (lastToken) {
|
|
753
|
+
this._lastToken = lastToken;
|
|
754
|
+
};
|
|
755
|
+
RESTTransport.prototype.withRetry = function (promiseFactory, retry) {
|
|
756
|
+
var _this = this;
|
|
757
|
+
if (retry === void 0) { retry = false; }
|
|
758
|
+
var isNewToken = false;
|
|
759
|
+
return this.getWithAuth(retry)
|
|
760
|
+
.then(function (res) {
|
|
761
|
+
isNewToken = _this._lastToken !== res;
|
|
762
|
+
_this._lastToken = res;
|
|
763
|
+
return res;
|
|
764
|
+
})
|
|
765
|
+
.then(promiseFactory)
|
|
766
|
+
.catch(function (err) {
|
|
767
|
+
// Only retry if the result is unauthorized and the last token isn't the same as the new one.
|
|
768
|
+
if ('code' in err &&
|
|
769
|
+
err.code === Code.UNAUTHORIZED &&
|
|
770
|
+
!retry &&
|
|
771
|
+
isNewToken) {
|
|
772
|
+
logDebug('Retrying due to unauthorized');
|
|
773
|
+
return _this.withRetry(promiseFactory, true);
|
|
637
774
|
}
|
|
638
|
-
|
|
639
|
-
|
|
775
|
+
throw err;
|
|
776
|
+
});
|
|
640
777
|
};
|
|
641
778
|
return RESTTransport;
|
|
642
779
|
}());
|
|
@@ -741,14 +878,17 @@ function parseOptions(fullHost) {
|
|
|
741
878
|
* Class representing Firebase Data Connect
|
|
742
879
|
*/
|
|
743
880
|
var DataConnect = /** @class */ (function () {
|
|
881
|
+
// @internal
|
|
744
882
|
function DataConnect(app,
|
|
745
883
|
// TODO(mtewani): Replace with _dataConnectOptions in the future
|
|
746
|
-
dataConnectOptions, _authProvider) {
|
|
884
|
+
dataConnectOptions, _authProvider, _appCheckProvider) {
|
|
747
885
|
this.app = app;
|
|
748
886
|
this.dataConnectOptions = dataConnectOptions;
|
|
749
887
|
this._authProvider = _authProvider;
|
|
888
|
+
this._appCheckProvider = _appCheckProvider;
|
|
750
889
|
this.isEmulator = false;
|
|
751
|
-
this.
|
|
890
|
+
this._initialized = false;
|
|
891
|
+
this._isUsingGeneratedSdk = false;
|
|
752
892
|
if (typeof process !== 'undefined' && process.env) {
|
|
753
893
|
var host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
|
|
754
894
|
if (host) {
|
|
@@ -758,17 +898,25 @@ var DataConnect = /** @class */ (function () {
|
|
|
758
898
|
}
|
|
759
899
|
}
|
|
760
900
|
}
|
|
901
|
+
// @internal
|
|
902
|
+
DataConnect.prototype._useGeneratedSdk = function () {
|
|
903
|
+
if (!this._isUsingGeneratedSdk) {
|
|
904
|
+
this._isUsingGeneratedSdk = true;
|
|
905
|
+
}
|
|
906
|
+
};
|
|
761
907
|
DataConnect.prototype._delete = function () {
|
|
762
908
|
app._removeServiceInstance(this.app, 'data-connect', JSON.stringify(this.getSettings()));
|
|
763
909
|
return Promise.resolve();
|
|
764
910
|
};
|
|
911
|
+
// @internal
|
|
765
912
|
DataConnect.prototype.getSettings = function () {
|
|
766
913
|
var copy = JSON.parse(JSON.stringify(this.dataConnectOptions));
|
|
767
914
|
delete copy.projectId;
|
|
768
915
|
return copy;
|
|
769
916
|
};
|
|
917
|
+
// @internal
|
|
770
918
|
DataConnect.prototype.setInitialized = function () {
|
|
771
|
-
if (this.
|
|
919
|
+
if (this._initialized) {
|
|
772
920
|
return;
|
|
773
921
|
}
|
|
774
922
|
if (this._transportClass === undefined) {
|
|
@@ -778,16 +926,20 @@ var DataConnect = /** @class */ (function () {
|
|
|
778
926
|
if (this._authProvider) {
|
|
779
927
|
this._authTokenProvider = new FirebaseAuthProvider(this.app.name, this.app.options, this._authProvider);
|
|
780
928
|
}
|
|
781
|
-
this.
|
|
782
|
-
|
|
929
|
+
if (this._appCheckProvider) {
|
|
930
|
+
this._appCheckTokenProvider = new AppCheckTokenProvider(this.app.name, this._appCheckProvider);
|
|
931
|
+
}
|
|
932
|
+
this._initialized = true;
|
|
933
|
+
this._transport = new this._transportClass(this.dataConnectOptions, this.app.options.apiKey, this.app.options.appId, this._authTokenProvider, this._appCheckTokenProvider, undefined, this._isUsingGeneratedSdk);
|
|
783
934
|
if (this._transportOptions) {
|
|
784
935
|
this._transport.useEmulator(this._transportOptions.host, this._transportOptions.port, this._transportOptions.sslEnabled);
|
|
785
936
|
}
|
|
786
937
|
this._queryManager = new QueryManager(this._transport);
|
|
787
938
|
this._mutationManager = new MutationManager(this._transport);
|
|
788
939
|
};
|
|
940
|
+
// @internal
|
|
789
941
|
DataConnect.prototype.enableEmulator = function (transportOptions) {
|
|
790
|
-
if (this.
|
|
942
|
+
if (this._initialized) {
|
|
791
943
|
logError('enableEmulator called after initialization');
|
|
792
944
|
throw new DataConnectError(Code.ALREADY_INITIALIZED, 'DataConnect instance already initialized!');
|
|
793
945
|
}
|
|
@@ -818,7 +970,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
818
970
|
dcOptions = optionalOptions;
|
|
819
971
|
app$1 = appOrOptions;
|
|
820
972
|
}
|
|
821
|
-
if (!app$1) {
|
|
973
|
+
if (!app$1 || Object.keys(app$1).length === 0) {
|
|
822
974
|
app$1 = app.getApp();
|
|
823
975
|
}
|
|
824
976
|
var provider = app._getProvider(app$1, 'data-connect');
|
|
@@ -832,9 +984,7 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
832
984
|
return dcInstance;
|
|
833
985
|
}
|
|
834
986
|
}
|
|
835
|
-
|
|
836
|
-
throw new DataConnectError(Code.INVALID_ARGUMENT, 'DC Option Required');
|
|
837
|
-
}
|
|
987
|
+
validateDCOptions(dcOptions);
|
|
838
988
|
logDebug('Creating new DataConnect instance');
|
|
839
989
|
// Initialize with options.
|
|
840
990
|
return provider.initialize({
|
|
@@ -842,6 +992,24 @@ function getDataConnect(appOrOptions, optionalOptions) {
|
|
|
842
992
|
options: dcOptions
|
|
843
993
|
});
|
|
844
994
|
}
|
|
995
|
+
/**
|
|
996
|
+
*
|
|
997
|
+
* @param dcOptions
|
|
998
|
+
* @returns {void}
|
|
999
|
+
* @internal
|
|
1000
|
+
*/
|
|
1001
|
+
function validateDCOptions(dcOptions) {
|
|
1002
|
+
var fields = ['connector', 'location', 'service'];
|
|
1003
|
+
if (!dcOptions) {
|
|
1004
|
+
throw new DataConnectError(Code.INVALID_ARGUMENT, 'DC Option Required');
|
|
1005
|
+
}
|
|
1006
|
+
fields.forEach(function (field) {
|
|
1007
|
+
if (dcOptions[field] === null || dcOptions[field] === undefined) {
|
|
1008
|
+
throw new DataConnectError(Code.INVALID_ARGUMENT, "".concat(field, " Required"));
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
return true;
|
|
1012
|
+
}
|
|
845
1013
|
/**
|
|
846
1014
|
* Delete DataConnect instance
|
|
847
1015
|
* @param dataConnect DataConnect instance
|
|
@@ -858,11 +1026,15 @@ function registerDataConnect(variant) {
|
|
|
858
1026
|
var settings = _a.instanceIdentifier, options = _a.options;
|
|
859
1027
|
var app = container.getProvider('app').getImmediate();
|
|
860
1028
|
var authProvider = container.getProvider('auth-internal');
|
|
1029
|
+
var appCheckProvider = container.getProvider('app-check-internal');
|
|
861
1030
|
var newOpts = options;
|
|
862
1031
|
if (settings) {
|
|
863
1032
|
newOpts = JSON.parse(settings);
|
|
864
1033
|
}
|
|
865
|
-
|
|
1034
|
+
if (!app.options.projectId) {
|
|
1035
|
+
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Project ID must be provided. Did you pass in a proper projectId to initializeApp?');
|
|
1036
|
+
}
|
|
1037
|
+
return new DataConnect(app, tslib.__assign(tslib.__assign({}, newOpts), { projectId: app.options.projectId }), authProvider, appCheckProvider);
|
|
866
1038
|
}, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
|
|
867
1039
|
app.registerVersion(name, version, variant);
|
|
868
1040
|
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
|
|
@@ -921,6 +1093,49 @@ function toQueryRef(serializedRef) {
|
|
|
921
1093
|
return queryRef(getDataConnect(connectorConfig), name, variables);
|
|
922
1094
|
}
|
|
923
1095
|
|
|
1096
|
+
/**
|
|
1097
|
+
* @license
|
|
1098
|
+
* Copyright 2024 Google LLC
|
|
1099
|
+
*
|
|
1100
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1101
|
+
* you may not use this file except in compliance with the License.
|
|
1102
|
+
* You may obtain a copy of the License at
|
|
1103
|
+
*
|
|
1104
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1105
|
+
*
|
|
1106
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1107
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1108
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1109
|
+
* See the License for the specific language governing permissions and
|
|
1110
|
+
* limitations under the License.
|
|
1111
|
+
*/
|
|
1112
|
+
/**
|
|
1113
|
+
* The generated SDK will allow the user to pass in either the variable or the data connect instance with the variable,
|
|
1114
|
+
* and this function validates the variables and returns back the DataConnect instance and variables based on the arguments passed in.
|
|
1115
|
+
* @param connectorConfig
|
|
1116
|
+
* @param dcOrVars
|
|
1117
|
+
* @param vars
|
|
1118
|
+
* @param validateVars
|
|
1119
|
+
* @returns {DataConnect} and {Variables} instance
|
|
1120
|
+
* @internal
|
|
1121
|
+
*/
|
|
1122
|
+
function validateArgs(connectorConfig, dcOrVars, vars, validateVars) {
|
|
1123
|
+
var dcInstance;
|
|
1124
|
+
var realVars;
|
|
1125
|
+
if (dcOrVars && 'enableEmulator' in dcOrVars) {
|
|
1126
|
+
dcInstance = dcOrVars;
|
|
1127
|
+
realVars = vars;
|
|
1128
|
+
}
|
|
1129
|
+
else {
|
|
1130
|
+
dcInstance = getDataConnect(connectorConfig);
|
|
1131
|
+
realVars = dcOrVars;
|
|
1132
|
+
}
|
|
1133
|
+
if (!dcInstance || (!realVars && validateVars)) {
|
|
1134
|
+
throw new DataConnectError(Code.INVALID_ARGUMENT, 'Variables required.');
|
|
1135
|
+
}
|
|
1136
|
+
return { dc: dcInstance, vars: realVars };
|
|
1137
|
+
}
|
|
1138
|
+
|
|
924
1139
|
/**
|
|
925
1140
|
* @license
|
|
926
1141
|
* Copyright 2024 Google LLC
|
|
@@ -996,8 +1211,6 @@ initializeFetch(fetch);
|
|
|
996
1211
|
registerDataConnect('node');
|
|
997
1212
|
|
|
998
1213
|
exports.DataConnect = DataConnect;
|
|
999
|
-
exports.FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR;
|
|
1000
|
-
exports.FirebaseAuthProvider = FirebaseAuthProvider;
|
|
1001
1214
|
exports.MUTATION_STR = MUTATION_STR;
|
|
1002
1215
|
exports.MutationManager = MutationManager;
|
|
1003
1216
|
exports.QUERY_STR = QUERY_STR;
|
|
@@ -1014,4 +1227,6 @@ exports.setLogLevel = setLogLevel;
|
|
|
1014
1227
|
exports.subscribe = subscribe;
|
|
1015
1228
|
exports.terminate = terminate;
|
|
1016
1229
|
exports.toQueryRef = toQueryRef;
|
|
1230
|
+
exports.validateArgs = validateArgs;
|
|
1231
|
+
exports.validateDCOptions = validateDCOptions;
|
|
1017
1232
|
//# sourceMappingURL=index.node.cjs.js.map
|