@appsemble/node-utils 0.24.12 → 0.25.0

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.12/config/assets/logo.svg) Appsemble Node Utilities
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.25.0/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.12/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.24.12)
6
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.25.0/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.25.0)
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.12/LICENSE.md) ©
29
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.25.0/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.24.12",
3
+ "version": "0.25.0",
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.12",
42
- "@appsemble/utils": "0.24.12",
41
+ "@appsemble/types": "0.25.0",
42
+ "@appsemble/utils": "0.25.0",
43
43
  "@formatjs/fast-memoize": "^2.0.0",
44
44
  "@fortawesome/fontawesome-free": "^6.0.0",
45
45
  "@koa/cors": "^4.0.0",
@@ -73,6 +73,10 @@ async function handleRequestProxy(ctx, app, action, useBody, options) {
73
73
  email_verified: Boolean((_b = (_a = user.EmailAuthorizations) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.verified),
74
74
  zoneinfo: user.timezone,
75
75
  }, options, ctx);
76
+ const proxyUrl = new URL(String(remap(action.url, data, remapperContext)));
77
+ if (/\/api\/apps\/\d+\/action\/.*/.test(proxyUrl.pathname) && ctx.URL.host === proxyUrl.host) {
78
+ throwKoaError(ctx, 400, 'Not allowed to make direct requests to the Appsemble action controller using this action.');
79
+ }
76
80
  let params;
77
81
  try {
78
82
  if (query.params) {
@@ -84,7 +88,7 @@ async function handleRequestProxy(ctx, app, action, useBody, options) {
84
88
  }
85
89
  let axiosConfig = {
86
90
  method: (_c = action.method) !== null && _c !== void 0 ? _c : 'GET',
87
- url: String(remap(action.url, data, remapperContext)),
91
+ url: String(proxyUrl),
88
92
  params,
89
93
  responseType: 'arraybuffer',
90
94
  headers: {},
@@ -1,3 +1,5 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { isDeepStrictEqual } from 'node:util';
1
3
  import { assertKoaError, getRemapperContext, getResourceDefinition, logger, processResourceBody, throwKoaError, } from '@appsemble/node-utils';
2
4
  import { defaultLocale, remap } from '@appsemble/utils';
3
5
  function generateQuery(ctx, { parseQuery }) {
@@ -178,23 +180,37 @@ export function createCreateResource(options) {
178
180
  // If the app has already been seeded, only new ephemeral resources are created,
179
181
  // processed from the request body.
180
182
  if (app.demoMode) {
181
- if (!resourceSeeded) {
183
+ if (!resourceSeeded && app.seed) {
184
+ const preparedSeedAssets = structuredClone(preparedAssets);
185
+ const preparedSeedResources = resources.map((resource) => {
186
+ var _a;
187
+ const cleanResource = { ...resource };
188
+ for (const referencedProperty of Object.keys((_a = resourceDefinition.references) !== null && _a !== void 0 ? _a : {})) {
189
+ delete cleanResource[referencedProperty];
190
+ }
191
+ return {
192
+ ...cleanResource,
193
+ $seed: true,
194
+ $ephemeral: false,
195
+ };
196
+ });
197
+ for (const preparedSeedAsset of preparedSeedAssets) {
198
+ const index = resources.findIndex(({ $clonable: clonable, $ephemeral: ephemeral, $seed: seed, ...cleanResource }) => {
199
+ const { $clonable, $ephemeral, $seed, ...cleanAssetResource } = preparedSeedAsset.resource;
200
+ return isDeepStrictEqual(cleanResource, cleanAssetResource);
201
+ });
202
+ const previousAssetId = preparedSeedAsset.id;
203
+ const newAssetId = randomUUID();
204
+ const updatedResource = JSON.parse(JSON.stringify(preparedSeedResources[index]).replace(previousAssetId, newAssetId));
205
+ preparedSeedAsset.id = newAssetId;
206
+ preparedSeedAsset.resource = updatedResource;
207
+ preparedSeedResources[index] = updatedResource;
208
+ }
182
209
  await createAppResourcesWithAssets({
183
210
  app,
184
211
  context: ctx,
185
- resources: resources.map((resource) => {
186
- var _a;
187
- const cleanResource = { ...resource };
188
- for (const referencedProperty of Object.keys((_a = resourceDefinition.references) !== null && _a !== void 0 ? _a : {})) {
189
- delete cleanResource[referencedProperty];
190
- }
191
- return {
192
- ...cleanResource,
193
- $seed: true,
194
- $ephemeral: false,
195
- };
196
- }),
197
- preparedAssets,
212
+ resources: preparedSeedResources,
213
+ preparedAssets: preparedSeedAssets,
198
214
  resourceType,
199
215
  action,
200
216
  options,