@restorecommerce/gql-bot 1.0.7 → 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/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.7",
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-cache-inmemory": "^1.6.6",
20
- "apollo-client": "^2.6.10",
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": "^15.5.0",
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": "^2.6.0",
26
+ "node-fetch": "^3.3.2",
29
27
  "promise-streams": "^2.1.1",
30
- "readdirp": "^3.6.0",
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
- "@types/color-hash": "^1.0.2",
36
- "@types/mocha": "^10.0.1",
37
- "@types/node": "^20.4.1",
38
- "@typescript-eslint/eslint-plugin": "^6.0.0",
39
- "@typescript-eslint/parser": "^6.0.0",
40
- "coveralls": "^3.1.1",
41
- "eslint": "^8.44.0",
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
- "mocha": "^10.2.0",
44
- "nock": "^13.3.1",
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": "nyc npm run mocha",
54
- "mocha": "mocha --full-trace --exit --timeout 20000",
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": "48456b8ea43fd3bfad46deaea7010ccd899ea074"
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 gql from 'graphql-tag';
5
- import { ApolloClient } from 'apollo-client';
6
- import { InMemoryCache } from 'apollo-cache-inmemory';
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): Boolean => {
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): Object => {
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(/(^|[^\\])\"/g, '$1');
160
+ mutation = mutation.replace(/(^|[^\\])"/g, '$1');
162
161
  // afterwards, replace escaped quotes with regular ones
163
- mutation = mutation.replace(/\\\"/g, '\"');
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(/\"([^(\")"]+)\":/g, '$1:');
172
+ resource_list = resource_list.replace(/"([^(")"]+)":/g, '$1:');
174
173
  mutation = _replaceInlineVars(mutation, { resource_list, apiKey });
175
174
  }
176
175
 
177
- const apolloLinkOpts: HttpLink.Options = {
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
- let apolloLink = createHttpLink(apolloLinkOpts);
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: gql`${mutation}` as any,
200
+ mutation: parse(`${mutation}`),
202
201
  variables
203
202
  });
204
203
 
package/src/index.ts CHANGED
@@ -1,8 +1,3 @@
1
- import { Client } from './client';
2
- export { Client };
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';
@@ -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,
@@ -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 './index';
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
- let yamlStream = new YamlStreamReadTransformer();
28
- let jobPath = task.path;
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
- let resultArr: any[] = [];
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
- const chalk = require('chalk');
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
- "compilerOptions": {
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
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "compilerOptions": {
3
- "outDir": "test"
4
- },
5
2
  "extends": "./tsconfig.json",
6
3
  "include": [
7
- "./test/**/*.ts"
4
+ "./src/**/*.ts",
5
+ "./tests/**/*.ts"
8
6
  ]
9
7
  }
@@ -0,0 +1,2 @@
1
+ import config from '../../node_modules/@restorecommerce/dev/vitest.config.js';
2
+ export default config;