@jiggai/kitchen-plugin-marketing 0.2.12 → 0.3.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.
@@ -34,6 +34,9 @@ __export(handler_exports, {
34
34
  module.exports = __toCommonJS(handler_exports);
35
35
  var import_drizzle_orm2 = require("drizzle-orm");
36
36
  var import_crypto2 = require("crypto");
37
+ var import_fs2 = require("fs");
38
+ var import_path2 = require("path");
39
+ var import_os2 = require("os");
37
40
 
38
41
  // src/db/index.ts
39
42
  var import_better_sqlite3 = __toESM(require("better-sqlite3"));
@@ -182,9 +185,14 @@ var accountMetricsRelations = (0, import_drizzle_orm.relations)(accountMetrics,
182
185
  // src/db/index.ts
183
186
  var import_migrator = require("drizzle-orm/better-sqlite3/migrator");
184
187
  var import_crypto = require("crypto");
188
+ var import_fs = require("fs");
189
+ var import_path = require("path");
190
+ var import_os = require("os");
191
+ var PLUGIN_ROOT = (0, import_path.dirname)((0, import_path.dirname)(__dirname));
185
192
  function createDatabase(teamId) {
186
- const dbPath = process.env.KITCHEN_PLUGIN_DB_PATH || "./data";
187
- const teamDbFile = `${dbPath}/marketing-${teamId}.db`;
193
+ const dbPath = process.env.KITCHEN_PLUGIN_DB_PATH || (0, import_path.join)((0, import_os.homedir)(), ".openclaw", "kitchen", "plugins", "marketing");
194
+ if (!(0, import_fs.existsSync)(dbPath)) (0, import_fs.mkdirSync)(dbPath, { recursive: true });
195
+ const teamDbFile = (0, import_path.join)(dbPath, `marketing-${teamId}.db`);
188
196
  const sqlite = new import_better_sqlite3.default(teamDbFile);
189
197
  const db = (0, import_better_sqlite32.drizzle)(sqlite, { schema: schema_exports });
190
198
  return { db, sqlite };
@@ -208,9 +216,10 @@ function decryptCredentials(encryptedData) {
208
216
  function initializeDatabase(teamId) {
209
217
  const { db, sqlite } = createDatabase(teamId);
210
218
  try {
211
- (0, import_migrator.migrate)(db, { migrationsFolder: "./db/migrations" });
219
+ const migrationsDir = (0, import_path.join)(PLUGIN_ROOT, "db", "migrations");
220
+ (0, import_migrator.migrate)(db, { migrationsFolder: migrationsDir });
212
221
  } catch (error) {
213
- console.warn("Migration warning:", error.message);
222
+ console.warn("Migration warning:", error?.message);
214
223
  }
215
224
  return { db, sqlite };
216
225
  }
@@ -350,6 +359,9 @@ var BaseDriver = class {
350
359
  async publishViaPostiz(content) {
351
360
  const cfg = this.config.postiz;
352
361
  if (!cfg) return { success: false, error: "Postiz not configured" };
362
+ if (!this._postizIntegrationId) {
363
+ await this.getStatus();
364
+ }
353
365
  const integrationId = this._postizIntegrationId || cfg.integrationId;
354
366
  if (!integrationId) return { success: false, error: "No Postiz integration found for " + this.platform };
355
367
  const result = await postizPublish(cfg, integrationId, content.text, {
@@ -454,12 +466,31 @@ var DiscordDriver = class extends BaseDriver {
454
466
  getMaxLength() {
455
467
  return 2e3;
456
468
  }
457
- /** Discord posting via OpenClaw gateway message tool */
458
469
  async publishViaGateway(content) {
459
- return {
460
- success: false,
461
- error: "Gateway publishing requires OpenClaw message routing \u2014 use the scheduler or workflow"
462
- };
470
+ if (content.scheduledAt) {
471
+ return {
472
+ success: false,
473
+ error: "Scheduling via gateway not supported \u2014 save as draft and use a workflow or cron to post later"
474
+ };
475
+ }
476
+ try {
477
+ const resp = await fetch("/api/openclaw/message", {
478
+ method: "POST",
479
+ headers: { "Content-Type": "application/json" },
480
+ body: JSON.stringify({
481
+ action: "send",
482
+ channel: "discord",
483
+ message: content.text
484
+ })
485
+ });
486
+ if (!resp.ok) {
487
+ const data = await resp.json().catch(() => ({}));
488
+ return { success: false, error: data?.error || `Gateway returned ${resp.status}` };
489
+ }
490
+ return { success: true, postId: `gw-discord-${Date.now()}` };
491
+ } catch (err) {
492
+ return { success: false, error: err?.message || "Gateway request failed" };
493
+ }
463
494
  }
464
495
  };
465
496
 
@@ -472,12 +503,31 @@ var TelegramDriver = class extends BaseDriver {
472
503
  getMaxLength() {
473
504
  return 4096;
474
505
  }
475
- /** Telegram posting via OpenClaw gateway message tool */
476
506
  async publishViaGateway(content) {
477
- return {
478
- success: false,
479
- error: "Gateway publishing requires OpenClaw message routing \u2014 use the scheduler or workflow"
480
- };
507
+ if (content.scheduledAt) {
508
+ return {
509
+ success: false,
510
+ error: "Scheduling via gateway not supported \u2014 save as draft and use a workflow or cron to post later"
511
+ };
512
+ }
513
+ try {
514
+ const resp = await fetch("/api/openclaw/message", {
515
+ method: "POST",
516
+ headers: { "Content-Type": "application/json" },
517
+ body: JSON.stringify({
518
+ action: "send",
519
+ channel: "telegram",
520
+ message: content.text
521
+ })
522
+ });
523
+ if (!resp.ok) {
524
+ const data = await resp.json().catch(() => ({}));
525
+ return { success: false, error: data?.error || `Gateway returned ${resp.status}` };
526
+ }
527
+ return { success: true, postId: `gw-telegram-${Date.now()}` };
528
+ } catch (err) {
529
+ return { success: false, error: err?.message || "Gateway request failed" };
530
+ }
481
531
  }
482
532
  };
483
533
 
@@ -548,12 +598,12 @@ function getBackendSources(req, teamId) {
548
598
  sources.postiz = { apiKey: postizKey, baseUrl: baseUrl.replace(/\/+$/, "") };
549
599
  }
550
600
  try {
551
- const fs = require("fs");
552
- const path = require("path");
553
- const os = require("os");
554
- const configPath = path.join(os.homedir(), ".openclaw", "openclaw.json");
555
- if (fs.existsSync(configPath)) {
556
- const cfg = JSON.parse(fs.readFileSync(configPath, "utf8"));
601
+ const configPath = (0, import_path2.join)((0, import_os2.homedir)(), ".openclaw", "openclaw.json");
602
+ const configPath5 = (0, import_path2.join)((0, import_os2.homedir)(), ".openclaw", "openclaw.json5");
603
+ const actualPath = (0, import_fs2.existsSync)(configPath) ? configPath : (0, import_fs2.existsSync)(configPath5) ? configPath5 : null;
604
+ if (actualPath) {
605
+ const raw = (0, import_fs2.readFileSync)(actualPath, "utf8").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
606
+ const cfg = JSON.parse(raw);
557
607
  const plugins = cfg?.plugins?.entries || {};
558
608
  const channels = [];
559
609
  if (plugins.discord?.enabled) channels.push("discord");
package/dist/index.js CHANGED
@@ -176,8 +176,9 @@ var init_schema = __esm({
176
176
 
177
177
  // src/db/index.ts
178
178
  function createDatabase(teamId) {
179
- const dbPath = process.env.KITCHEN_PLUGIN_DB_PATH || "./data";
180
- const teamDbFile = `${dbPath}/marketing-${teamId}.db`;
179
+ const dbPath = process.env.KITCHEN_PLUGIN_DB_PATH || (0, import_path.join)((0, import_os.homedir)(), ".openclaw", "kitchen", "plugins", "marketing");
180
+ if (!(0, import_fs.existsSync)(dbPath)) (0, import_fs.mkdirSync)(dbPath, { recursive: true });
181
+ const teamDbFile = (0, import_path.join)(dbPath, `marketing-${teamId}.db`);
181
182
  const sqlite = new import_better_sqlite3.default(teamDbFile);
182
183
  const db = (0, import_better_sqlite32.drizzle)(sqlite, { schema: schema_exports });
183
184
  return { db, sqlite };
@@ -200,13 +201,14 @@ function decryptCredentials(encryptedData) {
200
201
  function initializeDatabase(teamId) {
201
202
  const { db, sqlite } = createDatabase(teamId);
202
203
  try {
203
- (0, import_migrator.migrate)(db, { migrationsFolder: "./db/migrations" });
204
+ const migrationsDir = (0, import_path.join)(PLUGIN_ROOT, "db", "migrations");
205
+ (0, import_migrator.migrate)(db, { migrationsFolder: migrationsDir });
204
206
  } catch (error) {
205
- console.warn("Migration warning:", error.message);
207
+ console.warn("Migration warning:", error?.message);
206
208
  }
207
209
  return { db, sqlite };
208
210
  }
209
- var import_better_sqlite3, import_better_sqlite32, import_migrator, import_crypto, ENCRYPTION_KEY;
211
+ var import_better_sqlite3, import_better_sqlite32, import_migrator, import_crypto, import_fs, import_path, import_os, PLUGIN_ROOT, ENCRYPTION_KEY;
210
212
  var init_db = __esm({
211
213
  "src/db/index.ts"() {
212
214
  import_better_sqlite3 = __toESM(require("better-sqlite3"));
@@ -214,6 +216,10 @@ var init_db = __esm({
214
216
  init_schema();
215
217
  import_migrator = require("drizzle-orm/better-sqlite3/migrator");
216
218
  import_crypto = require("crypto");
219
+ import_fs = require("fs");
220
+ import_path = require("path");
221
+ import_os = require("os");
222
+ PLUGIN_ROOT = (0, import_path.dirname)((0, import_path.dirname)(__dirname));
217
223
  ENCRYPTION_KEY = process.env.KITCHEN_ENCRYPTION_KEY || "fallback-key-change-in-production";
218
224
  }
219
225
  });
@@ -1073,7 +1079,7 @@ init_db();
1073
1079
  init_schema();
1074
1080
  var import_crypto5 = require("crypto");
1075
1081
  var import_multer = __toESM(require("multer"));
1076
- var import_path = __toESM(require("path"));
1082
+ var import_path2 = __toESM(require("path"));
1077
1083
  var import_promises = __toESM(require("fs/promises"));
1078
1084
  var upload = (0, import_multer.default)({
1079
1085
  dest: "uploads/",
@@ -1373,10 +1379,10 @@ function createRoutes(app) {
1373
1379
  const { db } = initializeDatabase(teamId);
1374
1380
  const body = req.body;
1375
1381
  const mediaId = (0, import_crypto5.randomUUID)();
1376
- const filename = `${mediaId}${import_path.default.extname(req.file.originalname)}`;
1382
+ const filename = `${mediaId}${import_path2.default.extname(req.file.originalname)}`;
1377
1383
  const mediaDir = `./uploads/media/${teamId}`;
1378
1384
  await import_promises.default.mkdir(mediaDir, { recursive: true });
1379
- const finalPath = import_path.default.join(mediaDir, filename);
1385
+ const finalPath = import_path2.default.join(mediaDir, filename);
1380
1386
  await import_promises.default.rename(req.file.path, finalPath);
1381
1387
  const newMedia = {
1382
1388
  id: mediaId,
@@ -1428,7 +1434,7 @@ function createRoutes(app) {
1428
1434
  }
1429
1435
  const filePath = `./uploads/media/${teamId}/${media2.filename}`;
1430
1436
  res.set("Content-Type", media2.mimeType);
1431
- res.sendFile(import_path.default.resolve(filePath));
1437
+ res.sendFile(import_path2.default.resolve(filePath));
1432
1438
  } catch (error) {
1433
1439
  sendError5(res, 500, "FILE_ERROR", error.message);
1434
1440
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jiggai/kitchen-plugin-marketing",
3
- "version": "0.2.12",
3
+ "version": "0.3.0",
4
4
  "description": "Marketing Suite plugin for ClawKitchen",
5
5
  "main": "dist/index.js",
6
6
  "files": [