najm-auth 2.0.15 → 3.1.0
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 +261 -50
- package/dist/{NajmAuthClient-Cn9bObLB.d.ts → NajmAuthClient-DqGucYXi.d.ts} +3 -141
- package/dist/client/edge.d.ts +3 -18
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.js +15 -8
- package/dist/client/react/index.d.ts +11 -6
- package/dist/client/react/index.js +10 -3
- package/dist/client/server/index.d.ts +25 -78
- package/dist/client/server/index.js +104 -60
- package/dist/client/server/react.d.ts +48 -0
- package/dist/client/server/react.js +71 -0
- package/dist/client/server/reactClientGuard.d.ts +2 -0
- package/dist/client/server/reactClientGuard.js +4 -0
- package/dist/getSession-BthP85UA.d.ts +68 -0
- package/dist/identity/ma.d.ts +1 -0
- package/dist/identity/ma.js +64 -0
- package/dist/index.d.ts +395 -91
- package/dist/index.js +1733 -862
- package/dist/ma-sNHnUGLO.d.ts +88 -0
- package/dist/schema/pg.d.ts +260 -1
- package/dist/schema/pg.js +13 -0
- package/dist/schema/sqlite.d.ts +284 -1
- package/dist/schema/sqlite.js +14 -1
- package/dist/sessionRecovery-D5Fa0yZ1.d.ts +18 -0
- package/dist/types-BaSfgxqE.d.ts +166 -0
- package/package.json +15 -2
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { A as AuthUser } from './types-BaSfgxqE.js';
|
|
2
|
+
import { S as SessionRecoveryFailure } from './sessionRecovery-D5Fa0yZ1.js';
|
|
3
|
+
|
|
4
|
+
interface ServerSession {
|
|
5
|
+
user: AuthUser;
|
|
6
|
+
roles?: string[];
|
|
7
|
+
permissions?: string[];
|
|
8
|
+
}
|
|
9
|
+
interface GetSessionConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Base URL for auth endpoints.
|
|
12
|
+
* Defaults to `NEXT_PUBLIC_API_URL` or the same-origin `/api` path.
|
|
13
|
+
*/
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
/** Auth route prefix appended to baseURL (default: '/auth'). */
|
|
16
|
+
authPrefix?: string;
|
|
17
|
+
/** Refresh token cookie name (default: 'refreshToken'). */
|
|
18
|
+
cookieName?: string;
|
|
19
|
+
/** Signed session cookie name (default: 'najm.session'). */
|
|
20
|
+
sessionCookieName?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Secret used to verify the session cookie HMAC signature.
|
|
23
|
+
* Falls back to NAJM_SESSION_SECRET or JWT_ACCESS_SECRET env vars.
|
|
24
|
+
*/
|
|
25
|
+
sessionSecret?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum accepted session-cookie age in seconds.
|
|
28
|
+
* Must match the auth plugin's `session.maxAge`. Default: 300.
|
|
29
|
+
*/
|
|
30
|
+
sessionMaxAge?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Session-recovery endpoint. Defaults to
|
|
33
|
+
* `${baseURL}${authPrefix}/session/recover`. Set to false to disable fallback.
|
|
34
|
+
*/
|
|
35
|
+
recoveryURL?: string | false;
|
|
36
|
+
/** Loopback-only recovery endpoint for self-hosted reverse-proxy setups. */
|
|
37
|
+
internalRecoveryURL?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Error handling mode:
|
|
40
|
+
* - 'nullable' (default): returns null on any failure
|
|
41
|
+
* - 'strict': throws typed errors for debugging
|
|
42
|
+
*/
|
|
43
|
+
mode?: 'nullable' | 'strict';
|
|
44
|
+
/** Secret-free diagnostic hook for failed recovery attempts. */
|
|
45
|
+
onRecoveryFailure?: (failure: SessionRecoveryFailure) => void;
|
|
46
|
+
}
|
|
47
|
+
declare class NoSessionError extends Error {
|
|
48
|
+
readonly code = "NO_SESSION";
|
|
49
|
+
constructor(message?: string);
|
|
50
|
+
}
|
|
51
|
+
declare class AuthConfigError extends Error {
|
|
52
|
+
readonly code = "AUTH_CONFIG_ERROR";
|
|
53
|
+
constructor(message: string);
|
|
54
|
+
}
|
|
55
|
+
declare class AuthTransportError extends Error {
|
|
56
|
+
readonly status?: number;
|
|
57
|
+
readonly code = "AUTH_TRANSPORT_ERROR";
|
|
58
|
+
constructor(message: string, status?: number);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolve a session in a Next.js Server Component, Route Handler, or Server
|
|
62
|
+
* Action. Recovery returns claims for the current render but cannot persist
|
|
63
|
+
* response cookies during Server Component rendering; middleware performs that
|
|
64
|
+
* persistence for protected navigation.
|
|
65
|
+
*/
|
|
66
|
+
declare function getSession(config?: GetSessionConfig): Promise<ServerSession | null>;
|
|
67
|
+
|
|
68
|
+
export { AuthConfigError as A, type GetSessionConfig as G, NoSessionError as N, type ServerSession as S, AuthTransportError as a, getSession as g };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { M as MOROCCAN_CIN_TEMPORARY_CREDENTIAL_KIND, e as TemporaryCredential, T as TemporaryCredentialInput, i as isMoroccanCin, m as moroccanCinTemporaryCredential, j as moroccoIdentityPreset, n as normalizeMoroccanCin, k as normalizeMoroccanPhone } from '../ma-sNHnUGLO.js';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/identity/presets.ts
|
|
5
|
+
var compactPhone = /* @__PURE__ */ __name((value) => value.trim().replace(/[\s().-]+/g, ""), "compactPhone");
|
|
6
|
+
var MOROCCO_LOCAL = /^0\d{9}$/;
|
|
7
|
+
var MOROCCO_NATIONAL = /^212\d{9}$/;
|
|
8
|
+
var MOROCCO_E164 = /^\+212\d{9}$/;
|
|
9
|
+
var normalizeMoroccanPhone = /* @__PURE__ */ __name((value) => {
|
|
10
|
+
const compact = compactPhone(value);
|
|
11
|
+
if (MOROCCO_LOCAL.test(compact))
|
|
12
|
+
return `+212${compact.slice(1)}`;
|
|
13
|
+
if (MOROCCO_NATIONAL.test(compact))
|
|
14
|
+
return `+${compact}`;
|
|
15
|
+
if (MOROCCO_E164.test(compact))
|
|
16
|
+
return compact;
|
|
17
|
+
return null;
|
|
18
|
+
}, "normalizeMoroccanPhone");
|
|
19
|
+
var moroccoIdentityPreset = {
|
|
20
|
+
name: "ma",
|
|
21
|
+
normalize: normalizeMoroccanPhone
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/identity/temporaryCredential.ts
|
|
25
|
+
var EXACT_TEMPORARY_CREDENTIAL_KIND = "exact";
|
|
26
|
+
var exactKind = {
|
|
27
|
+
name: EXACT_TEMPORARY_CREDENTIAL_KIND,
|
|
28
|
+
normalize: /* @__PURE__ */ __name((value) => value, "normalize")
|
|
29
|
+
};
|
|
30
|
+
var MOROCCAN_CIN_TEMPORARY_CREDENTIAL_KIND = "ma-cin";
|
|
31
|
+
var MOROCCAN_CIN = /^[a-z]{1,3}\d{5,17}$/i;
|
|
32
|
+
function isMoroccanCin(value) {
|
|
33
|
+
const trimmed = value.trim();
|
|
34
|
+
return trimmed.length >= 8 && trimmed.length <= 20 && MOROCCAN_CIN.test(trimmed);
|
|
35
|
+
}
|
|
36
|
+
__name(isMoroccanCin, "isMoroccanCin");
|
|
37
|
+
function normalizeMoroccanCin(value) {
|
|
38
|
+
return isMoroccanCin(value) ? value.trim().toLowerCase() : value;
|
|
39
|
+
}
|
|
40
|
+
__name(normalizeMoroccanCin, "normalizeMoroccanCin");
|
|
41
|
+
var moroccanCinKind = {
|
|
42
|
+
name: MOROCCAN_CIN_TEMPORARY_CREDENTIAL_KIND,
|
|
43
|
+
normalize: normalizeMoroccanCin,
|
|
44
|
+
isTemporaryShape: isMoroccanCin
|
|
45
|
+
};
|
|
46
|
+
var KINDS = /* @__PURE__ */ new Map([
|
|
47
|
+
[exactKind.name, exactKind],
|
|
48
|
+
[moroccanCinKind.name, moroccanCinKind]
|
|
49
|
+
]);
|
|
50
|
+
function moroccanCinTemporaryCredential(value) {
|
|
51
|
+
if (!isMoroccanCin(value)) {
|
|
52
|
+
throw new Error("moroccanCinTemporaryCredential requires a valid Moroccan CIN");
|
|
53
|
+
}
|
|
54
|
+
return { kind: MOROCCAN_CIN_TEMPORARY_CREDENTIAL_KIND, value };
|
|
55
|
+
}
|
|
56
|
+
__name(moroccanCinTemporaryCredential, "moroccanCinTemporaryCredential");
|
|
57
|
+
export {
|
|
58
|
+
MOROCCAN_CIN_TEMPORARY_CREDENTIAL_KIND,
|
|
59
|
+
isMoroccanCin,
|
|
60
|
+
moroccanCinTemporaryCredential,
|
|
61
|
+
moroccoIdentityPreset,
|
|
62
|
+
normalizeMoroccanCin,
|
|
63
|
+
normalizeMoroccanPhone
|
|
64
|
+
};
|