Skip to content

Commit a63efdb

Browse files
committed
fix: add sandbox username to command JSON
1 parent cc61c22 commit a63efdb

File tree

12 files changed

+114
-58
lines changed

12 files changed

+114
-58
lines changed

schemas/force-org-create.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@
161161
},
162162
"ObjectSetting": {
163163
"type": "object",
164+
"additionalProperties": {
165+
"$ref": "#/definitions/Optional%3CAnyJson%3E"
166+
},
164167
"properties": {
165168
"sharingModel": {
166169
"type": "string"
167170
},
168171
"defaultRecordType": {
169172
"type": "string"
170173
}
171-
},
172-
"additionalProperties": {
173-
"$ref": "#/definitions/Optional%3CAnyJson%3E"
174174
}
175175
},
176176
"Optional<AnyJson>": {

schemas/org-create-sandbox.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/SandboxProcessObject",
3+
"$ref": "#/definitions/SandboxCommandResponse",
44
"definitions": {
5-
"SandboxProcessObject": {
5+
"SandboxCommandResponse": {
66
"type": "object",
7+
"additionalProperties": false,
78
"properties": {
9+
"SandboxUsername": {
10+
"type": "string"
11+
},
812
"Id": {
913
"type": "string"
1014
},
@@ -42,8 +46,7 @@
4246
"type": "string"
4347
}
4448
},
45-
"required": ["Id", "Status", "SandboxName", "SandboxInfoId", "LicenseType", "CreatedDate"],
46-
"additionalProperties": false
49+
"required": ["CreatedDate", "Id", "LicenseType", "SandboxInfoId", "SandboxName", "Status"]
4750
}
4851
}
4952
}

schemas/org-create-scratch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,16 @@
152152
},
153153
"ObjectSetting": {
154154
"type": "object",
155+
"additionalProperties": {
156+
"$ref": "#/definitions/Optional%3CAnyJson%3E"
157+
},
155158
"properties": {
156159
"sharingModel": {
157160
"type": "string"
158161
},
159162
"defaultRecordType": {
160163
"type": "string"
161164
}
162-
},
163-
"additionalProperties": {
164-
"$ref": "#/definitions/Optional%3CAnyJson%3E"
165165
}
166166
},
167167
"Optional<AnyJson>": {

schemas/org-refresh-sandbox.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/SandboxProcessObject",
3+
"$ref": "#/definitions/SandboxCommandResponse",
44
"definitions": {
5-
"SandboxProcessObject": {
5+
"SandboxCommandResponse": {
66
"type": "object",
7+
"additionalProperties": false,
78
"properties": {
9+
"SandboxUsername": {
10+
"type": "string"
11+
},
812
"Id": {
913
"type": "string"
1014
},
@@ -42,8 +46,7 @@
4246
"type": "string"
4347
}
4448
},
45-
"required": ["Id", "Status", "SandboxName", "SandboxInfoId", "LicenseType", "CreatedDate"],
46-
"additionalProperties": false
49+
"required": ["CreatedDate", "Id", "LicenseType", "SandboxInfoId", "SandboxName", "Status"]
4750
}
4851
}
4952
}

schemas/org-resume-sandbox.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$ref": "#/definitions/SandboxProcessObject",
3+
"$ref": "#/definitions/SandboxCommandResponse",
44
"definitions": {
5-
"SandboxProcessObject": {
5+
"SandboxCommandResponse": {
66
"type": "object",
7+
"additionalProperties": false,
78
"properties": {
9+
"SandboxUsername": {
10+
"type": "string"
11+
},
812
"Id": {
913
"type": "string"
1014
},
@@ -42,8 +46,7 @@
4246
"type": "string"
4347
}
4448
},
45-
"required": ["Id", "Status", "SandboxName", "SandboxInfoId", "LicenseType", "CreatedDate"],
46-
"additionalProperties": false
49+
"required": ["CreatedDate", "Id", "LicenseType", "SandboxInfoId", "SandboxName", "Status"]
4750
}
4851
}
4952
}

schemas/org-resume-scratch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,16 @@
152152
},
153153
"ObjectSetting": {
154154
"type": "object",
155+
"additionalProperties": {
156+
"$ref": "#/definitions/Optional%3CAnyJson%3E"
157+
},
155158
"properties": {
156159
"sharingModel": {
157160
"type": "string"
158161
},
159162
"defaultRecordType": {
160163
"type": "string"
161164
}
162-
},
163-
"additionalProperties": {
164-
"$ref": "#/definitions/Optional%3CAnyJson%3E"
165165
}
166166
},
167167
"Optional<AnyJson>": {

src/commands/org/create/sandbox.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import { Duration } from '@salesforce/kit';
99
import { Flags } from '@salesforce/sf-plugins-core';
10-
import { Lifecycle, Messages, SandboxEvents, SandboxProcessObject, SandboxRequest, SfError } from '@salesforce/core';
10+
import { Lifecycle, Messages, SandboxEvents, SandboxRequest, SfError } from '@salesforce/core';
1111
import { Ux } from '@salesforce/sf-plugins-core';
1212
import { Interfaces } from '@oclif/core';
1313
import requestFunctions from '../../../shared/sandboxRequest.js';
14-
import { SandboxCommandBase } from '../../../shared/sandboxCommandBase.js';
14+
import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js';
1515
import { SandboxLicenseType } from '../../../shared/orgTypes.js';
1616

1717
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -21,7 +21,7 @@ const getLicenseTypes = (): string[] => Object.values(SandboxLicenseType);
2121

2222
type SandboxConfirmData = SandboxRequest & { CloneSource?: string };
2323

24-
export default class CreateSandbox extends SandboxCommandBase<SandboxProcessObject> {
24+
export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResponse> {
2525
public static summary = messages.getMessage('summary');
2626
public static description = messages.getMessage('description');
2727
public static examples = messages.getMessages('examples');
@@ -110,7 +110,7 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxProcessObje
110110
};
111111
private flags!: Interfaces.InferredFlags<typeof CreateSandbox.flags>;
112112

113-
public async run(): Promise<SandboxProcessObject> {
113+
public async run(): Promise<SandboxCommandResponse> {
114114
this.sandboxRequestConfig = await this.getSandboxRequestConfig();
115115
this.flags = (await this.parse(CreateSandbox)).flags;
116116
this.debug('Create started with args %s ', this.flags);
@@ -142,14 +142,16 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxProcessObje
142142
};
143143
}
144144

145-
private async createSandbox(): Promise<SandboxProcessObject> {
145+
private async createSandbox(): Promise<SandboxCommandResponse> {
146146
const lifecycle = Lifecycle.getInstance();
147147

148+
this.prodOrg = this.flags['target-org'];
149+
148150
this.registerLifecycleListeners(lifecycle, {
149151
isAsync: this.flags.async,
150152
setDefault: this.flags['set-default'],
151153
alias: this.flags.alias,
152-
prodOrg: this.flags['target-org'],
154+
prodOrg: this.prodOrg,
153155
tracksSource: this.flags['no-track-source'] === true ? false : undefined,
154156
});
155157
const sandboxReq = await this.createSandboxRequest();
@@ -163,7 +165,7 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxProcessObje
163165
this.debug('Calling create with SandboxRequest: %s ', sandboxReq);
164166

165167
try {
166-
const sandboxProcessObject = await this.flags['target-org'].createSandbox(sandboxReq, {
168+
const sandboxProcessObject = await this.prodOrg.createSandbox(sandboxReq, {
167169
wait: this.flags.wait,
168170
interval: this.flags['poll-interval'],
169171
async: this.flags.async,
@@ -173,13 +175,13 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxProcessObje
173175
if (this.flags.async) {
174176
process.exitCode = 68;
175177
}
176-
return sandboxProcessObject;
178+
return this.getSandboxCommandResponse();
177179
} catch (err) {
178180
this.spinner.stop();
179181
if (this.pollingTimeOut && this.latestSandboxProgressObj) {
180182
void lifecycle.emit(SandboxEvents.EVENT_ASYNC_RESULT, undefined);
181183
process.exitCode = 68;
182-
return this.latestSandboxProgressObj;
184+
return this.getSandboxCommandResponse();
183185
} else if (
184186
err instanceof SfError &&
185187
err.name === 'SandboxCreateNotCompleteError' &&

src/commands/org/refresh/sandbox.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import { Duration, omit } from '@salesforce/kit';
99
import { Flags } from '@salesforce/sf-plugins-core';
10-
import { Lifecycle, Messages, SandboxInfo, SandboxEvents, SandboxProcessObject, SfError } from '@salesforce/core';
10+
import { Lifecycle, Messages, SandboxInfo, SandboxEvents, SfError } from '@salesforce/core';
1111
import { Ux } from '@salesforce/sf-plugins-core';
1212
import { Interfaces } from '@oclif/core';
1313
import requestFunctions from '../../../shared/sandboxRequest.js';
14-
import { SandboxCommandBase } from '../../../shared/sandboxCommandBase.js';
14+
import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js';
1515

1616
type SandboxInfoRecord = SandboxInfo & {
1717
attributes: {
@@ -41,7 +41,7 @@ const fields = [
4141
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
4242
const messages = Messages.loadMessages('@salesforce/plugin-org', 'refresh.sandbox');
4343

44-
export default class RefreshSandbox extends SandboxCommandBase<SandboxProcessObject> {
44+
export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandResponse> {
4545
public static summary = messages.getMessage('summary');
4646
public static description = messages.getMessage('description');
4747
public static examples = messages.getMessages('examples');
@@ -104,7 +104,7 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxProcessObj
104104

105105
private sbxConfig!: SandboxInfo;
106106

107-
public async run(): Promise<SandboxProcessObject> {
107+
public async run(): Promise<SandboxCommandResponse> {
108108
this.sandboxRequestConfig = await this.getSandboxRequestConfig();
109109
this.flags = (await this.parse(RefreshSandbox)).flags;
110110
this.validateFlags();
@@ -121,13 +121,13 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxProcessObj
121121
];
122122
}
123123

124-
private async refreshSandbox(): Promise<SandboxProcessObject> {
125-
const prodOrg = this.flags['target-org'];
124+
private async refreshSandbox(): Promise<SandboxCommandResponse> {
125+
this.prodOrg = this.flags['target-org'];
126126

127127
await this.confirmSandboxRefresh(this.sbxConfig);
128128

129129
const lifecycle = Lifecycle.getInstance();
130-
this.registerLifecycleListeners(lifecycle, { isAsync: this.flags['async'], prodOrg });
130+
this.registerLifecycleListeners(lifecycle, { isAsync: this.flags['async'], prodOrg: this.prodOrg });
131131

132132
// remove uneditable fields before refresh
133133
const updateableSandboxInfo = omit(this.sbxConfig, uneditableFields);
@@ -139,7 +139,7 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxProcessObj
139139
this.spinner.start('Sandbox Refresh');
140140
}
141141

142-
const sandboxProcessObject = await prodOrg.refreshSandbox(updateableSandboxInfo, {
142+
const sandboxProcessObject = await this.prodOrg.refreshSandbox(updateableSandboxInfo, {
143143
wait: this.flags['wait'],
144144
interval: this.flags['poll-interval'],
145145
async: this.flags['async'],
@@ -157,13 +157,13 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxProcessObj
157157
if (this.flags.async) {
158158
process.exitCode = 68;
159159
}
160-
return sandboxProcessObject;
160+
return this.getSandboxCommandResponse();
161161
} catch (err) {
162162
this.spinner.stop();
163163
if (this.pollingTimeOut && this.latestSandboxProgressObj) {
164164
void lifecycle.emit(SandboxEvents.EVENT_ASYNC_RESULT, undefined);
165165
process.exitCode = 68;
166-
return this.latestSandboxProgressObj;
166+
return this.getSandboxCommandResponse();
167167
} else if (
168168
err instanceof SfError &&
169169
err.name === 'SandboxRefreshNotCompleteError' &&

src/commands/org/resume/sandbox.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import {
2121
} from '@salesforce/core';
2222
import { Duration } from '@salesforce/kit';
2323
import { Interfaces } from '@oclif/core';
24-
import { SandboxCommandBase } from '../../../shared/sandboxCommandBase.js';
24+
import { SandboxCommandBase, SandboxCommandResponse } from '../../../shared/sandboxCommandBase.js';
2525

2626
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2727
const messages = Messages.loadMessages('@salesforce/plugin-org', 'resume.sandbox');
2828

29-
export default class ResumeSandbox extends SandboxCommandBase<SandboxProcessObject> {
29+
export default class ResumeSandbox extends SandboxCommandBase<SandboxCommandResponse> {
3030
public static summary = messages.getMessage('summary');
3131
public static description = messages.getMessage('description');
3232
public static examples = messages.getMessages('examples');
@@ -72,7 +72,7 @@ export default class ResumeSandbox extends SandboxCommandBase<SandboxProcessObje
7272
};
7373
private flags!: Interfaces.InferredFlags<typeof ResumeSandbox.flags>;
7474

75-
public async run(): Promise<SandboxProcessObject> {
75+
public async run(): Promise<SandboxCommandResponse> {
7676
this.sandboxRequestConfig = await this.getSandboxRequestConfig();
7777
this.flags = (await this.parse(ResumeSandbox)).flags;
7878
this.debug('Resume started with args %s ', this.flags);
@@ -104,9 +104,9 @@ export default class ResumeSandbox extends SandboxCommandBase<SandboxProcessObje
104104
};
105105
}
106106

107-
private async resumeSandbox(): Promise<SandboxProcessObject> {
107+
private async resumeSandbox(): Promise<SandboxCommandResponse> {
108108
this.sandboxRequestData = this.buildSandboxRequestCacheEntry();
109-
const prodOrgUsername: string = this.sandboxRequestData.prodOrgUsername;
109+
const prodOrgUsername = this.sandboxRequestData.prodOrgUsername;
110110

111111
if (!this.sandboxRequestData.sandboxProcessObject.SandboxName) {
112112
if (!this.flags['name'] && !this.flags['job-id']) {
@@ -134,7 +134,7 @@ export default class ResumeSandbox extends SandboxCommandBase<SandboxProcessObje
134134
lifecycle,
135135
}))
136136
) {
137-
return this.latestSandboxProgressObj;
137+
return this.getSandboxCommandResponse();
138138
}
139139

140140
const sandboxReq = this.createResumeSandboxRequest();
@@ -146,10 +146,11 @@ export default class ResumeSandbox extends SandboxCommandBase<SandboxProcessObje
146146
this.debug('Calling resume with ResumeSandboxRequest: %s ', sandboxReq);
147147

148148
try {
149-
return await this.prodOrg.resumeSandbox(sandboxReq, {
149+
this.latestSandboxProgressObj = await this.prodOrg.resumeSandbox(sandboxReq, {
150150
wait: this.flags.wait ?? Duration.seconds(0),
151151
interval: Duration.seconds(30),
152152
});
153+
return this.getSandboxCommandResponse();
153154
} catch (err) {
154155
this.spinner.stop();
155156
if (this.latestSandboxProgressObj && this.pollingTimeOut) {
@@ -215,13 +216,13 @@ export default class ResumeSandbox extends SandboxCommandBase<SandboxProcessObje
215216
lifecycle: Lifecycle;
216217
}): Promise<boolean> {
217218
const sandboxProcessObject: SandboxProcessObject = await getSandboxProcessObject(prodOrg, sandboxName, jobId);
218-
const sandboxUsername = `${prodOrg.getUsername()}.${sandboxProcessObject.SandboxName}`;
219-
const exists = await (await StateAggregator.getInstance()).orgs.exists(sandboxUsername);
219+
this.sandboxUsername = this.getSandboxUsername(prodOrg.getUsername() as string, sandboxProcessObject.SandboxName);
220+
const exists = await (await StateAggregator.getInstance()).orgs.exists(this.sandboxUsername);
220221
if (exists) {
221222
this.latestSandboxProgressObj = sandboxProcessObject;
222223
const resultEvent = {
223224
sandboxProcessObj: this.latestSandboxProgressObj,
224-
sandboxRes: { authUserName: sandboxUsername } as Partial<SandboxUserAuthResponse>,
225+
sandboxRes: { authUserName: this.sandboxUsername } as Partial<SandboxUserAuthResponse>,
225226
} as ResultEvent;
226227
await lifecycle.emit(SandboxEvents.EVENT_RESULT, resultEvent as Partial<ResultEvent>);
227228
return true;

0 commit comments

Comments
 (0)