diff --git a/package.json b/package.json index c5f92b1c0f..19efce563a 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "faye": "^1.4.0", "form-data": "^4.0.0", "js2xmlparser": "^4.0.1", - "jsforce": "^2.0.0-beta.24", + "jsforce": "^2.0.0-beta.25", "jsonwebtoken": "9.0.0", "jszip": "3.10.1", "proper-lockfile": "^4.1.2", @@ -171,4 +171,4 @@ ] } } -} \ No newline at end of file +} diff --git a/src/org/authInfo.ts b/src/org/authInfo.ts index 0dd278cc36..1cc6f0c590 100644 --- a/src/org/authInfo.ts +++ b/src/org/authInfo.ts @@ -25,7 +25,7 @@ import { Nullable, Optional, } from '@salesforce/ts-types'; -import { JwtOAuth2, JwtOAuth2Config, OAuth2, TokenResponse } from 'jsforce'; +import { OAuth2Config, OAuth2, TokenResponse } from 'jsforce'; import Transport from 'jsforce/lib/transport'; import * as jwt from 'jsonwebtoken'; import { Config } from '../config/config'; @@ -111,6 +111,14 @@ export type AuthSideEffects = { setTracksSource?: boolean; }; +export type JwtOAuth2Config = OAuth2Config & { + privateKey?: string; + privateKeyFile?: string; + authCode?: string; + refreshToken?: string; + username?: string; +}; + type UserInfo = AnyJson & { username: string; organizationId: string; @@ -938,10 +946,14 @@ export class AuthInfo extends AsyncOptionalCreatable { } ); - const oauth2 = new JwtOAuth2({ loginUrl }); - // jsforce has it types as any - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - return ensureJsonMap(await oauth2.jwtAuthorize(jwtToken)); + const oauth2 = new OAuth2({ loginUrl }); + return ensureJsonMap( + await oauth2.requestToken({ + // eslint-disable-next-line camelcase + grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', + assertion: jwtToken, + }) + ); } // Build OAuth config for a refresh token auth flow diff --git a/src/org/scratchOrgInfoApi.ts b/src/org/scratchOrgInfoApi.ts index 47ebb5fec5..9e42278659 100644 --- a/src/org/scratchOrgInfoApi.ts +++ b/src/org/scratchOrgInfoApi.ts @@ -7,8 +7,9 @@ import { env, Duration, upperFirst } from '@salesforce/kit'; import { AnyJson } from '@salesforce/ts-types'; -import { OAuth2Config, JwtOAuth2Config, SaveResult } from 'jsforce'; +import { OAuth2Config, SaveResult } from 'jsforce'; import { retryDecorator, RetryError } from 'ts-retry-promise'; +import { JwtOAuth2Config } from '../org/authInfo'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { SfError } from '../sfError'; diff --git a/src/org/scratchOrgLifecycleEvents.ts b/src/org/scratchOrgLifecycleEvents.ts index 32cbc6a29a..4d8e4470a2 100644 --- a/src/org/scratchOrgLifecycleEvents.ts +++ b/src/org/scratchOrgLifecycleEvents.ts @@ -21,7 +21,7 @@ export const scratchOrgLifecycleStages = [ 'done', ] as const; export interface ScratchOrgLifecycleEvent { - stage: typeof scratchOrgLifecycleStages[number]; + stage: (typeof scratchOrgLifecycleStages)[number]; scratchOrgInfo?: ScratchOrgInfo; } @@ -41,10 +41,10 @@ const postOrgCreateHookFields = [ 'username', ] as const; -type PostOrgCreateHook = Pick; +type PostOrgCreateHook = Pick; -const isHookField = (key: string): key is typeof postOrgCreateHookFields[number] => - postOrgCreateHookFields.includes(key as typeof postOrgCreateHookFields[number]); +const isHookField = (key: string): key is (typeof postOrgCreateHookFields)[number] => + postOrgCreateHookFields.includes(key as (typeof postOrgCreateHookFields)[number]); export const emitPostOrgCreate = async (authFields: AuthFields): Promise => { await emitter.emit( diff --git a/src/util/jsonXmlTools.ts b/src/util/jsonXmlTools.ts index ba7c79cb63..52d02ec402 100644 --- a/src/util/jsonXmlTools.ts +++ b/src/util/jsonXmlTools.ts @@ -41,7 +41,8 @@ export const writeJSONasXML = async ({ return fs.writeFile(path, xml); }; -export const JsonAsXml = ({ json, type, options = standardOptions }: JSONasXML): string => jsToXml.parse(type, fixExistingDollarSign(json), options); +export const JsonAsXml = ({ json, type, options = standardOptions }: JSONasXML): string => + jsToXml.parse(type, fixExistingDollarSign(json), options); export const fixExistingDollarSign = (existing: WriteJSONasXMLInputs['json']): Record => { const existingCopy = { ...existing } as Record; diff --git a/src/webOAuthServer.ts b/src/webOAuthServer.ts index 9345073875..b7633eb28c 100644 --- a/src/webOAuthServer.ts +++ b/src/webOAuthServer.ts @@ -12,7 +12,7 @@ import { parse as parseQueryString } from 'querystring'; import { parse as parseUrl } from 'url'; import { Socket } from 'net'; import { EventEmitter } from 'events'; -import { JwtOAuth2Config, OAuth2 } from 'jsforce'; +import { OAuth2 } from 'jsforce'; import { AsyncCreatable, Env, set, toNumber } from '@salesforce/kit'; import { asString, get, Nullable } from '@salesforce/ts-types'; import { Logger } from './logger'; @@ -20,6 +20,7 @@ import { AuthInfo, DEFAULT_CONNECTED_APP_INFO } from './org'; import { SfError } from './sfError'; import { Messages } from './messages'; import { SfProjectJson } from './sfProject'; +import { JwtOAuth2Config } from './org/authInfo'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/core', 'auth'); diff --git a/test/unit/org/authInfoTest.ts b/test/unit/org/authInfoTest.ts index 5a027cdfa7..a205b3316b 100644 --- a/test/unit/org/authInfoTest.ts +++ b/test/unit/org/authInfoTest.ts @@ -18,8 +18,9 @@ import { AnyJson, getJsonMap, JsonMap, toJsonMap } from '@salesforce/ts-types'; import { expect } from 'chai'; import { Transport } from 'jsforce/lib/transport'; -import { JwtOAuth2Config, OAuth2 } from 'jsforce'; +import { OAuth2 } from 'jsforce'; import { SinonSpy, SinonStub } from 'sinon'; +import { JwtOAuth2Config } from '../../../src/org/authInfo'; import { AuthFields, AuthInfo } from '../../../src/org'; import { MockTestOrgData, shouldThrow, shouldThrowSync, TestContext } from '../../../src/testSetup'; import { OrgConfigProperties } from '../../../src/org/orgConfigProperties'; diff --git a/yarn.lock b/yarn.lock index 3de94da7a6..6b7960f2f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2976,10 +2976,10 @@ jsesc@^2.5.1: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4" integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== -jsforce@^2.0.0-beta.24: - version "2.0.0-beta.24" - resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.24.tgz#fe054eb0f6f668eff10566e086892dd2387364f7" - integrity sha512-rbDC9Y054Ele3qlDyFZxFY6RRyqpH7DKPYhAwBM2TIzqOl9OG35EB4lnJLaIuv/MZVA2mvTIV/TwxVv8PiB1EA== +jsforce@^2.0.0-beta.25: + version "2.0.0-beta.25" + resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.25.tgz#120a3999babf96ae18ab8f1232003d56588a9ca5" + integrity sha512-ZtzwJErI4SSJYWrGAw0mHEHPZRB4Idz0RiXHakCtEgEjEWt6JIDR4sNbWRHUzWHdEO4O61z2YSBvdOuag1hkWg== dependencies: "@babel/runtime" "^7.12.5" "@babel/runtime-corejs3" "^7.12.5"