From fc76dc05dee95011b959f415e6aa64d79a756097 Mon Sep 17 00:00:00 2001
From: Jang ho Jung <jangho.jung@salesforce.com>
Date: Wed, 18 Sep 2024 13:36:33 -0700
Subject: [PATCH] linting

---
 .eslintrc.json                                |   6 -
 src/static/helpers/passwordlessHelper.test.ts | 153 +++++++++---------
 src/static/helpers/passwordlessHelper.ts      |  63 ++++----
 3 files changed, 111 insertions(+), 111 deletions(-)

diff --git a/.eslintrc.json b/.eslintrc.json
index 1df245e1..1ebee1b6 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -91,12 +91,6 @@
         "rules": {
           "@typescript-eslint/explicit-module-boundary-types": "error"
         }
-      },
-      {
-        "files": ["./src/static/helpers/passwordlessHelper.ts"],
-        "rules": {
-          "@typescript-eslint/ban-types": "off"
-        }
       }
     ],
     "settings": {
diff --git a/src/static/helpers/passwordlessHelper.test.ts b/src/static/helpers/passwordlessHelper.test.ts
index 5c9f5626..ddbedd1d 100644
--- a/src/static/helpers/passwordlessHelper.test.ts
+++ b/src/static/helpers/passwordlessHelper.test.ts
@@ -20,13 +20,13 @@ import {
 type slasHelperType = typeof slasHelper;
 // Mock the module
 jest.mock('./slasHelper', () => {
-    const actualUtils = jest.requireActual<slasHelperType>('./slasHelper');
-    const createCodeVerifierMock = jest.fn(() => 'code_verifier')
-    return {
-      ...actualUtils,
-      createCodeVerifier: createCodeVerifierMock, // Mock the specific function
-    };
-  });
+  const actualUtils = jest.requireActual<slasHelperType>('./slasHelper');
+  const createCodeVerifierMock = jest.fn(() => 'code_verifier');
+  return {
+    ...actualUtils,
+    createCodeVerifier: createCodeVerifierMock, // Mock the specific function
+  };
+});
 
 const authorizePasswordlessCustomerMock = jest.fn();
 const getPasswordLessAccessTokenMock = jest.fn();
@@ -56,75 +56,78 @@ beforeEach(() => {
 });
 
 describe('authorizePasswordless is working', () => {
-    test('Correct parameters are used to call SLAS Client authorize', async () => {
-        const mockSlasClient = createMockSlasClient();
-        const {clientId, organizationId, siteId} = mockSlasClient.clientConfig.parameters;
-    
-        const credentials = {
-          clientSecret: 'slas_private_secret',
-        };
-        const parameters = {
-          callbackURI: 'www.something.com/callback',
-          usid: 'a_usid',
-          userid: 'a_userid',
-          locale: 'a_locale',
-          mode: 'callback',
-        };
-        const authHeaderExpected = `Basic ${slasHelper.stringToBase64(
-            `${clientId}:${credentials.clientSecret}`
-          )}`;
-        await authorizePasswordless(mockSlasClient, credentials, parameters)
-        const expectedReqOptions = {
-            headers: {
-                Authorization: authHeaderExpected
-            },
-            parameters: {
-                organizationId
-            },
-            body: {
-                user_id: parameters.userid,
-                mode: parameters.mode,
-                locale: parameters.locale,
-                channel_id: siteId,
-                callback_uri: parameters.callbackURI,
-                usid: parameters.usid
-            }
-        }
-        expect(authorizePasswordlessCustomerMock).toBeCalledWith(expectedReqOptions);
-      });
+  test('Correct parameters are used to call SLAS Client authorize', async () => {
+    const mockSlasClient = createMockSlasClient();
+    const {clientId, organizationId, siteId} =
+      mockSlasClient.clientConfig.parameters;
+
+    const credentials = {
+      clientSecret: 'slas_private_secret',
+    };
+    const parameters = {
+      callbackURI: 'www.something.com/callback',
+      usid: 'a_usid',
+      userid: 'a_userid',
+      locale: 'a_locale',
+      mode: 'callback',
+    };
+    const authHeaderExpected = `Basic ${slasHelper.stringToBase64(
+      `${clientId}:${credentials.clientSecret}`
+    )}`;
+    await authorizePasswordless(mockSlasClient, credentials, parameters);
+    const expectedReqOptions = {
+      headers: {
+        Authorization: authHeaderExpected,
+      },
+      parameters: {
+        organizationId,
+      },
+      body: {
+        user_id: parameters.userid,
+        mode: parameters.mode,
+        locale: parameters.locale,
+        channel_id: siteId,
+        callback_uri: parameters.callbackURI,
+        usid: parameters.usid,
+      },
+    };
+    expect(authorizePasswordlessCustomerMock).toBeCalledWith(
+      expectedReqOptions, true
+    );
+  });
 });
 
 describe('getPasswordLessAccessToken is working', () => {
-    test('Correct parameters are used to call SLAS Client authorize', async () => {
-        const mockSlasClient = createMockSlasClient();
-        const {clientId, organizationId} = mockSlasClient.clientConfig.parameters;
-    
-        const credentials = {
-          clientSecret: 'slas_private_secret',
-        };
-        const parameters = {
-          pwdlessLoginToken: '123456',
-          dnt: '1'
-        };
-        const authHeaderExpected = `Basic ${slasHelper.stringToBase64(
-            `${clientId}:${credentials.clientSecret}`
-          )}`;
-        await getPasswordLessAccessToken(mockSlasClient, credentials, parameters)
-        const expectedReqOptions = {
-            headers: {
-                Authorization: authHeaderExpected
-            },
-            parameters: {
-                organizationId
-            },
-            body: {
-                dnt: parameters.dnt,
-                code_verifier: "code_verifier",
-                grant_type: 'client_credentials',
-                hint: 'pwdless_login',
-                pwdless_login_token: parameters.pwdlessLoginToken
-            }
-        }
-        expect(getPasswordLessAccessTokenMock).toBeCalledWith(expectedReqOptions);
-      });
+  test('Correct parameters are used to call SLAS Client authorize', async () => {
+    const mockSlasClient = createMockSlasClient();
+    const {clientId, organizationId} = mockSlasClient.clientConfig.parameters;
+
+    const credentials = {
+      clientSecret: 'slas_private_secret',
+    };
+    const parameters = {
+      pwdlessLoginToken: '123456',
+      dnt: '1',
+    };
+    const authHeaderExpected = `Basic ${slasHelper.stringToBase64(
+      `${clientId}:${credentials.clientSecret}`
+    )}`;
+    await getPasswordLessAccessToken(mockSlasClient, credentials, parameters);
+    const expectedReqOptions = {
+      headers: {
+        Authorization: authHeaderExpected,
+      },
+      parameters: {
+        organizationId,
+      },
+      body: {
+        dnt: parameters.dnt,
+        code_verifier: 'code_verifier',
+        grant_type: 'client_credentials',
+        hint: 'pwdless_login',
+        pwdless_login_token: parameters.pwdlessLoginToken,
+      },
+    };
+    expect(getPasswordLessAccessTokenMock).toBeCalledWith(expectedReqOptions);
+  });
 });
diff --git a/src/static/helpers/passwordlessHelper.ts b/src/static/helpers/passwordlessHelper.ts
index bbd583f1..791b79fd 100644
--- a/src/static/helpers/passwordlessHelper.ts
+++ b/src/static/helpers/passwordlessHelper.ts
@@ -38,7 +38,7 @@ export async function authorizePasswordless(
     locale?: string;
     mode: string;
   }
-): Promise<Response | Object> {
+): Promise<Response> {
   const authHeaderIdSecret = `Basic ${stringToBase64(
     `${slasClient.clientConfig.parameters.clientId}:${credentials.clientSecret}`
   )}`;
@@ -51,15 +51,18 @@ export async function authorizePasswordless(
     ...(parameters.callbackURI && {callback_uri: parameters.callbackURI}),
   };
 
-  return slasClient.authorizePasswordlessCustomer({
-    headers: {
-      Authorization: authHeaderIdSecret,
-    },
-    parameters: {
-      organizationId: slasClient.clientConfig.parameters.organizationId,
+  return slasClient.authorizePasswordlessCustomer(
+    {
+      headers: {
+        Authorization: authHeaderIdSecret,
+      },
+      parameters: {
+        organizationId: slasClient.clientConfig.parameters.organizationId,
+      },
+      body: tokenBody,
     },
-    body: tokenBody,
-  });
+    true
+  );
 }
 
 /**
@@ -87,27 +90,27 @@ export async function getPasswordLessAccessToken(
   parameters: {
     pwdlessLoginToken: string;
     dnt?: string;
-  } 
+  }
 ): Promise<TokenResponse> {
-    const codeVerifier = createCodeVerifier();
-    const authHeaderIdSecret = `Basic ${stringToBase64(
-        `${slasClient.clientConfig.parameters.clientId}:${credentials.clientSecret}`
-    )}`;
+  const codeVerifier = createCodeVerifier();
+  const authHeaderIdSecret = `Basic ${stringToBase64(
+    `${slasClient.clientConfig.parameters.clientId}:${credentials.clientSecret}`
+  )}`;
 
-    const tokenBody = {
-        grant_type: 'client_credentials',
-        hint: 'pwdless_login',
-        pwdless_login_token: parameters.pwdlessLoginToken,
-        code_verifier: codeVerifier,
-        ...(parameters.dnt && {dnt: parameters.dnt}),
-    };
-    return slasClient.getPasswordLessAccessToken({
-        headers: {
-        Authorization: authHeaderIdSecret,
-        },
-        parameters: {
-            organizationId: slasClient.clientConfig.parameters.organizationId,
-        },
-        body: tokenBody,
-    });
+  const tokenBody = {
+    grant_type: 'client_credentials',
+    hint: 'pwdless_login',
+    pwdless_login_token: parameters.pwdlessLoginToken,
+    code_verifier: codeVerifier,
+    ...(parameters.dnt && {dnt: parameters.dnt}),
+  };
+  return slasClient.getPasswordLessAccessToken({
+    headers: {
+      Authorization: authHeaderIdSecret,
+    },
+    parameters: {
+      organizationId: slasClient.clientConfig.parameters.organizationId,
+    },
+    body: tokenBody,
+  });
 }