-
Notifications
You must be signed in to change notification settings - Fork 27
/
share.ts
53 lines (43 loc) · 2.01 KB
/
share.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { flags, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { AnyJson, ensureString } from '@salesforce/ts-types';
import { runCommand } from '../../../lib/sfdx';
// Initialize Messages with the current plugin directory
Messages.importMessagesDirectory(__dirname);
// Load the specific messages for this file. Messages from @salesforce/command, @salesforce/core,
// or any library that is using the messages framework can also be loaded this way.
const messages = Messages.loadMessages('sfdx-waw-plugin', 'waw');
export default class ConnectedAppCreate extends SfdxCommand {
public static description = messages.getMessage('org.share.description');
public static examples = [];
public static readonly flagsConfig = {
emailaddress: flags.email({
char: 'e',
description: messages.getMessage('org.share.flags.emailaddress'),
required: true
})
};
protected static requiresUsername = true;
public async run(): Promise<AnyJson> {
const emailAddress = this.flags.emailaddress;
const username = this.org.getUsername();
const devHub = await this.org.getDevHubOrg();
const devHubUsername = devHub.getUsername();
const frontDoorUrlForOrg = ensureString((await runCommand(`sfdx force:org:open --urlonly -u ${username}`)).url);
const options = {
method: 'post',
body: JSON.stringify({
inputs: [{
emailBody: `${devHubUsername} has created you a Salesforce org. Here's your login URL: ${frontDoorUrlForOrg}. Keep this URL confidential and do not share with others.`,
emailAddresses: emailAddress,
emailSubject: `${devHubUsername} created you a new Salesforce org`,
senderType: 'CurrentUser'
}]
}),
url: '/services/data/v36.0/actions/standard/emailSimple'
};
await devHub.getConnection().request(options);
this.ux.log(`Successfully shared ${username} with ${emailAddress}.`);
return { username, devHubUsername, emailAddress, frontDoorUrlForOrg };
}
}