@salesforce/core
Advanced tools
Comparing version 0.21.0 to 0.21.1
@@ -44,2 +44,7 @@ /** | ||
} | ||
export interface AccessTokenOptions { | ||
accessToken?: string; | ||
loginUrl?: string; | ||
instanceUrl?: string; | ||
} | ||
export declare type RefreshFn = (conn: Connection, callback: (err: Nullable<Error>, accessToken?: string, res?: object) => Promise<void>) => Promise<void>; | ||
@@ -92,3 +97,3 @@ export declare type ConnectionOptions = AuthFields & { | ||
*/ | ||
static create(username?: string, options?: OAuth2Options): Promise<AuthInfo>; | ||
static create(username?: string, options?: OAuth2Options | AccessTokenOptions): Promise<AuthInfo>; | ||
/** | ||
@@ -136,3 +141,3 @@ * Get a list of all auth files stored in the global directory. | ||
*/ | ||
init(options?: OAuth2Options): Promise<AuthInfo>; | ||
init(options?: OAuth2Options | AccessTokenOptions): Promise<AuthInfo>; | ||
/** | ||
@@ -199,2 +204,3 @@ * Get the username. | ||
getSfdxAuthUrl(): string; | ||
private isTokenOptions; | ||
private refreshFn; | ||
@@ -201,0 +207,0 @@ private buildJwtConfig; |
@@ -51,2 +51,9 @@ "use strict"; | ||
*/ | ||
/** | ||
* Options for access token flow. | ||
* @typedef AccessTokenOptions | ||
* @property {string} accessToken | ||
* @property {string} loginUrl | ||
* @property {string} instanceUrl | ||
*/ | ||
const kit_1 = require("@salesforce/kit"); | ||
@@ -349,17 +356,22 @@ const ts_types_1 = require("@salesforce/ts-types"); | ||
options = kit_1.cloneJson(options); | ||
// jwt flow | ||
// Support both sfdx and jsforce private key values | ||
if (!options.privateKey && options.privateKeyFile) { | ||
options.privateKey = options.privateKeyFile; | ||
if (this.isTokenOptions(options)) { | ||
authConfig = options; | ||
} | ||
if (options.privateKey) { | ||
authConfig = await this.buildJwtConfig(options); | ||
} | ||
else if (!options.authCode && options.refreshToken) { | ||
// refresh token flow (from sfdxUrl or OAuth refreshFn) | ||
authConfig = await this.buildRefreshTokenConfig(options); | ||
} | ||
else { | ||
// authcode exchange / web auth flow | ||
authConfig = await this.buildWebAuthConfig(options); | ||
// jwt flow | ||
// Support both sfdx and jsforce private key values | ||
if (!options.privateKey && options.privateKeyFile) { | ||
options.privateKey = options.privateKeyFile; | ||
} | ||
if (options.privateKey) { | ||
authConfig = await this.buildJwtConfig(options); | ||
} | ||
else if (!options.authCode && options.refreshToken) { | ||
// refresh token flow (from sfdxUrl or OAuth refreshFn) | ||
authConfig = await this.buildRefreshTokenConfig(options); | ||
} | ||
else { | ||
// authcode exchange / web auth flow | ||
authConfig = await this.buildWebAuthConfig(options); | ||
} | ||
} | ||
@@ -545,2 +557,11 @@ // Update the auth fields WITH encryption | ||
} | ||
isTokenOptions(options) { | ||
// Although OAuth2Options does not contain refreshToken, privateKey, or privateKeyFile, a JS consumer could still pass those in | ||
// which WILL have an access token as well, but it should be considered an OAuth2Options at that point. | ||
return 'accessToken' in options | ||
&& !('refreshToken' in options) | ||
&& !('privateKey' in options) | ||
&& !('privateKeyFile' in options) | ||
&& !('authCode' in options); | ||
} | ||
// A callback function for a connection to refresh an access token. This is used | ||
@@ -547,0 +568,0 @@ // both for a JWT connection and an OAuth connection. |
/// <reference types="node" /> | ||
import { JsonMap } from '@salesforce/ts-types'; | ||
import { Dictionary, JsonMap } from '@salesforce/ts-types'; | ||
import { EventEmitter } from 'events'; | ||
@@ -24,3 +24,3 @@ import { Org } from '../org'; | ||
*/ | ||
abstract addExtension(extension: JsonMap): void; | ||
abstract addExtension(extension: Dictionary): void; | ||
/** | ||
@@ -157,7 +157,6 @@ * Sets an http header name/value. | ||
* streamProcessor(message: JsonMap): StatusResult<string> { | ||
* if (!message.payload.id) { | ||
* throw new SfdxError('Not found.', 'NotFound'); | ||
* } | ||
* const payload = ensureJsonMap(message.payload); | ||
* const id = ensureString(payload.id); | ||
* | ||
* if (message.payload.status !== 'Active') { | ||
* if (payload.status !== 'Active') { | ||
* return { completed: false }; | ||
@@ -168,4 +167,4 @@ * } | ||
* completed: true, | ||
* payload: message.payload.id | ||
* } | ||
* payload: id | ||
* }; | ||
* } | ||
@@ -175,4 +174,3 @@ * | ||
* const options: StreamingOptions<string> = | ||
* new DefaultStreamingOptions(org, org.getConnection().getApiVersion(), | ||
* TOPIC, this.streamProcessor.bind(this)); | ||
* new DefaultStreamingOptions(org, TOPIC, this.streamProcessor); | ||
* | ||
@@ -186,4 +184,4 @@ * try { | ||
* // Now that we are subscribed, we can initiate the request that will cause the events to start streaming. | ||
* const requestResponse = await org.getConnection().request(url); | ||
* this.id = requestResponse.id; | ||
* const requestResponse = asJsonMap(asAnyJson(await org.getConnection().request(url))); | ||
* this.id = ensureString(requestResponse.id); | ||
* }); | ||
@@ -193,3 +191,3 @@ * | ||
* // handle streaming message errors and timeouts here. ex. If the handshake fails you could try polling. | ||
* .... | ||
* // .... | ||
* } | ||
@@ -217,2 +215,3 @@ * | ||
private constructor(); | ||
replay(replayId: number): void; | ||
/** | ||
@@ -226,3 +225,3 @@ * Provides a convenient way to handshake with the server endpoint before trying to subscribe. | ||
* Subscribe to streaming events. | ||
* @param {function} streamInit - This function should call the platform apis that result in streaming updates on push topics. | ||
* @param {function} [streamInit] - This function should call the platform apis that result in streaming updates on push topics. | ||
* @returns {Promise<T>} - When the streaming processor that's set in the options completes, it returns a payload in | ||
@@ -233,3 +232,3 @@ * the StatusResult object. The payload is just echoed here for convenience. | ||
*/ | ||
subscribe(streamInit: () => Promise<void>): Promise<T>; | ||
subscribe(streamInit?: () => Promise<void>): Promise<T>; | ||
private incoming; | ||
@@ -236,0 +235,0 @@ private doTimeout; |
@@ -139,7 +139,6 @@ "use strict"; | ||
* streamProcessor(message: JsonMap): StatusResult<string> { | ||
* if (!message.payload.id) { | ||
* throw new SfdxError('Not found.', 'NotFound'); | ||
* } | ||
* const payload = ensureJsonMap(message.payload); | ||
* const id = ensureString(payload.id); | ||
* | ||
* if (message.payload.status !== 'Active') { | ||
* if (payload.status !== 'Active') { | ||
* return { completed: false }; | ||
@@ -150,4 +149,4 @@ * } | ||
* completed: true, | ||
* payload: message.payload.id | ||
* } | ||
* payload: id | ||
* }; | ||
* } | ||
@@ -157,4 +156,3 @@ * | ||
* const options: StreamingOptions<string> = | ||
* new DefaultStreamingOptions(org, org.getConnection().getApiVersion(), | ||
* TOPIC, this.streamProcessor.bind(this)); | ||
* new DefaultStreamingOptions(org, TOPIC, this.streamProcessor); | ||
* | ||
@@ -168,4 +166,4 @@ * try { | ||
* // Now that we are subscribed, we can initiate the request that will cause the events to start streaming. | ||
* const requestResponse = await org.getConnection().request(url); | ||
* this.id = requestResponse.id; | ||
* const requestResponse = asJsonMap(asAnyJson(await org.getConnection().request(url))); | ||
* this.id = ensureString(requestResponse.id); | ||
* }); | ||
@@ -175,3 +173,3 @@ * | ||
* // handle streaming message errors and timeouts here. ex. If the handshake fails you could try polling. | ||
* .... | ||
* // .... | ||
* } | ||
@@ -227,2 +225,18 @@ * | ||
} | ||
replay(replayId) { | ||
this.cometClient.addExtension({ | ||
outgoing: (message, callback) => { | ||
if (message.channel === '/meta/subscribe') { | ||
if (!message.ext) { | ||
message.ext = {}; | ||
} | ||
const replayFromMap = {}; | ||
replayFromMap[this.options.channel] = replayId; | ||
// add "ext : { "replay" : { CHANNEL : REPLAY_VALUE }}" to subscribe message | ||
message.ext['replay'] = replayFromMap; | ||
} | ||
callback(message); | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -251,3 +265,3 @@ * Provides a convenient way to handshake with the server endpoint before trying to subscribe. | ||
* Subscribe to streaming events. | ||
* @param {function} streamInit - This function should call the platform apis that result in streaming updates on push topics. | ||
* @param {function} [streamInit] - This function should call the platform apis that result in streaming updates on push topics. | ||
* @returns {Promise<T>} - When the streaming processor that's set in the options completes, it returns a payload in | ||
@@ -299,3 +313,3 @@ * the StatusResult object. The payload is just echoed here for convenience. | ||
// will affect the streaming events. I.E. create an org or run apex tests. | ||
return streamInit(); | ||
return streamInit && streamInit(); | ||
}) | ||
@@ -302,0 +316,0 @@ .catch(error => { |
{ | ||
"name": "@salesforce/core", | ||
"version": "0.21.0", | ||
"version": "0.21.1", | ||
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.", | ||
@@ -5,0 +5,0 @@ "main": "lib/exported", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2645026
11430