@appsemble/utils 0.23.7 → 0.23.9

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 CHANGED
@@ -1,9 +1,9 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.23.7/config/assets/logo.svg) Appsemble Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.23.9/config/assets/logo.svg) Appsemble Utilities
2
2
 
3
3
  > Internal utility functions used across multiple Appsemble projects.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@appsemble/utils)](https://www.npmjs.com/package/@appsemble/utils)
6
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.23.7/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.23.7)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.23.9/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.23.9)
7
7
  [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](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.23.7/LICENSE.md) ©
29
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.23.9/LICENSE.md) ©
30
30
  [Appsemble](https://appsemble.com)
@@ -75,6 +75,7 @@ export const ActionDefinition = {
75
75
  { $ref: '#/components/schemas/UserLoginActionDefinition' },
76
76
  { $ref: '#/components/schemas/UserLogoutActionDefinition' },
77
77
  { $ref: '#/components/schemas/UserRegisterActionDefinition' },
78
+ { $ref: '#/components/schemas/UserCreateActionDefinition' },
78
79
  { $ref: '#/components/schemas/UserUpdateActionDefinition' },
79
80
  ],
80
81
  },
@@ -0,0 +1 @@
1
+ export declare const UserCreateActionDefinition: import("openapi-types").OpenAPIV3.SchemaObject;
@@ -0,0 +1,33 @@
1
+ import { BaseActionDefinition } from './BaseActionDefinition.js';
2
+ import { extendJSONSchema } from './utils.js';
3
+ export const UserCreateActionDefinition = extendJSONSchema(BaseActionDefinition, {
4
+ type: 'object',
5
+ additionalProperties: false,
6
+ required: ['email', 'password'],
7
+ properties: {
8
+ type: {
9
+ enum: ['user.create'],
10
+ description: `Allows the user to create a new account using an email address and a password.
11
+
12
+ Does nothing if the user is already logged in.`,
13
+ },
14
+ password: {
15
+ description: 'The password to login with.',
16
+ },
17
+ email: {
18
+ description: 'The email to login with.',
19
+ },
20
+ displayName: {
21
+ description: 'The display name of the user.',
22
+ },
23
+ properties: {
24
+ description: `The custom properties for the user.
25
+
26
+ Every value will be converted to a string.`,
27
+ },
28
+ role: {
29
+ description: "The role for the created account. Defaults to the default role in the app's security definition.",
30
+ },
31
+ },
32
+ });
33
+ //# sourceMappingURL=UserCreateActionDefinition.js.map
@@ -121,6 +121,7 @@ export * from './UserEmail.js';
121
121
  export * from './UserLogoutActionDefinition.js';
122
122
  export * from './UserLoginActionDefinition.js';
123
123
  export * from './UserRegisterActionDefinition.js';
124
+ export * from './UserCreateActionDefinition.js';
124
125
  export * from './UserUpdateActionDefinition.js';
125
126
  export * from './LoopPageDefinition.js';
126
127
  export * from './LoopPageActionsDefinition.js';
@@ -121,6 +121,7 @@ export * from './UserEmail.js';
121
121
  export * from './UserLogoutActionDefinition.js';
122
122
  export * from './UserLoginActionDefinition.js';
123
123
  export * from './UserRegisterActionDefinition.js';
124
+ export * from './UserCreateActionDefinition.js';
124
125
  export * from './UserUpdateActionDefinition.js';
125
126
  export * from './LoopPageDefinition.js';
126
127
  export * from './LoopPageActionsDefinition.js';
package/api/index.js CHANGED
@@ -10,22 +10,34 @@ export * as schemas from './components/schemas/index.js';
10
10
  * @returns The OpenAPI document for Appsemble.
11
11
  */
12
12
  export function api(version, { port = 9999, ssl, host = `${ssl ? 'https' : 'http'}://localhost:${port}` } = {}) {
13
+ let hostToBeLogged = host;
14
+ if (port) {
15
+ const splitHost = hostToBeLogged.split(':');
16
+ if (Number.isNaN(Number(splitHost.at(-1))) === false) {
17
+ splitHost[splitHost.length - 1] = String(port);
18
+ hostToBeLogged = splitHost.join(':');
19
+ }
20
+ else {
21
+ splitHost.push(String(port));
22
+ hostToBeLogged = splitHost.join(':');
23
+ }
24
+ }
13
25
  return {
14
26
  openapi: '3.0.2',
15
27
  components,
16
28
  externalDocs: {
17
29
  description: 'Appsemble developer documentation',
18
- url: `${host}/docs`,
30
+ url: `${hostToBeLogged}/docs`,
19
31
  },
20
32
  info: {
21
33
  title: 'Appsemble',
22
34
  description: `Welcome to the Appsemble API.
23
35
 
24
36
  The app studio can be found on
25
- > ${host}
37
+ > ${hostToBeLogged}
26
38
 
27
39
  The OpenAPI explorer can be found on
28
- > ${host}/api-explorer
40
+ > ${hostToBeLogged}/api-explorer
29
41
  `,
30
42
  license: {
31
43
  name: 'LGPL',
package/api/paths/apps.js CHANGED
@@ -241,6 +241,10 @@ export const paths = {
241
241
  type: 'boolean',
242
242
  description: 'Whether the Appsemble OAuth2 login method should be shown.',
243
243
  },
244
+ enableSelfRegistration: {
245
+ type: 'boolean',
246
+ description: 'Whether new users should be able to register themselves.',
247
+ },
244
248
  emailName: {
245
249
  type: 'string',
246
250
  description: 'The name used for emails.',
package/api/paths/user.js CHANGED
@@ -352,6 +352,55 @@ export const paths = {
352
352
  },
353
353
  },
354
354
  },
355
+ '/api/user/apps/{appId}/accounts': {
356
+ parameters: [{ $ref: '#/components/parameters/appId' }],
357
+ post: {
358
+ tags: ['appMember'],
359
+ description: 'Create a new app account using an email address and a password.',
360
+ operationId: 'createMemberEmail',
361
+ security: [{ app: [] }],
362
+ requestBody: {
363
+ description: 'The user account to create.',
364
+ required: true,
365
+ content: {
366
+ 'multipart/form-data': {
367
+ schema: {
368
+ type: 'object',
369
+ required: ['email', 'password', 'timezone'],
370
+ properties: {
371
+ name: {
372
+ type: 'string',
373
+ },
374
+ email: {
375
+ type: 'string',
376
+ format: 'email',
377
+ },
378
+ password: {
379
+ type: 'string',
380
+ minLength: 8,
381
+ },
382
+ properties: {
383
+ type: 'object',
384
+ additionalProperties: { type: 'string' },
385
+ description: 'The member’s custom properties.',
386
+ },
387
+ timezone: { type: 'string' },
388
+ role: {
389
+ type: 'string',
390
+ description: "The role for the created account. Defaults to the default role in the app's security definition.",
391
+ },
392
+ },
393
+ },
394
+ },
395
+ },
396
+ },
397
+ responses: {
398
+ 201: {
399
+ description: 'The account that was created.',
400
+ },
401
+ },
402
+ },
403
+ },
355
404
  '/api/user/apps/{appId}/account/verify': {
356
405
  parameters: [{ $ref: '#/components/parameters/appId' }],
357
406
  post: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/utils",
3
- "version": "0.23.7",
3
+ "version": "0.23.9",
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.23.7",
40
+ "@appsemble/types": "0.23.9",
41
41
  "axios": "^1.0.0",
42
42
  "cron-parser": "^4.0.0",
43
43
  "date-fns": "^2.0.0",
@@ -59,7 +59,7 @@
59
59
  "@types/lcm": "^0.0.2",
60
60
  "bulma": "0.9.3",
61
61
  "koas-core": "^0.7.0",
62
- "vitest": "^0.34.0",
62
+ "vitest": "^1.0.0",
63
63
  "yaml": "^2.0.0"
64
64
  },
65
65
  "engines": {
@@ -167,6 +167,31 @@ remapper is a filtered list:
167
167
  ]
168
168
  \`\`\`
169
169
  `,
170
+ },
171
+ 'array.find': {
172
+ $ref: '#/components/schemas/RemapperDefinition',
173
+ description: `
174
+ Returns a single object or value from an array based on the given condition.
175
+
176
+ For example:
177
+
178
+ Input:
179
+
180
+ \`\`\`json
181
+ [{ name: "Craig" }, { name: "Joey" }, { name: "Stuart" }]
182
+ \`\`\`
183
+ \`\`\`yaml
184
+ array.find:
185
+ equals: [{ prop: "name" }, "Craig" ]
186
+ \`\`\`
187
+
188
+ Result:
189
+
190
+ \`\`\`json
191
+ { name: "Craig" }
192
+ \`\`\`
193
+
194
+ `,
170
195
  },
171
196
  'array.from': {
172
197
  type: 'array',
package/remap.js CHANGED
@@ -209,6 +209,22 @@ const mapperImplementations = {
209
209
  });
210
210
  },
211
211
  array: (prop, input, context) => { var _a; return (_a = context.array) === null || _a === void 0 ? void 0 : _a[prop]; },
212
+ 'array.find'(mapper, input, context) {
213
+ var _a;
214
+ if (!Array.isArray(input)) {
215
+ console.error(`${input} is not an array!`);
216
+ return null;
217
+ }
218
+ return ((_a = input === null || input === void 0 ? void 0 : input.find((item) => {
219
+ const remapped = remap(mapper, item, context);
220
+ switch (typeof remapped) {
221
+ case 'boolean':
222
+ return remap(mapper, item, context) ? item : null;
223
+ default:
224
+ return equal(remapped, item) ? item : null;
225
+ }
226
+ })) !== null && _a !== void 0 ? _a : null);
227
+ },
212
228
  'array.from': (mappers, input, context) => mappers.map((mapper) => remap(mapper, input, context)),
213
229
  'array.append': (mappers, input, context) => Array.isArray(input)
214
230
  ? input.concat(mappers.map((mapper) => remap(mapper, input, context)))
package/remap.test.js CHANGED
@@ -764,6 +764,25 @@ describe('array', () => {
764
764
  },
765
765
  });
766
766
  });
767
+ describe('array.find', () => {
768
+ runTests({
769
+ 'return object with specified value from array': {
770
+ input: [{ name: 'Craig' }, { name: 'Joey' }, { name: 'Stuart' }],
771
+ mappers: [{ 'array.find': { equals: [{ prop: 'name' }, 'Craig'] } }],
772
+ expected: { name: 'Craig' },
773
+ },
774
+ 'return undefined when condition doesn’t match anything': {
775
+ input: [{ name: 'Craig' }],
776
+ mappers: [{ 'array.find': { equals: [{ prop: 'name' }, 'foo'] } }],
777
+ expected: null,
778
+ },
779
+ 'return single value when the array does not include objects': {
780
+ input: ['Craig', 'Stuart'],
781
+ mappers: [{ 'array.find': 'Craig' }],
782
+ expected: 'Craig',
783
+ },
784
+ });
785
+ });
767
786
  describe('array.from', () => {
768
787
  runTests({
769
788
  'create new array with remapped values': {