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

@foo-software/foo-api-client

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@foo-software/foo-api-client - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

dist/ApiClient.test.d.ts

33

dist/ApiClient.d.ts

@@ -1,2 +0,2 @@

import { ApiResponseInterface, ClientConfigInterface } from './interfaces';
import { ClientConfigInterface, CreatePagePayloadInterface, CreatePageQueueItemPayloadInterface, LighthouseAuditApiResponseInterface, LighthouseAuditsApiResponseInterface, OptionalFindParameters, PageApiResponseInterface, ResourceParametersBase, PagesApiResponseInterface, QueueItemApiResponseInterface, QueueItemsApiResponseInterface, UpdateLighthouseAuditPayloadInterface, UpdatePagePayloadInterface } from './interfaces';
export default class ApiClient {

@@ -6,3 +6,32 @@ apiToken: string;

constructor({ apiToken, apiUrl }: ClientConfigInterface);
findPages(): Promise<ApiResponseInterface>;
createPage({ payload, }: {
payload: CreatePagePayloadInterface;
}): Promise<PageApiResponseInterface>;
createPageQueueItem({ parameters, payload, }: {
parameters: ResourceParametersBase;
payload: CreatePageQueueItemPayloadInterface;
}): Promise<QueueItemApiResponseInterface>;
findPageLighthouseAudits({ parameters, }: {
parameters: ResourceParametersBase;
}): Promise<LighthouseAuditsApiResponseInterface>;
findPageQueueItems({ parameters, }: {
parameters: ResourceParametersBase;
}): Promise<QueueItemsApiResponseInterface>;
findPages({ parameters, }?: {
parameters?: OptionalFindParameters;
}): Promise<PagesApiResponseInterface>;
removeLighthouseAudit({ parameters, }: {
parameters: ResourceParametersBase;
}): Promise<LighthouseAuditApiResponseInterface>;
removePage({ parameters, }: {
parameters: ResourceParametersBase;
}): Promise<PageApiResponseInterface>;
updateLighthouseAudit({ parameters, payload, }: {
parameters: ResourceParametersBase;
payload: UpdateLighthouseAuditPayloadInterface;
}): Promise<LighthouseAuditApiResponseInterface>;
updatePage({ parameters, payload, }: {
parameters: ResourceParametersBase;
payload: UpdatePagePayloadInterface;
}): Promise<PageApiResponseInterface>;
}

@@ -15,19 +15,92 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const createPage_1 = __importDefault(require("./createPage"));
const createPageQueueItem_1 = __importDefault(require("./createPageQueueItem"));
const findPageLighthouseAudits_1 = __importDefault(require("./findPageLighthouseAudits"));
const findPageQueueItems_1 = __importDefault(require("./findPageQueueItems"));
const findPages_1 = __importDefault(require("./findPages"));
const removeLighthouseAudit_1 = __importDefault(require("./removeLighthouseAudit"));
const removePage_1 = __importDefault(require("./removePage"));
const updateLighthouseAudit_1 = __importDefault(require("./updateLighthouseAudit"));
const updatePage_1 = __importDefault(require("./updatePage"));
const constants_1 = require("./constants");
class ApiClient {
constructor({ apiToken, apiUrl = constants_1.LATEST_API_URL }) {
if (!apiToken) {
throw Error('API token is missing.');
}
this.apiToken = apiToken;
this.apiUrl = apiUrl;
}
findPages() {
createPage({ payload, }) {
return __awaiter(this, void 0, void 0, function* () {
return createPage_1.default({
parameters: {
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
payload,
});
});
}
createPageQueueItem({ parameters, payload, }) {
return __awaiter(this, void 0, void 0, function* () {
return createPageQueueItem_1.default({
parameters: Object.assign(Object.assign({}, parameters), { apiToken: this.apiToken, apiUrl: this.apiUrl }),
payload,
});
});
}
findPageLighthouseAudits({ parameters, }) {
return __awaiter(this, void 0, void 0, function* () {
return findPageLighthouseAudits_1.default({
parameters: Object.assign(Object.assign({}, parameters), { apiToken: this.apiToken, apiUrl: this.apiUrl }),
});
});
}
findPageQueueItems({ parameters, }) {
return __awaiter(this, void 0, void 0, function* () {
return findPageQueueItems_1.default({
parameters: Object.assign(Object.assign({}, parameters), { apiToken: this.apiToken, apiUrl: this.apiUrl }),
});
});
}
findPages({ parameters, } = {}) {
return __awaiter(this, void 0, void 0, function* () {
return findPages_1.default({
apiToken: this.apiToken,
apiUrl: this.apiUrl,
parameters: Object.assign(Object.assign({}, parameters), { apiToken: this.apiToken, apiUrl: this.apiUrl }),
});
});
}
removeLighthouseAudit({ parameters, }) {
return __awaiter(this, void 0, void 0, function* () {
return removeLighthouseAudit_1.default({
parameters: Object.assign(Object.assign({}, parameters), { apiToken: this.apiToken, apiUrl: this.apiUrl }),
});
});
}
removePage({ parameters, }) {
return __awaiter(this, void 0, void 0, function* () {
return removePage_1.default({
parameters: Object.assign(Object.assign({}, parameters), { apiToken: this.apiToken, apiUrl: this.apiUrl }),
});
});
}
updateLighthouseAudit({ parameters, payload, }) {
return __awaiter(this, void 0, void 0, function* () {
return updateLighthouseAudit_1.default({
parameters: Object.assign(Object.assign({}, parameters), { apiToken: this.apiToken, apiUrl: this.apiUrl }),
payload,
});
});
}
updatePage({ parameters, payload, }) {
return __awaiter(this, void 0, void 0, function* () {
return updatePage_1.default({
parameters: Object.assign(Object.assign({}, parameters), { apiToken: this.apiToken, apiUrl: this.apiUrl }),
payload,
});
});
}
}
exports.default = ApiClient;
//# sourceMappingURL=ApiClient.js.map

6

dist/findPages.d.ts

@@ -1,3 +0,5 @@

import { ApiResponseInterface, ClientConfigInterface } from './interfaces';
declare const _default: ({ apiToken, apiUrl, }: ClientConfigInterface) => Promise<ApiResponseInterface>;
import { FindPagesParameters, PagesApiResponseInterface } from './interfaces';
declare const _default: ({ parameters: { apiToken, apiUrl, ...parameters }, }: {
parameters: FindPagesParameters;
}) => Promise<PagesApiResponseInterface>;
export default _default;

@@ -11,2 +11,13 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -18,4 +29,18 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const constants_1 = require("./constants");
exports.default = ({ apiToken, apiUrl = constants_1.LATEST_API_URL, }) => __awaiter(void 0, void 0, void 0, function* () {
const result = yield node_fetch_1.default(`${apiUrl}/pages`, {
const helpers_1 = require("./helpers");
const helpers_2 = require("./helpers");
exports.default = (_a) => { var _b, apiToken, apiUrl, parameters; return __awaiter(void 0, void 0, void 0, function* () {
_b = _a.parameters, { apiToken, apiUrl = constants_1.LATEST_API_URL } = _b, parameters = __rest(_b, ["apiToken", "apiUrl"]);
const error = helpers_2.getMissingRequiredFieldErrors({
fields: ['apiToken'],
data: {
apiToken,
},
});
if (error) {
return {
error: `${error}.`,
};
}
const result = yield node_fetch_1.default(`${apiUrl}/pages${helpers_1.getQueryString(parameters)}`, {
method: 'get',

@@ -28,3 +53,3 @@ headers: {

return result.json();
});
}); };
//# sourceMappingURL=findPages.js.map

@@ -0,1 +1,9 @@

export { default as createPage } from './createPage';
export { default as createPageQueueItem } from './createPageQueueItem';
export { default as findPageLighthouseAudits } from './findPageLighthouseAudits';
export { default as findPageQueueItems } from './findPageQueueItems';
export { default as findPages } from './findPages';
export { default as removeLighthouseAudit } from './removeLighthouseAudit';
export { default as removePage } from './removePage';
export { default as updateLighthouseAudit } from './updateLighthouseAudit';
export { default as updatePage } from './updatePage';

@@ -6,5 +6,21 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.findPages = void 0;
exports.updatePage = exports.updateLighthouseAudit = exports.removePage = exports.removeLighthouseAudit = exports.findPages = exports.findPageQueueItems = exports.findPageLighthouseAudits = exports.createPageQueueItem = exports.createPage = void 0;
var createPage_1 = require("./createPage");
Object.defineProperty(exports, "createPage", { enumerable: true, get: function () { return __importDefault(createPage_1).default; } });
var createPageQueueItem_1 = require("./createPageQueueItem");
Object.defineProperty(exports, "createPageQueueItem", { enumerable: true, get: function () { return __importDefault(createPageQueueItem_1).default; } });
var findPageLighthouseAudits_1 = require("./findPageLighthouseAudits");
Object.defineProperty(exports, "findPageLighthouseAudits", { enumerable: true, get: function () { return __importDefault(findPageLighthouseAudits_1).default; } });
var findPageQueueItems_1 = require("./findPageQueueItems");
Object.defineProperty(exports, "findPageQueueItems", { enumerable: true, get: function () { return __importDefault(findPageQueueItems_1).default; } });
var findPages_1 = require("./findPages");
Object.defineProperty(exports, "findPages", { enumerable: true, get: function () { return __importDefault(findPages_1).default; } });
var removeLighthouseAudit_1 = require("./removeLighthouseAudit");
Object.defineProperty(exports, "removeLighthouseAudit", { enumerable: true, get: function () { return __importDefault(removeLighthouseAudit_1).default; } });
var removePage_1 = require("./removePage");
Object.defineProperty(exports, "removePage", { enumerable: true, get: function () { return __importDefault(removePage_1).default; } });
var updateLighthouseAudit_1 = require("./updateLighthouseAudit");
Object.defineProperty(exports, "updateLighthouseAudit", { enumerable: true, get: function () { return __importDefault(updateLighthouseAudit_1).default; } });
var updatePage_1 = require("./updatePage");
Object.defineProperty(exports, "updatePage", { enumerable: true, get: function () { return __importDefault(updatePage_1).default; } });
//# sourceMappingURL=index.js.map

@@ -0,1 +1,5 @@

export interface ApiResponseInterface {
data?: any;
error?: string;
}
export interface ClientConfigInterface {

@@ -5,5 +9,97 @@ apiToken: string;

}
export interface ApiResponseInterface {
data?: any;
error?: string;
export interface CreatePagePayloadInterface {
device?: DeviceType;
name: string;
url: string;
}
export interface CreatePageQueueItemPayloadInterface {
tag?: string;
}
declare type DeviceType = 'desktop' | 'mobile';
export interface FindPageLighthouseAuditsParameters extends ResourceParametersBase, FindPagesParameters {
}
export interface FindPagesParameters extends ClientConfigInterface, OptionalFindParameters {
}
export interface LighthouseAuditInterface {
createdAt: string;
device: DeviceType;
error: string;
finalScreenshot: string;
id: string;
lighthouseVersion: string;
opportunities: Opportunity[];
pageId: string;
queueId: string;
report: string;
scoreAccessibility: number;
scoreBestPractices: number;
scorePerformance: number;
scoreProgressiveWebApp: number;
scoreSeo: number;
tag: string;
url: string;
}
export interface LighthouseAuditApiResponseInterface extends ApiResponseInterface {
data?: LighthouseAuditInterface;
}
export interface LighthouseAuditsApiResponseInterface extends ApiResponseInterface {
data?: LighthouseAuditInterface[];
}
export interface Opportunity {
id: string;
numericValue: number;
numericUnit?: 'millisecond' | string;
rating: 'average' | 'error' | 'fail' | 'pass' | string;
}
export interface OptionalFindParameters {
criteria?: 'ascending' | 'descending';
from?: string;
limit?: number;
skip?: number;
sort?: string;
to?: string;
}
export interface PageInterface {
accountId: string;
createdAt: string;
device: DeviceType;
id: string;
name: string;
url: string;
}
export interface PageApiResponseInterface extends ApiResponseInterface {
data?: PageInterface;
}
export interface PagesApiResponseInterface extends ApiResponseInterface {
data?: PageInterface[];
}
export interface QueueItemInterface {
createdAt: string;
id: string;
index: number;
pageId: string;
status: 'available' | 'busy';
tag: string;
type: string;
waitSeconds: string;
}
export interface QueueItemApiResponseInterface extends ApiResponseInterface {
data?: QueueItemInterface;
}
export interface QueueItemsApiResponseInterface extends ApiResponseInterface {
data?: QueueItemInterface[];
}
export interface ResourceParametersBase {
id: string;
}
export interface ResourceParameters extends ClientConfigInterface, ResourceParametersBase {
}
export interface UpdateLighthouseAuditPayloadInterface {
tag?: string;
}
export interface UpdatePagePayloadInterface {
device?: DeviceType;
name?: string;
url?: string;
}
export {};
{
"name": "@foo-software/foo-api-client",
"version": "0.0.2",
"version": "0.0.3",
"author": "Adam Henson <adamhenson1979@gmail.com> (https://github.com/adamhenson)",

@@ -24,3 +24,4 @@ "description": "An API client to communicate with Foo's REST API endpoints. Foo provides website quality monitoring with tools such as Lighthouse.",

"clean": "rimraf dist",
"prepare": "npm run clean && npm run build"
"prepare": "npm run clean && npm run build",
"test": "jest"
},

@@ -31,8 +32,11 @@ "dependencies": {

"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^14.14.2",
"@types/node-fetch": "^2.5.10",
"jest": "^26.6.3",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.5",
"typescript": "^4.0.3"
},
"gitHead": "b6be89a379db3241ce67ff567060caf8633c0e28"
"gitHead": "a4c4d0d05f7b2ce7849d90184015e6a404636a41"
}

@@ -0,3 +1,25 @@

import createPage from './createPage';
import createPageQueueItem from './createPageQueueItem';
import findPageLighthouseAudits from './findPageLighthouseAudits';
import findPageQueueItems from './findPageQueueItems';
import findPages from './findPages';
import { ApiResponseInterface, ClientConfigInterface } from './interfaces';
import removeLighthouseAudit from './removeLighthouseAudit';
import removePage from './removePage';
import updateLighthouseAudit from './updateLighthouseAudit';
import updatePage from './updatePage';
import {
ClientConfigInterface,
CreatePagePayloadInterface,
CreatePageQueueItemPayloadInterface,
LighthouseAuditApiResponseInterface,
LighthouseAuditsApiResponseInterface,
OptionalFindParameters,
PageApiResponseInterface,
ResourceParametersBase,
PagesApiResponseInterface,
QueueItemApiResponseInterface,
QueueItemsApiResponseInterface,
UpdateLighthouseAuditPayloadInterface,
UpdatePagePayloadInterface,
} from './interfaces';
import { LATEST_API_URL } from './constants';

@@ -10,2 +32,6 @@

constructor({ apiToken, apiUrl = LATEST_API_URL }: ClientConfigInterface) {
if (!apiToken) {
throw Error('API token is missing.');
}
this.apiToken = apiToken;

@@ -15,8 +41,136 @@ this.apiUrl = apiUrl;

async findPages(): Promise<ApiResponseInterface> {
async createPage({
payload,
}: {
payload: CreatePagePayloadInterface;
}): Promise<PageApiResponseInterface> {
return createPage({
parameters: {
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
payload,
});
}
async createPageQueueItem({
parameters,
payload,
}: {
parameters: ResourceParametersBase;
payload: CreatePageQueueItemPayloadInterface;
}): Promise<QueueItemApiResponseInterface> {
return createPageQueueItem({
parameters: {
...parameters,
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
payload,
});
}
async findPageLighthouseAudits({
parameters,
}: {
parameters: ResourceParametersBase;
}): Promise<LighthouseAuditsApiResponseInterface> {
return findPageLighthouseAudits({
parameters: {
...parameters,
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
});
}
async findPageQueueItems({
parameters,
}: {
parameters: ResourceParametersBase;
}): Promise<QueueItemsApiResponseInterface> {
return findPageQueueItems({
parameters: {
...parameters,
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
});
}
async findPages({
parameters,
}: {
parameters?: OptionalFindParameters;
} = {}): Promise<PagesApiResponseInterface> {
return findPages({
apiToken: this.apiToken,
apiUrl: this.apiUrl,
parameters: {
...parameters,
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
});
}
async removeLighthouseAudit({
parameters,
}: {
parameters: ResourceParametersBase;
}): Promise<LighthouseAuditApiResponseInterface> {
return removeLighthouseAudit({
parameters: {
...parameters,
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
});
}
async removePage({
parameters,
}: {
parameters: ResourceParametersBase;
}): Promise<PageApiResponseInterface> {
return removePage({
parameters: {
...parameters,
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
});
}
async updateLighthouseAudit({
parameters,
payload,
}: {
parameters: ResourceParametersBase;
payload: UpdateLighthouseAuditPayloadInterface;
}): Promise<LighthouseAuditApiResponseInterface> {
return updateLighthouseAudit({
parameters: {
...parameters,
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
payload,
});
}
async updatePage({
parameters,
payload,
}: {
parameters: ResourceParametersBase;
payload: UpdatePagePayloadInterface;
}): Promise<PageApiResponseInterface> {
return updatePage({
parameters: {
...parameters,
apiToken: this.apiToken,
apiUrl: this.apiUrl,
},
payload,
});
}
}
import fetch from 'node-fetch';
import { LATEST_API_URL } from './constants';
import { ApiResponseInterface, ClientConfigInterface } from './interfaces';
import { getQueryString } from './helpers';
import { FindPagesParameters, PagesApiResponseInterface } from './interfaces';
import { getMissingRequiredFieldErrors } from './helpers';
export default async ({
apiToken,
apiUrl = LATEST_API_URL,
}: ClientConfigInterface): Promise<ApiResponseInterface> => {
const result = await fetch(`${apiUrl}/pages`, {
parameters: { apiToken, apiUrl = LATEST_API_URL, ...parameters },
}: {
parameters: FindPagesParameters;
}): Promise<PagesApiResponseInterface> => {
const error = getMissingRequiredFieldErrors({
fields: ['apiToken'],
data: {
apiToken,
},
});
if (error) {
return {
error: `${error}.`,
};
}
const result = await fetch(`${apiUrl}/pages${getQueryString(parameters)}`, {
method: 'get',

@@ -11,0 +27,0 @@ headers: {

@@ -0,1 +1,9 @@

export { default as createPage } from './createPage';
export { default as createPageQueueItem } from './createPageQueueItem';
export { default as findPageLighthouseAudits } from './findPageLighthouseAudits';
export { default as findPageQueueItems } from './findPageQueueItems';
export { default as findPages } from './findPages';
export { default as removeLighthouseAudit } from './removeLighthouseAudit';
export { default as removePage } from './removePage';
export { default as updateLighthouseAudit } from './updateLighthouseAudit';
export { default as updatePage } from './updatePage';

@@ -0,1 +1,6 @@

export interface ApiResponseInterface {
data?: any;
error?: string;
}
export interface ClientConfigInterface {

@@ -6,5 +11,120 @@ apiToken: string;

export interface ApiResponseInterface {
data?: any;
error?: string;
export interface CreatePagePayloadInterface {
device?: DeviceType;
name: string;
url: string;
}
export interface CreatePageQueueItemPayloadInterface {
tag?: string;
}
type DeviceType = 'desktop' | 'mobile';
export interface FindPageLighthouseAuditsParameters
extends ResourceParametersBase,
FindPagesParameters {}
export interface FindPagesParameters
extends ClientConfigInterface,
OptionalFindParameters {}
export interface LighthouseAuditInterface {
createdAt: string;
device: DeviceType;
error: string;
finalScreenshot: string;
id: string;
lighthouseVersion: string;
opportunities: Opportunity[];
pageId: string;
queueId: string;
report: string;
scoreAccessibility: number;
scoreBestPractices: number;
scorePerformance: number;
scoreProgressiveWebApp: number;
scoreSeo: number;
tag: string;
url: string;
}
export interface LighthouseAuditApiResponseInterface
extends ApiResponseInterface {
data?: LighthouseAuditInterface;
}
export interface LighthouseAuditsApiResponseInterface
extends ApiResponseInterface {
data?: LighthouseAuditInterface[];
}
export interface Opportunity {
id: string;
numericValue: number;
numericUnit?: 'millisecond' | string;
rating: 'average' | 'error' | 'fail' | 'pass' | string;
}
export interface OptionalFindParameters {
criteria?: 'ascending' | 'descending';
from?: string;
limit?: number;
skip?: number;
sort?: string;
to?: string;
}
export interface PageInterface {
accountId: string;
createdAt: string;
device: DeviceType;
id: string;
name: string;
url: string;
}
export interface PageApiResponseInterface extends ApiResponseInterface {
data?: PageInterface;
}
export interface PagesApiResponseInterface extends ApiResponseInterface {
data?: PageInterface[];
}
export interface QueueItemInterface {
createdAt: string;
id: string;
index: number;
pageId: string;
status: 'available' | 'busy';
tag: string;
type: string;
waitSeconds: string;
}
export interface QueueItemApiResponseInterface extends ApiResponseInterface {
data?: QueueItemInterface;
}
export interface QueueItemsApiResponseInterface extends ApiResponseInterface {
data?: QueueItemInterface[];
}
export interface ResourceParametersBase {
id: string;
}
export interface ResourceParameters
extends ClientConfigInterface,
ResourceParametersBase {}
export interface UpdateLighthouseAuditPayloadInterface {
tag?: string;
}
export interface UpdatePagePayloadInterface {
device?: DeviceType;
name?: string;
url?: string;
}

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