Skip to content

This package is responsible for the common features of the heat-sfdx series.

License

Notifications You must be signed in to change notification settings

takahitomiyamoto/heat-sfdx-common

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MIT License npm version dependencies status devDependency status Code Climate

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:

src/auth.ts


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:

src/https.ts


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

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:

src/https.ts


json2xml(json: any): string

convert JSON to XML

  • json: any

Example:

import { json2xml } from 'heat-sfdx-common';

Code:

src/xml.ts


Emoji

emoji definition
♻️ refactored anything
🐛 fixed any bugs
👍 improved any features
added any features
🔥 removed any features
🎉 made a major change for any features

About

This package is responsible for the common features of the heat-sfdx series.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages