@toneflix/paystack-cli 0.1.2 → 0.1.3
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/bin/cli.cjs +66 -27
- package/bin/cli.js +53 -17
- package/package.json +1 -1
package/bin/cli.cjs
CHANGED
|
@@ -22,8 +22,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
|
|
24
24
|
//#endregion
|
|
25
|
+
let path = require("path");
|
|
26
|
+
path = __toESM(path);
|
|
25
27
|
let better_sqlite3 = require("better-sqlite3");
|
|
26
28
|
better_sqlite3 = __toESM(better_sqlite3);
|
|
29
|
+
let url = require("url");
|
|
30
|
+
url = __toESM(url);
|
|
31
|
+
let fs = require("fs");
|
|
32
|
+
fs = __toESM(fs);
|
|
27
33
|
let __h3ravel_shared = require("@h3ravel/shared");
|
|
28
34
|
__h3ravel_shared = __toESM(__h3ravel_shared);
|
|
29
35
|
let axios = require("axios");
|
|
@@ -38,11 +44,33 @@ let __ngrok_ngrok = require("@ngrok/ngrok");
|
|
|
38
44
|
__ngrok_ngrok = __toESM(__ngrok_ngrok);
|
|
39
45
|
|
|
40
46
|
//#region src/db.ts
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
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"));
|
|
50
|
+
(0, fs.mkdirSync)(dirPath, { recursive: true });
|
|
51
|
+
/**
|
|
52
|
+
* Hook to get or set the database instance.
|
|
53
|
+
*
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
const useDb = () => {
|
|
57
|
+
return [() => db, (newDb) => {
|
|
58
|
+
db = newDb;
|
|
59
|
+
const [{ journal_mode }] = db.pragma("journal_mode");
|
|
60
|
+
if (journal_mode !== "wal") db.pragma("journal_mode = WAL");
|
|
61
|
+
}];
|
|
62
|
+
};
|
|
63
|
+
const [getDatabase, setDatabase] = useDb();
|
|
64
|
+
setDatabase(new better_sqlite3.default(path.default.join(dirPath, "app.db")));
|
|
65
|
+
/**
|
|
66
|
+
* Initialize the database
|
|
67
|
+
*
|
|
68
|
+
* @param table
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
function init() {
|
|
72
|
+
return getDatabase().exec(`
|
|
73
|
+
CREATE TABLE IF NOT EXISTS json_store (
|
|
46
74
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
47
75
|
key TEXT UNIQUE,
|
|
48
76
|
value TEXT
|
|
@@ -56,16 +84,24 @@ function init(table = "json_store") {
|
|
|
56
84
|
* @param value
|
|
57
85
|
* @returns
|
|
58
86
|
*/
|
|
59
|
-
function write(key, value
|
|
87
|
+
function write(key, value) {
|
|
88
|
+
const db$1 = getDatabase();
|
|
60
89
|
if (typeof value === "boolean") value = value ? "1" : "0";
|
|
61
90
|
if (value instanceof Object) value = JSON.stringify(value);
|
|
62
|
-
return db.prepare(`INSERT INTO
|
|
91
|
+
return db$1.prepare(`INSERT INTO json_store (key, value)
|
|
63
92
|
VALUES (?, ?)
|
|
64
93
|
ON CONFLICT(key) DO UPDATE SET value=excluded.value
|
|
65
94
|
`).run(key, value).lastInsertRowid;
|
|
66
95
|
}
|
|
67
|
-
|
|
68
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Remove a value from the database
|
|
98
|
+
*
|
|
99
|
+
* @param key
|
|
100
|
+
* @param table
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
function remove(key) {
|
|
104
|
+
return getDatabase().prepare("DELETE FROM json_store WHERE key = ?").run(key).lastInsertRowid;
|
|
69
105
|
}
|
|
70
106
|
/**
|
|
71
107
|
* Read a value from the database
|
|
@@ -73,13 +109,16 @@ function remove(key, table = "json_store") {
|
|
|
73
109
|
* @param key
|
|
74
110
|
* @returns
|
|
75
111
|
*/
|
|
76
|
-
function read(key
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
112
|
+
function read(key) {
|
|
113
|
+
const db$1 = getDatabase();
|
|
114
|
+
try {
|
|
115
|
+
const row = db$1.prepare("SELECT * FROM json_store WHERE key = ?").get(key);
|
|
116
|
+
if (row) try {
|
|
117
|
+
return JSON.parse(row.value);
|
|
118
|
+
} catch {
|
|
119
|
+
return row.value;
|
|
120
|
+
}
|
|
121
|
+
} catch {}
|
|
83
122
|
return null;
|
|
84
123
|
}
|
|
85
124
|
|
|
@@ -260,14 +299,14 @@ async function executeSchema(schema, options) {
|
|
|
260
299
|
if (schema.method == "GET") params = options;
|
|
261
300
|
if (schema.method == "POST") data = options;
|
|
262
301
|
const pathVars = [...schema.endpoint.matchAll(/\{([^}]+)\}/g)].map((match) => match[1]);
|
|
263
|
-
if (pathVars.length >= 0) for (const path of pathVars) schema.endpoint = schema.endpoint.replace("{" + path + "}", options[path]);
|
|
264
|
-
const url = new URL(schema.endpoint, config.apiBaseURL || "https://api.paystack.co");
|
|
302
|
+
if (pathVars.length >= 0) for (const path$2 of pathVars) schema.endpoint = schema.endpoint.replace("{" + path$2 + "}", options[path$2]);
|
|
303
|
+
const url$1 = new URL(schema.endpoint, config.apiBaseURL || "https://api.paystack.co");
|
|
265
304
|
params = {
|
|
266
305
|
...params,
|
|
267
|
-
...Object.fromEntries(url.searchParams.entries())
|
|
306
|
+
...Object.fromEntries(url$1.searchParams.entries())
|
|
268
307
|
};
|
|
269
308
|
axios_default.request({
|
|
270
|
-
url: url.pathname,
|
|
309
|
+
url: url$1.pathname,
|
|
271
310
|
method: schema.method,
|
|
272
311
|
params,
|
|
273
312
|
data,
|
|
@@ -2895,10 +2934,10 @@ async function refreshIntegration() {
|
|
|
2895
2934
|
* @param domain
|
|
2896
2935
|
* @returns
|
|
2897
2936
|
*/
|
|
2898
|
-
function setWebhook(url, token, integrationId, domain = "test") {
|
|
2937
|
+
function setWebhook(url$1, token, integrationId, domain = "test") {
|
|
2899
2938
|
return new Promise((resolve, reject) => {
|
|
2900
2939
|
const data = {
|
|
2901
|
-
[domain + "_webhook_endpoint"]: url,
|
|
2940
|
+
[domain + "_webhook_endpoint"]: url$1,
|
|
2902
2941
|
integration: integrationId
|
|
2903
2942
|
};
|
|
2904
2943
|
axios_default.put("/integration/webhooks", data, { headers: {
|
|
@@ -2908,7 +2947,7 @@ function setWebhook(url, token, integrationId, domain = "test") {
|
|
|
2908
2947
|
const integration = read("selected_integration");
|
|
2909
2948
|
write("selected_integration", {
|
|
2910
2949
|
...integration,
|
|
2911
|
-
[domain + "_webhook_endpoint"]: url
|
|
2950
|
+
[domain + "_webhook_endpoint"]: url$1
|
|
2912
2951
|
});
|
|
2913
2952
|
resolve(resp.data.message);
|
|
2914
2953
|
}).catch((err) => {
|
|
@@ -3209,16 +3248,16 @@ var WebhookCommand = class extends __h3ravel_musket.Command {
|
|
|
3209
3248
|
this.error("ERROR: Your session has expired. Please run the `login` command to sign in again.");
|
|
3210
3249
|
return;
|
|
3211
3250
|
}
|
|
3212
|
-
const url = parseURL(local_route);
|
|
3213
|
-
if (!url.port) url.port = "8000";
|
|
3214
|
-
if (!url.search || url.search == "?") url.search = "";
|
|
3251
|
+
const url$1 = parseURL(local_route);
|
|
3252
|
+
if (!url$1.port) url$1.port = "8000";
|
|
3253
|
+
if (!url$1.search || url$1.search == "?") url$1.search = "";
|
|
3215
3254
|
try {
|
|
3216
3255
|
await __ngrok_ngrok.default.kill();
|
|
3217
3256
|
} catch {
|
|
3218
3257
|
this.debug("No existing ngrok process found to kill.");
|
|
3219
3258
|
}
|
|
3220
3259
|
const ngrokURL = (await __ngrok_ngrok.default.forward({
|
|
3221
|
-
addr: url.port,
|
|
3260
|
+
addr: url$1.port,
|
|
3222
3261
|
authtoken: config.ngrokAuthToken || process.env.NGROK_AUTH_TOKEN,
|
|
3223
3262
|
domain: process.env.NGROK_DOMAIN
|
|
3224
3263
|
})).url();
|
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import path, { dirname } from "path";
|
|
2
3
|
import Database from "better-sqlite3";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { mkdirSync } from "fs";
|
|
3
6
|
import { Logger } from "@h3ravel/shared";
|
|
4
7
|
import axios from "axios";
|
|
5
8
|
import { Command, Kernel } from "@h3ravel/musket";
|
|
@@ -8,11 +11,33 @@ import crypto from "crypto";
|
|
|
8
11
|
import ngrok from "@ngrok/ngrok";
|
|
9
12
|
|
|
10
13
|
//#region src/db.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
let db;
|
|
15
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const dirPath = path.normalize(path.join(__dirname, "..", "data"));
|
|
17
|
+
mkdirSync(dirPath, { recursive: true });
|
|
18
|
+
/**
|
|
19
|
+
* Hook to get or set the database instance.
|
|
20
|
+
*
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
const useDb = () => {
|
|
24
|
+
return [() => db, (newDb) => {
|
|
25
|
+
db = newDb;
|
|
26
|
+
const [{ journal_mode }] = db.pragma("journal_mode");
|
|
27
|
+
if (journal_mode !== "wal") db.pragma("journal_mode = WAL");
|
|
28
|
+
}];
|
|
29
|
+
};
|
|
30
|
+
const [getDatabase, setDatabase] = useDb();
|
|
31
|
+
setDatabase(new Database(path.join(dirPath, "app.db")));
|
|
32
|
+
/**
|
|
33
|
+
* Initialize the database
|
|
34
|
+
*
|
|
35
|
+
* @param table
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
function init() {
|
|
39
|
+
return getDatabase().exec(`
|
|
40
|
+
CREATE TABLE IF NOT EXISTS json_store (
|
|
16
41
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
17
42
|
key TEXT UNIQUE,
|
|
18
43
|
value TEXT
|
|
@@ -26,16 +51,24 @@ function init(table = "json_store") {
|
|
|
26
51
|
* @param value
|
|
27
52
|
* @returns
|
|
28
53
|
*/
|
|
29
|
-
function write(key, value
|
|
54
|
+
function write(key, value) {
|
|
55
|
+
const db$1 = getDatabase();
|
|
30
56
|
if (typeof value === "boolean") value = value ? "1" : "0";
|
|
31
57
|
if (value instanceof Object) value = JSON.stringify(value);
|
|
32
|
-
return db.prepare(`INSERT INTO
|
|
58
|
+
return db$1.prepare(`INSERT INTO json_store (key, value)
|
|
33
59
|
VALUES (?, ?)
|
|
34
60
|
ON CONFLICT(key) DO UPDATE SET value=excluded.value
|
|
35
61
|
`).run(key, value).lastInsertRowid;
|
|
36
62
|
}
|
|
37
|
-
|
|
38
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Remove a value from the database
|
|
65
|
+
*
|
|
66
|
+
* @param key
|
|
67
|
+
* @param table
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
function remove(key) {
|
|
71
|
+
return getDatabase().prepare("DELETE FROM json_store WHERE key = ?").run(key).lastInsertRowid;
|
|
39
72
|
}
|
|
40
73
|
/**
|
|
41
74
|
* Read a value from the database
|
|
@@ -43,13 +76,16 @@ function remove(key, table = "json_store") {
|
|
|
43
76
|
* @param key
|
|
44
77
|
* @returns
|
|
45
78
|
*/
|
|
46
|
-
function read(key
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
79
|
+
function read(key) {
|
|
80
|
+
const db$1 = getDatabase();
|
|
81
|
+
try {
|
|
82
|
+
const row = db$1.prepare("SELECT * FROM json_store WHERE key = ?").get(key);
|
|
83
|
+
if (row) try {
|
|
84
|
+
return JSON.parse(row.value);
|
|
85
|
+
} catch {
|
|
86
|
+
return row.value;
|
|
87
|
+
}
|
|
88
|
+
} catch {}
|
|
53
89
|
return null;
|
|
54
90
|
}
|
|
55
91
|
|
|
@@ -230,7 +266,7 @@ async function executeSchema(schema, options) {
|
|
|
230
266
|
if (schema.method == "GET") params = options;
|
|
231
267
|
if (schema.method == "POST") data = options;
|
|
232
268
|
const pathVars = [...schema.endpoint.matchAll(/\{([^}]+)\}/g)].map((match) => match[1]);
|
|
233
|
-
if (pathVars.length >= 0) for (const path of pathVars) schema.endpoint = schema.endpoint.replace("{" + path + "}", options[path]);
|
|
269
|
+
if (pathVars.length >= 0) for (const path$1 of pathVars) schema.endpoint = schema.endpoint.replace("{" + path$1 + "}", options[path$1]);
|
|
234
270
|
const url = new URL(schema.endpoint, config.apiBaseURL || "https://api.paystack.co");
|
|
235
271
|
params = {
|
|
236
272
|
...params,
|
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
|
+
"version": "0.1.3",
|
|
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,
|