守门员报告 Utils
共享 PDF, 电子邮件, 日期, 附件, 以及 Gatekeeper JourneyApps 报告的显示助手 .
安装
将软件包添加到 JourneyApps CloudCode 任务中 :
{
"dependencies": {
"@gatekeeper_technology/report-utils": "1.3.3"
}
}
创建一个 .npmrc 在 CloudCode 任务中使用 1Password 的只读 npm 令牌 :
//registry.npmjs.org/:_authToken=<read-only-npm-token>
然后导入助手 :
const reportUtils = require("@gatekeeper_technology/report-utils");
共同实例
格式化日期
const {
displayDate,
displayDateTime,
displayTime,
displayTimeWithSeconds,
getOffsetDate,
getStartOfWeek,
getEndOfWeek,
getWeekNumber,
isSameDay,
compareDates,
} = require("@gatekeeper_technology/report-utils");
const date = new Date(2026, 6, 10, 8, 30, 0);
displayDate(date); // "10 Jul 2026"
displayDate(date, "long"); // "10 July 2026"
displayTime(date); // "08:30"
displayTimeWithSeconds(date); // "08:30:00"
displayDateTime(date); // "10 Jul 2026, 08:30"
getOffsetDate(date, 7); // date plus 7 days
getStartOfWeek(date); // Monday start, ISO mode by default
getEndOfWeek(date); // Sunday end, ISO mode by default
getWeekNumber(date); // calendar week number
isSameDay(date, new Date()); // true/false
compareDates(date, new Date()); // -1, 0, or 1
非日期投入一般返回 null 用于日期比较帮助者和 "-" 用于显示助手.
准备发送Grid 收件人
const {
getToEmailsArray,
setCheckWhitelistEnvironments,
} = require("@gatekeeper_technology/report-utils");
const recipients = getToEmailsArray(
[" [email protected] ", "[email protected]; [email protected]"],
["[email protected]", "[email protected]"],
"staging",
["[email protected]", "[email protected]"]
);
// recipients:
// {
// to: [{ email: "[email protected]" }, { email: "[email protected]" }],
// cc: []
// }
getToEmailsArray 三进制、小写、去重复、拆分逗号/半结号分隔字符串、去除已输入的 CC 地址,以及用白名单过滤 staging 财务报告和审定财务报表 testing。 。 。 .
要改变使用白名单的环境 :
setCheckWhitelistEnvironments(["testing", "staging", "production"]);
生成 HTML 并保存 PDF 附录
const {
generateHTML,
postToJourneyBackend,
} = require("@gatekeeper_technology/report-utils");
async function createReport(request, data) {
const html = generateHTML(data, __dirname, "templates/report.html");
const saved = await postToJourneyBackend(
request,
"report_pdf",
html,
`report-${request.id}.pdf`,
process.env.JOURNEY_PDF_REPORTS_TOKEN
);
if (!saved) {
throw new Error("Report PDF could not be generated or saved");
}
}
generateHTML 读取和编译 Handlebars 模板. postToJourneyBackend 生成 PDF 与 @journeyapps/pdf-reports,创建行进录 Attachment,将其分配给请求的字段,并保存对象.
在报表中使用相片和签名
const {
getImageContentForPDF,
isAttachmentsUploaded,
loadAttachments,
loadPhotoOrSignature,
} = require("@gatekeeper_technology/report-utils");
async function buildReportData(inspection) {
try {
isAttachmentsUploaded(inspection);
} catch (error) {
if (error.cause === "attachments-uploading") {
// Reschedule the CloudCode task using the app's normal retry pattern.
throw error;
}
throw error;
}
return loadAttachments({}, inspection);
}
async function addSignature(inspection) {
return loadPhotoOrSignature(inspection, "customer_signature");
}
async function addImage(inspection) {
return {
image_url: await getImageContentForPDF(inspection.photo, "url"),
image_base64: await getImageContentForPDF(inspection.photo, "base64"),
};
}
随附帮助 cause: "attachments-uploading" 当 JourneyApps 附件未完成上传时 。 抓住这个错误, 从调用应用程序中重新安排任务 .
何时 type 实值 "base64", (中文(简体) ), getImageContentForPDF 从基数64有效载荷(PNG,JPEG,GIF,WebP,SVG)中检测出图像MIME类型,回落到附件URL扩展,再回落到PNG.
显示 JourneyApps 字段和排序数据
const {
formatText,
getDisplayLabel,
getDisplayValue,
sortArrayByField,
} = require("@gatekeeper_technology/report-utils");
const label = getDisplayLabel(store, "store_type");
const value = getDisplayValue(store, "store_type");
formatText(" Store Visit / Audit "); // "store_visit_audit"
formatText(" Store Visit / Audit ", "higher"); // "STORE_VISIT_AUDIT"
const stores = [
{ name: "Cape Town", score: 88 },
{ name: "Durban", score: 72 },
];
sortArrayByField(stores, "score", -1); // sorts highest score first
sortArrayByField 使用 JavaScript 的本地语言 Array.sort,因此它使原始阵列变异.
导出帮助
日期和时间
displayDate(date, monthLength)displayDateTime(date, monthLength)displayTime(date)displayTimeWithSeconds(date)getOffsetDate(originalDate, offsetDays)getStartOfWeek(date, iso)getEndOfWeek(date, iso)getWeekNumber(date, iso)isSameDay(date1, date2)compareDates(date1, date2)
电子邮件
getToEmailsArray(toArray, ccArray, env, whitelist)setCheckWhitelistEnvironments(environments)storeValidEmail(emailObject, email)validateEmail(email)
附录 和 PDF 数据
getImageContentForPDF(image, type)loadImageBase64(path)loadAttachments(target, objectToCheck)loadPhotoOrSignature(object, fieldName)isAttachmentsUploaded(objectToCheck)isAttachmentUploaded(object, fieldName)generateHTML(data, dirName, fileName)postToJourneyBackend(object, fieldName, pdfHtml, fileName, token)
常规
getDisplayValue(object, field)getDisplayLabel(object, field)formatText(text, type)sortArrayByField(objectArray, fieldName, sortDirection)
发展
从 1Password 安装已发布 npm 令牌 :
//registry.npmjs.org/:_authToken=<publish-npm-token>
发布清单 :
- 在
src/*.ts并导出新的助手index.ts。 。 。 . - 行为改变时添加或更新 Jest 测试.
- 更新版本为
package.json。 。 。 . - 下面添加一个更改日志条目 .
- 运行
npm test。 。 。 . - 发布方式
npm publish。 。 。 . - 提交并推进发布.
更改日志
[1.3.3]
固定
getImageContentForPDF现在检测Base64数据URI(PNG,JPEG,GIF,WebP,SVG)的正确MIME类型,而不是将非SVG附件作为PNG处理.- 日期帮助者现在将无效的日期值视为无效并返回
null编号 :"-"见文件.
已更改
- 重写 README 有安装步骤、 使用示例和导出助手参考 .
- 将过时的照片附件测试替换为MIME检测、上传检查和本地图像加载的覆盖.
- 与当前行为一致的通用测试和日期测试,并添加了电子邮件功能覆盖.
- 添加的游戏 +
ts-jest因此TypeScript源可以直接测试.
[1.3.2]
已更改
- 弹出
@journeyapps/db从^8.0.10改为^8.1.1。 。 。 .
[1.3.1]
已更改
- 弹出
@gatekeeper_technology/rollbar-utils改为^1.2.4。 。 。 .
[1.3.0]
已更改
- 将软件包版本跳出到
1.3.0。 。 。 . - 弹出
@gatekeeper_technology/rollbar-utils改为^1.2.3。 。 。 . - 弹出
@journeyapps/db改为^8.0.10。 。 。 . - 删除了未使用的
@journeyapps/cloudcode依赖性.
[1.2.3]
已更改
- 弹出
@gatekeeper_technology/rollbar-utils从1.1.1改为^1.2.2。 。 。 .
[1.2.2]
固定
- 固定
postToJourneyBackend所以当目标字段缺失时它会抛出,而不是当球段存在时抛出.
已更改
- 添加参数文档
generateHTML。 。 。 .
[1.2.1]
删除
dist忽略文件在.npmignore。 。 。 .
[1.2.0]
已添加
- 已添加
postToJourneyBackend函数 - 已添加
journeyAppsnpm 包作为依赖性来帮助报告UTI 包. - 已添加
sortArrayByField函数 - 已添加
generateHTML函数 - 已添加
formatText函数 - 已添加
getImageContentForPDF函数
已更改
- 移动到类型脚本
- 所有日期功能现在都能够接受
Day变量. .gitignore文件现在忽略了编译的文件.isAttachment(s)Uploaded函数不再重新安排。 它现在抛出一个错误的原因=attachments-uploading
[1.1.10]
删除
- 删除
loadBase64函数在对时间的比赛中.
[1.1.9]
已添加
- 测试案例
- 格式Text, 排序ArrayBy Field并生成 HTML 函数
- .d.ts 文档.
[1.1.8]
已更改
- 在一般提法上添加更多验证
已添加
- 单位测试Utils将军.
删除
- 日期 Utils 上的控制台. error () .
[1.1.7]
已更改
- 抛出错误的固定方式
- 增加了一个带有小内部图案的新图案文件夹
[1.1.6]
已更改
- 重试任务时, 我们不需要指定 CloudCode 任务名称, 因为可以通过程序访问它
[1.1.5]
已添加
- isSameDay:检查给定的两个日期是否在同一天倒下(第二个日期值默认为现在).
- 比较数据:检查给定的两个日期是否在同一日期和时间(返回0)上倒下,日期1在日期2(返回-1)之前,否则返回1(第二次日期值缺省至今).
删除
- 今日: 可以通过 IsSameDay () 函数使用
- isPastDate和 isFutureDate:可以通过比较Dates()函数成为用户
已更改
- 改进测试文件( WIP)
[1.1.4]
已添加
- 等分数
- 等效时间
- 当今
- 获取开始Week
- 获取周深
- 获得周数
- 未来日期
- 边框
[1.1.3]
固定
- 无法导入错误
report-utils软件包/mobile一个App的一面.
[1.1.2]
已更改
- 家 移动
loadImageBase64函数改为index.js以查看所需("fs")问题是否已经解决.
[1.1.1]
已更改
- [测试]将要求("fs")移出功能.
[1.1.0]
已更改
- 重构文件结构以区分关切 .
- 已替换
displayPhoto与journeyPhotoToBase64,它现在有一个更描述性的名字 - 已替换
loadPhotoOrSignature与getPhotoOrSignatureData,现在由开发者将数据装入数据散列. - 已替换
loadSignatureBase64与encodeBase64ImagePNG,重新命名函数,并将输入参数改为实际图像数据.
[1.00.07] (中文(简体) )
已添加
index.js: 添加了指定在何种环境中启用电子邮件白名单的能力 .
[1.00.06]
已更改
index.js: 在检查是否有效之前, 电子邮件先被剪切并切换到下Case .
[1.00.05]
已更改
index.js: 改变了方式loadAttachments函数收到重试 计数值.
[1.00.04]
固定
index.js: 错误,其中loadPhotoOrSignature函数已过时.
[1.00.03]
已更改
index.js: 电子邮件检查现在将所有邮件转换为小写后再检查复制件 .
[1.00.02]
已添加
index.js: 添加函数displayTimeWithSeconds。 。 。 .
已更改
index.js页:1.
[1.00.01]
已更改
Readme.md:解释有所改进.index.js: 已添加函数displayDateTime财务报告和审定财务报表displayTime。 。 。 .
[1.0
已添加
package.json: 已补.index.js: 添加并配有守门员手提箱功能..npmignore: 已补..gitignore: 已补.README.md:添加了描述,设置和更改日志.