@appsemble/node-utils 0.20.44 → 0.21.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 +3 -3
- package/app.d.ts +17 -0
- package/app.js +49 -0
- package/csv.d.ts +2 -0
- package/csv.js +55 -0
- package/fs.d.ts +3 -3
- package/fs.test.js +5 -5
- package/getAppsembleMessages.d.ts +9 -0
- package/getAppsembleMessages.js +32 -0
- package/handleError.test.js +4 -4
- package/icon.d.ts +44 -0
- package/icon.js +69 -0
- package/index.d.ts +22 -1
- package/index.js +22 -1
- package/interceptors.test.js +5 -6
- package/jsonschema.d.ts +2 -0
- package/jsonschema.js +7 -0
- package/koa.d.ts +6 -0
- package/koa.js +27 -0
- package/logger.js +3 -0
- package/mergeMessages.d.ts +9 -0
- package/mergeMessages.js +17 -0
- package/middleware/boom.d.ts +7 -0
- package/middleware/boom.js +32 -0
- package/middleware/boom.test.js +58 -0
- package/middleware/conditional.d.ts +2 -0
- package/middleware/conditional.js +9 -0
- package/middleware/frontend.d.ts +3 -0
- package/middleware/frontend.js +40 -0
- package/{loggerMiddleware.js → middleware/loggerMiddleware.js} +1 -1
- package/{loggerMiddleware.test.js → middleware/loggerMiddleware.test.js} +14 -15
- package/odata.d.ts +18 -0
- package/odata.js +45 -0
- package/organizationBlocklist.d.ts +4 -0
- package/organizationBlocklist.js +5 -0
- package/package.json +41 -4
- package/parsers.d.ts +3 -0
- package/parsers.js +18 -0
- package/readAsset.d.ts +13 -0
- package/readAsset.js +6 -0
- package/readFileOrString.d.ts +1 -1
- package/render.d.ts +21 -0
- package/render.js +46 -0
- package/resource.d.ts +43 -0
- package/resource.js +172 -0
- package/scim.d.ts +26 -0
- package/scim.js +32 -0
- package/server/controllers/action.d.ts +7 -0
- package/server/controllers/action.js +129 -0
- package/server/controllers/appMembers.d.ts +3 -0
- package/server/controllers/appMembers.js +19 -0
- package/server/controllers/appMessages.d.ts +3 -0
- package/server/controllers/appMessages.js +75 -0
- package/server/controllers/assets.d.ts +5 -0
- package/server/controllers/assets.js +74 -0
- package/server/controllers/index.d.ts +7 -0
- package/server/controllers/index.js +8 -0
- package/server/controllers/oauth2Provider.d.ts +3 -0
- package/server/controllers/oauth2Provider.js +7 -0
- package/server/controllers/resources.d.ts +8 -0
- package/server/controllers/resources.js +273 -0
- package/server/controllers/resources.test.d.ts +1 -0
- package/server/controllers/resources.test.js +552 -0
- package/server/controllers/teams.d.ts +3 -0
- package/server/controllers/teams.js +12 -0
- package/server/routes/appRouter/blockAssetHandler.d.ts +3 -0
- package/server/routes/appRouter/blockAssetHandler.js +13 -0
- package/server/routes/appRouter/blockCssHandler.d.ts +3 -0
- package/server/routes/appRouter/blockCssHandler.js +15 -0
- package/server/routes/appRouter/bulmaHandler.d.ts +3 -0
- package/server/routes/appRouter/bulmaHandler.js +116 -0
- package/server/routes/appRouter/cssHandler.d.ts +3 -0
- package/server/routes/appRouter/cssHandler.js +12 -0
- package/server/routes/appRouter/iconHandler.d.ts +3 -0
- package/server/routes/appRouter/iconHandler.js +23 -0
- package/server/routes/appRouter/index.d.ts +3 -0
- package/server/routes/appRouter/index.js +85 -0
- package/server/routes/appRouter/indexHandler.d.ts +5 -0
- package/server/routes/appRouter/indexHandler.js +69 -0
- package/server/routes/appRouter/manifestHandler.d.ts +3 -0
- package/server/routes/appRouter/manifestHandler.js +47 -0
- package/server/routes/appRouter/robotsHandler.d.ts +2 -0
- package/server/routes/appRouter/robotsHandler.js +6 -0
- package/server/routes/appRouter/screenshotHandler.d.ts +3 -0
- package/server/routes/appRouter/screenshotHandler.js +19 -0
- package/server/routes/appRouter/serviceWorkerHandler.d.ts +3 -0
- package/server/routes/appRouter/serviceWorkerHandler.js +18 -0
- package/server/routes/appRouter/staticHandler.d.ts +2 -0
- package/server/routes/appRouter/staticHandler.js +9 -0
- package/server/types.d.ts +356 -0
- package/server/types.js +2 -0
- package/testFixtures.d.ts +3 -3
- package/testFixtures.js +1 -1
- package/tinyRouter.d.ts +16 -0
- package/tinyRouter.js +34 -0
- package/tinyRouter.test.d.ts +1 -0
- package/tinyRouter.test.js +85 -0
- package/vitest.config.d.ts +2 -0
- package/vitest.setup.d.ts +1 -0
- package/{jest.setup.js → vitest.setup.js} +1 -1
- /package/{jest.setup.d.ts → middleware/boom.test.d.ts} +0 -0
- /package/{loggerMiddleware.d.ts → middleware/loggerMiddleware.d.ts} +0 -0
- /package/{loggerMiddleware.test.d.ts → middleware/loggerMiddleware.test.d.ts} +0 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { type App, type AppMember, type AppMessages, type Asset, type BlockConfig, type BlockDefinition, type BlockManifest, type EmailActionDefinition, type Resource, type ResourceDefinition, type TeamMember, type Theme as ThemeType, type UserInfo } from '@appsemble/types';
|
|
4
|
+
import { type IdentifiableBlock, type Permission } from '@appsemble/utils';
|
|
5
|
+
import { type RawAxiosRequestConfig } from 'axios';
|
|
6
|
+
import { type DefaultContext as DefaultContextInterface, type DefaultState, type ParameterizedContext } from 'koa';
|
|
7
|
+
export interface UtilsUser {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
primaryEmail: string;
|
|
11
|
+
timezone: string;
|
|
12
|
+
locale: string;
|
|
13
|
+
EmailAuthorizations?: {
|
|
14
|
+
verified: boolean;
|
|
15
|
+
}[];
|
|
16
|
+
}
|
|
17
|
+
declare module 'koa' {
|
|
18
|
+
interface Request {
|
|
19
|
+
body: any;
|
|
20
|
+
}
|
|
21
|
+
interface DefaultContext {
|
|
22
|
+
appHost: string;
|
|
23
|
+
appsembleApp: App;
|
|
24
|
+
appBlocks: BlockManifest[];
|
|
25
|
+
appMessages: AppMessages[];
|
|
26
|
+
appMembers: AppMember[];
|
|
27
|
+
appUserInfo: UserInfo;
|
|
28
|
+
appTeams: ExtendedTeam[];
|
|
29
|
+
appAssets: AppAsset[];
|
|
30
|
+
blockConfigs: ContextBlockConfig[];
|
|
31
|
+
params?: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
declare module 'koas-security' {
|
|
35
|
+
interface Clients {
|
|
36
|
+
app: {
|
|
37
|
+
scope: string;
|
|
38
|
+
app: App;
|
|
39
|
+
};
|
|
40
|
+
basic: {};
|
|
41
|
+
cli: {
|
|
42
|
+
scope: string;
|
|
43
|
+
};
|
|
44
|
+
studio: {};
|
|
45
|
+
}
|
|
46
|
+
interface Users {
|
|
47
|
+
app: UtilsUser;
|
|
48
|
+
basic: UtilsUser;
|
|
49
|
+
cli: UtilsUser;
|
|
50
|
+
scim: UtilsUser;
|
|
51
|
+
studio: UtilsUser;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
declare module 'koas-parameters' {
|
|
55
|
+
interface PathParams {
|
|
56
|
+
appId: number;
|
|
57
|
+
appOAuth2SecretId: number;
|
|
58
|
+
appSamlSecretId: number;
|
|
59
|
+
assetId: string;
|
|
60
|
+
blockId: string;
|
|
61
|
+
blockVersion: string;
|
|
62
|
+
clientId: string;
|
|
63
|
+
language: string;
|
|
64
|
+
memberId: string;
|
|
65
|
+
organizationId: string;
|
|
66
|
+
path: string;
|
|
67
|
+
resourceId: number;
|
|
68
|
+
resourceType: string;
|
|
69
|
+
resourceTypeId: string;
|
|
70
|
+
schemaId: string;
|
|
71
|
+
screenshotId: number;
|
|
72
|
+
snapshotId: number;
|
|
73
|
+
teamId: string;
|
|
74
|
+
token: string;
|
|
75
|
+
appServiceId: number;
|
|
76
|
+
userId: string;
|
|
77
|
+
}
|
|
78
|
+
interface QueryParams {
|
|
79
|
+
domains: string[];
|
|
80
|
+
$filter?: string;
|
|
81
|
+
filter: string;
|
|
82
|
+
$orderby?: string;
|
|
83
|
+
$select: string;
|
|
84
|
+
$top: number;
|
|
85
|
+
$skip: number;
|
|
86
|
+
code: string;
|
|
87
|
+
count: number;
|
|
88
|
+
startIndex: number;
|
|
89
|
+
view: string;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export type Operator = 'and' | 'not' | 'or';
|
|
93
|
+
export type Function = 'gt';
|
|
94
|
+
type Reserved = Function | Operator;
|
|
95
|
+
export type NonReserved<T extends string> = T extends Reserved ? never : T;
|
|
96
|
+
export type WhereOptions = Record<string, any>;
|
|
97
|
+
export type OrderItem = [string, string];
|
|
98
|
+
export interface FindOptions {
|
|
99
|
+
where?: WhereOptions;
|
|
100
|
+
limit?: number;
|
|
101
|
+
offset?: number;
|
|
102
|
+
attributes?: string[];
|
|
103
|
+
order?: OrderItem[];
|
|
104
|
+
include?: any[];
|
|
105
|
+
}
|
|
106
|
+
export interface ContextBlockConfig extends BlockConfig {
|
|
107
|
+
OrganizationId: string;
|
|
108
|
+
}
|
|
109
|
+
export interface GetAppParams {
|
|
110
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
111
|
+
query?: Record<string, any>;
|
|
112
|
+
}
|
|
113
|
+
export interface GetAppSubEntityParams {
|
|
114
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
115
|
+
app: App;
|
|
116
|
+
}
|
|
117
|
+
export interface GetAppMessagesParams extends GetAppSubEntityParams {
|
|
118
|
+
language?: string;
|
|
119
|
+
merge?: string[] | string;
|
|
120
|
+
}
|
|
121
|
+
export interface GetAppMembersParams extends GetAppSubEntityParams {
|
|
122
|
+
memberId: string;
|
|
123
|
+
}
|
|
124
|
+
export interface GetAppUserInfoParams {
|
|
125
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
126
|
+
client: {
|
|
127
|
+
scope: string;
|
|
128
|
+
} | {
|
|
129
|
+
scope: string;
|
|
130
|
+
app: App;
|
|
131
|
+
} | {};
|
|
132
|
+
user: UtilsUser;
|
|
133
|
+
}
|
|
134
|
+
export interface ExtendedTeam extends TeamMember {
|
|
135
|
+
size: number;
|
|
136
|
+
}
|
|
137
|
+
export interface GetAppTeamsParams extends GetAppSubEntityParams {
|
|
138
|
+
user: UtilsUser;
|
|
139
|
+
}
|
|
140
|
+
export interface GetAppBlockStylesParams extends GetAppSubEntityParams {
|
|
141
|
+
name: string;
|
|
142
|
+
}
|
|
143
|
+
export interface GetDbUpdatedParams extends GetAppSubEntityParams {
|
|
144
|
+
maskable: string[] | string | false;
|
|
145
|
+
}
|
|
146
|
+
export type BlockMessages = Pick<BlockManifest, 'messages' | 'name' | 'version'>;
|
|
147
|
+
export type BlockQueryItem = Pick<ContextBlockConfig, 'name' | 'OrganizationId' | 'version'>;
|
|
148
|
+
export interface GetBlockMessagesParams {
|
|
149
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
150
|
+
blockQuery: BlockQueryItem[];
|
|
151
|
+
baseLang: string;
|
|
152
|
+
lang: string;
|
|
153
|
+
}
|
|
154
|
+
export interface GetBlockAssetParams {
|
|
155
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
156
|
+
name: string;
|
|
157
|
+
filename: string;
|
|
158
|
+
version: string;
|
|
159
|
+
}
|
|
160
|
+
export interface GetBlocksAssetsPathsParams {
|
|
161
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
162
|
+
identifiableBlocks: IdentifiableBlock[];
|
|
163
|
+
}
|
|
164
|
+
export type ExtendedTheme = Omit<Partial<ThemeType>, 'font'> & {
|
|
165
|
+
bulmaVersion: string;
|
|
166
|
+
fontFamily: string;
|
|
167
|
+
fontSource: string;
|
|
168
|
+
};
|
|
169
|
+
export interface GetHostParams {
|
|
170
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
171
|
+
}
|
|
172
|
+
export interface GetThemeParams {
|
|
173
|
+
theme: ExtendedTheme;
|
|
174
|
+
}
|
|
175
|
+
export interface CreateThemeParams extends ExtendedTheme {
|
|
176
|
+
css: string;
|
|
177
|
+
}
|
|
178
|
+
export interface CreateSettingsParams {
|
|
179
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
180
|
+
app: App;
|
|
181
|
+
host: string;
|
|
182
|
+
identifiableBlocks: IdentifiableBlock[];
|
|
183
|
+
hostname: string;
|
|
184
|
+
languages: string[];
|
|
185
|
+
}
|
|
186
|
+
export interface GetCspParams {
|
|
187
|
+
app: App;
|
|
188
|
+
host: string;
|
|
189
|
+
hostname: string;
|
|
190
|
+
settingsHash: string;
|
|
191
|
+
nonce: string;
|
|
192
|
+
}
|
|
193
|
+
export type HookAction = 'create' | 'delete' | 'update';
|
|
194
|
+
export type Action = HookAction | 'count' | 'get' | 'patch' | 'query';
|
|
195
|
+
export interface VerifyResourceActionPermissionParams {
|
|
196
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
197
|
+
app: App;
|
|
198
|
+
resourceType: string;
|
|
199
|
+
action: Action;
|
|
200
|
+
options: Options;
|
|
201
|
+
}
|
|
202
|
+
export interface ApplyAppServiceSecretsParams {
|
|
203
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
204
|
+
app: App;
|
|
205
|
+
axiosConfig: RawAxiosRequestConfig<any>;
|
|
206
|
+
}
|
|
207
|
+
export interface CheckRoleParams {
|
|
208
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
209
|
+
app: App;
|
|
210
|
+
permissions: Permission | Permission[];
|
|
211
|
+
findOptions?: FindOptions;
|
|
212
|
+
}
|
|
213
|
+
export interface ReloadUserParams {
|
|
214
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
215
|
+
}
|
|
216
|
+
export interface ParseQueryParams {
|
|
217
|
+
$filter: string;
|
|
218
|
+
$orderby: string;
|
|
219
|
+
}
|
|
220
|
+
export interface GetAppResourceParams extends GetAppSubEntityParams {
|
|
221
|
+
findOptions: FindOptions;
|
|
222
|
+
type: string;
|
|
223
|
+
id: number | string;
|
|
224
|
+
}
|
|
225
|
+
export interface GetAppResourcesParams extends GetAppSubEntityParams {
|
|
226
|
+
findOptions: FindOptions;
|
|
227
|
+
type: string;
|
|
228
|
+
}
|
|
229
|
+
export interface PreparedAsset extends Pick<Asset, 'filename' | 'id' | 'mime'> {
|
|
230
|
+
data: Buffer;
|
|
231
|
+
resource?: Record<string, unknown>;
|
|
232
|
+
}
|
|
233
|
+
export interface CreateAppResourcesWithAssetsParams extends GetAppSubEntityParams {
|
|
234
|
+
resources: Record<string, unknown>[];
|
|
235
|
+
preparedAssets: PreparedAsset[];
|
|
236
|
+
resourceType: string;
|
|
237
|
+
action: HookAction;
|
|
238
|
+
options: Options;
|
|
239
|
+
}
|
|
240
|
+
export interface UpdateAppResourceParams extends GetAppSubEntityParams {
|
|
241
|
+
id: number | string;
|
|
242
|
+
resource: Record<string, unknown>;
|
|
243
|
+
preparedAssets: PreparedAsset[];
|
|
244
|
+
resourceDefinition: ResourceDefinition;
|
|
245
|
+
deletedAssetIds: string[];
|
|
246
|
+
type: string;
|
|
247
|
+
options: Options;
|
|
248
|
+
action: HookAction;
|
|
249
|
+
}
|
|
250
|
+
export interface DeleteAppResourceParams extends GetAppSubEntityParams {
|
|
251
|
+
id: number | string;
|
|
252
|
+
type: string;
|
|
253
|
+
whereOptions?: WhereOptions;
|
|
254
|
+
action: HookAction;
|
|
255
|
+
options: Options;
|
|
256
|
+
}
|
|
257
|
+
export interface CreateAppAssetParams extends GetAppSubEntityParams {
|
|
258
|
+
payload: {
|
|
259
|
+
filename: string;
|
|
260
|
+
mime: string;
|
|
261
|
+
name: string;
|
|
262
|
+
data: Buffer;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
export interface DeleteAppAssetParams extends GetAppSubEntityParams {
|
|
266
|
+
id: string;
|
|
267
|
+
transaction?: any;
|
|
268
|
+
}
|
|
269
|
+
export interface EmailParams {
|
|
270
|
+
action: EmailActionDefinition;
|
|
271
|
+
data: any;
|
|
272
|
+
mailer: any;
|
|
273
|
+
user: any;
|
|
274
|
+
options: Options;
|
|
275
|
+
context: ParameterizedContext<DefaultState, DefaultContextInterface, any>;
|
|
276
|
+
}
|
|
277
|
+
export interface SendNotificationsParams {
|
|
278
|
+
app: App;
|
|
279
|
+
to: string;
|
|
280
|
+
title: string;
|
|
281
|
+
body: string;
|
|
282
|
+
}
|
|
283
|
+
export interface AppDetails {
|
|
284
|
+
appPath: string;
|
|
285
|
+
organizationId: string;
|
|
286
|
+
}
|
|
287
|
+
export interface AppStyles {
|
|
288
|
+
coreStyle: string | undefined;
|
|
289
|
+
sharedStyle: string | undefined;
|
|
290
|
+
}
|
|
291
|
+
export interface AppScreenshot {
|
|
292
|
+
id: number;
|
|
293
|
+
mime: string;
|
|
294
|
+
screenshot: Buffer;
|
|
295
|
+
height: number;
|
|
296
|
+
width: number;
|
|
297
|
+
}
|
|
298
|
+
export interface AppBlockStyle {
|
|
299
|
+
style: string;
|
|
300
|
+
}
|
|
301
|
+
export interface AppAsset extends Asset {
|
|
302
|
+
data: Buffer;
|
|
303
|
+
}
|
|
304
|
+
export interface BlockAsset {
|
|
305
|
+
mime: string;
|
|
306
|
+
content: Buffer;
|
|
307
|
+
}
|
|
308
|
+
export interface Block extends BlockDefinition {
|
|
309
|
+
OrganizationId: string;
|
|
310
|
+
}
|
|
311
|
+
export interface Theme {
|
|
312
|
+
css: string;
|
|
313
|
+
}
|
|
314
|
+
export interface ParsedQuery {
|
|
315
|
+
order: OrderItem[];
|
|
316
|
+
where: WhereOptions;
|
|
317
|
+
}
|
|
318
|
+
export type ContentSecurityPolicy = Record<string, (string | false)[]>;
|
|
319
|
+
export interface Options {
|
|
320
|
+
getApp: (params: GetAppParams) => Promise<App>;
|
|
321
|
+
getAppDetails: (params: GetAppParams) => Promise<AppDetails>;
|
|
322
|
+
getAppMessages: (params: GetAppMessagesParams) => Promise<AppMessages[]>;
|
|
323
|
+
getAppMembers: (params: GetAppMembersParams) => Promise<AppMember[]>;
|
|
324
|
+
getAppUserInfo: (params: GetAppUserInfoParams) => Promise<UserInfo>;
|
|
325
|
+
getAppTeams: (params: GetAppTeamsParams) => Promise<ExtendedTeam[]>;
|
|
326
|
+
getAppStyles: (params: GetAppParams | GetAppSubEntityParams) => Promise<AppStyles>;
|
|
327
|
+
getAppScreenshots: (params: GetAppSubEntityParams) => Promise<AppScreenshot[]>;
|
|
328
|
+
getAppBlockStyles: (params: GetAppBlockStylesParams) => Promise<AppBlockStyle[]>;
|
|
329
|
+
getAppIcon: (params: GetAppSubEntityParams) => Promise<Buffer>;
|
|
330
|
+
getAppUrl: (params: GetAppSubEntityParams) => Promise<URL>;
|
|
331
|
+
getDbUpdated: (params: GetDbUpdatedParams) => Promise<Date | number>;
|
|
332
|
+
getBlockMessages: (params: GetBlockMessagesParams) => Promise<BlockMessages[]>;
|
|
333
|
+
getBlockAsset: (params: GetBlockAssetParams) => Promise<BlockAsset>;
|
|
334
|
+
getBlocksAssetsPaths: (params: GetBlocksAssetsPathsParams) => Promise<string[]>;
|
|
335
|
+
getTheme: (params: GetThemeParams) => Promise<Theme>;
|
|
336
|
+
createTheme: (params: CreateThemeParams) => Promise<Theme>;
|
|
337
|
+
getHost: (params: GetHostParams) => string;
|
|
338
|
+
getCsp: (params: GetCspParams) => ContentSecurityPolicy;
|
|
339
|
+
createSettings: (params: CreateSettingsParams) => Promise<[digest: string, script: string]>;
|
|
340
|
+
verifyResourceActionPermission: (params: VerifyResourceActionPermissionParams) => Promise<Record<string, any>>;
|
|
341
|
+
applyAppServiceSecrets: (params: ApplyAppServiceSecretsParams) => Promise<RawAxiosRequestConfig<any>>;
|
|
342
|
+
checkRole: (params: CheckRoleParams) => Promise<Record<string, any>>;
|
|
343
|
+
reloadUser: (params: ReloadUserParams) => Promise<Record<string, any>>;
|
|
344
|
+
parseQuery: (params: ParseQueryParams) => ParsedQuery;
|
|
345
|
+
getAppResource: (params: GetAppResourceParams) => Promise<Resource>;
|
|
346
|
+
getAppResources: (params: GetAppResourcesParams) => Promise<Resource[]>;
|
|
347
|
+
createAppResourcesWithAssets: (params: CreateAppResourcesWithAssetsParams) => Promise<Resource[]>;
|
|
348
|
+
updateAppResource: (params: UpdateAppResourceParams) => Promise<Resource | null>;
|
|
349
|
+
deleteAppResource: (params: DeleteAppResourceParams) => Promise<void>;
|
|
350
|
+
getAppAssets: (params: GetAppSubEntityParams) => Promise<AppAsset[]>;
|
|
351
|
+
createAppAsset: (params: CreateAppAssetParams) => Promise<AppAsset>;
|
|
352
|
+
deleteAppAsset: (params: DeleteAppAssetParams) => Promise<number>;
|
|
353
|
+
email: (params: EmailParams) => Promise<void>;
|
|
354
|
+
sendNotifications: (params: SendNotificationsParams) => Promise<void>;
|
|
355
|
+
}
|
|
356
|
+
export {};
|
package/server/types.js
ADDED
package/testFixtures.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import { type ReadStream } from 'node:fs';
|
|
4
4
|
/**
|
|
5
5
|
* Set the test fixture base path. This folder should contain a folder named `__fixtures__`.
|
|
6
6
|
*
|
|
7
|
-
* This is typically called in `
|
|
7
|
+
* This is typically called in `vitest.setup.ts`.
|
|
8
8
|
*
|
|
9
9
|
* @param meta The module meta object
|
|
10
10
|
* @example
|
package/testFixtures.js
CHANGED
|
@@ -5,7 +5,7 @@ let baseDir;
|
|
|
5
5
|
/**
|
|
6
6
|
* Set the test fixture base path. This folder should contain a folder named `__fixtures__`.
|
|
7
7
|
*
|
|
8
|
-
* This is typically called in `
|
|
8
|
+
* This is typically called in `vitest.setup.ts`.
|
|
9
9
|
*
|
|
10
10
|
* @param meta The module meta object
|
|
11
11
|
* @example
|
package/tinyRouter.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Middleware } from 'koa';
|
|
2
|
+
type HttpMethod = 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put';
|
|
3
|
+
type Route = {
|
|
4
|
+
[method in HttpMethod]?: Middleware;
|
|
5
|
+
} & {
|
|
6
|
+
route: RegExp | string;
|
|
7
|
+
any?: Middleware;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A tiny dynamic router middleware for GET requests.
|
|
11
|
+
*
|
|
12
|
+
* @param routes The routes to serve.
|
|
13
|
+
* @returns Middleware that serves middleware matching the route regex.
|
|
14
|
+
*/
|
|
15
|
+
export declare function tinyRouter(routes: Route[]): Middleware;
|
|
16
|
+
export {};
|
package/tinyRouter.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { has } from '@appsemble/utils';
|
|
2
|
+
import { methodNotAllowed } from '@hapi/boom';
|
|
3
|
+
/**
|
|
4
|
+
* A tiny dynamic router middleware for GET requests.
|
|
5
|
+
*
|
|
6
|
+
* @param routes The routes to serve.
|
|
7
|
+
* @returns Middleware that serves middleware matching the route regex.
|
|
8
|
+
*/
|
|
9
|
+
export function tinyRouter(routes) {
|
|
10
|
+
return (ctx, next) => {
|
|
11
|
+
const { method, path } = ctx;
|
|
12
|
+
let match;
|
|
13
|
+
const result = routes.find(({ route }) => {
|
|
14
|
+
if (typeof route === 'string') {
|
|
15
|
+
return path === route;
|
|
16
|
+
}
|
|
17
|
+
match = path.match(route);
|
|
18
|
+
return match;
|
|
19
|
+
});
|
|
20
|
+
if (!result) {
|
|
21
|
+
return next();
|
|
22
|
+
}
|
|
23
|
+
let m = method.toLowerCase();
|
|
24
|
+
if (!has(result, m)) {
|
|
25
|
+
if (!has(result, 'any')) {
|
|
26
|
+
throw methodNotAllowed();
|
|
27
|
+
}
|
|
28
|
+
m = 'any';
|
|
29
|
+
}
|
|
30
|
+
ctx.params = (match === null || match === void 0 ? void 0 : match.groups) ? { ...match.groups } : null;
|
|
31
|
+
return result[m](ctx, next);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=tinyRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { noop } from '@appsemble/utils';
|
|
2
|
+
import { request, setTestApp } from 'axios-test-instance';
|
|
3
|
+
import Koa from 'koa';
|
|
4
|
+
import { tinyRouter } from './tinyRouter.js';
|
|
5
|
+
let app;
|
|
6
|
+
let context;
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
app = new Koa();
|
|
9
|
+
app.silent = true;
|
|
10
|
+
app.use((ctx, next) => {
|
|
11
|
+
context = ctx;
|
|
12
|
+
return next();
|
|
13
|
+
});
|
|
14
|
+
await setTestApp(app);
|
|
15
|
+
});
|
|
16
|
+
it('should assign the match group to params', async () => {
|
|
17
|
+
app.use(tinyRouter([
|
|
18
|
+
{
|
|
19
|
+
route: /^\/(?<foo>.+)\/(?<bar>.+)/,
|
|
20
|
+
get: noop,
|
|
21
|
+
},
|
|
22
|
+
]));
|
|
23
|
+
await request.get('/1/2');
|
|
24
|
+
expect(context.params).toStrictEqual({ foo: '1', bar: '2' });
|
|
25
|
+
});
|
|
26
|
+
it('should throw method not allowed if a URL is matched, but not for the given method', async () => {
|
|
27
|
+
let error;
|
|
28
|
+
app.on('error', (err) => {
|
|
29
|
+
error = err;
|
|
30
|
+
});
|
|
31
|
+
app.use(tinyRouter([
|
|
32
|
+
{
|
|
33
|
+
route: '/',
|
|
34
|
+
get: noop,
|
|
35
|
+
},
|
|
36
|
+
]));
|
|
37
|
+
await request.post('/');
|
|
38
|
+
expect(error.isBoom).toBe(true);
|
|
39
|
+
expect(error.output.statusCode).toBe(405);
|
|
40
|
+
});
|
|
41
|
+
it('should fall back to the any handler if it exists', async () => {
|
|
42
|
+
const any = vi.fn();
|
|
43
|
+
app.use(tinyRouter([
|
|
44
|
+
{
|
|
45
|
+
route: '/',
|
|
46
|
+
any,
|
|
47
|
+
},
|
|
48
|
+
]));
|
|
49
|
+
await request.post('/');
|
|
50
|
+
expect(any).toHaveBeenCalledWith(context, expect.any(Function));
|
|
51
|
+
});
|
|
52
|
+
it('should pick method specific middleware over any', async () => {
|
|
53
|
+
const any = vi.fn();
|
|
54
|
+
const get = vi.fn();
|
|
55
|
+
app.use(tinyRouter([
|
|
56
|
+
{
|
|
57
|
+
route: '/',
|
|
58
|
+
any,
|
|
59
|
+
get,
|
|
60
|
+
},
|
|
61
|
+
]));
|
|
62
|
+
await request.get('/');
|
|
63
|
+
expect(any).not.toHaveBeenCalled();
|
|
64
|
+
expect(get).toHaveBeenCalledWith(context, expect.any(Function));
|
|
65
|
+
});
|
|
66
|
+
it('should not call next if there are matching routes', async () => {
|
|
67
|
+
const middleware = vi.fn();
|
|
68
|
+
app.use(tinyRouter([
|
|
69
|
+
{
|
|
70
|
+
route: '/',
|
|
71
|
+
get: noop,
|
|
72
|
+
},
|
|
73
|
+
]));
|
|
74
|
+
app.use(middleware);
|
|
75
|
+
await request.get('/');
|
|
76
|
+
expect(middleware).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
it('should call next if there are no matching routes', async () => {
|
|
79
|
+
const middleware = vi.fn();
|
|
80
|
+
app.use(tinyRouter([]));
|
|
81
|
+
app.use(middleware);
|
|
82
|
+
await request.get('/');
|
|
83
|
+
expect(middleware).toHaveBeenCalledWith(context, expect.any(Function));
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=tinyRouter.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|