@appsemble/node-utils 0.28.8 → 0.28.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.28.8/config/assets/logo.svg) Appsemble Node Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.28.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.28.8/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.28.8)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.28.10/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.28.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.28.8/LICENSE.md) ©
29
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.28.10/LICENSE.md) ©
30
30
  [Appsemble](https://appsemble.com)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/node-utils",
3
- "version": "0.28.8",
3
+ "version": "0.28.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.28.8",
42
- "@appsemble/utils": "0.28.8",
41
+ "@appsemble/types": "0.28.10",
42
+ "@appsemble/utils": "0.28.10",
43
43
  "@formatjs/fast-memoize": "^2.0.0",
44
44
  "@fortawesome/fontawesome-free": "^6.0.0",
45
45
  "@koa/cors": "^4.0.0",
@@ -0,0 +1,3 @@
1
+ import { type Middleware } from 'koa';
2
+ import { type Options } from '../types.js';
3
+ export declare function createGetAppVariables({ getApp, getAppVariables }: Options): Middleware;
@@ -0,0 +1,15 @@
1
+ import { assertKoaError } from '../../koa.js';
2
+ export function createGetAppVariables({ getApp, getAppVariables }) {
3
+ return async (ctx) => {
4
+ const { pathParams: { appId }, } = ctx;
5
+ const app = await getApp({ context: ctx, query: { where: { id: appId } } });
6
+ assertKoaError(!app, ctx, 404, 'App not found');
7
+ const variables = await getAppVariables({
8
+ context: ctx,
9
+ app,
10
+ query: { attributes: ['id', 'name', 'value'] },
11
+ });
12
+ ctx.body = variables;
13
+ };
14
+ }
15
+ //# sourceMappingURL=appVariables.js.map
@@ -3,5 +3,6 @@ export * from './appMessages.js';
3
3
  export * from './assets.js';
4
4
  export * from './resources.js';
5
5
  export * from './appMembers.js';
6
+ export * from './appVariables.js';
6
7
  export * from './teams.js';
7
8
  export * from './oauth2Provider.js';
@@ -3,6 +3,7 @@ export * from './appMessages.js';
3
3
  export * from './assets.js';
4
4
  export * from './resources.js';
5
5
  export * from './appMembers.js';
6
+ export * from './appVariables.js';
6
7
  export * from './teams.js';
7
8
  export * from './oauth2Provider.js';
8
9
  //# sourceMappingURL=index.js.map
@@ -355,36 +355,47 @@ export function createSeedResource(options) {
355
355
  ctx.body = Array.isArray(processedBody) ? createdResources : createdResources[0];
356
356
  };
357
357
  }
358
+ async function deleteResourcesRecursively(type, app, options, context) {
359
+ const { deleteAppResource, getAppResources } = options;
360
+ const referencingResources = Object.entries(app.definition.resources).filter(([, resourceDefinition]) => {
361
+ var _a;
362
+ return Object.values((_a = resourceDefinition.references) !== null && _a !== void 0 ? _a : {}).find((resourceReference) => resourceReference.resource === type);
363
+ });
364
+ for (const [referencingResourceType] of referencingResources) {
365
+ await deleteResourcesRecursively(referencingResourceType, app, options, context);
366
+ }
367
+ const resourcesToDeleteFindOptions = {
368
+ where: {
369
+ type,
370
+ AppId: app.id,
371
+ or: [{ seed: true }, { ephemeral: true }],
372
+ },
373
+ };
374
+ const resourcesToDelete = await getAppResources({
375
+ app,
376
+ findOptions: resourcesToDeleteFindOptions,
377
+ type,
378
+ context,
379
+ });
380
+ for (const resourceToDelete of resourcesToDelete) {
381
+ await deleteAppResource({
382
+ app,
383
+ context,
384
+ options,
385
+ id: resourceToDelete.id,
386
+ type,
387
+ });
388
+ }
389
+ }
358
390
  export function createDeleteSeedResources(options) {
359
391
  return async (ctx) => {
360
392
  var _a;
361
393
  const { pathParams: { appId }, } = ctx;
362
- const { deleteAppResource, getApp, getAppResources } = options;
394
+ const { getApp } = options;
363
395
  const app = await getApp({ context: ctx, query: { where: { id: appId } } });
364
396
  assertKoaError(!app, ctx, 404, 'App not found');
365
397
  for (const resourceType of Object.keys((_a = app.definition.resources) !== null && _a !== void 0 ? _a : {})) {
366
- const resourcesToDeleteFindOptions = {
367
- where: {
368
- type: resourceType,
369
- AppId: appId,
370
- or: [{ seed: true }, { ephemeral: true }],
371
- },
372
- };
373
- const resourcesToDelete = await getAppResources({
374
- app,
375
- findOptions: resourcesToDeleteFindOptions,
376
- type: resourceType,
377
- context: ctx,
378
- });
379
- for (const resourceToDelete of resourcesToDelete) {
380
- await deleteAppResource({
381
- app,
382
- context: ctx,
383
- options,
384
- id: resourceToDelete.id,
385
- type: resourceType,
386
- });
387
- }
398
+ await deleteResourcesRecursively(resourceType, app, options, ctx);
388
399
  }
389
400
  };
390
401
  }
package/server/types.d.ts CHANGED
@@ -58,7 +58,6 @@ declare module 'koas-security' {
58
58
  declare module 'koas-parameters' {
59
59
  interface PathParams {
60
60
  appId: number;
61
- appPath: string;
62
61
  appCollectionId: number;
63
62
  appOAuth2SecretId: number;
64
63
  appSamlSecretId: number;
@@ -133,6 +132,9 @@ export interface GetAppSubEntityParams {
133
132
  context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
134
133
  app: App;
135
134
  }
135
+ export interface GetAppVariablesParams extends GetAppSubEntityParams {
136
+ query?: Record<string, any>;
137
+ }
136
138
  export interface GetAppMessagesParams extends GetAppSubEntityParams {
137
139
  language?: string;
138
140
  merge?: string[] | string;
@@ -386,6 +388,6 @@ export interface Options {
386
388
  deleteAppAsset: (params: DeleteAppAssetParams) => Promise<number>;
387
389
  email: (params: EmailParams) => Promise<void>;
388
390
  sendNotifications: (params: SendNotificationsParams) => Promise<void>;
389
- getAppVariables: (params: GetAppSubEntityParams) => Promise<AppConfigEntry[]>;
391
+ getAppVariables: (params: GetAppVariablesParams) => Promise<AppConfigEntry[]>;
390
392
  }
391
393
  export {};