@restorecommerce/gql-bot 1.0.8 → 1.0.9
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 +13 -0
- package/eslint.config.mjs +22 -0
- package/lib/client.d.ts +1 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/client.js +79 -118
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +4 -6
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -10
- package/lib/index.js.map +1 -1
- package/lib/job_processor.d.ts +1 -2
- package/lib/job_processor.d.ts.map +1 -0
- package/lib/job_processor.js +120 -163
- package/lib/job_processor.js.map +1 -1
- package/lib/job_processor_gql.d.ts +2 -1
- package/lib/job_processor_gql.d.ts.map +1 -0
- package/lib/job_processor_gql.js +112 -149
- package/lib/job_processor_gql.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/utils.d.ts +2 -1
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +5 -13
- package/lib/utils.js.map +1 -1
- package/package.json +23 -29
- package/src/client.ts +13 -14
- package/src/index.ts +3 -8
- package/src/job_processor.ts +6 -6
- package/src/job_processor_gql.ts +8 -9
- package/src/utils.ts +2 -2
- package/tsconfig-base.json +14 -0
- package/tsconfig.json +1 -24
- package/tsconfig.test.json +2 -4
- package/vitest.config.ts +2 -0
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,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC;IAC9B,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC;CAC7B,CAA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C,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
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": "1.0.
|
|
5
|
+
"version": "1.0.9",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/restorecommerce/libs.git"
|
|
@@ -15,50 +15,44 @@
|
|
|
15
15
|
"tasks",
|
|
16
16
|
"processor"
|
|
17
17
|
],
|
|
18
|
+
"type": "module",
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"apollo
|
|
20
|
-
"
|
|
21
|
-
"apollo-link-http": "^1.5.17",
|
|
22
|
-
"chalk": "^4.1.2",
|
|
20
|
+
"@apollo/client": "^3.11.8",
|
|
21
|
+
"chalk": "^5.3.0",
|
|
23
22
|
"color-hash": "^2.0.2",
|
|
24
|
-
"graphql": "^
|
|
25
|
-
"graphql-tag": "^2.12.6",
|
|
23
|
+
"graphql": "^16.9.0",
|
|
26
24
|
"js-yaml": "^4.1.0",
|
|
27
25
|
"lodash": "^4.17.21",
|
|
28
|
-
"node-fetch": "^
|
|
26
|
+
"node-fetch": "^3.3.2",
|
|
29
27
|
"promise-streams": "^2.1.1",
|
|
30
|
-
"readdirp": "^
|
|
28
|
+
"readdirp": "^4.0.2",
|
|
31
29
|
"through2": "^4.0.2",
|
|
32
30
|
"yaml-document-stream": "^1.1.0"
|
|
33
31
|
},
|
|
34
32
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@types/
|
|
37
|
-
"@types/node": "^
|
|
38
|
-
"@
|
|
39
|
-
"@typescript-eslint/
|
|
40
|
-
"
|
|
41
|
-
"
|
|
33
|
+
"@restorecommerce/dev": "^0.0.13",
|
|
34
|
+
"@types/color-hash": "^2.0.0",
|
|
35
|
+
"@types/node": "^22.7.9",
|
|
36
|
+
"@types/through2": "^2.0.41",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
|
38
|
+
"@typescript-eslint/parser": "^8.11.0",
|
|
39
|
+
"@vitest/coverage-v8": "^2.1.4",
|
|
40
|
+
"eslint": "^9.13.0",
|
|
42
41
|
"eslint-plugin-prefer-arrow-functions": "^3.1.4",
|
|
43
|
-
"
|
|
44
|
-
"nock": "^13.
|
|
42
|
+
"msw": "^2.5.2",
|
|
43
|
+
"nock": "^13.5.5",
|
|
45
44
|
"npm-run-all": "^4.1.5",
|
|
46
|
-
"nyc": "^15.1.0",
|
|
47
|
-
"should": "^13.2.3",
|
|
48
45
|
"ts-node": "^10.9.1",
|
|
49
|
-
"typescript": "^5.1.6"
|
|
46
|
+
"typescript": "^5.1.6",
|
|
47
|
+
"vitest": "^2.1.4"
|
|
50
48
|
},
|
|
51
49
|
"scripts": {
|
|
52
50
|
"pretest": "npm run lint",
|
|
53
|
-
"test": "
|
|
54
|
-
"
|
|
55
|
-
"lint": "eslint './src/**/*.ts'",
|
|
51
|
+
"test": "vitest run --dangerouslyIgnoreUnhandledErrors",
|
|
52
|
+
"lint": "eslint src",
|
|
56
53
|
"build:tsc": "tsc -d",
|
|
57
54
|
"build:clean": "rimraf lib",
|
|
58
|
-
"build": "npm-run-all lint build:clean build:tsc"
|
|
59
|
-
"mocha-debug": "mocha -R spec test/*.js --full-trace --inspect-brk",
|
|
60
|
-
"lcov-report": "nyc report --reporter=lcov",
|
|
61
|
-
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
|
55
|
+
"build": "npm-run-all lint build:clean build:tsc"
|
|
62
56
|
},
|
|
63
57
|
"engines": {
|
|
64
58
|
"node": ">= 12.0.0"
|
|
@@ -72,5 +66,5 @@
|
|
|
72
66
|
}
|
|
73
67
|
}
|
|
74
68
|
},
|
|
75
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "2cdfe2ff31f5c695c8789831fd7b797e5256e25d"
|
|
76
70
|
}
|
package/src/client.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as _ from 'lodash';
|
|
2
2
|
import * as url from 'url';
|
|
3
3
|
import * as fs from 'fs';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import fetch from 'node-fetch'; // required for apollo-link-http
|
|
8
|
-
import { createHttpLink, HttpLink } from 'apollo-link-http';
|
|
4
|
+
import { ApolloClient } from '@apollo/client/core';
|
|
5
|
+
import { InMemoryCache } from '@apollo/client/cache';
|
|
6
|
+
import { HttpOptions, createHttpLink } from '@apollo/client/link/http';
|
|
9
7
|
import * as https from 'https';
|
|
10
|
-
import { processResponse } from './utils';
|
|
8
|
+
import { processResponse } from './utils.js';
|
|
9
|
+
import {parse} from 'graphql';
|
|
11
10
|
|
|
12
|
-
const _checkVariableMutation = (mutation: string):
|
|
11
|
+
const _checkVariableMutation = (mutation: string): boolean => {
|
|
13
12
|
const mutationName = mutation.slice(mutation.indexOf(' '),
|
|
14
13
|
mutation.indexOf('($'));
|
|
15
14
|
if (mutationName.indexOf('$') > 0) {
|
|
@@ -24,7 +23,7 @@ const _replaceInlineVars = (mutation: string, args: any): string => {
|
|
|
24
23
|
return mutation.replace(/\${(\w+)}/g, (_, v) => args[v]);
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
const _createQueryVariables = (inputVarName: string, queryVarKey: string, varValue: any):
|
|
26
|
+
const _createQueryVariables = (inputVarName: string, queryVarKey: string, varValue: any): object => {
|
|
28
27
|
if (queryVarKey) {
|
|
29
28
|
return {
|
|
30
29
|
[inputVarName]: {
|
|
@@ -158,9 +157,9 @@ export class Client {
|
|
|
158
157
|
// (i.e. if the quote is preceded by a backslash)
|
|
159
158
|
// make sure to also match line/expression start
|
|
160
159
|
// and keep the symbol preceding the quote
|
|
161
|
-
mutation = mutation.replace(/(^|[^\\])
|
|
160
|
+
mutation = mutation.replace(/(^|[^\\])"/g, '$1');
|
|
162
161
|
// afterwards, replace escaped quotes with regular ones
|
|
163
|
-
mutation = mutation.replace(
|
|
162
|
+
mutation = mutation.replace(/\\"/g, '"');
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
let variables;
|
|
@@ -170,11 +169,11 @@ export class Client {
|
|
|
170
169
|
variables = _createQueryVariables(inputVarName, queryVarKey, resource_list);
|
|
171
170
|
} else {
|
|
172
171
|
// To remove double quotes from the keys in JSON data
|
|
173
|
-
resource_list = resource_list.replace(
|
|
172
|
+
resource_list = resource_list.replace(/"([^(")"]+)":/g, '$1:');
|
|
174
173
|
mutation = _replaceInlineVars(mutation, { resource_list, apiKey });
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
const apolloLinkOpts:
|
|
176
|
+
const apolloLinkOpts: HttpOptions = {
|
|
178
177
|
uri: normalUrl,
|
|
179
178
|
fetch: fetch as any
|
|
180
179
|
};
|
|
@@ -189,7 +188,7 @@ export class Client {
|
|
|
189
188
|
};
|
|
190
189
|
}
|
|
191
190
|
|
|
192
|
-
|
|
191
|
+
const apolloLink = createHttpLink(apolloLinkOpts);
|
|
193
192
|
|
|
194
193
|
const apolloCache = new InMemoryCache();
|
|
195
194
|
const apolloClient = new ApolloClient({
|
|
@@ -198,7 +197,7 @@ export class Client {
|
|
|
198
197
|
});
|
|
199
198
|
|
|
200
199
|
const response = await apolloClient.mutate({
|
|
201
|
-
mutation:
|
|
200
|
+
mutation: parse(`${mutation}`),
|
|
202
201
|
variables
|
|
203
202
|
});
|
|
204
203
|
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
import { GraphQLProcessor } from './job_processor_gql';
|
|
5
|
-
export { GraphQLProcessor };
|
|
6
|
-
|
|
7
|
-
import { JobProcessor, Job } from './job_processor';
|
|
8
|
-
export { JobProcessor, Job };
|
|
1
|
+
export { Client } from './client.js';
|
|
2
|
+
export { GraphQLProcessor } from './job_processor_gql.js';
|
|
3
|
+
export { JobProcessor, Job } from './job_processor.js';
|
package/src/job_processor.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as through2 from 'through2';
|
|
|
5
5
|
import readdirp from 'readdirp';
|
|
6
6
|
import * as path from 'path';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
|
-
import { stringToChalk, processResponse } from './utils';
|
|
8
|
+
import { stringToChalk, processResponse } from './utils.js';
|
|
9
9
|
|
|
10
10
|
export class ReadArrayStream extends Readable {
|
|
11
11
|
array: any[];
|
|
@@ -32,7 +32,7 @@ export class ReadArrayStream extends Readable {
|
|
|
32
32
|
export class Job extends EventEmitter {
|
|
33
33
|
opts: any;
|
|
34
34
|
done = false;
|
|
35
|
-
error = undefined;
|
|
35
|
+
error: any = undefined;
|
|
36
36
|
|
|
37
37
|
constructor(opts?: any) {
|
|
38
38
|
super();
|
|
@@ -78,7 +78,7 @@ export class JobProcessor {
|
|
|
78
78
|
|
|
79
79
|
const concurrency = this.jobInfo.options.concurrency;
|
|
80
80
|
this.taskStream = ps.map({concurrent: concurrency}, (task: any) => {
|
|
81
|
-
return this.jobInfo.options.processor.process(task, verbose, ignoreErrors, ignoreSelfSigned).then((body) => {
|
|
81
|
+
return this.jobInfo.options.processor.process(task, verbose, ignoreErrors, ignoreSelfSigned).then((body: any) => {
|
|
82
82
|
const logColor = stringToChalk(task.name);
|
|
83
83
|
|
|
84
84
|
if (verbose) {
|
|
@@ -99,9 +99,9 @@ export class JobProcessor {
|
|
|
99
99
|
objectMode: true
|
|
100
100
|
}, tasks);
|
|
101
101
|
|
|
102
|
-
inputTaskStream.pipe(through2.obj(async (task, enc, cb) => {
|
|
102
|
+
inputTaskStream.pipe(through2.obj(async (task: any, enc: any, cb: any) => {
|
|
103
103
|
const operation = task.operation;
|
|
104
|
-
await this[operation].apply(this, [task, job]);
|
|
104
|
+
await this[operation as keyof JobProcessor].apply(this, [task, job]);
|
|
105
105
|
cb();
|
|
106
106
|
}));
|
|
107
107
|
|
|
@@ -123,7 +123,7 @@ export class JobProcessor {
|
|
|
123
123
|
|
|
124
124
|
async sync(task: any, job: Job): Promise<any> {
|
|
125
125
|
const pathOptions = {
|
|
126
|
-
fileFilter: (entry) => {
|
|
126
|
+
fileFilter: (entry: any) => {
|
|
127
127
|
return true;
|
|
128
128
|
},
|
|
129
129
|
depth: 1,
|
package/src/job_processor_gql.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
1
2
|
import * as _ from 'lodash';
|
|
2
3
|
import * as fs from 'fs';
|
|
3
|
-
import { Client } from './
|
|
4
|
+
import { Client } from './client.js';
|
|
4
5
|
import { YamlStreamReadTransformer } from 'yaml-document-stream';
|
|
5
|
-
import { stringToChalk } from './utils';
|
|
6
|
+
import { stringToChalk } from './utils.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* GraphQL-specific job processor.
|
|
@@ -24,21 +25,19 @@ export class GraphQLProcessor {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
async process(task: any, verbose = false, ignoreErrors = false, ignoreSelfSigned = false): Promise<any> {
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const yamlStream = new YamlStreamReadTransformer();
|
|
29
|
+
const jobPath = task.path;
|
|
29
30
|
let data = false;
|
|
30
31
|
const logColor = stringToChalk(task.name);
|
|
31
32
|
switch (task.operation) {
|
|
32
33
|
case 'sync': { // synchronous operation
|
|
33
34
|
return new Promise<any>((resolve, reject) => {
|
|
34
35
|
try {
|
|
35
|
-
yamlStream.on('error', (err) =>
|
|
36
|
-
!ignoreErrors && reject(err);
|
|
37
|
-
});
|
|
36
|
+
yamlStream.on('error', (err) => !ignoreErrors && reject(err));
|
|
38
37
|
|
|
39
38
|
const fileStream = fs.createReadStream(task.fullPath);
|
|
40
39
|
fileStream.pipe(yamlStream);
|
|
41
|
-
let batchsize;
|
|
40
|
+
let batchsize: number;
|
|
42
41
|
if (task.batchSize) {
|
|
43
42
|
batchsize = task.batchSize;
|
|
44
43
|
console.log(`[${logColor(task.name)}] Batch size:`, batchsize);
|
|
@@ -47,7 +46,7 @@ export class GraphQLProcessor {
|
|
|
47
46
|
let counter = 0;
|
|
48
47
|
let batchCounter = 0;
|
|
49
48
|
let docArr: any[] = [];
|
|
50
|
-
|
|
49
|
+
const resultArr: any[] = [];
|
|
51
50
|
|
|
52
51
|
// Here we read from the readable stream each yaml document parsed
|
|
53
52
|
// as an object, and if we have batching enabled we first batch this
|
package/src/utils.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import ColorHash from 'color-hash';
|
|
2
|
-
|
|
2
|
+
import chalk from 'chalk';
|
|
3
3
|
|
|
4
4
|
const colorHash = new ColorHash({
|
|
5
5
|
lightness: [0.45, 0.6, 0.75]
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
export const stringToChalk = (str) => {
|
|
8
|
+
export const stringToChalk = (str: string) => {
|
|
9
9
|
return chalk.hex(colorHash.hex(str));
|
|
10
10
|
};
|
|
11
11
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../node_modules/@restorecommerce/dev/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./lib",
|
|
5
|
+
"types": ["node"],
|
|
6
|
+
"resolveJsonModule": true,
|
|
7
|
+
"esModuleInterop": true
|
|
8
|
+
},
|
|
9
|
+
"exclude": [
|
|
10
|
+
"node_modules",
|
|
11
|
+
"lib",
|
|
12
|
+
"doc"
|
|
13
|
+
]
|
|
14
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"target": "es6",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
// "strict": true,
|
|
8
|
-
"emitDecoratorMetadata": true,
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"allowSyntheticDefaultImports": true,
|
|
11
|
-
"noUnusedLocals": false,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"outDir": "lib",
|
|
16
|
-
"lib": [
|
|
17
|
-
"es2020.promise",
|
|
18
|
-
"dom"
|
|
19
|
-
]
|
|
20
|
-
},
|
|
2
|
+
"extends": "./tsconfig-base.json",
|
|
21
3
|
"include": [
|
|
22
4
|
"./src/**/*.ts"
|
|
23
|
-
],
|
|
24
|
-
"exclude": [
|
|
25
|
-
"node_modules",
|
|
26
|
-
"lib",
|
|
27
|
-
"doc"
|
|
28
5
|
]
|
|
29
6
|
}
|
package/tsconfig.test.json
CHANGED
package/vitest.config.ts
ADDED