@appsemble/node-utils 0.27.10 → 0.27.12
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 +3 -3
- package/app.js +8 -1
- package/package.json +3 -3
- package/server/controllers/resources.test.js +9 -0
- package/server/types.d.ts +5 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#  Appsemble Node Utilities
|
|
2
2
|
|
|
3
3
|
> NodeJS utilities used by Appsemble internally.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/node-utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.27.12)
|
|
7
7
|
[](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.27.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.27.12/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
package/app.js
CHANGED
|
@@ -27,13 +27,14 @@ const getPluralRules = memoize((locale, opts) => new Intl.PluralRules(locale, op
|
|
|
27
27
|
*/
|
|
28
28
|
export async function getRemapperContext(app, language, userInfo, options, context) {
|
|
29
29
|
var _a, _b;
|
|
30
|
-
const { getAppMessages, getAppUrl } = options;
|
|
30
|
+
const { getAppMessages, getAppUrl, getAppVariables } = options;
|
|
31
31
|
const appUrl = String(await getAppUrl({ context, app }));
|
|
32
32
|
const appMessages = await getAppMessages({
|
|
33
33
|
app,
|
|
34
34
|
context,
|
|
35
35
|
language,
|
|
36
36
|
});
|
|
37
|
+
const appVariables = await getAppVariables({ context, app });
|
|
37
38
|
const cache = objectCache((message) => new IntlMessageFormat(message, language, undefined, {
|
|
38
39
|
formatters: {
|
|
39
40
|
// @ts-expect-error intl-messageformat types are wrong
|
|
@@ -51,6 +52,10 @@ export async function getRemapperContext(app, language, userInfo, options, conte
|
|
|
51
52
|
const message = msg ? msg.messages.messageIds[id] : defaultMessage;
|
|
52
53
|
return cache(message || `'{${id}}'`);
|
|
53
54
|
},
|
|
55
|
+
getVariable(variableName) {
|
|
56
|
+
var _a;
|
|
57
|
+
return (_a = appVariables.find((appVariable) => appVariable.name === variableName)) === null || _a === void 0 ? void 0 : _a.value;
|
|
58
|
+
},
|
|
54
59
|
userInfo,
|
|
55
60
|
appMember: userInfo === null || userInfo === void 0 ? void 0 : userInfo.appMember,
|
|
56
61
|
context: {},
|
|
@@ -229,10 +234,12 @@ export async function applyAppVariant(appPath, appVariant) {
|
|
|
229
234
|
await copy(appPath, appVariantDestDir);
|
|
230
235
|
logger.verbose(`Successfully copied app files to ${appVariantDestDir}`);
|
|
231
236
|
const appVariantDefDir = join(appPath, 'variants', appVariant);
|
|
237
|
+
await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'config');
|
|
232
238
|
await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'assets');
|
|
233
239
|
await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'resources');
|
|
234
240
|
await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'screenshots');
|
|
235
241
|
await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'icon.png');
|
|
242
|
+
await transferAppVariantFiles(appPath, appVariantDefDir, appVariantDestDir, 'maskable-icon.png');
|
|
236
243
|
await transferReadmes(appPath, appVariantDefDir, appVariantDestDir);
|
|
237
244
|
const patchesPath = join(appVariantDefDir, 'patches');
|
|
238
245
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/node-utils",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.12",
|
|
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.27.
|
|
42
|
-
"@appsemble/utils": "0.27.
|
|
41
|
+
"@appsemble/types": "0.27.12",
|
|
42
|
+
"@appsemble/utils": "0.27.12",
|
|
43
43
|
"@formatjs/fast-memoize": "^2.0.0",
|
|
44
44
|
"@fortawesome/fontawesome-free": "^6.0.0",
|
|
45
45
|
"@koa/cors": "^4.0.0",
|
|
@@ -10,6 +10,7 @@ let mockVerifyResourceActionPermission;
|
|
|
10
10
|
let mockParseQuery;
|
|
11
11
|
let mockGetAppUrl;
|
|
12
12
|
let mockGetAppMessages;
|
|
13
|
+
let mockGetAppVariables;
|
|
13
14
|
let mockCreateAppResourcesWithAssets;
|
|
14
15
|
let mockGetAppAssets;
|
|
15
16
|
let mockCtx;
|
|
@@ -22,6 +23,7 @@ describe('createQueryResources', () => {
|
|
|
22
23
|
mockParseQuery = vi.fn();
|
|
23
24
|
mockGetAppUrl = vi.fn();
|
|
24
25
|
mockGetAppMessages = vi.fn();
|
|
26
|
+
mockGetAppVariables = vi.fn();
|
|
25
27
|
mockCtx = {
|
|
26
28
|
pathParams: { appId: 1, resourceType: 'mockResourceType' },
|
|
27
29
|
queryParams: { $select: 'field1, field2', $skip: 0, $top: 10 },
|
|
@@ -161,11 +163,13 @@ describe('createQueryResources', () => {
|
|
|
161
163
|
};
|
|
162
164
|
const mockAppUrl = new URL('https://localhost');
|
|
163
165
|
const mockAppMessages = [{ language: 'eng', messages: {} }];
|
|
166
|
+
const mockAppVariables = [{ name: 'variable', value: 'variable' }];
|
|
164
167
|
mockGetApp.mockResolvedValue(mockApp);
|
|
165
168
|
mockGetAppResources.mockResolvedValue(mockResources);
|
|
166
169
|
mockParseQuery.mockReturnValue(mockParsedQuery);
|
|
167
170
|
mockGetAppUrl.mockResolvedValue(mockAppUrl);
|
|
168
171
|
mockGetAppMessages.mockResolvedValue(mockAppMessages);
|
|
172
|
+
mockGetAppVariables.mockResolvedValue(mockAppVariables);
|
|
169
173
|
mockCtx.queryParams.view = 'view';
|
|
170
174
|
const options = {
|
|
171
175
|
getApp: mockGetApp,
|
|
@@ -174,6 +178,7 @@ describe('createQueryResources', () => {
|
|
|
174
178
|
parseQuery: mockParseQuery,
|
|
175
179
|
getAppUrl: mockGetAppUrl,
|
|
176
180
|
getAppMessages: mockGetAppMessages,
|
|
181
|
+
getAppVariables: mockGetAppVariables,
|
|
177
182
|
};
|
|
178
183
|
const resourceDefinition = getResourceDefinition(mockApp, 'mockResourceType', mockCtx, 'view');
|
|
179
184
|
const remapperContext = await getRemapperContext(mockApp, mockApp.definition.defaultLanguage || defaultLocale, null, options, mockCtx);
|
|
@@ -305,6 +310,7 @@ describe('createGetResourceById', () => {
|
|
|
305
310
|
mockVerifyResourceActionPermission = vi.fn();
|
|
306
311
|
mockGetAppUrl = vi.fn();
|
|
307
312
|
mockGetAppMessages = vi.fn();
|
|
313
|
+
mockGetAppVariables = vi.fn();
|
|
308
314
|
mockCtx = {
|
|
309
315
|
pathParams: { appId: 1, resourceId: 1, resourceType: 'mockResourceType' },
|
|
310
316
|
user: { id: 'mockUserId', name: 'John Doe', primaryEmail: 'john@example.com' },
|
|
@@ -403,10 +409,12 @@ describe('createGetResourceById', () => {
|
|
|
403
409
|
const mockResource = { id: 1 };
|
|
404
410
|
const mockAppUrl = new URL('https://localhost');
|
|
405
411
|
const mockAppMessages = [{ language: 'eng', messages: {} }];
|
|
412
|
+
const mockAppVariables = [{ name: 'variable', value: 'variable' }];
|
|
406
413
|
mockGetApp.mockResolvedValue(mockApp);
|
|
407
414
|
mockGetAppResource.mockResolvedValue(mockResource);
|
|
408
415
|
mockGetAppUrl.mockResolvedValue(mockAppUrl);
|
|
409
416
|
mockGetAppMessages.mockResolvedValue(mockAppMessages);
|
|
417
|
+
mockGetAppVariables.mockResolvedValue(mockAppVariables);
|
|
410
418
|
mockCtx.queryParams = { view: 'view' };
|
|
411
419
|
const options = {
|
|
412
420
|
getApp: mockGetApp,
|
|
@@ -414,6 +422,7 @@ describe('createGetResourceById', () => {
|
|
|
414
422
|
verifyResourceActionPermission: mockVerifyResourceActionPermission,
|
|
415
423
|
getAppUrl: mockGetAppUrl,
|
|
416
424
|
getAppMessages: mockGetAppMessages,
|
|
425
|
+
getAppVariables: mockGetAppVariables,
|
|
417
426
|
};
|
|
418
427
|
const resourceDefinition = getResourceDefinition(mockApp, 'mockResourceType', mockCtx, 'view');
|
|
419
428
|
const remapperContext = await getRemapperContext(mockApp, mockApp.definition.defaultLanguage || defaultLocale, null, options, mockCtx);
|
package/server/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { type App, type AppMember, type AppMessages, type Asset, type BlockDefinition, type BlockManifest, type ControllerDefinition, type EmailActionDefinition, type Resource, type ResourceDefinition, type TeamMember, type Theme as ThemeType, type UserInfo } from '@appsemble/types';
|
|
2
|
+
import { type App, type AppConfigEntry, type AppMember, type AppMessages, type Asset, type BlockDefinition, type BlockManifest, type ControllerDefinition, type EmailActionDefinition, type Resource, type ResourceDefinition, type TeamMember, type Theme as ThemeType, type UserInfo } from '@appsemble/types';
|
|
3
3
|
import { type IdentifiableBlock, type Permission } from '@appsemble/utils';
|
|
4
4
|
import { type RawAxiosRequestConfig } from 'axios';
|
|
5
5
|
import { type Context, type DefaultContext as DefaultContextInterface, type DefaultState, type ParameterizedContext } from 'koa';
|
|
@@ -24,6 +24,7 @@ declare module 'koa' {
|
|
|
24
24
|
appsembleApp: App;
|
|
25
25
|
appBlocks: BlockManifest[];
|
|
26
26
|
appMessages: AppMessages[];
|
|
27
|
+
appVariables: AppConfigEntry[];
|
|
27
28
|
appMembers: AppMember[];
|
|
28
29
|
appUserInfo: UserInfo;
|
|
29
30
|
appTeams: ExtendedTeam[];
|
|
@@ -79,6 +80,8 @@ declare module 'koas-parameters' {
|
|
|
79
80
|
teamId: string;
|
|
80
81
|
token: string;
|
|
81
82
|
appServiceId: number;
|
|
83
|
+
appSecretId: number;
|
|
84
|
+
appVariableId: number;
|
|
82
85
|
userId: string;
|
|
83
86
|
memberEmail: string;
|
|
84
87
|
trainingBlockId: number;
|
|
@@ -380,5 +383,6 @@ export interface Options {
|
|
|
380
383
|
deleteAppAsset: (params: DeleteAppAssetParams) => Promise<number>;
|
|
381
384
|
email: (params: EmailParams) => Promise<void>;
|
|
382
385
|
sendNotifications: (params: SendNotificationsParams) => Promise<void>;
|
|
386
|
+
getAppVariables: (params: GetAppSubEntityParams) => Promise<AppConfigEntry[]>;
|
|
383
387
|
}
|
|
384
388
|
export {};
|