@auth/dgraph-adapter 1.0.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 +15 -0
- package/README.md +28 -0
- package/index.d.ts +255 -0
- package/index.d.ts.map +1 -0
- package/index.js +499 -0
- package/lib/client.d.ts +31 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/client.js +40 -0
- package/lib/graphql/fragments.d.ts +5 -0
- package/lib/graphql/fragments.d.ts.map +1 -0
- package/lib/graphql/fragments.js +38 -0
- package/lib/utils.d.ts +4 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +22 -0
- package/package.json +60 -0
- package/src/index.ts +570 -0
- package/src/lib/client.ts +79 -0
- package/src/lib/graphql/fragments.ts +40 -0
- package/src/lib/graphql/schema.gql +82 -0
- package/src/lib/utils.ts +24 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const User = /* GraphQL */ `
|
|
2
|
+
fragment UserFragment on User {
|
|
3
|
+
email
|
|
4
|
+
id
|
|
5
|
+
image
|
|
6
|
+
name
|
|
7
|
+
emailVerified
|
|
8
|
+
}
|
|
9
|
+
`
|
|
10
|
+
|
|
11
|
+
export const Account = /* GraphQL */ `
|
|
12
|
+
fragment AccountFragment on Account {
|
|
13
|
+
id
|
|
14
|
+
type
|
|
15
|
+
provider
|
|
16
|
+
providerAccountId
|
|
17
|
+
expires_at
|
|
18
|
+
token_type
|
|
19
|
+
scope
|
|
20
|
+
access_token
|
|
21
|
+
refresh_token
|
|
22
|
+
id_token
|
|
23
|
+
session_state
|
|
24
|
+
}
|
|
25
|
+
`
|
|
26
|
+
export const Session = /* GraphQL */ `
|
|
27
|
+
fragment SessionFragment on Session {
|
|
28
|
+
expires
|
|
29
|
+
id
|
|
30
|
+
sessionToken
|
|
31
|
+
}
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
export const VerificationToken = /* GraphQL */ `
|
|
35
|
+
fragment VerificationTokenFragment on VerificationToken {
|
|
36
|
+
identifier
|
|
37
|
+
token
|
|
38
|
+
expires
|
|
39
|
+
}
|
|
40
|
+
`
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
type Account
|
|
2
|
+
@auth(
|
|
3
|
+
delete: { rule: "{$nextAuth: { eq: true } }" }
|
|
4
|
+
add: { rule: "{$nextAuth: { eq: true } }" }
|
|
5
|
+
query: { rule: "{$nextAuth: { eq: true } }" }
|
|
6
|
+
update: { rule: "{$nextAuth: { eq: true } }" }
|
|
7
|
+
) {
|
|
8
|
+
id: ID
|
|
9
|
+
type: String
|
|
10
|
+
provider: String @search(by: [hash])
|
|
11
|
+
providerAccountId: String @search(by: [hash])
|
|
12
|
+
refreshToken: String
|
|
13
|
+
expires_at: Int64
|
|
14
|
+
accessToken: String
|
|
15
|
+
token_type: String
|
|
16
|
+
refresh_token: String
|
|
17
|
+
access_token: String
|
|
18
|
+
scope: String
|
|
19
|
+
id_token: String
|
|
20
|
+
session_state: String
|
|
21
|
+
user: User @hasInverse(field: "accounts")
|
|
22
|
+
}
|
|
23
|
+
type Session
|
|
24
|
+
@auth(
|
|
25
|
+
delete: { rule: "{$nextAuth: { eq: true } }" }
|
|
26
|
+
add: { rule: "{$nextAuth: { eq: true } }" }
|
|
27
|
+
query: { rule: "{$nextAuth: { eq: true } }" }
|
|
28
|
+
update: { rule: "{$nextAuth: { eq: true } }" }
|
|
29
|
+
) {
|
|
30
|
+
id: ID
|
|
31
|
+
expires: DateTime
|
|
32
|
+
sessionToken: String @search(by: [hash])
|
|
33
|
+
user: User @hasInverse(field: "sessions")
|
|
34
|
+
}
|
|
35
|
+
type User
|
|
36
|
+
@auth(
|
|
37
|
+
query: {
|
|
38
|
+
or: [
|
|
39
|
+
{
|
|
40
|
+
rule: """
|
|
41
|
+
query ($userId: String!) {queryUser(filter: { id: { eq: $userId } } ) {id}}
|
|
42
|
+
"""
|
|
43
|
+
}
|
|
44
|
+
{ rule: "{$nextAuth: { eq: true } }" }
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
delete: { rule: "{$nextAuth: { eq: true } }" }
|
|
48
|
+
add: { rule: "{$nextAuth: { eq: true } }" }
|
|
49
|
+
update: {
|
|
50
|
+
or: [
|
|
51
|
+
{
|
|
52
|
+
rule: """
|
|
53
|
+
query ($userId: String!) {queryUser(filter: { id: { eq: $userId } } ) {id}}
|
|
54
|
+
"""
|
|
55
|
+
}
|
|
56
|
+
{ rule: "{$nextAuth: { eq: true } }" }
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
) {
|
|
60
|
+
id: ID
|
|
61
|
+
name: String
|
|
62
|
+
email: String @search(by: [hash])
|
|
63
|
+
emailVerified: DateTime
|
|
64
|
+
image: String
|
|
65
|
+
accounts: [Account] @hasInverse(field: "user")
|
|
66
|
+
sessions: [Session] @hasInverse(field: "user")
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type VerificationToken
|
|
70
|
+
@auth(
|
|
71
|
+
delete: { rule: "{$nextAuth: { eq: true } }" }
|
|
72
|
+
add: { rule: "{$nextAuth: { eq: true } }" }
|
|
73
|
+
query: { rule: "{$nextAuth: { eq: true } }" }
|
|
74
|
+
update: { rule: "{$nextAuth: { eq: true } }" }
|
|
75
|
+
) {
|
|
76
|
+
id: ID
|
|
77
|
+
identifier: String @search(by: [hash])
|
|
78
|
+
token: String @search(by: [hash])
|
|
79
|
+
expires: DateTime
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
# Dgraph.Authorization {"VerificationKey":"<YOUR JWT SECRET HERE>","Header":"<YOUR AUTH HEADER HERE>","Namespace":"<YOUR CUSTOM NAMESPACE HERE>","Algo":"RS256"}
|
package/src/lib/utils.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|