@absolutejs/auth 0.56.3 → 0.56.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/dist/abuse/captcha.d.ts +11 -0
- package/dist/abuse/config.d.ts +29 -0
- package/dist/actions.d.ts +27 -0
- package/dist/agents/config.d.ts +44 -0
- package/dist/agents/context.d.ts +46 -0
- package/dist/agents/principal.d.ts +4 -0
- package/dist/agents/registration.d.ts +162 -0
- package/dist/agents/routes.d.ts +321 -0
- package/dist/agents/types.d.ts +129 -0
- package/dist/apikeys/config.d.ts +64 -0
- package/dist/apikeys/routes.d.ts +83 -0
- package/dist/apikeys/types.d.ts +53 -0
- package/dist/audit/config.d.ts +9 -0
- package/dist/audit/export.d.ts +2 -0
- package/dist/audit/inMemoryAuditStore.d.ts +2 -0
- package/dist/audit/integrity.d.ts +19 -0
- package/dist/audit/postgresAuditStore.d.ts +116 -0
- package/dist/audit/siem.d.ts +11 -0
- package/dist/audit/types.d.ts +19 -0
- package/dist/audit/wrap.d.ts +9 -0
- package/dist/authContext.d.ts +193 -0
- package/dist/authorization/config.d.ts +19 -0
- package/dist/authorization/protectPermission.d.ts +52 -0
- package/dist/cli/migrate.js.map +1 -1
- package/dist/compliance/cipher.d.ts +11 -0
- package/dist/compliance/config.d.ts +18 -0
- package/dist/compliance/redaction.d.ts +8 -0
- package/dist/compliance/routes.d.ts +89 -0
- package/dist/constants.d.ts +10 -0
- package/dist/credentials/backgroundOps.d.ts +45 -0
- package/dist/credentials/config.d.ts +68 -0
- package/dist/credentials/emailValidation.d.ts +9 -0
- package/dist/credentials/emailVerification.d.ts +83 -0
- package/dist/credentials/import.d.ts +34 -0
- package/dist/credentials/inMemoryCredentialStore.d.ts +2 -0
- package/dist/credentials/legacyHashers.d.ts +3 -0
- package/dist/credentials/login.d.ts +76 -0
- package/dist/credentials/passwordPolicy.d.ts +15 -0
- package/dist/credentials/passwordReset.d.ts +87 -0
- package/dist/credentials/postgresCredentialStore.d.ts +235 -0
- package/dist/credentials/register.d.ts +54 -0
- package/dist/credentials/routes.d.ts +201 -0
- package/dist/credentials/types.d.ts +26 -0
- package/dist/crypto.d.ts +32 -0
- package/dist/errors.d.ts +12 -0
- package/dist/federation/tokenStore.d.ts +29 -0
- package/dist/htmx/configuredRoutes.d.ts +542 -0
- package/dist/htmx/renderers.d.ts +8 -0
- package/dist/htmx/routes.d.ts +514 -0
- package/dist/htmx/types.d.ts +129 -0
- package/dist/index.js +31 -1
- package/dist/index.js.map +4 -4
- package/dist/linkedProviders/inMemoryStores.d.ts +9 -0
- package/dist/linkedProviders/neonStores.d.ts +484 -0
- package/dist/linkedProviders/oauthAccountResolver.d.ts +28 -0
- package/dist/linkedProviders/oauthResolver.d.ts +9 -0
- package/dist/linkedProviders/resolver.d.ts +22 -0
- package/dist/lockout/config.d.ts +17 -0
- package/dist/lockout/inMemoryLockoutStore.d.ts +2 -0
- package/dist/lockout/postgresLockoutStore.d.ts +71 -0
- package/dist/lockout/redisLockoutStore.d.ts +3 -0
- package/dist/lockout/types.d.ts +12 -0
- package/dist/mfa/backupCodes.d.ts +5 -0
- package/dist/mfa/challenge.d.ts +70 -0
- package/dist/mfa/config.d.ts +50 -0
- package/dist/mfa/gate.d.ts +2 -0
- package/dist/mfa/inMemoryMfaStore.d.ts +2 -0
- package/dist/mfa/management.d.ts +106 -0
- package/dist/mfa/postgresMfaStore.d.ts +206 -0
- package/dist/mfa/rotation.d.ts +17 -0
- package/dist/mfa/routes.d.ts +234 -0
- package/dist/mfa/secret.d.ts +2 -0
- package/dist/mfa/sms.d.ts +105 -0
- package/dist/mfa/totp.d.ts +91 -0
- package/dist/mfa/types.d.ts +23 -0
- package/dist/oidc/clientAuth.d.ts +19 -0
- package/dist/oidc/config.d.ts +296 -0
- package/dist/oidc/dpop.d.ts +23 -0
- package/dist/oidc/inMemoryVciStores.d.ts +3 -0
- package/dist/oidc/index.js +11 -1
- package/dist/oidc/index.js.map +3 -3
- package/dist/oidc/jar.d.ts +14 -0
- package/dist/oidc/keys.d.ts +35 -0
- package/dist/oidc/logout.d.ts +38 -0
- package/dist/oidc/mtls.d.ts +11 -0
- package/dist/oidc/par.d.ts +28 -0
- package/dist/oidc/registration.d.ts +138 -0
- package/dist/oidc/routes.d.ts +569 -0
- package/dist/oidc/types.d.ts +148 -0
- package/dist/oidc/userinfo.d.ts +21 -0
- package/dist/oidc/vci.d.ts +159 -0
- package/dist/oidc/vciRoutes.d.ts +92 -0
- package/dist/organizations/config.d.ts +46 -0
- package/dist/organizations/operations.d.ts +39 -0
- package/dist/organizations/routes.d.ts +299 -0
- package/dist/organizations/types.d.ts +45 -0
- package/dist/passwordless/config.d.ts +43 -0
- package/dist/passwordless/routes.d.ts +163 -0
- package/dist/passwordless/types.d.ts +9 -0
- package/dist/pluginIdentity.d.ts +2 -0
- package/dist/portal/config.d.ts +34 -0
- package/dist/portal/operations.d.ts +10 -0
- package/dist/portal/routes.d.ts +160 -0
- package/dist/portal/types.d.ts +16 -0
- package/dist/providers/clients.d.ts +1818 -0
- package/dist/providersFromEnv.d.ts +19 -0
- package/dist/roles/config.d.ts +27 -0
- package/dist/roles/operations.d.ts +8 -0
- package/dist/roles/routes.d.ts +106 -0
- package/dist/roles/types.d.ts +14 -0
- package/dist/routes/authorize.d.ts +102 -0
- package/dist/routes/callback.d.ts +64 -0
- package/dist/routes/profile.d.ts +70 -0
- package/dist/routes/protectRoute.d.ts +51 -0
- package/dist/routes/refresh.d.ts +74 -0
- package/dist/routes/revoke.d.ts +73 -0
- package/dist/routes/sessions.d.ts +103 -0
- package/dist/routes/signout.d.ts +70 -0
- package/dist/routes/stepUp.d.ts +48 -0
- package/dist/routes/userStatus.d.ts +72 -0
- package/dist/scim/config.d.ts +57 -0
- package/dist/scim/extensions.d.ts +30 -0
- package/dist/scim/inMemoryScimTokenStore.d.ts +2 -0
- package/dist/scim/routes.d.ts +366 -0
- package/dist/scim/serialize.d.ts +83 -0
- package/dist/scim/types.d.ts +54 -0
- package/dist/server.js +31 -1
- package/dist/server.js.map +4 -4
- package/dist/session/access.d.ts +33 -0
- package/dist/session/anonymous.d.ts +12 -0
- package/dist/session/cleanup.d.ts +45 -0
- package/dist/session/impersonation.d.ts +34 -0
- package/dist/session/inMemoryStore.d.ts +7 -0
- package/dist/session/multiSession.d.ts +27 -0
- package/dist/session/neonStore.d.ts +513 -0
- package/dist/session/promote.d.ts +23 -0
- package/dist/session/redisStore.d.ts +6 -0
- package/dist/session/sessionsConfig.d.ts +9 -0
- package/dist/session/state.d.ts +33 -0
- package/dist/session/types.d.ts +21 -0
- package/dist/session/userSessions.d.ts +19 -0
- package/dist/sso/config.d.ts +149 -0
- package/dist/sso/discoveryRoute.d.ts +63 -0
- package/dist/sso/oidcRoutes.d.ts +98 -0
- package/dist/sso/samlRoutes.d.ts +179 -0
- package/dist/sso/types.d.ts +53 -0
- package/dist/stores/postgres.d.ts +5 -0
- package/dist/stores/redis.d.ts +5 -0
- package/dist/telemetry/tracing.d.ts +15 -0
- package/dist/tenancy.d.ts +9 -0
- package/dist/typeGuards.d.ts +6 -0
- package/dist/typebox.d.ts +4 -0
- package/dist/types.d.ts +421 -0
- package/dist/utils.d.ts +45 -0
- package/dist/vault/config.d.ts +20 -0
- package/dist/vault/inMemoryVaultStore.d.ts +2 -0
- package/dist/vault/postgresVaultStore.d.ts +86 -0
- package/dist/vault/types.d.ts +14 -0
- package/dist/vc/inMemoryVpStores.d.ts +2 -0
- package/dist/vc/openid4vp.d.ts +82 -0
- package/dist/vc/postgresVcStores.d.ts +300 -0
- package/dist/vc/sdJwt.d.ts +37 -0
- package/dist/vc/statusList.d.ts +29 -0
- package/dist/vc/statusListRoutes.d.ts +63 -0
- package/dist/vc/vpRoutes.d.ts +120 -0
- package/dist/webauthn/adapter.d.ts +59 -0
- package/dist/webauthn/config.d.ts +36 -0
- package/dist/webauthn/routes.d.ts +155 -0
- package/dist/webauthn/types.d.ts +17 -0
- package/dist/webhooks/config.d.ts +34 -0
- package/dist/webhooks/dispatcher.d.ts +3 -0
- package/dist/webhooks/sign.d.ts +11 -0
- package/dist/webhooks/types.d.ts +25 -0
- package/package.json +3 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { OidcProviderConfig } from './config';
|
|
2
|
+
export type UserInfoResult = {
|
|
3
|
+
body: Record<string, unknown> & {
|
|
4
|
+
sub: string;
|
|
5
|
+
};
|
|
6
|
+
ok: true;
|
|
7
|
+
} | {
|
|
8
|
+
body: {
|
|
9
|
+
error: string;
|
|
10
|
+
error_description?: string;
|
|
11
|
+
};
|
|
12
|
+
error: 'invalid_request' | 'invalid_token';
|
|
13
|
+
ok: false;
|
|
14
|
+
};
|
|
15
|
+
export declare const readUserInfoBearer: (authorization: string | undefined) => string | undefined;
|
|
16
|
+
export declare const fetchUserInfo: <UserType>({ config, now, token }: {
|
|
17
|
+
config: OidcProviderConfig<UserType>;
|
|
18
|
+
now?: number;
|
|
19
|
+
token: string | undefined;
|
|
20
|
+
}) => Promise<UserInfoResult>;
|
|
21
|
+
export declare const userInfoChallengeHeader: (error: "invalid_request" | "invalid_token") => string;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { RouteString } from '../types';
|
|
2
|
+
import { type SigningKey } from './keys';
|
|
3
|
+
export declare const PRE_AUTHORIZED_CODE_GRANT = "urn:ietf:params:oauth:grant-type:pre-authorized_code";
|
|
4
|
+
export type CredentialConfiguration = {
|
|
5
|
+
format: 'vc+sd-jwt';
|
|
6
|
+
id: string;
|
|
7
|
+
display?: Array<{
|
|
8
|
+
locale?: string;
|
|
9
|
+
name: string;
|
|
10
|
+
}>;
|
|
11
|
+
order?: string[];
|
|
12
|
+
claims?: Record<string, {
|
|
13
|
+
display?: Array<{
|
|
14
|
+
locale?: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}>;
|
|
17
|
+
}>;
|
|
18
|
+
vct: string;
|
|
19
|
+
};
|
|
20
|
+
export type CredentialOffer = {
|
|
21
|
+
clientId: string;
|
|
22
|
+
configurationId: string;
|
|
23
|
+
createdAt: number;
|
|
24
|
+
expiresAt: number;
|
|
25
|
+
preAuthorizedCodeHash: string;
|
|
26
|
+
redeemed: boolean;
|
|
27
|
+
userId: string;
|
|
28
|
+
};
|
|
29
|
+
export type CredentialOfferStore = {
|
|
30
|
+
consumeOffer: (preAuthorizedCodeHash: string) => Promise<CredentialOffer | undefined>;
|
|
31
|
+
saveOffer: (offer: CredentialOffer) => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
export type CredentialNonceRecord = {
|
|
34
|
+
expiresAt: number;
|
|
35
|
+
nonceHash: string;
|
|
36
|
+
};
|
|
37
|
+
export type CredentialNonceStore = {
|
|
38
|
+
consumeNonce: (nonceHash: string) => Promise<CredentialNonceRecord | undefined>;
|
|
39
|
+
saveNonce: (record: CredentialNonceRecord) => Promise<void>;
|
|
40
|
+
};
|
|
41
|
+
export type VciConfig = {
|
|
42
|
+
accessTokenTtlMs?: number;
|
|
43
|
+
credentialConfigurations: CredentialConfiguration[];
|
|
44
|
+
credentialNonceStore?: CredentialNonceStore;
|
|
45
|
+
credentialOfferStore: CredentialOfferStore;
|
|
46
|
+
nonceTtlMs?: number;
|
|
47
|
+
offerTtlMs?: number;
|
|
48
|
+
resolveCredentialClaims: (context: {
|
|
49
|
+
configurationId: string;
|
|
50
|
+
userId: string;
|
|
51
|
+
}) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
52
|
+
resolveProtectedClaims?: (context: {
|
|
53
|
+
configurationId: string;
|
|
54
|
+
userId: string;
|
|
55
|
+
}) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
56
|
+
signingKey?: SigningKey;
|
|
57
|
+
vciRoute?: RouteString;
|
|
58
|
+
};
|
|
59
|
+
export declare const DEFAULT_VCI_ROUTE: RouteString;
|
|
60
|
+
export declare const createCredentialOffer: ({ clientId, configurationId, now, store, ttlMs, userId }: {
|
|
61
|
+
clientId: string;
|
|
62
|
+
configurationId: string;
|
|
63
|
+
now?: number;
|
|
64
|
+
store: CredentialOfferStore;
|
|
65
|
+
ttlMs?: number;
|
|
66
|
+
userId: string;
|
|
67
|
+
}) => Promise<{
|
|
68
|
+
offer: CredentialOffer;
|
|
69
|
+
preAuthorizedCode: string;
|
|
70
|
+
}>;
|
|
71
|
+
export type PreAuthExchangeResult = {
|
|
72
|
+
error: 'expired_token' | 'invalid_grant';
|
|
73
|
+
ok: false;
|
|
74
|
+
} | {
|
|
75
|
+
access_token: string;
|
|
76
|
+
c_nonce?: string;
|
|
77
|
+
c_nonce_expires_in?: number;
|
|
78
|
+
expires_in: number;
|
|
79
|
+
ok: true;
|
|
80
|
+
token_type: 'Bearer';
|
|
81
|
+
};
|
|
82
|
+
export declare const exchangePreAuthorizedCode: ({ config, issuer, now, preAuthorizedCode, signingKey }: {
|
|
83
|
+
config: VciConfig;
|
|
84
|
+
issuer: string;
|
|
85
|
+
now?: number;
|
|
86
|
+
preAuthorizedCode: string;
|
|
87
|
+
signingKey: SigningKey;
|
|
88
|
+
}) => Promise<{
|
|
89
|
+
error: "expired_token" | "invalid_grant";
|
|
90
|
+
ok: false;
|
|
91
|
+
} | {
|
|
92
|
+
access_token: string;
|
|
93
|
+
c_nonce?: string;
|
|
94
|
+
c_nonce_expires_in?: number;
|
|
95
|
+
expires_in: number;
|
|
96
|
+
ok: true;
|
|
97
|
+
token_type: "Bearer";
|
|
98
|
+
}>;
|
|
99
|
+
export type CredentialIssueInput = {
|
|
100
|
+
accessToken: string;
|
|
101
|
+
proofJwt?: string;
|
|
102
|
+
requestedFormat?: 'vc+sd-jwt';
|
|
103
|
+
};
|
|
104
|
+
export type CredentialIssueResult = {
|
|
105
|
+
credential: string;
|
|
106
|
+
format: 'vc+sd-jwt';
|
|
107
|
+
ok: true;
|
|
108
|
+
} | {
|
|
109
|
+
error: 'invalid_credential_request' | 'invalid_proof' | 'invalid_token' | 'unsupported_credential_format';
|
|
110
|
+
ok: false;
|
|
111
|
+
};
|
|
112
|
+
export declare const buildIssuerMetadata: ({ config, issuer, vciRoute }: {
|
|
113
|
+
config: VciConfig;
|
|
114
|
+
issuer: string;
|
|
115
|
+
vciRoute: RouteString;
|
|
116
|
+
}) => {
|
|
117
|
+
credential_configurations_supported: {
|
|
118
|
+
[k: string]: {
|
|
119
|
+
claims: Record<string, {
|
|
120
|
+
display?: Array<{
|
|
121
|
+
locale?: string;
|
|
122
|
+
name: string;
|
|
123
|
+
}>;
|
|
124
|
+
}> | undefined;
|
|
125
|
+
credential_signing_alg_values_supported: string[];
|
|
126
|
+
cryptographic_binding_methods_supported: string[];
|
|
127
|
+
display: {
|
|
128
|
+
locale?: string;
|
|
129
|
+
name: string;
|
|
130
|
+
}[] | undefined;
|
|
131
|
+
format: "vc+sd-jwt";
|
|
132
|
+
order: string[] | undefined;
|
|
133
|
+
proof_types_supported: {
|
|
134
|
+
jwt: {
|
|
135
|
+
proof_signing_alg_values_supported: string[];
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
vct: string;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
credential_endpoint: string;
|
|
142
|
+
credential_issuer: string;
|
|
143
|
+
nonce_endpoint: string | undefined;
|
|
144
|
+
token_endpoint: string;
|
|
145
|
+
};
|
|
146
|
+
export declare const issueCredential: ({ config, input, issuer, now, signingKey }: {
|
|
147
|
+
config: VciConfig;
|
|
148
|
+
input: CredentialIssueInput;
|
|
149
|
+
issuer: string;
|
|
150
|
+
now?: number;
|
|
151
|
+
signingKey: SigningKey;
|
|
152
|
+
}) => Promise<{
|
|
153
|
+
credential: string;
|
|
154
|
+
format: "vc+sd-jwt";
|
|
155
|
+
ok: true;
|
|
156
|
+
} | {
|
|
157
|
+
error: "invalid_credential_request" | "invalid_proof" | "invalid_token" | "unsupported_credential_format";
|
|
158
|
+
ok: false;
|
|
159
|
+
}>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Elysia } from 'elysia';
|
|
2
|
+
import type { SigningKey } from './keys';
|
|
3
|
+
import { type VciConfig } from './vci';
|
|
4
|
+
export declare const vciRoutes: ({ issuerUrl, signingKey, vciConfig }: {
|
|
5
|
+
issuerUrl: string;
|
|
6
|
+
signingKey: SigningKey;
|
|
7
|
+
vciConfig: VciConfig;
|
|
8
|
+
}) => Elysia<"", {
|
|
9
|
+
decorator: {};
|
|
10
|
+
store: {};
|
|
11
|
+
derive: {};
|
|
12
|
+
resolve: {};
|
|
13
|
+
}, {
|
|
14
|
+
typebox: {};
|
|
15
|
+
error: {};
|
|
16
|
+
}, {
|
|
17
|
+
schema: {};
|
|
18
|
+
standaloneSchema: {};
|
|
19
|
+
macro: {};
|
|
20
|
+
macroFn: {};
|
|
21
|
+
parser: {};
|
|
22
|
+
response: {};
|
|
23
|
+
}, {
|
|
24
|
+
".well-known": {
|
|
25
|
+
"openid-credential-issuer": {
|
|
26
|
+
get: {
|
|
27
|
+
body: unknown;
|
|
28
|
+
params: {};
|
|
29
|
+
query: unknown;
|
|
30
|
+
headers: unknown;
|
|
31
|
+
response: {
|
|
32
|
+
200: Response;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
} & {
|
|
38
|
+
[x: string]: {
|
|
39
|
+
credential: {
|
|
40
|
+
post: {
|
|
41
|
+
body: {
|
|
42
|
+
format?: "vc+sd-jwt" | undefined;
|
|
43
|
+
proof?: {
|
|
44
|
+
jwt: string;
|
|
45
|
+
proof_type: "jwt";
|
|
46
|
+
} | undefined;
|
|
47
|
+
};
|
|
48
|
+
params: {};
|
|
49
|
+
query: unknown;
|
|
50
|
+
headers: unknown;
|
|
51
|
+
response: {
|
|
52
|
+
200: Response;
|
|
53
|
+
422: {
|
|
54
|
+
type: "validation";
|
|
55
|
+
on: string;
|
|
56
|
+
summary?: string;
|
|
57
|
+
message?: string;
|
|
58
|
+
found?: unknown;
|
|
59
|
+
property?: string;
|
|
60
|
+
expected?: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
} & {
|
|
67
|
+
[x: string]: {
|
|
68
|
+
nonce: {
|
|
69
|
+
post: {
|
|
70
|
+
body: unknown;
|
|
71
|
+
params: {};
|
|
72
|
+
query: unknown;
|
|
73
|
+
headers: unknown;
|
|
74
|
+
response: {
|
|
75
|
+
200: Response;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
}, {
|
|
81
|
+
derive: {};
|
|
82
|
+
resolve: {};
|
|
83
|
+
schema: {};
|
|
84
|
+
standaloneSchema: {};
|
|
85
|
+
response: {};
|
|
86
|
+
}, {
|
|
87
|
+
derive: {};
|
|
88
|
+
resolve: {};
|
|
89
|
+
schema: {};
|
|
90
|
+
standaloneSchema: {};
|
|
91
|
+
response: {};
|
|
92
|
+
}>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AuditEmitter } from '../audit/config';
|
|
2
|
+
import type { AuthSessionStore } from '../session/types';
|
|
3
|
+
import type { OrganizationId } from '../tenancy';
|
|
4
|
+
import type { RouteString } from '../types';
|
|
5
|
+
import type { OrganizationMembership, OrganizationStore } from './types';
|
|
6
|
+
export declare const DEFAULT_INVITATION_TTL_MS: number;
|
|
7
|
+
export declare const DEFAULT_ORGANIZATIONS_ROUTE: RouteString;
|
|
8
|
+
export declare const DEFAULT_OWNER_ROLES: string[];
|
|
9
|
+
export type OrganizationInvitationMessage = {
|
|
10
|
+
email: string;
|
|
11
|
+
expiresAt: number;
|
|
12
|
+
inviterUserId?: string;
|
|
13
|
+
organizationId: OrganizationId;
|
|
14
|
+
token: string;
|
|
15
|
+
};
|
|
16
|
+
export type OrganizationsConfig<UserType> = {
|
|
17
|
+
getUserId: (user: UserType) => string;
|
|
18
|
+
organizationStore: OrganizationStore;
|
|
19
|
+
canCreateOrganization?: (user: UserType) => boolean | Promise<boolean>;
|
|
20
|
+
canManageMembers?: (context: {
|
|
21
|
+
membership?: OrganizationMembership;
|
|
22
|
+
organizationId: OrganizationId;
|
|
23
|
+
user: UserType;
|
|
24
|
+
}) => boolean | Promise<boolean>;
|
|
25
|
+
invitationDurationMs?: number;
|
|
26
|
+
onMembershipAdded?: (context: {
|
|
27
|
+
organizationId: OrganizationId;
|
|
28
|
+
roles: string[];
|
|
29
|
+
userId: string;
|
|
30
|
+
}) => void | Promise<void>;
|
|
31
|
+
onMembershipRemoved?: (context: {
|
|
32
|
+
organizationId: OrganizationId;
|
|
33
|
+
userId: string;
|
|
34
|
+
}) => void | Promise<void>;
|
|
35
|
+
onOrganizationCreated?: (context: {
|
|
36
|
+
organizationId: OrganizationId;
|
|
37
|
+
ownerUserId: string;
|
|
38
|
+
}) => void | Promise<void>;
|
|
39
|
+
onSendInvitation?: (message: OrganizationInvitationMessage) => void | Promise<void>;
|
|
40
|
+
organizationsRoute?: RouteString;
|
|
41
|
+
ownerRoles?: string[];
|
|
42
|
+
};
|
|
43
|
+
export type OrganizationsRouteProps<UserType> = OrganizationsConfig<UserType> & {
|
|
44
|
+
authSessionStore?: AuthSessionStore<UserType>;
|
|
45
|
+
emit?: AuditEmitter;
|
|
46
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { OrganizationId } from '../tenancy';
|
|
2
|
+
import type { Organization, OrganizationInvitation, OrganizationMembership, OrganizationStore } from './types';
|
|
3
|
+
export declare const acceptInvitation: ({ organizationStore, token, userId }: {
|
|
4
|
+
organizationStore: OrganizationStore;
|
|
5
|
+
token: string;
|
|
6
|
+
userId: string;
|
|
7
|
+
}) => Promise<OrganizationMembership | undefined>;
|
|
8
|
+
export declare const autoAssignOrgsByEmail: ({ email, getOrgsForDomain, organizationStore, roles, userId }: {
|
|
9
|
+
email: string;
|
|
10
|
+
getOrgsForDomain: (domain: string) => Promise<OrganizationId[]> | OrganizationId[];
|
|
11
|
+
organizationStore: OrganizationStore;
|
|
12
|
+
roles?: string[];
|
|
13
|
+
userId: string;
|
|
14
|
+
}) => Promise<string[]>;
|
|
15
|
+
export declare const createOrganization: ({ metadata, name, organizationStore, ownerRoles, ownerUserId }: {
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
name: string;
|
|
18
|
+
organizationStore: OrganizationStore;
|
|
19
|
+
ownerRoles?: string[];
|
|
20
|
+
ownerUserId: string;
|
|
21
|
+
}) => Promise<Organization>;
|
|
22
|
+
export declare const inviteToOrganization: ({ email, invitationDurationMs, inviterUserId, organizationId, organizationStore, roles }: {
|
|
23
|
+
email: string;
|
|
24
|
+
invitationDurationMs?: number;
|
|
25
|
+
inviterUserId?: string;
|
|
26
|
+
organizationId: OrganizationId;
|
|
27
|
+
organizationStore: OrganizationStore;
|
|
28
|
+
roles?: string[];
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
invitation: OrganizationInvitation;
|
|
31
|
+
token: string;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const listUserOrganizations: ({ organizationStore, userId }: {
|
|
34
|
+
organizationStore: OrganizationStore;
|
|
35
|
+
userId: string;
|
|
36
|
+
}) => Promise<{
|
|
37
|
+
membership: OrganizationMembership;
|
|
38
|
+
organization: Organization | undefined;
|
|
39
|
+
}[]>;
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { Elysia } from 'elysia';
|
|
2
|
+
import type { SessionRecord } from '../types';
|
|
3
|
+
import { type OrganizationsRouteProps } from './config';
|
|
4
|
+
export declare const organizationRoutes: <UserType>({ authSessionStore, canCreateOrganization, canManageMembers, emit, getUserId, invitationDurationMs, onMembershipAdded, onMembershipRemoved, onOrganizationCreated, onSendInvitation, organizationsRoute, organizationStore, ownerRoles }: OrganizationsRouteProps<UserType>) => Elysia<"", {
|
|
5
|
+
decorator: {};
|
|
6
|
+
store: {
|
|
7
|
+
session: SessionRecord<UserType>;
|
|
8
|
+
unregisteredSession: import("..").UnregisteredSessionRecord;
|
|
9
|
+
};
|
|
10
|
+
derive: {};
|
|
11
|
+
resolve: {};
|
|
12
|
+
}, {
|
|
13
|
+
typebox: {};
|
|
14
|
+
error: {};
|
|
15
|
+
}, {
|
|
16
|
+
schema: {};
|
|
17
|
+
standaloneSchema: {};
|
|
18
|
+
macro: {};
|
|
19
|
+
macroFn: {};
|
|
20
|
+
parser: {};
|
|
21
|
+
response: {};
|
|
22
|
+
}, {
|
|
23
|
+
[x: string]: {
|
|
24
|
+
get: {
|
|
25
|
+
body: unknown;
|
|
26
|
+
params: {};
|
|
27
|
+
query: unknown;
|
|
28
|
+
headers: unknown;
|
|
29
|
+
response: {
|
|
30
|
+
401: "Authentication required";
|
|
31
|
+
200: {
|
|
32
|
+
readonly organizations: {
|
|
33
|
+
membership: import("./types").OrganizationMembership;
|
|
34
|
+
organization: import("./types").Organization | undefined;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
422: {
|
|
38
|
+
type: "validation";
|
|
39
|
+
on: string;
|
|
40
|
+
summary?: string;
|
|
41
|
+
message?: string;
|
|
42
|
+
found?: unknown;
|
|
43
|
+
property?: string;
|
|
44
|
+
expected?: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
} & {
|
|
50
|
+
[x: string]: {
|
|
51
|
+
post: {
|
|
52
|
+
body: {
|
|
53
|
+
metadata?: {} | undefined;
|
|
54
|
+
name: string;
|
|
55
|
+
};
|
|
56
|
+
params: {};
|
|
57
|
+
query: unknown;
|
|
58
|
+
headers: unknown;
|
|
59
|
+
response: {
|
|
60
|
+
401: "Authentication required";
|
|
61
|
+
403: "Cannot create organizations";
|
|
62
|
+
200: {
|
|
63
|
+
readonly organization: import("./types").Organization;
|
|
64
|
+
};
|
|
65
|
+
422: {
|
|
66
|
+
type: "validation";
|
|
67
|
+
on: string;
|
|
68
|
+
summary?: string;
|
|
69
|
+
message?: string;
|
|
70
|
+
found?: unknown;
|
|
71
|
+
property?: string;
|
|
72
|
+
expected?: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
} & {
|
|
78
|
+
[x: string]: {
|
|
79
|
+
":organizationId": {
|
|
80
|
+
invitations: {
|
|
81
|
+
post: {
|
|
82
|
+
body: {
|
|
83
|
+
roles?: string[] | undefined;
|
|
84
|
+
email: string;
|
|
85
|
+
};
|
|
86
|
+
params: {
|
|
87
|
+
organizationId: string;
|
|
88
|
+
};
|
|
89
|
+
query: unknown;
|
|
90
|
+
headers: unknown;
|
|
91
|
+
response: {
|
|
92
|
+
401: "Authentication required";
|
|
93
|
+
403: "Cannot manage members";
|
|
94
|
+
200: {
|
|
95
|
+
readonly invitationId: string;
|
|
96
|
+
readonly token: string;
|
|
97
|
+
};
|
|
98
|
+
422: {
|
|
99
|
+
type: "validation";
|
|
100
|
+
on: string;
|
|
101
|
+
summary?: string;
|
|
102
|
+
message?: string;
|
|
103
|
+
found?: unknown;
|
|
104
|
+
property?: string;
|
|
105
|
+
expected?: string;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
} & {
|
|
113
|
+
[x: string]: {
|
|
114
|
+
":organizationId": {
|
|
115
|
+
invitations: {
|
|
116
|
+
get: {
|
|
117
|
+
body: unknown;
|
|
118
|
+
params: {
|
|
119
|
+
organizationId: string;
|
|
120
|
+
};
|
|
121
|
+
query: unknown;
|
|
122
|
+
headers: unknown;
|
|
123
|
+
response: {
|
|
124
|
+
401: "Authentication required";
|
|
125
|
+
403: "Cannot manage members";
|
|
126
|
+
200: {
|
|
127
|
+
readonly invitations: {
|
|
128
|
+
email: string;
|
|
129
|
+
expiresAt: number;
|
|
130
|
+
invitationId: string;
|
|
131
|
+
roles: string[];
|
|
132
|
+
state: import("./types").InvitationState;
|
|
133
|
+
}[];
|
|
134
|
+
};
|
|
135
|
+
422: {
|
|
136
|
+
type: "validation";
|
|
137
|
+
on: string;
|
|
138
|
+
summary?: string;
|
|
139
|
+
message?: string;
|
|
140
|
+
found?: unknown;
|
|
141
|
+
property?: string;
|
|
142
|
+
expected?: string;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
} & {
|
|
150
|
+
[x: string]: {
|
|
151
|
+
":organizationId": {
|
|
152
|
+
invitations: {
|
|
153
|
+
":invitationId": {
|
|
154
|
+
delete: {
|
|
155
|
+
body: unknown;
|
|
156
|
+
params: {
|
|
157
|
+
organizationId: string;
|
|
158
|
+
invitationId: string;
|
|
159
|
+
};
|
|
160
|
+
query: unknown;
|
|
161
|
+
headers: unknown;
|
|
162
|
+
response: {
|
|
163
|
+
401: "Authentication required";
|
|
164
|
+
403: "Cannot manage members";
|
|
165
|
+
404: "Invitation not found";
|
|
166
|
+
200: {
|
|
167
|
+
readonly revoked: string;
|
|
168
|
+
};
|
|
169
|
+
422: {
|
|
170
|
+
type: "validation";
|
|
171
|
+
on: string;
|
|
172
|
+
summary?: string;
|
|
173
|
+
message?: string;
|
|
174
|
+
found?: unknown;
|
|
175
|
+
property?: string;
|
|
176
|
+
expected?: string;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
} & {
|
|
185
|
+
[x: string]: {
|
|
186
|
+
invitations: {
|
|
187
|
+
accept: {
|
|
188
|
+
post: {
|
|
189
|
+
body: {
|
|
190
|
+
token: string;
|
|
191
|
+
};
|
|
192
|
+
params: {};
|
|
193
|
+
query: unknown;
|
|
194
|
+
headers: unknown;
|
|
195
|
+
response: {
|
|
196
|
+
400: "Invalid or expired invitation";
|
|
197
|
+
401: "Authentication required";
|
|
198
|
+
200: {
|
|
199
|
+
readonly organizationId: string;
|
|
200
|
+
readonly roles: string[];
|
|
201
|
+
};
|
|
202
|
+
422: {
|
|
203
|
+
type: "validation";
|
|
204
|
+
on: string;
|
|
205
|
+
summary?: string;
|
|
206
|
+
message?: string;
|
|
207
|
+
found?: unknown;
|
|
208
|
+
property?: string;
|
|
209
|
+
expected?: string;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
} & {
|
|
217
|
+
[x: string]: {
|
|
218
|
+
":organizationId": {
|
|
219
|
+
members: {
|
|
220
|
+
get: {
|
|
221
|
+
body: unknown;
|
|
222
|
+
params: {
|
|
223
|
+
organizationId: string;
|
|
224
|
+
};
|
|
225
|
+
query: unknown;
|
|
226
|
+
headers: unknown;
|
|
227
|
+
response: {
|
|
228
|
+
401: "Authentication required";
|
|
229
|
+
403: "Not a member";
|
|
230
|
+
200: {
|
|
231
|
+
readonly members: import("./types").OrganizationMembership[];
|
|
232
|
+
};
|
|
233
|
+
422: {
|
|
234
|
+
type: "validation";
|
|
235
|
+
on: string;
|
|
236
|
+
summary?: string;
|
|
237
|
+
message?: string;
|
|
238
|
+
found?: unknown;
|
|
239
|
+
property?: string;
|
|
240
|
+
expected?: string;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
} & {
|
|
248
|
+
[x: string]: {
|
|
249
|
+
":organizationId": {
|
|
250
|
+
members: {
|
|
251
|
+
":userId": {
|
|
252
|
+
delete: {
|
|
253
|
+
body: unknown;
|
|
254
|
+
params: {
|
|
255
|
+
userId: string;
|
|
256
|
+
organizationId: string;
|
|
257
|
+
};
|
|
258
|
+
query: unknown;
|
|
259
|
+
headers: unknown;
|
|
260
|
+
response: {
|
|
261
|
+
401: "Authentication required";
|
|
262
|
+
403: "Cannot manage members";
|
|
263
|
+
200: {
|
|
264
|
+
readonly removed: string;
|
|
265
|
+
};
|
|
266
|
+
422: {
|
|
267
|
+
type: "validation";
|
|
268
|
+
on: string;
|
|
269
|
+
summary?: string;
|
|
270
|
+
message?: string;
|
|
271
|
+
found?: unknown;
|
|
272
|
+
property?: string;
|
|
273
|
+
expected?: string;
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
}, {
|
|
282
|
+
derive: {};
|
|
283
|
+
resolve: {};
|
|
284
|
+
schema: {};
|
|
285
|
+
standaloneSchema: {};
|
|
286
|
+
response: {};
|
|
287
|
+
}, {
|
|
288
|
+
derive: {};
|
|
289
|
+
resolve: {};
|
|
290
|
+
schema: {};
|
|
291
|
+
standaloneSchema: {};
|
|
292
|
+
response: {};
|
|
293
|
+
} & {
|
|
294
|
+
derive: {};
|
|
295
|
+
resolve: {};
|
|
296
|
+
schema: {};
|
|
297
|
+
standaloneSchema: {};
|
|
298
|
+
response: {};
|
|
299
|
+
}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { OrganizationId } from '../tenancy';
|
|
2
|
+
export type Organization = {
|
|
3
|
+
createdAt: number;
|
|
4
|
+
metadata?: Record<string, unknown>;
|
|
5
|
+
name: string;
|
|
6
|
+
organizationId: OrganizationId;
|
|
7
|
+
updatedAt: number;
|
|
8
|
+
};
|
|
9
|
+
export type MembershipStatus = 'active' | 'suspended';
|
|
10
|
+
export type OrganizationMembership = {
|
|
11
|
+
createdAt: number;
|
|
12
|
+
organizationId: OrganizationId;
|
|
13
|
+
roles: string[];
|
|
14
|
+
status: MembershipStatus;
|
|
15
|
+
updatedAt: number;
|
|
16
|
+
userId: string;
|
|
17
|
+
};
|
|
18
|
+
export type InvitationState = 'accepted' | 'pending' | 'revoked';
|
|
19
|
+
export type OrganizationInvitation = {
|
|
20
|
+
acceptedAt?: number;
|
|
21
|
+
createdAt: number;
|
|
22
|
+
email: string;
|
|
23
|
+
expiresAt: number;
|
|
24
|
+
invitationId: string;
|
|
25
|
+
inviterUserId?: string;
|
|
26
|
+
organizationId: OrganizationId;
|
|
27
|
+
roles: string[];
|
|
28
|
+
state: InvitationState;
|
|
29
|
+
tokenHash: string;
|
|
30
|
+
};
|
|
31
|
+
export type OrganizationStore = {
|
|
32
|
+
deleteOrganization: (organizationId: OrganizationId) => Promise<void>;
|
|
33
|
+
getInvitation: (invitationId: string) => Promise<OrganizationInvitation | undefined>;
|
|
34
|
+
getInvitationByTokenHash: (tokenHash: string) => Promise<OrganizationInvitation | undefined>;
|
|
35
|
+
getMembership: (organizationId: OrganizationId, userId: string) => Promise<OrganizationMembership | undefined>;
|
|
36
|
+
getOrganization: (organizationId: OrganizationId) => Promise<Organization | undefined>;
|
|
37
|
+
listInvitationsByOrganization: (organizationId: OrganizationId) => Promise<OrganizationInvitation[]>;
|
|
38
|
+
listMembershipsByOrganization: (organizationId: OrganizationId) => Promise<OrganizationMembership[]>;
|
|
39
|
+
listMembershipsByUser: (userId: string) => Promise<OrganizationMembership[]>;
|
|
40
|
+
listOrganizations: () => Promise<Organization[]>;
|
|
41
|
+
removeMembership: (organizationId: OrganizationId, userId: string) => Promise<void>;
|
|
42
|
+
saveInvitation: (invitation: OrganizationInvitation) => Promise<void>;
|
|
43
|
+
saveMembership: (membership: OrganizationMembership) => Promise<void>;
|
|
44
|
+
saveOrganization: (organization: Organization) => Promise<void>;
|
|
45
|
+
};
|