@yrpri/api 9.0.127 → 9.0.129

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/app.js CHANGED
@@ -904,21 +904,20 @@ export class YourPrioritiesApi {
904
904
  err: bodyError,
905
905
  });
906
906
  }
907
- log.error("General Error", {
908
- context: "generalError",
909
- user: req.user ? toJson(req.user) : null,
910
- err: err,
911
- protocol: req.protocol,
912
- host: req.get("host"),
913
- originalUrl: req.originalUrl,
914
- body,
915
- errStack: err.stack,
916
- errorStatus: status,
917
- });
918
- err.url = req.url;
919
- err.params = req.params;
920
- if (status !== 404 && status !== 401) {
921
- // Optionally notify an error tracking service like Airbrake
907
+ if (status >= 500) {
908
+ log.error("General Error", {
909
+ context: "generalError",
910
+ user: req.user ? toJson(req.user) : null,
911
+ err: err,
912
+ protocol: req.protocol,
913
+ host: req.get("host"),
914
+ originalUrl: req.originalUrl,
915
+ body,
916
+ errStack: err.stack,
917
+ errorStatus: status,
918
+ });
919
+ err.url = req.url;
920
+ err.params = req.params;
922
921
  if (airbrake) {
923
922
  airbrake.notify(err).then((airbrakeErr) => {
924
923
  if (airbrakeErr.error) {
@@ -932,6 +931,18 @@ export class YourPrioritiesApi {
932
931
  });
933
932
  }
934
933
  }
934
+ else {
935
+ log.warn("Client Error", {
936
+ context: "clientError",
937
+ user: req.user ? toJson(req.user) : null,
938
+ err: err.message || err,
939
+ protocol: req.protocol,
940
+ host: req.get("host"),
941
+ originalUrl: req.originalUrl,
942
+ body,
943
+ errorStatus: status,
944
+ });
945
+ }
935
946
  res.sendStatus(status);
936
947
  });
937
948
  }
@@ -860,6 +860,9 @@ function updateDomainProperties(domain, req) {
860
860
  domain.set('configuration.sortAlphabetically', truthValueFromBody(req.body.sortAlphabetically));
861
861
  domain.set('configuration.useFixedTopAppBar', truthValueFromBody(req.body.useFixedTopAppBar));
862
862
  domain.set('configuration.disableArrowBasedTopNavigation', truthValueFromBody(req.body.disableArrowBasedTopNavigation));
863
+ domain.set('configuration.customerAiTokenMarkupPercent', req.body.customerAiTokenMarkupPercent && req.body.customerAiTokenMarkupPercent !== ''
864
+ ? parseInt(req.body.customerAiTokenMarkupPercent)
865
+ : null);
863
866
  domain.set('configuration.onlyAllowCreateUserOnInvite', truthValueFromBody(req.body.onlyAllowCreateUserOnInvite));
864
867
  domain.name = req.body.name;
865
868
  domain.description = req.body.description;
@@ -2227,10 +2227,20 @@ router.get('/auth/oidc/callback', function (req, res) {
2227
2227
  req.sso.authenticate('oidc-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2228
2228
  if (error) {
2229
2229
  log.error("Error from OIDC login", { err: error });
2230
- res.sendStatus(500);
2230
+ if (process.env.REDIRECT_AFTER_OIDC_ERROR_URL) {
2231
+ res.redirect(process.env.REDIRECT_AFTER_OIDC_ERROR_URL);
2232
+ }
2233
+ else {
2234
+ res.sendStatus(500);
2235
+ }
2231
2236
  }
2232
2237
  else {
2233
- res.render('samlLoginComplete', {});
2238
+ if (process.env.REDIRECT_TO_ROOT_AFTER_OIDC) {
2239
+ res.redirect('/');
2240
+ }
2241
+ else {
2242
+ res.render('samlLoginComplete', {});
2243
+ }
2234
2244
  }
2235
2245
  });
2236
2246
  });
@@ -2239,10 +2249,20 @@ router.get('/auth/audkenni/callback', async function (req, res) {
2239
2249
  req.sso.authenticate('oidc-strategy-' + req.ypDomain.id, {}, req, res, function (error, user) {
2240
2250
  if (error) {
2241
2251
  log.error("Error from Audkenni login", { err: error });
2242
- res.sendStatus(500);
2252
+ if (process.env.REDIRECT_AFTER_OIDC_ERROR_URL) {
2253
+ res.redirect(process.env.REDIRECT_AFTER_OIDC_ERROR_URL);
2254
+ }
2255
+ else {
2256
+ res.sendStatus(500);
2257
+ }
2243
2258
  }
2244
2259
  else {
2245
- res.render('samlLoginComplete', {});
2260
+ if (process.env.REDIRECT_TO_ROOT_AFTER_OIDC) {
2261
+ res.redirect('/');
2262
+ }
2263
+ else {
2264
+ res.render('samlLoginComplete', {});
2265
+ }
2246
2266
  }
2247
2267
  });
2248
2268
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yrpri/api",
3
- "version": "9.0.127",
3
+ "version": "9.0.129",
4
4
  "license": "MIT",
5
5
  "author": "Robert Bjarnason & Citizens Foundation",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "@google-cloud/vertexai": "^1.10.0",
26
26
  "@google-cloud/vision": "^5.1.0",
27
27
  "@node-saml/passport-saml": "^5.0.1",
28
- "@policysynth/agents": "^1.3.104",
28
+ "@policysynth/agents": "^1.3.105",
29
29
  "async": "^3.2.6",
30
30
  "authorized": "^1.0.0",
31
31
  "aws-sdk": "^2.1692.0",
@@ -2,11 +2,17 @@ import ExcelJS from 'exceljs';
2
2
  import models from '../../models/index.cjs';
3
3
  (async () => {
4
4
  try {
5
- const [xlsPath] = process.argv.slice(2);
5
+ const [xlsPath, clientId, clientSecret, issuer, authorizationURL, tokenURL, userInfoURL,] = process.argv.slice(2);
6
6
  if (!xlsPath) {
7
- console.log('Usage: node importDomainsFromXls.js <path-to-xls>');
7
+ console.log('Usage: node importDomainsFromXls.js <path-to-xls> [clientId clientSecret issuer authorizationURL tokenURL userInfoURL]');
8
8
  process.exit(1);
9
9
  }
10
+ const oidcProvided = clientId &&
11
+ clientSecret &&
12
+ issuer &&
13
+ authorizationURL &&
14
+ tokenURL &&
15
+ userInfoURL;
10
16
  const workbook = new ExcelJS.Workbook();
11
17
  await workbook.xlsx.readFile(xlsPath);
12
18
  const worksheet = workbook.getWorksheet(1);
@@ -15,6 +21,16 @@ import models from '../../models/index.cjs';
15
21
  process.exit(1);
16
22
  }
17
23
  await models.sequelize.transaction(async (t) => {
24
+ const oidcKeys = oidcProvided
25
+ ? {
26
+ client_id: clientId,
27
+ client_secret: clientSecret,
28
+ issuer,
29
+ authorizationURL,
30
+ tokenURL,
31
+ userInfoURL,
32
+ }
33
+ : null;
18
34
  for (let i = 2; i <= worksheet.rowCount; i++) {
19
35
  const row = worksheet.getRow(i);
20
36
  const name = String(row.getCell(1).text).trim();
@@ -26,7 +42,16 @@ import models from '../../models/index.cjs';
26
42
  transaction: t
27
43
  });
28
44
  if (existing) {
29
- await existing.update({ description }, { transaction: t });
45
+ const updateFields = { description };
46
+ if (oidcKeys) {
47
+ const e = existing;
48
+ const secretKeys = e.secret_api_keys || {};
49
+ secretKeys.oidc = oidcKeys;
50
+ e.secret_api_keys = secretKeys;
51
+ e.changed('secret_api_keys', true);
52
+ updateFields.secret_api_keys = secretKeys;
53
+ }
54
+ await existing.update(updateFields, { transaction: t });
30
55
  console.log(`Updated domain ${existing.domain_name}`);
31
56
  }
32
57
  else {
@@ -41,7 +66,8 @@ import models from '../../models/index.cjs';
41
66
  ip_address: '127.0.0.1',
42
67
  user_agent: 'import-script',
43
68
  default_locale: 'en',
44
- configuration: {}
69
+ configuration: {},
70
+ ...(oidcKeys ? { secret_api_keys: { oidc: oidcKeys } } : {})
45
71
  }, { transaction: t });
46
72
  console.log(`Created domain ${domainName}`);
47
73
  }
package/src/server.d.ts CHANGED
@@ -37,6 +37,7 @@ interface DomainClass extends DbData {
37
37
  ltp?: {
38
38
  crt?: LtpCurrentRealityTreeData
39
39
  }
40
+ customerAiTokenMarkupPercent?: number;
40
41
  };
41
42
  }
42
43