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

@stepci/runner

Package Overview
Dependencies
Maintainers
1
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stepci/runner - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

97

dist/index.js
"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 __importDefault = (this && this.__importDefault) || function (mod) {

@@ -9,4 +32,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const mustache_1 = __importDefault(require("mustache"));
const xpath_1 = __importDefault(require("xpath"));
const form_data_1 = __importDefault(require("form-data"));
const cheerio = __importStar(require("cheerio"));
const jsonpath_plus_1 = require("jsonpath-plus");
const xpath_1 = __importDefault(require("xpath"));
const xmldom_1 = require("xmldom");

@@ -71,3 +96,3 @@ // Matchers

name: step.name,
checks: [],
checks: {},
timestamp: Date.now()

@@ -78,3 +103,2 @@ };

stepResult.passed = false;
stepResult.passed = false;
stepResult.failReason = 'Step was skipped because previous one failed';

@@ -85,18 +109,35 @@ stepResult.skipped = true;

stepResult.passed = true;
// Parse template
step = JSON.parse(mustache_1.default.render(JSON.stringify(step), { captures, env: workflow.env, ...options }));
// GraphQL
if (step.graphql) {
step.body = JSON.stringify(step.graphql);
}
// Form Data
if (step.form) {
const formData = new URLSearchParams();
for (const key in step.form) {
formData.append(key, step.form[key]);
try {
// Parse template
step = JSON.parse(mustache_1.default.render(JSON.stringify(step), { captures, env: workflow.env, ...options }));
let requestBody = undefined;
// Body
if (step.body) {
requestBody = step.body;
}
step.body = formData.toString();
}
try {
const res = await (0, node_fetch_1.default)(step.url, { method: step.method, headers: step.headers, body: step.body || undefined });
// JSON
if (step.json) {
requestBody = JSON.stringify(step.json);
}
// GraphQL
if (step.graphql) {
requestBody = JSON.stringify(step.graphql);
}
// Form Data
if (step.form) {
const formData = new URLSearchParams();
for (const key in step.form) {
formData.append(key, step.form[key]);
}
requestBody = formData.toString();
}
// Multipart Form Data
if (step.formData) {
const formData = new form_data_1.default();
for (const key in step.form) {
formData.append(key, step.form[key]);
}
requestBody = formData;
}
const res = await (0, node_fetch_1.default)(step.url, { method: step.method, headers: step.headers, body: requestBody });
const body = await res.text();

@@ -130,3 +171,2 @@ const duration = Date.now() - stepResult.timestamp;

if (step.check) {
stepResult.checks = {};
// Check headers

@@ -163,2 +203,3 @@ if (step.check.headers) {

const json = JSON.parse(body);
stepResult.checks.jsonpath = {};
for (const path in step.check.jsonpath) {

@@ -179,2 +220,3 @@ const result = (0, jsonpath_plus_1.JSONPath)({ path, json });

if (step.check.xpath) {
stepResult.checks.xpath = {};
for (const path in step.check.xpath) {

@@ -194,2 +236,19 @@ const dom = new xmldom_1.DOMParser().parseFromString(body);

}
// Check HTML5 Selector
if (step.check.selector) {
stepResult.checks.selector = {};
const dom = cheerio.load(body);
for (const selector in step.check.selector) {
const result = dom(selector).html();
stepResult.checks.selector[selector] = {
expected: step.check.selector[selector],
given: result,
passed: check(result, step.check.selector[selector])
};
if (!stepResult.checks.selector[selector].passed) {
workflowResult.passed = false;
stepResult.passed = false;
}
}
}
// Check status

@@ -196,0 +255,0 @@ if (step.check.status) {

4

package.json
{
"name": "@stepci/runner",
"version": "0.1.4",
"version": "0.1.5",
"description": "Step CI Runner",

@@ -28,2 +28,4 @@ "main": "dist/index.js",

"dependencies": {
"cheerio": "^1.0.0-rc.12",
"form-data": "^4.0.0",
"jsonpath-plus": "^7.2.0",

@@ -30,0 +32,0 @@ "mustache": "^4.2.0",

import fetch from 'node-fetch'
import mustache from 'mustache'
import xpath from 'xpath'
import FormData from 'form-data'
import * as cheerio from 'cheerio'
import { JSONPath } from 'jsonpath-plus'
import xpath from 'xpath'
import { DOMParser } from 'xmldom'

@@ -22,2 +24,4 @@

form?: WorkflowStepForm
formData?: WorkflowStepForm
json?: any
graphql?: WorkflowStepGraphQL

@@ -60,2 +64,3 @@ captures?: WorkflowStepCaptures[]

xpath?: WorkflowStepCheckXPath | WorkflowStepCheckMatcher
selector?: WorkflowStepCheckSelector | WorkflowStepCheckMatcher
}

@@ -75,2 +80,6 @@

type WorkflowStepCheckSelector = {
[key: string]: string
}
type WorkflowStepCheckMatcher = {

@@ -109,3 +118,3 @@ [key: string]: WorkflowMatcher[]

name: string
checks: WorkflowResultCheck | any
checks: WorkflowResultCheck
failed?: boolean

@@ -136,2 +145,3 @@ failReason?: string

xpath?: WorkflowResultCheckXPath
selector?: WorkflowResultCheckSelector
status?: WorkflowResultCheckResponse

@@ -155,2 +165,6 @@ statusText?: WorkflowResultCheckResponse

type WorkflowResultCheckSelector = {
[key: string]: WorkflowResultCheckResponse
}
type WorkflowResultCheckResponse = {

@@ -209,3 +223,3 @@ expected: any

name: step.name,
checks: [],
checks: {},
timestamp: Date.now()

@@ -217,3 +231,2 @@ }

stepResult.passed = false
stepResult.passed = false
stepResult.failReason = 'Step was skipped because previous one failed'

@@ -223,23 +236,43 @@ stepResult.skipped = true

stepResult.passed = true
try {
// Parse template
step = JSON.parse(mustache.render(JSON.stringify(step), { captures, env: workflow.env, ...options }))
let requestBody: string | FormData | undefined = undefined
// Parse template
step = JSON.parse(mustache.render(JSON.stringify(step), { captures, env: workflow.env, ...options }))
// Body
if (step.body) {
requestBody = step.body
}
// GraphQL
if (step.graphql) {
step.body = JSON.stringify(step.graphql)
}
// JSON
if (step.json) {
requestBody = JSON.stringify(step.json)
}
// Form Data
if (step.form) {
const formData = new URLSearchParams()
for (const key in step.form) {
formData.append(key, step.form[key])
// GraphQL
if (step.graphql) {
requestBody = JSON.stringify(step.graphql)
}
step.body = formData.toString()
}
// Form Data
if (step.form) {
const formData = new URLSearchParams()
for (const key in step.form) {
formData.append(key, step.form[key])
}
try {
const res = await fetch(step.url, { method: step.method, headers: step.headers, body: step.body || undefined })
requestBody = formData.toString()
}
// Multipart Form Data
if (step.formData) {
const formData = new FormData()
for (const key in step.form) {
formData.append(key, step.form[key])
}
requestBody = formData
}
const res = await fetch(step.url, { method: step.method, headers: step.headers, body: requestBody })
const body = await res.text()

@@ -279,4 +312,2 @@ const duration = Date.now() - stepResult.timestamp

if (step.check) {
stepResult.checks = {}
// Check headers

@@ -318,5 +349,7 @@ if (step.check.headers){

const json = JSON.parse(body)
stepResult.checks.jsonpath = {}
for (const path in step.check.jsonpath) {
const result = JSONPath({ path, json })
stepResult.checks.jsonpath[path] = {

@@ -337,2 +370,4 @@ expected: step.check?.jsonpath[path],

if (step.check.xpath) {
stepResult.checks.xpath = {}
for (const path in step.check.xpath) {

@@ -347,2 +382,3 @@ const dom = new DOMParser().parseFromString(body)

}
if (!stepResult.checks.xpath[path].passed) {

@@ -355,2 +391,23 @@ workflowResult.passed = false

// Check HTML5 Selector
if (step.check.selector) {
stepResult.checks.selector = {}
const dom = cheerio.load(body)
for (const selector in step.check.selector) {
const result = dom(selector).html()
stepResult.checks.selector[selector] = {
expected: step.check.selector[selector],
given: result,
passed: check(result, step.check.selector[selector])
}
if (!stepResult.checks.selector[selector].passed) {
workflowResult.passed = false
stepResult.passed = false
}
}
}
// Check status

@@ -357,0 +414,0 @@ if (step.check.status) {

@@ -15,5 +15,5 @@ import { run } from '../src/index'

"check": {
"status": [{
"eq": 200
}]
"selector": {
"title": "Example Domain"
}
}

@@ -20,0 +20,0 @@ }]

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