@appsemble/node-utils 0.34.15 → 0.34.18-test.1

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 (25) hide show
  1. package/README.md +3 -3
  2. package/app.js +1 -0
  3. package/getMessagesUtil.js +4 -1
  4. package/package.json +4 -4
  5. package/resource.d.ts +1 -1
  6. package/server/controllers/common/apps/assets/createGetAppAssetByIdController.js +1 -1
  7. package/server/controllers/common/apps/groups/createGetAppGroupsController.js +1 -1
  8. package/server/controllers/common/apps/resources/createCountAppResourcesController.js +4 -1
  9. package/server/controllers/common/apps/resources/createCreateAppResourceController.js +5 -5
  10. package/server/controllers/common/apps/resources/createDeleteAppResourceController.js +4 -1
  11. package/server/controllers/common/apps/resources/createGetAppResourceByIdController.js +4 -1
  12. package/server/controllers/common/apps/resources/createQueryAppResourcesController.js +4 -1
  13. package/server/controllers/common/apps/resources/createUpdateAppResourceController.js +5 -5
  14. package/server/controllers/common/apps/variables/createGetAppVariablesController.js +1 -1
  15. package/server/controllers/main/apps/assets/createCreateAppAssetController.js +1 -1
  16. package/server/controllers/main/apps/resources/createDeleteAppSeedResourcesController.js +4 -1
  17. package/server/routes/appRouter/blockCssHandler.js +1 -1
  18. package/server/routes/appRouter/iconHandler.js +4 -1
  19. package/server/routes/appRouter/indexHandler.js +1 -0
  20. package/server/routes/appRouter/manifestHandler.js +1 -1
  21. package/server/routes/appRouter/readmeHandler.js +1 -1
  22. package/server/routes/appRouter/robotsHandler.js +1 -1
  23. package/server/routes/appRouter/screenshotHandler.js +1 -1
  24. package/server/routes/appRouter/serviceWorkerHandler.js +5 -1
  25. package/server/utils/actions.js +4 -1
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.34.15/config/assets/logo.svg) Appsemble Node Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.34.18-test.1/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.34.15/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.34.15)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.34.18-test.1/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.34.18-test.1)
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.34.15/LICENSE.md) ©
29
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.34.18-test.1/LICENSE.md) ©
30
30
  [Appsemble](https://appsemble.com)
package/app.js CHANGED
@@ -242,6 +242,7 @@ export async function applyAppVariant(appPath, appVariant) {
242
242
  await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'config');
243
243
  await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'assets');
244
244
  await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'resources');
245
+ await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'members');
245
246
  await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'screenshots');
246
247
  await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'icon.png');
247
248
  await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'maskable-icon.png');
@@ -12,7 +12,10 @@ export async function getMessagesUtil(ctx, language, appId, merge, { getApp, get
12
12
  .subtags()
13
13
  .find((sub) => sub.type() === 'language');
14
14
  const baseLang = baseLanguage && String(baseLanguage).toLowerCase();
15
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
15
+ const app = await getApp({
16
+ context: ctx,
17
+ query: { attributes: ['id', 'definition'], where: { id: appId } },
18
+ });
16
19
  assertKoaCondition(app != null, ctx, 404, 'App not found');
17
20
  const blockPrefixes = [];
18
21
  const blockQuery = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/node-utils",
3
- "version": "0.34.15",
3
+ "version": "0.34.18-test.1",
4
4
  "description": "NodeJS utilities used by Appsemble internally.",
5
5
  "keywords": [
6
6
  "app",
@@ -40,9 +40,9 @@
40
40
  "test": "vitest"
41
41
  },
42
42
  "dependencies": {
43
- "@appsemble/types": "0.34.15",
44
- "@appsemble/utils": "0.34.15",
45
- "@appsemble/lang-sdk": "0.34.15",
43
+ "@appsemble/types": "0.34.18-test.1",
44
+ "@appsemble/utils": "0.34.18-test.1",
45
+ "@appsemble/lang-sdk": "0.34.18-test.1",
46
46
  "@formatjs/fast-memoize": "^2.0.0",
47
47
  "@fortawesome/fontawesome-free": "^6.0.0",
48
48
  "@kubernetes/client-node": "^0.22.2",
package/resource.d.ts CHANGED
@@ -62,5 +62,5 @@ export declare function extractResourceBody(ctx: Context | ParameterizedContext<
62
62
  */
63
63
  export declare function processResourceBody(ctx: Context | ParameterizedContext<DefaultState, DefaultContext, any>, definition: ResourceDefinition, knownAssetIds?: string[], knownExpires?: Date, knownAssetNameIds?: {
64
64
  id: string;
65
- name: string;
65
+ name?: string;
66
66
  }[], isPatch?: boolean): [Record<string, unknown> | Record<string, unknown>[], PreparedAsset[], string[]];
@@ -3,7 +3,7 @@ import { assertKoaCondition } from '../../../../../koa.js';
3
3
  export function createGetAppAssetByIdController({ getApp, getAppAsset }) {
4
4
  return async (ctx) => {
5
5
  const { pathParams: { appId, assetId }, } = ctx;
6
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
6
+ const app = await getApp({ context: ctx, query: { attributes: ['id'], where: { id: appId } } });
7
7
  assertKoaCondition(app != null, ctx, 404, 'App not found');
8
8
  const asset = await getAppAsset({ app, context: ctx, id: assetId });
9
9
  if (assetId !== asset.id) {
@@ -3,7 +3,7 @@ import { assertKoaCondition } from '../../../../../koa.js';
3
3
  export function createGetAppGroupsController({ checkAuthSubjectAppPermissions, getApp, getAppGroups, }) {
4
4
  return async (ctx) => {
5
5
  const { pathParams: { appId }, } = ctx;
6
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
6
+ const app = await getApp({ context: ctx, query: { attributes: ['id'], where: { id: appId } } });
7
7
  assertKoaCondition(app != null, ctx, 404, 'App not found');
8
8
  await checkAuthSubjectAppPermissions({
9
9
  app,
@@ -3,7 +3,10 @@ export function createCountAppResourcesController(options) {
3
3
  return async (ctx) => {
4
4
  const { pathParams: { appId, resourceType }, queryParams: { $own, selectedGroupId }, user: authSubject, } = ctx;
5
5
  const { checkAppPermissions, getApp, getAppResources } = options;
6
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
6
+ const app = await getApp({
7
+ context: ctx,
8
+ query: { where: { id: appId }, attributes: ['demoMode', 'id'] },
9
+ });
7
10
  await checkAppPermissions({
8
11
  context: ctx,
9
12
  permissions: [
@@ -17,7 +17,10 @@ export function createCreateAppResourceController(options) {
17
17
  return async (ctx) => {
18
18
  const { pathParams: { appId, resourceType }, query, queryParams: { selectedGroupId }, } = ctx;
19
19
  const { checkAppPermissions, createAppResourcesWithAssets, getApp, getAppAssets } = options;
20
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
20
+ const app = await getApp({
21
+ context: ctx,
22
+ query: { attributes: ['id', 'demoMode', 'definition'], where: { id: appId } },
23
+ });
21
24
  await checkAppPermissions({
22
25
  context: ctx,
23
26
  permissions: [`$resource:${resourceType}:create`],
@@ -26,10 +29,7 @@ export function createCreateAppResourceController(options) {
26
29
  });
27
30
  const resourceDefinition = getResourceDefinition(app.definition, resourceType, ctx);
28
31
  const appAssets = await getAppAssets({ app, context: ctx });
29
- const [processedBody, preparedAssets] = processResourceBody(ctx, resourceDefinition, undefined, undefined,
30
- // @ts-expect-error 2345 argument of type is not assignable to parameter of type
31
- // (strictNullChecks)
32
- appAssets.map((appAsset) => ({ id: appAsset.id, name: appAsset.name })));
32
+ const [processedBody, preparedAssets] = processResourceBody(ctx, resourceDefinition, appAssets.map(({ id }) => id), undefined, appAssets.map((appAsset) => ({ id: appAsset.id, name: appAsset.name })));
33
33
  if (Array.isArray(processedBody) && !processedBody.length) {
34
34
  ctx.body = [];
35
35
  return;
@@ -3,7 +3,10 @@ export function createDeleteAppResourceController(options) {
3
3
  return async (ctx) => {
4
4
  const { pathParams: { appId, resourceId, resourceType }, queryParams: { selectedGroupId }, user: authSubject, } = ctx;
5
5
  const { checkAppPermissions, deleteAppResource, getApp, getAppResource } = options;
6
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
6
+ const app = await getApp({
7
+ context: ctx,
8
+ query: { attributes: ['demoMode', 'id'], where: { id: appId } },
9
+ });
7
10
  const findOptions = {
8
11
  where: {
9
12
  id: resourceId,
@@ -4,7 +4,10 @@ export function createGetAppResourceByIdController(options) {
4
4
  return async (ctx) => {
5
5
  const { pathParams: { appId, resourceId, resourceType }, queryParams: { selectedGroupId, view }, user: authSubject, } = ctx;
6
6
  const { checkAppPermissions, getApp, getAppResource } = options;
7
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
7
+ const app = await getApp({
8
+ context: ctx,
9
+ query: { attributes: ['demoMode', 'definition', 'id'], where: { id: appId } },
10
+ });
8
11
  const findOptions = {
9
12
  where: {
10
13
  id: resourceId,
@@ -5,7 +5,10 @@ export function createQueryAppResourcesController(options) {
5
5
  return async (ctx) => {
6
6
  const { pathParams: { appId, resourceType }, queryParams: { $own, $select, $skip, $top, selectedGroupId, view }, user: authSubject, } = ctx;
7
7
  const { checkAppPermissions, getApp, getAppResources } = options;
8
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
8
+ const app = await getApp({
9
+ context: ctx,
10
+ query: { attributes: ['definition', 'demoMode', 'id'], where: { id: appId } },
11
+ });
9
12
  const resourceDefinition = getResourceDefinition(app.definition, resourceType, ctx, view);
10
13
  const { order, where } = generateResourceQuery(ctx, options, resourceDefinition);
11
14
  await checkAppPermissions({
@@ -3,7 +3,10 @@ export function createUpdateAppResourceController(options) {
3
3
  return async (ctx) => {
4
4
  const { pathParams: { appId, resourceId, resourceType }, queryParams: { selectedGroupId }, user: authSubject, } = ctx;
5
5
  const { checkAppPermissions, getApp, getAppAssets, getAppResource, updateAppResource } = options;
6
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
6
+ const app = await getApp({
7
+ context: ctx,
8
+ query: { attributes: ['id', 'demoMode', 'definition'], where: { id: appId } },
9
+ });
7
10
  const findOptions = {
8
11
  where: {
9
12
  id: resourceId,
@@ -34,10 +37,7 @@ export function createUpdateAppResourceController(options) {
34
37
  });
35
38
  const appAssets = await getAppAssets({ context: ctx, app });
36
39
  const resourceDefinition = getResourceDefinition(app.definition, resourceType, ctx);
37
- const [processedBody, preparedAssets, deletedAssetIds] = processResourceBody(ctx, resourceDefinition, appAssets.filter((asset) => asset.resourceId === resourceId).map((asset) => asset.id), oldResource.expires,
38
- // @ts-expect-error 2345 argument of type is not assignable to parameter of type
39
- // (strictNullChecks)
40
- appAssets.map((asset) => ({ id: asset.id, name: asset.name })));
40
+ const [processedBody, preparedAssets, deletedAssetIds] = processResourceBody(ctx, resourceDefinition, appAssets.filter((asset) => asset.resourceId === resourceId).map((asset) => asset.id), oldResource.expires, appAssets.map((asset) => ({ id: asset.id, name: asset.name })));
41
41
  const resources = Array.isArray(processedBody) ? processedBody : [processedBody];
42
42
  ctx.body = await updateAppResource({
43
43
  app,
@@ -2,7 +2,7 @@ import { assertKoaCondition } from '../../../../../koa.js';
2
2
  export function createGetAppVariablesController({ getApp, getAppVariables }) {
3
3
  return async (ctx) => {
4
4
  const { pathParams: { appId }, } = ctx;
5
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
5
+ const app = await getApp({ context: ctx, query: { attributes: ['id'], where: { id: appId } } });
6
6
  assertKoaCondition(app != null, ctx, 404, 'App not found');
7
7
  ctx.body = await getAppVariables({
8
8
  context: ctx,
@@ -2,7 +2,7 @@ import { assertKoaCondition } from '../../../../../koa.js';
2
2
  export function createCreateAppAssetController({ createAppAsset, getApp }) {
3
3
  return async (ctx) => {
4
4
  const { pathParams: { appId }, request: { body: { file: { filename, mime, path }, name, }, }, } = ctx;
5
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
5
+ const app = await getApp({ context: ctx, query: { attributes: ['id'], where: { id: appId } } });
6
6
  assertKoaCondition(app != null, ctx, 404, 'App not found');
7
7
  const asset = await createAppAsset({
8
8
  app,
@@ -4,7 +4,10 @@ export function createDeleteAppSeedResourcesController(options) {
4
4
  return async (ctx) => {
5
5
  const { pathParams: { appId }, } = ctx;
6
6
  const { getApp } = options;
7
- const app = await getApp({ context: ctx, query: { where: { id: appId } } });
7
+ const app = await getApp({
8
+ context: ctx,
9
+ query: { attributes: ['id', 'definition'], where: { id: appId } },
10
+ });
8
11
  assertKoaCondition(app != null, ctx, 404, 'App not found');
9
12
  for (const resourceType of Object.keys(app.definition.resources ?? {})) {
10
13
  await deleteResourcesRecursively(resourceType, app, options, ctx);
@@ -4,7 +4,7 @@ export function createBlockCssHandler({ getApp, getAppBlockStyles }) {
4
4
  const {
5
5
  // @ts-expect-error Messed up
6
6
  params: { name }, } = ctx;
7
- const app = await getApp({ context: ctx });
7
+ const app = await getApp({ query: { attributes: ['id'] }, context: ctx });
8
8
  assertKoaCondition(app != null, ctx, 404, 'App not found');
9
9
  const appBlockStyles = await getAppBlockStyles({ app, name, context: ctx });
10
10
  const [style] = appBlockStyles;
@@ -7,7 +7,10 @@ export function createIconHandler({ getApp, getAppIcon, getDbUpdated }) {
7
7
  params: { size = 128 }, query: { maskable = false, updated }, } = ctx;
8
8
  const app = await getApp({
9
9
  context: ctx,
10
- query: { where: { ...(updated ? { updated } : {}) } },
10
+ query: {
11
+ attributes: ['id', 'icon', 'created', 'updated'],
12
+ where: { ...(updated ? { updated } : {}) },
13
+ },
11
14
  });
12
15
  const dbUpdated = app ? await getDbUpdated({ app, maskable, context: ctx }) : false;
13
16
  const appIcon = app ? await getAppIcon({ app, context: ctx }) : null;
@@ -10,6 +10,7 @@ export function createIndexHandler({ createSettings, getApp, getAppDetails, getA
10
10
  return async (ctx) => {
11
11
  const { hostname, path } = ctx;
12
12
  const host = getHost({ context: ctx });
13
+ // Most of the fields here are used either directly or indirectly that's why no attributes query
13
14
  const app = await getApp({ context: ctx });
14
15
  if (!app) {
15
16
  const { appPath, organizationId } = await getAppDetails({ context: ctx });
@@ -5,7 +5,7 @@ import { extension } from 'mime-types';
5
5
  const iconSizes = [48, 144, 192, 512];
6
6
  export function createManifestHandler({ getApp, getAppScreenshots }) {
7
7
  return async (ctx) => {
8
- const app = await getApp({ context: ctx });
8
+ const app = await getApp({ context: ctx, query: { attributes: ['id', 'definition'] } });
9
9
  assertKoaCondition(app != null, ctx, 404, 'Block asset not found');
10
10
  const { defaultPage, description, name, theme = baseTheme } = app.definition;
11
11
  const { themeColor = '#ffffff', splashColor = themeColor } = theme;
@@ -3,7 +3,7 @@ export function createReadmeHandler({ getApp, getAppReadmes }) {
3
3
  return async (ctx) => {
4
4
  // @ts-expect-error Messed up
5
5
  const { id } = ctx.params;
6
- const app = await getApp({ context: ctx });
6
+ const app = await getApp({ context: ctx, query: { attributes: ['id'] } });
7
7
  assertKoaCondition(app != null, ctx, 404, 'App not found');
8
8
  const appReadmes = await getAppReadmes({ app, context: ctx });
9
9
  const appReadme = appReadmes.find((readme) => readme.id === Number.parseInt(id));
@@ -1,7 +1,7 @@
1
1
  import { assertKoaCondition, logger } from '@appsemble/node-utils';
2
2
  export function createRobotsHandler({ getApp }) {
3
3
  return async (ctx) => {
4
- const app = await getApp({ context: ctx });
4
+ const app = await getApp({ context: ctx, query: { attributes: ['id', 'visibility'] } });
5
5
  assertKoaCondition(app != null, ctx, 404, 'App not found');
6
6
  switch (app.visibility) {
7
7
  case 'public':
@@ -3,7 +3,7 @@ export function createScreenshotHandler({ getApp, getAppScreenshots }) {
3
3
  return async (ctx) => {
4
4
  // @ts-expect-error Messed up
5
5
  const { id } = ctx.params;
6
- const app = await getApp({ context: ctx });
6
+ const app = await getApp({ context: ctx, query: { attributes: ['id'] } });
7
7
  assertKoaCondition(app != null, ctx, 404, 'App not found');
8
8
  const appScreenshots = await getAppScreenshots({ app, context: ctx });
9
9
  const appScreenshot = appScreenshots.find((screenshot) => screenshot.id === Number.parseInt(id));
@@ -8,10 +8,14 @@ export function createServiceWorkerHandler({ getApp, getBlocksAssetsPaths }) {
8
8
  const serviceWorker = await (production
9
9
  ? readFile(new URL('../../../../../dist/app/service-worker.js', import.meta.url), 'utf8')
10
10
  : ctx.fs.promises.readFile(filename, 'utf8'));
11
- const app = await getApp({ context: ctx });
11
+ const app = await getApp({
12
+ context: ctx,
13
+ query: { attributes: ['id', 'definition'] },
14
+ });
12
15
  assertKoaCondition(app != null, ctx, 404, 'App does not exist.');
13
16
  const identifiableBlocks = getAppBlocks(app.definition);
14
17
  const blocksAssetsPaths = await getBlocksAssetsPaths({ identifiableBlocks, context: ctx });
18
+ // App.version is a virtual column and comes from App.AppSnapshots
15
19
  ctx.body = `const appVersion = ${app.version};const blockAssets=${JSON.stringify(blocksAssetsPaths)};${serviceWorker}`;
16
20
  ctx.type = 'application/javascript';
17
21
  };
@@ -169,7 +169,10 @@ async function handleRequestProxy(ctx, app, action, useBody, options) {
169
169
  export function createProxyHandler(useBody, options) {
170
170
  return async (ctx) => {
171
171
  const { pathParams: { appId, path }, } = ctx;
172
- const app = await options.getApp({ context: ctx, query: { where: { id: appId } } });
172
+ const app = await options.getApp({
173
+ context: ctx,
174
+ query: { attributes: ['id', 'definition'], where: { id: appId } },
175
+ });
173
176
  assertKoaCondition(app != null, ctx, 404, 'App not found');
174
177
  const appAction = get(app.definition, path);
175
178
  const action = supportedActions.find((act) => act === appAction?.type);