Socket
Socket
Sign inDemoInstall

@prismatic-io/spectral

Package Overview
Dependencies
Maintainers
4
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prismatic-io/spectral - npm Package Compare versions

Comparing version 6.5.0 to 6.5.1

148

dist/clients/http/index.d.ts

@@ -0,4 +1,12 @@

import { AxiosResponse } from "axios";
import { AxiosInstance, AxiosRequestConfig } from "axios";
import { IAxiosRetryConfig } from "axios-retry";
import { ActionInputParameters } from "../../types";
import { inputs } from "./inputs";
export declare type HttpClient = AxiosInstance;
interface RetryConfig extends Omit<IAxiosRetryConfig, "retryDelay"> {
retryDelay?: IAxiosRetryConfig["retryDelay"] | number;
retryAllErrors?: boolean;
useExponentialBackoff?: boolean;
}
export interface ClientProps {

@@ -10,5 +18,143 @@ baseUrl?: string;

debug?: boolean;
retryConfig?: IAxiosRetryConfig;
retryConfig?: RetryConfig;
}
export declare const createClient: ({ baseUrl, responseType, headers, timeout, debug, retryConfig, }: ClientProps) => HttpClient;
export declare const handleErrors: (error: unknown) => unknown;
declare type SendRawRequestValues = ActionInputParameters<typeof inputs>;
export declare const sendRawRequest: (baseUrl: string, values: SendRawRequestValues, authorizationHeaders?: Record<string, string>) => Promise<AxiosResponse>;
export declare const buildRawRequestAction: (baseUrl: string, label?: string, description?: string) => import("../..").ActionDefinition<{
url: {
label: string;
placeholder: string;
type: "string";
required: true;
comments: string;
example: string;
clean: (value: unknown) => string;
};
method: {
label: string;
type: "string";
required: true;
model: {
label: import("axios").Method;
value: import("axios").Method;
}[];
comments: string;
clean: (value: unknown) => string;
};
data: {
label: string;
placeholder: string;
type: "string";
required: false;
comments: string;
example: string;
clean: (value: unknown) => string;
};
formData: {
label: string;
placeholder: string;
type: "string";
collection: "keyvaluelist";
required: false;
comments: string;
example: string;
};
fileData: {
label: string;
placeholder: string;
type: "string";
collection: "keyvaluelist";
required: false;
comments: string;
example: string;
};
queryParams: {
label: string;
placeholder: string;
type: "string";
collection: "keyvaluelist";
required: false;
comments: string;
};
headers: {
label: string;
placeholder: string;
type: "string";
collection: "keyvaluelist";
required: false;
comments: string;
example: string;
};
responseType: {
label: string;
placeholder: string;
type: "string";
default: string;
required: true;
comments: string;
model: {
label: import("axios").ResponseType;
value: import("axios").ResponseType;
}[];
clean: (value: unknown) => import("axios").ResponseType;
};
timeout: {
label: string;
type: "string";
required: false;
comments: string;
example: string;
clean: (value: unknown) => number;
};
debugRequest: {
label: string;
type: "boolean";
required: false;
comments: string;
clean: (value: unknown) => boolean;
};
retryDelayMS: {
label: string;
placeholder: string;
type: "string";
required: false;
comments: string;
default: string;
clean: (value: unknown) => number;
};
retryAllErrors: {
label: string;
type: "boolean";
default: string;
required: false;
comments: string;
clean: (value: unknown) => boolean;
};
maxRetries: {
label: string;
placeholder: string;
type: "string";
required: false;
comments: string;
default: string;
clean: (value: unknown) => number;
};
useExponentialBackoff: {
label: string;
type: "boolean";
default: string;
required: false;
comments: string;
clean: (value: unknown) => boolean;
};
connection: {
label: string;
type: "connection";
required: true;
};
}, boolean, {
data: any;
}>;
export { inputs };
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
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) {

@@ -6,6 +49,45 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.handleErrors = exports.createClient = void 0;
exports.inputs = exports.buildRawRequestAction = exports.sendRawRequest = exports.handleErrors = exports.createClient = void 0;
const lodash_1 = require("lodash");
const axios_1 = __importDefault(require("axios"));
const axios_retry_1 = __importDefault(require("axios-retry"));
const util_1 = require("../../util");
const axios_retry_1 = __importStar(require("axios-retry"));
const form_data_1 = __importDefault(require("form-data"));
const __1 = require("../..");
const util_1 = __importDefault(require("../../util"));
const inputs_1 = require("./inputs");
Object.defineProperty(exports, "inputs", { enumerable: true, get: function () { return inputs_1.inputs; } });
const toAuthorizationHeaders = (connection) => {
var _a, _b, _c, _d;
const accessToken = util_1.default.types.toString((_a = connection.token) === null || _a === void 0 ? void 0 : _a.access_token);
if (accessToken) {
return { Authorization: `Bearer ${accessToken}` };
}
const apiKey = util_1.default.types.toString((_b = connection.fields) === null || _b === void 0 ? void 0 : _b.apiKey);
if (apiKey) {
return { Authorization: `Bearer ${apiKey}` };
}
const username = util_1.default.types.toString((_c = connection.fields) === null || _c === void 0 ? void 0 : _c.username);
const password = util_1.default.types.toString((_d = connection.fields) === null || _d === void 0 ? void 0 : _d.password);
if (username && password) {
const encoded = Buffer.from(`${username}:${password}`).toString("base64");
return { Authorization: `Basic ${encoded}` };
}
throw new Error(`Failed to guess at authorization parameters for Connection: ${connection.key}`);
};
const toFormData = (formData, fileData) => {
const form = new form_data_1.default();
(formData || []).map(({ key, value }) => form.append(key, value));
(fileData || []).map(({ key, value }) => form.append(key, value, { filename: key }));
return form;
};
const computeRetryDelay = (retryDelay, useExponentialBackoff) => {
if (useExponentialBackoff) {
return axios_retry_1.exponentialDelay;
}
return typeof retryDelay === "number" ? () => retryDelay : retryDelay;
};
const toAxiosRetryConfig = (_a) => {
var { retryDelay, retryAllErrors, retryCondition, useExponentialBackoff } = _a, rest = __rest(_a, ["retryDelay", "retryAllErrors", "retryCondition", "useExponentialBackoff"]);
return (Object.assign(Object.assign({}, rest), { retryDelay: computeRetryDelay(retryDelay, useExponentialBackoff), retryCondition: retryAllErrors ? () => true : retryCondition }));
};
const createClient = ({ baseUrl, responseType, headers, timeout, debug = false, retryConfig, }) => {

@@ -22,7 +104,7 @@ const client = axios_1.default.create({

client.interceptors.request.use((request) => {
console.log((0, util_1.toJSON)(request));
console.log(util_1.default.types.toJSON(request));
return request;
});
client.interceptors.response.use((response) => {
console.log((0, util_1.toJSON)(response));
console.log(util_1.default.types.toJSON(response));
return response;

@@ -33,3 +115,3 @@ });

// eslint-disable-next-line @typescript-eslint/no-explicit-any
(0, axios_retry_1.default)(client, retryConfig);
(0, axios_retry_1.default)(client, toAxiosRetryConfig(retryConfig));
}

@@ -50,1 +132,37 @@ return client;

exports.handleErrors = handleErrors;
const sendRawRequest = (baseUrl, values, authorizationHeaders = {}) => __awaiter(void 0, void 0, void 0, function* () {
if (values.data && (!(0, lodash_1.isEmpty)(values.formData) || !(0, lodash_1.isEmpty)(values.fileData))) {
throw new Error("Cannot specify both Data and File/Form Data.");
}
const payload = values.data || toFormData(values.formData, values.fileData);
const client = (0, exports.createClient)({
baseUrl,
debug: values.debugRequest,
responseType: values.responseType,
timeout: values.timeout,
retryConfig: {
retries: values.maxRetries,
retryDelay: values.retryDelayMS,
retryAllErrors: values.retryAllErrors,
useExponentialBackoff: values.useExponentialBackoff,
},
});
return yield client.request({
method: values.method,
url: values.url,
headers: Object.assign(Object.assign(Object.assign({}, util_1.default.types.keyValPairListToObject(values.headers)), (payload instanceof form_data_1.default ? payload.getHeaders() : {})), authorizationHeaders),
params: util_1.default.types.keyValPairListToObject(values.queryParams),
data: payload,
});
});
exports.sendRawRequest = sendRawRequest;
const buildRawRequestAction = (baseUrl, label = "Raw Request", description = "Issue a raw HTTP request") => (0, __1.action)({
display: { label, description },
inputs: Object.assign({ connection: { label: "Connection", type: "connection", required: true } }, inputs_1.inputs),
perform: (context, _a) => __awaiter(void 0, void 0, void 0, function* () {
var { connection } = _a, httpInputValues = __rest(_a, ["connection"]);
const { data } = yield (0, exports.sendRawRequest)(baseUrl, httpInputValues, toAuthorizationHeaders(connection));
return { data };
}),
});
exports.buildRawRequestAction = buildRawRequestAction;

@@ -31,2 +31,3 @@ import { Method, ResponseType } from "axios";

type: "string";
required: true;
model: {

@@ -44,3 +45,3 @@ label: Method;

default: string;
required: false;
required: true;
comments: string;

@@ -51,3 +52,3 @@ model: {

}[];
clean: (value: unknown) => string;
clean: (value: unknown) => ResponseType;
};

@@ -87,2 +88,3 @@ export declare const headers: {

default: string;
clean: (value: unknown) => number;
};

@@ -97,3 +99,3 @@ export declare const useExponentialBackoff: {

};
export declare const retryOnAllErrors: {
export declare const retryAllErrors: {
label: string;

@@ -131,1 +133,129 @@ type: "boolean";

};
export declare const inputs: {
url: {
label: string;
placeholder: string;
type: "string";
required: true;
comments: string;
example: string;
clean: (value: unknown) => string;
};
method: {
label: string;
type: "string";
required: true;
model: {
label: Method;
value: Method;
}[];
comments: string;
clean: (value: unknown) => string;
};
data: {
label: string;
placeholder: string;
type: "string";
required: false;
comments: string;
example: string;
clean: (value: unknown) => string;
};
formData: {
label: string;
placeholder: string;
type: "string";
collection: "keyvaluelist";
required: false;
comments: string;
example: string;
};
fileData: {
label: string;
placeholder: string;
type: "string";
collection: "keyvaluelist";
required: false;
comments: string;
example: string;
};
queryParams: {
label: string;
placeholder: string;
type: "string";
collection: "keyvaluelist";
required: false;
comments: string;
};
headers: {
label: string;
placeholder: string;
type: "string";
collection: "keyvaluelist";
required: false;
comments: string;
example: string;
};
responseType: {
label: string;
placeholder: string;
type: "string";
default: string;
required: true;
comments: string;
model: {
label: ResponseType;
value: ResponseType;
}[];
clean: (value: unknown) => ResponseType;
};
timeout: {
label: string;
type: "string";
required: false;
comments: string;
example: string;
clean: (value: unknown) => number;
};
debugRequest: {
label: string;
type: "boolean";
required: false;
comments: string;
clean: (value: unknown) => boolean;
};
retryDelayMS: {
label: string;
placeholder: string;
type: "string";
required: false;
comments: string;
default: string;
clean: (value: unknown) => number;
};
retryAllErrors: {
label: string;
type: "boolean";
default: string;
required: false;
comments: string;
clean: (value: unknown) => boolean;
};
maxRetries: {
label: string;
placeholder: string;
type: "string";
required: false;
comments: string;
default: string;
clean: (value: unknown) => number;
};
useExponentialBackoff: {
label: string;
type: "boolean";
default: string;
required: false;
comments: string;
clean: (value: unknown) => boolean;
};
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debugRequest = exports.fileData = exports.formData = exports.retryOnAllErrors = exports.useExponentialBackoff = exports.retryDelayMS = exports.maxRetries = exports.queryParams = exports.headers = exports.responseType = exports.method = exports.timeout = exports.data = exports.url = void 0;
exports.inputs = exports.debugRequest = exports.fileData = exports.formData = exports.retryAllErrors = exports.useExponentialBackoff = exports.retryDelayMS = exports.maxRetries = exports.queryParams = exports.headers = exports.responseType = exports.method = exports.timeout = exports.data = exports.url = void 0;
const __1 = require("../..");

@@ -52,2 +52,3 @@ const supportedMethods = [

type: "string",
required: true,
model: supportedMethods.map((method) => ({ label: method, value: method })),

@@ -62,3 +63,3 @@ comments: "The HTTP method to use.",

default: "json",
required: false,
required: true,
comments: "The type of data you expect in the response. You can request json, text, or binary data.",

@@ -104,2 +105,3 @@ model: supportedResponseTypes.map((responseType) => ({

default: "0",
clean: (value) => __1.util.types.toNumber(value, 0),
});

@@ -114,3 +116,3 @@ exports.useExponentialBackoff = (0, __1.input)({

});
exports.retryOnAllErrors = (0, __1.input)({
exports.retryAllErrors = (0, __1.input)({
label: "Retry On All Errors",

@@ -148,1 +150,17 @@ type: "boolean",

});
exports.inputs = {
url: exports.url,
method: exports.method,
data: exports.data,
formData: exports.formData,
fileData: exports.fileData,
queryParams: exports.queryParams,
headers: exports.headers,
responseType: exports.responseType,
timeout: exports.timeout,
debugRequest: exports.debugRequest,
retryDelayMS: exports.retryDelayMS,
retryAllErrors: exports.retryAllErrors,
maxRetries: exports.maxRetries,
useExponentialBackoff: exports.useExponentialBackoff,
};

7

dist/serverTypes/perform.js

@@ -11,6 +11,9 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPerform = void 0;
const serialize_error_1 = require("serialize-error");
const util_1 = require("../util");
const util_1 = __importDefault(require("../util"));
const cleanParams = (params, cleaners) => Object.entries(params).reduce((result, [key, value]) => {

@@ -35,3 +38,3 @@ const cleanFn = cleaners[key];

const handled = errorHandler(error);
const serialized = (0, util_1.toJSON)((0, serialize_error_1.serializeError)(handled));
const serialized = util_1.default.types.toJSON((0, serialize_error_1.serializeError)(handled));
throw new Error(serialized);

@@ -38,0 +41,0 @@ }

@@ -7,8 +7,2 @@ /**

import { KeyValuePair, DataPayload } from "./types";
/** This function accepts an arbitrary object/value and safely serializes it (handles cyclic references).
*
* @param value Arbitrary object/value to serialize.
* @returns JSON serialized text that can be safely logged.
*/
export declare const toJSON: (value: unknown) => string;
/**

@@ -42,3 +36,3 @@ * This function returns a lower cased version of the headers passed to it.

toString: (value: unknown, defaultValue?: string) => string;
keyValPairListToObject: <TValue = unknown>(kvpList?: KeyValuePair<unknown>[], valueConverter?: ((value: unknown) => TValue) | undefined) => Record<string, TValue>;
keyValPairListToObject: <TValue = unknown>(kvpList: KeyValuePair<unknown>[], valueConverter?: ((value: unknown) => TValue) | undefined) => Record<string, TValue>;
isJSON: (value: string) => boolean;

@@ -45,0 +39,0 @@ toJSON: (value: unknown) => string;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.lowerCaseHeaders = exports.toJSON = void 0;
exports.lowerCaseHeaders = void 0;
/** */

@@ -201,4 +201,4 @@ const parseISO_1 = __importDefault(require("date-fns/parseISO"));

*/
const keyValPairListToObject = (kvpList = [], valueConverter) => {
return kvpList.reduce((result, { key, value }) => (Object.assign(Object.assign({}, result), { [key]: valueConverter ? valueConverter(value) : value })), {});
const keyValPairListToObject = (kvpList, valueConverter) => {
return (kvpList || []).reduce((result, { key, value }) => (Object.assign(Object.assign({}, result), { [key]: valueConverter ? valueConverter(value) : value })), {});
};

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

};
exports.toJSON = toJSON;
/**

@@ -362,3 +361,3 @@ * This function returns a lower cased version of the headers passed to it.

isJSON,
toJSON: exports.toJSON,
toJSON,
lowerCaseHeaders: exports.lowerCaseHeaders,

@@ -365,0 +364,0 @@ },

{
"name": "@prismatic-io/spectral",
"version": "6.5.0",
"version": "6.5.1",
"description": "Utility library for building Prismatic components",

@@ -40,5 +40,6 @@ "keywords": [

"dependencies": {
"axios": "0.26.1",
"axios-retry": "3.2.4",
"axios": "0.27.2",
"axios-retry": "3.2.5",
"date-fns": "2.28.0",
"form-data": "4.0.0",
"jest-mock": "27.0.3",

@@ -45,0 +46,0 @@ "soap": "0.43.0",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc