@appsemble/utils 0.21.3 → 0.22.0

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/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.21.3/config/assets/logo.svg) Appsemble Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.22.0/config/assets/logo.svg) Appsemble Utilities
2
2
 
3
3
  > Internal utility functions used across multiple Appsemble projects.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@appsemble/utils)](https://www.npmjs.com/package/@appsemble/utils)
6
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.21.3/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.21.3)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.22.0/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.22.0)
7
7
  [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)
8
8
 
9
9
  ## Table of Contents
@@ -26,5 +26,5 @@ not guaranteed.
26
26
 
27
27
  ## License
28
28
 
29
- [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.21.3/LICENSE.md) ©
29
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.22.0/LICENSE.md) ©
30
30
  [Appsemble](https://appsemble.com)
@@ -72,6 +72,7 @@ export const ActionDefinition = {
72
72
  { $ref: '#/components/schemas/TeamMembersActionDefinition' },
73
73
  { $ref: '#/components/schemas/ThrowActionDefinition' },
74
74
  { $ref: '#/components/schemas/UserLoginActionDefinition' },
75
+ { $ref: '#/components/schemas/UserLogoutActionDefinition' },
75
76
  { $ref: '#/components/schemas/UserRegisterActionDefinition' },
76
77
  { $ref: '#/components/schemas/UserUpdateActionDefinition' },
77
78
  ],
@@ -1,7 +1,7 @@
1
1
  import { normalized } from '../../../constants/index.js';
2
2
  export const Asset = {
3
3
  type: 'object',
4
- description: 'The response object of an asset create call.',
4
+ description: 'The response object of an asset publish call.',
5
5
  additionalProperties: false,
6
6
  properties: {
7
7
  id: {
@@ -61,6 +61,7 @@ name of the resource and how it should behave.
61
61
  properties: {
62
62
  resource: { type: 'string' },
63
63
  create: referenceAction,
64
+ patch: referenceAction,
64
65
  update: referenceAction,
65
66
  delete: referenceAction,
66
67
  },
@@ -171,6 +172,28 @@ name of the resource and how it should behave.
171
172
  },
172
173
  },
173
174
  },
175
+ patch: {
176
+ type: 'object',
177
+ description: "Overrides for 'patch' requests.",
178
+ additionalProperties: false,
179
+ properties: {
180
+ roles,
181
+ query,
182
+ method: {
183
+ type: 'string',
184
+ default: 'PATCH',
185
+ description: 'HTTP method to use for this type of request.',
186
+ },
187
+ url: {
188
+ type: 'string',
189
+ default: '/api/apps/{appId}/{resource}/{id}',
190
+ description: 'URL to use for this type of request.',
191
+ },
192
+ hooks: {
193
+ $ref: '#/components/schemas/ResourceHooksDefinition',
194
+ },
195
+ },
196
+ },
174
197
  update: {
175
198
  type: 'object',
176
199
  description: "Overrides for 'update' requests.",
@@ -0,0 +1 @@
1
+ export declare const UserLogoutActionDefinition: import("openapi-types").OpenAPIV3.SchemaObject;
@@ -0,0 +1,14 @@
1
+ import { BaseActionDefinition } from './BaseActionDefinition.js';
2
+ import { extendJSONSchema } from './utils.js';
3
+ export const UserLogoutActionDefinition = extendJSONSchema(BaseActionDefinition, {
4
+ type: 'object',
5
+ additionalProperties: false,
6
+ required: ['type'],
7
+ properties: {
8
+ type: {
9
+ enum: ['user.logout'],
10
+ description: 'Allow the users to logout of the application.',
11
+ },
12
+ },
13
+ });
14
+ //# sourceMappingURL=UserLogoutActionDefinition.js.map
@@ -112,6 +112,7 @@ export * from './Theme.js';
112
112
  export * from './ThrowActionDefinition.js';
113
113
  export * from './User.js';
114
114
  export * from './UserEmail.js';
115
+ export * from './UserLogoutActionDefinition.js';
115
116
  export * from './UserLoginActionDefinition.js';
116
117
  export * from './UserRegisterActionDefinition.js';
117
118
  export * from './UserUpdateActionDefinition.js';
@@ -112,6 +112,7 @@ export * from './Theme.js';
112
112
  export * from './ThrowActionDefinition.js';
113
113
  export * from './User.js';
114
114
  export * from './UserEmail.js';
115
+ export * from './UserLogoutActionDefinition.js';
115
116
  export * from './UserLoginActionDefinition.js';
116
117
  export * from './UserRegisterActionDefinition.js';
117
118
  export * from './UserUpdateActionDefinition.js';
@@ -11,6 +11,7 @@ export const cli = {
11
11
  scopes: {
12
12
  'apps:write': 'Create and update apps',
13
13
  'blocks:write': 'Register and update blocks, and publish new block versions.',
14
+ 'blocks:delete': 'Delete specific block versions.',
14
15
  'organizations:write': 'Create and manage organizations.',
15
16
  'resources:read': 'Read app resources on behalf of a user.',
16
17
  'resources:write': 'Modify app resources on behalf of a user.',
@@ -102,6 +102,17 @@ export const paths = {
102
102
  },
103
103
  },
104
104
  },
105
+ delete: {
106
+ tags: ['block', 'delete'],
107
+ description: 'Delete a single block version.',
108
+ operationId: 'removeBlockVersion',
109
+ responses: {
110
+ 204: {
111
+ description: 'Block version has successfully been deleted',
112
+ },
113
+ },
114
+ security: [{ cli: ['blocks:delete'] }],
115
+ },
105
116
  },
106
117
  '/api/blocks/@{organizationId}/{blockId}/versions/{blockVersion}/asset': {
107
118
  parameters: [
@@ -125,6 +125,17 @@ export const paths = {
125
125
  },
126
126
  security: [{ studio: [] }, { cli: ['organizations:write'] }],
127
127
  },
128
+ delete: {
129
+ tags: ['organization'],
130
+ description: 'Delete an organization.',
131
+ operationId: 'deleteOrganization',
132
+ responses: {
133
+ 200: {
134
+ description: 'successfully deleted organization',
135
+ },
136
+ },
137
+ security: [{ studio: [] }, {}],
138
+ },
128
139
  },
129
140
  '/api/organizations/{organizationId}/icon': {
130
141
  parameters: [{ $ref: '#/components/parameters/organizationId' }],
package/api/paths/user.js CHANGED
@@ -476,5 +476,44 @@ export const paths = {
476
476
  },
477
477
  },
478
478
  },
479
+ '/api/subscribed': {
480
+ get: {
481
+ tags: ['user'],
482
+ description: 'Get a list of active and verified users subscribed to the appsemble newsletter',
483
+ operationId: 'getSubscribedUsers',
484
+ responses: {
485
+ 200: { description: 'List of subscribed users' },
486
+ 401: { description: 'Invalid or missing admin API secret' },
487
+ },
488
+ },
489
+ },
490
+ '/api/unsubscribe': {
491
+ post: {
492
+ tags: ['user'],
493
+ description: 'Unsubscribe a user from the newsletter',
494
+ operationId: 'unsubscribe',
495
+ responses: {
496
+ 201: { description: 'Unsubscribed successfully' },
497
+ 401: { description: 'Invalid or missing admin API secret' },
498
+ },
499
+ requestBody: {
500
+ required: true,
501
+ content: {
502
+ 'application/json': {
503
+ schema: {
504
+ type: 'object',
505
+ required: ['email'],
506
+ properties: {
507
+ email: {
508
+ type: 'string',
509
+ format: 'email',
510
+ },
511
+ },
512
+ },
513
+ },
514
+ },
515
+ },
516
+ },
517
+ },
479
518
  };
480
519
  //# sourceMappingURL=user.js.map
@@ -26,53 +26,61 @@ export declare enum Permission {
26
26
  * The permission to edit the name and logo of an organization.
27
27
  */
28
28
  EditOrganization = 5,
29
+ /**
30
+ * The permission to delete an organization if it doesn't have any apps.
31
+ */
32
+ DeleteOrganization = 6,
29
33
  /**
30
34
  * The permission to invite new members into an organization,
31
35
  * removing existing invites, and resending invites.
32
36
  */
33
- InviteMember = 6,
37
+ InviteMember = 7,
34
38
  /**
35
39
  * The permission to create and delete assets.
36
40
  */
37
- ManageAssets = 7,
41
+ ManageAssets = 8,
38
42
  /**
39
43
  * The permission to remove organization members.
40
44
  */
41
- ManageMembers = 8,
45
+ ManageMembers = 9,
42
46
  /**
43
47
  * The permission to create, edit, and delete resources.
44
48
  */
45
- ManageResources = 9,
49
+ ManageResources = 10,
46
50
  /**
47
51
  * The permission to change the roles of organization members.
48
52
  */
49
- ManageRoles = 10,
53
+ ManageRoles = 11,
50
54
  /**
51
55
  * The permission to create and delete teams and manage its members.
52
56
  */
53
- ManageTeams = 11,
57
+ ManageTeams = 12,
54
58
  /**
55
59
  * The permission to publish blocks for an organization.
56
60
  */
57
- PublishBlocks = 12,
61
+ PublishBlocks = 13,
62
+ /**
63
+ * The permission to delete blocks for an organization.
64
+ */
65
+ DeleteBlocks = 14,
58
66
  /**
59
67
  * The permission to send manual push notifications for an app.
60
68
  */
61
- PushNotifications = 13,
69
+ PushNotifications = 15,
62
70
  /**
63
71
  * The permission to read assets.
64
72
  */
65
- ReadAssets = 14,
73
+ ReadAssets = 16,
66
74
  /**
67
75
  * The permission to read resources.
68
76
  */
69
- ReadResources = 15,
77
+ ReadResources = 17,
70
78
  /**
71
79
  * The permission to view private apps of an organization.
72
80
  */
73
- ViewApps = 16,
81
+ ViewApps = 18,
74
82
  /**
75
83
  * The permission to view the list of members in an organization.
76
84
  */
77
- ViewMembers = 17
85
+ ViewMembers = 19
78
86
  }
@@ -27,54 +27,62 @@ export var Permission;
27
27
  * The permission to edit the name and logo of an organization.
28
28
  */
29
29
  Permission[Permission["EditOrganization"] = 5] = "EditOrganization";
30
+ /**
31
+ * The permission to delete an organization if it doesn't have any apps.
32
+ */
33
+ Permission[Permission["DeleteOrganization"] = 6] = "DeleteOrganization";
30
34
  /**
31
35
  * The permission to invite new members into an organization,
32
36
  * removing existing invites, and resending invites.
33
37
  */
34
- Permission[Permission["InviteMember"] = 6] = "InviteMember";
38
+ Permission[Permission["InviteMember"] = 7] = "InviteMember";
35
39
  /**
36
40
  * The permission to create and delete assets.
37
41
  */
38
- Permission[Permission["ManageAssets"] = 7] = "ManageAssets";
42
+ Permission[Permission["ManageAssets"] = 8] = "ManageAssets";
39
43
  /**
40
44
  * The permission to remove organization members.
41
45
  */
42
- Permission[Permission["ManageMembers"] = 8] = "ManageMembers";
46
+ Permission[Permission["ManageMembers"] = 9] = "ManageMembers";
43
47
  /**
44
48
  * The permission to create, edit, and delete resources.
45
49
  */
46
- Permission[Permission["ManageResources"] = 9] = "ManageResources";
50
+ Permission[Permission["ManageResources"] = 10] = "ManageResources";
47
51
  /**
48
52
  * The permission to change the roles of organization members.
49
53
  */
50
- Permission[Permission["ManageRoles"] = 10] = "ManageRoles";
54
+ Permission[Permission["ManageRoles"] = 11] = "ManageRoles";
51
55
  /**
52
56
  * The permission to create and delete teams and manage its members.
53
57
  */
54
- Permission[Permission["ManageTeams"] = 11] = "ManageTeams";
58
+ Permission[Permission["ManageTeams"] = 12] = "ManageTeams";
55
59
  /**
56
60
  * The permission to publish blocks for an organization.
57
61
  */
58
- Permission[Permission["PublishBlocks"] = 12] = "PublishBlocks";
62
+ Permission[Permission["PublishBlocks"] = 13] = "PublishBlocks";
63
+ /**
64
+ * The permission to delete blocks for an organization.
65
+ */
66
+ Permission[Permission["DeleteBlocks"] = 14] = "DeleteBlocks";
59
67
  /**
60
68
  * The permission to send manual push notifications for an app.
61
69
  */
62
- Permission[Permission["PushNotifications"] = 13] = "PushNotifications";
70
+ Permission[Permission["PushNotifications"] = 15] = "PushNotifications";
63
71
  /**
64
72
  * The permission to read assets.
65
73
  */
66
- Permission[Permission["ReadAssets"] = 14] = "ReadAssets";
74
+ Permission[Permission["ReadAssets"] = 16] = "ReadAssets";
67
75
  /**
68
76
  * The permission to read resources.
69
77
  */
70
- Permission[Permission["ReadResources"] = 15] = "ReadResources";
78
+ Permission[Permission["ReadResources"] = 17] = "ReadResources";
71
79
  /**
72
80
  * The permission to view private apps of an organization.
73
81
  */
74
- Permission[Permission["ViewApps"] = 16] = "ViewApps";
82
+ Permission[Permission["ViewApps"] = 18] = "ViewApps";
75
83
  /**
76
84
  * The permission to view the list of members in an organization.
77
85
  */
78
- Permission[Permission["ViewMembers"] = 17] = "ViewMembers";
86
+ Permission[Permission["ViewMembers"] = 19] = "ViewMembers";
79
87
  })(Permission || (Permission = {}));
80
88
  //# sourceMappingURL=Permission.js.map
@@ -21,10 +21,12 @@ const Maintainer = [
21
21
  Permission.InviteMember,
22
22
  Permission.ManageTeams,
23
23
  Permission.PublishBlocks,
24
+ Permission.DeleteBlocks,
24
25
  ];
25
26
  const Owner = [
26
27
  ...Maintainer,
27
28
  Permission.EditOrganization,
29
+ Permission.DeleteOrganization,
28
30
  Permission.ManageMembers,
29
31
  Permission.ManageRoles,
30
32
  ];
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * All known OAuth2 scopes for client credentials.
3
3
  */
4
- export declare const scopes: readonly ["apps:write", "blocks:write", "organizations:write", "resources:read", "resources:write", "assets:write", "teams:read", "teams:write"];
4
+ export declare const scopes: readonly ["apps:write", "blocks:write", "blocks:delete", "organizations:write", "resources:read", "resources:write", "assets:write", "teams:read", "teams:write"];
@@ -4,6 +4,7 @@
4
4
  export const scopes = [
5
5
  'apps:write',
6
6
  'blocks:write',
7
+ 'blocks:delete',
7
8
  'organizations:write',
8
9
  'resources:read',
9
10
  'resources:write',
@@ -4,6 +4,7 @@ export function formatRequestAction({ method = 'GET', query, ...action }, data,
4
4
  url: String(remap(action.url, data, context)),
5
5
  headers: {},
6
6
  params: remap(query, data, context),
7
+ responseType: 'arraybuffer',
7
8
  };
8
9
  }
9
10
  //# sourceMappingURL=formatRequestAction.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/utils",
3
- "version": "0.21.3",
3
+ "version": "0.22.0",
4
4
  "description": "Utility functions used in Appsemble internally",
5
5
  "keywords": [
6
6
  "app",
@@ -37,7 +37,7 @@
37
37
  "test": "vitest"
38
38
  },
39
39
  "dependencies": {
40
- "@appsemble/types": "0.21.3",
40
+ "@appsemble/types": "0.22.0",
41
41
  "axios": "^1.0.0",
42
42
  "cron-parser": "^4.0.0",
43
43
  "date-fns": "^2.0.0",
@@ -39,7 +39,7 @@ Result:
39
39
  `,
40
40
  },
41
41
  'date.format': {
42
- enum: [null],
42
+ enum: ['string', null],
43
43
  description: `Format a date according to the RFC3339 format.
44
44
 
45
45
  Here is an example of a RFC3339 complicit date:
@@ -47,7 +47,7 @@ Here is an example of a RFC3339 complicit date:
47
47
 
48
48
  In an app definition, it’s best to use this when you want to display a date in a specific format.
49
49
  For example, if your app has a form with a Datepicker field the incoming data will be formatted
50
- as a simple date format. If you want to format it tot he RFC3339 format, you can use this remapper.
50
+ as a simple date format. If you want to format it to the RFC3339 format, you can use this remapper.
51
51
 
52
52
  When you submit a form with a DateField, the internal output looks like this:
53
53
 
@@ -63,7 +63,24 @@ date.format: null
63
63
 
64
64
  Result:
65
65
  \`\`\`js
66
- "2023-07-03T09:09:50.000Z"
66
+ "2023-07-02T22:00:00.000Z"
67
+ \`\`\`
68
+
69
+ The remapper can also be used to format a date or timestamp using a custom format.
70
+
71
+ \`\`\`js
72
+ "2023-07-02T22:00:00.000Z"
73
+ \`\`\`
74
+
75
+ You can then format the date with any supported pattern, please refer to https://date-fns.org/docs/format for the supported patterns.
76
+
77
+ \`\`\`yaml
78
+ date.format: yyyy-MM-dd
79
+ \`\`\`
80
+
81
+ Result:
82
+ \`\`\`js
83
+ 2023-07-03
67
84
  \`\`\`
68
85
  `,
69
86
  },
package/remap.js CHANGED
@@ -1,4 +1,4 @@
1
- import { addMilliseconds, parse, parseISO } from 'date-fns';
1
+ import { addMilliseconds, format, parse, parseISO } from 'date-fns';
2
2
  import equal from 'fast-deep-equal';
3
3
  import { createEvent } from 'ics';
4
4
  import parseDuration from 'parse-duration';
@@ -233,7 +233,7 @@ const mapperImplementations = {
233
233
  }
234
234
  return result;
235
235
  },
236
- 'date.parse': (format, input) => format ? parse(input, format, new Date()) : parseISO(input),
236
+ 'date.parse': (fmt, input) => (fmt ? parse(input, fmt, new Date()) : parseISO(input)),
237
237
  'date.now': () => new Date(),
238
238
  'date.add'(time, input) {
239
239
  const expireDuration = parseDuration(time);
@@ -248,7 +248,7 @@ const mapperImplementations = {
248
248
  : typeof input === 'number'
249
249
  ? new Date(input)
250
250
  : parseISO(String(input));
251
- return date.toJSON();
251
+ return args ? format(date, args) : date.toJSON();
252
252
  },
253
253
  'null.strip': (args, input) => stripNullValues(input, args || {}),
254
254
  'random.choice': (args, input) => Array.isArray(input) ? input[Math.floor(Math.random() * input.length)] : input,
package/remap.test.js CHANGED
@@ -183,6 +183,21 @@ describe('date.format', () => {
183
183
  mappers: { 'date.format': null },
184
184
  expected: '1970-01-01T00:00:00.000Z',
185
185
  },
186
+ 'format date objects to custom format': {
187
+ input: new Date('2020-01-02T03:04:05Z'),
188
+ mappers: { 'date.format': 'dd-MM-yyyy' },
189
+ expected: '02-01-2020',
190
+ },
191
+ 'format date strings to custom format': {
192
+ input: '2020-01-02T03:04:05Z',
193
+ mappers: { 'date.format': 'yyyy-MM-dd' },
194
+ expected: '2020-01-02',
195
+ },
196
+ 'format unix timestamps to custom format': {
197
+ input: 0,
198
+ mappers: { 'date.format': 'MM/dd/yyyy' },
199
+ expected: '01/01/1970',
200
+ },
186
201
  });
187
202
  });
188
203
  describe('log', () => {
package/theme.test.js CHANGED
@@ -1,4 +1,4 @@
1
- import bulmaPkg from 'bulma/package.json' assert { type: 'json' };
1
+ import bulmaPkg from 'bulma/package.json';
2
2
  import { createThemeURL, mergeThemes } from './theme.js';
3
3
  describe('mergeThemes', () => {
4
4
  it('should use the base theme as default', () => {
@@ -1,2 +0,0 @@
1
- declare const _default: import("vitest/dist/config.js").UserProjectConfigExport;
2
- export default _default;