import { fetch } from "https://esm.town/v/std/fetch";
let { californiaBusinessNotificationsLast } = await import("https://esm.town/v/tmcw/californiaBusinessNotificationsLast");
export const californiaBusinessNotifications = (async () => {
const { parse } = await import("https://deno.land/x/xml/mod.ts");
const res: any = await fetch(
"https://bizfileonline.sos.ca.gov/api/FilingDetail/business/4603/false",
{
headers: {
Accept: "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": "Mozilla/5.0",
},
},
).then((r) => r.text()).then(parse);
const list = res.DRAWER.DRAWER_DETAIL_LIST.DRAWER_DETAIL.map((detail) => {
return `## ${detail.LABEL}${detail.ALERT_YN ? " (alert)" : ""}
${detail.VALUE}`;
});
const lastValue = new Set(
californiaBusinessNotificationsLast || [],
);
let newEntries = [];
let removedEntries = [];
for (let val of list) {
if (!lastValue.has(val)) {
newEntries.push(val);
}
}
for (let val of lastValue.values()) {
if (!list.includes(val)) {
removedEntries.push(val);
}
}
californiaBusinessNotificationsLast = list;
if (newEntries.length || removedEntries.length) {
console.email(
`
Removed entries:
${removedEntries.join("\n\n")}
New entries:
${newEntries.join("\n\n")}`,
`Change in California business records!`,
);
}
return list;
})();