@appsemble/utils 0.27.11 → 0.27.12
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 +3 -3
- package/api/components/parameters/appVariableId.d.ts +2 -0
- package/api/components/parameters/appVariableId.js +8 -0
- package/api/components/parameters/index.d.ts +1 -0
- package/api/components/parameters/index.js +1 -0
- package/api/components/schemas/AppVariable.d.ts +2 -0
- package/api/components/schemas/AppVariable.js +22 -0
- package/api/components/schemas/index.d.ts +1 -0
- package/api/components/schemas/index.js +1 -0
- package/api/paths/appOAuth2Secrets.js +11 -1
- package/api/paths/appSSLSecrets.js +1 -1
- package/api/paths/appSamlSecrets.js +11 -1
- package/api/paths/appScimSecrets.js +1 -1
- package/api/paths/appServiceSecrets.js +12 -2
- package/api/paths/appVariables.d.ts +2 -0
- package/api/paths/appVariables.js +93 -0
- package/api/paths/index.js +2 -0
- package/api/paths/templates.js +8 -0
- package/examples.js +7 -0
- package/package.json +2 -2
- package/reference-schemas/remappers/config.d.ts +2 -0
- package/reference-schemas/remappers/config.js +7 -0
- package/reference-schemas/remappers/index.d.ts +1 -0
- package/reference-schemas/remappers/index.js +1 -0
- package/remap.d.ts +6 -1
- package/remap.js +6 -0
- package/remap.test.js +20 -2
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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.27.12)
|
|
7
7
|
[](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.27.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.27.12/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
|
@@ -18,6 +18,7 @@ export * from './resourceType.js';
|
|
|
18
18
|
export * from './screenshotId.js';
|
|
19
19
|
export * from './readmeId.js';
|
|
20
20
|
export * from './appServiceId.js';
|
|
21
|
+
export * from './appVariableId.js';
|
|
21
22
|
export * from './view.js';
|
|
22
23
|
export * from './trainingId.js';
|
|
23
24
|
export * from './trainingBlockId.js';
|
|
@@ -18,6 +18,7 @@ export * from './resourceType.js';
|
|
|
18
18
|
export * from './screenshotId.js';
|
|
19
19
|
export * from './readmeId.js';
|
|
20
20
|
export * from './appServiceId.js';
|
|
21
|
+
export * from './appVariableId.js';
|
|
21
22
|
export * from './view.js';
|
|
22
23
|
export * from './trainingId.js';
|
|
23
24
|
export * from './trainingBlockId.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const AppVariable = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
description: 'App variable',
|
|
4
|
+
required: ['name'],
|
|
5
|
+
additionalProperties: false,
|
|
6
|
+
properties: {
|
|
7
|
+
id: {
|
|
8
|
+
type: 'number',
|
|
9
|
+
description: 'An autogenerated ID.',
|
|
10
|
+
readOnly: true,
|
|
11
|
+
},
|
|
12
|
+
name: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: 'The name of the variable, that will be accessible from clients.',
|
|
15
|
+
},
|
|
16
|
+
value: {
|
|
17
|
+
description: 'The value of the variable.',
|
|
18
|
+
anyOf: [{ type: 'string' }, { type: 'boolean' }, { type: 'number' }],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=AppVariable.js.map
|
|
@@ -12,6 +12,7 @@ export * from './AppMessages.js';
|
|
|
12
12
|
export * from './AppOAuth2Secret.js';
|
|
13
13
|
export * from './AppsembleMessages.js';
|
|
14
14
|
export * from './AppServiceSecret.js';
|
|
15
|
+
export * from './AppVariable.js';
|
|
15
16
|
export * from './ArrayRemapperDefinition.js';
|
|
16
17
|
export * from './Asset.js';
|
|
17
18
|
export * from './BlockDefinition.js';
|
|
@@ -12,6 +12,7 @@ export * from './AppMessages.js';
|
|
|
12
12
|
export * from './AppOAuth2Secret.js';
|
|
13
13
|
export * from './AppsembleMessages.js';
|
|
14
14
|
export * from './AppServiceSecret.js';
|
|
15
|
+
export * from './AppVariable.js';
|
|
15
16
|
export * from './ArrayRemapperDefinition.js';
|
|
16
17
|
export * from './Asset.js';
|
|
17
18
|
export * from './BlockDefinition.js';
|
|
@@ -11,7 +11,7 @@ export const paths = {
|
|
|
11
11
|
},
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
|
-
security: [{ studio: [] }],
|
|
14
|
+
security: [{ studio: [] }, { cli: ['apps:write'] }],
|
|
15
15
|
responses: {
|
|
16
16
|
201: {
|
|
17
17
|
description: 'A list of the OAuth2 secrets for the app.',
|
|
@@ -41,6 +41,16 @@ export const paths = {
|
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
|
+
delete: {
|
|
45
|
+
tags: ['secret'],
|
|
46
|
+
operationId: 'deleteAppOAuth2Secrets',
|
|
47
|
+
security: [{ studio: [] }, { cli: ['apps:write'] }],
|
|
48
|
+
responses: {
|
|
49
|
+
204: {
|
|
50
|
+
description: 'The deleted app OAuth2 secrets.',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
44
54
|
},
|
|
45
55
|
'/api/apps/{appId}/secrets/oauth2/{appOAuth2SecretId}': {
|
|
46
56
|
parameters: [
|
|
@@ -11,7 +11,7 @@ export const paths = {
|
|
|
11
11
|
},
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
|
-
security: [{ studio: [] }],
|
|
14
|
+
security: [{ studio: [] }, { cli: ['apps:write'] }],
|
|
15
15
|
responses: {
|
|
16
16
|
201: {
|
|
17
17
|
description: 'A list of the SAML secrets for the app.',
|
|
@@ -41,6 +41,16 @@ export const paths = {
|
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
|
+
delete: {
|
|
45
|
+
tags: ['secret'],
|
|
46
|
+
operationId: 'deleteAppSamlSecrets',
|
|
47
|
+
security: [{ studio: [] }, { cli: ['apps:write'] }],
|
|
48
|
+
responses: {
|
|
49
|
+
204: {
|
|
50
|
+
description: 'The deleted app saml secrets.',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
44
54
|
},
|
|
45
55
|
'/api/apps/{appId}/secrets/saml/{appSamlSecretId}': {
|
|
46
56
|
parameters: [
|
|
@@ -3,7 +3,7 @@ export const paths = {
|
|
|
3
3
|
parameters: [{ $ref: '#/components/parameters/appId' }],
|
|
4
4
|
post: {
|
|
5
5
|
tags: ['secret'],
|
|
6
|
-
operationId: '
|
|
6
|
+
operationId: 'createAppServiceSecret',
|
|
7
7
|
requestBody: {
|
|
8
8
|
content: {
|
|
9
9
|
'application/json': {
|
|
@@ -11,7 +11,7 @@ export const paths = {
|
|
|
11
11
|
},
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
|
-
security: [{ studio: [] }],
|
|
14
|
+
security: [{ studio: [] }, { cli: ['apps:write'] }],
|
|
15
15
|
responses: {
|
|
16
16
|
201: {
|
|
17
17
|
description: 'The created app service secret.',
|
|
@@ -41,6 +41,16 @@ export const paths = {
|
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
|
+
delete: {
|
|
45
|
+
tags: ['secret'],
|
|
46
|
+
operationId: 'deleteAppServiceSecrets',
|
|
47
|
+
security: [{ studio: [] }, { cli: ['apps:write'] }],
|
|
48
|
+
responses: {
|
|
49
|
+
204: {
|
|
50
|
+
description: 'The deleted app service secrets.',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
44
54
|
},
|
|
45
55
|
'/api/apps/{appId}/secrets/service/{appServiceId}': {
|
|
46
56
|
parameters: [
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export const paths = {
|
|
2
|
+
'/api/apps/{appId}/variables': {
|
|
3
|
+
parameters: [{ $ref: '#/components/parameters/appId' }],
|
|
4
|
+
post: {
|
|
5
|
+
tags: ['variable'],
|
|
6
|
+
operationId: 'createAppVariable',
|
|
7
|
+
requestBody: {
|
|
8
|
+
content: {
|
|
9
|
+
'application/json': {
|
|
10
|
+
schema: { $ref: '#/components/schemas/AppVariable' },
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
security: [{ studio: [] }, { cli: ['apps:write'] }],
|
|
15
|
+
responses: {
|
|
16
|
+
201: {
|
|
17
|
+
description: 'The created app variable.',
|
|
18
|
+
content: {
|
|
19
|
+
'application/json': {
|
|
20
|
+
schema: { $ref: '#/components/schemas/AppVariable' },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
get: {
|
|
27
|
+
tags: ['variable'],
|
|
28
|
+
operationId: 'getAppVariables',
|
|
29
|
+
responses: {
|
|
30
|
+
200: {
|
|
31
|
+
description: 'The list of app variables.',
|
|
32
|
+
content: {
|
|
33
|
+
'application/json': {
|
|
34
|
+
schema: {
|
|
35
|
+
type: 'array',
|
|
36
|
+
items: { $ref: '#/components/schemas/AppVariable' },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
delete: {
|
|
44
|
+
tags: ['variable'],
|
|
45
|
+
operationId: 'deleteAppVariables',
|
|
46
|
+
security: [{ studio: [] }, { cli: ['apps:write'] }],
|
|
47
|
+
responses: {
|
|
48
|
+
204: {
|
|
49
|
+
description: 'The deleted app variables.',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
'/api/apps/{appId}/variables/{appVariableId}': {
|
|
55
|
+
parameters: [
|
|
56
|
+
{ $ref: '#/components/parameters/appId' },
|
|
57
|
+
{ $ref: '#/components/parameters/appVariableId' },
|
|
58
|
+
],
|
|
59
|
+
put: {
|
|
60
|
+
tags: ['secret'],
|
|
61
|
+
operationId: 'updateAppVariable',
|
|
62
|
+
requestBody: {
|
|
63
|
+
content: {
|
|
64
|
+
'application/json': {
|
|
65
|
+
schema: { $ref: '#/components/schemas/AppVariable' },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
security: [{ studio: [] }],
|
|
70
|
+
responses: {
|
|
71
|
+
200: {
|
|
72
|
+
description: 'The updated app variable.',
|
|
73
|
+
content: {
|
|
74
|
+
'application/json': {
|
|
75
|
+
schema: { $ref: '#/components/schemas/AppVariable' },
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
delete: {
|
|
82
|
+
tags: ['secret'],
|
|
83
|
+
operationId: 'deleteAppVariable',
|
|
84
|
+
security: [{ studio: [] }],
|
|
85
|
+
responses: {
|
|
86
|
+
204: {
|
|
87
|
+
description: 'The deleted app variable.',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=appVariables.js.map
|
package/api/paths/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { paths as appScimSecrets } from './appScimSecrets.js';
|
|
|
10
10
|
import { paths as appsembleMessages } from './appsembleMessages.js';
|
|
11
11
|
import { paths as appServiceSecrets } from './appServiceSecrets.js';
|
|
12
12
|
import { paths as appSSLSecrets } from './appSSLSecrets.js';
|
|
13
|
+
import { paths as appVariables } from './appVariables.js';
|
|
13
14
|
import { paths as assets } from './assets.js';
|
|
14
15
|
import { paths as blocks } from './blocks.js';
|
|
15
16
|
import { paths as emails } from './emails.js';
|
|
@@ -33,6 +34,7 @@ export const paths = {
|
|
|
33
34
|
...scimEndpoints,
|
|
34
35
|
...appsembleMessages,
|
|
35
36
|
...appSSLSecrets,
|
|
37
|
+
...appVariables,
|
|
36
38
|
...appCollections,
|
|
37
39
|
...appQuotas,
|
|
38
40
|
...assets,
|
package/api/paths/templates.js
CHANGED
|
@@ -68,6 +68,14 @@ export const paths = {
|
|
|
68
68
|
type: 'boolean',
|
|
69
69
|
description: 'Include example assets.',
|
|
70
70
|
},
|
|
71
|
+
variables: {
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
description: 'Include example variables.',
|
|
74
|
+
},
|
|
75
|
+
secrets: {
|
|
76
|
+
type: 'boolean',
|
|
77
|
+
description: 'Include example secrets.',
|
|
78
|
+
},
|
|
71
79
|
visibility: {
|
|
72
80
|
$ref: '#/components/schemas/App/properties/visibility',
|
|
73
81
|
},
|
package/examples.js
CHANGED
|
@@ -279,6 +279,12 @@ export const examples = {
|
|
|
279
279
|
result: {},
|
|
280
280
|
skip: true,
|
|
281
281
|
},
|
|
282
|
+
variable: {
|
|
283
|
+
input: null,
|
|
284
|
+
remapper: {},
|
|
285
|
+
result: {},
|
|
286
|
+
skip: true,
|
|
287
|
+
},
|
|
282
288
|
'date.add': {
|
|
283
289
|
input: '2023-06-30T14:50:19.601Z',
|
|
284
290
|
remapper: [
|
|
@@ -649,6 +655,7 @@ export function schemaExample(remapper, options) {
|
|
|
649
655
|
export function createExampleContext(url, lang, userInfo, history) {
|
|
650
656
|
return {
|
|
651
657
|
getMessage: ({ defaultMessage }) => new IntlMessageFormat(defaultMessage, lang, undefined),
|
|
658
|
+
getVariable: () => null,
|
|
652
659
|
url: String(url),
|
|
653
660
|
appUrl: `${url.protocol}//example-app.example-organization.${url.host}`,
|
|
654
661
|
userInfo: userInfo !== null && userInfo !== void 0 ? userInfo : {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.12",
|
|
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.27.
|
|
40
|
+
"@appsemble/types": "0.27.12",
|
|
41
41
|
"axios": "^1.0.0",
|
|
42
42
|
"cron-parser": "^4.0.0",
|
|
43
43
|
"date-fns": "^2.0.0",
|
package/remap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AppMember, type Remapper, type UserInfo } from '@appsemble/types';
|
|
1
|
+
import { type AppMember, type Remapper, type UserInfo, type ValueFromProcess } from '@appsemble/types';
|
|
2
2
|
import { type IntlMessageFormat } from 'intl-messageformat';
|
|
3
3
|
export interface IntlMessage {
|
|
4
4
|
id?: string;
|
|
@@ -11,6 +11,7 @@ export interface IntlMessage {
|
|
|
11
11
|
* @returns A message format instance.
|
|
12
12
|
*/
|
|
13
13
|
export type MessageGetter = (msg: IntlMessage) => IntlMessageFormat;
|
|
14
|
+
export type AppConfigEntryGetter = (name: string) => ValueFromProcess;
|
|
14
15
|
export interface RemapperContext {
|
|
15
16
|
/**
|
|
16
17
|
* The id of the app whose context the remapper is run in.
|
|
@@ -28,6 +29,10 @@ export interface RemapperContext {
|
|
|
28
29
|
* @see MessageGetter
|
|
29
30
|
*/
|
|
30
31
|
getMessage: MessageGetter;
|
|
32
|
+
/**
|
|
33
|
+
* @see VariableGetter
|
|
34
|
+
*/
|
|
35
|
+
getVariable: AppConfigEntryGetter;
|
|
31
36
|
/**
|
|
32
37
|
* The history stack containing the states before an action was called.
|
|
33
38
|
*/
|
package/remap.js
CHANGED
|
@@ -84,6 +84,12 @@ const mapperImplementations = {
|
|
|
84
84
|
}
|
|
85
85
|
return result !== null && result !== void 0 ? result : null;
|
|
86
86
|
},
|
|
87
|
+
variable(name, input, context) {
|
|
88
|
+
if (context.getVariable) {
|
|
89
|
+
return context.getVariable(name);
|
|
90
|
+
}
|
|
91
|
+
return { variable: name };
|
|
92
|
+
},
|
|
87
93
|
equals(mappers, input, context) {
|
|
88
94
|
if (mappers.length <= 1) {
|
|
89
95
|
return true;
|
package/remap.test.js
CHANGED
|
@@ -3,9 +3,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
3
3
|
import { createExampleContext, examples } from './examples.js';
|
|
4
4
|
import { remap } from './remap.js';
|
|
5
5
|
function runTests(tests) {
|
|
6
|
-
it.each(Object.entries(tests))('should %s', (name, { context, expected, history, input, mappers, messages, userInfo }) => {
|
|
6
|
+
it.each(Object.entries(tests))('should %s', (name, { context, expected, history, input, mappers, messages, userInfo, variables }) => {
|
|
7
7
|
const result = remap(mappers, input, {
|
|
8
8
|
getMessage: ({ defaultMessage, id }) => { var _a, _b; return new IntlMessageFormat((_b = (_a = messages === null || messages === void 0 ? void 0 : messages.messageIds) === null || _a === void 0 ? void 0 : _a[id]) !== null && _b !== void 0 ? _b : defaultMessage); },
|
|
9
|
+
getVariable: (variableName) => { var _a; return (_a = variables.find((variable) => variable.name === variableName)) === null || _a === void 0 ? void 0 : _a.value; },
|
|
9
10
|
url: 'https://example.com/en/example',
|
|
10
11
|
appUrl: 'https://example.com',
|
|
11
12
|
userInfo,
|
|
@@ -120,6 +121,22 @@ describe('context', () => {
|
|
|
120
121
|
},
|
|
121
122
|
});
|
|
122
123
|
});
|
|
124
|
+
describe('variable', () => {
|
|
125
|
+
runTests({
|
|
126
|
+
'get a variable': {
|
|
127
|
+
input: {},
|
|
128
|
+
mappers: { variable: 'my-variable' },
|
|
129
|
+
expected: 'my-variable-value',
|
|
130
|
+
variables: [{ id: 0, name: 'my-variable', value: 'my-variable-value' }],
|
|
131
|
+
},
|
|
132
|
+
'get an undefined variable': {
|
|
133
|
+
input: {},
|
|
134
|
+
mappers: { variable: 'my-variable' },
|
|
135
|
+
expected: undefined,
|
|
136
|
+
variables: [],
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
});
|
|
123
140
|
describe('date.now', () => {
|
|
124
141
|
beforeEach(() => {
|
|
125
142
|
vi.useFakeTimers({ now: 0 });
|
|
@@ -210,7 +227,7 @@ describe('log', () => {
|
|
|
210
227
|
vi.spyOn(console, 'warn').mockImplementation(null);
|
|
211
228
|
});
|
|
212
229
|
function runLogTests(tests) {
|
|
213
|
-
it.each(Object.entries(tests))('should %s', (name, { context, expected: expectedInput, history, input, mappers, messages, userInfo }) => {
|
|
230
|
+
it.each(Object.entries(tests))('should %s', (name, { context, expected: expectedInput, history, input, mappers, messages, userInfo, variables, }) => {
|
|
214
231
|
const expected = JSON.stringify({
|
|
215
232
|
input: expectedInput,
|
|
216
233
|
context: {
|
|
@@ -228,6 +245,7 @@ describe('log', () => {
|
|
|
228
245
|
}, null, 2);
|
|
229
246
|
remap(mappers, input, {
|
|
230
247
|
getMessage: ({ defaultMessage, id }) => { var _a, _b; return new IntlMessageFormat((_b = (_a = messages === null || messages === void 0 ? void 0 : messages.messageIds) === null || _a === void 0 ? void 0 : _a[id]) !== null && _b !== void 0 ? _b : defaultMessage); },
|
|
248
|
+
getVariable: (variableName) => variables.find((variable) => variable.name === variableName).value,
|
|
231
249
|
url: 'https://example.com/en/example',
|
|
232
250
|
appUrl: 'https://example.com',
|
|
233
251
|
userInfo,
|