@appsemble/cli 0.30.14-test.6 → 0.32.1-test.14

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 (72) hide show
  1. package/README.md +3 -3
  2. package/commands/app/create.js +9 -4
  3. package/commands/app/delete.js +1 -1
  4. package/commands/app/export.js +1 -1
  5. package/commands/app/patch.d.ts +2 -0
  6. package/commands/app/patch.js +8 -0
  7. package/commands/app/update.js +1 -1
  8. package/commands/asset/publish.js +1 -1
  9. package/commands/cleanupSoftDeletedRecords.d.ts +6 -0
  10. package/commands/cleanupSoftDeletedRecords.js +40 -0
  11. package/commands/config/get.js +6 -2
  12. package/commands/config/set.js +6 -1
  13. package/commands/migrate.js +19 -0
  14. package/commands/serve.js +5 -1
  15. package/commands/start.js +19 -0
  16. package/commands/synchronizeTrainings.d.ts +6 -0
  17. package/commands/synchronizeTrainings.js +40 -0
  18. package/index.js +5 -0
  19. package/lib/app.d.ts +8 -0
  20. package/lib/app.js +59 -17
  21. package/lib/asset.d.ts +1 -1
  22. package/lib/authentication.js +4 -4
  23. package/lib/block.js +15 -6
  24. package/lib/coercers.js +1 -0
  25. package/lib/config.js +26 -18
  26. package/lib/createServers.js +3 -1
  27. package/lib/group.d.ts +1 -1
  28. package/lib/group.js +7 -6
  29. package/lib/output.js +3 -1
  30. package/lib/processCss.js +1 -1
  31. package/lib/project.js +3 -2
  32. package/lib/serverImport.d.ts +1 -1
  33. package/lib/serverImport.js +1 -1
  34. package/package.json +19 -16
  35. package/server/db/methods.js +3 -0
  36. package/server/options/createAppAsset.d.ts +1 -1
  37. package/server/options/createAppAsset.js +5 -6
  38. package/server/options/createAppResourcesWithAssets.js +4 -6
  39. package/server/options/createSettings.js +1 -1
  40. package/server/options/createTheme.js +2 -0
  41. package/server/options/getAppAsset.js +5 -10
  42. package/server/options/getAppAssets.js +5 -9
  43. package/server/options/getAppScreenshots.js +3 -3
  44. package/server/options/getBlockAsset.js +3 -0
  45. package/server/options/getTheme.js +1 -0
  46. package/server/options/options.js +2 -0
  47. package/templates/apps/empty/app-definition.yaml +2 -2
  48. package/templates/blocks/mini-jsx/package.json +4 -1
  49. package/templates/blocks/mini-jsx/src/index.tsx +1 -1
  50. package/templates/blocks/preact/package.json +5 -2
  51. package/templates/blocks/vanilla/package.json +4 -1
  52. package/vitest.setup.js +11 -2
  53. package/lib/app.test.d.ts +0 -1
  54. package/lib/app.test.js +0 -2212
  55. package/lib/asset.test.d.ts +0 -1
  56. package/lib/asset.test.js +0 -105
  57. package/lib/block.test.d.ts +0 -1
  58. package/lib/block.test.js +0 -235
  59. package/lib/coercers.test.d.ts +0 -1
  60. package/lib/coercers.test.js +0 -27
  61. package/lib/config.test.d.ts +0 -1
  62. package/lib/config.test.js +0 -239
  63. package/lib/group.test.d.ts +0 -1
  64. package/lib/group.test.js +0 -616
  65. package/lib/organization.test.d.ts +0 -1
  66. package/lib/organization.test.js +0 -222
  67. package/lib/resource.test.d.ts +0 -1
  68. package/lib/resource.test.js +0 -393
  69. package/server/db/methods.test.d.ts +0 -1
  70. package/server/db/methods.test.js +0 -366
  71. package/server/options/parseQuery.test.d.ts +0 -1
  72. package/server/options/parseQuery.test.js +0 -46
@@ -1,222 +0,0 @@
1
- import { createFixtureStream, readFixture } from '@appsemble/node-utils';
2
- import { createServer, createTestUser, models, setArgv } from '@appsemble/server';
3
- import { PredefinedOrganizationRole } from '@appsemble/types';
4
- import { setTestApp } from 'axios-test-instance';
5
- import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
6
- import { initAxios } from './initAxios.js';
7
- import { createOrganization, updateOrganization, upsertOrganization } from './organization.js';
8
- import { authorizeCLI } from './testUtils.js';
9
- const argv = { host: 'http://localhost', secret: 'test', aesSecret: 'testSecret' };
10
- let user;
11
- let testApp;
12
- const { Organization, OrganizationMember } = models;
13
- describe('organization', () => {
14
- beforeAll(() => {
15
- vi.useFakeTimers();
16
- setArgv(argv);
17
- });
18
- beforeEach(async () => {
19
- vi.clearAllTimers();
20
- vi.setSystemTime(0);
21
- const server = await createServer();
22
- testApp = await setTestApp(server);
23
- initAxios({ remote: testApp.defaults.baseURL });
24
- user = await createTestUser();
25
- });
26
- afterAll(() => {
27
- vi.useRealTimers();
28
- });
29
- describe('createOrganization', () => {
30
- it('should create a new organization', async () => {
31
- await authorizeCLI('organizations:write', testApp);
32
- await createOrganization({
33
- description: 'test description',
34
- id: 'test',
35
- name: 'Test',
36
- email: 'test@example.com',
37
- icon: createFixtureStream('apps/tux.png'),
38
- website: 'https://example.com',
39
- });
40
- const organization = await Organization.findOne();
41
- expect(organization).toMatchObject({
42
- description: 'test description',
43
- email: 'test@example.com',
44
- icon: await readFixture('apps/tux.png'),
45
- id: 'test',
46
- name: 'Test',
47
- website: 'https://example.com',
48
- });
49
- });
50
- it('should not create a new organization with duplicate id', async () => {
51
- const organization = await Organization.create({
52
- id: 'test',
53
- name: 'Test',
54
- });
55
- vi.useRealTimers();
56
- await authorizeCLI('organizations:write', testApp);
57
- await expect(() => createOrganization({
58
- description: 'test description',
59
- id: organization.id,
60
- name: 'Test',
61
- email: 'test@example.com',
62
- icon: null,
63
- website: 'https://example.com',
64
- })).rejects.toThrow('Request failed with status code 409');
65
- vi.useFakeTimers();
66
- });
67
- });
68
- describe('updateOrganization', () => {
69
- it('should update an existing organization', async () => {
70
- const organization = await Organization.create({
71
- id: 'test',
72
- name: 'Test',
73
- });
74
- await OrganizationMember.create({
75
- OrganizationId: organization.id,
76
- UserId: user.id,
77
- role: PredefinedOrganizationRole.Owner,
78
- });
79
- await authorizeCLI('organizations:write', testApp);
80
- await updateOrganization({
81
- id: organization.id,
82
- name: 'Test changed',
83
- description: 'Description Changed',
84
- email: 'test@example.com',
85
- website: null,
86
- icon: createFixtureStream('apps/tux.png'),
87
- });
88
- await organization.reload();
89
- expect(organization.dataValues).toMatchInlineSnapshot({
90
- icon: expect.any(Buffer),
91
- }, `
92
- {
93
- "created": 1970-01-01T00:00:00.000Z,
94
- "deleted": null,
95
- "description": "Description Changed",
96
- "email": "test@example.com",
97
- "icon": Any<Buffer>,
98
- "id": "test",
99
- "name": "Test changed",
100
- "updated": 1970-01-01T00:00:00.000Z,
101
- "website": null,
102
- }
103
- `);
104
- });
105
- it('should throw if the organization does not exist', async () => {
106
- const organization = await Organization.create({
107
- id: 'test',
108
- name: 'Test',
109
- });
110
- await OrganizationMember.create({
111
- OrganizationId: organization.id,
112
- UserId: user.id,
113
- role: PredefinedOrganizationRole.Owner,
114
- });
115
- await organization.destroy();
116
- await authorizeCLI('organizations:write', testApp);
117
- await expect(() => updateOrganization({
118
- id: organization.id,
119
- name: 'Test changed',
120
- description: null,
121
- email: 'test@example.com',
122
- website: null,
123
- icon: null,
124
- })).rejects.toThrow('Request failed with status code 404');
125
- });
126
- it('should throw if the user is not authorized', async () => {
127
- const organization = await Organization.create({
128
- id: 'test',
129
- name: 'Test',
130
- });
131
- await OrganizationMember.create({
132
- OrganizationId: organization.id,
133
- UserId: user.id,
134
- role: PredefinedOrganizationRole.Owner,
135
- });
136
- await expect(() => updateOrganization({
137
- id: organization.id,
138
- name: 'Test changed',
139
- description: null,
140
- email: 'test@example.com',
141
- website: null,
142
- icon: null,
143
- })).rejects.toThrow('Request failed with status code 401');
144
- });
145
- });
146
- describe('upsertOrganization', () => {
147
- it('should create a new organization if doesn’t exist already', async () => {
148
- await authorizeCLI('organizations:write', testApp);
149
- await upsertOrganization({
150
- description: 'test description',
151
- id: 'test',
152
- name: 'Test',
153
- email: 'test@example.com',
154
- icon: null,
155
- website: 'https://example.com',
156
- });
157
- const organization = await Organization.findOne();
158
- expect(organization).toMatchObject({
159
- id: 'test',
160
- description: 'test description',
161
- name: 'Test',
162
- email: 'test@example.com',
163
- icon: null,
164
- website: 'https://example.com',
165
- });
166
- });
167
- it('should update an existing organization', async () => {
168
- const organization = await Organization.create({
169
- id: 'test',
170
- name: 'Test',
171
- });
172
- await OrganizationMember.create({
173
- OrganizationId: organization.id,
174
- UserId: user.id,
175
- role: PredefinedOrganizationRole.Owner,
176
- });
177
- await authorizeCLI('organizations:write', testApp);
178
- await upsertOrganization({
179
- id: organization.id,
180
- name: 'Test changed',
181
- description: null,
182
- email: 'test@example.com',
183
- website: null,
184
- icon: null,
185
- });
186
- expect(organization).toMatchObject({
187
- id: 'test',
188
- name: 'Test',
189
- });
190
- await organization.reload();
191
- expect(organization).toMatchObject({
192
- id: organization.id,
193
- name: 'Test changed',
194
- description: null,
195
- email: 'test@example.com',
196
- website: null,
197
- icon: null,
198
- });
199
- });
200
- it('should throw if there is an error', async () => {
201
- const organization = await Organization.create({
202
- id: 'test',
203
- name: 'Test',
204
- });
205
- await authorizeCLI('organizations:write', testApp);
206
- // Fails because the organization member does not exist.
207
- await expect(() => upsertOrganization({
208
- id: organization.id,
209
- name: 'Test changed',
210
- description: null,
211
- email: 'test@example.com',
212
- website: 'https://www.example.com',
213
- icon: null,
214
- })).rejects.toThrow('Request failed with status code 403');
215
- expect(organization).toMatchObject({
216
- id: 'test',
217
- name: 'Test',
218
- });
219
- });
220
- });
221
- });
222
- //# sourceMappingURL=organization.test.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,393 +0,0 @@
1
- import { resolveFixture } from '@appsemble/node-utils';
2
- import { createServer, createTestUser, models, setArgv } from '@appsemble/server';
3
- import { PredefinedOrganizationRole } from '@appsemble/types';
4
- import { setTestApp } from 'axios-test-instance';
5
- import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
6
- import { initAxios } from './initAxios.js';
7
- import { publishResource, updateResource } from './resource.js';
8
- import { authorizeCLI } from './testUtils.js';
9
- const { App, Organization, OrganizationMember, Resource } = models;
10
- const argv = { host: 'http://localhost', secret: 'test', aesSecret: 'testSecret' };
11
- let user;
12
- let organization;
13
- let testApp;
14
- describe('resource', () => {
15
- beforeAll(() => {
16
- vi.useFakeTimers();
17
- setArgv(argv);
18
- });
19
- beforeEach(async () => {
20
- vi.clearAllTimers();
21
- vi.setSystemTime(0);
22
- const server = await createServer();
23
- testApp = await setTestApp(server);
24
- initAxios({ remote: testApp.defaults.baseURL });
25
- user = await createTestUser();
26
- organization = await Organization.create({
27
- id: 'testorganization',
28
- name: 'Test Organization',
29
- });
30
- await OrganizationMember.create({
31
- OrganizationId: organization.id,
32
- UserId: user.id,
33
- role: PredefinedOrganizationRole.Owner,
34
- });
35
- await Organization.create({ id: 'appsemble', name: 'Appsemble' });
36
- });
37
- afterAll(() => {
38
- vi.useRealTimers();
39
- });
40
- describe('publishResource', () => {
41
- it('should publish resources from a file', async () => {
42
- const resourceDefinition = {
43
- roles: ['$public'],
44
- schema: {
45
- type: 'object',
46
- additionalProperties: false,
47
- required: ['name'],
48
- properties: {
49
- name: {
50
- type: 'string',
51
- },
52
- email: {
53
- type: 'string',
54
- format: 'email',
55
- },
56
- },
57
- },
58
- };
59
- const app = await App.create({
60
- path: 'test-app',
61
- definition: {
62
- resources: { test: resourceDefinition },
63
- name: 'Test App',
64
- defaultPage: 'Test Page',
65
- },
66
- vapidPublicKey: 'a',
67
- vapidPrivateKey: 'b',
68
- visibility: 'public',
69
- OrganizationId: organization.id,
70
- });
71
- await authorizeCLI('resources:write', testApp);
72
- await publishResource({
73
- appId: app.id,
74
- definition: resourceDefinition,
75
- path: resolveFixture('resources/test.json'),
76
- remote: testApp.defaults.baseURL,
77
- type: 'test',
78
- seed: false,
79
- });
80
- const resources = await Resource.findAll({
81
- where: { AppId: app.id },
82
- });
83
- expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
84
- [
85
- {
86
- "$created": "1970-01-01T00:00:00.000Z",
87
- "$updated": "1970-01-01T00:00:00.000Z",
88
- "email": "test@example.com",
89
- "id": 1,
90
- "name": "John Doe",
91
- },
92
- {
93
- "$created": "1970-01-01T00:00:00.000Z",
94
- "$updated": "1970-01-01T00:00:00.000Z",
95
- "email": "test2@example.com",
96
- "id": 2,
97
- "name": "Jane Doe",
98
- },
99
- {
100
- "$created": "1970-01-01T00:00:00.000Z",
101
- "$updated": "1970-01-01T00:00:00.000Z",
102
- "id": 3,
103
- "name": "test name",
104
- },
105
- ]
106
- `);
107
- });
108
- });
109
- it('should throw if there is an error', async () => {
110
- const resourceDefinition = {
111
- roles: ['$public'],
112
- schema: {
113
- type: 'object',
114
- additionalProperties: false,
115
- required: ['name'],
116
- properties: {
117
- name: {
118
- type: 'string',
119
- },
120
- email: {
121
- type: 'string',
122
- format: 'email',
123
- },
124
- },
125
- },
126
- };
127
- const app = await App.create({
128
- path: 'test-app',
129
- definition: {
130
- resources: { test: resourceDefinition },
131
- name: 'Test App',
132
- defaultPage: 'Test Page',
133
- },
134
- vapidPublicKey: 'a',
135
- vapidPrivateKey: 'b',
136
- visibility: 'public',
137
- OrganizationId: organization.id,
138
- });
139
- await authorizeCLI('resources:write', testApp);
140
- await app.destroy();
141
- await expect(() => publishResource({
142
- appId: app.id,
143
- definition: resourceDefinition,
144
- path: resolveFixture('resources/test.json'),
145
- remote: testApp.defaults.baseURL,
146
- type: 'test',
147
- seed: false,
148
- })).rejects.toThrow('Request failed with status code 404');
149
- });
150
- describe('updateResource', () => {
151
- it('should update existing resources', async () => {
152
- const resourceDefinition = {
153
- roles: ['$public'],
154
- schema: {
155
- type: 'object',
156
- additionalProperties: false,
157
- required: ['name'],
158
- properties: {
159
- name: {
160
- type: 'string',
161
- },
162
- email: {
163
- type: 'string',
164
- format: 'email',
165
- },
166
- },
167
- },
168
- };
169
- const app = await App.create({
170
- path: 'test-app',
171
- definition: {
172
- resources: { test: resourceDefinition },
173
- name: 'Test App',
174
- defaultPage: 'Test Page',
175
- },
176
- vapidPublicKey: 'a',
177
- vapidPrivateKey: 'b',
178
- visibility: 'public',
179
- OrganizationId: organization.id,
180
- });
181
- await Resource.bulkCreate([
182
- {
183
- id: 1,
184
- type: 'test',
185
- AppId: app.id,
186
- data: {
187
- name: 'Hello World',
188
- },
189
- },
190
- {
191
- id: 2,
192
- type: 'test',
193
- AppId: app.id,
194
- data: {
195
- name: 'World Hello',
196
- email: 'hello@example.com',
197
- },
198
- },
199
- {
200
- id: 3,
201
- type: 'test',
202
- AppId: app.id,
203
- data: {
204
- name: 'Random name',
205
- email: 'removed@example.com',
206
- },
207
- },
208
- ]);
209
- await authorizeCLI('resources:write', testApp);
210
- await updateResource({
211
- appId: app.id,
212
- resourceName: 'test',
213
- remote: testApp.defaults.baseURL,
214
- path: resolveFixture('resources/test-update.json'),
215
- });
216
- const resources = await Resource.findAll();
217
- expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
218
- [
219
- {
220
- "$created": "1970-01-01T00:00:00.000Z",
221
- "$updated": "1970-01-01T00:00:00.000Z",
222
- "email": "test@example.com",
223
- "id": 1,
224
- "name": "John Doe",
225
- },
226
- {
227
- "$created": "1970-01-01T00:00:00.000Z",
228
- "$updated": "1970-01-01T00:00:00.000Z",
229
- "email": "test2@example.com",
230
- "id": 2,
231
- "name": "Jane Doe",
232
- },
233
- {
234
- "$created": "1970-01-01T00:00:00.000Z",
235
- "$updated": "1970-01-01T00:00:00.000Z",
236
- "id": 3,
237
- "name": "test name",
238
- },
239
- ]
240
- `);
241
- });
242
- it('should throw if the resource to be updated does not exist', async () => {
243
- const resourceDefinition = {
244
- roles: ['$public'],
245
- schema: {
246
- type: 'object',
247
- additionalProperties: false,
248
- required: ['name'],
249
- properties: {
250
- name: {
251
- type: 'string',
252
- },
253
- email: {
254
- type: 'string',
255
- format: 'email',
256
- },
257
- },
258
- },
259
- };
260
- const app = await App.create({
261
- path: 'test-app',
262
- definition: {
263
- resources: { test: resourceDefinition },
264
- name: 'Test App',
265
- defaultPage: 'Test Page',
266
- },
267
- vapidPublicKey: 'a',
268
- vapidPrivateKey: 'b',
269
- visibility: 'public',
270
- OrganizationId: organization.id,
271
- });
272
- await Resource.bulkCreate([
273
- {
274
- id: 1,
275
- type: 'test',
276
- AppId: app.id,
277
- data: {
278
- name: 'Hello World',
279
- },
280
- },
281
- {
282
- id: 2,
283
- type: 'test',
284
- AppId: app.id,
285
- data: {
286
- name: 'World Hello',
287
- email: 'hello@example.com',
288
- },
289
- },
290
- ]);
291
- await authorizeCLI('resources:write', testApp);
292
- await expect(() => updateResource({
293
- appId: app.id,
294
- resourceName: 'test',
295
- remote: testApp.defaults.baseURL,
296
- path: resolveFixture('resources/test-update.json'),
297
- })).rejects.toThrow('Request failed with status code 404');
298
- });
299
- it('should not update if there are no IDs in resource file', async () => {
300
- const resourceDefinition = {
301
- roles: ['$public'],
302
- schema: {
303
- type: 'object',
304
- additionalProperties: false,
305
- required: ['name'],
306
- properties: {
307
- name: {
308
- type: 'string',
309
- },
310
- email: {
311
- type: 'string',
312
- format: 'email',
313
- },
314
- },
315
- },
316
- };
317
- const app = await App.create({
318
- path: 'test-app',
319
- definition: {
320
- resources: { test: resourceDefinition },
321
- name: 'Test App',
322
- defaultPage: 'Test Page',
323
- },
324
- vapidPublicKey: 'a',
325
- vapidPrivateKey: 'b',
326
- visibility: 'public',
327
- OrganizationId: organization.id,
328
- });
329
- await Resource.bulkCreate([
330
- {
331
- id: 1,
332
- type: 'test',
333
- AppId: app.id,
334
- data: {
335
- name: 'Hello World',
336
- },
337
- },
338
- {
339
- id: 2,
340
- type: 'test',
341
- AppId: app.id,
342
- data: {
343
- name: 'World Hello',
344
- email: 'hello@example.com',
345
- },
346
- },
347
- ]);
348
- await authorizeCLI('resources:write', testApp);
349
- const resources = await Resource.findAll();
350
- expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
351
- [
352
- {
353
- "$created": "1970-01-01T00:00:00.000Z",
354
- "$updated": "1970-01-01T00:00:00.000Z",
355
- "id": 1,
356
- "name": "Hello World",
357
- },
358
- {
359
- "$created": "1970-01-01T00:00:00.000Z",
360
- "$updated": "1970-01-01T00:00:00.000Z",
361
- "email": "hello@example.com",
362
- "id": 2,
363
- "name": "World Hello",
364
- },
365
- ]
366
- `);
367
- await updateResource({
368
- appId: app.id,
369
- resourceName: 'test',
370
- remote: testApp.defaults.baseURL,
371
- path: resolveFixture('resources/test.json'),
372
- });
373
- expect(resources.map((r) => r.toJSON())).toMatchInlineSnapshot(`
374
- [
375
- {
376
- "$created": "1970-01-01T00:00:00.000Z",
377
- "$updated": "1970-01-01T00:00:00.000Z",
378
- "id": 1,
379
- "name": "Hello World",
380
- },
381
- {
382
- "$created": "1970-01-01T00:00:00.000Z",
383
- "$updated": "1970-01-01T00:00:00.000Z",
384
- "email": "hello@example.com",
385
- "id": 2,
386
- "name": "World Hello",
387
- },
388
- ]
389
- `);
390
- });
391
- });
392
- });
393
- //# sourceMappingURL=resource.test.js.map
@@ -1 +0,0 @@
1
- export {};