sc-postiz-poster/lib/config.js
2026-10-19 01:20:42 -05:00

50 lines
2 KiB
JavaScript

// Plugin-level configuration: the Postiz connection (base URL + API key). Set
// once per Saltcorn site under Settings -> Plugins -> postiz-poster. Every
// trigger action reuses this saved connection.
const Workflow = require("@saltcorn/data/models/workflow");
const Form = require("@saltcorn/data/models/form");
const { sealApiKey } = require("./apiKey");
// The API key is sealed before Saltcorn stores it: the configure route saves
// what onDone returns, and the autosave route saves the very form-values object
// onStepSave receives -- so a typed key never reaches the database in plaintext.
const configurationWorkflow = () =>
new Workflow({
onDone: (context) => ({ ...context, apiKey: sealApiKey(context.apiKey) }),
onStepSave: (step, context, formVals) => {
if ("apiKey" in formVals) {
formVals.apiKey = sealApiKey(formVals.apiKey);
}
},
steps: [
{
name: "Postiz connection",
form: async () =>
new Form({
fields: [
{
name: "baseUrl",
label: "Postiz base URL",
type: "String",
required: true,
sublabel: "Cloud: https://api.postiz.com | Self-hosted: the backend URL, normally your Postiz site + /api (e.g. https://postiz.example.com/api)"
},
{
name: "apiKey",
label: "Public API key",
type: "String",
required: true,
sublabel: "Postiz -> Settings -> Developers -> Public API",
attributes: { input_type: "password" }
}
]
})
}
]
});
module.exports = { configurationWorkflow };