UNPKG

6.35 kBTypeScriptView Raw
1import { AsyncCreatable } from '@salesforce/kit';
2import { SecureBuffer } from '../crypto/secureBuffer';
3import { Org } from './org';
4import { AuthInfo } from './authInfo';
5/**
6 * A Map of Required Salesforce User fields.
7 */
8export declare const REQUIRED_FIELDS: {
9 id: string;
10 username: string;
11 lastName: string;
12 alias: string;
13 timeZoneSidKey: string;
14 localeSidKey: string;
15 emailEncodingKey: string;
16 profileId: string;
17 languageLocaleKey: string;
18 email: string;
19};
20/**
21 * Required fields type needed to represent a Salesforce User object.
22 *
23 * **See** https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_user.htm
24 */
25export type UserFields = {
26 -readonly [K in keyof typeof REQUIRED_FIELDS]: string;
27};
28/**
29 * Provides a default set of fields values that can be used to create a user. This is handy for
30 * software development purposes.
31 *
32 * ```
33 * const connection: Connection = await Connection.create({
34 * authInfo: await AuthInfo.create({ username: 'user@example.com' })
35 * });
36 * const org: Org = await Org.create({ connection });
37 * const options: DefaultUserFields.Options = {
38 * templateUser: org.getUsername()
39 * };
40 * const fields = (await DefaultUserFields.create(options)).getFields();
41 * ```
42 */
43export declare class DefaultUserFields extends AsyncCreatable<DefaultUserFields.Options> {
44 private logger;
45 private userFields;
46 private options;
47 /**
48 * @ignore
49 */
50 constructor(options: DefaultUserFields.Options);
51 /**
52 * Get user fields.
53 */
54 getFields(): UserFields;
55 /**
56 * Initialize asynchronous components.
57 */
58 protected init(): Promise<void>;
59}
60export declare namespace DefaultUserFields {
61 /**
62 * Used to initialize default values for fields based on a templateUser user. This user will be part of the
63 * Standard User profile.
64 */
65 interface Options {
66 templateUser: string;
67 newUserName?: string;
68 }
69}
70export interface PasswordConditions {
71 length: number;
72 complexity: number;
73}
74/**
75 * A class for creating a User, generating a password for a user, and assigning a user to one or more permission sets.
76 * See methods for examples.
77 */
78export declare class User extends AsyncCreatable<User.Options> {
79 private org;
80 private logger;
81 /**
82 * @ignore
83 */
84 constructor(options: User.Options);
85 /**
86 * Generate default password for a user. Returns An encrypted buffer containing a utf8 encoded password.
87 */
88 static generatePasswordUtf8(passwordCondition?: PasswordConditions): SecureBuffer<void>;
89 /**
90 * Initialize a new instance of a user and return it.
91 */
92 init(): Promise<void>;
93 /**
94 * Assigns a password to a user. For a user to have the ability to assign their own password, the org needs the
95 * following org feature: EnableSetPasswordInApi.
96 *
97 * @param info The AuthInfo object for user to assign the password to.
98 * @param password [throwWhenRemoveFails = User.generatePasswordUtf8()] A SecureBuffer containing the new password.
99 */
100 assignPassword(info: AuthInfo, password?: SecureBuffer<void>): Promise<void>;
101 /**
102 * Methods to assign one or more permission set names to a user.
103 *
104 * @param id The Salesforce id of the user to assign the permission set to.
105 * @param permsetNames An array of permission set names.
106 *
107 * ```
108 * const username = 'user@example.com';
109 * const connection: Connection = await Connection.create({
110 * authInfo: await AuthInfo.create({ username })
111 * });
112 * const org = await Org.create({ connection });
113 * const user: User = await User.create({ org });
114 * const fields: UserFields = await user.retrieve(username);
115 * await user.assignPermissionSets(fields.id, ['sfdx', 'approver']);
116 * ```
117 */
118 assignPermissionSets(id: string, permsetNames: string[]): Promise<void>;
119 /**
120 * Method for creating a new User.
121 *
122 * By default scratch orgs only allow creating 2 additional users. Work with Salesforce Customer Service to increase
123 * user limits.
124 *
125 * The Org Preferences required to increase the number of users are:
126 * Standard User Licenses
127 * Salesforce CRM Content User
128 *
129 * @param fields The required fields for creating a user.
130 *
131 * ```
132 * const connection: Connection = await Connection.create({
133 * authInfo: await AuthInfo.create({ username: 'user@example.com' })
134 * });
135 * const org = await Org.create({ connection });
136 *
137 * const defaultUserFields = await DefaultUserFields.create({ templateUser: 'devhub_user@example.com' });
138 * const user: User = await User.create({ org });
139 * const info: AuthInfo = await user.createUser(defaultUserFields.getFields());
140 * ```
141 */
142 createUser(fields: UserFields): Promise<AuthInfo>;
143 /**
144 * Method to retrieve the UserFields for a user.
145 *
146 * @param username The username of the user.
147 *
148 * ```
149 * const username = 'boris@thecat.com';
150 * const connection: Connection = await Connection.create({
151 * authInfo: await AuthInfo.create({ username })
152 * });
153 * const org = await Org.create({ connection });
154 * const user: User = await User.create({ org });
155 * const fields: UserFields = await user.retrieve(username);
156 * ```
157 */
158 retrieve(username: string): Promise<UserFields>;
159 /**
160 * Helper method that verifies the server's User object is available and if so allows persisting the Auth information.
161 *
162 * @param newUserAuthInfo The AuthInfo for the new user.
163 */
164 private describeUserAndSave;
165 /**
166 * Helper that makes a REST request to create the user, and update additional required fields.
167 *
168 * @param fields The configuration the new user should have.
169 */
170 private createUserInternal;
171 private rawRequest;
172 /**
173 * Update the remaining required fields for the user.
174 *
175 * @param fields The fields for the user.
176 */
177 private updateRequiredUserFields;
178}
179export declare namespace User {
180 /**
181 * Used to initialize default values for fields based on a templateUser user. This user will be part of the
182 * Standard User profile.
183 */
184 interface Options {
185 org: Org;
186 }
187}