@appsemble/utils 0.20.42 → 0.20.44
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/LICENSE.md +126 -0
- package/README.md +9 -3
- package/api/components/index.d.ts +1 -1
- package/api/components/parameters/$filter.d.ts +1 -1
- package/api/components/parameters/$orderby.d.ts +1 -1
- package/api/components/parameters/$select.d.ts +1 -1
- package/api/components/parameters/$team.d.ts +1 -1
- package/api/components/parameters/$top.d.ts +1 -1
- package/api/components/parameters/appId.d.ts +1 -1
- package/api/components/parameters/appOAuth2SecretId.d.ts +1 -1
- package/api/components/parameters/appSamlSecretId.d.ts +1 -1
- package/api/components/parameters/appServiceId.d.ts +2 -0
- package/api/components/parameters/appServiceId.js +8 -0
- package/api/components/parameters/assetId.d.ts +1 -1
- package/api/components/parameters/blockId.d.ts +1 -1
- package/api/components/parameters/blockVersion.d.ts +1 -1
- package/api/components/parameters/endpoint.d.ts +1 -1
- package/api/components/parameters/index.d.ts +1 -0
- package/api/components/parameters/index.js +1 -0
- package/api/components/parameters/language.d.ts +1 -1
- package/api/components/parameters/organizationId.d.ts +1 -1
- package/api/components/parameters/resourceId.d.ts +1 -1
- package/api/components/parameters/resourceType.d.ts +1 -1
- package/api/components/parameters/screenshotId.d.ts +1 -1
- package/api/components/parameters/view.d.ts +1 -1
- package/api/components/requestBodies/oauth2Consent.d.ts +1 -1
- package/api/components/requestBodies/resource.d.ts +1 -1
- package/api/components/requestBodies/user.d.ts +1 -1
- package/api/components/responses/app.d.ts +1 -1
- package/api/components/responses/blockVersion.d.ts +1 -1
- package/api/components/responses/invite.d.ts +1 -1
- package/api/components/responses/oauth2AuthorizationCode.d.ts +1 -1
- package/api/components/responses/organization.d.ts +1 -1
- package/api/components/responses/resource.d.ts +1 -1
- package/api/components/responses/subscriptions.d.ts +1 -1
- package/api/components/schemas/ActionDefinition.d.ts +1 -1
- package/api/components/schemas/App.d.ts +1 -1
- package/api/components/schemas/AppAccount.d.ts +1 -1
- package/api/components/schemas/AppDefinition.d.ts +1 -1
- package/api/components/schemas/AppLayoutDefinition.d.ts +1 -1
- package/api/components/schemas/AppMessages.d.ts +1 -1
- package/api/components/schemas/AppOAuth2Secret.d.ts +1 -1
- package/api/components/schemas/AppServiceSecret.d.ts +2 -0
- package/api/components/schemas/AppServiceSecret.js +45 -0
- package/api/components/schemas/AppsembleMessages.d.ts +1 -1
- package/api/components/schemas/ArrayRemapperDefinition.d.ts +1 -1
- package/api/components/schemas/Asset.d.ts +1 -1
- package/api/components/schemas/BaseActionDefinition.d.ts +1 -1
- package/api/components/schemas/BaseJSONSchema.d.ts +1 -1
- package/api/components/schemas/BasePageDefinition.d.ts +1 -1
- package/api/components/schemas/BlockDefinition.d.ts +1 -1
- package/api/components/schemas/BlockVersion.d.ts +1 -1
- package/api/components/schemas/CronDefinition.d.ts +1 -1
- package/api/components/schemas/CustomFontDefinition.d.ts +1 -1
- package/api/components/schemas/Error.d.ts +1 -1
- package/api/components/schemas/EventsDefinition.d.ts +1 -1
- package/api/components/schemas/FlowPageActionsDefinition.d.ts +1 -1
- package/api/components/schemas/GoogleFontDefinition.d.ts +1 -1
- package/api/components/schemas/Health.d.ts +1 -1
- package/api/components/schemas/JSONSchema.d.ts +1 -1
- package/api/components/schemas/LoopPageActionsDefinition.d.ts +1 -1
- package/api/components/schemas/Member.d.ts +1 -1
- package/api/components/schemas/NotificationHookDataDefinition.d.ts +1 -1
- package/api/components/schemas/NotificationHookDefinition.d.ts +1 -1
- package/api/components/schemas/OAuth2AuthorizationCode.d.ts +1 -1
- package/api/components/schemas/OAuth2ClientCredentials.d.ts +1 -1
- package/api/components/schemas/ObjectRemapperDefinition.d.ts +1 -1
- package/api/components/schemas/ObjectRemapperDefinition.js +42 -1
- package/api/components/schemas/Organization.d.ts +1 -1
- package/api/components/schemas/Rating.d.ts +1 -1
- package/api/components/schemas/RemapperDefinition.d.ts +1 -1
- package/api/components/schemas/Resource.d.ts +1 -1
- package/api/components/schemas/ResourceDefinition.d.ts +1 -1
- package/api/components/schemas/ResourceHistoryDefinition.d.ts +1 -1
- package/api/components/schemas/ResourceHooksDefinition.d.ts +1 -1
- package/api/components/schemas/ResourceSubscription.d.ts +1 -1
- package/api/components/schemas/ResourceViewDefinition.d.ts +1 -1
- package/api/components/schemas/SSLSecret.d.ts +1 -1
- package/api/components/schemas/SSOConfiguration.d.ts +1 -1
- package/api/components/schemas/SecurityDefaultDefinition.d.ts +1 -1
- package/api/components/schemas/SecurityDefaultDefinition.js +7 -0
- package/api/components/schemas/SecurityDefinition.d.ts +1 -1
- package/api/components/schemas/SecurityRoleDefinition.d.ts +1 -1
- package/api/components/schemas/SubPage.d.ts +1 -1
- package/api/components/schemas/TeamsDefinition.d.ts +1 -1
- package/api/components/schemas/Theme.d.ts +1 -1
- package/api/components/schemas/User.d.ts +1 -1
- package/api/components/schemas/UserEmail.d.ts +1 -1
- package/api/components/schemas/index.d.ts +1 -0
- package/api/components/schemas/index.js +1 -0
- package/api/components/schemas/utils.d.ts +1 -1
- package/api/components/securitySchemes/app.d.ts +1 -1
- package/api/components/securitySchemes/basic.d.ts +1 -1
- package/api/components/securitySchemes/cli.d.ts +1 -1
- package/api/components/securitySchemes/cli.test.js +1 -1
- package/api/components/securitySchemes/studio.d.ts +1 -1
- package/api/index.d.ts +1 -1
- package/api/paths/action.d.ts +1 -1
- package/api/paths/appMessages.d.ts +1 -1
- package/api/paths/appOAuth2Secrets.d.ts +1 -1
- package/api/paths/appSSLSecrets.d.ts +1 -1
- package/api/paths/appSamlSecrets.d.ts +1 -1
- package/api/paths/appServiceSecrets.d.ts +2 -0
- package/api/paths/appServiceSecrets.js +84 -0
- package/api/paths/apps.d.ts +1 -1
- package/api/paths/appsembleMessages.d.ts +1 -1
- package/api/paths/assets.d.ts +1 -1
- package/api/paths/blocks.d.ts +1 -1
- package/api/paths/emails.d.ts +1 -1
- package/api/paths/health.d.ts +1 -1
- package/api/paths/index.js +2 -0
- package/api/paths/invite.d.ts +1 -1
- package/api/paths/oauth2ClientCredentials.d.ts +1 -1
- package/api/paths/oauth2Login.d.ts +1 -1
- package/api/paths/oauth2Provider.d.ts +1 -1
- package/api/paths/organizations.d.ts +1 -1
- package/api/paths/resourceHistory.d.ts +1 -1
- package/api/paths/resources.d.ts +1 -1
- package/api/paths/saml.d.ts +1 -1
- package/api/paths/templates.d.ts +1 -1
- package/api/paths/user.d.ts +1 -1
- package/api/tags/app.d.ts +1 -1
- package/api/tags/appMember.d.ts +1 -1
- package/api/tags/asset.d.ts +1 -1
- package/api/tags/auth.d.ts +1 -1
- package/api/tags/language.d.ts +1 -1
- package/api/tags/organization.d.ts +1 -1
- package/api/tags/resource.d.ts +1 -1
- package/api/tags/template.d.ts +1 -1
- package/api/tags/user.d.ts +1 -1
- package/appMessages.d.ts +3 -3
- package/appMessages.js +1 -1
- package/appSecurity.d.ts +1 -1
- package/blockUtils.d.ts +1 -1
- package/checkAppRole.d.ts +1 -1
- package/constants/baseTheme.d.ts +1 -1
- package/formatRequestAction.d.ts +2 -2
- package/ics.d.ts +1 -1
- package/iterApp.d.ts +1 -1
- package/jsonschema.d.ts +2 -2
- package/langmap.d.ts +1 -1
- package/normalize.d.ts +1 -1
- package/normalize.js +1 -1
- package/package.json +2 -2
- package/remap.d.ts +2 -2
- package/remap.js +15 -0
- package/remap.test.js +126 -0
- package/serverActions.d.ts +1 -0
- package/serverActions.js +13 -0
- package/theme.d.ts +1 -1
- package/validation.d.ts +5 -5
- package/validation.js +6 -1
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
|
@@ -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>;
|
package/serverActions.js
ADDED
package/theme.d.ts
CHANGED
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
|
-
*
|
|
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
|
-
*
|
|
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) {
|