@appsemble/utils 0.27.10 → 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/$skip.d.ts +2 -0
- package/api/components/parameters/$skip.js +7 -0
- package/api/components/parameters/$top.js +1 -2
- package/api/components/parameters/appVariableId.d.ts +2 -0
- package/api/components/parameters/appVariableId.js +8 -0
- package/api/components/parameters/index.d.ts +2 -0
- package/api/components/parameters/index.js +2 -0
- package/api/components/schemas/App.js +1 -1
- package/api/components/schemas/AppVariable.d.ts +2 -0
- package/api/components/schemas/AppVariable.js +22 -0
- package/api/components/schemas/BlockDefinition.js +8 -2
- 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/assets.js +4 -1
- package/api/paths/index.js +2 -0
- package/api/paths/resources.js +1 -0
- package/api/paths/templates.js +8 -0
- package/constants/patterns.d.ts +4 -0
- package/constants/patterns.js +4 -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)
|
|
@@ -2,7 +2,6 @@ export const $top = {
|
|
|
2
2
|
name: '$top',
|
|
3
3
|
in: 'query',
|
|
4
4
|
description: 'Limit the number of entities returned.',
|
|
5
|
-
|
|
6
|
-
schema: { type: 'string' },
|
|
5
|
+
schema: { type: 'integer', minimum: 0 },
|
|
7
6
|
};
|
|
8
7
|
//# sourceMappingURL=$top.js.map
|
|
@@ -3,6 +3,7 @@ export * from './$orderby.js';
|
|
|
3
3
|
export * from './$select.js';
|
|
4
4
|
export * from './$team.js';
|
|
5
5
|
export * from './$top.js';
|
|
6
|
+
export * from './$skip.js';
|
|
6
7
|
export * from './appId.js';
|
|
7
8
|
export * from './appOAuth2SecretId.js';
|
|
8
9
|
export * from './appSamlSecretId.js';
|
|
@@ -17,6 +18,7 @@ export * from './resourceType.js';
|
|
|
17
18
|
export * from './screenshotId.js';
|
|
18
19
|
export * from './readmeId.js';
|
|
19
20
|
export * from './appServiceId.js';
|
|
21
|
+
export * from './appVariableId.js';
|
|
20
22
|
export * from './view.js';
|
|
21
23
|
export * from './trainingId.js';
|
|
22
24
|
export * from './trainingBlockId.js';
|
|
@@ -3,6 +3,7 @@ export * from './$orderby.js';
|
|
|
3
3
|
export * from './$select.js';
|
|
4
4
|
export * from './$team.js';
|
|
5
5
|
export * from './$top.js';
|
|
6
|
+
export * from './$skip.js';
|
|
6
7
|
export * from './appId.js';
|
|
7
8
|
export * from './appOAuth2SecretId.js';
|
|
8
9
|
export * from './appSamlSecretId.js';
|
|
@@ -17,6 +18,7 @@ export * from './resourceType.js';
|
|
|
17
18
|
export * from './screenshotId.js';
|
|
18
19
|
export * from './readmeId.js';
|
|
19
20
|
export * from './appServiceId.js';
|
|
21
|
+
export * from './appVariableId.js';
|
|
20
22
|
export * from './view.js';
|
|
21
23
|
export * from './trainingId.js';
|
|
22
24
|
export * from './trainingBlockId.js';
|
|
@@ -77,7 +77,7 @@ This doesn’t affect whether or not the app can be accessed on its own domain.
|
|
|
77
77
|
description: `
|
|
78
78
|
A long description for the app.
|
|
79
79
|
|
|
80
|
-
The long
|
|
80
|
+
The long description will be rendered on the app details page. Markdown content is supported.
|
|
81
81
|
`,
|
|
82
82
|
},
|
|
83
83
|
definition: { $ref: '#/components/schemas/AppDefinition' },
|
|
@@ -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
|
|
@@ -32,7 +32,13 @@ will remain the same until it is manually updated.
|
|
|
32
32
|
`,
|
|
33
33
|
},
|
|
34
34
|
layout: {
|
|
35
|
-
description:
|
|
35
|
+
description: `An override of the block’s default layout.
|
|
36
|
+
|
|
37
|
+
\`float\` sets the block position to float on the page and does not collide with other blocks.
|
|
38
|
+
Layout float can be combined with the \`position\` property to place the block on the desired location.
|
|
39
|
+
\`grow\` adds space between blocks so the page is filled.
|
|
40
|
+
\`static\` on the contrary, does not add extra space between blocks.
|
|
41
|
+
`,
|
|
36
42
|
enum: ['float', 'grow', 'static'],
|
|
37
43
|
},
|
|
38
44
|
header: {
|
|
@@ -50,7 +56,7 @@ If a user does not have the right role, the block is not rendered.
|
|
|
50
56
|
},
|
|
51
57
|
},
|
|
52
58
|
position: {
|
|
53
|
-
description: 'For floating blocks this
|
|
59
|
+
description: 'For floating blocks this property defines where the block should float.',
|
|
54
60
|
default: 'bottom right',
|
|
55
61
|
enum: [
|
|
56
62
|
'top left',
|
|
@@ -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/assets.js
CHANGED
|
@@ -66,7 +66,10 @@ export const paths = {
|
|
|
66
66
|
tags: ['asset'],
|
|
67
67
|
description: 'Get all of the app’s assets.',
|
|
68
68
|
operationId: 'getAssets',
|
|
69
|
-
parameters: [
|
|
69
|
+
parameters: [
|
|
70
|
+
{ $ref: '#/components/parameters/$skip' },
|
|
71
|
+
{ $ref: '#/components/parameters/$top' },
|
|
72
|
+
],
|
|
70
73
|
responses: {
|
|
71
74
|
200: {
|
|
72
75
|
description: 'The assets associated with the app.',
|
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/resources.js
CHANGED
|
@@ -87,6 +87,7 @@ export const paths = {
|
|
|
87
87
|
{ $ref: '#/components/parameters/$filter' },
|
|
88
88
|
{ $ref: '#/components/parameters/$orderby' },
|
|
89
89
|
{ $ref: '#/components/parameters/$select' },
|
|
90
|
+
{ $ref: '#/components/parameters/$skip' },
|
|
90
91
|
{ $ref: '#/components/parameters/$top' },
|
|
91
92
|
{ $ref: '#/components/parameters/$team' },
|
|
92
93
|
],
|
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/constants/patterns.d.ts
CHANGED
package/constants/patterns.js
CHANGED
|
@@ -35,4 +35,8 @@ export const uuid4Pattern = /^[\d[a-f]{8}-[\da-f]{4}-4[\da-f]{3}-[\da-f]{4}-[\d[
|
|
|
35
35
|
* A pattern which matches a JSON web token.
|
|
36
36
|
*/
|
|
37
37
|
export const jwtPattern = /^[\w-]+(?:\.[\w-]+){2}$/;
|
|
38
|
+
/**
|
|
39
|
+
* A pattern which matches an ISO 8601 datetime string.
|
|
40
|
+
*/
|
|
41
|
+
export const ISODateTimePattern = /\d{4}(.\d{2}){2}(\s|T)(\d{2}.){2}\d{2}/;
|
|
38
42
|
//# sourceMappingURL=patterns.js.map
|
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,
|