@appsemble/utils 0.20.32 → 0.20.33
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 +4 -4
- package/api/components/schemas/ActionDefinition.js +1 -0
- package/api/components/schemas/AppDefinition.js +3 -1
- package/api/components/schemas/NotifyActionDefinition.d.ts +1 -0
- package/api/components/schemas/NotifyActionDefinition.js +32 -0
- package/api/components/schemas/index.d.ts +1 -0
- package/api/components/schemas/index.js +1 -0
- package/api/paths/apps.js +2 -2
- package/blockUtils.js +0 -1
- package/formatRequestAction.d.ts +2 -2
- package/jsonschema.js +0 -1
- package/miscellaneous.js +0 -1
- package/package.json +2 -2
- package/validation.js +4 -1
- package/validation.test.js +12 -0
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#  Appsemble Utilities
|
|
2
2
|
|
|
3
3
|
> Internal utility functions used across multiple Appsemble projects.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.20.33)
|
|
7
|
+
[](https://codecov.io/gl/appsemble/appsemble)
|
|
8
8
|
[](https://prettier.io)
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
@@ -21,5 +21,5 @@ not guaranteed.
|
|
|
21
21
|
|
|
22
22
|
## License
|
|
23
23
|
|
|
24
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.20.
|
|
24
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.20.33/LICENSE.md) ©
|
|
25
25
|
[Appsemble](https://appsemble.com)
|
|
@@ -44,6 +44,7 @@ export const ActionDefinition = {
|
|
|
44
44
|
{ $ref: '#/components/schemas/LogActionDefinition' },
|
|
45
45
|
{ $ref: '#/components/schemas/MessageActionDefinition' },
|
|
46
46
|
{ $ref: '#/components/schemas/NoopActionDefinition' },
|
|
47
|
+
{ $ref: '#/components/schemas/NotifyActionDefinition' },
|
|
47
48
|
{ $ref: '#/components/schemas/RequestActionDefinition' },
|
|
48
49
|
{ $ref: '#/components/schemas/ResourceCountActionDefinition' },
|
|
49
50
|
{ $ref: '#/components/schemas/ResourceCreateActionDefinition' },
|
|
@@ -39,13 +39,15 @@ This will be displayed on the app store.
|
|
|
39
39
|
description: 'Properties related to the layout of the app.',
|
|
40
40
|
},
|
|
41
41
|
notifications: {
|
|
42
|
-
enum: ['opt-in', 'startup'],
|
|
42
|
+
enum: ['login', 'opt-in', 'startup'],
|
|
43
43
|
description: `The strategy to use for apps to subscribe to push notifications.
|
|
44
44
|
|
|
45
45
|
If specified, push notifications can be sent to subscribed users via the _Notifications_ tab in the
|
|
46
46
|
app details page in Appsemble Studio. Setting this to \`opt-in\` allows for users to opt into
|
|
47
47
|
receiving push notifications by pressing the subscribe button in the App settings page. Setting this
|
|
48
48
|
to \`startup\` will cause Appsemble to immediately request for the permission upon opening the app.
|
|
49
|
+
If this is set to \`login\`, the app will request permissions for push notification once the user
|
|
50
|
+
logs in.
|
|
49
51
|
|
|
50
52
|
> **Note**: Setting \`notifications\` to \`startup\` is not recommended, due to its invasive nature.
|
|
51
53
|
`,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const NotifyActionDefinition: import("openapi-types").OpenAPIV3.SchemaObject;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseActionDefinition } from './BaseActionDefinition.js';
|
|
2
|
+
import { extendJSONSchema } from './utils.js';
|
|
3
|
+
export const NotifyActionDefinition = extendJSONSchema(BaseActionDefinition, {
|
|
4
|
+
type: 'object',
|
|
5
|
+
additionalProperties: false,
|
|
6
|
+
required: ['type', 'title', 'body', 'to'],
|
|
7
|
+
properties: {
|
|
8
|
+
type: {
|
|
9
|
+
enum: ['notify'],
|
|
10
|
+
description: 'Send notifications to one or all the users of an app.',
|
|
11
|
+
},
|
|
12
|
+
title: {
|
|
13
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
14
|
+
description: 'The title of the notification.',
|
|
15
|
+
},
|
|
16
|
+
body: {
|
|
17
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
18
|
+
description: 'The description of the notification.',
|
|
19
|
+
},
|
|
20
|
+
to: {
|
|
21
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
22
|
+
description: `To whom the notification should be sent.
|
|
23
|
+
|
|
24
|
+
Use \`all\` to send the notification to all app subscribed users.
|
|
25
|
+
Or notify specific users by passing either a single user id or an array of user ids.
|
|
26
|
+
|
|
27
|
+
Nothing is sent if the value is **not** a valid user id.
|
|
28
|
+
`,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=NotifyActionDefinition.js.map
|
|
@@ -56,6 +56,7 @@ export * from './MessageActionDefinition.js';
|
|
|
56
56
|
export * from './NoopActionDefinition.js';
|
|
57
57
|
export * from './NotificationHookDataDefinition.js';
|
|
58
58
|
export * from './NotificationHookDefinition.js';
|
|
59
|
+
export * from './NotifyActionDefinition.js';
|
|
59
60
|
export * from './OAuth2AuthorizationCode.js';
|
|
60
61
|
export * from './OAuth2ClientCredentials.js';
|
|
61
62
|
export * from './ObjectRemapperDefinition.js';
|
|
@@ -56,6 +56,7 @@ export * from './MessageActionDefinition.js';
|
|
|
56
56
|
export * from './NoopActionDefinition.js';
|
|
57
57
|
export * from './NotificationHookDataDefinition.js';
|
|
58
58
|
export * from './NotificationHookDefinition.js';
|
|
59
|
+
export * from './NotifyActionDefinition.js';
|
|
59
60
|
export * from './OAuth2AuthorizationCode.js';
|
|
60
61
|
export * from './OAuth2ClientCredentials.js';
|
|
61
62
|
export * from './ObjectRemapperDefinition.js';
|
package/api/paths/apps.js
CHANGED
|
@@ -444,7 +444,7 @@ export const paths = {
|
|
|
444
444
|
description: 'The subscription has successfully been registered.',
|
|
445
445
|
},
|
|
446
446
|
},
|
|
447
|
-
security: [{
|
|
447
|
+
security: [{ app: ['openid'] }, {}],
|
|
448
448
|
},
|
|
449
449
|
patch: {
|
|
450
450
|
tags: ['app'],
|
|
@@ -484,7 +484,7 @@ export const paths = {
|
|
|
484
484
|
description: 'The subscription has successfully been updated.',
|
|
485
485
|
},
|
|
486
486
|
},
|
|
487
|
-
security: [{
|
|
487
|
+
security: [{ app: ['openid'] }, {}],
|
|
488
488
|
},
|
|
489
489
|
},
|
|
490
490
|
'/api/apps/{appId}/members': {
|
package/blockUtils.js
CHANGED
package/formatRequestAction.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Remapper, RequestLikeActionDefinition } from '@appsemble/types';
|
|
2
|
-
import {
|
|
3
|
-
export declare function formatRequestAction({ method, query, ...action }: RequestLikeActionDefinition, data: unknown, remap: (remapper: Remapper, data: any, context: Record<string, unknown>) => any, context: Record<string, unknown>):
|
|
2
|
+
import { RawAxiosRequestConfig } from 'axios';
|
|
3
|
+
export declare function formatRequestAction({ method, query, ...action }: RequestLikeActionDefinition, data: unknown, remap: (remapper: Remapper, data: any, context: Record<string, unknown>) => any, context: Record<string, unknown>): RawAxiosRequestConfig;
|
package/jsonschema.js
CHANGED
package/miscellaneous.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.33",
|
|
4
4
|
"description": "Utility functions used in Appsemble internally",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@appsemble/types": "0.20.
|
|
34
|
+
"@appsemble/types": "0.20.33",
|
|
35
35
|
"axios": "^1.0.0",
|
|
36
36
|
"cron-parser": "^4.0.0",
|
|
37
37
|
"date-fns": "^2.0.0",
|
package/validation.js
CHANGED
|
@@ -224,9 +224,12 @@ function checkCyclicRoleInheritance(roles, name, report) {
|
|
|
224
224
|
* @param report A function used to report a value.
|
|
225
225
|
*/
|
|
226
226
|
function validateSecurity(definition, report) {
|
|
227
|
-
const { security } = definition;
|
|
227
|
+
const { notifications, security } = definition;
|
|
228
228
|
const defaultAllow = ['$none', '$public', '$team:member', '$team:manager'];
|
|
229
229
|
if (!security) {
|
|
230
|
+
if (notifications === 'login') {
|
|
231
|
+
report(notifications, 'only works if security is defined', ['notifications']);
|
|
232
|
+
}
|
|
230
233
|
return;
|
|
231
234
|
}
|
|
232
235
|
const checkRoleExists = (name, path, allow = defaultAllow) => {
|
package/validation.test.js
CHANGED
|
@@ -701,6 +701,18 @@ describe('validateAppDefinition', () => {
|
|
|
701
701
|
const result = await validateAppDefinition(app, () => []);
|
|
702
702
|
expect(result.valid).toBe(true);
|
|
703
703
|
});
|
|
704
|
+
it('should report if notifications is "login" without a security definition', async () => {
|
|
705
|
+
const app = createTestApp();
|
|
706
|
+
delete app.security;
|
|
707
|
+
app.notifications = 'login';
|
|
708
|
+
const result = await validateAppDefinition(app, () => []);
|
|
709
|
+
expect(result.valid).toBe(false);
|
|
710
|
+
expect(result.errors).toStrictEqual([
|
|
711
|
+
new ValidationError('only works if security is defined', 'login', undefined, [
|
|
712
|
+
'notifications',
|
|
713
|
+
]),
|
|
714
|
+
]);
|
|
715
|
+
});
|
|
704
716
|
it('should validate the default role exists', async () => {
|
|
705
717
|
const app = createTestApp();
|
|
706
718
|
app.security.default.role = 'Unknown';
|