@toneflix/paystack-cli 0.1.4 → 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 +78 -8
  2. package/bin/cli.js +78 -8
  3. package/package.json +1 -1
package/bin/cli.cjs CHANGED
@@ -49,8 +49,8 @@ __ngrok_ngrok = __toESM(__ngrok_ngrok);
49
49
 
50
50
  //#region src/db.ts
51
51
  let db;
52
- const __dirname$1 = (0, path.dirname)((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
53
- 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"));
54
54
  (0, fs.mkdirSync)(dirPath, { recursive: true });
55
55
  const useDbPath = () => [dirPath];
56
56
  /**
@@ -261,14 +261,42 @@ var axios_default = api;
261
261
 
262
262
  //#endregion
263
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
+ */
264
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
+ */
265
279
  function isJson(val) {
266
280
  return val instanceof Array || val instanceof Object ? true : false;
267
281
  }
282
+ /**
283
+ * Parse a URL
284
+ *
285
+ * @param uri
286
+ * @returns
287
+ */
268
288
  function parseURL(uri) {
269
289
  if (!uri.startsWith("http")) uri = "http://" + uri;
270
290
  return new URL(uri);
271
291
  }
292
+ /**
293
+ * Get integration keys
294
+ *
295
+ * @param token
296
+ * @param type
297
+ * @param domain
298
+ * @returns
299
+ */
272
300
  function getKeys$1(token, type = "secret", domain = "test") {
273
301
  return new Promise((resolve, reject) => {
274
302
  axios_default.get("/integration/keys", { headers: {
@@ -285,14 +313,18 @@ function getKeys$1(token, type = "secret", domain = "test") {
285
313
  }
286
314
  resolve(key.key);
287
315
  }).catch((error) => {
288
- if (error.response) {
289
- reject(error.response.data.message);
290
- return;
291
- }
316
+ if (error.response) return void reject(error.response.data.message);
292
317
  reject(error);
293
318
  });
294
319
  });
295
320
  }
321
+ /**
322
+ * Execute a schema
323
+ *
324
+ * @param schema
325
+ * @param options
326
+ * @returns
327
+ */
296
328
  async function executeSchema(schema, options) {
297
329
  let domain = "test";
298
330
  if (options.domain) domain = options.domain;
@@ -304,7 +336,7 @@ async function executeSchema(schema, options) {
304
336
  if (schema.method == "GET") params = options;
305
337
  if (schema.method == "POST") data = options;
306
338
  const pathVars = [...schema.endpoint.matchAll(/\{([^}]+)\}/g)].map((match) => match[1]);
307
- 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]);
308
340
  const url$1 = new URL(schema.endpoint, config.apiBaseURL || "https://api.paystack.co");
309
341
  params = {
310
342
  ...params,
@@ -324,6 +356,13 @@ async function executeSchema(schema, options) {
324
356
  });
325
357
  });
326
358
  }
359
+ /**
360
+ * Wait for a specified number of milliseconds
361
+ *
362
+ * @param ms
363
+ * @param callback
364
+ * @returns
365
+ */
327
366
  const wait = (ms, callback) => {
328
367
  return new Promise((resolve) => {
329
368
  setTimeout(() => {
@@ -332,9 +371,33 @@ const wait = (ms, callback) => {
332
371
  }, ms);
333
372
  });
334
373
  };
374
+ /**
375
+ * Logger helper
376
+ *
377
+ * @param str
378
+ * @param config
379
+ * @returns
380
+ */
335
381
  const logger = (str, config = ["green", "italic"]) => {
336
382
  return __h3ravel_shared.Logger.log(str, config, false);
337
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
+ };
338
401
 
339
402
  //#endregion
340
403
  //#region src/paystack/apis.ts
@@ -2679,13 +2742,20 @@ var InfoCommand = class extends __h3ravel_musket.Command {
2679
2742
  signature = "info";
2680
2743
  description = "Display application runtime information.";
2681
2744
  async handle() {
2745
+ let pkg = {
2746
+ version: "unknown",
2747
+ dependencies: {}
2748
+ };
2749
+ const pkgPath = findCLIPackageJson();
2682
2750
  const require$1 = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
2683
2751
  const [_, setCommand] = useCommand();
2684
2752
  const [dbPath] = useDbPath();
2685
2753
  setCommand(this);
2686
2754
  init();
2687
- const pkg = require$1("../../package.json");
2688
2755
  const spinner = (0, ora.default)("Gathering application information...\n").start();
2756
+ if (pkgPath) try {
2757
+ pkg = require$1(pkgPath);
2758
+ } catch {}
2689
2759
  wait(500, () => {
2690
2760
  spinner.stop();
2691
2761
  dataRenderer({
package/bin/cli.js CHANGED
@@ -2,7 +2,7 @@
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";
@@ -14,8 +14,8 @@ import ngrok from "@ngrok/ngrok";
14
14
 
15
15
  //#region src/db.ts
16
16
  let db;
17
- const __dirname = dirname(fileURLToPath(import.meta.url));
18
- 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"));
19
19
  mkdirSync(dirPath, { recursive: true });
20
20
  const useDbPath = () => [dirPath];
21
21
  /**
@@ -226,14 +226,42 @@ var axios_default = api;
226
226
 
227
227
  //#endregion
228
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
+ */
229
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
+ */
230
244
  function isJson(val) {
231
245
  return val instanceof Array || val instanceof Object ? true : false;
232
246
  }
247
+ /**
248
+ * Parse a URL
249
+ *
250
+ * @param uri
251
+ * @returns
252
+ */
233
253
  function parseURL(uri) {
234
254
  if (!uri.startsWith("http")) uri = "http://" + uri;
235
255
  return new URL(uri);
236
256
  }
257
+ /**
258
+ * Get integration keys
259
+ *
260
+ * @param token
261
+ * @param type
262
+ * @param domain
263
+ * @returns
264
+ */
237
265
  function getKeys$1(token, type = "secret", domain = "test") {
238
266
  return new Promise((resolve, reject) => {
239
267
  axios_default.get("/integration/keys", { headers: {
@@ -250,14 +278,18 @@ function getKeys$1(token, type = "secret", domain = "test") {
250
278
  }
251
279
  resolve(key.key);
252
280
  }).catch((error) => {
253
- if (error.response) {
254
- reject(error.response.data.message);
255
- return;
256
- }
281
+ if (error.response) return void reject(error.response.data.message);
257
282
  reject(error);
258
283
  });
259
284
  });
260
285
  }
286
+ /**
287
+ * Execute a schema
288
+ *
289
+ * @param schema
290
+ * @param options
291
+ * @returns
292
+ */
261
293
  async function executeSchema(schema, options) {
262
294
  let domain = "test";
263
295
  if (options.domain) domain = options.domain;
@@ -289,6 +321,13 @@ async function executeSchema(schema, options) {
289
321
  });
290
322
  });
291
323
  }
324
+ /**
325
+ * Wait for a specified number of milliseconds
326
+ *
327
+ * @param ms
328
+ * @param callback
329
+ * @returns
330
+ */
292
331
  const wait = (ms, callback) => {
293
332
  return new Promise((resolve) => {
294
333
  setTimeout(() => {
@@ -297,9 +336,33 @@ const wait = (ms, callback) => {
297
336
  }, ms);
298
337
  });
299
338
  };
339
+ /**
340
+ * Logger helper
341
+ *
342
+ * @param str
343
+ * @param config
344
+ * @returns
345
+ */
300
346
  const logger = (str, config = ["green", "italic"]) => {
301
347
  return Logger.log(str, config, false);
302
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
+ };
303
366
 
304
367
  //#endregion
305
368
  //#region src/paystack/apis.ts
@@ -2644,13 +2707,20 @@ var InfoCommand = class extends Command {
2644
2707
  signature = "info";
2645
2708
  description = "Display application runtime information.";
2646
2709
  async handle() {
2710
+ let pkg = {
2711
+ version: "unknown",
2712
+ dependencies: {}
2713
+ };
2714
+ const pkgPath = findCLIPackageJson();
2647
2715
  const require = createRequire(import.meta.url);
2648
2716
  const [_, setCommand] = useCommand();
2649
2717
  const [dbPath] = useDbPath();
2650
2718
  setCommand(this);
2651
2719
  init();
2652
- const pkg = require("../../package.json");
2653
2720
  const spinner = ora("Gathering application information...\n").start();
2721
+ if (pkgPath) try {
2722
+ pkg = require(pkgPath);
2723
+ } catch {}
2654
2724
  wait(500, () => {
2655
2725
  spinner.stop();
2656
2726
  dataRenderer({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@toneflix/paystack-cli",
3
3
  "type": "module",
4
- "version": "0.1.4",
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,