@prismatic-io/spectral 5.2.0 → 5.2.1

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,32 +1,31 @@
1
1
  import { Connection } from "../../index";
2
- import { Client, IMTOMAttachments } from "soap";
2
+ import { IMTOMAttachments } from "soap";
3
+ /**
4
+ * SOAPConnection takes standard connection fields, and adds an optional `wsdlDefinitionUrl` field.
5
+ */
3
6
  export interface SOAPConnection extends Connection {
4
7
  fields: {
5
8
  [key: string]: unknown;
6
9
  wsdlDefinitionUrl?: string;
7
10
  };
8
11
  }
12
+ /**
13
+ * This function determines if the object presented is a SOAP connection with a `wsdlDefinitionUrl` field.
14
+ * @param connection The connection to test
15
+ * @returns This function returns true if the connection is a SOAPConnection, and false otherwise.
16
+ */
9
17
  export declare const isSOAPConnection: (connection: unknown) => connection is SOAPConnection;
10
- export interface GetClient {
11
- (connection: SOAPConnection): Promise<Client>;
12
- (wsdlDefinition: string): Promise<Client>;
13
- }
18
+ /**
19
+ * SOAP requests return a 4-tuple or 5-tuple with the response first, the XML response second, headers third, and the XML request fourth, and optional message attachments fifth.
20
+ */
21
+ export declare type SOAPResponse = [any, any, any, any, IMTOMAttachments?];
22
+ /**
23
+ * Overload the `soapRequest` function to take a variety of types of arguments.
24
+ */
14
25
  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
- ]>;
26
+ (params: RequestParams): Promise<SOAPResponse>;
27
+ (params: RequestParams, methodParams: Record<string, unknown>): Promise<SOAPResponse>;
28
+ (params: RequestParams, methodParams: undefined): Promise<SOAPResponse>;
30
29
  }
31
30
  export interface RequestParams {
32
31
  wsdlParam: SOAPConnection | string;
@@ -56,6 +55,11 @@ export interface BasicAuthConnection extends Connection {
56
55
  loginMethod: unknown;
57
56
  };
58
57
  }
58
+ /**
59
+ * This function determines if the object presented is a Basic Auth connection with `username`, `password`, and `loginMethod` fields.
60
+ * @param connection The connection to test
61
+ * @returns This function returns true if the connection is a SOAPConnection, and false otherwise.
62
+ */
59
63
  export declare const isBasicAuthConnection: (connection: Connection) => connection is BasicAuthConnection;
60
64
  export interface SOAPAuth {
61
65
  (connection: BasicAuthConnection, wsdlDefinition: string): Promise<any>;
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isBasicAuthConnection = exports.isSOAPConnection = void 0;
4
+ /**
5
+ * This function determines if the object presented is a SOAP connection with a `wsdlDefinitionUrl` field.
6
+ * @param connection The connection to test
7
+ * @returns This function returns true if the connection is a SOAPConnection, and false otherwise.
8
+ */
4
9
  const isSOAPConnection = (connection) => {
5
10
  var _a;
6
11
  if (typeof connection === "object" && connection !== null)
@@ -8,6 +13,11 @@ const isSOAPConnection = (connection) => {
8
13
  return false;
9
14
  };
10
15
  exports.isSOAPConnection = isSOAPConnection;
16
+ /**
17
+ * This function determines if the object presented is a Basic Auth connection with `username`, `password`, and `loginMethod` fields.
18
+ * @param connection The connection to test
19
+ * @returns This function returns true if the connection is a SOAPConnection, and false otherwise.
20
+ */
11
21
  const isBasicAuthConnection = (connection) => {
12
22
  const { fields } = connection;
13
23
  return ("username" in fields && "password" in fields && "loginMethod" in fields);
@@ -1,13 +1,12 @@
1
- import { ClientOverrides, GenerateHeader, GetClient, SOAPAuth, SOAPRequest, DescribeWSDL } from "./types";
1
+ import { ClientOverrides, GenerateHeader, SOAPAuth, SOAPConnection, SOAPRequest, DescribeWSDL } from "./types";
2
2
  import { Client } from "soap";
3
- export declare const describeWSDL: DescribeWSDL;
4
3
  declare const _default: {
4
+ describeWSDL: DescribeWSDL;
5
5
  generateHeader: GenerateHeader;
6
- getSOAPClient: GetClient;
7
6
  getSOAPAuth: SOAPAuth;
7
+ getSOAPClient: <T extends string | SOAPConnection = string | SOAPConnection>(wsdlParam: T) => Promise<Client>;
8
8
  getWSDL: (wsdlDefinitionURL: string) => Promise<string>;
9
9
  overrideClientDefaults: (client: Client, overrides: ClientOverrides) => void;
10
10
  soapRequest: SOAPRequest;
11
- describeWSDL: DescribeWSDL;
12
11
  };
13
12
  export default _default;
@@ -12,10 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.describeWSDL = void 0;
16
15
  /* 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
16
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
20
17
  const types_1 = require("./types");
21
18
  const index_1 = require("../../index");
@@ -23,18 +20,25 @@ const soap_1 = require("soap");
23
20
  const axios_1 = __importDefault(require("axios"));
24
21
  const promises_1 = require("fs/promises");
25
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
+ */
26
30
  const debugRequest = (client) => {
27
31
  console.debug(client.lastRequest);
28
32
  console.debug(client.lastResponse);
29
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
+ */
30
40
  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
- }
41
+ const client = yield getSOAPClient(types_1.isSOAPConnection(wsdlParam) ? wsdlParam : index_1.util.types.toString(wsdlParam));
38
42
  try {
39
43
  const result = client.describe();
40
44
  return result;
@@ -43,7 +47,11 @@ const describeWSDL = (wsdlParam) => __awaiter(void 0, void 0, void 0, function*
43
47
  throw new Error("Unable to parse WSDL Services due to circular references");
44
48
  }
45
49
  });
46
- exports.describeWSDL = describeWSDL;
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
+ */
47
55
  const getWSDL = (wsdlDefinitionURL) => __awaiter(void 0, void 0, void 0, function* () {
48
56
  const httpClient = axios_1.default.create({
49
57
  baseURL: wsdlDefinitionURL,
@@ -52,10 +60,15 @@ const getWSDL = (wsdlDefinitionURL) => __awaiter(void 0, void 0, void 0, functio
52
60
  const { data } = yield httpClient.get("");
53
61
  return index_1.util.types.toString(data);
54
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
+ */
55
68
  const getSOAPClient = (wsdlParam) => __awaiter(void 0, void 0, void 0, function* () {
56
69
  if (typeof wsdlParam === "string") {
57
70
  const wsdl = index_1.util.types.toString(wsdlParam);
58
- const filePath = `/tmp/${uuid_1.v4()}.wsdl`;
71
+ const filePath = path_1.default.join(os_1.default.tmpdir(), `${uuid_1.v4()}.wsdl`);
59
72
  yield promises_1.writeFile(filePath, wsdl);
60
73
  const client = yield soap_1.createClientAsync(filePath);
61
74
  yield promises_1.rm(filePath);
@@ -74,6 +87,11 @@ const getSOAPClient = (wsdlParam) => __awaiter(void 0, void 0, void 0, function*
74
87
  throw new Error("WSDL Definition or the Connection field 'wsdlDefinitionURL' must be supplied.");
75
88
  }
76
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
+ */
77
95
  const overrideClientDefaults = (client, overrides) => {
78
96
  const { endpointURL, soapHeaders } = overrides;
79
97
  if (endpointURL) {
@@ -85,14 +103,14 @@ const overrideClientDefaults = (client, overrides) => {
85
103
  });
86
104
  }
87
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
+ */
88
112
  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
- }
113
+ const client = yield getSOAPClient(types_1.isSOAPConnection(wsdlParam) ? wsdlParam : index_1.util.types.toString(wsdlParam));
96
114
  if (overrides) {
97
115
  overrideClientDefaults(client, overrides);
98
116
  }
@@ -114,17 +132,19 @@ const soapRequest = ({ wsdlParam, method, overrides, debug }, methodParams) => _
114
132
  if (index_1.util.types.isBool(debug) && debug) {
115
133
  debugRequest(client);
116
134
  }
135
+ console.warn("Please verify that the method you specified exists in the WSDL specification.");
117
136
  throw error;
118
137
  }
119
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
+ */
120
146
  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
- }
147
+ const client = yield getSOAPClient(types_1.isSOAPConnection(wsdlParam) ? wsdlParam : index_1.util.types.toString(wsdlParam));
128
148
  let options = [];
129
149
  if (headerOptions) {
130
150
  options = Object.values(headerOptions);
@@ -132,6 +152,12 @@ const generateHeader = (wsdlParam, headerPayload, headerOptions) => __awaiter(vo
132
152
  const index = client.addSoapHeader(headerPayload, "", ...options);
133
153
  return client.getSoapHeaders()[index];
134
154
  });
155
+ /**
156
+ * Fetch authentication information for a SOAPConnection
157
+ * @param connection The SOAPConnection
158
+ * @param wsdlDefinition The XML WSDL definition
159
+ * @returns
160
+ */
135
161
  const getSOAPAuth = (connection, wsdlDefinition) => __awaiter(void 0, void 0, void 0, function* () {
136
162
  if (types_1.isBasicAuthConnection(connection) && wsdlDefinition) {
137
163
  const { fields: { username, password, loginMethod }, } = connection;
@@ -155,11 +181,11 @@ const getSOAPAuth = (connection, wsdlDefinition) => __awaiter(void 0, void 0, vo
155
181
  }
156
182
  });
157
183
  exports.default = {
184
+ describeWSDL,
158
185
  generateHeader,
159
- getSOAPClient,
160
186
  getSOAPAuth,
187
+ getSOAPClient,
161
188
  getWSDL,
162
189
  overrideClientDefaults,
163
190
  soapRequest,
164
- describeWSDL: exports.describeWSDL,
165
191
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"