@toneflix/paystack-cli 0.1.3 → 0.1.5

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.
Files changed (3) hide show
  1. package/bin/cli.cjs +117 -11
  2. package/bin/cli.js +115 -11
  3. package/package.json +5 -5
package/bin/cli.cjs CHANGED
@@ -38,6 +38,10 @@ let __h3ravel_musket = require("@h3ravel/musket");
38
38
  __h3ravel_musket = __toESM(__h3ravel_musket);
39
39
  let ora = require("ora");
40
40
  ora = __toESM(ora);
41
+ let module$1 = require("module");
42
+ module$1 = __toESM(module$1);
43
+ let os = require("os");
44
+ os = __toESM(os);
41
45
  let crypto = require("crypto");
42
46
  crypto = __toESM(crypto);
43
47
  let __ngrok_ngrok = require("@ngrok/ngrok");
@@ -45,9 +49,10 @@ __ngrok_ngrok = __toESM(__ngrok_ngrok);
45
49
 
46
50
  //#region src/db.ts
47
51
  let db;
48
- const __dirname$1 = (0, path.dirname)((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
49
- const dirPath = path.default.normalize(path.default.join(__dirname$1, "..", "data"));
52
+ const __dirname$2 = (0, path.dirname)((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
53
+ const dirPath = path.default.normalize(path.default.join(__dirname$2, "..", "data"));
50
54
  (0, fs.mkdirSync)(dirPath, { recursive: true });
55
+ const useDbPath = () => [dirPath];
51
56
  /**
52
57
  * Hook to get or set the database instance.
53
58
  *
@@ -256,14 +261,42 @@ var axios_default = api;
256
261
 
257
262
  //#endregion
258
263
  //#region src/helpers.ts
264
+ const __filename$1 = (0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
265
+ const __dirname$1 = path.default.dirname(__filename$1);
266
+ /**
267
+ * Wrap a promise to return a tuple of error and result
268
+ *
269
+ * @param promise
270
+ * @returns
271
+ */
259
272
  const promiseWrapper = (promise) => promise.then((data) => [null, data]).catch((error) => [typeof error === "string" ? error : error.message, null]);
273
+ /**
274
+ * Check if a value is JSON
275
+ *
276
+ * @param val
277
+ * @returns
278
+ */
260
279
  function isJson(val) {
261
280
  return val instanceof Array || val instanceof Object ? true : false;
262
281
  }
282
+ /**
283
+ * Parse a URL
284
+ *
285
+ * @param uri
286
+ * @returns
287
+ */
263
288
  function parseURL(uri) {
264
289
  if (!uri.startsWith("http")) uri = "http://" + uri;
265
290
  return new URL(uri);
266
291
  }
292
+ /**
293
+ * Get integration keys
294
+ *
295
+ * @param token
296
+ * @param type
297
+ * @param domain
298
+ * @returns
299
+ */
267
300
  function getKeys$1(token, type = "secret", domain = "test") {
268
301
  return new Promise((resolve, reject) => {
269
302
  axios_default.get("/integration/keys", { headers: {
@@ -280,14 +313,18 @@ function getKeys$1(token, type = "secret", domain = "test") {
280
313
  }
281
314
  resolve(key.key);
282
315
  }).catch((error) => {
283
- if (error.response) {
284
- reject(error.response.data.message);
285
- return;
286
- }
316
+ if (error.response) return void reject(error.response.data.message);
287
317
  reject(error);
288
318
  });
289
319
  });
290
320
  }
321
+ /**
322
+ * Execute a schema
323
+ *
324
+ * @param schema
325
+ * @param options
326
+ * @returns
327
+ */
291
328
  async function executeSchema(schema, options) {
292
329
  let domain = "test";
293
330
  if (options.domain) domain = options.domain;
@@ -299,7 +336,7 @@ async function executeSchema(schema, options) {
299
336
  if (schema.method == "GET") params = options;
300
337
  if (schema.method == "POST") data = options;
301
338
  const pathVars = [...schema.endpoint.matchAll(/\{([^}]+)\}/g)].map((match) => match[1]);
302
- if (pathVars.length >= 0) for (const path$2 of pathVars) schema.endpoint = schema.endpoint.replace("{" + path$2 + "}", options[path$2]);
339
+ if (pathVars.length >= 0) for (const path$3 of pathVars) schema.endpoint = schema.endpoint.replace("{" + path$3 + "}", options[path$3]);
303
340
  const url$1 = new URL(schema.endpoint, config.apiBaseURL || "https://api.paystack.co");
304
341
  params = {
305
342
  ...params,
@@ -319,6 +356,13 @@ async function executeSchema(schema, options) {
319
356
  });
320
357
  });
321
358
  }
359
+ /**
360
+ * Wait for a specified number of milliseconds
361
+ *
362
+ * @param ms
363
+ * @param callback
364
+ * @returns
365
+ */
322
366
  const wait = (ms, callback) => {
323
367
  return new Promise((resolve) => {
324
368
  setTimeout(() => {
@@ -327,9 +371,33 @@ const wait = (ms, callback) => {
327
371
  }, ms);
328
372
  });
329
373
  };
374
+ /**
375
+ * Logger helper
376
+ *
377
+ * @param str
378
+ * @param config
379
+ * @returns
380
+ */
330
381
  const logger = (str, config = ["green", "italic"]) => {
331
382
  return __h3ravel_shared.Logger.log(str, config, false);
332
383
  };
384
+ /**
385
+ * Find the nearest package.json file
386
+ *
387
+ * @param startDir
388
+ * @returns
389
+ */
390
+ const findCLIPackageJson = (startDir = __dirname$1) => {
391
+ let dir = startDir;
392
+ while (true) {
393
+ const pkgPath = path.default.join(dir, "package.json");
394
+ if ((0, fs.existsSync)(pkgPath)) return pkgPath;
395
+ const parent = path.default.dirname(dir);
396
+ if (parent === dir) break;
397
+ dir = parent;
398
+ }
399
+ return null;
400
+ };
333
401
 
334
402
  //#endregion
335
403
  //#region src/paystack/apis.ts
@@ -2575,10 +2643,7 @@ var Commands_default = () => {
2575
2643
  for (const param of schema.params) if (param.required && !this.argument(param.parameter)) return void this.newLine().error(`Missing required argument: ${param.parameter}`).newLine();
2576
2644
  const selected_integration = read("selected_integration")?.id;
2577
2645
  const user = read("user")?.id;
2578
- if (!selected_integration || !user) {
2579
- this.error("ERROR: You're not signed in, please run the [login] command before you begin").newLine();
2580
- return;
2581
- }
2646
+ if (!selected_integration || !user) return void this.error("ERROR: You're not signed in, please run the [login] command before you begin").newLine();
2582
2647
  this.newLine();
2583
2648
  const spinner = (0, ora.default)("Loading...\n").start();
2584
2649
  const [err, result] = await promiseWrapper(executeSchema(schema, {
@@ -2671,6 +2736,46 @@ var ConfigCommand = class extends __h3ravel_musket.Command {
2671
2736
  }
2672
2737
  };
2673
2738
 
2739
+ //#endregion
2740
+ //#region src/Commands/InfoCommand.ts
2741
+ var InfoCommand = class extends __h3ravel_musket.Command {
2742
+ signature = "info";
2743
+ description = "Display application runtime information.";
2744
+ async handle() {
2745
+ let pkg = {
2746
+ version: "unknown",
2747
+ dependencies: {}
2748
+ };
2749
+ const pkgPath = findCLIPackageJson();
2750
+ const require$1 = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
2751
+ const [_, setCommand] = useCommand();
2752
+ const [dbPath] = useDbPath();
2753
+ setCommand(this);
2754
+ init();
2755
+ const spinner = (0, ora.default)("Gathering application information...\n").start();
2756
+ if (pkgPath) try {
2757
+ pkg = require$1(pkgPath);
2758
+ } catch {}
2759
+ wait(500, () => {
2760
+ spinner.stop();
2761
+ dataRenderer({
2762
+ appVersion: pkg.version,
2763
+ platform: os.default.platform(),
2764
+ arch: os.default.arch(),
2765
+ cpus: os.default.cpus().length,
2766
+ hostname: os.default.hostname(),
2767
+ totalMemory: os.default.totalmem(),
2768
+ freeMemory: os.default.freemem(),
2769
+ uptime: os.default.uptime(),
2770
+ username: os.default.userInfo().username,
2771
+ database: dbPath + "/app.db",
2772
+ dependencies: Object.keys(pkg.dependencies).join(", ")
2773
+ });
2774
+ this.newLine();
2775
+ });
2776
+ }
2777
+ };
2778
+
2674
2779
  //#endregion
2675
2780
  //#region src/Commands/InitCommand.ts
2676
2781
  var InitCommand = class extends __h3ravel_musket.Command {
@@ -3304,6 +3409,7 @@ __h3ravel_musket.Kernel.init(new Application(), {
3304
3409
  console.error(config.debug ? exception : exception.message);
3305
3410
  },
3306
3411
  baseCommands: [
3412
+ InfoCommand,
3307
3413
  InitCommand,
3308
3414
  LoginCommand,
3309
3415
  LogoutCommand,
package/bin/cli.js CHANGED
@@ -2,19 +2,22 @@
2
2
  import path, { dirname } from "path";
3
3
  import Database from "better-sqlite3";
4
4
  import { fileURLToPath } from "url";
5
- import { mkdirSync } from "fs";
5
+ import { existsSync, mkdirSync } from "fs";
6
6
  import { Logger } from "@h3ravel/shared";
7
7
  import axios from "axios";
8
8
  import { Command, Kernel } from "@h3ravel/musket";
9
9
  import ora from "ora";
10
+ import { createRequire } from "module";
11
+ import os from "os";
10
12
  import crypto from "crypto";
11
13
  import ngrok from "@ngrok/ngrok";
12
14
 
13
15
  //#region src/db.ts
14
16
  let db;
15
- const __dirname = dirname(fileURLToPath(import.meta.url));
16
- const dirPath = path.normalize(path.join(__dirname, "..", "data"));
17
+ const __dirname$1 = dirname(fileURLToPath(import.meta.url));
18
+ const dirPath = path.normalize(path.join(__dirname$1, "..", "data"));
17
19
  mkdirSync(dirPath, { recursive: true });
20
+ const useDbPath = () => [dirPath];
18
21
  /**
19
22
  * Hook to get or set the database instance.
20
23
  *
@@ -223,14 +226,42 @@ var axios_default = api;
223
226
 
224
227
  //#endregion
225
228
  //#region src/helpers.ts
229
+ const __filename = fileURLToPath(import.meta.url);
230
+ const __dirname = path.dirname(__filename);
231
+ /**
232
+ * Wrap a promise to return a tuple of error and result
233
+ *
234
+ * @param promise
235
+ * @returns
236
+ */
226
237
  const promiseWrapper = (promise) => promise.then((data) => [null, data]).catch((error) => [typeof error === "string" ? error : error.message, null]);
238
+ /**
239
+ * Check if a value is JSON
240
+ *
241
+ * @param val
242
+ * @returns
243
+ */
227
244
  function isJson(val) {
228
245
  return val instanceof Array || val instanceof Object ? true : false;
229
246
  }
247
+ /**
248
+ * Parse a URL
249
+ *
250
+ * @param uri
251
+ * @returns
252
+ */
230
253
  function parseURL(uri) {
231
254
  if (!uri.startsWith("http")) uri = "http://" + uri;
232
255
  return new URL(uri);
233
256
  }
257
+ /**
258
+ * Get integration keys
259
+ *
260
+ * @param token
261
+ * @param type
262
+ * @param domain
263
+ * @returns
264
+ */
234
265
  function getKeys$1(token, type = "secret", domain = "test") {
235
266
  return new Promise((resolve, reject) => {
236
267
  axios_default.get("/integration/keys", { headers: {
@@ -247,14 +278,18 @@ function getKeys$1(token, type = "secret", domain = "test") {
247
278
  }
248
279
  resolve(key.key);
249
280
  }).catch((error) => {
250
- if (error.response) {
251
- reject(error.response.data.message);
252
- return;
253
- }
281
+ if (error.response) return void reject(error.response.data.message);
254
282
  reject(error);
255
283
  });
256
284
  });
257
285
  }
286
+ /**
287
+ * Execute a schema
288
+ *
289
+ * @param schema
290
+ * @param options
291
+ * @returns
292
+ */
258
293
  async function executeSchema(schema, options) {
259
294
  let domain = "test";
260
295
  if (options.domain) domain = options.domain;
@@ -286,6 +321,13 @@ async function executeSchema(schema, options) {
286
321
  });
287
322
  });
288
323
  }
324
+ /**
325
+ * Wait for a specified number of milliseconds
326
+ *
327
+ * @param ms
328
+ * @param callback
329
+ * @returns
330
+ */
289
331
  const wait = (ms, callback) => {
290
332
  return new Promise((resolve) => {
291
333
  setTimeout(() => {
@@ -294,9 +336,33 @@ const wait = (ms, callback) => {
294
336
  }, ms);
295
337
  });
296
338
  };
339
+ /**
340
+ * Logger helper
341
+ *
342
+ * @param str
343
+ * @param config
344
+ * @returns
345
+ */
297
346
  const logger = (str, config = ["green", "italic"]) => {
298
347
  return Logger.log(str, config, false);
299
348
  };
349
+ /**
350
+ * Find the nearest package.json file
351
+ *
352
+ * @param startDir
353
+ * @returns
354
+ */
355
+ const findCLIPackageJson = (startDir = __dirname) => {
356
+ let dir = startDir;
357
+ while (true) {
358
+ const pkgPath = path.join(dir, "package.json");
359
+ if (existsSync(pkgPath)) return pkgPath;
360
+ const parent = path.dirname(dir);
361
+ if (parent === dir) break;
362
+ dir = parent;
363
+ }
364
+ return null;
365
+ };
300
366
 
301
367
  //#endregion
302
368
  //#region src/paystack/apis.ts
@@ -2542,10 +2608,7 @@ var Commands_default = () => {
2542
2608
  for (const param of schema.params) if (param.required && !this.argument(param.parameter)) return void this.newLine().error(`Missing required argument: ${param.parameter}`).newLine();
2543
2609
  const selected_integration = read("selected_integration")?.id;
2544
2610
  const user = read("user")?.id;
2545
- if (!selected_integration || !user) {
2546
- this.error("ERROR: You're not signed in, please run the [login] command before you begin").newLine();
2547
- return;
2548
- }
2611
+ if (!selected_integration || !user) return void this.error("ERROR: You're not signed in, please run the [login] command before you begin").newLine();
2549
2612
  this.newLine();
2550
2613
  const spinner = ora("Loading...\n").start();
2551
2614
  const [err, result] = await promiseWrapper(executeSchema(schema, {
@@ -2638,6 +2701,46 @@ var ConfigCommand = class extends Command {
2638
2701
  }
2639
2702
  };
2640
2703
 
2704
+ //#endregion
2705
+ //#region src/Commands/InfoCommand.ts
2706
+ var InfoCommand = class extends Command {
2707
+ signature = "info";
2708
+ description = "Display application runtime information.";
2709
+ async handle() {
2710
+ let pkg = {
2711
+ version: "unknown",
2712
+ dependencies: {}
2713
+ };
2714
+ const pkgPath = findCLIPackageJson();
2715
+ const require = createRequire(import.meta.url);
2716
+ const [_, setCommand] = useCommand();
2717
+ const [dbPath] = useDbPath();
2718
+ setCommand(this);
2719
+ init();
2720
+ const spinner = ora("Gathering application information...\n").start();
2721
+ if (pkgPath) try {
2722
+ pkg = require(pkgPath);
2723
+ } catch {}
2724
+ wait(500, () => {
2725
+ spinner.stop();
2726
+ dataRenderer({
2727
+ appVersion: pkg.version,
2728
+ platform: os.platform(),
2729
+ arch: os.arch(),
2730
+ cpus: os.cpus().length,
2731
+ hostname: os.hostname(),
2732
+ totalMemory: os.totalmem(),
2733
+ freeMemory: os.freemem(),
2734
+ uptime: os.uptime(),
2735
+ username: os.userInfo().username,
2736
+ database: dbPath + "/app.db",
2737
+ dependencies: Object.keys(pkg.dependencies).join(", ")
2738
+ });
2739
+ this.newLine();
2740
+ });
2741
+ }
2742
+ };
2743
+
2641
2744
  //#endregion
2642
2745
  //#region src/Commands/InitCommand.ts
2643
2746
  var InitCommand = class extends Command {
@@ -3271,6 +3374,7 @@ Kernel.init(new Application(), {
3271
3374
  console.error(config.debug ? exception : exception.message);
3272
3375
  },
3273
3376
  baseCommands: [
3377
+ InfoCommand,
3274
3378
  InitCommand,
3275
3379
  LoginCommand,
3276
3380
  LogoutCommand,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@toneflix/paystack-cli",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "description": "Interact with the Paystack API, test webhooks locally, and manage your integration settings without leaving your command line.",
6
6
  "main": "bin/cli.js",
7
7
  "private": false,
@@ -37,18 +37,18 @@
37
37
  "toneflix"
38
38
  ],
39
39
  "dependencies": {
40
- "@eslint/js": "^9.39.2",
41
- "@eslint/markdown": "^7.5.1",
42
40
  "@h3ravel/musket": "^0.6.18",
43
41
  "@h3ravel/shared": "^0.28.4",
44
42
  "@ngrok/ngrok": "^1.7.0",
45
43
  "axios": "^1.13.2",
46
44
  "better-sqlite3": "^12.6.2",
47
45
  "ora": "^9.0.0",
48
- "tsdown": "^0.15.4",
49
- "typescript-eslint": "^8.53.0"
46
+ "tsdown": "^0.15.4"
50
47
  },
51
48
  "devDependencies": {
49
+ "@eslint/js": "^9.39.2",
50
+ "typescript-eslint": "^8.53.0",
51
+ "@eslint/markdown": "^7.5.1",
52
52
  "sass-embedded": "^1.90.0",
53
53
  "@changesets/cli": "^2.29.5",
54
54
  "@swc/core": "^1.6.1",