@ptkl/toolkit 0.11.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/dist/bin/toolkit.js +0 -0
- package/dist/commands/billing.js +111 -0
- package/dist/commands/config.js +33 -0
- package/dist/commands/forge.js +731 -36
- package/dist/commands/functions.js +87 -22
- package/dist/commands/index.js +25 -1
- package/dist/commands/integration.js +146 -0
- package/dist/commands/integrations/dms.js +625 -0
- package/dist/commands/integrations/mail.js +120 -0
- package/dist/commands/integrations/payments.js +199 -0
- package/dist/commands/integrations/serbia.js +610 -0
- package/dist/commands/integrations/timber.js +120 -0
- package/dist/commands/kortex.js +297 -0
- package/dist/commands/logs.js +96 -0
- package/dist/commands/project.js +147 -0
- package/dist/commands/ratchet.js +82 -0
- package/dist/commands/sandbox.js +122 -0
- package/dist/commands/satellite.js +111 -0
- package/dist/commands/template.js +96 -0
- package/dist/commands/thunder.js +123 -0
- package/dist/commands/users.js +31 -19
- package/dist/commands/workflow.js +225 -30
- package/dist/lib/forgeDevKernelPlugin.js +2 -1
- package/dist/lib/kortex/bridge.js +113 -0
- package/dist/lib/kortex/config.js +21 -0
- package/dist/lib/kortex/conversations.js +84 -0
- package/dist/lib/kortex/mcp.js +193 -0
- package/dist/lib/kortex/session.js +763 -0
- package/dist/lib/kortex/tools.js +406 -0
- package/dist/lib/kortex/ui/App.js +455 -0
- package/dist/lib/kortex/ui/SelectAgent.js +23 -0
- package/dist/lib/scaffold.js +51 -0
- package/dist/lib/sdk.js +88 -0
- package/package.json +11 -2
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { writeFileSync } from "fs";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import * as sdk from "../../lib/sdk.js";
|
|
5
|
+
import { registerCommand, withEnvOption, withProfile } from "../../lib/scaffold.js";
|
|
6
|
+
import { isActive, integrationSub } from "../integration.js";
|
|
7
|
+
/** `ptkl integration mail` — typed interface for the Protokol Mail integration (RFC §4.3/§6.1
|
|
8
|
+
* layer 2). Maps 1:1 onto the SDK `Mail` client (`@ptkl/sdk/beta`, same door as
|
|
9
|
+
* `Integrations.getMail()`): `send`/`list`/`get`/`resend`/`attachments`. Every subcommand
|
|
10
|
+
* precheck's `isActive('protokol-mail')` so an inactive integration surfaces the friendly
|
|
11
|
+
* "run `ptkl integration activate protokol-mail`" hint instead of a raw 403. */
|
|
12
|
+
const MAIL_ID = "protokol-mail";
|
|
13
|
+
function parseJSON(label, raw) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(raw);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
console.error(`${label} must be valid JSON`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function splitList(raw) {
|
|
23
|
+
if (!raw)
|
|
24
|
+
return undefined;
|
|
25
|
+
return raw
|
|
26
|
+
.split(",")
|
|
27
|
+
.map((v) => v.trim())
|
|
28
|
+
.filter(Boolean);
|
|
29
|
+
}
|
|
30
|
+
class MailCommand {
|
|
31
|
+
register() {
|
|
32
|
+
const cmd = new Command("mail").description("Protokol Mail integration: send/list/get/resend emails, manage attachments");
|
|
33
|
+
cmd.addCommand(this.registerSend());
|
|
34
|
+
cmd.addCommand(this.registerList());
|
|
35
|
+
cmd.addCommand(this.registerGet());
|
|
36
|
+
cmd.addCommand(this.registerResend());
|
|
37
|
+
cmd.addCommand(this.registerAttachments());
|
|
38
|
+
integrationSub(cmd);
|
|
39
|
+
return cmd;
|
|
40
|
+
}
|
|
41
|
+
registerSend() {
|
|
42
|
+
return registerCommand(new Command("send")
|
|
43
|
+
.description("Send an email (queued for async delivery)")
|
|
44
|
+
.requiredOption("-t, --to <emails>", "Comma-separated recipient email addresses")
|
|
45
|
+
.requiredOption("-s, --subject <subject>", "Email subject")
|
|
46
|
+
.requiredOption("-b, --body <html>", "Email body (HTML)")
|
|
47
|
+
.option("--cc <emails>", "Comma-separated CC email addresses")
|
|
48
|
+
.option("--bcc <emails>", "Comma-separated BCC email addresses")
|
|
49
|
+
.option("--reply-to <email>", "Reply-to email address")
|
|
50
|
+
.option("--sender-name <name>", "Custom sender display name")
|
|
51
|
+
.option("-a, --attachments <json>", "Attachments as a JSON array string, e.g. '[{\"file_name\":\"a.pdf\",\"mime_type\":\"application/pdf\",\"content\":\"<base64>\"}]'")).action(withProfile(async (profile, opts) => {
|
|
52
|
+
await isActive(profile, MAIL_ID);
|
|
53
|
+
const attachments = opts.attachments ? parseJSON("--attachments", opts.attachments) : undefined;
|
|
54
|
+
return await sdk.mail(profile).send({
|
|
55
|
+
to: splitList(opts.to),
|
|
56
|
+
...(opts.cc ? { cc: splitList(opts.cc) } : {}),
|
|
57
|
+
...(opts.bcc ? { bcc: splitList(opts.bcc) } : {}),
|
|
58
|
+
subject: opts.subject,
|
|
59
|
+
body: opts.body,
|
|
60
|
+
...(opts.replyTo ? { reply_to: opts.replyTo } : {}),
|
|
61
|
+
...(opts.senderName ? { sender_name: opts.senderName } : {}),
|
|
62
|
+
...(attachments !== undefined ? { attachments } : {}),
|
|
63
|
+
});
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
registerList() {
|
|
67
|
+
return registerCommand(new Command("list")
|
|
68
|
+
.description("List emails for the current project (paginated)")
|
|
69
|
+
.option("--status <status>", "Filter by status: pending | sent | failed")
|
|
70
|
+
.option("--page <page>", "Page number (1-indexed)", (v) => parseInt(v, 10))
|
|
71
|
+
.option("--limit <limit>", "Items per page (max 100, default 20)", (v) => parseInt(v, 10))).action(withProfile(async (profile, opts) => {
|
|
72
|
+
await isActive(profile, MAIL_ID);
|
|
73
|
+
return await sdk.mail(profile).list({
|
|
74
|
+
...(opts.status ? { status: opts.status } : {}),
|
|
75
|
+
...(opts.page !== undefined ? { page: opts.page } : {}),
|
|
76
|
+
...(opts.limit !== undefined ? { limit: opts.limit } : {}),
|
|
77
|
+
});
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
registerGet() {
|
|
81
|
+
return registerCommand(new Command("get")
|
|
82
|
+
.description("Get a single email by its message ID")
|
|
83
|
+
.argument("<messageId>", "The email message UUID")).action(withProfile(async (profile, messageId) => {
|
|
84
|
+
await isActive(profile, MAIL_ID);
|
|
85
|
+
return await sdk.mail(profile).get(messageId);
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
registerResend() {
|
|
89
|
+
return registerCommand(new Command("resend")
|
|
90
|
+
.description("Resend a previously failed email (resets retry counter)")
|
|
91
|
+
.argument("<messageId>", "The email message UUID")).action(withProfile(async (profile, messageId) => {
|
|
92
|
+
await isActive(profile, MAIL_ID);
|
|
93
|
+
return await sdk.mail(profile).resend(messageId);
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
registerAttachments() {
|
|
97
|
+
const cmd = new Command("attachments").description("Manage email attachments");
|
|
98
|
+
cmd.addCommand(registerCommand(new Command("list")
|
|
99
|
+
.description("List attachment metadata for an email")
|
|
100
|
+
.argument("<messageId>", "The email message UUID")).action(withProfile(async (profile, messageId) => {
|
|
101
|
+
await isActive(profile, MAIL_ID);
|
|
102
|
+
return await sdk.mail(profile).listAttachments(messageId);
|
|
103
|
+
})));
|
|
104
|
+
const downloadCmd = withEnvOption(new Command("download")
|
|
105
|
+
.description("Download an attachment's binary content to a file")
|
|
106
|
+
.argument("<messageId>", "The email message UUID")
|
|
107
|
+
.argument("<attachmentId>", "The attachment UUID")
|
|
108
|
+
.requiredOption("-o, --out <file>", "File path to write the attachment to"));
|
|
109
|
+
downloadCmd.action(withProfile(async (profile, messageId, attachmentId, opts) => {
|
|
110
|
+
await isActive(profile, MAIL_ID);
|
|
111
|
+
const data = await sdk.mail(profile).downloadAttachment(messageId, attachmentId);
|
|
112
|
+
const outPath = resolve(opts.out);
|
|
113
|
+
writeFileSync(outPath, Buffer.from(data));
|
|
114
|
+
console.log(`Attachment written to ${outPath}`);
|
|
115
|
+
}));
|
|
116
|
+
cmd.addCommand(downloadCmd);
|
|
117
|
+
return cmd;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export default new MailCommand();
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
|
+
import * as sdk from "../../lib/sdk.js";
|
|
3
|
+
import { registerCommand, withProfile } from "../../lib/scaffold.js";
|
|
4
|
+
import { integrationSub, isActive } from "../integration.js";
|
|
5
|
+
/** `ptkl integration payments` — typed interface onto the `protokol-payments` integration (RFC
|
|
6
|
+
* §4.3 / §6.1, layer 2). `ptkl integration payments refund --provider monri --user <U> --tx <T>`
|
|
7
|
+
* is literally `new Integrations({profile}).getPayments().refund('monri', U, T)` ->
|
|
8
|
+
* `/karadjordje/v1/payment/monri/{U}/refund/{T}` — reached here via `sdk.payments(profile)`
|
|
9
|
+
* (src/lib/sdk.ts), which builds the same `Payments` client against the integrations gateway.
|
|
10
|
+
*
|
|
11
|
+
* Every subcommand pre-checks `isActive('protokol-payments')` (see ../integration.ts) so an
|
|
12
|
+
* installed-but-inactive integration fails with a friendly hint instead of a raw 403. */
|
|
13
|
+
// The SDK's `PaymentProvider` type (@ptkl/sdk/beta, types/integrations/payments.ts) currently only
|
|
14
|
+
// enumerates "monri" and isn't re-exported from the package's public surface. The platform itself
|
|
15
|
+
// supports the four providers below (RFC §4.3), so `--provider` is validated against that wider
|
|
16
|
+
// set here and cast through to the SDK call — narrowing this cast away is an SDK-side fix, out of
|
|
17
|
+
// this WP's sanctioned paths.
|
|
18
|
+
const PROVIDERS = ["monri", "wspay", "stripe", "braintree"];
|
|
19
|
+
function providerOption() {
|
|
20
|
+
return new Option("-p, --provider <provider>", "Payment provider").choices(PROVIDERS).makeOptionMandatory();
|
|
21
|
+
}
|
|
22
|
+
function parseJSON(label, raw) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(raw);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
console.error(`${label} must be valid JSON`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Builds the `PaymentAmount` union (`{ totalAmount }` or `{ items }`) from the shared
|
|
32
|
+
* `--total-amount`/`--items` flags used by `link` and `direct-pay`. Exactly one is required. */
|
|
33
|
+
function parseAmount(opts) {
|
|
34
|
+
if (opts.totalAmount && opts.items) {
|
|
35
|
+
console.error("--total-amount and --items are mutually exclusive");
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
if (opts.totalAmount) {
|
|
39
|
+
return { totalAmount: opts.totalAmount };
|
|
40
|
+
}
|
|
41
|
+
if (opts.items) {
|
|
42
|
+
return { items: parseJSON("--items", opts.items) };
|
|
43
|
+
}
|
|
44
|
+
console.error("one of --total-amount or --items is required");
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
function amountOptions(cmd) {
|
|
48
|
+
return cmd
|
|
49
|
+
.option("-a, --total-amount <amount>", "Total amount as `<euros>,<cents>` (e.g. 10,00), mutually exclusive with --items")
|
|
50
|
+
.option("-i, --items <json>", "Line items as a JSON array ([{ name, price, ... }]), mutually exclusive with --total-amount");
|
|
51
|
+
}
|
|
52
|
+
class PaymentsCommand {
|
|
53
|
+
register() {
|
|
54
|
+
const cmd = new Command("payments").description("Payments integration (protokol-payments): transactions, links, refunds/void/cancel, settings");
|
|
55
|
+
cmd.addCommand(this.registerList());
|
|
56
|
+
cmd.addCommand(this.registerGet());
|
|
57
|
+
cmd.addCommand(this.registerLink());
|
|
58
|
+
cmd.addCommand(this.registerTokenRequest());
|
|
59
|
+
cmd.addCommand(this.registerDirectPay());
|
|
60
|
+
cmd.addCommand(this.registerRefund());
|
|
61
|
+
cmd.addCommand(this.registerVoid());
|
|
62
|
+
cmd.addCommand(this.registerCancel());
|
|
63
|
+
cmd.addCommand(this.registerSettings());
|
|
64
|
+
return integrationSub(cmd);
|
|
65
|
+
}
|
|
66
|
+
registerList() {
|
|
67
|
+
return registerCommand(new Command("list")
|
|
68
|
+
.description("List payment transactions for a user")
|
|
69
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
70
|
+
.option("-s, --status <status>", "Filter by transaction status")
|
|
71
|
+
.option("--sort-by <field>", "Field to sort by")
|
|
72
|
+
.option("--sort-direction <direction>", "Sort direction: asc | desc")
|
|
73
|
+
.option("-l, --limit <n>", "Max rows to return")
|
|
74
|
+
.option("--page <n>", "Page number")).action(withProfile(async (profile, opts) => {
|
|
75
|
+
await isActive(profile, "protokol-payments");
|
|
76
|
+
const hasParams = opts.status || opts.sortBy || opts.sortDirection || opts.limit !== undefined || opts.page !== undefined;
|
|
77
|
+
const params = hasParams
|
|
78
|
+
? {
|
|
79
|
+
status: opts.status,
|
|
80
|
+
sortBy: opts.sortBy,
|
|
81
|
+
sortDirection: opts.sortDirection,
|
|
82
|
+
limit: opts.limit !== undefined ? Number(opts.limit) : undefined,
|
|
83
|
+
page: opts.page !== undefined ? Number(opts.page) : undefined,
|
|
84
|
+
}
|
|
85
|
+
: undefined;
|
|
86
|
+
const res = await sdk.payments(profile).getTransactions(opts.user, params);
|
|
87
|
+
return res?.data ?? res;
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
registerGet() {
|
|
91
|
+
return registerCommand(new Command("get")
|
|
92
|
+
.description("Get a single payment transaction")
|
|
93
|
+
.addOption(providerOption())
|
|
94
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
95
|
+
.requiredOption("-t, --tx <transactionId>", "Transaction id")).action(withProfile(async (profile, opts) => {
|
|
96
|
+
await isActive(profile, "protokol-payments");
|
|
97
|
+
const res = await sdk.payments(profile).getTransaction(opts.provider, opts.user, opts.tx);
|
|
98
|
+
return res?.data ?? res;
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
registerLink() {
|
|
102
|
+
return registerCommand(amountOptions(new Command("link")
|
|
103
|
+
.description("Create a payment link")
|
|
104
|
+
.addOption(providerOption())
|
|
105
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
106
|
+
.requiredOption("-d, --description <description>", "Payment description")
|
|
107
|
+
.option("--token <token>", "Pre-existing tokenized card to charge, if any")
|
|
108
|
+
.option("--is-token-request", "Request tokenization of the card during payment")
|
|
109
|
+
.option("--redirect-url <url>", "URL to redirect to after payment")
|
|
110
|
+
.option("--lang <lang>", "Payment page language: en | es | ba | hr"))).action(withProfile(async (profile, opts) => {
|
|
111
|
+
await isActive(profile, "protokol-payments");
|
|
112
|
+
const res = await sdk.payments(profile).getPaymentLink(opts.provider, opts.user, {
|
|
113
|
+
...parseAmount(opts),
|
|
114
|
+
description: opts.description,
|
|
115
|
+
...(opts.token ? { token: opts.token } : {}),
|
|
116
|
+
...(opts.isTokenRequest ? { isTokenRequest: true } : {}),
|
|
117
|
+
...(opts.redirectUrl ? { redirectUrl: opts.redirectUrl } : {}),
|
|
118
|
+
...(opts.lang ? { lang: opts.lang } : {}),
|
|
119
|
+
});
|
|
120
|
+
return res?.data ?? res;
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
registerTokenRequest() {
|
|
124
|
+
return registerCommand(new Command("token-request")
|
|
125
|
+
.description("Create a token-request link (tokenize a card without charging it)")
|
|
126
|
+
.addOption(providerOption())
|
|
127
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
128
|
+
.requiredOption("-d, --description <description>", "Description shown on the payment page")
|
|
129
|
+
.option("--redirect-url <url>", "URL to redirect to after tokenization")
|
|
130
|
+
.option("--lang <lang>", "Payment page language: en | es | ba | hr")).action(withProfile(async (profile, opts) => {
|
|
131
|
+
await isActive(profile, "protokol-payments");
|
|
132
|
+
const res = await sdk.payments(profile).getTokenRequestLink(opts.provider, opts.user, {
|
|
133
|
+
description: opts.description,
|
|
134
|
+
...(opts.redirectUrl ? { redirectUrl: opts.redirectUrl } : {}),
|
|
135
|
+
...(opts.lang ? { lang: opts.lang } : {}),
|
|
136
|
+
});
|
|
137
|
+
return res?.data ?? res;
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
registerDirectPay() {
|
|
141
|
+
return registerCommand(amountOptions(new Command("direct-pay")
|
|
142
|
+
.description("Charge a previously tokenized card directly (no redirect)")
|
|
143
|
+
.addOption(providerOption())
|
|
144
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
145
|
+
.requiredOption("--token <token>", "Tokenized card to charge")
|
|
146
|
+
.requiredOption("-d, --description <description>", "Payment description"))).action(withProfile(async (profile, opts) => {
|
|
147
|
+
await isActive(profile, "protokol-payments");
|
|
148
|
+
const res = await sdk.payments(profile).directPayUsingToken(opts.provider, opts.user, {
|
|
149
|
+
...parseAmount(opts),
|
|
150
|
+
token: opts.token,
|
|
151
|
+
description: opts.description,
|
|
152
|
+
});
|
|
153
|
+
return res?.data ?? res;
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
registerRefund() {
|
|
157
|
+
return registerCommand(new Command("refund")
|
|
158
|
+
.description("Refund a payment transaction")
|
|
159
|
+
.addOption(providerOption())
|
|
160
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
161
|
+
.requiredOption("-t, --tx <transactionId>", "Transaction id")).action(withProfile(async (profile, opts) => {
|
|
162
|
+
await isActive(profile, "protokol-payments");
|
|
163
|
+
const res = await sdk.payments(profile).refund(opts.provider, opts.user, opts.tx);
|
|
164
|
+
return res?.data ?? res;
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
registerVoid() {
|
|
168
|
+
return registerCommand(new Command("void")
|
|
169
|
+
.description("Void a payment transaction")
|
|
170
|
+
.addOption(providerOption())
|
|
171
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
172
|
+
.requiredOption("-t, --tx <transactionId>", "Transaction id")).action(withProfile(async (profile, opts) => {
|
|
173
|
+
await isActive(profile, "protokol-payments");
|
|
174
|
+
const res = await sdk.payments(profile).voidTransaction(opts.provider, opts.user, opts.tx);
|
|
175
|
+
return res?.data ?? res;
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
registerCancel() {
|
|
179
|
+
return registerCommand(new Command("cancel")
|
|
180
|
+
.description("Cancel (deactivate) a payment link")
|
|
181
|
+
.addOption(providerOption())
|
|
182
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
183
|
+
.requiredOption("-t, --tx <transactionId>", "Transaction id")).action(withProfile(async (profile, opts) => {
|
|
184
|
+
await isActive(profile, "protokol-payments");
|
|
185
|
+
const res = await sdk.payments(profile).deactivatePaymentLink(opts.provider, opts.user, opts.tx);
|
|
186
|
+
return res?.data ?? res;
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
registerSettings() {
|
|
190
|
+
return registerCommand(new Command("settings")
|
|
191
|
+
.description("Get the merchant settings for a payment provider")
|
|
192
|
+
.addOption(providerOption())).action(withProfile(async (profile, opts) => {
|
|
193
|
+
await isActive(profile, "protokol-payments");
|
|
194
|
+
const res = await sdk.payments(profile).settings(opts.provider);
|
|
195
|
+
return res?.data ?? res;
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
export default new PaymentsCommand();
|