@auth/edgedb-adapter 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,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2022-2023, Balázs Orbán
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ <p align="center">
2
+ <br/>
3
+ <a href="https://authjs.dev" target="_blank">
4
+ <img height="64px" src="https://authjs.dev/img/logo/logo-sm.png" />
5
+ </a>
6
+ <a href="https://www.edgedb.com/" target="_blank">
7
+ <img height="64px" src="https://authjs.dev/img/adapters/edgedb.svg"/>
8
+ </a>
9
+ <h3 align="center"><b>Edge DB Adapter</b> - NextAuth.js / Auth.js</a></h3>
10
+ <p align="center" style="align: center;">
11
+ <a href="https://npm.im/@auth/edgedb-adapter">
12
+ <img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
13
+ </a>
14
+ <a href="https://npm.im/@auth/edgedb-adapter">
15
+ <img alt="npm" src="https://img.shields.io/npm/v/@auth/edgedb-adapter?color=green&label=@auth/edgedb-adapter&style=flat-square">
16
+ </a>
17
+ <a href="https://www.npmtrends.com/@auth/edgedb-adapter">
18
+ <img src="https://img.shields.io/npm/dm/@auth/edgedb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
19
+ </a>
20
+ <a href="https://github.com/nextauthjs/next-auth/stargazers">
21
+ <img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="Github Stars" />
22
+ </a>
23
+ </p>
24
+ </p>
25
+
26
+ ---
27
+
28
+ Check out the documentation at [authjs.dev](https://authjs.dev/reference/adapter/edgedb).
package/index.d.ts ADDED
@@ -0,0 +1,286 @@
1
+ /**
2
+ * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: 16}}>
3
+ * <p style={{fontWeight: "normal"}}>Official <a href="https://www.edgedb.com/">Edge DB</a> adapter for Auth.js / NextAuth.js.</p>
4
+ * <a href="https://www.edgedb.com/">
5
+ * <img style={{display: "block"}} src="/img/adapters/edgedb.svg" width="38" />
6
+ * </a>
7
+ * </div>
8
+ *
9
+ * ## Installation
10
+ *
11
+ * ```bash npm2yarn2pnpm
12
+ * npm install edgedb @auth/edgedb-adapter
13
+ * npm install @edgedb/generate --save-dev
14
+ * ```
15
+ *
16
+ * @module @auth/edgedb-adapter
17
+ */
18
+ import type { Adapter } from "@auth/core/adapters";
19
+ import type { Client } from "edgedb";
20
+ /**
21
+ *
22
+ * To use this Adapter, you need to install `edgedb`, `@edgedb/generate`, and the separate `@auth/edgedb-adapter` package:
23
+ *
24
+ * ```bash npm2yarn2pnpm
25
+ * npm install edgedb @auth/edgedb-adapter
26
+ * npm install @edgedb/generate --save-dev
27
+ * ```
28
+ *
29
+ * ## Installation
30
+ *
31
+ * First, ensure you have the EdgeDB CLI installed.
32
+ *
33
+ * Follow the instructions below, or read the [EdgeDB quickstart](https://www.edgedb.com/docs/intro/quickstart) to install the EdgeDB CLI and initialize a project
34
+ *
35
+ * ### Linux or macOS
36
+ * ```bash
37
+ * curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
38
+ * ```
39
+ *
40
+ * ### Windows
41
+ * ```powershell
42
+ * iwr https://ps1.edgedb.com -useb | iex
43
+ * ```
44
+ *
45
+ * Check that the CLI is available with the `edgedb --version` command. If you get a `Command not found` error, you may need to open a new terminal window before the `edgedb` command is available.
46
+ *
47
+ * Once the CLI is installed, initialize a project from the application’s root directory. You’ll be presented with a series of prompts.
48
+ *
49
+ * ```bash
50
+ * edgedb project init
51
+ * ```
52
+ *
53
+ * This process will spin up an EdgeDB instance and [“link”](https://www.edgedb.com/docs/cli/edgedb_instance/edgedb_instance_link#edgedb-instance-link) it with your current directory. As long as you’re inside that directory, CLI commands and client libraries will be able to connect to the linked instance automatically, without additional configuration.
54
+ *
55
+ * ## Setup
56
+ *
57
+ * ### NextAuth.js configuration
58
+ *
59
+ * Configure your NextAuth.js to use the EdgeDB Adapter:
60
+ *
61
+ * ```javascript title="pages/api/auth/[...nextauth].js"
62
+ * import NextAuth from "next-auth"
63
+ * import GoogleProvider from "next-auth/providers/google"
64
+ * import { EdgeDBAdapter } from "@auth/edgedb-adapter"
65
+ * import { createClient } from "edgedb"
66
+ *
67
+ * const client = createClient()
68
+ *
69
+ * export default NextAuth({
70
+ * adapter: EdgeDBAdapter(client),
71
+ * providers: [
72
+ * GoogleProvider({
73
+ * clientId: process.env.GOOGLE_CLIENT_ID,
74
+ * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
75
+ * }),
76
+ * ],
77
+ * })
78
+ * ```
79
+ *
80
+ * ### Create the EdgeDB schema
81
+ *
82
+ * Replace the contents of the auto-generated file in `dbschema/default.esdl` with the following:
83
+ *
84
+ * > This schema is adapted for use in EdgeDB and based upon our main [schema](/adapters/models)
85
+ *
86
+ * ```json title="default.esdl"
87
+ * module default {
88
+ * type User {
89
+ * property name -> str;
90
+ * required property email -> str {
91
+ * constraint exclusive;
92
+ * }
93
+ * property emailVerified -> datetime;
94
+ * property image -> str;
95
+ * multi link accounts := .<user[is Account];
96
+ * multi link sessions := .<user[is Session];
97
+ * property createdAt -> datetime {
98
+ * default := datetime_current();
99
+ * };
100
+ * }
101
+ *
102
+ * type Account {
103
+ * required property userId := .user.id;
104
+ * required property type -> str;
105
+ * required property provider -> str;
106
+ * required property providerAccountId -> str {
107
+ * constraint exclusive;
108
+ * };
109
+ * property refresh_token -> str;
110
+ * property access_token -> str;
111
+ * property expires_at -> int64;
112
+ * property token_type -> str;
113
+ * property scope -> str;
114
+ * property id_token -> str;
115
+ * property session_state -> str;
116
+ * required link user -> User {
117
+ * on target delete delete source;
118
+ * };
119
+ * property createdAt -> datetime {
120
+ * default := datetime_current();
121
+ * };
122
+ *
123
+ * constraint exclusive on ((.provider, .providerAccountId))
124
+ * }
125
+ *
126
+ * type Session {
127
+ * required property sessionToken -> str {
128
+ * constraint exclusive;
129
+ * }
130
+ * required property userId := .user.id;
131
+ * required property expires -> datetime;
132
+ * required link user -> User {
133
+ * on target delete delete source;
134
+ * };
135
+ * property createdAt -> datetime {
136
+ * default := datetime_current();
137
+ * };
138
+ * }
139
+ *
140
+ * type VerificationToken {
141
+ * required property identifier -> str;
142
+ * required property token -> str {
143
+ * constraint exclusive;
144
+ * }
145
+ * required property expires -> datetime;
146
+ * property createdAt -> datetime {
147
+ * default := datetime_current();
148
+ * };
149
+ *
150
+ * constraint exclusive on ((.identifier, .token))
151
+ * }
152
+ * }
153
+ *
154
+ * # Disable the application of access policies within access policies
155
+ * # themselves. This behavior will become the default in EdgeDB 3.0.
156
+ * # See: https://www.edgedb.com/docs/reference/ddl/access_policies#nonrecursive
157
+ * using future nonrecursive_access_policies;
158
+ * ```
159
+ *
160
+ * ### Migrate the database schema
161
+ *
162
+ * Create a migration
163
+ *
164
+ * ```
165
+ * edgedb migration create
166
+ * ```
167
+ *
168
+ * Apply the migration
169
+ *
170
+ * ```
171
+ * edgedb migrate
172
+ * ```
173
+ *
174
+ * To learn more about [EdgeDB migrations](https://www.edgedb.com/docs/intro/migrations#generate-a-migration), check out the [Migrations docs](https://www.edgedb.com/docs/intro/migrations).
175
+ *
176
+ * ### Generate the query builder
177
+ *
178
+ * ```npm2yarn2pnpm
179
+ * npx @edgedb/generate edgeql-js
180
+ * ```
181
+ *
182
+ * This will generate the [query builder](https://www.edgedb.com/docs/clients/js/querybuilder) so that you can write fully typed EdgeQL queries with TypeScript in a code-first way.
183
+ *
184
+ * For example
185
+ *
186
+ * ```ts
187
+ * const query = e.select(e.User, () => ({
188
+ * id: true,
189
+ * email: true,
190
+ * emailVerified: true,
191
+ * name: true,
192
+ * image: true,
193
+ * filter_single: { email: 'johndoe@example.com' },
194
+ * }));
195
+ *
196
+ * return await query.run(client);
197
+ *
198
+ * // Return type:
199
+ * // {
200
+ * // id: string;
201
+ * // email: string;
202
+ * // emailVerified: Date | null;
203
+ * // image: string | null;
204
+ * // name: string | null;
205
+ * // } | null
206
+ *
207
+ * ```
208
+ *
209
+ *
210
+ * ## Deploying
211
+ *
212
+ * ### Deploy EdgeDB
213
+ *
214
+ * First deploy an EdgeDB instance on your preferred cloud provider:
215
+ *
216
+ * [AWS](https://www.edgedb.com/docs/guides/deployment/aws_aurora_ecs)
217
+ *
218
+ * [Google Cloud](https://www.edgedb.com/docs/guides/deployment/gcp)
219
+ *
220
+ * [Azure](https://www.edgedb.com/docs/guides/deployment/azure_flexibleserver)
221
+ *
222
+ * [DigitalOcean](https://www.edgedb.com/docs/guides/deployment/digitalocean)
223
+ *
224
+ * [Fly.io](https://www.edgedb.com/docs/guides/deployment/fly_io)
225
+ *
226
+ * [Docker](https://www.edgedb.com/docs/guides/deployment/docker) (cloud-agnostic)
227
+ *
228
+ * ### Find your instance’s DSN
229
+ *
230
+ * The DSN is also known as a connection string. It will have the format `edgedb://username:password@hostname:port`. The exact instructions for this depend on which cloud you are deploying to.
231
+ *
232
+ * ### Set an environment variable
233
+ *
234
+ * ```env title=".env"
235
+ * EDGEDB_DSN=edgedb://johndoe:supersecure@myhost.com:420
236
+ * ```
237
+ *
238
+ * ### Update the client
239
+ *
240
+ * ```diff title="pages/api/auth/[...nextauth].js"
241
+ * import NextAuth from "next-auth"
242
+ * import GoogleProvider from "next-auth/providers/google"
243
+ * import { EdgeDBAdapter } from "@auth/edgedb-adapter"
244
+ * import { createClient } from "edgedb"
245
+ *
246
+ * - const client = createClient()
247
+ * + const client = createClient({ dsn: process.env.EDGEDB_DSN })
248
+ *
249
+ * export default NextAuth({
250
+ * adapter: EdgeDBAdapter(client),
251
+ * providers: [
252
+ * GoogleProvider({
253
+ * clientId: process.env.GOOGLE_CLIENT_ID,
254
+ * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
255
+ * }),
256
+ * ],
257
+ * })
258
+ * ```
259
+ *
260
+ *
261
+ *
262
+ * ### Apply migrations
263
+ *
264
+ * Use the DSN to apply migrations against your remote instance.
265
+ *
266
+ * ```bash
267
+ * edgedb migrate --dsn <your-instance-dsn>
268
+ * ```
269
+ *
270
+ * ### Set up a `prebuild` script
271
+ *
272
+ * Add the following `prebuild` script to your `package.json`. When your hosting provider initializes the build, it will trigger this script which will generate the query builder. The `npx @edgedb/generate edgeql-js` command will read the value of the `EDGEDB_DSN` environment variable, connect to the database, and generate the query builder before your hosting provider starts building the project.
273
+ *
274
+ * ```diff title="package.json"
275
+ * "scripts": {
276
+ * "dev": "next dev",
277
+ * "build": "next build",
278
+ * "start": "next start",
279
+ * "lint": "next lint",
280
+ * + "prebuild": "npx @edgedb/generate edgeql-js"
281
+ * },
282
+ * ```
283
+ *
284
+ */
285
+ export declare function EdgeDBAdapter(client: Client): Adapter;
286
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,OAAO,EAIR,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwQG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAmUrD"}