@platformos/pos-cli
Version:
Manage your platformOS application
74 lines (64 loc) • 1.94 kB
JavaScript
// platformos.constants.unset tool - delete a constant
import { resolveAuth } from '../auth.js';
import Gateway from '../../lib/proxy.js';
function buildUnsetMutation(name) {
const escapedName = name.replace(/"/g, '\\"');
return `mutation {
constant_unset(name: "${escapedName}") {
name
}
}`;
}
const constantsUnsetTool = {
description: 'Delete a constant from a platformOS instance.',
inputSchema: {
type: 'object',
additionalProperties: false,
required: ['env', 'name'],
properties: {
env: { type: 'string', description: 'Environment name from .pos config' },
name: { type: 'string', description: 'Name of the constant to delete' }
}
},
handler: async (params, ctx = {}) => {
const startedAt = new Date().toISOString();
try {
const auth = await resolveAuth(params, ctx);
const GatewayCtor = ctx.Gateway || Gateway;
const gateway = new GatewayCtor({ url: auth.url, token: auth.token, email: auth.email });
const query = buildUnsetMutation(params.name);
const resp = await gateway.graph({ query });
if (resp && Array.isArray(resp.errors) && resp.errors.length > 0) {
return {
ok: false,
error: {
code: 'GRAPHQL_ERROR',
message: resp.errors[0]?.message || 'GraphQL error'
}
};
}
const result = resp?.data?.constant_unset;
return {
ok: true,
data: {
name: result?.name || params.name,
deleted: !!result
},
meta: {
startedAt,
finishedAt: new Date().toISOString()
}
};
} catch (e) {
return {
ok: false,
error: { code: 'CONSTANTS_UNSET_FAILED', message: String(e.message || e) },
meta: {
startedAt,
finishedAt: new Date().toISOString()
}
};
}
}
};
export default constantsUnsetTool;