@bemedev/react-guardian 0.0.0-stage → 0.1.1
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/CHANGELOG.md +84 -0
- package/LICENSE +21 -0
- package/README.md +194 -2
- package/lib/browser.d.ts +34 -0
- package/lib/browser.d.ts.map +1 -0
- package/lib/browser.js +54 -0
- package/lib/browser.js.map +1 -0
- package/lib/connect-Bw2GVANX.js +72 -0
- package/lib/connect-Bw2GVANX.js.map +1 -0
- package/lib/connect-Dc_Y4PVe.d.ts +103 -0
- package/lib/connect-Dc_Y4PVe.d.ts.map +1 -0
- package/lib/connect.d.ts +2 -0
- package/lib/connect.js +2 -0
- package/lib/constants.d.ts +19 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +22 -0
- package/lib/constants.js.map +1 -0
- package/lib/crypto.d.ts +17 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +97 -0
- package/lib/crypto.js.map +1 -0
- package/lib/disconnect.d.ts +26 -0
- package/lib/disconnect.d.ts.map +1 -0
- package/lib/disconnect.js +18 -0
- package/lib/disconnect.js.map +1 -0
- package/lib/env.d.ts +13 -0
- package/lib/env.d.ts.map +1 -0
- package/lib/env.js +20 -0
- package/lib/env.js.map +1 -0
- package/lib/guardian.d.ts +27 -0
- package/lib/guardian.d.ts.map +1 -0
- package/lib/guardian.js +42 -0
- package/lib/guardian.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +5 -0
- package/lib/session.d.ts +31 -0
- package/lib/session.d.ts.map +1 -0
- package/lib/session.js +52 -0
- package/lib/session.js.map +1 -0
- package/lib/verify.d.ts +19 -0
- package/lib/verify.d.ts.map +1 -0
- package/lib/verify.js +23 -0
- package/lib/verify.js.map +1 -0
- package/package.json +127 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
## CHANGELOG
|
|
2
|
+
|
|
3
|
+
<details>
|
|
4
|
+
<summary>
|
|
5
|
+
|
|
6
|
+
## **[0.1.1] - 04/12/2026** => _21:30_
|
|
7
|
+
|
|
8
|
+
</summary>
|
|
9
|
+
|
|
10
|
+
- ⚠️ Remove the `connectWithPassword` and `connectSeamless` named exports in favor of
|
|
11
|
+
the expanded `connect`
|
|
12
|
+
- ✨ Expand `connect` with `connect.withPassword` and `connect.seamless`
|
|
13
|
+
- 📦 Publish every module as its own subpath export (`./browser`, `./connect`,
|
|
14
|
+
`./constants`, `./crypto`, `./disconnect`, `./env`, `./guardian`, `./session`,
|
|
15
|
+
`./verify`)
|
|
16
|
+
- 🏷️ Add an explicit `VerifyCode` type so `verify` keeps a small declaration file
|
|
17
|
+
- 📝 Document the library and the example app with complete JSDoc
|
|
18
|
+
- 🧪 Split the guardian tests and add tests for the example app
|
|
19
|
+
- <u>Test coverage **_100%_**</u>
|
|
20
|
+
|
|
21
|
+
</details>
|
|
22
|
+
|
|
23
|
+
<br/>
|
|
24
|
+
<br/>
|
|
25
|
+
|
|
26
|
+
<details>
|
|
27
|
+
<summary>
|
|
28
|
+
|
|
29
|
+
## **[0.1.0] - 04/12/2026** => _19:20_
|
|
30
|
+
|
|
31
|
+
</summary>
|
|
32
|
+
|
|
33
|
+
- ✨ First published version of `@bemedev/react-guardian`
|
|
34
|
+
- 🔐 The access code is kept in `sessionStorage` and encrypted with AES-GCM (Web
|
|
35
|
+
Crypto)
|
|
36
|
+
- 🖥️ The code is verified server-side by a TanStack Start server function through
|
|
37
|
+
`BEMEDEV_CODE_ENV` (`.env`)
|
|
38
|
+
- 🛡️ `reactGuardian(to)` redirects disconnected visitors to the connexion page while
|
|
39
|
+
keeping the requested URL in the `redirect` parameter
|
|
40
|
+
- 🔑 `connect`, `connect.withPassword` and `connect.seamless` handle password and
|
|
41
|
+
passwordless (redirect) connections
|
|
42
|
+
- 🚪 `disconnect` clears the session and optionally navigates to a page
|
|
43
|
+
- 🧰 Session helpers `getCode`, `isConnected`, `setCode` and `clearCode`
|
|
44
|
+
- 📦 Every module is published as its own subpath export (`./browser`, `./connect`,
|
|
45
|
+
`./constants`, `./crypto`, `./disconnect`, `./env`, `./guardian`, `./session`,
|
|
46
|
+
`./verify`)
|
|
47
|
+
- 🌐 Website open when `BEMEDEV_CODE_ENV` is not configured
|
|
48
|
+
- ♻️ Replace the sample `packages/core` package with `packages/react-guardian`
|
|
49
|
+
- 📝 Add the library README and CHANGELOG
|
|
50
|
+
- 🧪 Tests for the guard, connection, disconnection and encryption
|
|
51
|
+
- <u>Test coverage **_100%_**</u>
|
|
52
|
+
|
|
53
|
+
</details>
|
|
54
|
+
|
|
55
|
+
<br/>
|
|
56
|
+
<br/>
|
|
57
|
+
|
|
58
|
+
### Version [0.0.1] --> _date & hour_
|
|
59
|
+
|
|
60
|
+
- ✨ Première version de la bibliothèque
|
|
61
|
+
- 🔐 Le code d'accès est stocké dans `sessionStorage`
|
|
62
|
+
- 🔒 Le code de session est chiffré avec AES-GCM (Web Crypto)
|
|
63
|
+
- 🖥️ Le code est vérifié côté serveur via `BEMEDEV_CODE_ENV` (`.env`)
|
|
64
|
+
- 🔑 `connectWithPassword` pour une connexion avec mot de passe
|
|
65
|
+
- ↩️ `connectSeamless` pour une connexion sans mot de passe par redirection
|
|
66
|
+
- 🚪 `disconnect` pour effacer la session
|
|
67
|
+
- 🛡️ `reactGuardian` redirige les visiteurs non connectés vers la page de connexion
|
|
68
|
+
- 🌐 Site ouvert quand `BEMEDEV_CODE_ENV` n'est pas configuré
|
|
69
|
+
|
|
70
|
+
<br/>
|
|
71
|
+
|
|
72
|
+
## Auteur
|
|
73
|
+
|
|
74
|
+
chlbri (bri_lvi@icloud.com)
|
|
75
|
+
|
|
76
|
+
[My github](https://github.com/chlbri?tab=repositories)
|
|
77
|
+
|
|
78
|
+
[<svg width="98" height="96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#24292f"/></svg>](https://github.com/chlbri?tab=repositories)
|
|
79
|
+
|
|
80
|
+
<br/>
|
|
81
|
+
|
|
82
|
+
## Liens
|
|
83
|
+
|
|
84
|
+
- [Documentation](https://github.com/chlbri/react-guardian)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 chlbri
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,195 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bemedev/react-guardian
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Headless access gate for [TanStack Start](https://tanstack.com/start) React
|
|
4
|
+
applications. Client websites are protected by an access code stored encrypted
|
|
5
|
+
(AES-GCM) in `sessionStorage` and verified on the server against the
|
|
6
|
+
`BEMEDEV_CODE_ENV` environment variable.
|
|
7
|
+
|
|
8
|
+
The package provides:
|
|
9
|
+
|
|
10
|
+
- `reactGuardian(to)` — guard a route and redirect disconnected visitors to the
|
|
11
|
+
connexion page.
|
|
12
|
+
- `connect({ password })` — connect with a password.
|
|
13
|
+
- `connect()` / `connect.seamless()` — connect without a password from the `code`
|
|
14
|
+
query parameter (seamless redirect).
|
|
15
|
+
- `connect.withPassword(password)` — explicit password helper.
|
|
16
|
+
- `disconnect()` — clear the session.
|
|
17
|
+
|
|
18
|
+
<br/>
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @bemedev/react-guardian
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
<br/>
|
|
27
|
+
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
Add the expected access code to `.env`. It stays on the server:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
BEMEDEV_CODE_ENV=my-secret-code
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
When `BEMEDEV_CODE_ENV` is missing or empty, the website is considered open and every
|
|
37
|
+
visitor is accepted.
|
|
38
|
+
|
|
39
|
+
The server function must be transformed by the TanStack Start Vite plugin. When the
|
|
40
|
+
library is consumed from `node_modules`, exclude it from dependency pre-bundling in
|
|
41
|
+
development:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// vite.config.ts
|
|
45
|
+
export default defineConfig({
|
|
46
|
+
optimizeDeps: { exclude: ['@bemedev/react-guardian'] },
|
|
47
|
+
plugins: [tanstackStart(), viteReact()],
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
<br/>
|
|
52
|
+
|
|
53
|
+
## Guard a route
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { reactGuardian } from '@bemedev/react-guardian';
|
|
57
|
+
import { createFileRoute } from '@tanstack/react-router';
|
|
58
|
+
|
|
59
|
+
export const Route = createFileRoute('/')({
|
|
60
|
+
beforeLoad: () => reactGuardian('/connexion'),
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
When the code stored in `sessionStorage` is missing or invalid, the guard redirects
|
|
65
|
+
to `/connexion?redirect=<current-url>`. When it is valid, the requested page renders.
|
|
66
|
+
|
|
67
|
+
`sessionStorage` only exists in the browser, so the guard returns early during server
|
|
68
|
+
rendering. Protect server data with your own server checks as well.
|
|
69
|
+
|
|
70
|
+
<br/>
|
|
71
|
+
|
|
72
|
+
## Connect with a password
|
|
73
|
+
|
|
74
|
+
On the connexion page, verify the password entered by the visitor:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { connect } from '@bemedev/react-guardian';
|
|
78
|
+
|
|
79
|
+
async function onSubmit(password: string) {
|
|
80
|
+
const connected = await connect.withPassword(password, { redirectTo: '/' });
|
|
81
|
+
|
|
82
|
+
if (!connected) {
|
|
83
|
+
// Show an error message.
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The password is verified on the server, stored in `sessionStorage`, and the visitor
|
|
89
|
+
is sent to `redirectTo`. You can also read the page to open from the `redirect` query
|
|
90
|
+
parameter by omitting `redirectTo`.
|
|
91
|
+
|
|
92
|
+
<br/>
|
|
93
|
+
|
|
94
|
+
## Connect without a password (seamless redirect)
|
|
95
|
+
|
|
96
|
+
When the connexion page sends the visitor back with a `code` query parameter, connect
|
|
97
|
+
seamlessly:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { connect } from '@bemedev/react-guardian';
|
|
101
|
+
|
|
102
|
+
await connect.seamless();
|
|
103
|
+
// Reads /?code=<code>&redirect=<page>, verifies the code on the server,
|
|
104
|
+
// stores it in sessionStorage, and opens <page>.
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`connect()` behaves the same way when no `password` is provided:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
await connect({ redirectTo: '/dashboard' });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
<br/>
|
|
114
|
+
|
|
115
|
+
## Disconnect
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { disconnect } from '@bemedev/react-guardian';
|
|
119
|
+
|
|
120
|
+
disconnect({ redirectTo: '/connexion' });
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
This clears the code from `sessionStorage` and optionally opens a page.
|
|
124
|
+
|
|
125
|
+
<br/>
|
|
126
|
+
|
|
127
|
+
## API
|
|
128
|
+
|
|
129
|
+
### `reactGuardian(to)`
|
|
130
|
+
|
|
131
|
+
Verifies the session code on the server. Redirects to `to` when the visitor is not
|
|
132
|
+
connected. `to` can be an internal route or an absolute URL.
|
|
133
|
+
|
|
134
|
+
### `connect(options?)`
|
|
135
|
+
|
|
136
|
+
- `options.password` — Password variant. Verified on the server.
|
|
137
|
+
- `options.redirectTo` — Page to open after a successful connection. Defaults to the
|
|
138
|
+
`redirect` query parameter, then `/`.
|
|
139
|
+
- `options.navigate` — Navigation implementation. Defaults to
|
|
140
|
+
`window.location.replace`.
|
|
141
|
+
|
|
142
|
+
Returns `true` when connected, `false` otherwise.
|
|
143
|
+
|
|
144
|
+
### `connect.withPassword(password, options?)`
|
|
145
|
+
|
|
146
|
+
Password variant of `connect`.
|
|
147
|
+
|
|
148
|
+
### `connect.seamless(options?)`
|
|
149
|
+
|
|
150
|
+
Seamless variant of `connect`. Reads the code from the `code` query parameter.
|
|
151
|
+
|
|
152
|
+
### `disconnect(options?)`
|
|
153
|
+
|
|
154
|
+
Clears the session code. `options.redirectTo` optionally opens a page, and
|
|
155
|
+
`options.navigate` overrides navigation.
|
|
156
|
+
|
|
157
|
+
### Session helpers
|
|
158
|
+
|
|
159
|
+
- `getCode()` — decrypted code from `sessionStorage`, or `null`.
|
|
160
|
+
- `isConnected()` — whether a valid code is stored.
|
|
161
|
+
- `setCode(code)` — encrypt with AES-GCM and persist the code.
|
|
162
|
+
- `clearCode()` — remove the code.
|
|
163
|
+
|
|
164
|
+
### Subpath exports
|
|
165
|
+
|
|
166
|
+
Every module is published as its own entry point:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import { SESSION_KEY } from '@bemedev/react-guardian/constants';
|
|
170
|
+
import { encryptCode } from '@bemedev/react-guardian/crypto';
|
|
171
|
+
import { readEnv } from '@bemedev/react-guardian/env';
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The available subpaths are `browser`, `connect`, `constants`, `crypto`, `disconnect`,
|
|
175
|
+
`env`, `guardian`, `session` and `verify`.
|
|
176
|
+
|
|
177
|
+
<br/>
|
|
178
|
+
|
|
179
|
+
## Licence
|
|
180
|
+
|
|
181
|
+
MIT
|
|
182
|
+
|
|
183
|
+
## CHANGE_LOG
|
|
184
|
+
|
|
185
|
+
Read [CHANGELOG.md](CHANGELOG.md) for more details about the changes.
|
|
186
|
+
|
|
187
|
+
<br/>
|
|
188
|
+
|
|
189
|
+
## Auteur
|
|
190
|
+
|
|
191
|
+
chlbri (bri_lvi@icloud.com)
|
|
192
|
+
|
|
193
|
+
[My github](https://github.com/chlbri?tab=repositories)
|
|
194
|
+
|
|
195
|
+
[<svg width="98" height="96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#24292f"/></svg>](https://github.com/chlbri?tab=repositories)
|
package/lib/browser.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the browser session storage, when available.
|
|
3
|
+
*
|
|
4
|
+
* @returns The session storage, or `undefined` during server rendering.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getSessionStorage(): Storage | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the current browser URL, when available.
|
|
9
|
+
*
|
|
10
|
+
* @returns The current URL, or `undefined` during server rendering.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getCurrentUrl(): URL | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Default navigation implementation.
|
|
15
|
+
*
|
|
16
|
+
* Uses `window.location.replace` so a successful connection does not leave the
|
|
17
|
+
* connexion page in the browser history.
|
|
18
|
+
*
|
|
19
|
+
* @param href - Absolute or relative URL to open.
|
|
20
|
+
*/
|
|
21
|
+
export declare function defaultNavigate(href: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Reads the code from the `code` query parameter of the current URL.
|
|
24
|
+
*
|
|
25
|
+
* @returns The code, or `undefined` when it is not present.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readUrlCode(): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Reads the page to open from the `redirect` query parameter of the current URL.
|
|
30
|
+
*
|
|
31
|
+
* @returns The requested page, or `undefined` when it is not present.
|
|
32
|
+
*/
|
|
33
|
+
export declare function readUrlRedirect(): string | undefined;
|
|
34
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","names":[],"sources":["../src/browser.ts"],"mappings":";;;;;wBAOgB,qBAAqB;;;;;;wBAerB,iBAAiB;;;;;;;;;wBAcjB,gBAAgB;;;;;;wBAShB;;;;;;wBASA"}
|
package/lib/browser.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import "./constants.js";
|
|
2
|
+
// src/browser.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns the browser session storage, when available.
|
|
5
|
+
*
|
|
6
|
+
* @returns The session storage, or `undefined` during server rendering.
|
|
7
|
+
*/
|
|
8
|
+
function getSessionStorage() {
|
|
9
|
+
if (typeof window === "undefined") return void 0;
|
|
10
|
+
try {
|
|
11
|
+
return window.sessionStorage;
|
|
12
|
+
} catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the current browser URL, when available.
|
|
18
|
+
*
|
|
19
|
+
* @returns The current URL, or `undefined` during server rendering.
|
|
20
|
+
*/
|
|
21
|
+
function getCurrentUrl() {
|
|
22
|
+
if (typeof window === "undefined") return void 0;
|
|
23
|
+
return new URL(window.location.href);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Default navigation implementation.
|
|
27
|
+
*
|
|
28
|
+
* Uses `window.location.replace` so a successful connection does not leave the
|
|
29
|
+
* connexion page in the browser history.
|
|
30
|
+
*
|
|
31
|
+
* @param href - Absolute or relative URL to open.
|
|
32
|
+
*/
|
|
33
|
+
function defaultNavigate(href) {
|
|
34
|
+
if (typeof window !== "undefined") window.location.replace(href);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Reads the code from the `code` query parameter of the current URL.
|
|
38
|
+
*
|
|
39
|
+
* @returns The code, or `undefined` when it is not present.
|
|
40
|
+
*/
|
|
41
|
+
function readUrlCode() {
|
|
42
|
+
return getCurrentUrl()?.searchParams.get("code") ?? void 0;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Reads the page to open from the `redirect` query parameter of the current URL.
|
|
46
|
+
*
|
|
47
|
+
* @returns The requested page, or `undefined` when it is not present.
|
|
48
|
+
*/
|
|
49
|
+
function readUrlRedirect() {
|
|
50
|
+
return getCurrentUrl()?.searchParams.get("redirect") ?? void 0;
|
|
51
|
+
}
|
|
52
|
+
export { defaultNavigate, getCurrentUrl, getSessionStorage, readUrlCode, readUrlRedirect };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","names":[],"sources":["../src/browser.ts"],"sourcesContent":["import { CODE_PARAM, REDIRECT_PARAM } from './constants';\n\n/**\n * Returns the browser session storage, when available.\n *\n * @returns The session storage, or `undefined` during server rendering.\n */\nexport function getSessionStorage(): Storage | undefined {\n if (typeof window === 'undefined') return undefined;\n\n try {\n return window.sessionStorage;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns the current browser URL, when available.\n *\n * @returns The current URL, or `undefined` during server rendering.\n */\nexport function getCurrentUrl(): URL | undefined {\n if (typeof window === 'undefined') return undefined;\n\n return new URL(window.location.href);\n}\n\n/**\n * Default navigation implementation.\n *\n * Uses `window.location.replace` so a successful connection does not leave the\n * connexion page in the browser history.\n *\n * @param href - Absolute or relative URL to open.\n */\nexport function defaultNavigate(href: string): void {\n if (typeof window !== 'undefined') window.location.replace(href);\n}\n\n/**\n * Reads the code from the `code` query parameter of the current URL.\n *\n * @returns The code, or `undefined` when it is not present.\n */\nexport function readUrlCode(): string | undefined {\n return getCurrentUrl()?.searchParams.get(CODE_PARAM) ?? undefined;\n}\n\n/**\n * Reads the page to open from the `redirect` query parameter of the current URL.\n *\n * @returns The requested page, or `undefined` when it is not present.\n */\nexport function readUrlRedirect(): string | undefined {\n return getCurrentUrl()?.searchParams.get(REDIRECT_PARAM) ?? undefined;\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,oBAAyC;CACvD,IAAI,OAAO,WAAW,aAAa,OAAO,KAAA;CAE1C,IAAI;EACF,OAAO,OAAO;CAChB,QAAQ;EACN;CACF;AACF;;;;;;AAOA,SAAgB,gBAAiC;CAC/C,IAAI,OAAO,WAAW,aAAa,OAAO,KAAA;CAE1C,OAAO,IAAI,IAAI,OAAO,SAAS,IAAI;AACrC;;;;;;;;;AAUA,SAAgB,gBAAgB,MAAoB;CAClD,IAAI,OAAO,WAAW,aAAa,OAAO,SAAS,QAAQ,IAAI;AACjE;;;;;;AAOA,SAAgB,cAAkC;CAChD,OAAO,cAAc,CAAC,EAAE,aAAa,IAAA,MAAc,KAAK,KAAA;AAC1D;;;;;;AAOA,SAAgB,kBAAsC;CACpD,OAAO,cAAc,CAAC,EAAE,aAAa,IAAA,UAAkB,KAAK,KAAA;AAC9D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { defaultNavigate, readUrlCode, readUrlRedirect } from "./browser.js";
|
|
2
|
+
import "./constants.js";
|
|
3
|
+
import { setCode } from "./session.js";
|
|
4
|
+
import { verifyCode } from "./verify.js";
|
|
5
|
+
// src/libs/bemedev/globals/utils/expandFn.ts
|
|
6
|
+
const _expandFn = (main, extensions) => {
|
|
7
|
+
const out = main;
|
|
8
|
+
if (extensions) for (const key of Reflect.ownKeys(extensions)) Object.defineProperty(out, key, {
|
|
9
|
+
configurable: true,
|
|
10
|
+
enumerable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: extensions[key]
|
|
13
|
+
});
|
|
14
|
+
return out;
|
|
15
|
+
};
|
|
16
|
+
// src/connect.ts
|
|
17
|
+
/**
|
|
18
|
+
* Connects the visitor with or without a password.
|
|
19
|
+
*
|
|
20
|
+
* - With `options.password`, the entered password is verified on the server.
|
|
21
|
+
* - Without `options.password`, the `code` query parameter is read from the current
|
|
22
|
+
* URL and verified on the server. This is the seamless redirect variant used when a
|
|
23
|
+
* connexion page sends the visitor back to the client website.
|
|
24
|
+
*
|
|
25
|
+
* On success the verified code is stored in `sessionStorage`, the visitor is sent to
|
|
26
|
+
* the requested page, and the function resolves to `true`. On failure nothing is
|
|
27
|
+
* stored or navigated, and the function resolves to `false`.
|
|
28
|
+
*
|
|
29
|
+
* @param options - Connection options.
|
|
30
|
+
*
|
|
31
|
+
* @returns `true` when the visitor is connected, `false` otherwise.
|
|
32
|
+
*
|
|
33
|
+
* @see -- type {@linkcode ConnectOptions}
|
|
34
|
+
*/
|
|
35
|
+
const connect = _expandFn(_expandFn, { typed: _expandFn })(async (options = {}) => {
|
|
36
|
+
const code = options.password ?? readUrlCode() ?? "";
|
|
37
|
+
if (!await verifyCode({ data: code })) return false;
|
|
38
|
+
await setCode(code || "bemedev:open");
|
|
39
|
+
const target = options.redirectTo ?? readUrlRedirect() ?? "/";
|
|
40
|
+
(options.navigate ?? defaultNavigate)(target);
|
|
41
|
+
return true;
|
|
42
|
+
}, {
|
|
43
|
+
/**
|
|
44
|
+
* Connects the visitor with a password.
|
|
45
|
+
*
|
|
46
|
+
* @param password - Password entered by the visitor.
|
|
47
|
+
* @param options - Connection options without the password.
|
|
48
|
+
*
|
|
49
|
+
* @returns `true` when the visitor is connected, `false` otherwise.
|
|
50
|
+
*
|
|
51
|
+
* @see {@linkcode connect}
|
|
52
|
+
*/
|
|
53
|
+
withPassword: (password, options = {}) => connect({
|
|
54
|
+
...options,
|
|
55
|
+
password
|
|
56
|
+
}),
|
|
57
|
+
/**
|
|
58
|
+
* Connects the visitor seamlessly from the `code` query parameter.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Connection options without the password.
|
|
61
|
+
*
|
|
62
|
+
* @returns `true` when the visitor is connected, `false` otherwise.
|
|
63
|
+
*
|
|
64
|
+
* @see {@linkcode connect}
|
|
65
|
+
*/
|
|
66
|
+
seamless: (options = {}) => {
|
|
67
|
+
return connect(options);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
export { connect as t };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=connect-Bw2GVANX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-Bw2GVANX.js","names":[],"sources":["../src/libs/bemedev/globals/utils/expandFn.ts","../src/connect.ts"],"sourcesContent":["/* v8 ignore start -- @preserve */\n\nimport type { Equals } from '../../features/common/types';\nimport type { Fn, FnBasic, OnlyFn } from '../../features/functions/types';\nimport type { EmptyO } from '../../features/objects/types';\n\n/**\n * GetObject type - Auto-generated expression\n *\n * ⚠️ WARNING: This expression is auto-generated and should not be modified.\n * Any manual changes will be overwritten during the next generation.\n *\n * @generated\n * @readonly\n * @author chlbri (bri_lvi@icloud.com)\n */\nexport type GetObject<T extends Fn> = { [K in keyof T]: T[K] };\n\n/**\n * TypedArgs type - Auto-generated expression\n *\n * ⚠️ WARNING: This expression is auto-generated and should not be modified.\n * Any manual changes will be overwritten during the next generation.\n *\n * @generated\n * @readonly\n * @author chlbri (bri_lvi@icloud.com)\n */\nexport type TypedArgs<\n T extends Fn,\n G extends GetObject<T> = GetObject<T>,\n F extends OnlyFn<T> = OnlyFn<T>,\n> = Equals<G, EmptyO> extends true ? [main: F] : [main: F, extension: G];\n\n// #region Cooking\ntype _ExpandFn_F = <const Main extends Fn, const Tr extends object = object>(\n main: Main,\n extensions?: Tr,\n) => FnBasic<Main, Tr>;\n\ntype _ExpandFnTyped_F = <const T extends Fn>(\n ...args: TypedArgs<T>\n) => FnBasic<OnlyFn<T>, GetObject<T>>;\n\nconst _expandFn: _ExpandFn_F = (main, extensions) => {\n const out: any = main;\n if (extensions) {\n // Define instead of assign so read-only function properties such as\n // `length` and `name` can be replaced by extension members.\n for (const key of Reflect.ownKeys(extensions)) {\n Object.defineProperty(out, key, {\n configurable: true,\n enumerable: true,\n writable: true,\n value: (extensions as Record<PropertyKey, unknown>)[key],\n });\n }\n }\n return out;\n};\n// #endregion\n\n/**\n * ExpandFn_F type - Auto-generated expression\n *\n * ⚠️ WARNING: This expression is auto-generated and should not be modified.\n * Any manual changes will be overwritten during the next generation.\n *\n * @generated\n * @readonly\n * @author chlbri (bri_lvi@icloud.com)\n */\nexport type ExpandFn_F = FnBasic<_ExpandFn_F, { readonly typed: _ExpandFnTyped_F }>;\n\n/**\n * expandFn variable - Auto-generated expression\n *\n * ⚠️ WARNING: This expression is auto-generated and should not be modified.\n * Any manual changes will be overwritten during the next generation.\n *\n * @generated\n * @readonly\n * @author chlbri (bri_lvi@icloud.com)\n */\nexport const expandFn: ExpandFn_F = _expandFn(_expandFn, {\n typed: _expandFn as _ExpandFnTyped_F,\n});\n","import { defaultNavigate, readUrlCode, readUrlRedirect } from './browser';\nimport { DEFAULT_REDIRECT, OPEN_CODE } from './constants';\nimport { expandFn } from './libs/bemedev/globals/utils/expandFn';\nimport { setCode } from './session';\nimport { verifyCode } from './verify';\n\n/**\n * Options accepted by {@linkcode connect}.\n */\nexport type ConnectOptions = {\n /**\n * Password entered by the visitor.\n *\n * When omitted, {@linkcode connect} runs the seamless variant and reads the code\n * from the `code` query parameter.\n */\n password?: string;\n\n /**\n * Page to open after a successful connection.\n *\n * Defaults to the `redirect` query parameter, then to `/`.\n */\n redirectTo?: string;\n\n /**\n * Navigation implementation.\n *\n * Defaults to `window.location.replace`.\n */\n navigate?: (href: string) => void;\n};\n\n/**\n * Connects the visitor with or without a password.\n *\n * - With `options.password`, the entered password is verified on the server.\n * - Without `options.password`, the `code` query parameter is read from the current\n * URL and verified on the server. This is the seamless redirect variant used when a\n * connexion page sends the visitor back to the client website.\n *\n * On success the verified code is stored in `sessionStorage`, the visitor is sent to\n * the requested page, and the function resolves to `true`. On failure nothing is\n * stored or navigated, and the function resolves to `false`.\n *\n * @param options - Connection options.\n *\n * @returns `true` when the visitor is connected, `false` otherwise.\n *\n * @see -- type {@linkcode ConnectOptions}\n */\nexport const connect = expandFn(\n async (options: ConnectOptions = {}): Promise<boolean> => {\n const code = options.password ?? readUrlCode() ?? '';\n const valid = await verifyCode({ data: code });\n\n if (!valid) return false;\n\n await setCode(code || OPEN_CODE);\n\n const target = options.redirectTo ?? readUrlRedirect() ?? DEFAULT_REDIRECT;\n const navigate = options.navigate ?? defaultNavigate;\n\n navigate(target);\n\n return true;\n },\n {\n /**\n * Connects the visitor with a password.\n *\n * @param password - Password entered by the visitor.\n * @param options - Connection options without the password.\n *\n * @returns `true` when the visitor is connected, `false` otherwise.\n *\n * @see {@linkcode connect}\n */\n withPassword: (\n password: string,\n options: Omit<ConnectOptions, 'password'> = {},\n ): Promise<boolean> => connect({ ...options, password }),\n\n /**\n * Connects the visitor seamlessly from the `code` query parameter.\n *\n * @param options - Connection options without the password.\n *\n * @returns `true` when the visitor is connected, `false` otherwise.\n *\n * @see {@linkcode connect}\n */\n seamless: (options: Omit<ConnectOptions, 'password'> = {}): Promise<boolean> => {\n return connect(options);\n },\n },\n);\n"],"mappings":";;;;;AA4CA,MAAM,aAA0B,MAAM,eAAe;CACnD,MAAM,MAAW;CACjB,IAAI,YAGF,KAAK,MAAM,OAAO,QAAQ,QAAQ,UAAU,GAC1C,OAAO,eAAe,KAAK,KAAK;EAC9B,cAAc;EACd,YAAY;EACZ,UAAU;EACV,OAAQ,WAA4C;CACtD,CAAC;CAGL,OAAO;AACT;;;;;;;;;;;;;;;;;;;;ACRA,MAAa,UDiCuB,UAAU,WAAW,EACvD,OAAO,UACT,CCnCuB,CAAA,CACrB,OAAO,UAA0B,CAAC,MAAwB;CACxD,MAAM,OAAO,QAAQ,YAAY,YAAY,KAAK;CAGlD,IAAI,CAAC,MAFe,WAAW,EAAE,MAAM,KAAK,CAAC,GAEjC,OAAO;CAEnB,MAAM,QAAQ,QAAA,cAAiB;CAE/B,MAAM,SAAS,QAAQ,cAAc,gBAAgB,KAAA;CAGrD,CAFiB,QAAQ,YAAY,gBAAA,CAE5B,MAAM;CAEf,OAAO;AACT,GACA;;;;;;;;;;;CAWE,eACE,UACA,UAA4C,CAAC,MACxB,QAAQ;EAAE,GAAG;EAAS;CAAS,CAAC;;;;;;;;;;CAWvD,WAAW,UAA4C,CAAC,MAAwB;EAC9E,OAAO,QAAQ,OAAO;CACxB;AACF,CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic function type.
|
|
3
|
+
*
|
|
4
|
+
* @template Args - Tuple of the function parameters.
|
|
5
|
+
* @template R - Type returned by the function.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Fn type - Auto-generated expression
|
|
9
|
+
*
|
|
10
|
+
* ⚠️ WARNING: This expression is auto-generated and should not be modified.
|
|
11
|
+
* Any manual changes will be overwritten during the next generation.
|
|
12
|
+
*
|
|
13
|
+
* @generated
|
|
14
|
+
* @readonly
|
|
15
|
+
* @author chlbri (bri_lvi@icloud.com)
|
|
16
|
+
*/
|
|
17
|
+
type Fn<Args extends any[] = any[], R = any> = (...args: Args) => R;
|
|
18
|
+
/**
|
|
19
|
+
* Function augmented with extension members.
|
|
20
|
+
*
|
|
21
|
+
* Intersects the extension object `Tr` with the main function type `Main`.
|
|
22
|
+
*
|
|
23
|
+
* @template Main - Base function type.
|
|
24
|
+
* @template Tr - Type of the extension members.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* FnBasic type - Auto-generated expression
|
|
28
|
+
*
|
|
29
|
+
* ⚠️ WARNING: This expression is auto-generated and should not be modified.
|
|
30
|
+
* Any manual changes will be overwritten during the next generation.
|
|
31
|
+
*
|
|
32
|
+
* @generated
|
|
33
|
+
* @readonly
|
|
34
|
+
* @author chlbri (bri_lvi@icloud.com)
|
|
35
|
+
*/
|
|
36
|
+
type FnBasic<Main extends Fn, Tr extends object> = Tr & Main;
|
|
37
|
+
/**
|
|
38
|
+
* Options accepted by {@linkcode connect}.
|
|
39
|
+
*/
|
|
40
|
+
type ConnectOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* Password entered by the visitor.
|
|
43
|
+
*
|
|
44
|
+
* When omitted, {@linkcode connect} runs the seamless variant and reads the code
|
|
45
|
+
* from the `code` query parameter.
|
|
46
|
+
*/
|
|
47
|
+
password?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Page to open after a successful connection.
|
|
50
|
+
*
|
|
51
|
+
* Defaults to the `redirect` query parameter, then to `/`.
|
|
52
|
+
*/
|
|
53
|
+
redirectTo?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Navigation implementation.
|
|
56
|
+
*
|
|
57
|
+
* Defaults to `window.location.replace`.
|
|
58
|
+
*/
|
|
59
|
+
navigate?: (href: string) => void;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Connects the visitor with or without a password.
|
|
63
|
+
*
|
|
64
|
+
* - With `options.password`, the entered password is verified on the server.
|
|
65
|
+
* - Without `options.password`, the `code` query parameter is read from the current
|
|
66
|
+
* URL and verified on the server. This is the seamless redirect variant used when a
|
|
67
|
+
* connexion page sends the visitor back to the client website.
|
|
68
|
+
*
|
|
69
|
+
* On success the verified code is stored in `sessionStorage`, the visitor is sent to
|
|
70
|
+
* the requested page, and the function resolves to `true`. On failure nothing is
|
|
71
|
+
* stored or navigated, and the function resolves to `false`.
|
|
72
|
+
*
|
|
73
|
+
* @param options - Connection options.
|
|
74
|
+
*
|
|
75
|
+
* @returns `true` when the visitor is connected, `false` otherwise.
|
|
76
|
+
*
|
|
77
|
+
* @see -- type {@linkcode ConnectOptions}
|
|
78
|
+
*/
|
|
79
|
+
declare const connect: FnBasic<(options?: ConnectOptions) => Promise<boolean>, {
|
|
80
|
+
/**
|
|
81
|
+
* Connects the visitor with a password.
|
|
82
|
+
*
|
|
83
|
+
* @param password - Password entered by the visitor.
|
|
84
|
+
* @param options - Connection options without the password.
|
|
85
|
+
*
|
|
86
|
+
* @returns `true` when the visitor is connected, `false` otherwise.
|
|
87
|
+
*
|
|
88
|
+
* @see {@linkcode connect}
|
|
89
|
+
*/
|
|
90
|
+
readonly withPassword: (password: string, options?: Omit<ConnectOptions, "password">) => Promise<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Connects the visitor seamlessly from the `code` query parameter.
|
|
93
|
+
*
|
|
94
|
+
* @param options - Connection options without the password.
|
|
95
|
+
*
|
|
96
|
+
* @returns `true` when the visitor is connected, `false` otherwise.
|
|
97
|
+
*
|
|
98
|
+
* @see {@linkcode connect}
|
|
99
|
+
*/
|
|
100
|
+
readonly seamless: (options?: Omit<ConnectOptions, "password">) => Promise<boolean>;
|
|
101
|
+
}>;
|
|
102
|
+
export { connect as n, ConnectOptions as t };
|
|
103
|
+
//# sourceMappingURL=connect-Dc_Y4PVe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-Dc_Y4PVe.d.ts","names":["_$__libs_bemedev_globals_types0.FnBasic"],"sources":["../src/libs/bemedev/features/functions/types.ts","../src/connect.ts"],"mappings":";;;;;;;;;;;;;;;;KAmBY,GAAG,4BAA4B,eAAe,MAAM,SAAS;;;;;;;;;;;;;;;;;;;KAoB7D,QAAQ,aAAa,IAAI,qBAAqB,KAAK;;;;KC9BnD;;;;;;;EAOV;;;;;;EAOA;;;;;;EAOA,YAAY;;;;;;;;;;;;;;;;;;;;cAqBD,SAyCmDA,SAzC5C,UACF,mBAAsB;;;;;;;;;;;WA2BxB,eAAA,kBAAM,UACP,KAAK,gCACb;;;;;;;;;;WAWiB,WAAA,UAAA,KAAK,gCAAmC"}
|
package/lib/connect.d.ts
ADDED
package/lib/connect.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Name of the `.env` variable holding the expected access code. */
|
|
2
|
+
export declare const CODE_ENV = "BEMEDEV_CODE_ENV";
|
|
3
|
+
/** Key used to persist the access code in `sessionStorage`. */
|
|
4
|
+
export declare const SESSION_KEY = "bemedev:react-guardian:code";
|
|
5
|
+
/** Query parameter carrying the code during a seamless connection. */
|
|
6
|
+
export declare const CODE_PARAM = "code";
|
|
7
|
+
/** Query parameter carrying the page to open after a connection. */
|
|
8
|
+
export declare const REDIRECT_PARAM = "redirect";
|
|
9
|
+
/** Value stored when the website has no access code configured. */
|
|
10
|
+
export declare const OPEN_CODE = "bemedev:open";
|
|
11
|
+
/** Default page opened after a successful connection. */
|
|
12
|
+
export declare const DEFAULT_REDIRECT = "/";
|
|
13
|
+
/** Secret used to derive the AES-GCM session key. */
|
|
14
|
+
export declare const ENCRYPTION_SECRET = "bemedev:react-guardian:v1";
|
|
15
|
+
/** AES-GCM encryption algorithm. */
|
|
16
|
+
export declare const ENCRYPTION_ALGORITHM = "AES-GCM";
|
|
17
|
+
/** Length of the AES-GCM initialization vector, in bytes. */
|
|
18
|
+
export declare const IV_LENGTH = 12;
|
|
19
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";qBACa;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;qBAGA"}
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
/** Name of the `.env` variable holding the expected access code. */
|
|
3
|
+
const CODE_ENV = "BEMEDEV_CODE_ENV";
|
|
4
|
+
/** Key used to persist the access code in `sessionStorage`. */
|
|
5
|
+
const SESSION_KEY = "bemedev:react-guardian:code";
|
|
6
|
+
/** Query parameter carrying the code during a seamless connection. */
|
|
7
|
+
const CODE_PARAM = "code";
|
|
8
|
+
/** Query parameter carrying the page to open after a connection. */
|
|
9
|
+
const REDIRECT_PARAM = "redirect";
|
|
10
|
+
/** Value stored when the website has no access code configured. */
|
|
11
|
+
const OPEN_CODE = "bemedev:open";
|
|
12
|
+
/** Default page opened after a successful connection. */
|
|
13
|
+
const DEFAULT_REDIRECT = "/";
|
|
14
|
+
/** Secret used to derive the AES-GCM session key. */
|
|
15
|
+
const ENCRYPTION_SECRET = "bemedev:react-guardian:v1";
|
|
16
|
+
/** AES-GCM encryption algorithm. */
|
|
17
|
+
const ENCRYPTION_ALGORITHM = "AES-GCM";
|
|
18
|
+
/** Length of the AES-GCM initialization vector, in bytes. */
|
|
19
|
+
const IV_LENGTH = 12;
|
|
20
|
+
export { CODE_ENV, CODE_PARAM, DEFAULT_REDIRECT, ENCRYPTION_ALGORITHM, ENCRYPTION_SECRET, IV_LENGTH, OPEN_CODE, REDIRECT_PARAM, SESSION_KEY };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/** Name of the `.env` variable holding the expected access code. */\nexport const CODE_ENV = 'BEMEDEV_CODE_ENV';\n\n/** Key used to persist the access code in `sessionStorage`. */\nexport const SESSION_KEY = 'bemedev:react-guardian:code';\n\n/** Query parameter carrying the code during a seamless connection. */\nexport const CODE_PARAM = 'code';\n\n/** Query parameter carrying the page to open after a connection. */\nexport const REDIRECT_PARAM = 'redirect';\n\n/** Value stored when the website has no access code configured. */\nexport const OPEN_CODE = 'bemedev:open';\n\n/** Default page opened after a successful connection. */\nexport const DEFAULT_REDIRECT = '/';\n\n/** Secret used to derive the AES-GCM session key. */\nexport const ENCRYPTION_SECRET = 'bemedev:react-guardian:v1';\n\n/** AES-GCM encryption algorithm. */\nexport const ENCRYPTION_ALGORITHM = 'AES-GCM';\n\n/** Length of the AES-GCM initialization vector, in bytes. */\nexport const IV_LENGTH = 12;\n"],"mappings":";;AACA,MAAa,WAAW;;AAGxB,MAAa,cAAc;;AAG3B,MAAa,aAAa;;AAG1B,MAAa,iBAAiB;;AAG9B,MAAa,YAAY;;AAGzB,MAAa,mBAAmB;;AAGhC,MAAa,oBAAoB;;AAGjC,MAAa,uBAAuB;;AAGpC,MAAa,YAAY"}
|