Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@firebase/data-connect

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/data-connect - npm Package Compare versions

Comparing version 0.1.0-canary.2e2804139 to 0.1.0-canary.479226bf3

5

dist/index.cjs.js

@@ -11,3 +11,3 @@ 'use strict';

const name = "@firebase/data-connect";
const version = "0.1.0-canary.2e2804139";
const version = "0.1.0-canary.479226bf3";

@@ -399,2 +399,5 @@ /**

executeQuery(queryRef) {
if (queryRef.refType !== QUERY_STR) {
throw new DataConnectError(Code.INVALID_ARGUMENT, `ExecuteQuery can only execute query operation`);
}
const key = encoderImpl({

@@ -401,0 +404,0 @@ name: queryRef.name,

@@ -7,3 +7,3 @@ import { _removeServiceInstance, getApp, _getProvider, _registerComponent, registerVersion, SDK_VERSION as SDK_VERSION$1 } from '@firebase/app';

const name = "@firebase/data-connect";
const version = "0.1.0-canary.2e2804139";
const version = "0.1.0-canary.479226bf3";

@@ -395,2 +395,5 @@ /**

executeQuery(queryRef) {
if (queryRef.refType !== QUERY_STR) {
throw new DataConnectError(Code.INVALID_ARGUMENT, `ExecuteQuery can only execute query operation`);
}
const key = encoderImpl({

@@ -397,0 +400,0 @@ name: queryRef.name,

590

dist/index.node.cjs.js

@@ -5,3 +5,2 @@ 'use strict';

var tslib = require('tslib');
var util = require('@firebase/util');

@@ -28,3 +27,3 @@ var logger$1 = require('@firebase/logger');

*/
var Code = {
const Code = {
OTHER: 'other',

@@ -39,6 +38,5 @@ ALREADY_INITIALIZED: 'already-initialized',

/** An error returned by a DataConnect operation. */
var DataConnectError = /** @class */ (function (_super) {
tslib.__extends(DataConnectError, _super);
class DataConnectError extends util.FirebaseError {
/** @hideconstructor */
function DataConnectError(
constructor(
/**

@@ -52,13 +50,11 @@ * The backend error code associated with this error.

message) {
var _this = _super.call(this, code, message) || this;
_this.code = code;
_this.message = message;
super(code, message);
this.code = code;
this.message = message;
// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
_this.toString = function () { return "".concat(_this.name, ": [code=").concat(_this.code, "]: ").concat(_this.message); };
return _this;
this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
}
return DataConnectError;
}(util.FirebaseError));
}

@@ -82,3 +78,3 @@ /**

/** The semver (www.semver.org) version of the SDK. */
var SDK_VERSION = '';
let SDK_VERSION = '';
/**

@@ -108,3 +104,3 @@ * SDK_VERSION should be set before any database instance is created

*/
var logger = new logger$1.Logger('@firebase/data-connect');
const logger = new logger$1.Logger('@firebase/data-connect');
function setLogLevel(logLevel) {

@@ -114,6 +110,6 @@ logger.setLogLevel(logLevel);

function logDebug(msg) {
logger.debug("DataConnect (".concat(SDK_VERSION, "): ").concat(msg));
logger.debug(`DataConnect (${SDK_VERSION}): ${msg}`);
}
function logError(msg) {
logger.error("DataConnect (".concat(SDK_VERSION, "): ").concat(msg));
logger.error(`DataConnect (${SDK_VERSION}): ${msg}`);
}

@@ -137,3 +133,3 @@

*/
var connectFetch = globalThis.fetch;
let connectFetch = globalThis.fetch;
function initializeFetch(fetchImpl) {

@@ -143,3 +139,3 @@ connectFetch = fetchImpl;

function getGoogApiClientValue(_isUsingGen) {
var str = 'gl-js/ fire/' + SDK_VERSION;
let str = 'gl-js/ fire/' + SDK_VERSION;
if (_isUsingGen) {

@@ -150,9 +146,7 @@ str += ' js/gen';

}
function dcFetch(url, body, _a, appId, accessToken, appCheckToken, _isUsingGen) {
var _this = this;
var signal = _a.signal;
function dcFetch(url, body, { signal }, appId, accessToken, appCheckToken, _isUsingGen) {
if (!connectFetch) {
throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
}
var headers = {
const headers = {
'Content-Type': 'application/json',

@@ -170,45 +164,34 @@ 'X-Goog-Api-Client': getGoogApiClientValue(_isUsingGen)

}
var bodyStr = JSON.stringify(body);
logDebug("Making request out to ".concat(url, " with body: ").concat(bodyStr));
const bodyStr = JSON.stringify(body);
logDebug(`Making request out to ${url} with body: ${bodyStr}`);
return connectFetch(url, {
body: bodyStr,
method: 'POST',
headers: headers,
signal: signal
headers,
signal
})
.catch(function (err) {
.catch(err => {
throw new DataConnectError(Code.OTHER, 'Failed to fetch: ' + JSON.stringify(err));
})
.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
var jsonResponse, e_1, message;
return tslib.__generator(this, function (_a) {
switch (_a.label) {
case 0:
jsonResponse = null;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, response.json()];
case 2:
jsonResponse = _a.sent();
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
throw new DataConnectError(Code.OTHER, JSON.stringify(e_1));
case 4:
message = getMessage(jsonResponse);
if (response.status >= 400) {
logError('Error while performing request: ' + JSON.stringify(jsonResponse));
if (response.status === 401) {
throw new DataConnectError(Code.UNAUTHORIZED, message);
}
throw new DataConnectError(Code.OTHER, message);
}
return [2 /*return*/, jsonResponse];
.then(async (response) => {
let jsonResponse = null;
try {
jsonResponse = await response.json();
}
catch (e) {
throw new DataConnectError(Code.OTHER, JSON.stringify(e));
}
const message = getMessage(jsonResponse);
if (response.status >= 400) {
logError('Error while performing request: ' + JSON.stringify(jsonResponse));
if (response.status === 401) {
throw new DataConnectError(Code.UNAUTHORIZED, message);
}
});
}); })
.then(function (res) {
throw new DataConnectError(Code.OTHER, message);
}
return jsonResponse;
})
.then(res => {
if (res.errors && res.errors.length) {
var stringified = JSON.stringify(res.errors);
const stringified = JSON.stringify(res.errors);
logError('DataConnect error while performing request: ' + stringified);

@@ -227,4 +210,4 @@ throw new DataConnectError(Code.OTHER, stringified);

var name = "@firebase/data-connect";
var version = "0.1.0-canary.2e2804139";
const name = "@firebase/data-connect";
const version = "0.1.0-canary.479226bf3";

@@ -251,5 +234,4 @@ /**

*/
var AppCheckTokenProvider = /** @class */ (function () {
function AppCheckTokenProvider(appName_, appCheckProvider) {
var _this = this;
class AppCheckTokenProvider {
constructor(appName_, appCheckProvider) {
this.appName_ = appName_;

@@ -259,9 +241,8 @@ this.appCheckProvider = appCheckProvider;

if (!this.appCheck) {
void (appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(function (appCheck) { return (_this.appCheck = appCheck); }).catch());
void (appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(appCheck => (this.appCheck = appCheck)).catch());
}
}
AppCheckTokenProvider.prototype.getToken = function (forceRefresh) {
var _this = this;
getToken(forceRefresh) {
if (!this.appCheck) {
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
// Support delayed initialization of FirebaseAppCheck. This allows our

@@ -271,5 +252,5 @@ // customers to initialize the RTDB SDK before initializing Firebase

// becomes available before the timoeout below expires.
setTimeout(function () {
if (_this.appCheck) {
_this.getToken(forceRefresh).then(resolve, reject);
setTimeout(() => {
if (this.appCheck) {
this.getToken(forceRefresh).then(resolve, reject);
}

@@ -283,9 +264,8 @@ else {

return this.appCheck.getToken(forceRefresh);
};
AppCheckTokenProvider.prototype.addTokenChangeListener = function (listener) {
}
addTokenChangeListener(listener) {
var _a;
void ((_a = this.appCheckProvider) === null || _a === void 0 ? void 0 : _a.get().then(function (appCheck) { return appCheck.addTokenListener(listener); }));
};
return AppCheckTokenProvider;
}());
void ((_a = this.appCheckProvider) === null || _a === void 0 ? void 0 : _a.get().then(appCheck => appCheck.addTokenListener(listener)));
}
}

@@ -309,5 +289,4 @@ /**

// @internal
var FirebaseAuthProvider = /** @class */ (function () {
function FirebaseAuthProvider(_appName, _options, _authProvider) {
var _this = this;
class FirebaseAuthProvider {
constructor(_appName, _options, _authProvider) {
this._appName = _appName;

@@ -318,12 +297,11 @@ this._options = _options;

if (!this._auth) {
_authProvider.onInit(function (auth) { return (_this._auth = auth); });
_authProvider.onInit(auth => (this._auth = auth));
}
}
FirebaseAuthProvider.prototype.getToken = function (forceRefresh) {
var _this = this;
getToken(forceRefresh) {
if (!this._auth) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
if (_this._auth) {
_this.getToken(forceRefresh).then(resolve, reject);
return new Promise((resolve, reject) => {
setTimeout(() => {
if (this._auth) {
this.getToken(forceRefresh).then(resolve, reject);
}

@@ -336,3 +314,3 @@ else {

}
return this._auth.getToken(forceRefresh).catch(function (error) {
return this._auth.getToken(forceRefresh).catch(error => {
if (error && error.code === 'auth/token-not-initialized') {

@@ -348,15 +326,14 @@ logDebug('Got auth/token-not-initialized error. Treating as null token.');

});
};
FirebaseAuthProvider.prototype.addTokenChangeListener = function (listener) {
}
addTokenChangeListener(listener) {
var _a;
(_a = this._auth) === null || _a === void 0 ? void 0 : _a.addAuthTokenListener(listener);
};
FirebaseAuthProvider.prototype.removeTokenChangeListener = function (listener) {
}
removeTokenChangeListener(listener) {
this._authProvider
.get()
.then(function (auth) { return auth.removeAuthTokenListener(listener); })
.catch(function (err) { return logError(err); });
};
return FirebaseAuthProvider;
}());
.then(auth => auth.removeAuthTokenListener(listener))
.catch(err => logError(err));
}
}

@@ -379,6 +356,6 @@ /**

*/
var QUERY_STR = 'query';
var MUTATION_STR = 'mutation';
var SOURCE_SERVER = 'SERVER';
var SOURCE_CACHE = 'CACHE';
const QUERY_STR = 'query';
const MUTATION_STR = 'mutation';
const SOURCE_SERVER = 'SERVER';
const SOURCE_CACHE = 'CACHE';

@@ -401,7 +378,7 @@ /**

*/
var encoderImpl;
let encoderImpl;
function setEncoder(encoder) {
encoderImpl = encoder;
}
setEncoder(function (o) { return JSON.stringify(o); });
setEncoder(o => JSON.stringify(o));

@@ -449,27 +426,27 @@ /**

return {
data: data,
data,
refInfo: {
name: queryRef.name,
variables: queryRef.variables,
connectorConfig: tslib.__assign({ projectId: queryRef.dataConnect.app.options.projectId }, queryRef.dataConnect.getSettings())
connectorConfig: Object.assign({ projectId: queryRef.dataConnect.app.options.projectId }, queryRef.dataConnect.getSettings())
},
fetchTime: Date.now().toLocaleString(),
source: source
source
};
};
}
var QueryManager = /** @class */ (function () {
function QueryManager(transport) {
class QueryManager {
constructor(transport) {
this.transport = transport;
this._queries = new Map();
}
QueryManager.prototype.track = function (queryName, variables, initialCache) {
var ref = {
track(queryName, variables, initialCache) {
const ref = {
name: queryName,
variables: variables,
variables,
refType: QUERY_STR
};
var key = encoderImpl(ref);
var newTrackedQuery = {
ref: ref,
const key = encoderImpl(ref);
const newTrackedQuery = {
ref,
subscriptions: [],

@@ -482,6 +459,5 @@ currentCache: initialCache || null,

return this._queries.get(key);
};
QueryManager.prototype.addSubscription = function (queryRef, onResultCallback, onErrorCallback, initialCache) {
var _this = this;
var key = encoderImpl({
}
addSubscription(queryRef, onResultCallback, onErrorCallback, initialCache) {
const key = encoderImpl({
name: queryRef.name,

@@ -491,10 +467,10 @@ variables: queryRef.variables,

});
var trackedQuery = this._queries.get(key);
var subscription = {
const trackedQuery = this._queries.get(key);
const subscription = {
userCallback: onResultCallback,
errCallback: onErrorCallback
};
var unsubscribe = function () {
var trackedQuery = _this._queries.get(key);
trackedQuery.subscriptions = trackedQuery.subscriptions.filter(function (sub) { return sub !== subscription; });
const unsubscribe = () => {
const trackedQuery = this._queries.get(key);
trackedQuery.subscriptions = trackedQuery.subscriptions.filter(sub => sub !== subscription);
};

@@ -510,3 +486,3 @@ if (initialCache && trackedQuery.currentCache !== initialCache) {

if (trackedQuery.currentCache !== null) {
var cachedData = trackedQuery.currentCache.data;
const cachedData = trackedQuery.currentCache.data;
onResultCallback({

@@ -526,14 +502,17 @@ data: cachedData,

errCallback: onErrorCallback,
unsubscribe: unsubscribe
unsubscribe
});
if (!trackedQuery.currentCache) {
logDebug("No cache available for query ".concat(queryRef.name, " with variables ").concat(JSON.stringify(queryRef.variables), ". Calling executeQuery."));
var promise = this.executeQuery(queryRef);
logDebug(`No cache available for query ${queryRef.name} with variables ${JSON.stringify(queryRef.variables)}. Calling executeQuery.`);
const promise = this.executeQuery(queryRef);
// We want to ignore the error and let subscriptions handle it
promise.then(undefined, function (err) { });
promise.then(undefined, err => { });
}
return unsubscribe;
};
QueryManager.prototype.executeQuery = function (queryRef) {
var key = encoderImpl({
}
executeQuery(queryRef) {
if (queryRef.refType !== QUERY_STR) {
throw new DataConnectError(Code.INVALID_ARGUMENT, `ExecuteQuery can only execute query operation`);
}
const key = encoderImpl({
name: queryRef.name,

@@ -543,8 +522,8 @@ variables: queryRef.variables,

});
var trackedQuery = this._queries.get(key);
var result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
var newR = result.then(function (res) {
var fetchTime = new Date().toString();
var result = tslib.__assign(tslib.__assign({}, res), { source: SOURCE_SERVER, ref: queryRef, toJSON: getRefSerializer(queryRef, res.data, SOURCE_SERVER), fetchTime: fetchTime });
trackedQuery.subscriptions.forEach(function (subscription) {
const trackedQuery = this._queries.get(key);
const result = this.transport.invokeQuery(queryRef.name, queryRef.variables);
const newR = result.then(res => {
const fetchTime = new Date().toString();
const result = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: queryRef, toJSON: getRefSerializer(queryRef, res.data, SOURCE_SERVER), fetchTime });
trackedQuery.subscriptions.forEach(subscription => {
subscription.userCallback(result);

@@ -555,8 +534,8 @@ });

source: SOURCE_CACHE,
fetchTime: fetchTime
fetchTime
};
return result;
}, function (err) {
}, err => {
trackedQuery.lastError = err;
trackedQuery.subscriptions.forEach(function (subscription) {
trackedQuery.subscriptions.forEach(subscription => {
if (subscription.errCallback) {

@@ -569,11 +548,10 @@ subscription.errCallback(err);

return newR;
};
QueryManager.prototype.enableEmulator = function (host, port) {
}
enableEmulator(host, port) {
this.transport.useEmulator(host, port);
};
return QueryManager;
}());
}
}
function compareDates(str1, str2) {
var date1 = new Date(str1);
var date2 = new Date(str2);
const date1 = new Date(str1);
const date2 = new Date(str2);
return date1.getTime() < date2.getTime();

@@ -599,9 +577,9 @@ }

function urlBuilder(projectConfig, transportOptions) {
var connector = projectConfig.connector, location = projectConfig.location, project = projectConfig.projectId, service = projectConfig.service;
var host = transportOptions.host, sslEnabled = transportOptions.sslEnabled, port = transportOptions.port;
var protocol = sslEnabled ? 'https' : 'http';
var realHost = host || "firebasedataconnect.googleapis.com";
var baseUrl = "".concat(protocol, "://").concat(realHost);
const { connector, location, projectId: project, service } = projectConfig;
const { host, sslEnabled, port } = transportOptions;
const protocol = sslEnabled ? 'https' : 'http';
const realHost = host || `firebasedataconnect.googleapis.com`;
let baseUrl = `${protocol}://${realHost}`;
if (typeof port === 'number') {
baseUrl += ":".concat(port);
baseUrl += `:${port}`;
}

@@ -612,3 +590,3 @@ else if (typeof port !== 'undefined') {

}
return "".concat(baseUrl, "/v1beta/projects/").concat(project, "/locations/").concat(location, "/services/").concat(service, "/connectors/").concat(connector);
return `${baseUrl}/v1beta/projects/${project}/locations/${location}/services/${service}/connectors/${connector}`;
}

@@ -619,3 +597,3 @@ function addToken(url, apiKey) {

}
var newUrl = new URL(url);
const newUrl = new URL(url);
newUrl.searchParams.append('key', apiKey);

@@ -641,6 +619,4 @@ return newUrl.toString();

*/
var RESTTransport = /** @class */ (function () {
function RESTTransport(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen) {
if (_isUsingGen === void 0) { _isUsingGen = false; }
var _this = this;
class RESTTransport {
constructor(options, apiKey, appId, authProvider, appCheckProvider, transportOptions, _isUsingGen = false) {
var _a, _b;

@@ -661,13 +637,11 @@ this.apiKey = apiKey;

// TODO(mtewani): Update U to include shape of body defined in line 13.
this.invokeQuery = function (queryName, body) {
var abortController = new AbortController();
this.invokeQuery = (queryName, body) => {
const abortController = new AbortController();
// TODO(mtewani): Update to proper value
var withAuth = _this.withRetry(function () {
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeQuery"), _this.apiKey), {
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
operationName: queryName,
variables: body
}, // TODO(mtewani): This is a patch, fix this.
abortController, _this.appId, _this._accessToken, _this._appCheckToken, _this._isUsingGen);
});
const withAuth = this.withRetry(() => dcFetch(addToken(`${this.endpointUrl}:executeQuery`, this.apiKey), {
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
operationName: queryName,
variables: body
}, // TODO(mtewani): This is a patch, fix this.
abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen));
return {

@@ -678,10 +652,10 @@ then: withAuth.then.bind(withAuth),

};
this.invokeMutation = function (mutationName, body) {
var abortController = new AbortController();
var taskResult = _this.withRetry(function () {
return dcFetch(addToken("".concat(_this.endpointUrl, ":executeMutation"), _this.apiKey), {
name: "projects/".concat(_this._project, "/locations/").concat(_this._location, "/services/").concat(_this._serviceName, "/connectors/").concat(_this._connectorName),
this.invokeMutation = (mutationName, body) => {
const abortController = new AbortController();
const taskResult = this.withRetry(() => {
return dcFetch(addToken(`${this.endpointUrl}:executeMutation`, this.apiKey), {
name: `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`,
operationName: mutationName,
variables: body
}, abortController, _this.appId, _this._accessToken, _this._appCheckToken, _this._isUsingGen);
}, abortController, this.appId, this._accessToken, this._appCheckToken, this._isUsingGen);
});

@@ -692,3 +666,3 @@ return {

// finally: taskResult.finally.bind(taskResult),
cancel: function () { return abortController.abort(); }
cancel: () => abortController.abort()
};

@@ -705,3 +679,3 @@ };

}
var location = options.location, project = options.projectId, connector = options.connector, service = options.service;
const { location, projectId: project, connector, service } = options;
if (location) {

@@ -718,25 +692,21 @@ this._location = location;

this._connectorName = connector;
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(function (token) {
logDebug("New Token Available: ".concat(token));
_this._accessToken = token;
(_a = this.authProvider) === null || _a === void 0 ? void 0 : _a.addTokenChangeListener(token => {
logDebug(`New Token Available: ${token}`);
this._accessToken = token;
});
(_b = this.appCheckProvider) === null || _b === void 0 ? void 0 : _b.addTokenChangeListener(function (result) {
var token = result.token;
logDebug("New App Check Token Available: ".concat(token));
_this._appCheckToken = token;
(_b = this.appCheckProvider) === null || _b === void 0 ? void 0 : _b.addTokenChangeListener(result => {
const { token } = result;
logDebug(`New App Check Token Available: ${token}`);
this._appCheckToken = token;
});
}
Object.defineProperty(RESTTransport.prototype, "endpointUrl", {
get: function () {
return urlBuilder({
connector: this._connectorName,
location: this._location,
projectId: this._project,
service: this._serviceName
}, { host: this._host, sslEnabled: this._secure, port: this._port });
},
enumerable: false,
configurable: true
});
RESTTransport.prototype.useEmulator = function (host, port, isSecure) {
get endpointUrl() {
return urlBuilder({
connector: this._connectorName,
location: this._location,
projectId: this._project,
service: this._serviceName
}, { host: this._host, sslEnabled: this._secure, port: this._port });
}
useEmulator(host, port, isSecure) {
this._host = host;

@@ -749,59 +719,41 @@ if (typeof port === 'number') {

}
};
RESTTransport.prototype.onTokenChanged = function (newToken) {
}
onTokenChanged(newToken) {
this._accessToken = newToken;
};
RESTTransport.prototype.getWithAuth = function (forceToken) {
}
async getWithAuth(forceToken = false) {
var _a;
if (forceToken === void 0) { forceToken = false; }
return tslib.__awaiter(this, void 0, void 0, function () {
var starterPromise, _b;
var _this = this;
return tslib.__generator(this, function (_c) {
switch (_c.label) {
case 0:
starterPromise = new Promise(function (resolve) {
return resolve(_this._accessToken);
});
if (!this.appCheckProvider) return [3 /*break*/, 2];
_b = this;
return [4 /*yield*/, this.appCheckProvider.getToken()];
case 1:
_b._appCheckToken = (_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.token;
_c.label = 2;
case 2:
if (this.authProvider) {
starterPromise = this.authProvider
.getToken(/*forceToken=*/ forceToken)
.then(function (data) {
if (!data) {
return null;
}
_this._accessToken = data.accessToken;
return _this._accessToken;
});
}
else {
starterPromise = new Promise(function (resolve) { return resolve(''); });
}
return [2 /*return*/, starterPromise];
let starterPromise = new Promise(resolve => resolve(this._accessToken));
if (this.appCheckProvider) {
this._appCheckToken = (_a = (await this.appCheckProvider.getToken())) === null || _a === void 0 ? void 0 : _a.token;
}
if (this.authProvider) {
starterPromise = this.authProvider
.getToken(/*forceToken=*/ forceToken)
.then(data => {
if (!data) {
return null;
}
this._accessToken = data.accessToken;
return this._accessToken;
});
});
};
RESTTransport.prototype._setLastToken = function (lastToken) {
}
else {
starterPromise = new Promise(resolve => resolve(''));
}
return starterPromise;
}
_setLastToken(lastToken) {
this._lastToken = lastToken;
};
RESTTransport.prototype.withRetry = function (promiseFactory, retry) {
var _this = this;
if (retry === void 0) { retry = false; }
var isNewToken = false;
}
withRetry(promiseFactory, retry = false) {
let isNewToken = false;
return this.getWithAuth(retry)
.then(function (res) {
isNewToken = _this._lastToken !== res;
_this._lastToken = res;
.then(res => {
isNewToken = this._lastToken !== res;
this._lastToken = res;
return res;
})
.then(promiseFactory)
.catch(function (err) {
.catch(err => {
// Only retry if the result is unauthorized and the last token isn't the same as the new one.

@@ -813,9 +765,8 @@ if ('code' in err &&

logDebug('Retrying due to unauthorized');
return _this.withRetry(promiseFactory, true);
return this.withRetry(promiseFactory, true);
}
throw err;
});
};
return RESTTransport;
}());
}
}

@@ -847,3 +798,3 @@ /**

dcInstance.setInitialized();
var ref = {
const ref = {
dataConnect: dcInstance,

@@ -859,23 +810,19 @@ name: mutationName,

*/
var MutationManager = /** @class */ (function () {
function MutationManager(_transport) {
class MutationManager {
constructor(_transport) {
this._transport = _transport;
this._inflight = [];
}
MutationManager.prototype.executeMutation = function (mutationRef) {
var _this = this;
var result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
var withRefPromise = result.then(function (res) {
var obj = tslib.__assign(tslib.__assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
executeMutation(mutationRef) {
const result = this._transport.invokeMutation(mutationRef.name, mutationRef.variables);
const withRefPromise = result.then(res => {
const obj = Object.assign(Object.assign({}, res), { source: SOURCE_SERVER, ref: mutationRef, fetchTime: Date.now().toLocaleString() });
return obj;
});
this._inflight.push(result);
var removePromise = function () {
return (_this._inflight = _this._inflight.filter(function (promise) { return promise !== result; }));
};
const removePromise = () => (this._inflight = this._inflight.filter(promise => promise !== result));
result.then(removePromise, removePromise);
return withRefPromise;
};
return MutationManager;
}());
}
}
/**

@@ -906,3 +853,3 @@ * Execute Mutation

*/
var FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = 'FIREBASE_DATA_CONNECT_EMULATOR_HOST';
const FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR = 'FIREBASE_DATA_CONNECT_EMULATOR_HOST';
/**

@@ -915,7 +862,7 @@ *

function parseOptions(fullHost) {
var _a = fullHost.split('://'), protocol = _a[0], hostName = _a[1];
var isSecure = protocol === 'https';
var _b = hostName.split(':'), host = _b[0], portAsString = _b[1];
var port = Number(portAsString);
return { host: host, port: port, sslEnabled: isSecure };
const [protocol, hostName] = fullHost.split('://');
const isSecure = protocol === 'https';
const [host, portAsString] = hostName.split(':');
const port = Number(portAsString);
return { host, port, sslEnabled: isSecure };
}

@@ -925,5 +872,5 @@ /**

*/
var DataConnect = /** @class */ (function () {
class DataConnect {
// @internal
function DataConnect(app,
constructor(app,
// TODO(mtewani): Replace with _dataConnectOptions in the future

@@ -939,3 +886,3 @@ dataConnectOptions, _authProvider, _appCheckProvider) {

if (typeof process !== 'undefined' && process.env) {
var host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
const host = process.env[FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR];
if (host) {

@@ -949,19 +896,19 @@ logDebug('Found custom host. Using emulator');

// @internal
DataConnect.prototype._useGeneratedSdk = function () {
_useGeneratedSdk() {
if (!this._isUsingGeneratedSdk) {
this._isUsingGeneratedSdk = true;
}
};
DataConnect.prototype._delete = function () {
}
_delete() {
app._removeServiceInstance(this.app, 'data-connect', JSON.stringify(this.getSettings()));
return Promise.resolve();
};
}
// @internal
DataConnect.prototype.getSettings = function () {
var copy = JSON.parse(JSON.stringify(this.dataConnectOptions));
getSettings() {
const copy = JSON.parse(JSON.stringify(this.dataConnectOptions));
delete copy.projectId;
return copy;
};
}
// @internal
DataConnect.prototype.setInitialized = function () {
setInitialized() {
if (this._initialized) {

@@ -987,5 +934,5 @@ return;

this._mutationManager = new MutationManager(this._transport);
};
}
// @internal
DataConnect.prototype.enableEmulator = function (transportOptions) {
enableEmulator(transportOptions) {
if (this._initialized) {

@@ -997,5 +944,4 @@ logError('enableEmulator called after initialization');

this.isEmulator = true;
};
return DataConnect;
}());
}
}
/**

@@ -1008,9 +954,8 @@ * Connect to the DataConnect Emulator

*/
function connectDataConnectEmulator(dc, host, port, sslEnabled) {
if (sslEnabled === void 0) { sslEnabled = false; }
dc.enableEmulator({ host: host, port: port, sslEnabled: sslEnabled });
function connectDataConnectEmulator(dc, host, port, sslEnabled = false) {
dc.enableEmulator({ host, port, sslEnabled });
}
function getDataConnect(appOrOptions, optionalOptions) {
var app$1;
var dcOptions;
let app$1;
let dcOptions;
if ('location' in appOrOptions) {

@@ -1027,8 +972,8 @@ dcOptions = appOrOptions;

}
var provider = app._getProvider(app$1, 'data-connect');
var identifier = JSON.stringify(dcOptions);
const provider = app._getProvider(app$1, 'data-connect');
const identifier = JSON.stringify(dcOptions);
if (provider.isInitialized(identifier)) {
var dcInstance = provider.getImmediate({ identifier: identifier });
var options = provider.getOptions(identifier);
var optionsValid = Object.keys(options).length > 0;
const dcInstance = provider.getImmediate({ identifier });
const options = provider.getOptions(identifier);
const optionsValid = Object.keys(options).length > 0;
if (optionsValid) {

@@ -1054,9 +999,9 @@ logDebug('Re-using cached instance');

function validateDCOptions(dcOptions) {
var fields = ['connector', 'location', 'service'];
const fields = ['connector', 'location', 'service'];
if (!dcOptions) {
throw new DataConnectError(Code.INVALID_ARGUMENT, 'DC Option Required');
}
fields.forEach(function (field) {
fields.forEach(field => {
if (dcOptions[field] === null || dcOptions[field] === undefined) {
throw new DataConnectError(Code.INVALID_ARGUMENT, "".concat(field, " Required"));
throw new DataConnectError(Code.INVALID_ARGUMENT, `${field} Required`);
}

@@ -1076,10 +1021,25 @@ });

/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function registerDataConnect(variant) {
setSDKVersion(app.SDK_VERSION);
app._registerComponent(new component.Component('data-connect', function (container, _a) {
var settings = _a.instanceIdentifier, options = _a.options;
var app = container.getProvider('app').getImmediate();
var authProvider = container.getProvider('auth-internal');
var appCheckProvider = container.getProvider('app-check-internal');
var newOpts = options;
app._registerComponent(new component.Component('data-connect', (container, { instanceIdentifier: settings, options }) => {
const app = container.getProvider('app').getImmediate();
const authProvider = container.getProvider('auth-internal');
const appCheckProvider = container.getProvider('app-check-internal');
let newOpts = options;
if (settings) {

@@ -1091,7 +1051,7 @@ newOpts = JSON.parse(settings);

}
return new DataConnect(app, tslib.__assign(tslib.__assign({}, newOpts), { projectId: app.options.projectId }), authProvider, appCheckProvider);
return new DataConnect(app, Object.assign(Object.assign({}, newOpts), { projectId: app.options.projectId }), authProvider, appCheckProvider);
}, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
app.registerVersion(name, version, variant);
// BUILD_TARGET will be replaced by values like esm5, esm2017, cjs5, etc during the compilation
app.registerVersion(name, version, 'cjs5');
app.registerVersion(name, version, 'cjs2017');
}

@@ -1147,3 +1107,3 @@

function toQueryRef(serializedRef) {
var _a = serializedRef.refInfo, name = _a.name, variables = _a.variables, connectorConfig = _a.connectorConfig;
const { refInfo: { name, variables, connectorConfig } } = serializedRef;
return queryRef(getDataConnect(connectorConfig), name, variables);

@@ -1179,4 +1139,4 @@ }

function validateArgs(connectorConfig, dcOrVars, vars, validateVars) {
var dcInstance;
var realVars;
let dcInstance;
let realVars;
if (dcOrVars && 'enableEmulator' in dcOrVars) {

@@ -1221,11 +1181,11 @@ dcInstance = dcOrVars;

function subscribe(queryRefOrSerializedResult, observerOrOnNext, onError, onComplete) {
var ref;
var initialCache;
let ref;
let initialCache;
if ('refInfo' in queryRefOrSerializedResult) {
var serializedRef = queryRefOrSerializedResult;
var data = serializedRef.data, source = serializedRef.source, fetchTime = serializedRef.fetchTime;
const serializedRef = queryRefOrSerializedResult;
const { data, source, fetchTime } = serializedRef;
initialCache = {
data: data,
source: source,
fetchTime: fetchTime
data,
source,
fetchTime
};

@@ -1237,3 +1197,3 @@ ref = toQueryRef(serializedRef);

}
var onResult = undefined;
let onResult = undefined;
if (typeof observerOrOnNext === 'function') {

@@ -1240,0 +1200,0 @@ onResult = observerOrOnNext;

@@ -196,3 +196,3 @@ import { FirebaseError } from '@firebase/util';

const name = "@firebase/data-connect";
const version = "0.1.0-canary.2e2804139";
const version = "0.1.0-canary.479226bf3";

@@ -484,2 +484,5 @@ /**

executeQuery(queryRef) {
if (queryRef.refType !== QUERY_STR) {
throw new DataConnectError(Code.INVALID_ARGUMENT, `ExecuteQuery can only execute query operation`);
}
const key = encoderImpl({

@@ -486,0 +489,0 @@ name: queryRef.name,

{
"name": "@firebase/data-connect",
"version": "0.1.0-canary.2e2804139",
"version": "0.1.0-canary.479226bf3",
"description": "",

@@ -9,3 +9,2 @@ "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",

"module": "dist/index.esm2017.js",
"esm5": "dist/index.esm5.js",
"exports": {

@@ -18,3 +17,2 @@ ".": {

},
"esm5": "./dist/index.esm5.js",
"browser": {

@@ -52,13 +50,13 @@ "require": "./dist/index.cjs.js",

"peerDependencies": {
"@firebase/app": "0.10.13-canary.2e2804139"
"@firebase/app": "0.10.13-canary.479226bf3"
},
"dependencies": {
"@firebase/auth-interop-types": "0.2.3-canary.2e2804139",
"@firebase/component": "0.6.9-canary.2e2804139",
"@firebase/logger": "0.4.2-canary.2e2804139",
"@firebase/util": "1.10.0-canary.2e2804139",
"@firebase/auth-interop-types": "0.2.3-canary.479226bf3",
"@firebase/component": "0.6.9-canary.479226bf3",
"@firebase/logger": "0.4.2-canary.479226bf3",
"@firebase/util": "1.10.0-canary.479226bf3",
"tslib": "^2.1.0"
},
"devDependencies": {
"@firebase/app": "0.10.13-canary.2e2804139",
"@firebase/app": "0.10.13-canary.479226bf3",
"rollup": "2.79.1",

@@ -65,0 +63,0 @@ "rollup-plugin-typescript2": "0.31.2",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc