closer-cli 0.5.7 → 2.7.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.
- package/CHANGELOG.md +46 -0
- package/cmds/importData.js +1 -1
- package/cmds/importStock.js +213 -0
- package/helpers.js +5 -2
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [2.6.0](https://code.hfarm.dev/closer/closer/compare/v2.5.1...v2.6.0) (2022-04-19)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **#PJX-415:** [Server] Import configuration ([a3fa87e](https://code.hfarm.dev/closer/closer/commits/a3fa87ea22c0a0d850afa025a0a04937bbd3b4dd)), closes [#PJX-415](https://code.hfarm.dev/closer/closer/issues/PJX-415)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [2.5.0](https://code.hfarm.dev/closer/closer/compare/v2.4.0...v2.5.0) (2022-04-13)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **#PJX-388:** Aggiungere alla chat dell'ordine i cambi di stato ([544219c](https://code.hfarm.dev/closer/closer/commits/544219c76e9230db4541366ffc47dabb4c11fb42)), closes [#PJX-388](https://code.hfarm.dev/closer/closer/issues/PJX-388)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# [2.4.0](https://code.hfarm.dev/closer/closer/compare/v2.4.0-beta.1...v2.4.0) (2022-04-11)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package closer-cli
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# [2.3.0](https://code.hfarm.dev/closer/closer/compare/v2.3.0-beta.0...v2.3.0) (2022-04-06)
|
|
37
|
+
|
|
38
|
+
**Note:** Version bump only for package closer-cli
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# [2.2.0](https://code.hfarm.dev/closer/closer/compare/v2.2.0-beta.1...v2.2.0) (2022-04-06)
|
|
45
|
+
|
|
46
|
+
**Note:** Version bump only for package closer-cli
|
package/cmds/importData.js
CHANGED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/* eslint-disable no-await-in-loop */
|
|
2
|
+
/* eslint-disable no-restricted-syntax */
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const chalk = require('chalk')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
|
|
8
|
+
const Ora = require('ora')
|
|
9
|
+
const prompts = require('prompts')
|
|
10
|
+
const {
|
|
11
|
+
importCsvFromFile,
|
|
12
|
+
getExecutionTime,
|
|
13
|
+
callAfterDataImportProcess,
|
|
14
|
+
ALLOWED_CSV_FILES,
|
|
15
|
+
download,
|
|
16
|
+
validateCsvFromFile,
|
|
17
|
+
getArchiveFolder,
|
|
18
|
+
getGoogleSheetCsvUrl
|
|
19
|
+
} = require('../helpers')
|
|
20
|
+
|
|
21
|
+
exports.command = 'import:stock'
|
|
22
|
+
|
|
23
|
+
exports.desc = 'Import Stock Availability from CSV file'
|
|
24
|
+
|
|
25
|
+
exports.builder = yargs => {
|
|
26
|
+
yargs
|
|
27
|
+
.usage(`Usage: ${chalk.cyan('$0 import:stock')} [options]`)
|
|
28
|
+
.option('fromFile', {
|
|
29
|
+
alias: 'f',
|
|
30
|
+
describe: 'File to import',
|
|
31
|
+
type: 'string'
|
|
32
|
+
})
|
|
33
|
+
.option('fromUrl', {
|
|
34
|
+
alias: 'u',
|
|
35
|
+
describe: 'Remote URL file to import',
|
|
36
|
+
type: 'string'
|
|
37
|
+
})
|
|
38
|
+
.option('fromDir', {
|
|
39
|
+
alias: 'd',
|
|
40
|
+
describe: 'Directory path that contains file to import',
|
|
41
|
+
type: 'string'
|
|
42
|
+
})
|
|
43
|
+
.option('fromGoogleDocId', {
|
|
44
|
+
alias: 'g',
|
|
45
|
+
describe: 'Google Doc ID that contains sheet to import',
|
|
46
|
+
type: 'string'
|
|
47
|
+
})
|
|
48
|
+
// .conflicts('fromFile', 'fromUrl', 'fromDir', 'fromGoogleDocId')
|
|
49
|
+
.check(argv => {
|
|
50
|
+
if (!argv.fromFile && !argv.fromUrl && !argv.fromDir && !argv.fromGoogleDocId) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
'Missing required argument: fromFile OR fromUrl OR fromDir OR fromGoogleDocId'
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (argv.fromFile) {
|
|
57
|
+
fs.accessSync(argv.fromFile, fs.constants.F_OK)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (argv.fromDir) {
|
|
61
|
+
fs.accessSync(argv.fromDir, fs.constants.F_OK)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return true
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.handler = async argv => {
|
|
69
|
+
// eslint-disable-next-line no-param-reassign
|
|
70
|
+
argv.out = argv.out || getArchiveFolder(argv.endpoint)
|
|
71
|
+
|
|
72
|
+
const spinner = new Ora()
|
|
73
|
+
const hrstart = process.hrtime()
|
|
74
|
+
|
|
75
|
+
const report = {
|
|
76
|
+
start: new Date(),
|
|
77
|
+
end: null,
|
|
78
|
+
time: null,
|
|
79
|
+
endpoint: argv.endpoint,
|
|
80
|
+
mode: null,
|
|
81
|
+
type: [],
|
|
82
|
+
result: []
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const ws = {
|
|
86
|
+
endpoint: argv.endpoint,
|
|
87
|
+
adminSecret: argv['admin-secret']
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const interactive = !argv.nonInteractive
|
|
91
|
+
|
|
92
|
+
const csvType = 'stockAvailability'
|
|
93
|
+
|
|
94
|
+
let file
|
|
95
|
+
if (argv.fromDir) {
|
|
96
|
+
file = {
|
|
97
|
+
file: path.resolve(argv.fromDir, ALLOWED_CSV_FILES.stockAvailability),
|
|
98
|
+
csvType
|
|
99
|
+
}
|
|
100
|
+
} else if (argv.fromGoogleDocId) {
|
|
101
|
+
file = {
|
|
102
|
+
url: getGoogleSheetCsvUrl(argv.fromGoogleDocId, csvType),
|
|
103
|
+
csvType
|
|
104
|
+
}
|
|
105
|
+
} else if (argv.fromFile) {
|
|
106
|
+
file = {
|
|
107
|
+
file: argv.fromFile,
|
|
108
|
+
csvType
|
|
109
|
+
}
|
|
110
|
+
} else if (argv.fromUrl) {
|
|
111
|
+
file = {
|
|
112
|
+
url: argv.fromUrl,
|
|
113
|
+
csvType
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let mode
|
|
118
|
+
if (interactive && !argv.mode) {
|
|
119
|
+
const answers = await prompts(
|
|
120
|
+
[
|
|
121
|
+
{
|
|
122
|
+
type: 'select',
|
|
123
|
+
name: 'mode',
|
|
124
|
+
message: 'Import Mode',
|
|
125
|
+
choices: [
|
|
126
|
+
{
|
|
127
|
+
title: 'Incremental',
|
|
128
|
+
value: 'incremental'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
title: 'Full',
|
|
132
|
+
description: 'Before starting, all database records will be logically deleted',
|
|
133
|
+
value: 'full'
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
hint: ' '
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
{ onCancel: () => process.exit() }
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
mode = answers.mode
|
|
143
|
+
} else {
|
|
144
|
+
mode = argv.mode
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (interactive) {
|
|
148
|
+
console.log('')
|
|
149
|
+
const { confirmed } = await prompts(
|
|
150
|
+
[
|
|
151
|
+
{
|
|
152
|
+
type: 'confirm',
|
|
153
|
+
name: 'confirmed',
|
|
154
|
+
message: 'Continue?',
|
|
155
|
+
initial: false
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
{ onCancel: () => process.exit() }
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
if (!confirmed) {
|
|
162
|
+
process.exit()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.log('')
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let filepath = argv.fromFile
|
|
169
|
+
|
|
170
|
+
if (argv.fromUrl || argv.fromGoogleDocId) {
|
|
171
|
+
spinner.start('Downloading file...')
|
|
172
|
+
filepath = await download(file.url, argv.out, `${csvType}.csv`)
|
|
173
|
+
spinner.succeed('Downloaded file')
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const validation = await validateCsvFromFile(filepath, csvType, ws, argv.csvDelimiter)
|
|
177
|
+
|
|
178
|
+
if (validation.error) {
|
|
179
|
+
console.log(`ERROR => [${chalk.red(validation.inputFile)}] ${validation.error}`)
|
|
180
|
+
process.exit()
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const csvReport = await importCsvFromFile(
|
|
184
|
+
filepath,
|
|
185
|
+
csvType,
|
|
186
|
+
argv.out,
|
|
187
|
+
spinner,
|
|
188
|
+
ws,
|
|
189
|
+
argv.csvDelimiter
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
//
|
|
193
|
+
// Report
|
|
194
|
+
//
|
|
195
|
+
|
|
196
|
+
report.end = new Date()
|
|
197
|
+
report.time = getExecutionTime(hrstart)
|
|
198
|
+
report.mode = mode
|
|
199
|
+
report.type = [csvType]
|
|
200
|
+
|
|
201
|
+
const reportRows = []
|
|
202
|
+
|
|
203
|
+
reportRows.push({
|
|
204
|
+
type: 'import.csv',
|
|
205
|
+
payload: csvReport
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
report.result = reportRows
|
|
209
|
+
|
|
210
|
+
await callAfterDataImportProcess(spinner, ws, report)
|
|
211
|
+
|
|
212
|
+
process.exit()
|
|
213
|
+
}
|
package/helpers.js
CHANGED
|
@@ -13,7 +13,7 @@ const { createWriteStream } = require('fs')
|
|
|
13
13
|
const slugify = require('slugify')
|
|
14
14
|
|
|
15
15
|
exports.createSocketConnection = (endpoint, adminSecret) => {
|
|
16
|
-
const protocol = endpoint.includes('localhost') ? 'ws' : 'wss'
|
|
16
|
+
const protocol = endpoint.includes('localhost') || endpoint.includes('127.0.0.1') ? 'ws' : 'wss'
|
|
17
17
|
const socket = new WebSocket(`${protocol}://${endpoint}/import`, {
|
|
18
18
|
headers: { 'x-closer-admin-secret': adminSecret }
|
|
19
19
|
})
|
|
@@ -31,6 +31,8 @@ exports.ALLOWED_CSV_FILES = {
|
|
|
31
31
|
label: 'labels.csv',
|
|
32
32
|
filterPosition: 'filterPosition.csv',
|
|
33
33
|
fieldConfiguration: 'fieldConfigurations.csv',
|
|
34
|
+
stockAvailability: 'stockAvailability.csv',
|
|
35
|
+
configuration: 'configurations.csv',
|
|
34
36
|
userCustomer: 'userCustomers.csv'
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -219,7 +221,7 @@ exports.importCsvFromFile = (file, csvType, outputDir, spinner, ws, delimiter =
|
|
|
219
221
|
})
|
|
220
222
|
})
|
|
221
223
|
|
|
222
|
-
exports.validateCsvFromFile = (file, csvType, ws, delimiter = '
|
|
224
|
+
exports.validateCsvFromFile = (file, csvType, ws, delimiter = ';') =>
|
|
223
225
|
new Promise(resolve => {
|
|
224
226
|
const socket = this.createSocketConnection(ws.endpoint, ws.adminSecret)
|
|
225
227
|
|
|
@@ -418,6 +420,7 @@ exports.refreshOrders = (spinner, ws) =>
|
|
|
418
420
|
const { type, payload } = JSON.parse(packet)
|
|
419
421
|
switch (type) {
|
|
420
422
|
case 'refreshDraftOrdersResponse': {
|
|
423
|
+
console.log(JSON.stringify({ type, payload }))
|
|
421
424
|
spinner.text = this.printRefreshedOrders({
|
|
422
425
|
...payload,
|
|
423
426
|
executionTime: this.getExecutionTime(hrstart)
|