@securitydept/basic-auth-context-client 0.3.0-beta.3 → 0.3.0-beta.5
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/README.md +6 -0
- package/dist/index.d.mts +253 -10
- package/dist/index.mjs +757 -3
- package/dist/index.mjs.map +1 -0
- package/package.json +12 -11
- package/dist/client-DU98lpa_.d.mts +0 -91
- package/dist/client-D_0eAARH.mjs +0 -136
- package/dist/client-D_0eAARH.mjs.map +0 -1
- package/dist/server/index.d.mts +0 -73
- package/dist/server/index.mjs +0 -47
- package/dist/server/index.mjs.map +0 -1
- package/dist/types-2IoKrgnl.mjs +0 -20
- package/dist/types-2IoKrgnl.mjs.map +0 -1
- package/dist/web/index.d.mts +0 -50
- package/dist/web/index.mjs +0 -50
- package/dist/web/index.mjs.map +0 -1
package/dist/web/index.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { n as AuthGuardResultKind } from "../types-2IoKrgnl.mjs";
|
|
2
|
-
import { assertResolveEnvironment } from "@securitydept/client/web";
|
|
3
|
-
//#region src/web/login-redirect.ts
|
|
4
|
-
const BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE$1 = "basic-auth browser redirect helpers require an explicit page environment.\nCreate one in your composition root with createBrowserPageClientEnvironment(...).";
|
|
5
|
-
/**
|
|
6
|
-
* One-shot browser redirect to the zone login endpoint for the given path.
|
|
7
|
-
*
|
|
8
|
-
* 1. Resolves the zone for the current (or specified) path.
|
|
9
|
-
* 2. Navigates the current window to the zone's login URL with a
|
|
10
|
-
* post-auth redirect parameter.
|
|
11
|
-
*
|
|
12
|
-
* Returns `false` if no zone matches the path (no redirect performed).
|
|
13
|
-
* Returns `true` if the redirect was initiated.
|
|
14
|
-
*
|
|
15
|
-
* This is the recommended browser entry point for initiating basic-auth
|
|
16
|
-
* login. It is intentionally a standalone function (not a method on
|
|
17
|
-
* `BasicAuthContextClient`) to keep browser-specific side-effects out
|
|
18
|
-
* of the host-neutral client contract.
|
|
19
|
-
*/
|
|
20
|
-
function loginWithRedirect(client, options = {}) {
|
|
21
|
-
const environment = assertResolveEnvironment(options.environment, failMissingPageEnvironment$1);
|
|
22
|
-
const currentPath = options.currentPath ?? environment.location.pathname ?? new URL(environment.location.href).pathname;
|
|
23
|
-
const zone = client.zoneForPath(currentPath);
|
|
24
|
-
if (!zone) return false;
|
|
25
|
-
const postAuthRedirectUri = options.postAuthRedirectUri ?? environment.location.href;
|
|
26
|
-
environment.location.href = client.loginUrl(zone, postAuthRedirectUri);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
function failMissingPageEnvironment$1() {
|
|
30
|
-
throw new Error(BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE$1);
|
|
31
|
-
}
|
|
32
|
-
//#endregion
|
|
33
|
-
//#region src/web/redirect.ts
|
|
34
|
-
const BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE = "basic-auth browser redirect helpers require an explicit page environment.\nCreate one in your composition root with createBrowserPageClientEnvironment(...).";
|
|
35
|
-
/**
|
|
36
|
-
* Perform a browser redirect for an `AuthGuardResult` that requires redirection.
|
|
37
|
-
*/
|
|
38
|
-
function performRedirect(result, options = {}) {
|
|
39
|
-
if (result.kind === AuthGuardResultKind.Redirect) {
|
|
40
|
-
const environment = assertResolveEnvironment(options.environment, failMissingPageEnvironment);
|
|
41
|
-
environment.location.href = result.location;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function failMissingPageEnvironment() {
|
|
45
|
-
throw new Error(BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE);
|
|
46
|
-
}
|
|
47
|
-
//#endregion
|
|
48
|
-
export { loginWithRedirect, performRedirect };
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/web/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE","failMissingPageEnvironment"],"sources":["../../src/web/login-redirect.ts","../../src/web/redirect.ts"],"sourcesContent":["// Basic Auth Context Client — Browser login redirect convenience\n//\n// Provides a one-shot browser redirect to a zone's login page, matching the\n// convenience pattern established by session-context-client/web.\n//\n// Unlike session-context where there is a single login URL, basic-auth is\n// zone-based: the adopter must identify which zone to target. This helper\n// resolves the zone from a path and performs the redirect.\n//\n// Stability: provisional\n\nimport type { PageLocationCapability } from \"@securitydept/client\";\nimport { assertResolveEnvironment } from \"@securitydept/client/web\";\nimport type { BasicAuthContextClient } from \"../client\";\n\nconst BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE =\n\t\"basic-auth browser redirect helpers require an explicit page environment.\\n\" +\n\t\"Create one in your composition root with createBrowserPageClientEnvironment(...).\";\n\n/**\n * Options for {@link loginWithRedirect}.\n */\nexport interface LoginWithRedirectOptions {\n\tenvironment?: PageLocationCapability;\n\n\t/**\n\t * The current request path to resolve the target zone.\n\t *\n\t * When omitted, `environment.location.pathname` is used.\n\t */\n\tcurrentPath?: string;\n\n\t/**\n\t * Where to redirect the user after successful authentication.\n\t *\n\t * When omitted, `environment.location.href` is used as the return URI.\n\t */\n\tpostAuthRedirectUri?: string;\n}\n\n/**\n * One-shot browser redirect to the zone login endpoint for the given path.\n *\n * 1. Resolves the zone for the current (or specified) path.\n * 2. Navigates the current window to the zone's login URL with a\n * post-auth redirect parameter.\n *\n * Returns `false` if no zone matches the path (no redirect performed).\n * Returns `true` if the redirect was initiated.\n *\n * This is the recommended browser entry point for initiating basic-auth\n * login. It is intentionally a standalone function (not a method on\n * `BasicAuthContextClient`) to keep browser-specific side-effects out\n * of the host-neutral client contract.\n */\nexport function loginWithRedirect(\n\tclient: BasicAuthContextClient,\n\toptions: LoginWithRedirectOptions = {},\n): boolean {\n\tconst environment = assertResolveEnvironment(\n\t\toptions.environment,\n\t\tfailMissingPageEnvironment,\n\t);\n\tconst currentPath =\n\t\toptions.currentPath ??\n\t\tenvironment.location.pathname ??\n\t\tnew URL(environment.location.href).pathname;\n\tconst zone = client.zoneForPath(currentPath);\n\tif (!zone) {\n\t\treturn false;\n\t}\n\n\tconst postAuthRedirectUri =\n\t\toptions.postAuthRedirectUri ?? environment.location.href;\n\tenvironment.location.href = client.loginUrl(zone, postAuthRedirectUri);\n\treturn true;\n}\n\nfunction failMissingPageEnvironment(): never {\n\tthrow new Error(BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE);\n}\n","import type { PageLocationCapability } from \"@securitydept/client\";\nimport { assertResolveEnvironment } from \"@securitydept/client/web\";\nimport type { AuthGuardResult } from \"../types\";\nimport { AuthGuardResultKind } from \"../types\";\n\nconst BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE =\n\t\"basic-auth browser redirect helpers require an explicit page environment.\\n\" +\n\t\"Create one in your composition root with createBrowserPageClientEnvironment(...).\";\n\nexport interface PerformRedirectOptions {\n\tenvironment?: PageLocationCapability;\n}\n\n/**\n * Perform a browser redirect for an `AuthGuardResult` that requires redirection.\n */\nexport function performRedirect(\n\tresult: AuthGuardResult<unknown>,\n\toptions: PerformRedirectOptions = {},\n): void {\n\tif (result.kind === AuthGuardResultKind.Redirect) {\n\t\tconst environment = assertResolveEnvironment(\n\t\t\toptions.environment,\n\t\t\tfailMissingPageEnvironment,\n\t\t);\n\t\tenvironment.location.href = result.location;\n\t}\n}\n\nfunction failMissingPageEnvironment(): never {\n\tthrow new Error(BASIC_AUTH_PAGE_ENVIRONMENT_ERROR_MESSAGE);\n}\n"],"mappings":";;;AAeA,MAAMA,8CACL;;;;;;;;;;;;;;;;AAuCD,SAAgB,kBACf,QACA,UAAoC,EAAE,EAC5B;CACV,MAAM,cAAc,yBACnB,QAAQ,aACRC,6BACA;CACD,MAAM,cACL,QAAQ,eACR,YAAY,SAAS,YACrB,IAAI,IAAI,YAAY,SAAS,KAAK,CAAC;CACpC,MAAM,OAAO,OAAO,YAAY,YAAY;CAC5C,IAAI,CAAC,MACJ,OAAO;CAGR,MAAM,sBACL,QAAQ,uBAAuB,YAAY,SAAS;CACrD,YAAY,SAAS,OAAO,OAAO,SAAS,MAAM,oBAAoB;CACtE,OAAO;;AAGR,SAASA,+BAAoC;CAC5C,MAAM,IAAI,MAAMD,4CAA0C;;;;AC1E3D,MAAM,4CACL;;;;AAUD,SAAgB,gBACf,QACA,UAAkC,EAAE,EAC7B;CACP,IAAI,OAAO,SAAS,oBAAoB,UAAU;EACjD,MAAM,cAAc,yBACnB,QAAQ,aACR,2BACA;EACD,YAAY,SAAS,OAAO,OAAO;;;AAIrC,SAAS,6BAAoC;CAC5C,MAAM,IAAI,MAAM,0CAA0C"}
|