@atproto/lex-schema 0.0.9 → 0.0.11
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/CHANGELOG.md +41 -0
- package/LICENSE.txt +1 -1
- package/dist/core/$type.d.ts +11 -0
- package/dist/core/$type.d.ts.map +1 -1
- package/dist/core/$type.js +4 -0
- package/dist/core/$type.js.map +1 -1
- package/dist/core/schema.d.ts +31 -24
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +38 -8
- package/dist/core/schema.js.map +1 -1
- package/dist/core/string-format.d.ts +35 -35
- package/dist/core/string-format.d.ts.map +1 -1
- package/dist/core/string-format.js +49 -91
- package/dist/core/string-format.js.map +1 -1
- package/dist/core/validation-error.d.ts +1 -1
- package/dist/core/validation-issue.js +1 -1
- package/dist/core/validation-issue.js.map +1 -1
- package/dist/core/validator.d.ts +53 -32
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js +18 -22
- package/dist/core/validator.js.map +1 -1
- package/dist/external.d.ts +0 -85
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js +0 -164
- package/dist/external.js.map +1 -1
- package/dist/helpers.d.ts +13 -5
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +4 -4
- package/dist/helpers.js.map +1 -1
- package/dist/schema/array.d.ts +9 -5
- package/dist/schema/array.d.ts.map +1 -1
- package/dist/schema/array.js +14 -5
- package/dist/schema/array.js.map +1 -1
- package/dist/schema/blob.d.ts +9 -7
- package/dist/schema/blob.d.ts.map +1 -1
- package/dist/schema/blob.js +9 -5
- package/dist/schema/blob.js.map +1 -1
- package/dist/schema/boolean.d.ts +3 -7
- package/dist/schema/boolean.d.ts.map +1 -1
- package/dist/schema/boolean.js +6 -7
- package/dist/schema/boolean.js.map +1 -1
- package/dist/schema/bytes.d.ts +3 -2
- package/dist/schema/bytes.d.ts.map +1 -1
- package/dist/schema/bytes.js +7 -3
- package/dist/schema/bytes.js.map +1 -1
- package/dist/schema/cid.d.ts +7 -7
- package/dist/schema/cid.d.ts.map +1 -1
- package/dist/schema/cid.js +5 -1
- package/dist/schema/cid.js.map +1 -1
- package/dist/schema/custom.d.ts +6 -5
- package/dist/schema/custom.d.ts.map +1 -1
- package/dist/schema/custom.js +10 -4
- package/dist/schema/custom.js.map +1 -1
- package/dist/schema/dict.d.ts +8 -8
- package/dist/schema/dict.d.ts.map +1 -1
- package/dist/schema/dict.js +11 -2
- package/dist/schema/dict.js.map +1 -1
- package/dist/schema/discriminated-union.d.ts +21 -14
- package/dist/schema/discriminated-union.d.ts.map +1 -1
- package/dist/schema/discriminated-union.js +7 -0
- package/dist/schema/discriminated-union.js.map +1 -1
- package/dist/schema/enum.d.ts +7 -9
- package/dist/schema/enum.d.ts.map +1 -1
- package/dist/schema/enum.js +8 -4
- package/dist/schema/enum.js.map +1 -1
- package/dist/schema/integer.d.ts +5 -5
- package/dist/schema/integer.d.ts.map +1 -1
- package/dist/schema/integer.js +9 -5
- package/dist/schema/integer.js.map +1 -1
- package/dist/schema/intersection.d.ts +4 -4
- package/dist/schema/intersection.d.ts.map +1 -1
- package/dist/schema/intersection.js +5 -0
- package/dist/schema/intersection.js.map +1 -1
- package/dist/schema/literal.d.ts +6 -9
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js +7 -4
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/never.d.ts +3 -2
- package/dist/schema/never.d.ts.map +1 -1
- package/dist/schema/never.js +5 -1
- package/dist/schema/never.js.map +1 -1
- package/dist/schema/null.d.ts +4 -3
- package/dist/schema/null.d.ts.map +1 -1
- package/dist/schema/null.js +6 -4
- package/dist/schema/null.js.map +1 -1
- package/dist/schema/nullable.d.ts +6 -5
- package/dist/schema/nullable.d.ts.map +1 -1
- package/dist/schema/nullable.js +9 -5
- package/dist/schema/nullable.js.map +1 -1
- package/dist/schema/object.d.ts +10 -8
- package/dist/schema/object.d.ts.map +1 -1
- package/dist/schema/object.js +11 -3
- package/dist/schema/object.js.map +1 -1
- package/dist/schema/optional.d.ts +7 -5
- package/dist/schema/optional.d.ts.map +1 -1
- package/dist/schema/optional.js +14 -6
- package/dist/schema/optional.js.map +1 -1
- package/dist/schema/params.d.ts +26 -13
- package/dist/schema/params.d.ts.map +1 -1
- package/dist/schema/params.js +47 -25
- package/dist/schema/params.js.map +1 -1
- package/dist/schema/payload.d.ts +12 -9
- package/dist/schema/payload.d.ts.map +1 -1
- package/dist/schema/payload.js +11 -0
- package/dist/schema/payload.js.map +1 -1
- package/dist/schema/permission-set.d.ts +1 -0
- package/dist/schema/permission-set.d.ts.map +1 -1
- package/dist/schema/permission-set.js +5 -0
- package/dist/schema/permission-set.js.map +1 -1
- package/dist/schema/permission.d.ts +6 -5
- package/dist/schema/permission.d.ts.map +1 -1
- package/dist/schema/permission.js +5 -0
- package/dist/schema/permission.js.map +1 -1
- package/dist/schema/procedure.d.ts +2 -1
- package/dist/schema/procedure.d.ts.map +1 -1
- package/dist/schema/procedure.js +5 -0
- package/dist/schema/procedure.js.map +1 -1
- package/dist/schema/query.d.ts +2 -1
- package/dist/schema/query.d.ts.map +1 -1
- package/dist/schema/query.js +5 -0
- package/dist/schema/query.js.map +1 -1
- package/dist/schema/record.d.ts +48 -30
- package/dist/schema/record.d.ts.map +1 -1
- package/dist/schema/record.js +12 -9
- package/dist/schema/record.js.map +1 -1
- package/dist/schema/ref.d.ts +9 -6
- package/dist/schema/ref.d.ts.map +1 -1
- package/dist/schema/ref.js +9 -16
- package/dist/schema/ref.js.map +1 -1
- package/dist/schema/refine.d.ts +4 -4
- package/dist/schema/refine.d.ts.map +1 -1
- package/dist/schema/refine.js.map +1 -1
- package/dist/schema/regexp.d.ts +4 -3
- package/dist/schema/regexp.d.ts.map +1 -1
- package/dist/schema/regexp.js +5 -0
- package/dist/schema/regexp.js.map +1 -1
- package/dist/schema/string.d.ts +7 -8
- package/dist/schema/string.d.ts.map +1 -1
- package/dist/schema/string.js +13 -19
- package/dist/schema/string.js.map +1 -1
- package/dist/schema/subscription.d.ts +2 -1
- package/dist/schema/subscription.d.ts.map +1 -1
- package/dist/schema/subscription.js +5 -0
- package/dist/schema/subscription.js.map +1 -1
- package/dist/schema/token.d.ts +6 -5
- package/dist/schema/token.d.ts.map +1 -1
- package/dist/schema/token.js +5 -0
- package/dist/schema/token.js.map +1 -1
- package/dist/schema/typed-object.d.ts +43 -26
- package/dist/schema/typed-object.d.ts.map +1 -1
- package/dist/schema/typed-object.js +6 -3
- package/dist/schema/typed-object.js.map +1 -1
- package/dist/schema/typed-ref.d.ts +16 -25
- package/dist/schema/typed-ref.d.ts.map +1 -1
- package/dist/schema/typed-ref.js +7 -17
- package/dist/schema/typed-ref.js.map +1 -1
- package/dist/schema/typed-union.d.ts +9 -21
- package/dist/schema/typed-union.d.ts.map +1 -1
- package/dist/schema/typed-union.js +15 -11
- package/dist/schema/typed-union.js.map +1 -1
- package/dist/schema/union.d.ts +6 -6
- package/dist/schema/union.d.ts.map +1 -1
- package/dist/schema/union.js +7 -5
- package/dist/schema/union.js.map +1 -1
- package/dist/schema/unknown-object.d.ts +5 -4
- package/dist/schema/unknown-object.d.ts.map +1 -1
- package/dist/schema/unknown-object.js +5 -1
- package/dist/schema/unknown-object.js.map +1 -1
- package/dist/schema/unknown.d.ts +3 -2
- package/dist/schema/unknown.d.ts.map +1 -1
- package/dist/schema/unknown.js +5 -1
- package/dist/schema/unknown.js.map +1 -1
- package/dist/schema/with-default.d.ts +9 -0
- package/dist/schema/with-default.d.ts.map +1 -0
- package/dist/schema/with-default.js +27 -0
- package/dist/schema/with-default.js.map +1 -0
- package/dist/schema.d.ts +2 -2
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -4
- package/dist/schema.js.map +1 -1
- package/dist/util/assertion-util.d.ts +0 -6
- package/dist/util/assertion-util.d.ts.map +1 -1
- package/dist/util/assertion-util.js +0 -28
- package/dist/util/assertion-util.js.map +1 -1
- package/dist/util/memoize.d.ts +2 -2
- package/dist/util/memoize.d.ts.map +1 -1
- package/dist/util/memoize.js +23 -39
- package/dist/util/memoize.js.map +1 -1
- package/package.json +3 -3
- package/src/core/$type.test.ts +20 -0
- package/src/core/$type.ts +30 -0
- package/src/core/schema.ts +86 -38
- package/src/core/string-format.ts +119 -158
- package/src/core/validation-issue.ts +1 -1
- package/src/core/validator.ts +93 -53
- package/src/external.ts +0 -404
- package/src/helpers.test.ts +22 -21
- package/src/helpers.ts +19 -14
- package/src/schema/array.test.ts +38 -40
- package/src/schema/array.ts +35 -13
- package/src/schema/blob.test.ts +21 -21
- package/src/schema/blob.ts +19 -17
- package/src/schema/boolean.test.ts +9 -8
- package/src/schema/boolean.ts +7 -13
- package/src/schema/bytes.test.ts +13 -13
- package/src/schema/bytes.ts +13 -8
- package/src/schema/cid.test.ts +3 -3
- package/src/schema/cid.ts +13 -12
- package/src/schema/custom.test.ts +26 -26
- package/src/schema/custom.ts +20 -13
- package/src/schema/dict.test.ts +21 -39
- package/src/schema/dict.ts +28 -19
- package/src/schema/discriminated-union.test.ts +128 -128
- package/src/schema/discriminated-union.ts +45 -26
- package/src/schema/enum.test.ts +17 -16
- package/src/schema/enum.ts +16 -16
- package/src/schema/integer.test.ts +22 -21
- package/src/schema/integer.ts +12 -9
- package/src/schema/intersection.test.ts +10 -10
- package/src/schema/intersection.ts +17 -14
- package/src/schema/literal.test.ts +35 -34
- package/src/schema/literal.ts +12 -15
- package/src/schema/never.test.ts +5 -5
- package/src/schema/never.ts +7 -2
- package/src/schema/null.test.ts +3 -3
- package/src/schema/null.ts +9 -9
- package/src/schema/nullable.test.ts +31 -42
- package/src/schema/nullable.ts +17 -9
- package/src/schema/object.test.ts +10 -12
- package/src/schema/object.ts +27 -18
- package/src/schema/optional.test.ts +21 -28
- package/src/schema/optional.ts +27 -10
- package/src/schema/params.test.ts +471 -47
- package/src/schema/params.ts +74 -38
- package/src/schema/payload.test.ts +150 -156
- package/src/schema/payload.ts +35 -19
- package/src/schema/permission-set.test.ts +206 -273
- package/src/schema/permission-set.ts +8 -0
- package/src/schema/permission.test.ts +177 -177
- package/src/schema/permission.ts +13 -5
- package/src/schema/procedure.test.ts +183 -242
- package/src/schema/procedure.ts +18 -5
- package/src/schema/query.test.ts +186 -200
- package/src/schema/query.ts +16 -4
- package/src/schema/record.test.ts +121 -101
- package/src/schema/record.ts +74 -40
- package/src/schema/ref.test.ts +101 -118
- package/src/schema/ref.ts +33 -28
- package/src/schema/refine.test.ts +28 -28
- package/src/schema/refine.ts +23 -20
- package/src/schema/regexp.test.ts +29 -33
- package/src/schema/regexp.ts +11 -7
- package/src/schema/string.test.ts +35 -35
- package/src/schema/string.ts +24 -33
- package/src/schema/subscription.test.ts +259 -387
- package/src/schema/subscription.ts +16 -4
- package/src/schema/token.test.ts +47 -324
- package/src/schema/token.ts +14 -7
- package/src/schema/typed-object.test.ts +98 -81
- package/src/schema/typed-object.ts +68 -33
- package/src/schema/typed-ref.test.ts +206 -234
- package/src/schema/typed-ref.ts +40 -42
- package/src/schema/typed-union.test.ts +40 -64
- package/src/schema/typed-union.ts +36 -58
- package/src/schema/union.test.ts +17 -27
- package/src/schema/union.ts +20 -16
- package/src/schema/unknown-object.test.ts +8 -8
- package/src/schema/unknown-object.ts +9 -7
- package/src/schema/unknown.test.ts +4 -4
- package/src/schema/unknown.ts +7 -5
- package/src/schema/with-default.ts +35 -0
- package/src/schema.ts +2 -6
- package/src/util/assertion-util.ts +0 -39
- package/src/util/memoize.ts +26 -46
- package/dist/schema/_parameters.d.ts +0 -17
- package/dist/schema/_parameters.d.ts.map +0 -1
- package/dist/schema/_parameters.js +0 -20
- package/dist/schema/_parameters.js.map +0 -1
- package/src/schema/_parameters.test.ts +0 -417
- package/src/schema/_parameters.ts +0 -26
|
@@ -1,90 +1,81 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Permission } from './permission.js'
|
|
2
|
+
import { PermissionSet, permissionSet } from './permission-set.js'
|
|
3
|
+
import { Permission, permission } from './permission.js'
|
|
5
4
|
|
|
6
5
|
describe('PermissionSet', () => {
|
|
7
6
|
describe('constructor', () => {
|
|
8
7
|
it('creates a PermissionSet instance with all parameters', () => {
|
|
9
|
-
const nsid =
|
|
8
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
10
9
|
const permissions = [
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
permission('app.bsky.feed.post:read', {}),
|
|
11
|
+
permission('app.bsky.feed.post:write', {}),
|
|
13
12
|
] as const
|
|
14
13
|
const options = {
|
|
15
14
|
title: 'Post Management',
|
|
16
15
|
detail: 'Allows reading and writing posts',
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
const
|
|
18
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
20
19
|
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
20
|
+
expect(perms).toBeInstanceOf(PermissionSet)
|
|
21
|
+
expect(perms.nsid).toBe(nsid)
|
|
22
|
+
expect(perms.permissions).toBe(permissions)
|
|
23
|
+
expect(perms.options).toBe(options)
|
|
25
24
|
})
|
|
26
25
|
|
|
27
26
|
it('creates a PermissionSet instance with minimal options', () => {
|
|
28
|
-
const nsid =
|
|
29
|
-
const permissions = [
|
|
30
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
31
|
-
] as const
|
|
27
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
28
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
32
29
|
const options = {}
|
|
33
30
|
|
|
34
|
-
const
|
|
31
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
35
32
|
|
|
36
|
-
expect(
|
|
37
|
-
expect(
|
|
38
|
-
expect(
|
|
39
|
-
expect(
|
|
33
|
+
expect(perms).toBeInstanceOf(PermissionSet)
|
|
34
|
+
expect(perms.nsid).toBe(nsid)
|
|
35
|
+
expect(perms.permissions).toBe(permissions)
|
|
36
|
+
expect(perms.options).toEqual({})
|
|
40
37
|
})
|
|
41
38
|
|
|
42
39
|
it('creates a PermissionSet instance with empty permissions array', () => {
|
|
43
|
-
const nsid =
|
|
40
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
44
41
|
const permissions = [] as const
|
|
45
42
|
const options = {}
|
|
46
43
|
|
|
47
|
-
const
|
|
44
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
48
45
|
|
|
49
|
-
expect(
|
|
50
|
-
expect(
|
|
46
|
+
expect(perms).toBeInstanceOf(PermissionSet)
|
|
47
|
+
expect(perms.permissions).toEqual([])
|
|
51
48
|
})
|
|
52
49
|
|
|
53
50
|
it('creates a PermissionSet instance with title only', () => {
|
|
54
|
-
const nsid =
|
|
55
|
-
const permissions = [
|
|
56
|
-
new Permission('app.bsky.feed.like:read', {}),
|
|
57
|
-
] as const
|
|
51
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
52
|
+
const permissions = [permission('app.bsky.feed.like:read', {})] as const
|
|
58
53
|
const options = {
|
|
59
54
|
title: 'Like Management',
|
|
60
55
|
}
|
|
61
56
|
|
|
62
|
-
const
|
|
57
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
63
58
|
|
|
64
|
-
expect(
|
|
65
|
-
expect(
|
|
59
|
+
expect(perms.options.title).toBe('Like Management')
|
|
60
|
+
expect(perms.options.detail).toBeUndefined()
|
|
66
61
|
})
|
|
67
62
|
|
|
68
63
|
it('creates a PermissionSet instance with detail only', () => {
|
|
69
|
-
const nsid =
|
|
70
|
-
const permissions = [
|
|
71
|
-
new Permission('app.bsky.feed.like:read', {}),
|
|
72
|
-
] as const
|
|
64
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
65
|
+
const permissions = [permission('app.bsky.feed.like:read', {})] as const
|
|
73
66
|
const options = {
|
|
74
67
|
detail: 'Allows reading likes on posts',
|
|
75
68
|
}
|
|
76
69
|
|
|
77
|
-
const
|
|
70
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
78
71
|
|
|
79
|
-
expect(
|
|
80
|
-
expect(
|
|
72
|
+
expect(perms.options.title).toBeUndefined()
|
|
73
|
+
expect(perms.options.detail).toBe('Allows reading likes on posts')
|
|
81
74
|
})
|
|
82
75
|
|
|
83
76
|
it('creates a PermissionSet instance with localized titles', () => {
|
|
84
|
-
const nsid =
|
|
85
|
-
const permissions = [
|
|
86
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
87
|
-
] as const
|
|
77
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
78
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
88
79
|
const options = {
|
|
89
80
|
title: 'Post Management',
|
|
90
81
|
'title:lang': {
|
|
@@ -93,20 +84,18 @@ describe('PermissionSet', () => {
|
|
|
93
84
|
},
|
|
94
85
|
}
|
|
95
86
|
|
|
96
|
-
const
|
|
87
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
97
88
|
|
|
98
|
-
expect(
|
|
99
|
-
expect(
|
|
89
|
+
expect(perms.options.title).toBe('Post Management')
|
|
90
|
+
expect(perms.options['title:lang']).toEqual({
|
|
100
91
|
es: 'Gestión de Publicaciones',
|
|
101
92
|
fr: 'Gestion des Publications',
|
|
102
93
|
})
|
|
103
94
|
})
|
|
104
95
|
|
|
105
96
|
it('creates a PermissionSet instance with localized details', () => {
|
|
106
|
-
const nsid =
|
|
107
|
-
const permissions = [
|
|
108
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
109
|
-
] as const
|
|
97
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
98
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
110
99
|
const options = {
|
|
111
100
|
detail: 'Allows reading posts',
|
|
112
101
|
'detail:lang': {
|
|
@@ -115,20 +104,20 @@ describe('PermissionSet', () => {
|
|
|
115
104
|
},
|
|
116
105
|
}
|
|
117
106
|
|
|
118
|
-
const
|
|
107
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
119
108
|
|
|
120
|
-
expect(
|
|
121
|
-
expect(
|
|
109
|
+
expect(perms.options.detail).toBe('Allows reading posts')
|
|
110
|
+
expect(perms.options['detail:lang']).toEqual({
|
|
122
111
|
es: 'Permite leer publicaciones',
|
|
123
112
|
fr: 'Permet de lire les publications',
|
|
124
113
|
})
|
|
125
114
|
})
|
|
126
115
|
|
|
127
116
|
it('creates a PermissionSet instance with all options including localization', () => {
|
|
128
|
-
const nsid =
|
|
117
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
129
118
|
const permissions = [
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
permission('app.bsky.feed.post:read', {}),
|
|
120
|
+
permission('app.bsky.feed.post:write', {}),
|
|
132
121
|
] as const
|
|
133
122
|
const options = {
|
|
134
123
|
title: 'Post Management',
|
|
@@ -145,18 +134,16 @@ describe('PermissionSet', () => {
|
|
|
145
134
|
},
|
|
146
135
|
}
|
|
147
136
|
|
|
148
|
-
const
|
|
137
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
149
138
|
|
|
150
|
-
expect(
|
|
151
|
-
expect(
|
|
139
|
+
expect(perms.options.title).toBe('Post Management')
|
|
140
|
+
expect(perms.options['title:lang']).toEqual({
|
|
152
141
|
es: 'Gestión de Publicaciones',
|
|
153
142
|
fr: 'Gestion des Publications',
|
|
154
143
|
de: 'Beitragsverwaltung',
|
|
155
144
|
})
|
|
156
|
-
expect(
|
|
157
|
-
|
|
158
|
-
)
|
|
159
|
-
expect(permissionSet.options['detail:lang']).toEqual({
|
|
145
|
+
expect(perms.options.detail).toBe('Allows reading and writing posts')
|
|
146
|
+
expect(perms.options['detail:lang']).toEqual({
|
|
160
147
|
es: 'Permite leer y escribir publicaciones',
|
|
161
148
|
fr: 'Permet de lire et écrire les publications',
|
|
162
149
|
de: 'Ermöglicht das Lesen und Schreiben von Beiträgen',
|
|
@@ -166,138 +153,119 @@ describe('PermissionSet', () => {
|
|
|
166
153
|
|
|
167
154
|
describe('property immutability', () => {
|
|
168
155
|
it('options object itself is mutable', () => {
|
|
169
|
-
const nsid =
|
|
170
|
-
const permissions = [
|
|
171
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
172
|
-
] as const
|
|
156
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
157
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
173
158
|
const options = { title: 'Test' }
|
|
174
159
|
|
|
175
|
-
const
|
|
160
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
176
161
|
|
|
177
162
|
// The reference is readonly, but the object itself can be mutated
|
|
178
163
|
options.title = 'Updated Title'
|
|
179
|
-
expect(
|
|
164
|
+
expect(perms.options.title).toBe('Updated Title')
|
|
180
165
|
})
|
|
181
166
|
})
|
|
182
167
|
|
|
183
168
|
describe('with multiple permissions', () => {
|
|
184
169
|
it('creates a PermissionSet with multiple read permissions', () => {
|
|
185
|
-
const nsid =
|
|
170
|
+
const nsid = 'app.bsky.oauth.read'
|
|
186
171
|
const permissions = [
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
172
|
+
permission('app.bsky.feed.post:read', {}),
|
|
173
|
+
permission('app.bsky.feed.like:read', {}),
|
|
174
|
+
permission('app.bsky.feed.repost:read', {}),
|
|
175
|
+
permission('app.bsky.graph.follow:read', {}),
|
|
191
176
|
] as const
|
|
192
177
|
const options = {
|
|
193
178
|
title: 'Read Access',
|
|
194
179
|
detail: 'Allows reading various resources',
|
|
195
180
|
}
|
|
196
181
|
|
|
197
|
-
const
|
|
182
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
198
183
|
|
|
199
|
-
expect(
|
|
200
|
-
expect(
|
|
201
|
-
|
|
202
|
-
)
|
|
203
|
-
expect(
|
|
204
|
-
'app.bsky.feed.like:read',
|
|
205
|
-
)
|
|
206
|
-
expect(permissionSet.permissions[2].resource).toBe(
|
|
207
|
-
'app.bsky.feed.repost:read',
|
|
208
|
-
)
|
|
209
|
-
expect(permissionSet.permissions[3].resource).toBe(
|
|
210
|
-
'app.bsky.graph.follow:read',
|
|
211
|
-
)
|
|
184
|
+
expect(perms.permissions).toHaveLength(4)
|
|
185
|
+
expect(perms.permissions[0].resource).toBe('app.bsky.feed.post:read')
|
|
186
|
+
expect(perms.permissions[1].resource).toBe('app.bsky.feed.like:read')
|
|
187
|
+
expect(perms.permissions[2].resource).toBe('app.bsky.feed.repost:read')
|
|
188
|
+
expect(perms.permissions[3].resource).toBe('app.bsky.graph.follow:read')
|
|
212
189
|
})
|
|
213
190
|
|
|
214
191
|
it('creates a PermissionSet with mixed read/write permissions', () => {
|
|
215
|
-
const nsid =
|
|
192
|
+
const nsid = 'app.bsky.oauth.full'
|
|
216
193
|
const permissions = [
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
194
|
+
permission('app.bsky.feed.post:read', {}),
|
|
195
|
+
permission('app.bsky.feed.post:write', {}),
|
|
196
|
+
permission('app.bsky.feed.like:read', {}),
|
|
197
|
+
permission('app.bsky.feed.like:write', {}),
|
|
221
198
|
] as const
|
|
222
199
|
const options = {
|
|
223
200
|
title: 'Full Access',
|
|
224
201
|
detail: 'Allows reading and writing posts and likes',
|
|
225
202
|
}
|
|
226
203
|
|
|
227
|
-
const
|
|
204
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
228
205
|
|
|
229
|
-
expect(
|
|
206
|
+
expect(perms.permissions).toHaveLength(4)
|
|
230
207
|
})
|
|
231
208
|
|
|
232
209
|
it('creates a PermissionSet with a single permission', () => {
|
|
233
|
-
const nsid =
|
|
210
|
+
const nsid = 'app.bsky.oauth.limited'
|
|
234
211
|
const permissions = [
|
|
235
|
-
|
|
212
|
+
permission('app.bsky.actor.profile:read', {}),
|
|
236
213
|
] as const
|
|
237
214
|
const options = {
|
|
238
215
|
title: 'Profile Read',
|
|
239
216
|
detail: 'Allows reading user profiles only',
|
|
240
217
|
}
|
|
241
218
|
|
|
242
|
-
const
|
|
219
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
243
220
|
|
|
244
|
-
expect(
|
|
245
|
-
expect(
|
|
246
|
-
'app.bsky.actor.profile:read',
|
|
247
|
-
)
|
|
221
|
+
expect(perms.permissions).toHaveLength(1)
|
|
222
|
+
expect(perms.permissions[0].resource).toBe('app.bsky.actor.profile:read')
|
|
248
223
|
})
|
|
249
224
|
})
|
|
250
225
|
|
|
251
226
|
describe('edge cases', () => {
|
|
252
227
|
it('handles very long NSID', () => {
|
|
253
|
-
const nsid =
|
|
254
|
-
'com.example.very.long.namespace.identifier.oauth.permissions'
|
|
255
|
-
)
|
|
256
|
-
const permissions = [new Permission('resource:action', {})] as const
|
|
228
|
+
const nsid =
|
|
229
|
+
'com.example.very.long.namespace.identifier.oauth.permissions'
|
|
230
|
+
const permissions = [permission('resource:action', {})] as const
|
|
257
231
|
const options = {}
|
|
258
232
|
|
|
259
|
-
const
|
|
233
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
260
234
|
|
|
261
|
-
expect(
|
|
235
|
+
expect(perms.nsid).toBe(nsid)
|
|
262
236
|
})
|
|
263
237
|
|
|
264
238
|
it('handles long title strings', () => {
|
|
265
|
-
const nsid =
|
|
266
|
-
const permissions = [
|
|
267
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
268
|
-
] as const
|
|
239
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
240
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
269
241
|
const longTitle = 'A'.repeat(500)
|
|
270
242
|
const options = {
|
|
271
243
|
title: longTitle,
|
|
272
244
|
}
|
|
273
245
|
|
|
274
|
-
const
|
|
246
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
275
247
|
|
|
276
|
-
expect(
|
|
277
|
-
expect(
|
|
248
|
+
expect(perms.options.title).toBe(longTitle)
|
|
249
|
+
expect(perms.options.title?.length).toBe(500)
|
|
278
250
|
})
|
|
279
251
|
|
|
280
252
|
it('handles long detail strings', () => {
|
|
281
|
-
const nsid =
|
|
282
|
-
const permissions = [
|
|
283
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
284
|
-
] as const
|
|
253
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
254
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
285
255
|
const longDetail = 'B'.repeat(1000)
|
|
286
256
|
const options = {
|
|
287
257
|
detail: longDetail,
|
|
288
258
|
}
|
|
289
259
|
|
|
290
|
-
const
|
|
260
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
291
261
|
|
|
292
|
-
expect(
|
|
293
|
-
expect(
|
|
262
|
+
expect(perms.options.detail).toBe(longDetail)
|
|
263
|
+
expect(perms.options.detail?.length).toBe(1000)
|
|
294
264
|
})
|
|
295
265
|
|
|
296
266
|
it('handles multiple language codes in title:lang', () => {
|
|
297
|
-
const nsid =
|
|
298
|
-
const permissions = [
|
|
299
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
300
|
-
] as const
|
|
267
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
268
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
301
269
|
const options = {
|
|
302
270
|
title: 'Post Management',
|
|
303
271
|
'title:lang': {
|
|
@@ -312,18 +280,14 @@ describe('PermissionSet', () => {
|
|
|
312
280
|
},
|
|
313
281
|
}
|
|
314
282
|
|
|
315
|
-
const
|
|
283
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
316
284
|
|
|
317
|
-
expect(
|
|
318
|
-
Object.keys(permissionSet.options['title:lang'] || {}),
|
|
319
|
-
).toHaveLength(8)
|
|
285
|
+
expect(Object.keys(perms.options['title:lang'] || {})).toHaveLength(8)
|
|
320
286
|
})
|
|
321
287
|
|
|
322
288
|
it('handles undefined values in title:lang', () => {
|
|
323
|
-
const nsid =
|
|
324
|
-
const permissions = [
|
|
325
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
326
|
-
] as const
|
|
289
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
290
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
327
291
|
const options = {
|
|
328
292
|
title: 'Post Management',
|
|
329
293
|
'title:lang': {
|
|
@@ -333,20 +297,16 @@ describe('PermissionSet', () => {
|
|
|
333
297
|
},
|
|
334
298
|
}
|
|
335
299
|
|
|
336
|
-
const
|
|
300
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
337
301
|
|
|
338
|
-
expect(
|
|
339
|
-
|
|
340
|
-
)
|
|
341
|
-
expect(permissionSet.options['title:lang']?.fr).toBeUndefined()
|
|
342
|
-
expect(permissionSet.options['title:lang']?.de).toBe('Beitragsverwaltung')
|
|
302
|
+
expect(perms.options['title:lang']?.es).toBe('Gestión de Publicaciones')
|
|
303
|
+
expect(perms.options['title:lang']?.fr).toBeUndefined()
|
|
304
|
+
expect(perms.options['title:lang']?.de).toBe('Beitragsverwaltung')
|
|
343
305
|
})
|
|
344
306
|
|
|
345
307
|
it('handles undefined values in detail:lang', () => {
|
|
346
|
-
const nsid =
|
|
347
|
-
const permissions = [
|
|
348
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
349
|
-
] as const
|
|
308
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
309
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
350
310
|
const options = {
|
|
351
311
|
detail: 'Allows reading posts',
|
|
352
312
|
'detail:lang': {
|
|
@@ -355,113 +315,102 @@ describe('PermissionSet', () => {
|
|
|
355
315
|
},
|
|
356
316
|
}
|
|
357
317
|
|
|
358
|
-
const
|
|
318
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
359
319
|
|
|
360
|
-
expect(
|
|
361
|
-
expect(
|
|
320
|
+
expect(perms.options['detail:lang']?.es).toBeUndefined()
|
|
321
|
+
expect(perms.options['detail:lang']?.fr).toBe(
|
|
362
322
|
'Permet de lire les publications',
|
|
363
323
|
)
|
|
364
324
|
})
|
|
365
325
|
|
|
366
326
|
it('handles special characters in title', () => {
|
|
367
|
-
const nsid =
|
|
368
|
-
const permissions = [
|
|
369
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
370
|
-
] as const
|
|
327
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
328
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
371
329
|
const options = {
|
|
372
330
|
title: 'Post Management: Read & Write (Full Access)',
|
|
373
331
|
}
|
|
374
332
|
|
|
375
|
-
const
|
|
333
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
376
334
|
|
|
377
|
-
expect(
|
|
335
|
+
expect(perms.options.title).toBe(
|
|
378
336
|
'Post Management: Read & Write (Full Access)',
|
|
379
337
|
)
|
|
380
338
|
})
|
|
381
339
|
|
|
382
340
|
it('handles special characters in detail', () => {
|
|
383
|
-
const nsid =
|
|
384
|
-
const permissions = [
|
|
385
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
386
|
-
] as const
|
|
341
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
342
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
387
343
|
const options = {
|
|
388
344
|
detail:
|
|
389
345
|
'Allows reading posts, likes & reposts (includes all sub-resources)',
|
|
390
346
|
}
|
|
391
347
|
|
|
392
|
-
const
|
|
348
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
393
349
|
|
|
394
|
-
expect(
|
|
350
|
+
expect(perms.options.detail).toBe(
|
|
395
351
|
'Allows reading posts, likes & reposts (includes all sub-resources)',
|
|
396
352
|
)
|
|
397
353
|
})
|
|
398
354
|
|
|
399
355
|
it('handles unicode characters in title', () => {
|
|
400
|
-
const nsid =
|
|
401
|
-
const permissions = [
|
|
402
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
403
|
-
] as const
|
|
356
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
357
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
404
358
|
const options = {
|
|
405
359
|
title: '投稿管理 📝',
|
|
406
360
|
}
|
|
407
361
|
|
|
408
|
-
const
|
|
362
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
409
363
|
|
|
410
|
-
expect(
|
|
364
|
+
expect(perms.options.title).toBe('投稿管理 📝')
|
|
411
365
|
})
|
|
412
366
|
|
|
413
367
|
it('handles empty strings in title', () => {
|
|
414
|
-
const nsid =
|
|
415
|
-
const permissions = [
|
|
416
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
417
|
-
] as const
|
|
368
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
369
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
418
370
|
const options = {
|
|
419
371
|
title: '',
|
|
420
372
|
}
|
|
421
373
|
|
|
422
|
-
const
|
|
374
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
423
375
|
|
|
424
|
-
expect(
|
|
376
|
+
expect(perms.options.title).toBe('')
|
|
425
377
|
})
|
|
426
378
|
|
|
427
379
|
it('handles empty strings in detail', () => {
|
|
428
|
-
const nsid =
|
|
429
|
-
const permissions = [
|
|
430
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
431
|
-
] as const
|
|
380
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
381
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
432
382
|
const options = {
|
|
433
383
|
detail: '',
|
|
434
384
|
}
|
|
435
385
|
|
|
436
|
-
const
|
|
386
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
437
387
|
|
|
438
|
-
expect(
|
|
388
|
+
expect(perms.options.detail).toBe('')
|
|
439
389
|
})
|
|
440
390
|
|
|
441
391
|
it('handles large number of permissions', () => {
|
|
442
|
-
const nsid =
|
|
443
|
-
const permissions = Array.from(
|
|
444
|
-
{
|
|
445
|
-
(_, i) => new Permission(`resource${i}:action`, {}),
|
|
392
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
393
|
+
const permissions = Array.from({ length: 100 }, (_, i) =>
|
|
394
|
+
permission(`resource${i}:action`, {}),
|
|
446
395
|
) as any
|
|
447
396
|
const options = {}
|
|
448
397
|
|
|
449
|
-
const
|
|
398
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
450
399
|
|
|
451
|
-
expect(
|
|
400
|
+
expect(perms.permissions).toHaveLength(100)
|
|
452
401
|
})
|
|
453
402
|
})
|
|
454
403
|
|
|
455
404
|
describe('real-world permission set examples', () => {
|
|
456
405
|
it('creates a feed management permission set', () => {
|
|
457
|
-
const nsid =
|
|
406
|
+
const nsid = 'app.bsky.oauth.feed'
|
|
458
407
|
const permissions = [
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
408
|
+
permission('app.bsky.feed.post:read', {}),
|
|
409
|
+
permission('app.bsky.feed.post:write', {}),
|
|
410
|
+
permission('app.bsky.feed.like:read', {}),
|
|
411
|
+
permission('app.bsky.feed.like:write', {}),
|
|
412
|
+
permission('app.bsky.feed.repost:read', {}),
|
|
413
|
+
permission('app.bsky.feed.repost:write', {}),
|
|
465
414
|
] as const
|
|
466
415
|
const options = {
|
|
467
416
|
title: 'Feed Management',
|
|
@@ -476,39 +425,39 @@ describe('PermissionSet', () => {
|
|
|
476
425
|
},
|
|
477
426
|
}
|
|
478
427
|
|
|
479
|
-
const
|
|
428
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
480
429
|
|
|
481
|
-
expect(
|
|
482
|
-
expect(
|
|
483
|
-
expect(
|
|
430
|
+
expect(perms.nsid).toBe('app.bsky.oauth.feed')
|
|
431
|
+
expect(perms.permissions).toHaveLength(6)
|
|
432
|
+
expect(perms.options.title).toBe('Feed Management')
|
|
484
433
|
})
|
|
485
434
|
|
|
486
435
|
it('creates a read-only permission set', () => {
|
|
487
|
-
const nsid =
|
|
436
|
+
const nsid = 'app.bsky.oauth.readonly'
|
|
488
437
|
const permissions = [
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
438
|
+
permission('app.bsky.feed.post:read', {}),
|
|
439
|
+
permission('app.bsky.feed.like:read', {}),
|
|
440
|
+
permission('app.bsky.actor.profile:read', {}),
|
|
441
|
+
permission('app.bsky.graph.follow:read', {}),
|
|
493
442
|
] as const
|
|
494
443
|
const options = {
|
|
495
444
|
title: 'Read-Only Access',
|
|
496
445
|
detail: 'View posts, likes, profiles, and follows without modification',
|
|
497
446
|
}
|
|
498
447
|
|
|
499
|
-
const
|
|
448
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
500
449
|
|
|
501
|
-
expect(
|
|
502
|
-
expect(
|
|
503
|
-
|
|
504
|
-
)
|
|
450
|
+
expect(perms.nsid).toBe('app.bsky.oauth.readonly')
|
|
451
|
+
expect(perms.permissions.every((p) => p.resource.endsWith(':read'))).toBe(
|
|
452
|
+
true,
|
|
453
|
+
)
|
|
505
454
|
})
|
|
506
455
|
|
|
507
456
|
it('creates a profile management permission set', () => {
|
|
508
|
-
const nsid =
|
|
457
|
+
const nsid = 'app.bsky.oauth.profile'
|
|
509
458
|
const permissions = [
|
|
510
|
-
|
|
511
|
-
|
|
459
|
+
permission('app.bsky.actor.profile:read', {}),
|
|
460
|
+
permission('app.bsky.actor.profile:write', {}),
|
|
512
461
|
] as const
|
|
513
462
|
const options = {
|
|
514
463
|
title: 'Profile Management',
|
|
@@ -525,121 +474,107 @@ describe('PermissionSet', () => {
|
|
|
525
474
|
},
|
|
526
475
|
}
|
|
527
476
|
|
|
528
|
-
const
|
|
477
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
529
478
|
|
|
530
|
-
expect(
|
|
531
|
-
expect(
|
|
479
|
+
expect(perms.nsid).toBe('app.bsky.oauth.profile')
|
|
480
|
+
expect(perms.permissions).toHaveLength(2)
|
|
532
481
|
})
|
|
533
482
|
|
|
534
483
|
it('creates a minimal permission set', () => {
|
|
535
|
-
const nsid =
|
|
484
|
+
const nsid = 'app.bsky.oauth.minimal'
|
|
536
485
|
const permissions = [
|
|
537
|
-
|
|
486
|
+
permission('app.bsky.actor.profile:read', {}),
|
|
538
487
|
] as const
|
|
539
488
|
const options = {
|
|
540
489
|
title: 'Basic Access',
|
|
541
490
|
}
|
|
542
491
|
|
|
543
|
-
const
|
|
492
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
544
493
|
|
|
545
|
-
expect(
|
|
546
|
-
expect(
|
|
547
|
-
expect(
|
|
494
|
+
expect(perms.nsid).toBe('app.bsky.oauth.minimal')
|
|
495
|
+
expect(perms.permissions).toHaveLength(1)
|
|
496
|
+
expect(perms.options.detail).toBeUndefined()
|
|
548
497
|
})
|
|
549
498
|
})
|
|
550
499
|
|
|
551
500
|
describe('permission validation', () => {
|
|
552
501
|
it('validates that permissions are Permission instances', () => {
|
|
553
|
-
const nsid =
|
|
554
|
-
const permission1 =
|
|
555
|
-
const permission2 =
|
|
502
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
503
|
+
const permission1 = permission('app.bsky.feed.post:read', {})
|
|
504
|
+
const permission2 = permission('app.bsky.feed.post:write', {})
|
|
556
505
|
const permissions = [permission1, permission2] as const
|
|
557
506
|
const options = {}
|
|
558
507
|
|
|
559
|
-
const
|
|
508
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
560
509
|
|
|
561
|
-
expect(
|
|
562
|
-
expect(
|
|
510
|
+
expect(perms.permissions[0]).toBeInstanceOf(Permission)
|
|
511
|
+
expect(perms.permissions[1]).toBeInstanceOf(Permission)
|
|
563
512
|
})
|
|
564
513
|
|
|
565
514
|
it('preserves permission resource strings', () => {
|
|
566
|
-
const nsid =
|
|
515
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
567
516
|
const permissions = [
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
517
|
+
permission('app.bsky.feed.post:read', {}),
|
|
518
|
+
permission('app.bsky.feed.like:write', {}),
|
|
519
|
+
permission('app.bsky.graph.follow:read', {}),
|
|
571
520
|
] as const
|
|
572
521
|
const options = {}
|
|
573
522
|
|
|
574
|
-
const
|
|
523
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
575
524
|
|
|
576
|
-
expect(
|
|
577
|
-
|
|
578
|
-
)
|
|
579
|
-
expect(permissionSet.permissions[1].resource).toBe(
|
|
580
|
-
'app.bsky.feed.like:write',
|
|
581
|
-
)
|
|
582
|
-
expect(permissionSet.permissions[2].resource).toBe(
|
|
583
|
-
'app.bsky.graph.follow:read',
|
|
584
|
-
)
|
|
525
|
+
expect(perms.permissions[0].resource).toBe('app.bsky.feed.post:read')
|
|
526
|
+
expect(perms.permissions[1].resource).toBe('app.bsky.feed.like:write')
|
|
527
|
+
expect(perms.permissions[2].resource).toBe('app.bsky.graph.follow:read')
|
|
585
528
|
})
|
|
586
529
|
|
|
587
530
|
it('preserves permission options', () => {
|
|
588
|
-
const nsid =
|
|
531
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
589
532
|
const permissionOptions = { custom: 'value' }
|
|
590
533
|
const permissions = [
|
|
591
|
-
|
|
534
|
+
permission('app.bsky.feed.post:read', permissionOptions),
|
|
592
535
|
] as const
|
|
593
536
|
const options = {}
|
|
594
537
|
|
|
595
|
-
const
|
|
538
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
596
539
|
|
|
597
|
-
expect(
|
|
540
|
+
expect(perms.permissions[0].options).toBe(permissionOptions)
|
|
598
541
|
})
|
|
599
542
|
})
|
|
600
543
|
|
|
601
544
|
describe('option variations', () => {
|
|
602
545
|
it('accepts title without detail', () => {
|
|
603
|
-
const nsid =
|
|
604
|
-
const permissions = [
|
|
605
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
606
|
-
] as const
|
|
546
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
547
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
607
548
|
const options = {
|
|
608
549
|
title: 'Post Reading',
|
|
609
550
|
}
|
|
610
551
|
|
|
611
|
-
const
|
|
552
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
612
553
|
|
|
613
|
-
expect(
|
|
614
|
-
expect(
|
|
615
|
-
expect(
|
|
616
|
-
expect(
|
|
554
|
+
expect(perms.options.title).toBe('Post Reading')
|
|
555
|
+
expect(perms.options.detail).toBeUndefined()
|
|
556
|
+
expect(perms.options['title:lang']).toBeUndefined()
|
|
557
|
+
expect(perms.options['detail:lang']).toBeUndefined()
|
|
617
558
|
})
|
|
618
559
|
|
|
619
560
|
it('accepts detail without title', () => {
|
|
620
|
-
const nsid =
|
|
621
|
-
const permissions = [
|
|
622
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
623
|
-
] as const
|
|
561
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
562
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
624
563
|
const options = {
|
|
625
564
|
detail: 'Allows reading posts from the feed',
|
|
626
565
|
}
|
|
627
566
|
|
|
628
|
-
const
|
|
567
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
629
568
|
|
|
630
|
-
expect(
|
|
631
|
-
expect(
|
|
632
|
-
|
|
633
|
-
)
|
|
634
|
-
expect(permissionSet.options['title:lang']).toBeUndefined()
|
|
635
|
-
expect(permissionSet.options['detail:lang']).toBeUndefined()
|
|
569
|
+
expect(perms.options.title).toBeUndefined()
|
|
570
|
+
expect(perms.options.detail).toBe('Allows reading posts from the feed')
|
|
571
|
+
expect(perms.options['title:lang']).toBeUndefined()
|
|
572
|
+
expect(perms.options['detail:lang']).toBeUndefined()
|
|
636
573
|
})
|
|
637
574
|
|
|
638
575
|
it('accepts title:lang without title', () => {
|
|
639
|
-
const nsid =
|
|
640
|
-
const permissions = [
|
|
641
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
642
|
-
] as const
|
|
576
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
577
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
643
578
|
const options = {
|
|
644
579
|
'title:lang': {
|
|
645
580
|
es: 'Gestión de Publicaciones',
|
|
@@ -647,20 +582,18 @@ describe('PermissionSet', () => {
|
|
|
647
582
|
},
|
|
648
583
|
}
|
|
649
584
|
|
|
650
|
-
const
|
|
585
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
651
586
|
|
|
652
|
-
expect(
|
|
653
|
-
expect(
|
|
587
|
+
expect(perms.options.title).toBeUndefined()
|
|
588
|
+
expect(perms.options['title:lang']).toEqual({
|
|
654
589
|
es: 'Gestión de Publicaciones',
|
|
655
590
|
fr: 'Gestion des Publications',
|
|
656
591
|
})
|
|
657
592
|
})
|
|
658
593
|
|
|
659
594
|
it('accepts detail:lang without detail', () => {
|
|
660
|
-
const nsid =
|
|
661
|
-
const permissions = [
|
|
662
|
-
new Permission('app.bsky.feed.post:read', {}),
|
|
663
|
-
] as const
|
|
595
|
+
const nsid = 'app.bsky.oauth.permissions'
|
|
596
|
+
const permissions = [permission('app.bsky.feed.post:read', {})] as const
|
|
664
597
|
const options = {
|
|
665
598
|
'detail:lang': {
|
|
666
599
|
es: 'Permite leer publicaciones',
|
|
@@ -668,10 +601,10 @@ describe('PermissionSet', () => {
|
|
|
668
601
|
},
|
|
669
602
|
}
|
|
670
603
|
|
|
671
|
-
const
|
|
604
|
+
const perms = permissionSet(nsid, permissions, options)
|
|
672
605
|
|
|
673
|
-
expect(
|
|
674
|
-
expect(
|
|
606
|
+
expect(perms.options.detail).toBeUndefined()
|
|
607
|
+
expect(perms.options['detail:lang']).toEqual({
|
|
675
608
|
es: 'Permite leer publicaciones',
|
|
676
609
|
fr: 'Permet de lire les publications',
|
|
677
610
|
})
|