@effect-auth/core 0.1.0-alpha.3 → 0.1.0-alpha.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.
Files changed (158) hide show
  1. package/README.md +148 -13
  2. package/dist/ApiKey.d.ts +207 -0
  3. package/dist/ApiKey.d.ts.map +1 -0
  4. package/dist/ApiKey.js +275 -0
  5. package/dist/ApiKey.js.map +1 -0
  6. package/dist/AuditLog.d.ts +204 -1
  7. package/dist/AuditLog.d.ts.map +1 -1
  8. package/dist/AuditLog.js +170 -0
  9. package/dist/AuditLog.js.map +1 -1
  10. package/dist/AuthConfig.d.ts +0 -9
  11. package/dist/AuthConfig.d.ts.map +1 -1
  12. package/dist/AuthConfig.js +1 -14
  13. package/dist/AuthConfig.js.map +1 -1
  14. package/dist/AuthFlow.d.ts +220 -51
  15. package/dist/AuthFlow.d.ts.map +1 -1
  16. package/dist/AuthFlow.js +550 -22
  17. package/dist/AuthFlow.js.map +1 -1
  18. package/dist/AuthKernel.d.ts +1 -1
  19. package/dist/Challenge.d.ts +5 -1
  20. package/dist/Challenge.d.ts.map +1 -1
  21. package/dist/Challenge.js +58 -48
  22. package/dist/Challenge.js.map +1 -1
  23. package/dist/Client.d.ts +263 -1
  24. package/dist/Client.d.ts.map +1 -1
  25. package/dist/Client.js +533 -1
  26. package/dist/Client.js.map +1 -1
  27. package/dist/D1Kysely.d.ts +1 -1
  28. package/dist/D1Kysely.d.ts.map +1 -1
  29. package/dist/EffectQbSqliteStorage.d.ts +115 -3
  30. package/dist/EffectQbSqliteStorage.d.ts.map +1 -1
  31. package/dist/EffectQbSqliteStorage.js +314 -4
  32. package/dist/EffectQbSqliteStorage.js.map +1 -1
  33. package/dist/EmailOtp.d.ts +5 -2
  34. package/dist/EmailOtp.d.ts.map +1 -1
  35. package/dist/EmailOtp.js +11 -4
  36. package/dist/EmailOtp.js.map +1 -1
  37. package/dist/EmailVerification.d.ts +2 -2
  38. package/dist/EmailVerification.d.ts.map +1 -1
  39. package/dist/EmailVerification.js +2 -3
  40. package/dist/EmailVerification.js.map +1 -1
  41. package/dist/HttpApi/Api.d.ts +1363 -19
  42. package/dist/HttpApi/Api.d.ts.map +1 -1
  43. package/dist/HttpApi/Api.js +1625 -20
  44. package/dist/HttpApi/Api.js.map +1 -1
  45. package/dist/HttpApi/Endpoints.d.ts +682 -0
  46. package/dist/HttpApi/Endpoints.d.ts.map +1 -1
  47. package/dist/HttpApi/Endpoints.js +252 -1
  48. package/dist/HttpApi/Endpoints.js.map +1 -1
  49. package/dist/HttpApi/Schemas.d.ts +841 -0
  50. package/dist/HttpApi/Schemas.d.ts.map +1 -1
  51. package/dist/HttpApi/Schemas.js +513 -1
  52. package/dist/HttpApi/Schemas.js.map +1 -1
  53. package/dist/HttpApi/Security.d.ts +13 -1
  54. package/dist/HttpApi/Security.d.ts.map +1 -1
  55. package/dist/HttpApi/Security.js +107 -16
  56. package/dist/HttpApi/Security.js.map +1 -1
  57. package/dist/HttpApi/Transport.d.ts +36 -2
  58. package/dist/HttpApi/Transport.d.ts.map +1 -1
  59. package/dist/HttpApi/Transport.js +151 -9
  60. package/dist/HttpApi/Transport.js.map +1 -1
  61. package/dist/Jwt.d.ts +271 -0
  62. package/dist/Jwt.d.ts.map +1 -0
  63. package/dist/Jwt.js +512 -0
  64. package/dist/Jwt.js.map +1 -0
  65. package/dist/KyselyStorage.d.ts +151 -1
  66. package/dist/KyselyStorage.d.ts.map +1 -1
  67. package/dist/KyselyStorage.js +1021 -4
  68. package/dist/KyselyStorage.js.map +1 -1
  69. package/dist/LoginApproval.d.ts +314 -0
  70. package/dist/LoginApproval.d.ts.map +1 -0
  71. package/dist/LoginApproval.js +551 -0
  72. package/dist/LoginApproval.js.map +1 -0
  73. package/dist/LoginNotification.d.ts +183 -0
  74. package/dist/LoginNotification.d.ts.map +1 -0
  75. package/dist/LoginNotification.js +329 -0
  76. package/dist/LoginNotification.js.map +1 -0
  77. package/dist/LoginRisk.d.ts +73 -0
  78. package/dist/LoginRisk.d.ts.map +1 -0
  79. package/dist/LoginRisk.js +57 -0
  80. package/dist/LoginRisk.js.map +1 -0
  81. package/dist/MagicLink.d.ts +85 -0
  82. package/dist/MagicLink.d.ts.map +1 -0
  83. package/dist/MagicLink.js +206 -0
  84. package/dist/MagicLink.js.map +1 -0
  85. package/dist/Mailer.d.ts +33 -2
  86. package/dist/Mailer.d.ts.map +1 -1
  87. package/dist/Mailer.js +107 -0
  88. package/dist/Mailer.js.map +1 -1
  89. package/dist/OAuth.d.ts +742 -0
  90. package/dist/OAuth.d.ts.map +1 -0
  91. package/dist/OAuth.js +1387 -0
  92. package/dist/OAuth.js.map +1 -0
  93. package/dist/Passkey.d.ts +334 -0
  94. package/dist/Passkey.d.ts.map +1 -0
  95. package/dist/Passkey.js +422 -0
  96. package/dist/Passkey.js.map +1 -0
  97. package/dist/Password.d.ts +138 -8
  98. package/dist/Password.d.ts.map +1 -1
  99. package/dist/Password.js +397 -8
  100. package/dist/Password.js.map +1 -1
  101. package/dist/RecoveryCode.d.ts +169 -0
  102. package/dist/RecoveryCode.d.ts.map +1 -0
  103. package/dist/RecoveryCode.js +299 -0
  104. package/dist/RecoveryCode.js.map +1 -0
  105. package/dist/RefreshToken.d.ts +222 -0
  106. package/dist/RefreshToken.d.ts.map +1 -0
  107. package/dist/RefreshToken.js +342 -0
  108. package/dist/RefreshToken.js.map +1 -0
  109. package/dist/Sessions.d.ts +52 -2
  110. package/dist/Sessions.d.ts.map +1 -1
  111. package/dist/Sessions.js +123 -1
  112. package/dist/Sessions.js.map +1 -1
  113. package/dist/StepUp.d.ts +44 -0
  114. package/dist/StepUp.d.ts.map +1 -0
  115. package/dist/StepUp.js +82 -0
  116. package/dist/StepUp.js.map +1 -0
  117. package/dist/Storage.d.ts +14 -1
  118. package/dist/Storage.d.ts.map +1 -1
  119. package/dist/Storage.js.map +1 -1
  120. package/dist/StorageMigrations.d.ts +10 -1
  121. package/dist/StorageMigrations.d.ts.map +1 -1
  122. package/dist/StorageMigrations.js +179 -0
  123. package/dist/StorageMigrations.js.map +1 -1
  124. package/dist/Testing.d.ts +1 -1
  125. package/dist/Totp.d.ts +220 -0
  126. package/dist/Totp.d.ts.map +1 -0
  127. package/dist/Totp.js +477 -0
  128. package/dist/Totp.js.map +1 -0
  129. package/dist/TrustedDevice.d.ts +115 -0
  130. package/dist/TrustedDevice.d.ts.map +1 -0
  131. package/dist/TrustedDevice.js +222 -0
  132. package/dist/TrustedDevice.js.map +1 -0
  133. package/dist/Webhook.d.ts +72 -0
  134. package/dist/Webhook.d.ts.map +1 -0
  135. package/dist/Webhook.js +82 -0
  136. package/dist/Webhook.js.map +1 -0
  137. package/dist/alchemy/cloudflare/Email.d.ts +25 -0
  138. package/dist/alchemy/cloudflare/Email.d.ts.map +1 -0
  139. package/dist/alchemy/cloudflare/Email.js +117 -0
  140. package/dist/alchemy/cloudflare/Email.js.map +1 -0
  141. package/dist/cloudflare/Email.d.ts +25 -0
  142. package/dist/cloudflare/Email.d.ts.map +1 -0
  143. package/dist/cloudflare/Email.js +153 -0
  144. package/dist/cloudflare/Email.js.map +1 -0
  145. package/dist/index.d.ts +14 -0
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +14 -0
  148. package/dist/index.js.map +1 -1
  149. package/migrations/0003_auth_login_approval_review.sql +22 -0
  150. package/migrations/0004_auth_trusted_device.sql +12 -0
  151. package/migrations/0005_auth_passkey.sql +17 -0
  152. package/migrations/0006_auth_totp_factor.sql +17 -0
  153. package/migrations/0007_auth_recovery_code.sql +13 -0
  154. package/migrations/0008_auth_api_key.sql +17 -0
  155. package/migrations/0009_auth_refresh_token.sql +21 -0
  156. package/migrations/0010_auth_jwt_revocation.sql +8 -0
  157. package/migrations/0011_auth_oauth_account.sql +16 -0
  158. package/package.json +65 -1
@@ -0,0 +1,183 @@
1
+ import { Context, Duration, Effect, Layer, Redacted } from "effect";
2
+ import type { AuthMethod } from "./AuthFlow.js";
3
+ import { Challenge } from "./Challenge.js";
4
+ import type { ChallengeService } from "./Challenge.js";
5
+ import { Crypto } from "./Crypto.js";
6
+ import type { CryptoService } from "./Crypto.js";
7
+ import type { ChallengeId, Email, SessionId, UnixMillis, UserId } from "./Identifiers.js";
8
+ import type { LoginApprovalIntent, LoginDeviceContext, LoginDeviceStatus } from "./LoginApproval.js";
9
+ import type { LoginRequestContext, LoginRiskContext } from "./LoginRisk.js";
10
+ import { AuthMailer } from "./Mailer.js";
11
+ import type { AuthMailerService } from "./Mailer.js";
12
+ import { Sessions } from "./Sessions.js";
13
+ import type { AuthAssuranceLevel, AuthMethodReference, SessionClaims, SessionsService } from "./Sessions.js";
14
+ import type { WaitUntilService } from "./WaitUntil.js";
15
+ export declare const loginNotificationReportChallengeType: "login-notification-report";
16
+ export declare const defaultLoginNotificationReportTtl: Duration.Duration;
17
+ export declare const defaultLoginNotificationReportSecretBytes = 32;
18
+ export type LoginNotificationReason = "known-device" | "new-device" | "unknown-device" | "high-risk" | (string & {});
19
+ export type LoginNotificationReportAction = "revoke-sessions" | (string & {});
20
+ export interface LoginNotificationSession {
21
+ readonly sessionId: SessionId;
22
+ readonly userId: UserId;
23
+ readonly authTime: UnixMillis;
24
+ readonly expiresAt: UnixMillis;
25
+ readonly aal: AuthAssuranceLevel;
26
+ readonly amr: readonly AuthMethodReference[];
27
+ readonly claims?: SessionClaims;
28
+ }
29
+ export interface LoginNotificationPolicyInput {
30
+ readonly userId: UserId;
31
+ readonly email?: Email;
32
+ readonly intent?: LoginApprovalIntent;
33
+ readonly method: AuthMethod;
34
+ readonly amr: readonly AuthMethodReference[];
35
+ readonly aal: AuthAssuranceLevel;
36
+ readonly session: LoginNotificationSession;
37
+ readonly device: LoginDeviceContext;
38
+ readonly risk: LoginRiskContext;
39
+ readonly request?: LoginRequestContext;
40
+ readonly metadata?: Readonly<Record<string, unknown>>;
41
+ }
42
+ export interface LoginNotificationReportDecision {
43
+ readonly action?: LoginNotificationReportAction;
44
+ readonly ttl?: Duration.Duration;
45
+ readonly metadata?: Readonly<Record<string, unknown>>;
46
+ }
47
+ export type LoginNotificationPolicyDecision = {
48
+ readonly _tag: "Skip";
49
+ } | {
50
+ readonly _tag: "Notify";
51
+ readonly reason: LoginNotificationReason;
52
+ readonly report?: LoginNotificationReportDecision;
53
+ readonly locale?: string;
54
+ readonly metadata?: Readonly<Record<string, unknown>>;
55
+ };
56
+ export interface LoginNotificationPolicyService {
57
+ readonly decide: (input: LoginNotificationPolicyInput) => Effect.Effect<LoginNotificationPolicyDecision>;
58
+ }
59
+ declare const LoginNotificationPolicy_base: Context.ServiceClass<LoginNotificationPolicy, "auth/LoginNotificationPolicy", LoginNotificationPolicyService>;
60
+ export declare class LoginNotificationPolicy extends LoginNotificationPolicy_base {
61
+ }
62
+ export declare namespace LoginNotificationPolicy {
63
+ const make: (service: LoginNotificationPolicyService) => LoginNotificationPolicyService;
64
+ const custom: (decide: LoginNotificationPolicyService["decide"]) => LoginNotificationPolicyService;
65
+ }
66
+ export declare const LoginNotificationDecision: {
67
+ skip: () => LoginNotificationPolicyDecision;
68
+ notify: (input: {
69
+ readonly reason: LoginNotificationReason;
70
+ readonly report?: LoginNotificationReportDecision;
71
+ readonly locale?: string;
72
+ readonly metadata?: Readonly<Record<string, unknown>>;
73
+ }) => LoginNotificationPolicyDecision;
74
+ };
75
+ export interface LoginNotificationPolicyOptions {
76
+ readonly intents?: readonly LoginApprovalIntent[];
77
+ readonly methods?: readonly AuthMethod[];
78
+ readonly devices?: readonly LoginDeviceStatus[];
79
+ readonly reason?: LoginNotificationReason;
80
+ readonly report?: LoginNotificationReportDecision | false;
81
+ }
82
+ export declare const makeLoginNotificationPolicy: (options?: LoginNotificationPolicyOptions) => LoginNotificationPolicyService;
83
+ export declare const LoginNotificationPolicyLive: (options?: LoginNotificationPolicyOptions) => Layer.Layer<LoginNotificationPolicy, never, never>;
84
+ export interface LoginNotificationReportUrlInput {
85
+ readonly challengeId: ChallengeId;
86
+ readonly secret: Redacted.Redacted<string>;
87
+ readonly userId: UserId;
88
+ readonly sessionId: SessionId;
89
+ readonly email?: Email;
90
+ readonly reason: LoginNotificationReason;
91
+ readonly action: LoginNotificationReportAction;
92
+ readonly expiresAt: UnixMillis;
93
+ readonly request?: LoginRequestContext;
94
+ readonly metadata?: Readonly<Record<string, unknown>>;
95
+ }
96
+ export interface LoginNotificationNotifyInput extends LoginNotificationPolicyInput {
97
+ }
98
+ export interface LoginNotificationReportInput {
99
+ readonly challengeId: ChallengeId;
100
+ readonly secret: Redacted.Redacted<string>;
101
+ }
102
+ export interface LoginNotificationReportResult {
103
+ readonly userId: UserId;
104
+ readonly email?: Email;
105
+ readonly sessionId: SessionId;
106
+ readonly method: AuthMethod;
107
+ readonly deviceStatus: LoginDeviceStatus;
108
+ readonly request?: LoginRequestContext;
109
+ readonly occurredAt: UnixMillis;
110
+ readonly reason: LoginNotificationReason;
111
+ readonly action: LoginNotificationReportAction;
112
+ }
113
+ declare const LoginNotificationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
114
+ readonly _tag: "LoginNotificationError";
115
+ } & Readonly<A>;
116
+ export declare class LoginNotificationError extends LoginNotificationError_base<{
117
+ readonly message: string;
118
+ readonly cause?: unknown;
119
+ }> {
120
+ }
121
+ export type LoginNotificationReportErrorReason = "invalid_report" | "unsupported_action" | "internal";
122
+ declare const LoginNotificationReportError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
123
+ readonly _tag: "LoginNotificationReportError";
124
+ } & Readonly<A>;
125
+ export declare class LoginNotificationReportError extends LoginNotificationReportError_base<{
126
+ readonly reason: LoginNotificationReportErrorReason;
127
+ readonly message: string;
128
+ readonly cause?: unknown;
129
+ }> {
130
+ }
131
+ export interface LoginNotificationReportActionInput {
132
+ readonly userId: UserId;
133
+ readonly email?: Email;
134
+ readonly sessionId: SessionId;
135
+ readonly method: AuthMethod;
136
+ readonly deviceStatus: LoginDeviceStatus;
137
+ readonly request?: LoginRequestContext;
138
+ readonly occurredAt: UnixMillis;
139
+ readonly reason: LoginNotificationReason;
140
+ readonly action: LoginNotificationReportAction;
141
+ readonly metadata?: Readonly<Record<string, unknown>>;
142
+ }
143
+ export interface LoginNotificationReportActionHandlerService {
144
+ readonly handle: (input: LoginNotificationReportActionInput) => Effect.Effect<void, LoginNotificationReportError>;
145
+ }
146
+ declare const LoginNotificationReportActionHandler_base: Context.ServiceClass<LoginNotificationReportActionHandler, "auth/LoginNotificationReportActionHandler", LoginNotificationReportActionHandlerService>;
147
+ export declare class LoginNotificationReportActionHandler extends LoginNotificationReportActionHandler_base {
148
+ }
149
+ export declare namespace LoginNotificationReportActionHandler {
150
+ const make: (service: LoginNotificationReportActionHandlerService) => LoginNotificationReportActionHandlerService;
151
+ const custom: (handle: LoginNotificationReportActionHandlerService["handle"]) => LoginNotificationReportActionHandlerService;
152
+ }
153
+ export interface LoginNotificationService {
154
+ readonly notify: (input: LoginNotificationNotifyInput) => Effect.Effect<void, LoginNotificationError>;
155
+ readonly report: (input: LoginNotificationReportInput) => Effect.Effect<LoginNotificationReportResult, LoginNotificationReportError>;
156
+ }
157
+ declare const LoginNotification_base: Context.ServiceClass<LoginNotification, "auth/LoginNotification", LoginNotificationService>;
158
+ export declare class LoginNotification extends LoginNotification_base {
159
+ }
160
+ export declare namespace LoginNotification {
161
+ const make: (service: LoginNotificationService) => LoginNotificationService;
162
+ }
163
+ export interface LoginNotificationOptions {
164
+ readonly makeReportUrl: (input: LoginNotificationReportUrlInput) => string;
165
+ readonly reportTtl?: Duration.Duration;
166
+ readonly reportSecretBytes?: number;
167
+ }
168
+ export interface LoginNotificationDependencies extends LoginNotificationOptions {
169
+ readonly policy: LoginNotificationPolicyService;
170
+ readonly challenge: ChallengeService;
171
+ readonly crypto: CryptoService;
172
+ readonly authMailer: AuthMailerService;
173
+ readonly actionHandler: LoginNotificationReportActionHandlerService;
174
+ readonly waitUntil?: WaitUntilService;
175
+ }
176
+ export declare const makeLoginNotificationReportActionHandler: (dependencies: {
177
+ readonly sessions: SessionsService;
178
+ }) => LoginNotificationReportActionHandlerService;
179
+ export declare const LoginNotificationReportActionHandlerLive: Layer.Layer<LoginNotificationReportActionHandler, never, Sessions>;
180
+ export declare const makeLoginNotification: (dependencies: LoginNotificationDependencies) => LoginNotificationService;
181
+ export declare const LoginNotificationLive: (options: LoginNotificationOptions) => Layer.Layer<LoginNotification, never, Crypto | Sessions | AuthMailer | Challenge>;
182
+ export {};
183
+ //# sourceMappingURL=LoginNotification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoginNotification.d.ts","sourceRoot":"","sources":["../src/LoginNotification.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,QAAQ,EACR,MAAM,EACN,KAAK,EAEL,QAAQ,EACT,MAAM,QAAQ,CAAC;AAEhB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACV,WAAW,EACX,KAAK,EACL,SAAS,EACT,UAAU,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,iBAAiB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7B,CAAC;CACH;;AAED,qBAAa,iBAAkB,SAAQ,sBAGV;CAAG;AAEhC,yBAAiB,iBAAiB,CAAC;IAC1B,MAAM,IAAI,GACf,SAAS,wBAAwB,KAChC,wBAAyD,CAAC;CAC9D;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,+BAA+B,KAAK,MAAM,CAAC;IAC3E,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC;IACvC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,6BAA8B,SAAQ,wBAAwB;IAC7E,QAAQ,CAAC,MAAM,EAAE,8BAA8B,CAAC;IAChD,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAC;IACvC,QAAQ,CAAC,aAAa,EAAE,2CAA2C,CAAC;IACpE,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;CACvC;AA8MD,eAAO,MAAM,wCAAwC,GAAI,cAAc;IACrE,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;CACpC,KAAG,2CAuBA,CAAC;AAEL,eAAO,MAAM,wCAAwC,oEAQpD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,cAAc,6BAA6B,KAC1C,wBAqIC,CAAC;AAEL,eAAO,MAAM,qBAAqB,GAAI,SAAS,wBAAwB,sFA2BpE,CAAC"}
@@ -0,0 +1,329 @@
1
+ import { Context, Data, Duration, Effect, Layer, Option, Redacted, } from "effect";
2
+ import { Challenge } from "./Challenge.js";
3
+ import { Crypto } from "./Crypto.js";
4
+ import { SessionId as makeSessionId, UserId as makeUserId, } from "./Identifiers.js";
5
+ import { AuthMailer } from "./Mailer.js";
6
+ import { Sessions } from "./Sessions.js";
7
+ import { WaitUntil } from "./WaitUntil.js";
8
+ export const loginNotificationReportChallengeType = "login-notification-report";
9
+ export const defaultLoginNotificationReportTtl = Duration.days(7);
10
+ export const defaultLoginNotificationReportSecretBytes = 32;
11
+ export class LoginNotificationPolicy extends Context.Service()("auth/LoginNotificationPolicy") {
12
+ }
13
+ (function (LoginNotificationPolicy) {
14
+ LoginNotificationPolicy.make = (service) => LoginNotificationPolicy.of(service);
15
+ LoginNotificationPolicy.custom = (decide) => LoginNotificationPolicy.of({ decide });
16
+ })(LoginNotificationPolicy || (LoginNotificationPolicy = {}));
17
+ const skipDecision = { _tag: "Skip" };
18
+ export const LoginNotificationDecision = {
19
+ skip: () => skipDecision,
20
+ notify: (input) => ({
21
+ _tag: "Notify",
22
+ reason: input.reason,
23
+ ...(input.report === undefined ? {} : { report: input.report }),
24
+ ...(input.locale === undefined ? {} : { locale: input.locale }),
25
+ ...(input.metadata === undefined ? {} : { metadata: input.metadata }),
26
+ }),
27
+ };
28
+ export const makeLoginNotificationPolicy = (options = {}) => {
29
+ const intents = options.intents ?? [];
30
+ const methods = options.methods ?? [];
31
+ const devices = options.devices ?? [];
32
+ return LoginNotificationPolicy.make({
33
+ decide: Effect.fn("auth.login_notification_policy.decide")(function* (input) {
34
+ if (intents.length > 0 &&
35
+ (input.intent === undefined || !intents.includes(input.intent))) {
36
+ return skipDecision;
37
+ }
38
+ if (methods.length > 0 && !methods.includes(input.method)) {
39
+ return skipDecision;
40
+ }
41
+ if (devices.length > 0 && !devices.includes(input.device.status)) {
42
+ return skipDecision;
43
+ }
44
+ if (intents.length === 0 &&
45
+ methods.length === 0 &&
46
+ devices.length === 0) {
47
+ return skipDecision;
48
+ }
49
+ return LoginNotificationDecision.notify({
50
+ reason: options.reason ?? reasonFromDeviceStatus(input.device.status),
51
+ ...(options.report === false
52
+ ? {}
53
+ : { report: options.report ?? { action: "revoke-sessions" } }),
54
+ });
55
+ }),
56
+ });
57
+ };
58
+ export const LoginNotificationPolicyLive = (options) => Layer.succeed(LoginNotificationPolicy)(makeLoginNotificationPolicy(options));
59
+ export class LoginNotificationError extends Data.TaggedError("LoginNotificationError") {
60
+ }
61
+ export class LoginNotificationReportError extends Data.TaggedError("LoginNotificationReportError") {
62
+ }
63
+ export class LoginNotificationReportActionHandler extends Context.Service()("auth/LoginNotificationReportActionHandler") {
64
+ }
65
+ (function (LoginNotificationReportActionHandler) {
66
+ LoginNotificationReportActionHandler.make = (service) => LoginNotificationReportActionHandler.of(service);
67
+ LoginNotificationReportActionHandler.custom = (handle) => LoginNotificationReportActionHandler.of({ handle });
68
+ })(LoginNotificationReportActionHandler || (LoginNotificationReportActionHandler = {}));
69
+ export class LoginNotification extends Context.Service()("auth/LoginNotification") {
70
+ }
71
+ (function (LoginNotification) {
72
+ LoginNotification.make = (service) => LoginNotification.of(service);
73
+ })(LoginNotification || (LoginNotification = {}));
74
+ const mergeMetadata = (left, right) => {
75
+ const metadata = { ...left, ...right };
76
+ return Object.keys(metadata).length === 0 ? undefined : metadata;
77
+ };
78
+ const metadataString = (metadata, key) => {
79
+ const value = metadata?.[key];
80
+ return typeof value === "string" && value.length > 0 ? value : undefined;
81
+ };
82
+ const metadataNumber = (metadata, key) => {
83
+ const value = metadata?.[key];
84
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
85
+ };
86
+ const metadataDeviceStatus = (metadata, key) => {
87
+ const value = metadataString(metadata, key);
88
+ return value === "known" || value === "new" || value === "unknown"
89
+ ? value
90
+ : undefined;
91
+ };
92
+ const metadataRecord = (metadata, key) => {
93
+ const value = metadata?.[key];
94
+ return typeof value === "object" && value !== null && !Array.isArray(value)
95
+ ? value
96
+ : undefined;
97
+ };
98
+ const reportMetadata = (input) => ({
99
+ ...(input.email === undefined ? {} : { email: input.email }),
100
+ sessionId: input.sessionId,
101
+ method: input.method,
102
+ deviceStatus: input.deviceStatus,
103
+ ...(input.request === undefined ? {} : { request: input.request }),
104
+ occurredAt: Number(input.occurredAt),
105
+ reason: input.reason,
106
+ action: input.action,
107
+ ...(input.metadata === undefined ? {} : { metadata: input.metadata }),
108
+ });
109
+ const reasonFromDeviceStatus = (status) => {
110
+ switch (status) {
111
+ case "known": {
112
+ return "known-device";
113
+ }
114
+ case "new": {
115
+ return "new-device";
116
+ }
117
+ case "unknown": {
118
+ return "unknown-device";
119
+ }
120
+ }
121
+ };
122
+ const invalidateReportChallenge = (challenge, id) => challenge
123
+ .consume(id)
124
+ .pipe(Effect.catchTag("ChallengeConsumeError", () => Effect.void));
125
+ const makeReportUrl = (dependencies, input) => Effect.try({
126
+ try: () => dependencies.makeReportUrl(input),
127
+ catch: (cause) => new LoginNotificationError({
128
+ message: "Failed to build login notification report URL",
129
+ cause,
130
+ }),
131
+ });
132
+ const issueReport = (dependencies, input, decision, metadata) => Effect.gen(function* () {
133
+ const { report } = decision;
134
+ if (report === undefined) {
135
+ return undefined;
136
+ }
137
+ const action = report.action ?? "revoke-sessions";
138
+ const secret = Redacted.make(yield* dependencies.crypto.randomToken(dependencies.reportSecretBytes ??
139
+ defaultLoginNotificationReportSecretBytes));
140
+ const issued = yield* dependencies.challenge.issue({
141
+ type: loginNotificationReportChallengeType,
142
+ subject: input.userId,
143
+ ttl: report.ttl ??
144
+ dependencies.reportTtl ??
145
+ defaultLoginNotificationReportTtl,
146
+ secret,
147
+ metadata: reportMetadata({
148
+ ...(input.email === undefined ? {} : { email: input.email }),
149
+ sessionId: input.session.sessionId,
150
+ method: input.method,
151
+ deviceStatus: input.device.status,
152
+ ...(input.request === undefined ? {} : { request: input.request }),
153
+ occurredAt: input.session.authTime,
154
+ reason: decision.reason,
155
+ action,
156
+ metadata: report.metadata,
157
+ }),
158
+ });
159
+ const reportUrl = yield* makeReportUrl(dependencies, {
160
+ challengeId: issued.id,
161
+ secret,
162
+ userId: input.userId,
163
+ sessionId: input.session.sessionId,
164
+ ...(input.email === undefined ? {} : { email: input.email }),
165
+ reason: decision.reason,
166
+ action,
167
+ expiresAt: issued.expiresAt,
168
+ ...(input.request === undefined ? {} : { request: input.request }),
169
+ ...(metadata === undefined ? {} : { metadata }),
170
+ }).pipe(Effect.matchEffect({
171
+ onSuccess: Effect.succeed,
172
+ onFailure: (error) => invalidateReportChallenge(dependencies.challenge, issued.id).pipe(Effect.flatMap(() => Effect.fail(error))),
173
+ }));
174
+ return {
175
+ challengeId: issued.id,
176
+ url: reportUrl,
177
+ expiresAt: issued.expiresAt,
178
+ };
179
+ }).pipe(Effect.mapError((cause) => cause instanceof LoginNotificationError
180
+ ? cause
181
+ : new LoginNotificationError({
182
+ message: "Failed to issue login notification report",
183
+ cause,
184
+ })));
185
+ const scheduleDelivery = (dependencies, delivery) => dependencies.waitUntil === undefined
186
+ ? delivery
187
+ : dependencies.waitUntil.waitUntil(delivery).pipe(Effect.mapError((cause) => new LoginNotificationError({
188
+ message: "Failed to schedule login notification",
189
+ cause,
190
+ })));
191
+ export const makeLoginNotificationReportActionHandler = (dependencies) => LoginNotificationReportActionHandler.make({
192
+ handle: Effect.fn("auth.login_notification.report.action")(function* (input) {
193
+ if (input.action !== "revoke-sessions") {
194
+ return yield* new LoginNotificationReportError({
195
+ reason: "unsupported_action",
196
+ message: `Unsupported login notification action: ${input.action}`,
197
+ });
198
+ }
199
+ yield* dependencies.sessions.revokeAllForUser(input.userId).pipe(Effect.mapError((cause) => new LoginNotificationReportError({
200
+ reason: "internal",
201
+ message: "Failed to revoke sessions for reported login",
202
+ cause,
203
+ })));
204
+ }),
205
+ });
206
+ export const LoginNotificationReportActionHandlerLive = Layer.effect(LoginNotificationReportActionHandler)(Effect.gen(function* () {
207
+ const sessions = yield* Sessions;
208
+ return makeLoginNotificationReportActionHandler({ sessions });
209
+ }));
210
+ export const makeLoginNotification = (dependencies) => LoginNotification.make({
211
+ notify: Effect.fn("auth.login_notification.notify")(function* (input) {
212
+ const decision = yield* dependencies.policy.decide(input);
213
+ const { email } = input;
214
+ if (decision._tag === "Skip" || email === undefined) {
215
+ return;
216
+ }
217
+ const metadata = mergeMetadata(input.metadata, decision.metadata);
218
+ const delivery = Effect.gen(function* () {
219
+ const report = yield* issueReport(dependencies, input, decision, metadata);
220
+ yield* dependencies.authMailer
221
+ .send({
222
+ _tag: "LoginNotification",
223
+ to: email,
224
+ userId: input.userId,
225
+ sessionId: input.session.sessionId,
226
+ method: input.method,
227
+ reason: decision.reason,
228
+ deviceStatus: input.device.status,
229
+ request: input.request,
230
+ occurredAt: input.session.authTime,
231
+ ...(report === undefined
232
+ ? {}
233
+ : {
234
+ reportChallengeId: report.challengeId,
235
+ reportUrl: report.url,
236
+ reportExpiresAt: report.expiresAt,
237
+ }),
238
+ ...(decision.locale === undefined
239
+ ? {}
240
+ : { locale: decision.locale }),
241
+ ...(metadata === undefined ? {} : { metadata }),
242
+ })
243
+ .pipe(Effect.matchEffect({
244
+ onSuccess: () => Effect.void,
245
+ onFailure: (cause) => report === undefined
246
+ ? Effect.fail(new LoginNotificationError({
247
+ message: "Failed to send login notification",
248
+ cause,
249
+ }))
250
+ : invalidateReportChallenge(dependencies.challenge, report.challengeId).pipe(Effect.flatMap(() => Effect.fail(new LoginNotificationError({
251
+ message: "Failed to send login notification",
252
+ cause,
253
+ })))),
254
+ }));
255
+ });
256
+ yield* scheduleDelivery(dependencies, delivery);
257
+ }),
258
+ report: Effect.fn("auth.login_notification.report")(function* (input) {
259
+ const verified = yield* dependencies.challenge
260
+ .verify({
261
+ challengeId: input.challengeId,
262
+ type: loginNotificationReportChallengeType,
263
+ secret: input.secret,
264
+ })
265
+ .pipe(Effect.mapError((cause) => new LoginNotificationReportError({
266
+ reason: "invalid_report",
267
+ message: "Invalid login notification report",
268
+ cause,
269
+ })));
270
+ const sessionId = metadataString(verified.metadata, "sessionId");
271
+ const email = metadataString(verified.metadata, "email");
272
+ const method = metadataString(verified.metadata, "method");
273
+ const deviceStatus = metadataDeviceStatus(verified.metadata, "deviceStatus");
274
+ const request = metadataRecord(verified.metadata, "request");
275
+ const occurredAt = metadataNumber(verified.metadata, "occurredAt");
276
+ const reason = metadataString(verified.metadata, "reason");
277
+ const action = metadataString(verified.metadata, "action");
278
+ if (sessionId === undefined ||
279
+ method === undefined ||
280
+ deviceStatus === undefined ||
281
+ occurredAt === undefined ||
282
+ reason === undefined ||
283
+ action === undefined) {
284
+ return yield* new LoginNotificationReportError({
285
+ reason: "invalid_report",
286
+ message: "Login notification report is missing metadata",
287
+ });
288
+ }
289
+ const reportResult = {
290
+ userId: makeUserId(verified.subject),
291
+ ...(email === undefined ? {} : { email: email }),
292
+ sessionId: makeSessionId(sessionId),
293
+ method,
294
+ deviceStatus,
295
+ ...(request === undefined ? {} : { request }),
296
+ occurredAt: occurredAt,
297
+ reason,
298
+ action,
299
+ };
300
+ yield* dependencies.actionHandler.handle({
301
+ ...reportResult,
302
+ metadata: metadataRecord(verified.metadata, "metadata"),
303
+ });
304
+ return reportResult;
305
+ }),
306
+ });
307
+ export const LoginNotificationLive = (options) => Layer.effect(LoginNotification)(Effect.gen(function* () {
308
+ const policy = yield* Effect.serviceOption(LoginNotificationPolicy);
309
+ const actionHandler = yield* Effect.serviceOption(LoginNotificationReportActionHandler);
310
+ const waitUntil = yield* Effect.serviceOption(WaitUntil);
311
+ const challenge = yield* Challenge;
312
+ const crypto = yield* Crypto;
313
+ const authMailer = yield* AuthMailer;
314
+ const sessions = yield* Sessions;
315
+ return makeLoginNotification({
316
+ ...options,
317
+ policy: Option.isSome(policy)
318
+ ? policy.value
319
+ : makeLoginNotificationPolicy(),
320
+ actionHandler: Option.isSome(actionHandler)
321
+ ? actionHandler.value
322
+ : makeLoginNotificationReportActionHandler({ sessions }),
323
+ challenge,
324
+ crypto,
325
+ authMailer,
326
+ ...(Option.isSome(waitUntil) ? { waitUntil: waitUntil.value } : {}),
327
+ });
328
+ }));
329
+ //# sourceMappingURL=LoginNotification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoginNotification.js","sourceRoot":"","sources":["../src/LoginNotification.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,MAAM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C,MAAM,CAAC,MAAM,CAAC;YAC3B,CAAC,CAAC,MAAM,CAAC,KAAK;YACd,CAAC,CAAC,2BAA2B,EAAE;QACjC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;YACzC,CAAC,CAAC,aAAa,CAAC,KAAK;YACrB,CAAC,CAAC,wCAAwC,CAAC,EAAE,QAAQ,EAAE,CAAC;QAC1D,SAAS;QACT,MAAM;QACN,UAAU;QACV,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpE,CAAC,CAAC;AACL,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { Context, Effect, Layer, Schema } from "effect";
2
+ import type { AuthMethod } from "./AuthFlow.js";
3
+ import type { Email, UserId } from "./Identifiers.js";
4
+ import type { LoginDeviceContext } from "./LoginApproval.js";
5
+ import type { AuthAssuranceLevel, AuthMethodReference } from "./Sessions.js";
6
+ export declare const LoginRiskLevelSchema: Schema.Literals<readonly ["unknown", "low", "medium", "high", "critical"]>;
7
+ export type LoginRiskLevel = Schema.Schema.Type<typeof LoginRiskLevelSchema>;
8
+ declare const LoginRiskSignal_base: Schema.Class<LoginRiskSignal, Schema.Struct<{
9
+ readonly type: Schema.String;
10
+ readonly level: Schema.optional<Schema.Literals<readonly ["unknown", "low", "medium", "high", "critical"]>>;
11
+ readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
12
+ }>, {}>;
13
+ export declare class LoginRiskSignal extends LoginRiskSignal_base {
14
+ }
15
+ export interface LoginRiskSignalEncoded extends Schema.Codec.Encoded<typeof LoginRiskSignal> {
16
+ }
17
+ export declare const isLoginRiskSignal: <I>(input: I) => input is I & LoginRiskSignal;
18
+ declare const LoginRiskContext_base: Schema.Class<LoginRiskContext, Schema.Struct<{
19
+ readonly level: Schema.Literals<readonly ["unknown", "low", "medium", "high", "critical"]>;
20
+ readonly signals: Schema.$Array<typeof LoginRiskSignal>;
21
+ readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
22
+ }>, {}>;
23
+ export declare class LoginRiskContext extends LoginRiskContext_base {
24
+ hasSignal(type: string): boolean;
25
+ getSignal(type: string): LoginRiskSignal | undefined;
26
+ isAtLeast(level: LoginRiskLevel): boolean;
27
+ }
28
+ export interface LoginRiskContextEncoded extends Schema.Codec.Encoded<typeof LoginRiskContext> {
29
+ }
30
+ export declare const isLoginRiskContext: <I>(input: I) => input is I & LoginRiskContext;
31
+ export interface LoginRequestContext {
32
+ readonly ip?: string;
33
+ readonly userAgent?: string;
34
+ readonly country?: string;
35
+ readonly region?: string;
36
+ readonly city?: string;
37
+ readonly latitude?: number;
38
+ readonly longitude?: number;
39
+ }
40
+ export interface LoginRiskAssessInput {
41
+ readonly userId: UserId;
42
+ readonly email?: Email;
43
+ readonly emailVerified?: boolean;
44
+ readonly method: AuthMethod;
45
+ readonly amr: readonly AuthMethodReference[];
46
+ readonly aal: AuthAssuranceLevel;
47
+ readonly device: LoginDeviceContext;
48
+ readonly request?: LoginRequestContext;
49
+ readonly metadata?: Readonly<Record<string, unknown>>;
50
+ }
51
+ declare const LoginRiskError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
52
+ readonly _tag: "LoginRiskError";
53
+ } & Readonly<A>;
54
+ export declare class LoginRiskError extends LoginRiskError_base<{
55
+ readonly message: string;
56
+ readonly cause?: unknown;
57
+ }> {
58
+ }
59
+ export interface LoginRiskEngineService {
60
+ readonly assess: (input: LoginRiskAssessInput) => Effect.Effect<LoginRiskContext, LoginRiskError>;
61
+ }
62
+ declare const LoginRiskEngine_base: Context.ServiceClass<LoginRiskEngine, "auth/LoginRiskEngine", LoginRiskEngineService>;
63
+ export declare class LoginRiskEngine extends LoginRiskEngine_base {
64
+ }
65
+ export declare namespace LoginRiskEngine {
66
+ const make: (service: LoginRiskEngineService) => LoginRiskEngineService;
67
+ const custom: (assess: LoginRiskEngineService["assess"]) => LoginRiskEngineService;
68
+ }
69
+ export declare const defaultLoginRiskContext: LoginRiskContext;
70
+ export declare const makeLoginRiskEngineNoop: () => LoginRiskEngineService;
71
+ export declare const LoginRiskEngineNoopLive: Layer.Layer<LoginRiskEngine, never, never>;
72
+ export {};
73
+ //# sourceMappingURL=LoginRisk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoginRisk.d.ts","sourceRoot":"","sources":["../src/LoginRisk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAQ,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE7E,eAAO,MAAM,oBAAoB,4EAMtB,CAAC;AAEZ,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,oBAAoB,CAAC,CAAC;;;;;;AAY7E,qBAAa,eAAgB,SAAQ,oBAMnC;CAAG;AAEL,MAAM,WAAW,sBACf,SAAQ,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,eAAe,CAAC;CAAG;AAEzD,eAAO,MAAM,iBAAiB,+CAA6B,CAAC;;;;;;AAE5D,qBAAa,gBAAiB,SAAQ,qBAMpC;IACA,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIhC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG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