1 | import { AsyncCreatable } from '@salesforce/kit';
|
2 | import { AuthInfo } from './authInfo';
|
3 | import { Org } from './org';
|
4 | import { SecureBuffer } from './secureBuffer';
|
5 | /**
|
6 | * A Map of Required Salesforce User fields.
|
7 | */
|
8 | export 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 | */
|
25 | export declare 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 | */
|
43 | export 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 | }
|
60 | export 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 | }
|
70 | /**
|
71 | * A class for creating a User, generating a password for a user, and assigning a user to one or more permission sets.
|
72 | * See methods for examples.
|
73 | */
|
74 | export declare class User extends AsyncCreatable<User.Options> {
|
75 | /**
|
76 | * Generate default password for a user. Returns An encrypted buffer containing a utf8 encoded password.
|
77 | */
|
78 | static generatePasswordUtf8(): SecureBuffer<void>;
|
79 | private org;
|
80 | private logger;
|
81 | /**
|
82 | * @ignore
|
83 | */
|
84 | constructor(options: User.Options);
|
85 | /**
|
86 | * Initialize a new instance of a user and return it.
|
87 | */
|
88 | init(): Promise<void>;
|
89 | /**
|
90 | * Assigns a password to a user. For a user to have the ability to assign their own password, the org needs the
|
91 | * following org preference: SelfSetPasswordInApi.
|
92 | * @param info The AuthInfo object for user to assign the password to.
|
93 | * @param password [throwWhenRemoveFails = User.generatePasswordUtf8()] A SecureBuffer containing the new password.
|
94 | */
|
95 | assignPassword(info: AuthInfo, password?: SecureBuffer<void>): Promise<{}>;
|
96 | /**
|
97 | * Methods to assign one or more permission set names to a user.
|
98 | * @param id The Salesforce id of the user to assign the permission set to.
|
99 | * @param permsetNames An array of permission set names.
|
100 | *
|
101 | * ```
|
102 | * const username = 'user@example.com';
|
103 | * const connection: Connection = await Connection.create({
|
104 | * authInfo: await AuthInfo.create({ username })
|
105 | * });
|
106 | * const org = await Org.create({ connection });
|
107 | * const user: User = await User.create({ org });
|
108 | * const fields: UserFields = await user.retrieve(username);
|
109 | * await user.assignPermissionSets(fields.id, ['sfdx', 'approver']);
|
110 | * ```
|
111 | */
|
112 | assignPermissionSets(id: string, permsetNames: string[]): Promise<void>;
|
113 | /**
|
114 | * Method for creating a new User.
|
115 | *
|
116 | * By default scratch orgs only allow creating 2 additional users. Work with Salesforce Customer Service to increase
|
117 | * user limits.
|
118 | *
|
119 | * The Org Preferences required to increase the number of users are:
|
120 | * Standard User Licenses
|
121 | * Salesforce CRM Content User
|
122 | *
|
123 | * @param fields The required fields for creating a user.
|
124 | *
|
125 | * ```
|
126 | * const connection: Connection = await Connection.create({
|
127 | * authInfo: await AuthInfo.create({ username: 'user@example.com' })
|
128 | * });
|
129 | * const org = await Org.create({ connection });
|
130 | *
|
131 | * const defaultUserFields = await DefaultUserFields.create({ templateUser: 'devhub_user@example.com' });
|
132 | * const user: User = await User.create({ org });
|
133 | * const info: AuthInfo = await user.createUser(defaultUserFields.getFields());
|
134 | * ```
|
135 | */
|
136 | createUser(fields: UserFields): Promise<AuthInfo>;
|
137 | /**
|
138 | * Method to retrieve the UserFields for a user.
|
139 | * @param username The username of the user.
|
140 | *
|
141 | * ```
|
142 | * const username = 'boris@thecat.com';
|
143 | * const connection: Connection = await Connection.create({
|
144 | * authInfo: await AuthInfo.create({ username })
|
145 | * });
|
146 | * const org = await Org.create({ connection });
|
147 | * const user: User = await User.create({ org });
|
148 | * const fields: UserFields = await user.retrieve(username);
|
149 | * ```
|
150 | */
|
151 | retrieve(username: string): Promise<UserFields>;
|
152 | /**
|
153 | * Helper method that verifies the server's User object is available and if so allows persisting the Auth information.
|
154 | * @param newUserAuthInfo The AuthInfo for the new user.
|
155 | */
|
156 | private describeUserAndSave;
|
157 | /**
|
158 | * Helper that makes a REST request to create the user, and update additional required fields.
|
159 | * @param fields The configuration the new user should have.
|
160 | */
|
161 | private createUserInternal;
|
162 | /**
|
163 | * Update the remaining required fields for the user.
|
164 | * @param fields The fields for the user.
|
165 | */
|
166 | private updateRequiredUserFields;
|
167 | }
|
168 | export declare namespace User {
|
169 | /**
|
170 | * Used to initialize default values for fields based on a templateUser user. This user will be part of the
|
171 | * Standard User profile.
|
172 | */
|
173 | interface Options {
|
174 | org: Org;
|
175 | }
|
176 | }
|