@auth/dgraph-adapter 2.0.0 → 2.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/README.md +1 -1
- package/index.d.ts +6 -5
- package/index.d.ts.map +1 -1
- package/index.js +20 -4
- package/package.json +2 -2
- package/src/index.ts +48 -22
- package/lib/utils.d.ts +0 -4
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -22
- package/src/lib/utils.ts +0 -24
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<img src="https://img.shields.io/npm/dm/@auth/dgraph-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
|
|
19
19
|
</a>
|
|
20
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="
|
|
21
|
+
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="GitHub Stars" />
|
|
22
22
|
</a>
|
|
23
23
|
</p>
|
|
24
24
|
</p>
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export type { DgraphClientParams, DgraphClientError } from "./lib/client";
|
|
1
|
+
import { type Adapter } from "@auth/core/adapters";
|
|
2
|
+
import type { DgraphClientParams } from "./lib/client.js";
|
|
3
|
+
export type { DgraphClientParams, DgraphClientError } from "./lib/client.js";
|
|
5
4
|
/** This is the interface of the Dgraph adapter options. */
|
|
6
5
|
export interface DgraphAdapterOptions {
|
|
7
6
|
/**
|
|
@@ -18,6 +17,8 @@ export interface DgraphAdapterOptions {
|
|
|
18
17
|
VerificationToken?: string;
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
|
-
export { format };
|
|
22
20
|
export declare function DgraphAdapter(client: DgraphClientParams, options?: DgraphAdapterOptions): Adapter;
|
|
21
|
+
export declare const format: {
|
|
22
|
+
from<T>(object?: Record<string, any>): T | null;
|
|
23
|
+
};
|
|
23
24
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AASzD,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAE5E,2DAA2D;AAC3D,MAAM,WAAW,oBAAoB;IACnC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE;QACV,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAC3B,CAAA;CACF;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,kBAAkB,EAC1B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAyST;AAED,eAAO,MAAM,MAAM;qBACA,OAAO,MAAM,EAAE,GAAG,CAAC;CAcrC,CAAA"}
|
package/index.js
CHANGED
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @module @auth/dgraph-adapter
|
|
16
16
|
*/
|
|
17
|
-
import { client as dgraphClient } from "./lib/client";
|
|
18
|
-
import {
|
|
19
|
-
import * as defaultFragments from "./lib/graphql/fragments";
|
|
20
|
-
export { format };
|
|
17
|
+
import { client as dgraphClient } from "./lib/client.js";
|
|
18
|
+
import { isDate } from "@auth/core/adapters";
|
|
19
|
+
import * as defaultFragments from "./lib/graphql/fragments.js";
|
|
21
20
|
export function DgraphAdapter(client, options) {
|
|
22
21
|
const c = dgraphClient(client);
|
|
23
22
|
const fragments = { ...defaultFragments, ...options?.fragments };
|
|
@@ -265,3 +264,20 @@ export function DgraphAdapter(client, options) {
|
|
|
265
264
|
},
|
|
266
265
|
};
|
|
267
266
|
}
|
|
267
|
+
export const format = {
|
|
268
|
+
from(object) {
|
|
269
|
+
const newObject = {};
|
|
270
|
+
if (!object)
|
|
271
|
+
return null;
|
|
272
|
+
for (const key in object) {
|
|
273
|
+
const value = object[key];
|
|
274
|
+
if (isDate(value)) {
|
|
275
|
+
newObject[key] = new Date(value);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
newObject[key] = value;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return newObject;
|
|
282
|
+
},
|
|
283
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth/dgraph-adapter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Dgraph adapter for Auth.js",
|
|
5
5
|
"homepage": "https://authjs.dev",
|
|
6
6
|
"repository": "https://github.com/nextauthjs/next-auth",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"jsonwebtoken": "^9.0.0",
|
|
44
|
-
"@auth/core": "0.
|
|
44
|
+
"@auth/core": "0.32.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsc",
|
package/src/index.ts
CHANGED
|
@@ -14,13 +14,18 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @module @auth/dgraph-adapter
|
|
16
16
|
*/
|
|
17
|
-
import { client as dgraphClient } from "./lib/client"
|
|
18
|
-
import {
|
|
19
|
-
import type {
|
|
20
|
-
import
|
|
21
|
-
import
|
|
17
|
+
import { client as dgraphClient } from "./lib/client.js"
|
|
18
|
+
import { isDate, type Adapter } from "@auth/core/adapters"
|
|
19
|
+
import type { DgraphClientParams } from "./lib/client.js"
|
|
20
|
+
import * as defaultFragments from "./lib/graphql/fragments.js"
|
|
21
|
+
import {
|
|
22
|
+
AdapterAccount,
|
|
23
|
+
AdapterSession,
|
|
24
|
+
AdapterUser,
|
|
25
|
+
VerificationToken,
|
|
26
|
+
} from "@auth/core/adapters"
|
|
22
27
|
|
|
23
|
-
export type { DgraphClientParams, DgraphClientError } from "./lib/client"
|
|
28
|
+
export type { DgraphClientParams, DgraphClientError } from "./lib/client.js"
|
|
24
29
|
|
|
25
30
|
/** This is the interface of the Dgraph adapter options. */
|
|
26
31
|
export interface DgraphAdapterOptions {
|
|
@@ -39,8 +44,6 @@ export interface DgraphAdapterOptions {
|
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
export { format }
|
|
43
|
-
|
|
44
47
|
export function DgraphAdapter(
|
|
45
48
|
client: DgraphClientParams,
|
|
46
49
|
options?: DgraphAdapterOptions
|
|
@@ -49,7 +52,7 @@ export function DgraphAdapter(
|
|
|
49
52
|
|
|
50
53
|
const fragments = { ...defaultFragments, ...options?.fragments }
|
|
51
54
|
return {
|
|
52
|
-
async createUser(input) {
|
|
55
|
+
async createUser(input: AdapterUser) {
|
|
53
56
|
const result = await c.run<{ user: any[] }>(
|
|
54
57
|
/* GraphQL */ `
|
|
55
58
|
mutation ($input: [AddUserInput!]!) {
|
|
@@ -66,7 +69,7 @@ export function DgraphAdapter(
|
|
|
66
69
|
|
|
67
70
|
return format.from<any>(result?.user[0])
|
|
68
71
|
},
|
|
69
|
-
async getUser(id) {
|
|
72
|
+
async getUser(id: string) {
|
|
70
73
|
const result = await c.run<any>(
|
|
71
74
|
/* GraphQL */ `
|
|
72
75
|
query ($id: ID!) {
|
|
@@ -81,7 +84,7 @@ export function DgraphAdapter(
|
|
|
81
84
|
|
|
82
85
|
return format.from<any>(result)
|
|
83
86
|
},
|
|
84
|
-
async getUserByEmail(email) {
|
|
87
|
+
async getUserByEmail(email: string) {
|
|
85
88
|
const [user] = await c.run<any>(
|
|
86
89
|
/* GraphQL */ `
|
|
87
90
|
query ($email: String = "") {
|
|
@@ -95,7 +98,10 @@ export function DgraphAdapter(
|
|
|
95
98
|
)
|
|
96
99
|
return format.from<any>(user)
|
|
97
100
|
},
|
|
98
|
-
async getUserByAccount(provider_providerAccountId
|
|
101
|
+
async getUserByAccount(provider_providerAccountId: {
|
|
102
|
+
provider: string
|
|
103
|
+
providerAccountId: string
|
|
104
|
+
}) {
|
|
99
105
|
const [account] = await c.run<any>(
|
|
100
106
|
/* GraphQL */ `
|
|
101
107
|
query ($providerAccountId: String = "", $provider: String = "") {
|
|
@@ -119,7 +125,7 @@ export function DgraphAdapter(
|
|
|
119
125
|
)
|
|
120
126
|
return format.from<any>(account?.user)
|
|
121
127
|
},
|
|
122
|
-
async updateUser({ id, ...input }) {
|
|
128
|
+
async updateUser({ id, ...input }: { id: string }) {
|
|
123
129
|
const result = await c.run<any>(
|
|
124
130
|
/* GraphQL */ `
|
|
125
131
|
mutation ($id: [ID!] = "", $input: UserPatch) {
|
|
@@ -135,7 +141,7 @@ export function DgraphAdapter(
|
|
|
135
141
|
)
|
|
136
142
|
return format.from<any>(result.user[0])
|
|
137
143
|
},
|
|
138
|
-
async deleteUser(id) {
|
|
144
|
+
async deleteUser(id: string) {
|
|
139
145
|
const result = await c.run<any>(
|
|
140
146
|
/* GraphQL */ `
|
|
141
147
|
mutation ($id: [ID!] = "") {
|
|
@@ -177,7 +183,7 @@ export function DgraphAdapter(
|
|
|
177
183
|
return deletedUser
|
|
178
184
|
},
|
|
179
185
|
|
|
180
|
-
async linkAccount(data) {
|
|
186
|
+
async linkAccount(data: AdapterAccount) {
|
|
181
187
|
const { userId, ...input } = data
|
|
182
188
|
await c.run<any>(
|
|
183
189
|
/* GraphQL */ `
|
|
@@ -194,7 +200,10 @@ export function DgraphAdapter(
|
|
|
194
200
|
)
|
|
195
201
|
return data
|
|
196
202
|
},
|
|
197
|
-
async unlinkAccount(provider_providerAccountId
|
|
203
|
+
async unlinkAccount(provider_providerAccountId: {
|
|
204
|
+
provider: string
|
|
205
|
+
providerAccountId: string
|
|
206
|
+
}) {
|
|
198
207
|
await c.run<any>(
|
|
199
208
|
/* GraphQL */ `
|
|
200
209
|
mutation ($providerAccountId: String = "", $provider: String = "") {
|
|
@@ -214,7 +223,7 @@ export function DgraphAdapter(
|
|
|
214
223
|
)
|
|
215
224
|
},
|
|
216
225
|
|
|
217
|
-
async getSessionAndUser(sessionToken) {
|
|
226
|
+
async getSessionAndUser(sessionToken: string) {
|
|
218
227
|
const [sessionAndUser] = await c.run<any>(
|
|
219
228
|
/* GraphQL */ `
|
|
220
229
|
query ($sessionToken: String = "") {
|
|
@@ -239,7 +248,7 @@ export function DgraphAdapter(
|
|
|
239
248
|
session: { ...format.from<any>(session), userId: user.id },
|
|
240
249
|
}
|
|
241
250
|
},
|
|
242
|
-
async createSession(data) {
|
|
251
|
+
async createSession(data: AdapterSession) {
|
|
243
252
|
const { userId, ...input } = data
|
|
244
253
|
|
|
245
254
|
await c.run<any>(
|
|
@@ -258,7 +267,7 @@ export function DgraphAdapter(
|
|
|
258
267
|
|
|
259
268
|
return data as any
|
|
260
269
|
},
|
|
261
|
-
async updateSession({ sessionToken, ...input }) {
|
|
270
|
+
async updateSession({ sessionToken, ...input }: { sessionToken: string }) {
|
|
262
271
|
const result = await c.run<any>(
|
|
263
272
|
/* GraphQL */ `
|
|
264
273
|
mutation ($input: SessionPatch = {}, $sessionToken: String) {
|
|
@@ -286,7 +295,7 @@ export function DgraphAdapter(
|
|
|
286
295
|
|
|
287
296
|
return { ...session, userId: session.user.id }
|
|
288
297
|
},
|
|
289
|
-
async deleteSession(sessionToken) {
|
|
298
|
+
async deleteSession(sessionToken: string) {
|
|
290
299
|
await c.run<any>(
|
|
291
300
|
/* GraphQL */ `
|
|
292
301
|
mutation ($sessionToken: String = "") {
|
|
@@ -299,7 +308,7 @@ export function DgraphAdapter(
|
|
|
299
308
|
)
|
|
300
309
|
},
|
|
301
310
|
|
|
302
|
-
async createVerificationToken(input) {
|
|
311
|
+
async createVerificationToken(input: VerificationToken) {
|
|
303
312
|
const result = await c.run<any>(
|
|
304
313
|
/* GraphQL */ `
|
|
305
314
|
mutation ($input: [AddVerificationTokenInput!]!) {
|
|
@@ -313,7 +322,7 @@ export function DgraphAdapter(
|
|
|
313
322
|
return format.from<any>(result)
|
|
314
323
|
},
|
|
315
324
|
|
|
316
|
-
async useVerificationToken(params) {
|
|
325
|
+
async useVerificationToken(params: { identifier: string; token: string }) {
|
|
317
326
|
const result = await c.run<any>(
|
|
318
327
|
/* GraphQL */ `
|
|
319
328
|
mutation ($token: String = "", $identifier: String = "") {
|
|
@@ -336,3 +345,20 @@ export function DgraphAdapter(
|
|
|
336
345
|
},
|
|
337
346
|
}
|
|
338
347
|
}
|
|
348
|
+
|
|
349
|
+
export const format = {
|
|
350
|
+
from<T>(object?: Record<string, any>): T | null {
|
|
351
|
+
const newObject: Record<string, unknown> = {}
|
|
352
|
+
if (!object) return null
|
|
353
|
+
for (const key in object) {
|
|
354
|
+
const value = object[key]
|
|
355
|
+
if (isDate(value)) {
|
|
356
|
+
newObject[key] = new Date(value)
|
|
357
|
+
} else {
|
|
358
|
+
newObject[key] = value
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return newObject as T
|
|
363
|
+
},
|
|
364
|
+
}
|
package/lib/utils.d.ts
DELETED
package/lib/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/lib/utils.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM;qBACA,OAAO,MAAM,EAAE,GAAG,CAAC;CAcrC,CAAA"}
|
package/lib/utils.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// https://github.com/honeinc/is-iso-date/blob/master/index.js
|
|
2
|
-
const isoDateRE = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/;
|
|
3
|
-
function isDate(value) {
|
|
4
|
-
return value && isoDateRE.test(value) && !isNaN(Date.parse(value));
|
|
5
|
-
}
|
|
6
|
-
export const format = {
|
|
7
|
-
from(object) {
|
|
8
|
-
const newObject = {};
|
|
9
|
-
if (!object)
|
|
10
|
-
return null;
|
|
11
|
-
for (const key in object) {
|
|
12
|
-
const value = object[key];
|
|
13
|
-
if (isDate(value)) {
|
|
14
|
-
newObject[key] = new Date(value);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
newObject[key] = value;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return newObject;
|
|
21
|
-
},
|
|
22
|
-
};
|
package/src/lib/utils.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// https://github.com/honeinc/is-iso-date/blob/master/index.js
|
|
2
|
-
const isoDateRE =
|
|
3
|
-
/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/
|
|
4
|
-
|
|
5
|
-
function isDate(value: any) {
|
|
6
|
-
return value && isoDateRE.test(value) && !isNaN(Date.parse(value))
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const format = {
|
|
10
|
-
from<T>(object?: Record<string, any>): T | null {
|
|
11
|
-
const newObject: Record<string, unknown> = {}
|
|
12
|
-
if (!object) return null
|
|
13
|
-
for (const key in object) {
|
|
14
|
-
const value = object[key]
|
|
15
|
-
if (isDate(value)) {
|
|
16
|
-
newObject[key] = new Date(value)
|
|
17
|
-
} else {
|
|
18
|
-
newObject[key] = value
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return newObject as T
|
|
23
|
-
},
|
|
24
|
-
}
|