@faststore/core 3.100.2 → 3.100.3

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.
Files changed (52) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +47 -47
  3. package/.next/cache/.tsbuildinfo +1 -1
  4. package/.next/cache/config.json +3 -3
  5. package/.next/cache/webpack/client-production/0.pack +0 -0
  6. package/.next/cache/webpack/client-production/index.pack +0 -0
  7. package/.next/cache/webpack/edge-server-production/0.pack +0 -0
  8. package/.next/cache/webpack/edge-server-production/index.pack +0 -0
  9. package/.next/cache/webpack/server-production/0.pack +0 -0
  10. package/.next/cache/webpack/server-production/index.pack +0 -0
  11. package/.next/prerender-manifest.js +1 -1
  12. package/.next/prerender-manifest.json +1 -1
  13. package/.next/routes-manifest.json +1 -1
  14. package/.next/server/functions-config-manifest.json +1 -1
  15. package/.next/server/middleware-build-manifest.js +1 -1
  16. package/.next/server/middleware-manifest.json +2 -2
  17. package/.next/server/pages/api/fs/password-protection/unlock.js +1 -0
  18. package/.next/server/pages/en-US/404.html +2 -2
  19. package/.next/server/pages/en-US/500.html +2 -2
  20. package/.next/server/pages/en-US/checkout.html +2 -2
  21. package/.next/server/pages/en-US/login.html +2 -2
  22. package/.next/server/pages/en-US/{fs-auth-login.html → password-protection.html} +2 -2
  23. package/.next/server/pages/en-US/s.html +2 -2
  24. package/.next/server/pages/en-US.html +2 -2
  25. package/.next/server/pages-manifest.json +1 -1
  26. package/.next/server/src/middleware.js +33 -33
  27. package/.next/server/src/middleware.js.map +1 -1
  28. package/.next/static/0OKcQtIHO8diwBsczup15/_buildManifest.js +1 -0
  29. package/.next/static/chunks/main-a2d1cfe626f2fef1.js +1 -0
  30. package/.next/static/chunks/pages/password-protection-8dece47ea041d372.js +1 -0
  31. package/.next/static/chunks/{webpack-95c583fdc5f7d468.js → webpack-25c67512e1907efd.js} +1 -1
  32. package/.next/static/css/033b9397a0c0cf71.css +1 -0
  33. package/.next/trace +156 -156
  34. package/.turbo/turbo-build.log +18 -18
  35. package/.turbo/turbo-test.log +8 -8
  36. package/CHANGELOG.md +6 -0
  37. package/package.json +2 -2
  38. package/src/middleware.ts +14 -13
  39. package/src/pages/api/fs/{auth/login.ts → password-protection/unlock.ts} +4 -4
  40. package/src/pages/{fs-auth-login → password-protection}/index.tsx +10 -7
  41. package/src/pages/{fs-auth-login/fs-auth-login.module.scss → password-protection/password-protection.module.scss} +1 -1
  42. package/src/server/{authentication-service.ts → password-protection-service.ts} +22 -18
  43. package/src/utils/{loginResponse.ts → unlockResponse.ts} +7 -2
  44. package/test/server/{authentication-service.test.ts → password-protection-service.test.ts} +71 -59
  45. package/.next/server/pages/api/fs/auth/login.js +0 -1
  46. package/.next/static/chunks/main-083a618181bb5fbb.js +0 -1
  47. package/.next/static/chunks/pages/fs-auth-login-ba2d1b3ef0ef0415.js +0 -1
  48. package/.next/static/css/3bd4edd425711792.css +0 -1
  49. package/.next/static/qnFvdN4P3Em9yV6nJ1gX8/_buildManifest.js +0 -1
  50. /package/.next/server/pages/api/fs/{auth/login.js.nft.json → password-protection/unlock.js.nft.json} +0 -0
  51. /package/.next/server/pages/{fs-auth-login.js.nft.json → password-protection.js.nft.json} +0 -0
  52. /package/.next/static/{qnFvdN4P3Em9yV6nJ1gX8 → 0OKcQtIHO8diwBsczup15}/_ssgManifest.js +0 -0
@@ -1,23 +1,23 @@
1
1
 
2
- > @faststore/core@3.100.1 prebuild /home/runner/work/faststore/faststore/packages/core
2
+ > @faststore/core@3.100.2 prebuild /home/runner/work/faststore/faststore/packages/core
3
3
  > na run partytown && na run generate
4
4
 
5
5
 
6
- > @faststore/core@3.100.1 partytown /home/runner/work/faststore/faststore/packages/core
6
+ > @faststore/core@3.100.2 partytown /home/runner/work/faststore/faststore/packages/core
7
7
  > partytown copylib ./public/~partytown
8
8
 
9
9
  Partytown lib copied to: /home/runner/work/faststore/faststore/packages/core/public/~partytown
10
10
 
11
- > @faststore/core@3.100.1 generate /home/runner/work/faststore/faststore/packages/core
11
+ > @faststore/core@3.100.2 generate /home/runner/work/faststore/faststore/packages/core
12
12
  > na run generate:schema && na run generate:codegen && na run format:generated
13
13
 
14
14
 
15
- > @faststore/core@3.100.1 generate:schema /home/runner/work/faststore/faststore/packages/core
15
+ > @faststore/core@3.100.2 generate:schema /home/runner/work/faststore/faststore/packages/core
16
16
  > tsx src/server/generator/generateGraphQLSchemaFile.ts
17
17
 
18
18
  Schema GraphQL file generated successfully
19
19
 
20
- > @faststore/core@3.100.1 generate:codegen /home/runner/work/faststore/faststore/packages/core
20
+ > @faststore/core@3.100.2 generate:codegen /home/runner/work/faststore/faststore/packages/core
21
21
  > graphql-codegen
22
22
 
23
23
  [STARTED] Parse Configuration
@@ -37,11 +37,11 @@ Running lifecycle hook "afterStart" scripts...
37
37
  [CLI] Loading Documents
38
38
  [CLI] Generating output
39
39
 
40
- > @faststore/core@3.100.1 format:generated /home/runner/work/faststore/faststore/packages/core
40
+ > @faststore/core@3.100.2 format:generated /home/runner/work/faststore/faststore/packages/core
41
41
  > prettier --write "@generated/**/*.{ts,js,tsx,jsx,json}" --loglevel error
42
42
 
43
43
 
44
- > @faststore/core@3.100.1 build /home/runner/work/faststore/faststore/packages/core
44
+ > @faststore/core@3.100.2 build /home/runner/work/faststore/faststore/packages/core
45
45
  > next build
46
46
 
47
47
  ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
@@ -63,7 +63,6 @@ Browserslist: browsers data (caniuse-lite) is 17 months old. Please run:
63
63
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
64
64
  <w> [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item 'Compilation/modules|/home/runner/work/faststore/faststore/node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[7].oneOf[9].use[1]!/home/runner/work/faststore/faststore/node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[7].oneOf[9].use[2]!/home/runner/work/faststore/faststore/node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/resolve-url-loader/index.js??ruleSet[1].rules[7].oneOf[9].use[3]!/home/runner/work/faststore/faststore/node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/compiled/sass-loader/cjs.js??ruleSet[1].rules[7].oneOf[9].use[4]!/home/runner/work/faststore/faststore/packages/core/src/components/common/Toast/section.module.scss': No serializer registered for Warning
65
65
  <w> while serializing webpack/lib/cache/PackFileCacheStrategy.PackContentItems -> webpack/lib/NormalModule -> Array { 1 items } -> webpack/lib/ModuleWarning -> Warning
66
- Collecting page data ...
67
66
  ⚠ Compiled with warnings
68
67
 
69
68
  ./src/components/common/Toast/section.module.scss.webpack[javascript/auto]!=!../../node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[7].oneOf[9].use[1]!../../node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[7].oneOf[9].use[2]!../../node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/resolve-url-loader/index.js??ruleSet[1].rules[7].oneOf[9].use[3]!../../node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/compiled/sass-loader/cjs.js??ruleSet[1].rules[7].oneOf[9].use[4]!./src/components/common/Toast/section.module.scss
@@ -84,9 +83,9 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime
84
83
 
85
84
  Import trace for requested module:
86
85
  ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/lib/deflate.js
87
- ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
86
+ ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
88
87
  ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/index.js
89
- ./src/server/authentication-service.ts
88
+ ./src/server/password-protection-service.ts
90
89
 
91
90
  ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/lib/deflate.js
92
91
  A Node.js API is used (DecompressionStream at line: 25) which is not supported in the Edge Runtime.
@@ -94,17 +93,18 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime
94
93
 
95
94
  Import trace for requested module:
96
95
  ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/lib/deflate.js
97
- ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
96
+ ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
98
97
  ../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/index.js
99
- ./src/server/authentication-service.ts
98
+ ./src/server/password-protection-service.ts
100
99
 
100
+ Collecting page data ...
101
101
  Generating static pages (0/8) ...
102
102
 
103
103
  Generating static pages (2/8)
104
104
  Search not found. Add a new component for this section or remove it from the CMS
105
105
  Warning: Dynamic Content not found for the page: home. Refer to the Dynamic Content documentation at https://developers.vtex.com/docs/guides/faststore/dynamic-content-overview for mapping the page and the corresponding data-fetching function.
106
- Search not found. Add a new component for this section or remove it from the CMS
107
106
  Search not found. Add a new component for this section or remove it from the CMS
108
107
 
109
108
  Generating static pages (4/8)
109
+ Search not found. Add a new component for this section or remove it from the CMS
110
110
  Search not found. Add a new component for this section or remove it from the CMS
111
111
 
112
112
  Generating static pages (6/8)
113
113
  Search not found. Add a new component for this section or remove it from the CMS
@@ -123,16 +123,16 @@ Route (pages) Size First Load JS
123
123
  ├ └ css/54cedf4b65e5863f.css 16.7 kB
124
124
  ├ ○ /404 1.58 kB 160 kB
125
125
  ├ ● /500 1.58 kB 160 kB
126
- ├ λ /api/fs/auth/login 0 B 109 kB
127
126
  ├ λ /api/fs/logout 0 B 109 kB
127
+ ├ λ /api/fs/password-protection/unlock 0 B 109 kB
128
128
  ├ λ /api/graphql 0 B 109 kB
129
129
  ├ λ /api/health/live 0 B 109 kB
130
130
  ├ λ /api/health/ready 0 B 109 kB
131
131
  ├ λ /api/preview 0 B 109 kB
132
132
  ├ ● /checkout 750 B 159 kB
133
- ├ ○ /fs-auth-login 2.17 kB 111 kB
134
- ├ └ css/3bd4edd425711792.css 3.2 kB
135
133
  ├ ● /login 1.7 kB 160 kB
134
+ ├ ○ /password-protection 2.18 kB 111 kB
135
+ ├ └ css/033b9397a0c0cf71.css 3.2 kB
136
136
  ├ λ /pvt/account 247 B 109 kB
137
137
  ├ ● /pvt/account/[...unknown] 287 B 109 kB
138
138
  ├ λ /pvt/account/403 3 kB 161 kB
@@ -152,9 +152,9 @@ Route (pages) Size First Load JS
152
152
  └ ● /s 3.35 kB 176 kB
153
153
  + First Load JS shared by all 118 kB
154
154
  ├ chunks/framework-d514426edf885c68.js 45.4 kB
155
- ├ chunks/main-083a618181bb5fbb.js 33.4 kB
155
+ ├ chunks/main-a2d1cfe626f2fef1.js 33.4 kB
156
156
  ├ chunks/pages/_app-35e8dda638ee2672.js 26.6 kB
157
- ├ chunks/webpack-95c583fdc5f7d468.js 3.9 kB
157
+ ├ chunks/webpack-25c67512e1907efd.js 3.9 kB
158
158
  └ css/146a8678babc61bf.css 9.2 kB
159
159
 
160
160
  ƒ Middleware 44.8 kB
@@ -1,20 +1,20 @@
1
1
 
2
- > @faststore/core@3.100.1 test /home/runner/work/faststore/faststore/packages/core
2
+ > @faststore/core@3.100.2 test /home/runner/work/faststore/faststore/packages/core
3
3
  > jest
4
4
 
5
- PASS test/utils/clearCookies.test.ts (12.2 s)
6
- PASS test/utils/cookieCacheBusting.test.ts (13.763 s)
7
- PASS test/server/authentication-service.test.ts (16.35 s)
5
+ PASS test/utils/clearCookies.test.ts (9.746 s)
8
6
  PASS test/utils/multipleTemplates.test.ts
9
- PASS test/utils/validateSessionRefreshToken.test.ts
7
+ PASS test/server/password-protection-service.test.ts (16.656 s)
8
+ PASS test/utils/cookieCacheBusting.test.ts (15.853 s)
10
9
  PASS test/server/cms/global.test.ts
10
+ PASS test/utils/validateSessionRefreshToken.test.ts
11
11
  PASS test/utils/isLocalHost.test.ts
12
+ PASS test/server/cms/index.test.ts
12
13
  PASS test/utils/isLocalHost.browser.test.ts
13
- PASS test/server/cms/index.test.ts (5.347 s)
14
- PASS test/server/index.test.ts (9.735 s)
14
+ PASS test/server/index.test.ts (11.788 s)
15
15
 
16
16
  Test Suites: 10 passed, 10 total
17
17
  Tests: 85 passed, 85 total
18
18
  Snapshots: 0 total
19
- Time: 26.942 s
19
+ Time: 27.32 s
20
20
  Ran all test suites.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
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
+ ## [3.100.3](https://github.com/vtex/faststore/compare/v3.100.2...v3.100.3) (2026-06-30)
7
+
8
+ ### Bug Fixes
9
+
10
+ - align password-protection vocabulary in v3 (unlock, not login) ([#3404](https://github.com/vtex/faststore/issues/3404)) ([30222fc](https://github.com/vtex/faststore/commit/30222fcde2b180eb3ded421949a2359917ba53d4)), closes [#3276](https://github.com/vtex/faststore/issues/3276)
11
+
6
12
  ## [3.100.2](https://github.com/vtex/faststore/compare/v3.100.1...v3.100.2) (2026-06-11)
7
13
 
8
14
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "3.100.2",
3
+ "version": "3.100.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -127,5 +127,5 @@
127
127
  "ts-jest": "29.1.1",
128
128
  "typescript": "5.3.2"
129
129
  },
130
- "gitHead": "b2ec3212a504a92012ea95d7f9b13a2bed38b9ee"
130
+ "gitHead": "bf4812f3e3a53108f22ab987098b74f7eed9bfa3"
131
131
  }
package/src/middleware.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Middleware is always active. It runs:
3
- * 1. Password protection (AuthenticationService) — when applicable (default/custom domains per env).
3
+ * 1. Password protection (PasswordProtectionService) — when applicable (default/custom domains per env).
4
4
  * 2. Redirects — only when ENABLE_REDIRECTS_MIDDLEWARE is set at runtime.
5
5
  */
6
6
 
@@ -8,7 +8,7 @@ import { NextResponse } from 'next/server'
8
8
  import type { NextRequest } from 'next/server'
9
9
  import storeConfig from 'discovery.config'
10
10
 
11
- import { AuthenticationService } from './server/authentication-service'
11
+ import { PasswordProtectionService } from './server/password-protection-service'
12
12
 
13
13
  type Redirect = {
14
14
  from: string
@@ -31,19 +31,20 @@ const redirectsClient = new DynamoRedirectsClient()
31
31
  export async function middleware(request: NextRequest) {
32
32
  const path = request.nextUrl.pathname
33
33
 
34
- let authResult: Awaited<
35
- ReturnType<AuthenticationService['authenticateRequest']>
34
+ let storeProtectionResult: Awaited<
35
+ ReturnType<PasswordProtectionService['checkStoreProtection']>
36
36
  >
37
37
 
38
38
  try {
39
- const authService = new AuthenticationService()
40
- authResult = await authService.authenticateRequest(request)
39
+ const protectionService = new PasswordProtectionService()
40
+ storeProtectionResult =
41
+ await protectionService.checkStoreProtection(request)
41
42
  } catch {
42
43
  return NextResponse.error()
43
44
  }
44
45
 
45
- if (authResult.response.status !== 200) {
46
- return authResult.response
46
+ if (storeProtectionResult.response.status !== 200) {
47
+ return storeProtectionResult.response
47
48
  }
48
49
 
49
50
  if (process.env.ENABLE_REDIRECTS_MIDDLEWARE === 'true') {
@@ -54,7 +55,7 @@ export async function middleware(request: NextRequest) {
54
55
  const redirectStatusCode = redirect.type === 'permanent' ? 301 : 302
55
56
  const response = NextResponse.redirect(redirectUrl, redirectStatusCode)
56
57
 
57
- for (const cookie of authResult.response.cookies.getAll()) {
58
+ for (const cookie of storeProtectionResult.response.cookies.getAll()) {
58
59
  response.cookies.set(cookie)
59
60
  }
60
61
 
@@ -67,7 +68,7 @@ export async function middleware(request: NextRequest) {
67
68
  }
68
69
  }
69
70
 
70
- return authResult.response
71
+ return storeProtectionResult.response
71
72
  }
72
73
 
73
74
  export const config = {
@@ -75,13 +76,13 @@ export const config = {
75
76
  /*
76
77
  * Match all paths including `/`
77
78
  * Exclude:
78
- * - api (e.g. api/fs/auth/login)
79
+ * - api (e.g. api/fs/password-protection/unlock)
79
80
  * - _next/static, _next/image
80
81
  * - favicon.ico
81
- * - fs-auth-login (login page)
82
+ * - password-protection (unlock page)
82
83
  * - ~partytown (partytown scripts)
83
84
  */
84
85
  '/',
85
- '/((?!api|_next/static|_next/image|favicon.ico|fs-auth-login|~partytown).*)',
86
+ '/((?!api|_next/static|_next/image|favicon.ico|password-protection|~partytown).*)',
86
87
  ],
87
88
  }
@@ -2,7 +2,7 @@ import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next'
2
2
 
3
3
  import storeConfig from 'discovery.config'
4
4
 
5
- import type { LoginResponse } from '../../../../utils/loginResponse'
5
+ import type { UnlockResponse } from '../../../../utils/unlockResponse'
6
6
  import {
7
7
  sessionUrl,
8
8
  passwordProtectionTimeouts,
@@ -10,7 +10,7 @@ import {
10
10
  import {
11
11
  COOKIE_NAME,
12
12
  TOKEN_TTL_SECONDS,
13
- } from 'src/server/authentication-service'
13
+ } from 'src/server/password-protection-service'
14
14
 
15
15
  interface WebOpsSessionPayload {
16
16
  valid: boolean
@@ -36,9 +36,9 @@ const isWebOpsSessionPayload = (
36
36
  )
37
37
  }
38
38
 
39
- const handler: NextApiHandler<LoginResponse> = async (
39
+ const handler: NextApiHandler<UnlockResponse> = async (
40
40
  request: NextApiRequest,
41
- response: NextApiResponse<LoginResponse>
41
+ response: NextApiResponse<UnlockResponse>
42
42
  ) => {
43
43
  if (request.method !== 'POST') {
44
44
  response.status(405).end()
@@ -3,8 +3,8 @@ import Head from 'next/head'
3
3
  import { useRouter } from 'next/router'
4
4
  import { type FormEvent, useState } from 'react'
5
5
 
6
- import { isLoginResponse } from '../../utils/loginResponse'
7
- import styles from './fs-auth-login.module.scss'
6
+ import { isUnlockResponse } from '../../utils/unlockResponse'
7
+ import styles from './password-protection.module.scss'
8
8
 
9
9
  export default function PasswordProtectionLogin() {
10
10
  const router = useRouter()
@@ -21,7 +21,10 @@ export default function PasswordProtectionLogin() {
21
21
  setError('')
22
22
 
23
23
  try {
24
- const url = new URL('/api/fs/auth/login', globalThis.location.origin)
24
+ const url = new URL(
25
+ '/api/fs/password-protection/unlock',
26
+ globalThis.location.origin
27
+ )
25
28
  url.searchParams.set('returnTo', returnTo)
26
29
 
27
30
  const response = await fetch(url.toString(), {
@@ -32,7 +35,7 @@ export default function PasswordProtectionLogin() {
32
35
 
33
36
  const data: unknown = await response.json()
34
37
 
35
- if (!isLoginResponse(data)) {
38
+ if (!isUnlockResponse(data)) {
36
39
  setError('Service temporarily unavailable')
37
40
  return
38
41
  }
@@ -50,7 +53,7 @@ export default function PasswordProtectionLogin() {
50
53
  }
51
54
 
52
55
  return (
53
- <div className={styles.fsAuthLogin}>
56
+ <div className={styles.fsPasswordProtection}>
54
57
  <Head>
55
58
  <meta name="robots" content="noindex,nofollow" />
56
59
  </Head>
@@ -63,7 +66,7 @@ export default function PasswordProtectionLogin() {
63
66
 
64
67
  <form className={styles.form} onSubmit={handleSubmit}>
65
68
  <InputField
66
- id="fs-auth-password"
69
+ id="password-protection-input"
67
70
  label="Password"
68
71
  type="password"
69
72
  value={password}
@@ -81,7 +84,7 @@ export default function PasswordProtectionLogin() {
81
84
  disabled={loading}
82
85
  loading={loading}
83
86
  >
84
- Login
87
+ Unlock
85
88
  </Button>
86
89
  </form>
87
90
  </div>
@@ -1,5 +1,5 @@
1
1
  @layer components {
2
- .fsAuthLogin {
2
+ .fsPasswordProtection {
3
3
  @import "@faststore/ui/src/components/atoms/Button/styles.scss";
4
4
  @import "@faststore/ui/src/components/atoms/Input/styles.scss";
5
5
  @import "@faststore/ui/src/components/atoms/Loader/styles.scss";
@@ -12,7 +12,7 @@ import {
12
12
  passwordProtectionTimeouts,
13
13
  } from './password-protection/webops-api'
14
14
 
15
- export const COOKIE_NAME = '__fs_auth_token'
15
+ export const COOKIE_NAME = '__fs_password_protection'
16
16
  export const TOKEN_TTL_SECONDS = 10 * 60
17
17
  /** How long to reuse the RSA public key fetched from WebOps */
18
18
  const PUBLIC_KEY_CACHE_MS = 60 * 60 * 1000
@@ -25,7 +25,7 @@ interface TokenPayload {
25
25
  exp?: number
26
26
  }
27
27
 
28
- interface AuthResult {
28
+ interface StoreProtectionResult {
29
29
  response: NextResponse
30
30
  }
31
31
 
@@ -73,7 +73,7 @@ export function resetPasswordProtectionPublicKeyCacheForTests(): void {
73
73
  publicKeyCache = null
74
74
  }
75
75
 
76
- export class AuthenticationService {
76
+ export class PasswordProtectionService {
77
77
  private readonly storeId: string
78
78
 
79
79
  constructor() {
@@ -85,7 +85,9 @@ export class AuthenticationService {
85
85
  return host.split(':')[0].toLowerCase()
86
86
  }
87
87
 
88
- async authenticateRequest(request: NextRequest): Promise<AuthResult> {
88
+ async checkStoreProtection(
89
+ request: NextRequest
90
+ ): Promise<StoreProtectionResult> {
89
91
  if (!this.shouldCheckProtection(request)) {
90
92
  return { response: NextResponse.next() }
91
93
  }
@@ -104,7 +106,7 @@ export class AuthenticationService {
104
106
  }
105
107
  }
106
108
 
107
- return await this.handleNoAuth(request)
109
+ return await this.handleProtectionCheck(request)
108
110
  }
109
111
 
110
112
  private shouldCheckProtection(request: NextRequest): boolean {
@@ -182,7 +184,7 @@ export class AuthenticationService {
182
184
  request: NextRequest,
183
185
  expiredToken: string,
184
186
  payload: TokenPayload
185
- ): Promise<AuthResult> {
187
+ ): Promise<StoreProtectionResult> {
186
188
  try {
187
189
  const res = await fetch(renewUrl(), {
188
190
  method: 'POST',
@@ -199,7 +201,7 @@ export class AuthenticationService {
199
201
 
200
202
  if (data.valid && data.token) {
201
203
  const response = NextResponse.next()
202
- this.setAuthCookie(response, data.token)
204
+ this.setProtectionCookie(response, data.token)
203
205
 
204
206
  return { response }
205
207
  }
@@ -212,17 +214,19 @@ export class AuthenticationService {
212
214
  return { response: NextResponse.next() }
213
215
  }
214
216
 
215
- return { response: this.redirectToLogin(request) }
217
+ return { response: this.redirectToUnlockPage(request) }
216
218
  }
217
219
 
218
- private async handleNoAuth(request: NextRequest): Promise<AuthResult> {
220
+ private async handleProtectionCheck(
221
+ request: NextRequest
222
+ ): Promise<StoreProtectionResult> {
219
223
  try {
220
224
  const res = await fetch(protectionStatusUrl(), {
221
225
  signal: AbortSignal.timeout(passwordProtectionTimeouts.defaultMs),
222
226
  })
223
227
 
224
228
  if (!res.ok) {
225
- return { response: this.redirectToLogin(request) }
229
+ return { response: this.redirectToUnlockPage(request) }
226
230
  }
227
231
 
228
232
  const status = await res.json()
@@ -231,7 +235,7 @@ export class AuthenticationService {
231
235
  const response = NextResponse.next()
232
236
 
233
237
  if (status.token) {
234
- this.setAuthCookie(response, status.token)
238
+ this.setProtectionCookie(response, status.token)
235
239
  }
236
240
 
237
241
  return { response }
@@ -241,13 +245,13 @@ export class AuthenticationService {
241
245
  return { response: NextResponse.next() }
242
246
  }
243
247
 
244
- return { response: this.redirectToLogin(request) }
248
+ return { response: this.redirectToUnlockPage(request) }
245
249
  } catch {
246
- return { response: this.redirectToLogin(request) }
250
+ return { response: this.redirectToUnlockPage(request) }
247
251
  }
248
252
  }
249
253
 
250
- private setAuthCookie(response: NextResponse, token: string): void {
254
+ private setProtectionCookie(response: NextResponse, token: string): void {
251
255
  response.cookies.set(COOKIE_NAME, token, {
252
256
  httpOnly: true,
253
257
  secure: true,
@@ -257,12 +261,12 @@ export class AuthenticationService {
257
261
  })
258
262
  }
259
263
 
260
- private redirectToLogin(request: NextRequest): NextResponse {
261
- const loginUrl = new URL('/fs-auth-login', request.url)
264
+ private redirectToUnlockPage(request: NextRequest): NextResponse {
265
+ const unlockUrl = new URL('/password-protection', request.url)
262
266
  const returnTo = `${request.nextUrl.pathname}${request.nextUrl.search}`
263
- loginUrl.searchParams.set('returnTo', returnTo)
267
+ unlockUrl.searchParams.set('returnTo', returnTo)
264
268
 
265
- const response = NextResponse.redirect(loginUrl)
269
+ const response = NextResponse.redirect(unlockUrl)
266
270
  response.headers.set('Cache-Control', 'no-store')
267
271
 
268
272
  return response
@@ -1,17 +1,22 @@
1
- export interface LoginResponse {
1
+ export interface UnlockResponse {
2
2
  success?: boolean
3
3
  redirectUrl?: string
4
4
  error?: string
5
5
  }
6
6
 
7
- export const isLoginResponse = (data: unknown): data is LoginResponse => {
7
+ export const isUnlockResponse = (data: unknown): data is UnlockResponse => {
8
8
  if (typeof data !== 'object' || data === null || Array.isArray(data)) {
9
9
  return false
10
10
  }
11
11
 
12
12
  const payload = data as Record<string, unknown>
13
+ const hasUnlockResponseField =
14
+ payload.success !== undefined ||
15
+ payload.redirectUrl !== undefined ||
16
+ payload.error !== undefined
13
17
 
14
18
  return (
19
+ hasUnlockResponseField &&
15
20
  (payload.success === undefined || typeof payload.success === 'boolean') &&
16
21
  (payload.redirectUrl === undefined ||
17
22
  typeof payload.redirectUrl === 'string') &&