Socket
Socket
Sign inDemoInstall

@serenity-js/rest

Package Overview
Dependencies
Maintainers
1
Versions
360
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serenity-js/rest - npm Package Compare versions

Comparing version 3.19.0 to 3.20.0

lib/io/axiosProxyOverridesFor.d.ts

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [3.20.0](https://github.com/serenity-js/serenity-js/compare/v3.19.0...v3.20.0) (2024-03-02)
### Features
* **rest:** createAxios function instantiates axios with HTTP proxy support ([c453678](https://github.com/serenity-js/serenity-js/commit/c4536784c0bd9e77826563b944904fb862c43c83))
# [3.19.0](https://github.com/serenity-js/serenity-js/compare/v3.18.1...v3.19.0) (2024-03-01)

@@ -8,0 +19,0 @@

1

lib/index.d.ts

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

export * from './io';
export * from './screenplay';
//# sourceMappingURL=index.d.ts.map

@@ -17,3 +17,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./io"), exports);
__exportStar(require("./screenplay"), exports);
//# sourceMappingURL=index.js.map

16

lib/screenplay/abilities/CallAnApi.d.ts
/// <reference types="node" />
import { Ability } from '@serenity-js/core';
import { type AxiosDefaults, type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';
import type { AxiosRequestConfigDefaults } from './AxiosRequestConfigDefaults';
import type { AxiosRequestConfigDefaults } from '../../io';
/**

@@ -140,10 +140,9 @@ * An {@apilink Ability} that wraps [axios client](https://axios-http.com/docs/api_intro) and enables

* import { actorCalled } from '@serenity-js/core'
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { createAxios, CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { Ensure, equals } from '@serenity-js/assertions'
*
* import axios from 'axios'
* import axiosRetry from 'axios-retry'
*
* const instance = axios.create({ baseURL 'https://api.example.org/' })
* axiosRetry(axios, { retries: 3 })
* const instance = createAxios({ baseURL 'https://api.example.org/' })
* axiosRetry(instance, { retries: 3 })
*

@@ -171,7 +170,7 @@ * await actorCalled('Apisitt')

*
* import axios from 'axios'
* import { axiosCreate } from '@serenity-js/rest'
* import axiosRetry from 'axios-retry'
*
* const instance = axios.create({ baseURL 'https://api.example.org/' })
* axiosRetry(axios, { retries: 3 })
* const instance = axiosCreate({ baseURL 'https://api.example.org/' })
* axiosRetry(instance, { retries: 3 })
*

@@ -320,3 +319,2 @@ * await actorCalled('Apisitt')

private lastResponse;
private static readonly defaults;
/**

@@ -323,0 +321,0 @@ * Produces an {@apilink Ability|ability} to call a REST API at a specified `baseURL`;

"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CallAnApi = void 0;
const core_1 = require("@serenity-js/core");
const axios_1 = __importStar(require("axios"));
const proxy_1 = require("./proxy");
const io_1 = require("../../io");
/**

@@ -165,10 +141,9 @@ * An {@apilink Ability} that wraps [axios client](https://axios-http.com/docs/api_intro) and enables

* import { actorCalled } from '@serenity-js/core'
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { createAxios, CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { Ensure, equals } from '@serenity-js/assertions'
*
* import axios from 'axios'
* import axiosRetry from 'axios-retry'
*
* const instance = axios.create({ baseURL 'https://api.example.org/' })
* axiosRetry(axios, { retries: 3 })
* const instance = createAxios({ baseURL 'https://api.example.org/' })
* axiosRetry(instance, { retries: 3 })
*

@@ -196,7 +171,7 @@ * await actorCalled('Apisitt')

*
* import axios from 'axios'
* import { axiosCreate } from '@serenity-js/rest'
* import axiosRetry from 'axios-retry'
*
* const instance = axios.create({ baseURL 'https://api.example.org/' })
* axiosRetry(axios, { retries: 3 })
* const instance = axiosCreate({ baseURL 'https://api.example.org/' })
* axiosRetry(instance, { retries: 3 })
*

@@ -345,5 +320,2 @@ * await actorCalled('Apisitt')

lastResponse;
static defaults = {
timeout: core_1.Duration.ofSeconds(10).inMilliseconds(),
};
/**

@@ -381,17 +353,3 @@ * Produces an {@apilink Ability|ability} to call a REST API at a specified `baseURL`;

static using(axiosInstanceOrConfig) {
const axiosInstanceGiven = isAxiosInstance(axiosInstanceOrConfig);
const axiosInstance = axiosInstanceGiven
? axiosInstanceOrConfig
: axios_1.default.create({
...CallAnApi.defaults,
...omit(axiosInstanceOrConfig, 'proxy'),
});
const proxyConfig = axiosInstanceGiven
? axiosInstanceOrConfig.defaults.proxy
: axiosInstanceOrConfig.proxy;
const proxyOverrides = (0, proxy_1.axiosProxyOverridesFor)({
...axiosInstance.defaults,
proxy: proxyConfig || undefined,
});
return new CallAnApi(withOverrides(axiosInstance, proxyOverrides));
return new CallAnApi((0, io_1.createAxios)(axiosInstanceOrConfig));
}

@@ -493,16 +451,2 @@ /**

exports.CallAnApi = CallAnApi;
function isAxiosInstance(axiosInstanceOrConfig) {
return axiosInstanceOrConfig
&& (axiosInstanceOrConfig instanceof axios_1.Axios || axiosInstanceOrConfig.defaults);
}
function withOverrides(axiosInstance, overrides) {
for (const [key, override] of Object.entries(overrides)) {
axiosInstance.defaults[key] = override;
}
return axiosInstance;
}
function omit(record, key) {
const { [key]: omitted_, ...rest } = record;
return rest;
}
//# sourceMappingURL=CallAnApi.js.map

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

export * from './AxiosRequestConfigDefaults';
export * from './CallAnApi';
//# sourceMappingURL=index.d.ts.map

@@ -17,4 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./AxiosRequestConfigDefaults"), exports);
__exportStar(require("./CallAnApi"), exports);
//# sourceMappingURL=index.js.map

@@ -12,3 +12,3 @@ import type { Answerable } from '@serenity-js/core';

* import { By Navigate, PageElement, Text } from '@serenity-js/web';
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { axiosCreate, CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { Ensure, equals } from '@serenity-js/assertions';

@@ -29,3 +29,3 @@ *

* // Note: no default base URL is given when the axios instance is created
* CallAnApi.using(axios.create()),
* CallAnApi.using(axiosCreate()),
* )

@@ -32,0 +32,0 @@ * .attemptsTo(

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

* import { By Navigate, PageElement, Text } from '@serenity-js/web';
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { axiosCreate, CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { Ensure, equals } from '@serenity-js/assertions';

@@ -33,3 +33,3 @@ *

* // Note: no default base URL is given when the axios instance is created
* CallAnApi.using(axios.create()),
* CallAnApi.using(axiosCreate()),
* )

@@ -36,0 +36,0 @@ * .attemptsTo(

{
"name": "@serenity-js/rest",
"version": "3.19.0",
"version": "3.20.0",
"description": "Test REST APIs with Serenity/JS",

@@ -49,3 +49,3 @@ "author": {

"dependencies": {
"@serenity-js/core": "3.19.0",
"@serenity-js/core": "3.20.0",
"agent-base": "7.1.0",

@@ -60,3 +60,3 @@ "axios": "1.6.7",

"@integration/testing-tools": "3.0.0",
"@serenity-js/assertions": "3.19.0",
"@serenity-js/assertions": "3.20.0",
"@types/chai": "4.3.12",

@@ -71,3 +71,3 @@ "@types/mocha": "10.0.6",

},
"gitHead": "6bc255b85d3e74d000b1584a64e460cc5adc1e23"
"gitHead": "2089afc60adb2751416fa6d800d4e7af95a99f25"
}

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

export * from './io';
export * from './screenplay';

@@ -1,4 +0,3 @@

import { Ability, ConfigurationError, Duration, LogicError, TestCompromisedError } from '@serenity-js/core';
import axios, {
Axios,
import { Ability, ConfigurationError, LogicError, TestCompromisedError } from '@serenity-js/core';
import {
type AxiosDefaults,

@@ -9,7 +8,6 @@ type AxiosError,

type AxiosResponse,
type CreateAxiosDefaults,
} from 'axios';
import type { AxiosRequestConfigDefaults, AxiosRequestConfigProxyDefaults } from './AxiosRequestConfigDefaults';
import { axiosProxyOverridesFor } from './proxy';
import type { AxiosRequestConfigDefaults} from '../../io';
import { createAxios } from '../../io';

@@ -151,10 +149,9 @@ /**

* import { actorCalled } from '@serenity-js/core'
* import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { createAxios, CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { Ensure, equals } from '@serenity-js/assertions'
*
* import axios from 'axios'
* import axiosRetry from 'axios-retry'
*
* const instance = axios.create({ baseURL 'https://api.example.org/' })
* axiosRetry(axios, { retries: 3 })
* const instance = createAxios({ baseURL 'https://api.example.org/' })
* axiosRetry(instance, { retries: 3 })
*

@@ -182,7 +179,7 @@ * await actorCalled('Apisitt')

*
* import axios from 'axios'
* import { axiosCreate } from '@serenity-js/rest'
* import axiosRetry from 'axios-retry'
*
* const instance = axios.create({ baseURL 'https://api.example.org/' })
* axiosRetry(axios, { retries: 3 })
* const instance = axiosCreate({ baseURL 'https://api.example.org/' })
* axiosRetry(instance, { retries: 3 })
*

@@ -332,6 +329,2 @@ * await actorCalled('Apisitt')

private static readonly defaults: CreateAxiosDefaults<any> = {
timeout: Duration.ofSeconds(10).inMilliseconds(),
};
/**

@@ -370,22 +363,3 @@ * Produces an {@apilink Ability|ability} to call a REST API at a specified `baseURL`;

static using(axiosInstanceOrConfig: AxiosInstance | AxiosRequestConfigDefaults): CallAnApi {
const axiosInstanceGiven = isAxiosInstance(axiosInstanceOrConfig);
const axiosInstance = axiosInstanceGiven
? axiosInstanceOrConfig
: axios.create({
...CallAnApi.defaults,
...omit(axiosInstanceOrConfig, 'proxy'),
});
const proxyConfig: AxiosRequestConfigProxyDefaults | false | undefined = axiosInstanceGiven
? axiosInstanceOrConfig.defaults.proxy
: axiosInstanceOrConfig.proxy;
const proxyOverrides = axiosProxyOverridesFor({
...axiosInstance.defaults,
proxy: proxyConfig || undefined,
});
return new CallAnApi(withOverrides(axiosInstance, proxyOverrides));
return new CallAnApi(createAxios(axiosInstanceOrConfig));
}

@@ -496,19 +470,1 @@

}
function isAxiosInstance(axiosInstanceOrConfig: any): axiosInstanceOrConfig is AxiosInstance {
return axiosInstanceOrConfig
&& (axiosInstanceOrConfig instanceof Axios || axiosInstanceOrConfig.defaults);
}
function withOverrides<Data = any>(axiosInstance: AxiosInstance, overrides: AxiosRequestConfig<Data>): AxiosInstance {
for (const [key, override] of Object.entries(overrides)) {
axiosInstance.defaults[key] = override;
}
return axiosInstance;
}
function omit<T extends object, K extends keyof T>(record: T, key: K): Omit<T, K> {
const { [key]: omitted_, ...rest } = record;
return rest;
}

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

export * from './AxiosRequestConfigDefaults';
export * from './CallAnApi';

@@ -16,3 +16,3 @@ import type { Answerable, AnswersQuestions, CollectsArtifacts, UsesAbilities } from '@serenity-js/core';

* import { By Navigate, PageElement, Text } from '@serenity-js/web';
* import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { axiosCreate, CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
* import { Ensure, equals } from '@serenity-js/assertions';

@@ -33,3 +33,3 @@ *

* // Note: no default base URL is given when the axios instance is created
* CallAnApi.using(axios.create()),
* CallAnApi.using(axiosCreate()),
* )

@@ -36,0 +36,0 @@ * .attemptsTo(

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