@contember/engine-server 1.2.0-alpha.1 → 1.2.0-alpha.4

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.
Files changed (73) hide show
  1. package/dist/src/MasterContainer.d.ts +18 -3
  2. package/dist/src/MasterContainer.d.ts.map +1 -1
  3. package/dist/src/MasterContainer.js +19 -1
  4. package/dist/src/MasterContainer.js.map +1 -1
  5. package/dist/src/bootstrap/Initializer.d.ts.map +1 -1
  6. package/dist/src/bootstrap/Initializer.js +0 -2
  7. package/dist/src/bootstrap/Initializer.js.map +1 -1
  8. package/dist/src/tsconfig.tsbuildinfo +1 -1
  9. package/dist/src/utils/sentry.d.ts +1 -1
  10. package/dist/src/utils/sentry.d.ts.map +1 -1
  11. package/dist/src/utils/sentry.js +1 -1
  12. package/dist/src/utils/sentry.js.map +1 -1
  13. package/dist/tests/e2e/acl-condition-variable.test.d.ts +2 -0
  14. package/dist/tests/e2e/acl-condition-variable.test.d.ts.map +1 -0
  15. package/dist/tests/e2e/acl-condition-variable.test.js +77 -0
  16. package/dist/tests/e2e/acl-condition-variable.test.js.map +1 -0
  17. package/dist/tests/e2e/assume-identity.test.d.ts +2 -0
  18. package/dist/tests/e2e/assume-identity.test.d.ts.map +1 -0
  19. package/dist/tests/e2e/assume-identity.test.js +109 -0
  20. package/dist/tests/e2e/assume-identity.test.js.map +1 -0
  21. package/dist/tests/e2e/assume-membership.test.d.ts +2 -0
  22. package/dist/tests/e2e/assume-membership.test.d.ts.map +1 -0
  23. package/dist/tests/e2e/assume-membership.test.js +58 -0
  24. package/dist/tests/e2e/assume-membership.test.js.map +1 -0
  25. package/dist/tests/e2e/content-api-basic.test.d.ts +2 -0
  26. package/dist/tests/e2e/content-api-basic.test.d.ts.map +1 -0
  27. package/dist/tests/e2e/content-api-basic.test.js +50 -0
  28. package/dist/tests/e2e/content-api-basic.test.js.map +1 -0
  29. package/dist/tests/e2e/content-invalid-schema.test.d.ts +2 -0
  30. package/dist/tests/e2e/content-invalid-schema.test.d.ts.map +1 -0
  31. package/dist/tests/e2e/content-invalid-schema.test.js +29 -0
  32. package/dist/tests/e2e/content-invalid-schema.test.js.map +1 -0
  33. package/dist/tests/e2e/homepage.test.d.ts +2 -0
  34. package/dist/tests/e2e/homepage.test.d.ts.map +1 -0
  35. package/dist/tests/e2e/homepage.test.js +15 -0
  36. package/dist/tests/e2e/homepage.test.js.map +1 -0
  37. package/dist/tests/e2e/tenant-member-access.test.d.ts +2 -0
  38. package/dist/tests/e2e/tenant-member-access.test.d.ts.map +1 -0
  39. package/dist/tests/e2e/tenant-member-access.test.js +43 -0
  40. package/dist/tests/e2e/tenant-member-access.test.js.map +1 -0
  41. package/dist/tests/e2e/x-contember-ref.test.d.ts +2 -0
  42. package/dist/tests/e2e/x-contember-ref.test.d.ts.map +1 -0
  43. package/dist/tests/e2e/x-contember-ref.test.js +63 -0
  44. package/dist/tests/e2e/x-contember-ref.test.js.map +1 -0
  45. package/dist/tests/{e2e → src}/requests.d.ts +2 -1
  46. package/dist/tests/src/requests.d.ts.map +1 -0
  47. package/dist/tests/{e2e → src}/requests.js +14 -5
  48. package/dist/tests/{e2e → src}/requests.js.map +1 -1
  49. package/dist/tests/{e2e → src}/tester.d.ts +0 -0
  50. package/dist/tests/{e2e → src}/tester.d.ts.map +1 -1
  51. package/dist/tests/{e2e → src}/tester.js +0 -0
  52. package/dist/tests/{e2e → src}/tester.js.map +1 -1
  53. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +23 -23
  55. package/src/MasterContainer.ts +38 -2
  56. package/src/bootstrap/Initializer.ts +0 -2
  57. package/src/utils/sentry.ts +1 -1
  58. package/tests/e2e/acl-condition-variable.test.ts +74 -0
  59. package/tests/e2e/assume-identity.test.ts +127 -0
  60. package/tests/e2e/assume-membership.test.ts +64 -0
  61. package/tests/e2e/content-api-basic.test.ts +51 -0
  62. package/tests/e2e/content-invalid-schema.test.ts +31 -0
  63. package/tests/e2e/homepage.test.ts +10 -0
  64. package/tests/e2e/tenant-member-access.test.ts +51 -0
  65. package/tests/e2e/x-contember-ref.test.ts +71 -0
  66. package/tests/{e2e → src}/requests.ts +15 -5
  67. package/tests/{e2e → src}/tester.ts +0 -0
  68. package/dist/tests/e2e/http.test.d.ts +0 -2
  69. package/dist/tests/e2e/http.test.d.ts.map +0 -1
  70. package/dist/tests/e2e/http.test.js +0 -192
  71. package/dist/tests/e2e/http.test.js.map +0 -1
  72. package/dist/tests/e2e/requests.d.ts.map +0 -1
  73. package/tests/e2e/http.test.ts +0 -237
@@ -1,192 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const supertest_1 = __importDefault(require("supertest"));
7
- const vitest_1 = require("vitest");
8
- const schema_definition_1 = require("@contember/schema-definition");
9
- const tester_1 = require("./tester");
10
- const requests_1 = require("./requests");
11
- (0, vitest_1.test)('show homepage', async () => {
12
- await (0, supertest_1.default)(tester_1.apiUrl)
13
- .get('/')
14
- .expect(200)
15
- .expect('App is running');
16
- });
17
- var TagModel;
18
- (function (TagModel) {
19
- class Tag {
20
- constructor() {
21
- this.label = schema_definition_1.SchemaDefinition.stringColumn();
22
- }
23
- }
24
- TagModel.Tag = Tag;
25
- })(TagModel || (TagModel = {}));
26
- (0, vitest_1.test)('Content API: create & read tag', async () => {
27
- const tester = await (0, tester_1.createTester)((0, schema_definition_1.createSchema)(TagModel));
28
- await tester((0, tester_1.gql) `
29
- mutation {
30
- createTag(data: { label: "graphql" }) {
31
- ok
32
- }
33
- }
34
- `)
35
- .expect(response => {
36
- vitest_1.assert.deepStrictEqual(response.body.data, {
37
- createTag: {
38
- ok: true,
39
- },
40
- });
41
- })
42
- .expect(200);
43
- await tester((0, tester_1.gql) `
44
- query {
45
- listTag(filter: { label: { eq: "graphql" } }) {
46
- label
47
- }
48
- }
49
- `)
50
- .expect(response => {
51
- vitest_1.assert.deepStrictEqual(response.body.data, {
52
- listTag: [
53
- {
54
- label: 'graphql',
55
- },
56
- ],
57
- });
58
- })
59
- .expect(200);
60
- });
61
- (0, vitest_1.test)('Content API: X-Contember-Ref header', async () => {
62
- const tester = await (0, tester_1.createTester)((0, schema_definition_1.createSchema)(TagModel));
63
- await tester((0, tester_1.gql) `
64
- mutation {
65
- createTag(data: { label: "typescript" }) {
66
- ok
67
- }
68
- }
69
- `).expect(200);
70
- const response = await tester((0, tester_1.gql) `
71
- query {
72
- listTag(filter: { label: { eq: "typescript" } }) {
73
- label
74
- }
75
- }
76
- `)
77
- .set('X-Contember-Ref', 'None')
78
- .expect(response => {
79
- vitest_1.assert.deepStrictEqual(response.body.data, {
80
- listTag: [
81
- {
82
- label: 'typescript',
83
- },
84
- ],
85
- });
86
- })
87
- .expect(200);
88
- const eventKey = response.get('X-Contember-Ref');
89
- await tester((0, tester_1.gql) `
90
- query {
91
- listTag {
92
- label
93
- }
94
- }
95
- `)
96
- .set('X-Contember-Ref', eventKey)
97
- .expect(304);
98
- // ignored for mutation
99
- await tester((0, tester_1.gql) `
100
- mutation {
101
- createTag(data: { label: "typescript" }) {
102
- ok
103
- }
104
- }
105
- `)
106
- .set('X-Contember-Ref', eventKey)
107
- .expect(200);
108
- });
109
- (0, vitest_1.test)('Content API: invalid schema error', async () => {
110
- const tester = await (0, tester_1.createTester)((0, schema_definition_1.createSchema)(TagModel));
111
- await tester((0, tester_1.gql) `
112
- mutation {
113
- createFoo(data: { label: "graphql" }) {
114
- ok
115
- }
116
- }
117
- `)
118
- .expect(400)
119
- .expect(response => {
120
- vitest_1.assert.deepStrictEqual(response.body.errors[0].message, 'Cannot query field "createFoo" on type "Mutation". Did you mean "createTag"?');
121
- });
122
- });
123
- (0, vitest_1.test)('Tenant API: sign up, add to a project and check project access', async () => {
124
- const tester = await (0, tester_1.createTester)((0, schema_definition_1.createSchema)(TagModel));
125
- const email = `john+${Date.now()}@doe.com`;
126
- const identityId = await (0, requests_1.signUp)(email);
127
- const authKey = await (0, requests_1.signIn)(email);
128
- await tester((0, tester_1.gql) `
129
- query {
130
- listTag {
131
- id
132
- }
133
- }
134
- `, { authorizationToken: authKey })
135
- .expect(404)
136
- .expect({ errors: [{ message: `Project ${tester.projectSlug} NOT found`, code: 404 }] });
137
- await (0, requests_1.addProjectMember)(identityId, tester.projectSlug);
138
- await tester((0, tester_1.gql) `
139
- query {
140
- listTag {
141
- id
142
- }
143
- }
144
- `, { authorizationToken: authKey })
145
- .expect(response => {
146
- vitest_1.assert.deepStrictEqual(response.body.data, { listTag: [] });
147
- })
148
- .expect(200);
149
- });
150
- (0, vitest_1.test)('Content API: assume membership', async () => {
151
- const tester = await (0, tester_1.createTester)((0, schema_definition_1.createSchema)(TagModel, schema => {
152
- return {
153
- ...schema,
154
- acl: {
155
- roles: {
156
- test: {
157
- entities: {},
158
- variables: {},
159
- content: {
160
- assumeMembership: {
161
- admin: {},
162
- },
163
- },
164
- },
165
- },
166
- },
167
- };
168
- }));
169
- const email = `john+${Date.now()}@doe.com`;
170
- const identityId = await (0, requests_1.signUp)(email);
171
- const authKey = await (0, requests_1.signIn)(email);
172
- await (0, requests_1.addProjectMember)(identityId, tester.projectSlug, 'test');
173
- await tester((0, tester_1.gql) `
174
- query {
175
- listTag {
176
- id
177
- }
178
- }
179
- `, { authorizationToken: authKey })
180
- .expect(400);
181
- await tester((0, tester_1.gql) `
182
- query {
183
- listTag {
184
- id
185
- }
186
- }
187
- `, { authorizationToken: authKey })
188
- .set('X-Contember-assume-membership', JSON.stringify({ memberships: [{ role: 'admin', variables: [] }] }))
189
- .expect({ data: { listTag: [] } })
190
- .expect(200);
191
- });
192
- //# sourceMappingURL=http.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.test.js","sourceRoot":"","sources":["../../../tests/e2e/http.test.ts"],"names":[],"mappings":";;;;;AAAA,0DAAiC;AACjC,mCAAqC;AACrC,oEAAoF;AACpF,qCAAoD;AACpD,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["../../../tests/e2e/requests.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,UAAiB,MAAM,wBAAwB,QAAQ,MAAM,CAoB/E,CAAA;AAGD,eAAO,MAAM,MAAM,UAAiB,MAAM,oCAuBzC,CAAA;AAGD,eAAO,MAAM,gBAAgB,eAAsB,MAAM,eAAe,MAAM,iCAkB7E,CAAA"}
@@ -1,237 +0,0 @@
1
- import supertest from 'supertest'
2
- import { assert, test } from 'vitest'
3
- import { createSchema, SchemaDefinition as def } from '@contember/schema-definition'
4
- import { apiUrl, createTester, gql } from './tester'
5
- import { addProjectMember, signIn, signUp } from './requests'
6
-
7
-
8
- test('show homepage', async () => {
9
- await supertest(apiUrl)
10
- .get('/')
11
- .expect(200)
12
- .expect('App is running')
13
- })
14
-
15
- namespace TagModel {
16
- export class Tag {
17
- label = def.stringColumn()
18
- }
19
- }
20
-
21
- test('Content API: create & read tag', async () => {
22
- const tester = await createTester(createSchema(TagModel))
23
-
24
- await tester(
25
- gql`
26
- mutation {
27
- createTag(data: { label: "graphql" }) {
28
- ok
29
- }
30
- }
31
- `,
32
- )
33
- .expect(response => {
34
- assert.deepStrictEqual(response.body.data, {
35
- createTag: {
36
- ok: true,
37
- },
38
- })
39
- })
40
- .expect(200)
41
-
42
- await tester(
43
- gql`
44
- query {
45
- listTag(filter: { label: { eq: "graphql" } }) {
46
- label
47
- }
48
- }
49
- `,
50
- )
51
- .expect(response => {
52
- assert.deepStrictEqual(response.body.data, {
53
- listTag: [
54
- {
55
- label: 'graphql',
56
- },
57
- ],
58
- })
59
- })
60
- .expect(200)
61
- })
62
-
63
- test('Content API: X-Contember-Ref header', async () => {
64
-
65
- const tester = await createTester(createSchema(TagModel))
66
-
67
- await tester(
68
- gql`
69
- mutation {
70
- createTag(data: { label: "typescript" }) {
71
- ok
72
- }
73
- }
74
- `,
75
- ).expect(200)
76
-
77
- const response = await tester(
78
- gql`
79
- query {
80
- listTag(filter: { label: { eq: "typescript" } }) {
81
- label
82
- }
83
- }
84
- `,
85
- )
86
- .set('X-Contember-Ref', 'None')
87
- .expect(response => {
88
- assert.deepStrictEqual(response.body.data, {
89
- listTag: [
90
- {
91
- label: 'typescript',
92
- },
93
- ],
94
- })
95
- })
96
- .expect(200)
97
- const eventKey = response.get('X-Contember-Ref')
98
- await tester(
99
- gql`
100
- query {
101
- listTag {
102
- label
103
- }
104
- }
105
- `,
106
- )
107
- .set('X-Contember-Ref', eventKey)
108
- .expect(304)
109
-
110
- // ignored for mutation
111
- await tester(
112
- gql`
113
- mutation {
114
- createTag(data: { label: "typescript" }) {
115
- ok
116
- }
117
- }
118
- `,
119
- )
120
- .set('X-Contember-Ref', eventKey)
121
- .expect(200)
122
- })
123
-
124
- test('Content API: invalid schema error', async () => {
125
- const tester = await createTester(createSchema(TagModel))
126
-
127
- await tester(
128
- gql`
129
- mutation {
130
- createFoo(data: { label: "graphql" }) {
131
- ok
132
- }
133
- }
134
- `,
135
- )
136
- .expect(400)
137
- .expect(response => {
138
- assert.deepStrictEqual(
139
- response.body.errors[0].message,
140
- 'Cannot query field "createFoo" on type "Mutation". Did you mean "createTag"?',
141
- )
142
- })
143
- })
144
-
145
- test('Tenant API: sign up, add to a project and check project access', async () => {
146
- const tester = await createTester(createSchema(TagModel))
147
-
148
- const email = `john+${Date.now()}@doe.com`
149
- const identityId = await signUp(email)
150
- const authKey = await signIn(email)
151
-
152
- await tester(
153
- gql`
154
- query {
155
- listTag {
156
- id
157
- }
158
- }
159
- `,
160
- { authorizationToken: authKey },
161
- )
162
- .expect(404)
163
- .expect({ errors: [{ message: `Project ${tester.projectSlug} NOT found`, code: 404 }] })
164
-
165
-
166
- await addProjectMember(identityId, tester.projectSlug)
167
-
168
- await tester(
169
- gql`
170
- query {
171
- listTag {
172
- id
173
- }
174
- }
175
- `,
176
- { authorizationToken: authKey },
177
- )
178
- .expect(response => {
179
- assert.deepStrictEqual(response.body.data, { listTag: [] })
180
- })
181
- .expect(200)
182
- })
183
-
184
-
185
- test('Content API: assume membership', async () => {
186
- const tester = await createTester(createSchema(TagModel, schema => {
187
- return {
188
- ...schema,
189
- acl: {
190
- roles: {
191
- test: {
192
- entities: {},
193
- variables: {},
194
- content: {
195
- assumeMembership: {
196
- admin: {},
197
- },
198
- },
199
- },
200
- },
201
- },
202
- }
203
- }))
204
-
205
- const email = `john+${Date.now()}@doe.com`
206
- const identityId = await signUp(email)
207
- const authKey = await signIn(email)
208
- await addProjectMember(identityId, tester.projectSlug, 'test')
209
-
210
- await tester(
211
- gql`
212
- query {
213
- listTag {
214
- id
215
- }
216
- }
217
- `,
218
- { authorizationToken: authKey },
219
- )
220
- .expect(400)
221
-
222
-
223
-
224
- await tester(
225
- gql`
226
- query {
227
- listTag {
228
- id
229
- }
230
- }
231
- `,
232
- { authorizationToken: authKey },
233
- )
234
- .set('X-Contember-assume-membership', JSON.stringify({ memberships: [{ role: 'admin', variables: [] }] }))
235
- .expect({ data: { listTag: [] } })
236
- .expect(200)
237
- })