@elasticpath/component-test-framework 1.4.33 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.js +40 -4
- package/lib/api.js.map +1 -1
- package/lib/elasticsearch.js +34 -1
- package/lib/elasticsearch.js.map +1 -1
- package/lib/index.js +7 -4
- package/lib/index.js.map +1 -1
- package/lib/mongodb.js +34 -1
- package/lib/mongodb.js.map +1 -1
- package/lib/utils.js +35 -2
- package/lib/utils.js.map +1 -1
- package/package.json +19 -19
package/lib/api.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,12 +41,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
42
|
});
|
|
10
43
|
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
11
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const axios_1 = require("axios");
|
|
13
|
-
const AxiosLogger = require("axios-logger");
|
|
48
|
+
const axios_1 = __importDefault(require("axios"));
|
|
49
|
+
const AxiosLogger = __importStar(require("axios-logger"));
|
|
14
50
|
const chai_1 = require("chai");
|
|
15
|
-
const resource_store_1 = require("./resource_store");
|
|
16
|
-
const Logger = require("./logger");
|
|
51
|
+
const resource_store_1 = __importDefault(require("./resource_store"));
|
|
52
|
+
const Logger = __importStar(require("./logger"));
|
|
17
53
|
const utils_1 = require("./utils");
|
|
18
54
|
class Api {
|
|
19
55
|
constructor() {
|
package/lib/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAAuH;AACvH,4CAA2C;AAE3C,+BAA6B;AAG7B,qDAA4C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,WAAW,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,CACvG,CAAA;YAED,IAAI,CAAA,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,0CAAE,MAAM,MAAK,SAAS,EAAE,CAAC;gBAC/C,MAAM,CAAC,KAAK,CAAC,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,0CAAE,MAAM,CAAC,CAAA;YAC5C,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;IAED,kDAAkD;IAC1C,OAAO,CAAC,QAAuB;QACrC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpC,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;aAAM,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAED,kBAAe,GAAG,CAAA","sourcesContent":["import Axios, { AxiosInstance, AxiosError, AxiosResponse, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios'\nimport * as AxiosLogger from 'axios-logger'\nimport * as FormData from 'form-data'\nimport { expect } from 'chai'\n\nimport { ApiPayload, ApiResponse, ApiArrayResponse, Error, V2Response, V3Response } from './api.interfaces'\nimport ResourceStore from './resource_store'\nimport * as Logger from './logger'\nimport { nullOrValue } from './utils'\n\nclass Api {\n public axiosInstance: AxiosInstance\n\n private axiosResponseObject: AxiosResponse | AxiosError\n\n private requestPath: string\n\n private requestMethod: string\n\n // We can't add this to the interceptors because we sometimes\n // need to overwrite this\n private readonly defaultHeaders: object\n\n private headers: object\n\n private readonly baseUrl: string\n\n public constructor() {\n const { CTF_BASE_URL, CTF_LOGGING_LEVEL } = process.env\n\n this.defaultHeaders = {\n 'content-type': 'application/json',\n }\n this.headers = this.defaultHeaders\n\n this.axiosInstance = Axios.create({\n baseURL: CTF_BASE_URL,\n timeout: 4000,\n timeoutErrorMessage: `[Fail] Api request timed out. Is the service running on ${CTF_BASE_URL}`,\n })\n\n this.axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {\n // eslint-disable-next-line no-param-reassign\n config.headers.accept = 'application/json'\n return config\n })\n\n if (CTF_LOGGING_LEVEL === 'debug') {\n this.axiosInstance.interceptors.request.use((internalrequest: InternalAxiosRequestConfig) => {\n const { headers } = internalrequest\n const request: AxiosRequestConfig = {\n ...internalrequest,\n }\n const logrequest = AxiosLogger.requestLogger(request as any)\n return {\n ...logrequest,\n headers,\n }\n }, AxiosLogger.errorLogger)\n this.axiosInstance.interceptors.response.use(AxiosLogger.responseLogger)\n }\n\n this.baseUrl = CTF_BASE_URL\n }\n\n private isError(response): response is AxiosError {\n return (<AxiosError>this.axiosResponseObject).isAxiosError !== undefined\n }\n\n public isV3Response(data: V2Response | V3Response): data is V3Response {\n if (this.isError(this.axiosResponseObject)) {\n return false\n }\n\n return <V3Response>data.attributes !== undefined\n }\n\n public IsV2Response(data: V2Response | V3Response): data is V2Response {\n return !this.isV3Response(data)\n }\n\n public get errors(): Array<Error> | Array<any> {\n // Response data is never an array if there's errors\n if (Array.isArray(this.response.data)) {\n Logger.error('Attempted to access errors on an array response')\n return null\n }\n\n return this.response.data.errors\n }\n\n public get response(): ApiResponse | ApiArrayResponse {\n if (this.isError(this.axiosResponseObject)) {\n return {\n status: this.axiosResponseObject?.response?.status,\n data: this.axiosResponseObject?.response?.data,\n } as ApiResponse\n }\n\n return {\n status: this.axiosResponseObject.status,\n // add everything else from the response\n ...this.axiosResponseObject.data,\n }\n }\n\n public validateUrl(endpoint: string) {\n const regex = /(?<!http:)\\/{2,}/\n const fqURL = `${this.baseUrl}${endpoint}`\n\n if (regex.test(fqURL)) {\n throw new Error(`invalid URL: ${fqURL}`)\n }\n }\n\n public async get(endpoint: string, abortOnError: boolean = true): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'GET'\n\n this.axiosResponseObject = await this.axiosInstance\n .get(endpoint, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n if (!this.isEmpty(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n public async post(\n endpoint: string,\n payload: ApiPayload,\n abortOnError: boolean = true,\n ): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'POST'\n\n this.axiosResponseObject = await this.axiosInstance\n .post(endpoint, payload, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n // Check if there's data to save\n if (this.axiosResponseObject.status !== 204) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n public async form(endpoint: string, form: FormData, abortOnError: boolean = true): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'POST'\n const headers = { ...this.headers, ...form.getHeaders() }\n\n this.axiosResponseObject = await this.axiosInstance\n .post(endpoint, form, { headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n public async put(\n endpoint: string,\n payload: ApiPayload,\n abortOnError: boolean = true,\n ): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'PUT'\n\n this.axiosResponseObject = await this.axiosInstance\n .put(endpoint, payload, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n public async delete(\n endpoint: string,\n payload?: ApiPayload,\n abortOnError: boolean = true,\n ): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'DELETE'\n // For some reason, axios delete requests specify the payload and headers in the same object\n const config = {\n ...payload,\n ...{ headers: this.headers },\n }\n\n this.axiosResponseObject = await this.axiosInstance\n .delete(endpoint, config)\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n // setHeaders will merge the new headers with the current ones, overwriting if\n // the same key exists. The value will use nullOrValue to properly map strings to literals ('null' => null)\n public setHeaders(newHeaders: object, reset: boolean = false, preserveValueType: boolean = false): void {\n if (reset) {\n this.headers = {}\n }\n\n Object.entries(newHeaders).forEach((h) => {\n let value = h[1]\n if (!preserveValueType) {\n value = nullOrValue(value)\n }\n return Object.assign(this.headers, {\n [h[0]]: value,\n })\n })\n }\n\n public deleteHeader(key: string) {\n delete this.headers[key]\n }\n\n private fail(error: AxiosError, abortOnError: boolean): AxiosError {\n if (abortOnError) {\n this.beautifyError(error)\n expect.fail(error.message)\n }\n\n return error\n }\n\n private beautifyError(error: any): void {\n if (error.response) {\n Logger.error(\n `Failed requesting ${this.requestMethod.toUpperCase()} ${process.env.CTF_BASE_URL}${this.requestPath}`,\n )\n\n if (error.response?.data?.errors !== undefined) {\n Logger.error(error.response?.data?.errors)\n }\n } else {\n Logger.error('[FATAL ERROR]', error, '\\n')\n }\n }\n\n // eslint-disable-next-line class-methods-use-this\n private isEmpty(response: AxiosResponse): boolean {\n if (!response.data) {\n return true\n }\n\n if (Array.isArray(response.data.data)) {\n if (response.data.data.length === 0) {\n return true\n }\n } else if (Object.keys(response.data.data).length === 0) {\n return true\n }\n\n return false\n }\n}\n\nexport default Api\n"]}
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAuH;AACvH,0DAA2C;AAE3C,+BAA6B;AAG7B,sEAA4C;AAC5C,iDAAkC;AAClC,mCAAqC;AAErC,MAAM,GAAG;IAiBP;QACE,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;QAEvD,IAAI,CAAC,cAAc,GAAG;YACpB,cAAc,EAAE,kBAAkB;SACnC,CAAA;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,cAAc,CAAA;QAElC,IAAI,CAAC,aAAa,GAAG,eAAK,CAAC,MAAM,CAAC;YAChC,OAAO,EAAE,YAAY;YACrB,OAAO,EAAE,IAAI;YACb,mBAAmB,EAAE,2DAA2D,YAAY,EAAE;SAC/F,CAAC,CAAA;QAEF,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAkC,EAAE,EAAE;YACjF,6CAA6C;YAC7C,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,kBAAkB,CAAA;YAC1C,OAAO,MAAM,CAAA;QACf,CAAC,CAAC,CAAA;QAEF,IAAI,iBAAiB,KAAK,OAAO,EAAE,CAAC;YAClC,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,eAA2C,EAAE,EAAE;gBAC1F,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAA;gBACnC,MAAM,OAAO,qBACR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,MAAM,KAAK,CAAC,EAAE,CAAC;YACxD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAED,kBAAe,GAAG,CAAA","sourcesContent":["import Axios, { AxiosInstance, AxiosError, AxiosResponse, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios'\nimport * as AxiosLogger from 'axios-logger'\nimport * as FormData from 'form-data'\nimport { expect } from 'chai'\n\nimport { ApiPayload, ApiResponse, ApiArrayResponse, Error, V2Response, V3Response } from './api.interfaces'\nimport ResourceStore from './resource_store'\nimport * as Logger from './logger'\nimport { nullOrValue } from './utils'\n\nclass Api {\n public axiosInstance: AxiosInstance\n\n private axiosResponseObject: AxiosResponse | AxiosError\n\n private requestPath: string\n\n private requestMethod: string\n\n // We can't add this to the interceptors because we sometimes\n // need to overwrite this\n private readonly defaultHeaders: object\n\n private headers: object\n\n private readonly baseUrl: string\n\n public constructor() {\n const { CTF_BASE_URL, CTF_LOGGING_LEVEL } = process.env\n\n this.defaultHeaders = {\n 'content-type': 'application/json',\n }\n this.headers = this.defaultHeaders\n\n this.axiosInstance = Axios.create({\n baseURL: CTF_BASE_URL,\n timeout: 4000,\n timeoutErrorMessage: `[Fail] Api request timed out. Is the service running on ${CTF_BASE_URL}`,\n })\n\n this.axiosInstance.interceptors.request.use((config: InternalAxiosRequestConfig) => {\n // eslint-disable-next-line no-param-reassign\n config.headers.accept = 'application/json'\n return config\n })\n\n if (CTF_LOGGING_LEVEL === 'debug') {\n this.axiosInstance.interceptors.request.use((internalrequest: InternalAxiosRequestConfig) => {\n const { headers } = internalrequest\n const request: AxiosRequestConfig = {\n ...internalrequest,\n }\n const logrequest = AxiosLogger.requestLogger(request as any)\n return {\n ...logrequest,\n headers,\n }\n }, AxiosLogger.errorLogger)\n this.axiosInstance.interceptors.response.use(AxiosLogger.responseLogger)\n }\n\n this.baseUrl = CTF_BASE_URL\n }\n\n private isError(response): response is AxiosError {\n return (<AxiosError>this.axiosResponseObject).isAxiosError !== undefined\n }\n\n public isV3Response(data: V2Response | V3Response): data is V3Response {\n if (this.isError(this.axiosResponseObject)) {\n return false\n }\n\n return <V3Response>data.attributes !== undefined\n }\n\n public IsV2Response(data: V2Response | V3Response): data is V2Response {\n return !this.isV3Response(data)\n }\n\n public get errors(): Array<Error> | Array<any> {\n // Response data is never an array if there's errors\n if (Array.isArray(this.response.data)) {\n Logger.error('Attempted to access errors on an array response')\n return null\n }\n\n return this.response.data.errors\n }\n\n public get response(): ApiResponse | ApiArrayResponse {\n if (this.isError(this.axiosResponseObject)) {\n return {\n status: this.axiosResponseObject?.response?.status,\n data: this.axiosResponseObject?.response?.data,\n } as ApiResponse\n }\n\n return {\n status: this.axiosResponseObject.status,\n // add everything else from the response\n ...this.axiosResponseObject.data,\n }\n }\n\n public validateUrl(endpoint: string) {\n const regex = /(?<!http:)\\/{2,}/\n const fqURL = `${this.baseUrl}${endpoint}`\n\n if (regex.test(fqURL)) {\n throw new Error(`invalid URL: ${fqURL}`)\n }\n }\n\n public async get(endpoint: string, abortOnError: boolean = true): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'GET'\n\n this.axiosResponseObject = await this.axiosInstance\n .get(endpoint, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n if (!this.isEmpty(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n public async post(\n endpoint: string,\n payload: ApiPayload,\n abortOnError: boolean = true,\n ): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'POST'\n\n this.axiosResponseObject = await this.axiosInstance\n .post(endpoint, payload, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n // Check if there's data to save\n if (this.axiosResponseObject.status !== 204) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n public async form(endpoint: string, form: FormData, abortOnError: boolean = true): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'POST'\n const headers = { ...this.headers, ...form.getHeaders() }\n\n this.axiosResponseObject = await this.axiosInstance\n .post(endpoint, form, { headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n public async put(\n endpoint: string,\n payload: ApiPayload,\n abortOnError: boolean = true,\n ): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'PUT'\n\n this.axiosResponseObject = await this.axiosInstance\n .put(endpoint, payload, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n public async delete(\n endpoint: string,\n payload?: ApiPayload,\n abortOnError: boolean = true,\n ): Promise<AxiosResponse<any, any>> {\n this.validateUrl(endpoint)\n this.requestPath = endpoint\n this.requestMethod = 'DELETE'\n // For some reason, axios delete requests specify the payload and headers in the same object\n const config = {\n ...payload,\n ...{ headers: this.headers },\n }\n\n this.axiosResponseObject = await this.axiosInstance\n .delete(endpoint, config)\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n return this.axiosResponseObject\n }\n\n return this.axiosResponseObject.response\n }\n\n // setHeaders will merge the new headers with the current ones, overwriting if\n // the same key exists. The value will use nullOrValue to properly map strings to literals ('null' => null)\n public setHeaders(newHeaders: object, reset: boolean = false, preserveValueType: boolean = false): void {\n if (reset) {\n this.headers = {}\n }\n\n Object.entries(newHeaders).forEach((h) => {\n let value = h[1]\n if (!preserveValueType) {\n value = nullOrValue(value)\n }\n return Object.assign(this.headers, {\n [h[0]]: value,\n })\n })\n }\n\n public deleteHeader(key: string) {\n delete this.headers[key]\n }\n\n private fail(error: AxiosError, abortOnError: boolean): AxiosError {\n if (abortOnError) {\n this.beautifyError(error)\n expect.fail(error.message)\n }\n\n return error\n }\n\n private beautifyError(error: any): void {\n if (error.response) {\n Logger.error(\n `Failed requesting ${this.requestMethod.toUpperCase()} ${process.env.CTF_BASE_URL}${this.requestPath}`,\n )\n\n if (error.response?.data?.errors !== undefined) {\n Logger.error(error.response?.data?.errors)\n }\n } else {\n Logger.error('[FATAL ERROR]', error, '\\n')\n }\n }\n\n // eslint-disable-next-line class-methods-use-this\n private isEmpty(response: AxiosResponse): boolean {\n if (!response.data) {\n return true\n }\n\n if (Array.isArray(response.data.data)) {\n if (response.data.data.length === 0) {\n return true\n }\n } else if (Object.keys(response.data.data).length === 0) {\n return true\n }\n\n return false\n }\n}\n\nexport default Api\n"]}
|
package/lib/elasticsearch.js
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
const elasticsearch_1 = require("@elastic/elasticsearch");
|
|
4
|
-
const Logger = require("./logger");
|
|
37
|
+
const Logger = __importStar(require("./logger"));
|
|
5
38
|
class Elasticsearch {
|
|
6
39
|
constructor() {
|
|
7
40
|
if (!process.env.CTF_ELS_URL) {
|
package/lib/elasticsearch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elasticsearch.js","sourceRoot":"","sources":["../src/elasticsearch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"elasticsearch.js","sourceRoot":"","sources":["../src/elasticsearch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA+C;AAC/C,iDAAkC;AAElC,MAAqB,aAAa;IAGhC;QACE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YAC7B,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;YAC9C,MAAM,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAA;YACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAM,CAAC;YAC1B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;SAC9B,CAAC,CAAA;IACJ,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;CACF;AAjBD,gCAiBC","sourcesContent":["import { Client } from '@elastic/elasticsearch'\nimport * as Logger from './logger'\n\nexport default class Elasticsearch {\n private readonly elsClient: Client\n\n public constructor() {\n if (!process.env.CTF_ELS_URL) {\n Logger.error('No Elasticsearch URL specified')\n Logger.error('Please update the .env file to provide an ELS_URL')\n process.exit(1)\n }\n this.elsClient = new Client({\n node: process.env.CTF_ELS_URL,\n })\n }\n\n public get client() {\n return this.elsClient\n }\n}\n"]}
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ResourceStore = exports.Resource = exports.Payload = exports.MongoDB = exports.Api = void 0;
|
|
4
|
-
const api_1 = require("./api");
|
|
7
|
+
const api_1 = __importDefault(require("./api"));
|
|
5
8
|
exports.Api = api_1.default;
|
|
6
|
-
const mongodb_1 = require("./mongodb");
|
|
9
|
+
const mongodb_1 = __importDefault(require("./mongodb"));
|
|
7
10
|
exports.MongoDB = mongodb_1.default;
|
|
8
|
-
const payload_1 = require("./payload");
|
|
11
|
+
const payload_1 = __importDefault(require("./payload"));
|
|
9
12
|
exports.Payload = payload_1.default;
|
|
10
|
-
const resource_store_1 = require("./resource_store");
|
|
13
|
+
const resource_store_1 = __importDefault(require("./resource_store"));
|
|
11
14
|
exports.ResourceStore = resource_store_1.default;
|
|
12
15
|
const resource_1 = require("./resource");
|
|
13
16
|
Object.defineProperty(exports, "Resource", { enumerable: true, get: function () { return resource_1.Resource; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAOd,cAPF,aAAG,CAOE;AANZ,wDAA+B;AAMc,kBANtC,iBAAO,CAMsC;AALpD,wDAA+B;AAKuB,kBAL/C,iBAAO,CAK+C;AAJ7D,sEAA4C;AAI6B,wBAJlE,wBAAa,CAIkE;AAHtF,yCAAqC;AAG0B,yFAHtD,mBAAQ,OAGsD","sourcesContent":["import Api from './api'\nimport MongoDB from './mongodb'\nimport Payload from './payload'\nimport ResourceStore from './resource_store'\nimport { Resource } from './resource'\nimport { ApiResponse, ApiArrayResponse, V2Response, V3Response } from './api.interfaces'\n\nexport { Api, ApiResponse, ApiArrayResponse, MongoDB, Payload, Resource, ResourceStore, V2Response, V3Response }\n"]}
|
package/lib/mongodb.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -10,7 +43,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
43
|
};
|
|
11
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
45
|
const mongodb_1 = require("mongodb");
|
|
13
|
-
const Logger = require("./logger");
|
|
46
|
+
const Logger = __importStar(require("./logger"));
|
|
14
47
|
class MongoDB {
|
|
15
48
|
/**
|
|
16
49
|
* Sets up the MongoDB Client
|
package/lib/mongodb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb.js","sourceRoot":"","sources":["../src/mongodb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mongodb.js","sourceRoot":"","sources":["../src/mongodb.ts"],"names":[],"mappings":";;;;;;;;;;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AAC;IAED;;;OAGG;IACU,KAAK;;YAChB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QAC3B,CAAC;KAAA;CACF;AApDD,0BAoDC","sourcesContent":["import { MongoClient, MongoClientOptions } from 'mongodb'\nimport type { Collection } from 'mongodb'\nimport * as Logger from './logger'\n\nexport default class MongoDB {\n private client: MongoClient\n\n /**\n * Sets up the MongoDB Client\n */\n public constructor() {\n if (!process.env.CTF_MONGO_DSN) {\n Logger.error('No Mongo DSN specified')\n Logger.error('Please update the .env file to provide a MONGO_DSN')\n process.exit(1)\n }\n\n const mongoOptions: MongoClientOptions = {\n serverSelectionTimeoutMS: parseInt(process.env.CTF_MONGO_TIMEOUT, 10) || 4000,\n directConnection: process.env.CTF_MONGO_DIRECT_CONNECTION === 'true',\n }\n\n this.client = new MongoClient(process.env.CTF_MONGO_DSN, mongoOptions)\n }\n\n /**\n * Connects to the Mongo Database.\n */\n public async connect(): Promise<void> {\n await this.client.connect().catch((e) => {\n Logger.error('Could not connect to MongoDB:', e)\n process.exit(1)\n })\n }\n\n /**\n * Returns all MongoDB Collections.\n */\n public async getAllCollections(): Promise<Collection<any>[]> {\n return this.client.db(process.env.CTF_MONGO_DB).collections()\n }\n\n /**\n * Returns a specific Collection.\n */\n public collection(name: string): Collection {\n return this.client.db(process.env.CTF_MONGO_DB).collection(name)\n }\n\n /**\n * Closes the MongoDB connection.\n * @return Promise<void>\n */\n public async close(): Promise<void> {\n await this.client.close()\n }\n}\n"]}
|
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.Capitalize = exports.Pluralize = exports.nullOrValue = void 0;
|
|
4
|
-
const Logger = require("./logger");
|
|
37
|
+
const Logger = __importStar(require("./logger"));
|
|
5
38
|
/*
|
|
6
39
|
Values from the component tests are always strings. Some times we
|
|
7
40
|
want to actually nullify a value. This makes sure any string 'null' is
|
|
@@ -40,7 +73,7 @@ const nullOrValue = (value) => {
|
|
|
40
73
|
try {
|
|
41
74
|
returnValue = JSON.parse(value);
|
|
42
75
|
}
|
|
43
|
-
catch (
|
|
76
|
+
catch (_a) {
|
|
44
77
|
Logger.error('Failed to parse JSON value', value);
|
|
45
78
|
}
|
|
46
79
|
}
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAkC;AAElC;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,KAAU,EAAO,EAAE;IAC7C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACtC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QACtB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,WAAW,GAAG,KAAK,CAAA;IAEvB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,uEAAuE;QACvE,4EAA4E;QAC5E,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;YAChC,OAAO,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;QAC/C,CAAC;QACD,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;YAChC,OAAO,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAA;QAC7C,CAAC;QAED,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACjC,CAAC;YAAC,WAAM,CAAC;gBACP,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAA;YACnD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AA/CY,QAAA,WAAW,eA+CvB;AAEM,MAAM,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE;IAChD,MAAM,QAAQ,GAAG;QACf,SAAS,EAAE,aAAa;KACzB,CAAA;IAED,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;QACzD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IAED,OAAO,GAAG,IAAI,GAAG,CAAA;AACnB,CAAC,CAAA;AAVY,QAAA,SAAS,aAUrB;AAEM,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE,CACjD,IAAI;KACD,KAAK,CAAC,MAAM,CAAC;KACb,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,IAAI,CAAC,EAAE,CAAC,CAAA;AAJA,QAAA,UAAU,cAIV","sourcesContent":["import * as Logger from './logger'\n\n/*\n Values from the component tests are always strings. Some times we\n want to actually nullify a value. This makes sure any string 'null' is\n parsed as literal null as well as some other type conversions\n */\nexport const nullOrValue = (value: any): any => {\n if (value === true || value === false) {\n return value\n }\n\n if (value === 'null') {\n return null\n }\n\n if (value === '\"\"') {\n return ''\n }\n\n if (value === undefined) {\n return undefined\n }\n\n if (value === 'true') {\n return true\n }\n\n if (value === 'false') {\n return false\n }\n\n let returnValue = value\n\n if (typeof value === 'string') {\n // We can't just parseInt the string if it's numeric like \"123\" because\n // a product upc_ean can be numeric but the api expects it as a string still\n if (value.match('<i>') !== null) {\n return parseInt(value.replace('<i>', ''), 10)\n }\n if (value.match('<f>') !== null) {\n return parseFloat(value.replace('<f>', ''))\n }\n\n if (value.match(/^\\[|{/)) {\n try {\n returnValue = JSON.parse(value)\n } catch {\n Logger.error('Failed to parse JSON value', value)\n }\n }\n }\n\n return returnValue\n}\n\nexport const Pluralize = (word: string): string => {\n const oddities = {\n hierarchy: 'hierarchies',\n }\n\n if (Object.prototype.hasOwnProperty.call(oddities, word)) {\n return oddities[word]\n }\n\n return `${word}s`\n}\n\nexport const Capitalize = (word: string): string =>\n word\n .split(/[_-]/)\n .map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`)\n .join('')\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elasticpath/component-test-framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A framework for component tests written using ts-flow",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"directories": {
|
|
@@ -30,36 +30,36 @@
|
|
|
30
30
|
"author": "carl.markham@elasticpath.com",
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@cucumber/cucumber": "^
|
|
34
|
-
"@elastic/elasticsearch": "^
|
|
35
|
-
"@faker-js/faker": "^
|
|
33
|
+
"@cucumber/cucumber": "^11.0.0",
|
|
34
|
+
"@elastic/elasticsearch": "^8.19.0",
|
|
35
|
+
"@faker-js/faker": "^9.0.0",
|
|
36
36
|
"axios": "^1.5.0",
|
|
37
37
|
"axios-logger": "^2.7.0",
|
|
38
|
-
"chai": "^4.
|
|
38
|
+
"chai": "^4.5.0",
|
|
39
39
|
"cucumber-tsflow": "^4.1.1",
|
|
40
|
-
"dotenv": "^
|
|
40
|
+
"dotenv": "^17.0.0",
|
|
41
41
|
"form-data": "^4.0.0",
|
|
42
|
-
"mongodb": "^6.
|
|
43
|
-
"sinon": "^
|
|
42
|
+
"mongodb": "^6.0.0",
|
|
43
|
+
"sinon": "^21.0.0",
|
|
44
44
|
"ts-node": "^10.9.1",
|
|
45
45
|
"typescript": "^5.2.2",
|
|
46
|
-
"uuid": "^
|
|
46
|
+
"uuid": "^13.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/chai": "^4.3.
|
|
49
|
+
"@types/chai": "^4.3.0",
|
|
50
50
|
"@types/elasticsearch": "^5.0.40",
|
|
51
51
|
"@types/mocha": "^10.0.1",
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"@types/sinon": "^
|
|
54
|
-
"@types/uuid": "^
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
56
|
-
"@typescript-eslint/parser": "^
|
|
57
|
-
"eslint": "^
|
|
58
|
-
"
|
|
59
|
-
"eslint-config-prettier": "
|
|
52
|
+
"@types/node": "^24.0.0",
|
|
53
|
+
"@types/sinon": "^21.0.0",
|
|
54
|
+
"@types/uuid": "^11.0.0",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
56
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
57
|
+
"eslint": "^9.0.0",
|
|
58
|
+
"globals": "^16.0.0",
|
|
59
|
+
"eslint-config-prettier": "10.1.8",
|
|
60
60
|
"eslint-plugin-import": "^2.27.5",
|
|
61
61
|
"eslint-plugin-prettier": "5.5.5",
|
|
62
|
-
"mocha": "^
|
|
62
|
+
"mocha": "^11.0.0",
|
|
63
63
|
"prettier": "^3.0.3"
|
|
64
64
|
},
|
|
65
65
|
"mocha": {
|