@faststore/core 4.3.0-dev.5 → 4.3.0-dev.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-generate.log +3 -3
- package/.turbo/turbo-test.log +41 -36
- package/CHANGELOG.md +12 -0
- package/lighthouserc.js +1 -1
- package/package.json +7 -7
- package/src/sdk/account/useSetPassword.ts +82 -72
- package/test/sdk/account/useSetPassword.test.ts +192 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @faststore/core@4.3.0-dev.
|
|
2
|
+
> @faststore/core@4.3.0-dev.6 generate /home/runner/work/faststore/faststore/packages/core
|
|
3
3
|
> pnpm run gen-types && pnpm run cache-graphql
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @faststore/core@4.3.0-dev.
|
|
6
|
+
> @faststore/core@4.3.0-dev.6 gen-types /home/runner/work/faststore/faststore/packages/core
|
|
7
7
|
> node ../cli/bin/run generate-types .
|
|
8
8
|
|
|
9
9
|
[33m[STARTED][39m Parse Configuration
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
[32m[COMPLETED][39m Generate to /home/runner/work/faststore/faststore/packages/core/@generated/
|
|
20
20
|
[32m[COMPLETED][39m Generate outputs
|
|
21
21
|
|
|
22
|
-
> @faststore/core@4.3.0-dev.
|
|
22
|
+
> @faststore/core@4.3.0-dev.6 cache-graphql /home/runner/work/faststore/faststore/packages/core
|
|
23
23
|
> node ../cli/bin/run cache-graphql --config=./discovery.config.default.js --queries=./@generated/persisted-documents.json
|
|
24
24
|
|
|
25
25
|
[Info] - Config file location: /home/runner/work/faststore/faststore/packages/core/discovery.config.default.js
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
> @faststore/core@4.3.0-dev.
|
|
2
|
+
> @faststore/core@4.3.0-dev.6 test /home/runner/work/faststore/faststore/packages/core
|
|
3
3
|
> vitest run
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
[1m[46m RUN [49m[22m [36mv4.0.7 [39m[90m/home/runner/work/faststore/faststore/packages/core[39m
|
|
7
7
|
|
|
8
|
-
[32m✓[39m [30m[46m browser [49m[39m test/sdk/session/getInitialSession.browser.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m
|
|
9
|
-
[32m✓[39m [30m[46m browser [49m[39m test/sdk/session/installLocaleCorrector.browser.test.ts [2m([22m[2m7 tests[22m[2m)[22m[32m
|
|
8
|
+
[32m✓[39m [30m[46m browser [49m[39m test/sdk/session/getInitialSession.browser.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 36[2mms[22m[39m
|
|
9
|
+
[32m✓[39m [30m[46m browser [49m[39m test/sdk/session/installLocaleCorrector.browser.test.ts [2m([22m[2m7 tests[22m[2m)[22m[32m 54[2mms[22m[39m
|
|
10
10
|
[90mstderr[2m | test/sdk/localization/store-url.browser.test.ts
|
|
11
11
|
[22m[39mError in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
|
|
12
12
|
at validateCart [90m(/home/runner/work/faststore/faststore/packages/core/[39msrc/sdk/cart/index.ts:119:27[90m)[39m
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:353:23)
|
|
15
15
|
[90m at processTicksAndRejections (node:internal/process/task_queues:103:5)[39m
|
|
16
16
|
|
|
17
|
-
[32m✓[39m [30m[
|
|
18
|
-
[32m✓[39m [30m[
|
|
19
|
-
[32m✓[39m [30m[43m node [49m[39m test/utils/match-url.test.ts [2m([22m[2m10 tests[22m[2m)[22m[32m
|
|
17
|
+
[32m✓[39m [30m[46m browser [49m[39m test/sdk/localization/store-url.browser.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 11[2mms[22m[39m
|
|
18
|
+
[32m✓[39m [30m[43m node [49m[39m test/utils/localization/bindingPaths.test.ts [2m([22m[2m71 tests[22m[2m)[22m[32m 123[2mms[22m[39m
|
|
19
|
+
[32m✓[39m [30m[43m node [49m[39m test/utils/match-url.test.ts [2m([22m[2m10 tests[22m[2m)[22m[32m 21[2mms[22m[39m
|
|
20
20
|
[32m✓[39m [30m[46m browser [49m[39m test/utils/isLocalHost.browser.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 15[2mms[22m[39m
|
|
21
|
-
[32m✓[39m [30m[43m node [49m[39m test/sdk/localization/bindingSelector.test.ts [2m([22m[2m18 tests[22m[2m)[22m[32m
|
|
21
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/localization/bindingSelector.test.ts [2m([22m[2m18 tests[22m[2m)[22m[32m 20[2mms[22m[39m
|
|
22
22
|
[90mstderr[2m | test/components/search/SearchInputComponent.test.tsx
|
|
23
23
|
[22m[39mWarning: forwardRef render functions accept exactly two parameters: props and ref. Did you forget to use the ref parameter?
|
|
24
24
|
|
|
@@ -82,13 +82,17 @@ Warning: React does not recognize the `providerProps` prop on a DOM element. If
|
|
|
82
82
|
at Suspense
|
|
83
83
|
at Wrapper (/home/runner/work/faststore/faststore/packages/core/test/components/search/SearchInputComponent.test.tsx:106:20)
|
|
84
84
|
|
|
85
|
-
[32m✓[39m [30m[43m node [49m[39m test/components/search/SearchInputComponent.test.tsx [2m([22m[2m6 tests[22m[2m)[22m[33m
|
|
86
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
87
|
-
[32m✓[39m [30m[43m node [49m[39m test/sdk/search/useSearchHistory.test.ts [2m([22m[2m13 tests[22m[2m)[22m[32m
|
|
88
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
89
|
-
[32m✓[39m [30m[43m node [49m[39m test/utils/
|
|
90
|
-
[32m✓[39m [30m[43m node [49m[39m test/utils/
|
|
91
|
-
|
|
85
|
+
[32m✓[39m [30m[43m node [49m[39m test/components/search/SearchInputComponent.test.tsx [2m([22m[2m6 tests[22m[2m)[22m[33m 372[2mms[22m[39m
|
|
86
|
+
[32m✓[39m [30m[43m node [49m[39m test/utils/cookieCacheBusting.test.ts [2m([22m[2m10 tests[22m[2m)[22m[32m 50[2mms[22m[39m
|
|
87
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/search/useSearchHistory.test.ts [2m([22m[2m13 tests[22m[2m)[22m[32m 244[2mms[22m[39m
|
|
88
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/localization/useBindingSelector.test.tsx [2m([22m[2m12 tests[22m[2m)[22m[32m 71[2mms[22m[39m
|
|
89
|
+
[32m✓[39m [30m[43m node [49m[39m test/utils/clearCookies.test.ts [2m([22m[2m20 tests[22m[2m)[22m[32m 98[2mms[22m[39m
|
|
90
|
+
[32m✓[39m [30m[43m node [49m[39m test/utils/multipleTemplates.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m 37[2mms[22m[39m
|
|
91
|
+
[90mstderr[2m | test/sdk/account/useSetPassword.test.ts[2m > [22m[2museSetPassword[2m > [22m[2mmaps wrongcredentials error responses to the existing message
|
|
92
|
+
[22m[39mSet password request failed: Bad Request
|
|
93
|
+
|
|
94
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/account/useSetPassword.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 247[2mms[22m[39m
|
|
95
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/orderEntry/useOrderEntryOperation.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m 89[2mms[22m[39m
|
|
92
96
|
[90mstderr[2m | test/pages/api/graphql.test.ts[2m > [22m[2m/api/graphql error status propagation[2m > [22m[2mpropagates the upstream 400 from a wrapped BadRequestError instead of 500
|
|
93
97
|
[22m[39mGraphql execution returned with error: [
|
|
94
98
|
{
|
|
@@ -135,26 +139,27 @@ Warning: React does not recognize the `providerProps` prop on a DOM element. If
|
|
|
135
139
|
{ message: [32m'bad'[39m, status: [33m400[39m, type: [32m'BadRequestError'[39m }
|
|
136
140
|
]
|
|
137
141
|
|
|
138
|
-
[32m✓[39m [30m[43m node [49m[39m test/pages/api/graphql.test.ts [2m([22m[2m10 tests[22m[2m)[22m[32m
|
|
139
|
-
[32m✓[39m [30m[43m node [49m[39m test/sdk/orderEntry/useOrderEntryUpload.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m
|
|
140
|
-
[32m✓[39m [30m[43m node [49m[39m test/sdk/orderEntry/useOrderEntry.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m
|
|
141
|
-
[32m✓[39m [30m[43m node [49m[39m test/sdk/orderEntry/useOrderFormItems.test.ts [2m([22m[2m7 tests[22m[2m)[22m[32m
|
|
142
|
-
[32m✓[39m [30m[43m node [49m[39m test/server/cms/global.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m
|
|
143
|
-
[32m✓[39m [30m[43m node [49m[39m test/server/
|
|
144
|
-
|
|
145
|
-
[33m[2m✓[22m[39m should handle options and execute [33m
|
|
146
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
147
|
-
[32m✓[39m [30m[43m node [49m[39m test/sdk/localization/store-url.test.ts [2m([22m[2m1 test[22m[2m)[22m[32m
|
|
148
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
149
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
150
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
151
|
-
[32m✓[39m [30m[43m node [49m[39m test/utils/validateSessionRefreshToken.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m
|
|
152
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
153
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
154
|
-
[32m✓[39m [30m[43m node [49m[39m test/
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
[2m
|
|
158
|
-
[2m
|
|
159
|
-
[2m
|
|
142
|
+
[32m✓[39m [30m[43m node [49m[39m test/pages/api/graphql.test.ts [2m([22m[2m10 tests[22m[2m)[22m[32m 59[2mms[22m[39m
|
|
143
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/orderEntry/useOrderEntryUpload.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m 81[2mms[22m[39m
|
|
144
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/orderEntry/useOrderEntry.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m 62[2mms[22m[39m
|
|
145
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/orderEntry/useOrderFormItems.test.ts [2m([22m[2m7 tests[22m[2m)[22m[32m 41[2mms[22m[39m
|
|
146
|
+
[32m✓[39m [30m[43m node [49m[39m test/server/cms/global.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 5[2mms[22m[39m
|
|
147
|
+
[32m✓[39m [30m[43m node [49m[39m test/server/index.test.ts [2m([22m[2m7 tests[22m[2m)[22m[33m 862[2mms[22m[39m
|
|
148
|
+
[33m[2m✓[22m[39m should exist with its plugins [33m 303[2mms[22m[39m
|
|
149
|
+
[33m[2m✓[22m[39m should handle options and execute [33m 311[2mms[22m[39m
|
|
150
|
+
[32m✓[39m [30m[43m node [49m[39m test/server/content/service.test.ts [2m([22m[2m5 tests[22m[2m)[22m[32m 6[2mms[22m[39m
|
|
151
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/localization/store-url.test.ts [2m([22m[2m1 test[22m[2m)[22m[32m 5[2mms[22m[39m
|
|
152
|
+
[32m✓[39m [30m[43m node [49m[39m test/utils/getRequestHostname.test.ts [2m([22m[2m12 tests[22m[2m)[22m[32m 7[2mms[22m[39m
|
|
153
|
+
[32m✓[39m [30m[43m node [49m[39m test/pages/api/preview.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m 10[2mms[22m[39m
|
|
154
|
+
[32m✓[39m [30m[43m node [49m[39m test/sdk/auth/useAuth.test.ts [2m([22m[2m5 tests[22m[2m)[22m[32m 33[2mms[22m[39m
|
|
155
|
+
[32m✓[39m [30m[43m node [49m[39m test/utils/validateSessionRefreshToken.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 5[2mms[22m[39m
|
|
156
|
+
[32m✓[39m [30m[43m node [49m[39m test/components/search/SearchInput.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 8[2mms[22m[39m
|
|
157
|
+
[32m✓[39m [30m[43m node [49m[39m test/utils/isLocalHost.test.ts [2m([22m[2m7 tests[22m[2m)[22m[32m 6[2mms[22m[39m
|
|
158
|
+
[32m✓[39m [30m[43m node [49m[39m test/server/cms/index.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m 6[2mms[22m[39m
|
|
159
|
+
[32m✓[39m [30m[43m node [49m[39m test/components/auth/ProfileChallenge.test.tsx [2m([22m[2m3 tests[22m[2m)[22m[32m 27[2mms[22m[39m
|
|
160
|
+
|
|
161
|
+
[2m Test Files [22m [1m[32m31 passed[39m[22m[90m (31)[39m
|
|
162
|
+
[2m Tests [22m [1m[32m293 passed[39m[22m[90m (293)[39m
|
|
163
|
+
[2m Start at [22m 16:58:10
|
|
164
|
+
[2m Duration [22m 24.02s[2m (transform 5.83s, setup 0ms, collect 19.89s, tests 2.71s, environment 32.71s, prepare 998ms)[22m
|
|
160
165
|
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.3.0-dev.7](https://github.com/vtex/faststore/compare/v4.3.0-dev.6...v4.3.0-dev.7) (2026-06-17)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **core:** use authenticator route for setpassword ([#3380](https://github.com/vtex/faststore/issues/3380)) ([a155269](https://github.com/vtex/faststore/commit/a155269678d8a0584a98008b1384bf146f6da1cb))
|
|
11
|
+
|
|
12
|
+
# [4.3.0-dev.6](https://github.com/vtex/faststore/compare/v4.3.0-dev.5...v4.3.0-dev.6) (2026-06-17)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- migrate partytown [@builder](https://github.com/builder).io → [@qwik](https://github.com/qwik).dev@0.14.0 ([#3394](https://github.com/vtex/faststore/issues/3394)) ([dae8d3b](https://github.com/vtex/faststore/commit/dae8d3b3823b3e1758af9547cae9bd92cef480b9))
|
|
17
|
+
|
|
6
18
|
# [4.3.0-dev.5](https://github.com/vtex/faststore/compare/v4.3.0-dev.4...v4.3.0-dev.5) (2026-06-16)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @faststore/core
|
package/lighthouserc.js
CHANGED
|
@@ -9,7 +9,7 @@ module.exports = lhConfig({
|
|
|
9
9
|
'csp-xss': 'off',
|
|
10
10
|
|
|
11
11
|
// The following rules should be removed one this is fixed:
|
|
12
|
-
// https://github.com/
|
|
12
|
+
// https://github.com/QwikDev/partytown/issues/178
|
|
13
13
|
'categories:best-practices': [
|
|
14
14
|
'error',
|
|
15
15
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/core",
|
|
3
|
-
"version": "4.3.0-dev.
|
|
3
|
+
"version": "4.3.0-dev.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@antfu/ni": "0.21.12",
|
|
26
|
-
"@builder.io/partytown": "^0.6.1",
|
|
27
26
|
"@envelop/core": "^5",
|
|
28
27
|
"@envelop/graphql-jit": "^11",
|
|
29
28
|
"@envelop/parser-cache": "^10",
|
|
@@ -45,6 +44,7 @@
|
|
|
45
44
|
"@lexical/react": "^0.34.0",
|
|
46
45
|
"@lexical/rich-text": "^0.34.0",
|
|
47
46
|
"@lhci/cli": "^0.15.1",
|
|
47
|
+
"@qwik.dev/partytown": "^0.14.0",
|
|
48
48
|
"@types/react": "^18.3.27",
|
|
49
49
|
"@vtex/client-cms": "^0.2.16",
|
|
50
50
|
"@vtex/client-cp": "0.6.0",
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"style-loader": "^3.3.1",
|
|
71
71
|
"swr": "^2.2.5",
|
|
72
72
|
"use-sync-external-store": "^1.6.0",
|
|
73
|
-
"@faststore/api": "4.3.0-dev.
|
|
74
|
-
"@faststore/
|
|
75
|
-
"@faststore/
|
|
76
|
-
"@faststore/
|
|
77
|
-
"@faststore/
|
|
73
|
+
"@faststore/api": "4.3.0-dev.7",
|
|
74
|
+
"@faststore/diagnostics": "4.3.0-dev.7",
|
|
75
|
+
"@faststore/lighthouse": "4.3.0-dev.7",
|
|
76
|
+
"@faststore/ui": "4.3.0-dev.7",
|
|
77
|
+
"@faststore/sdk": "4.3.0-dev.7"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@cypress/code-coverage": "^3.12.1",
|
|
@@ -39,84 +39,89 @@ const authMessage = {
|
|
|
39
39
|
export const useSetPassword = (accountName?: string) => {
|
|
40
40
|
const [loading, setLoading] = useState<boolean>(false)
|
|
41
41
|
|
|
42
|
-
const setPassword = useCallback(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const body = {
|
|
49
|
-
login: input.userEmail,
|
|
50
|
-
currentPassword: input.currentPassword,
|
|
51
|
-
newPassword: input.newPassword,
|
|
52
|
-
accesskey: !input.accesskey ? null : input.accesskey,
|
|
53
|
-
recaptcha: !input.recaptcha ? null : input.recaptcha,
|
|
54
|
-
}
|
|
42
|
+
const setPassword = useCallback(
|
|
43
|
+
async (input: SetPasswordInput) => {
|
|
44
|
+
setLoading(true)
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const an = encodeURIComponent(accountName ?? config.api.storeId)
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
await startLogin({ email: input.userEmail, accountName, an })
|
|
50
|
+
|
|
51
|
+
const body = {
|
|
52
|
+
login: input.userEmail,
|
|
53
|
+
currentPassword: input.currentPassword,
|
|
54
|
+
newPassword: input.newPassword,
|
|
55
|
+
accesskey: !input.accesskey ? null : input.accesskey,
|
|
56
|
+
recaptcha: !input.recaptcha ? null : input.recaptcha,
|
|
62
57
|
}
|
|
63
|
-
)
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
const response = await fetch(
|
|
60
|
+
`/api/authenticator/pub/authentication/classic/setpassword?expireSessions=true&an=${an}`,
|
|
61
|
+
{
|
|
62
|
+
method: 'POST',
|
|
63
|
+
body: buildFormData(body),
|
|
64
|
+
credentials: 'include',
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
setLoading(false)
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
console.error('Set password request failed:', response.statusText)
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
let errorStatus = AUTH_STATUS.UNEXPECTED_ERROR
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
try {
|
|
76
|
+
const errorBody = await response.json()
|
|
77
|
+
if (errorBody?.authStatus) {
|
|
78
|
+
errorStatus = String(errorBody.authStatus).toLowerCase().trim()
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
// Keep the default error
|
|
76
82
|
}
|
|
77
|
-
} catch {
|
|
78
|
-
// Keep the default error
|
|
79
|
-
}
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
return {
|
|
85
|
+
success: false,
|
|
86
|
+
message: authMessage[errorStatus],
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
|
-
}
|
|
86
89
|
|
|
87
|
-
|
|
90
|
+
const result: SetPasswordResultType = await response.json()
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
if (!result) {
|
|
93
|
+
setLoading(false)
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
message: authMessage[AUTH_STATUS.NO_RESPONSE],
|
|
98
|
+
}
|
|
95
99
|
}
|
|
96
|
-
}
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
const authStatus = result?.authStatus?.toLowerCase().trim() ?? ''
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
return {
|
|
104
|
+
success: authStatus === AUTH_STATUS.SUCCESS,
|
|
105
|
+
message: authMessage[authStatus] || 'Unexpected error occurred',
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
console.error('Error setting password:', err)
|
|
106
109
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
const authStatus =
|
|
111
|
+
typeof err === 'object' && err !== null && 'authStatus' in err
|
|
112
|
+
? String(err.authStatus).toLowerCase().trim()
|
|
113
|
+
: AUTH_STATUS.UNEXPECTED_ERROR
|
|
111
114
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
message: authMessage[authStatus] || 'Unexpected error occurred',
|
|
118
|
+
}
|
|
119
|
+
} finally {
|
|
120
|
+
setLoading(false)
|
|
115
121
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}, [])
|
|
122
|
+
},
|
|
123
|
+
[accountName]
|
|
124
|
+
)
|
|
120
125
|
|
|
121
126
|
return { setPassword, loading }
|
|
122
127
|
}
|
|
@@ -124,23 +129,28 @@ export const useSetPassword = (accountName?: string) => {
|
|
|
124
129
|
const startLogin = async ({
|
|
125
130
|
email,
|
|
126
131
|
accountName,
|
|
132
|
+
an,
|
|
127
133
|
}: {
|
|
128
134
|
email: string
|
|
129
135
|
accountName?: string
|
|
136
|
+
an: string
|
|
130
137
|
}) => {
|
|
131
138
|
try {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
const scope = accountName ?? config.api.storeId
|
|
140
|
+
|
|
141
|
+
const response = await fetch(
|
|
142
|
+
`/api/authenticator/pub/authentication/start?an=${an}`,
|
|
143
|
+
{
|
|
144
|
+
method: 'POST',
|
|
145
|
+
credentials: 'include',
|
|
146
|
+
body: buildFormData({
|
|
147
|
+
user: email,
|
|
148
|
+
scope,
|
|
149
|
+
accountName: scope,
|
|
150
|
+
returnUrl: '/',
|
|
151
|
+
}),
|
|
152
|
+
}
|
|
153
|
+
)
|
|
144
154
|
|
|
145
155
|
if (!response.ok) {
|
|
146
156
|
throw {
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { act, renderHook } from '@testing-library/react'
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
7
|
+
|
|
8
|
+
vi.mock('discovery.config', () => ({
|
|
9
|
+
__esModule: true,
|
|
10
|
+
default: {
|
|
11
|
+
api: { storeId: 'storeframework' },
|
|
12
|
+
},
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
const mockFetch = vi.hoisted(() => vi.fn())
|
|
16
|
+
vi.mock('isomorphic-unfetch', () => ({ __esModule: true, default: mockFetch }))
|
|
17
|
+
|
|
18
|
+
import { useSetPassword } from '../../../src/sdk/account/useSetPassword'
|
|
19
|
+
|
|
20
|
+
const okResponse = (body: unknown) => ({
|
|
21
|
+
ok: true,
|
|
22
|
+
statusText: 'OK',
|
|
23
|
+
json: async () => body,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const errorResponse = (body: unknown) => ({
|
|
27
|
+
ok: false,
|
|
28
|
+
statusText: 'Bad Request',
|
|
29
|
+
json: async () => body,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const validInput = {
|
|
33
|
+
userEmail: 'shopper@example.com',
|
|
34
|
+
currentPassword: 'OldPass123',
|
|
35
|
+
newPassword: 'NewPass123',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getSetPasswordCall() {
|
|
39
|
+
return mockFetch.mock.calls.find((call) =>
|
|
40
|
+
String(call[0]).includes('setpassword')
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getStartLoginCall() {
|
|
45
|
+
return mockFetch.mock.calls.find((call) =>
|
|
46
|
+
String(call[0]).includes('/pub/authentication/start')
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('useSetPassword', () => {
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
mockFetch.mockReset()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
vi.clearAllMocks()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('posts to the new authenticator setpassword route with expireSessions and an', async () => {
|
|
60
|
+
mockFetch
|
|
61
|
+
.mockResolvedValueOnce(okResponse({})) // startLogin
|
|
62
|
+
.mockResolvedValueOnce(okResponse({ authStatus: 'success' }))
|
|
63
|
+
|
|
64
|
+
const { result } = renderHook(() => useSetPassword('myaccount'))
|
|
65
|
+
|
|
66
|
+
await act(async () => {
|
|
67
|
+
await result.current.setPassword(validInput)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const call = getSetPasswordCall()
|
|
71
|
+
expect(call).toBeDefined()
|
|
72
|
+
|
|
73
|
+
const url = String(call?.[0])
|
|
74
|
+
expect(url).toContain(
|
|
75
|
+
'/api/authenticator/pub/authentication/classic/setpassword'
|
|
76
|
+
)
|
|
77
|
+
expect(url).not.toContain('/api/vtexid/')
|
|
78
|
+
expect(url).toContain('expireSessions=true')
|
|
79
|
+
expect(url).toContain('an=myaccount')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('posts to the new authenticator start route with an and credentials', async () => {
|
|
83
|
+
mockFetch
|
|
84
|
+
.mockResolvedValueOnce(okResponse({})) // startLogin
|
|
85
|
+
.mockResolvedValueOnce(okResponse({ authStatus: 'success' }))
|
|
86
|
+
|
|
87
|
+
const { result } = renderHook(() => useSetPassword('myaccount'))
|
|
88
|
+
|
|
89
|
+
await act(async () => {
|
|
90
|
+
await result.current.setPassword(validInput)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const call = getStartLoginCall()
|
|
94
|
+
expect(call).toBeDefined()
|
|
95
|
+
|
|
96
|
+
const url = String(call?.[0])
|
|
97
|
+
expect(url).toContain('/api/authenticator/pub/authentication/start')
|
|
98
|
+
expect(url).not.toContain('/api/vtexid/')
|
|
99
|
+
expect(url).toContain('an=myaccount')
|
|
100
|
+
|
|
101
|
+
const init = call?.[1] as RequestInit
|
|
102
|
+
expect(init?.method).toBe('POST')
|
|
103
|
+
expect(init?.credentials).toBe('include')
|
|
104
|
+
|
|
105
|
+
const body = init?.body as FormData
|
|
106
|
+
expect(body).toBeInstanceOf(FormData)
|
|
107
|
+
expect(body.get('user')).toBe(validInput.userEmail)
|
|
108
|
+
expect(body.get('scope')).toBe('myaccount')
|
|
109
|
+
expect(body.get('accountName')).toBe('myaccount')
|
|
110
|
+
expect(body.get('returnUrl')).toBe('/')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('sends a POST with credentials and the expected form-data body', async () => {
|
|
114
|
+
mockFetch
|
|
115
|
+
.mockResolvedValueOnce(okResponse({}))
|
|
116
|
+
.mockResolvedValueOnce(okResponse({ authStatus: 'success' }))
|
|
117
|
+
|
|
118
|
+
const { result } = renderHook(() => useSetPassword('myaccount'))
|
|
119
|
+
|
|
120
|
+
await act(async () => {
|
|
121
|
+
await result.current.setPassword(validInput)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const call = getSetPasswordCall()
|
|
125
|
+
const init = call?.[1] as RequestInit
|
|
126
|
+
|
|
127
|
+
expect(init?.method).toBe('POST')
|
|
128
|
+
expect(init?.credentials).toBe('include')
|
|
129
|
+
|
|
130
|
+
const body = init?.body as FormData
|
|
131
|
+
expect(body).toBeInstanceOf(FormData)
|
|
132
|
+
expect(body.get('login')).toBe(validInput.userEmail)
|
|
133
|
+
expect(body.get('currentPassword')).toBe(validInput.currentPassword)
|
|
134
|
+
expect(body.get('newPassword')).toBe(validInput.newPassword)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('returns success when the endpoint reports authStatus success', async () => {
|
|
138
|
+
mockFetch
|
|
139
|
+
.mockResolvedValueOnce(okResponse({}))
|
|
140
|
+
.mockResolvedValueOnce(okResponse({ authStatus: 'success' }))
|
|
141
|
+
|
|
142
|
+
const { result } = renderHook(() => useSetPassword('myaccount'))
|
|
143
|
+
|
|
144
|
+
let outcome: { success: boolean; message: string } | undefined
|
|
145
|
+
await act(async () => {
|
|
146
|
+
outcome = await result.current.setPassword(validInput)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
expect(outcome).toEqual({
|
|
150
|
+
success: true,
|
|
151
|
+
message: 'Password set successfully',
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('maps wrongcredentials error responses to the existing message', async () => {
|
|
156
|
+
mockFetch
|
|
157
|
+
.mockResolvedValueOnce(okResponse({}))
|
|
158
|
+
.mockResolvedValueOnce(errorResponse({ authStatus: 'wrongcredentials' }))
|
|
159
|
+
|
|
160
|
+
const { result } = renderHook(() => useSetPassword('myaccount'))
|
|
161
|
+
|
|
162
|
+
let outcome: { success: boolean; message: string } | undefined
|
|
163
|
+
await act(async () => {
|
|
164
|
+
outcome = await result.current.setPassword(validInput)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
expect(outcome).toEqual({ success: false, message: 'Wrong credentials' })
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('falls back to config.api.storeId when accountName is missing', async () => {
|
|
171
|
+
mockFetch
|
|
172
|
+
.mockResolvedValueOnce(okResponse({}))
|
|
173
|
+
.mockResolvedValueOnce(okResponse({ authStatus: 'success' }))
|
|
174
|
+
|
|
175
|
+
const { result } = renderHook(() => useSetPassword())
|
|
176
|
+
|
|
177
|
+
await act(async () => {
|
|
178
|
+
await result.current.setPassword(validInput)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
const setPasswordUrl = String(getSetPasswordCall()?.[0])
|
|
182
|
+
expect(setPasswordUrl).toContain('an=storeframework')
|
|
183
|
+
|
|
184
|
+
const startLoginCall = getStartLoginCall()
|
|
185
|
+
const startLoginUrl = String(startLoginCall?.[0])
|
|
186
|
+
expect(startLoginUrl).toContain('an=storeframework')
|
|
187
|
+
|
|
188
|
+
const startBody = (startLoginCall?.[1] as RequestInit)?.body as FormData
|
|
189
|
+
expect(startBody.get('scope')).toBe('storeframework')
|
|
190
|
+
expect(startBody.get('accountName')).toBe('storeframework')
|
|
191
|
+
})
|
|
192
|
+
})
|