refactor phase 3a api admin auth documents email targeted actions imports
This commit is contained in:
@@ -18,11 +18,9 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import {
|
import { azureHeadersPagedCustom } from "../../../actions/core/headers";
|
||||||
azureHeadersPagedCustom,
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
consoleLogger,
|
import { getToken } from "../../../actions/core/token";
|
||||||
getToken,
|
|
||||||
} from "../../../actions";
|
|
||||||
import { number } from "prop-types";
|
import { number } from "prop-types";
|
||||||
|
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
@@ -154,7 +152,7 @@ export default async function ApiProxy(req, res) {
|
|||||||
let flattened = data.value.map((r) => ({
|
let flattened = data.value.map((r) => ({
|
||||||
...r,
|
...r,
|
||||||
ticketnumber: r.pinswg_DocumentIds?.ticketnumber || null,
|
ticketnumber: r.pinswg_DocumentIds?.ticketnumber || null,
|
||||||
publishtoweb: r.pinswg_DocumentIds?.pinswg_publishtoweb || null,
|
publishtoweb: r.pinswg_DocumentIds?.pinswg_publishtoweb || null
|
||||||
}));
|
}));
|
||||||
|
|
||||||
data.value = flattened;
|
data.value = flattened;
|
||||||
|
|||||||
@@ -18,11 +18,9 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import {
|
import { azureHeadersPagedCustom } from "../../../actions/core/headers";
|
||||||
azureHeadersPagedCustom,
|
import { getToken } from "../../../actions/core/token";
|
||||||
consoleLogger,
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
getToken,
|
|
||||||
} from "../../../actions";
|
|
||||||
|
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import { PrismaAdapter } from "@next-auth/prisma-adapter";
|
|||||||
import { PrismaClient } from "@prisma/client";
|
import { PrismaClient } from "@prisma/client";
|
||||||
import NextAuth from "next-auth";
|
import NextAuth from "next-auth";
|
||||||
import EmailProvider from "next-auth/providers/email";
|
import EmailProvider from "next-auth/providers/email";
|
||||||
import { consoleLogger, getPreferredLanguage } from "../../../actions";
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
|
import { getPreferredLanguage } from "../../../actions/services/accountService";
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ const parseUrl = (url) => {
|
|||||||
host: _url.host,
|
host: _url.host,
|
||||||
path,
|
path,
|
||||||
base,
|
base,
|
||||||
toString: () => base,
|
toString: () => base
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@ const authOptions = (locale, req, res) => {
|
|||||||
return res
|
return res
|
||||||
.writeHead(200, { "Content-Type": "application/json" })
|
.writeHead(200, { "Content-Type": "application/json" })
|
||||||
.json({ url: formURL });
|
.json({ url: formURL });
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
EmailProvider({
|
EmailProvider({
|
||||||
maxAge: 2 * 60 * 60, //10 * 60, // Magic links are valid for 10 min only
|
maxAge: 2 * 60 * 60, //10 * 60, // Magic links are valid for 10 min only
|
||||||
@@ -191,7 +192,7 @@ const authOptions = (locale, req, res) => {
|
|||||||
// url.split("&token")[1]
|
// url.split("&token")[1]
|
||||||
// : url,
|
// : url,
|
||||||
|
|
||||||
"linkExpiry": 2 * 60 * 60,
|
"linkExpiry": 2 * 60 * 60
|
||||||
};
|
};
|
||||||
const reference = "PEDW-SIGNIN";
|
const reference = "PEDW-SIGNIN";
|
||||||
|
|
||||||
@@ -208,14 +209,14 @@ const authOptions = (locale, req, res) => {
|
|||||||
emailAddress,
|
emailAddress,
|
||||||
{
|
{
|
||||||
personalisation: personalisation,
|
personalisation: personalisation,
|
||||||
reference: reference,
|
reference: reference
|
||||||
// emailReplyToId: emailReplyToId,
|
// emailReplyToId: emailReplyToId,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
//.then((response) => console.log(response))
|
//.then((response) => console.log(response))
|
||||||
.catch((error) => consoleLogger(error));
|
.catch((error) => consoleLogger(error));
|
||||||
},
|
}
|
||||||
}),
|
})
|
||||||
],
|
],
|
||||||
adapter: PrismaAdapter(prisma),
|
adapter: PrismaAdapter(prisma),
|
||||||
secret: process.env.NEXTAUTH_SECRET,
|
secret: process.env.NEXTAUTH_SECRET,
|
||||||
@@ -226,7 +227,7 @@ const authOptions = (locale, req, res) => {
|
|||||||
theme: "dark",
|
theme: "dark",
|
||||||
debug: true,
|
debug: true,
|
||||||
maxAge: 30 * 60,
|
maxAge: 30 * 60,
|
||||||
updateAge: 5 * 60, // 24 hours
|
updateAge: 5 * 60 // 24 hours
|
||||||
},
|
},
|
||||||
cookies: {
|
cookies: {
|
||||||
callbackUrl: {
|
callbackUrl: {
|
||||||
@@ -234,16 +235,16 @@ const authOptions = (locale, req, res) => {
|
|||||||
options: {
|
options: {
|
||||||
sameSite: "lax",
|
sameSite: "lax",
|
||||||
path: "/",
|
path: "/",
|
||||||
secure: true,
|
secure: true
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
pages: {
|
pages: {
|
||||||
signIn: (locale == "cy" ? "/cy" : "") + "/auth/signin",
|
signIn: (locale == "cy" ? "/cy" : "") + "/auth/signin",
|
||||||
error: (locale == "cy" ? "/cy" : "") + "/auth/error", // Error code passed in query string as ?error=
|
error: (locale == "cy" ? "/cy" : "") + "/auth/error", // Error code passed in query string as ?error=
|
||||||
verifyRequest:
|
verifyRequest:
|
||||||
(locale == "cy" ? "/cy" : "") + "/auth/verify-request", // (used for check email message)
|
(locale == "cy" ? "/cy" : "") + "/auth/verify-request", // (used for check email message)
|
||||||
newUser: (locale == "cy" ? "/cy" : "") + "/account/register", // New users will be directed here on first sign in (leave the property out if not of interest)
|
newUser: (locale == "cy" ? "/cy" : "") + "/account/register" // New users will be directed here on first sign in (leave the property out if not of interest)
|
||||||
},
|
},
|
||||||
callbacks: {
|
callbacks: {
|
||||||
session: async (session, user) => {
|
session: async (session, user) => {
|
||||||
@@ -275,8 +276,8 @@ const authOptions = (locale, req, res) => {
|
|||||||
|
|
||||||
console.log("the url:", updatedUrl);
|
console.log("the url:", updatedUrl);
|
||||||
return updatedUrl;
|
return updatedUrl;
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,8 @@
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getToken, consoleLogger } from "../../../../actions";
|
import { getToken } from "../../../../actions/core/token";
|
||||||
|
import { consoleLogger } from "../../../../actions/core/logger";
|
||||||
|
|
||||||
const WEBAPI_URL =
|
const WEBAPI_URL =
|
||||||
process.env.RELAY_ROOT ||
|
process.env.RELAY_ROOT ||
|
||||||
@@ -149,9 +150,9 @@ const ApiProxy = async (req, res) => {
|
|||||||
"Prefer":
|
"Prefer":
|
||||||
'odata.include-annotations="*",return=representation',
|
'odata.include-annotations="*",return=representation',
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": "Bearer " + token.access_token,
|
"Authorization": "Bearer " + token.access_token
|
||||||
},
|
},
|
||||||
responseType: "stream",
|
responseType: "stream"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -196,8 +197,8 @@ const ApiProxy = async (req, res) => {
|
|||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
api: {
|
api: {
|
||||||
responseLimit: false,
|
responseLimit: false
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ApiProxy;
|
export default ApiProxy;
|
||||||
|
|||||||
+22
-26
@@ -1,13 +1,9 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import {
|
import { azureHeaders, azureHeadersPaged } from "../../../actions/core/headers";
|
||||||
getToken,
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
azureHeaders,
|
import { getToken } from "../../../actions/core/token";
|
||||||
azureHeadersPaged,
|
|
||||||
consoleLogger,
|
|
||||||
sendEmail,
|
|
||||||
} from "../../../actions";
|
|
||||||
import { formatDates } from "../../../components/utils";
|
import { formatDates } from "../../../components/utils";
|
||||||
|
|
||||||
var NotifyClient = require("notifications-node-client").NotifyClient;
|
var NotifyClient = require("notifications-node-client").NotifyClient;
|
||||||
@@ -79,14 +75,14 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
|||||||
noRef: "No Ref",
|
noRef: "No Ref",
|
||||||
untitled: "Untitled",
|
untitled: "Untitled",
|
||||||
noDate: "No Date",
|
noDate: "No Date",
|
||||||
link: "Link",
|
link: "Link"
|
||||||
},
|
},
|
||||||
cy: {
|
cy: {
|
||||||
noRef: "Dim Cyfeirnod",
|
noRef: "Dim Cyfeirnod",
|
||||||
untitled: "Heb Deitl",
|
untitled: "Heb Deitl",
|
||||||
noDate: "Dim Dyddiad",
|
noDate: "Dim Dyddiad",
|
||||||
link: "Dolen",
|
link: "Dolen"
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const t = labels[language] || labels.en;
|
const t = labels[language] || labels.en;
|
||||||
@@ -114,13 +110,13 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
|||||||
en: {
|
en: {
|
||||||
unnamed: "Unnamed Event",
|
unnamed: "Unnamed Event",
|
||||||
noDate: "No Date",
|
noDate: "No Date",
|
||||||
on: "on",
|
on: "on"
|
||||||
},
|
},
|
||||||
cy: {
|
cy: {
|
||||||
unnamed: "Digwyddiad Heb Enw",
|
unnamed: "Digwyddiad Heb Enw",
|
||||||
noDate: "Dim Dyddiad",
|
noDate: "Dim Dyddiad",
|
||||||
on: "ar",
|
on: "ar"
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const t = labels[language] || labels.en;
|
const t = labels[language] || labels.en;
|
||||||
@@ -144,14 +140,14 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
|||||||
open: "Open",
|
open: "Open",
|
||||||
to: "to",
|
to: "to",
|
||||||
close: "Close",
|
close: "Close",
|
||||||
na: "N/A",
|
na: "N/A"
|
||||||
},
|
},
|
||||||
cy: {
|
cy: {
|
||||||
open: "Agor",
|
open: "Agor",
|
||||||
to: "i",
|
to: "i",
|
||||||
close: "Cau",
|
close: "Cau",
|
||||||
na: "Dim ar gael",
|
na: "Dim ar gael"
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const t = labels[language] || labels.en;
|
const t = labels[language] || labels.en;
|
||||||
@@ -234,7 +230,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
|||||||
docSection,
|
docSection,
|
||||||
sipSection,
|
sipSection,
|
||||||
repsSection,
|
repsSection,
|
||||||
caseUnsubscribelink,
|
caseUnsubscribelink
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join("\n")}`;
|
.join("\n")}`;
|
||||||
@@ -242,7 +238,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
|||||||
.join("\n\n"),
|
.join("\n\n"),
|
||||||
unsubscribeLink: `Unsubscribe by selecting this link if you no longer want to receive any updates ${
|
unsubscribeLink: `Unsubscribe by selecting this link if you no longer want to receive any updates ${
|
||||||
process.env.NEXTAUTH_URL + "/unsubscribeall/" + contactId
|
process.env.NEXTAUTH_URL + "/unsubscribeall/" + contactId
|
||||||
}`,
|
}`
|
||||||
};
|
};
|
||||||
|
|
||||||
const personalisationCY = {
|
const personalisationCY = {
|
||||||
@@ -281,7 +277,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
|||||||
docSection,
|
docSection,
|
||||||
sipSection,
|
sipSection,
|
||||||
repsSection,
|
repsSection,
|
||||||
caseUnsubscribelink,
|
caseUnsubscribelink
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join("\n")}`;
|
.join("\n")}`;
|
||||||
@@ -289,7 +285,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
|||||||
.join("\n\n"),
|
.join("\n\n"),
|
||||||
unsubscribeLink: `Dad-danysgrifiwch drwy ddewis y ddolen hon os nad ydych chi eisiau derbyn unrhyw ddiweddariadau mwyach ${
|
unsubscribeLink: `Dad-danysgrifiwch drwy ddewis y ddolen hon os nad ydych chi eisiau derbyn unrhyw ddiweddariadau mwyach ${
|
||||||
process.env.NEXTAUTH_URL + "/unsubscribeall/" + contactId
|
process.env.NEXTAUTH_URL + "/unsubscribeall/" + contactId
|
||||||
}`,
|
}`
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -305,7 +301,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
|||||||
process.env.NEXTAUTH_URL +
|
process.env.NEXTAUTH_URL +
|
||||||
(prefLanguage == 846040001 ? "en" : "cy") +
|
(prefLanguage == 846040001 ? "en" : "cy") +
|
||||||
"/unsubscribeall/" +
|
"/unsubscribeall/" +
|
||||||
contactId,
|
contactId
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(Boolean); // Remove any nulls from filtered-out users
|
.filter(Boolean); // Remove any nulls from filtered-out users
|
||||||
@@ -348,7 +344,7 @@ export default async function CombinedApiProxy(req, res) {
|
|||||||
...doc,
|
...doc,
|
||||||
pinswg_hashlink: encryptDocReference(
|
pinswg_hashlink: encryptDocReference(
|
||||||
doc.pinswg_isharedocumentreference
|
doc.pinswg_isharedocumentreference
|
||||||
),
|
)
|
||||||
}));
|
}));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
consoleLogger(
|
consoleLogger(
|
||||||
@@ -401,7 +397,7 @@ export default async function CombinedApiProxy(req, res) {
|
|||||||
...entry,
|
...entry,
|
||||||
repsPeriods,
|
repsPeriods,
|
||||||
documents,
|
documents,
|
||||||
sipEvents,
|
sipEvents
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -428,7 +424,7 @@ export default async function CombinedApiProxy(req, res) {
|
|||||||
reference: payload.reference,
|
reference: payload.reference,
|
||||||
template_id: payload.template_id,
|
template_id: payload.template_id,
|
||||||
language:
|
language:
|
||||||
payload.pinswg_preferredlanguage == 846040001 ? "en" : "cy",
|
payload.pinswg_preferredlanguage == 846040001 ? "en" : "cy"
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -437,7 +433,7 @@ export default async function CombinedApiProxy(req, res) {
|
|||||||
payload.email_address,
|
payload.email_address,
|
||||||
{
|
{
|
||||||
personalisation: payload.personalisation,
|
personalisation: payload.personalisation,
|
||||||
reference: payload.reference,
|
reference: payload.reference
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
result.status = "success";
|
result.status = "success";
|
||||||
@@ -455,7 +451,7 @@ export default async function CombinedApiProxy(req, res) {
|
|||||||
consoleLogger(error);
|
consoleLogger(error);
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
error: "An error occurred while retrieving combined data.",
|
error: "An error occurred while retrieving combined data.",
|
||||||
details: error.message || error.toString(),
|
details: error.message || error.toString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { getToken, azureHeaders, consoleLogger } from "../../../actions";
|
import { azureHeaders } from "../../../actions/core/headers";
|
||||||
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
|
import { getToken } from "../../../actions/core/token";
|
||||||
|
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { azureHeadersPaged, consoleLogger, getToken } from "../../../actions";
|
import { azureHeadersPaged } from "../../../actions/core/headers";
|
||||||
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
|
import { getToken } from "../../../actions/core/token";
|
||||||
|
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
const WEBAPI_URL =
|
const WEBAPI_URL =
|
||||||
@@ -84,7 +86,7 @@ export default async function ApiProxy(req, res) {
|
|||||||
...doc,
|
...doc,
|
||||||
pinswg_hashlink: encryptDocReference(
|
pinswg_hashlink: encryptDocReference(
|
||||||
doc.pinswg_isharedocumentreference
|
doc.pinswg_isharedocumentreference
|
||||||
),
|
)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
res.status(200).json({ ...data, value: resultsWithLinks });
|
res.status(200).json({ ...data, value: resultsWithLinks });
|
||||||
@@ -92,7 +94,7 @@ export default async function ApiProxy(req, res) {
|
|||||||
consoleLogger(error);
|
consoleLogger(error);
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
error: "Failed to fetch document details.",
|
error: "Failed to fetch document details.",
|
||||||
details: error.message || error.toString(),
|
details: error.message || error.toString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { getToken, azureHeaders, consoleLogger } from "../../../actions";
|
import { azureHeaders } from "../../../actions/core/headers";
|
||||||
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
|
import { getToken } from "../../../actions/core/token";
|
||||||
|
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
const WEBAPI_URL =
|
const WEBAPI_URL =
|
||||||
@@ -67,7 +69,7 @@ export default async function ApiProxy(req, res) {
|
|||||||
consoleLogger(error);
|
consoleLogger(error);
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
error: "An error occurred while retrieving data.",
|
error: "An error occurred while retrieving data.",
|
||||||
details: error.message || error.toString(),
|
details: error.message || error.toString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { getToken, azureHeaders, consoleLogger } from "../../../actions";
|
import { azureHeaders } from "../../../actions/core/headers";
|
||||||
|
import { consoleLogger } from "../../../actions/core/logger";
|
||||||
|
import { getToken } from "../../../actions/core/token";
|
||||||
|
|
||||||
const WORDKEY = process.env.HASHKEY;
|
const WORDKEY = process.env.HASHKEY;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user