heat-sfdx-common
v0.3.7
Published
![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat) [![npm version](https://badge.fury.io/js/heat-sfdx-common.svg)](https://badge.fury.io/js/heat-sfdx-common) [![dependencies status](https://david-dm.org/takahitomiyamoto/heat-sfdx-
Downloads
206
Readme
heat-sfdx-common
This package is responsible for the common features of the heat-sfdx series.
heat-sfdx series
| category | package | | :----------- | :--------------------------------------------------------------------------- | | Metadata API | heat-sfdx-metadata | | SOAP API | heat-sfdx-soap | | Tooling API | heat-sfdx-tooling | | Common | heat-sfdx-common |
How to install
yarn add --dev --exact heat-sfdx-common --update-checksums
Reference
loginJwt(params: authentication): Promise<string>
login with JWT Bearer Flow.
- params: authentication
- privateKey: string | local path of a private key file for a certificate added to a connected app
- clientId: string | consumer key in a connected app
- username: string | username for login
- hostname: string | hostname fot login
Example:
import { loginJwt } from 'heat-sfdx-common';
const params: authentication = {
privateKey: '.secrets/server.key',
clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
username: '[email protected]',
hostname: 'login.salesforce.com'
};
const result = await loginJwt(params);
console.log(JSON.parse(result));
{
"accessToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"scope": "web api",
"instanceUrl": "https://xxxxx.my.salesforce.com",
"id": "https://login.salesforce.com/id/00Dxxxxxxxxxxxxxxx/005xxxxxxxxxxxxxxx",
"tokenType": "Bearer"
}
Code:
httpRequest(options: https.RequestOptions, requestBody?: string): Promise<any>
send HTTP request
- options: https.RequestOptions
- hostname: string | hostname
- path: string | endpoint
- method: string | HTTP method
- headers: any | HTTP headers
- requestBody: string | HTTP request body
Example:
import { httpRequest } from 'heat-sfdx-common';
const options = {
hostname: 'login.salesforce.com',
path: '/services/oauth2/token',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
const bodyString =
'grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=xxxxxxxxxxxxxxxxxxxx';
const result: any = await httpRequest(options, bodyString);
console.log(JSON.parse(result));
{
"accessToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"scope": "web api",
"instanceUrl": "https://xxxxx.my.salesforce.com",
"id": "https://login.salesforce.com/id/00Dxxxxxxxxxxxxxxx/005xxxxxxxxxxxxxxx",
"tokenType": "Bearer"
}
Code:
requestBody2String(params: requestBody[]): string
[{key: k1, value: v1}, {key: k2, value: v2}, ... ]
=>k1=v1&k2=v2&...
- params: requestBody[]
- requestBody | HTTP request body
- key: string | key of HTTP request body
- value: string | value of HTTP request body
- requestBody | HTTP request body
Example:
import { requestBody2String } from 'heat-sfdx-common';
const bodies: requestBody[] = [
{
key: 'grant_type',
value: 'urn:ietf:params:oauth:grant-type:jwt-bearer'
},
{
key: 'assertion',
value: 'xxxxxxxxxxxxxxxxxxxx'
}
];
const bodyString: string = requestBody2String(bodies);
console.log(bodyString);
grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=xxxxxxxxxxxxxxxxxxxx
Code:
json2xml(json: any): string
convert JSON to XML
- json: any
Example:
import { json2xml } from 'heat-sfdx-common';
Code:
Emoji
| emoji | definition | | :--------- | :----------------------------------- | | :recycle: | refactored anything | | :bug: | fixed any bugs | | :+1: | improved any features | | :sparkles: | added any features | | :fire: | removed any features | | :tada: | made a major change for any features |