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
2717
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.3-canary.6045a08 to 0.1.3-canary.ae78569

.rpt2_cache/rpt2_2e4b1ab0816cf18c79e028ce6a2448de596a7c19/code/cache/03badcc63fb26f8163137b77902291b0b159b03c

30

dist/index.cjs.js

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

var version = "0.1.3-canary.6045a08";
var version = "0.1.3-canary.ae78569";

@@ -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.3-canary.6045a08";
var version = "0.1.3-canary.ae78569";

@@ -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.3-canary.6045a08";
const version = "0.1.3-canary.ae78569";

@@ -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>;
{
"name": "@firebase/installations",
"version": "0.1.3-canary.6045a08",
"version": "0.1.3-canary.ae78569",
"main": "dist/index.cjs.js",

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

"peerDependencies": {
"@firebase/app": "0.4.3-canary.6045a08",
"@firebase/app-types": "0.4.0-canary.6045a08"
"@firebase/app": "0.4.3-canary.ae78569",
"@firebase/app-types": "0.4.0-canary.ae78569"
},
"dependencies": {
"@firebase/installations-types": "0.1.1-canary.6045a08",
"@firebase/util": "0.2.17-canary.6045a08",
"@firebase/installations-types": "0.1.1-canary.ae78569",
"@firebase/util": "0.2.17-canary.ae78569",
"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();

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