@@ -30,7 +30,7 @@ export type PollSeedResponse = {
3030export 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' ;
3434const csrfUrl = `${ baseUrl } /get-csrf-token` ;
3535const seedUrl = `${ baseUrl } /data-seed` ;
3636const 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
106116export const pollSeedStatus = async ( jobId : string ) : Promise < PollSeedResponse > => {
0 commit comments