@ruiapp/rapid-core 0.3.6 → 0.3.7

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/dist/index.js CHANGED
@@ -4409,32 +4409,32 @@ function tryValidateLicense(logger, server) {
4409
4409
  return false;
4410
4410
  }
4411
4411
 
4412
- const code$u = "listMetaModels";
4413
- async function handler$u(plugin, ctx, options) {
4412
+ const code$v = "listMetaModels";
4413
+ async function handler$v(plugin, ctx, options) {
4414
4414
  const { applicationConfig } = ctx;
4415
4415
  ctx.output = { list: applicationConfig.models };
4416
4416
  }
4417
4417
 
4418
4418
  var listMetaModels = /*#__PURE__*/Object.freeze({
4419
4419
  __proto__: null,
4420
- code: code$u,
4421
- handler: handler$u
4420
+ code: code$v,
4421
+ handler: handler$v
4422
4422
  });
4423
4423
 
4424
- const code$t = "listMetaRoutes";
4425
- async function handler$t(plugin, ctx, options) {
4424
+ const code$u = "listMetaRoutes";
4425
+ async function handler$u(plugin, ctx, options) {
4426
4426
  const { applicationConfig } = ctx;
4427
4427
  ctx.output = { list: applicationConfig.routes };
4428
4428
  }
4429
4429
 
4430
4430
  var listMetaRoutes = /*#__PURE__*/Object.freeze({
4431
4431
  __proto__: null,
4432
- code: code$t,
4433
- handler: handler$t
4432
+ code: code$u,
4433
+ handler: handler$u
4434
4434
  });
4435
4435
 
4436
- const code$s = "getMetaModelDetail";
4437
- async function handler$s(plugin, ctx, options) {
4436
+ const code$t = "getMetaModelDetail";
4437
+ async function handler$t(plugin, ctx, options) {
4438
4438
  const { server, input } = ctx;
4439
4439
  const model = server.getModel(input);
4440
4440
  ctx.output = model;
@@ -4442,8 +4442,8 @@ async function handler$s(plugin, ctx, options) {
4442
4442
 
4443
4443
  var getMetaModelDetail = /*#__PURE__*/Object.freeze({
4444
4444
  __proto__: null,
4445
- code: code$s,
4446
- handler: handler$s
4445
+ code: code$t,
4446
+ handler: handler$t
4447
4447
  });
4448
4448
 
4449
4449
  function removeFiltersWithNullValue(filters) {
@@ -4957,9 +4957,9 @@ async function runCollectionEntityActionHandler(ctx, options, code, handleEntity
4957
4957
  }
4958
4958
  }
4959
4959
 
4960
- const code$r = "findCollectionEntities";
4961
- async function handler$r(plugin, ctx, options) {
4962
- await runCollectionEntityActionHandler(ctx, options, code$r, async (entityManager, input) => {
4960
+ const code$s = "findCollectionEntities";
4961
+ async function handler$s(plugin, ctx, options) {
4962
+ await runCollectionEntityActionHandler(ctx, options, code$s, async (entityManager, input) => {
4963
4963
  input.filters = removeFiltersWithNullValue(input.filters);
4964
4964
  input.routeContext = ctx.routerContext;
4965
4965
  const entities = await entityManager.findEntities(input);
@@ -4975,14 +4975,14 @@ async function handler$r(plugin, ctx, options) {
4975
4975
 
4976
4976
  var findCollectionEntities = /*#__PURE__*/Object.freeze({
4977
4977
  __proto__: null,
4978
- code: code$r,
4979
- handler: handler$r
4978
+ code: code$s,
4979
+ handler: handler$s
4980
4980
  });
4981
4981
 
4982
- const code$q = "findCollectionEntityById";
4983
- async function handler$q(plugin, ctx, options) {
4982
+ const code$r = "findCollectionEntityById";
4983
+ async function handler$r(plugin, ctx, options) {
4984
4984
  const { logger, server, input } = ctx;
4985
- logger.debug(`Running ${code$q} handler...`, { input });
4985
+ logger.debug(`Running ${code$r} handler...`, { input });
4986
4986
  const { id } = input;
4987
4987
  const entityManager = server.getEntityManager(options.singularCode);
4988
4988
  const entity = await entityManager.findById({
@@ -4997,13 +4997,13 @@ async function handler$q(plugin, ctx, options) {
4997
4997
 
4998
4998
  var findCollectionEntityById = /*#__PURE__*/Object.freeze({
4999
4999
  __proto__: null,
5000
- code: code$q,
5001
- handler: handler$q
5000
+ code: code$r,
5001
+ handler: handler$r
5002
5002
  });
5003
5003
 
5004
- const code$p = "countCollectionEntities";
5005
- async function handler$p(plugin, ctx, options) {
5006
- await runCollectionEntityActionHandler(ctx, options, code$p, async (entityManager, input) => {
5004
+ const code$q = "countCollectionEntities";
5005
+ async function handler$q(plugin, ctx, options) {
5006
+ await runCollectionEntityActionHandler(ctx, options, code$q, async (entityManager, input) => {
5007
5007
  input.filters = removeFiltersWithNullValue(input.filters);
5008
5008
  input.routeContext = ctx.routerContext;
5009
5009
  const count = await entityManager.count(input);
@@ -5013,16 +5013,16 @@ async function handler$p(plugin, ctx, options) {
5013
5013
 
5014
5014
  var countCollectionEntities = /*#__PURE__*/Object.freeze({
5015
5015
  __proto__: null,
5016
- code: code$p,
5017
- handler: handler$p
5016
+ code: code$q,
5017
+ handler: handler$q
5018
5018
  });
5019
5019
 
5020
- const code$o = "createCollectionEntity";
5021
- async function handler$o(plugin, ctx, options) {
5020
+ const code$p = "createCollectionEntity";
5021
+ async function handler$p(plugin, ctx, options) {
5022
5022
  const { logger, server, input } = ctx;
5023
5023
  const { defaultInput, fixedInput } = options;
5024
5024
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
5025
- logger.debug(`Running ${code$o} handler...`, { defaultInput, fixedInput, mergedInput });
5025
+ logger.debug(`Running ${code$p} handler...`, { defaultInput, fixedInput, mergedInput });
5026
5026
  const entityManager = server.getEntityManager(options.singularCode);
5027
5027
  const output = await entityManager.createEntity({
5028
5028
  entity: input,
@@ -5033,15 +5033,15 @@ async function handler$o(plugin, ctx, options) {
5033
5033
 
5034
5034
  var createCollectionEntity = /*#__PURE__*/Object.freeze({
5035
5035
  __proto__: null,
5036
- code: code$o,
5037
- handler: handler$o
5036
+ code: code$p,
5037
+ handler: handler$p
5038
5038
  });
5039
5039
 
5040
- const code$n = "createCollectionEntitiesBatch";
5041
- async function handler$n(plugin, ctx, options) {
5040
+ const code$o = "createCollectionEntitiesBatch";
5041
+ async function handler$o(plugin, ctx, options) {
5042
5042
  const { logger, server, input } = ctx;
5043
5043
  const { defaultInput, fixedInput } = options;
5044
- logger.debug(`Running ${code$n} handler...`, { defaultInput, fixedInput, input });
5044
+ logger.debug(`Running ${code$o} handler...`, { defaultInput, fixedInput, input });
5045
5045
  const { entities } = input;
5046
5046
  if (!lodash.isArray(entities)) {
5047
5047
  throw new Error("input.entities should be an array.");
@@ -5065,16 +5065,16 @@ async function handler$n(plugin, ctx, options) {
5065
5065
 
5066
5066
  var createCollectionEntitiesBatch = /*#__PURE__*/Object.freeze({
5067
5067
  __proto__: null,
5068
- code: code$n,
5069
- handler: handler$n
5068
+ code: code$o,
5069
+ handler: handler$o
5070
5070
  });
5071
5071
 
5072
- const code$m = "updateCollectionEntityById";
5073
- async function handler$m(plugin, ctx, options) {
5072
+ const code$n = "updateCollectionEntityById";
5073
+ async function handler$n(plugin, ctx, options) {
5074
5074
  const { logger, server, input } = ctx;
5075
5075
  const { defaultInput, fixedInput } = options;
5076
5076
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
5077
- logger.debug(`Running ${code$m} handler...`, { defaultInput, fixedInput, mergedInput });
5077
+ logger.debug(`Running ${code$n} handler...`, { defaultInput, fixedInput, mergedInput });
5078
5078
  const operation = mergedInput.$operation;
5079
5079
  if (operation) {
5080
5080
  delete mergedInput.$operation;
@@ -5102,15 +5102,15 @@ async function handler$m(plugin, ctx, options) {
5102
5102
 
5103
5103
  var updateCollectionEntityById = /*#__PURE__*/Object.freeze({
5104
5104
  __proto__: null,
5105
- code: code$m,
5106
- handler: handler$m
5105
+ code: code$n,
5106
+ handler: handler$n
5107
5107
  });
5108
5108
 
5109
- const code$l = "deleteCollectionEntities";
5110
- async function handler$l(plugin, ctx, options) {
5109
+ const code$m = "deleteCollectionEntities";
5110
+ async function handler$m(plugin, ctx, options) {
5111
5111
  const { logger, server, routerContext } = ctx;
5112
5112
  const input = ctx.input;
5113
- logger.debug(`Running ${code$l} handler...`);
5113
+ logger.debug(`Running ${code$m} handler...`);
5114
5114
  if (!input.filters || !input.filters.length) {
5115
5115
  throw new Error("Filters are required when deleting entities.");
5116
5116
  }
@@ -5131,14 +5131,14 @@ async function handler$l(plugin, ctx, options) {
5131
5131
 
5132
5132
  var deleteCollectionEntities = /*#__PURE__*/Object.freeze({
5133
5133
  __proto__: null,
5134
- code: code$l,
5135
- handler: handler$l
5134
+ code: code$m,
5135
+ handler: handler$m
5136
5136
  });
5137
5137
 
5138
- const code$k = "deleteCollectionEntityById";
5139
- async function handler$k(plugin, ctx, options) {
5138
+ const code$l = "deleteCollectionEntityById";
5139
+ async function handler$l(plugin, ctx, options) {
5140
5140
  const { logger, server, input } = ctx;
5141
- logger.debug(`Running ${code$k} handler...`);
5141
+ logger.debug(`Running ${code$l} handler...`);
5142
5142
  const entityManager = server.getEntityManager(options.singularCode);
5143
5143
  await entityManager.deleteById({
5144
5144
  id: input.id,
@@ -5150,16 +5150,16 @@ async function handler$k(plugin, ctx, options) {
5150
5150
 
5151
5151
  var deleteCollectionEntityById = /*#__PURE__*/Object.freeze({
5152
5152
  __proto__: null,
5153
- code: code$k,
5154
- handler: handler$k
5153
+ code: code$l,
5154
+ handler: handler$l
5155
5155
  });
5156
5156
 
5157
- const code$j = "addEntityRelations";
5158
- async function handler$j(plugin, ctx, options) {
5157
+ const code$k = "addEntityRelations";
5158
+ async function handler$k(plugin, ctx, options) {
5159
5159
  const { logger, server, input } = ctx;
5160
5160
  const { defaultInput, fixedInput } = options;
5161
5161
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
5162
- logger.debug(`Running ${code$j} handler...`, { defaultInput, fixedInput, mergedInput });
5162
+ logger.debug(`Running ${code$k} handler...`, { defaultInput, fixedInput, mergedInput });
5163
5163
  const entityManager = server.getEntityManager(options.singularCode);
5164
5164
  mergedInput.routeContext = ctx.routerContext;
5165
5165
  await entityManager.addRelations(mergedInput, plugin);
@@ -5168,16 +5168,16 @@ async function handler$j(plugin, ctx, options) {
5168
5168
 
5169
5169
  var addEntityRelations = /*#__PURE__*/Object.freeze({
5170
5170
  __proto__: null,
5171
- code: code$j,
5172
- handler: handler$j
5171
+ code: code$k,
5172
+ handler: handler$k
5173
5173
  });
5174
5174
 
5175
- const code$i = "removeEntityRelations";
5176
- async function handler$i(plugin, ctx, options) {
5175
+ const code$j = "removeEntityRelations";
5176
+ async function handler$j(plugin, ctx, options) {
5177
5177
  const { logger, server, input } = ctx;
5178
5178
  const { defaultInput, fixedInput } = options;
5179
5179
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
5180
- logger.debug(`Running ${code$i} handler...`, { defaultInput, fixedInput, mergedInput });
5180
+ logger.debug(`Running ${code$j} handler...`, { defaultInput, fixedInput, mergedInput });
5181
5181
  mergedInput.routeContext = ctx.routerContext;
5182
5182
  const entityManager = server.getEntityManager(options.singularCode);
5183
5183
  await entityManager.removeRelations(mergedInput, plugin);
@@ -5186,16 +5186,16 @@ async function handler$i(plugin, ctx, options) {
5186
5186
 
5187
5187
  var removeEntityRelations = /*#__PURE__*/Object.freeze({
5188
5188
  __proto__: null,
5189
- code: code$i,
5190
- handler: handler$i
5189
+ code: code$j,
5190
+ handler: handler$j
5191
5191
  });
5192
5192
 
5193
- const code$h = "queryDatabase";
5194
- async function handler$h(plugin, ctx, options) {
5193
+ const code$i = "queryDatabase";
5194
+ async function handler$i(plugin, ctx, options) {
5195
5195
  const { logger, server, input } = ctx;
5196
5196
  const { sql, querySingle, defaultInput, fixedInput } = options;
5197
5197
  const mergedInput = mergeInput(defaultInput, input, fixedInput);
5198
- logger.debug(`Running ${code$h} handler...`, { defaultInput, fixedInput, mergedInput });
5198
+ logger.debug(`Running ${code$i} handler...`, { defaultInput, fixedInput, mergedInput });
5199
5199
  const result = await server.queryDatabaseObject(sql, mergedInput);
5200
5200
  if (querySingle) {
5201
5201
  ctx.output = lodash.first(result);
@@ -5207,8 +5207,8 @@ async function handler$h(plugin, ctx, options) {
5207
5207
 
5208
5208
  var queryDatabase = /*#__PURE__*/Object.freeze({
5209
5209
  __proto__: null,
5210
- code: code$h,
5211
- handler: handler$h
5210
+ code: code$i,
5211
+ handler: handler$i
5212
5212
  });
5213
5213
 
5214
5214
  /**
@@ -5386,17 +5386,17 @@ async function sendSourceResponse(proxyCtx, targetRes) {
5386
5386
  srcRes.body = targetRes.body;
5387
5387
  }
5388
5388
 
5389
- const code$g = "httpProxy";
5390
- async function handler$g(plugin, ctx, options) {
5389
+ const code$h = "httpProxy";
5390
+ async function handler$h(plugin, ctx, options) {
5391
5391
  const { logger } = ctx;
5392
- logger.debug(`Running ${code$g} handler...`);
5392
+ logger.debug(`Running ${code$h} handler...`);
5393
5393
  await doProxy(ctx.routerContext, options);
5394
5394
  }
5395
5395
 
5396
5396
  var httpProxy = /*#__PURE__*/Object.freeze({
5397
5397
  __proto__: null,
5398
- code: code$g,
5399
- handler: handler$g
5398
+ code: code$h,
5399
+ handler: handler$h
5400
5400
  });
5401
5401
 
5402
5402
  /**
@@ -5443,8 +5443,8 @@ class RouteManager {
5443
5443
  }
5444
5444
  }
5445
5445
 
5446
- const code$f = "generateSn";
5447
- async function handler$f(plugin, ctx, options) {
5446
+ const code$g = "generateSn";
5447
+ async function handler$g(plugin, ctx, options) {
5448
5448
  const { server, routerContext } = ctx;
5449
5449
  const input = ctx.input;
5450
5450
  if (options?.ruleCode) {
@@ -5462,8 +5462,8 @@ async function handler$f(plugin, ctx, options) {
5462
5462
 
5463
5463
  var generateSn$1 = /*#__PURE__*/Object.freeze({
5464
5464
  __proto__: null,
5465
- code: code$f,
5466
- handler: handler$f
5465
+ code: code$g,
5466
+ handler: handler$g
5467
5467
  });
5468
5468
 
5469
5469
  var pluginActionHandlers$8 = [generateSn$1];
@@ -6042,8 +6042,8 @@ class WebhooksPlugin {
6042
6042
  }
6043
6043
  }
6044
6044
 
6045
- const code$e = "changePassword";
6046
- async function handler$e(plugin, ctx, options) {
6045
+ const code$f = "changePassword";
6046
+ async function handler$f(plugin, ctx, options) {
6047
6047
  const { server, input, routerContext } = ctx;
6048
6048
  const { id, oldPassword, newPassword } = input;
6049
6049
  const userId = routerContext.state.userId;
@@ -6084,12 +6084,12 @@ async function handler$e(plugin, ctx, options) {
6084
6084
 
6085
6085
  var changePassword$1 = /*#__PURE__*/Object.freeze({
6086
6086
  __proto__: null,
6087
- code: code$e,
6088
- handler: handler$e
6087
+ code: code$f,
6088
+ handler: handler$f
6089
6089
  });
6090
6090
 
6091
- const code$d = "createSession";
6092
- async function handler$d(plugin, ctx, options) {
6091
+ const code$e = "createSession";
6092
+ async function handler$e(plugin, ctx, options) {
6093
6093
  const { server, input, routerContext: routeContext, logger } = ctx;
6094
6094
  const { response } = routeContext;
6095
6095
  const { account, password } = input;
@@ -6136,12 +6136,12 @@ async function handler$d(plugin, ctx, options) {
6136
6136
 
6137
6137
  var createSession = /*#__PURE__*/Object.freeze({
6138
6138
  __proto__: null,
6139
- code: code$d,
6140
- handler: handler$d
6139
+ code: code$e,
6140
+ handler: handler$e
6141
6141
  });
6142
6142
 
6143
- const code$c = "deleteSession";
6144
- async function handler$c(plugin, ctx, options) {
6143
+ const code$d = "deleteSession";
6144
+ async function handler$d(plugin, ctx, options) {
6145
6145
  const { server, input, routerContext } = ctx;
6146
6146
  const { response } = routerContext;
6147
6147
  setCookie(response.headers, {
@@ -6154,12 +6154,12 @@ async function handler$c(plugin, ctx, options) {
6154
6154
 
6155
6155
  var deleteSession = /*#__PURE__*/Object.freeze({
6156
6156
  __proto__: null,
6157
- code: code$c,
6158
- handler: handler$c
6157
+ code: code$d,
6158
+ handler: handler$d
6159
6159
  });
6160
6160
 
6161
- const code$b = "getMyProfile";
6162
- async function handler$b(plugin, ctx, options) {
6161
+ const code$c = "getMyProfile";
6162
+ async function handler$c(plugin, ctx, options) {
6163
6163
  const { server, input, routerContext } = ctx;
6164
6164
  const userId = routerContext.state.userId;
6165
6165
  if (!userId) {
@@ -6189,12 +6189,12 @@ async function handler$b(plugin, ctx, options) {
6189
6189
 
6190
6190
  var getMyProfile$2 = /*#__PURE__*/Object.freeze({
6191
6191
  __proto__: null,
6192
- code: code$b,
6193
- handler: handler$b
6192
+ code: code$c,
6193
+ handler: handler$c
6194
6194
  });
6195
6195
 
6196
- const code$a = "resetPassword";
6197
- async function handler$a(plugin, ctx, options) {
6196
+ const code$b = "resetPassword";
6197
+ async function handler$b(plugin, ctx, options) {
6198
6198
  const { server, input, routerContext } = ctx;
6199
6199
  const { userId, password } = input;
6200
6200
  const userDataAccessor = server.getDataAccessor({
@@ -6221,8 +6221,8 @@ async function handler$a(plugin, ctx, options) {
6221
6221
 
6222
6222
  var resetPassword$1 = /*#__PURE__*/Object.freeze({
6223
6223
  __proto__: null,
6224
- code: code$a,
6225
- handler: handler$a
6224
+ code: code$b,
6225
+ handler: handler$b
6226
6226
  });
6227
6227
 
6228
6228
  var pluginActionHandlers$7 = [changePassword$1, createSession, deleteSession, getMyProfile$2, resetPassword$1];
@@ -6445,8 +6445,8 @@ function getFileBaseName(pathname) {
6445
6445
  return path__default["default"].basename(pathname, extName);
6446
6446
  }
6447
6447
 
6448
- const code$9 = "downloadDocument";
6449
- async function handler$9(plugin, ctx, options) {
6448
+ const code$a = "downloadDocument";
6449
+ async function handler$a(plugin, ctx, options) {
6450
6450
  const { server, applicationConfig, routerContext, input } = ctx;
6451
6451
  const { request, response } = routerContext;
6452
6452
  const documentDataAccessor = ctx.server.getDataAccessor({
@@ -6502,12 +6502,12 @@ async function handler$9(plugin, ctx, options) {
6502
6502
 
6503
6503
  var downloadDocumentActionHandler = /*#__PURE__*/Object.freeze({
6504
6504
  __proto__: null,
6505
- code: code$9,
6506
- handler: handler$9
6505
+ code: code$a,
6506
+ handler: handler$a
6507
6507
  });
6508
6508
 
6509
- const code$8 = "downloadFile";
6510
- async function handler$8(plugin, ctx, options) {
6509
+ const code$9 = "downloadFile";
6510
+ async function handler$9(plugin, ctx, options) {
6511
6511
  const { server, applicationConfig, routerContext } = ctx;
6512
6512
  const { request, response } = routerContext;
6513
6513
  //TODO: only public files can download by this handler
@@ -6533,12 +6533,12 @@ async function handler$8(plugin, ctx, options) {
6533
6533
 
6534
6534
  var downloadFileActionHandler = /*#__PURE__*/Object.freeze({
6535
6535
  __proto__: null,
6536
- code: code$8,
6537
- handler: handler$8
6536
+ code: code$9,
6537
+ handler: handler$9
6538
6538
  });
6539
6539
 
6540
- const code$7 = "uploadFile";
6541
- async function handler$7(plugin, ctx, options) {
6540
+ const code$8 = "uploadFile";
6541
+ async function handler$8(plugin, ctx, options) {
6542
6542
  const { server, applicationConfig, routerContext, input } = ctx;
6543
6543
  let file = input.file || input.files;
6544
6544
  if (lodash.isArray(file)) {
@@ -6559,8 +6559,8 @@ async function handler$7(plugin, ctx, options) {
6559
6559
 
6560
6560
  var uploadFileActionHandler = /*#__PURE__*/Object.freeze({
6561
6561
  __proto__: null,
6562
- code: code$7,
6563
- handler: handler$7
6562
+ code: code$8,
6563
+ handler: handler$8
6564
6564
  });
6565
6565
 
6566
6566
  var getMyProfile = {
@@ -6636,8 +6636,8 @@ class FileManager {
6636
6636
  }
6637
6637
  }
6638
6638
 
6639
- const code$6 = "getLicense";
6640
- async function handler$6(plugin, ctx, options) {
6639
+ const code$7 = "getLicense";
6640
+ async function handler$7(plugin, ctx, options) {
6641
6641
  const { server, routerContext } = ctx;
6642
6642
  const licenseService = server.getService("licenseService");
6643
6643
  const license = licenseService.getLicense();
@@ -6645,12 +6645,27 @@ async function handler$6(plugin, ctx, options) {
6645
6645
  }
6646
6646
 
6647
6647
  var getLicense$1 = /*#__PURE__*/Object.freeze({
6648
+ __proto__: null,
6649
+ code: code$7,
6650
+ handler: handler$7
6651
+ });
6652
+
6653
+ const code$6 = "updateLicense";
6654
+ async function handler$6(plugin, ctx, options) {
6655
+ const { server, routerContext } = ctx;
6656
+ const input = ctx.input;
6657
+ const licenseService = server.getService("licenseService");
6658
+ const license = await licenseService.updateLicense(input.certText);
6659
+ ctx.output = license;
6660
+ }
6661
+
6662
+ var updateLicense$1 = /*#__PURE__*/Object.freeze({
6648
6663
  __proto__: null,
6649
6664
  code: code$6,
6650
6665
  handler: handler$6
6651
6666
  });
6652
6667
 
6653
- var pluginActionHandlers$6 = [getLicense$1];
6668
+ var pluginActionHandlers$6 = [getLicense$1, updateLicense$1];
6654
6669
 
6655
6670
  var pluginModels$4 = [];
6656
6671
 
@@ -6668,7 +6683,21 @@ var getLicense = {
6668
6683
  ],
6669
6684
  };
6670
6685
 
6671
- var pluginRoutes$5 = [getLicense];
6686
+ var updateLicense = {
6687
+ namespace: "svc",
6688
+ name: "svc.updateLicense",
6689
+ code: "svc.updateLicense",
6690
+ type: "RESTful",
6691
+ method: "POST",
6692
+ endpoint: "/svc/license",
6693
+ actions: [
6694
+ {
6695
+ code: "updateLicense",
6696
+ },
6697
+ ],
6698
+ };
6699
+
6700
+ var pluginRoutes$5 = [getLicense, updateLicense];
6672
6701
 
6673
6702
  function getEncryptionIV(input) {
6674
6703
  const hash = crypto__default["default"].createHash("sha512").update(input).digest("hex");
@@ -6724,12 +6753,9 @@ class LicenseService {
6724
6753
  async loadLicense() {
6725
6754
  const settingService = this.#server.getService("settingService");
6726
6755
  const licenseSettings = await settingService.getSystemSettingValues("license");
6727
- const { deployId } = licenseSettings;
6728
- const certText = licenseSettings.cert;
6729
- const certJSON = Buffer.from(certText, "base64").toString();
6730
- const cert = JSON.parse(certJSON);
6756
+ const { deployId, cert: certText } = licenseSettings;
6731
6757
  try {
6732
- const license = extractCertLicense(this.#encryptionKey, deployId, cert);
6758
+ const license = this.parseLicense(deployId, certText);
6733
6759
  this.#license = license;
6734
6760
  }
6735
6761
  catch (error) {
@@ -6740,6 +6766,26 @@ class LicenseService {
6740
6766
  getLicense() {
6741
6767
  return this.#license;
6742
6768
  }
6769
+ parseLicense(deployId, certText) {
6770
+ const certJSON = Buffer.from(certText, "base64").toString();
6771
+ const cert = JSON.parse(certJSON);
6772
+ return extractCertLicense(this.#encryptionKey, deployId, cert);
6773
+ }
6774
+ async updateLicense(certText) {
6775
+ const settingService = this.#server.getService("settingService");
6776
+ const deployId = await settingService.getSystemSettingValue("license", "deployId");
6777
+ let license;
6778
+ try {
6779
+ license = this.parseLicense(deployId, certText);
6780
+ }
6781
+ catch (error) {
6782
+ this.#server.getLogger().error("Parse license failed.", error);
6783
+ throw new Error("Parse license failed.");
6784
+ }
6785
+ await settingService.setSystemSettingValue("license", "cert", certText);
6786
+ this.#license = license;
6787
+ return license;
6788
+ }
6743
6789
  isExpired() {
6744
6790
  if (!this.#license) {
6745
6791
  return true;
@@ -15,6 +15,8 @@ export default class LicenseService {
15
15
  constructor(server: IRpdServer, encryptionKey: string);
16
16
  loadLicense(): Promise<void>;
17
17
  getLicense(): RpdLicense;
18
+ parseLicense(deployId: string, certText: string): RpdLicense;
19
+ updateLicense(certText: string): Promise<RpdLicense>;
18
20
  isExpired(): boolean;
19
21
  getQuota(name: string): any;
20
22
  isOutOfQuota(name: string, currentAmount: number): boolean;
@@ -1,3 +1,4 @@
1
1
  import * as getLicense from "./getLicense";
2
- declare const _default: (typeof getLicense)[];
2
+ import * as updateLicense from "./updateLicense";
3
+ declare const _default: (typeof getLicense | typeof updateLicense)[];
3
4
  export default _default;
@@ -0,0 +1,9 @@
1
+ import { ActionHandlerContext } from "../../../core/actionHandler";
2
+ import { RapidPlugin } from "../../../core/server";
3
+ export interface UpdateLicenseOptions {
4
+ }
5
+ export interface UpdateLicenseInput {
6
+ certText: string;
7
+ }
8
+ export declare const code = "updateLicense";
9
+ export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: UpdateLicenseOptions): Promise<void>;
@@ -1,4 +1,4 @@
1
- declare const _default: {
1
+ declare const _default: ({
2
2
  namespace: string;
3
3
  name: string;
4
4
  code: string;
@@ -8,5 +8,15 @@ declare const _default: {
8
8
  actions: {
9
9
  code: string;
10
10
  }[];
11
- }[];
11
+ } | {
12
+ namespace: string;
13
+ name: string;
14
+ code: string;
15
+ type: "RESTful";
16
+ method: "POST";
17
+ endpoint: string;
18
+ actions: {
19
+ code: string;
20
+ }[];
21
+ })[];
12
22
  export default _default;
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ namespace: string;
3
+ name: string;
4
+ code: string;
5
+ type: "RESTful";
6
+ method: "POST";
7
+ endpoint: string;
8
+ actions: {
9
+ code: string;
10
+ }[];
11
+ };
12
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,13 +37,10 @@ export default class LicenseService {
37
37
  async loadLicense(): Promise<void> {
38
38
  const settingService = this.#server.getService<SettingService>("settingService");
39
39
  const licenseSettings = await settingService.getSystemSettingValues("license");
40
- const { deployId } = licenseSettings as LicenseSettings;
41
- const certText = licenseSettings.cert;
42
- const certJSON = Buffer.from(certText, "base64").toString();
43
- const cert: RpdCert = JSON.parse(certJSON);
40
+ const { deployId, cert: certText } = licenseSettings as LicenseSettings;
44
41
 
45
42
  try {
46
- const license = extractCertLicense(this.#encryptionKey, deployId, cert);
43
+ const license = this.parseLicense(deployId, certText);
47
44
  this.#license = license;
48
45
  } catch (error) {
49
46
  this.#server.getLogger().error("Loading license failed.", error);
@@ -55,6 +52,29 @@ export default class LicenseService {
55
52
  return this.#license;
56
53
  }
57
54
 
55
+ parseLicense(deployId: string, certText: string): RpdLicense {
56
+ const certJSON = Buffer.from(certText, "base64").toString();
57
+ const cert: RpdCert = JSON.parse(certJSON);
58
+ return extractCertLicense(this.#encryptionKey, deployId, cert);
59
+ }
60
+
61
+ async updateLicense(certText: string) {
62
+ const settingService = this.#server.getService<SettingService>("settingService");
63
+ const deployId: string = await settingService.getSystemSettingValue("license", "deployId");
64
+
65
+ let license: RpdLicense;
66
+ try {
67
+ license = this.parseLicense(deployId, certText);
68
+ } catch (error) {
69
+ this.#server.getLogger().error("Parse license failed.", error);
70
+ throw new Error("Parse license failed.");
71
+ }
72
+
73
+ await settingService.setSystemSettingValue("license", "cert", certText);
74
+ this.#license = license;
75
+ return license;
76
+ }
77
+
58
78
  isExpired() {
59
79
  if (!this.#license) {
60
80
  return true;
@@ -1,4 +1,5 @@
1
1
  import { IPluginActionHandler } from "~/core/actionHandler";
2
2
  import * as getLicense from "./getLicense";
3
+ import * as updateLicense from "./updateLicense";
3
4
 
4
- export default [getLicense] satisfies IPluginActionHandler[];
5
+ export default [getLicense, updateLicense] satisfies IPluginActionHandler[];
@@ -0,0 +1,24 @@
1
+ import { ActionHandlerContext } from "~/core/actionHandler";
2
+ import { RapidPlugin } from "~/core/server";
3
+ import LicenseService from "../LicenseService";
4
+
5
+ export interface UpdateLicenseOptions {}
6
+
7
+ export interface UpdateLicenseInput {
8
+ certText: string;
9
+ }
10
+
11
+ export const code = "updateLicense";
12
+
13
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: UpdateLicenseOptions) {
14
+ const { server, routerContext } = ctx;
15
+ const { response } = routerContext;
16
+
17
+ const input: UpdateLicenseInput = ctx.input;
18
+
19
+ const licenseService = server.getService<LicenseService>("licenseService");
20
+
21
+ const license = await licenseService.updateLicense(input.certText);
22
+
23
+ ctx.output = license;
24
+ }
@@ -1,3 +1,4 @@
1
1
  import getLicense from "./getLicense";
2
+ import updateLicense from "./updateLicense";
2
3
 
3
- export default [getLicense];
4
+ export default [getLicense, updateLicense];
@@ -0,0 +1,15 @@
1
+ import { RpdRoute } from "~/types";
2
+
3
+ export default {
4
+ namespace: "svc",
5
+ name: "svc.updateLicense",
6
+ code: "svc.updateLicense",
7
+ type: "RESTful",
8
+ method: "POST",
9
+ endpoint: "/svc/license",
10
+ actions: [
11
+ {
12
+ code: "updateLicense",
13
+ },
14
+ ],
15
+ } satisfies RpdRoute;