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

@firebase/installations

Package Overview
Dependencies
Maintainers
5
Versions
2730
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/installations - npm Package Compare versions

Comparing version 0.1.4-0 to 0.1.4-canary.039f06b

.rpt2_cache/rpt2_94b9f4f674ffe72ea4268d86df7264609c0e4f5f/code/cache/03badcc63fb26f8163137b77902291b0b159b03c

30

dist/index.cjs.js

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

var version = "0.1.4-0";
var version = "0.1.4-canary.039f06b";

@@ -162,2 +162,24 @@ /**

}
/**
* Calls the passed in fetch wrapper and returns the response.
* If the returned response has a status of 5xx, re-runs the function once and
* returns the response.
*/
function retryIfServerError(fn) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var result;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fn()];
case 1:
result = _a.sent();
if (result.status >= 500 && result.status < 600) {
// Internal Server Error. Retry request.
return [2 /*return*/, fn()];
}
return [2 /*return*/, result];
}
});
});
}
function getExpiresInFromResponseExpiresIn(responseExpiresIn) {

@@ -207,3 +229,3 @@ // This works because the server will never respond with fractions of a second.

};
return [4 /*yield*/, fetch(endpoint, request)];
return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];
case 1:

@@ -674,3 +696,3 @@ response = _b.sent();

};
return [4 /*yield*/, fetch(endpoint, request)];
return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];
case 1:

@@ -948,3 +970,3 @@ response = _a.sent();

};
return [4 /*yield*/, fetch(endpoint, request)];
return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];
case 1:

@@ -951,0 +973,0 @@ response = _a.sent();

@@ -7,3 +7,3 @@ import firebase from '@firebase/app';

var version = "0.1.4-0";
var version = "0.1.4-canary.039f06b";

@@ -157,2 +157,24 @@ /**

}
/**
* Calls the passed in fetch wrapper and returns the response.
* If the returned response has a status of 5xx, re-runs the function once and
* returns the response.
*/
function retryIfServerError(fn) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fn()];
case 1:
result = _a.sent();
if (result.status >= 500 && result.status < 600) {
// Internal Server Error. Retry request.
return [2 /*return*/, fn()];
}
return [2 /*return*/, result];
}
});
});
}
function getExpiresInFromResponseExpiresIn(responseExpiresIn) {

@@ -202,3 +224,3 @@ // This works because the server will never respond with fractions of a second.

};
return [4 /*yield*/, fetch(endpoint, request)];
return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];
case 1:

@@ -669,3 +691,3 @@ response = _b.sent();

};
return [4 /*yield*/, fetch(endpoint, request)];
return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];
case 1:

@@ -943,3 +965,3 @@ response = _a.sent();

};
return [4 /*yield*/, fetch(endpoint, request)];
return [4 /*yield*/, retryIfServerError(function () { return fetch(endpoint, request); })];
case 1:

@@ -946,0 +968,0 @@ response = _a.sent();

@@ -5,3 +5,3 @@ import firebase from '@firebase/app';

const version = "0.1.4-0";
const version = "0.1.4-canary.039f06b";

@@ -142,2 +142,15 @@ /**

}
/**
* Calls the passed in fetch wrapper and returns the response.
* If the returned response has a status of 5xx, re-runs the function once and
* returns the response.
*/
async function retryIfServerError(fn) {
const result = await fn();
if (result.status >= 500 && result.status < 600) {
// Internal Server Error. Retry request.
return fn();
}
return result;
}
function getExpiresInFromResponseExpiresIn(responseExpiresIn) {

@@ -181,3 +194,3 @@ // This works because the server will never respond with fractions of a second.

};
const response = await fetch(endpoint, request);
const response = await retryIfServerError(() => fetch(endpoint, request));
if (response.ok) {

@@ -549,3 +562,3 @@ const responseValue = await response.json();

};
const response = await fetch(endpoint, request);
const response = await retryIfServerError(() => fetch(endpoint, request));
if (response.ok) {

@@ -739,3 +752,3 @@ const responseValue = await response.json();

};
const response = await fetch(endpoint, request);
const response = await retryIfServerError(() => fetch(endpoint, request));
if (!response.ok) {

@@ -742,0 +755,0 @@ throw await getErrorFromResponse('Delete Installation', response);

16

dist/src/api/common.d.ts

@@ -26,6 +26,14 @@ /**

export declare function getHeadersWithAuth(appConfig: AppConfig, { refreshToken }: RegisteredInstallationEntry): Headers;
export interface ErrorData {
code: number;
message: string;
status: string;
export interface ErrorResponse {
error: {
code: number;
message: string;
status: string;
};
}
/**
* Calls the passed in fetch wrapper and returns the response.
* If the returned response has a status of 5xx, re-runs the function once and
* returns the response.
*/
export declare function retryIfServerError(fn: () => Promise<Response>): Promise<Response>;

@@ -19,3 +19,3 @@ /**

/** Gets record(s) from the objectStore that match the given key. */
export declare function get<ReturnType>(appConfig: AppConfig): Promise<ReturnType | undefined>;
export declare function get(appConfig: AppConfig): Promise<unknown>;
/** Assigns or overwrites the record for the given key with the given value. */

@@ -22,0 +22,0 @@ export declare function set<ValueType>(appConfig: AppConfig, value: ValueType): Promise<ValueType>;

{
"name": "@firebase/installations",
"version": "0.1.4-0",
"version": "0.1.4-canary.039f06b",
"main": "dist/index.cjs.js",

@@ -48,8 +48,8 @@ "module": "dist/index.esm.js",

"peerDependencies": {
"@firebase/app": "0.x",
"@firebase/app-types": "0.x"
"@firebase/app": "0.4.3-canary.039f06b",
"@firebase/app-types": "0.4.0-canary.039f06b"
},
"dependencies": {
"@firebase/installations-types": "0.1.1",
"@firebase/util": "0.2.17",
"@firebase/installations-types": "0.1.1-canary.039f06b",
"@firebase/util": "0.2.17-canary.039f06b",
"idb": "3.0.2",

@@ -56,0 +56,0 @@ "tslib": "1.9.3"

@@ -51,3 +51,3 @@ /**

): Promise<FirebaseError> {
const responseJson = await response.json();
const responseJson: ErrorResponse = await response.json();
const errorData = responseJson.error;

@@ -79,8 +79,28 @@ return ERROR_FACTORY.create(ErrorCode.REQUEST_FAILED, {

export interface ErrorData {
code: number;
message: string;
status: string;
export interface ErrorResponse {
error: {
code: number;
message: string;
status: string;
};
}
/**
* Calls the passed in fetch wrapper and returns the response.
* If the returned response has a status of 5xx, re-runs the function once and
* returns the response.
*/
export async function retryIfServerError(
fn: () => Promise<Response>
): Promise<Response> {
const result = await fn();
if (result.status >= 500 && result.status < 600) {
// Internal Server Error. Retry request.
return fn();
}
return result;
}
function getExpiresInFromResponseExpiresIn(responseExpiresIn: string): number {

@@ -87,0 +107,0 @@ // This works because the server will never respond with fractions of a second.

@@ -35,2 +35,3 @@ /**

} from '../util/constants';
import { ErrorResponse } from './common';
import { createInstallation } from './create-installation';

@@ -44,2 +45,3 @@

let inProgressInstallationEntry: InProgressInstallationEntry;
let response: CreateInstallationResponse;

@@ -54,2 +56,12 @@ beforeEach(() => {

};
response = {
refreshToken: 'refreshToken',
authToken: {
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
expiresIn: '604800s'
}
};
fetchSpy = stub(self, 'fetch');
});

@@ -59,14 +71,3 @@

beforeEach(() => {
const response: CreateInstallationResponse = {
refreshToken: 'refreshToken',
authToken: {
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
expiresIn: '604800s'
}
};
fetchSpy = stub(self, 'fetch').resolves(
new Response(JSON.stringify(response))
);
fetchSpy.resolves(new Response(JSON.stringify(response)));
});

@@ -111,4 +112,4 @@

describe('failed request', () => {
beforeEach(() => {
const response = {
it('throws a FirebaseError with the error information from the server', async () => {
const errorResponse: ErrorResponse = {
error: {

@@ -121,8 +122,6 @@ code: 409,

fetchSpy = stub(self, 'fetch').resolves(
new Response(JSON.stringify(response), { status: 409 })
fetchSpy.resolves(
new Response(JSON.stringify(errorResponse), { status: 409 })
);
});
it('throws a FirebaseError with the error information from the server', async () => {
await expect(

@@ -132,3 +131,22 @@ createInstallation(appConfig, inProgressInstallationEntry)

});
it('retries once if the server returns a 5xx error', async () => {
const errorResponse: ErrorResponse = {
error: {
code: 500,
message: 'Internal server error',
status: 'SERVER_ERROR'
}
};
fetchSpy
.onCall(0)
.resolves(new Response(JSON.stringify(errorResponse), { status: 500 }));
fetchSpy.onCall(1).resolves(new Response(JSON.stringify(response)));
await expect(createInstallation(appConfig, inProgressInstallationEntry))
.to.be.fulfilled;
expect(fetchSpy).to.be.calledTwice;
});
});
});

@@ -30,3 +30,4 @@ /**

getHeaders,
getInstallationsEndpoint
getInstallationsEndpoint,
retryIfServerError
} from './common';

@@ -54,3 +55,3 @@

const response = await fetch(endpoint, request);
const response = await retryIfServerError(() => fetch(endpoint, request));
if (response.ok) {

@@ -57,0 +58,0 @@ const responseValue: CreateInstallationResponse = await response.json();

@@ -33,2 +33,3 @@ /**

} from '../util/constants';
import { ErrorResponse } from './common';
import { deleteInstallation } from './delete-installation';

@@ -54,2 +55,4 @@

};
fetchSpy = stub(self, 'fetch');
});

@@ -59,3 +62,3 @@

beforeEach(() => {
fetchSpy = stub(self, 'fetch').resolves(new Response());
fetchSpy.resolves(new Response());
});

@@ -85,4 +88,4 @@

describe('failed request', () => {
beforeEach(() => {
const response = {
it('throws a FirebaseError with the error information from the server', async () => {
const errorResponse: ErrorResponse = {
error: {

@@ -95,8 +98,6 @@ code: 409,

fetchSpy = stub(self, 'fetch').resolves(
new Response(JSON.stringify(response), { status: 409 })
fetchSpy.resolves(
new Response(JSON.stringify(errorResponse), { status: 409 })
);
});
it('throws a FirebaseError with the error information from the server', async () => {
await expect(

@@ -106,3 +107,22 @@ deleteInstallation(appConfig, registeredInstallationEntry)

});
it('retries once if the server returns a 5xx error', async () => {
const errorResponse: ErrorResponse = {
error: {
code: 500,
message: 'Internal server error',
status: 'SERVER_ERROR'
}
};
fetchSpy
.onCall(0)
.resolves(new Response(JSON.stringify(errorResponse), { status: 500 }));
fetchSpy.onCall(1).resolves(new Response());
await expect(deleteInstallation(appConfig, registeredInstallationEntry))
.to.be.fulfilled;
expect(fetchSpy).to.be.calledTwice;
});
});
});

@@ -23,3 +23,4 @@ /**

getHeadersWithAuth,
getInstallationsEndpoint
getInstallationsEndpoint,
retryIfServerError
} from './common';

@@ -39,3 +40,3 @@

const response = await fetch(endpoint, request);
const response = await retryIfServerError(() => fetch(endpoint, request));
if (!response.ok) {

@@ -42,0 +43,0 @@ throw await getErrorFromResponse('Delete Installation', response);

@@ -36,2 +36,3 @@ /**

} from '../util/constants';
import { ErrorResponse } from './common';
import { generateAuthToken } from './generate-auth-token';

@@ -45,2 +46,3 @@

let registeredInstallationEntry: RegisteredInstallationEntry;
let response: GenerateAuthTokenResponse;

@@ -58,2 +60,10 @@ beforeEach(() => {

};
response = {
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
expiresIn: '604800s'
};
fetchSpy = stub(self, 'fetch');
});

@@ -63,11 +73,3 @@

beforeEach(() => {
const response: GenerateAuthTokenResponse = {
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
expiresIn: '604800s'
};
fetchSpy = stub(self, 'fetch').resolves(
new Response(JSON.stringify(response))
);
fetchSpy.resolves(new Response(JSON.stringify(response)));
});

@@ -113,4 +115,4 @@

describe('failed request', () => {
beforeEach(() => {
const response = {
it('throws a FirebaseError with the error information from the server', async () => {
const errorResponse: ErrorResponse = {
error: {

@@ -123,8 +125,6 @@ code: 409,

fetchSpy = stub(self, 'fetch').resolves(
new Response(JSON.stringify(response), { status: 409 })
fetchSpy.resolves(
new Response(JSON.stringify(errorResponse), { status: 409 })
);
});
it('throws a FirebaseError with the error information from the server', async () => {
await expect(

@@ -134,3 +134,22 @@ generateAuthToken(appConfig, registeredInstallationEntry)

});
it('retries once if the server returns a 5xx error', async () => {
const errorResponse: ErrorResponse = {
error: {
code: 500,
message: 'Internal server error',
status: 'SERVER_ERROR'
}
};
fetchSpy
.onCall(0)
.resolves(new Response(JSON.stringify(errorResponse), { status: 500 }));
fetchSpy.onCall(1).resolves(new Response(JSON.stringify(response)));
await expect(generateAuthToken(appConfig, registeredInstallationEntry)).to
.be.fulfilled;
expect(fetchSpy).to.be.calledTwice;
});
});
});

@@ -29,3 +29,4 @@ /**

getHeadersWithAuth,
getInstallationsEndpoint
getInstallationsEndpoint,
retryIfServerError
} from './common';

@@ -52,3 +53,3 @@

const response = await fetch(endpoint, request);
const response = await retryIfServerError(() => fetch(endpoint, request));
if (response.ok) {

@@ -55,0 +56,0 @@ const responseValue: GenerateAuthTokenResponse = await response.json();

@@ -232,14 +232,14 @@ /**

const token = await getToken(app);
const installationEntry = await get<RegisteredInstallationEntry>(
const installationEntry = (await get(
appConfig
);
)) as RegisteredInstallationEntry;
expect(installationEntry).not.to.be.undefined;
expect(installationEntry!.registrationStatus).to.equal(
expect(installationEntry.registrationStatus).to.equal(
RequestStatus.COMPLETED
);
expect(installationEntry!.authToken.requestStatus).to.equal(
expect(installationEntry.authToken.requestStatus).to.equal(
RequestStatus.COMPLETED
);
expect(
(installationEntry!.authToken as CompletedAuthToken).token
(installationEntry.authToken as CompletedAuthToken).token
).to.equal(token);

@@ -246,0 +246,0 @@ });

@@ -24,3 +24,2 @@ /**

InProgressInstallationEntry,
InstallationEntry,
RegisteredInstallationEntry,

@@ -74,3 +73,3 @@ RequestStatus,

it('saves the InstallationEntry in the database before returning it', async () => {
const oldDbEntry = await get<InstallationEntry>(appConfig);
const oldDbEntry = await get(appConfig);
expect(oldDbEntry).to.be.undefined;

@@ -80,3 +79,3 @@

const newDbEntry = await get<InstallationEntry>(appConfig);
const newDbEntry = await get(appConfig);
expect(newDbEntry).to.deep.equal(installationEntry);

@@ -88,3 +87,3 @@ });

const oldDbEntry = await get<InstallationEntry>(appConfig);
const oldDbEntry = await get(appConfig);
expect(oldDbEntry).to.be.undefined;

@@ -94,3 +93,3 @@

const newDbEntry = await get<InstallationEntry>(appConfig);
const newDbEntry = await get(appConfig);
expect(newDbEntry).to.deep.equal(installationEntry);

@@ -109,3 +108,3 @@ });

const oldDbEntry = await get<InstallationEntry>(appConfig);
const oldDbEntry = await get(appConfig);
expect(oldDbEntry).to.deep.equal(installationEntry);

@@ -116,6 +115,4 @@

const newDbEntry = await get<InstallationEntry>(appConfig);
expect(newDbEntry!.registrationStatus).to.deep.equal(
RequestStatus.COMPLETED
);
const newDbEntry = (await get(appConfig)) as RegisteredInstallationEntry;
expect(newDbEntry.registrationStatus).to.equal(RequestStatus.COMPLETED);
});

@@ -143,3 +140,3 @@

const oldDbEntry = await get<InstallationEntry>(appConfig);
const oldDbEntry = await get(appConfig);
expect(oldDbEntry).to.deep.equal(installationEntry);

@@ -150,6 +147,4 @@

const newDbEntry = await get<InstallationEntry>(appConfig);
expect(newDbEntry!.registrationStatus).to.deep.equal(
RequestStatus.NOT_STARTED
);
const newDbEntry = (await get(appConfig)) as UnregisteredInstallationEntry;
expect(newDbEntry.registrationStatus).to.equal(RequestStatus.NOT_STARTED);
});

@@ -176,3 +171,3 @@

const oldDbEntry = await get<InstallationEntry>(appConfig);
const oldDbEntry = await get(appConfig);
expect(oldDbEntry).to.deep.equal(installationEntry);

@@ -183,3 +178,3 @@

const newDbEntry = await get<InstallationEntry>(appConfig);
const newDbEntry = await get(appConfig);
expect(newDbEntry).to.be.undefined;

@@ -186,0 +181,0 @@ });

@@ -36,3 +36,3 @@ /**

await set(appConfig1, 'value');
const value = await get<string>(appConfig1);
const value = await get(appConfig1);
expect(value).to.equal('value');

@@ -42,3 +42,3 @@ });

it('gets undefined for a key that does not exist', async () => {
const value = await get<string>(appConfig1);
const value = await get(appConfig1);
expect(value).to.be.undefined;

@@ -50,4 +50,4 @@ });

await set(appConfig2, 'value2');
expect(await get<string>(appConfig1)).to.equal('value');
expect(await get<string>(appConfig2)).to.equal('value2');
expect(await get(appConfig1)).to.equal('value');
expect(await get(appConfig2)).to.equal('value2');
});

@@ -58,3 +58,3 @@

await set(appConfig1, 'newValue');
expect(await get<string>(appConfig1)).to.equal('newValue');
expect(await get(appConfig1)).to.equal('newValue');
});

@@ -67,3 +67,3 @@ });

await remove(appConfig1);
expect(await get<string>(appConfig1)).to.be.undefined;
expect(await get(appConfig1)).to.be.undefined;
});

@@ -73,3 +73,3 @@

await remove(appConfig1);
expect(await get<string>(appConfig1)).to.be.undefined;
expect(await get(appConfig1)).to.be.undefined;
});

@@ -105,3 +105,3 @@ });

// Called immediately after update, but before update completed.
const getPromise = get<string>(appConfig1);
const getPromise = get(appConfig1);
isGetCalled = true;

@@ -132,3 +132,3 @@

// Called immediately after update, but before update completed.
const getPromise = get<number>(appConfig1);
const getPromise = get(appConfig1);
isGetCalled = true;

@@ -135,0 +135,0 @@

@@ -41,5 +41,3 @@ /**

/** Gets record(s) from the objectStore that match the given key. */
export async function get<ReturnType>(
appConfig: AppConfig
): Promise<ReturnType | undefined> {
export async function get(appConfig: AppConfig): Promise<unknown> {
const key = getKey(appConfig);

@@ -46,0 +44,0 @@ const db = await dbPromise;

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