@ruiapp/rapid-core 0.1.41 → 0.1.43

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 (126) hide show
  1. package/dist/dataAccess/dataAccessTypes.d.ts +63 -0
  2. package/dist/dataAccess/dataAccessor.d.ts +5 -4
  3. package/dist/dataAccess/entityMapper.d.ts +7 -2
  4. package/dist/dataAccess/metaHelper.d.ts +6 -0
  5. package/dist/index.js +576 -324
  6. package/dist/plugins/sequence/SequencePluginTypes.d.ts +1 -0
  7. package/dist/queryBuilder/queryBuilder.d.ts +12 -22
  8. package/dist/types.d.ts +34 -5
  9. package/dist/utilities/errorUtility.d.ts +3 -0
  10. package/package.json +1 -1
  11. package/rollup.config.js +13 -17
  12. package/src/bootstrapApplicationConfig.ts +25 -4
  13. package/src/core/actionHandler.ts +2 -5
  14. package/src/core/eventManager.ts +1 -4
  15. package/src/core/facility.ts +1 -1
  16. package/src/core/http/formDataParser.ts +31 -43
  17. package/src/core/pluginManager.ts +13 -39
  18. package/src/core/providers/runtimeProvider.ts +1 -1
  19. package/src/core/request.ts +3 -3
  20. package/src/core/response.ts +2 -7
  21. package/src/core/routeContext.ts +2 -6
  22. package/src/core/routesBuilder.ts +46 -55
  23. package/src/core/server.ts +8 -34
  24. package/src/dataAccess/dataAccessTypes.ts +86 -0
  25. package/src/dataAccess/dataAccessor.ts +46 -24
  26. package/src/dataAccess/entityManager.ts +294 -245
  27. package/src/dataAccess/entityMapper.ts +32 -15
  28. package/src/dataAccess/filterHelper.ts +1 -3
  29. package/src/dataAccess/metaHelper.ts +45 -0
  30. package/src/dataAccess/propertyMapper.ts +3 -3
  31. package/src/deno-std/datetime/to_imf.ts +2 -17
  32. package/src/deno-std/encoding/base64.ts +1 -5
  33. package/src/deno-std/http/cookie.ts +26 -59
  34. package/src/facilities/log/LogFacility.ts +0 -1
  35. package/src/helpers/entityHelpers.ts +1 -4
  36. package/src/helpers/runCollectionEntityActionHandler.ts +2 -10
  37. package/src/plugins/auth/AuthPlugin.ts +2 -5
  38. package/src/plugins/auth/actionHandlers/changePassword.ts +6 -10
  39. package/src/plugins/auth/actionHandlers/createSession.ts +14 -15
  40. package/src/plugins/auth/actionHandlers/deleteSession.ts +1 -5
  41. package/src/plugins/auth/actionHandlers/getMyProfile.ts +5 -9
  42. package/src/plugins/auth/actionHandlers/index.ts +1 -7
  43. package/src/plugins/auth/actionHandlers/resetPassword.ts +3 -7
  44. package/src/plugins/auth/models/AccessToken.ts +2 -2
  45. package/src/plugins/auth/models/index.ts +1 -3
  46. package/src/plugins/auth/routes/changePassword.ts +1 -1
  47. package/src/plugins/auth/routes/getMyProfile.ts +1 -1
  48. package/src/plugins/auth/routes/index.ts +1 -7
  49. package/src/plugins/auth/routes/resetPassword.ts +1 -1
  50. package/src/plugins/auth/routes/signin.ts +1 -1
  51. package/src/plugins/auth/routes/signout.ts +1 -1
  52. package/src/plugins/cronJob/CronJobPlugin.ts +12 -21
  53. package/src/plugins/cronJob/CronJobPluginTypes.ts +9 -9
  54. package/src/plugins/cronJob/actionHandlers/index.ts +1 -3
  55. package/src/plugins/cronJob/actionHandlers/runCronJob.ts +3 -8
  56. package/src/plugins/cronJob/routes/index.ts +1 -3
  57. package/src/plugins/cronJob/routes/runCronJob.ts +1 -1
  58. package/src/plugins/dataManage/DataManagePlugin.ts +5 -11
  59. package/src/plugins/dataManage/actionHandlers/addEntityRelations.ts +1 -5
  60. package/src/plugins/dataManage/actionHandlers/countCollectionEntities.ts +5 -14
  61. package/src/plugins/dataManage/actionHandlers/createCollectionEntitiesBatch.ts +8 -9
  62. package/src/plugins/dataManage/actionHandlers/createCollectionEntity.ts +7 -8
  63. package/src/plugins/dataManage/actionHandlers/deleteCollectionEntityById.ts +1 -5
  64. package/src/plugins/dataManage/actionHandlers/findCollectionEntities.ts +15 -24
  65. package/src/plugins/dataManage/actionHandlers/findCollectionEntityById.ts +1 -5
  66. package/src/plugins/dataManage/actionHandlers/queryDatabase.ts +1 -5
  67. package/src/plugins/dataManage/actionHandlers/removeEntityRelations.ts +1 -5
  68. package/src/plugins/dataManage/actionHandlers/updateCollectionEntityById.ts +1 -5
  69. package/src/plugins/entityAccessControl/EntityAccessControlPlugin.ts +5 -6
  70. package/src/plugins/entityWatch/EntityWatchPlugin.ts +18 -17
  71. package/src/plugins/entityWatch/EntityWatchPluginTypes.ts +3 -10
  72. package/src/plugins/fileManage/FileManagePlugin.ts +1 -3
  73. package/src/plugins/fileManage/actionHandlers/downloadDocument.ts +2 -6
  74. package/src/plugins/fileManage/actionHandlers/downloadFile.ts +2 -6
  75. package/src/plugins/fileManage/actionHandlers/uploadFile.ts +3 -7
  76. package/src/plugins/fileManage/routes/downloadDocument.ts +1 -1
  77. package/src/plugins/fileManage/routes/downloadFile.ts +1 -1
  78. package/src/plugins/fileManage/routes/index.ts +1 -5
  79. package/src/plugins/fileManage/routes/uploadFile.ts +1 -1
  80. package/src/plugins/metaManage/MetaManagePlugin.ts +45 -92
  81. package/src/plugins/metaManage/actionHandlers/getMetaModelDetail.ts +1 -5
  82. package/src/plugins/metaManage/actionHandlers/listMetaModels.ts +1 -5
  83. package/src/plugins/metaManage/actionHandlers/listMetaRoutes.ts +1 -5
  84. package/src/plugins/routeManage/RouteManagePlugin.ts +2 -7
  85. package/src/plugins/routeManage/actionHandlers/httpProxy.ts +1 -5
  86. package/src/plugins/sequence/SequencePlugin.ts +14 -16
  87. package/src/plugins/sequence/SequencePluginTypes.ts +20 -29
  88. package/src/plugins/sequence/SequenceService.ts +16 -15
  89. package/src/plugins/sequence/actionHandlers/generateSn.ts +2 -7
  90. package/src/plugins/sequence/actionHandlers/index.ts +1 -3
  91. package/src/plugins/sequence/models/SequenceAutoIncrementRecord.ts +2 -2
  92. package/src/plugins/sequence/models/SequenceRule.ts +2 -2
  93. package/src/plugins/sequence/models/index.ts +1 -4
  94. package/src/plugins/sequence/routes/generateSn.ts +1 -1
  95. package/src/plugins/sequence/routes/index.ts +1 -3
  96. package/src/plugins/sequence/segment-utility.ts +1 -1
  97. package/src/plugins/sequence/segments/autoIncrement.ts +4 -8
  98. package/src/plugins/sequence/segments/dayOfMonth.ts +3 -7
  99. package/src/plugins/sequence/segments/index.ts +1 -8
  100. package/src/plugins/sequence/segments/literal.ts +1 -1
  101. package/src/plugins/sequence/segments/month.ts +3 -7
  102. package/src/plugins/sequence/segments/parameter.ts +3 -7
  103. package/src/plugins/sequence/segments/year.ts +3 -7
  104. package/src/plugins/serverOperation/ServerOperationPlugin.ts +12 -22
  105. package/src/plugins/serverOperation/ServerOperationPluginTypes.ts +1 -1
  106. package/src/plugins/serverOperation/actionHandlers/index.ts +1 -3
  107. package/src/plugins/stateMachine/StateMachinePlugin.ts +19 -22
  108. package/src/plugins/stateMachine/StateMachinePluginTypes.ts +6 -7
  109. package/src/plugins/stateMachine/actionHandlers/index.ts +1 -3
  110. package/src/plugins/stateMachine/actionHandlers/sendStateMachineEvent.ts +3 -7
  111. package/src/plugins/stateMachine/models/StateMachine.ts +2 -2
  112. package/src/plugins/stateMachine/models/index.ts +1 -3
  113. package/src/plugins/stateMachine/routes/index.ts +1 -3
  114. package/src/plugins/stateMachine/routes/sendStateMachineEvent.ts +1 -1
  115. package/src/plugins/webhooks/WebhooksPlugin.ts +9 -41
  116. package/src/polyfill.ts +1 -1
  117. package/src/proxy/mod.ts +4 -13
  118. package/src/queryBuilder/queryBuilder.ts +149 -106
  119. package/src/server.ts +19 -44
  120. package/src/types.ts +54 -79
  121. package/src/utilities/accessControlUtility.ts +4 -4
  122. package/src/utilities/errorUtility.ts +17 -0
  123. package/src/utilities/fsUtility.ts +12 -13
  124. package/src/utilities/httpUtility.ts +1 -5
  125. package/src/utilities/jwtUtility.ts +6 -10
  126. package/tsconfig.json +1 -1
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RapidPlugin } from "./core/server";
2
+ import { CountRowOptions, FindRowOptions } from "./dataAccess/dataAccessTypes";
2
3
 
3
4
  export type RapidServerConfig = {
4
5
  baseUrl?: string;
@@ -17,11 +18,15 @@ export interface IDatabaseConfig {
17
18
  dbPoolConnections?: number;
18
19
  }
19
20
 
21
+ export type DatabaseQuery = {
22
+ command: string;
23
+ params?: unknown[] | Record<string, unknown>;
24
+ }
25
+
20
26
  export interface IDatabaseAccessor {
21
27
  queryDatabaseObject: (sql: string, params?: unknown[] | Record<string, unknown>) => Promise<any[]>;
22
28
  }
23
29
 
24
-
25
30
  export interface RunEntityActionHandlerOptions {
26
31
  /** 模型所在的命名空间 */
27
32
  namespace: string;
@@ -75,18 +80,21 @@ export type RpdServerEventTypes = {
75
80
  export interface RpdEntityBeforeCreateEventPayload {
76
81
  namespace: string;
77
82
  modelSingularCode: string;
83
+ baseModelSingularCode?: string;
78
84
  before: any;
79
85
  }
80
86
 
81
87
  export interface RpdEntityCreateEventPayload {
82
88
  namespace: string;
83
89
  modelSingularCode: string;
90
+ baseModelSingularCode?: string;
84
91
  after: any;
85
92
  }
86
93
 
87
94
  export interface RpdEntityBeforeUpdateEventPayload {
88
95
  namespace: string;
89
96
  modelSingularCode: string;
97
+ baseModelSingularCode?: string;
90
98
  before: any;
91
99
  changes: any;
92
100
  }
@@ -94,6 +102,7 @@ export interface RpdEntityBeforeUpdateEventPayload {
94
102
  export interface RpdEntityUpdateEventPayload {
95
103
  namespace: string;
96
104
  modelSingularCode: string;
105
+ baseModelSingularCode?: string;
97
106
  before: any;
98
107
  after: any;
99
108
  changes: any;
@@ -102,18 +111,21 @@ export interface RpdEntityUpdateEventPayload {
102
111
  export interface RpdEntityBeforeDeleteEventPayload {
103
112
  namespace: string;
104
113
  modelSingularCode: string;
114
+ baseModelSingularCode?: string;
105
115
  before: any;
106
116
  }
107
117
 
108
118
  export interface RpdEntityDeleteEventPayload {
109
119
  namespace: string;
110
120
  modelSingularCode: string;
121
+ baseModelSingularCode?: string;
111
122
  before: any;
112
123
  }
113
124
 
114
125
  export interface RpdEntityAddRelationsEventPayload {
115
126
  namespace: string;
116
127
  modelSingularCode: string;
128
+ baseModelSingularCode?: string;
117
129
  entity: any;
118
130
  property: string;
119
131
  relations: any[];
@@ -122,6 +134,7 @@ export interface RpdEntityAddRelationsEventPayload {
122
134
  export interface RpdEntityRemoveRelationsEventPayload {
123
135
  namespace: string;
124
136
  modelSingularCode: string;
137
+ baseModelSingularCode?: string;
125
138
  entity: any;
126
139
  property: string;
127
140
  relations: any[];
@@ -137,7 +150,6 @@ export interface IQueryBuilder {
137
150
  quoteObject: (name: string) => string;
138
151
  }
139
152
 
140
-
141
153
  export interface RpdApplicationConfig {
142
154
  code?: string;
143
155
  name?: string;
@@ -153,6 +165,18 @@ export interface RpdDataModel {
153
165
  pluralCode: string;
154
166
  schema?: string;
155
167
  tableName: string;
168
+ /**
169
+ * Configure the singular code of base entity.
170
+ */
171
+ base?: string;
172
+ /**
173
+ * Configure the type of derived entity.
174
+ */
175
+ derivedType?: string;
176
+ /**
177
+ * Configure the property code to save derived type for base entity.
178
+ */
179
+ derivedTypePropertyCode?: string;
156
180
  properties: RpdDataModelProperty[];
157
181
  extensions?: RpdDataModelExtension[];
158
182
  permissionPolicies?: RpdDataModelPermissionPolicies;
@@ -175,6 +199,10 @@ export interface RpdDataModelProperty {
175
199
  * 表示此属性由谁来维护
176
200
  */
177
201
  maintainedBy?: string;
202
+ /**
203
+ * 表示是否基础属性
204
+ */
205
+ isBaseProperty?: boolean;
178
206
  /**
179
207
  * 字段名称。可以包含中文。
180
208
  */
@@ -244,21 +272,7 @@ export interface RpdDataModelProperty {
244
272
  linkSchema?: string;
245
273
  }
246
274
 
247
- export type RpdDataPropertyTypes =
248
- | "integer"
249
- | "long"
250
- | "float"
251
- | "double"
252
- | "decimal"
253
- | "text"
254
- | "boolean"
255
- | "date"
256
- | "datetime"
257
- | "json"
258
- | "relation"
259
- | "relation[]"
260
- | "option";
261
-
275
+ export type RpdDataPropertyTypes = "integer" | "long" | "float" | "double" | "decimal" | "text" | "boolean" | "date" | "datetime" | "json" | "relation" | "relation[]" | "option";
262
276
 
263
277
  /**
264
278
  * 数据字典
@@ -277,7 +291,7 @@ export type RpdDataDictionary = {
277
291
  /**
278
292
  * 字典项值类型
279
293
  */
280
- type: 'string' | 'integer';
294
+ type: "string" | "integer";
281
295
 
282
296
  /**
283
297
  * 字典项
@@ -315,16 +329,12 @@ export type RpdDataDictionaryEntry = {
315
329
  disabled: boolean;
316
330
  };
317
331
 
318
-
319
332
  export interface RpdDataModelExtension {
320
333
  code: string;
321
334
  config: any;
322
335
  }
323
336
 
324
- export type EventHandler<T = any> = (
325
- sender: RapidPlugin,
326
- payload: T,
327
- ) => void;
337
+ export type EventHandler<T = any> = (sender: RapidPlugin, payload: T) => void;
328
338
 
329
339
  export interface RpdRoute {
330
340
  name: string;
@@ -347,69 +357,34 @@ export interface IRpdDataAccessor<T = any> {
347
357
  getModel(): RpdDataModel;
348
358
  create(entity: any): Promise<any>;
349
359
  updateById(id: any, entity: any): Promise<any>;
350
- find(options: FindEntityOptions): Promise<T[]>;
351
- findOne(options: FindEntityOptions): Promise<T | null>;
360
+ find(options: FindRowOptions): Promise<T[]>;
361
+ findOne(options: FindRowOptions): Promise<T | null>;
352
362
  findById(id: any): Promise<T | null>;
353
- count(options: CountEntityOptions): Promise<any>;
363
+ count(options: CountRowOptions): Promise<any>;
354
364
  deleteById(id: any): Promise<void>;
355
365
  }
356
366
 
357
- export type EntityFilterRelationalOperators =
358
- | "eq"
359
- | "ne"
360
- | "lt"
361
- | "lte"
362
- | "gt"
363
- | "gte"
364
- | "contains"
365
- | "notContains"
366
- | "containsCS"
367
- | "notContainsCS"
368
- | "startsWith"
369
- | "notStartsWith"
370
- | "endsWith"
371
- | "notEndsWith";
372
-
373
- export type EntityFilterSetOperators =
374
- | "in"
375
- | "notIn";
376
-
377
- export type EntityFilterLogicalOperators =
378
- | "or"
379
- | "and";
380
-
381
- export type EntityFilterUnaryOperators =
382
- | "null"
383
- | "notNull";
384
-
385
- export type EntityFilterExistenceOperators =
386
- | "exists"
387
- | "notExists";
388
-
389
- export type EntityFilterOperators =
390
- | EntityFilterRelationalOperators
391
- | EntityFilterSetOperators
392
- | EntityFilterLogicalOperators
393
- | EntityFilterUnaryOperators
394
- | EntityFilterExistenceOperators;
395
-
396
- export type EntityFilterOptions =
397
- | FindEntityRelationalFilterOptions
398
- | FindEntitySetFilterOptions
399
- | FindEntityLogicalFilterOptions
400
- | FindEntityUnaryFilterOptions
401
- | FindEntityExistenceFilterOptions;
402
-
403
- export type EntityNonRelationPropertyFilterOptions =
404
- | FindEntityRelationalFilterOptions
405
- | FindEntitySetFilterOptions
406
- | FindEntityUnaryFilterOptions;
367
+ export type EntityFilterRelationalOperators = "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "contains" | "notContains" | "containsCS" | "notContainsCS" | "startsWith" | "notStartsWith" | "endsWith" | "notEndsWith";
368
+
369
+ export type EntityFilterSetOperators = "in" | "notIn";
370
+
371
+ export type EntityFilterLogicalOperators = "or" | "and";
372
+
373
+ export type EntityFilterUnaryOperators = "null" | "notNull";
374
+
375
+ export type EntityFilterExistenceOperators = "exists" | "notExists";
376
+
377
+ export type EntityFilterOperators = EntityFilterRelationalOperators | EntityFilterSetOperators | EntityFilterLogicalOperators | EntityFilterUnaryOperators | EntityFilterExistenceOperators;
378
+
379
+ export type EntityFilterOptions = FindEntityRelationalFilterOptions | FindEntitySetFilterOptions | FindEntityLogicalFilterOptions | FindEntityUnaryFilterOptions | FindEntityExistenceFilterOptions;
380
+
381
+ export type EntityNonRelationPropertyFilterOptions = FindEntityRelationalFilterOptions | FindEntitySetFilterOptions | FindEntityUnaryFilterOptions;
407
382
 
408
383
  export interface FindEntityOptions {
409
384
  filters?: EntityFilterOptions[];
410
385
  orderBy?: FindEntityOrderByOptions[];
411
386
  pagination?: FindEntityPaginationOptions;
412
- properties?: string[] | Record<string, any>;
387
+ properties?: string[];
413
388
  keepNonPropertyFields?: boolean;
414
389
  }
415
390
 
@@ -484,11 +459,11 @@ export interface DeleteEntityOptions {
484
459
  export interface AddEntityRelationsOptions {
485
460
  id: number;
486
461
  property: string;
487
- relations: {id?: number, [k: string]: any}[];
462
+ relations: { id?: number; [k: string]: any }[];
488
463
  }
489
464
 
490
465
  export interface RemoveEntityRelationsOptions {
491
466
  id: number;
492
467
  property: string;
493
- relations: {id?: number, [k: string]: any}[];
468
+ relations: { id?: number; [k: string]: any }[];
494
469
  }
@@ -3,7 +3,7 @@ import { find } from "lodash";
3
3
  export type PermissionCheckPolicy = {
4
4
  any?: string[];
5
5
  all?: string[];
6
- }
6
+ };
7
7
 
8
8
  export function isAccessAllowed(policy: PermissionCheckPolicy, allowedActions: string[]): boolean {
9
9
  let isAnyCheckPassed = true;
@@ -12,7 +12,7 @@ export function isAccessAllowed(policy: PermissionCheckPolicy, allowedActions: s
12
12
  if (policy.any) {
13
13
  isAnyCheckPassed = false;
14
14
  for (const action of policy.any) {
15
- if (find(allowedActions, item => item === action) != null) {
15
+ if (find(allowedActions, (item) => item === action) != null) {
16
16
  isAnyCheckPassed = true;
17
17
  break;
18
18
  }
@@ -22,7 +22,7 @@ export function isAccessAllowed(policy: PermissionCheckPolicy, allowedActions: s
22
22
  if (policy.all) {
23
23
  isAllCheckPassed = true;
24
24
  for (const action of policy.all) {
25
- if (find(allowedActions, item => item === action) == null) {
25
+ if (find(allowedActions, (item) => item === action) == null) {
26
26
  isAnyCheckPassed = false;
27
27
  break;
28
28
  }
@@ -30,4 +30,4 @@ export function isAccessAllowed(policy: PermissionCheckPolicy, allowedActions: s
30
30
  }
31
31
 
32
32
  return isAnyCheckPassed && isAllCheckPassed;
33
- }
33
+ }
@@ -0,0 +1,17 @@
1
+ export function newError(type: string, message?: string, cause?: any) {
2
+ const error = new Error(
3
+ message, {
4
+ cause,
5
+ }
6
+ );
7
+ error.name = type;
8
+ return error;
9
+ }
10
+
11
+ export function newDatabaseError(message?: string, cause?: any) {
12
+ return newError("DatabaseError", message, cause);
13
+ }
14
+
15
+ export function newEntityOperationError(message?: string, cause?: any) {
16
+ return newError("EntityOperationError", message, cause);
17
+ }
@@ -1,4 +1,4 @@
1
- import fs from 'fs';
1
+ import fs from "fs";
2
2
 
3
3
  export async function readFile(path: string): Promise<Buffer> {
4
4
  return new Promise((resolve, reject) => {
@@ -8,8 +8,8 @@ export async function readFile(path: string): Promise<Buffer> {
8
8
  } else {
9
9
  resolve(data);
10
10
  }
11
- })
12
- })
11
+ });
12
+ });
13
13
  }
14
14
 
15
15
  export async function copyFile(fromPath: string, toPath: string): Promise<void> {
@@ -20,8 +20,8 @@ export async function copyFile(fromPath: string, toPath: string): Promise<void>
20
20
  } else {
21
21
  resolve();
22
22
  }
23
- })
24
- })
23
+ });
24
+ });
25
25
  }
26
26
 
27
27
  export async function removeFile(path: string): Promise<void> {
@@ -32,8 +32,8 @@ export async function removeFile(path: string): Promise<void> {
32
32
  } else {
33
33
  resolve();
34
34
  }
35
- })
36
- })
35
+ });
36
+ });
37
37
  }
38
38
 
39
39
  export async function moveFile(fromPath: string, toPath: string): Promise<void> {
@@ -44,8 +44,8 @@ export async function moveFile(fromPath: string, toPath: string): Promise<void>
44
44
  } else {
45
45
  resolve();
46
46
  }
47
- })
48
- })
47
+ });
48
+ });
49
49
  }
50
50
 
51
51
  export async function appendFile(path: string, data: ArrayBuffer): Promise<void> {
@@ -56,7 +56,6 @@ export async function appendFile(path: string, data: ArrayBuffer): Promise<void>
56
56
  } else {
57
57
  resolve();
58
58
  }
59
- })
60
- })
61
-
62
- }
59
+ });
60
+ });
61
+ }
@@ -1,8 +1,4 @@
1
- export async function fetchWithTimeout(
2
- url: string,
3
- reqInit: RequestInit,
4
- timeout?: number,
5
- ) : Promise<Response> {
1
+ export async function fetchWithTimeout(url: string, reqInit: RequestInit, timeout?: number): Promise<Response> {
6
2
  if (!timeout) {
7
3
  return await fetch(url, reqInit);
8
4
  }
@@ -4,27 +4,23 @@ import crypto from "crypto";
4
4
 
5
5
  export function createJwt(payload: Record<string, any>, secret: Secret) {
6
6
  return sign(payload, secret, {
7
- algorithm: 'HS512',
7
+ algorithm: "HS512",
8
8
  });
9
9
  }
10
10
 
11
11
  export function verifyJwt(token: string, secret: Secret): JwtPayload {
12
12
  return verify(token, secret, {
13
- algorithms: ['HS512'],
13
+ algorithms: ["HS512"],
14
14
  }) as JwtPayload;
15
15
  }
16
16
 
17
17
  export function decodeJwt(token: string) {
18
- return decode(token, { complete: true});
18
+ return decode(token, { complete: true });
19
19
  }
20
20
 
21
21
  export async function generateJwtSecretKey() {
22
- const key = await crypto.subtle.generateKey(
23
- { name: "HMAC", hash: "SHA-512" },
24
- true,
25
- ["sign", "verify"],
26
- );
27
-
22
+ const key = await crypto.subtle.generateKey({ name: "HMAC", hash: "SHA-512" }, true, ["sign", "verify"]);
23
+
28
24
  const exportedKey = await crypto.subtle.exportKey("raw", key);
29
25
  return base64Encode(exportedKey);
30
- }
26
+ }
package/tsconfig.json CHANGED
@@ -16,4 +16,4 @@
16
16
  },
17
17
  "exclude": ["src/**/*.spec.ts", "src/**/*.spec.tsx", "node_modules"],
18
18
  "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
19
- }
19
+ }