@salesforce/core
Advanced tools
Comparing version 0.26.1 to 0.27.1
@@ -33,4 +33,6 @@ import { AsyncCreatable } from '@salesforce/kit'; | ||
* ``` | ||
* const options: DefaultUserFieldsOptions = { | ||
* templateUser: org.getUsername() || '' | ||
* const connection: Connection = await Connection.create({authInfo: await AuthInfo.create({username: 'user@example.com'})}); | ||
* const org: Org = await Org.create({ connection }); | ||
* const options: DefaultUserFields.Options = { | ||
* templateUser: org.getUsername() | ||
* }; | ||
@@ -40,3 +42,3 @@ * const fields = (await DefaultUserFields.create(options)).getFields(); | ||
*/ | ||
export declare class DefaultUserFields extends AsyncCreatable<User.Options> { | ||
export declare class DefaultUserFields extends AsyncCreatable<DefaultUserFields.Options> { | ||
private logger; | ||
@@ -48,3 +50,3 @@ private userFields; | ||
*/ | ||
constructor(options: User.Options); | ||
constructor(options: DefaultUserFields.Options); | ||
/** | ||
@@ -59,2 +61,12 @@ * Get user fields. | ||
} | ||
export declare namespace DefaultUserFields { | ||
/** | ||
* Used to initialize default values for fields based on a templateUser user. This user will be part of the | ||
* Standard User profile. | ||
*/ | ||
interface Options { | ||
templateUser: string; | ||
newUserName?: string; | ||
} | ||
} | ||
/** | ||
@@ -64,9 +76,4 @@ * A class for creating a User, generating a password for a user, and assigning a user to one or more permission sets. | ||
*/ | ||
export declare class User { | ||
export declare class User extends AsyncCreatable<User.Options> { | ||
/** | ||
* Initialize a new instance of a user and return it. | ||
* @param org The org associated with the user. | ||
*/ | ||
static init(org: Org): Promise<User>; | ||
/** | ||
* Generate default password for a user. Returns An encrypted buffer containing a utf8 encoded password. | ||
@@ -77,4 +84,11 @@ */ | ||
private logger; | ||
private constructor(); | ||
/** | ||
* @ignore | ||
*/ | ||
constructor(options: User.Options); | ||
/** | ||
* Initialize a new instance of a user and return it. | ||
*/ | ||
init(): Promise<void>; | ||
/** | ||
* Assigns a password to a user. For a user to have the ability to assign their own password, the org needs the | ||
@@ -92,5 +106,7 @@ * following org preference: SelfSetPasswordInApi. | ||
* ``` | ||
* const org = await Org.create(await Connection.create(await AuthInfo.create('standardUser'))); | ||
* const user: User = await User.init(org) | ||
* const fields: UserFields = await user.retrieve(); | ||
* const username = 'user@example.com'; | ||
* const connection: Connection = await Connection.create({authInfo: await AuthInfo.create({ username })}); | ||
* const org = await Org.create({ connection }); | ||
* const user: User = await User.create({ org }); | ||
* const fields: UserFields = await user.retrieve(username); | ||
* await user.assignPermissionSets(fields.id, ['sfdx', 'approver']); | ||
@@ -113,9 +129,11 @@ * ``` | ||
* ``` | ||
* const org = await Org.create(await Connection.create(await AuthInfo.create('fooUser'))); | ||
* const fields: UserFields = await DefaultUserFields.init(org); | ||
* const user: User = await User.init(org); | ||
* const info: AuthInfo = await user.create(fields); | ||
* const connection: Connection = await Connection.create({authInfo: await AuthInfo.create({username: 'user@example.com'})}); | ||
* const org = await Org.create({ connection }); | ||
* | ||
* const defaultUserFields = await DefaultUserFields.create({ templateUser: 'devhub_user@example.com' }); | ||
* const user: User = await User.create({ org }); | ||
* const info: AuthInfo = await user.createUser(defaultUserFields.getFields()); | ||
* ``` | ||
*/ | ||
create(fields: UserFields): Promise<AuthInfo>; | ||
createUser(fields: UserFields): Promise<AuthInfo>; | ||
/** | ||
@@ -126,5 +144,7 @@ * Method to retrieve the UserFields for a user. | ||
* ``` | ||
* const org = await Org.create(await Connection.create(await AuthInfo.create('fooUser'))); | ||
* const user: User = await User.init(org); | ||
* const fields: UserFields = await user.retrieve('boris@thecat.com') | ||
* const username = 'boris@thecat.com'; | ||
* const connection: Connection = await Connection.create({authInfo: await AuthInfo.create({ username })}); | ||
* const org = await Org.create({ connection }); | ||
* const user: User = await User.create({ org }); | ||
* const fields: UserFields = await user.retrieve(username); | ||
* ``` | ||
@@ -155,5 +175,4 @@ */ | ||
interface Options { | ||
templateUser: string; | ||
newUserName?: string; | ||
org: Org; | ||
} | ||
} |
@@ -96,4 +96,6 @@ "use strict"; | ||
* ``` | ||
* const options: DefaultUserFieldsOptions = { | ||
* templateUser: org.getUsername() || '' | ||
* const connection: Connection = await Connection.create({authInfo: await AuthInfo.create({username: 'user@example.com'})}); | ||
* const org: Org = await Org.create({ connection }); | ||
* const options: DefaultUserFields.Options = { | ||
* templateUser: org.getUsername() | ||
* }; | ||
@@ -140,17 +142,4 @@ * const fields = (await DefaultUserFields.create(options)).getFields(); | ||
*/ | ||
class User { | ||
class User extends kit_1.AsyncCreatable { | ||
/** | ||
* Initialize a new instance of a user and return it. | ||
* @param org The org associated with the user. | ||
*/ | ||
static async init(org) { | ||
if (!org) { | ||
throw sfdxError_1.SfdxError.create('@salesforce/core', 'user', 'orgRequired'); | ||
} | ||
const logger = await logger_1.Logger.child('User'); | ||
await org.refreshAuth(); | ||
logger.debug('Auth refresh ok'); | ||
return new User(org, logger); | ||
} | ||
/** | ||
* Generate default password for a user. Returns An encrypted buffer containing a utf8 encoded password. | ||
@@ -170,7 +159,18 @@ */ | ||
} | ||
constructor(org, logger) { | ||
this.org = org; | ||
this.logger = logger; | ||
/** | ||
* @ignore | ||
*/ | ||
constructor(options) { | ||
super(options); | ||
this.org = options.org; | ||
} | ||
/** | ||
* Initialize a new instance of a user and return it. | ||
*/ | ||
async init() { | ||
this.logger = await logger_1.Logger.child('User'); | ||
await this.org.refreshAuth(); | ||
this.logger.debug('Auth refresh ok'); | ||
} | ||
/** | ||
* Assigns a password to a user. For a user to have the ability to assign their own password, the org needs the | ||
@@ -205,5 +205,7 @@ * following org preference: SelfSetPasswordInApi. | ||
* ``` | ||
* const org = await Org.create(await Connection.create(await AuthInfo.create('standardUser'))); | ||
* const user: User = await User.init(org) | ||
* const fields: UserFields = await user.retrieve(); | ||
* const username = 'user@example.com'; | ||
* const connection: Connection = await Connection.create({authInfo: await AuthInfo.create({ username })}); | ||
* const org = await Org.create({ connection }); | ||
* const user: User = await User.create({ org }); | ||
* const fields: UserFields = await user.retrieve(username); | ||
* await user.assignPermissionSets(fields.id, ['sfdx', 'approver']); | ||
@@ -237,9 +239,11 @@ * ``` | ||
* ``` | ||
* const org = await Org.create(await Connection.create(await AuthInfo.create('fooUser'))); | ||
* const fields: UserFields = await DefaultUserFields.init(org); | ||
* const user: User = await User.init(org); | ||
* const info: AuthInfo = await user.create(fields); | ||
* const connection: Connection = await Connection.create({authInfo: await AuthInfo.create({username: 'user@example.com'})}); | ||
* const org = await Org.create({ connection }); | ||
* | ||
* const defaultUserFields = await DefaultUserFields.create({ templateUser: 'devhub_user@example.com' }); | ||
* const user: User = await User.create({ org }); | ||
* const info: AuthInfo = await user.createUser(defaultUserFields.getFields()); | ||
* ``` | ||
*/ | ||
async create(fields) { | ||
async createUser(fields) { | ||
// Create a user and get a refresh token | ||
@@ -276,5 +280,7 @@ const refreshTokenSecret = await this.createUserInternal(fields); | ||
* ``` | ||
* const org = await Org.create(await Connection.create(await AuthInfo.create('fooUser'))); | ||
* const user: User = await User.init(org); | ||
* const fields: UserFields = await user.retrieve('boris@thecat.com') | ||
* const username = 'boris@thecat.com'; | ||
* const connection: Connection = await Connection.create({authInfo: await AuthInfo.create({ username })}); | ||
* const org = await Org.create({ connection }); | ||
* const user: User = await User.create({ org }); | ||
* const fields: UserFields = await user.retrieve(username); | ||
* ``` | ||
@@ -281,0 +287,0 @@ */ |
{ | ||
"name": "@salesforce/core", | ||
"version": "0.26.1", | ||
"version": "0.27.1", | ||
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.", | ||
@@ -5,0 +5,0 @@ "main": "lib/exported", |
@@ -0,1 +1,4 @@ | ||
[![NPM](https://img.shields.io/npm/v/@salesforce/core.svg)](https://www.npmjs.com/package/@salesforce/core) | ||
[![CircleCI](https://circleci.com/gh/forcedotcom/sfdx-core.svg?style=svg&circle-token=2377ca31221869e9d13448313620486da80e595f)](https://circleci.com/gh/forcedotcom/sfdx-core) | ||
# Description | ||
@@ -9,3 +12,3 @@ | ||
## Contributing | ||
## Contributing | ||
@@ -16,4 +19,4 @@ If you are interested in contributing, please take a look at the [CONTRIBUTING](https://github.com/forcedotcom/sfdx-core/blob/develop/CONTRIBUTING.md) guide. | ||
* @forcedotcom/cli-packages - Base Salesforce CLI command | ||
* @forcedotcom/sfdx-plugin-generate - The generator plug-in for building plug-ins for Salesforce CLI | ||
- [@salesforce/command](https://github.com/forcedotcom/cli-packages/tree/master/packages/command) - Contains base Salesforce CLI command, `SfdxCommand`. | ||
- [@salesforce/plugin-generator](https://github.com/forcedotcom/sfdx-plugin-generate) - The generator plug-in for building plug-ins for Salesforce CLI. | ||
@@ -24,3 +27,3 @@ # Using TestSetup | ||
### Mocking AuthInfo | ||
## Mocking AuthInfo | ||
@@ -82,7 +85,7 @@ Here you can mock authorization for a Salesforce scratch org. | ||
### Using the Built-in Sinon Sandboxes | ||
## Using the Built-in Sinon Sandboxes | ||
sfdx-core uses Sinon as its underlying mocking system. If you're unfamiliar with Sinon and it's sandboxing concept you can find more information here: | ||
https://sinonjs.org/ | ||
Sinon stubs and spys must be cleaned up after test invocations. To ease the use of Sinon with sfdx core we've exposed our sandbox in TestSetup. After adding your own stubs and/or spys they will automatically be cleaned up after each test using mocha's afterEach method. | ||
Sinon `stub`s and `spy`s must be cleaned up after test invocations. To ease the use of Sinon with sfdx core we've exposed our sandbox in TestSetup. After adding your own `stub`s and/or `spy`s they will automatically be cleaned up after each test using mocha's afterEach method. | ||
@@ -106,5 +109,5 @@ ```typescript | ||
### Testing Expected Failures | ||
## Testing Expected Failures | ||
It's important to have negative tests that ensure proper error handling. With *shouldThrow* it's easy to test for expected async rejections. | ||
It's important to have negative tests that ensure proper error handling. With `shouldThrow` it's easy to test for expected async rejections. | ||
@@ -133,3 +136,3 @@ ```typescript | ||
### Testing Log Lines | ||
## Testing Log Lines | ||
@@ -136,0 +139,0 @@ It's also useful to check expected values and content from log lines. TestSetup configures the sfdx-core logger to use an in memory LogLine storage structure. These can be easily accessed from tests. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4024153
19865
164