@appsemble/node-utils 0.24.8 → 0.24.10

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.24.8/config/assets/logo.svg) Appsemble Node Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.24.10/config/assets/logo.svg) Appsemble Node Utilities
2
2
 
3
3
  > NodeJS utilities used by Appsemble internally.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@appsemble/node-utils)](https://www.npmjs.com/package/@appsemble/node-utils)
6
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.24.8/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.24.8)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.24.10/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.24.10)
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 @@ compatibility is not guaranteed.
26
26
 
27
27
  ## License
28
28
 
29
- [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.24.8/LICENSE.md) ©
29
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.24.10/LICENSE.md) ©
30
30
  [Appsemble](https://appsemble.com)
package/app.js CHANGED
@@ -42,6 +42,7 @@ export async function getRemapperContext(app, language, userInfo, options, conte
42
42
  return cache(message || `'{${id}}'`);
43
43
  },
44
44
  userInfo,
45
+ appMember: userInfo === null || userInfo === void 0 ? void 0 : userInfo.appMember,
45
46
  context: {},
46
47
  locale: (_b = (_a = userInfo === null || userInfo === void 0 ? void 0 : userInfo.locale) !== null && _a !== void 0 ? _a : app.definition.defaultLanguage) !== null && _b !== void 0 ? _b : defaultLocale,
47
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/node-utils",
3
- "version": "0.24.8",
3
+ "version": "0.24.10",
4
4
  "description": "NodeJS utilities used by Appsemble internally.",
5
5
  "keywords": [
6
6
  "app",
@@ -38,8 +38,8 @@
38
38
  "test": "vitest"
39
39
  },
40
40
  "dependencies": {
41
- "@appsemble/types": "0.24.8",
42
- "@appsemble/utils": "0.24.8",
41
+ "@appsemble/types": "0.24.10",
42
+ "@appsemble/utils": "0.24.10",
43
43
  "@formatjs/fast-memoize": "^2.0.0",
44
44
  "@fortawesome/fontawesome-free": "^6.0.0",
45
45
  "@koa/cors": "^4.0.0",
package/resource.d.ts CHANGED
@@ -35,10 +35,14 @@ export declare function extractResourceBody(ctx: Context): [Record<string, unkno
35
35
  * @param definition The resource definition to use for processing the request body.
36
36
  * @param knownAssetIds A list of asset IDs that are already known to be linked to the resource.
37
37
  * @param knownExpires A previously known expires value.
38
+ * @param knownAssetNameIds A list of asset ids with asset names that already exist.
38
39
  * @returns A tuple which consists of:
39
40
  *
40
41
  * 1. One or more resources processed from the request body.
41
42
  * 2. A list of newly uploaded assets which should be linked to the resources.
42
43
  * 3. Asset IDs from the `knownAssetIds` array which are no longer used.
43
44
  */
44
- export declare function processResourceBody(ctx: Context, definition: ResourceDefinition, knownAssetIds?: string[], knownExpires?: Date): [Record<string, unknown> | Record<string, unknown>[], PreparedAsset[], string[]];
45
+ export declare function processResourceBody(ctx: Context, definition: ResourceDefinition, knownAssetIds?: string[], knownExpires?: Date, knownAssetNameIds?: {
46
+ id: string;
47
+ name: string;
48
+ }[]): [Record<string, unknown> | Record<string, unknown>[], PreparedAsset[], string[]];
package/resource.js CHANGED
@@ -90,13 +90,14 @@ export function extractResourceBody(ctx) {
90
90
  * @param definition The resource definition to use for processing the request body.
91
91
  * @param knownAssetIds A list of asset IDs that are already known to be linked to the resource.
92
92
  * @param knownExpires A previously known expires value.
93
+ * @param knownAssetNameIds A list of asset ids with asset names that already exist.
93
94
  * @returns A tuple which consists of:
94
95
  *
95
96
  * 1. One or more resources processed from the request body.
96
97
  * 2. A list of newly uploaded assets which should be linked to the resources.
97
98
  * 3. Asset IDs from the `knownAssetIds` array which are no longer used.
98
99
  */
99
- export function processResourceBody(ctx, definition, knownAssetIds = [], knownExpires) {
100
+ export function processResourceBody(ctx, definition, knownAssetIds = [], knownExpires, knownAssetNameIds = []) {
100
101
  const [resource, assets, preValidateProperty] = extractResourceBody(ctx);
101
102
  const validator = new Validator();
102
103
  const assetIdMap = new Map();
@@ -113,6 +114,11 @@ export function processResourceBody(ctx, definition, knownAssetIds = [], knownEx
113
114
  reusedAssets.add(input);
114
115
  return true;
115
116
  }
117
+ const assetNameId = knownAssetNameIds.find((idName) => idName.name === input);
118
+ if (assetNameId) {
119
+ reusedAssets.add(assetNameId.id);
120
+ return true;
121
+ }
116
122
  if (!/^\d+$/.test(input)) {
117
123
  return false;
118
124
  }
@@ -1,11 +1,11 @@
1
1
  import { assertKoaError } from '../../koa.js';
2
2
  export function createGetAppMember({ getApp, getAppMembers }) {
3
3
  return async (ctx) => {
4
- const { pathParams: { appId, memberId }, } = ctx;
4
+ const { pathParams: { appId, userId }, } = ctx;
5
5
  const app = await getApp({ context: ctx, query: { where: { id: appId } } });
6
6
  assertKoaError(!app, ctx, 404, 'App not found');
7
7
  assertKoaError(app.definition.security === undefined, ctx, 404, 'App does not have a security definition');
8
- const appMembers = await getAppMembers({ context: ctx, app, memberId });
8
+ const appMembers = await getAppMembers({ context: ctx, app, userId });
9
9
  assertKoaError(appMembers.length !== 1, ctx, 404, 'App member not found');
10
10
  ctx.body = appMembers[0];
11
11
  };
@@ -157,13 +157,14 @@ export function createGetResourceById(options) {
157
157
  export function createCreateResource(options) {
158
158
  return async (ctx) => {
159
159
  const { pathParams: { appId, resourceType }, } = ctx;
160
- const { checkSeededResources, createAppResourcesWithAssets, getApp, verifyResourceActionPermission, } = options;
160
+ const { checkSeededResources, createAppResourcesWithAssets, getApp, getAppAssets, verifyResourceActionPermission, } = options;
161
161
  const action = 'create';
162
162
  const app = await getApp({ context: ctx, query: { where: { id: appId } } });
163
163
  const resourceSeeded = await checkSeededResources({ context: ctx, app, resourceType });
164
164
  const resourceDefinition = getResourceDefinition(app, resourceType, ctx);
165
165
  await verifyResourceActionPermission({ app, context: ctx, action, resourceType, options, ctx });
166
- const [processedBody, preparedAssets] = processResourceBody(ctx, resourceDefinition);
166
+ const appAssets = await getAppAssets({ app, context: ctx });
167
+ const [processedBody, preparedAssets] = processResourceBody(ctx, resourceDefinition, undefined, undefined, appAssets.map((appAsset) => ({ id: appAsset.id, name: appAsset.name })));
167
168
  if (Array.isArray(processedBody) && !processedBody.length) {
168
169
  ctx.body = [];
169
170
  return;
@@ -12,6 +12,7 @@ let mockGetAppUrl;
12
12
  let mockGetAppMessages;
13
13
  let mockCreateAppResourcesWithAssets;
14
14
  let mockCheckSeededResources;
15
+ let mockGetAppAssets;
15
16
  let mockCtx;
16
17
  let mockCtxIs;
17
18
  describe('createQueryResources', () => {
@@ -429,6 +430,7 @@ describe('createCreateResource', () => {
429
430
  mockVerifyResourceActionPermission = vi.fn();
430
431
  mockCreateAppResourcesWithAssets = vi.fn();
431
432
  mockCheckSeededResources = vi.fn();
433
+ mockGetAppAssets = vi.fn();
432
434
  mockCtxIs = vi.fn();
433
435
  mockCtx = {
434
436
  pathParams: { appId: 1, resourceType: 'mockResourceType' },
@@ -452,11 +454,13 @@ describe('createCreateResource', () => {
452
454
  mockCtxIs.mockReturnValue('multipart/form-data');
453
455
  mockCreateAppResourcesWithAssets.mockResolvedValue(mockResources);
454
456
  mockCheckSeededResources.mockResolvedValue(false);
457
+ mockGetAppAssets.mockResolvedValue([]);
455
458
  const middleware = createCreateResource({
456
459
  getApp: mockGetApp,
457
460
  createAppResourcesWithAssets: mockCreateAppResourcesWithAssets,
458
461
  verifyResourceActionPermission: mockVerifyResourceActionPermission,
459
462
  checkSeededResources: mockCheckSeededResources,
463
+ getAppAssets: mockGetAppAssets,
460
464
  });
461
465
  await middleware(mockCtx, vi.fn());
462
466
  expect(mockGetApp).toHaveBeenCalledWith(expect.objectContaining({
@@ -511,11 +515,13 @@ describe('createCreateResource', () => {
511
515
  mockCtxIs.mockReturnValue('multipart/form-data');
512
516
  mockCreateAppResourcesWithAssets.mockResolvedValue(mockResources);
513
517
  mockCheckSeededResources.mockResolvedValue(false);
518
+ mockGetAppAssets.mockResolvedValue([]);
514
519
  const middleware = createCreateResource({
515
520
  getApp: mockGetApp,
516
521
  createAppResourcesWithAssets: mockCreateAppResourcesWithAssets,
517
522
  verifyResourceActionPermission: mockVerifyResourceActionPermission,
518
523
  checkSeededResources: mockCheckSeededResources,
524
+ getAppAssets: mockGetAppAssets,
519
525
  });
520
526
  await middleware(mockCtx, vi.fn());
521
527
  expect(mockGetApp).toHaveBeenCalledWith(expect.objectContaining({
package/server/types.d.ts CHANGED
@@ -132,7 +132,7 @@ export interface GetAppMessagesParams extends GetAppSubEntityParams {
132
132
  merge?: string[] | string;
133
133
  }
134
134
  export interface GetAppMembersParams extends GetAppSubEntityParams {
135
- memberId: string;
135
+ userId: string;
136
136
  }
137
137
  export interface GetAppUserInfoParams {
138
138
  context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;