@api-client/core 0.18.59 → 0.18.61
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/build/src/modeling/ApiModel.d.ts.map +1 -1
- package/build/src/modeling/ApiModel.js +2 -2
- package/build/src/modeling/ApiModel.js.map +1 -1
- package/build/src/modeling/ExposedEntity.d.ts.map +1 -1
- package/build/src/modeling/ExposedEntity.js +4 -4
- package/build/src/modeling/ExposedEntity.js.map +1 -1
- package/build/src/modeling/actions/Action.d.ts.map +1 -1
- package/build/src/modeling/actions/Action.js +2 -2
- package/build/src/modeling/actions/Action.js.map +1 -1
- package/build/src/modeling/actions/index.d.ts +10 -0
- package/build/src/modeling/actions/index.d.ts.map +1 -1
- package/build/src/modeling/actions/index.js +30 -0
- package/build/src/modeling/actions/index.js.map +1 -1
- package/build/src/modeling/rules/AllowAuthenticated.d.ts +2 -2
- package/build/src/modeling/rules/AllowAuthenticated.d.ts.map +1 -1
- package/build/src/modeling/rules/AllowAuthenticated.js +1 -1
- package/build/src/modeling/rules/AllowAuthenticated.js.map +1 -1
- package/build/src/modeling/rules/AllowPublic.d.ts +2 -2
- package/build/src/modeling/rules/AllowPublic.d.ts.map +1 -1
- package/build/src/modeling/rules/AllowPublic.js +1 -1
- package/build/src/modeling/rules/AllowPublic.js.map +1 -1
- package/build/src/modeling/rules/MatchResourceOwner.d.ts +15 -6
- package/build/src/modeling/rules/MatchResourceOwner.d.ts.map +1 -1
- package/build/src/modeling/rules/MatchResourceOwner.js +18 -5
- package/build/src/modeling/rules/MatchResourceOwner.js.map +1 -1
- package/build/src/modeling/rules/index.d.ts +11 -0
- package/build/src/modeling/rules/index.d.ts.map +1 -1
- package/build/src/modeling/rules/index.js +30 -0
- package/build/src/modeling/rules/index.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +10 -10
- package/package.json +1 -1
- package/src/modeling/ApiModel.ts +2 -1
- package/src/modeling/ExposedEntity.ts +4 -2
- package/src/modeling/actions/Action.ts +2 -1
- package/src/modeling/rules/AllowAuthenticated.ts +3 -3
- package/src/modeling/rules/AllowPublic.ts +3 -3
- package/src/modeling/rules/MatchResourceOwner.ts +25 -10
- package/tests/unit/modeling/actions/Action.spec.ts +10 -10
- package/tests/unit/modeling/actions/CreateAction.spec.ts +8 -8
- package/tests/unit/modeling/actions/DeleteAction.spec.ts +5 -5
- package/tests/unit/modeling/actions/ReadAction.spec.ts +9 -9
- package/tests/unit/modeling/api_model.spec.ts +3 -3
- package/tests/unit/modeling/exposed_entity.spec.ts +8 -8
- package/tests/unit/modeling/exposed_entity_actions.spec.ts +182 -0
- package/tests/unit/modeling/rules/AllowAuthenticated.spec.ts +2 -2
- package/tests/unit/modeling/rules/AllowPublic.spec.ts +2 -2
- package/tests/unit/modeling/rules/MatchResourceOwner.spec.ts +24 -4
- package/tests/unit/modeling/rules/restoring_rules.spec.ts +121 -0
|
@@ -42810,6 +42810,9 @@
|
|
|
42810
42810
|
"@id": "#219"
|
|
42811
42811
|
},
|
|
42812
42812
|
{
|
|
42813
|
+
"@id": "#219"
|
|
42814
|
+
},
|
|
42815
|
+
{
|
|
42813
42816
|
"@id": "#210"
|
|
42814
42817
|
},
|
|
42815
42818
|
{
|
|
@@ -42817,9 +42820,6 @@
|
|
|
42817
42820
|
},
|
|
42818
42821
|
{
|
|
42819
42822
|
"@id": "#216"
|
|
42820
|
-
},
|
|
42821
|
-
{
|
|
42822
|
-
"@id": "#219"
|
|
42823
42823
|
}
|
|
42824
42824
|
],
|
|
42825
42825
|
"doc:root": false,
|
|
@@ -44232,7 +44232,7 @@
|
|
|
44232
44232
|
"doc:ExternalDomainElement",
|
|
44233
44233
|
"doc:DomainElement"
|
|
44234
44234
|
],
|
|
44235
|
-
"doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '
|
|
44235
|
+
"doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
|
|
44236
44236
|
"core:mediaType": "application/yaml",
|
|
44237
44237
|
"sourcemaps:sources": [
|
|
44238
44238
|
{
|
|
@@ -44253,7 +44253,7 @@
|
|
|
44253
44253
|
"doc:ExternalDomainElement",
|
|
44254
44254
|
"doc:DomainElement"
|
|
44255
44255
|
],
|
|
44256
|
-
"doc:raw": "type: 'GENERAL'\
|
|
44256
|
+
"doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
|
|
44257
44257
|
"core:mediaType": "application/yaml",
|
|
44258
44258
|
"sourcemaps:sources": [
|
|
44259
44259
|
{
|
|
@@ -44274,7 +44274,7 @@
|
|
|
44274
44274
|
"doc:ExternalDomainElement",
|
|
44275
44275
|
"doc:DomainElement"
|
|
44276
44276
|
],
|
|
44277
|
-
"doc:raw": "
|
|
44277
|
+
"doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
|
|
44278
44278
|
"core:mediaType": "application/yaml",
|
|
44279
44279
|
"sourcemaps:sources": [
|
|
44280
44280
|
{
|
|
@@ -44295,7 +44295,7 @@
|
|
|
44295
44295
|
"doc:ExternalDomainElement",
|
|
44296
44296
|
"doc:DomainElement"
|
|
44297
44297
|
],
|
|
44298
|
-
"doc:raw": "type:
|
|
44298
|
+
"doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '22'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)22 000000'\n",
|
|
44299
44299
|
"core:mediaType": "application/yaml",
|
|
44300
44300
|
"sourcemaps:sources": [
|
|
44301
44301
|
{
|
|
@@ -45121,17 +45121,17 @@
|
|
|
45121
45121
|
{
|
|
45122
45122
|
"@id": "#215/source-map/lexical/element_0",
|
|
45123
45123
|
"sourcemaps:element": "amf://id#215",
|
|
45124
|
-
"sourcemaps:value": "[(1,0)-(
|
|
45124
|
+
"sourcemaps:value": "[(1,0)-(7,0)]"
|
|
45125
45125
|
},
|
|
45126
45126
|
{
|
|
45127
45127
|
"@id": "#218/source-map/lexical/element_0",
|
|
45128
45128
|
"sourcemaps:element": "amf://id#218",
|
|
45129
|
-
"sourcemaps:value": "[(1,0)-(
|
|
45129
|
+
"sourcemaps:value": "[(1,0)-(3,0)]"
|
|
45130
45130
|
},
|
|
45131
45131
|
{
|
|
45132
45132
|
"@id": "#221/source-map/lexical/element_0",
|
|
45133
45133
|
"sourcemaps:element": "amf://id#221",
|
|
45134
|
-
"sourcemaps:value": "[(1,0)-(
|
|
45134
|
+
"sourcemaps:value": "[(1,0)-(6,0)]"
|
|
45135
45135
|
},
|
|
45136
45136
|
{
|
|
45137
45137
|
"@id": "#338/source-map/synthesized-field/element_1",
|
package/package.json
CHANGED
package/src/modeling/ApiModel.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { createDomainKey } from './helpers/keying.js'
|
|
|
19
19
|
import { ExposedEntity } from './ExposedEntity.js'
|
|
20
20
|
import { AccessRule, AccessRuleSchema } from './rules/AccessRule.js'
|
|
21
21
|
import { RateLimitingConfiguration, RateLimitingConfigurationSchema } from './rules/RateLimitingConfiguration.js'
|
|
22
|
+
import { restoreAccessRule } from './rules/index.js'
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Contact information for the exposed API.
|
|
@@ -310,7 +311,7 @@ export class ApiModel extends DependentModel {
|
|
|
310
311
|
this.exposes = []
|
|
311
312
|
}
|
|
312
313
|
if (Array.isArray(init.accessRule)) {
|
|
313
|
-
this.accessRule = init.accessRule.map((rule) =>
|
|
314
|
+
this.accessRule = init.accessRule.map((rule) => restoreAccessRule(rule))
|
|
314
315
|
} else {
|
|
315
316
|
this.accessRule = []
|
|
316
317
|
}
|
|
@@ -2,9 +2,11 @@ import { observed } from '../decorators/observed.js'
|
|
|
2
2
|
import { ExposedEntityKind } from '../models/kinds.js'
|
|
3
3
|
import { nanoid } from '../nanoid.js'
|
|
4
4
|
import { Action } from './actions/Action.js'
|
|
5
|
+
import { restoreAction } from './actions/index.js'
|
|
5
6
|
import type { ApiModel } from './ApiModel.js'
|
|
6
7
|
import { ensureLeadingSlash, joinPaths } from './helpers/endpointHelpers.js'
|
|
7
8
|
import { AccessRule } from './rules/AccessRule.js'
|
|
9
|
+
import { restoreAccessRule } from './rules/index.js'
|
|
8
10
|
import { RateLimitingConfiguration } from './rules/RateLimitingConfiguration.js'
|
|
9
11
|
import type { AssociationTarget, ExposeOptions, ExposeParentRef, ExposedEntitySchema } from './types.js'
|
|
10
12
|
|
|
@@ -182,8 +184,8 @@ export class ExposedEntity extends EventTarget {
|
|
|
182
184
|
this.isRoot = init.isRoot
|
|
183
185
|
this.parent = init.parent
|
|
184
186
|
this.exposeOptions = init.exposeOptions
|
|
185
|
-
this.actions = init.actions ? init.actions.map((a) =>
|
|
186
|
-
this.accessRule = init.accessRule ? init.accessRule.map((ar) =>
|
|
187
|
+
this.actions = init.actions ? init.actions.map((a) => restoreAction(a)) : []
|
|
188
|
+
this.accessRule = init.accessRule ? init.accessRule.map((ar) => restoreAccessRule(ar)) : []
|
|
187
189
|
this.rateLimiting = init.rateLimiting ? new RateLimitingConfiguration(init.rateLimiting) : undefined
|
|
188
190
|
this.truncated = init.truncated
|
|
189
191
|
this.#initializing = false
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AccessRule, AccessRuleSchema } from '../rules/AccessRule.js'
|
|
2
2
|
import { RateLimitingConfiguration, RateLimitingConfigurationSchema } from '../rules/RateLimitingConfiguration.js'
|
|
3
3
|
import { observed } from '../../decorators/observed.js'
|
|
4
|
+
import { restoreAccessRule } from '../rules/index.js'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* A base interface for common properties across all actions.
|
|
@@ -41,7 +42,7 @@ export class Action extends EventTarget implements ActionSchema {
|
|
|
41
42
|
constructor(state: Partial<ActionSchema> = {}) {
|
|
42
43
|
super()
|
|
43
44
|
this.kind = state.kind || ''
|
|
44
|
-
this.accessRule = state.accessRule ? state.accessRule.map((rule) =>
|
|
45
|
+
this.accessRule = state.accessRule ? state.accessRule.map((rule) => restoreAccessRule(rule)) : []
|
|
45
46
|
this.rateLimiting = state.rateLimiting ? new RateLimitingConfiguration(state.rateLimiting) : undefined
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -6,7 +6,7 @@ import { AccessRule, type AccessRuleSchema } from './AccessRule.js'
|
|
|
6
6
|
* It is used for resources that should be accessible to all logged-in users.
|
|
7
7
|
*/
|
|
8
8
|
export interface AllowAuthenticatedAccessRuleSchema extends AccessRuleSchema {
|
|
9
|
-
type: '
|
|
9
|
+
type: 'allowAuthenticated'
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -15,10 +15,10 @@ export interface AllowAuthenticatedAccessRuleSchema extends AccessRuleSchema {
|
|
|
15
15
|
* It is used for resources that should be accessible to all logged-in users.
|
|
16
16
|
*/
|
|
17
17
|
export class AllowAuthenticatedAccessRule extends AccessRule implements AllowAuthenticatedAccessRuleSchema {
|
|
18
|
-
override readonly type: '
|
|
18
|
+
override readonly type: 'allowAuthenticated'
|
|
19
19
|
|
|
20
20
|
constructor(state: Partial<AllowAuthenticatedAccessRuleSchema> = {}) {
|
|
21
21
|
super(state)
|
|
22
|
-
this.type = '
|
|
22
|
+
this.type = 'allowAuthenticated'
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -6,7 +6,7 @@ import { AccessRule, type AccessRuleSchema } from './AccessRule.js'
|
|
|
6
6
|
* It is the most permissive rule and should be used with caution.
|
|
7
7
|
*/
|
|
8
8
|
export interface AllowPublicAccessRuleSchema extends AccessRuleSchema {
|
|
9
|
-
type: '
|
|
9
|
+
type: 'allowPublic'
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -15,10 +15,10 @@ export interface AllowPublicAccessRuleSchema extends AccessRuleSchema {
|
|
|
15
15
|
* It is the most permissive rule and should be used with caution.
|
|
16
16
|
*/
|
|
17
17
|
export class AllowPublicAccessRule extends AccessRule implements AllowPublicAccessRuleSchema {
|
|
18
|
-
override readonly type: '
|
|
18
|
+
override readonly type: 'allowPublic'
|
|
19
19
|
|
|
20
20
|
constructor(state: Partial<AllowPublicAccessRuleSchema> = {}) {
|
|
21
21
|
super(state)
|
|
22
|
-
this.type = '
|
|
22
|
+
this.type = 'allowPublic'
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -7,15 +7,24 @@ import { observed } from '../../decorators/observed.js'
|
|
|
7
7
|
* For example, a user can only access their own profile or documents.
|
|
8
8
|
*/
|
|
9
9
|
export interface MatchResourceOwnerAccessRuleSchema extends AccessRuleSchema {
|
|
10
|
-
type: '
|
|
10
|
+
type: 'matchResourceOwner'
|
|
11
11
|
/**
|
|
12
|
-
* The property on the resource that
|
|
13
|
-
*
|
|
12
|
+
* The property on the resource that references the user's ID (the key in the semantically annotated `User` entity).
|
|
13
|
+
*
|
|
14
|
+
* When the current exposed entity has a property annotated with the "ResourceOwnerIdentifier" semantic,
|
|
15
|
+
* this property should be used. It directly references the user's key.
|
|
14
16
|
*
|
|
15
17
|
* The domain model should annotate this property with the "ResourceOwnerIdentifier" semantic
|
|
16
18
|
* to indicate that it is used for ownership checks.
|
|
17
19
|
*/
|
|
18
|
-
property
|
|
20
|
+
property?: string
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The target for the ownership check.
|
|
24
|
+
* - `property`: The check is performed against a specific property on the resource (default).
|
|
25
|
+
* - `user-entity`: The check is performed against the entity itself (used when the entity represents the user).
|
|
26
|
+
*/
|
|
27
|
+
target?: 'property' | 'user-entity'
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
/**
|
|
@@ -24,20 +33,26 @@ export interface MatchResourceOwnerAccessRuleSchema extends AccessRuleSchema {
|
|
|
24
33
|
* For example, a user can only access their own profile or documents.
|
|
25
34
|
*/
|
|
26
35
|
export class MatchResourceOwnerAccessRule extends AccessRule implements MatchResourceOwnerAccessRuleSchema {
|
|
27
|
-
override readonly type: '
|
|
36
|
+
override readonly type: 'matchResourceOwner'
|
|
28
37
|
|
|
29
|
-
@observed() accessor property: string
|
|
38
|
+
@observed() accessor property: string | undefined
|
|
39
|
+
@observed() accessor target: 'property' | 'user-entity'
|
|
30
40
|
|
|
31
41
|
constructor(state: Partial<MatchResourceOwnerAccessRuleSchema> = {}) {
|
|
32
42
|
super(state)
|
|
33
|
-
this.type = '
|
|
34
|
-
this.property = state.property
|
|
43
|
+
this.type = 'matchResourceOwner'
|
|
44
|
+
this.property = state.property
|
|
45
|
+
this.target = state.target ?? 'property'
|
|
35
46
|
}
|
|
36
47
|
|
|
37
48
|
override toJSON(): MatchResourceOwnerAccessRuleSchema {
|
|
38
|
-
|
|
49
|
+
const json: MatchResourceOwnerAccessRuleSchema = {
|
|
39
50
|
...(super.toJSON() as MatchResourceOwnerAccessRuleSchema),
|
|
40
|
-
|
|
51
|
+
target: this.target,
|
|
52
|
+
}
|
|
53
|
+
if (this.property) {
|
|
54
|
+
json.property = this.property
|
|
41
55
|
}
|
|
56
|
+
return json
|
|
42
57
|
}
|
|
43
58
|
}
|
|
@@ -13,27 +13,27 @@ test.group('Action', () => {
|
|
|
13
13
|
test('initializes with provided values', ({ assert }) => {
|
|
14
14
|
const schema: ActionSchema = {
|
|
15
15
|
kind: 'read',
|
|
16
|
-
accessRule: [{ type: '
|
|
16
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
17
17
|
rateLimiting: { rules: [] },
|
|
18
18
|
}
|
|
19
19
|
const action = new Action(schema)
|
|
20
20
|
assert.equal(action.kind, 'read')
|
|
21
21
|
assert.lengthOf(action.accessRule, 1)
|
|
22
22
|
assert.instanceOf(action.accessRule[0], AccessRule)
|
|
23
|
-
assert.equal(action.accessRule[0].type, '
|
|
23
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
24
24
|
assert.instanceOf(action.rateLimiting, RateLimitingConfiguration)
|
|
25
25
|
}).tags(['@modeling', '@action'])
|
|
26
26
|
|
|
27
27
|
test('serializes to JSON', ({ assert }) => {
|
|
28
28
|
const action = new Action({
|
|
29
29
|
kind: 'write',
|
|
30
|
-
accessRule: [{ type: '
|
|
30
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
31
31
|
rateLimiting: { rules: [] },
|
|
32
32
|
})
|
|
33
33
|
const json = action.toJSON()
|
|
34
34
|
|
|
35
35
|
assert.equal(json.kind, 'write')
|
|
36
|
-
assert.deepEqual(json.accessRule, [{ type: '
|
|
36
|
+
assert.deepEqual(json.accessRule, [{ type: 'allowPublic' }])
|
|
37
37
|
assert.deepEqual(json.rateLimiting, { rules: [] })
|
|
38
38
|
}).tags(['@modeling', '@action'])
|
|
39
39
|
|
|
@@ -58,7 +58,7 @@ test.group('Action', () => {
|
|
|
58
58
|
notified = true
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
action.accessRule = [new AccessRule({ type: '
|
|
61
|
+
action.accessRule = [new AccessRule({ type: 'allowPublic' })]
|
|
62
62
|
await Promise.resolve()
|
|
63
63
|
assert.isTrue(notified)
|
|
64
64
|
}).tags(['@modeling', '@action', '@observed'])
|
|
@@ -76,21 +76,21 @@ test.group('Action', () => {
|
|
|
76
76
|
}).tags(['@modeling', '@action', '@observed'])
|
|
77
77
|
|
|
78
78
|
test('constructor copies accessRule array (immutability)', ({ assert }) => {
|
|
79
|
-
const rules = [{ type: '
|
|
79
|
+
const rules = [{ type: 'allowPublic' }]
|
|
80
80
|
const action = new Action({ kind: 'read', accessRule: rules })
|
|
81
81
|
|
|
82
82
|
// Modify original array
|
|
83
|
-
rules.push({ type: '
|
|
83
|
+
rules.push({ type: 'other' })
|
|
84
84
|
rules[0].type = 'changed'
|
|
85
85
|
|
|
86
86
|
assert.lengthOf(action.accessRule, 1)
|
|
87
|
-
assert.equal(action.accessRule[0].type, '
|
|
87
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
88
88
|
}).tags(['@modeling', '@action', '@immutability'])
|
|
89
89
|
|
|
90
90
|
test('toJSON returns safe copy', ({ assert }) => {
|
|
91
91
|
const action = new Action({
|
|
92
92
|
kind: 'read',
|
|
93
|
-
accessRule: [{ type: '
|
|
93
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
94
94
|
rateLimiting: { rules: [] },
|
|
95
95
|
})
|
|
96
96
|
const json = action.toJSON()
|
|
@@ -104,6 +104,6 @@ test.group('Action', () => {
|
|
|
104
104
|
|
|
105
105
|
assert.equal(action.kind, 'read')
|
|
106
106
|
assert.lengthOf(action.accessRule, 1)
|
|
107
|
-
assert.equal(action.accessRule[0].type, '
|
|
107
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
108
108
|
}).tags(['@modeling', '@action', '@immutability'])
|
|
109
109
|
})
|
|
@@ -11,32 +11,32 @@ test.group('CreateAction', () => {
|
|
|
11
11
|
|
|
12
12
|
test('initializes with inherited values', ({ assert }) => {
|
|
13
13
|
const action = new CreateAction({
|
|
14
|
-
accessRule: [{ type: '
|
|
14
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
assert.equal(action.kind, 'create')
|
|
18
18
|
assert.lengthOf(action.accessRule, 1)
|
|
19
|
-
assert.equal(action.accessRule[0].type, '
|
|
19
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
20
20
|
}).tags(['@modeling', '@action', '@create-action'])
|
|
21
21
|
|
|
22
22
|
test('constructor copies arrays (immutability)', ({ assert }) => {
|
|
23
|
-
const rules = [{ type: '
|
|
23
|
+
const rules = [{ type: 'allowPublic' }]
|
|
24
24
|
|
|
25
25
|
const action = new CreateAction({
|
|
26
26
|
accessRule: rules,
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
// Modify original source
|
|
30
|
-
rules.push({ type: '
|
|
30
|
+
rules.push({ type: 'other' })
|
|
31
31
|
rules[0].type = 'changed'
|
|
32
32
|
|
|
33
33
|
assert.lengthOf(action.accessRule, 1)
|
|
34
|
-
assert.equal(action.accessRule[0].type, '
|
|
34
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
35
35
|
}).tags(['@modeling', '@action', '@create-action', '@immutability'])
|
|
36
36
|
|
|
37
37
|
test('toJSON returns valid schema', ({ assert }) => {
|
|
38
38
|
const action = new CreateAction({
|
|
39
|
-
accessRule: [{ type: '
|
|
39
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
const json = action.toJSON()
|
|
@@ -44,7 +44,7 @@ test.group('CreateAction', () => {
|
|
|
44
44
|
assert.equal(json.kind, 'create')
|
|
45
45
|
if (json.accessRule) {
|
|
46
46
|
assert.lengthOf(json.accessRule, 1)
|
|
47
|
-
assert.equal(json.accessRule[0].type, '
|
|
47
|
+
assert.equal(json.accessRule[0].type, 'allowPublic')
|
|
48
48
|
} else {
|
|
49
49
|
assert.fail('accessRule should be present in JSON')
|
|
50
50
|
}
|
|
@@ -58,7 +58,7 @@ test.group('CreateAction', () => {
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
// Modify inherited property
|
|
61
|
-
action.accessRule = [new AccessRule({ type: '
|
|
61
|
+
action.accessRule = [new AccessRule({ type: 'allowPublic' })]
|
|
62
62
|
await Promise.resolve()
|
|
63
63
|
assert.isTrue(notified)
|
|
64
64
|
}).tags(['@modeling', '@action', '@create-action', '@observed'])
|
|
@@ -14,29 +14,29 @@ test.group('DeleteAction', () => {
|
|
|
14
14
|
const action = new DeleteAction({
|
|
15
15
|
strategy: 'hard',
|
|
16
16
|
retentionPeriod: 0,
|
|
17
|
-
accessRule: [{ type: '
|
|
17
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
assert.equal(action.kind, 'delete')
|
|
21
21
|
assert.equal(action.strategy, 'hard')
|
|
22
22
|
assert.equal(action.retentionPeriod, 0)
|
|
23
23
|
assert.lengthOf(action.accessRule, 1)
|
|
24
|
-
assert.equal(action.accessRule[0].type, '
|
|
24
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
25
25
|
}).tags(['@modeling', '@action', '@delete-action'])
|
|
26
26
|
|
|
27
27
|
test('constructor copies arrays (immutability)', ({ assert }) => {
|
|
28
|
-
const rules = [{ type: '
|
|
28
|
+
const rules = [{ type: 'allowPublic' }]
|
|
29
29
|
|
|
30
30
|
const action = new DeleteAction({
|
|
31
31
|
accessRule: rules,
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
// Modify original source
|
|
35
|
-
rules.push({ type: '
|
|
35
|
+
rules.push({ type: 'other' })
|
|
36
36
|
rules[0].type = 'changed'
|
|
37
37
|
|
|
38
38
|
assert.lengthOf(action.accessRule, 1)
|
|
39
|
-
assert.equal(action.accessRule[0].type, '
|
|
39
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
40
40
|
}).tags(['@modeling', '@action', '@delete-action', '@immutability'])
|
|
41
41
|
|
|
42
42
|
test('toJSON returns valid schema', ({ assert }) => {
|
|
@@ -11,32 +11,32 @@ test.group('ReadAction', () => {
|
|
|
11
11
|
|
|
12
12
|
test('initializes with inherited values', ({ assert }) => {
|
|
13
13
|
const action = new ReadAction({
|
|
14
|
-
accessRule: [{ type: '
|
|
14
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
assert.equal(action.kind, 'read')
|
|
18
18
|
assert.lengthOf(action.accessRule, 1)
|
|
19
|
-
assert.equal(action.accessRule[0].type, '
|
|
19
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
20
20
|
}).tags(['@modeling', '@action', '@read-action'])
|
|
21
21
|
|
|
22
22
|
test('constructor copies arrays (immutability)', ({ assert }) => {
|
|
23
|
-
const rules = [{ type: '
|
|
23
|
+
const rules = [{ type: 'allowPublic' }]
|
|
24
24
|
|
|
25
25
|
const action = new ReadAction({
|
|
26
26
|
accessRule: rules,
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
// Modify original source
|
|
30
|
-
rules.push({ type: '
|
|
30
|
+
rules.push({ type: 'other' })
|
|
31
31
|
rules[0].type = 'changed'
|
|
32
32
|
|
|
33
33
|
assert.lengthOf(action.accessRule, 1)
|
|
34
|
-
assert.equal(action.accessRule[0].type, '
|
|
34
|
+
assert.equal(action.accessRule[0].type, 'allowPublic')
|
|
35
35
|
}).tags(['@modeling', '@action', '@read-action', '@immutability'])
|
|
36
36
|
|
|
37
37
|
test('toJSON returns valid schema', ({ assert }) => {
|
|
38
38
|
const action = new ReadAction({
|
|
39
|
-
accessRule: [{ type: '
|
|
39
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
const json = action.toJSON()
|
|
@@ -44,7 +44,7 @@ test.group('ReadAction', () => {
|
|
|
44
44
|
assert.equal(json.kind, 'read')
|
|
45
45
|
if (json.accessRule) {
|
|
46
46
|
assert.lengthOf(json.accessRule, 1)
|
|
47
|
-
assert.equal(json.accessRule[0].type, '
|
|
47
|
+
assert.equal(json.accessRule[0].type, 'allowPublic')
|
|
48
48
|
} else {
|
|
49
49
|
assert.fail('accessRule should be present in JSON')
|
|
50
50
|
}
|
|
@@ -58,7 +58,7 @@ test.group('ReadAction', () => {
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
// Modify inherited property
|
|
61
|
-
action.accessRule = [new AccessRule({ type: '
|
|
61
|
+
action.accessRule = [new AccessRule({ type: 'allowPublic' })]
|
|
62
62
|
await Promise.resolve()
|
|
63
63
|
assert.isTrue(notified)
|
|
64
64
|
}).tags(['@modeling', '@action', '@read-action', '@observed'])
|
|
@@ -70,7 +70,7 @@ test.group('ReadAction', () => {
|
|
|
70
70
|
notified = true
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
-
action.accessRule.push(new AccessRule({ type: '
|
|
73
|
+
action.accessRule.push(new AccessRule({ type: 'allowPublic' }))
|
|
74
74
|
await Promise.resolve()
|
|
75
75
|
assert.isTrue(notified)
|
|
76
76
|
}).tags(['@modeling', '@action', '@read-action', '@observed'])
|
|
@@ -130,7 +130,7 @@ test.group('ApiModel.constructor()', () => {
|
|
|
130
130
|
authentication: { strategy: 'UsernamePassword' },
|
|
131
131
|
authorization: { strategy: 'RBAC', roleKey: 'role' } as RolesBasedAccessControl,
|
|
132
132
|
session: { secret: 'secret', properties: ['email'] },
|
|
133
|
-
accessRule: [{ type: '
|
|
133
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
134
134
|
rateLimiting: { rules: [] },
|
|
135
135
|
termsOfService: 'https://example.com/terms',
|
|
136
136
|
contact: { name: 'John Doe', email: 'john.doe@example.com' },
|
|
@@ -263,7 +263,7 @@ test.group('ApiModel.toJSON()', () => {
|
|
|
263
263
|
authentication: { strategy: 'UsernamePassword' },
|
|
264
264
|
authorization: { strategy: 'RBAC', roleKey: 'role' } as RolesBasedAccessControl,
|
|
265
265
|
session: { secret: 'secret', properties: ['email'] },
|
|
266
|
-
accessRule: [{ type: '
|
|
266
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
267
267
|
rateLimiting: { rules: [] },
|
|
268
268
|
termsOfService: 'https://example.com/terms',
|
|
269
269
|
contact: { name: 'John Doe', email: 'john.doe@example.com' },
|
|
@@ -281,7 +281,7 @@ test.group('ApiModel.toJSON()', () => {
|
|
|
281
281
|
assert.deepEqual(json.authentication, { strategy: 'UsernamePassword' })
|
|
282
282
|
assert.deepEqual(json.authorization, { strategy: 'RBAC', roleKey: 'role' })
|
|
283
283
|
assert.deepEqual(json.session, { secret: 'secret', properties: ['email'] })
|
|
284
|
-
assert.deepEqual(json.accessRule, [{ type: '
|
|
284
|
+
assert.deepEqual(json.accessRule, [{ type: 'allowPublic' }])
|
|
285
285
|
assert.deepEqual(json.rateLimiting, { rules: [] })
|
|
286
286
|
assert.equal(json.termsOfService, 'https://example.com/terms')
|
|
287
287
|
assert.deepEqual(json.contact, { name: 'John Doe', email: 'john.doe@example.com' })
|
|
@@ -156,29 +156,29 @@ test.group('ExposedEntity', () => {
|
|
|
156
156
|
test('restores actions and rules from schema', ({ assert }) => {
|
|
157
157
|
const model = new ApiModel()
|
|
158
158
|
const ex = new ExposedEntity(model, {
|
|
159
|
-
actions: [{ kind: 'read', accessRule: [{ type: '
|
|
160
|
-
accessRule: [{ type: '
|
|
159
|
+
actions: [{ kind: 'read', accessRule: [{ type: 'allowPublic' }] }],
|
|
160
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
161
161
|
})
|
|
162
162
|
|
|
163
163
|
assert.lengthOf(ex.actions, 1)
|
|
164
164
|
assert.equal(ex.actions[0].kind, 'read')
|
|
165
165
|
assert.lengthOf(ex.actions[0].accessRule, 1)
|
|
166
|
-
assert.equal(ex.actions[0].accessRule[0].type, '
|
|
166
|
+
assert.equal(ex.actions[0].accessRule[0].type, 'allowPublic')
|
|
167
167
|
|
|
168
168
|
assert.lengthOf(ex.accessRule!, 1)
|
|
169
|
-
assert.equal(ex.accessRule![0].type, '
|
|
169
|
+
assert.equal(ex.accessRule![0].type, 'allowPublic')
|
|
170
170
|
}).tags(['@modeling', '@exposed-entity'])
|
|
171
171
|
|
|
172
172
|
test('serializes actions and rules', ({ assert }) => {
|
|
173
173
|
const model = new ApiModel()
|
|
174
174
|
const ex = new ExposedEntity(model, {
|
|
175
175
|
actions: [{ kind: 'read' }],
|
|
176
|
-
accessRule: [{ type: '
|
|
176
|
+
accessRule: [{ type: 'allowPublic' }],
|
|
177
177
|
})
|
|
178
178
|
|
|
179
179
|
const json = ex.toJSON()
|
|
180
180
|
assert.deepInclude(json.actions[0], { kind: 'read' })
|
|
181
|
-
assert.deepInclude(json.accessRule![0], { type: '
|
|
181
|
+
assert.deepInclude(json.accessRule![0], { type: 'allowPublic' })
|
|
182
182
|
}).tags(['@modeling', '@exposed-entity'])
|
|
183
183
|
|
|
184
184
|
test('notifies change when action property changes', async ({ assert }) => {
|
|
@@ -212,7 +212,7 @@ test.group('ExposedEntity', () => {
|
|
|
212
212
|
|
|
213
213
|
test('constructor copies accessRule array (immutability)', ({ assert }) => {
|
|
214
214
|
const model = new ApiModel()
|
|
215
|
-
const rules = [{ type: '
|
|
215
|
+
const rules = [{ type: 'allowPublic' }]
|
|
216
216
|
const ex = new ExposedEntity(model, {
|
|
217
217
|
actions: [],
|
|
218
218
|
accessRule: rules,
|
|
@@ -223,6 +223,6 @@ test.group('ExposedEntity', () => {
|
|
|
223
223
|
rules[0].type = 'changed'
|
|
224
224
|
|
|
225
225
|
assert.lengthOf(ex.accessRule!, 1)
|
|
226
|
-
assert.equal(ex.accessRule![0].type, '
|
|
226
|
+
assert.equal(ex.accessRule![0].type, 'allowPublic')
|
|
227
227
|
}).tags(['@modeling', '@exposed-entity', '@immutability'])
|
|
228
228
|
})
|