@contember/engine-server 1.4.0-rc.8 → 2.0.0-alpha.8

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 (110) hide show
  1. package/dist/development/src/cluster.cjs +87 -0
  2. package/dist/development/src/cluster.cjs.map +1 -0
  3. package/dist/development/src/cluster.js +87 -0
  4. package/dist/development/src/cluster.js.map +1 -0
  5. package/dist/development/src/loadPlugins.cjs +9 -0
  6. package/dist/development/src/loadPlugins.cjs.map +1 -0
  7. package/dist/development/src/loadPlugins.js +10 -0
  8. package/dist/development/src/loadPlugins.js.map +1 -0
  9. package/dist/development/src/utils.cjs +7 -0
  10. package/dist/development/src/utils.cjs.map +1 -0
  11. package/dist/development/src/utils.js +7 -0
  12. package/dist/development/src/utils.js.map +1 -0
  13. package/dist/development/start.cjs +152 -0
  14. package/dist/development/start.cjs.map +1 -0
  15. package/dist/development/start.js +134 -0
  16. package/dist/development/start.js.map +1 -0
  17. package/dist/production/src/cluster.cjs +87 -0
  18. package/dist/production/src/cluster.cjs.map +1 -0
  19. package/dist/production/src/cluster.js +87 -0
  20. package/dist/production/src/cluster.js.map +1 -0
  21. package/dist/production/src/loadPlugins.cjs +9 -0
  22. package/dist/production/src/loadPlugins.cjs.map +1 -0
  23. package/dist/production/src/loadPlugins.js +10 -0
  24. package/dist/production/src/loadPlugins.js.map +1 -0
  25. package/dist/production/src/utils.cjs +7 -0
  26. package/dist/production/src/utils.cjs.map +1 -0
  27. package/dist/production/src/utils.js +7 -0
  28. package/dist/production/src/utils.js.map +1 -0
  29. package/dist/production/start.cjs +152 -0
  30. package/dist/production/start.cjs.map +1 -0
  31. package/dist/production/start.js +134 -0
  32. package/dist/production/start.js.map +1 -0
  33. package/dist/types/cluster.d.ts +16 -0
  34. package/dist/types/cluster.d.ts.map +1 -0
  35. package/dist/{src → types}/loadPlugins.d.ts.map +1 -1
  36. package/dist/types/tsconfig.tsbuildinfo +1 -0
  37. package/dist/types/utils.d.ts +2 -0
  38. package/dist/types/utils.d.ts.map +1 -0
  39. package/esbuild.cjs +42 -0
  40. package/package.json +28 -14
  41. package/src/cluster.ts +95 -0
  42. package/src/loadPlugins.ts +2 -1
  43. package/src/start.ts +128 -17
  44. package/src/tsconfig.json +2 -1
  45. package/src/utils.ts +4 -0
  46. package/tsconfig.json +0 -1
  47. package/types/prom-client/index.d.ts +17 -0
  48. package/dist/src/loadPlugins.js +0 -12
  49. package/dist/src/loadPlugins.js.map +0 -1
  50. package/dist/src/start.js +0 -47
  51. package/dist/src/start.js.map +0 -1
  52. package/dist/src/tsconfig.tsbuildinfo +0 -1
  53. package/dist/tests/e2e/acl-condition-variable.test.d.ts +0 -2
  54. package/dist/tests/e2e/acl-condition-variable.test.d.ts.map +0 -1
  55. package/dist/tests/e2e/acl-condition-variable.test.js +0 -77
  56. package/dist/tests/e2e/acl-condition-variable.test.js.map +0 -1
  57. package/dist/tests/e2e/assume-identity.test.d.ts +0 -2
  58. package/dist/tests/e2e/assume-identity.test.d.ts.map +0 -1
  59. package/dist/tests/e2e/assume-identity.test.js +0 -109
  60. package/dist/tests/e2e/assume-identity.test.js.map +0 -1
  61. package/dist/tests/e2e/assume-membership.test.d.ts +0 -2
  62. package/dist/tests/e2e/assume-membership.test.d.ts.map +0 -1
  63. package/dist/tests/e2e/assume-membership.test.js +0 -58
  64. package/dist/tests/e2e/assume-membership.test.js.map +0 -1
  65. package/dist/tests/e2e/content-api-basic.test.d.ts +0 -2
  66. package/dist/tests/e2e/content-api-basic.test.d.ts.map +0 -1
  67. package/dist/tests/e2e/content-api-basic.test.js +0 -50
  68. package/dist/tests/e2e/content-api-basic.test.js.map +0 -1
  69. package/dist/tests/e2e/content-invalid-schema.test.d.ts +0 -2
  70. package/dist/tests/e2e/content-invalid-schema.test.d.ts.map +0 -1
  71. package/dist/tests/e2e/content-invalid-schema.test.js +0 -29
  72. package/dist/tests/e2e/content-invalid-schema.test.js.map +0 -1
  73. package/dist/tests/e2e/homepage.test.d.ts +0 -2
  74. package/dist/tests/e2e/homepage.test.d.ts.map +0 -1
  75. package/dist/tests/e2e/homepage.test.js +0 -15
  76. package/dist/tests/e2e/homepage.test.js.map +0 -1
  77. package/dist/tests/e2e/tenant-member-access.test.d.ts +0 -2
  78. package/dist/tests/e2e/tenant-member-access.test.d.ts.map +0 -1
  79. package/dist/tests/e2e/tenant-member-access.test.js +0 -43
  80. package/dist/tests/e2e/tenant-member-access.test.js.map +0 -1
  81. package/dist/tests/e2e/x-contember-ref.test.d.ts +0 -2
  82. package/dist/tests/e2e/x-contember-ref.test.d.ts.map +0 -1
  83. package/dist/tests/e2e/x-contember-ref.test.js +0 -63
  84. package/dist/tests/e2e/x-contember-ref.test.js.map +0 -1
  85. package/dist/tests/src/requests.d.ts +0 -5
  86. package/dist/tests/src/requests.d.ts.map +0 -1
  87. package/dist/tests/src/requests.js +0 -68
  88. package/dist/tests/src/requests.js.map +0 -1
  89. package/dist/tests/src/tester.d.ts +0 -19
  90. package/dist/tests/src/tester.d.ts.map +0 -1
  91. package/dist/tests/src/tester.js +0 -99
  92. package/dist/tests/src/tester.js.map +0 -1
  93. package/dist/tests/tsconfig.tsbuildinfo +0 -1
  94. package/esbuild.js +0 -7
  95. package/tests/e2e/acl-condition-variable.test.ts +0 -74
  96. package/tests/e2e/assume-identity.test.ts +0 -126
  97. package/tests/e2e/assume-membership.test.ts +0 -64
  98. package/tests/e2e/content-api-basic.test.ts +0 -51
  99. package/tests/e2e/content-invalid-schema.test.ts +0 -31
  100. package/tests/e2e/homepage.test.ts +0 -10
  101. package/tests/e2e/tenant-member-access.test.ts +0 -51
  102. package/tests/e2e/x-contember-ref.test.ts +0 -71
  103. package/tests/src/requests.ts +0 -81
  104. package/tests/src/tester.ts +0 -118
  105. package/tests/start-server.sh +0 -16
  106. package/tests/tsconfig.json +0 -11
  107. package/vite.config.js +0 -3
  108. /package/dist/{src → types}/loadPlugins.d.ts +0 -0
  109. /package/dist/{src → types}/start.d.ts +0 -0
  110. /package/dist/{src → types}/start.d.ts.map +0 -0
@@ -1,64 +0,0 @@
1
- import { test } from 'vitest'
2
- import { createTester, gql } from '../src/tester'
3
- import { addProjectMember, signIn, signUp } from '../src/requests'
4
- import { createSchema, SchemaDefinition as def } from '@contember/schema-definition'
5
-
6
- namespace TagModel {
7
- export class Tag {
8
- label = def.stringColumn()
9
- }
10
- }
11
-
12
-
13
- test('Content API: assume membership', async () => {
14
- const tester = await createTester(createSchema(TagModel, schema => {
15
- return {
16
- ...schema,
17
- acl: {
18
- roles: {
19
- test: {
20
- entities: {},
21
- variables: {},
22
- content: {
23
- assumeMembership: {
24
- admin: {},
25
- },
26
- },
27
- },
28
- },
29
- },
30
- }
31
- }))
32
-
33
- const email = `john+${Date.now()}@doe.com`
34
- const identityId = await signUp(email)
35
- const authKey = await signIn(email)
36
- await addProjectMember(identityId, tester.projectSlug, { role: 'test', variables: [] })
37
-
38
- await tester(
39
- gql`
40
- query {
41
- listTag {
42
- id
43
- }
44
- }
45
- `,
46
- { authorizationToken: authKey },
47
- )
48
- .expect(400)
49
-
50
-
51
- await tester(
52
- gql`
53
- query {
54
- listTag {
55
- id
56
- }
57
- }
58
- `,
59
- { authorizationToken: authKey },
60
- )
61
- .set('X-Contember-assume-membership', JSON.stringify({ memberships: [{ role: 'admin', variables: [] }] }))
62
- .expect({ data: { listTag: [] } })
63
- .expect(200)
64
- })
@@ -1,51 +0,0 @@
1
- import { assert, test } from 'vitest'
2
- import { createTester, gql } from '../src/tester'
3
- import { createSchema, SchemaDefinition as def } from '@contember/schema-definition'
4
-
5
- namespace TagModel {
6
- export class Tag {
7
- label = def.stringColumn()
8
- }
9
- }
10
-
11
- test('Content API: create & read tag', async () => {
12
- const tester = await createTester(createSchema(TagModel))
13
-
14
- await tester(
15
- gql`
16
- mutation {
17
- createTag(data: { label: "graphql" }) {
18
- ok
19
- }
20
- }
21
- `,
22
- )
23
- .expect(response => {
24
- assert.deepStrictEqual(response.body.data, {
25
- createTag: {
26
- ok: true,
27
- },
28
- })
29
- })
30
- .expect(200)
31
-
32
- await tester(
33
- gql`
34
- query {
35
- listTag(filter: { label: { eq: "graphql" } }) {
36
- label
37
- }
38
- }
39
- `,
40
- )
41
- .expect(response => {
42
- assert.deepStrictEqual(response.body.data, {
43
- listTag: [
44
- {
45
- label: 'graphql',
46
- },
47
- ],
48
- })
49
- })
50
- .expect(200)
51
- })
@@ -1,31 +0,0 @@
1
- import { assert, test } from 'vitest'
2
- import { createSchema, SchemaDefinition as def } from '@contember/schema-definition'
3
- import { createTester, gql } from '../src/tester'
4
-
5
-
6
- namespace TagModel {
7
- export class Tag {
8
- label = def.stringColumn()
9
- }
10
- }
11
-
12
- test('Content API: invalid schema error', async () => {
13
- const tester = await createTester(createSchema(TagModel))
14
-
15
- await tester(
16
- gql`
17
- mutation {
18
- createFoo(data: { label: "graphql" }) {
19
- ok
20
- }
21
- }
22
- `,
23
- )
24
- .expect(400)
25
- .expect(response => {
26
- assert.deepStrictEqual(
27
- response.body.errors[0].message,
28
- 'Cannot query field "createFoo" on type "Mutation". Did you mean "createTag"?',
29
- )
30
- })
31
- })
@@ -1,10 +0,0 @@
1
- import { test } from 'vitest'
2
- import supertest from 'supertest'
3
- import { apiUrl } from '../src/tester'
4
-
5
- test('show homepage', async () => {
6
- await supertest(apiUrl)
7
- .get('/')
8
- .expect(200)
9
- .expect('App is running')
10
- })
@@ -1,51 +0,0 @@
1
- import { assert, test } from 'vitest'
2
- import { createSchema, SchemaDefinition as def } from '@contember/schema-definition'
3
- import { createTester, gql } from '../src/tester'
4
- import { addProjectMember, signIn, signUp } from '../src/requests'
5
-
6
-
7
- namespace TagModel {
8
- export class Tag {
9
- label = def.stringColumn()
10
- }
11
- }
12
-
13
-
14
- test('Tenant API: sign up, add to a project and check project access', async () => {
15
- const tester = await createTester(createSchema(TagModel))
16
-
17
- const email = `john+${Date.now()}@doe.com`
18
- const identityId = await signUp(email)
19
- const authKey = await signIn(email)
20
-
21
- await tester(
22
- gql`
23
- query {
24
- listTag {
25
- id
26
- }
27
- }
28
- `,
29
- { authorizationToken: authKey },
30
- )
31
- .expect(404)
32
- .expect({ errors: [{ message: `Project ${tester.projectSlug} NOT found`, code: 404 }] })
33
-
34
-
35
- await addProjectMember(identityId, tester.projectSlug)
36
-
37
- await tester(
38
- gql`
39
- query {
40
- listTag {
41
- id
42
- }
43
- }
44
- `,
45
- { authorizationToken: authKey },
46
- )
47
- .expect(response => {
48
- assert.deepStrictEqual(response.body.data, { listTag: [] })
49
- })
50
- .expect(200)
51
- })
@@ -1,71 +0,0 @@
1
- import { assert, test } from 'vitest'
2
- import { createTester, gql } from '../src/tester'
3
- import { createSchema, SchemaDefinition as def } from '@contember/schema-definition'
4
-
5
- namespace TagModel {
6
- export class Tag {
7
- label = def.stringColumn()
8
- }
9
- }
10
-
11
-
12
- test('Content API: X-Contember-Ref header', async () => {
13
-
14
- const tester = await createTester(createSchema(TagModel))
15
-
16
- await tester(
17
- gql`
18
- mutation {
19
- createTag(data: { label: "typescript" }) {
20
- ok
21
- }
22
- }
23
- `,
24
- ).expect(200)
25
-
26
- const response = await tester(
27
- gql`
28
- query {
29
- listTag(filter: { label: { eq: "typescript" } }) {
30
- label
31
- }
32
- }
33
- `,
34
- )
35
- .set('X-Contember-Ref', 'None')
36
- .expect(response => {
37
- assert.deepStrictEqual(response.body.data, {
38
- listTag: [
39
- {
40
- label: 'typescript',
41
- },
42
- ],
43
- })
44
- })
45
- .expect(200)
46
- const eventKey = response.get('X-Contember-Ref')
47
- await tester(
48
- gql`
49
- query {
50
- listTag {
51
- label
52
- }
53
- }
54
- `,
55
- )
56
- .set('X-Contember-Ref', eventKey)
57
- .expect(304)
58
-
59
- // ignored for mutation
60
- await tester(
61
- gql`
62
- mutation {
63
- createTag(data: { label: "typescript" }) {
64
- ok
65
- }
66
- }
67
- `,
68
- )
69
- .set('X-Contember-Ref', eventKey)
70
- .expect(200)
71
- })
@@ -1,81 +0,0 @@
1
- import { executeGraphql, gql, loginToken } from './tester'
2
- import { assert } from 'vitest'
3
- import { Acl } from '@contember/schema'
4
-
5
- export const signIn = async (email: string, password = '123456'): Promise<string> => {
6
- const response = await executeGraphql(
7
- '/tenant',
8
- gql`
9
- mutation ($email: String!, $password: String!) {
10
- signIn(email: $email, password: $password) {
11
- ok
12
- result {
13
- token
14
- }
15
- }
16
- }
17
- `,
18
- {
19
- variables: { email, password },
20
- authorizationToken: loginToken,
21
- },
22
- ).expect(200)
23
-
24
- return response.body.data.signIn.result.token
25
- }
26
-
27
-
28
- export const signUp = async (email: string, password = '123456') => {
29
- const signUpResponse = await executeGraphql(
30
- '/tenant',
31
- gql`
32
- mutation($email: String!, $password: String!) {
33
- signUp(email: $email, password: $password) {
34
- ok
35
- result {
36
- person {
37
- identity {
38
- id
39
- }
40
- }
41
- }
42
- }
43
- }
44
- `,
45
- {
46
- variables: { email, password },
47
- },
48
- ).expect(200)
49
-
50
- return signUpResponse.body.data.signUp.result.person.identity.id
51
- }
52
-
53
-
54
- export const addProjectMember = async (identityId: string, projectSlug: string, membership: Acl.Membership = { role: 'admin', variables: [] }) => {
55
- await executeGraphql(
56
- '/tenant',
57
- gql`
58
- mutation ($identity: String!, $projectSlug: String!, $membership: MembershipInput!) {
59
- addProjectMember(identityId: $identity, projectSlug: $projectSlug, memberships: [$membership]) {
60
- ok
61
- error {
62
- code
63
- developerMessage
64
- membershipValidation {
65
- code
66
- role
67
- variable
68
- }
69
- }
70
- }
71
- }
72
- `,
73
- {
74
- variables: { identity: identityId, projectSlug, membership },
75
- },
76
- )
77
- .expect(200)
78
- .expect(response => {
79
- assert.deepStrictEqual(response.body.data, { addProjectMember: { ok: true, error: null } })
80
- })
81
- }
@@ -1,118 +0,0 @@
1
- import nodeAssert from 'node:assert'
2
- import supertest from 'supertest'
3
- import { Schema } from '@contember/schema'
4
- import {
5
- Migration,
6
- MigrationVersionHelper,
7
- ModificationHandlerFactory,
8
- SchemaDiffer,
9
- SchemaMigrator, VERSION_LATEST,
10
- } from '@contember/schema-migrations'
11
- import { emptySchema } from '@contember/schema-utils'
12
- import { assert } from 'vitest'
13
-
14
-
15
- export const rootToken = String(process.env.CONTEMBER_ROOT_TOKEN)
16
- export const loginToken = String(process.env.CONTEMBER_LOGIN_TOKEN)
17
- export const apiUrl = String(process.env.CONTEMBER_API_URL)
18
-
19
- // Used to allow prettier formatting of GraphQL queries
20
- export const gql = (strings: TemplateStringsArray) => {
21
- nodeAssert.strictEqual(strings.length, 1)
22
- return strings[0]
23
- }
24
-
25
-
26
- export const executeGraphql = (
27
- path: string,
28
- query: string,
29
- options: { authorizationToken?: string; variables?: Record<string, any> },
30
- ) => {
31
- return supertest(apiUrl)
32
- .post(path)
33
- .set('Authorization', 'Bearer ' + (options.authorizationToken || rootToken))
34
- .send({
35
- query,
36
- variables: options.variables || {},
37
- })
38
- }
39
-
40
-
41
- const createMigrations = (schema: Schema) => {
42
- const modificationHandlerFactory = new ModificationHandlerFactory(ModificationHandlerFactory.defaultFactoryMap)
43
- const differ = new SchemaDiffer(new SchemaMigrator(modificationHandlerFactory))
44
- return differ.diffSchemas(emptySchema, schema)
45
- }
46
-
47
- const createProject = async (slug: string) => {
48
- await executeGraphql(
49
- '/tenant',
50
- gql`
51
- mutation($projectSlug: String!, $config: Json!) {
52
- createProject(projectSlug: $projectSlug, config: $config) {
53
- ok
54
- error { code }
55
- }
56
- }
57
- `,
58
- {
59
- variables: {
60
- projectSlug: slug,
61
- config: {},
62
- },
63
- })
64
- .expect(response => {
65
- assert.isOk(response.body)
66
- assert.isOk(response.body.data)
67
- assert.isOk(response.body.data.createProject)
68
- assert.isOk(response.body.data.createProject.ok)
69
- })
70
- .expect(200)
71
- }
72
-
73
- const executeMigrations = async (projectSlug: string, modifications: Migration.Modification[]) => {
74
- const [version, fullName] = MigrationVersionHelper.createVersion('test')
75
- await executeGraphql(
76
- '/system/' + projectSlug,
77
- gql`
78
- mutation($migrations: [Migration!]!) {
79
- migrate(migrations: $migrations) {
80
- ok
81
- error { code }
82
- }
83
- }
84
- `,
85
- {
86
- variables: {
87
- migrations: [{
88
- formatVersion: VERSION_LATEST,
89
- modifications,
90
- version,
91
- name: fullName,
92
- }],
93
- },
94
- })
95
- .expect(response => {
96
- assert.deepStrictEqual(response.body.data, {
97
- migrate: {
98
- error: null,
99
- ok: true,
100
- },
101
- })
102
- })
103
- }
104
-
105
- export const createTester = async (schema: Schema) => {
106
- const projectSlug = 'test_' + Date.now()
107
- await createProject(projectSlug)
108
- const migrations = createMigrations(schema)
109
- await executeMigrations(projectSlug, migrations)
110
-
111
- const queryCb = (
112
- query: string,
113
- options: { path?: string; authorizationToken?: string; variables?: Record<string, any> } = {}) => {
114
- return executeGraphql(options.path ?? '/content/' + projectSlug + '/live', query, options)
115
- }
116
- queryCb.projectSlug = projectSlug
117
- return queryCb
118
- }
@@ -1,16 +0,0 @@
1
- #!/bin/bash
2
-
3
- node ./packages/engine-server/dist/src/start.js &
4
-
5
- max_retry=20
6
- counter=0
7
- until curl --silent --fail localhost:${CONTEMBER_PORT:-4000}/;
8
- do
9
- sleep 1
10
- [[ counter -eq $max_retry ]] && echo "Failed!" && exit 1
11
- echo "Trying again. Try #$counter"
12
- ((counter++))
13
- done
14
-
15
- echo "Ok!"
16
- exit 0
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../tsconfig.settings.json",
3
- "compilerOptions": {
4
- "outDir": "../dist/tests",
5
- "esModuleInterop": true
6
- },
7
- "references": [
8
- { "path": "../src" },
9
- { "path": "../../engine-api-tester/src" }
10
- ]
11
- }
package/vite.config.js DELETED
@@ -1,3 +0,0 @@
1
- import { createViteConfig } from '../../scripts/vite/createViteConfig'
2
-
3
- export default createViteConfig()
File without changes
File without changes
File without changes