@appsemble/utils 0.20.41 → 0.20.43

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 (156) hide show
  1. package/LICENSE.md +126 -0
  2. package/README.md +9 -3
  3. package/api/components/index.d.ts +1 -1
  4. package/api/components/parameters/$filter.d.ts +1 -1
  5. package/api/components/parameters/$orderby.d.ts +1 -1
  6. package/api/components/parameters/$select.d.ts +1 -1
  7. package/api/components/parameters/$team.d.ts +1 -1
  8. package/api/components/parameters/$top.d.ts +1 -1
  9. package/api/components/parameters/appId.d.ts +1 -1
  10. package/api/components/parameters/appOAuth2SecretId.d.ts +1 -1
  11. package/api/components/parameters/appSamlSecretId.d.ts +1 -1
  12. package/api/components/parameters/appServiceId.d.ts +2 -0
  13. package/api/components/parameters/appServiceId.js +8 -0
  14. package/api/components/parameters/assetId.d.ts +1 -1
  15. package/api/components/parameters/blockId.d.ts +1 -1
  16. package/api/components/parameters/blockVersion.d.ts +1 -1
  17. package/api/components/parameters/endpoint.d.ts +1 -1
  18. package/api/components/parameters/index.d.ts +1 -0
  19. package/api/components/parameters/index.js +1 -0
  20. package/api/components/parameters/language.d.ts +1 -1
  21. package/api/components/parameters/organizationId.d.ts +1 -1
  22. package/api/components/parameters/resourceId.d.ts +1 -1
  23. package/api/components/parameters/resourceType.d.ts +1 -1
  24. package/api/components/parameters/screenshotId.d.ts +1 -1
  25. package/api/components/parameters/view.d.ts +1 -1
  26. package/api/components/requestBodies/oauth2Consent.d.ts +1 -1
  27. package/api/components/requestBodies/resource.d.ts +1 -1
  28. package/api/components/requestBodies/user.d.ts +1 -1
  29. package/api/components/responses/app.d.ts +1 -1
  30. package/api/components/responses/blockVersion.d.ts +1 -1
  31. package/api/components/responses/invite.d.ts +1 -1
  32. package/api/components/responses/oauth2AuthorizationCode.d.ts +1 -1
  33. package/api/components/responses/organization.d.ts +1 -1
  34. package/api/components/responses/resource.d.ts +1 -1
  35. package/api/components/responses/subscriptions.d.ts +1 -1
  36. package/api/components/schemas/ActionDefinition.d.ts +1 -1
  37. package/api/components/schemas/App.d.ts +1 -1
  38. package/api/components/schemas/AppAccount.d.ts +1 -1
  39. package/api/components/schemas/AppDefinition.d.ts +1 -1
  40. package/api/components/schemas/AppLayoutDefinition.d.ts +1 -1
  41. package/api/components/schemas/AppMessages.d.ts +1 -1
  42. package/api/components/schemas/AppOAuth2Secret.d.ts +1 -1
  43. package/api/components/schemas/AppServiceSecret.d.ts +2 -0
  44. package/api/components/schemas/AppServiceSecret.js +45 -0
  45. package/api/components/schemas/AppsembleMessages.d.ts +1 -1
  46. package/api/components/schemas/ArrayRemapperDefinition.d.ts +1 -1
  47. package/api/components/schemas/Asset.d.ts +1 -1
  48. package/api/components/schemas/BaseActionDefinition.d.ts +1 -1
  49. package/api/components/schemas/BaseJSONSchema.d.ts +1 -1
  50. package/api/components/schemas/BasePageDefinition.d.ts +1 -1
  51. package/api/components/schemas/BlockDefinition.d.ts +1 -1
  52. package/api/components/schemas/BlockVersion.d.ts +1 -1
  53. package/api/components/schemas/CronDefinition.d.ts +1 -1
  54. package/api/components/schemas/CustomFontDefinition.d.ts +1 -1
  55. package/api/components/schemas/Error.d.ts +1 -1
  56. package/api/components/schemas/EventsDefinition.d.ts +1 -1
  57. package/api/components/schemas/FlowPageActionsDefinition.d.ts +1 -1
  58. package/api/components/schemas/GoogleFontDefinition.d.ts +1 -1
  59. package/api/components/schemas/Health.d.ts +1 -1
  60. package/api/components/schemas/JSONSchema.d.ts +1 -1
  61. package/api/components/schemas/LoopPageActionsDefinition.d.ts +1 -1
  62. package/api/components/schemas/Member.d.ts +1 -1
  63. package/api/components/schemas/NotificationHookDataDefinition.d.ts +1 -1
  64. package/api/components/schemas/NotificationHookDefinition.d.ts +1 -1
  65. package/api/components/schemas/OAuth2AuthorizationCode.d.ts +1 -1
  66. package/api/components/schemas/OAuth2ClientCredentials.d.ts +1 -1
  67. package/api/components/schemas/ObjectRemapperDefinition.d.ts +1 -1
  68. package/api/components/schemas/ObjectRemapperDefinition.js +42 -1
  69. package/api/components/schemas/Organization.d.ts +1 -1
  70. package/api/components/schemas/Rating.d.ts +1 -1
  71. package/api/components/schemas/RemapperDefinition.d.ts +1 -1
  72. package/api/components/schemas/Resource.d.ts +1 -1
  73. package/api/components/schemas/ResourceDefinition.d.ts +1 -1
  74. package/api/components/schemas/ResourceHistoryDefinition.d.ts +1 -1
  75. package/api/components/schemas/ResourceHooksDefinition.d.ts +1 -1
  76. package/api/components/schemas/ResourceSubscription.d.ts +1 -1
  77. package/api/components/schemas/ResourceViewDefinition.d.ts +1 -1
  78. package/api/components/schemas/SSLSecret.d.ts +1 -1
  79. package/api/components/schemas/SSOConfiguration.d.ts +1 -1
  80. package/api/components/schemas/SecurityDefaultDefinition.d.ts +1 -1
  81. package/api/components/schemas/SecurityDefaultDefinition.js +7 -0
  82. package/api/components/schemas/SecurityDefinition.d.ts +1 -1
  83. package/api/components/schemas/SecurityRoleDefinition.d.ts +1 -1
  84. package/api/components/schemas/SubPage.d.ts +1 -1
  85. package/api/components/schemas/TeamsDefinition.d.ts +1 -1
  86. package/api/components/schemas/Theme.d.ts +1 -1
  87. package/api/components/schemas/User.d.ts +1 -1
  88. package/api/components/schemas/UserEmail.d.ts +1 -1
  89. package/api/components/schemas/index.d.ts +1 -0
  90. package/api/components/schemas/index.js +1 -0
  91. package/api/components/schemas/utils.d.ts +1 -1
  92. package/api/components/securitySchemes/app.d.ts +1 -1
  93. package/api/components/securitySchemes/basic.d.ts +1 -1
  94. package/api/components/securitySchemes/cli.d.ts +1 -1
  95. package/api/components/securitySchemes/cli.test.js +1 -1
  96. package/api/components/securitySchemes/studio.d.ts +1 -1
  97. package/api/index.d.ts +1 -1
  98. package/api/paths/action.d.ts +1 -1
  99. package/api/paths/appMessages.d.ts +1 -1
  100. package/api/paths/appOAuth2Secrets.d.ts +1 -1
  101. package/api/paths/appSSLSecrets.d.ts +1 -1
  102. package/api/paths/appSamlSecrets.d.ts +1 -1
  103. package/api/paths/appServiceSecrets.d.ts +2 -0
  104. package/api/paths/appServiceSecrets.js +84 -0
  105. package/api/paths/apps.d.ts +1 -1
  106. package/api/paths/appsembleMessages.d.ts +1 -1
  107. package/api/paths/assets.d.ts +1 -1
  108. package/api/paths/blocks.d.ts +1 -1
  109. package/api/paths/emails.d.ts +1 -1
  110. package/api/paths/health.d.ts +1 -1
  111. package/api/paths/index.js +2 -0
  112. package/api/paths/invite.d.ts +1 -1
  113. package/api/paths/oauth2ClientCredentials.d.ts +1 -1
  114. package/api/paths/oauth2Login.d.ts +1 -1
  115. package/api/paths/oauth2Provider.d.ts +1 -1
  116. package/api/paths/organizations.d.ts +1 -1
  117. package/api/paths/resourceHistory.d.ts +1 -1
  118. package/api/paths/resources.d.ts +1 -1
  119. package/api/paths/saml.d.ts +1 -1
  120. package/api/paths/templates.d.ts +1 -1
  121. package/api/paths/user.d.ts +1 -1
  122. package/api/tags/app.d.ts +1 -1
  123. package/api/tags/appMember.d.ts +1 -1
  124. package/api/tags/asset.d.ts +1 -1
  125. package/api/tags/auth.d.ts +1 -1
  126. package/api/tags/language.d.ts +1 -1
  127. package/api/tags/organization.d.ts +1 -1
  128. package/api/tags/resource.d.ts +1 -1
  129. package/api/tags/template.d.ts +1 -1
  130. package/api/tags/user.d.ts +1 -1
  131. package/appMessages.d.ts +3 -3
  132. package/appMessages.js +1 -1
  133. package/appSecurity.d.ts +1 -1
  134. package/blockUtils.d.ts +1 -1
  135. package/checkAppRole.d.ts +1 -1
  136. package/constants/baseTheme.d.ts +1 -1
  137. package/formatRequestAction.d.ts +2 -2
  138. package/ics.d.ts +1 -1
  139. package/index.d.ts +0 -1
  140. package/index.js +0 -1
  141. package/iterApp.d.ts +1 -1
  142. package/jsonschema.d.ts +2 -2
  143. package/langmap.d.ts +1 -1
  144. package/normalize.d.ts +1 -1
  145. package/normalize.js +1 -1
  146. package/package.json +2 -2
  147. package/remap.d.ts +2 -2
  148. package/remap.js +15 -0
  149. package/remap.test.js +127 -1
  150. package/serverActions.d.ts +1 -0
  151. package/serverActions.js +13 -0
  152. package/theme.d.ts +1 -1
  153. package/validation.d.ts +5 -5
  154. package/validation.js +6 -1
  155. package/intl-messageformat.d.ts +0 -3
  156. package/intl-messageformat.js +0 -5
package/remap.js CHANGED
@@ -91,6 +91,13 @@ const mapperImplementations = {
91
91
  const values = mappers.map((mapper) => remap(mapper, input, context));
92
92
  return values.every((value) => equal(values[0], value));
93
93
  },
94
+ not(mappers, input, context) {
95
+ if (mappers.length <= 1) {
96
+ return false;
97
+ }
98
+ const [firstValue, ...otherValues] = mappers.map((mapper) => remap(mapper, input, context));
99
+ return !otherValues.some((value) => equal(firstValue, value));
100
+ },
94
101
  step(mapper, input, context) {
95
102
  return context.stepRef.current[mapper];
96
103
  },
@@ -149,6 +156,10 @@ const mapperImplementations = {
149
156
  const condition = remap(mappers.condition, input, context);
150
157
  return remap(condition ? mappers.then : mappers.else, input, context);
151
158
  },
159
+ match(mappers, input, context) {
160
+ var _a, _b;
161
+ return ((_b = remap((_a = mappers.find((mapper) => remap(mapper.case, input, context))) === null || _a === void 0 ? void 0 : _a.value, input, context)) !== null && _b !== void 0 ? _b : null);
162
+ },
152
163
  'object.from': (mappers, input, context) => mapValues(mappers, (mapper) => remap(mapper, input, context)),
153
164
  'object.assign': (mappers, input, context) => ({
154
165
  ...input,
@@ -295,6 +306,10 @@ const mapperImplementations = {
295
306
  }
296
307
  return input;
297
308
  },
309
+ log(level, input, context) {
310
+ console[level !== null && level !== void 0 ? level : 'info'](JSON.stringify({ input, context }, null, 2));
311
+ return input;
312
+ },
298
313
  'string.format'({ messageId, template, values }, input, context) {
299
314
  try {
300
315
  const message = context.getMessage({ id: messageId, defaultMessage: template });
package/remap.test.js CHANGED
@@ -1,4 +1,4 @@
1
- import { IntlMessageFormat } from './intl-messageformat.js';
1
+ import { IntlMessageFormat } from 'intl-messageformat';
2
2
  import { remap } from './remap.js';
3
3
  function runTests(tests) {
4
4
  it.each(Object.entries(tests))('should %s', (name, { context, expected, history, input, mappers, messages, userInfo }) => {
@@ -185,6 +185,68 @@ describe('date.format', () => {
185
185
  },
186
186
  });
187
187
  });
188
+ describe('log', () => {
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();
193
+ });
194
+ function runLogTests(tests) {
195
+ it.each(Object.entries(tests))('should %s', (name, { context, expected: expectedInput, history, input, mappers, messages, userInfo }) => {
196
+ const expected = JSON.stringify({
197
+ input: expectedInput,
198
+ context: {
199
+ root: {
200
+ message: 'hi mom!',
201
+ },
202
+ url: 'https://example.com/en/example',
203
+ appUrl: 'https://example.com',
204
+ appId: 6789,
205
+ locale: 'en',
206
+ pageData: {
207
+ hello: 'Page data',
208
+ },
209
+ },
210
+ }, null, 2);
211
+ remap(mappers, input, {
212
+ 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); },
213
+ url: 'https://example.com/en/example',
214
+ appUrl: 'https://example.com',
215
+ userInfo,
216
+ context,
217
+ history,
218
+ appId: 6789,
219
+ locale: 'en',
220
+ pageData: { hello: 'Page data' },
221
+ });
222
+ expect(console[mappers.log]).toHaveBeenCalledWith(expected);
223
+ });
224
+ }
225
+ runLogTests({
226
+ 'log `hi mom!` with log level `info`': {
227
+ input: { message: 'hi mom!' },
228
+ mappers: { log: 'info' },
229
+ expected: { message: 'hi mom!' },
230
+ },
231
+ 'log `hi mom!` with log level `warn`': {
232
+ input: { message: 'hi mom!' },
233
+ mappers: { log: 'warn' },
234
+ expected: { message: 'hi mom!' },
235
+ },
236
+ 'log `hi mom!` with log level `error`': {
237
+ input: { message: 'hi mom!' },
238
+ mappers: { log: 'error' },
239
+ expected: { message: 'hi mom!' },
240
+ },
241
+ });
242
+ runTests({
243
+ 'return input': {
244
+ input: 'input',
245
+ mappers: { log: 'info' },
246
+ expected: 'input',
247
+ },
248
+ });
249
+ });
188
250
  describe('le', () => {
189
251
  runTests({
190
252
  'return true if the left value is less than the right value': {
@@ -252,6 +314,35 @@ describe('equals', () => {
252
314
  },
253
315
  });
254
316
  });
317
+ describe('not', () => {
318
+ runTests({
319
+ 'return false if any of the values are equal to the first': {
320
+ input: [1, 2, 1],
321
+ mappers: { not: [{ prop: '0' }, { prop: '1' }, { prop: '2' }] },
322
+ expected: false,
323
+ },
324
+ 'use deep equality': {
325
+ input: [{ foo: { bar: 3 } }, { foo: { bar: 3 } }],
326
+ mappers: { not: [{ prop: '0' }, { prop: '1' }] },
327
+ expected: false,
328
+ },
329
+ 'return true if all values are not equal to the first': {
330
+ input: [{ foo: { bar: 3 } }, { foo: { bar: 2 } }, { foo: { bar: 2 } }],
331
+ mappers: { not: [{ prop: '0' }, { prop: '1' }] },
332
+ expected: true,
333
+ },
334
+ 'return false on empty arrays': {
335
+ input: { empty: [] },
336
+ mappers: { not: [] },
337
+ expected: false,
338
+ },
339
+ 'return false on arrays with 1 entry': {
340
+ input: { empty: [] },
341
+ mappers: { not: [{ prop: 'empty' }] },
342
+ expected: false,
343
+ },
344
+ });
345
+ });
255
346
  describe('ics', () => {
256
347
  runTests({
257
348
  'support string date': {
@@ -463,6 +554,41 @@ describe('if', () => {
463
554
  },
464
555
  });
465
556
  });
557
+ describe('match', () => {
558
+ runTests({
559
+ 'return the value of the first case if case is truthy': {
560
+ input: {},
561
+ mappers: {
562
+ match: [
563
+ { case: true, value: 'case 1' },
564
+ { case: true, value: 'case 2' },
565
+ { case: true, value: 'case 3' },
566
+ ],
567
+ },
568
+ expected: 'case 1',
569
+ },
570
+ });
571
+ runTests({
572
+ 'return the value of the second case if case 1 is falsy and 2 is truthy': {
573
+ input: {},
574
+ mappers: {
575
+ match: [
576
+ { case: false, value: 'case 1' },
577
+ { case: true, value: 'case 2' },
578
+ { case: false, value: 'case 3' },
579
+ ],
580
+ },
581
+ expected: 'case 2',
582
+ },
583
+ });
584
+ runTests({
585
+ 'return null if all cases are falsy': {
586
+ input: {},
587
+ mappers: { match: [{ case: false, value: 'case 1' }] },
588
+ expected: null,
589
+ },
590
+ });
591
+ });
466
592
  describe('object.from', () => {
467
593
  runTests({
468
594
  'create a new object from remappers': {
@@ -0,0 +1 @@
1
+ export declare const serverActions: Set<string>;
@@ -0,0 +1,13 @@
1
+ export const serverActions = new Set([
2
+ 'noop',
3
+ 'throw',
4
+ 'condition',
5
+ 'each',
6
+ 'email',
7
+ 'log',
8
+ 'notify',
9
+ 'request',
10
+ 'resource.query',
11
+ 'static',
12
+ ]);
13
+ //# sourceMappingURL=serverActions.js.map
package/theme.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Theme } from '@appsemble/types';
1
+ import { type Theme } from '@appsemble/types';
2
2
  /**
3
3
  * Merge multiple partial themes and the base theme into one resulting theme.
4
4
  *
package/validation.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { AppDefinition, BlockManifest } from '@appsemble/types';
2
- import { ValidatorResult } from 'jsonschema';
3
- import { Promisable } from 'type-fest';
4
- import { IdentifiableBlock } from './blockUtils.js';
1
+ import { type AppDefinition, type BlockManifest } from '@appsemble/types';
2
+ import { type ValidatorResult } from 'jsonschema';
3
+ import { type Promisable } from 'type-fest';
4
+ import { type IdentifiableBlock } from './blockUtils.js';
5
5
  /**
6
6
  * Check whether or not the given link represents a link related to the Appsemble core.
7
7
  *
@@ -18,7 +18,7 @@ export type BlockVersionsGetter = (blockMap: IdentifiableBlock[]) => Promisable<
18
18
  * @param definition The app validation to check.
19
19
  * @param getBlockVersions A function for getting block manifests from block versions.
20
20
  * @param validatorResult If specified, error messages will be applied to this existing validator
21
- * result.
21
+ * result.
22
22
  * @returns A validator result which contains all app validation violations.
23
23
  */
24
24
  export declare function validateAppDefinition(definition: AppDefinition, getBlockVersions: BlockVersionsGetter, validatorResult?: ValidatorResult): Promise<ValidatorResult>;
package/validation.js CHANGED
@@ -5,6 +5,7 @@ import { getAppBlocks, normalizeBlockName } from './blockUtils.js';
5
5
  import { has } from './has.js';
6
6
  import { partialNormalized } from './index.js';
7
7
  import { iterApp } from './iterApp.js';
8
+ import { serverActions } from './serverActions.js';
8
9
  /**
9
10
  * Check whether or not the given link represents a link related to the Appsemble core.
10
11
  *
@@ -381,6 +382,10 @@ function validateActions(definition, report) {
381
382
  iterApp(definition, {
382
383
  onAction(action, path) {
383
384
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
385
+ if (path[0] === 'cron' && !serverActions.has(action.type)) {
386
+ report(action.type, 'action type is not supported for cron jobs', [...path, 'type']);
387
+ return;
388
+ }
384
389
  if (action.type.startsWith('user.') && !definition.security) {
385
390
  report(action.type, 'refers to a user action but the app doesn’t have a security definition', [...path, 'type']);
386
391
  return;
@@ -587,7 +592,7 @@ function validateEvents(definition, blockVersions, report) {
587
592
  * @param definition The app validation to check.
588
593
  * @param getBlockVersions A function for getting block manifests from block versions.
589
594
  * @param validatorResult If specified, error messages will be applied to this existing validator
590
- * result.
595
+ * result.
591
596
  * @returns A validator result which contains all app validation violations.
592
597
  */
593
598
  export async function validateAppDefinition(definition, getBlockVersions, validatorResult) {
@@ -1,3 +0,0 @@
1
- import intl from 'intl-messageformat';
2
- export type IntlMessageFormat = intl;
3
- export declare const IntlMessageFormat: typeof intl;
@@ -1,5 +0,0 @@
1
- import intl from 'intl-messageformat';
2
- // @ts-expect-error Remove if the intl-message format types are fixed upstream
3
- // eslint-disable-next-line @typescript-eslint/no-redeclare
4
- export const IntlMessageFormat = (intl.IntlMessageFormat || intl);
5
- //# sourceMappingURL=intl-messageformat.js.map