@talajs/auth 0.0.0-stage → 0.2.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
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,78 @@
1
- # Temporary Holding Version
1
+ # @talajs/auth
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional built-in sign-in for the people who run a business on Tala: owners, managers and staff. Powered by [Better Auth](https://better-auth.com), running on Tala's own database client, inside your Worker.
4
+
5
+ - **Magic link by default.** People sign in with a link emailed to them. It needs no password hashing, so it runs on Workers Free.
6
+ - **Email and password, opt in.** Includes email confirmation and reset. Secure password hashing needs more CPU per request than Workers Free allows, so turn it on with Workers Paid.
7
+ - **Google, opt in.**
8
+ - **Invite-only.** Nobody can create an account without a pending invitation, unless you enable self-serve businesses.
9
+ - **Revocation is immediate.** Sessions live in the database, with no cookie cache: signing out everywhere, a password reset or a removed membership take effect on the next request.
10
+ - **Rate limited without extra infrastructure.** An atomic Postgres counter, keyed on Cloudflare's `cf-connecting-ip`, plus per-email limits on outgoing links.
11
+
12
+ Better Auth only answers *who is this person*. What they may do is decided by their Tala membership (OWNER, MANAGER or STAFF, and which stores), as for every other identity source.
13
+
14
+ ```ts
15
+ import { createTalaApp } from '@talajs/api'
16
+ import { serviceToken } from '@talajs/api/auth/service-token'
17
+ import { resend } from '@talajs/api/email/resend'
18
+ import { createTalaAuth } from '@talajs/auth'
19
+ import { createDb } from '@talajs/db'
20
+ import { Hono } from 'hono'
21
+
22
+ const db = (env: Env) => createDb({ url: env.DATABASE_URL }) // or env.HYPERDRIVE.connectionString
23
+ const mailer = (env: Env) => resend({ apiKey: env.RESEND_API_KEY, from: 'Café <hello@cafe.example>' })
24
+
25
+ const auth = createTalaAuth<Env>({
26
+ db,
27
+ secret: (env) => env.BETTER_AUTH_SECRET, // wrangler secret put BETTER_AUTH_SECRET
28
+ baseURL: (env) => `${env.PUBLIC_ORIGIN}/tala/auth`,
29
+ mailer,
30
+ appName: 'Café',
31
+ methods: { magicLink: true, password: false }, // password: Workers Paid
32
+ })
33
+
34
+ const app = new Hono<{ Bindings: Env }>()
35
+ app.on(['GET', 'POST'], '/tala/auth/*', (c) => auth.handler(c.req.raw, c.env, c.executionCtx))
36
+ app.route('/tala', createTalaApp<Env>({
37
+ db,
38
+ auth: [auth.adapter, serviceToken({ token: (env) => env.TALA_SERVICE_TOKEN })],
39
+ invitations: { acceptUrl: (token, env) => `${env.PUBLIC_ORIGIN}/admin/invite/${token}`, mailer },
40
+ }))
41
+ ```
42
+
43
+ Serve the admin with `auth: { mode: 'better-auth', methods: { magicLink: true, password: false } }` in its runtime config (match `methods`), on the same origin.
44
+
45
+ ## Setup
46
+
47
+ 1. **Migrate.** `tala-db migrate` creates Better Auth's tables in the `tala_auth` schema (migration `0002`). People and sessions aren't tenant data, so they live apart from the `tala` schema.
48
+ 2. **Secret.** `BETTER_AUTH_SECRET`: at least 32 random characters (`openssl rand -base64 32`). To rotate it without signing everyone out, see Better Auth's `BETTER_AUTH_SECRETS`.
49
+ 3. **Email.** A mailer is required: without email nobody can sign in. Any `Mailer` from `@talajs/api` works; `resend()` is built in.
50
+ 4. **Origins.** `baseURL`'s origin is trusted for CSRF checks. List any other origin that calls the handler in `trustedOrigins`.
51
+ 5. **The first owner.** Provision a business with a service token (`POST /tala/v1/tenants`) and invite its owner (`POST /tala/v1/tenants/{id}/invitations` with `role: "OWNER"`). Or set `allowSelfServeTenants: true` on both `createTalaAuth` and `createTalaApp` to let anyone with a verified email create a business.
52
+
53
+ ## Options
54
+
55
+ | Option | |
56
+ |---|---|
57
+ | `db` | The same per-request client factory as `createTalaApp`. |
58
+ | `secret` | `BETTER_AUTH_SECRET`. |
59
+ | `baseURL` | Public URL of the handler; its path is the mount point. |
60
+ | `trustedOrigins` | Other origins allowed to call the handler. |
61
+ | `mailer` | Sends sign-in links, confirmations and resets. |
62
+ | `appName`, `renderEmail` | Branding for the emails. |
63
+ | `methods` | `{ magicLink = true, password = false, google? }`. `google` takes `{ clientId, clientSecret }`. |
64
+ | `allowSelfServeTenants` | Let anyone sign up. Match `createTalaApp`. Default off: invite only. |
65
+ | `bearer` | Accept the session token as `Authorization: Bearer` (clients without cookies). Default off. |
66
+ | `configure` | Last word on the Better Auth options, for anything else. |
67
+
68
+ The adapter's identity is `{ kind: 'staff', subject: 'ba:<user id>', email, emailVerified, name }`. The `ba:` prefix can't collide with Cloudflare Access emails or OIDC subjects.
69
+
70
+ ## Operators and Cloudflare Access
71
+
72
+ Don't put a Cloudflare Access application in front of the paths merchants use (`/admin`, `/tala`): they could never reach the sign-in screen. Route a second hostname to the same Worker for operators and protect that one with Access. Keep `cloudflareAccess()` in the adapter list; it only matches requests that carry an Access token. [`examples/worker`](../../examples/worker) does exactly this.
73
+
74
+ ## Notes
75
+
76
+ - One Better Auth instance is created per request, on that request's database client. Workers can't share database connections between requests, even through Hyperdrive.
77
+ - Better Auth requires Prisma 7; Tala stays on Prisma 7 until Better Auth supports 8.
78
+ - Tested in workerd with node-postgres through Hyperdrive. The Neon serverless driver sits below Prisma, so Better Auth sees the same client either way.
@@ -0,0 +1,16 @@
1
+ export interface AuthEmail {
2
+ subject: string;
3
+ html: string;
4
+ text: string;
5
+ }
6
+ export type AuthEmailKind = 'magic-link' | 'verify-email' | 'reset-password';
7
+ export interface AuthEmailData {
8
+ kind: AuthEmailKind;
9
+ to: string;
10
+ url: string;
11
+ /** `appName` from the options, e.g. the café's name. */
12
+ appName: string;
13
+ }
14
+ /** Plain sign-in emails. Pass `renderEmail` to `createTalaAuth` to brand them. */
15
+ export declare function renderAuthEmail({ kind, url, appName }: AuthEmailData): AuthEmail;
16
+ //# sourceMappingURL=emails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emails.d.ts","sourceRoot":"","sources":["../src/emails.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,cAAc,GAAG,gBAAgB,CAAA;AAE5E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,aAAa,CAAA;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAA;CAChB;AA8BD,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,aAAa,GAAG,SAAS,CAWhF"}
package/dist/emails.js ADDED
@@ -0,0 +1,35 @@
1
+ const escapeHtml = (s) => s.replace(/[&<>"']/g, (ch) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[ch] ?? ch);
2
+ const COPY = {
3
+ 'magic-link': {
4
+ subject: 'Your sign-in link',
5
+ lead: 'Use this link to sign in.',
6
+ button: 'Sign in',
7
+ tail: "It works once and expires in 5 minutes. If you didn't ask for it, you can ignore this email.",
8
+ },
9
+ 'verify-email': {
10
+ subject: 'Confirm your email',
11
+ lead: 'Confirm this is your email address.',
12
+ button: 'Confirm email',
13
+ tail: "If you didn't create an account, you can ignore this email.",
14
+ },
15
+ 'reset-password': {
16
+ subject: 'Reset your password',
17
+ lead: 'Use this link to choose a new password. Resetting signs you out everywhere.',
18
+ button: 'Reset password',
19
+ tail: "It expires in 1 hour. If you didn't ask for it, you can ignore this email.",
20
+ },
21
+ };
22
+ /** Plain sign-in emails. Pass `renderEmail` to `createTalaAuth` to brand them. */
23
+ export function renderAuthEmail({ kind, url, appName }) {
24
+ const copy = COPY[kind];
25
+ const subject = `${appName}: ${copy.subject}`;
26
+ const text = `${copy.lead}\n\n${url}\n\n${copy.tail}`;
27
+ const html = `<!doctype html><html><body style="font-family:system-ui,sans-serif;max-width:480px;margin:auto;padding:24px;color:#111">
28
+ <p><strong>${escapeHtml(appName)}</strong></p>
29
+ <p>${escapeHtml(copy.lead)}</p>
30
+ <p><a href="${escapeHtml(url)}" style="display:inline-block;padding:10px 16px;background:#111;color:#fff;border-radius:6px;text-decoration:none">${escapeHtml(copy.button)}</a></p>
31
+ <p style="color:#555;font-size:14px">${escapeHtml(copy.tail)}</p>
32
+ </body></html>`;
33
+ return { subject, html, text };
34
+ }
35
+ //# sourceMappingURL=emails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emails.js","sourceRoot":"","sources":["../src/emails.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE,CAC/B,CAAC,CAAC,OAAO,CACP,UAAU,EACV,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAC5F,CAAA;AAEH,MAAM,IAAI,GACR;IACE,YAAY,EAAE;QACZ,OAAO,EAAE,mBAAmB;QAC5B,IAAI,EAAE,2BAA2B;QACjC,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,8FAA8F;KACrG;IACD,cAAc,EAAE;QACd,OAAO,EAAE,oBAAoB;QAC7B,IAAI,EAAE,qCAAqC;QAC3C,MAAM,EAAE,eAAe;QACvB,IAAI,EAAE,6DAA6D;KACpE;IACD,gBAAgB,EAAE;QAChB,OAAO,EAAE,qBAAqB;QAC9B,IAAI,EAAE,6EAA6E;QACnF,MAAM,EAAE,gBAAgB;QACxB,IAAI,EAAE,4EAA4E;KACnF;CACF,CAAA;AAEH,kFAAkF;AAClF,MAAM,UAAU,eAAe,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAiB;IACnE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;IACvB,MAAM,OAAO,GAAG,GAAG,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE,CAAA;IAC7C,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,EAAE,CAAA;IACrD,MAAM,IAAI,GAAG;aACF,UAAU,CAAC,OAAO,CAAC;KAC3B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;cACZ,UAAU,CAAC,GAAG,CAAC,sHAAsH,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;uCACnI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;eAC7C,CAAA;IACb,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AAChC,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { type Configurable, type Identity, type Mailer } from '@talajs/api';
2
+ import type { TalaDb } from '@talajs/db';
3
+ import { type BetterAuthOptions } from 'better-auth';
4
+ import { type AuthEmailData } from './emails.js';
5
+ export { type AuthEmail, type AuthEmailData, type AuthEmailKind, renderAuthEmail, } from './emails.js';
6
+ export interface GoogleOptions {
7
+ clientId: string;
8
+ clientSecret: string;
9
+ }
10
+ export interface TalaAuthOptions<E> {
11
+ /** The same per-request client factory you give `createTalaApp`. */
12
+ db: (env: E) => TalaDb;
13
+ /** `BETTER_AUTH_SECRET`: at least 32 random characters. Signs cookies and tokens. */
14
+ secret: Configurable<string, E>;
15
+ /**
16
+ * The public URL the handler is mounted at, e.g. `https://cafe.example/tala/auth`. Its origin
17
+ * is trusted for CSRF checks and its path is the base path.
18
+ */
19
+ baseURL: Configurable<string, E>;
20
+ /** Other origins allowed to call the handler (the same origin always is). */
21
+ trustedOrigins?: Configurable<string[], E>;
22
+ /** Sends sign-in links, email confirmations and password resets. */
23
+ mailer: Configurable<Mailer, E>;
24
+ /** Shown in emails, e.g. your business name. Default "Sign in". */
25
+ appName?: string;
26
+ renderEmail?: (data: AuthEmailData) => {
27
+ subject: string;
28
+ html: string;
29
+ text: string;
30
+ };
31
+ methods?: {
32
+ /** Email sign-in links. Default on; needs no password hashing, so it runs on Workers Free. */
33
+ magicLink?: boolean;
34
+ /**
35
+ * Email and password, with email confirmation and reset. Default off: secure password hashing
36
+ * needs more CPU than Workers Free allows per request, so enable it on Workers Paid.
37
+ */
38
+ password?: boolean;
39
+ /** Sign in with Google. Off unless configured. */
40
+ google?: Configurable<GoogleOptions | undefined, E>;
41
+ };
42
+ /**
43
+ * Who may create an account. By default only people with a pending invitation, so nobody can
44
+ * sign up to an empty account. Set it to match `createTalaApp`'s `allowSelfServeTenants`.
45
+ */
46
+ allowSelfServeTenants?: boolean;
47
+ /** Accept the session token as `Authorization: Bearer` for clients without cookies. Default off. */
48
+ bearer?: boolean;
49
+ /** Final say over the Better Auth options, for anything not covered here. */
50
+ configure?: (options: BetterAuthOptions, env: E) => BetterAuthOptions;
51
+ }
52
+ /** Adapter subjects are `ba:<user id>`, which can't collide with Access emails or OIDC subjects. */
53
+ export declare const SUBJECT_PREFIX = "ba:";
54
+ export declare function createTalaAuth<E>(options: TalaAuthOptions<E>): {
55
+ /**
56
+ * Serve Better Auth's endpoints. Mount at the `baseURL` path:
57
+ *
58
+ * app.on(['GET', 'POST'], '/tala/auth/*', (c) => auth.handler(c.req.raw, c.env, c.executionCtx))
59
+ */
60
+ handler(request: Request, env: E, ctx?: {
61
+ waitUntil(promise: Promise<unknown>): void;
62
+ }): Promise<Response>;
63
+ /** For `createTalaApp({ auth: [auth.adapter, …] })`: a signed-in person, from the session cookie. */
64
+ adapter: {
65
+ name: string;
66
+ authenticate(c: import("@talajs/api").TalaContext<E>): Promise<Identity | null>;
67
+ };
68
+ /** A Better Auth instance for server-side calls (`auth.api.*`) within one request. */
69
+ instance: (env: E, db: TalaDb) => import("better-auth").Auth<BetterAuthOptions>;
70
+ };
71
+ export type TalaAuth<E> = ReturnType<typeof createTalaAuth<E>>;
72
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAGjB,KAAK,QAAQ,EACb,KAAK,MAAM,EACZ,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAY,KAAK,iBAAiB,EAAc,MAAM,aAAa,CAAA;AAG1E,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,aAAa,CAAA;AAEjE,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,eAAe,GAChB,MAAM,aAAa,CAAA;AAKpB,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,oEAAoE;IACpE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAA;IACtB,qFAAqF;IACrF,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IAC/B;;;OAGG;IACH,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IAChC,6EAA6E;IAC7E,cAAc,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAA;IAC1C,oEAAoE;IACpE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IAC/B,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACtF,OAAO,CAAC,EAAE;QACR,8FAA8F;QAC9F,SAAS,CAAC,EAAE,OAAO,CAAA;QACnB;;;WAGG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,kDAAkD;QAClD,MAAM,CAAC,EAAE,YAAY,CAAC,aAAa,GAAG,SAAS,EAAE,CAAC,CAAC,CAAA;KACpD,CAAA;IACD;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,oGAAoG;IACpG,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC,KAAK,iBAAiB,CAAA;CACtE;AAED,oGAAoG;AACpG,eAAO,MAAM,cAAc,QAAQ,CAAA;AAanC,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;IA6FzD;;;;OAIG;qBAEQ,OAAO,OACX,CAAC,QACA;QAAE,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;KAAE,GACnD,OAAO,CAAC,QAAQ,CAAC;IAWpB,qGAAqG;;;+DAG5E,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;;IAoBjD,sFAAsF;oBACtE,CAAC,MAAM,MAAM;EAEhC;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,158 @@
1
+ import { consumeRateLimit, hasPendingInvitation, } from '@talajs/api';
2
+ import { uuidv7 } from '@talajs/contracts';
3
+ import { APIError, betterAuth } from 'better-auth';
4
+ import { prismaAdapter } from 'better-auth/adapters/prisma';
5
+ import { bearer, magicLink } from 'better-auth/plugins';
6
+ import { renderAuthEmail } from './emails.js';
7
+ export { renderAuthEmail, } from './emails.js';
8
+ const resolve = (value, env) => typeof value === 'function' ? value(env) : value;
9
+ /** Adapter subjects are `ba:<user id>`, which can't collide with Access emails or OIDC subjects. */
10
+ export const SUBJECT_PREFIX = 'ba:';
11
+ /** Per-IP rules on the handler's endpoints (seconds, requests). */
12
+ const RULES = {
13
+ '/sign-in/*': { window: 60, max: 5 },
14
+ '/sign-up/*': { window: 60, max: 3 },
15
+ '/request-password-reset': { window: 600, max: 3 },
16
+ '/send-verification-email': { window: 600, max: 3 },
17
+ '/magic-link/verify': { window: 60, max: 10 },
18
+ };
19
+ /** Per-email limit on outgoing links, on top of the per-IP rules. */
20
+ const PER_EMAIL = { window: 600, max: 3 };
21
+ export function createTalaAuth(options) {
22
+ const appName = options.appName ?? 'Sign in';
23
+ const render = options.renderEmail ?? renderAuthEmail;
24
+ const methods = { magicLink: true, password: false, ...options.methods };
25
+ function build(env, db) {
26
+ const mailer = resolve(options.mailer, env);
27
+ async function sendLink(kind, to, url) {
28
+ // Quietly drop links past the per-email limit: an error would tell a stranger which
29
+ // addresses have accounts, and the owner of the inbox already has a recent link.
30
+ const limit = await consumeRateLimit(db, `email:${kind}:${to.toLowerCase()}`, PER_EMAIL);
31
+ if (!limit.allowed)
32
+ return;
33
+ await mailer.send({ to, ...render({ kind, to, url, appName }) });
34
+ }
35
+ const baseURL = resolve(options.baseURL, env);
36
+ const google = methods.google ? resolve(methods.google, env) : undefined;
37
+ const plugins = [];
38
+ if (methods.magicLink) {
39
+ plugins.push(magicLink({ sendMagicLink: ({ email, url }) => sendLink('magic-link', email, url) }));
40
+ }
41
+ if (options.bearer)
42
+ plugins.push(bearer());
43
+ const config = {
44
+ appName,
45
+ secret: resolve(options.secret, env),
46
+ baseURL,
47
+ basePath: new URL(baseURL).pathname,
48
+ trustedOrigins: options.trustedOrigins ? resolve(options.trustedOrigins, env) : [],
49
+ database: prismaAdapter(db.client, { provider: 'postgresql' }),
50
+ user: { modelName: 'authUser' },
51
+ session: {
52
+ modelName: 'authSession',
53
+ // Off, so a revoked session or membership stops working on the very next request.
54
+ cookieCache: { enabled: false },
55
+ },
56
+ account: { modelName: 'authAccount', accountLinking: { enabled: true } },
57
+ verification: { modelName: 'authVerification' },
58
+ emailAndPassword: {
59
+ enabled: methods.password,
60
+ requireEmailVerification: true,
61
+ revokeSessionsOnPasswordReset: true,
62
+ sendResetPassword: ({ user, url }) => sendLink('reset-password', user.email, url),
63
+ },
64
+ emailVerification: {
65
+ sendOnSignUp: true,
66
+ autoSignInAfterVerification: true,
67
+ sendVerificationEmail: ({ user, url }) => sendLink('verify-email', user.email, url),
68
+ },
69
+ ...(google ? { socialProviders: { google } } : {}),
70
+ databaseHooks: {
71
+ user: {
72
+ create: {
73
+ async before(user) {
74
+ if (options.allowSelfServeTenants)
75
+ return;
76
+ if (await hasPendingInvitation(db, user.email))
77
+ return;
78
+ throw new APIError('FORBIDDEN', {
79
+ code: 'INVITE_REQUIRED',
80
+ message: 'Ask your manager for an invitation to sign up',
81
+ });
82
+ },
83
+ },
84
+ },
85
+ },
86
+ rateLimit: {
87
+ enabled: true,
88
+ window: 60,
89
+ max: 60,
90
+ customRules: RULES,
91
+ customStorage: {
92
+ consume: async (key, rule) => {
93
+ const result = await consumeRateLimit(db, `auth:${key}`, rule);
94
+ return {
95
+ allowed: result.allowed,
96
+ retryAfter: result.allowed ? null : result.retryAfter,
97
+ };
98
+ },
99
+ },
100
+ },
101
+ advanced: {
102
+ cookiePrefix: 'tala',
103
+ ipAddress: { ipAddressHeaders: ['cf-connecting-ip'] },
104
+ database: { generateId: () => uuidv7() },
105
+ },
106
+ telemetry: { enabled: false },
107
+ plugins,
108
+ };
109
+ return betterAuth(options.configure ? options.configure(config, env) : config);
110
+ }
111
+ return {
112
+ /**
113
+ * Serve Better Auth's endpoints. Mount at the `baseURL` path:
114
+ *
115
+ * app.on(['GET', 'POST'], '/tala/auth/*', (c) => auth.handler(c.req.raw, c.env, c.executionCtx))
116
+ */
117
+ async handler(request, env, ctx) {
118
+ const db = options.db(env);
119
+ try {
120
+ return await build(env, db).handler(request);
121
+ }
122
+ finally {
123
+ const done = db.dispose();
124
+ if (ctx)
125
+ ctx.waitUntil(done);
126
+ else
127
+ await done;
128
+ }
129
+ },
130
+ /** For `createTalaApp({ auth: [auth.adapter, …] })`: a signed-in person, from the session cookie. */
131
+ adapter: {
132
+ name: 'better-auth',
133
+ async authenticate(c) {
134
+ const headers = c.req.raw.headers;
135
+ const cookie = headers.get('cookie') ?? '';
136
+ const hasCookie = cookie.includes('tala.session_token=');
137
+ const hasBearer = options.bearer && /^bearer\s/i.test(headers.get('authorization') ?? '');
138
+ if (!hasCookie && !hasBearer)
139
+ return null;
140
+ const session = await build(c.env, c.get('db')).api.getSession({ headers });
141
+ if (!session)
142
+ return null;
143
+ const { user } = session;
144
+ return {
145
+ kind: 'staff',
146
+ subject: `${SUBJECT_PREFIX}${user.id}`,
147
+ email: user.email.toLowerCase(),
148
+ emailVerified: user.emailVerified,
149
+ name: user.name || undefined,
150
+ claims: { sessionId: session.session.id },
151
+ };
152
+ },
153
+ },
154
+ /** A Better Auth instance for server-side calls (`auth.api.*`) within one request. */
155
+ instance: (env, db) => build(env, db),
156
+ };
157
+ }
158
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,EAChB,oBAAoB,GAGrB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAA0B,UAAU,EAAE,MAAM,aAAa,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAsB,eAAe,EAAE,MAAM,aAAa,CAAA;AAEjE,OAAO,EAIL,eAAe,GAChB,MAAM,aAAa,CAAA;AAEpB,MAAM,OAAO,GAAG,C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AAC,IAAI,IAAI,SAAS;oBAC5B,MAAM,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE;iBAC1C,CAAA;YACH,CAAC;SACuB;QAE1B,sFAAsF;QACtF,QAAQ,EAAE,CAAC,GAAM,EAAE,EAAU,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC;KACjD,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@talajs/auth",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Optional built-in sign-in for Tala merchants and staff (magic link, password, Google), powered by Better Auth.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://github.com/NovaDovaDao/talajs/tree/main/packages/auth#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/NovaDovaDao/talajs/issues"
9
+ },
10
+ "keywords": [
11
+ "better-auth",
12
+ "auth",
13
+ "magic-link",
14
+ "cloudflare-workers",
15
+ "pos",
16
+ "commerce"
17
+ ],
18
+ "type": "module",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/NovaDovaDao/talajs.git",
22
+ "directory": "packages/auth"
23
+ },
24
+ "sideEffects": false,
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "dependencies": {
35
+ "better-auth": "1.7.27",
36
+ "@talajs/contracts": "0.2.0",
37
+ "@talajs/api": "0.2.0",
38
+ "@talajs/db": "0.2.0"
39
+ },
40
+ "devDependencies": {
41
+ "@cloudflare/vitest-plugin": "1.8.2",
42
+ "@cloudflare/workers-types": "^5.20261118.1",
43
+ "@types/pg": "^8.23.1",
44
+ "hono": "^4.13.18",
45
+ "pg": "^8.23.1",
46
+ "wrangler": "4.162.0"
47
+ },
48
+ "engines": {
49
+ "node": ">=22"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "scripts": {
55
+ "build": "tsc -p tsconfig.build.json",
56
+ "typecheck": "tsc --noEmit",
57
+ "test": "vitest run"
58
+ }
6
59
  }