@sharinpix/sharinpix-sf-cli 1.7.0 → 1.9.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 CHANGED
@@ -47,6 +47,10 @@ sf sharinpix permission pull -o yourusername@salesforce.com
47
47
  # Push form templates and permissions to Salesforce
48
48
  sf sharinpix form push -o yourusername@salesforce.com
49
49
  sf sharinpix permission push -o yourusername@salesforce.com
50
+
51
+ # Push with deletion of orphaned records (records that exist in Salesforce but have no corresponding local files)
52
+ sf sharinpix form push -o yourusername@salesforce.com --delete
53
+ sf sharinpix permission push -o yourusername@salesforce.com -d
50
54
  ```
51
55
 
52
56
  ## Issues
@@ -101,6 +105,25 @@ sf plugins link .
101
105
  sf plugins
102
106
  ```
103
107
 
108
+ ## Key Features
109
+
110
+ ### Deletion Functionality
111
+
112
+ Both `form push` and `permission push` commands support a `--delete/-d` flag that provides automatic cleanup of orphaned records:
113
+
114
+ - **Orphaned Records**: Records that exist in your Salesforce org but no longer have corresponding local JSON files
115
+ - **Safety**: Deletion only occurs when the flag is explicitly provided
116
+ - **Reporting**: The command reports how many records were deleted, failed, uploaded, and skipped
117
+ - **Error Handling**: If a deletion fails, it's logged as a warning and counted in the failed total
118
+
119
+ **⚠️ Important**: Use the `--delete` flag with caution as deletions cannot be undone. Always ensure you have backups of your data before using this feature.
120
+
121
+ **Example Workflow**:
122
+
123
+ 1. Pull existing records: `sf sharinpix form pull`
124
+ 2. Remove unwanted local JSON files
125
+ 3. Push with cleanup: `sf sharinpix form push --delete`
126
+
104
127
  ## Commands
105
128
 
106
129
  <!-- commands -->
@@ -152,9 +175,10 @@ Push SharinPix form templates to Salesforce org.
152
175
 
153
176
  ```
154
177
  USAGE
155
- $ sf sharinpix form push -o <value> [--json] [--flags-dir <value>]
178
+ $ sf sharinpix form push -o <value> [--json] [--flags-dir <value>] [-d]
156
179
 
157
180
  FLAGS
181
+ -d, --delete Delete form templates from org that no longer have corresponding local files.
158
182
  -o, --org=<value> (required) The Salesforce org to push form templates to.
159
183
 
160
184
  GLOBAL FLAGS
@@ -177,7 +201,16 @@ EXAMPLES
177
201
 
178
202
  $ sf sharinpix form push --target-org myorg@example.com
179
203
 
204
+ Push form templates and delete orphaned records:
205
+
206
+ $ sf sharinpix form push --delete
207
+
180
208
  FLAG DESCRIPTIONS
209
+ -d, --delete Delete form templates from org that no longer have corresponding local files.
210
+
211
+ When enabled, this flag will delete form template records from the Salesforce org if their corresponding local JSON
212
+ files are missing. Use with caution as this operation cannot be undone.
213
+
181
214
  -o, --org=<value> The Salesforce org to push form templates to.
182
215
 
183
216
  The target Salesforce org where the SharinPix form templates will be uploaded and stored.
@@ -202,8 +235,8 @@ DESCRIPTION
202
235
  Pull SharinPix permissions from Salesforce org.
203
236
 
204
237
  Retrieves all SharinPix permissions from the connected Salesforce org and saves them as JSON files in the local
205
- sharinpix/permission directory. This command fetches the permission metadata and the JSON configuration data stored in
206
- the sharinpix**Json**c field.
238
+ sharinpix/permissions directory. This command fetches the permission metadata and the JSON configuration data stored
239
+ in the sharinpix**Json**c field.
207
240
 
208
241
  EXAMPLES
209
242
  Pull all SharinPix permissions from the default org:
@@ -226,9 +259,10 @@ Push SharinPix permissions to Salesforce org.
226
259
 
227
260
  ```
228
261
  USAGE
229
- $ sf sharinpix permission push -o <value> [--json] [--flags-dir <value>]
262
+ $ sf sharinpix permission push -o <value> [--json] [--flags-dir <value>] [-d]
230
263
 
231
264
  FLAGS
265
+ -d, --delete Delete SharinPix permissions from org that no longer have corresponding local files.
232
266
  -o, --org=<value> (required) The Salesforce org to push SharinPix permissions to.
233
267
 
234
268
  GLOBAL FLAGS
@@ -251,7 +285,16 @@ EXAMPLES
251
285
 
252
286
  $ sf sharinpix permission push --target-org myorg@example.com
253
287
 
288
+ Push SharinPix permissions and delete orphaned records:
289
+
290
+ $ sf sharinpix permission push --delete
291
+
254
292
  FLAG DESCRIPTIONS
293
+ -d, --delete Delete SharinPix permissions from org that no longer have corresponding local files.
294
+
295
+ When enabled, this flag will delete SharinPix permission records from the Salesforce org if their corresponding
296
+ local JSON files are missing. Use with caution as this operation cannot be undone.
297
+
255
298
  -o, --org=<value> The Salesforce org to push SharinPix permissions to.
256
299
 
257
300
  The target Salesforce org where the SharinPix permissions will be uploaded and stored.
@@ -4,6 +4,7 @@ export type PushResult = {
4
4
  uploaded?: number;
5
5
  failed?: number;
6
6
  skipped?: number;
7
+ deleted?: number;
7
8
  };
8
9
  export default class Push extends SfCommand<PushResult> {
9
10
  static readonly summary: string;
@@ -11,6 +12,7 @@ export default class Push extends SfCommand<PushResult> {
11
12
  static readonly examples: string[];
12
13
  static readonly flags: {
13
14
  org: import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
15
+ delete: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
16
  };
15
17
  run(): Promise<PushResult>;
16
18
  }
@@ -1,10 +1,8 @@
1
- /* eslint-disable no-console */
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
2
  /* eslint-disable no-await-in-loop */
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
3
  import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
6
4
  import { Messages } from '@salesforce/core';
7
- import { isJsonEqual } from '../../../helpers/utils.js';
5
+ import { isJsonEqual, readJsonFile, getNameFromJson, getJsonFiles, fetchJson, formatErrorMessage, } from '../../../helpers/utils.js';
8
6
  Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
9
7
  const messages = Messages.loadMessages('@sharinpix/sharinpix-sf-cli', 'sharinpix.form.push');
10
8
  export default class Push extends SfCommand {
@@ -17,23 +15,17 @@ export default class Push extends SfCommand {
17
15
  summary: messages.getMessage('flags.org.summary'),
18
16
  description: messages.getMessage('flags.org.description'),
19
17
  }),
18
+ delete: Flags.boolean({
19
+ char: 'd',
20
+ summary: messages.getMessage('flags.delete.summary'),
21
+ description: messages.getMessage('flags.delete.description'),
22
+ default: false,
23
+ }),
20
24
  };
21
25
  async run() {
22
26
  const { flags } = await this.parse(Push);
23
27
  const connection = flags.org.getConnection('63.0');
24
- const files = fs
25
- .readdirSync('sharinpix/forms')
26
- .filter((file) => file.endsWith('.json'))
27
- .map((file) => path.join('sharinpix/forms', file));
28
- if (files.length === 0) {
29
- this.log('No form template files found in the specified directory.');
30
- return {
31
- name: 'OK',
32
- uploaded: 0,
33
- failed: 0,
34
- skipped: 0,
35
- };
36
- }
28
+ const files = getJsonFiles('sharinpix/forms');
37
29
  const body = {
38
30
  // eslint-disable-next-line camelcase
39
31
  form_template_create: true,
@@ -46,41 +38,25 @@ export default class Push extends SfCommand {
46
38
  let uploaded = 0;
47
39
  let failed = 0;
48
40
  let skipped = 0;
41
+ let deleted = 0;
49
42
  for (const file of files) {
50
- try {
51
- const fileContent = fs.readFileSync(file, 'utf8');
52
- const json = JSON.parse(fileContent);
53
- const fileName = json.name;
43
+ const processFile = async () => {
44
+ const json = readJsonFile(file);
45
+ const fileName = getNameFromJson(json);
54
46
  const existingRecord = existingMap.get(fileName);
55
47
  const existingId = existingRecord?.Id ?? null;
56
48
  if (existingRecord) {
57
- // Check if form has changed by comparing with stored JSON
58
- const response = await fetch(existingRecord?.sharinpix__FormUrl__c + '.json', {
59
- headers: {
60
- Accept: 'application/json',
61
- },
49
+ const existingJson = await fetchJson(existingRecord.sharinpix__FormUrl__c + '.json').catch((error) => {
50
+ this.warn(`Failed to check changes for ${fileName}, proceeding with update: ${formatErrorMessage(error)}`);
51
+ return null;
62
52
  });
63
- if (!response.ok) {
64
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
65
- }
66
- const existingJson = await response.json();
67
- if (existingJson) {
68
- try {
69
- if (isJsonEqual(json, existingJson)) {
70
- this.log(messages.getMessage('info.skipped', [fileName]));
71
- skipped++;
72
- continue;
73
- }
74
- }
75
- catch (parseError) {
76
- this.warn(`Failed to parse stored JSON for ${fileName}, proceeding with update`);
77
- failed++;
78
- continue;
79
- }
53
+ if (existingJson && isJsonEqual(json, existingJson)) {
54
+ this.log(messages.getMessage('info.skipped', [fileName]));
55
+ skipped++;
56
+ return;
80
57
  }
81
58
  }
82
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
83
- const responseData = await (await fetch(`${responseToken.host}/api/v1/form/templates`, {
59
+ const response = await fetch(`${responseToken.host}/api/v1/form/templates`, {
84
60
  method: 'POST',
85
61
  body: JSON.stringify({
86
62
  sfid: existingId ?? undefined,
@@ -94,7 +70,11 @@ export default class Push extends SfCommand {
94
70
  Accept: 'application/json',
95
71
  Authorization: `Bearer ${responseToken.token}`,
96
72
  },
97
- })).json();
73
+ });
74
+ if (!response.ok) {
75
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
76
+ }
77
+ const responseData = (await response.json());
98
78
  const formTemplateJson = JSON.stringify({
99
79
  ...json,
100
80
  url: responseData.url,
@@ -105,29 +85,47 @@ export default class Push extends SfCommand {
105
85
  url: responseData.url,
106
86
  formTemplateJson,
107
87
  });
108
- if (existingId) {
109
- this.log(messages.getMessage('info.updated', [fileName]));
88
+ this.log(messages.getMessage(existingId ? 'info.updated' : 'info.created', [fileName]));
89
+ uploaded++;
90
+ };
91
+ await processFile().catch((error) => {
92
+ try {
93
+ const json = readJsonFile(file);
94
+ const fileName = getNameFromJson(json);
95
+ this.warn(`Failed to push form template ${fileName}: ${formatErrorMessage(error)}`);
110
96
  }
111
- else {
112
- this.log(messages.getMessage('info.created', [fileName]));
97
+ catch {
98
+ this.warn(`Failed to parse JSON for form template in ${file}: ${formatErrorMessage(error)}`);
113
99
  }
114
- uploaded++;
115
- }
116
- catch (error) {
117
- const fileContent = fs.readFileSync(file, 'utf8');
118
- const json = JSON.parse(fileContent);
119
- const fileName = json.name;
120
- this.warn(`Failed to push form template ${fileName}: ${error instanceof Error ? error.message : 'Unknown error'}`);
121
100
  failed++;
122
- continue;
101
+ });
102
+ }
103
+ if (flags.delete) {
104
+ const localFileNames = new Set(files.map((file) => {
105
+ const json = readJsonFile(file);
106
+ return getNameFromJson(json);
107
+ }));
108
+ for (const [recordName, record] of existingMap) {
109
+ if (!localFileNames.has(recordName)) {
110
+ await connection.sobject('sharinpix__FormTemplate__c').delete(record.Id)
111
+ .then(() => {
112
+ this.log(messages.getMessage('info.deleted', [recordName]));
113
+ deleted++;
114
+ })
115
+ .catch((error) => {
116
+ this.warn(`Failed to delete form template ${recordName}: ${formatErrorMessage(error)}`);
117
+ failed++;
118
+ });
119
+ }
123
120
  }
124
121
  }
125
- this.log(messages.getMessage('info.summary', [uploaded, failed, skipped]));
122
+ this.log(messages.getMessage('info.summary', [uploaded, failed, skipped, deleted]));
126
123
  return {
127
124
  name: 'OK',
128
125
  uploaded,
129
126
  failed,
130
127
  skipped,
128
+ deleted,
131
129
  };
132
130
  }
133
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"push.js","sourceRoot":"","sources":["../../../../src/commands/sharinpix/form/push.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,6BAA6B,EAAE,qBAAqB,CAAC,CAAC;AAgB7F,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,SAAqB;IAC9C,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU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,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;wBAC5D,OAAO,EAAE,CAAC;oBACZ,CAAC,CAAC;yBACD,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;wBACtB,IAAI,CAAC,IAAI,CAAC,kCAAkC,UAAU,KAAK,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;wBACxF,MAAM,EAAE,CAAC;oBACX,CAAC,CAAC,CAAC;gBACP,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAEpF,OAAO;YACL,IAAI,EAAE,IAAI;YACV,QAAQ;YACR,MAAM;YACN,OAAO;YACP,OAAO;SACR,CAAC;IACJ,CAAC"}
@@ -20,8 +20,8 @@ export default class Pull extends SfCommand {
20
20
  async run() {
21
21
  const { flags } = await this.parse(Pull);
22
22
  const connection = flags.org.getConnection('63.0');
23
- fs.mkdirSync('sharinpix/permission', { recursive: true });
24
- const records = (await connection.query('SELECT Id, Name, sharinpix__Description__c, sharinpix__ID__c, sharinpix__Json__c FROM sharinpix__SharinPixPermission__c order by LastModifiedDate desc')).records;
23
+ fs.mkdirSync('sharinpix/permissions', { recursive: true });
24
+ const records = (await connection.query('SELECT Id, Name, sharinpix__Description__c, sharinpix__Json__c FROM sharinpix__SharinPixPermission__c order by LastModifiedDate desc')).records;
25
25
  let permissionsDownloaded = 0;
26
26
  let permissionsFailed = 0;
27
27
  for (const record of records) {
@@ -32,7 +32,7 @@ export default class Pull extends SfCommand {
32
32
  name: record.Name,
33
33
  };
34
34
  const safeFilename = createSafeFilename(record.Name);
35
- fs.writeFileSync(`sharinpix/permission/${safeFilename}.json`, JSON.stringify(permissionData, null, 2));
35
+ fs.writeFileSync(`sharinpix/permissions/${safeFilename}.json`, JSON.stringify(permissionData, null, 2));
36
36
  this.log(messages.getMessage('info.hello', [record.Name, record.sharinpix__Description__c || 'No description']));
37
37
  permissionsDownloaded++;
38
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pull.js","sourceRoot":"","sources":["../../../../src/commands/sharinpix/permission/pull.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,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,2BAA2B,CAAC,CAAC;AAgBnG,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,SAAqB;IAC9C,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5D,MAAM,CAAU,KAAK,GAAG;QAC7B,GAAG,EAAE,KAAK,CAAC,WAAW,CAAC;YACrB,IAAI,EAAE,GAAG;YACT,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,mBAAmB,CAAC;YACjD,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC;SAC1D,CAAC;KACH,CAAC;IAEK,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM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AI,CAAC,GAAG,CAAC,2BAA2B,qBAAqB,6BAA6B,iBAAiB,UAAU,CAAC,CAAC;QAEnH,OAAO;YACL,IAAI,EAAE,IAAI;YACV,qBAAqB;YACrB,iBAAiB;SAClB,CAAC;IACJ,CAAC"}
@@ -4,6 +4,7 @@ export type PushResult = {
4
4
  uploaded?: number;
5
5
  failed?: number;
6
6
  skipped?: number;
7
+ deleted?: number;
7
8
  };
8
9
  export default class Push extends SfCommand<PushResult> {
9
10
  static readonly summary: string;
@@ -11,6 +12,7 @@ export default class Push extends SfCommand<PushResult> {
11
12
  static readonly examples: string[];
12
13
  static readonly flags: {
13
14
  org: import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
15
+ delete: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
16
  };
15
17
  run(): Promise<PushResult>;
16
18
  }
@@ -1,10 +1,8 @@
1
- /* eslint-disable no-console */
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
2
  /* eslint-disable no-await-in-loop */
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
3
  import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
6
4
  import { Messages } from '@salesforce/core';
7
- import { isJsonEqual } from '../../../helpers/utils.js';
5
+ import { isJsonEqual, readJsonFile, getNameFromJson, getJsonFiles, formatErrorMessage, } from '../../../helpers/utils.js';
8
6
  Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
9
7
  const messages = Messages.loadMessages('@sharinpix/sharinpix-sf-cli', 'sharinpix.permission.push');
10
8
  export default class Push extends SfCommand {
@@ -17,52 +15,43 @@ export default class Push extends SfCommand {
17
15
  summary: messages.getMessage('flags.org.summary'),
18
16
  description: messages.getMessage('flags.org.description'),
19
17
  }),
18
+ delete: Flags.boolean({
19
+ char: 'd',
20
+ summary: messages.getMessage('flags.delete.summary'),
21
+ description: messages.getMessage('flags.delete.description'),
22
+ default: false,
23
+ }),
20
24
  };
21
25
  async run() {
22
26
  const { flags } = await this.parse(Push);
23
27
  const connection = flags.org.getConnection('63.0');
24
- const files = fs
25
- .readdirSync('sharinpix/permission')
26
- .filter((file) => file.endsWith('.json'))
27
- .map((file) => path.join('sharinpix/permission', file));
28
- if (files.length === 0) {
29
- this.log('No SharinPix permission files found in the specified directory.');
30
- return {
31
- name: 'OK',
32
- uploaded: 0,
33
- failed: 0,
34
- skipped: 0,
35
- };
36
- }
37
- const existingRecords = (await connection.query('SELECT Id, Name, sharinpix__Description__c, sharinpix__ID__c, sharinpix__Json__c FROM sharinpix__SharinPixPermission__c')).records;
28
+ const files = getJsonFiles('sharinpix/permissions');
29
+ const existingRecords = (await connection.query('SELECT Id, Name, sharinpix__Description__c, sharinpix__Json__c FROM sharinpix__SharinPixPermission__c')).records;
38
30
  const existingMap = new Map(existingRecords.map((record) => [record.Name, record]));
39
31
  let uploaded = 0;
40
32
  let failed = 0;
41
33
  let skipped = 0;
34
+ let deleted = 0;
42
35
  for (const file of files) {
43
- try {
44
- const fileContent = fs.readFileSync(file, 'utf8');
45
- const json = JSON.parse(fileContent);
46
- const fileName = json.name;
36
+ const processFile = async () => {
37
+ const json = readJsonFile(file);
38
+ const fileName = getNameFromJson(json);
47
39
  const existingRecord = existingMap.get(fileName);
48
- const existingId = existingRecord?.Id ?? null;
49
40
  const jsonWithoutName = { ...json };
50
41
  delete jsonWithoutName.name;
51
42
  if (existingRecord) {
52
- // Check if permission has changed by comparing with stored JSON
53
43
  try {
54
44
  const existingJson = JSON.parse(existingRecord.sharinpix__Json__c);
55
45
  if (isJsonEqual(jsonWithoutName, existingJson)) {
56
46
  this.log(messages.getMessage('info.skipped', [fileName]));
57
47
  skipped++;
58
- continue;
48
+ return;
59
49
  }
60
50
  }
61
51
  catch (parseError) {
62
52
  this.warn(`Failed to parse stored JSON for ${fileName}, proceeding with update`);
63
53
  }
64
54
  }
65
- // Update or create the permission record
66
55
  const permissionData = {
67
56
  Name: fileName,
68
57
  // eslint-disable-next-line camelcase
@@ -72,36 +61,56 @@ export default class Push extends SfCommand {
72
61
  sharinpix__Description__c: existingRecord.sharinpix__Description__c,
73
62
  }),
74
63
  };
75
- if (existingId) {
76
- // Update existing record
64
+ if (existingRecord?.Id) {
77
65
  await connection.sobject('sharinpix__SharinPixPermission__c').update({
78
66
  ...permissionData,
79
- Id: existingId,
67
+ Id: existingRecord.Id,
80
68
  });
81
- this.log(messages.getMessage('info.updated', [fileName]));
82
69
  }
83
70
  else {
84
- // Create new record
85
71
  await connection.sobject('sharinpix__SharinPixPermission__c').create(permissionData);
86
- this.log(messages.getMessage('info.created', [fileName]));
87
72
  }
73
+ this.log(messages.getMessage(existingRecord ? 'info.updated' : 'info.created', [fileName]));
88
74
  uploaded++;
89
- }
90
- catch (error) {
91
- const fileContent = fs.readFileSync(file, 'utf8');
92
- const json = JSON.parse(fileContent);
93
- const fileName = json.name;
94
- this.warn(`Failed to push SharinPix permission ${fileName}: ${error instanceof Error ? error.message : 'Unknown error'}`);
75
+ };
76
+ await processFile().catch((error) => {
77
+ try {
78
+ const json = readJsonFile(file);
79
+ const fileName = getNameFromJson(json);
80
+ this.warn(`Failed to push SharinPix permission ${fileName}: ${formatErrorMessage(error)}`);
81
+ }
82
+ catch {
83
+ this.warn(`Failed to parse JSON for SharinPix permission in ${file}: ${formatErrorMessage(error)}`);
84
+ }
95
85
  failed++;
96
- continue;
86
+ });
87
+ }
88
+ if (flags.delete) {
89
+ const localFileNames = new Set(files.map((file) => {
90
+ const json = readJsonFile(file);
91
+ return getNameFromJson(json);
92
+ }));
93
+ for (const [recordName, record] of existingMap) {
94
+ if (!localFileNames.has(recordName)) {
95
+ await connection.sobject('sharinpix__SharinPixPermission__c').delete(record.Id)
96
+ .then(() => {
97
+ this.log(messages.getMessage('info.deleted', [recordName]));
98
+ deleted++;
99
+ })
100
+ .catch((error) => {
101
+ this.warn(`Failed to delete SharinPix permission ${recordName}: ${formatErrorMessage(error)}`);
102
+ failed++;
103
+ });
104
+ }
97
105
  }
98
106
  }
99
- this.log(messages.getMessage('info.summary', [uploaded, failed, skipped]));
107
+ this.log(messages.getMessage('info.summary', [uploaded, failed, skipped, deleted]));
100
108
  return {
101
109
  name: 'OK',
102
110
  uploaded,
103
111
  failed,
104
112
  skipped,
113
+ deleted,
105
114
  };
106
115
  }
107
116
  }
@@ -1 +1 @@
1
- {"version":3,"file":"push.js","sourceRoot":"","sources":["../../../../src/commands/sharinpix/permission/push.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,6BAA6B,EAAE,2BAA2B,CAAC,CAAC;AAiBnG,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,SAAqB;IAC9C,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5D,MAAM,CAAU,KAAK,GAAG;QAC7B,GAAG,EAAE,KAAK,CAAC,WAAW,CAAC;YACrB,IAAI,EAAE,GAAG;YACT,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,mBAAmB,CAAC;YACjD,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC;SAC1D,CAAC;KACH,CAAC;IAEK,KA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ACR,CAAC;IACJ,CAAC"}
@@ -1,2 +1,9 @@
1
1
  export declare function isJsonEqual(obj1: unknown, obj2: unknown): boolean;
2
2
  export declare function createSafeFilename(name: string): string;
3
+ export declare function readJsonFile(filePath: string): Record<string, unknown>;
4
+ export declare function writeJsonFile(filePath: string, data: unknown): void;
5
+ export declare function fetchJson(url: string): Promise<unknown>;
6
+ export declare function getNameFromJson(json: Record<string, unknown>): string;
7
+ export declare function ensureDirectoryExists(dirPath: string): void;
8
+ export declare function formatErrorMessage(error: unknown): string;
9
+ export declare function getJsonFiles(dirPath: string): string[];
@@ -1,4 +1,5 @@
1
1
  import * as crypto from 'node:crypto';
2
+ import fs from 'node:fs';
2
3
  export function isJsonEqual(obj1, obj2) {
3
4
  return JSON.stringify(obj1) === JSON.stringify(obj2);
4
5
  }
@@ -6,4 +7,35 @@ export function createSafeFilename(name) {
6
7
  const md5Hash = crypto.createHash('md5').update(name).digest('hex').slice(0, 8);
7
8
  return `${name.replaceAll(/[^a-zA-Z0-9]/g, '_')}-${md5Hash}`;
8
9
  }
10
+ export function readJsonFile(filePath) {
11
+ const fileContent = fs.readFileSync(filePath, 'utf8');
12
+ return JSON.parse(fileContent);
13
+ }
14
+ export function writeJsonFile(filePath, data) {
15
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
16
+ }
17
+ export async function fetchJson(url) {
18
+ const response = await fetch(url, {
19
+ headers: { Accept: 'application/json' },
20
+ });
21
+ if (!response.ok) {
22
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
23
+ }
24
+ return response.json();
25
+ }
26
+ export function getNameFromJson(json) {
27
+ return json.name;
28
+ }
29
+ export function ensureDirectoryExists(dirPath) {
30
+ fs.mkdirSync(dirPath, { recursive: true });
31
+ }
32
+ export function formatErrorMessage(error) {
33
+ return error instanceof Error ? error.message : 'Unknown error';
34
+ }
35
+ export function getJsonFiles(dirPath) {
36
+ return fs
37
+ .readdirSync(dirPath)
38
+ .filter((file) => file.endsWith('.json'))
39
+ .map((file) => `${dirPath}/${file}`);
40
+ }
9
41
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/helpers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,MAAM,UAAU,WAAW,CAAC,IAAa,EAAE,IAAa;IACtD,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChF,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC;AAC/D,CAAC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/helpers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,MAAM,UAAU,WAAW,CAAC,IAAa,EAAE,IAAa;IACtD,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChF,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,GAAG,CAA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O,CAAC;SACpB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;SACxC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC"}
@@ -14,6 +14,14 @@ The Salesforce org to push form templates to.
14
14
 
15
15
  The target Salesforce org where the SharinPix form templates will be uploaded and stored.
16
16
 
17
+ # flags.delete.summary
18
+
19
+ Delete form templates from org that no longer have corresponding local files.
20
+
21
+ # flags.delete.description
22
+
23
+ When enabled, this flag will delete form template records from the Salesforce org if their corresponding local JSON files are missing. Use with caution as this operation cannot be undone.
24
+
17
25
  # examples
18
26
 
19
27
  - Push all form templates to the default org:
@@ -24,6 +32,10 @@ The target Salesforce org where the SharinPix form templates will be uploaded an
24
32
 
25
33
  <%= config.bin %> <%= command.id %> --target-org myorg@example.com
26
34
 
35
+ - Push form templates and delete orphaned records:
36
+
37
+ <%= config.bin %> <%= command.id %> --delete
38
+
27
39
  # info.created
28
40
 
29
41
  Created form template %s
@@ -36,6 +48,10 @@ Updated form template %s
36
48
 
37
49
  Skipped form template %s (no changes detected)
38
50
 
51
+ # info.deleted
52
+
53
+ Deleted form template %s
54
+
39
55
  # info.summary
40
56
 
41
- Push completed: %d forms uploaded, %d forms failed, %d forms skipped
57
+ Push completed: %d forms uploaded, %d forms failed, %d forms skipped, %d forms deleted
@@ -4,7 +4,7 @@ Pull SharinPix permissions from Salesforce org.
4
4
 
5
5
  # description
6
6
 
7
- Retrieves all SharinPix permissions from the connected Salesforce org and saves them as JSON files in the local sharinpix/permission directory. This command fetches the permission metadata and the JSON configuration data stored in the sharinpix**Json**c field.
7
+ Retrieves all SharinPix permissions from the connected Salesforce org and saves them as JSON files in the local sharinpix/permissions directory. This command fetches the permission metadata and the JSON configuration data stored in the sharinpix**Json**c field.
8
8
 
9
9
  # flags.org.summary
10
10
 
@@ -14,6 +14,14 @@ The Salesforce org to push SharinPix permissions to.
14
14
 
15
15
  The target Salesforce org where the SharinPix permissions will be uploaded and stored.
16
16
 
17
+ # flags.delete.summary
18
+
19
+ Delete SharinPix permissions from org that no longer have corresponding local files.
20
+
21
+ # flags.delete.description
22
+
23
+ When enabled, this flag will delete SharinPix permission records from the Salesforce org if their corresponding local JSON files are missing. Use with caution as this operation cannot be undone.
24
+
17
25
  # examples
18
26
 
19
27
  - Push all SharinPix permissions to the default org:
@@ -24,6 +32,10 @@ The target Salesforce org where the SharinPix permissions will be uploaded and s
24
32
 
25
33
  <%= config.bin %> <%= command.id %> --target-org myorg@example.com
26
34
 
35
+ - Push SharinPix permissions and delete orphaned records:
36
+
37
+ <%= config.bin %> <%= command.id %> --delete
38
+
27
39
  # info.created
28
40
 
29
41
  Created SharinPix permission %s
@@ -36,6 +48,10 @@ Updated SharinPix permission %s
36
48
 
37
49
  Skipped SharinPix permission %s (no changes detected)
38
50
 
51
+ # info.deleted
52
+
53
+ Deleted SharinPix permission %s
54
+
39
55
  # info.summary
40
56
 
41
- Push completed: %d permissions uploaded, %d permissions failed, %d permissions skipped
57
+ Push completed: %d permissions uploaded, %d permissions failed, %d permissions skipped, %d permissions deleted
package/oclif.lock CHANGED
@@ -2711,6 +2711,13 @@
2711
2711
  resolved "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.10.tgz"
2712
2712
  integrity sha512-xPyYSz1cMPnJQhl0CLMH68j3gprKZaTjG3s5Vi+fDgx+uhG9NOXwbVt52eFS8ECyXhyKcjDLCBEqBExKuiZb7Q==
2713
2713
 
2714
+ "@types/mock-fs@^4.13.4":
2715
+ version "4.13.4"
2716
+ resolved "https://registry.yarnpkg.com/@types/mock-fs/-/mock-fs-4.13.4.tgz#e73edb4b4889d44d23f1ea02d6eebe50aa30b09a"
2717
+ integrity sha512-mXmM0o6lULPI8z3XNnQCpL0BGxPwx1Ul1wXYEPBGl4efShyxW2Rln0JOPEWGyZaYZMM6OVXM/15zUuFMY52ljg==
2718
+ dependencies:
2719
+ "@types/node" "*"
2720
+
2714
2721
  "@types/mute-stream@^0.0.4":
2715
2722
  version "0.0.4"
2716
2723
  resolved "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.4.tgz"
@@ -7237,6 +7244,11 @@ mocha@^10.7.0:
7237
7244
  yargs-parser "^20.2.9"
7238
7245
  yargs-unparser "^2.0.0"
7239
7246
 
7247
+ mock-fs@^5.5.0:
7248
+ version "5.5.0"
7249
+ resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-5.5.0.tgz#94a46d299aaa588e735a201cbe823c876e91f385"
7250
+ integrity sha512-d/P1M/RacgM3dB0sJ8rjeRNXxtapkPCUnMGmIN0ixJ16F/E4GUZCvWcSGfWGz8eaXYvn1s9baUwNjI4LOPEjiA==
7251
+
7240
7252
  mri@^1.2.0:
7241
7253
  version "1.2.0"
7242
7254
  resolved "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz"
@@ -69,7 +69,8 @@
69
69
  "description": "Uploads SharinPix form templates from local JSON files to the connected Salesforce org. This command reads form templates from the local directory and creates or updates corresponding records in Salesforce. Existing forms will be updated unless the force flag is used to skip them.",
70
70
  "examples": [
71
71
  "Push all form templates to the default org:\n<%= config.bin %> <%= command.id %>",
72
- "Push form templates to a specific org:\n<%= config.bin %> <%= command.id %> --target-org myorg@example.com"
72
+ "Push form templates to a specific org:\n<%= config.bin %> <%= command.id %> --target-org myorg@example.com",
73
+ "Push form templates and delete orphaned records:\n<%= config.bin %> <%= command.id %> --delete"
73
74
  ],
74
75
  "flags": {
75
76
  "json": {
@@ -97,6 +98,14 @@
97
98
  "hasDynamicHelp": true,
98
99
  "multiple": false,
99
100
  "type": "option"
101
+ },
102
+ "delete": {
103
+ "char": "d",
104
+ "description": "When enabled, this flag will delete form template records from the Salesforce org if their corresponding local JSON files are missing. Use with caution as this operation cannot be undone.",
105
+ "name": "delete",
106
+ "summary": "Delete form templates from org that no longer have corresponding local files.",
107
+ "allowNo": false,
108
+ "type": "boolean"
100
109
  }
101
110
  },
102
111
  "hasDynamicHelp": true,
@@ -129,7 +138,7 @@
129
138
  "sharinpix:permission:pull": {
130
139
  "aliases": [],
131
140
  "args": {},
132
- "description": "Retrieves all SharinPix permissions from the connected Salesforce org and saves them as JSON files in the local sharinpix/permission directory. This command fetches the permission metadata and the JSON configuration data stored in the sharinpix**Json**c field.",
141
+ "description": "Retrieves all SharinPix permissions from the connected Salesforce org and saves them as JSON files in the local sharinpix/permissions directory. This command fetches the permission metadata and the JSON configuration data stored in the sharinpix**Json**c field.",
133
142
  "examples": [
134
143
  "Pull all SharinPix permissions from the default org:\n<%= config.bin %> <%= command.id %>",
135
144
  "Pull SharinPix permissions from a specific org:\n<%= config.bin %> <%= command.id %> --target-org myorg@example.com"
@@ -195,7 +204,8 @@
195
204
  "description": "Uploads SharinPix permissions from local JSON files to the connected Salesforce org. This command reads permission configurations from the local directory and creates or updates corresponding records in Salesforce. The sharinpix**Json**c field will be updated with the JSON configuration data.",
196
205
  "examples": [
197
206
  "Push all SharinPix permissions to the default org:\n<%= config.bin %> <%= command.id %>",
198
- "Push SharinPix permissions to a specific org:\n<%= config.bin %> <%= command.id %> --target-org myorg@example.com"
207
+ "Push SharinPix permissions to a specific org:\n<%= config.bin %> <%= command.id %> --target-org myorg@example.com",
208
+ "Push SharinPix permissions and delete orphaned records:\n<%= config.bin %> <%= command.id %> --delete"
199
209
  ],
200
210
  "flags": {
201
211
  "json": {
@@ -223,6 +233,14 @@
223
233
  "hasDynamicHelp": true,
224
234
  "multiple": false,
225
235
  "type": "option"
236
+ },
237
+ "delete": {
238
+ "char": "d",
239
+ "description": "When enabled, this flag will delete SharinPix permission records from the Salesforce org if their corresponding local JSON files are missing. Use with caution as this operation cannot be undone.",
240
+ "name": "delete",
241
+ "summary": "Delete SharinPix permissions from org that no longer have corresponding local files.",
242
+ "allowNo": false,
243
+ "type": "boolean"
226
244
  }
227
245
  },
228
246
  "hasDynamicHelp": true,
@@ -253,5 +271,5 @@
253
271
  ]
254
272
  }
255
273
  },
256
- "version": "1.7.0"
274
+ "version": "1.9.0"
257
275
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sharinpix/sharinpix-sf-cli",
3
3
  "description": "SharinPix salesforce cli plugin",
4
- "version": "1.7.0",
4
+ "version": "1.9.0",
5
5
  "dependencies": {
6
6
  "@oclif/core": "^4",
7
7
  "@salesforce/core": "^8",
@@ -183,8 +183,10 @@
183
183
  "@salesforce/cli-plugins-testkit": "^5.3.10",
184
184
  "@salesforce/dev-scripts": "^10",
185
185
  "@types/mocha": "^10.0.7",
186
+ "@types/mock-fs": "^4.13.4",
186
187
  "eslint-plugin-sf-plugin": "^1.18.6",
187
188
  "husky": "^9.1.7",
189
+ "mock-fs": "^5.5.0",
188
190
  "oclif": "^4.14.0",
189
191
  "semantic-release": "^24.2.7",
190
192
  "ts-node": "^10.9.2",