@prismatic-io/spectral 8.0.0-preview7 → 8.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.
@@ -1,191 +0,0 @@
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
- /* eslint-disable @typescript-eslint/no-unsafe-return */
16
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
17
- const types_1 = require("./types");
18
- const index_1 = require("../../index");
19
- const soap_1 = require("soap");
20
- const axios_1 = __importDefault(require("axios"));
21
- const promises_1 = require("fs/promises");
22
- const uuid_1 = require("uuid");
23
- const os_1 = __importDefault(require("os"));
24
- const path_1 = __importDefault(require("path"));
25
- /**
26
- * Optionally log out SOAP requests and responses for debugging purposes
27
- *
28
- * @param client A SOAP client that generates requests and responses
29
- */
30
- const debugRequest = (client) => {
31
- console.debug(client.lastRequest);
32
- console.debug(client.lastResponse);
33
- };
34
- /**
35
- * This function takes either the URL of a WSDL or the XML defining a WSDL, and returns an object describing the methods and attributes defined in the WSDL.
36
- *
37
- * @param wsdlParam Either the URL where a WSDL is stored, or the XML defining a WSDL.
38
- * @returns An object containing the methods and attributes defined in a WSDL
39
- */
40
- const describeWSDL = (wsdlParam) => __awaiter(void 0, void 0, void 0, function* () {
41
- const client = yield getSOAPClient((0, types_1.isSOAPConnection)(wsdlParam) ? wsdlParam : index_1.util.types.toString(wsdlParam));
42
- try {
43
- const result = client.describe();
44
- return result;
45
- }
46
- catch (error) {
47
- throw new Error("Unable to parse WSDL Services due to circular references");
48
- }
49
- });
50
- /**
51
- * Fetch a WSDL from a URL
52
- * @param wsdlDefinitionURL The URL where the WSDL is stored
53
- * @returns The WSDL's raw XML
54
- */
55
- const getWSDL = (wsdlDefinitionURL) => __awaiter(void 0, void 0, void 0, function* () {
56
- const httpClient = axios_1.default.create({
57
- baseURL: wsdlDefinitionURL,
58
- headers: { "Content-Type": "text/xml" },
59
- });
60
- const { data } = yield httpClient.get("");
61
- return index_1.util.types.toString(data);
62
- });
63
- /**
64
- * Create a SOAP client given a WSDL or SOAPConnection
65
- * @param wsdlParam a SOAPConnection or XML defining a WSDL
66
- * @returns An HTTP client configured to query a SOAP-based API
67
- */
68
- const getSOAPClient = (wsdlParam) => __awaiter(void 0, void 0, void 0, function* () {
69
- if (typeof wsdlParam === "string") {
70
- const wsdl = index_1.util.types.toString(wsdlParam);
71
- const filePath = path_1.default.join(os_1.default.tmpdir(), `${(0, uuid_1.v4)()}.wsdl`);
72
- yield (0, promises_1.writeFile)(filePath, wsdl);
73
- const client = yield (0, soap_1.createClientAsync)(filePath);
74
- yield (0, promises_1.rm)(filePath);
75
- return client;
76
- }
77
- else if ((0, types_1.isSOAPConnection)(wsdlParam)) {
78
- const { fields: { wsdlDefinitionURL }, } = wsdlParam;
79
- if (!wsdlDefinitionURL ||
80
- !index_1.util.types.isUrl(index_1.util.types.toString(wsdlDefinitionURL))) {
81
- throw new Error("WSDL Definition or the Connection field 'wsdlDefinitionURL' must be supplied.");
82
- }
83
- const client = yield (0, soap_1.createClientAsync)(index_1.util.types.toString(wsdlDefinitionURL));
84
- return client;
85
- }
86
- else {
87
- throw new Error("WSDL Definition or the Connection field 'wsdlDefinitionURL' must be supplied.");
88
- }
89
- });
90
- /**
91
- * Override some HTTP client defaults
92
- * @param client The client to override
93
- * @param overrides An endpoint URL or SOAP headers to override
94
- */
95
- const overrideClientDefaults = (client, overrides) => {
96
- const { endpointURL, soapHeaders } = overrides;
97
- if (endpointURL) {
98
- client.setEndpoint(endpointURL);
99
- }
100
- if (soapHeaders) {
101
- soapHeaders.map((header) => {
102
- client.addSoapHeader(header);
103
- });
104
- }
105
- };
106
- /**
107
- * Make a request to a SOAP-based API
108
- * @param param0
109
- * @param methodParams Parameters to pass to the specified SOAP method
110
- * @returns The results from the SOAP request, including the full XML of the request and response
111
- */
112
- const soapRequest = ({ wsdlParam, method, overrides, debug }, methodParams) => __awaiter(void 0, void 0, void 0, function* () {
113
- const client = yield getSOAPClient((0, types_1.isSOAPConnection)(wsdlParam) ? wsdlParam : index_1.util.types.toString(wsdlParam));
114
- if (overrides) {
115
- overrideClientDefaults(client, overrides);
116
- }
117
- const requestFunction = client[`${method}Async`];
118
- let results = undefined;
119
- try {
120
- if (typeof methodParams === "object" && methodParams !== null) {
121
- results = yield requestFunction(methodParams);
122
- }
123
- else {
124
- results = yield requestFunction({});
125
- }
126
- if (index_1.util.types.isBool(debug) && debug) {
127
- debugRequest(client);
128
- }
129
- return results;
130
- }
131
- catch (error) {
132
- if (index_1.util.types.isBool(debug) && debug) {
133
- debugRequest(client);
134
- }
135
- console.warn("Please verify that the method you specified exists in the WSDL specification.");
136
- throw error;
137
- }
138
- });
139
- /**
140
- * Create a SOAP header
141
- * @param wsdlParam A SOAPConnection or XML definition of a WSDL
142
- * @param headerPayload The contents of a header XML node
143
- * @param headerOptions Attributes for a header XML node, like namespace or xmlns
144
- * @returns
145
- */
146
- const generateHeader = (wsdlParam, headerPayload, headerOptions) => __awaiter(void 0, void 0, void 0, function* () {
147
- const client = yield getSOAPClient((0, types_1.isSOAPConnection)(wsdlParam) ? wsdlParam : index_1.util.types.toString(wsdlParam));
148
- let options = [];
149
- if (headerOptions) {
150
- options = Object.values(headerOptions);
151
- }
152
- const index = client.addSoapHeader(headerPayload, "", ...options);
153
- return client.getSoapHeaders()[index];
154
- });
155
- /**
156
- * Fetch authentication information for a SOAPConnection
157
- * @param connection The SOAPConnection
158
- * @param wsdlDefinition The XML WSDL definition
159
- * @returns
160
- */
161
- const getSOAPAuth = (connection, wsdlDefinition) => __awaiter(void 0, void 0, void 0, function* () {
162
- if ((0, types_1.isBasicAuthConnection)(connection) && wsdlDefinition) {
163
- const { fields: { username, password, loginMethod }, } = connection;
164
- const result = yield soapRequest({
165
- wsdlParam: index_1.util.types.toString(wsdlDefinition),
166
- method: index_1.util.types.toString(loginMethod),
167
- }, { username, password });
168
- return result;
169
- }
170
- else if ((0, types_1.isSOAPConnection)(connection) &&
171
- (0, types_1.isBasicAuthConnection)(connection)) {
172
- const { fields: { username, password, loginMethod }, } = connection;
173
- const result = yield soapRequest({
174
- wsdlParam: connection,
175
- method: index_1.util.types.toString(loginMethod),
176
- }, { username, password });
177
- return result;
178
- }
179
- else {
180
- throw new Error("Must supply a SOAP Connection or a WSDL Definition");
181
- }
182
- });
183
- exports.default = {
184
- describeWSDL,
185
- generateHeader,
186
- getSOAPAuth,
187
- getSOAPClient,
188
- getWSDL,
189
- overrideClientDefaults,
190
- soapRequest,
191
- };