Skip to content

Commit d1eac95

Browse files
committed
fix(@W-17233341): changes for minting JWT and SFAP endpoints
1 parent 6da3f00 commit d1eac95

File tree

4 files changed

+49
-41
lines changed

4 files changed

+49
-41
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# plugin-data-seeding
44

5-
[![NPM](https://img.shields.io/npm/v/@salesforce/plugin-data-seeding.svg?label=@salesforce/plugin-data-seeding)](https://www.npmjs.com/package/@salesforce/plugin-data-seeding) [![Downloads/week](https://img.shields.io/npm/dw/@salesforce/plugin-data-seeding.svg)](https://npmjs.org/package/@salesforce/plugin-data-seeding) [![License](https://img.shields.io/badge/License-BSD%203--Clause-brightgreen.svg)](https://raw.githubusercontent.com/salesforcecli/plugin-data-seeding/main/LICENSE.txt)
5+
[![NPM](https://img.shields.io/npm/v/@salesforce/plugin-data-seeding.svg?label=@salesforce/plugin-data-seeding)](https://www.npmjs.com/package/@salesforce/plugin-data-seeding) [![Downloads/week](https://img.shields.io/npm/dw/@salesforce/plugin-data-seeding.svg)](https://npmjs.org/package/@salesforce/plugin-data-seeding) [![License](https://img.shields.io/badge/License-BSD%203--Clause-brightgreen.svg)](https://raw.githubusercontent.com/salesforcecli/plugin-data-seeding/refs/heads/main/LICENSE.txt)
66

77
## Using the template
88

@@ -166,7 +166,7 @@ EXAMPLES
166166
./config/seed-config.json --wait 5
167167
```
168168

169-
_See code: [src/commands/data-seeding/generate/index.ts](https://github.com/salesforcecli/plugin-data-seeding/blob/v1.0.10/src/commands/data-seeding/generate/index.ts)_
169+
_See code: [src/commands/data-seeding/generate/index.ts](https://github.com/salesforcecli/plugin-data-seeding/blob/main/src/commands/data-seeding/generate/index.ts)_
170170

171171
## `sf data-seeding generate report`
172172

@@ -201,7 +201,7 @@ EXAMPLES
201201
$ sf data-seeding generate report --use-most-recent
202202
```
203203

204-
_See code: [src/commands/data-seeding/generate/report.ts](https://github.com/salesforcecli/plugin-data-seeding/blob/v1.0.10/src/commands/data-seeding/generate/report.ts)_
204+
_See code: [src/commands/data-seeding/generate/report.ts](https://github.com/salesforcecli/plugin-data-seeding/blob/main/src/commands/data-seeding/generate/report.ts)_
205205

206206
## `sf data-seeding migrate`
207207

@@ -254,7 +254,7 @@ EXAMPLES
254254
./config/data-seed.json --wait 5
255255
```
256256

257-
_See code: [src/commands/data-seeding/migrate/index.ts](https://github.com/salesforcecli/plugin-data-seeding/blob/v1.0.10/src/commands/data-seeding/migrate/index.ts)_
257+
_See code: [src/commands/data-seeding/migrate/index.ts](https://github.com/salesforcecli/plugin-data-seeding/blob/main/src/commands/data-seeding/migrate/index.ts)_
258258

259259
## `sf data-seeding migrate report`
260260

@@ -289,6 +289,6 @@ EXAMPLES
289289
$ sf data-seeding migrate report --use-most-recent
290290
```
291291

292-
_See code: [src/commands/data-seeding/migrate/report.ts](https://github.com/salesforcecli/plugin-data-seeding/blob/v1.0.10/src/commands/data-seeding/migrate/report.ts)_
292+
_See code: [src/commands/data-seeding/migrate/report.ts](https://github.com/salesforcecli/plugin-data-seeding/blob/main/src/commands/data-seeding/migrate/report.ts)_
293293

294294
<!-- commandsstop -->

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
99
import { Messages, PollingClient, SfError, StatusResult } from '@salesforce/core';
1010
import { Duration } from '@salesforce/kit';
11-
import { initiateDataSeed, pollSeedStatus, PollSeedResponse, initiateJWTMint } from '../../../utils/api.js'
11+
import { initiateDataSeed, pollSeedStatus, PollSeedResponse, initiateJWTMint } from '../../../utils/api.js';
1212
import { getSeedGenerateMso, getSeedGenerateStage as getStage } from '../../../utils/mso.js';
1313
import { DataSeedingGenerateResult } from '../../../utils/types.js';
1414
import { GenerateRequestCache } from '../../../utils/cache.js';
@@ -56,19 +56,18 @@ export default class DataSeedingGenerate extends SfCommand<DataSeedingGenerateRe
5656
public async run(): Promise<DataSeedingGenerateResult> {
5757
const { flags } = await this.parse(DataSeedingGenerate);
5858
const { async, 'config-file': configFile, 'source-org': srcOrgObj, 'target-org': tgtOrgObj, wait } = flags;
59-
59+
6060
const sourceOrg = srcOrgObj.getOrgId();
6161
const srcAccessToken = srcOrgObj.getConnection().accessToken as string;
62-
const srcOrgInstUrl = srcOrgObj.getConnection().instanceUrl as string;
62+
const srcOrgInstUrl = srcOrgObj.getConnection().instanceUrl;
6363

6464
const targetOrg = tgtOrgObj.getOrgId();
6565
const tgtAccessToken = tgtOrgObj.getConnection().accessToken as string;
66-
const tgtOrgInstUrl = tgtOrgObj.getConnection().instanceUrl as string;
67-
68-
//Fetch Valid JWT with Data Seed Org Perm
69-
const { jwt: jwtValue} = await initiateJWTMint(srcOrgInstUrl,srcAccessToken,tgtOrgInstUrl,tgtAccessToken );
70-
this.log("\nValid JWT Token Fetched.");
71-
const { request_id: jobId } = await initiateDataSeed(configFile, 'data-generation',jwtValue);
66+
const tgtOrgInstUrl = tgtOrgObj.getConnection().instanceUrl;
67+
68+
// Fetch Valid JWT with Data Seed Org Perm
69+
const { jwt: jwtValue } = await initiateJWTMint(srcOrgInstUrl, srcAccessToken, tgtOrgInstUrl, tgtAccessToken);
70+
const { request_id: jobId } = await initiateDataSeed(configFile, 'data-generation', jwtValue);
7271
const reportMessage = messages.getMessage('report.suggestion', [jobId]);
7372

7473
if (!jobId) throw new Error('Failed to receive job id');

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,19 @@ export default class DataSeedingMigrate extends SfCommand<DataSeedingMigrateResu
5656
public async run(): Promise<DataSeedingMigrateResult> {
5757
const { flags } = await this.parse(DataSeedingMigrate);
5858
const { async, 'config-file': configFile, 'source-org': sourceOrgObj, 'target-org': targetOrgObj, wait } = flags;
59-
59+
6060
const sourceOrg = sourceOrgObj.getOrgId();
6161
const srcAccessToken = sourceOrgObj.getConnection().accessToken as string;
62-
const srcOrgInstUrl = sourceOrgObj.getConnection().instanceUrl as string;
62+
const srcOrgInstUrl = sourceOrgObj.getConnection().instanceUrl;
6363

6464
const targetOrg = targetOrgObj.getOrgId();
6565
const tgtAccessToken = targetOrgObj.getConnection().accessToken as string;
66-
const tgtOrgInstUrl = targetOrgObj.getConnection().instanceUrl as string;
67-
68-
//Fetch Valid JWT with Data Seed Org Perm
69-
const { jwt: jwtValue} = await initiateJWTMint(srcOrgInstUrl,srcAccessToken,tgtOrgInstUrl,tgtAccessToken);
70-
this.log("\nValid JWT Token Fetched.");
66+
const tgtOrgInstUrl = targetOrgObj.getConnection().instanceUrl;
67+
68+
// Fetch Valid JWT with Data Seed Org Perm
69+
const { jwt: jwtValue } = await initiateJWTMint(srcOrgInstUrl, srcAccessToken, tgtOrgInstUrl, tgtAccessToken);
7170

72-
const { request_id: jobId } = await initiateDataSeed(configFile, 'data-copy',jwtValue);
71+
const { request_id: jobId } = await initiateDataSeed(configFile, 'data-copy', jwtValue);
7372

7473
if (!jobId) throw new Error('Failed to receive job id');
7574

src/utils/api.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type PollSeedResponse = {
3030
export type DataSeedingOperation = 'data-generation' | 'data-copy';
3131

3232
// TODO Change to SFAP Endpoint
33-
const baseUrl = process.env.SF_DATA_SEEDING_URL ?? 'https://data-seed-gid.sfdc-yfeipo.svc.sfdcfc.net';
33+
const baseUrl = process.env.SF_DATA_SEEDING_URL ?? 'https://data-seed-gid.sfdc-yfeipo.svc.sfdcfc.net';
3434
const csrfUrl = `${baseUrl}/get-csrf-token`;
3535
const seedUrl = `${baseUrl}/data-seed`;
3636
const pollUrl = `${baseUrl}/status`;
@@ -48,9 +48,13 @@ export const getCsrfToken = (cookieJar: CookieJar): string => {
4848
return csrfToken;
4949
};
5050

51-
export const initiateDataSeed = async (config: string, operation: DataSeedingOperation, jwt: string): Promise<SeedResponse> => {
52-
//const cookieJar = await getCookieJar();
53-
//const csrf = getCsrfToken(cookieJar);
51+
export const initiateDataSeed = async (
52+
config: string,
53+
operation: DataSeedingOperation,
54+
jwt: string
55+
): Promise<SeedResponse> => {
56+
// const cookieJar = await getCookieJar();
57+
// const csrf = getCsrfToken(cookieJar);
5458
const form = new FormData();
5559
form.append('config_file', fs.createReadStream(config));
5660
// TODO : Remove credential file once SFAP is active and dataseed endpoint accepts orgurl and token
@@ -60,11 +64,11 @@ export const initiateDataSeed = async (config: string, operation: DataSeedingOpe
6064
// Update the return type as well
6165
const response = await got.post(seedUrl, {
6266
throwHttpErrors: false,
63-
//cookieJar,
67+
// cookieJar,
6468
headers: {
6569
...form.getHeaders(),
6670
// 'X-CSRFToken': csrf,
67-
'Authorization': 'Bearer '+jwt,
71+
Authorization: 'Bearer ' + jwt,
6872
},
6973
body: form,
7074
});
@@ -76,31 +80,37 @@ export const initiateDataSeed = async (config: string, operation: DataSeedingOpe
7680
return JSON.parse(response.body) as SeedResponse;
7781
};
7882

79-
export const initiateJWTMint = async (src_org_url: string, src_access_token: string, tgt_org_url: string, tgt_access_token: string ): Promise<ServletResponse> => {
80-
81-
const src_servlet_url = src_org_url+'/dataseed/auth'
82-
const response_src = await got.post(src_servlet_url, {
83+
export const initiateJWTMint = async (
84+
srcOrgUrl: string,
85+
srcAccessToken: string,
86+
tgtOrgUrl: string,
87+
tgtAccessToken: string
88+
): Promise<ServletResponse> => {
89+
const srcServletUrl = srcOrgUrl + '/dataseed/auth';
90+
const responseSrc = await got.post(srcServletUrl, {
8391
throwHttpErrors: false,
8492
headers: {
85-
'Authorization': 'Bearer '+src_access_token,
93+
Authorization: 'Bearer ' + srcAccessToken,
8694
},
8795
});
8896

89-
if (response_src.statusCode !== 200) {
90-
const tgt_servlet_url = tgt_org_url+'/dataseed/auth'
91-
const response_tgt = await got.post(tgt_servlet_url, {
97+
if (responseSrc.statusCode !== 200) {
98+
const tgtServletUrl = tgtOrgUrl + '/dataseed/auth';
99+
const responseTgt = await got.post(tgtServletUrl, {
92100
throwHttpErrors: false,
93101
headers: {
94-
'Authorization': 'Bearer '+tgt_access_token,
102+
Authorization: 'Bearer ' + tgtAccessToken,
95103
},
96104
});
97-
if (response_tgt.statusCode !== 200) {
98-
throw new SfError(`Org permission for data seed not found in source & target org.\nSource Response: Error Code : ${response_src.statusCode} - ${response_src.body}. \nTarget Response: Error Code : ${response_tgt.statusCode} - ${response_tgt.body}`);
105+
if (responseTgt.statusCode !== 200) {
106+
throw new SfError(
107+
`Org permission for data seed not found in source & target org.\nSource Response: Error Code : ${responseSrc.statusCode} - ${responseSrc.body}. \nTarget Response: Error Code : ${responseTgt.statusCode} - ${responseTgt.body}`
108+
);
99109
}
100-
return JSON.parse(response_tgt.body) as ServletResponse;
110+
return JSON.parse(responseTgt.body) as ServletResponse;
101111
}
102112

103-
return JSON.parse(response_src.body) as ServletResponse;
113+
return JSON.parse(responseSrc.body) as ServletResponse;
104114
};
105115

106116
export const pollSeedStatus = async (jobId: string): Promise<PollSeedResponse> => {

0 commit comments

Comments
 (0)