@open-neko/plugin-magic-link 0.3.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of the work is included on the
186
+ same line as the file name.
187
+
188
+ Copyright 2026 Amit Deshmukh
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
199
+ implied, including, without limitation, any warranties or conditions
200
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
201
+ PARTICULAR PURPOSE. See the License for the specific language governing
202
+ permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @open-neko/plugin-magic-link
2
+
3
+ Passwordless email sign-in for [OpenNeko](https://github.com/open-neko/neko). Implements the generic `auth` contract with **manual provisioning**: an admin creates each user (email + role) in OpenNeko first, and only those users can request a sign-in link. Possession of a mailbox never mints an account — the whole world can know your sign-in URL and still get nowhere.
4
+
5
+ ## Setup — one command, then the browser
6
+
7
+ ```sh
8
+ openneko install @open-neko/plugin-magic-link
9
+ ```
10
+
11
+ That's the only terminal step. The signing secret is generated and stored by the host automatically (`autogenerate` in the manifest) — you are never prompted for it and never see it.
12
+
13
+ Everything else happens at **Admin → Settings → Email-link sign-in**, a single page with live status:
14
+
15
+ 1. **Email delivery** — pick a provider (Resend, Postmark, or SendGrid), paste its API key once, and set the From address (must be a sender verified with that provider).
16
+ 2. **Who can sign in** — add your own email **as admin**, then the rest of your users. There is no invite email; tell people however you like.
17
+ 3. **Delivery test** — send yourself a real email through the configured provider to confirm delivery. The test email's link is deliberately unusable; real sign-in happens at `/signin`.
18
+
19
+ The page's status banner lists exactly what is still missing. **The sign-in gate cannot flip on until every required value is set *and* at least one active admin user exists** — a half-finished setup can never lock you out; the deployment simply stays in single-operator mode.
20
+
21
+ ## How sign-in works
22
+
23
+ 1. A user enters their email at `/signin` and clicks **Email me a sign-in link**.
24
+ 2. OpenNeko's core checks the email against provisioned, non-disabled users **before this plugin is ever called**. Unknown emails get the same "check your email" notice and nothing is sent — no account enumeration, no mailbox spam. Delivery failures are masked identically (diagnose via worker logs, or the delivery test).
25
+ 3. For known users, the plugin HMAC-signs `{email, state, expiry}` into a token and emails the link. Clicking it lands on OpenNeko's standard auth callback.
26
+ 4. `complete_auth` verifies the signature, expiry, and state binding, and returns the identity. The core signs the user in with the role the admin assigned.
27
+
28
+ ## Security properties
29
+
30
+ | Property | Mechanism |
31
+ |---|---|
32
+ | Only authorized users sign in | Core gate on pre-provisioned users at begin **and** complete (defense in depth) |
33
+ | No lockout window | Gate requires ≥1 active provisioned admin before it can flip on |
34
+ | Single-use links | Core's state cookie is read-and-cleared on first callback; the token is bound to that state |
35
+ | Same-browser only | Same state binding — the emailed link only completes where it was requested |
36
+ | 10-minute expiry | Token `exp` claim (configurable 60–600 s via `MAGIC_LINK_TTL_SECONDS`) + the core's state-cookie TTL |
37
+ | No self-asserted authorization | Identity always carries `groups: []`; roles come from the admin, never the plugin |
38
+ | Instant revocation | Delete the stored `MAGIC_LINK_SIGNING_SECRET` and restart → every outstanding link dies |
39
+
40
+ ## Environment reference
41
+
42
+ | Key | Required | Set by | Purpose |
43
+ |---|---|---|---|
44
+ | `MAGIC_LINK_SIGNING_SECRET` | yes | **host (auto-generated)** | HMAC key for sign-in tokens |
45
+ | `MAGIC_LINK_FROM` | yes | settings page (or CLI) | From address, e.g. `OpenNeko <signin@company.com>` |
46
+ | `RESEND_API_KEY` | one of three | settings page (or CLI) | selects Resend delivery |
47
+ | `POSTMARK_SERVER_TOKEN` | one of three | settings page (or CLI) | selects Postmark delivery |
48
+ | `SENDGRID_API_KEY` | one of three | settings page (or CLI) | selects SendGrid delivery |
49
+ | `MAGIC_LINK_TTL_SECONDS` | no | CLI | link lifetime, 60–600 (default 600) |
50
+
51
+ Exactly one provider key may be set — the settings page enforces this by clearing the other two when you save. CLI-inclined operators can use `openneko secrets set @open-neko/plugin-magic-link <KEY>` for any of these instead.
52
+
53
+ Network egress from the plugin VM is locked to `api.resend.com`, `api.postmarkapp.com`, and `api.sendgrid.com`.
54
+
55
+ ## Switching from an SSO plugin
56
+
57
+ `app_user.sub` is bound to the previous provider's subject. A magic-link sign-in for the same email will refuse to take over a row with a foreign `sub` — clear the `sub` column for affected users and it attaches fresh on their next sign-in.
58
+
59
+ ## Development
60
+
61
+ ```sh
62
+ pnpm install
63
+ pnpm build # tsc + esbuild → dist/run.js
64
+ pnpm test # vitest
65
+ ```
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Sign-in email delivery. Three interchangeable HTTPS providers —
3
+ * Resend, Postmark, SendGrid — selected by which API-key env var is
4
+ * set. The VM's egress allowlist covers exactly their API hosts.
5
+ */
6
+ export interface EmailMessage {
7
+ from: string;
8
+ to: string;
9
+ subject: string;
10
+ text: string;
11
+ html: string;
12
+ }
13
+ export type EmailSender = (message: EmailMessage) => Promise<void>;
14
+ export interface ProviderEnv {
15
+ resendApiKey?: string;
16
+ postmarkServerToken?: string;
17
+ sendgridApiKey?: string;
18
+ }
19
+ export declare function resolveProvider(env: ProviderEnv): {
20
+ name: "resend" | "postmark" | "sendgrid";
21
+ send: EmailSender;
22
+ };
23
+ /** "Name <addr@x>" → { name, email }; bare address → { email }. */
24
+ export declare function parseFrom(from: string): {
25
+ email: string;
26
+ name?: string;
27
+ };
28
+ export declare function buildSignInEmail(input: {
29
+ from: string;
30
+ to: string;
31
+ link: string;
32
+ ttlMinutes: number;
33
+ }): EmailMessage;
34
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnE,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG;IACjD,IAAI,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;IACzC,IAAI,EAAE,WAAW,CAAC;CACnB,CAyBA;AA6ED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAQxE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,YAAY,CAuBf"}
package/dist/email.js ADDED
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Sign-in email delivery. Three interchangeable HTTPS providers —
3
+ * Resend, Postmark, SendGrid — selected by which API-key env var is
4
+ * set. The VM's egress allowlist covers exactly their API hosts.
5
+ */
6
+ export function resolveProvider(env) {
7
+ const configured = [
8
+ env.resendApiKey && "resend",
9
+ env.postmarkServerToken && "postmark",
10
+ env.sendgridApiKey && "sendgrid",
11
+ ].filter((value) => Boolean(value));
12
+ if (configured.length === 0) {
13
+ throw new Error("no email provider configured — set one of RESEND_API_KEY, POSTMARK_SERVER_TOKEN, or SENDGRID_API_KEY");
14
+ }
15
+ if (configured.length > 1) {
16
+ throw new Error(`multiple email providers configured (${configured.join(", ")}) — set exactly one API key`);
17
+ }
18
+ if (env.resendApiKey) {
19
+ return { name: "resend", send: resendSender(env.resendApiKey) };
20
+ }
21
+ if (env.postmarkServerToken) {
22
+ return { name: "postmark", send: postmarkSender(env.postmarkServerToken) };
23
+ }
24
+ return { name: "sendgrid", send: sendgridSender(env.sendgridApiKey) };
25
+ }
26
+ async function expectOk(res, provider) {
27
+ if (res.ok)
28
+ return;
29
+ const body = await res.text().catch(() => "");
30
+ // Provider errors can echo the recipient address; truncate and pass
31
+ // through — this surfaces in worker logs only, never to the visitor
32
+ // (the core masks manual-provisioning begin failures).
33
+ throw new Error(`${provider} rejected the sign-in email (${res.status}): ${body.slice(0, 300)}`);
34
+ }
35
+ function resendSender(apiKey) {
36
+ return async (message) => {
37
+ const res = await fetch("https://api.resend.com/emails", {
38
+ method: "POST",
39
+ headers: {
40
+ Authorization: `Bearer ${apiKey}`,
41
+ "Content-Type": "application/json",
42
+ },
43
+ body: JSON.stringify({
44
+ from: message.from,
45
+ to: [message.to],
46
+ subject: message.subject,
47
+ text: message.text,
48
+ html: message.html,
49
+ }),
50
+ });
51
+ await expectOk(res, "Resend");
52
+ };
53
+ }
54
+ function postmarkSender(serverToken) {
55
+ return async (message) => {
56
+ const res = await fetch("https://api.postmarkapp.com/email", {
57
+ method: "POST",
58
+ headers: {
59
+ "X-Postmark-Server-Token": serverToken,
60
+ "Content-Type": "application/json",
61
+ Accept: "application/json",
62
+ },
63
+ body: JSON.stringify({
64
+ From: message.from,
65
+ To: message.to,
66
+ Subject: message.subject,
67
+ TextBody: message.text,
68
+ HtmlBody: message.html,
69
+ MessageStream: "outbound",
70
+ }),
71
+ });
72
+ await expectOk(res, "Postmark");
73
+ };
74
+ }
75
+ function sendgridSender(apiKey) {
76
+ return async (message) => {
77
+ const res = await fetch("https://api.sendgrid.com/v3/mail/send", {
78
+ method: "POST",
79
+ headers: {
80
+ Authorization: `Bearer ${apiKey}`,
81
+ "Content-Type": "application/json",
82
+ },
83
+ body: JSON.stringify({
84
+ personalizations: [{ to: [{ email: message.to }] }],
85
+ from: parseFrom(message.from),
86
+ subject: message.subject,
87
+ content: [
88
+ { type: "text/plain", value: message.text },
89
+ { type: "text/html", value: message.html },
90
+ ],
91
+ }),
92
+ });
93
+ await expectOk(res, "SendGrid");
94
+ };
95
+ }
96
+ /** "Name <addr@x>" → { name, email }; bare address → { email }. */
97
+ export function parseFrom(from) {
98
+ const match = /^\s*(.*?)\s*<([^<>\s]+@[^<>\s]+)>\s*$/.exec(from);
99
+ const email = match?.[2];
100
+ if (match && email) {
101
+ const name = (match[1] ?? "").replace(/^"|"$/g, "").trim();
102
+ return name ? { email, name } : { email };
103
+ }
104
+ return { email: from.trim() };
105
+ }
106
+ export function buildSignInEmail(input) {
107
+ const { to, link, ttlMinutes } = input;
108
+ return {
109
+ from: input.from,
110
+ to,
111
+ subject: "Your OpenNeko sign-in link",
112
+ text: [
113
+ `Sign in to OpenNeko`,
114
+ ``,
115
+ `Open this link to sign in as ${to}:`,
116
+ ``,
117
+ link,
118
+ ``,
119
+ `The link works once and expires in ${ttlMinutes} minutes. Open it in`,
120
+ `the same browser you requested it from.`,
121
+ ``,
122
+ `Someone asked for a sign-in link for this address. If that was not`,
123
+ `you, ignore this email. Nobody can sign in without the link.`,
124
+ ``,
125
+ `OpenNeko · AI that helps run your business.`,
126
+ ].join("\n"),
127
+ html: signInHtml({ to, link, ttlMinutes }),
128
+ };
129
+ }
130
+ /**
131
+ * Table layout with inline styles, because Gmail and Outlook drop
132
+ * stylesheets, and system fonts, because they drop web fonts too.
133
+ */
134
+ function signInHtml(input) {
135
+ const href = escapeHtml(input.link);
136
+ const address = escapeHtml(input.to);
137
+ const minutes = String(input.ttlMinutes);
138
+ const sans = "-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif";
139
+ const mono = "ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace";
140
+ return `<!doctype html>
141
+ <html lang="en">
142
+ <head>
143
+ <meta charset="utf-8">
144
+ <meta name="viewport" content="width=device-width,initial-scale=1">
145
+ <meta name="color-scheme" content="light">
146
+ <meta name="supported-color-schemes" content="light">
147
+ <title>Your OpenNeko sign-in link</title>
148
+ </head>
149
+ <body style="margin:0;padding:0;background:#FAFAF7;">
150
+ <div style="display:none;max-height:0;overflow:hidden;opacity:0;">The link works once and expires in ${minutes} minutes.</div>
151
+ <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#FAFAF7;">
152
+ <tr><td align="center" style="padding:32px 16px;">
153
+ <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="max-width:480px;background:#FFFFFF;border:1px solid #EEEBE4;border-radius:14px;">
154
+ <tr><td style="padding:32px 32px 8px 32px;font-family:${sans};">
155
+ <div style="font-size:15px;font-weight:700;letter-spacing:-0.01em;color:#2D2A24;">OpenNeko</div>
156
+ </td></tr>
157
+ <tr><td style="padding:16px 32px 0 32px;font-family:${sans};">
158
+ <h1 style="margin:0;font-size:22px;line-height:1.3;font-weight:700;letter-spacing:-0.02em;color:#2D2A24;">Sign in to OpenNeko</h1>
159
+ <p style="margin:12px 0 0 0;font-size:15px;line-height:1.55;color:#6F6A60;">Select the button to sign in as <span style="color:#2D2A24;font-weight:600;">${address}</span>.</p>
160
+ </td></tr>
161
+ <tr><td style="padding:24px 32px 0 32px;">
162
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0"><tr>
163
+ <td align="center" bgcolor="#6B5CE7" style="border-radius:10px;">
164
+ <a href="${href}" style="display:inline-block;padding:14px 28px;font-family:${sans};font-size:15px;font-weight:600;color:#FFFFFF;text-decoration:none;border-radius:10px;">Sign in</a>
165
+ </td></tr></table>
166
+ <p style="margin:16px 0 0 0;font-family:${sans};font-size:13px;line-height:1.55;color:#6F6A60;">The link works once and expires in ${minutes} minutes. Open it in the same browser you requested it from.</p>
167
+ </td></tr>
168
+ <tr><td style="padding:24px 32px 0 32px;font-family:${sans};">
169
+ <p style="margin:0 0 8px 0;font-size:13px;color:#6F6A60;">Or paste this link into your browser:</p>
170
+ <div style="padding:12px 14px;background:#F7F4ED;border:1px solid #EEEBE4;border-radius:10px;font-family:${mono};font-size:12px;line-height:1.6;color:#2D2A24;word-break:break-all;">${href}</div>
171
+ </td></tr>
172
+ <tr><td style="padding:24px 32px 32px 32px;font-family:${sans};">
173
+ <div style="height:1px;background:#EEEBE4;font-size:0;line-height:0;">&nbsp;</div>
174
+ <p style="margin:20px 0 0 0;font-size:12px;line-height:1.6;color:#756F65;">Someone asked for a sign-in link for this address. If that was not you, ignore this email. Nobody can sign in without the link.</p>
175
+ <p style="margin:12px 0 0 0;font-size:12px;line-height:1.6;color:#756F65;">OpenNeko · AI that helps run your business.</p>
176
+ </td></tr>
177
+ </table>
178
+ </td></tr>
179
+ </table>
180
+ </body>
181
+ </html>`;
182
+ }
183
+ function escapeHtml(value) {
184
+ return value
185
+ .replaceAll("&", "&amp;")
186
+ .replaceAll("<", "&lt;")
187
+ .replaceAll(">", "&gt;")
188
+ .replaceAll('"', "&quot;");
189
+ }
190
+ //# sourceMappingURL=email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.js","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,MAAM,UAAU,eAAe,CAAC,GAAgB;IAI9C,MAAM,UAAU,GAAG;QACjB,GAAG,CAAC,YAAY,IAAK,QAAkB;QACvC,GAAG,CAAC,mBAAmB,IAAK,UAAoB;QAChD,GAAG,CAAC,cAAc,IAAK,UAAoB;KAC5C,CAAC,MAAM,CAAC,CAAC,KAAK,EAA+C,EAAE,CAC9D,OAAO,CAAC,KAAK,CAAC,CACf,CAAC;IACF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,sGAAsG,CACvG,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,wCAAwC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAC3F,CAAC;IACJ,CAAC;IACD,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;QACrB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,EA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IAAI,EAAE,UAAU,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;KAC3C,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CAAC,KAAuD;IACzE,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,+EAA+E,CAAC;IAC7F,MAAM,IAAI,GAAG,wEAAwE,CAAC;IACtF,OAAO;;;;;;;;;;uGAU8F,OAAO;;;;wDAItD,IAAI;;;sDAGN,IAAI;;2JAEiG,OAAO;;;;;WAKvJ,IAAI,+DAA+D,IAAI;;0CAExC,IAAI,uFAAuF,OAAO;;sDAEtF,IAAI;;2GAEiD,IAAI,wEAAwE,IAAI;;yDAElI,IAAI;;;;;;;;;QASrD,CAAC;AACT,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK;SACT,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @open-neko/plugin-magic-link — passwordless email sign-in.
3
+ *
4
+ * Implements OpenNeko's auth contract with `provisioning: "manual"`:
5
+ * the core only starts this flow for emails an admin pre-provisioned,
6
+ * and never creates users from it. This plugin's job is narrow —
7
+ * mint a signed token, email the link, verify the token on callback:
8
+ *
9
+ * begin_auth → HMAC-sign {email, state, expiry}, email the link
10
+ * `${redirectUri}?code=<token>&state=<state>`, and
11
+ * point the browser at the "check your email" notice.
12
+ * complete_auth → verify signature + expiry + state binding, return
13
+ * the identity (groups always empty — role and
14
+ * access assignment is the core's job, and nothing
15
+ * self-asserted should influence it).
16
+ *
17
+ * Single-use and same-browser properties come from the core's
18
+ * read-and-clear state cookie; see token.ts for the exact argument.
19
+ */
20
+ import { type BeginAuthParams, type BeginAuthResult, type CompleteAuthParams, type CompleteAuthResult } from "@open-neko/plugin-types";
21
+ import { type EmailSender } from "./email.js";
22
+ export declare class MagicLinkPluginError extends Error {
23
+ readonly cause?: unknown | undefined;
24
+ constructor(message: string, cause?: unknown | undefined);
25
+ }
26
+ /** Test seam: inject a fake sender / clock instead of the real ones. */
27
+ export interface InvokeOptions {
28
+ send?: EmailSender;
29
+ nowMs?: number;
30
+ }
31
+ export declare function runBeginAuth(params: BeginAuthParams, options?: InvokeOptions): Promise<BeginAuthResult>;
32
+ export declare function runCompleteAuth(params: CompleteAuthParams, options?: InvokeOptions): Promise<CompleteAuthResult>;
33
+ declare const _default: import("@open-neko/plugin-types").PluginDefinition;
34
+ export default _default;
35
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAqC,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAQjF,qBAAa,oBAAqB,SAAQ,KAAK;aACS,KAAK,CAAC,EAAE,OAAO;gBAAzD,OAAO,EAAE,MAAM,EAA2B,KAAK,CAAC,EAAE,OAAO,YAAA;CAItE;AAED,wEAAwE;AACxE,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA0BD,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,eAAe,CAAC,CAwD1B;AAED,wBAAsB,eAAe,CACnC,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAyB7B;;AAED,wBAUG"}