Skip to content

Commit

Permalink
Merge pull request #1050 from forcedotcom/sm/core7-jsforce
Browse files Browse the repository at this point in the history
Sm/core7-jsforce
  • Loading branch information
mshanemc authored Apr 10, 2024
2 parents dc1e4a8 + de4943b commit 01b5620
Show file tree
Hide file tree
Showing 44 changed files with 320 additions and 431 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@

module.exports = {
extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license'],
rules: {},
root: true,
};
79 changes: 79 additions & 0 deletions MIGRATING_V6-V7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Migrating `@salesforce/core` from v6 to v7

v7 replaces `jsforce` with the new `@jsforce/jsforce-node`. It's a much smaller library. See https://github.com/jsforce/jsforce/issues/1374.

If you use `@salesforce/core` AND jsforce together, you should switch to using `@jsforce/jsforce-node`.

If you use another library that is using jsforce modules or types, be sure to update to a version of that library which uses `@jsforce/jsforce-node`

## Interfaces=>Type

We're going to standardize on Types instead of interfaces. They're almost identical except where they aren't. You probably won't notice.

## Breaking changes to AliasAccessor

Alias accessor had previously deprecated methods that are removed by this PR.

- `set`
- `unset`
- `unsetAll`
- `write` (has been a no-op since v6)

If you use these, typically via StateAggregator, update your code to use `setAndSave` or `unsetAndSave`

## SfError

SfError previously had a `cause` that conflicted with the more recent ES2022 native Error.cause

SfError has some new convenience methods. SfError.create (pass in props instead of setting 5 via params and others via instance methods).
SfError.wrap and the `cause` prop of SfError.create are now typed as `unknown` for convenience (throw the `unknown` from a catch block without having to worry about types!).
SfError.data is now constrained to be AnyJson (some sort of JSON/primitive or collection of that).

## Top-level exports

v7 exports more top-level modules. If you had previously imported via `@salesforce/core/lib/foo` you may be able to import them from the top-level. See the package.json for what's available now.

everything that was previously available via `import ____ from '@salesforce/core'` is still available the same way.

```
"./messages": {
"types": "./lib/messages.d.ts",
"require": "./lib/messages.js",
"import": "./lib/messages.js"
},
"./logger": {
"types": "./lib/logger.d.ts",
"require": "./lib/logger.js",
"import": "./lib/logger.js"
},
"./project": {
"types": "./lib/project.d.ts",
"require": "./lib/project.js",
"import": "./lib/project.js"
},
"./sfError": {
"types": "./lib/sfError.d.ts",
"require": "./lib/sfError.js",
"import": "./lib/sfError.js"
},
"./stateAggregator": {
"types": "./lib/stateAggregator/stateAggregator.d.ts",
"require": "./lib/stateAggregator/stateAggregator.js",
"import": "./lib/stateAggregator/stateAggregator.js"
},
"./configAggregator": {
"types": "./lib/config/configAggregator.d.ts",
"require": "./lib/config/configAggregator.js",
"import": "./lib/config/configAggregator.js"
},
"./lifecycle": {
"types": "./lib/lifecycleEvents.d.ts",
"require": "./lib/lifecycleEvents.js",
"import": "./lib/lifecycleEvents.js"
},
"./envVars": {
"types": "./lib/config/envVars.d.ts",
"require.js": "./lib/config/envVars.js",
"import": "./lib/config/envVars.js"
},
```
2 changes: 1 addition & 1 deletion TEST_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup';
import { AnyJson, ensureJsonMap, JsonMap } from '@salesforce/ts-types';
import { ensureString } from '@salesforce/ts-types';
import { deepStrictEqual } from 'assert';
import { QueryResult } from 'jsforce';
import { QueryResult } from '@jsforce/jsforce-node';

describe('Mocking a force server call', () => {
const $$ = new TestContext();
Expand Down
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
{
"name": "@salesforce/core",
"version": "6.7.6",
"version": "6.7.7-qa.1",
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
"main": "lib/index",
"types": "lib/index.d.ts",
"license": "BSD-3-Clause",
"engines": {
"node": ">=18.0.0"
},
"exports": {
".": "./lib/index.js",
"./testSetup": "./lib/testSetup.js",
"./messages": "./lib/messages.js",
"./sfError": "./lib/sfError.js",
"./lifecycle": "./lib/lifecycleEvents.js",
"./logger": "./lib/logger/logger.js",
"./configAggregator": "./lib/config/configAggregator.js",
"./stateAggregator": "./lib/stateAggregator/stateAggregator.js",
"./config": "./lib/config/config.js",
"./project": "./lib/sfProject.js",
"./messageTransformer": "./lib/messageTransformer.js"
},
"scripts": {
"build": "wireit",
"clean": "sf-clean",
Expand Down Expand Up @@ -38,6 +51,7 @@
"messageTransformer/messageTransformer.ts"
],
"dependencies": {
"@jsforce/jsforce-node": "^3.1.0",
"@salesforce/kit": "^3.1.0",
"@salesforce/schemas": "^1.7.0",
"@salesforce/ts-types": "^2.0.9",
Expand All @@ -46,7 +60,6 @@
"faye": "^1.4.0",
"form-data": "^4.0.0",
"js2xmlparser": "^4.0.1",
"jsforce": "^2.0.0-beta.29",
"jsonwebtoken": "9.0.2",
"jszip": "3.10.1",
"pino": "^8.19.0",
Expand All @@ -57,7 +70,7 @@
"ts-retry-promise": "^0.7.1"
},
"devDependencies": {
"@salesforce/dev-scripts": "^8.4.2",
"@salesforce/dev-scripts": "^8.5.0",
"@salesforce/ts-sinon": "^1.4.19",
"@types/benchmark": "^2.1.5",
"@types/chai-string": "^1.4.5",
Expand Down
8 changes: 4 additions & 4 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CONFIG_FILE_NAME = 'config.json';
/**
* Interface for meta information about config properties
*/
export interface ConfigPropertyMeta {
export type ConfigPropertyMeta = {
/**
* The config property name.
*/
Expand Down Expand Up @@ -65,12 +65,12 @@ export interface ConfigPropertyMeta {
* Is only used if deprecated is set to true.
*/
newKey?: string;
}
};

/**
* Config property input validation
*/
export interface ConfigPropertyMetaInput {
export type ConfigPropertyMetaInput = {
/**
* Tests if the input value is valid and returns true if the input data is valid.
*
Expand All @@ -82,7 +82,7 @@ export interface ConfigPropertyMetaInput {
* The message to return in the error if the validation fails.
*/
failedMessage: string | ((value: ConfigValue) => string);
}
};

export enum SfConfigProperties {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const messages = Messages.loadMessages('@salesforce/core', 'config');
/**
* Information about a config property.
*/
export interface ConfigInfo {
export type ConfigInfo = {
/**
* key The config key.
*/
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface ConfigInfo {
* True if the config property is deprecated.
*/
deprecated?: boolean;
}
};

/**
* Aggregate global and local project config files, as well as environment variables for
Expand Down
4 changes: 2 additions & 2 deletions src/config/configFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export namespace ConfigFile {
/**
* The interface for Config options.
*/
export interface Options extends BaseConfigStore.Options {
export type Options = {
/**
* The root folder where the config file is stored.
*/
Expand Down Expand Up @@ -435,5 +435,5 @@ export namespace ConfigFile {
* Indicates if init should throw if the corresponding config file is not found.
*/
throwOnNotFound?: boolean;
}
} & BaseConfigStore.Options;
}
8 changes: 4 additions & 4 deletions src/config/configStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ConfigContents, ConfigEntry, ConfigValue, Key } from './configStackType
/**
* An interface for a config object with a persistent store.
*/
export interface ConfigStore<P extends ConfigContents = ConfigContents> {
export type ConfigStore<P extends ConfigContents = ConfigContents> = {
// Map manipulation methods
entries(): ConfigEntry[];
// NEXT_RELEASE: update types to specify return can be P[K] | undefined
Expand All @@ -40,7 +40,7 @@ export interface ConfigStore<P extends ConfigContents = ConfigContents> {

// Content methods
getContents(): P;
}
};

/**
* An abstract class that implements all the config management functions but
Expand Down Expand Up @@ -433,7 +433,7 @@ export namespace BaseConfigStore {
/**
* Options for the config store.
*/
export interface Options {
export type Options = {
/**
* Keys to encrypt.
*
Expand All @@ -443,5 +443,5 @@ export namespace BaseConfigStore {
* defining a new class.
*/
encryptedKeys?: Array<string | RegExp>;
}
};
}
4 changes: 2 additions & 2 deletions src/config/orgUsersConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export namespace OrgUsersConfig {
/**
* The config file options.
*/
export interface Options extends ConfigFile.Options {
export type Options = {
/**
* The org id associated with this user.
*/
orgId: string;
}
} & ConfigFile.Options;
}
4 changes: 2 additions & 2 deletions src/config/sandboxOrgConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export namespace SandboxOrgConfig {
/**
* The config file options.
*/
export interface Options extends ConfigFile.Options {
export type Options = {
/**
* The org id associated with this sandbox.
*/
orgId: string;
}
} & ConfigFile.Options;

export enum Fields {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/crypto/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ const detectCryptoVersion = (pwd?: string): void => {
Messages.importMessagesDirectory(pathJoin(__dirname));
const messages = Messages.loadMessages('@salesforce/core', 'encryption');

interface CredType {
type CredType = {
username: string;
password: string;
}
};

const makeSecureBuffer = (password: string, encoding: CryptoEncoding): SecureBuffer<string> => {
const newSb = new SecureBuffer<string>();
Expand Down Expand Up @@ -179,12 +179,12 @@ const keychainPromises = {
},
};

interface CryptoOptions {
type CryptoOptions = {
keychain?: KeyChain;
platform?: string;
retryStatus?: string;
noResetOnClose?: boolean;
}
};

/**
* Class for managing encrypting and decrypting private auth information.
Expand Down
12 changes: 6 additions & 6 deletions src/crypto/keyChainImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const _validateProgram = async (
/**
* Basic keychain interface.
*/
export interface PasswordStore {
export type PasswordStore = {
/**
* Gets a password
*
Expand All @@ -106,7 +106,7 @@ export interface PasswordStore {
* @param fn function callback for password.
*/
setPassword(opts: ProgramOpts, fn: (error: Nullable<Error>, contents?: SecretContents) => void): Promise<void>;
}
};

/**
* @private
Expand Down Expand Up @@ -247,13 +247,13 @@ export class KeychainAccess implements PasswordStore {
}
}

interface ProgramOpts {
type ProgramOpts = {
account: string;
service: string;
password?: string;
}
};

interface OsImpl {
type OsImpl = {
getProgram(): string;
getProgramOptions(opts: ProgramOpts): string[];
getCommandFunc(
Expand All @@ -279,7 +279,7 @@ interface OsImpl {
opts: ProgramOpts,
fn: (err: Nullable<Error>) => void
): Promise<void>;
}
};

/**
* Linux implementation.
Expand Down
16 changes: 8 additions & 8 deletions src/deviceOauthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
/* eslint-disable camelcase */
/* eslint-disable @typescript-eslint/ban-types */

import Transport from 'jsforce/lib/transport';
import Transport from '@jsforce/jsforce-node/lib/transport';
import { AsyncCreatable, Duration, parseJsonMap, sleep } from '@salesforce/kit';
import { HttpRequest, OAuth2Config } from 'jsforce';
import { HttpRequest, OAuth2Config } from '@jsforce/jsforce-node';
import { ensureString, isString, JsonMap, Nullable } from '@salesforce/ts-types';
import FormData from 'form-data';
import { Logger } from './logger/logger';
Expand All @@ -21,14 +21,14 @@ import { Messages } from './messages';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'auth');

export interface DeviceCodeResponse extends JsonMap {
export type DeviceCodeResponse = {
device_code: string;
interval: number;
user_code: string;
verification_uri: string;
}
} & JsonMap;

export interface DeviceCodePollingResponse extends JsonMap {
export type DeviceCodePollingResponse = {
access_token: string;
refresh_token: string;
signature: string;
Expand All @@ -37,13 +37,13 @@ export interface DeviceCodePollingResponse extends JsonMap {
id: string;
token_type: string;
issued_at: string;
}
} & JsonMap;

interface DeviceCodeAuthError extends SfError {
type DeviceCodeAuthError = {
error: string;
error_description: string;
status: number;
}
} & SfError;

async function makeRequest<T extends JsonMap>(options: HttpRequest): Promise<T> {
const rawResponse = await new Transport().httpRequest(options);
Expand Down
Loading

2 comments on commit 01b5620

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 01b5620 Previous: b9050fc Ratio
Child logger creation 469593 ops/sec (±0.39%) 471071 ops/sec (±0.68%) 1.00
Logging a string on root logger 848118 ops/sec (±6.15%) 815084 ops/sec (±6.29%) 0.96
Logging an object on root logger 636707 ops/sec (±5.34%) 607732 ops/sec (±6.29%) 0.95
Logging an object with a message on root logger 5316 ops/sec (±217.18%) 8890 ops/sec (±204.54%) 1.67
Logging an object with a redacted prop on root logger 479366 ops/sec (±6.81%) 422802 ops/sec (±12.09%) 0.88
Logging a nested 3-level object on root logger 385060 ops/sec (±10.13%) 363163 ops/sec (±8.12%) 0.94

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 01b5620 Previous: b9050fc Ratio
Child logger creation 338484 ops/sec (±0.56%) 346417 ops/sec (±0.44%) 1.02
Logging a string on root logger 784094 ops/sec (±10.80%) 824843 ops/sec (±11.96%) 1.05
Logging an object on root logger 604801 ops/sec (±6.79%) 635539 ops/sec (±8.09%) 1.05
Logging an object with a message on root logger 6373 ops/sec (±206.35%) 2320 ops/sec (±242.77%) 0.36
Logging an object with a redacted prop on root logger 437363 ops/sec (±12.52%) 483051 ops/sec (±8.36%) 1.10
Logging a nested 3-level object on root logger 318606 ops/sec (±6.77%) 337662 ops/sec (±4.83%) 1.06

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.