Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
6e2b71c
1CC Payments: cherry-pick batch 1
kumaravinashcommercecloud Nov 10, 2025
49ffb6d
1CC Payments: cherry-pick batch 2
kumaravinashcommercecloud Nov 10, 2025
4dc358a
1CC Payments: cherry-pick batch 3 (merge commit 93aba267)
kumaravinashcommercecloud Nov 10, 2025
822a200
add transalations
syadupathi-sf Jul 10, 2025
df19e5d
Resolve merge conflict
dannyphan2000 Jul 11, 2025
6ae375b
@W-18912438 Remove login options irrelevant to one click checkout (#2…
syadupathi-sf Jul 16, 2025
6050b95
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
69240b1
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
e8d0705
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
4f5a5d8
Resolve merge conflict
syadupathi-sf Jul 7, 2025
c9b11b3
add lint fixes
syadupathi-sf Jul 10, 2025
0d2c261
Resolve merge conflict
syadupathi-sf Jul 10, 2025
00dc830
Resolve merge conflict
dannyphan2000 Jul 11, 2025
9d0f69e
Resolve merge conflict
syadupathi-sf Jul 16, 2025
9012d20
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
3268200
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
9e17ef7
@W-19135066: add saved phone number (#2943)
dannyphan2000 Jul 30, 2025
330484d
@W-19135066: add saved shipping address (#2956)
dannyphan2000 Aug 1, 2025
9380a21
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
627d559
original fix
smahbubani99 Aug 8, 2025
39bce75
disable place order until payment form is complete
smahbubani99 Aug 8, 2025
1a3cf61
code changes + test
smahbubani99 Aug 8, 2025
16f2d01
linting
smahbubani99 Aug 8, 2025
cae57c9
original fix
smahbubani99 Aug 8, 2025
96e88ca
W-19120814: Save payment instrument for the shopper after order is cr…
kumaravinashcommercecloud Aug 8, 2025
b7f0ecd
@W-18927185 Get authenticated shopper's saved shipping information (#…
syadupathi-sf Aug 11, 2025
5e20d9e
Put focus on the first digit of the OTP in the modal (#3051)
syadupathi-sf Aug 11, 2025
1351317
add transalations
syadupathi-sf Jul 10, 2025
a23dc04
Resolve merge conflict
dannyphan2000 Jul 11, 2025
42d5507
@W-18912438 Remove login options irrelevant to one click checkout (#2…
syadupathi-sf Jul 16, 2025
d42baf0
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
bc86ce1
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
c14c26a
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
4dbd5b7
Resolve merge conflict
syadupathi-sf Jul 7, 2025
b820220
add lint fixes
syadupathi-sf Jul 10, 2025
85dd111
Resolve merge conflict
syadupathi-sf Jul 10, 2025
2fa30ab
Resolve merge conflict
dannyphan2000 Jul 11, 2025
6f410e5
Resolve merge conflict
syadupathi-sf Jul 16, 2025
5a63ea8
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
25be995
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
e6658d6
@W-19135066: add saved phone number (#2943)
dannyphan2000 Jul 30, 2025
a97b5b7
@W-19135066: add saved shipping address (#2956)
dannyphan2000 Aug 1, 2025
9b5b518
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
7566038
original fix
smahbubani99 Aug 8, 2025
38eea7a
disable place order until payment form is complete
smahbubani99 Aug 8, 2025
ebfea15
code changes + test
smahbubani99 Aug 8, 2025
878031f
linting
smahbubani99 Aug 8, 2025
fca5cab
original fix
smahbubani99 Aug 8, 2025
99e6156
W-19120814: Save payment instrument for the shopper after order is cr…
kumaravinashcommercecloud Aug 8, 2025
97cd188
@W-18927185 Get authenticated shopper's saved shipping information (#…
syadupathi-sf Aug 11, 2025
603326a
Put focus on the first digit of the OTP in the modal (#3051)
syadupathi-sf Aug 11, 2025
d242b70
Resolve merge conflict
dannyphan2000 Jul 11, 2025
a9f5282
@W-18912438 Remove login options irrelevant to one click checkout (#2…
syadupathi-sf Jul 16, 2025
5099743
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
5018877
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
62efb11
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
08eb044
disable place order until payment form is complete
smahbubani99 Aug 8, 2025
8a6b8ae
code changes + test
smahbubani99 Aug 8, 2025
419276d
Resolve merge conflict
syadupathi-sf Aug 11, 2025
97daa26
Resolve merge conflict
syadupathi-sf Jul 7, 2025
bdbfb17
add lint fixes
syadupathi-sf Jul 10, 2025
5a5ee7c
Resolve merge conflict
syadupathi-sf Jul 10, 2025
e4472db
Resolve merge conflict
dannyphan2000 Jul 11, 2025
f363015
Resolve merge conflict
syadupathi-sf Jul 16, 2025
41ab9f1
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
5c1ed21
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
42778e8
@W-19135066: add saved phone number (#2943)
dannyphan2000 Jul 30, 2025
2260311
@W-19135066: add saved shipping address (#2956)
dannyphan2000 Aug 1, 2025
9e09397
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
b87b3ab
original fix
smahbubani99 Aug 8, 2025
0614dbf
disable place order until payment form is complete
smahbubani99 Aug 8, 2025
783964b
code changes + test
smahbubani99 Aug 8, 2025
b1a2751
linting
smahbubani99 Aug 8, 2025
a6c8f57
original fix
smahbubani99 Aug 8, 2025
d04ab78
W-19120814: Save payment instrument for the shopper after order is cr…
kumaravinashcommercecloud Aug 8, 2025
578c784
@W-18927185 Get authenticated shopper's saved shipping information (#…
syadupathi-sf Aug 11, 2025
a8f0bb4
Put focus on the first digit of the OTP in the modal (#3051)
syadupathi-sf Aug 11, 2025
9c0424b
@W-19251999 Resend OTP (#3082)
syadupathi-sf Aug 13, 2025
b4f9cac
W-19336033 Continue to Shipping Address button visibility (#3095)
syadupathi-sf Aug 14, 2025
322c276
code + test changes
smahbubani99 Aug 15, 2025
56c44be
resolve conflict on test file
smahbubani99 Aug 15, 2025
df185f4
remove phone icon from otp modal
smahbubani99 Aug 15, 2025
68272be
button is light gray
smahbubani99 Aug 15, 2025
4542444
disable user registration for guest checkout
smahbubani99 Aug 15, 2025
30bdd06
add tests for user registration form
smahbubani99 Aug 15, 2025
8a59285
lint check
smahbubani99 Aug 15, 2025
2f1d96b
original fix
smahbubani99 Aug 8, 2025
1beccf0
code changes
smahbubani99 Aug 8, 2025
727ce5a
unstage changes to checkout-one-click
smahbubani99 Aug 15, 2025
31e5c4e
correcting userRegistration import from lint fix
smahbubani99 Aug 18, 2025
ae5541c
Squash commit for display saved payment instruments on Account page
smahbubani99 Aug 19, 2025
383654e
Internationalization of email address check
kumaravinashcommercecloud Aug 20, 2025
b44f613
Internationalization of email address check
kumaravinashcommercecloud Aug 21, 2025
77a636b
Internationalization of email address check
kumaravinashcommercecloud Aug 21, 2025
9c0a45e
Lint fix
kumaravinashcommercecloud Aug 21, 2025
afc72d0
Added more test scenarios
kumaravinashcommercecloud Aug 21, 2025
0851006
@W-19377497 Enable saving payment instruments for registered users (#…
smahbubani99 Aug 22, 2025
c822f57
W-19404760: send telemetry events for otp-auth
kumaravinashcommercecloud Aug 22, 2025
bd024d4
W-19404760: lint fix
kumaravinashcommercecloud Aug 22, 2025
7dad25c
test fix
kumaravinashcommercecloud Aug 22, 2025
3f15840
@W-19419048: Improve test coverage for 1cc (#3219)
kumaravinashcommercecloud Sep 1, 2025
ab33271
Open OTP modal when user clicks proceed to shipping address
sf-mkosak Sep 4, 2025
be402e9
fixed linting error
sf-mkosak Sep 4, 2025
a41de7f
@W-19121709 Saved payment instrument (#3213)
syadupathi-sf Sep 4, 2025
8dc02bd
made email field readonly in user profile page
sf-mkosak Sep 5, 2025
3e4f650
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
ef451d3
@W-19444570 Add Payment Instrument (#3277)
syadupathi-sf Sep 10, 2025
58b669e
@W-19444575 Delete payment instrument (#3288)
syadupathi-sf Sep 12, 2025
ae93eb5
W-19593646 Show save payment method checkbox for returning users (#3295)
syadupathi-sf Sep 12, 2025
8ac5765
W-19627227 add failure toasts (#3304)
syadupathi-sf Sep 12, 2025
801f7ca
W-19641480 Fix saved payment method notifications (#3311)
syadupathi-sf Sep 15, 2025
3c844d1
@W-19121647 display payment method list (#3313)
sf-mkosak Sep 16, 2025
514f87f
@W-19548614 Revert proxy changes for passwordless login (#3330)
syadupathi-sf Sep 22, 2025
3e8a01a
@W-19121647 show all payment methods in checkout (#3316)
sf-mkosak Sep 23, 2025
ad93272
@W-19751635 SPM UX changes in checkout (#3365)
syadupathi-sf Sep 30, 2025
4ae75ec
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
78d9700
@W-19135066: add saved phone number (#2943)
dannyphan2000 Jul 30, 2025
579ef14
@W-19135066: add saved shipping address (#2956)
dannyphan2000 Aug 1, 2025
2e26d98
Hide add new payment method button for SFP
sf-mkosak Oct 3, 2025
a0f7cfe
lint fix
sf-mkosak Oct 6, 2025
a5ddbc4
Fixed loading and error states of the shopper configuration API
sf-mkosak Oct 7, 2025
8fa5c39
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
ae82d9f
@W-19797935 Save payment method to customer account (#3384)
syadupathi-sf Oct 15, 2025
13ab8bd
@W-19444573 Default payment instrument (#3438)
syadupathi-sf Oct 29, 2025
e909a52
@W-19425801 Guest Shopper Flow (#3417)
syadupathi-sf Nov 7, 2025
d1cbff3
code changes + test
smahbubani99 Aug 8, 2025
5d522b3
linting
smahbubani99 Aug 8, 2025
68778c6
Resolve merge conflict
syadupathi-sf Aug 11, 2025
2b25c2f
Resolve merge conflict
syadupathi-sf Jul 7, 2025
8850855
add lint fixes
syadupathi-sf Jul 10, 2025
60ec87c
Resolve merge conflict
syadupathi-sf Jul 10, 2025
c8edda1
Resolve merge conflict
dannyphan2000 Jul 11, 2025
152fe6f
Resolve merge conflict
syadupathi-sf Jul 16, 2025
2b8abdf
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
39554ca
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
f6baf66
@W-19135066: add saved phone number (#2943)
dannyphan2000 Jul 30, 2025
3bed604
@W-19135066: add saved shipping address (#2956)
dannyphan2000 Aug 1, 2025
67e18ae
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
2487744
code changes + test
smahbubani99 Aug 8, 2025
9cff605
linting
smahbubani99 Aug 8, 2025
21b385c
@W-18927185 Get authenticated shopper's saved shipping information (#…
syadupathi-sf Aug 11, 2025
788198b
Put focus on the first digit of the OTP in the modal (#3051)
syadupathi-sf Aug 11, 2025
460bec1
@W-19251999 Resend OTP (#3082)
syadupathi-sf Aug 13, 2025
961baed
code + test changes
smahbubani99 Aug 15, 2025
1592cc0
disable user registration for guest checkout
smahbubani99 Aug 15, 2025
437af74
lint check
smahbubani99 Aug 15, 2025
097a242
Merge pull request #3102 from SalesforceCommerceCloud/smahbubani.W-19…
smahbubani99 Aug 15, 2025
7c75b73
code changes
smahbubani99 Aug 8, 2025
649a943
unstage changes to checkout-one-click
smahbubani99 Aug 15, 2025
a1d8790
Merge pull request #3111 from SalesforceCommerceCloud/smahbubani.W-19…
smahbubani99 Aug 15, 2025
f9bd2e3
Squash commit for display saved payment instruments on Account page
smahbubani99 Aug 19, 2025
8774ca1
Internationalization of email address check
kumaravinashcommercecloud Aug 20, 2025
4cbeecb
Internationalization of email address check
kumaravinashcommercecloud Aug 21, 2025
4ed54a7
Internationalization of email address check
kumaravinashcommercecloud Aug 21, 2025
21994d2
Lint fix
kumaravinashcommercecloud Aug 21, 2025
d267079
Added more test scenarios
kumaravinashcommercecloud Aug 21, 2025
6f54b82
Merge pull request #3149 from SalesforceCommerceCloud/avinash.W-19389…
kumaravinashcommercecloud Aug 21, 2025
1e3e5a5
@W-19377497 Enable saving payment instruments for registered users (#…
smahbubani99 Aug 22, 2025
1ac141d
Merge branch 'develop' of https://github.com/SalesforceCommerceCloud/…
kumaravinashcommercecloud Aug 25, 2025
d3b86df
Merge pull request #3176 from SalesforceCommerceCloud/avinash.develop…
kumaravinashcommercecloud Aug 25, 2025
e078446
Open OTP modal when user clicks proceed to shipping address
sf-mkosak Sep 4, 2025
6a84303
Merge pull request #3243 from sf-mkosak/mkosak.W-19525615.otp-continu…
sf-mkosak Sep 4, 2025
939d4a3
@W-19121709 Saved payment instrument (#3213)
syadupathi-sf Sep 4, 2025
cdbde04
@W-19444570 Add Payment Instrument (#3277)
syadupathi-sf Sep 10, 2025
485ea45
@W-19444575 Delete payment instrument (#3288)
syadupathi-sf Sep 12, 2025
49202c9
W-19627227 add failure toasts (#3304)
syadupathi-sf Sep 12, 2025
ecebce5
W-19641480 Fix saved payment method notifications (#3311)
syadupathi-sf Sep 15, 2025
004b687
@W-19121647 display payment method list (#3313)
sf-mkosak Sep 16, 2025
7716166
@W-19548614 Revert proxy changes for passwordless login (#3330)
syadupathi-sf Sep 22, 2025
6c296d0
@W-19121647 show all payment methods in checkout (#3316)
sf-mkosak Sep 23, 2025
b4702b2
@W-19751635 SPM UX changes in checkout (#3365)
syadupathi-sf Sep 30, 2025
a79cc53
Hide add new payment method button for SFP
sf-mkosak Oct 3, 2025
445c7ad
@W-19797935 Save payment method to customer account (#3384)
syadupathi-sf Oct 15, 2025
722e9e4
@W-19425801 Guest Shopper Flow (#3417)
syadupathi-sf Nov 7, 2025
5af2f78
Resolve merge conflict
dannyphan2000 Jul 11, 2025
a589145
@W-18912438 Remove login options irrelevant to one click checkout (#2…
syadupathi-sf Jul 16, 2025
58b3904
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
fccec8c
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
883b21a
@W-19135066: add saved phone number (#2943)
dannyphan2000 Jul 30, 2025
30d52f6
@W-19135066: add saved shipping address (#2956)
dannyphan2000 Aug 1, 2025
b76cd26
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
3095457
code changes + test
smahbubani99 Aug 8, 2025
a86a89c
linting
smahbubani99 Aug 8, 2025
0ff06e5
Resolve merge conflict
syadupathi-sf Aug 11, 2025
6c54e3b
Resolve merge conflict
syadupathi-sf Jul 7, 2025
53edaa1
add lint fixes
syadupathi-sf Jul 10, 2025
bf4446c
Resolve merge conflict
syadupathi-sf Jul 10, 2025
311d6e1
Resolve merge conflict
dannyphan2000 Jul 11, 2025
d3551e0
Resolve merge conflict
syadupathi-sf Jul 16, 2025
4dd25d7
@W-19084772 Remove review order step in one click checkout (#2863)
syadupathi-sf Jul 25, 2025
54fc4de
@W-18927217: New component for user registration (#2876)
dannyphan2000 Jul 25, 2025
c7a7c05
@W-19135066: add saved phone number (#2943)
dannyphan2000 Jul 30, 2025
4d3b909
@W-19135066: add saved shipping address (#2956)
dannyphan2000 Aug 1, 2025
004d585
@W-18927151 Trigger OTP modal on leaving the email address field (#2992)
syadupathi-sf Aug 5, 2025
a03552a
code changes + test
smahbubani99 Aug 8, 2025
b9f80b5
linting
smahbubani99 Aug 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/commerce-sdk-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
- [Bugfix] Skip deleting dwsid on shopper login if hybrid auth is enabled for current site. [#3151](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3151)
- Update Auth class and CommerceApiProvider to support custom headers in SCAPI requests [#3183](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3183)

- [Bugfix] Skip deleting dwsid on shopper login if hybrid auth is enabled for current site. [#3151](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3151)

- [Bugfix] Skip deleting dwsid on shopper login if hybrid auth is enabled for current site. [#3151](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/3151)

## v3.4.0 (Jul 22, 2025)

- Optionally disable auth init in CommerceApiProvider [#2629](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2629)
Expand Down
84 changes: 84 additions & 0 deletions packages/commerce-sdk-react/src/auth/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,3 +1280,87 @@ describe('hybridAuthEnabled property toggles clearECOMSession', () => {
expect(auth.get('dwsid')).toBe('test-dwsid-value')
})
})

describe('hybridAuthEnabled property toggles clearECOMSession', () => {
beforeEach(() => {
jest.clearAllMocks()
})

test('clears DWSID cookie when hybridAuthEnabled is false', () => {
const auth = new Auth({...config, hybridAuthEnabled: false})

// Set a DWSID cookie value
// @ts-expect-error private method
auth.set('dwsid', 'test-dwsid-value')

// Verify the cookie was set
expect(auth.get('dwsid')).toBe('test-dwsid-value')

// Call clearECOMSession
// @ts-expect-error private method
auth.clearECOMSession()

// Verify the cookie was cleared
expect(auth.get('dwsid')).toBeFalsy()
})

test('does NOT clear DWSID cookie when hybridAuthEnabled is true', () => {
const auth = new Auth({...config, hybridAuthEnabled: true})

// Set a DWSID cookie value
// @ts-expect-error private method
auth.set('dwsid', 'test-dwsid-value')

// Verify the cookie was set
expect(auth.get('dwsid')).toBe('test-dwsid-value')

// Call clearECOMSession
// @ts-expect-error private method
auth.clearECOMSession()

// Verify the cookie was NOT cleared
expect(auth.get('dwsid')).toBe('test-dwsid-value')
})
})

describe('hybridAuthEnabled property toggles clearECOMSession', () => {
beforeEach(() => {
jest.clearAllMocks()
})

test('clears DWSID cookie when hybridAuthEnabled is false', () => {
const auth = new Auth({...config, hybridAuthEnabled: false})

// Set a DWSID cookie value
// @ts-expect-error private method
auth.set('dwsid', 'test-dwsid-value')

// Verify the cookie was set
expect(auth.get('dwsid')).toBe('test-dwsid-value')

// Call clearECOMSession
// @ts-expect-error private method
auth.clearECOMSession()

// Verify the cookie was cleared
expect(auth.get('dwsid')).toBeFalsy()
})

test('does NOT clear DWSID cookie when hybridAuthEnabled is true', () => {
const auth = new Auth({...config, hybridAuthEnabled: true})

// Set a DWSID cookie value
// @ts-expect-error private method
auth.set('dwsid', 'test-dwsid-value')

// Verify the cookie was set
expect(auth.get('dwsid')).toBe('test-dwsid-value')

// Call clearECOMSession
// @ts-expect-error private method
auth.clearECOMSession()

// Verify the cookie was NOT cleared
expect(auth.get('dwsid')).toBe('test-dwsid-value')
})
})
72 changes: 58 additions & 14 deletions packages/commerce-sdk-react/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
isOriginTrusted,
onClient,
getDefaultCookieAttributes,
isAbsoluteUrl,
stringToBase64,
extractCustomParameters
} from '../utils'
Expand Down Expand Up @@ -96,10 +95,19 @@ type AuthorizePasswordlessParams = {
callbackURI?: string
userid: string
mode?: string
/** When true, SLAS will register the customer as part of the passwordless flow */
register_customer?: boolean | string
/** Optional registration details forwarded to SLAS when register_customer=true */
first_name?: string
last_name?: string
email?: string
phone_number?: string
}

type GetPasswordLessAccessTokenParams = {
pwdlessLoginToken: string
/** When true, SLAS will register the customer if not already registered */
register_customer?: boolean | string
}

/**
Expand Down Expand Up @@ -1260,26 +1268,54 @@ class Auth {
* A wrapper method for commerce-sdk-isomorphic helper: authorizePasswordless.
*/
async authorizePasswordless(parameters: AuthorizePasswordlessParams) {
const slasClient = this.client
const usid = this.get('usid')
const callbackURI = parameters.callbackURI || this.passwordlessLoginCallbackURI
const finalMode = callbackURI ? 'callback' : parameters.mode || 'sms'
const finalMode = parameters.mode || (callbackURI ? 'callback' : 'sms')

const res = await helpers.authorizePasswordless({
slasClient: this.client,
credentials: {
clientSecret: this.clientSecret
const options = {
headers: {
Authorization: ''
},
parameters: {
...(callbackURI && {callbackURI: callbackURI}),
...(parameters.register_customer !== undefined && {
register_customer:
typeof parameters.register_customer === 'boolean'
? String(parameters.register_customer)
: parameters.register_customer
})
},
body: {
user_id: parameters.userid,
mode: finalMode,
// Include usid and site as required by SLAS
...(usid && {usid}),
userid: parameters.userid,
mode: finalMode
channel_id: slasClient.clientConfig.parameters.siteId,
...(callbackURI && {callback_uri: callbackURI}),
...(parameters.last_name && {last_name: parameters.last_name}),
...(parameters.email && {email: parameters.email}),
...(parameters.first_name && {first_name: parameters.first_name}),
...(parameters.phone_number && {phone_number: parameters.phone_number})
}
})
if (res && res.status !== 200) {
const errorData = await res.json()
throw new Error(`${res.status} ${String(errorData.message)}`)
} as {
headers?: {[key: string]: string}
parameters?: Record<string, string>
body: ShopperLoginTypes.authorizePasswordlessCustomerBodyType &
helpers.CustomRequestBody
}

// Use Basic auth header when using private client
if (this.clientSecret) {
options.headers = options.headers || {}
options.headers.Authorization = `Basic ${stringToBase64(
`${slasClient.clientConfig.parameters.clientId}:${this.clientSecret}`
)}`
} else {
// If not using private client, avoid sending Authorization header
delete options.headers
}

const res = await slasClient.authorizePasswordlessCustomer(options)
return res
}

Expand All @@ -1289,14 +1325,22 @@ class Auth {
async getPasswordLessAccessToken(parameters: GetPasswordLessAccessTokenParams) {
const pwdlessLoginToken = parameters.pwdlessLoginToken || ''
const dntPref = this.getDnt({includeDefaults: true})
const usid = this.get('usid')
const token = await helpers.getPasswordLessAccessToken({
slasClient: this.client,
credentials: {
clientSecret: this.clientSecret
},
parameters: {
pwdlessLoginToken,
dnt: dntPref !== undefined ? String(dntPref) : undefined
dnt: dntPref !== undefined ? String(dntPref) : undefined,
...(usid && {usid}),
...(parameters.register_customer !== undefined && {
register_customer:
typeof parameters.register_customer === 'boolean'
? String(parameters.register_customer)
: parameters.register_customer
})
}
})
const isGuest = false
Expand Down
3 changes: 2 additions & 1 deletion packages/commerce-sdk-react/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ export const CLIENT_KEYS = {
SHOPPER_PROMOTIONS: 'shopperPromotions',
SHOPPER_SEARCH: 'shopperSearch',
SHOPPER_SEO: 'shopperSeo',
SHOPPER_STORES: 'shopperStores'
SHOPPER_STORES: 'shopperStores',
SHOPPER_CONFIGURATIONS: 'shopperConfigurations'
} as const
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {CLIENT_KEYS} from '../../constant'
import {ApiClients, CacheUpdateMatrix} from '../types'

const CLIENT_KEY = CLIENT_KEYS.SHOPPER_CONFIGURATIONS
type Client = NonNullable<ApiClients[typeof CLIENT_KEY]>

// ShopperConfigurations API is primarily for reading configuration data
// No mutations are currently supported
export const cacheUpdateMatrix: CacheUpdateMatrix<Client> = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {renderHook} from '@testing-library/react'
import {useConfigurations} from './query'

describe('ShopperConfigurations', () => {
describe('useConfigurations', () => {
it('should be defined', () => {
expect(useConfigurations).toBeDefined()
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
export * from './query'
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import nock from 'nock'
import {
mockQueryEndpoint,
renderHookWithProviders,
waitAndExpectError,
waitAndExpectSuccess,
createQueryClient
} from '../../test-utils'

import {Argument} from '../types'
import * as queries from './query'

jest.mock('../../auth/index.ts', () => {
const {default: mockAuth} = jest.requireActual('../../auth/index.ts')
mockAuth.prototype.ready = jest.fn().mockResolvedValue({access_token: 'access_token'})
return mockAuth
})

type Queries = typeof queries
const configurationsEndpoint = '/organizations/'
// Not all endpoints use all parameters, but unused parameters are safely discarded
const OPTIONS: Argument<Queries[keyof Queries]> = {
parameters: {organizationId: 'f_ecom_zzrmy_orgf_001'}
}

// Mock data for configurations
const mockConfigurationsData = {
configurations: [
{
id: 'gcp',
value: 'test-gcp-api-key'
},
{
id: 'einstein',
value: 'test-einstein-api-key'
}
]
}

describe('Shopper Configurations query hooks', () => {
beforeEach(() => nock.cleanAll())
afterEach(() => {
expect(nock.pendingMocks()).toHaveLength(0)
})

test('`useConfigurations` has meta.displayName defined', async () => {
mockQueryEndpoint(configurationsEndpoint, mockConfigurationsData)
const queryClient = createQueryClient()
const {result} = renderHookWithProviders(
() => {
return queries.useConfigurations(OPTIONS)
},
{queryClient}
)
await waitAndExpectSuccess(() => result.current)
expect(queryClient.getQueryCache().getAll()[0].meta?.displayName).toBe('useConfigurations')
})

test('`useConfigurations` returns data on success', async () => {
mockQueryEndpoint(configurationsEndpoint, mockConfigurationsData)
const {result} = renderHookWithProviders(() => {
return queries.useConfigurations(OPTIONS)
})
await waitAndExpectSuccess(() => result.current)
expect(result.current.data).toEqual(mockConfigurationsData)
})

test('`useConfigurations` returns error on error', async () => {
mockQueryEndpoint(configurationsEndpoint, {}, 400)
const {result} = renderHookWithProviders(() => {
return queries.useConfigurations(OPTIONS)
})
await waitAndExpectError(() => result.current)
})

test('`useConfigurations` handles 500 server error', async () => {
mockQueryEndpoint(configurationsEndpoint, {}, 500)
const {result} = renderHookWithProviders(() => {
return queries.useConfigurations(OPTIONS)
})
await waitAndExpectError(() => result.current)
})
})
Loading
Loading