New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@teleporthq/teleport-plugin-common

Package Overview
Dependencies
Maintainers
2
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teleporthq/teleport-plugin-common - npm Package Compare versions

Comparing version 0.32.0 to 0.32.3

1

dist/cjs/utils/ast-utils.d.ts

@@ -49,2 +49,3 @@ import * as types from '@babel/types';

export declare const generateURLParamsAST: (urlParams: Record<string, UIDLStaticValue | UIDLStateValue | UIDLPropValue | UIDLExpressionValue>) => types.TemplateLiteral | null;
export declare const computeFetchUrl: (resource: UIDLResourceItem) => types.TemplateLiteral;
export declare const resolveObjectValue: (prop: UIDLStaticValue | UIDLExpressionValue) => types.Identifier | types.StringLiteral | types.NumericLiteral | types.BooleanLiteral | types.ObjectExpression | types.Expression;

@@ -51,0 +52,0 @@ export declare const getExpressionFromUIDLExpressionNode: (node: UIDLExpressionValue) => types.Expression;

82

dist/cjs/utils/ast-utils.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.getExpressionFromUIDLExpressionNode = exports.resolveObjectValue = exports.generateURLParamsAST = exports.generateMemberExpressionASTFromPath = exports.generateMemberExpressionASTFromBase = exports.generateRemoteResourceASTs = exports.wrapObjectPropertiesWithExpression = exports.generateDynamicWindowImport = exports.createStateHookAST = exports.createReturnExpressionSyntax = exports.createPureComponent = exports.createClassComponent = exports.removeAttributeByName = exports.findAttributeByName = exports.getTSAnnotationForType = exports.addPropertyToASTObject = exports.convertValueToLiteral = exports.objectToObjectExpression = exports.renameJSXTag = exports.addSpreadAttributeToJSXTag = exports.addChildJSXText = exports.addChildJSXTag = exports.addRawAttributeToJSXTag = exports.addAttributeToJSXTag = exports.stringAsTemplateLiteral = exports.addMultipleDynamicAttributesToJSXTag = exports.addDynamicExpressionAttributeToJSXTag = exports.addDynamicAttributeToJSXTag = exports.addClassStringOnJSXTag = void 0;
exports.getExpressionFromUIDLExpressionNode = exports.resolveObjectValue = exports.computeFetchUrl = exports.generateURLParamsAST = exports.generateMemberExpressionASTFromPath = exports.generateMemberExpressionASTFromBase = exports.generateRemoteResourceASTs = exports.wrapObjectPropertiesWithExpression = exports.generateDynamicWindowImport = exports.createStateHookAST = exports.createReturnExpressionSyntax = exports.createPureComponent = exports.createClassComponent = exports.removeAttributeByName = exports.findAttributeByName = exports.getTSAnnotationForType = exports.addPropertyToASTObject = exports.convertValueToLiteral = exports.objectToObjectExpression = exports.renameJSXTag = exports.addSpreadAttributeToJSXTag = exports.addChildJSXText = exports.addChildJSXTag = exports.addRawAttributeToJSXTag = exports.addAttributeToJSXTag = exports.stringAsTemplateLiteral = exports.addMultipleDynamicAttributesToJSXTag = exports.addDynamicExpressionAttributeToJSXTag = exports.addDynamicAttributeToJSXTag = exports.addClassStringOnJSXTag = void 0;
var types = __importStar(require("@babel/types"));

@@ -45,3 +45,2 @@ var core_1 = require("@babel/core");

var preset_react_1 = __importDefault(require("@babel/preset-react"));
var __1 = require("..");
/**

@@ -421,5 +420,4 @@ * Adds a class definition string to an existing string of classes

var generateRemoteResourceASTs = function (resource) {
var _a, _b;
var fetchUrl = computeFetchUrl(resource);
var authHeaderAST = computeAuthorizationHeaderAST(resource === null || resource === void 0 ? void 0 : resource.headers);
var _a, _b, _c;
var fetchUrl = (0, exports.computeFetchUrl)(resource);
var headersASTs = (resource === null || resource === void 0 ? void 0 : resource.headers) ? generateRESTHeadersAST(resource.headers) : [];

@@ -436,20 +434,4 @@ var queryParams = (0, exports.generateURLParamsAST)(resource === null || resource === void 0 ? void 0 : resource.params);

}
var paramsDeclerations = Object.keys((resource === null || resource === void 0 ? void 0 : resource.params) || {}).reduce(function (acc, item) {
var prop = resource.params[item];
if (prop.type === 'static') {
acc.push(types.objectProperty(types.stringLiteral(item), __1.ASTUtils.resolveObjectValue(prop)));
}
if (prop.type === 'expr') {
acc.push(types.objectProperty(types.stringLiteral(item), __1.ASTUtils.getExpressionFromUIDLExpressionNode(prop)));
}
if (prop.type === 'dynamic') {
acc.push(types.spreadElement(types.logicalExpression('&&', types.memberExpression(types.identifier('params'), types.stringLiteral(prop.content.id), true, false), types.objectExpression([
types.objectProperty(types.stringLiteral(item), types.memberExpression(types.identifier('params'), types.stringLiteral(prop.content.id), true, false)),
]))));
}
return acc;
}, []);
var paramsAST = types.variableDeclaration('const', [
types.variableDeclarator(types.identifier('urlParams'), types.objectExpression(paramsDeclerations)),
]);
var urlParamsDecleration = generateParamsAST(resource === null || resource === void 0 ? void 0 : resource.params);
var bodyParamsDecleration = generateParamsAST(resource === null || resource === void 0 ? void 0 : resource.body);
var url = (queryParams === null || queryParams === void 0 ? void 0 : queryParams.quasis)

@@ -460,4 +442,4 @@ ? types.templateLiteral(__spreadArray(__spreadArray([], fetchUrlQuasis, true), queryParamsQuasis, true), __spreadArray([], fetchUrl.expressions.concat(queryParams.expressions), true))

var allHeaders = [];
if (authHeaderAST) {
allHeaders.push(authHeaderAST);
if ((_a = resource === null || resource === void 0 ? void 0 : resource.headers) === null || _a === void 0 ? void 0 : _a.authToken) {
allHeaders.push(computeAuthorizationHeaderAST(resource === null || resource === void 0 ? void 0 : resource.headers));
}

@@ -467,10 +449,19 @@ if (headersASTs.length) {

}
var headers = types.objectProperty(types.identifier('headers'), types.objectExpression(allHeaders));
var fetchAST = types.variableDeclaration('const', [
types.variableDeclarator(types.identifier('data'), types.awaitExpression(types.callExpression(types.identifier('fetch'), [
url,
types.objectExpression([method, headers]),
types.objectExpression(__spreadArray(__spreadArray([
method
], (allHeaders.length > 0
? [
types.objectProperty(types.identifier('headers'), types.objectExpression(allHeaders)),
]
: []), true), (bodyParamsDecleration.length > 0 && (resource === null || resource === void 0 ? void 0 : resource.method) === 'POST'
? [
types.objectProperty(types.identifier('body'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [types.identifier('bodyParams')])),
]
: []), true)),
]))),
]);
var responseType = (_b = (_a = resource === null || resource === void 0 ? void 0 : resource.response) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : 'json';
var responseType = (_c = (_b = resource === null || resource === void 0 ? void 0 : resource.response) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'json';
var responseJSONAST;

@@ -515,5 +506,37 @@ /**

}
return [paramsAST, fetchAST, responseJSONAST];
return __spreadArray(__spreadArray(__spreadArray([], (urlParamsDecleration.length > 0
? [
types.variableDeclaration('const', [
types.variableDeclarator(types.identifier('urlParams'), types.objectExpression(urlParamsDecleration)),
]),
]
: []), true), (bodyParamsDecleration.length > 0
? [
types.variableDeclaration('const', [
types.variableDeclarator(types.identifier('bodyParams'), types.objectExpression(bodyParamsDecleration)),
]),
]
: []), true), [
fetchAST,
responseJSONAST,
], false);
};
exports.generateRemoteResourceASTs = generateRemoteResourceASTs;
var generateParamsAST = function (props) {
return Object.keys(props || {}).reduce(function (acc, item) {
var prop = props[item];
if (prop.type === 'static') {
acc.push(types.objectProperty(types.stringLiteral(item), (0, exports.resolveObjectValue)(prop)));
}
if (prop.type === 'expr') {
acc.push(types.objectProperty(types.stringLiteral(item), (0, exports.getExpressionFromUIDLExpressionNode)(prop)));
}
if (prop.type === 'dynamic') {
acc.push(types.spreadElement(types.logicalExpression('&&', types.memberExpression(types.identifier('params'), types.stringLiteral(prop.content.id), true, false), types.objectExpression([
types.objectProperty(types.stringLiteral(item), types.memberExpression(types.identifier('params'), types.stringLiteral(prop.content.id), true, false)),
]))));
}
return acc;
}, []);
};
var generateRESTHeadersAST = function (headers) {

@@ -662,2 +685,3 @@ return Object.keys(headers)

};
exports.computeFetchUrl = computeFetchUrl;
var resolveResourceValue = function (value) {

@@ -664,0 +688,0 @@ if (!value) {

@@ -49,2 +49,3 @@ import * as types from '@babel/types';

export declare const generateURLParamsAST: (urlParams: Record<string, UIDLStaticValue | UIDLStateValue | UIDLPropValue | UIDLExpressionValue>) => types.TemplateLiteral | null;
export declare const computeFetchUrl: (resource: UIDLResourceItem) => types.TemplateLiteral;
export declare const resolveObjectValue: (prop: UIDLStaticValue | UIDLExpressionValue) => types.Identifier | types.StringLiteral | types.NumericLiteral | types.BooleanLiteral | types.ObjectExpression | types.Expression;

@@ -51,0 +52,0 @@ export declare const getExpressionFromUIDLExpressionNode: (node: UIDLExpressionValue) => types.Expression;

@@ -15,3 +15,2 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

import babelPresetReact from '@babel/preset-react';
import { ASTUtils } from '..';
/**

@@ -368,5 +367,4 @@ * Adds a class definition string to an existing string of classes

export var generateRemoteResourceASTs = function (resource) {
var _a, _b;
var _a, _b, _c;
var fetchUrl = computeFetchUrl(resource);
var authHeaderAST = computeAuthorizationHeaderAST(resource === null || resource === void 0 ? void 0 : resource.headers);
var headersASTs = (resource === null || resource === void 0 ? void 0 : resource.headers) ? generateRESTHeadersAST(resource.headers) : [];

@@ -383,20 +381,4 @@ var queryParams = generateURLParamsAST(resource === null || resource === void 0 ? void 0 : resource.params);

}
var paramsDeclerations = Object.keys((resource === null || resource === void 0 ? void 0 : resource.params) || {}).reduce(function (acc, item) {
var prop = resource.params[item];
if (prop.type === 'static') {
acc.push(types.objectProperty(types.stringLiteral(item), ASTUtils.resolveObjectValue(prop)));
}
if (prop.type === 'expr') {
acc.push(types.objectProperty(types.stringLiteral(item), ASTUtils.getExpressionFromUIDLExpressionNode(prop)));
}
if (prop.type === 'dynamic') {
acc.push(types.spreadElement(types.logicalExpression('&&', types.memberExpression(types.identifier('params'), types.stringLiteral(prop.content.id), true, false), types.objectExpression([
types.objectProperty(types.stringLiteral(item), types.memberExpression(types.identifier('params'), types.stringLiteral(prop.content.id), true, false)),
]))));
}
return acc;
}, []);
var paramsAST = types.variableDeclaration('const', [
types.variableDeclarator(types.identifier('urlParams'), types.objectExpression(paramsDeclerations)),
]);
var urlParamsDecleration = generateParamsAST(resource === null || resource === void 0 ? void 0 : resource.params);
var bodyParamsDecleration = generateParamsAST(resource === null || resource === void 0 ? void 0 : resource.body);
var url = (queryParams === null || queryParams === void 0 ? void 0 : queryParams.quasis)

@@ -407,4 +389,4 @@ ? types.templateLiteral(__spreadArray(__spreadArray([], fetchUrlQuasis, true), queryParamsQuasis, true), __spreadArray([], fetchUrl.expressions.concat(queryParams.expressions), true))

var allHeaders = [];
if (authHeaderAST) {
allHeaders.push(authHeaderAST);
if ((_a = resource === null || resource === void 0 ? void 0 : resource.headers) === null || _a === void 0 ? void 0 : _a.authToken) {
allHeaders.push(computeAuthorizationHeaderAST(resource === null || resource === void 0 ? void 0 : resource.headers));
}

@@ -414,10 +396,19 @@ if (headersASTs.length) {

}
var headers = types.objectProperty(types.identifier('headers'), types.objectExpression(allHeaders));
var fetchAST = types.variableDeclaration('const', [
types.variableDeclarator(types.identifier('data'), types.awaitExpression(types.callExpression(types.identifier('fetch'), [
url,
types.objectExpression([method, headers]),
types.objectExpression(__spreadArray(__spreadArray([
method
], (allHeaders.length > 0
? [
types.objectProperty(types.identifier('headers'), types.objectExpression(allHeaders)),
]
: []), true), (bodyParamsDecleration.length > 0 && (resource === null || resource === void 0 ? void 0 : resource.method) === 'POST'
? [
types.objectProperty(types.identifier('body'), types.callExpression(types.memberExpression(types.identifier('JSON'), types.identifier('stringify')), [types.identifier('bodyParams')])),
]
: []), true)),
]))),
]);
var responseType = (_b = (_a = resource === null || resource === void 0 ? void 0 : resource.response) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : 'json';
var responseType = (_c = (_b = resource === null || resource === void 0 ? void 0 : resource.response) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'json';
var responseJSONAST;

@@ -462,4 +453,36 @@ /**

}
return [paramsAST, fetchAST, responseJSONAST];
return __spreadArray(__spreadArray(__spreadArray([], (urlParamsDecleration.length > 0
? [
types.variableDeclaration('const', [
types.variableDeclarator(types.identifier('urlParams'), types.objectExpression(urlParamsDecleration)),
]),
]
: []), true), (bodyParamsDecleration.length > 0
? [
types.variableDeclaration('const', [
types.variableDeclarator(types.identifier('bodyParams'), types.objectExpression(bodyParamsDecleration)),
]),
]
: []), true), [
fetchAST,
responseJSONAST,
], false);
};
var generateParamsAST = function (props) {
return Object.keys(props || {}).reduce(function (acc, item) {
var prop = props[item];
if (prop.type === 'static') {
acc.push(types.objectProperty(types.stringLiteral(item), resolveObjectValue(prop)));
}
if (prop.type === 'expr') {
acc.push(types.objectProperty(types.stringLiteral(item), getExpressionFromUIDLExpressionNode(prop)));
}
if (prop.type === 'dynamic') {
acc.push(types.spreadElement(types.logicalExpression('&&', types.memberExpression(types.identifier('params'), types.stringLiteral(prop.content.id), true, false), types.objectExpression([
types.objectProperty(types.stringLiteral(item), types.memberExpression(types.identifier('params'), types.stringLiteral(prop.content.id), true, false)),
]))));
}
return acc;
}, []);
};
var generateRESTHeadersAST = function (headers) {

@@ -560,3 +583,3 @@ return Object.keys(headers)

};
var computeFetchUrl = function (resource) {
export var computeFetchUrl = function (resource) {
var _a, _b;

@@ -563,0 +586,0 @@ var path = resource.path;

{
"name": "@teleporthq/teleport-plugin-common",
"version": "0.32.0",
"version": "0.32.3",
"description": "Common building and modelating functions for ASTs and HASTs",

@@ -30,8 +30,8 @@ "author": "teleportHQ",

"@babel/types": "^7.5.5",
"@teleporthq/teleport-shared": "^0.32.0",
"@teleporthq/teleport-types": "^0.32.0",
"@teleporthq/teleport-shared": "^0.32.3",
"@teleporthq/teleport-types": "^0.32.3",
"jss": "^10.0.0",
"jss-preset-default": "^10.0.0"
},
"gitHead": "08e6b6b0a6328cdbf86891871be39a377450a084"
"gitHead": "891708b576d816bfd3d47c8d894f64f654ccc903"
}

@@ -17,3 +17,2 @@ import * as types from '@babel/types'

import babelPresetReact from '@babel/preset-react'
import { ASTUtils } from '..'

@@ -562,5 +561,3 @@ /**

const fetchUrl = computeFetchUrl(resource)
const authHeaderAST = computeAuthorizationHeaderAST(resource?.headers)
const headersASTs = resource?.headers ? generateRESTHeadersAST(resource.headers) : []
const queryParams = generateURLParamsAST(resource?.params)

@@ -580,56 +577,4 @@ const fetchUrlQuasis = fetchUrl.quasis

const paramsDeclerations: Array<types.ObjectProperty | types.SpreadElement> = Object.keys(
resource?.params || {}
).reduce((acc: Array<types.ObjectProperty | types.SpreadElement>, item) => {
const prop = resource.params[item]
if (prop.type === 'static') {
acc.push(types.objectProperty(types.stringLiteral(item), ASTUtils.resolveObjectValue(prop)))
}
if (prop.type === 'expr') {
acc.push(
types.objectProperty(
types.stringLiteral(item),
ASTUtils.getExpressionFromUIDLExpressionNode(prop)
)
)
}
if (prop.type === 'dynamic') {
acc.push(
types.spreadElement(
types.logicalExpression(
'&&',
types.memberExpression(
types.identifier('params'),
types.stringLiteral(prop.content.id),
true,
false
),
types.objectExpression([
types.objectProperty(
types.stringLiteral(item),
types.memberExpression(
types.identifier('params'),
types.stringLiteral(prop.content.id),
true,
false
)
),
])
)
)
)
}
return acc
}, [])
const paramsAST = types.variableDeclaration('const', [
types.variableDeclarator(
types.identifier('urlParams'),
types.objectExpression(paramsDeclerations)
),
])
const urlParamsDecleration = generateParamsAST(resource?.params)
const bodyParamsDecleration = generateParamsAST(resource?.body)
const url = queryParams?.quasis

@@ -649,4 +594,4 @@ ? types.templateLiteral(

if (authHeaderAST) {
allHeaders.push(authHeaderAST)
if (resource?.headers?.authToken) {
allHeaders.push(computeAuthorizationHeaderAST(resource?.headers))
}

@@ -658,7 +603,2 @@

const headers = types.objectProperty(
types.identifier('headers'),
types.objectExpression(allHeaders)
)
const fetchAST = types.variableDeclaration('const', [

@@ -670,3 +610,27 @@ types.variableDeclarator(

url,
types.objectExpression([method, headers]),
types.objectExpression([
method,
...(allHeaders.length > 0
? [
types.objectProperty(
types.identifier('headers'),
types.objectExpression(allHeaders)
),
]
: []),
...(bodyParamsDecleration.length > 0 && resource?.method === 'POST'
? [
types.objectProperty(
types.identifier('body'),
types.callExpression(
types.memberExpression(
types.identifier('JSON'),
types.identifier('stringify')
),
[types.identifier('bodyParams')]
)
),
]
: []),
]),
])

@@ -743,5 +707,77 @@ )

return [paramsAST, fetchAST, responseJSONAST]
return [
...(urlParamsDecleration.length > 0
? [
types.variableDeclaration('const', [
types.variableDeclarator(
types.identifier('urlParams'),
types.objectExpression(urlParamsDecleration)
),
]),
]
: []),
...(bodyParamsDecleration.length > 0
? [
types.variableDeclaration('const', [
types.variableDeclarator(
types.identifier('bodyParams'),
types.objectExpression(bodyParamsDecleration)
),
]),
]
: []),
fetchAST,
responseJSONAST,
]
}
const generateParamsAST = (
props: Record<string, UIDLStaticValue | UIDLPropValue | UIDLStateValue | UIDLExpressionValue>
): Array<types.ObjectProperty | types.SpreadElement> => {
return Object.keys(props || {}).reduce(
(acc: Array<types.ObjectProperty | types.SpreadElement>, item) => {
const prop = props[item]
if (prop.type === 'static') {
acc.push(types.objectProperty(types.stringLiteral(item), resolveObjectValue(prop)))
}
if (prop.type === 'expr') {
acc.push(
types.objectProperty(types.stringLiteral(item), getExpressionFromUIDLExpressionNode(prop))
)
}
if (prop.type === 'dynamic') {
acc.push(
types.spreadElement(
types.logicalExpression(
'&&',
types.memberExpression(
types.identifier('params'),
types.stringLiteral(prop.content.id),
true,
false
),
types.objectExpression([
types.objectProperty(
types.stringLiteral(item),
types.memberExpression(
types.identifier('params'),
types.stringLiteral(prop.content.id),
true,
false
)
),
])
)
)
)
}
return acc
},
[]
)
}
const generateRESTHeadersAST = (headers: UIDLResourceItem['headers']): types.ObjectProperty[] => {

@@ -910,3 +946,3 @@ return Object.keys(headers)

const computeFetchUrl = (resource: UIDLResourceItem) => {
export const computeFetchUrl = (resource: UIDLResourceItem) => {
const { path } = resource

@@ -913,0 +949,0 @@ const fetchBaseUrl = resolveResourceValue(path.baseUrl)

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

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