@kitalive/sfdx-plugin 0.1.1 → 0.1.5

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  =====================
3
3
 
4
4
  [![Version](https://img.shields.io/npm/v/@kitalive/sfdx-plugin.svg)](https://npmjs.org/package/@kitalive/sfdx-plugin)
5
- [![License](https://img.shields.io/npm/l/@kitalive/sfdx-plugin.svg)](https://github.com/Kitalive-Inc/sfdx-plugin/blob/master/package.json)
5
+ [![License](https://img.shields.io/npm/l/@kitalive/sfdx-plugin.svg)](https://github.com/Kitalive-Inc/sfdx-plugin/blob/main/package.json)
6
6
 
7
7
  ## Install
8
8
 
@@ -18,7 +18,7 @@ $ npm install -g @kitalive/sfdx-plugin
18
18
  $ sfdx COMMAND
19
19
  running command...
20
20
  $ sfdx (-v|--version|version)
21
- @kitalive/sfdx-plugin/0.1.1 darwin-x64 node-v15.10.0
21
+ @kitalive/sfdx-plugin/0.1.5 darwin-x64 node-v16.12.0
22
22
  $ sfdx --help [COMMAND]
23
23
  USAGE
24
24
  $ sfdx COMMAND
@@ -29,12 +29,13 @@ USAGE
29
29
  ## Commands
30
30
 
31
31
  <!-- commands -->
32
- * [`sfdx kit:data:bulk:upsert -o <string> -i <string> -f <filepath> [-e <string>] [-d <string>] [-m <filepath>] [-c <filepath>] [--setnull] [--save] [--saveonly] [--concurrencymode <string>] [--assignmentruleid <string>] [-s <integer>] [-w <integer>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-kitdatabulkupsert--o-string--i-string--f-filepath--e-string--d-string--m-filepath--c-filepath---setnull---save---saveonly---concurrencymode-string---assignmentruleid-string--s-integer--w-integer--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
33
- * [`sfdx kit:data:csv:convert [-f <filepath>] [-o <filepath>] [-e <string>] [-d <string>] [-m <filepath>] [-c <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-kitdatacsvconvert--f-filepath--o-filepath--e-string--d-string--m-filepath--c-filepath---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
32
+ * [`sfdx kit:data:bulk:upsert -o <string> -i <string> -f <filepath> [-r <filepath>] [-e <string>] [-d <string>] [-q <string>] [--skiplines <integer>] [--trim] [-m <filepath>] [-c <filepath>] [--setnull] [--convertonly] [--concurrencymode <string>] [--assignmentruleid <string>] [-s <integer>] [-w <integer>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-kitdatabulkupsert--o-string--i-string--f-filepath--r-filepath--e-string--d-string--q-string---skiplines-integer---trim--m-filepath--c-filepath---setnull---convertonly---concurrencymode-string---assignmentruleid-string--s-integer--w-integer--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
33
+ * [`sfdx kit:data:csv:convert [-f <filepath>] [-o <filepath>] [-e <string>] [-d <string>] [-q <string>] [--skiplines <integer>] [--trim] [-m <filepath>] [-c <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-kitdatacsvconvert--f-filepath--o-filepath--e-string--d-string--q-string---skiplines-integer---trim--m-filepath--c-filepath---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
34
34
  * [`sfdx kit:layout:assignments:deploy -f <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-kitlayoutassignmentsdeploy--f-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
35
35
  * [`sfdx kit:layout:assignments:retrieve -f <string> [-p <string>] [-o <string>] [--merge] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-kitlayoutassignmentsretrieve--f-string--p-string--o-string---merge--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
36
+ * [`sfdx kit:script:execute [-f <filepath>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-kitscriptexecute--f-filepath--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
36
37
 
37
- ## `sfdx kit:data:bulk:upsert -o <string> -i <string> -f <filepath> [-e <string>] [-d <string>] [-m <filepath>] [-c <filepath>] [--setnull] [--save] [--saveonly] [--concurrencymode <string>] [--assignmentruleid <string>] [-s <integer>] [-w <integer>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
38
+ ## `sfdx kit:data:bulk:upsert -o <string> -i <string> -f <filepath> [-r <filepath>] [-e <string>] [-d <string>] [-q <string>] [--skiplines <integer>] [--trim] [-m <filepath>] [-c <filepath>] [--setnull] [--convertonly] [--concurrencymode <string>] [--assignmentruleid <string>] [-s <integer>] [-w <integer>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
38
39
 
39
40
  bulk upsert records from a CSV file
40
41
 
@@ -44,10 +45,10 @@ Upsert records using Bulk API and returns a job ID and a batch ID. Use these IDs
44
45
  For information about CSV file formats, see [Prepare CSV Files](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_csv_preparing.htm) in the Bulk API Developer Guide.
45
46
 
46
47
  USAGE
47
- $ sfdx kit:data:bulk:upsert -o <string> -i <string> -f <filepath> [-e <string>] [-d <string>] [-m <filepath>] [-c
48
- <filepath>] [--setnull] [--save] [--saveonly] [--concurrencymode <string>] [--assignmentruleid <string>] [-s
49
- <integer>] [-w <integer>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
50
- trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
48
+ $ sfdx kit:data:bulk:upsert -o <string> -i <string> -f <filepath> [-r <filepath>] [-e <string>] [-d <string>] [-q
49
+ <string>] [--skiplines <integer>] [--trim] [-m <filepath>] [-c <filepath>] [--setnull] [--convertonly]
50
+ [--concurrencymode <string>] [--assignmentruleid <string>] [-s <integer>] [-w <integer>] [-u <string>] [--apiversion
51
+ <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
51
52
 
52
53
  OPTIONS
53
54
  -c, --converter=converter the path of the script to convert
@@ -59,8 +60,8 @@ OPTIONS
59
60
  -e, --encoding=encoding [default: utf8] the input CSV file
60
61
  encoding
61
62
 
62
- -f, --csvfile=csvfile (required) the path of the CSV file
63
- that defines the records to upsert
63
+ -f, --csvfile=csvfile (required) the CSV file path that
64
+ defines the records to upsert
64
65
 
65
66
  -i, --externalid=externalid (required) [default: Id] the column
66
67
  name of the external ID
@@ -71,6 +72,12 @@ OPTIONS
71
72
  -o, --object=object (required) the sObject name to
72
73
  upsert
73
74
 
75
+ -q, --quote=quote [default: "] the input CSV file
76
+ quote character
77
+
78
+ -r, --resultfile=resultfile the CSV file path for writing the
79
+ upsert results
80
+
74
81
  -s, --batchsize=batchsize [default: 10000] the batch size of
75
82
  the job
76
83
 
@@ -91,20 +98,22 @@ OPTIONS
91
98
  mode (Parallel or Serial) for the
92
99
  job
93
100
 
101
+ --convertonly output converted.csv file and skip
102
+ upsert for debugging
103
+
94
104
  --json format output as json
95
105
 
96
106
  --loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
97
107
  this command invocation
98
108
 
99
- --save output converted.csv file
100
-
101
- --saveonly output converted.csv file and skip
102
- upsert for debugging
103
-
104
109
  --setnull set blank values as null values
105
110
  during upsert operations (default:
106
111
  empty field values are ignored)
107
112
 
113
+ --skiplines=skiplines the number of lines to skip
114
+
115
+ --trim trim all white space from columns
116
+
108
117
  DESCRIPTION
109
118
  Upsert records using Bulk API and returns a job ID and a batch ID. Use these IDs to check job status with
110
119
  data:bulk:status.
@@ -118,9 +127,9 @@ EXAMPLES
118
127
  10
119
128
  ```
120
129
 
121
- _See code: [src/commands/kit/data/bulk/upsert.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.1/src/commands/kit/data/bulk/upsert.ts)_
130
+ _See code: [src/commands/kit/data/bulk/upsert.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.5/src/commands/kit/data/bulk/upsert.ts)_
122
131
 
123
- ## `sfdx kit:data:csv:convert [-f <filepath>] [-o <filepath>] [-e <string>] [-d <string>] [-m <filepath>] [-c <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
132
+ ## `sfdx kit:data:csv:convert [-f <filepath>] [-o <filepath>] [-e <string>] [-d <string>] [-q <string>] [--skiplines <integer>] [--trim] [-m <filepath>] [-c <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
124
133
 
125
134
  convert CSV data using column mapping file or Node.js script
126
135
 
@@ -128,8 +137,9 @@ convert CSV data using column mapping file or Node.js script
128
137
  convert CSV data using column mapping file or Node.js script
129
138
 
130
139
  USAGE
131
- $ sfdx kit:data:csv:convert [-f <filepath>] [-o <filepath>] [-e <string>] [-d <string>] [-m <filepath>] [-c
132
- <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
140
+ $ sfdx kit:data:csv:convert [-f <filepath>] [-o <filepath>] [-e <string>] [-d <string>] [-q <string>] [--skiplines
141
+ <integer>] [--trim] [-m <filepath>] [-c <filepath>] [--json] [--loglevel
142
+ trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
133
143
 
134
144
  OPTIONS
135
145
  -c, --converter=converter the path of the script to convert
@@ -150,17 +160,24 @@ OPTIONS
150
160
  -o, --outputfile=outputfile the path of the output CSV file
151
161
  (default: standard output)
152
162
 
163
+ -q, --quote=quote [default: "] the input CSV file
164
+ quote character
165
+
153
166
  --json format output as json
154
167
 
155
168
  --loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
156
169
  this command invocation
157
170
 
171
+ --skiplines=skiplines the number of lines to skip
172
+
173
+ --trim trim all white space from columns
174
+
158
175
  EXAMPLES
159
176
  $ sfdx kit:data:csv:convert -f ./path/to/input.csv -m ./path/to/mapping.json
160
177
  $ sfdx kit:data:csv:convert -f ./path/to/input.csv -o ./path/to/output.csv -c ./path/to/convert.js -e cp932 -d :
161
178
  ```
162
179
 
163
- _See code: [src/commands/kit/data/csv/convert.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.1/src/commands/kit/data/csv/convert.ts)_
180
+ _See code: [src/commands/kit/data/csv/convert.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.5/src/commands/kit/data/csv/convert.ts)_
164
181
 
165
182
  ## `sfdx kit:layout:assignments:deploy -f <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
166
183
 
@@ -195,7 +212,7 @@ EXAMPLES
195
212
  $ sfdx kit:layout:assignments:deploy -u me@my.org -f config/layout-assignments.sandbox.json
196
213
  ```
197
214
 
198
- _See code: [src/commands/kit/layout/assignments/deploy.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.1/src/commands/kit/layout/assignments/deploy.ts)_
215
+ _See code: [src/commands/kit/layout/assignments/deploy.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.5/src/commands/kit/layout/assignments/deploy.ts)_
199
216
 
200
217
  ## `sfdx kit:layout:assignments:retrieve -f <string> [-p <string>] [-o <string>] [--merge] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
201
218
 
@@ -241,5 +258,50 @@ EXAMPLES
241
258
  $ sfdx kit:layout:assignments:retrieve -u me@my.org -f config/layout-assignments.sandbox.json
242
259
  ```
243
260
 
244
- _See code: [src/commands/kit/layout/assignments/retrieve.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.1/src/commands/kit/layout/assignments/retrieve.ts)_
261
+ _See code: [src/commands/kit/layout/assignments/retrieve.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.5/src/commands/kit/layout/assignments/retrieve.ts)_
262
+
263
+ ## `sfdx kit:script:execute [-f <filepath>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
264
+
265
+ execute Node.js scripts in SfdxCommand context
266
+
267
+ ```
268
+ execute Node.js scripts in SfdxCommand context
269
+ Available variables in Node.js scripts
270
+ conn: jsforce Connection
271
+ context: SfdxCommand
272
+
273
+ USAGE
274
+ $ sfdx kit:script:execute [-f <filepath>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
275
+ trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
276
+
277
+ OPTIONS
278
+ -f, --file=file the path of the Node.js script file
279
+ to execute
280
+
281
+ -u, --targetusername=targetusername username or alias for the target
282
+ org; overrides default target org
283
+
284
+ --apiversion=apiversion override the api version used for
285
+ api requests made by this command
286
+
287
+ --json format output as json
288
+
289
+ --loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for
290
+ this command invocation
291
+
292
+ DESCRIPTION
293
+ Available variables in Node.js scripts
294
+ conn: jsforce Connection
295
+ context: SfdxCommand
296
+
297
+ ALIASES
298
+ $ sfdx kit:script
299
+
300
+ EXAMPLES
301
+ $ sfdx kit:script -f ./path/to/script.js
302
+ $ sfdx kit:script:execute
303
+ > await conn.query('SELECT Id, Name FROM Account LIMIT 1')
304
+ ```
305
+
306
+ _See code: [src/commands/kit/script/execute.ts](https://github.com/Kitalive-Inc/sfdx-plugin/blob/v0.1.5/src/commands/kit/script/execute.ts)_
245
307
  <!-- commandsstop -->
@@ -11,13 +11,16 @@ export default class UpsertCommand extends SfdxCommand {
11
11
  object: flags.Discriminated<flags.String>;
12
12
  externalid: flags.Discriminated<flags.String>;
13
13
  csvfile: flags.Discriminated<flags.String>;
14
+ resultfile: flags.Discriminated<flags.String>;
14
15
  encoding: flags.Discriminated<flags.String>;
15
16
  delimiter: flags.Discriminated<flags.String>;
17
+ quote: flags.Discriminated<flags.String>;
18
+ skiplines: flags.Discriminated<flags.Number>;
19
+ trim: flags.Discriminated<flags.Boolean<boolean>>;
16
20
  mapping: flags.Discriminated<flags.String>;
17
21
  converter: flags.Discriminated<flags.String>;
18
22
  setnull: flags.Discriminated<flags.Boolean<boolean>>;
19
- save: flags.Discriminated<flags.Boolean<boolean>>;
20
- saveonly: flags.Discriminated<flags.Boolean<boolean>>;
23
+ convertonly: flags.Discriminated<flags.Boolean<boolean>>;
21
24
  concurrencymode: flags.Discriminated<flags.String>;
22
25
  assignmentruleid: flags.Discriminated<flags.String>;
23
26
  batchsize: flags.Discriminated<flags.Number>;
@@ -27,6 +30,9 @@ export default class UpsertCommand extends SfdxCommand {
27
30
  parseCsv(input: Readable, options?: {
28
31
  encoding?: string;
29
32
  delimiter?: string;
33
+ quote?: string;
34
+ skiplines?: number;
35
+ trim?: boolean;
30
36
  setnull?: boolean;
31
37
  mapping?: JsonMap;
32
38
  convert?: (row: JsonMap) => JsonMap | null | undefined;
@@ -34,6 +40,8 @@ export default class UpsertCommand extends SfdxCommand {
34
40
  [field: string]: string;
35
41
  };
36
42
  }): Promise<JsonMap[]>;
43
+ private executeBatches;
44
+ private executeBatch;
37
45
  private saveCsv;
38
46
  private loadScript;
39
47
  private getFieldTypes;
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@salesforce/command");
4
- const csv = require("csv");
5
4
  const dayjs = require("dayjs");
5
+ const csv = require("fast-csv");
6
6
  const fs = require("fs-extra");
7
7
  const path = require("path");
8
8
  const utils_1 = require("../../../../utils");
9
9
  const convert_1 = require("../csv/convert");
10
10
  const convert_2 = require("../csv/convert");
11
- /* tslint:disable:no-var-requires */
12
- const ALM_PATH = path.dirname(require.resolve('salesforce-alm'));
13
- const dataBulk = require(path.join(ALM_PATH, 'lib/data/dataBulkUpsertCommand'));
14
- const logger = require(path.join(ALM_PATH, 'lib/core/logApi'));
15
11
  function normalizeDateString(str, format) {
16
12
  if (!str)
17
13
  return str;
@@ -25,7 +21,7 @@ const converters = {
25
21
  const csvFlags = convert_1.default['flagsConfig'];
26
22
  class UpsertCommand extends command_1.SfdxCommand {
27
23
  async run() {
28
- const { csvfile, mapping, converter, encoding, delimiter, setnull } = this.flags;
24
+ const { csvfile, mapping, converter, encoding, delimiter, quote, skiplines, trim, setnull } = this.flags;
29
25
  const mappingJson = (mapping) ? (await fs.readJson(mapping)) : undefined;
30
26
  const script = converter ? this.loadScript(converter) : {};
31
27
  const fieldTypes = await this.getFieldTypes(this.flags.object);
@@ -35,6 +31,9 @@ class UpsertCommand extends command_1.SfdxCommand {
35
31
  let rows = await this.parseCsv(fs.createReadStream(csvfile), {
36
32
  encoding,
37
33
  delimiter,
34
+ quote,
35
+ skiplines,
36
+ trim: !!trim,
38
37
  setnull,
39
38
  mapping: mappingJson,
40
39
  convert: script.convert,
@@ -46,33 +45,73 @@ class UpsertCommand extends command_1.SfdxCommand {
46
45
  rows = result;
47
46
  }
48
47
  this.ux.stopSpinner();
49
- if (this.flags.save || this.flags.saveonly) {
48
+ if (this.flags.convertonly) {
50
49
  const base = path.basename(csvfile, path.extname(csvfile));
51
50
  this.saveCsv(path.join(path.dirname(csvfile), base + '.converted.csv'), rows);
52
- if (this.flags.saveonly)
53
- return;
51
+ return;
54
52
  }
55
53
  this.ux.startSpinner('Bulk Upsert');
54
+ let job;
56
55
  try {
57
- const job = await this.createJob(this.flags.object, {
56
+ job = await this.createJob(this.flags.object, {
58
57
  extIdField: this.flags.externalid,
59
58
  concurrencyMode: this.flags.concurrencymode,
60
59
  assignmentRuleId: this.flags.assignmentruleid
61
60
  });
62
- const batches = utils_1.chunk(rows, this.flags.batchsize);
63
- logger.setHumanConsumable(!this.flags.json);
64
- const result = await dataBulk.createAndExecuteBatches(this.org.getConnection(), job, batches, this.flags.object, this.flags.wait);
65
- return result;
61
+ const batchResults = await this.executeBatches(job, rows, this.flags.batchsize, this.flags.wait);
62
+ const batchErrors = [];
63
+ if (this.flags.wait) {
64
+ rows = rows.map((data, i) => {
65
+ var _a;
66
+ const { id, errors } = (_a = batchResults[i]) !== null && _a !== void 0 ? _a : {};
67
+ const message = errors === null || errors === void 0 ? void 0 : errors.join(', ');
68
+ if (message) {
69
+ batchErrors.push({ line: i + 2, message, data });
70
+ }
71
+ return Object.assign(Object.assign({}, data), { Id: id, Errors: message });
72
+ });
73
+ if (batchErrors.length) {
74
+ this.ux.styledHeader('Upsert errors');
75
+ batchErrors.forEach(({ line, message }) => this.ux.log(`line ${line}: ${message}`));
76
+ }
77
+ }
78
+ else {
79
+ const batchInfos = await job.list();
80
+ let command = 'sfdx force:data:bulk:status';
81
+ if (this.flags.targetusername)
82
+ command += ' -u ' + this.flags.targetusername;
83
+ batchInfos.forEach((batch, i) => this.ux.log([
84
+ `Check batch #${i + 1}’s status with the command: `,
85
+ `${command} -i ${batch.jobId} -b ${batch.id}`
86
+ ].join('\n')));
87
+ }
88
+ if (this.flags.resultfile)
89
+ this.saveCsv(this.flags.resultfile, rows);
90
+ const jobInfo = await job.check();
91
+ delete jobInfo.$;
92
+ delete jobInfo.state;
93
+ if (this.flags.wait) {
94
+ this.ux.styledHeader('Job Status');
95
+ this.ux.styledObject(jobInfo, Object.keys(jobInfo));
96
+ }
97
+ if (batchErrors.length)
98
+ jobInfo.errors = batchErrors;
99
+ return jobInfo;
66
100
  }
67
101
  catch (e) {
68
102
  this.ux.stopSpinner('error');
69
103
  throw e;
70
104
  }
105
+ finally {
106
+ job === null || job === void 0 ? void 0 : job.close();
107
+ }
71
108
  }
72
109
  async parseCsv(input, options) {
73
- const { encoding, delimiter, mapping, convert, setnull, fieldTypes } = options !== null && options !== void 0 ? options : {};
74
- return await convert_2.parseCsv(input, { encoding, delimiter, mapping, convert: row => {
110
+ const { encoding, delimiter, quote, skiplines, trim, mapping, convert, setnull, fieldTypes } = options !== null && options !== void 0 ? options : {};
111
+ return await convert_2.parseCsv(input, { encoding, delimiter, quote, skiplines, trim, mapping, convert: row => {
75
112
  const result = convert ? convert(row) : row;
113
+ if (!result)
114
+ return;
76
115
  if (fieldTypes) {
77
116
  for (const key of Object.keys(result)) {
78
117
  const converter = converters[fieldTypes[key]];
@@ -91,19 +130,48 @@ class UpsertCommand extends command_1.SfdxCommand {
91
130
  return result;
92
131
  } });
93
132
  }
133
+ executeBatches(job, rows, batchSize, wait) {
134
+ return Promise.all(utils_1.chunk(rows, batchSize).map(batchRows => this.executeBatch(job, batchRows, wait))).then(result => result.flat());
135
+ }
136
+ executeBatch(job, rows, wait) {
137
+ return new Promise((resolve, reject) => {
138
+ const batch = job.createBatch();
139
+ batch.on('error', e => {
140
+ if (e.message.startsWith('Polling time out'))
141
+ job.emit('error', e);
142
+ reject(e);
143
+ });
144
+ batch.on('queue', batchInfo => {
145
+ batch.check().then(result => {
146
+ if (result.state === 'Failed') {
147
+ reject(result.stateMessage);
148
+ }
149
+ else if (wait) {
150
+ batch.poll(5000, wait * 60000);
151
+ }
152
+ else {
153
+ resolve([]);
154
+ }
155
+ });
156
+ });
157
+ batch.on('response', resolve);
158
+ batch.execute(rows, error => error && reject(error));
159
+ });
160
+ }
94
161
  saveCsv(file, rows) {
95
- csv.stringify(rows, { header: true })
96
- .pipe(fs.createWriteStream(file));
162
+ csv.writeToPath(file, rows, { headers: true });
97
163
  }
98
164
  loadScript(file) {
99
165
  return convert_2.loadScript(file);
100
166
  }
101
167
  async getFieldTypes(sobject) {
102
- const objectInfo = await this.org.getConnection().describe(sobject);
168
+ const conn = this.org.getConnection();
169
+ const objectInfo = await conn.describe(sobject);
103
170
  return objectInfo.fields.reduce((info, { name, type }) => Object.assign(info, { [name]: type }), {});
104
171
  }
105
172
  async createJob(sobject, options) {
106
- const job = this.org.getConnection().bulk.createJob(sobject, 'upsert', options);
173
+ const conn = this.org.getConnection();
174
+ const job = conn.bulk.createJob(sobject, 'upsert', options);
107
175
  await job.on('error', e => { throw e; }).open();
108
176
  return job;
109
177
  }
@@ -124,14 +192,17 @@ UpsertCommand.flagsConfig = {
124
192
  object: command_1.flags.string({ char: 'o', required: true, description: 'the sObject name to upsert' }),
125
193
  externalid: command_1.flags.string({ char: 'i', required: true, default: 'Id', description: 'the column name of the external ID' }),
126
194
  // csv settings
127
- csvfile: command_1.flags.filepath({ char: 'f', required: true, description: 'the path of the CSV file that defines the records to upsert' }),
195
+ csvfile: command_1.flags.filepath({ char: 'f', required: true, description: 'the CSV file path that defines the records to upsert' }),
196
+ resultfile: command_1.flags.filepath({ char: 'r', description: 'the CSV file path for writing the upsert results' }),
128
197
  encoding: csvFlags.encoding,
129
198
  delimiter: csvFlags.delimiter,
199
+ quote: csvFlags.quote,
200
+ skiplines: csvFlags.skiplines,
201
+ trim: csvFlags.trim,
130
202
  mapping: csvFlags.mapping,
131
203
  converter: csvFlags.converter,
132
204
  setnull: command_1.flags.boolean({ description: 'set blank values as null values during upsert operations (default: empty field values are ignored)' }),
133
- save: command_1.flags.boolean({ description: 'output converted.csv file' }),
134
- saveonly: command_1.flags.boolean({ description: 'output converted.csv file and skip upsert for debugging' }),
205
+ convertonly: command_1.flags.boolean({ description: 'output converted.csv file and skip upsert for debugging' }),
135
206
  // job settings
136
207
  concurrencymode: command_1.flags.string({ default: 'Parallel', description: 'the concurrency mode (Parallel or Serial) for the job' }),
137
208
  assignmentruleid: command_1.flags.string({ description: 'the ID of a specific assignment rule to run for a case or a lead.' }),
@@ -1 +1 @@
1
- {"version":3,"file":"upsert.js","sourceRoot":"","sources":["../../../../../src/commands/kit/data/bulk/upsert.ts"],"names":[],"mappings":";;AAAA,iDAAyD;AAEzD,2BAA2B;AAC3B,+BAA+B;AAC/B,+BAA+B;AAC/B,6BAA6B;AAE7B,6CAA0C;AAC1C,4CAA+C;AAC/C,4CAAsD;AAEtD,oCAAoC;AACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACjE,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,gCAAgC,CAAC,CAAC,CAAC;AAChF,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAE/D,SAAS,mBAAmB,CAAC,GAAG,EAAE,MAAO;IACvC,IAAI,CAAC,GAAG;QAAE,OAAO,GAAG,CAAC;IACrB,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACrB,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,GAAG;IACjB,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,YAAY,CAAC;IACvD,QAAQ,EAAE,mBAA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e;IACf,eAAe,EAAE,eAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,uDAAuD,EAAE,CAAC;IAC5H,gBAAgB,EAAE,eAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,mEAAmE,EAAE,CAAC;IACpH,SAAS,EAAE,eAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;IACrH,IAAI,EAAE,eAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,WAAW,EAAE,yFAAyF,EAAE,CAAC;CACnJ,CAAC"}
@@ -12,6 +12,9 @@ export default class CsvConvertCommand extends SfdxCommand {
12
12
  outputfile: flags.Discriminated<flags.String>;
13
13
  encoding: flags.Discriminated<flags.String>;
14
14
  delimiter: flags.Discriminated<flags.String>;
15
+ quote: flags.Discriminated<flags.String>;
16
+ skiplines: flags.Discriminated<flags.Number>;
17
+ trim: flags.Discriminated<flags.Boolean<boolean>>;
15
18
  mapping: flags.Discriminated<flags.String>;
16
19
  converter: flags.Discriminated<flags.String>;
17
20
  };
@@ -22,6 +25,9 @@ export default class CsvConvertCommand extends SfdxCommand {
22
25
  export declare function parseCsv(input: Readable, options?: {
23
26
  encoding?: string;
24
27
  delimiter?: string;
28
+ quote?: string;
29
+ skiplines?: number;
30
+ trim?: boolean;
25
31
  mapping?: JsonMap;
26
32
  convert?: (row: JsonMap) => JsonMap | null | undefined;
27
33
  }): Promise<JsonMap[]>;
@@ -2,20 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.columnMapper = exports.loadScript = exports.parseCsv = void 0;
4
4
  const command_1 = require("@salesforce/command");
5
- const csv = require("csv");
5
+ const csv = require("fast-csv");
6
6
  const fs = require("fs-extra");
7
7
  const iconv_lite_1 = require("iconv-lite");
8
8
  const path = require("path");
9
9
  const stream_1 = require("stream");
10
10
  class CsvConvertCommand extends command_1.SfdxCommand {
11
11
  async run() {
12
- const { inputfile, outputfile, mapping, converter, encoding, delimiter } = this.flags;
12
+ const { inputfile, outputfile, mapping, converter, encoding, delimiter, quote, skiplines, trim } = this.flags;
13
13
  const mappingJson = mapping ? (await fs.readJson(mapping)) : undefined;
14
14
  const convert = converter ? this.loadConverter(converter) : undefined;
15
15
  const input = inputfile ? fs.createReadStream(inputfile) : process.stdin;
16
16
  const rows = await parseCsv(input, {
17
17
  encoding,
18
18
  delimiter,
19
+ quote,
20
+ skiplines,
21
+ trim,
19
22
  mapping: mappingJson,
20
23
  convert
21
24
  });
@@ -26,7 +29,7 @@ class CsvConvertCommand extends command_1.SfdxCommand {
26
29
  return rows;
27
30
  }
28
31
  writeCsv(rows, stream) {
29
- csv.stringify(rows, { header: true }).pipe(stream);
32
+ csv.writeToStream(stream, rows, { headers: true });
30
33
  }
31
34
  loadConverter(file) {
32
35
  return loadScript(file).convert;
@@ -45,36 +48,46 @@ CsvConvertCommand.flagsConfig = {
45
48
  outputfile: command_1.flags.filepath({ char: 'o', description: 'the path of the output CSV file (default: standard output)' }),
46
49
  encoding: command_1.flags.string({ char: 'e', default: 'utf8', description: 'the input CSV file encoding' }),
47
50
  delimiter: command_1.flags.string({ char: 'd', default: ',', description: 'the input CSV file delimiter' }),
51
+ quote: command_1.flags.string({ char: 'q', default: '"', description: 'the input CSV file quote character' }),
52
+ skiplines: command_1.flags.integer({ default: 0, description: 'the number of lines to skip' }),
53
+ trim: command_1.flags.boolean({ description: 'trim all white space from columns' }),
48
54
  mapping: command_1.flags.filepath({ char: 'm', description: 'the path of the JSON file that defines CSV column mappings' }),
49
55
  converter: command_1.flags.filepath({ char: 'c', description: 'the path of the script to convert CSV rows' })
50
56
  };
51
- async function parseCsv(input, options) {
52
- const { encoding, delimiter, mapping, convert } = options !== null && options !== void 0 ? options : {};
57
+ function parseCsv(input, options) {
58
+ const { encoding, delimiter, quote, skiplines, trim, mapping, convert } = options !== null && options !== void 0 ? options : {};
53
59
  return new Promise((resolve, reject) => {
54
- const reader = (!encoding || encoding === 'utf8') ? input : input.pipe(iconv_lite_1.decodeStream(encoding));
55
60
  const mapper = mapping ? columnMapper(mapping) : undefined;
61
+ let lines = 2;
56
62
  const rows = [];
57
63
  const parser = csv.parse({
58
- columns: true,
59
- skip_empty_lines: true,
60
- skip_lines_with_empty_values: true,
61
- delimiter: delimiter === '\\t' ? '\t' : delimiter,
62
- on_record: (row, { lines }) => {
63
- try {
64
- if (mapper)
65
- row = mapper(row);
66
- if (convert)
67
- row = convert(row);
68
- if (row)
69
- rows.push(row);
70
- return row;
71
- }
72
- catch (e) {
73
- throw new Error(`A error occurred in csv file at line ${lines}: ${e.message}\ndata: ${JSON.stringify(row)}`);
74
- }
64
+ headers: true,
65
+ ignoreEmpty: true,
66
+ delimiter: delimiter === '\\t' ? '\t' : (delimiter || ','),
67
+ quote: quote !== null && quote !== void 0 ? quote : '"',
68
+ skipLines: skiplines,
69
+ trim
70
+ }).on('data', row => {
71
+ try {
72
+ if (mapper)
73
+ row = mapper(row);
74
+ if (convert)
75
+ row = convert(row);
76
+ if (row)
77
+ rows.push(row);
78
+ lines++;
79
+ }
80
+ catch (e) {
81
+ throw new Error(`A error occurred in csv file at line ${lines}: ${e.message}\ndata: ${JSON.stringify(row)}`);
75
82
  }
76
83
  });
77
- stream_1.pipeline(reader, parser, e => e ? reject(e) : resolve(rows));
84
+ const callback = e => e ? reject(e) : resolve(rows);
85
+ if (!encoding || encoding === 'utf8') {
86
+ stream_1.pipeline(input, parser, callback);
87
+ }
88
+ else {
89
+ stream_1.pipeline(input, iconv_lite_1.decodeStream(encoding), parser, callback);
90
+ }
78
91
  });
79
92
  }
80
93
  exports.parseCsv = parseCsv;
@@ -1 +1 @@
1
- {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../../../src/commands/kit/data/csv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AQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;SACnC;aAAM;YACL,iBAAQ,CAAC,KAAK,EAAE,yBAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;SAC3D;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AA3CD,4BA2CC;AAED,SAAgB,UAAU,CAAC,IAAI;IAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACzE,OAAO,MAAM,CAAC;AAChB,CAAC;AAJD,gCAIC;AAED,SAAgB,YAAY,CAAC,OAAO;IAClC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,GAAG,CAAC,EAAE;QACX,MAAM,MAAM,GAAG,EAAE,CAAC;QAClB,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE;YACrB,MAAM,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;YACzB,IAAI,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,gBAAgB,CAAC,CAAC;YACzE,MAAM,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;SACxB;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAXD,oCAWC"}
@@ -0,0 +1,13 @@
1
+ import { flags, SfdxCommand } from '@salesforce/command';
2
+ export default class ScriptExecuteCommand extends SfdxCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static aliases: string[];
6
+ static strict: boolean;
7
+ protected static requiresUsername: boolean;
8
+ protected static requiresProject: boolean;
9
+ protected static flagsConfig: {
10
+ file: flags.Discriminated<flags.String>;
11
+ };
12
+ run(): Promise<void>;
13
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("@salesforce/command");
4
+ const fs = require("fs-extra");
5
+ const repl = require("repl");
6
+ class ScriptExecuteCommand extends command_1.SfdxCommand {
7
+ async run() {
8
+ const { file } = this.flags;
9
+ if (file) {
10
+ const script = fs.readFileSync(file).toString('utf8');
11
+ const asyncFunction = Object.getPrototypeOf(async () => { }).constructor;
12
+ new asyncFunction('context', 'conn', script)(this, this.org.getConnection());
13
+ }
14
+ else {
15
+ this.ux.log('Starting sfdx REPL mode');
16
+ this.ux.log('Available variables');
17
+ this.ux.log(' conn: jsforce Connection');
18
+ this.ux.log(' context: SfdxCommand');
19
+ this.ux.log('Type .exit or Press Ctrl+D to exit the REPL');
20
+ const replServer = repl.start('> ');
21
+ replServer.context.context = this;
22
+ replServer.context.conn = this.org.getConnection();
23
+ return new Promise(resolve => replServer.on('exit', () => resolve()));
24
+ }
25
+ }
26
+ }
27
+ exports.default = ScriptExecuteCommand;
28
+ ScriptExecuteCommand.description = [
29
+ 'execute Node.js scripts in SfdxCommand context',
30
+ 'Available variables in Node.js scripts',
31
+ ' conn: jsforce Connection',
32
+ ' context: SfdxCommand'
33
+ ].join('\n');
34
+ ScriptExecuteCommand.examples = [
35
+ '$ sfdx kit:script -f ./path/to/script.js',
36
+ '$ sfdx kit:script:execute',
37
+ "> await conn.query('SELECT Id, Name FROM Account LIMIT 1')"
38
+ ];
39
+ ScriptExecuteCommand.aliases = ['kit:script'];
40
+ ScriptExecuteCommand.strict = false;
41
+ ScriptExecuteCommand.requiresUsername = true;
42
+ ScriptExecuteCommand.requiresProject = false;
43
+ ScriptExecuteCommand.flagsConfig = {
44
+ file: command_1.flags.filepath({ char: 'f', description: 'the path of the Node.js script file to execute' })
45
+ };
46
+ //# sourceMappingURL=execute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../../src/commands/k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;AA7CH,uCA8CC;AA7Ce,gCAAW,GAAG;IAC1B,gDAAgD;IAChD,wCAAwC;IACxC,4BAA4B;IAC5B,wBAAwB;CACzB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEC,6BAAQ,GAAG;IACvB,0CAA0C;IAC1C,2BAA2B;IAC3B,4DAA4D;CAC7D,CAAC;AAEY,4BAAO,GAAG,CAAC,YAAY,CAAC,CAAC;AACzB,2BAAM,GAAG,KAAK,CAAC;AACZ,qCAAgB,GAAG,IAAI,CAAC;AACxB,oCAAe,GAAG,KAAK,CAAC;AAExB,gCAAW,GAAG;IAC7B,IAAI,EAAE,eAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,gDAAgD,EAAE,CAAC;CACnG,CAAC"}
@@ -1 +1 @@
1
- {"version":"0.1.1","commands":{"kit:data:bulk:upsert":{"id":"kit:data:bulk:upsert","description":"bulk upsert records from a CSV file\nUpsert records using Bulk API and returns a job ID and a batch ID. Use these IDs to check job status with data:bulk:status.\nFor information about CSV file formats, see [Prepare CSV Files](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_csv_preparing.htm) in the Bulk API Developer Guide.","usage":"<%= command.id %> -o <string> -i <string> -f <filepath> [-e <string>] [-d <string>] [-m <filepath>] [-c <filepath>] [--setnull] [--save] [--saveonly] [--concurrencymode <string>] [--assignmentruleid <string>] [-s <integer>] [-w <integer>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx kit:data:bulk:upsert -o Account -f ./path/to/Account.csv -m ./path/to/mapping.json","$ sfdx kit:data:bulk:upsert -o MyObject__c -f ./path/to/MyObject__c.csv -c ./path/to/convert.js -i MyExternalId__c -w 10"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"object":{"name":"object","type":"option","char":"o","description":"the sObject name to upsert","required":true},"externalid":{"name":"externalid","type":"option","char":"i","description":"the column name of the external ID","required":true,"default":"Id"},"csvfile":{"name":"csvfile","type":"option","char":"f","description":"the path of the CSV file that defines the records to upsert","required":true},"encoding":{"name":"encoding","type":"option","char":"e","description":"the input CSV file encoding","default":"utf8"},"delimiter":{"name":"delimiter","type":"option","char":"d","description":"the input CSV file delimiter","default":","},"mapping":{"name":"mapping","type":"option","char":"m","description":"the path of the JSON file that defines CSV column mappings"},"converter":{"name":"converter","type":"option","char":"c","description":"the path of the script to convert CSV rows"},"setnull":{"name":"setnull","type":"boolean","description":"set blank values as null values during upsert operations (default: empty field values are ignored)","allowNo":false},"save":{"name":"save","type":"boolean","description":"output converted.csv file","allowNo":false},"saveonly":{"name":"saveonly","type":"boolean","description":"output converted.csv file and skip upsert for debugging","allowNo":false},"concurrencymode":{"name":"concurrencymode","type":"option","description":"the concurrency mode (Parallel or Serial) for the job","default":"Parallel"},"assignmentruleid":{"name":"assignmentruleid","type":"option","description":"the ID of a specific assignment rule to run for a case or a lead."},"batchsize":{"name":"batchsize","type":"option","char":"s","description":"the batch size of the job","default":10000},"wait":{"name":"wait","type":"option","char":"w","description":"the number of minutes to wait for the command to complete before displaying the results"}},"args":[]},"kit:data:csv:convert":{"id":"kit:data:csv:convert","description":"convert CSV data using column mapping file or Node.js script","usage":"<%= command.id %> [-f <filepath>] [-o <filepath>] [-e <string>] [-d <string>] [-m <filepath>] [-c <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx kit:data:csv:convert -f ./path/to/input.csv -m ./path/to/mapping.json","$ sfdx kit:data:csv:convert -f ./path/to/input.csv -o ./path/to/output.csv -c ./path/to/convert.js -e cp932 -d :"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"inputfile":{"name":"inputfile","type":"option","char":"f","description":"the path of the input CSV file (default: standard input)"},"outputfile":{"name":"outputfile","type":"option","char":"o","description":"the path of the output CSV file (default: standard output)"},"encoding":{"name":"encoding","type":"option","char":"e","description":"the input CSV file encoding","default":"utf8"},"delimiter":{"name":"delimiter","type":"option","char":"d","description":"the input CSV file delimiter","default":","},"mapping":{"name":"mapping","type":"option","char":"m","description":"the path of the JSON file that defines CSV column mappings"},"converter":{"name":"converter","type":"option","char":"c","description":"the path of the script to convert CSV rows"}},"args":[]},"kit:layout:assignments:deploy":{"id":"kit:layout:assignments:deploy","description":"deploy page layout assignments from JSON file","usage":"<%= command.id %> -f <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx kit:layout:assignments:deploy","$ sfdx kit:layout:assignments:deploy -f config/layout-assignments.scratch.json","$ sfdx kit:layout:assignments:deploy -u me@my.org -f config/layout-assignments.sandbox.json"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"file":{"name":"file","type":"option","char":"f","description":"input file path","required":true,"default":"config/layout-assignments.json"}},"args":[]},"kit:layout:assignments:retrieve":{"id":"kit:layout:assignments:retrieve","description":"retrieve page layout assignments and save to JSON file","usage":"<%= command.id %> -f <string> [-p <string>] [-o <string>] [--merge] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx kit:layout:assignments:retrieve","$ sfdx kit:layout:assignments:retrieve -p Admin,Standard,StandardAul -o Account,CustomObject__c -f config/layout-assignments.scratch.json","$ sfdx kit:layout:assignments:retrieve -u me@my.org -f config/layout-assignments.sandbox.json"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"file":{"name":"file","type":"option","char":"f","description":"output file path","required":true,"default":"config/layout-assignments.json"},"profile":{"name":"profile","type":"option","char":"p","description":"comma separated profile names to retrieve (default: all profiles)","required":false},"object":{"name":"object","type":"option","char":"o","description":"comma separated object names to retrieve (default: objects which have multiple layouts)","required":false},"merge":{"name":"merge","type":"boolean","description":"merge retrieved configurations with existing file","required":false,"allowNo":false}},"args":[]}}}
1
+ {"version":"0.1.5","commands":{"kit:script:execute":{"id":"kit:script:execute","description":"execute Node.js scripts in SfdxCommand context\nAvailable variables in Node.js scripts\n conn: jsforce Connection\n context: SfdxCommand","usage":"<%= command.id %> [-f <filepath>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":["kit:script"],"examples":["$ sfdx kit:script -f ./path/to/script.js","$ sfdx kit:script:execute","> await conn.query('SELECT Id, Name FROM Account LIMIT 1')"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"file":{"name":"file","type":"option","char":"f","description":"the path of the Node.js script file to execute"}},"args":[]},"kit:data:bulk:upsert":{"id":"kit:data:bulk:upsert","description":"bulk upsert records from a CSV file\nUpsert records using Bulk API and returns a job ID and a batch ID. Use these IDs to check job status with data:bulk:status.\nFor information about CSV file formats, see [Prepare CSV Files](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_csv_preparing.htm) in the Bulk API Developer Guide.","usage":"<%= command.id %> -o <string> -i <string> -f <filepath> [-r <filepath>] [-e <string>] [-d <string>] [-q <string>] [--skiplines <integer>] [--trim] [-m <filepath>] [-c <filepath>] [--setnull] [--convertonly] [--concurrencymode <string>] [--assignmentruleid <string>] [-s <integer>] [-w <integer>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx kit:data:bulk:upsert -o Account -f ./path/to/Account.csv -m ./path/to/mapping.json","$ sfdx kit:data:bulk:upsert -o MyObject__c -f ./path/to/MyObject__c.csv -c ./path/to/convert.js -i MyExternalId__c -w 10"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"object":{"name":"object","type":"option","char":"o","description":"the sObject name to upsert","required":true},"externalid":{"name":"externalid","type":"option","char":"i","description":"the column name of the external ID","required":true,"default":"Id"},"csvfile":{"name":"csvfile","type":"option","char":"f","description":"the CSV file path that defines the records to upsert","required":true},"resultfile":{"name":"resultfile","type":"option","char":"r","description":"the CSV file path for writing the upsert results"},"encoding":{"name":"encoding","type":"option","char":"e","description":"the input CSV file encoding","default":"utf8"},"delimiter":{"name":"delimiter","type":"option","char":"d","description":"the input CSV file delimiter","default":","},"quote":{"name":"quote","type":"option","char":"q","description":"the input CSV file quote character","default":"\""},"skiplines":{"name":"skiplines","type":"option","description":"the number of lines to skip","default":0},"trim":{"name":"trim","type":"boolean","description":"trim all white space from columns","allowNo":false},"mapping":{"name":"mapping","type":"option","char":"m","description":"the path of the JSON file that defines CSV column mappings"},"converter":{"name":"converter","type":"option","char":"c","description":"the path of the script to convert CSV rows"},"setnull":{"name":"setnull","type":"boolean","description":"set blank values as null values during upsert operations (default: empty field values are ignored)","allowNo":false},"convertonly":{"name":"convertonly","type":"boolean","description":"output converted.csv file and skip upsert for debugging","allowNo":false},"concurrencymode":{"name":"concurrencymode","type":"option","description":"the concurrency mode (Parallel or Serial) for the job","default":"Parallel"},"assignmentruleid":{"name":"assignmentruleid","type":"option","description":"the ID of a specific assignment rule to run for a case or a lead."},"batchsize":{"name":"batchsize","type":"option","char":"s","description":"the batch size of the job","default":10000},"wait":{"name":"wait","type":"option","char":"w","description":"the number of minutes to wait for the command to complete before displaying the results"}},"args":[]},"kit:data:csv:convert":{"id":"kit:data:csv:convert","description":"convert CSV data using column mapping file or Node.js script","usage":"<%= command.id %> [-f <filepath>] [-o <filepath>] [-e <string>] [-d <string>] [-q <string>] [--skiplines <integer>] [--trim] [-m <filepath>] [-c <filepath>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx kit:data:csv:convert -f ./path/to/input.csv -m ./path/to/mapping.json","$ sfdx kit:data:csv:convert -f ./path/to/input.csv -o ./path/to/output.csv -c ./path/to/convert.js -e cp932 -d :"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"inputfile":{"name":"inputfile","type":"option","char":"f","description":"the path of the input CSV file (default: standard input)"},"outputfile":{"name":"outputfile","type":"option","char":"o","description":"the path of the output CSV file (default: standard output)"},"encoding":{"name":"encoding","type":"option","char":"e","description":"the input CSV file encoding","default":"utf8"},"delimiter":{"name":"delimiter","type":"option","char":"d","description":"the input CSV file delimiter","default":","},"quote":{"name":"quote","type":"option","char":"q","description":"the input CSV file quote character","default":"\""},"skiplines":{"name":"skiplines","type":"option","description":"the number of lines to skip","default":0},"trim":{"name":"trim","type":"boolean","description":"trim all white space from columns","allowNo":false},"mapping":{"name":"mapping","type":"option","char":"m","description":"the path of the JSON file that defines CSV column mappings"},"converter":{"name":"converter","type":"option","char":"c","description":"the path of the script to convert CSV rows"}},"args":[]},"kit:layout:assignments:deploy":{"id":"kit:layout:assignments:deploy","description":"deploy page layout assignments from JSON file","usage":"<%= command.id %> -f <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx kit:layout:assignments:deploy","$ sfdx kit:layout:assignments:deploy -f config/layout-assignments.scratch.json","$ sfdx kit:layout:assignments:deploy -u me@my.org -f config/layout-assignments.sandbox.json"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"file":{"name":"file","type":"option","char":"f","description":"input file path","required":true,"default":"config/layout-assignments.json"}},"args":[]},"kit:layout:assignments:retrieve":{"id":"kit:layout:assignments:retrieve","description":"retrieve page layout assignments and save to JSON file","usage":"<%= command.id %> -f <string> [-p <string>] [-o <string>] [--merge] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"@kitalive/sfdx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx kit:layout:assignments:retrieve","$ sfdx kit:layout:assignments:retrieve -p Admin,Standard,StandardAul -o Account,CustomObject__c -f config/layout-assignments.scratch.json","$ sfdx kit:layout:assignments:retrieve -u me@my.org -f config/layout-assignments.sandbox.json"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"file":{"name":"file","type":"option","char":"f","description":"output file path","required":true,"default":"config/layout-assignments.json"},"profile":{"name":"profile","type":"option","char":"p","description":"comma separated profile names to retrieve (default: all profiles)","required":false},"object":{"name":"object","type":"option","char":"o","description":"comma separated object names to retrieve (default: objects which have multiple layouts)","required":false},"merge":{"name":"merge","type":"boolean","description":"merge retrieved configurations with existing file","required":false,"allowNo":false}},"args":[]}}}
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "name": "@kitalive/sfdx-plugin",
3
3
  "description": "Kitalive SFDX plugin",
4
- "version": "0.1.1",
4
+ "version": "0.1.5",
5
5
  "author": "Akihiro Ono",
6
6
  "bugs": "https://github.com/Kitalive-Inc/sfdx-plugin/issues",
7
7
  "dependencies": {
8
8
  "@oclif/command": "^1",
9
9
  "@oclif/config": "^1",
10
10
  "@oclif/errors": "^1",
11
- "@salesforce/command": "^2",
12
- "@salesforce/core": "^2",
13
- "csv": "^5.3.2",
11
+ "@salesforce/command": "^3.1.3",
12
+ "@salesforce/core": "^2.23.5",
14
13
  "dayjs": "^1.10.4",
14
+ "fast-csv": "^4.3.6",
15
15
  "fs-extra": "^9.1.0",
16
16
  "iconv-lite": "^0.6.2",
17
17
  "jsforce": "^1.10.1",
18
- "salesforce-alm": "^51.3.0",
19
18
  "tslib": "^1"
20
19
  },
21
20
  "devDependencies": {
@@ -25,14 +24,13 @@
25
24
  "@salesforce/dev-config": "1.4.1",
26
25
  "@salesforce/ts-sinon": "^1.3.0",
27
26
  "@types/chai": "^4",
27
+ "@types/jsforce": "^1.9.29",
28
28
  "@types/mocha": "^5",
29
- "@types/node": "^10",
30
29
  "chai": "^4",
31
30
  "globby": "^8",
32
31
  "mocha": "^5",
33
32
  "nyc": "^14",
34
33
  "ts-node": "^8",
35
- "tslint": "^5",
36
34
  "typescript": "^4.2.3"
37
35
  },
38
36
  "engines": {