@simplysf/simply-data 1.1.7 → 1.1.9-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +47 -2
- package/lib/commands/simply/data/files/download.d.ts +13 -0
- package/lib/commands/simply/data/files/download.js +100 -0
- package/lib/commands/simply/data/files/download.js.map +1 -0
- package/lib/common/contentVersionTypes.d.ts +11 -1
- package/lib/common/contentVersionUtils.d.ts +2 -1
- package/lib/common/contentVersionUtils.js +10 -0
- package/lib/common/contentVersionUtils.js.map +1 -1
- package/messages/simply.data.files.download.md +33 -0
- package/npm-shrinkwrap.json +1303 -192
- package/oclif.lock +761 -67
- package/oclif.manifest.json +99 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [1.1.8](https://github.com/SimplySF/simply-data/compare/1.1.7...1.1.8) (2024-03-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** bump @oclif/core from 3.23.0 to 3.25.0 ([82656fb](https://github.com/SimplySF/simply-data/commit/82656fb8bc6cc80864dcb46d09d186977d597282))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
## [1.1.7](https://github.com/SimplySF/simply-data/compare/1.1.6...1.1.7) (2024-03-05)
|
|
2
11
|
|
|
3
12
|
|
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ sf plugins
|
|
|
57
57
|
|
|
58
58
|
<!-- commands -->
|
|
59
59
|
* [`sf simply data file upload`](#sf-simply-data-file-upload)
|
|
60
|
+
* [`sf simply data files download`](#sf-simply-data-files-download)
|
|
60
61
|
* [`sf simply data files upload`](#sf-simply-data-files-upload)
|
|
61
62
|
|
|
62
63
|
## `sf simply data file upload`
|
|
@@ -90,7 +91,51 @@ EXAMPLES
|
|
|
90
91
|
$ sf simply data file upload --file-path fileToUpload.txt --first-publish-location-id 0019000000DmehK --target-org myTargetOrg
|
|
91
92
|
```
|
|
92
93
|
|
|
93
|
-
_See code: [src/commands/simply/data/file/upload.ts](https://github.com/SimplySF/simply-data/blob/1.1.
|
|
94
|
+
_See code: [src/commands/simply/data/file/upload.ts](https://github.com/SimplySF/simply-data/blob/1.1.9-dev.0/src/commands/simply/data/file/upload.ts)_
|
|
95
|
+
|
|
96
|
+
## `sf simply data files download`
|
|
97
|
+
|
|
98
|
+
Download files from a Salesforce org.
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
USAGE
|
|
102
|
+
$ sf simply data files download -o <value> --where <value> [--json] [--api-version <value>] [--max-parallel-jobs
|
|
103
|
+
<value>]
|
|
104
|
+
|
|
105
|
+
FLAGS
|
|
106
|
+
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the `target-org`
|
|
107
|
+
configuration variable is already set.
|
|
108
|
+
--api-version=<value> Override the api version used for api requests made by this command
|
|
109
|
+
--max-parallel-jobs=<value> [default: 1] Maximum number of parallel jobs.
|
|
110
|
+
--where=<value> (required) WHERE clause for ContentVersion query.
|
|
111
|
+
|
|
112
|
+
GLOBAL FLAGS
|
|
113
|
+
--json Format output as json.
|
|
114
|
+
|
|
115
|
+
DESCRIPTION
|
|
116
|
+
Download files from a Salesforce org.
|
|
117
|
+
|
|
118
|
+
Downloads files specified by a where clause to a ContentVersion query from a Salesforce org. By default, the plugin
|
|
119
|
+
uses the REST API for the download as to allow for the streaming of large files without issue. This means that each
|
|
120
|
+
file will use one REST API request.
|
|
121
|
+
|
|
122
|
+
EXAMPLES
|
|
123
|
+
$ sf simply data files download --where 'IsLatest=true' --target-org myTargetOrg
|
|
124
|
+
|
|
125
|
+
$ sf simply data files download --where 'IsLatest=true' --max-parallel-jobs 5 --target-org myTargetOrg
|
|
126
|
+
|
|
127
|
+
FLAG DESCRIPTIONS
|
|
128
|
+
--max-parallel-jobs=<value> Maximum number of parallel jobs.
|
|
129
|
+
|
|
130
|
+
By default the plugin will only process a single file download at a time. You can increase this value to allow for
|
|
131
|
+
quasi concurrent downloads. Please note that setting this value too high can cause performance issues.
|
|
132
|
+
|
|
133
|
+
--where=<value> WHERE clause for ContentVersion query.
|
|
134
|
+
|
|
135
|
+
Provide a WHERE clause to allow the plugin to specify which ContentVersion records should be downloaded.
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
_See code: [src/commands/simply/data/files/download.ts](https://github.com/SimplySF/simply-data/blob/1.1.9-dev.0/src/commands/simply/data/files/download.ts)_
|
|
94
139
|
|
|
95
140
|
## `sf simply data files upload`
|
|
96
141
|
|
|
@@ -134,5 +179,5 @@ FLAG DESCRIPTIONS
|
|
|
134
179
|
quasi concurrent uploads. Please note that setting this value too high can cause performance issues.
|
|
135
180
|
```
|
|
136
181
|
|
|
137
|
-
_See code: [src/commands/simply/data/files/upload.ts](https://github.com/SimplySF/simply-data/blob/1.1.
|
|
182
|
+
_See code: [src/commands/simply/data/files/upload.ts](https://github.com/SimplySF/simply-data/blob/1.1.9-dev.0/src/commands/simply/data/files/upload.ts)_
|
|
138
183
|
<!-- commandsstop -->
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
export default class DataFilesDownload extends SfCommand<void> {
|
|
3
|
+
static readonly summary: string;
|
|
4
|
+
static readonly description: string;
|
|
5
|
+
static readonly examples: string[];
|
|
6
|
+
static readonly flags: {
|
|
7
|
+
'api-version': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
+
'max-parallel-jobs': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<number, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
9
|
+
'target-org': import("@oclif/core/lib/interfaces/parser.js").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
10
|
+
where: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024, Clay Chipps; Copyright (c) 2024, Salesforce.com, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* Licensed under the BSD 3-Clause license.
|
|
5
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
import { createObjectCsvWriter } from 'csv-writer';
|
|
8
|
+
import PQueue from 'p-queue';
|
|
9
|
+
import { Messages } from '@salesforce/core';
|
|
10
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
11
|
+
import { downloadContentVersion } from '../../../../common/contentVersionUtils.js';
|
|
12
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
13
|
+
const messages = Messages.loadMessages('@simplysf/simply-data', 'simply.data.files.download');
|
|
14
|
+
export default class DataFilesDownload extends SfCommand {
|
|
15
|
+
static summary = messages.getMessage('summary');
|
|
16
|
+
static description = messages.getMessage('description');
|
|
17
|
+
static examples = messages.getMessages('examples');
|
|
18
|
+
static flags = {
|
|
19
|
+
'api-version': Flags.orgApiVersion(),
|
|
20
|
+
'max-parallel-jobs': Flags.integer({
|
|
21
|
+
summary: messages.getMessage('flags.max-parallel-jobs.summary'),
|
|
22
|
+
description: messages.getMessage('flags.max-parallel-jobs.description'),
|
|
23
|
+
default: 1,
|
|
24
|
+
}),
|
|
25
|
+
'target-org': Flags.requiredOrg(),
|
|
26
|
+
where: Flags.string({
|
|
27
|
+
summary: messages.getMessage('flags.where.summary'),
|
|
28
|
+
description: messages.getMessage('flags.where.description'),
|
|
29
|
+
required: true,
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
async run() {
|
|
33
|
+
const { flags } = await this.parse(DataFilesDownload);
|
|
34
|
+
// Authorize to the target org
|
|
35
|
+
const targetOrgConnection = flags['target-org']?.getConnection(flags['api-version']);
|
|
36
|
+
if (!targetOrgConnection) {
|
|
37
|
+
throw messages.createError('error.targetOrgConnectionFailed');
|
|
38
|
+
}
|
|
39
|
+
this.spinner.start('Querying for files', '\n', { stdout: true });
|
|
40
|
+
const query = await targetOrgConnection.autoFetchQuery(`SELECT ContentDocumentId, ContentSize, Description, FileExtension, FileType, FirstPublishLocationId, Id, IsLatest, PathOnClient, Title FROM ContentVersion WHERE ${flags.where}`);
|
|
41
|
+
const contentVersionDownloads = query.records;
|
|
42
|
+
this.spinner.start('Downloading files', '\n', { stdout: true });
|
|
43
|
+
const successWriter = createObjectCsvWriter({
|
|
44
|
+
path: 'success.csv',
|
|
45
|
+
header: [
|
|
46
|
+
{ id: 'Id', title: 'Id' },
|
|
47
|
+
{ id: 'ContentDocumentId', title: 'ContentDocumentId' },
|
|
48
|
+
{ id: 'ContentSize', title: 'ContentSize' },
|
|
49
|
+
{ id: 'Description', title: 'Description' },
|
|
50
|
+
{ id: 'FileExtension', title: 'FileExtension' },
|
|
51
|
+
{ id: 'FileType', title: 'FileType' },
|
|
52
|
+
{ id: 'FirstPublishLocationId', title: 'FirstPublishLocationId' },
|
|
53
|
+
{ id: 'IsLatest', title: 'IsLatest' },
|
|
54
|
+
{ id: 'PathOnClient', title: 'PathOnClient' },
|
|
55
|
+
{ id: 'Title', title: 'Title' },
|
|
56
|
+
{ id: 'FilePath', title: 'FilePath' },
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
const errorWriter = createObjectCsvWriter({
|
|
60
|
+
path: 'error.csv',
|
|
61
|
+
header: [
|
|
62
|
+
{ id: 'Id', title: 'Id' },
|
|
63
|
+
{ id: 'ContentDocumentId', title: 'ContentDocumentId' },
|
|
64
|
+
{ id: 'ContentSize', title: 'ContentSize' },
|
|
65
|
+
{ id: 'Description', title: 'Description' },
|
|
66
|
+
{ id: 'FileExtension', title: 'FileExtension' },
|
|
67
|
+
{ id: 'FileType', title: 'FileType' },
|
|
68
|
+
{ id: 'FirstPublishLocationId', title: 'FirstPublishLocationId' },
|
|
69
|
+
{ id: 'IsLatest', title: 'IsLatest' },
|
|
70
|
+
{ id: 'PathOnClient', title: 'PathOnClient' },
|
|
71
|
+
{ id: 'Title', title: 'Title' },
|
|
72
|
+
{ id: 'Error', title: 'Error' },
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
const downloadQueue = new PQueue({ concurrency: flags['max-parallel-jobs'] });
|
|
76
|
+
let count = 0;
|
|
77
|
+
downloadQueue.on('add', () => {
|
|
78
|
+
this.spinner.status = `Completed: ${count}. Size: ${downloadQueue.size} Pending: ${downloadQueue.pending}\n`;
|
|
79
|
+
});
|
|
80
|
+
downloadQueue.on('completed', () => {
|
|
81
|
+
count++;
|
|
82
|
+
this.spinner.status = `Completed: ${count}. Size: ${downloadQueue.size} Pending: ${downloadQueue.pending}\n`;
|
|
83
|
+
});
|
|
84
|
+
for await (const contentVersionDownload of contentVersionDownloads) {
|
|
85
|
+
void downloadQueue.add(async () => {
|
|
86
|
+
try {
|
|
87
|
+
await downloadContentVersion(targetOrgConnection, contentVersionDownload);
|
|
88
|
+
await successWriter.writeRecords([contentVersionDownload]);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
contentVersionDownload.Error = error;
|
|
92
|
+
await errorWriter.writeRecords([contentVersionDownload]);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
await downloadQueue.onIdle();
|
|
97
|
+
this.spinner.stop();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["../../../../../src/commands/simply/data/files/download.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,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cAAc,KAAK,WAAW,aAAa,CAAC,IAAI,cAAc,aAAa,CAAC,OAAO,IAAI,CAAC;QAChH,CAAC,CAAC,CAAC;QAEH,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;YACjC,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,cAAc,KAAK,WAAW,aAAa,CAAC,IAAI,cAAc,aAAa,CAAC,OAAO,IAAI,CAAC;QAChH,CAAC,CAAC,CAAC;QAEH,IAAI,KAAK,EAAE,MAAM,sBAAsB,IAAI,uBAAuB,EAAE,CAAC;YACnE,KAAK,aAAa,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;gBAChC,IAAI,CAAC;oBACH,MAAM,sBAAsB,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,CAAC;oBAC1E,MAAM,aAAa,CAAC,YAAY,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC;gBAC7D,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,sBAAsB,CAAC,KAAK,GAAG,KAAe,CAAC;oBAC/C,MAAM,WAAW,CAAC,YAAY,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC;gBAC3D,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,aAAa,CAAC,MAAM,EAAE,CAAC;QAE7B,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export interface ContentVersion {
|
|
2
|
-
ContentDocumentId
|
|
2
|
+
ContentDocumentId: string;
|
|
3
|
+
ContentSize: string;
|
|
4
|
+
Description: string;
|
|
3
5
|
FileExtension: string;
|
|
6
|
+
FileType: string;
|
|
7
|
+
FirstPublishLocationId: string;
|
|
4
8
|
Id: string;
|
|
9
|
+
IsLatest: string;
|
|
10
|
+
PathOnClient: string;
|
|
5
11
|
Title: string;
|
|
6
12
|
}
|
|
7
13
|
export interface ContentVersionCreateRequest {
|
|
@@ -16,6 +22,10 @@ export interface ContentVersionCreateResult {
|
|
|
16
22
|
name: string;
|
|
17
23
|
message: string;
|
|
18
24
|
}
|
|
25
|
+
export interface ContentVersionDownload extends ContentVersion {
|
|
26
|
+
Error?: string;
|
|
27
|
+
FilePath?: string;
|
|
28
|
+
}
|
|
19
29
|
export type ContentVersionToUpload = {
|
|
20
30
|
ContentDocumentId?: string;
|
|
21
31
|
Error?: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Connection } from '@salesforce/core';
|
|
2
|
-
import { ContentVersion } from './contentVersionTypes.js';
|
|
2
|
+
import { ContentVersion, ContentVersionDownload } from './contentVersionTypes.js';
|
|
3
|
+
export declare function downloadContentVersion(targetOrgConnection: Connection, contentVersionDownload: ContentVersionDownload): Promise<void>;
|
|
3
4
|
export declare function uploadContentVersion(targetOrgConnection: Connection, pathOnClient: string, title?: string, firstPublishLocationId?: string): Promise<ContentVersion>;
|
|
@@ -6,8 +6,18 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
|
+
import stream from 'node:stream';
|
|
9
10
|
import FormData from 'form-data';
|
|
10
11
|
import got from 'got';
|
|
12
|
+
export async function downloadContentVersion(targetOrgConnection, contentVersionDownload) {
|
|
13
|
+
const filePath = `${contentVersionDownload.ContentDocumentId}_${contentVersionDownload.Title.replaceAll(' ', '_')}.${contentVersionDownload.FileExtension}`;
|
|
14
|
+
await stream.promises.pipeline(got.stream(`${targetOrgConnection.baseUrl()}/sobjects/ContentVersion/${contentVersionDownload.Id}/VersionData`, {
|
|
15
|
+
headers: {
|
|
16
|
+
Authorization: `Bearer ${targetOrgConnection.accessToken}`,
|
|
17
|
+
},
|
|
18
|
+
}), fs.createWriteStream(filePath));
|
|
19
|
+
contentVersionDownload.FilePath = filePath;
|
|
20
|
+
}
|
|
11
21
|
export async function uploadContentVersion(targetOrgConnection, pathOnClient, title, firstPublishLocationId) {
|
|
12
22
|
// Check that we have access to the file
|
|
13
23
|
await fs.promises.access(pathOnClient, fs.constants.F_OK);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentVersionUtils.js","sourceRoot":"","sources":["../../src/common/contentVersionUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,GAAG,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"contentVersionUtils.js","sourceRoot":"","sources":["../../src/common/contentVersionUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,GAAG,MAAM,KAAK,CAAC;AAStB,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,mBAA+B,EAC/B,sBAA8C;IAE9C,MAAM,QAAQ,GAAG,GAAG,sBAAsB,CAAC,iBAAiB,IAAI,sBAAsB,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,IAC/G,sBAAsB,CAAC,aACzB,EAAE,CAAC;IAEH,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAC5B,GAAG,CAAC,MAAM,CAAC,GAAG,mBAAmB,CAAC,OAAO,EAAE,4BAA4B,sBAAsB,CAAC,EAAE,cAAc,EAAE;QAC9G,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,mBAAmB,CAAC,WAAW,EAAE;SAC3D;KACF,CAAC,EACF,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAC/B,CAAC;IAEF,sBAAsB,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7C,CAAC;AAED,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
2
|
+
|
|
3
|
+
Download files from a Salesforce org.
|
|
4
|
+
|
|
5
|
+
# description
|
|
6
|
+
|
|
7
|
+
Downloads files specified by a where clause to a ContentVersion query from a Salesforce org. By default, the plugin uses the REST API for the download as to allow for the streaming of large files without issue. This means that each file will use one REST API request.
|
|
8
|
+
|
|
9
|
+
# flags.max-parallel-jobs.summary
|
|
10
|
+
|
|
11
|
+
Maximum number of parallel jobs.
|
|
12
|
+
|
|
13
|
+
# flags.max-parallel-jobs.description
|
|
14
|
+
|
|
15
|
+
By default the plugin will only process a single file download at a time. You can increase this value to allow for quasi concurrent downloads. Please note that setting this value too high can cause performance issues.
|
|
16
|
+
|
|
17
|
+
# flags.where.summary
|
|
18
|
+
|
|
19
|
+
WHERE clause for ContentVersion query.
|
|
20
|
+
|
|
21
|
+
# flags.where.description
|
|
22
|
+
|
|
23
|
+
Provide a WHERE clause to allow the plugin to specify which ContentVersion records should be downloaded.
|
|
24
|
+
|
|
25
|
+
# examples
|
|
26
|
+
|
|
27
|
+
- <%= config.bin %> <%= command.id %> --where 'IsLatest=true' --target-org myTargetOrg
|
|
28
|
+
|
|
29
|
+
- <%= config.bin %> <%= command.id %> --where 'IsLatest=true' --max-parallel-jobs 5 --target-org myTargetOrg
|
|
30
|
+
|
|
31
|
+
# error.targetOrgConnectionFailed
|
|
32
|
+
|
|
33
|
+
Unable to establish connection to the org.
|