@yrpri/api 9.0.124 → 9.0.126

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
@@ -502,7 +502,15 @@ export class YourPrioritiesApi {
502
502
  this.app.use(requestIp.mw());
503
503
  this.app.use(bodyParser.json({ limit: "100mb", strict: false }));
504
504
  this.app.use(bodyParser.urlencoded({ limit: "100mb", extended: true }));
505
- this.app.use(cors());
505
+ if (process.env.ALLOWED_ORIGINS) {
506
+ this.app.use(cors({
507
+ origin: process.env.ALLOWED_ORIGINS.split(","),
508
+ credentials: true,
509
+ }));
510
+ }
511
+ else {
512
+ this.app.use(cors());
513
+ }
506
514
  this.app.use(compression());
507
515
  this.app.set("views", __dirname + "/views");
508
516
  this.app.set("view engine", "pug");
@@ -510,13 +518,19 @@ export class YourPrioritiesApi {
510
518
  if (!process.env.SESSION_SECRET) {
511
519
  throw new Error("SESSION_SECRET is not set");
512
520
  }
521
+ let cookieValues = {
522
+ autoSubDomain: true,
523
+ };
524
+ if (process.env.ALLOWED_ORIGINS) {
525
+ cookieValues.sameSite = "none";
526
+ }
513
527
  const sessionConfig = {
514
528
  store: store,
515
529
  name: "yrpri.sid",
516
530
  secret: process.env.SESSION_SECRET,
517
531
  resave: false,
518
532
  proxy: process.env.USING_NGINX_PROXY ? true : undefined,
519
- cookie: { autoSubDomain: true },
533
+ cookie: cookieValues,
520
534
  saveUninitialized: false,
521
535
  };
522
536
  if (this.app.get("env") === "production") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yrpri/api",
3
- "version": "9.0.124",
3
+ "version": "9.0.126",
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.102",
28
+ "@policysynth/agents": "^1.3.103",
29
29
  "async": "^3.2.6",
30
30
  "authorized": "^1.0.0",
31
31
  "aws-sdk": "^2.1692.0",
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ import ExcelJS from 'exceljs';
2
+ import models from '../../models/index.cjs';
3
+ (async () => {
4
+ try {
5
+ const [xlsPath] = process.argv.slice(2);
6
+ if (!xlsPath) {
7
+ console.log('Usage: node importDomainsFromXls.js <path-to-xls>');
8
+ process.exit(1);
9
+ }
10
+ const workbook = new ExcelJS.Workbook();
11
+ await workbook.xlsx.readFile(xlsPath);
12
+ const worksheet = workbook.getWorksheet(1);
13
+ if (!worksheet) {
14
+ console.error('No worksheet found in file');
15
+ process.exit(1);
16
+ }
17
+ await models.sequelize.transaction(async (t) => {
18
+ for (let i = 2; i <= worksheet.rowCount; i++) {
19
+ const row = worksheet.getRow(i);
20
+ const name = String(row.getCell(1).text).trim();
21
+ const description = String(row.getCell(2).text).trim();
22
+ if (!name)
23
+ continue;
24
+ const existing = await models.Domain.findOne({
25
+ where: { name },
26
+ transaction: t
27
+ });
28
+ if (existing) {
29
+ await existing.update({ description }, { transaction: t });
30
+ console.log(`Updated domain ${existing.domain_name}`);
31
+ }
32
+ else {
33
+ const randomPart = Math.random().toString(36).substring(2, 10);
34
+ const domainName = `domain_${randomPart}`;
35
+ await models.Domain.create({
36
+ name,
37
+ description,
38
+ domain_name: domainName,
39
+ access: 1,
40
+ user_id: 1,
41
+ ip_address: '127.0.0.1',
42
+ user_agent: 'import-script',
43
+ default_locale: 'en',
44
+ configuration: {}
45
+ }, { transaction: t });
46
+ console.log(`Created domain ${domainName}`);
47
+ }
48
+ }
49
+ });
50
+ await models.sequelize.close();
51
+ console.log('Import completed');
52
+ process.exit(0);
53
+ }
54
+ catch (err) {
55
+ console.error(err);
56
+ process.exit(1);
57
+ }
58
+ })();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ import ExcelJS from 'exceljs';
2
+ import models from '../../models/index.cjs';
3
+ (async () => {
4
+ try {
5
+ const [filePath] = process.argv.slice(2);
6
+ if (!filePath) {
7
+ console.log('Usage: node importUsersForDomainsFromXls.js <xlsFilePath>');
8
+ process.exit(1);
9
+ }
10
+ const workbook = new ExcelJS.Workbook();
11
+ await workbook.xlsx.readFile(filePath);
12
+ const sheet = workbook.worksheets[0];
13
+ const transaction = await models.sequelize.transaction();
14
+ try {
15
+ for (let i = 2; i <= sheet.rowCount; i++) {
16
+ const row = sheet.getRow(i);
17
+ const domainName = String(row.getCell(1).text).trim();
18
+ const fullUserName = String(row.getCell(2).text).trim();
19
+ const userEmail = String(row.getCell(3).text).trim().toLowerCase();
20
+ const userSsn = String(row.getCell(4).text).trim();
21
+ const userSsnNumber = userSsn ? Number(userSsn) : undefined;
22
+ if (!domainName || !fullUserName || !userEmail) {
23
+ throw new Error(`Missing data in row ${i}`);
24
+ }
25
+ const existingEmail = await models.User.unscoped().findOne({
26
+ where: { email: userEmail },
27
+ transaction,
28
+ });
29
+ if (existingEmail) {
30
+ throw new Error(`User with email ${userEmail} already exists`);
31
+ }
32
+ if (userSsn) {
33
+ const existingSsn = await models.User.unscoped().findOne({
34
+ where: { ssn: userSsn },
35
+ transaction,
36
+ });
37
+ if (existingSsn) {
38
+ throw new Error(`User with ssn ${userSsn} already exists`);
39
+ }
40
+ }
41
+ let domain = await models.Domain.findOne({
42
+ where: { domain_name: domainName },
43
+ transaction,
44
+ });
45
+ if (!domain) {
46
+ domain = await models.Domain.create({
47
+ domain_name: domainName,
48
+ name: domainName,
49
+ access: 1,
50
+ ip_address: '127.0.0.1',
51
+ user_agent: 'xls-import',
52
+ default_locale: 'en',
53
+ configuration: {},
54
+ }, { transaction });
55
+ }
56
+ const user = await models.User.create({
57
+ email: userEmail,
58
+ name: fullUserName,
59
+ status: 'active',
60
+ ssn: userSsnNumber,
61
+ }, { transaction });
62
+ await domain.addDomainUsers(user, { transaction });
63
+ }
64
+ await transaction.commit();
65
+ console.log('Import completed');
66
+ process.exit(0);
67
+ }
68
+ catch (error) {
69
+ await transaction.rollback();
70
+ throw error;
71
+ }
72
+ }
73
+ catch (err) {
74
+ console.error(err);
75
+ process.exit(1);
76
+ }
77
+ })();