@restorecommerce/gql-bot 0.2.0 → 0.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.2.1](https://github.com/restorecommerce/libs/compare/@restorecommerce/gql-bot@0.2.0...@restorecommerce/gql-bot@0.2.1) (2022-06-20)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **gql-bot:** add option to ignore ssl errors ([b82d302](https://github.com/restorecommerce/libs/commit/b82d3020318ec5495ad1c6143cd5c80cb1657f80))
12
+
13
+
14
+
15
+
16
+
6
17
  # [0.2.0](https://github.com/restorecommerce/libs/compare/@restorecommerce/gql-bot@0.1.18...@restorecommerce/gql-bot@0.2.0) (2022-06-20)
7
18
 
8
19
 
package/lib/client.d.ts CHANGED
@@ -5,5 +5,5 @@ export declare class Client {
5
5
  constructor(opts: any);
6
6
  _buildURLs(): any;
7
7
  _normalizeUrl(source?: any): string;
8
- post(source: any, job?: any, verbose?: boolean): Promise<any>;
8
+ post(source: any, job?: any, verbose?: boolean, ignoreSelfSigned?: boolean): Promise<any>;
9
9
  }
package/lib/client.js CHANGED
@@ -18,6 +18,7 @@ const apollo_client_1 = require("apollo-client");
18
18
  const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
19
19
  const node_fetch_1 = require("node-fetch"); // required for apollo-link-http
20
20
  const apollo_link_http_1 = require("apollo-link-http");
21
+ const https = require("https");
21
22
  const _checkVariableMutation = (mutation) => {
22
23
  const mutationName = mutation.slice(mutation.indexOf(' '), mutation.indexOf('($'));
23
24
  if (mutationName.indexOf('$') > 0) {
@@ -132,7 +133,7 @@ class Client {
132
133
  }
133
134
  return url.resolve(this.entryBaseUrl, extendURL);
134
135
  }
135
- post(source, job, verbose = false) {
136
+ post(source, job, verbose = false, ignoreSelfSigned = false) {
136
137
  return __awaiter(this, void 0, void 0, function* () {
137
138
  const normalUrl = this._normalizeUrl();
138
139
  let mutation;
@@ -171,6 +172,11 @@ class Client {
171
172
  if (this.opts.headers) {
172
173
  apolloLinkOpts['headers'] = this.opts.headers;
173
174
  }
175
+ if (ignoreSelfSigned) {
176
+ apolloLinkOpts.fetchOptions = {
177
+ agent: new https.Agent({ rejectUnauthorized: false }),
178
+ };
179
+ }
174
180
  let apolloLink = apollo_link_http_1.createHttpLink(apolloLinkOpts);
175
181
  const apolloCache = new apollo_cache_inmemory_1.InMemoryCache();
176
182
  const apolloClient = new apollo_client_1.ApolloClient({
@@ -19,6 +19,6 @@ export declare class JobProcessor {
19
19
  processedTasks: number;
20
20
  taskStream: ps.PromiseStream<any>;
21
21
  constructor(jobInfo: any);
22
- start(tasks?: any, job?: Job, verbose?: boolean, ignoreErrors?: boolean): Promise<any>;
22
+ start(tasks?: any, job?: Job, verbose?: boolean, ignoreErrors?: boolean, ignoreSelfSigned?: boolean): Promise<any>;
23
23
  sync(task: any, job: Job): Promise<any>;
24
24
  }
@@ -99,13 +99,13 @@ class JobProcessor {
99
99
  processor: null
100
100
  });
101
101
  }
102
- start(tasks, job, verbose = false, ignoreErrors = false) {
102
+ start(tasks, job, verbose = false, ignoreErrors = false, ignoreSelfSigned = false) {
103
103
  return __awaiter(this, void 0, void 0, function* () {
104
104
  job = job || new Job();
105
105
  tasks = tasks || this.jobInfo.tasks;
106
106
  const concurrency = this.jobInfo.options.concurrency;
107
107
  this.taskStream = ps.map({ concurrent: concurrency }, (task) => {
108
- return this.jobInfo.options.processor.process(task, verbose, ignoreErrors).then((body) => {
108
+ return this.jobInfo.options.processor.process(task, verbose, ignoreErrors, ignoreSelfSigned).then((body) => {
109
109
  const logColor = utils_1.stringToChalk(task.name);
110
110
  if (verbose) {
111
111
  const processed = processResponse(body);
@@ -6,5 +6,5 @@ export declare class GraphQLProcessor {
6
6
  opts: any;
7
7
  client: Client;
8
8
  constructor(opts: any);
9
- process(task: any, verbose?: boolean, ignoreErrors?: boolean): Promise<any>;
9
+ process(task: any, verbose?: boolean, ignoreErrors?: boolean, ignoreSelfSigned?: boolean): Promise<any>;
10
10
  }
@@ -30,7 +30,7 @@ class GraphQLProcessor {
30
30
  this.opts = opts;
31
31
  this.client = new index_1.Client(opts);
32
32
  }
33
- process(task, verbose = false, ignoreErrors = false) {
33
+ process(task, verbose = false, ignoreErrors = false, ignoreSelfSigned = false) {
34
34
  return __awaiter(this, void 0, void 0, function* () {
35
35
  let yamlStream = new yaml_document_stream_1.YamlStreamReadTransformer();
36
36
  let jobPath = task.path;
@@ -89,7 +89,7 @@ class GraphQLProcessor {
89
89
  // 'yamlStream' readable stream.
90
90
  yamlStream.on('pause', () => __awaiter(this, void 0, void 0, function* () {
91
91
  try {
92
- resultArr.push(yield this.client.post(docArr, task, verbose));
92
+ resultArr.push(yield this.client.post(docArr, task, verbose, ignoreSelfSigned));
93
93
  yamlStream.resume();
94
94
  }
95
95
  catch (e) {
@@ -120,7 +120,7 @@ class GraphQLProcessor {
120
120
  batchCounter++;
121
121
  console.log(`[${logColor(task.name)}] Processing batch: ${batchCounter}${batchText}`);
122
122
  try {
123
- resultArr.push(yield this.client.post(docArr, task, verbose));
123
+ resultArr.push(yield this.client.post(docArr, task, verbose, ignoreSelfSigned));
124
124
  }
125
125
  catch (e) {
126
126
  !ignoreErrors && reject(e);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@restorecommerce/gql-bot",
3
3
  "description": "GraphQL Client Automated Task Processor",
4
4
  "main": "lib/index",
5
- "version": "0.2.0",
5
+ "version": "0.2.1",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/restorecommerce/libs.git"
@@ -71,5 +71,5 @@
71
71
  }
72
72
  }
73
73
  },
74
- "gitHead": "65fa379f6d4a215fb6c760431f9718c25b6f51ad"
74
+ "gitHead": "81045bce9b7838e15911349d28685be9416ac773"
75
75
  }
package/src/client.ts CHANGED
@@ -5,7 +5,8 @@ import gql from 'graphql-tag';
5
5
  import { ApolloClient } from 'apollo-client';
6
6
  import { InMemoryCache } from 'apollo-cache-inmemory';
7
7
  import fetch from 'node-fetch'; // required for apollo-link-http
8
- import { createHttpLink } from 'apollo-link-http';
8
+ import { createHttpLink, HttpLink } from 'apollo-link-http';
9
+ import * as https from 'https';
9
10
 
10
11
  const _checkVariableMutation = (mutation: string): Boolean => {
11
12
  const mutationName = mutation.slice(mutation.indexOf(' '),
@@ -138,7 +139,7 @@ export class Client {
138
139
  return url.resolve(this.entryBaseUrl, extendURL);
139
140
  }
140
141
 
141
- async post(source: any, job?: any, verbose = false): Promise<any> {
142
+ async post(source: any, job?: any, verbose = false, ignoreSelfSigned = false): Promise<any> {
142
143
  const normalUrl = this._normalizeUrl();
143
144
 
144
145
  let mutation;
@@ -172,7 +173,7 @@ export class Client {
172
173
  mutation = _replaceInlineVars(mutation, { resource_list, apiKey });
173
174
  }
174
175
 
175
- const apolloLinkOpts = {
176
+ const apolloLinkOpts: HttpLink.Options = {
176
177
  uri: normalUrl,
177
178
  fetch
178
179
  };
@@ -181,6 +182,12 @@ export class Client {
181
182
  apolloLinkOpts['headers'] = this.opts.headers;
182
183
  }
183
184
 
185
+ if (ignoreSelfSigned) {
186
+ apolloLinkOpts.fetchOptions = {
187
+ agent: new https.Agent({rejectUnauthorized: false}),
188
+ };
189
+ }
190
+
184
191
  let apolloLink = createHttpLink(apolloLinkOpts);
185
192
 
186
193
  const apolloCache = new InMemoryCache();
@@ -101,13 +101,13 @@ export class JobProcessor {
101
101
  });
102
102
  }
103
103
 
104
- async start(tasks?: any, job?: Job, verbose = false, ignoreErrors = false): Promise<any> {
104
+ async start(tasks?: any, job?: Job, verbose = false, ignoreErrors = false, ignoreSelfSigned = false): Promise<any> {
105
105
  job = job || new Job();
106
106
  tasks = tasks || this.jobInfo.tasks;
107
107
 
108
108
  const concurrency = this.jobInfo.options.concurrency;
109
109
  this.taskStream = ps.map({concurrent: concurrency}, (task: any) => {
110
- return this.jobInfo.options.processor.process(task, verbose, ignoreErrors).then((body) => {
110
+ return this.jobInfo.options.processor.process(task, verbose, ignoreErrors, ignoreSelfSigned).then((body) => {
111
111
  const logColor = stringToChalk(task.name);
112
112
 
113
113
  if (verbose) {
@@ -23,7 +23,7 @@ export class GraphQLProcessor {
23
23
  this.client = new Client(opts);
24
24
  }
25
25
 
26
- async process(task: any, verbose = false, ignoreErrors = false): Promise<any> {
26
+ async process(task: any, verbose = false, ignoreErrors = false, ignoreSelfSigned = false): Promise<any> {
27
27
  let yamlStream = new YamlStreamReadTransformer();
28
28
  let jobPath = task.path;
29
29
  let data = false;
@@ -85,7 +85,7 @@ export class GraphQLProcessor {
85
85
  // 'yamlStream' readable stream.
86
86
  yamlStream.on('pause', async () => {
87
87
  try {
88
- resultArr.push(await this.client.post(docArr, task, verbose));
88
+ resultArr.push(await this.client.post(docArr, task, verbose, ignoreSelfSigned));
89
89
  yamlStream.resume();
90
90
  } catch (e) {
91
91
  !ignoreErrors && reject(e);
@@ -118,7 +118,7 @@ export class GraphQLProcessor {
118
118
  batchCounter++;
119
119
  console.log(`[${logColor(task.name)}] Processing batch: ${batchCounter}${batchText}`);
120
120
  try {
121
- resultArr.push(await this.client.post(docArr, task, verbose));
121
+ resultArr.push(await this.client.post(docArr, task, verbose, ignoreSelfSigned));
122
122
  } catch (e) {
123
123
  !ignoreErrors && reject(e);
124
124
  }