Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

feat: add env api command #1

Merged
merged 5 commits into from
Dec 1, 2022
Merged

feat: add env api command #1

merged 5 commits into from
Dec 1, 2022

Conversation

cristiand391
Copy link
Owner

@cristiand391 cristiand391 commented Nov 17, 2022

What does this PR do?

Adds the env api command to interact with Saleforce APIs.
Original idea: https://cli.github.com/manual/gh_api

Benefits over curl:

  1. No need to set auth token in command line
  2. No need to set instance url, only provide the auth'd org alias or login

Example:

Upsert record field:

Screen Shot 2022-11-17 at 12 18 08

Get XML response by setting Accept header
also provides some help if header format is invalid
Screen Shot 2022-11-17 at 12 21 36

What issues does this PR fix or reference?

@W-11963169@

@@ -1,5 +1,3 @@
{
"test": {
"testsPath": "test/**/*.test.ts"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: re-enable the tests scripts once I add NUTs.
I skipped this as I'll need to set up some hub credentials for this repo.

"format": "sf-format",
"lint": "sf-lint",
"lint": "eslint \"src/**/*.ts\"",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sf-lint will fail as there's no test folder yet, replaced it to only look at the src folder.

default: false,
}),
method: Flags.enum<Method>({
options: ['GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'],
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got accepts lowercase HTTP methods but I decided to only support the uppercase ones only, the --help output for the command adds the possible options so having a bunch seems like a lot of noise.

let body: Buffer;

if (flags.body) {
body = await readFile(flags.body);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If body is passed, it would be convenient if the appropriate Content-Type header was added for you automatically.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, the command pass the body file to got as a Buffer so some headers are set:
https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#body

to get the content-type of the buffer we could use this
https://github.com/sindresorhus/file-type/

I'll add a new issue for this 👍🏼

summary: messages.getMessage('flags.target-org.summary'),
char: 'o',
}),
include: Flags.boolean({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include could have the short character i to match curl

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ✅

curl also has -I/--head which makes it only prints the headers and skip the response, I'll add a flag for that later, sometimes you are interested on the headers and if the response is big you need to scroll to the top.

@iowillhoit
Copy link
Contributor

This is awesome @cristiand391! I added a few "nice to haves", but feel free to go ahead and merge

QA Notes

  • Print JSON
  • Print XML
  • Update a record with JSON
  • Update a record with XML
  • List headers with --include
  • Confirm errors are printed to correct mistakes

@cristiand391
Copy link
Owner Author

Thanks @iowillhoit!

I added a link to the rest api guide in the command description and the shorter flag version for include.

@cristiand391 cristiand391 merged commit c8c7625 into main Dec 1, 2022
@cristiand391 cristiand391 deleted the cd/add-env-api-cmd branch December 1, 2022 19:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants