sc-postiz-poster/index.js
2026-06-17 17:40:57 -05:00

35 lines
1.3 KiB
JavaScript

// postiz-poster: Saltcorn plugin that publishes table rows to social networks
// through a Postiz instance (self-hosted or cloud). Exposes one trigger action,
// post_to_postiz, configured per-trigger. The Postiz connection itself lives in
// the plugin configuration (see lib/config.js); the API key is sealed at rest
// (see lib/secretsAtRest.js).
const { PLUGIN_NAME } = require("./lib/constants");
const { configurationWorkflow } = require("./lib/config");
const { makePostAction, sealStoredApiKey } = require("./lib/action");
// Runs each time the plugin loads -- including immediately after a config save
// (Saltcorn calls Plugin.loadPlugin after upsert). Seals any plaintext apiKey
// the autoSave form left in the database.
const onLoad = async () => {
try {
await sealStoredApiKey();
} catch (err) {
// eslint-disable-next-line no-console
console.error(`[${PLUGIN_NAME}] sealing stored secrets failed:`, err);
}
};
module.exports = {
sc_plugin_api_version: 1,
plugin_name: PLUGIN_NAME,
configuration_workflow: configurationWorkflow,
onLoad: onLoad,
// Saltcorn calls capability keys with the saved plugin config when a
// configuration_workflow is present (see saltcorn-data db/state.ts).
actions: (pluginCfg) => ({
post_to_postiz: makePostAction(pluginCfg || {})
})
};