@appsemble/utils 0.20.45 → 0.21.1
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/schemas/ObjectRemapperDefinition.js +6 -504
- package/api/components/schemas/RequestActionDefinition.js +1 -1
- package/api/components/schemas/ScimPatchOp.d.ts +2 -0
- package/api/components/schemas/ScimPatchOp.js +47 -0
- package/api/components/schemas/ScimSecret.d.ts +2 -0
- package/api/components/schemas/ScimSecret.js +16 -0
- package/api/components/schemas/ScimUser.d.ts +2 -0
- package/api/components/schemas/ScimUser.js +60 -0
- package/api/components/schemas/index.d.ts +3 -0
- package/api/components/schemas/index.js +3 -0
- package/api/components/securitySchemes/index.d.ts +1 -0
- package/api/components/securitySchemes/index.js +1 -0
- package/api/components/securitySchemes/scim.d.ts +2 -0
- package/api/components/securitySchemes/scim.js +6 -0
- package/api/index.test.js +1 -1
- package/api/paths/appScimEndpoints.d.ts +2 -0
- package/api/paths/appScimEndpoints.js +260 -0
- package/api/paths/appScimSecrets.d.ts +2 -0
- package/api/paths/appScimSecrets.js +45 -0
- package/api/paths/index.js +4 -0
- package/appMessages.test.js +1 -1
- package/convertToCsv.js +1 -1
- package/iterApp.test.js +44 -48
- package/jsonschema.test.js +8 -8
- package/normalize.js +2 -2
- package/package.json +4 -4
- package/pem.js +3 -3
- package/reference-schemas/remappers/arrays.d.ts +2 -0
- package/reference-schemas/remappers/arrays.js +334 -0
- package/reference-schemas/remappers/conditionals.d.ts +2 -0
- package/reference-schemas/remappers/conditionals.js +93 -0
- package/reference-schemas/remappers/data.d.ts +2 -0
- package/reference-schemas/remappers/data.js +321 -0
- package/reference-schemas/remappers/dates.d.ts +2 -0
- package/reference-schemas/remappers/dates.js +38 -0
- package/reference-schemas/remappers/history.d.ts +2 -0
- package/reference-schemas/remappers/history.js +246 -0
- package/reference-schemas/remappers/index.d.ts +9 -0
- package/reference-schemas/remappers/index.js +10 -0
- package/reference-schemas/remappers/objects.d.ts +2 -0
- package/reference-schemas/remappers/objects.js +157 -0
- package/reference-schemas/remappers/randoms.d.ts +2 -0
- package/reference-schemas/remappers/randoms.js +35 -0
- package/reference-schemas/remappers/strings.d.ts +2 -0
- package/reference-schemas/remappers/strings.js +81 -0
- package/reference-schemas/remappers/unsorted.d.ts +2 -0
- package/reference-schemas/remappers/unsorted.js +71 -0
- package/remap.js +1 -1
- package/remap.test.js +8 -9
- package/string.js +2 -2
- package/vitest.config.d.ts +2 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export const objectRemappers = {
|
|
2
|
+
'object.assign': {
|
|
3
|
+
additionalProperties: {
|
|
4
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
5
|
+
},
|
|
6
|
+
description: `
|
|
7
|
+
|
|
8
|
+
Let’s say you have an existing object that you want to add an additional value on top of. For this
|
|
9
|
+
you can use the \`object.assign\` remapper. The remapper takes an existing object and allows the user
|
|
10
|
+
to assign their own value on top of that.
|
|
11
|
+
|
|
12
|
+
Input:
|
|
13
|
+
|
|
14
|
+
\`\`\`json
|
|
15
|
+
{
|
|
16
|
+
"title": "Weekly fishing 21"
|
|
17
|
+
}
|
|
18
|
+
\`\`\`
|
|
19
|
+
|
|
20
|
+
\`\`\`yaml
|
|
21
|
+
object.assign:
|
|
22
|
+
author: John Doe
|
|
23
|
+
\`\`\`
|
|
24
|
+
|
|
25
|
+
Result:
|
|
26
|
+
|
|
27
|
+
\`\`\`json
|
|
28
|
+
{
|
|
29
|
+
"title": "Weekly fishing 21",
|
|
30
|
+
"author": "John Doe"
|
|
31
|
+
}
|
|
32
|
+
\`\`\`
|
|
33
|
+
|
|
34
|
+
`,
|
|
35
|
+
},
|
|
36
|
+
'object.from': {
|
|
37
|
+
additionalProperties: {
|
|
38
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
39
|
+
},
|
|
40
|
+
description: `
|
|
41
|
+
|
|
42
|
+
With this remapper you can create an entirely new object based on input values and other remappers.
|
|
43
|
+
\`object.from\` itself accepts remapper functions as its input which allows you to chain multiple
|
|
44
|
+
remappers together to make complex objects.
|
|
45
|
+
|
|
46
|
+
As a base, the remapper looks like this:
|
|
47
|
+
|
|
48
|
+
\`\`\`yaml
|
|
49
|
+
object.from:
|
|
50
|
+
username: Chris Taub
|
|
51
|
+
email: example@hotmail.com
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
\`\`\`json
|
|
55
|
+
{
|
|
56
|
+
"username": "Chris Taub",
|
|
57
|
+
"email": "example@hotmail.com"
|
|
58
|
+
}
|
|
59
|
+
\`\`\`
|
|
60
|
+
|
|
61
|
+
Most of the time you won’t create an object just to store one value. Luckily, this is where the
|
|
62
|
+
chaining of remappers comes in. You can create an object that contains an \`object.from\` remapper
|
|
63
|
+
which then allows more inputs:
|
|
64
|
+
|
|
65
|
+
\`\`\`yaml
|
|
66
|
+
object.from:
|
|
67
|
+
username: Chris Taub
|
|
68
|
+
email: example@hotmail.com
|
|
69
|
+
addresses:
|
|
70
|
+
object.from:
|
|
71
|
+
work:
|
|
72
|
+
object.from:
|
|
73
|
+
city: Eindhoven
|
|
74
|
+
address: Nachtegaallaan 15
|
|
75
|
+
home:
|
|
76
|
+
object.from:
|
|
77
|
+
city: Amsterdam
|
|
78
|
+
address: Amstel 1
|
|
79
|
+
\`\`\`
|
|
80
|
+
|
|
81
|
+
\`\`\`json
|
|
82
|
+
{
|
|
83
|
+
"username": "Chris Taub",
|
|
84
|
+
"email": "example@hotmail.com",
|
|
85
|
+
"addresses": {
|
|
86
|
+
"work": {
|
|
87
|
+
"city": "Eindhoven",
|
|
88
|
+
"address": "Nachtegaallaan 15"
|
|
89
|
+
},
|
|
90
|
+
"home": {
|
|
91
|
+
"city": "Amsterdam",
|
|
92
|
+
"address": "Amstel 1"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
\`\`\`
|
|
97
|
+
|
|
98
|
+
`,
|
|
99
|
+
},
|
|
100
|
+
'object.omit': {
|
|
101
|
+
type: 'array',
|
|
102
|
+
items: {
|
|
103
|
+
minItems: 1,
|
|
104
|
+
anyOf: [
|
|
105
|
+
{ type: 'string' },
|
|
106
|
+
{
|
|
107
|
+
type: 'array',
|
|
108
|
+
minItems: 2,
|
|
109
|
+
items: {
|
|
110
|
+
type: 'string',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
description: `
|
|
116
|
+
|
|
117
|
+
In contrary to the previous remapper, what if you have an object from which you want to remove a
|
|
118
|
+
value? Then you can use \`object.omit\`. The remapper can remove properties from an existing object
|
|
119
|
+
based on the given object keys. This includes nested properties.
|
|
120
|
+
|
|
121
|
+
Input:
|
|
122
|
+
|
|
123
|
+
\`\`\`json
|
|
124
|
+
{
|
|
125
|
+
"title": "Weekly fishing 21",
|
|
126
|
+
"author": "John Doe",
|
|
127
|
+
"content": {
|
|
128
|
+
"introduction": "This is the introduction for the new weekly fishing issue",
|
|
129
|
+
"paragraph1": "...",
|
|
130
|
+
"interview": "..."
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
\`\`\`
|
|
134
|
+
|
|
135
|
+
\`\`\`yaml
|
|
136
|
+
object.omit:
|
|
137
|
+
- author
|
|
138
|
+
- - content
|
|
139
|
+
- interview
|
|
140
|
+
\`\`\`
|
|
141
|
+
|
|
142
|
+
Result:
|
|
143
|
+
|
|
144
|
+
\`\`\`json
|
|
145
|
+
{
|
|
146
|
+
"title": "Weekly fishing 21",
|
|
147
|
+
"content": {
|
|
148
|
+
"introduction": "This is the introduction for the new weekly fishing issue",
|
|
149
|
+
"paragraph1": "..."
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
\`\`\`
|
|
153
|
+
|
|
154
|
+
`,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=objects.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const randomRemappers = {
|
|
2
|
+
'random.choice': {
|
|
3
|
+
enum: [null],
|
|
4
|
+
description: 'Pick and return a random entry from an array. If the input is not an array, the input is returned as-is.',
|
|
5
|
+
},
|
|
6
|
+
'random.integer': {
|
|
7
|
+
type: 'array',
|
|
8
|
+
maxItems: 2,
|
|
9
|
+
minItems: 2,
|
|
10
|
+
items: {
|
|
11
|
+
type: 'integer',
|
|
12
|
+
},
|
|
13
|
+
description: 'Pick and return a random integer between the provided lowest and highest values.',
|
|
14
|
+
},
|
|
15
|
+
'random.float': {
|
|
16
|
+
type: 'array',
|
|
17
|
+
maxItems: 2,
|
|
18
|
+
minItems: 2,
|
|
19
|
+
items: {
|
|
20
|
+
type: 'number',
|
|
21
|
+
},
|
|
22
|
+
description: 'Pick and return a random number between the provided lowest and highest values.',
|
|
23
|
+
},
|
|
24
|
+
'random.string': {
|
|
25
|
+
type: 'object',
|
|
26
|
+
required: ['choice', 'length'],
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
properties: {
|
|
29
|
+
choice: { type: 'string', minLength: 1 },
|
|
30
|
+
length: { type: 'integer', minimum: 1 },
|
|
31
|
+
},
|
|
32
|
+
description: 'Pick and return a random string from a given length using characters from a given input string.',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=randoms.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const stringRemappers = {
|
|
2
|
+
'string.case': {
|
|
3
|
+
enum: ['lower', 'upper'],
|
|
4
|
+
description: `Convert a string to upper or lower case.
|
|
5
|
+
\`\`\`yaml
|
|
6
|
+
string.case: upper
|
|
7
|
+
\`\`\`
|
|
8
|
+
|
|
9
|
+
Result:
|
|
10
|
+
|
|
11
|
+
\`\`\`json
|
|
12
|
+
"PATRICK"
|
|
13
|
+
\`\`\`
|
|
14
|
+
|
|
15
|
+
`,
|
|
16
|
+
},
|
|
17
|
+
'string.format': {
|
|
18
|
+
type: 'object',
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
properties: {
|
|
21
|
+
messageId: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'The message id pointing to the template string to format.',
|
|
24
|
+
},
|
|
25
|
+
template: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'The template default string to format.',
|
|
28
|
+
},
|
|
29
|
+
values: {
|
|
30
|
+
description: 'A set of remappers to convert the input to usable values.',
|
|
31
|
+
additionalProperties: {
|
|
32
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
description: `Format a string using remapped input variables.
|
|
37
|
+
Useful for replacing static text with generated values.
|
|
38
|
+
|
|
39
|
+
\`\`\`yaml
|
|
40
|
+
string.format:
|
|
41
|
+
template: 'You have won €{lotteryAmount} in the lottery!!'
|
|
42
|
+
values:
|
|
43
|
+
lotteryAmount: { prop: lotteryPrize }
|
|
44
|
+
\`\`\`
|
|
45
|
+
|
|
46
|
+
Result:
|
|
47
|
+
|
|
48
|
+
\`\`\`json
|
|
49
|
+
"You have won €5000 in the lottery!!"
|
|
50
|
+
\`\`\`
|
|
51
|
+
|
|
52
|
+
> **Tip:** Considering this can be inserted anywhere a remapper is accepted. You can also use this
|
|
53
|
+
> to choose specific URL’s more accurately.
|
|
54
|
+
|
|
55
|
+
`,
|
|
56
|
+
},
|
|
57
|
+
'string.replace': {
|
|
58
|
+
type: 'object',
|
|
59
|
+
minProperties: 1,
|
|
60
|
+
maxProperties: 1,
|
|
61
|
+
additionalProperties: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
},
|
|
64
|
+
description: `
|
|
65
|
+
Uses RegEx to find a value in a string and replace it with a given value.
|
|
66
|
+
|
|
67
|
+
\`\`\`yaml
|
|
68
|
+
# Input: Eindhoven is the best city in the Netherlands
|
|
69
|
+
string.replace:
|
|
70
|
+
(beszt*)\\w+: cleanest
|
|
71
|
+
\`\`\`
|
|
72
|
+
|
|
73
|
+
Result:
|
|
74
|
+
|
|
75
|
+
\`\`\`json
|
|
76
|
+
"Eindhoven is the cleanest city in the Netherlands"
|
|
77
|
+
\`\`\`
|
|
78
|
+
`,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=strings.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const unsortedRemappers = {
|
|
2
|
+
ics: {
|
|
3
|
+
type: 'object',
|
|
4
|
+
description: 'Create a calendar event',
|
|
5
|
+
additionalProperties: false,
|
|
6
|
+
required: ['start', 'title'],
|
|
7
|
+
properties: {
|
|
8
|
+
start: {
|
|
9
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
10
|
+
description: 'The start of the icalendar event.',
|
|
11
|
+
},
|
|
12
|
+
end: {
|
|
13
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
14
|
+
description: 'The end of the icalendar event.',
|
|
15
|
+
},
|
|
16
|
+
duration: {
|
|
17
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
18
|
+
description: 'The duration of the event.',
|
|
19
|
+
example: '1w 3d 10h 30m',
|
|
20
|
+
},
|
|
21
|
+
title: {
|
|
22
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
23
|
+
description: 'The title of the event.',
|
|
24
|
+
},
|
|
25
|
+
description: {
|
|
26
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
27
|
+
description: 'An optional description of the event.',
|
|
28
|
+
},
|
|
29
|
+
url: {
|
|
30
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
31
|
+
description: 'An optional link to attach to the event.',
|
|
32
|
+
},
|
|
33
|
+
location: {
|
|
34
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
35
|
+
description: 'An optional location description to attach to the event.',
|
|
36
|
+
},
|
|
37
|
+
coordinates: {
|
|
38
|
+
$ref: '#/components/schemas/RemapperDefinition',
|
|
39
|
+
description: `An optional geolocation description to attach to the event.
|
|
40
|
+
|
|
41
|
+
This must be an object with the properties \`lat\` or \`latitude\`, and \`lon\`, \`lng\` or \`longitude\`.`,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
'null.strip': {
|
|
46
|
+
description: 'Strip all null, undefined, and empty array values from an object.',
|
|
47
|
+
anyOf: [
|
|
48
|
+
{ enum: [null] },
|
|
49
|
+
{
|
|
50
|
+
type: 'object',
|
|
51
|
+
required: ['depth'],
|
|
52
|
+
additionalProperties: false,
|
|
53
|
+
description: 'Options for the null.strip remapper.',
|
|
54
|
+
properties: {
|
|
55
|
+
depth: {
|
|
56
|
+
type: 'integer',
|
|
57
|
+
minimum: 1,
|
|
58
|
+
description: 'How deep to recurse into objects and arrays to remove null values.',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
log: {
|
|
65
|
+
enum: ['info', 'warn', 'error'],
|
|
66
|
+
description: `Logs its input data (returns it) and its context.
|
|
67
|
+
|
|
68
|
+
The value to set is the log level.`,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=unsorted.js.map
|
package/remap.js
CHANGED
|
@@ -324,7 +324,7 @@ const mapperImplementations = {
|
|
|
324
324
|
},
|
|
325
325
|
'string.replace'(values, input) {
|
|
326
326
|
const [[regex, replacer]] = Object.entries(values);
|
|
327
|
-
return String(input).
|
|
327
|
+
return String(input).replaceAll(new RegExp(regex, 'gm'), replacer);
|
|
328
328
|
},
|
|
329
329
|
translate(messageId, input, context) {
|
|
330
330
|
const message = context.getMessage({ id: messageId });
|
package/remap.test.js
CHANGED
|
@@ -119,7 +119,7 @@ describe('context', () => {
|
|
|
119
119
|
});
|
|
120
120
|
describe('date.now', () => {
|
|
121
121
|
beforeEach(() => {
|
|
122
|
-
|
|
122
|
+
vi.useFakeTimers({ now: 0 });
|
|
123
123
|
});
|
|
124
124
|
runTests({
|
|
125
125
|
'return the current date': {
|
|
@@ -131,7 +131,7 @@ describe('date.now', () => {
|
|
|
131
131
|
});
|
|
132
132
|
describe('date.add', () => {
|
|
133
133
|
beforeEach(() => {
|
|
134
|
-
|
|
134
|
+
vi.useFakeTimers({ now: 0 });
|
|
135
135
|
});
|
|
136
136
|
runTests({
|
|
137
137
|
'add 3 days to the given date': {
|
|
@@ -187,9 +187,9 @@ describe('date.format', () => {
|
|
|
187
187
|
});
|
|
188
188
|
describe('log', () => {
|
|
189
189
|
beforeEach(() => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
vi.spyOn(console, 'error').mockImplementation(null);
|
|
191
|
+
vi.spyOn(console, 'info').mockImplementation(null);
|
|
192
|
+
vi.spyOn(console, 'warn').mockImplementation(null);
|
|
193
193
|
});
|
|
194
194
|
function runLogTests(tests) {
|
|
195
195
|
it.each(Object.entries(tests))('should %s', (name, { context, expected: expectedInput, history, input, mappers, messages, userInfo }) => {
|
|
@@ -870,7 +870,7 @@ describe('random.choice', () => {
|
|
|
870
870
|
});
|
|
871
871
|
describe('random.integer', () => {
|
|
872
872
|
beforeEach(() => {
|
|
873
|
-
|
|
873
|
+
vi.spyOn(Math, 'random').mockReturnValue(0.5);
|
|
874
874
|
});
|
|
875
875
|
runTests({
|
|
876
876
|
'return the input if the input is not an array': {
|
|
@@ -882,7 +882,7 @@ describe('random.integer', () => {
|
|
|
882
882
|
});
|
|
883
883
|
describe('random.float', () => {
|
|
884
884
|
beforeEach(() => {
|
|
885
|
-
|
|
885
|
+
vi.spyOn(Math, 'random').mockReturnValue(0.5);
|
|
886
886
|
});
|
|
887
887
|
runTests({
|
|
888
888
|
'return the input if the input is not an array': {
|
|
@@ -894,8 +894,7 @@ describe('random.float', () => {
|
|
|
894
894
|
});
|
|
895
895
|
describe('random.string', () => {
|
|
896
896
|
beforeEach(() => {
|
|
897
|
-
|
|
898
|
-
.spyOn(Math, 'random')
|
|
897
|
+
vi.spyOn(Math, 'random')
|
|
899
898
|
.mockReturnValueOnce(0)
|
|
900
899
|
.mockReturnValueOnce(0.4)
|
|
901
900
|
.mockReturnValueOnce(0.5)
|
package/string.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @returns The input, but hyphenated.
|
|
6
6
|
*/
|
|
7
7
|
export function camelToHyphen(string) {
|
|
8
|
-
return string.
|
|
8
|
+
return string.replaceAll(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Convert a string to upper case.
|
|
@@ -25,6 +25,6 @@ export function toUpperCase(input) {
|
|
|
25
25
|
* @returns The escaped JSON pointer segment.
|
|
26
26
|
*/
|
|
27
27
|
export function decodeJSONRef(ref) {
|
|
28
|
-
return decodeURIComponent(ref).
|
|
28
|
+
return decodeURIComponent(ref).replaceAll('~1', '/').replaceAll('~0', '~');
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=string.js.map
|