@salesforce/plugin-api 1.2.1 → 1.3.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 +112 -52
- package/lib/commands/api/request/rest.d.ts +42 -2
- package/lib/commands/api/request/rest.js +96 -20
- package/lib/commands/api/request/rest.js.map +1 -1
- package/lib/shared/shared.d.ts +0 -2
- package/lib/shared/shared.js +0 -14
- package/lib/shared/shared.js.map +1 -1
- package/messages/graphql.md +12 -25
- package/messages/rest.md +53 -15
- package/oclif.manifest.json +32 -12
- package/package.json +10 -6
- package/npm-shrinkwrap.json +0 -13362
- package/oclif.lock +0 -7529
package/README.md
CHANGED
|
@@ -60,11 +60,11 @@ sf plugins
|
|
|
60
60
|
<!-- commands -->
|
|
61
61
|
|
|
62
62
|
- [`sf api request graphql`](#sf-api-request-graphql)
|
|
63
|
-
- [`sf api request rest
|
|
63
|
+
- [`sf api request rest [URL]`](#sf-api-request-rest-url)
|
|
64
64
|
|
|
65
65
|
## `sf api request graphql`
|
|
66
66
|
|
|
67
|
-
Execute GraphQL
|
|
67
|
+
Execute a GraphQL statement.
|
|
68
68
|
|
|
69
69
|
```
|
|
70
70
|
USAGE
|
|
@@ -77,92 +77,152 @@ FLAGS
|
|
|
77
77
|
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the
|
|
78
78
|
`target-org` configuration variable is already set.
|
|
79
79
|
--api-version=<value> Override the api version used for api requests made by this command
|
|
80
|
-
--body=file (required) File or content with GraphQL statement. Specify "-" to read
|
|
81
|
-
standard input.
|
|
80
|
+
--body=file (required) File or content with the GraphQL statement. Specify "-" to read
|
|
81
|
+
from standard input.
|
|
82
82
|
|
|
83
83
|
GLOBAL FLAGS
|
|
84
84
|
--flags-dir=<value> Import flag values from a directory.
|
|
85
85
|
--json Format output as json.
|
|
86
86
|
|
|
87
87
|
DESCRIPTION
|
|
88
|
-
Execute GraphQL
|
|
88
|
+
Execute a GraphQL statement.
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
Specify the GraphQL statement with the "--body" flag, either directly at the command line or with a file that contains
|
|
91
|
+
the statement. You can query Salesforce records using a "query" statement or use mutations to modify Salesforce
|
|
92
|
+
records.
|
|
93
|
+
|
|
94
|
+
This command uses the GraphQL API to query or modify Salesforce objects. For details about the API, and examples of
|
|
95
|
+
queries and mutations, see https://developer.salesforce.com/docs/platform/graphql/guide/graphql-about.html.
|
|
92
96
|
|
|
93
97
|
EXAMPLES
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
$ sf api request graphql --body example.txt
|
|
114
|
-
will create a new account returning specified fields (Id, Name)
|
|
98
|
+
Execute a GraphQL query on the Account object by specifying the query directly to the "--body" flag; the command
|
|
99
|
+
uses your default org:
|
|
100
|
+
|
|
101
|
+
$ sf api request graphql --body "query accounts { uiapi { query { Account { edges { node { Id \n Name { value } \
|
|
102
|
+
} } } } } }"
|
|
103
|
+
|
|
104
|
+
Read the GraphQL statement from a file called "example.txt" and execute it on an org with alias "my-org":
|
|
105
|
+
|
|
106
|
+
$ sf api request graphql --body example.txt --target-org my-org
|
|
107
|
+
|
|
108
|
+
Pipe the GraphQL statement that you want to execute from standard input to the command:
|
|
109
|
+
$ echo graphql | sf api request graphql --body -
|
|
110
|
+
|
|
111
|
+
Write the output of the command to a file called "output.txt" and include the HTTP response status and headers:
|
|
112
|
+
|
|
113
|
+
$ sf api request graphql --body example.txt --stream-to-file output.txt --include
|
|
115
114
|
```
|
|
116
115
|
|
|
117
|
-
_See code: [src/commands/api/request/graphql.ts](https://github.com/salesforcecli/plugin-api/blob/1.
|
|
116
|
+
_See code: [src/commands/api/request/graphql.ts](https://github.com/salesforcecli/plugin-api/blob/1.3.0/src/commands/api/request/graphql.ts)_
|
|
118
117
|
|
|
119
|
-
## `sf api request rest
|
|
118
|
+
## `sf api request rest [URL]`
|
|
120
119
|
|
|
121
|
-
Make an authenticated HTTP request
|
|
120
|
+
Make an authenticated HTTP request using the Salesforce REST API.
|
|
122
121
|
|
|
123
122
|
```
|
|
124
123
|
USAGE
|
|
125
|
-
$ sf api request rest
|
|
126
|
-
|
|
124
|
+
$ sf api request rest [URL] -o <value> [--flags-dir <value>] [--api-version <value>] [-i | -S Example: report.xlsx]
|
|
125
|
+
[-X GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE] [-H key:value...] [-f file] [-b file]
|
|
127
126
|
|
|
128
127
|
ARGUMENTS
|
|
129
|
-
|
|
128
|
+
URL Salesforce API endpoint
|
|
130
129
|
|
|
131
130
|
FLAGS
|
|
132
131
|
-H, --header=key:value... HTTP header in "key:value" format.
|
|
133
132
|
-S, --stream-to-file=Example: report.xlsx Stream responses to a file.
|
|
134
|
-
-X, --method=<option>
|
|
133
|
+
-X, --method=<option> HTTP method for the request.
|
|
135
134
|
<options: GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE>
|
|
135
|
+
-b, --body=file File or content for the body of the HTTP request. Specify "-" to read from
|
|
136
|
+
standard input or "" for an empty body.
|
|
137
|
+
-f, --file=file JSON file that contains values for the request header, body, method, and
|
|
138
|
+
URL.
|
|
136
139
|
-i, --include Include the HTTP response status and headers in the output.
|
|
137
140
|
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the
|
|
138
141
|
`target-org` configuration variable is already set.
|
|
139
142
|
--api-version=<value> Override the api version used for api requests made by this command
|
|
140
|
-
--body=file File to use as the body for the request. Specify "-" to read from standard
|
|
141
|
-
input; specify "" for an empty body.
|
|
142
143
|
|
|
143
144
|
GLOBAL FLAGS
|
|
144
145
|
--flags-dir=<value> Import flag values from a directory.
|
|
145
146
|
|
|
147
|
+
DESCRIPTION
|
|
148
|
+
Make an authenticated HTTP request using the Salesforce REST API.
|
|
149
|
+
|
|
150
|
+
When sending the HTTP request with the "--body" flag, you can specify the request directly at the command line or with
|
|
151
|
+
a file that contains the request.
|
|
152
|
+
|
|
153
|
+
For a full list of supported REST endpoints and resources, see
|
|
154
|
+
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_list.htm.
|
|
155
|
+
|
|
146
156
|
EXAMPLES
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
sf api request rest '
|
|
155
|
-
|
|
157
|
+
List information about limits in the org with alias "my-org":
|
|
158
|
+
|
|
159
|
+
$ sf api request rest 'limits' --target-org my-org
|
|
160
|
+
|
|
161
|
+
List all endpoints in your default org; write the output to a file called "output.txt" and include the HTTP response
|
|
162
|
+
status and headers:
|
|
163
|
+
|
|
164
|
+
$ sf api request rest '/' --stream-to-file output.txt --include
|
|
165
|
+
|
|
166
|
+
Get the response in XML format by specifying the "Accept" HTTP header:
|
|
167
|
+
|
|
168
|
+
$ sf api request rest 'limits' --header 'Accept: application/xml'
|
|
169
|
+
|
|
170
|
+
Create an account record using the POST method; specify the request details directly in the "--body" flag:
|
|
171
|
+
|
|
172
|
+
$ sf api request rest sobjects/account --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \
|
|
173
|
+
\"Boise\"}" --method POST
|
|
174
|
+
|
|
175
|
+
Create an account record using the information in a file called "info.json":
|
|
176
|
+
|
|
177
|
+
$ sf api request rest 'sobjects/account' --body info.json --method POST
|
|
178
|
+
|
|
179
|
+
Update an account record using the PATCH method:
|
|
180
|
+
|
|
181
|
+
$ sf api request rest 'sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method \
|
|
182
|
+
PATCH
|
|
183
|
+
|
|
184
|
+
Store the values for the request header, body, and so on, in a file, which you then specify with the --file flag;
|
|
185
|
+
see the description of --file for more information:
|
|
186
|
+
|
|
187
|
+
$ sf api request rest --file myFile.json
|
|
188
|
+
|
|
189
|
+
FLAG DESCRIPTIONS
|
|
190
|
+
-f, --file=file JSON file that contains values for the request header, body, method, and URL.
|
|
191
|
+
|
|
192
|
+
Use this flag instead of specifying the request details with individual flags, such as --body or --method. This
|
|
193
|
+
schema defines how to create the JSON file:
|
|
194
|
+
|
|
156
195
|
{
|
|
157
|
-
|
|
158
|
-
|
|
196
|
+
url: { raw: string } | string;
|
|
197
|
+
method: 'GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE';
|
|
198
|
+
description?: string;
|
|
199
|
+
header: string | Array<Record<string, string>>;
|
|
200
|
+
body: { mode: 'raw' | 'formdata'; raw: string; formdata: FormData };
|
|
159
201
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
202
|
+
|
|
203
|
+
Salesforce CLI defined this schema to be mimic Postman schemas; both share similar properties. The CLI's schema also
|
|
204
|
+
supports Postman Collections to reuse and share requests. As a result, you can build an API call using Postman,
|
|
205
|
+
export and save it to a file, and then use the file as a value to this flag. For information about Postman, see
|
|
206
|
+
https://learning.postman.com/.
|
|
207
|
+
|
|
208
|
+
Here's a simple example of a JSON file that contains values for the request URL, method, and body:
|
|
209
|
+
|
|
210
|
+
{
|
|
211
|
+
"url": "sobjects/Account/<Account ID>",
|
|
212
|
+
"method": "PATCH",
|
|
213
|
+
"body" : {
|
|
214
|
+
"mode": "raw",
|
|
215
|
+
"raw": {
|
|
216
|
+
"BillingCity": "Boise"
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
See more examples in the plugin-api test directory, including JSON files that use "formdata" to define collections:
|
|
222
|
+
https://github.com/salesforcecli/plugin-api/tree/main/test/test-files/data-project.
|
|
163
223
|
```
|
|
164
224
|
|
|
165
|
-
_See code: [src/commands/api/request/rest.ts](https://github.com/salesforcecli/plugin-api/blob/1.
|
|
225
|
+
_See code: [src/commands/api/request/rest.ts](https://github.com/salesforcecli/plugin-api/blob/1.3.0/src/commands/api/request/rest.ts)_
|
|
166
226
|
|
|
167
227
|
<!-- commandsstop -->
|
|
168
228
|
|
|
@@ -1,7 +1,43 @@
|
|
|
1
|
+
import type { Headers } from 'got';
|
|
1
2
|
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
3
|
import { Org } from '@salesforce/core';
|
|
4
|
+
import FormData from 'form-data';
|
|
5
|
+
declare const methodOptions: readonly ["GET", "POST", "PUT", "PATCH", "HEAD", "DELETE", "OPTIONS", "TRACE"];
|
|
6
|
+
type FileFormData = {
|
|
7
|
+
type: 'file';
|
|
8
|
+
src: string | string[];
|
|
9
|
+
key: string;
|
|
10
|
+
};
|
|
11
|
+
type StringFormData = {
|
|
12
|
+
type: 'text';
|
|
13
|
+
value: string;
|
|
14
|
+
key: string;
|
|
15
|
+
};
|
|
16
|
+
type FormDataPostmanSchema = {
|
|
17
|
+
mode: 'formdata';
|
|
18
|
+
formdata: Array<FileFormData | StringFormData>;
|
|
19
|
+
};
|
|
20
|
+
type RawPostmanSchema = {
|
|
21
|
+
mode: 'raw';
|
|
22
|
+
raw: string | Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
export type PostmanSchema = {
|
|
25
|
+
url: {
|
|
26
|
+
raw: string;
|
|
27
|
+
} | string;
|
|
28
|
+
method: typeof methodOptions;
|
|
29
|
+
description?: string;
|
|
30
|
+
header: string | Array<{
|
|
31
|
+
key: string;
|
|
32
|
+
value: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
description?: string;
|
|
35
|
+
}>;
|
|
36
|
+
body: RawPostmanSchema | FormDataPostmanSchema;
|
|
37
|
+
};
|
|
3
38
|
export declare class Rest extends SfCommand<void> {
|
|
4
39
|
static readonly summary: string;
|
|
40
|
+
static readonly description: string;
|
|
5
41
|
static readonly examples: string[];
|
|
6
42
|
static state: string;
|
|
7
43
|
static enableJsonFlag: boolean;
|
|
@@ -9,13 +45,17 @@ export declare class Rest extends SfCommand<void> {
|
|
|
9
45
|
'target-org': import("@oclif/core/interfaces").OptionFlag<Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
46
|
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
47
|
include: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
-
method: import("@oclif/core/interfaces").OptionFlag<"GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "TRACE" | "PATCH", import("@oclif/core/interfaces").CustomOptions>;
|
|
48
|
+
method: import("@oclif/core/interfaces").OptionFlag<"GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "TRACE" | "PATCH" | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
49
|
header: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
50
|
+
file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
51
|
'stream-to-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
52
|
body: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
53
|
};
|
|
17
54
|
static args: {
|
|
18
|
-
|
|
55
|
+
url: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
19
56
|
};
|
|
20
57
|
run(): Promise<void>;
|
|
21
58
|
}
|
|
59
|
+
export declare const getBodyContents: (body?: PostmanSchema["body"]) => string | FormData;
|
|
60
|
+
export declare function getHeaders(keyValPair: string[] | PostmanSchema['header'] | undefined): Headers;
|
|
61
|
+
export {};
|
|
@@ -4,17 +4,19 @@
|
|
|
4
4
|
* Licensed under the BSD 3-Clause license.
|
|
5
5
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
6
|
*/
|
|
7
|
-
import { readFileSync,
|
|
8
|
-
import { join } from 'node:path';
|
|
7
|
+
import { readFileSync, createReadStream } from 'node:fs';
|
|
9
8
|
import { ProxyAgent } from 'proxy-agent';
|
|
10
9
|
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
11
|
-
import { Messages, Org, SFDX_HTTP_HEADERS } from '@salesforce/core';
|
|
10
|
+
import { Messages, Org, SFDX_HTTP_HEADERS, SfError } from '@salesforce/core';
|
|
12
11
|
import { Args } from '@oclif/core';
|
|
13
|
-
import
|
|
12
|
+
import FormData from 'form-data';
|
|
13
|
+
import { includeFlag, sendAndPrintRequest, streamToFileFlag } from '../../../shared/shared.js';
|
|
14
14
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
15
15
|
const messages = Messages.loadMessages('@salesforce/plugin-api', 'rest');
|
|
16
|
+
const methodOptions = ['GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'];
|
|
16
17
|
export class Rest extends SfCommand {
|
|
17
18
|
static summary = messages.getMessage('summary');
|
|
19
|
+
static description = messages.getMessage('description');
|
|
18
20
|
static examples = messages.getMessages('examples');
|
|
19
21
|
static state = 'beta';
|
|
20
22
|
static enableJsonFlag = false;
|
|
@@ -23,10 +25,9 @@ export class Rest extends SfCommand {
|
|
|
23
25
|
'api-version': Flags.orgApiVersion(),
|
|
24
26
|
include: includeFlag,
|
|
25
27
|
method: Flags.option({
|
|
26
|
-
options:
|
|
28
|
+
options: methodOptions,
|
|
27
29
|
summary: messages.getMessage('flags.method.summary'),
|
|
28
30
|
char: 'X',
|
|
29
|
-
default: 'GET',
|
|
30
31
|
})(),
|
|
31
32
|
header: Flags.string({
|
|
32
33
|
summary: messages.getMessage('flags.header.summary'),
|
|
@@ -34,38 +35,58 @@ export class Rest extends SfCommand {
|
|
|
34
35
|
char: 'H',
|
|
35
36
|
multiple: true,
|
|
36
37
|
}),
|
|
38
|
+
file: Flags.file({
|
|
39
|
+
summary: messages.getMessage('flags.file.summary'),
|
|
40
|
+
description: messages.getMessage('flags.file.description'),
|
|
41
|
+
helpValue: 'file',
|
|
42
|
+
char: 'f',
|
|
43
|
+
}),
|
|
37
44
|
'stream-to-file': streamToFileFlag,
|
|
38
45
|
body: Flags.string({
|
|
39
46
|
summary: messages.getMessage('flags.body.summary'),
|
|
40
47
|
allowStdin: true,
|
|
41
48
|
helpValue: 'file',
|
|
49
|
+
char: 'b',
|
|
42
50
|
}),
|
|
43
51
|
};
|
|
44
52
|
static args = {
|
|
45
|
-
|
|
53
|
+
url: Args.string({
|
|
46
54
|
description: 'Salesforce API endpoint',
|
|
47
|
-
required:
|
|
55
|
+
required: false,
|
|
48
56
|
}),
|
|
49
57
|
};
|
|
50
58
|
async run() {
|
|
51
59
|
const { flags, args } = await this.parse(Rest);
|
|
52
60
|
const org = flags['target-org'];
|
|
53
61
|
const streamFile = flags['stream-to-file'];
|
|
54
|
-
const
|
|
62
|
+
const fileOptions = flags.file
|
|
63
|
+
? JSON.parse(readFileSync(flags.file, 'utf8'))
|
|
64
|
+
: undefined;
|
|
65
|
+
// validate that we have a URL to hit
|
|
66
|
+
if (!args.url && !fileOptions?.url) {
|
|
67
|
+
throw new SfError("The url is required either in --file file's content or as an argument");
|
|
68
|
+
}
|
|
69
|
+
// the conditional above ensures we either have an arg or it's in the file - now we just have to find where the URL value is
|
|
70
|
+
const specified = args.url ?? (fileOptions?.url).raw ?? fileOptions?.url;
|
|
71
|
+
const url = new URL(`${org.getField(Org.Fields.INSTANCE_URL)}/services/data/v${flags['api-version'] ?? (await org.retrieveMaxApiVersion())
|
|
55
72
|
// replace first '/' to create valid URL
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
}/${specified.replace(/\//y, '')}`);
|
|
74
|
+
// default the method to GET here to allow flags to override, but not hinder reading from files, rather than setting the default in the flag definition
|
|
75
|
+
const method = flags.method ?? fileOptions?.method ?? 'GET';
|
|
76
|
+
// @ts-expect-error users _could_ put one of these in their file without knowing it's wrong - TS is smarter than users here :)
|
|
77
|
+
if (!methodOptions.includes(method)) {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
79
|
+
throw new SfError(`"${method}" must be one of ${methodOptions.join(', ')}`);
|
|
80
|
+
}
|
|
81
|
+
const body = method !== 'GET' ? flags.body ?? getBodyContents(fileOptions?.body) : undefined;
|
|
82
|
+
let headers = getHeaders(flags.header ?? fileOptions?.header);
|
|
83
|
+
if (body instanceof FormData) {
|
|
84
|
+
// if it's a multi-part formdata request, those have extra headers
|
|
85
|
+
headers = { ...headers, ...body.getHeaders() };
|
|
86
|
+
}
|
|
66
87
|
const options = {
|
|
67
88
|
agent: { https: new ProxyAgent() },
|
|
68
|
-
method
|
|
89
|
+
method,
|
|
69
90
|
headers: {
|
|
70
91
|
...SFDX_HTTP_HEADERS,
|
|
71
92
|
Authorization: `Bearer ${
|
|
@@ -78,7 +99,62 @@ export class Rest extends SfCommand {
|
|
|
78
99
|
throwHttpErrors: false,
|
|
79
100
|
followRedirect: false,
|
|
80
101
|
};
|
|
102
|
+
await org.refreshAuth();
|
|
81
103
|
await sendAndPrintRequest({ streamFile, url, options, include: flags.include, this: this });
|
|
82
104
|
}
|
|
83
105
|
}
|
|
106
|
+
export const getBodyContents = (body) => {
|
|
107
|
+
if (!body?.mode) {
|
|
108
|
+
throw new SfError("No 'mode' found in 'body' entry", undefined, ['add "mode":"raw" | "formdata" to your body']);
|
|
109
|
+
}
|
|
110
|
+
if (body?.mode === 'raw') {
|
|
111
|
+
return JSON.stringify(body.raw);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// parse formdata
|
|
115
|
+
const form = new FormData();
|
|
116
|
+
body?.formdata.map((data) => {
|
|
117
|
+
if (data.type === 'text') {
|
|
118
|
+
form.append(data.key, data.value);
|
|
119
|
+
}
|
|
120
|
+
else if (data.type === 'file' && typeof data.src === 'string') {
|
|
121
|
+
form.append(data.key, createReadStream(data.src));
|
|
122
|
+
}
|
|
123
|
+
else if (Array.isArray(data.src)) {
|
|
124
|
+
form.append(data.key, data.src);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return form;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export function getHeaders(keyValPair) {
|
|
131
|
+
if (!keyValPair)
|
|
132
|
+
return {};
|
|
133
|
+
const headers = {};
|
|
134
|
+
if (typeof keyValPair === 'string') {
|
|
135
|
+
const [key, ...rest] = keyValPair.split(':');
|
|
136
|
+
headers[key.toLowerCase()] = rest.join(':').trim();
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
keyValPair.map((header) => {
|
|
140
|
+
if (typeof header === 'string') {
|
|
141
|
+
const [key, ...rest] = header.split(':');
|
|
142
|
+
const value = rest.join(':').trim();
|
|
143
|
+
if (!key || !value) {
|
|
144
|
+
throw new SfError(`Failed to parse HTTP header: "${header}".`, 'Failed To Parse HTTP Header', [
|
|
145
|
+
'Make sure the header is in a "key:value" format, e.g. "Accept: application/json"',
|
|
146
|
+
]);
|
|
147
|
+
}
|
|
148
|
+
headers[key.toLowerCase()] = value;
|
|
149
|
+
}
|
|
150
|
+
else if (!header.disabled) {
|
|
151
|
+
if (!header.key || !header.value) {
|
|
152
|
+
throw new SfError(`Failed to validate header: missing key: ${header.key} or value: ${header.value}`);
|
|
153
|
+
}
|
|
154
|
+
headers[header.key.toLowerCase()] = header.value;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return headers;
|
|
159
|
+
}
|
|
84
160
|
//# sourceMappingURL=rest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../../src/commands/api/request/rest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,Y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AI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACzC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;gBACpC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;oBACnB,MAAM,IAAI,OAAO,CAAC,iCAAiC,MAAM,IAAI,EAAE,6BAA6B,EAAE;wBAC5F,kFAAkF;qBACnF,CAAC,CAAC;gBACL,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;YACrC,CAAC;iBAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAC5B,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;oBACjC,MAAM,IAAI,OAAO,CAAC,2CAA2C,MAAM,CAAC,GAAG,cAAc,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;gBACvG,CAAC;gBACD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;YACnD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/lib/shared/shared.d.ts
CHANGED
package/lib/shared/shared.js
CHANGED
|
@@ -11,20 +11,6 @@ import ansis from 'ansis';
|
|
|
11
11
|
import got from 'got';
|
|
12
12
|
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
13
13
|
const messages = Messages.loadMessages('@salesforce/plugin-api', 'shared');
|
|
14
|
-
export function getHeaders(keyValPair) {
|
|
15
|
-
const headers = {};
|
|
16
|
-
for (const header of keyValPair) {
|
|
17
|
-
const [key, ...rest] = header.split(':');
|
|
18
|
-
const value = rest.join(':').trim();
|
|
19
|
-
if (!key || !value) {
|
|
20
|
-
throw new SfError(`Failed to parse HTTP header: "${header}".`, 'Failed To Parse HTTP Header', [
|
|
21
|
-
'Make sure the header is in a "key:value" format, e.g. "Accept: application/json"',
|
|
22
|
-
]);
|
|
23
|
-
}
|
|
24
|
-
headers[key] = value;
|
|
25
|
-
}
|
|
26
|
-
return headers;
|
|
27
|
-
}
|
|
28
14
|
export async function sendAndPrintRequest(options) {
|
|
29
15
|
if (options.streamFile) {
|
|
30
16
|
const responseStream = options.options.method
|
package/lib/shared/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/shared/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/shared/shared.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAa,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,wBAAwB,EAAE,QAAQ,CAAC,CAAC;AAE3E,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAMzC;IACC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM;YAC3C,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,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
|
|
1
1
|
# summary
|
|
2
2
|
|
|
3
|
-
Execute GraphQL
|
|
3
|
+
Execute a GraphQL statement.
|
|
4
4
|
|
|
5
5
|
# description
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Specify the GraphQL statement with the "--body" flag, either directly at the command line or with a file that contains the statement. You can query Salesforce records using a "query" statement or use mutations to modify Salesforce records.
|
|
8
|
+
|
|
9
|
+
This command uses the GraphQL API to query or modify Salesforce objects. For details about the API, and examples of queries and mutations, see https://developer.salesforce.com/docs/platform/graphql/guide/graphql-about.html.
|
|
8
10
|
|
|
9
11
|
# examples
|
|
10
12
|
|
|
11
|
-
-
|
|
13
|
+
- Execute a GraphQL query on the Account object by specifying the query directly to the "--body" flag; the command uses your default org:
|
|
12
14
|
|
|
13
15
|
<%= config.bin %> <%= command.id %> --body "query accounts { uiapi { query { Account { edges { node { Id \n Name { value } } } } } } }"
|
|
14
16
|
|
|
15
|
-
-
|
|
17
|
+
- Read the GraphQL statement from a file called "example.txt" and execute it on an org with alias "my-org":
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
uiapi {
|
|
19
|
-
AccountCreate(input: {
|
|
20
|
-
Account: {
|
|
21
|
-
Name: "Trailblazer Express"
|
|
22
|
-
}
|
|
23
|
-
}) {
|
|
24
|
-
Record {
|
|
25
|
-
Id
|
|
26
|
-
Name {
|
|
27
|
-
value
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
19
|
+
<%= config.bin %> <%= command.id %> --body example.txt --target-org my-org
|
|
33
20
|
|
|
34
|
-
|
|
21
|
+
- Pipe the GraphQL statement that you want to execute from standard input to the command:
|
|
35
22
|
|
|
36
|
-
|
|
23
|
+
$ echo graphql | sf api request graphql --body -
|
|
37
24
|
|
|
38
|
-
|
|
25
|
+
- Write the output of the command to a file called "output.txt" and include the HTTP response status and headers:
|
|
39
26
|
|
|
40
|
-
|
|
27
|
+
<%= config.bin %> <%= command.id %> --body example.txt --stream-to-file output.txt --include
|
|
41
28
|
|
|
42
29
|
# flags.body.summary
|
|
43
30
|
|
|
44
|
-
File or content with GraphQL statement. Specify "-" to read from standard input.
|
|
31
|
+
File or content with the GraphQL statement. Specify "-" to read from standard input.
|