-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
various SLAS adjustments, added callbackURIs #318
Merged
tobiaslohr
merged 3 commits into
SalesforceCommerceCloud:master
from
sandragolden:bugfix/slas-updates
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,11 @@ const secrets = require('./secrets'); | |
* Generates a SLAS Admin Url | ||
* @param {string} tenantId the tenant found in BM - e.g bbsv_stg | ||
* @param {string} shortcode the shortcode found in BM - e.g acdefg | ||
* @param {string} [clientId] if provided a client URL is generated | ||
* @param {string} [clientId] if provided a client URL is generated | ||
*/ | ||
function getSlasUrl(tenantId, shortcode, clientId) { | ||
return `https://${shortcode}.api.commercecloud.salesforce.com/shopper/auth-admin/v1/tenants/${tenantId | ||
+ (clientId ? ('/clients/' + clientId) : '')}`; | ||
+ (clientId ? ('/clients/' + clientId) : '')}`; | ||
} | ||
|
||
|
||
|
@@ -26,6 +26,10 @@ async function handleResponse(response) { | |
throw new Error(`HTTP Fault ${response.status} (${response.statusText})`) | ||
} | ||
|
||
if (response.status === 204) { | ||
return 'Success, 204: No Content'; | ||
} | ||
|
||
const resultText = await response.text(); | ||
return JSON.parse(resultText); | ||
} | ||
|
@@ -63,8 +67,8 @@ const slas = { | |
let result | ||
try { | ||
result = await slas.api.tenant.add(tenantId, shortcode, | ||
description, merchantName, contact, emailAddress, fileName) | ||
console.info('sucessfully add tenant') | ||
description, merchantName, contact, emailAddress, fileName, auth.getToken()) | ||
console.info('sucessfully added tenant') | ||
handleCLIOutput(result, asJson) | ||
} catch (e) { | ||
handleCLIError('Could not add tenant: ', e.message, asJson) | ||
|
@@ -73,7 +77,7 @@ const slas = { | |
get: async (tenantId, shortcode, asJson) => { | ||
let result | ||
try { | ||
result = await slas.api.tenant.get(tenantId, shortcode) | ||
result = await slas.api.tenant.get(tenantId, shortcode, auth.getToken()) | ||
handleCLIOutput(result, asJson) | ||
} catch (e) { | ||
handleCLIError('Could not get tenant: ', e.message, asJson) | ||
|
@@ -82,7 +86,7 @@ const slas = { | |
list: async (shortcode, asJson) => { | ||
let result | ||
try { | ||
result = await slas.api.tenant.list(shortcode) | ||
result = await slas.api.tenant.list(shortcode, auth.getToken()) | ||
handleCLIOutput(result, asJson) | ||
} catch (e) { | ||
handleCLIError('Could not get tenants: ', e.message, asJson) | ||
|
@@ -91,7 +95,7 @@ const slas = { | |
delete: async (tenantId, shortcode, asJson) => { | ||
let result | ||
try { | ||
result = await slas.api.tenant.delete(tenantId, shortcode) | ||
result = await slas.api.tenant.delete(tenantId, shortcode, auth.getToken()) | ||
handleCLIOutput(result, asJson) | ||
} catch (e) { | ||
handleCLIError('Could not delete tenant: ', e.message, asJson) | ||
|
@@ -100,12 +104,13 @@ const slas = { | |
}, | ||
client : { | ||
add: async (tenantId, shortcode, fileName,clientid, clientname, privateclient, | ||
ecomtenant, ecomsite, secret, channels, scopes, redirecturis, asJson) => { | ||
ecomtenant, ecomsite, secret, channels, scopes, redirecturis, callbackuris, asJson) => { | ||
let result | ||
try { | ||
result = await slas.api.client.add(tenantId, shortcode, fileName, clientid, clientname, | ||
privateclient, ecomtenant, ecomsite, secret, channels, scopes, redirecturis); | ||
console.info('sucessfully add client ') | ||
privateclient, ecomtenant, ecomsite, secret, channels, scopes, redirecturis, | ||
callbackuris, auth.getToken()); | ||
console.info('sucessfully added client ') | ||
handleCLIOutput(result, asJson) | ||
} catch (e) { | ||
handleCLIError('Could not add client: ', e.message, asJson) | ||
|
@@ -114,16 +119,16 @@ const slas = { | |
get: async (tenantId, shortcode, clientId, asJson) => { | ||
let result | ||
try { | ||
result = await slas.api.client.get(tenantId, shortcode, clientId) | ||
result = await slas.api.client.get(tenantId, shortcode, clientId, auth.getToken()) | ||
handleCLIOutput(result, asJson) | ||
} catch (e) { | ||
handleCLIError('Could not get tenant: ', e.message, asJson) | ||
} | ||
}, | ||
list: async (shortcode, tenantId, asJson) => { | ||
list: async (tenantId, shortcode, asJson) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. order from cli expects the reverse: |
||
let result | ||
try { | ||
result = await slas.api.client.list(shortcode, tenantId); | ||
result = await slas.api.client.list(shortcode, tenantId, auth.getToken()); | ||
if (asJson) { | ||
console.info(JSON.stringify(result, null, 4)); | ||
} else { | ||
|
@@ -136,7 +141,7 @@ const slas = { | |
delete: async (tenantId, shortcode, clientId, asJson) => { | ||
let result | ||
try { | ||
result = await slas.api.client.delete(tenantId, shortcode, clientId) | ||
result = await slas.api.client.delete(tenantId, shortcode, clientId, auth.getToken()) | ||
handleCLIOutput(result, asJson) | ||
} catch (e) { | ||
handleCLIError('Could not delete tenant: ', e.message, asJson) | ||
|
@@ -146,8 +151,7 @@ const slas = { | |
}, | ||
api: { | ||
tenant: { | ||
add: async (tenantId, shortcode, description, merchantName, contact, emailAddress, fileName) => { | ||
const token = auth.getToken(); | ||
add: async (tenantId, shortcode, description, merchantName, contact, emailAddress, fileName, token) => { | ||
let params | ||
// set fallbacks | ||
shortcode = secrets.getScapiShortCode(shortcode); | ||
|
@@ -180,9 +184,7 @@ const slas = { | |
|
||
return await handleResponse(response); | ||
}, | ||
get: async (tenantId, shortcode) => { | ||
const token = auth.getToken(); | ||
|
||
get: async (tenantId, shortcode, token) => { | ||
// set fallbacks | ||
tenantId = secrets.getScapiTenantId(tenantId); | ||
shortcode = secrets.getScapiShortCode(shortcode); | ||
|
@@ -197,11 +199,8 @@ const slas = { | |
|
||
return await handleResponse(response); | ||
}, | ||
list: async (shortcode) => { | ||
const token = auth.getToken(); | ||
|
||
list: async (shortcode, token) => { | ||
// set fallbacks | ||
tenantId = secrets.getScapiTenantId(tenantId); | ||
shortcode = secrets.getScapiShortCode(shortcode); | ||
|
||
const response = await fetch(getSlasUrl('', shortcode), { | ||
|
@@ -213,9 +212,7 @@ const slas = { | |
}); | ||
return await handleResponse(response); | ||
}, | ||
delete: async (tenantId, shortcode) => { | ||
const token = auth.getToken(); | ||
|
||
delete: async (tenantId, shortcode, token) => { | ||
// set fallbacks | ||
tenantId = secrets.getScapiTenantId(tenantId); | ||
shortcode = secrets.getScapiShortCode(shortcode); | ||
|
@@ -233,9 +230,7 @@ const slas = { | |
}, | ||
client: { | ||
add: async (tenantId, shortcode, file, clientid, clientname, privateclient, | ||
ecomtenant, ecomsite, secret, channels, scopes, redirecturis,) => { | ||
const token = auth.getToken(); | ||
|
||
ecomtenant, ecomsite, secret, channels, scopes, redirecturis, callbackuris, token) => { | ||
// set fallbacks | ||
shortcode = secrets.getScapiShortCode(shortcode); | ||
let params; | ||
|
@@ -251,7 +246,8 @@ const slas = { | |
secret: secret, | ||
channels: channels, | ||
scopes: scopes, | ||
redirectUri: redirecturis | ||
redirectUri: redirecturis || [], | ||
callbackUri: callbackuris || [] | ||
} | ||
} | ||
tenantId = secrets.getScapiTenantId(tenantId || params.ecomTenant); | ||
|
@@ -263,12 +259,9 @@ const slas = { | |
}, | ||
body: JSON.stringify(params) | ||
}); | ||
|
||
return await handleResponse(response); | ||
}, | ||
get: async (tenantId, shortcode, clientId) => { | ||
const token = auth.getToken(); | ||
|
||
get: async (tenantId, shortcode, clientId, token) => { | ||
// set fallbacks | ||
tenantId = secrets.getScapiTenantId(tenantId); | ||
shortcode = secrets.getScapiShortCode(shortcode); | ||
|
@@ -283,9 +276,7 @@ const slas = { | |
|
||
return await handleResponse(response); | ||
}, | ||
list: async (shortcode, tenantId) => { | ||
const token = auth.getToken(); | ||
|
||
list: async (shortcode, tenantId, token) => { | ||
// set fallbacks | ||
tenantId = secrets.getScapiTenantId(tenantId); | ||
shortcode = secrets.getScapiShortCode(shortcode); | ||
|
@@ -297,11 +288,10 @@ const slas = { | |
'Content-Type': 'application/json' | ||
} | ||
}); | ||
|
||
return await handleResponse(response); | ||
}, | ||
delete: async (tenantId, shortcode, clientId) => { | ||
const token = auth.getToken(); | ||
|
||
delete: async (tenantId, shortcode, clientId, token) => { | ||
// set fallbacks | ||
tenantId = secrets.getScapiTenantId(tenantId); | ||
shortcode = secrets.getScapiShortCode(shortcode); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be set to an empty array if the client does not have redirectURLs (passwordless login)