@appsemble/utils 0.20.44 → 0.21.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.
Files changed (55) hide show
  1. package/README.md +3 -3
  2. package/api/components/schemas/ActionDefinition.js +1 -0
  3. package/api/components/schemas/ObjectRemapperDefinition.js +6 -504
  4. package/api/components/schemas/RequestActionDefinition.js +1 -1
  5. package/api/components/schemas/ScimPatchOp.d.ts +2 -0
  6. package/api/components/schemas/ScimPatchOp.js +47 -0
  7. package/api/components/schemas/ScimSecret.d.ts +2 -0
  8. package/api/components/schemas/ScimSecret.js +16 -0
  9. package/api/components/schemas/ScimUser.d.ts +2 -0
  10. package/api/components/schemas/ScimUser.js +60 -0
  11. package/api/components/schemas/TeamMembersActionDefinition.d.ts +1 -0
  12. package/api/components/schemas/TeamMembersActionDefinition.js +18 -0
  13. package/api/components/schemas/index.d.ts +4 -0
  14. package/api/components/schemas/index.js +4 -0
  15. package/api/components/securitySchemes/index.d.ts +1 -0
  16. package/api/components/securitySchemes/index.js +1 -0
  17. package/api/components/securitySchemes/scim.d.ts +2 -0
  18. package/api/components/securitySchemes/scim.js +6 -0
  19. package/api/index.d.ts +18 -1
  20. package/api/index.js +8 -1
  21. package/api/index.test.js +1 -1
  22. package/api/paths/appScimEndpoints.d.ts +2 -0
  23. package/api/paths/appScimEndpoints.js +260 -0
  24. package/api/paths/appScimSecrets.d.ts +2 -0
  25. package/api/paths/appScimSecrets.js +45 -0
  26. package/api/paths/apps.js +18 -1
  27. package/api/paths/index.js +4 -0
  28. package/appMessages.test.js +1 -1
  29. package/iterApp.test.js +44 -48
  30. package/jsonschema.test.js +8 -8
  31. package/package.json +3 -3
  32. package/reference-schemas/remappers/arrays.d.ts +2 -0
  33. package/reference-schemas/remappers/arrays.js +334 -0
  34. package/reference-schemas/remappers/conditionals.d.ts +2 -0
  35. package/reference-schemas/remappers/conditionals.js +93 -0
  36. package/reference-schemas/remappers/data.d.ts +2 -0
  37. package/reference-schemas/remappers/data.js +321 -0
  38. package/reference-schemas/remappers/dates.d.ts +2 -0
  39. package/reference-schemas/remappers/dates.js +38 -0
  40. package/reference-schemas/remappers/history.d.ts +2 -0
  41. package/reference-schemas/remappers/history.js +246 -0
  42. package/reference-schemas/remappers/index.d.ts +9 -0
  43. package/reference-schemas/remappers/index.js +10 -0
  44. package/reference-schemas/remappers/objects.d.ts +2 -0
  45. package/reference-schemas/remappers/objects.js +157 -0
  46. package/reference-schemas/remappers/randoms.d.ts +2 -0
  47. package/reference-schemas/remappers/randoms.js +35 -0
  48. package/reference-schemas/remappers/strings.d.ts +2 -0
  49. package/reference-schemas/remappers/strings.js +81 -0
  50. package/reference-schemas/remappers/unsorted.d.ts +2 -0
  51. package/reference-schemas/remappers/unsorted.js +71 -0
  52. package/remap.js +1 -1
  53. package/remap.test.js +20 -16
  54. package/serverActions.js +5 -0
  55. package/vitest.config.d.ts +2 -0
@@ -0,0 +1,9 @@
1
+ export * from './arrays.js';
2
+ export * from './conditionals.js';
3
+ export * from './data.js';
4
+ export * from './dates.js';
5
+ export * from './history.js';
6
+ export * from './objects.js';
7
+ export * from './randoms.js';
8
+ export * from './strings.js';
9
+ export * from './unsorted.js';
@@ -0,0 +1,10 @@
1
+ export * from './arrays.js';
2
+ export * from './conditionals.js';
3
+ export * from './data.js';
4
+ export * from './dates.js';
5
+ export * from './history.js';
6
+ export * from './objects.js';
7
+ export * from './randoms.js';
8
+ export * from './strings.js';
9
+ export * from './unsorted.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import { type OpenAPIV3 } from 'openapi-types';
2
+ export declare const objectRemappers: Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;
@@ -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,2 @@
1
+ import { type OpenAPIV3 } from 'openapi-types';
2
+ export declare const randomRemappers: Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;
@@ -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,2 @@
1
+ import { type OpenAPIV3 } from 'openapi-types';
2
+ export declare const stringRemappers: Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;
@@ -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,2 @@
1
+ import { type OpenAPIV3 } from 'openapi-types';
2
+ export declare const unsortedRemappers: Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject>;
@@ -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
@@ -93,7 +93,7 @@ const mapperImplementations = {
93
93
  },
94
94
  not(mappers, input, context) {
95
95
  if (mappers.length <= 1) {
96
- return false;
96
+ return !remap(mappers[0], input, context);
97
97
  }
98
98
  const [firstValue, ...otherValues] = mappers.map((mapper) => remap(mapper, input, context));
99
99
  return !otherValues.some((value) => equal(firstValue, value));
package/remap.test.js CHANGED
@@ -119,7 +119,7 @@ describe('context', () => {
119
119
  });
120
120
  describe('date.now', () => {
121
121
  beforeEach(() => {
122
- import.meta.jest.useFakeTimers({ now: 0 });
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
- import.meta.jest.useFakeTimers({ now: 0 });
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
- import.meta.jest.spyOn(console, 'error').mockImplementation();
191
- import.meta.jest.spyOn(console, 'info').mockImplementation();
192
- import.meta.jest.spyOn(console, 'warn').mockImplementation();
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 }) => {
@@ -331,16 +331,21 @@ describe('not', () => {
331
331
  mappers: { not: [{ prop: '0' }, { prop: '1' }] },
332
332
  expected: true,
333
333
  },
334
- 'return false on empty arrays': {
335
- input: { empty: [] },
336
- mappers: { not: [] },
337
- expected: false,
334
+ 'return true if (computed) input is false': {
335
+ input: false,
336
+ mappers: { not: [{ root: null }] },
337
+ expected: true,
338
338
  },
339
- 'return false on arrays with 1 entry': {
340
- input: { empty: [] },
341
- mappers: { not: [{ prop: 'empty' }] },
339
+ 'return false if (computed) input is true': {
340
+ input: true,
341
+ mappers: { not: [{ root: null }] },
342
342
  expected: false,
343
343
  },
344
+ 'return true when mappers is empty': {
345
+ input: true,
346
+ mappers: { not: [] },
347
+ expected: true,
348
+ },
344
349
  });
345
350
  });
346
351
  describe('ics', () => {
@@ -865,7 +870,7 @@ describe('random.choice', () => {
865
870
  });
866
871
  describe('random.integer', () => {
867
872
  beforeEach(() => {
868
- import.meta.jest.spyOn(Math, 'random').mockReturnValue(0.5);
873
+ vi.spyOn(Math, 'random').mockReturnValue(0.5);
869
874
  });
870
875
  runTests({
871
876
  'return the input if the input is not an array': {
@@ -877,7 +882,7 @@ describe('random.integer', () => {
877
882
  });
878
883
  describe('random.float', () => {
879
884
  beforeEach(() => {
880
- import.meta.jest.spyOn(Math, 'random').mockReturnValue(0.5);
885
+ vi.spyOn(Math, 'random').mockReturnValue(0.5);
881
886
  });
882
887
  runTests({
883
888
  'return the input if the input is not an array': {
@@ -889,8 +894,7 @@ describe('random.float', () => {
889
894
  });
890
895
  describe('random.string', () => {
891
896
  beforeEach(() => {
892
- import.meta.jest
893
- .spyOn(Math, 'random')
897
+ vi.spyOn(Math, 'random')
894
898
  .mockReturnValueOnce(0)
895
899
  .mockReturnValueOnce(0.4)
896
900
  .mockReturnValueOnce(0.5)
package/serverActions.js CHANGED
@@ -7,7 +7,12 @@ export const serverActions = new Set([
7
7
  'log',
8
8
  'notify',
9
9
  'request',
10
+ 'resource.get',
10
11
  'resource.query',
12
+ 'resource.create',
13
+ 'resource.patch',
14
+ 'resource.update',
15
+ 'resource.delete',
11
16
  'static',
12
17
  ]);
13
18
  //# sourceMappingURL=serverActions.js.map
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vitest/dist/config.js").UserProjectConfigExport;
2
+ export default _default;