@sharinpix/sharinpix-sf-cli 1.10.0 → 1.12.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/README.md +128 -9
- package/lib/commands/sharinpix/config/pull.d.ts +18 -0
- package/lib/commands/sharinpix/config/pull.js +60 -0
- package/lib/commands/sharinpix/config/pull.js.map +1 -0
- package/lib/commands/sharinpix/config/push.d.ts +18 -0
- package/lib/commands/sharinpix/config/push.js +59 -0
- package/lib/commands/sharinpix/config/push.js.map +1 -0
- package/lib/commands/sharinpix/form/csv2json.js +54 -61
- package/lib/commands/sharinpix/form/csv2json.js.map +1 -1
- package/lib/commands/sharinpix/form/json2csv.js +10 -13
- package/lib/commands/sharinpix/form/json2csv.js.map +1 -1
- package/lib/commands/sharinpix/form/pull.js +6 -2
- package/lib/commands/sharinpix/form/pull.js.map +1 -1
- package/lib/commands/sharinpix/pull.d.ts +1 -0
- package/lib/commands/sharinpix/pull.js +7 -1
- package/lib/commands/sharinpix/pull.js.map +1 -1
- package/lib/commands/sharinpix/push.d.ts +1 -0
- package/lib/commands/sharinpix/push.js +7 -1
- package/lib/commands/sharinpix/push.js.map +1 -1
- package/lib/commands/sharinpix/settings.d.ts +10 -0
- package/lib/commands/sharinpix/settings.js +24 -0
- package/lib/commands/sharinpix/settings.js.map +1 -0
- package/lib/helpers/form/elementKeys.d.ts +3 -0
- package/lib/helpers/form/elementKeys.js +74 -0
- package/lib/helpers/form/elementKeys.js.map +1 -0
- package/lib/helpers/form/transformers.d.ts +9 -0
- package/lib/helpers/form/transformers.js +84 -0
- package/lib/helpers/form/transformers.js.map +1 -0
- package/lib/helpers/utils.js +4 -17
- package/lib/helpers/utils.js.map +1 -1
- package/messages/sharinpix.config.pull.md +37 -0
- package/messages/sharinpix.config.push.md +37 -0
- package/messages/sharinpix.form.pull.md +2 -2
- package/messages/sharinpix.settings.md +22 -0
- package/oclif.lock +1412 -2051
- package/oclif.manifest.json +186 -3
- package/package.json +17 -11
- package/lib/helpers/form/elementKeyOrder.d.ts +0 -1
- package/lib/helpers/form/elementKeyOrder.js +0 -53
- package/lib/helpers/form/elementKeyOrder.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@sharinpix/sharinpix-sf-cli) [](https://npmjs.org/package/@sharinpix/sharinpix-sf-cli) [](https://raw.githubusercontent.com/sharinpix/sharinpix-sf-cli/main/LICENSE.txt)
|
|
4
4
|
|
|
5
|
-
The SharinPix Salesforce CLI plugin provides tools to interact with SharinPix form templates and permissions in your Salesforce orgs. This plugin allows you to pull and push form templates and permissions from/to your Salesforce org, saving them as local JSON files for version control and deployment management.
|
|
5
|
+
The SharinPix Salesforce CLI plugin provides tools to interact with SharinPix organization configuration, form templates, and permissions in your Salesforce orgs. This plugin allows you to pull and push configs, form templates, and permissions from/to your Salesforce org, saving them as local JSON files for version control and deployment management.
|
|
6
6
|
|
|
7
7
|
## Learn about `sf` plugins
|
|
8
8
|
|
|
@@ -28,7 +28,7 @@ For cross clouds commands, e.g. `sf env list`, we utilize [oclif hooks](https://
|
|
|
28
28
|
|
|
29
29
|
This plugin includes sample hooks in the [src/hooks directory](src/hooks). You'll just need to add the appropriate logic. You can also delete any of the hooks if they aren't required for your plugin.
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
## About this plugin
|
|
32
32
|
|
|
33
33
|
This plugin is bundled with the [Salesforce CLI](https://developer.salesforce.com/tools/sfdxcli). For more information on the CLI, read the [getting started guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm).
|
|
34
34
|
|
|
@@ -40,15 +40,24 @@ We always recommend using the latest version of these commands bundled with the
|
|
|
40
40
|
sf org login web
|
|
41
41
|
sf plugins install @sharinpix/sharinpix-sf-cli
|
|
42
42
|
|
|
43
|
-
# Pull
|
|
43
|
+
# Pull all (configs, forms, and permissions) from Salesforce
|
|
44
|
+
sf sharinpix pull -o yourusername@salesforce.com
|
|
45
|
+
|
|
46
|
+
# Push all (configs, forms, and permissions) to Salesforce
|
|
47
|
+
sf sharinpix push -o yourusername@salesforce.com
|
|
48
|
+
|
|
49
|
+
# Pull individual components
|
|
50
|
+
sf sharinpix config pull -o yourusername@salesforce.com
|
|
44
51
|
sf sharinpix form pull -o yourusername@salesforce.com
|
|
45
52
|
sf sharinpix permission pull -o yourusername@salesforce.com
|
|
46
53
|
|
|
47
|
-
# Push
|
|
54
|
+
# Push individual components
|
|
55
|
+
sf sharinpix config push -o yourusername@salesforce.com
|
|
48
56
|
sf sharinpix form push -o yourusername@salesforce.com
|
|
49
57
|
sf sharinpix permission push -o yourusername@salesforce.com
|
|
50
58
|
|
|
51
|
-
# Push with deletion of orphaned records (
|
|
59
|
+
# Push with deletion of orphaned records (for forms and permissions only)
|
|
60
|
+
sf sharinpix push -o yourusername@salesforce.com --delete
|
|
52
61
|
sf sharinpix form push -o yourusername@salesforce.com --delete
|
|
53
62
|
sf sharinpix permission push -o yourusername@salesforce.com -d
|
|
54
63
|
```
|
|
@@ -92,6 +101,8 @@ To use your plugin, run using the local `./bin/dev` or `./bin/dev.cmd` file.
|
|
|
92
101
|
|
|
93
102
|
```bash
|
|
94
103
|
# Run using local run file.
|
|
104
|
+
./bin/dev sharinpix pull --target-org myorg@example.com
|
|
105
|
+
./bin/dev sharinpix config pull --target-org myorg@example.com
|
|
95
106
|
./bin/dev sharinpix form pull --target-org myorg@example.com
|
|
96
107
|
./bin/dev sharinpix permission pull --target-org myorg@example.com
|
|
97
108
|
```
|
|
@@ -127,6 +138,8 @@ Both `form push` and `permission push` commands support a `--delete/-d` flag tha
|
|
|
127
138
|
## Commands
|
|
128
139
|
|
|
129
140
|
<!-- commands -->
|
|
141
|
+
* [`sf sharinpix config pull`](#sf-sharinpix-config-pull)
|
|
142
|
+
* [`sf sharinpix config push`](#sf-sharinpix-config-push)
|
|
130
143
|
* [`sf sharinpix form csv2json`](#sf-sharinpix-form-csv2json)
|
|
131
144
|
* [`sf sharinpix form json2csv`](#sf-sharinpix-form-json2csv)
|
|
132
145
|
* [`sf sharinpix form pull`](#sf-sharinpix-form-pull)
|
|
@@ -135,6 +148,80 @@ Both `form push` and `permission push` commands support a `--delete/-d` flag tha
|
|
|
135
148
|
* [`sf sharinpix permission push`](#sf-sharinpix-permission-push)
|
|
136
149
|
* [`sf sharinpix pull`](#sf-sharinpix-pull)
|
|
137
150
|
* [`sf sharinpix push`](#sf-sharinpix-push)
|
|
151
|
+
* [`sf sharinpix settings`](#sf-sharinpix-settings)
|
|
152
|
+
|
|
153
|
+
## `sf sharinpix config pull`
|
|
154
|
+
|
|
155
|
+
Pull organization config from SharinPix API.
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
USAGE
|
|
159
|
+
$ sf sharinpix config pull -o <value> [--json] [--flags-dir <value>]
|
|
160
|
+
|
|
161
|
+
FLAGS
|
|
162
|
+
-o, --org=<value> (required) The Salesforce org to authenticate with.
|
|
163
|
+
|
|
164
|
+
GLOBAL FLAGS
|
|
165
|
+
--flags-dir=<value> Import flag values from a directory.
|
|
166
|
+
--json Format output as json.
|
|
167
|
+
|
|
168
|
+
DESCRIPTION
|
|
169
|
+
Pull organization config from SharinPix API.
|
|
170
|
+
|
|
171
|
+
Downloads the organization configuration from the SharinPix API and saves it to a local JSON file. This command
|
|
172
|
+
connects to your Salesforce org to obtain an authentication token, then fetches the config from the SharinPix API
|
|
173
|
+
endpoint.
|
|
174
|
+
|
|
175
|
+
EXAMPLES
|
|
176
|
+
Pull organization config using the default org:
|
|
177
|
+
|
|
178
|
+
$ sf sharinpix config pull
|
|
179
|
+
|
|
180
|
+
Pull organization config from a specific org:
|
|
181
|
+
|
|
182
|
+
$ sf sharinpix config pull --target-org myorg@example.com
|
|
183
|
+
|
|
184
|
+
FLAG DESCRIPTIONS
|
|
185
|
+
-o, --org=<value> The Salesforce org to authenticate with.
|
|
186
|
+
|
|
187
|
+
The Salesforce org used to obtain the authentication token for accessing the SharinPix API.
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## `sf sharinpix config push`
|
|
191
|
+
|
|
192
|
+
Push organization config to SharinPix API.
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
USAGE
|
|
196
|
+
$ sf sharinpix config push -o <value> [--json] [--flags-dir <value>]
|
|
197
|
+
|
|
198
|
+
FLAGS
|
|
199
|
+
-o, --org=<value> (required) The Salesforce org to authenticate with.
|
|
200
|
+
|
|
201
|
+
GLOBAL FLAGS
|
|
202
|
+
--flags-dir=<value> Import flag values from a directory.
|
|
203
|
+
--json Format output as json.
|
|
204
|
+
|
|
205
|
+
DESCRIPTION
|
|
206
|
+
Push organization config to SharinPix API.
|
|
207
|
+
|
|
208
|
+
Uploads the organization configuration from a local JSON file to the SharinPix API. This command connects to your
|
|
209
|
+
Salesforce org to obtain an authentication token, then pushes the config to the SharinPix API endpoint.
|
|
210
|
+
|
|
211
|
+
EXAMPLES
|
|
212
|
+
Push organization config using the default org:
|
|
213
|
+
|
|
214
|
+
$ sf sharinpix config push
|
|
215
|
+
|
|
216
|
+
Push organization config to a specific org:
|
|
217
|
+
|
|
218
|
+
$ sf sharinpix config push --target-org myorg@example.com
|
|
219
|
+
|
|
220
|
+
FLAG DESCRIPTIONS
|
|
221
|
+
-o, --org=<value> The Salesforce org to authenticate with.
|
|
222
|
+
|
|
223
|
+
The Salesforce org used to obtain the authentication token for accessing the SharinPix API.
|
|
224
|
+
```
|
|
138
225
|
|
|
139
226
|
## `sf sharinpix form csv2json`
|
|
140
227
|
|
|
@@ -205,12 +292,12 @@ GLOBAL FLAGS
|
|
|
205
292
|
DESCRIPTION
|
|
206
293
|
Pull SharinPix form templates from Salesforce org.
|
|
207
294
|
|
|
208
|
-
Retrieves
|
|
209
|
-
sharinpix/forms directory. This command fetches the form template metadata and downloads the actual
|
|
210
|
-
files.
|
|
295
|
+
Retrieves active, version-record SharinPix form templates from the connected Salesforce org and saves them as JSON
|
|
296
|
+
files in the local sharinpix/forms directory. This command fetches the form template metadata and downloads the actual
|
|
297
|
+
form definition files.
|
|
211
298
|
|
|
212
299
|
EXAMPLES
|
|
213
|
-
Pull
|
|
300
|
+
Pull active form templates from the default org:
|
|
214
301
|
|
|
215
302
|
$ sf sharinpix form pull
|
|
216
303
|
|
|
@@ -454,4 +541,36 @@ FLAG DESCRIPTIONS
|
|
|
454
541
|
|
|
455
542
|
The target Salesforce org where the SharinPix assets will be pushed.
|
|
456
543
|
```
|
|
544
|
+
|
|
545
|
+
## `sf sharinpix settings`
|
|
546
|
+
|
|
547
|
+
Open the SharinPix settings page in a Salesforce org.
|
|
548
|
+
|
|
549
|
+
```
|
|
550
|
+
USAGE
|
|
551
|
+
$ sf sharinpix settings -o <value> [--json] [--flags-dir <value>]
|
|
552
|
+
|
|
553
|
+
FLAGS
|
|
554
|
+
-o, --org=<value> (required) The Salesforce org to open.
|
|
555
|
+
|
|
556
|
+
GLOBAL FLAGS
|
|
557
|
+
--flags-dir=<value> Import flag values from a directory.
|
|
558
|
+
--json Format output as json.
|
|
559
|
+
|
|
560
|
+
DESCRIPTION
|
|
561
|
+
Open the SharinPix settings page in a Salesforce org.
|
|
562
|
+
|
|
563
|
+
Opens the SharinPix settings Lightning page in your default browser for the specified Salesforce org. This command is
|
|
564
|
+
a convenience wrapper around `sf org open` with the path set to `/lightning/n/sharinpix__SharinPix_setting`.
|
|
565
|
+
|
|
566
|
+
EXAMPLES
|
|
567
|
+
Open the SharinPix settings page for a specific org:
|
|
568
|
+
|
|
569
|
+
$ sf sharinpix settings --target-org myorg@example.com
|
|
570
|
+
|
|
571
|
+
FLAG DESCRIPTIONS
|
|
572
|
+
-o, --org=<value> The Salesforce org to open.
|
|
573
|
+
|
|
574
|
+
The target Salesforce org (username or alias) where the SharinPix settings page should be opened.
|
|
575
|
+
```
|
|
457
576
|
<!-- commandsstop -->
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Org } from '@salesforce/core';
|
|
3
|
+
export type PullResult = {
|
|
4
|
+
name: string;
|
|
5
|
+
success?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export default class Pull extends SfCommand<PullResult> {
|
|
8
|
+
static readonly summary: string;
|
|
9
|
+
static readonly description: string;
|
|
10
|
+
static readonly examples: string[];
|
|
11
|
+
static readonly flags: {
|
|
12
|
+
org: import("@oclif/core/interfaces").OptionFlag<Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<PullResult>;
|
|
15
|
+
runWithFlags(flags: {
|
|
16
|
+
org: Org;
|
|
17
|
+
}): Promise<PullResult>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
4
|
+
import { Messages } from '@salesforce/core';
|
|
5
|
+
import { formatErrorMessage } from '../../../helpers/utils.js';
|
|
6
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
7
|
+
const messages = Messages.loadMessages('@sharinpix/sharinpix-sf-cli', 'sharinpix.config.pull');
|
|
8
|
+
export default class Pull extends SfCommand {
|
|
9
|
+
static summary = messages.getMessage('summary');
|
|
10
|
+
static description = messages.getMessage('description');
|
|
11
|
+
static examples = messages.getMessages('examples');
|
|
12
|
+
static flags = {
|
|
13
|
+
org: Flags.requiredOrg({
|
|
14
|
+
char: 'o',
|
|
15
|
+
summary: messages.getMessage('flags.org.summary'),
|
|
16
|
+
description: messages.getMessage('flags.org.description'),
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
async run() {
|
|
20
|
+
const { flags } = await this.parse(Pull);
|
|
21
|
+
return this.runWithFlags(flags);
|
|
22
|
+
}
|
|
23
|
+
async runWithFlags(flags) {
|
|
24
|
+
const connection = flags.org.getConnection('63.0');
|
|
25
|
+
fs.mkdirSync('sharinpix/configs', { recursive: true });
|
|
26
|
+
try {
|
|
27
|
+
// Get authentication token
|
|
28
|
+
const body = {
|
|
29
|
+
// eslint-disable-next-line camelcase
|
|
30
|
+
form_template_create: true,
|
|
31
|
+
};
|
|
32
|
+
const responseToken = await connection.apex.post('/sharinpix/Token', {
|
|
33
|
+
payload: JSON.stringify(body),
|
|
34
|
+
});
|
|
35
|
+
// Fetch config from API
|
|
36
|
+
const response = await fetch(`${responseToken.host}/api/v1/organization/config`, {
|
|
37
|
+
method: 'GET',
|
|
38
|
+
headers: {
|
|
39
|
+
Accept: 'application/json',
|
|
40
|
+
Authorization: `Bearer ${responseToken.token}`,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
45
|
+
}
|
|
46
|
+
const config = await response.json();
|
|
47
|
+
// Save to local file
|
|
48
|
+
fs.writeFileSync('sharinpix/config.json', JSON.stringify(config, null, 2));
|
|
49
|
+
this.log(messages.getMessage('info.success'));
|
|
50
|
+
return {
|
|
51
|
+
name: 'OK',
|
|
52
|
+
success: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
this.error(messages.getMessage('error.failed', [formatErrorMessage(error)]));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=pull.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pull.js","sourceRoot":"","sources":["../../../../src/commands/sharinpix/config/pull.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAO,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE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AkB,EAAE;gBACpG,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;aAC9B,CAAC,CAAC;YAEH,wBAAwB;YACxB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,aAAa,CAAC,IAAI,6BAA6B,EAAE;gBAC/E,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,MAAM,EAAE,kBAAkB;oBAC1B,aAAa,EAAE,UAAU,aAAa,CAAC,KAAK,EAAE;iBAC/C;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YACrE,CAAC;YAED,MAAM,MAAM,GAAY,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAE9C,qBAAqB;YACrB,EAAE,CAAC,aAAa,CAAC,uBAAuB,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3E,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC;YAE9C,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Org } from '@salesforce/core';
|
|
3
|
+
export type PushResult = {
|
|
4
|
+
name: string;
|
|
5
|
+
success?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export default class Push extends SfCommand<PushResult> {
|
|
8
|
+
static readonly summary: string;
|
|
9
|
+
static readonly description: string;
|
|
10
|
+
static readonly examples: string[];
|
|
11
|
+
static readonly flags: {
|
|
12
|
+
org: import("@oclif/core/interfaces").OptionFlag<Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<PushResult>;
|
|
15
|
+
runWithFlags(flags: {
|
|
16
|
+
org: Org;
|
|
17
|
+
}): Promise<PushResult>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
4
|
+
import { Messages } from '@salesforce/core';
|
|
5
|
+
import { formatErrorMessage } from '../../../helpers/utils.js';
|
|
6
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
7
|
+
const messages = Messages.loadMessages('@sharinpix/sharinpix-sf-cli', 'sharinpix.config.push');
|
|
8
|
+
export default class Push extends SfCommand {
|
|
9
|
+
static summary = messages.getMessage('summary');
|
|
10
|
+
static description = messages.getMessage('description');
|
|
11
|
+
static examples = messages.getMessages('examples');
|
|
12
|
+
static flags = {
|
|
13
|
+
org: Flags.requiredOrg({
|
|
14
|
+
char: 'o',
|
|
15
|
+
summary: messages.getMessage('flags.org.summary'),
|
|
16
|
+
description: messages.getMessage('flags.org.description'),
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
async run() {
|
|
20
|
+
const { flags } = await this.parse(Push);
|
|
21
|
+
return this.runWithFlags(flags);
|
|
22
|
+
}
|
|
23
|
+
async runWithFlags(flags) {
|
|
24
|
+
const connection = flags.org.getConnection('63.0');
|
|
25
|
+
try {
|
|
26
|
+
// Read local config file
|
|
27
|
+
if (!fs.existsSync('sharinpix/config.json')) {
|
|
28
|
+
this.error(messages.getMessage('error.notFound'));
|
|
29
|
+
}
|
|
30
|
+
const configContent = fs.readFileSync('sharinpix/config.json', 'utf-8');
|
|
31
|
+
const config = JSON.parse(configContent);
|
|
32
|
+
const responseToken = await connection.apex.post('/sharinpix/Token', {
|
|
33
|
+
payload: JSON.stringify({}),
|
|
34
|
+
});
|
|
35
|
+
// Push config to API
|
|
36
|
+
const response = await fetch(`${responseToken.host}/api/v1/organization/config`, {
|
|
37
|
+
method: 'PUT',
|
|
38
|
+
body: JSON.stringify(config),
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
Accept: '*/*',
|
|
42
|
+
Authorization: `Token token="${responseToken.token}"`,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
47
|
+
}
|
|
48
|
+
this.log(messages.getMessage('info.success'));
|
|
49
|
+
return {
|
|
50
|
+
name: 'OK',
|
|
51
|
+
success: true,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
this.error(messages.getMessage('error.failed', [formatErrorMessage(error)]));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=push.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.js","sourceRoot":"","sources":["../../../../src/commands/sharinpix/config/push.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAO,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,6BAA6B,EAAE,uBAAuB,CAA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E;gBACpG,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;aAC5B,CAAC,CAAC;YAEH,qBAAqB;YACrB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,aAAa,CAAC,IAAI,6BAA6B,EAAE;gBAC/E,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBAC5B,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,MAAM,EAAE,KAAK;oBACb,aAAa,EAAE,gBAAgB,aAAa,CAAC,KAAK,GAAG;iBACtD;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YACrE,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC;YAE9C,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC"}
|
|
@@ -4,10 +4,10 @@ import { parse } from 'csv-parse/sync';
|
|
|
4
4
|
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
5
5
|
import { Messages } from '@salesforce/core';
|
|
6
6
|
import { getCsvFiles, formatErrorMessage, orderElementKeys } from '../../../helpers/utils.js';
|
|
7
|
+
import { parseCell } from '../../../helpers/form/elementKeys.js';
|
|
7
8
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
8
9
|
const messages = Messages.loadMessages('@sharinpix/sharinpix-sf-cli', 'sharinpix.form.csv2json');
|
|
9
10
|
const FORMS_DIRECTORY = 'sharinpix/forms';
|
|
10
|
-
const NUMERIC_FIELDS = ['index', 'max', 'min', 'step', 'rows', 'cols'];
|
|
11
11
|
const CSV_PARSE_OPTIONS = {
|
|
12
12
|
skipEmptyLines: true,
|
|
13
13
|
relaxColumnCount: true,
|
|
@@ -16,69 +16,44 @@ const CSV_PARSE_OPTIONS = {
|
|
|
16
16
|
function parseCsvRows(content) {
|
|
17
17
|
return parse(content, CSV_PARSE_OPTIONS);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
if (trimmed === '')
|
|
22
|
-
return '';
|
|
23
|
-
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
24
|
-
try {
|
|
25
|
-
const parsed = JSON.parse(trimmed);
|
|
26
|
-
if (typeof parsed === 'object' && parsed !== null)
|
|
27
|
-
return parsed;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
// Ignore parse errors, continue with other type detection
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (NUMERIC_FIELDS.includes(header)) {
|
|
34
|
-
const numValue = Number(trimmed);
|
|
35
|
-
const numberPattern = /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/;
|
|
36
|
-
if (!Number.isNaN(numValue) && isFinite(numValue) && numberPattern.test(trimmed)) {
|
|
37
|
-
return numValue;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return trimmed;
|
|
19
|
+
function mergeElementsIntoJson(existingJson, elements) {
|
|
20
|
+
return { ...existingJson, elements };
|
|
41
21
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
for (let index = 0; index < headers.length; index++) {
|
|
45
|
-
const header = headers[index];
|
|
46
|
-
const rawValue = row[index] ?? '';
|
|
47
|
-
if (header && rawValue !== '') {
|
|
48
|
-
values.set(header, parseCellValue(header, rawValue));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const orderedKeys = orderElementKeys(Array.from(values.keys()));
|
|
22
|
+
function createOrderedElement(merged) {
|
|
23
|
+
const orderedKeys = orderElementKeys(Object.keys(merged));
|
|
52
24
|
const element = {};
|
|
53
25
|
for (const key of orderedKeys) {
|
|
54
|
-
element[key] =
|
|
26
|
+
element[key] = merged[key];
|
|
55
27
|
}
|
|
56
28
|
return element;
|
|
57
29
|
}
|
|
58
|
-
function
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
30
|
+
function parseRowValues(headers, row, rowNumber) {
|
|
31
|
+
const values = new Map();
|
|
32
|
+
const keysToClear = new Set();
|
|
33
|
+
for (let index = 0; index < headers.length; index++) {
|
|
34
|
+
const header = (headers[index] ?? '').trim();
|
|
35
|
+
const rawValue = row[index] ?? '';
|
|
36
|
+
if (!header)
|
|
37
|
+
continue;
|
|
38
|
+
if (header === 'index')
|
|
39
|
+
continue;
|
|
40
|
+
if (rawValue === '') {
|
|
41
|
+
keysToClear.add(header);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (rawValue === '""') {
|
|
45
|
+
values.set(header, '');
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
values.set(header, parseCell(header, rawValue));
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const errorMsg = `Failed to parse value for key "${header}" at row ${rowNumber}, column ${index + 1}: ${error instanceof Error ? error.message : String(error)}`;
|
|
53
|
+
throw new Error(errorMsg, { cause: error });
|
|
70
54
|
}
|
|
71
|
-
return typedElement;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
function mergeElementsIntoJson(existingJson, elements) {
|
|
75
|
-
const originalElements = Array.isArray(existingJson.elements) ? existingJson.elements : [];
|
|
76
|
-
const typedElements = preserveElementTypes(elements, originalElements);
|
|
77
|
-
const merged = {};
|
|
78
|
-
for (const [key, value] of Object.entries(existingJson)) {
|
|
79
|
-
merged[key] = key === 'elements' ? typedElements : value;
|
|
80
55
|
}
|
|
81
|
-
return
|
|
56
|
+
return { values, keysToClear };
|
|
82
57
|
}
|
|
83
58
|
async function loadAndValidateJson(jsonPath) {
|
|
84
59
|
const jsonFileName = path.basename(jsonPath);
|
|
@@ -109,13 +84,29 @@ async function processCsvFile(filePath) {
|
|
|
109
84
|
const rows = parseCsvRows(content);
|
|
110
85
|
if (rows.length < 2)
|
|
111
86
|
throw new Error(messages.getMessage('error.noDataRows'));
|
|
87
|
+
const jsonPath = filePath.replace(/\.csv$/i, '.json');
|
|
88
|
+
const existingJson = await loadAndValidateJson(jsonPath);
|
|
89
|
+
const existingElementsRaw = existingJson.elements;
|
|
90
|
+
const existingElements = Array.isArray(existingElementsRaw) ? existingElementsRaw : [];
|
|
112
91
|
const headers = rows[0];
|
|
113
92
|
const elements = [];
|
|
114
93
|
for (let i = 1; i < rows.length; i++) {
|
|
115
|
-
|
|
94
|
+
const row = rows[i];
|
|
95
|
+
const rowNumber = i + 1;
|
|
96
|
+
const elementIndex = i - 1;
|
|
97
|
+
const { values, keysToClear } = parseRowValues(headers, row, rowNumber);
|
|
98
|
+
const baseCandidate = existingElements[i - 1];
|
|
99
|
+
const base = typeof baseCandidate === 'object' && baseCandidate !== null && !Array.isArray(baseCandidate)
|
|
100
|
+
? baseCandidate
|
|
101
|
+
: {};
|
|
102
|
+
const baseWithoutCleared = { ...base };
|
|
103
|
+
for (const key of keysToClear) {
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
105
|
+
delete baseWithoutCleared[key];
|
|
106
|
+
}
|
|
107
|
+
const merged = { ...baseWithoutCleared, ...Object.fromEntries(values), index: elementIndex };
|
|
108
|
+
elements.push(createOrderedElement(merged));
|
|
116
109
|
}
|
|
117
|
-
const jsonPath = filePath.replace(/\.csv$/i, '.json');
|
|
118
|
-
const existingJson = await loadAndValidateJson(jsonPath);
|
|
119
110
|
const mergedJson = mergeElementsIntoJson(existingJson, elements);
|
|
120
111
|
await fs.promises.writeFile(jsonPath, JSON.stringify(mergedJson, null, 2), 'utf8');
|
|
121
112
|
return { success: true, fileName };
|
|
@@ -145,8 +136,10 @@ export default class Csv2Json extends SfCommand {
|
|
|
145
136
|
converted++;
|
|
146
137
|
return;
|
|
147
138
|
}
|
|
148
|
-
|
|
149
|
-
|
|
139
|
+
else {
|
|
140
|
+
this.log(messages.getMessage('info.skipped', [result.fileName, result.reason]));
|
|
141
|
+
skipped++;
|
|
142
|
+
}
|
|
150
143
|
});
|
|
151
144
|
this.log(messages.getMessage('info.summary', [converted, skipped]));
|
|
152
145
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csv2json.js","sourceRoot":"","sources":["../../../../src/commands/sharinpix/form/csv2json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"csv2json.js","sourceRoot":"","sources":["../../../../src/commands/sharinpix/form/csv2json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,kBA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AO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QAClD,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7E,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACzB,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,SAAS,EAAE,CAAC;gBACZ,OAAO;YACT,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAChF,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAEpE,OAAO;YACL,IAAI,EAAE,IAAI;YACV,SAAS;YACT,OAAO;SACR,CAAC;IACJ,CAAC"}
|
|
@@ -3,37 +3,34 @@ import path from 'node:path';
|
|
|
3
3
|
import { stringify } from 'csv-stringify/sync';
|
|
4
4
|
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
5
5
|
import { Messages } from '@salesforce/core';
|
|
6
|
-
import { getJsonFiles, formatErrorMessage
|
|
6
|
+
import { getJsonFiles, formatErrorMessage } from '../../../helpers/utils.js';
|
|
7
|
+
import { elementKeyOrder, serializeCell } from '../../../helpers/form/elementKeys.js';
|
|
7
8
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
8
9
|
const messages = Messages.loadMessages('@sharinpix/sharinpix-sf-cli', 'sharinpix.form.json2csv');
|
|
9
10
|
const FORMS_DIRECTORY = 'sharinpix/forms';
|
|
10
11
|
const CSV_OPTIONS = {
|
|
11
12
|
quotedMatch: /[",\n\r]/,
|
|
12
|
-
quotedEmpty:
|
|
13
|
+
quotedEmpty: true,
|
|
13
14
|
escape: '"',
|
|
14
15
|
};
|
|
15
|
-
function formatCell(value) {
|
|
16
|
-
if (value === null || value === undefined)
|
|
17
|
-
return '';
|
|
18
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
19
|
-
return String(value);
|
|
20
|
-
if (Array.isArray(value) || typeof value === 'object')
|
|
21
|
-
return JSON.stringify(value);
|
|
22
|
-
return String(value);
|
|
23
|
-
}
|
|
24
16
|
function buildHeaders(elements) {
|
|
25
17
|
const allKeys = new Set();
|
|
26
18
|
for (const element of elements) {
|
|
27
19
|
for (const key of Object.keys(element)) {
|
|
20
|
+
if (key === 'index')
|
|
21
|
+
continue;
|
|
28
22
|
allKeys.add(key);
|
|
29
23
|
}
|
|
30
24
|
}
|
|
31
|
-
return
|
|
25
|
+
return elementKeyOrder.filter((key) => key !== 'index' && allKeys.has(key));
|
|
32
26
|
}
|
|
33
27
|
function generateCsvContent(headers, elements) {
|
|
34
28
|
const rows = [headers];
|
|
35
29
|
for (const element of elements) {
|
|
36
|
-
const row = headers.map((key) =>
|
|
30
|
+
const row = headers.map((key) => {
|
|
31
|
+
const value = element[key];
|
|
32
|
+
return serializeCell(key, value);
|
|
33
|
+
});
|
|
37
34
|
rows.push(row);
|
|
38
35
|
}
|
|
39
36
|
return stringify(rows, CSV_OPTIONS);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json2csv.js","sourceRoot":"","sources":["../../../../src/commands/sharinpix/form/json2csv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AA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