0.3.6 • Published 12 months ago

heat-sfdx-common v0.3.6

Weekly downloads
1
License
MIT
Repository
github
Last release
12 months ago

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

categorypackage
Metadata APIheat-sfdx-metadata
SOAP APIheat-sfdx-soap
Tooling APIheat-sfdx-tooling
Commonheat-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: 'admin@heat-sfdx-common.com',
  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

emojidefinition
: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
0.3.6

12 months ago

0.3.5

12 months ago

0.3.2

12 months ago

0.3.4

12 months ago

0.3.3

12 months ago

0.3.1

1 year ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.0

3 years ago

0.1.15

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.14

4 years ago

0.1.12

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago