prodlysfcli 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/prodly/checkin.d.ts +20 -0
- package/lib/commands/prodly/checkin.js +130 -0
- package/lib/commands/prodly/checkin.js.map +1 -0
- package/lib/commands/prodly/checkout.d.ts +21 -0
- package/lib/commands/prodly/checkout.js +137 -0
- package/lib/commands/prodly/checkout.js.map +1 -0
- package/lib/commands/prodly/deploy.d.ts +26 -0
- package/lib/commands/prodly/deploy.js +264 -0
- package/lib/commands/prodly/deploy.js.map +1 -0
- package/lib/commands/prodly/jobs.d.ts +15 -0
- package/lib/commands/prodly/jobs.js +33 -0
- package/lib/commands/prodly/jobs.js.map +1 -0
- package/lib/commands/prodly/manage.d.ts +24 -0
- package/lib/commands/prodly/manage.js +167 -0
- package/lib/commands/prodly/manage.js.map +1 -0
- package/lib/commands/prodly/version.d.ts +15 -0
- package/lib/commands/prodly/version.js +68 -0
- package/lib/commands/prodly/version.js.map +1 -0
- package/lib/constants/index.d.ts +5 -0
- package/lib/constants/index.js +6 -0
- package/lib/constants/index.js.map +1 -0
- package/lib/helpers/index.d.ts +6 -0
- package/lib/helpers/index.js +17 -0
- package/lib/helpers/index.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/services/connections.d.ts +7 -0
- package/lib/services/connections.js +109 -0
- package/lib/services/connections.js.map +1 -0
- package/lib/services/connections.types.d.ts +31 -0
- package/lib/services/connections.types.js +2 -0
- package/lib/services/connections.types.js.map +1 -0
- package/lib/services/jobs.d.ts +4 -0
- package/lib/services/jobs.js +26 -0
- package/lib/services/jobs.js.map +1 -0
- package/lib/services/jobs.types.d.ts +13 -0
- package/lib/services/jobs.types.js +2 -0
- package/lib/services/jobs.types.js.map +1 -0
- package/lib/services/manage-instances.d.ts +8 -0
- package/lib/services/manage-instances.js +108 -0
- package/lib/services/manage-instances.js.map +1 -0
- package/lib/services/manage-instances.types.d.ts +50 -0
- package/lib/services/manage-instances.types.js +2 -0
- package/lib/services/manage-instances.types.js.map +1 -0
- package/lib/services/queries.d.ts +8 -0
- package/lib/services/queries.js +54 -0
- package/lib/services/queries.js.map +1 -0
- package/lib/types/generic.d.ts +5 -0
- package/lib/types/generic.js +2 -0
- package/lib/types/generic.js.map +1 -0
- package/lib/types/prodly.d.ts +69 -0
- package/lib/types/prodly.js +2 -0
- package/lib/types/prodly.js.map +1 -0
- package/lib/types/salesforce.d.ts +14 -0
- package/lib/types/salesforce.js +2 -0
- package/lib/types/salesforce.js.map +1 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/index.js.map +1 -0
- package/npm-shrinkwrap.json +1428 -924
- package/oclif.lock +2160 -1952
- package/oclif.manifest.json +700 -2
- package/package.json +10 -10
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { JSONObject } from '../../types/generic.js';
|
|
3
|
+
export default class ProdlyCheckin extends SfCommand<JSONObject> {
|
|
4
|
+
static readonly summary: string;
|
|
5
|
+
static readonly description: string;
|
|
6
|
+
static readonly examples: string[];
|
|
7
|
+
static readonly flags: {
|
|
8
|
+
'target-dev-hub': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
comment: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
filter: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
instance: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
notes: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
plan: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
};
|
|
18
|
+
run(): Promise<JSONObject>;
|
|
19
|
+
private checkinInstance;
|
|
20
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Messages, SfError } from '@salesforce/core';
|
|
2
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
3
|
+
import { constructQueryFilter } from '../../helpers/index.js';
|
|
4
|
+
import { updateConnection } from '../../services/connections.js';
|
|
5
|
+
import { getManagedInstance } from '../../services/manage-instances.js';
|
|
6
|
+
import { getDeploymentEntityId } from '../../services/queries.js';
|
|
7
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
8
|
+
const commandMessages = Messages.loadMessages('prodlysfcli', 'prodly.checkin');
|
|
9
|
+
const prodlyMessages = Messages.loadMessages('prodlysfcli', 'prodly');
|
|
10
|
+
export default class ProdlyCheckin extends SfCommand {
|
|
11
|
+
static summary = commandMessages.getMessage('summary');
|
|
12
|
+
static description = prodlyMessages.getMessage('descriptionCheckinCommand');
|
|
13
|
+
static examples = commandMessages.getMessages('examples');
|
|
14
|
+
static flags = {
|
|
15
|
+
'target-dev-hub': Flags.requiredHub(),
|
|
16
|
+
'target-org': Flags.requiredOrg(),
|
|
17
|
+
branch: Flags.string({ char: 'b', summary: prodlyMessages.getMessage('branchFlagDescription') }),
|
|
18
|
+
comment: Flags.string({ char: 'c', required: true, summary: prodlyMessages.getMessage('commentFlagDescription') }),
|
|
19
|
+
dataset: Flags.string({ char: 't', summary: prodlyMessages.getMessage('dataSetFlagDescription') }),
|
|
20
|
+
filter: Flags.string({ char: 'q', summary: prodlyMessages.getMessage('queryFilterFlagDescription') }),
|
|
21
|
+
instance: Flags.string({ char: 'i', summary: prodlyMessages.getMessage('instanceFlagDescription') }),
|
|
22
|
+
notes: Flags.string({ char: 'z', summary: prodlyMessages.getMessage('notesFlagDescription') }),
|
|
23
|
+
plan: Flags.string({ char: 'p', summary: prodlyMessages.getMessage('deploymentPlanFlagDescription') }),
|
|
24
|
+
};
|
|
25
|
+
async run() {
|
|
26
|
+
const { flags } = await this.parse(ProdlyCheckin);
|
|
27
|
+
const { branch: branchFlag, comment: commentFlag, dataset: datasetFlag, filter: queryFilterFlag, instance: instanceFlag, notes: deploymentNotesFlag, plan: planFlag, } = flags;
|
|
28
|
+
this.log('Instance flag: ' + instanceFlag);
|
|
29
|
+
this.log('Deployment description flag: ' + deploymentNotesFlag);
|
|
30
|
+
this.log('Comment flag: ' + commentFlag);
|
|
31
|
+
this.log('Branch flag: ' + branchFlag);
|
|
32
|
+
this.log('Data set flag: ' + datasetFlag);
|
|
33
|
+
this.log('Deployment plan flag: ' + planFlag);
|
|
34
|
+
this.log('Query filter flag: ' + queryFilterFlag);
|
|
35
|
+
if (!datasetFlag && !planFlag) {
|
|
36
|
+
throw new SfError(prodlyMessages.getMessage('errorNoDatasetAndPlanFlags', []));
|
|
37
|
+
}
|
|
38
|
+
if (!datasetFlag && queryFilterFlag) {
|
|
39
|
+
throw new SfError(prodlyMessages.getMessage('errorQueryFilterFlag', []));
|
|
40
|
+
}
|
|
41
|
+
const org = flags['target-org'];
|
|
42
|
+
const hubOrg = flags['target-dev-hub'];
|
|
43
|
+
const hubConn = hubOrg.getConnection();
|
|
44
|
+
const print = (message, ...args) => this.log(message, ...args);
|
|
45
|
+
let mangedInstanceId = null;
|
|
46
|
+
let dataSetId;
|
|
47
|
+
let deploymentPlanId;
|
|
48
|
+
// Retrieve the data set or deployment plan to deploy
|
|
49
|
+
this.log('Retrieving data set or deployment plan to deploy.');
|
|
50
|
+
if (datasetFlag) {
|
|
51
|
+
dataSetId = await getDeploymentEntityId({
|
|
52
|
+
dataEntityFlag: datasetFlag,
|
|
53
|
+
dataEntityType: 'PDRI__DataSet__c',
|
|
54
|
+
hubConn,
|
|
55
|
+
print,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else if (planFlag) {
|
|
59
|
+
deploymentPlanId = await getDeploymentEntityId({
|
|
60
|
+
dataEntityFlag: planFlag,
|
|
61
|
+
dataEntityType: 'PDRI__Deployment_Plan__c',
|
|
62
|
+
hubConn,
|
|
63
|
+
print,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
this.log(`Data set ID: ${dataSetId ?? ''}`);
|
|
67
|
+
this.log(`Deployment plan ID: ${deploymentPlanId ?? ''}`);
|
|
68
|
+
// Check if instance is provided
|
|
69
|
+
if (instanceFlag) {
|
|
70
|
+
// Use provided managed instance
|
|
71
|
+
this.log(`Managed instance ID provided, using instance with id ${instanceFlag}`);
|
|
72
|
+
mangedInstanceId = instanceFlag;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// Retrieve the managed instance associated with target org
|
|
76
|
+
// DevHub control org is never used as the default
|
|
77
|
+
const managedInstance = await getManagedInstance({ hubConn, orgId: org.getOrgId(), print });
|
|
78
|
+
if (!managedInstance) {
|
|
79
|
+
throw new SfError(prodlyMessages.getMessage('errorManagedInstaceNotFound'));
|
|
80
|
+
}
|
|
81
|
+
this.log(`Managed instance ID retrieved, using instance with id ${managedInstance.id}`);
|
|
82
|
+
mangedInstanceId = managedInstance.id;
|
|
83
|
+
this.log('Refreshing org session auth');
|
|
84
|
+
try {
|
|
85
|
+
await org.refreshAuth();
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Target username not valid or not specified, refresh failed
|
|
89
|
+
}
|
|
90
|
+
// Update the connection with the latest access token
|
|
91
|
+
this.log('Updating the connection with the latest access token');
|
|
92
|
+
await updateConnection({ connectionId: managedInstance.connectionId, hubConn, org });
|
|
93
|
+
}
|
|
94
|
+
// Perform the checkin
|
|
95
|
+
const jobId = await this.checkinInstance({
|
|
96
|
+
branchFlag,
|
|
97
|
+
comment: commentFlag,
|
|
98
|
+
dataSetId,
|
|
99
|
+
deploymentNotes: deploymentNotesFlag,
|
|
100
|
+
deploymentPlanId,
|
|
101
|
+
filter: queryFilterFlag,
|
|
102
|
+
hubConn,
|
|
103
|
+
mangedInstanceId,
|
|
104
|
+
});
|
|
105
|
+
this.log(`Checkin launched with Job ID: ${jobId}`);
|
|
106
|
+
return { jobId, message: 'Checkin launched' };
|
|
107
|
+
}
|
|
108
|
+
async checkinInstance({ branchFlag, comment, dataSetId, deploymentNotes, deploymentPlanId, filter, hubConn, mangedInstanceId, }) {
|
|
109
|
+
this.log(`Performing checkin for managed instance with id ${mangedInstanceId}.`);
|
|
110
|
+
const path = `/services/apexrest/PDRI/v1/instances/${mangedInstanceId}/checkin`;
|
|
111
|
+
const checkinInstance = {
|
|
112
|
+
branchName: branchFlag,
|
|
113
|
+
datasetId: dataSetId,
|
|
114
|
+
deploymentNotes,
|
|
115
|
+
deploymentPlanId,
|
|
116
|
+
options: { commitMessage: comment },
|
|
117
|
+
queryFilter: constructQueryFilter(filter),
|
|
118
|
+
};
|
|
119
|
+
const request = {
|
|
120
|
+
body: JSON.stringify(checkinInstance),
|
|
121
|
+
method: 'POST',
|
|
122
|
+
url: path,
|
|
123
|
+
};
|
|
124
|
+
const res = await hubConn.request(request);
|
|
125
|
+
const jobsWrapper = JSON.parse(res);
|
|
126
|
+
const jobId = jobsWrapper.jobs[0].id;
|
|
127
|
+
return jobId;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=checkin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkin.js","sourceRoot":"","sources":["../../../src/commands/prodly/checkin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;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Object } from '../../types/generic.js';
|
|
3
|
+
export default class ProdlyCheckout extends SfCommand<JSONObject> {
|
|
4
|
+
static readonly summary: string;
|
|
5
|
+
static readonly description: string;
|
|
6
|
+
static readonly examples: string[];
|
|
7
|
+
static readonly flags: {
|
|
8
|
+
'target-dev-hub': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
deactivate: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
filter: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
instance: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
notes: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
plan: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
};
|
|
19
|
+
run(): Promise<JSONObject>;
|
|
20
|
+
private checkoutInstance;
|
|
21
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Messages, SfError } from '@salesforce/core';
|
|
2
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
3
|
+
import { constructQueryFilter } from '../../helpers/index.js';
|
|
4
|
+
import { updateConnection } from '../../services/connections.js';
|
|
5
|
+
import { getManagedInstance } from '../../services/manage-instances.js';
|
|
6
|
+
import { getDeploymentEntityId } from '../../services/queries.js';
|
|
7
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
8
|
+
const commandMessages = Messages.loadMessages('prodlysfcli', 'prodly.checkout');
|
|
9
|
+
const prodlyMessages = Messages.loadMessages('prodlysfcli', 'prodly');
|
|
10
|
+
export default class ProdlyCheckout extends SfCommand {
|
|
11
|
+
static summary = commandMessages.getMessage('summary');
|
|
12
|
+
static description = prodlyMessages.getMessage('descriptionCheckoutCommand');
|
|
13
|
+
static examples = commandMessages.getMessages('examples');
|
|
14
|
+
static flags = {
|
|
15
|
+
'target-dev-hub': Flags.requiredHub(),
|
|
16
|
+
'target-org': Flags.requiredOrg(),
|
|
17
|
+
branch: Flags.string({ char: 'b', summary: prodlyMessages.getMessage('branchFlagDescription') }),
|
|
18
|
+
dataset: Flags.string({ char: 't', summary: prodlyMessages.getMessage('dataSetFlagDescription') }),
|
|
19
|
+
deactivate: Flags.boolean({ char: 'e', summary: prodlyMessages.getMessage('deactivateFlagDescription') }),
|
|
20
|
+
filter: Flags.string({ char: 'q', summary: prodlyMessages.getMessage('queryFilterFlagDescription') }),
|
|
21
|
+
instance: Flags.string({ char: 'i', summary: prodlyMessages.getMessage('instanceFlagDescription') }),
|
|
22
|
+
name: Flags.string({ char: 'n', summary: prodlyMessages.getMessage('deplomentNameFlagDescription') }),
|
|
23
|
+
notes: Flags.string({ char: 'z', summary: prodlyMessages.getMessage('notesFlagDescription') }),
|
|
24
|
+
plan: Flags.string({ char: 'p', summary: prodlyMessages.getMessage('deploymentPlanFlagDescription') }),
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { flags } = await this.parse(ProdlyCheckout);
|
|
28
|
+
const { branch: branchFlag, dataset: datasetFlag, deactivate: deactivateFlag, filter: queryFilterFlag, instance: instanceFlag, name: deploymentNameFlag, notes: deploymentNotesFlag, plan: planFlag, } = flags;
|
|
29
|
+
this.log('Deployment name flag: ' + deploymentNameFlag);
|
|
30
|
+
this.log('Instance flag: ' + instanceFlag);
|
|
31
|
+
this.log('Deactivate flag: ' + deactivateFlag);
|
|
32
|
+
this.log('Deployment description flag: ' + deploymentNotesFlag);
|
|
33
|
+
this.log('Branch flag: ' + branchFlag);
|
|
34
|
+
this.log('Data set flag: ' + datasetFlag);
|
|
35
|
+
this.log('Deployment plan flag: ' + planFlag);
|
|
36
|
+
this.log('Query filter flag: ' + queryFilterFlag);
|
|
37
|
+
if (!datasetFlag && !planFlag) {
|
|
38
|
+
throw new SfError(prodlyMessages.getMessage('errorNoDatasetAndPlanFlags', []));
|
|
39
|
+
}
|
|
40
|
+
if (!deploymentNameFlag) {
|
|
41
|
+
throw new SfError(prodlyMessages.getMessage('errorDeploymentNameFlag', []));
|
|
42
|
+
}
|
|
43
|
+
if (!datasetFlag && queryFilterFlag) {
|
|
44
|
+
throw new SfError(prodlyMessages.getMessage('errorQueryFilterFlag', []));
|
|
45
|
+
}
|
|
46
|
+
const org = flags['target-org'];
|
|
47
|
+
const hubOrg = flags['target-dev-hub'];
|
|
48
|
+
const hubConn = hubOrg.getConnection();
|
|
49
|
+
const print = (message, ...args) => this.log(message, ...args);
|
|
50
|
+
let mangedInstanceId = null;
|
|
51
|
+
let dataSetId;
|
|
52
|
+
let deploymentPlanId;
|
|
53
|
+
// Retrieve the data set or deployment plan to deploy
|
|
54
|
+
this.log('Retrieving data set or deployment plan to deploy.');
|
|
55
|
+
if (datasetFlag !== undefined) {
|
|
56
|
+
dataSetId = await getDeploymentEntityId({
|
|
57
|
+
dataEntityFlag: datasetFlag,
|
|
58
|
+
dataEntityType: 'PDRI__DataSet__c',
|
|
59
|
+
hubConn,
|
|
60
|
+
print,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else if (planFlag !== undefined) {
|
|
64
|
+
deploymentPlanId = await getDeploymentEntityId({
|
|
65
|
+
dataEntityFlag: planFlag,
|
|
66
|
+
dataEntityType: 'PDRI__Deployment_Plan__c',
|
|
67
|
+
hubConn,
|
|
68
|
+
print,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
this.log('Data set ID: ' + dataSetId);
|
|
72
|
+
this.log('Deployment plan ID: ' + deploymentPlanId);
|
|
73
|
+
// Check if instance is provided
|
|
74
|
+
if (instanceFlag !== undefined) {
|
|
75
|
+
// Use provided managed instance
|
|
76
|
+
this.log(`Managed instance ID provided, using instance with id ${instanceFlag}`);
|
|
77
|
+
mangedInstanceId = instanceFlag;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Retrieve the managed instance associated with target org
|
|
81
|
+
// DevHub control org is never used as the default
|
|
82
|
+
const managedInstance = await getManagedInstance({ orgId: org.getOrgId(), hubConn, print });
|
|
83
|
+
if (!managedInstance) {
|
|
84
|
+
throw new SfError(prodlyMessages.getMessage('errorManagedInstaceNotFound'));
|
|
85
|
+
}
|
|
86
|
+
this.log(`Managed instance ID retrieved, using instance with id ${managedInstance.id}`);
|
|
87
|
+
mangedInstanceId = managedInstance.id;
|
|
88
|
+
this.log('Refreshing org session auth');
|
|
89
|
+
try {
|
|
90
|
+
await org.refreshAuth();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// console.log('Target username not valid or not specified, refresh failed');
|
|
94
|
+
}
|
|
95
|
+
// Update the connection with the latest access token
|
|
96
|
+
this.log('Updating the connection with the latest access token');
|
|
97
|
+
await updateConnection({ connectionId: managedInstance.connectionId, org, hubConn });
|
|
98
|
+
}
|
|
99
|
+
// Perform the checkout
|
|
100
|
+
const jobId = await this.checkoutInstance({
|
|
101
|
+
branchFlag,
|
|
102
|
+
dataSetId,
|
|
103
|
+
deactivateAllEvents: deactivateFlag,
|
|
104
|
+
deploymentNameFlag,
|
|
105
|
+
deploymentNotes: deploymentNotesFlag,
|
|
106
|
+
deploymentPlanId,
|
|
107
|
+
filter: queryFilterFlag,
|
|
108
|
+
hubConn,
|
|
109
|
+
mangedInstanceId,
|
|
110
|
+
});
|
|
111
|
+
this.log(`Checkout launched with Job ID: ${jobId}`);
|
|
112
|
+
return { jobId, message: 'Checkout launched' };
|
|
113
|
+
}
|
|
114
|
+
async checkoutInstance({ branchFlag, dataSetId, deactivateAllEvents, deploymentNameFlag, deploymentNotes, deploymentPlanId, filter, hubConn, mangedInstanceId, }) {
|
|
115
|
+
this.log(`Performing checkout for managed instance with id ${mangedInstanceId}.`);
|
|
116
|
+
const path = `/services/apexrest/PDRI/v1/instances/${mangedInstanceId}/checkout`;
|
|
117
|
+
const checkoutInstance = {
|
|
118
|
+
branchName: branchFlag,
|
|
119
|
+
datasetId: dataSetId,
|
|
120
|
+
deactivateAll: deactivateAllEvents === undefined ? false : true,
|
|
121
|
+
deploymentName: deploymentNameFlag,
|
|
122
|
+
deploymentNotes,
|
|
123
|
+
deploymentPlanId,
|
|
124
|
+
queryFilter: constructQueryFilter(filter),
|
|
125
|
+
};
|
|
126
|
+
const request = {
|
|
127
|
+
body: JSON.stringify(checkoutInstance),
|
|
128
|
+
method: 'POST',
|
|
129
|
+
url: path,
|
|
130
|
+
};
|
|
131
|
+
const res = await hubConn.request(request);
|
|
132
|
+
const jobsWrapper = JSON.parse(res);
|
|
133
|
+
const jobId = jobsWrapper.jobs[0].id;
|
|
134
|
+
return jobId;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=checkout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../../src/commands/prodly/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;A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,CAAC,KAAK,CAAC,GAAG,CAAS,CAAC;QAE5C,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAErC,OAAO,KAAK,CAAC;IACf,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { JSONObject } from '../../types/generic.js';
|
|
3
|
+
export type ProdlyDeployResult = {
|
|
4
|
+
path: string;
|
|
5
|
+
};
|
|
6
|
+
export default class ProdlyDeploy extends SfCommand<JSONObject> {
|
|
7
|
+
static readonly summary: string;
|
|
8
|
+
static readonly description: string;
|
|
9
|
+
static readonly examples: string[];
|
|
10
|
+
static readonly flags: {
|
|
11
|
+
'target-dev-hub': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
deactivate: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
|
+
destination: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
filter: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
label: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
notes: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
plan: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
21
|
+
simulation: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
22
|
+
source: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
|
+
};
|
|
24
|
+
run(): Promise<JSONObject>;
|
|
25
|
+
private deploy;
|
|
26
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
2
|
+
import { Messages, SfError } from '@salesforce/core';
|
|
3
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
4
|
+
import { constructQueryFilter } from '../../helpers/index.js';
|
|
5
|
+
import { createConnection, getConnectionId, updateConnection } from '../../services/connections.js';
|
|
6
|
+
import { getManagedInstance, manageInstance } from '../../services/manage-instances.js';
|
|
7
|
+
import { getDeploymentEntityId } from '../../services/queries.js';
|
|
8
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
9
|
+
const commandMessages = Messages.loadMessages('prodlysfcli', 'prodly.deploy');
|
|
10
|
+
const prodlyMessages = Messages.loadMessages('prodlysfcli', 'prodly');
|
|
11
|
+
export default class ProdlyDeploy extends SfCommand {
|
|
12
|
+
static summary = commandMessages.getMessage('summary');
|
|
13
|
+
static description = prodlyMessages.getMessage('descriptionDeployCommand');
|
|
14
|
+
static examples = commandMessages.getMessages('examples');
|
|
15
|
+
static flags = {
|
|
16
|
+
'target-dev-hub': Flags.requiredHub(),
|
|
17
|
+
'target-org': Flags.requiredOrg(),
|
|
18
|
+
dataset: Flags.string({ char: 't', summary: prodlyMessages.getMessage('dataSetFlagDescription') }),
|
|
19
|
+
deactivate: Flags.boolean({ char: 'e', summary: prodlyMessages.getMessage('deactivateFlagDescription') }),
|
|
20
|
+
destination: Flags.string({ char: 'd', summary: prodlyMessages.getMessage('destinationFlagDescription') }),
|
|
21
|
+
filter: Flags.string({ char: 'q', summary: prodlyMessages.getMessage('queryFilterFlagDescription') }),
|
|
22
|
+
label: Flags.string({ char: 'b', summary: prodlyMessages.getMessage('instanceNameFlagDescription') }),
|
|
23
|
+
name: Flags.string({ char: 'n', summary: prodlyMessages.getMessage('deplomentNameFlagDescription') }),
|
|
24
|
+
notes: Flags.string({ char: 'z', summary: prodlyMessages.getMessage('notesFlagDescription') }),
|
|
25
|
+
plan: Flags.string({ char: 'p', summary: prodlyMessages.getMessage('deploymentPlanFlagDescription') }),
|
|
26
|
+
simulation: Flags.boolean({ char: 'l', summary: prodlyMessages.getMessage('simulationFlagDescription') }),
|
|
27
|
+
source: Flags.string({ char: 's', summary: prodlyMessages.getMessage('sourceFlagDescription') }),
|
|
28
|
+
};
|
|
29
|
+
async run() {
|
|
30
|
+
const { flags } = await this.parse(ProdlyDeploy);
|
|
31
|
+
const { dataset: datasetFlag, deactivate: deactivateFlag, destination: destinationFlag, filter: queryFilterFlag, label: labelFlag, name: deploymentNameFlag, notes: deploymentNotesFlag, plan: planFlag, simulation: simulationFlag, source: sourceFlag, } = flags;
|
|
32
|
+
const isOrgSpecified = sourceFlag !== undefined || destinationFlag !== undefined;
|
|
33
|
+
this.log('Deployment name flag: ' + deploymentNameFlag);
|
|
34
|
+
this.log('Deployment description flag: ' + deploymentNotesFlag);
|
|
35
|
+
this.log('Source instance flag: ' + sourceFlag);
|
|
36
|
+
this.log('Destination instance flag: ' + destinationFlag);
|
|
37
|
+
this.log('Data set flag: ' + datasetFlag);
|
|
38
|
+
this.log('Deployment plan flag: ' + planFlag);
|
|
39
|
+
this.log('Instance name flag: ' + labelFlag);
|
|
40
|
+
this.log('Deactivate flag: ' + deactivateFlag);
|
|
41
|
+
this.log('Simulation flag: ' + simulationFlag);
|
|
42
|
+
this.log('Query filter flag: ' + queryFilterFlag);
|
|
43
|
+
if (!datasetFlag && !planFlag) {
|
|
44
|
+
throw new SfError(prodlyMessages.getMessage('errorNoDatasetAndPlanFlags', []));
|
|
45
|
+
}
|
|
46
|
+
if (datasetFlag && planFlag) {
|
|
47
|
+
throw new SfError(prodlyMessages.getMessage('errorDatasetAndPlanFlags', []));
|
|
48
|
+
}
|
|
49
|
+
if (!datasetFlag && queryFilterFlag) {
|
|
50
|
+
throw new SfError(prodlyMessages.getMessage('errorQueryFilterFlag', []));
|
|
51
|
+
}
|
|
52
|
+
const org = flags['target-org'];
|
|
53
|
+
const hubOrg = flags['target-dev-hub'];
|
|
54
|
+
const hubConn = hubOrg.getConnection();
|
|
55
|
+
const print = (message, ...args) => this.log(message, ...args);
|
|
56
|
+
let sourceInstanceId;
|
|
57
|
+
let destinationInstanceId;
|
|
58
|
+
let dataSetId;
|
|
59
|
+
let deploymentPlanId;
|
|
60
|
+
// Four posibilities:
|
|
61
|
+
// 1. Source and destination instance params are provided, deploy from source to destination instance
|
|
62
|
+
// 2. Source instance and dx org param are provided, deploy from source instance to dx org instance
|
|
63
|
+
// 3. Destination instance and dx org param are provided, deploy from dx org instance to destination instance
|
|
64
|
+
// 4. Only dx org param is provided, deploy from devhub/control org to the destination instance.
|
|
65
|
+
//
|
|
66
|
+
// Any auto managed instances, and its associated auto created connections, will only contain a short lived refresh token
|
|
67
|
+
// This means that for any subsequent deployments the refresh token needs to be updated with the latest
|
|
68
|
+
// Which can only happen if we have a provided target username parameter for the instance org
|
|
69
|
+
// So only the source or destination instance can be an auto managed
|
|
70
|
+
// Set source mamanaged instance
|
|
71
|
+
if (sourceFlag) {
|
|
72
|
+
// Source and/or destination is a managed instance and the other is a DX managed org
|
|
73
|
+
this.log(`Source managed instance parameter is specified: ${sourceFlag}`);
|
|
74
|
+
// Source is a managed instance, use the managed instance ID
|
|
75
|
+
sourceInstanceId = sourceFlag;
|
|
76
|
+
}
|
|
77
|
+
else if (isOrgSpecified) {
|
|
78
|
+
// Source is a DX managed org
|
|
79
|
+
this.log(`Source managed instance parameter is not specified, finding or creating managed instance by org ID: ${org.getOrgId()}`);
|
|
80
|
+
// Check if a managed instance exist with the same org ID
|
|
81
|
+
let managedInstance = await getManagedInstance({ hubConn, orgId: org.getOrgId(), print });
|
|
82
|
+
this.log(`Retrieved managed instance: ${JSON.stringify(managedInstance)}`);
|
|
83
|
+
if (managedInstance) {
|
|
84
|
+
// If exists, use that managed instance ID
|
|
85
|
+
this.log(`Managed instance found, using it, with ID: ${managedInstance.id}`);
|
|
86
|
+
sourceInstanceId = managedInstance.id;
|
|
87
|
+
// Update the connection with the latest access token
|
|
88
|
+
this.log('Updating the connection with the latest access token');
|
|
89
|
+
await updateConnection({ connectionId: managedInstance.connectionId, hubConn, org });
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.log('Managed instance for the org does not exist, managing instance.');
|
|
93
|
+
// If doesn't exist, query for an active connection to the org
|
|
94
|
+
let connectionId = await getConnectionId({ hubConn, orgId: org.getOrgId(), print });
|
|
95
|
+
this.log(`Retrieved connection ID: ${connectionId ?? ''}`);
|
|
96
|
+
if (!connectionId) {
|
|
97
|
+
// If a connection doesn't exist, create it, then use it to manage the new instance
|
|
98
|
+
this.log('Connection does not exist, creating.');
|
|
99
|
+
connectionId = await createConnection({ hubConn, name: labelFlag, org });
|
|
100
|
+
this.log(`Created connection with record ID: ${connectionId ?? ''}`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Update the connection with the latest access token
|
|
104
|
+
this.log('Updating the connection with the latest access token');
|
|
105
|
+
await updateConnection({ connectionId, hubConn, org });
|
|
106
|
+
}
|
|
107
|
+
// Connection exists, use it to manage the new instance
|
|
108
|
+
const orgId = org.getOrgId();
|
|
109
|
+
const { managedInstance: newManagedInstance } = await manageInstance({
|
|
110
|
+
body: {
|
|
111
|
+
platformInstance: {
|
|
112
|
+
platformInstanceId: orgId,
|
|
113
|
+
connectionId,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
hubConn,
|
|
117
|
+
orgId,
|
|
118
|
+
});
|
|
119
|
+
managedInstance = newManagedInstance;
|
|
120
|
+
this.log(`New managed instance: ${managedInstance.id}`);
|
|
121
|
+
sourceInstanceId = managedInstance.id;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// Source is the dev hub/control org
|
|
126
|
+
this.log(`Source and Destination not specified, setting hub as the source, org ID: ${hubConn.getAuthInfoFields().orgId ?? ''}`);
|
|
127
|
+
const managedInstance = await getManagedInstance({ hubConn, orgId: hubConn.getAuthInfoFields().orgId, print });
|
|
128
|
+
this.log(`Retrieved managed instance ID for the control org: ${managedInstance?.id ?? ''}`);
|
|
129
|
+
if (!managedInstance) {
|
|
130
|
+
throw new SfError('No managed instance found for the devhub/control org.');
|
|
131
|
+
}
|
|
132
|
+
sourceInstanceId = managedInstance.id;
|
|
133
|
+
}
|
|
134
|
+
if (destinationFlag) {
|
|
135
|
+
this.log('Destination managed instance parameter is specified: ', sourceFlag);
|
|
136
|
+
// Destination is a managed instance, use the managed instance ID
|
|
137
|
+
destinationInstanceId = destinationFlag;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Destination is a DX managed org
|
|
141
|
+
this.log(`Destination managed instance parameter is not specified, finding or creating managed instance by org ID: ${org.getOrgId()}`);
|
|
142
|
+
// Check if a managed instance exist with the same org ID
|
|
143
|
+
let managedInstance = await getManagedInstance({ hubConn, orgId: org.getOrgId(), print });
|
|
144
|
+
this.log('Retrieved managed instance: ', JSON.stringify(managedInstance));
|
|
145
|
+
if (managedInstance) {
|
|
146
|
+
// If exists, use that managed instance ID
|
|
147
|
+
this.log(`Managed instance found, using it, with ID: ${managedInstance?.id}`);
|
|
148
|
+
destinationInstanceId = managedInstance?.id;
|
|
149
|
+
// Update the connection with the latest access token
|
|
150
|
+
this.log('Updating the connection with the latest access token');
|
|
151
|
+
await updateConnection({ connectionId: managedInstance.connectionId, hubConn, org });
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
this.log('Managed instance for the org does not exist, managing instance.');
|
|
155
|
+
// If doesn't exist, query for an active connection to the org
|
|
156
|
+
let connectionId = await getConnectionId({ hubConn, orgId: org.getOrgId(), print });
|
|
157
|
+
this.log('Retrieved connection ID: ', connectionId);
|
|
158
|
+
if (!connectionId) {
|
|
159
|
+
// If a connection doesn't exist, create it, then use it to manage the new instance
|
|
160
|
+
this.log('Connection does not exist, creating.');
|
|
161
|
+
connectionId = await createConnection({ hubConn, name: labelFlag, org });
|
|
162
|
+
this.log(`Created connection with record ID: ${connectionId ?? ''}`);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
// Update the connection with the latest access token
|
|
166
|
+
this.log('Updating the connection with the latest access token');
|
|
167
|
+
await updateConnection({ connectionId, hubConn, org });
|
|
168
|
+
}
|
|
169
|
+
// Connection exists, use it to manage the new instance
|
|
170
|
+
const orgId = org.getOrgId();
|
|
171
|
+
const body = {
|
|
172
|
+
platformInstance: {
|
|
173
|
+
platformInstanceId: orgId,
|
|
174
|
+
connectionId,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
const { managedInstance: newManagedInstance } = await manageInstance({
|
|
178
|
+
body,
|
|
179
|
+
hubConn,
|
|
180
|
+
orgId,
|
|
181
|
+
});
|
|
182
|
+
managedInstance = newManagedInstance;
|
|
183
|
+
this.log(`New managed instance ID: ${managedInstance.id}`);
|
|
184
|
+
destinationInstanceId = managedInstance.id;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this.log('Refreshing org session auth');
|
|
188
|
+
try {
|
|
189
|
+
await org.refreshAuth();
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// Target username not valid or not specified, refresh failed
|
|
193
|
+
}
|
|
194
|
+
// Retrieve the data set or deployment plan to deploy
|
|
195
|
+
this.log('Retrieving data set or deployment plan to deploy.');
|
|
196
|
+
if (datasetFlag) {
|
|
197
|
+
dataSetId = await getDeploymentEntityId({
|
|
198
|
+
dataEntityFlag: datasetFlag,
|
|
199
|
+
dataEntityType: 'PDRI__DataSet__c',
|
|
200
|
+
hubConn,
|
|
201
|
+
print,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
else if (planFlag) {
|
|
205
|
+
deploymentPlanId = await getDeploymentEntityId({
|
|
206
|
+
dataEntityFlag: planFlag,
|
|
207
|
+
dataEntityType: 'PDRI__Deployment_Plan__c',
|
|
208
|
+
hubConn,
|
|
209
|
+
print,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
this.log('Launching deployment.');
|
|
213
|
+
const jobId = await this.deploy({
|
|
214
|
+
dataSetId,
|
|
215
|
+
deactivateAllEvents: deactivateFlag,
|
|
216
|
+
deploymentName: deploymentNameFlag,
|
|
217
|
+
deploymentNotes: deploymentNotesFlag,
|
|
218
|
+
deploymentPlanId,
|
|
219
|
+
destinationInstanceId,
|
|
220
|
+
hubConn,
|
|
221
|
+
queryFilter: queryFilterFlag,
|
|
222
|
+
simulation: simulationFlag,
|
|
223
|
+
sourceInstanceId,
|
|
224
|
+
});
|
|
225
|
+
this.log(`Deployment launched with Job ID: ${jobId}`);
|
|
226
|
+
// Return an object to be displayed with --json
|
|
227
|
+
return { jobId, message: 'Deployment launched' };
|
|
228
|
+
}
|
|
229
|
+
async deploy({ dataSetId, deactivateAllEvents, deploymentName, deploymentNotes, deploymentPlanId, destinationInstanceId, hubConn, queryFilter, simulation, sourceInstanceId, }) {
|
|
230
|
+
this.log('Invoking deployment.');
|
|
231
|
+
const path = `/services/apexrest/PDRI/v1/instances/${destinationInstanceId}/deploy`;
|
|
232
|
+
const eventControlOptions = {
|
|
233
|
+
deactivateAll: !!deactivateAllEvents,
|
|
234
|
+
};
|
|
235
|
+
const dataDeploymentOptions = {
|
|
236
|
+
dataSetId,
|
|
237
|
+
deploymentPlanId,
|
|
238
|
+
simulation: simulation ?? false,
|
|
239
|
+
eventControlOptions,
|
|
240
|
+
queryFilter: constructQueryFilter(queryFilter),
|
|
241
|
+
};
|
|
242
|
+
const sourceOptions = {
|
|
243
|
+
managedInstanceId: sourceInstanceId,
|
|
244
|
+
};
|
|
245
|
+
const deployInstance = {
|
|
246
|
+
deploymentName,
|
|
247
|
+
deploymentNotes,
|
|
248
|
+
engagementId: null,
|
|
249
|
+
data: [dataDeploymentOptions],
|
|
250
|
+
metadata: {},
|
|
251
|
+
source: sourceOptions,
|
|
252
|
+
};
|
|
253
|
+
const request = {
|
|
254
|
+
body: JSON.stringify(deployInstance),
|
|
255
|
+
method: 'POST',
|
|
256
|
+
url: path,
|
|
257
|
+
};
|
|
258
|
+
const res = await hubConn.request(request);
|
|
259
|
+
const jobsWrapper = JSON.parse(res);
|
|
260
|
+
const jobId = jobsWrapper.jobs[0].id;
|
|
261
|
+
return jobId;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=deploy.js.map
|