Workflow-App/Workflow/scripts/_patch_vat_fields.js
sjcoetzeesj-coder 11d0178ab1 feat: commit Workflow app source; move CIPC credentials to env
Adds the full Next.js app (app/, components/, lib/, scripts/, assets/,
docs/, Dockerfile, compose, configs) to version control.

Security:
- CIPC BizPortal customer-code logins (Login 1 + Login 3) now read
  CIPC_LOGIN1_CODE / CIPC_LOGIN1_PASSWORD / CIPC_LOGIN3_CODE /
  CIPC_LOGIN3_PASSWORD from .env.local instead of source.
- BizPortal personal login in apply-bizportal route reads
  BIZPORTAL_ID_NO / BIZPORTAL_PASSWORD.
- Added .env.example as the committed template.

.gitignore excludes .env*, node_modules, .next, logs, sqlite, Playwright
storage_state.json (live CIPC cookies), scratch dirs, client PDFs and
debug screenshots.
2026-10-18 15:21:45 +02:00

68 lines
3.9 KiB
JavaScript

// scripts/_patch_vat_fields.js
// Try with `fields` instead of `schema` to see if PB persists the
// schema that way (some PB versions expect "fields" on PATCH).
const fs = require("node:fs");
const path = require("node:path");
const ENV_PATH = path.join(__dirname, "..", ".env.local");
for (const line of fs.readFileSync(ENV_PATH, "utf-8").split(/\r?\n/)) {
const m = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
if (m && !process.env[m[1]]) process.env[m[1]] = m[2].trim();
}
const PB_URL = process.env.PB_URL;
const PB_TOKEN = process.env.PB_TOKEN;
const COLLECTION_ID = "pbc_3919993741";
const fields = [
{ name: "period", type: "text", required: true, options: { min: 6, max: 6, pattern: "^\\d{6}$" } },
{ name: "Standard Rate 1", type: "number", required: false, options: {} },
{ name: "Zero Rate 2", type: "number", required: false, options: {} },
{ name: "Exempt and non Supplies 3", type: "number", required: false, options: {} },
{ name: "Capital goods and services supplied to you 14", type: "number", required: false, options: {} },
{ name: "Other goods and services supplied to you 15", type: "number", required: false, options: {} },
{ name: "total_payable", type: "number", required: false, options: {} },
{ name: "interest_d", type: "number", required: false, options: {} },
{ name: "penalties_d", type: "number", required: false, options: {} },
{ name: "status", type: "select", required: true, options: { maxSelect: 1, values: ["draft", "submitted", "paid"] } },
{ name: "date_submitted", type: "date", required: false, options: { min: "", max: "" } },
{ name: "date_paid", type: "date", required: false, options: { min: "", max: "" } },
{ name: "due_date", type: "date", required: false, options: { min: "", max: "" } },
{ name: "payment_reference", type: "text", required: false, options: { min: 0, max: 100, pattern: "" } },
{ name: "company_period_key", type: "text", required: false, options: { min: 0, max: 0, pattern: "" } },
{ name: "company", type: "relation", required: true, options: { collectionId: "pbc_3748838150", cascadeDelete: false, minSelect: 1, maxSelect: 1 } },
{ name: "Return_Filed", type: "bool", required: false, options: {} },
{ name: "last_updated", type: "date", required: false, options: { min: "", max: "" } },
{ name: "notes", type: "text", required: false, options: { min: 0, max: 0, pattern: "" } },
{ name: "First Name", type: "text", required: false, options: { min: 0, max: 0, pattern: "" } },
{ name: "Surname", type: "text", required: false, options: { min: 0, max: 0, pattern: "" } },
{ name: "Capacity", type: "text", required: false, options: { min: 0, max: 0, pattern: "" } },
{ name: "Bus Tel no", type: "number", required: false, options: {} },
{ name: "Cell no", type: "number", required: false, options: {} },
{ name: "Contact Email", type: "email", required: false, options: { exceptDomains: [], onlyDomains: [] } },
{ name: "is_active", type: "bool", required: false, options: {} },
{ name: "documents", type: "file", required: false, options: { maxSelect: 10, maxSize: 10485760, mimeTypes: ["application/pdf", "image/png", "image/jpeg"], thumbs: null, protected: false } },
];
(async () => {
console.log(`PATCH /api/collections/${COLLECTION_ID} (with key=fields)`);
const res = await fetch(`${PB_URL}/api/collections/${COLLECTION_ID}`, {
method: "PATCH",
headers: { Authorization: PB_TOKEN, "Content-Type": "application/json" },
body: JSON.stringify({ fields }),
});
const text = await res.text();
console.log(`HTTP ${res.status}`);
if (!res.ok) {
console.error(`Failed: ${text.slice(0, 600)}`);
process.exit(1);
}
const json = JSON.parse(text);
console.log(`fields returned: ${(json.fields || []).length}`);
console.log(`schema returned: ${(json.schema || []).length}`);
process.exit(0);
})().catch((err) => {
console.error("Unexpected error:", err);
process.exit(1);
});