@prismatic-io/spectral 5.0.0 → 5.1.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.
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export * from "./utils";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./types"), exports);
14
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,67 @@
1
+ import { Connection } from "../../index";
2
+ import { Client, IMTOMAttachments } from "soap";
3
+ export interface SOAPConnection extends Connection {
4
+ fields: {
5
+ [key: string]: unknown;
6
+ wsdlDefinitionUrl?: string;
7
+ };
8
+ }
9
+ export declare const isSOAPConnection: (connection: unknown) => connection is SOAPConnection;
10
+ export interface GetClient {
11
+ (connection: SOAPConnection): Promise<Client>;
12
+ (wsdlDefinition: string): Promise<Client>;
13
+ }
14
+ export interface SOAPRequest {
15
+ (params: RequestParams): Promise<[any, any, any, any, IMTOMAttachments?]>;
16
+ (params: RequestParams, methodParams: Record<string, unknown>): Promise<[
17
+ any,
18
+ any,
19
+ any,
20
+ any,
21
+ IMTOMAttachments?
22
+ ]>;
23
+ (params: RequestParams, methodParams: undefined): Promise<[
24
+ any,
25
+ any,
26
+ any,
27
+ any,
28
+ IMTOMAttachments?
29
+ ]>;
30
+ }
31
+ export interface RequestParams {
32
+ wsdlParam: SOAPConnection | string;
33
+ method: string;
34
+ overrides?: ClientOverrides;
35
+ debug?: boolean;
36
+ }
37
+ export interface ClientOverrides {
38
+ endpointURL?: string;
39
+ soapHeaders?: unknown[];
40
+ }
41
+ export interface HeaderPayload {
42
+ [x: string]: any;
43
+ }
44
+ export interface GenerateHeader {
45
+ (wsdlParam: SOAPConnection | string, headerPayload: HeaderPayload, headerOptions: undefined): Promise<string>;
46
+ (wsdlParam: SOAPConnection | string, headerPayload: HeaderPayload, headerOptions: {
47
+ namespace: string;
48
+ xmlns: string;
49
+ }): Promise<string>;
50
+ }
51
+ export interface BasicAuthConnection extends Connection {
52
+ fields: {
53
+ [key: string]: unknown;
54
+ username: unknown;
55
+ password: unknown;
56
+ loginMethod: unknown;
57
+ };
58
+ }
59
+ export declare const isBasicAuthConnection: (connection: Connection) => connection is BasicAuthConnection;
60
+ export interface SOAPAuth {
61
+ (connection: BasicAuthConnection, wsdlDefinition: string): Promise<any>;
62
+ (connection: BasicAuthConnection & SOAPConnection): Promise<any>;
63
+ }
64
+ export interface DescribeWSDL {
65
+ (connection: SOAPConnection): Promise<any>;
66
+ (wsdlDefinition: string): Promise<any>;
67
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBasicAuthConnection = exports.isSOAPConnection = void 0;
4
+ const isSOAPConnection = (connection) => {
5
+ var _a;
6
+ if (typeof connection === "object" && connection !== null)
7
+ return "wsdlDefinitionURL" in ((_a = connection) === null || _a === void 0 ? void 0 : _a.fields);
8
+ return false;
9
+ };
10
+ exports.isSOAPConnection = isSOAPConnection;
11
+ const isBasicAuthConnection = (connection) => {
12
+ const { fields } = connection;
13
+ return ("username" in fields && "password" in fields && "loginMethod" in fields);
14
+ };
15
+ exports.isBasicAuthConnection = isBasicAuthConnection;
@@ -0,0 +1,13 @@
1
+ import { ClientOverrides, GenerateHeader, GetClient, SOAPAuth, SOAPRequest, DescribeWSDL } from "./types";
2
+ import { Client } from "soap";
3
+ export declare const describeWSDL: DescribeWSDL;
4
+ declare const _default: {
5
+ generateHeader: GenerateHeader;
6
+ getSOAPClient: GetClient;
7
+ getSOAPAuth: SOAPAuth;
8
+ getWSDL: (wsdlDefinitionURL: string) => Promise<string>;
9
+ overrideClientDefaults: (client: Client, overrides: ClientOverrides) => void;
10
+ soapRequest: SOAPRequest;
11
+ describeWSDL: DescribeWSDL;
12
+ };
13
+ export default _default;
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.describeWSDL = void 0;
16
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
17
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
18
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
19
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
20
+ const types_1 = require("./types");
21
+ const index_1 = require("../../index");
22
+ const soap_1 = require("soap");
23
+ const axios_1 = __importDefault(require("axios"));
24
+ const promises_1 = require("fs/promises");
25
+ const uuid_1 = require("uuid");
26
+ const debugRequest = (client) => {
27
+ console.debug(client.lastRequest);
28
+ console.debug(client.lastResponse);
29
+ };
30
+ const describeWSDL = (wsdlParam) => __awaiter(void 0, void 0, void 0, function* () {
31
+ let client;
32
+ if (types_1.isSOAPConnection(wsdlParam)) {
33
+ client = yield getSOAPClient(wsdlParam);
34
+ }
35
+ else {
36
+ client = yield getSOAPClient(index_1.util.types.toString(wsdlParam));
37
+ }
38
+ try {
39
+ const result = client.describe();
40
+ return result;
41
+ }
42
+ catch (error) {
43
+ throw new Error("Unable to parse WSDL Services due to circular references");
44
+ }
45
+ });
46
+ exports.describeWSDL = describeWSDL;
47
+ const getWSDL = (wsdlDefinitionURL) => __awaiter(void 0, void 0, void 0, function* () {
48
+ const httpClient = axios_1.default.create({
49
+ baseURL: wsdlDefinitionURL,
50
+ headers: { "Content-Type": "text/xml" },
51
+ });
52
+ const { data } = yield httpClient.get("");
53
+ return index_1.util.types.toString(data);
54
+ });
55
+ const getSOAPClient = (wsdlParam) => __awaiter(void 0, void 0, void 0, function* () {
56
+ if (typeof wsdlParam === "string") {
57
+ const wsdl = index_1.util.types.toString(wsdlParam);
58
+ const filePath = `/tmp/${uuid_1.v4()}.wsdl`;
59
+ yield promises_1.writeFile(filePath, wsdl);
60
+ const client = yield soap_1.createClientAsync(filePath);
61
+ yield promises_1.rm(filePath);
62
+ return client;
63
+ }
64
+ else if (types_1.isSOAPConnection(wsdlParam)) {
65
+ const { fields: { wsdlDefinitionURL }, } = wsdlParam;
66
+ if (!wsdlDefinitionURL ||
67
+ !index_1.util.types.isUrl(index_1.util.types.toString(wsdlDefinitionURL))) {
68
+ throw new Error("WSDL Definition or the Connection field 'wsdlDefinitionURL' must be supplied.");
69
+ }
70
+ const client = yield soap_1.createClientAsync(index_1.util.types.toString(wsdlDefinitionURL));
71
+ return client;
72
+ }
73
+ else {
74
+ throw new Error("WSDL Definition or the Connection field 'wsdlDefinitionURL' must be supplied.");
75
+ }
76
+ });
77
+ const overrideClientDefaults = (client, overrides) => {
78
+ const { endpointURL, soapHeaders } = overrides;
79
+ if (endpointURL) {
80
+ client.setEndpoint(endpointURL);
81
+ }
82
+ if (soapHeaders) {
83
+ soapHeaders.map((header) => {
84
+ client.addSoapHeader(header);
85
+ });
86
+ }
87
+ };
88
+ const soapRequest = ({ wsdlParam, method, overrides, debug }, methodParams) => __awaiter(void 0, void 0, void 0, function* () {
89
+ let client;
90
+ if (types_1.isSOAPConnection(wsdlParam)) {
91
+ client = yield getSOAPClient(wsdlParam);
92
+ }
93
+ else {
94
+ client = yield getSOAPClient(wsdlParam);
95
+ }
96
+ if (overrides) {
97
+ overrideClientDefaults(client, overrides);
98
+ }
99
+ const requestFunction = client[`${method}Async`];
100
+ let results = undefined;
101
+ try {
102
+ if (typeof methodParams === "object" && methodParams !== null) {
103
+ results = yield requestFunction(methodParams);
104
+ }
105
+ else {
106
+ results = yield requestFunction({});
107
+ }
108
+ if (index_1.util.types.isBool(debug) && debug) {
109
+ debugRequest(client);
110
+ }
111
+ return results;
112
+ }
113
+ catch (error) {
114
+ if (index_1.util.types.isBool(debug) && debug) {
115
+ debugRequest(client);
116
+ }
117
+ throw error;
118
+ }
119
+ });
120
+ const generateHeader = (wsdlParam, headerPayload, headerOptions) => __awaiter(void 0, void 0, void 0, function* () {
121
+ let client;
122
+ if (types_1.isSOAPConnection(wsdlParam)) {
123
+ client = yield getSOAPClient(wsdlParam);
124
+ }
125
+ else {
126
+ client = yield getSOAPClient(wsdlParam);
127
+ }
128
+ let options = [];
129
+ if (headerOptions) {
130
+ options = Object.values(headerOptions);
131
+ }
132
+ const index = client.addSoapHeader(headerPayload, "", ...options);
133
+ return client.getSoapHeaders()[index];
134
+ });
135
+ const getSOAPAuth = (connection, wsdlDefinition) => __awaiter(void 0, void 0, void 0, function* () {
136
+ if (types_1.isBasicAuthConnection(connection) && wsdlDefinition) {
137
+ const { fields: { username, password, loginMethod }, } = connection;
138
+ const result = yield soapRequest({
139
+ wsdlParam: index_1.util.types.toString(wsdlDefinition),
140
+ method: index_1.util.types.toString(loginMethod),
141
+ }, { username, password });
142
+ return result;
143
+ }
144
+ else if (types_1.isSOAPConnection(connection) &&
145
+ types_1.isBasicAuthConnection(connection)) {
146
+ const { fields: { username, password, loginMethod }, } = connection;
147
+ const result = yield soapRequest({
148
+ wsdlParam: connection,
149
+ method: index_1.util.types.toString(loginMethod),
150
+ }, { username, password });
151
+ return result;
152
+ }
153
+ else {
154
+ throw new Error("Must supply a SOAP Connection or a WSDL Definition");
155
+ }
156
+ });
157
+ exports.default = {
158
+ generateHeader,
159
+ getSOAPClient,
160
+ getSOAPAuth,
161
+ getWSDL,
162
+ overrideClientDefaults,
163
+ soapRequest,
164
+ describeWSDL: exports.describeWSDL,
165
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"
@@ -32,13 +32,19 @@
32
32
  "dist/"
33
33
  ],
34
34
  "dependencies": {
35
+ "axios": "0.24.0",
35
36
  "date-fns": "2.17.0",
36
37
  "jest-mock": "27.0.3",
38
+ "soap": "0.43.0",
39
+ "uuid": "8.3.1",
37
40
  "valid-url": "1.0.9"
38
41
  },
39
42
  "devDependencies": {
43
+ "@types/axios": "0.14.0",
40
44
  "@types/jest": "26.0.23",
41
45
  "@types/node": "14.14.35",
46
+ "@types/sax": "1.2.4",
47
+ "@types/uuid": "8.3.1",
42
48
  "@types/valid-url": "1.0.3",
43
49
  "@typescript-eslint/eslint-plugin": "4.27.0",
44
50
  "@typescript-eslint/parser": "4.27.0",