@salesforce/plugin-api 1.1.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/LICENSE.txt +12 -0
- package/README.md +165 -0
- package/lib/commands/api/request/rest.d.ts +21 -0
- package/lib/commands/api/request/rest.js +128 -0
- package/lib/commands/api/request/rest.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/shared/methods.d.ts +2 -0
- package/lib/shared/methods.js +22 -0
- package/lib/shared/methods.js.map +1 -0
- package/messages/rest.md +56 -0
- package/npm-shrinkwrap.json +13361 -0
- package/oclif.lock +7529 -0
- package/oclif.manifest.json +130 -0
- package/package.json +207 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright (c) 2024, Salesforce.com, Inc.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
+
|
|
8
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
+
|
|
10
|
+
* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
|
+
|
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
**NOTE: This template for sf plugins is not yet official. Please consult with the Platform CLI team before using this template.**
|
|
2
|
+
|
|
3
|
+
# plugin-template-sf
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@salesforce/plugin-template-sf) [](https://npmjs.org/package/@salesforce/plugin-template-sf) [](https://raw.githubusercontent.com/salesforcecli/plugin-template-sf/main/LICENSE.txt)
|
|
6
|
+
|
|
7
|
+
## Using the template
|
|
8
|
+
|
|
9
|
+
This repository provides a template for creating a plugin for the Salesforce CLI. To convert this template to a working plugin:
|
|
10
|
+
|
|
11
|
+
1. Please get in touch with the Platform CLI team. We want to help you develop your plugin.
|
|
12
|
+
2. Generate your plugin:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
sf plugins install dev
|
|
16
|
+
sf dev generate plugin
|
|
17
|
+
|
|
18
|
+
git init -b main
|
|
19
|
+
git add . && git commit -m "chore: initial commit"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
3. Create your plugin's repo in the salesforcecli github org
|
|
23
|
+
4. When you're ready, replace the contents of this README with the information you want.
|
|
24
|
+
|
|
25
|
+
## Learn about `sf` plugins
|
|
26
|
+
|
|
27
|
+
Salesforce CLI plugins are based on the [oclif plugin framework](https://oclif.io/docs/introduction). Read the [plugin developer guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_plugins.meta/sfdx_cli_plugins/cli_plugins_architecture_sf_cli.htm) to learn about Salesforce CLI plugin development.
|
|
28
|
+
|
|
29
|
+
This repository contains a lot of additional scripts and tools to help with general Salesforce node development and enforce coding standards. You should familiarize yourself with some of the [node developer packages](#tooling) used by Salesforce. There is also a default circleci config using the [release management orb](https://github.com/forcedotcom/npm-release-management-orb) standards.
|
|
30
|
+
|
|
31
|
+
Additionally, there are some additional tests that the Salesforce CLI will enforce if this plugin is ever bundled with the CLI. These test are included by default under the `posttest` script and it is required to keep these tests active in your plugin if you plan to have it bundled.
|
|
32
|
+
|
|
33
|
+
### Tooling
|
|
34
|
+
|
|
35
|
+
- [@salesforce/core](https://github.com/forcedotcom/sfdx-core)
|
|
36
|
+
- [@salesforce/kit](https://github.com/forcedotcom/kit)
|
|
37
|
+
- [@salesforce/sf-plugins-core](https://github.com/salesforcecli/sf-plugins-core)
|
|
38
|
+
- [@salesforce/ts-types](https://github.com/forcedotcom/ts-types)
|
|
39
|
+
- [@salesforce/ts-sinon](https://github.com/forcedotcom/ts-sinon)
|
|
40
|
+
- [@salesforce/dev-config](https://github.com/forcedotcom/dev-config)
|
|
41
|
+
- [@salesforce/dev-scripts](https://github.com/forcedotcom/dev-scripts)
|
|
42
|
+
|
|
43
|
+
# Everything past here is only a suggestion as to what should be in your specific plugin's description
|
|
44
|
+
|
|
45
|
+
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).
|
|
46
|
+
|
|
47
|
+
We always recommend using the latest version of these commands bundled with the CLI, however, you can install a specific version or tag if needed.
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
sf plugins install @salesforce/plugin-template-sf@x.y.z
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Issues
|
|
56
|
+
|
|
57
|
+
Please report any issues at https://github.com/forcedotcom/cli/issues
|
|
58
|
+
|
|
59
|
+
## Contributing
|
|
60
|
+
|
|
61
|
+
1. Please read our [Code of Conduct](CODE_OF_CONDUCT.md)
|
|
62
|
+
2. Create a new issue before starting your project so that we can keep track of
|
|
63
|
+
what you are trying to add/fix. That way, we can also offer suggestions or
|
|
64
|
+
let you know if there is already an effort in progress.
|
|
65
|
+
3. Fork this repository.
|
|
66
|
+
4. [Build the plugin locally](#build)
|
|
67
|
+
5. Create a _topic_ branch in your fork. Note, this step is recommended but technically not required if contributing using a fork.
|
|
68
|
+
6. Edit the code in your fork.
|
|
69
|
+
7. Write appropriate tests for your changes. Try to achieve at least 95% code coverage on any new code. No pull request will be accepted without unit tests.
|
|
70
|
+
8. Sign CLA (see [CLA](#cla) below).
|
|
71
|
+
9. Send us a pull request when you are done. We'll review your code, suggest any needed changes, and merge it in.
|
|
72
|
+
|
|
73
|
+
### CLA
|
|
74
|
+
|
|
75
|
+
External contributors will be required to sign a Contributor's License
|
|
76
|
+
Agreement. You can do so by going to https://cla.salesforce.com/sign-cla.
|
|
77
|
+
|
|
78
|
+
### Build
|
|
79
|
+
|
|
80
|
+
To build the plugin locally, make sure to have yarn installed and run the following commands:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Clone the repository
|
|
84
|
+
git clone git@github.com:salesforcecli/plugin-template-sf
|
|
85
|
+
|
|
86
|
+
# Install the dependencies and compile
|
|
87
|
+
yarn && yarn build
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
To use your plugin, run using the local `./bin/dev` or `./bin/dev.cmd` file.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Run using local run file.
|
|
94
|
+
./bin/dev hello world
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
There should be no differences when running via the Salesforce CLI or using the local run file. However, it can be useful to link the plugin to do some additional testing or run your commands from anywhere on your machine.
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Link your plugin to the sf cli
|
|
101
|
+
sf plugins link .
|
|
102
|
+
# To verify
|
|
103
|
+
sf plugins
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Commands
|
|
107
|
+
|
|
108
|
+
<!-- commands -->
|
|
109
|
+
|
|
110
|
+
- [`sf api request rest ENDPOINT`](#sf-api-request-rest-endpoint)
|
|
111
|
+
|
|
112
|
+
## `sf api request rest ENDPOINT`
|
|
113
|
+
|
|
114
|
+
Make an authenticated HTTP request to Salesforce REST API and print the response.
|
|
115
|
+
|
|
116
|
+
````
|
|
117
|
+
USAGE
|
|
118
|
+
$ sf api request rest ENDPOINT -o <value> [--flags-dir <value>] [--api-version <value>] [-i | -S Example:
|
|
119
|
+
report.xlsx] [-X GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE] [-H key:value...] [--body file]
|
|
120
|
+
|
|
121
|
+
ARGUMENTS
|
|
122
|
+
ENDPOINT Salesforce API endpoint
|
|
123
|
+
|
|
124
|
+
FLAGS
|
|
125
|
+
-H, --header=key:value... HTTP header in "key:value" format.
|
|
126
|
+
-S, --stream-to-file=Example: report.xlsx Stream responses to a file.
|
|
127
|
+
-X, --method=<option> [default: GET] HTTP method for the request.
|
|
128
|
+
<options: GET|POST|PUT|PATCH|HEAD|DELETE|OPTIONS|TRACE>
|
|
129
|
+
-i, --include Include the HTTP response status and headers in the output.
|
|
130
|
+
-o, --target-org=<value> (required) Username or alias of the target org. Not required if the
|
|
131
|
+
`target-org` configuration variable is already set.
|
|
132
|
+
--api-version=<value> Override the api version used for api requests made by this command
|
|
133
|
+
--body=file File to use as the body for the request. Specify "-" to read from standard
|
|
134
|
+
input; specify "" for an empty body.
|
|
135
|
+
|
|
136
|
+
GLOBAL FLAGS
|
|
137
|
+
--flags-dir=<value> Import flag values from a directory.
|
|
138
|
+
|
|
139
|
+
EXAMPLES
|
|
140
|
+
- List information about limits in the org with alias "my-org":
|
|
141
|
+
sf api request rest 'limits' --target-org my-org
|
|
142
|
+
- List all endpoints
|
|
143
|
+
sf api request rest '/'
|
|
144
|
+
- Get the response in XML format by specifying the "Accept" HTTP header:
|
|
145
|
+
sf api request rest 'limits' --target-org my-org --header 'Accept: application/xml'
|
|
146
|
+
- POST to create an Account object
|
|
147
|
+
sf api request rest 'sobjects/account' --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \"Boise\"}" --method POST
|
|
148
|
+
- or with a file 'info.json' containing
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"Name": "Demo",
|
|
152
|
+
"ShippingCity": "Boise"
|
|
153
|
+
}
|
|
154
|
+
````
|
|
155
|
+
|
|
156
|
+
$ sf api request rest 'sobjects/account' --body info.json --method POST
|
|
157
|
+
|
|
158
|
+
- Update object
|
|
159
|
+
sf api request rest 'sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method PATCH
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
_See code: [src/commands/api/request/rest.ts](https://github.com/salesforcecli/plugin-api/blob/0.1.0/src/commands/api/request/rest.ts)_
|
|
164
|
+
<!-- commandsstop -->
|
|
165
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Org } from '@salesforce/core';
|
|
3
|
+
export declare class Rest extends SfCommand<void> {
|
|
4
|
+
static readonly summary: string;
|
|
5
|
+
static readonly examples: string[];
|
|
6
|
+
static state: string;
|
|
7
|
+
static enableJsonFlag: boolean;
|
|
8
|
+
static readonly flags: {
|
|
9
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
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>;
|
|
13
|
+
header: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
'stream-to-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
body: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
};
|
|
17
|
+
static args: {
|
|
18
|
+
endpoint: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
19
|
+
};
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023, 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 { createWriteStream, readFileSync, existsSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import got from 'got';
|
|
10
|
+
import { ProxyAgent } from 'proxy-agent';
|
|
11
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
12
|
+
import { Messages, Org, SFDX_HTTP_HEADERS, SfError } from '@salesforce/core';
|
|
13
|
+
import { Args } from '@oclif/core';
|
|
14
|
+
import ansis from 'ansis';
|
|
15
|
+
import { getHeaders } from '../../../shared/methods.js';
|
|
16
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
17
|
+
const messages = Messages.loadMessages('@salesforce/plugin-api', 'rest');
|
|
18
|
+
export class Rest extends SfCommand {
|
|
19
|
+
static summary = messages.getMessage('summary');
|
|
20
|
+
static examples = messages.getMessages('examples');
|
|
21
|
+
static state = 'beta';
|
|
22
|
+
static enableJsonFlag = false;
|
|
23
|
+
static flags = {
|
|
24
|
+
'target-org': Flags.requiredOrg(),
|
|
25
|
+
'api-version': Flags.orgApiVersion(),
|
|
26
|
+
include: Flags.boolean({
|
|
27
|
+
char: 'i',
|
|
28
|
+
summary: messages.getMessage('flags.include.summary'),
|
|
29
|
+
default: false,
|
|
30
|
+
exclusive: ['stream-to-file'],
|
|
31
|
+
}),
|
|
32
|
+
method: Flags.option({
|
|
33
|
+
options: ['GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'],
|
|
34
|
+
summary: messages.getMessage('flags.method.summary'),
|
|
35
|
+
char: 'X',
|
|
36
|
+
default: 'GET',
|
|
37
|
+
})(),
|
|
38
|
+
header: Flags.string({
|
|
39
|
+
summary: messages.getMessage('flags.header.summary'),
|
|
40
|
+
helpValue: 'key:value',
|
|
41
|
+
char: 'H',
|
|
42
|
+
multiple: true,
|
|
43
|
+
}),
|
|
44
|
+
'stream-to-file': Flags.string({
|
|
45
|
+
summary: messages.getMessage('flags.stream-to-file.summary'),
|
|
46
|
+
helpValue: 'Example: report.xlsx',
|
|
47
|
+
char: 'S',
|
|
48
|
+
exclusive: ['include'],
|
|
49
|
+
}),
|
|
50
|
+
body: Flags.string({
|
|
51
|
+
summary: messages.getMessage('flags.body.summary'),
|
|
52
|
+
allowStdin: true,
|
|
53
|
+
helpValue: 'file',
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
static args = {
|
|
57
|
+
endpoint: Args.string({
|
|
58
|
+
description: 'Salesforce API endpoint',
|
|
59
|
+
required: true,
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
async run() {
|
|
63
|
+
const { flags, args } = await this.parse(Rest);
|
|
64
|
+
const org = flags['target-org'];
|
|
65
|
+
const streamFile = flags['stream-to-file'];
|
|
66
|
+
const headers = flags.header ? getHeaders(flags.header) : {};
|
|
67
|
+
// replace first '/' to create valid URL
|
|
68
|
+
const endpoint = args.endpoint.startsWith('/') ? args.endpoint.replace('/', '') : args.endpoint;
|
|
69
|
+
const url = new URL(`${org.getField(Org.Fields.INSTANCE_URL)}/services/data/v${flags['api-version'] ?? (await org.retrieveMaxApiVersion())}/${endpoint}`);
|
|
70
|
+
const body = flags.method === 'GET'
|
|
71
|
+
? undefined
|
|
72
|
+
: // if they've passed in a file name, check and read it
|
|
73
|
+
existsSync(join(process.cwd(), flags.body ?? ''))
|
|
74
|
+
? readFileSync(join(process.cwd(), flags.body ?? ''))
|
|
75
|
+
: // otherwise it's a stdin, and we use it directly
|
|
76
|
+
flags.body;
|
|
77
|
+
await org.refreshAuth();
|
|
78
|
+
const options = {
|
|
79
|
+
agent: { https: new ProxyAgent() },
|
|
80
|
+
method: flags.method,
|
|
81
|
+
headers: {
|
|
82
|
+
...SFDX_HTTP_HEADERS,
|
|
83
|
+
Authorization: `Bearer ${
|
|
84
|
+
// we don't care about apiVersion here, just need to get the access token.
|
|
85
|
+
// eslint-disable-next-line sf-plugin/get-connection-with-version
|
|
86
|
+
org.getConnection().getConnectionOptions().accessToken}`,
|
|
87
|
+
...headers,
|
|
88
|
+
},
|
|
89
|
+
body,
|
|
90
|
+
throwHttpErrors: false,
|
|
91
|
+
followRedirect: false,
|
|
92
|
+
};
|
|
93
|
+
if (streamFile) {
|
|
94
|
+
const responseStream = got.stream(url, options);
|
|
95
|
+
const fileStream = createWriteStream(streamFile);
|
|
96
|
+
responseStream.pipe(fileStream);
|
|
97
|
+
fileStream.on('finish', () => this.log(`File saved to ${streamFile}`));
|
|
98
|
+
fileStream.on('error', (error) => {
|
|
99
|
+
throw SfError.wrap(error);
|
|
100
|
+
});
|
|
101
|
+
responseStream.on('error', (error) => {
|
|
102
|
+
throw SfError.wrap(error);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const res = await got(url, options);
|
|
107
|
+
// Print HTTP response status and headers.
|
|
108
|
+
if (flags.include) {
|
|
109
|
+
this.log(`HTTP/${res.httpVersion} ${res.statusCode}`);
|
|
110
|
+
Object.entries(res.headers).map(([header, value]) => {
|
|
111
|
+
this.log(`${ansis.blue.bold(header)}: ${Array.isArray(value) ? value.join(',') : value ?? '<undefined>'}`);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
// Try to pretty-print JSON response.
|
|
116
|
+
this.styledJSON(JSON.parse(res.body));
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
// If response body isn't JSON, just print it to stdout.
|
|
120
|
+
this.log(res.body === '' ? `Server responded with an empty body, status code ${res.statusCode}` : res.body);
|
|
121
|
+
}
|
|
122
|
+
if (res.statusCode >= 400) {
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=rest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../../src/commands/api/request/rest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,wBAAwB,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AAC;QACH,CAAC;IACH,CAAC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, 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
|
+
export default {};
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023, 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 { SfError } from '@salesforce/core';
|
|
8
|
+
export function getHeaders(keyValPair) {
|
|
9
|
+
const headers = {};
|
|
10
|
+
for (const header of keyValPair) {
|
|
11
|
+
const [key, ...rest] = header.split(':');
|
|
12
|
+
const value = rest.join(':').trim();
|
|
13
|
+
if (!key || !value) {
|
|
14
|
+
throw new SfError(`Failed to parse HTTP header: "${header}".`, 'Failed To Parse HTTP Header', [
|
|
15
|
+
'Make sure the header is in a "key:value" format, e.g. "Accept: application/json"',
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
headers[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return headers;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/shared/methods.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,MAAM,UAAU,UAAU,CAAC,UAAoB;IAC7C,MAAM,OAAO,GAA8B,EAAE,CAAC;IAE9C,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YACnB,MAAM,IAAI,OAAO,CAAC,iCAAiC,MAAM,IAAI,EAAE,6BAA6B,EAAE;gBAC5F,kFAAkF;aACnF,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/messages/rest.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# summary
|
|
2
|
+
|
|
3
|
+
Make an authenticated HTTP request to Salesforce REST API and print the response.
|
|
4
|
+
|
|
5
|
+
# examples
|
|
6
|
+
|
|
7
|
+
- List information about limits in the org with alias "my-org":
|
|
8
|
+
|
|
9
|
+
<%= config.bin %> <%= command.id %> 'limits' --target-org my-org
|
|
10
|
+
|
|
11
|
+
- List all endpoints
|
|
12
|
+
|
|
13
|
+
<%= config.bin %> <%= command.id %> '/'
|
|
14
|
+
|
|
15
|
+
- Get the response in XML format by specifying the "Accept" HTTP header:
|
|
16
|
+
|
|
17
|
+
<%= config.bin %> <%= command.id %> 'limits' --target-org my-org --header 'Accept: application/xml'
|
|
18
|
+
|
|
19
|
+
- POST to create an Account object
|
|
20
|
+
|
|
21
|
+
<%= config.bin %> <%= command.id %> 'sobjects/account' --body "{\"Name\" : \"Account from REST API\",\"ShippingCity\" : \"Boise\"}" --method POST
|
|
22
|
+
|
|
23
|
+
- or with a file 'info.json' containing
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"Name": "Demo",
|
|
28
|
+
"ShippingCity": "Boise"
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
<%= config.bin %> <%= command.id %> 'sobjects/account' --body info.json --method POST
|
|
33
|
+
|
|
34
|
+
- Update object
|
|
35
|
+
|
|
36
|
+
<%= config.bin %> <%= command.id %> 'sobjects/account/<Account ID>' --body "{\"BillingCity\": \"San Francisco\"}" --method PATCH
|
|
37
|
+
|
|
38
|
+
# flags.include.summary
|
|
39
|
+
|
|
40
|
+
Include the HTTP response status and headers in the output.
|
|
41
|
+
|
|
42
|
+
# flags.method.summary
|
|
43
|
+
|
|
44
|
+
HTTP method for the request.
|
|
45
|
+
|
|
46
|
+
# flags.header.summary
|
|
47
|
+
|
|
48
|
+
HTTP header in "key:value" format.
|
|
49
|
+
|
|
50
|
+
# flags.stream-to-file.summary
|
|
51
|
+
|
|
52
|
+
Stream responses to a file.
|
|
53
|
+
|
|
54
|
+
# flags.body.summary
|
|
55
|
+
|
|
56
|
+
File to use as the body for the request. Specify "-" to read from standard input; specify "" for an empty body.
|