Skip to content

Commit 1eacf88

Browse files
committed
feat: extra checks in connectWithAuth
1 parent ae676f0 commit 1eacf88

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/client.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ export default class PubSubApiClient {
102102
* @returns {Promise<void>} Promise that resolves once the connection is established
103103
*/
104104
async connectWithAuth(accessToken, instanceUrl, organizationId, username) {
105+
if (!instanceUrl || !instanceUrl.startsWith('https://')) {
106+
throw new Error(
107+
`Invalid Salesforce Instance URL format supplied: ${instanceUrl}`
108+
);
109+
}
110+
if (
111+
!organizationId ||
112+
(organizationId.length !== 15 && organizationId.length !== 18)
113+
) {
114+
throw new Error(
115+
`Invalid Salesforce Org ID format supplied: ${organizationId}`
116+
);
117+
}
118+
if (!username || username.indexOf('@') === -1) {
119+
throw new Error(
120+
`Invalid Salesforce username format supplied: ${username}`
121+
);
122+
}
105123
return this.#connectToPubSubApi({
106124
accessToken,
107125
instanceUrl,

0 commit comments

Comments
 (0)