Skip to content

Commit 2cd57c5

Browse files
committed
@W-17233341 - Updating SFAP prod endpoint, adding sourceOrgID body parameter for token update
1 parent 5be2126 commit 2cd57c5

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

src/commands/data-seeding/generate/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export default class DataSeedingGenerate extends SfCommand<DataSeedingGenerateRe
7474
srcOrgInstUrl,
7575
srcAccessToken,
7676
tgtOrgInstUrl,
77-
tgtAccessToken
77+
tgtAccessToken,
78+
sourceOrg
7879
);
7980
const reportMessage = messages.getMessage('report.suggestion', [jobId]);
8081

@@ -100,7 +101,8 @@ export default class DataSeedingGenerate extends SfCommand<DataSeedingGenerateRe
100101

101102
const options: PollingClient.Options = {
102103
poll: async (): Promise<StatusResult> => {
103-
const response = await pollSeedStatus(jobId);
104+
const { jwt: jwtValue } = await initiateJWTMint(srcOrgInstUrl, srcAccessToken, tgtOrgInstUrl, tgtAccessToken);
105+
const response = await pollSeedStatus(jobId,jwtValue);
104106

105107
mso.goto(getStage(response.step), {
106108
startTime: response.execution_start_time,
@@ -151,7 +153,8 @@ export default class DataSeedingGenerate extends SfCommand<DataSeedingGenerateRe
151153
throw err;
152154
}
153155
} else {
154-
const response = await pollSeedStatus(jobId);
156+
const { jwt: jwtValue } = await initiateJWTMint(srcOrgInstUrl, srcAccessToken, tgtOrgInstUrl, tgtAccessToken);
157+
const response = await pollSeedStatus(jobId,jwtValue);
155158

156159
const mso = getSeedGenerateMso({
157160
jsonEnabled: this.jsonEnabled(),

src/commands/data-seeding/generate/report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class DataSeedingGenerateReport extends SfCommand<DataSeedingRepo
4343

4444
if (!jobId) throw new SfError('No job ID provided or found in cache');
4545

46-
const response = await pollSeedStatus(jobId);
46+
const response = await pollSeedStatus(jobId,"");
4747

4848
const data = {
4949
jobId,

src/commands/data-seeding/migrate/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export default class DataSeedingMigrate extends SfCommand<DataSeedingMigrateResu
7474
srcOrgInstUrl,
7575
srcAccessToken,
7676
tgtOrgInstUrl,
77-
tgtAccessToken
77+
tgtAccessToken,
78+
sourceOrg
7879
);
7980

8081
if (!jobId) throw new Error('Failed to receive job id');
@@ -101,7 +102,8 @@ export default class DataSeedingMigrate extends SfCommand<DataSeedingMigrateResu
101102

102103
const options: PollingClient.Options = {
103104
poll: async (): Promise<StatusResult> => {
104-
const response = await pollSeedStatus(jobId);
105+
const { jwt: jwtValue } = await initiateJWTMint(srcOrgInstUrl, srcAccessToken, tgtOrgInstUrl, tgtAccessToken);
106+
const response = await pollSeedStatus(jobId,jwtValue);
105107

106108
mso.goto(getStage(response.step), {
107109
startTime: response.execution_start_time,
@@ -154,7 +156,8 @@ export default class DataSeedingMigrate extends SfCommand<DataSeedingMigrateResu
154156
throw err;
155157
}
156158
} else {
157-
const response = await pollSeedStatus(jobId);
159+
const { jwt: jwtValue } = await initiateJWTMint(srcOrgInstUrl, srcAccessToken, tgtOrgInstUrl, tgtAccessToken);
160+
const response = await pollSeedStatus(jobId,jwtValue);
158161

159162
const mso = getSeedMigrateMso({
160163
jsonEnabled: this.jsonEnabled(),

src/commands/data-seeding/migrate/report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class DataSeedingMigrateReport extends SfCommand<DataSeedingRepor
4040

4141
if (!jobId) throw new SfError('No job ID provided or found in cache');
4242

43-
const response = await pollSeedStatus(jobId);
43+
const response = await pollSeedStatus(jobId,"");
4444

4545
const data = {
4646
jobId,

src/utils/api.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ export type DataSeedingOperation = 'data-generation' | 'data-copy';
3535
const baseUrl = 'https://api.salesforce.com/platform/data-seed/v1';
3636
const seedUrl = `${baseUrl}/data-seed`;
3737
const pollUrl = `${baseUrl}/status`;
38-
38+
const sfRegion = 'us-east-1'
3939
export const initiateDataSeed = async (
4040
config: string,
4141
operation: DataSeedingOperation,
4242
jwt: string,
4343
srcOrgUrl: string,
4444
srcAccessToken: string,
4545
tgtOrgUrl: string,
46-
tgtAccessToken: string
46+
tgtAccessToken: string,
47+
srcOrgId: string
4748
): Promise<SeedResponse> => {
4849
const form = new FormData();
4950
form.append('config_file', fs.createReadStream(config));
@@ -52,13 +53,15 @@ export const initiateDataSeed = async (
5253
form.append('source_instance_url', srcOrgUrl);
5354
form.append('target_access_token', tgtAccessToken);
5455
form.append('target_instance_url', tgtOrgUrl);
56+
form.append('source_org_id',srcOrgId);
5557
// TODO: Update to use .json() instead of JSON.parse once the Error response is changed to be JSON
5658
// Update the return type as well
5759
const response = await got.post(seedUrl, {
5860
throwHttpErrors: false,
5961
headers: {
6062
...form.getHeaders(),
6163
Authorization: `Bearer ${jwt}`,
64+
'x-salesforce-region':sfRegion,
6265
},
6366
body: form,
6467
});
@@ -110,12 +113,16 @@ const callAuthServlet = async (url: string, accessToken: string): Promise<AuthSe
110113
};
111114
};
112115

113-
export const pollSeedStatus = async (jobId: string): Promise<PollSeedResponse> => {
116+
export const pollSeedStatus = async (jobId: string, jwt: string): Promise<PollSeedResponse> => {
114117
const logger = await Logger.child('PollSeedStatus');
115118

116119
// TODO: Update to use .json() instead of JSON.parse once the Error response is changed to be JSON
117120
// Update the return type as well
118-
const response = await got.get(`${pollUrl}/${jobId}`, { throwHttpErrors: false });
121+
const headers = {
122+
Authorization: `Bearer ${jwt}`,
123+
'x-salesforce-region': sfRegion,
124+
};
125+
const response = await got.get(`${pollUrl}/${jobId}`, { throwHttpErrors: false, headers });
119126

120127
if (response.statusCode !== 200) {
121128
// TODO: Print error body once the Error response is changed to be JSON

src/utils/mso.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type MsoGet = string | undefined;
2828
// - They have been converted to lowercase for later comparison
2929
// The values in this Map are used as the stage names in mso
3030
const seedGenerateStagesMap = new Map<string, string>([
31+
['init','Initializing'],
3132
['querying source org', 'Querying Source Org'],
3233
['data generation', 'Data Generation'],
3334
['populating target org', 'Populating Target Org'],

0 commit comments

Comments
 (0)