@madapay/cli 0.0.0-stage → 0.1.1
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/LICENSE +176 -0
- package/README.md +22 -2
- package/dist/bin.cjs +195 -0
- package/dist/bin.cjs.map +1 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +188 -0
- package/dist/bin.js.map +1 -0
- package/dist/index.cjs +157 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +148 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the document
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or exemplary damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @madapay/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official CLI for initializing, configuring, and managing MadaPay payment integrations.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **`madapay init`**: Generates project `.env` with empty secrets, defaults all provider environments to sandbox, and enforces `.gitignore` protection.
|
|
8
|
+
- **Provider Scaffolding**: Easily select active mobile money providers (MVola, Orange Money, Airtel Money, PAPI, FiveOne, Alefa).
|
|
9
|
+
- **Framework Support**: Starter templates for Fastify, Express, and Next.js.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add -D @madapay/cli
|
|
15
|
+
# or install globally
|
|
16
|
+
npm install -g @madapay/cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
madapay init
|
|
23
|
+
```
|
package/dist/bin.cjs
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var commander = require('commander');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
11
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
|
+
|
|
13
|
+
function generateEnvContent(providers) {
|
|
14
|
+
const lines = [
|
|
15
|
+
"# MadaPay Merchant Environment Configuration",
|
|
16
|
+
"# All credentials MUST run strictly on your secure backend server.",
|
|
17
|
+
"# NEVER expose these credentials to client browsers or mobile devices.",
|
|
18
|
+
"",
|
|
19
|
+
"# Merchant Identity",
|
|
20
|
+
"MERCHANT_ID=",
|
|
21
|
+
"MERCHANT_API_KEY=",
|
|
22
|
+
"PORT=3000",
|
|
23
|
+
"",
|
|
24
|
+
"# Persistence & Database",
|
|
25
|
+
"DATABASE_URL=postgresql://postgres:postgres@localhost:5432/madapay",
|
|
26
|
+
""
|
|
27
|
+
];
|
|
28
|
+
const providerList = providers.map((p) => p.toLowerCase());
|
|
29
|
+
if (providerList.includes("mvola")) {
|
|
30
|
+
lines.push(
|
|
31
|
+
"# Telma MVola",
|
|
32
|
+
"MVOLA_CONSUMER_KEY=",
|
|
33
|
+
"MVOLA_CONSUMER_SECRET=",
|
|
34
|
+
"MVOLA_MERCHANT_NUMBER=",
|
|
35
|
+
"MVOLA_ENVIRONMENT=sandbox",
|
|
36
|
+
""
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (providerList.includes("orange") || providerList.includes("orange_money") || providerList.includes("orange-money")) {
|
|
40
|
+
lines.push(
|
|
41
|
+
"# Orange Money Madagascar",
|
|
42
|
+
"ORANGE_CLIENT_ID=",
|
|
43
|
+
"ORANGE_CLIENT_SECRET=",
|
|
44
|
+
"ORANGE_MERCHANT_KEY=",
|
|
45
|
+
"ORANGE_ENVIRONMENT=sandbox",
|
|
46
|
+
""
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (providerList.includes("airtel") || providerList.includes("airtel_money") || providerList.includes("airtel-money")) {
|
|
50
|
+
lines.push(
|
|
51
|
+
"# Airtel Money Madagascar",
|
|
52
|
+
"AIRTEL_CLIENT_ID=",
|
|
53
|
+
"AIRTEL_CLIENT_SECRET=",
|
|
54
|
+
"AIRTEL_ENVIRONMENT=sandbox",
|
|
55
|
+
""
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (providerList.includes("papi")) {
|
|
59
|
+
lines.push("# PAPI Aggregator", "PAPI_API_KEY=", "PAPI_ENVIRONMENT=sandbox", "");
|
|
60
|
+
}
|
|
61
|
+
if (providerList.includes("fiveone")) {
|
|
62
|
+
lines.push(
|
|
63
|
+
"# FiveOne Aggregator",
|
|
64
|
+
"FIVEONE_API_KEY=",
|
|
65
|
+
"FIVEONE_SECRET_KEY=",
|
|
66
|
+
"FIVEONE_ENVIRONMENT=sandbox",
|
|
67
|
+
""
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (providerList.includes("alefa")) {
|
|
71
|
+
lines.push(
|
|
72
|
+
"# Alefa Aggregator",
|
|
73
|
+
"ALEFA_API_KEY=",
|
|
74
|
+
"ALEFA_SECRET_KEY=",
|
|
75
|
+
"ALEFA_ENVIRONMENT=sandbox",
|
|
76
|
+
""
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return lines.join("\n");
|
|
80
|
+
}
|
|
81
|
+
function ensureGitignoreProtection(targetDir) {
|
|
82
|
+
const gitignorePath = path__default.default.join(targetDir, ".gitignore");
|
|
83
|
+
let updated = false;
|
|
84
|
+
if (fs__default.default.existsSync(gitignorePath)) {
|
|
85
|
+
const existing = fs__default.default.readFileSync(gitignorePath, "utf8");
|
|
86
|
+
const lines = existing.split(/\r?\n/).map((l) => l.trim());
|
|
87
|
+
const needed = [".env", ".env.local", ".env.*.local"];
|
|
88
|
+
const missing = needed.filter((item) => !lines.includes(item));
|
|
89
|
+
if (missing.length > 0) {
|
|
90
|
+
const appendContent = `
|
|
91
|
+
# MadaPay secrets protection
|
|
92
|
+
${missing.join("\n")}
|
|
93
|
+
`;
|
|
94
|
+
fs__default.default.appendFileSync(gitignorePath, appendContent, "utf8");
|
|
95
|
+
updated = true;
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
const defaultGitignore = [
|
|
99
|
+
"# MadaPay secrets protection",
|
|
100
|
+
".env",
|
|
101
|
+
".env.local",
|
|
102
|
+
".env.*.local",
|
|
103
|
+
"node_modules",
|
|
104
|
+
"dist",
|
|
105
|
+
""
|
|
106
|
+
].join("\n");
|
|
107
|
+
fs__default.default.writeFileSync(gitignorePath, defaultGitignore, "utf8");
|
|
108
|
+
updated = true;
|
|
109
|
+
}
|
|
110
|
+
return updated;
|
|
111
|
+
}
|
|
112
|
+
function initProject(options = {}) {
|
|
113
|
+
const targetDir = path__default.default.resolve(process.cwd(), options.directory || ".");
|
|
114
|
+
if (!fs__default.default.existsSync(targetDir)) {
|
|
115
|
+
fs__default.default.mkdirSync(targetDir, { recursive: true });
|
|
116
|
+
}
|
|
117
|
+
const providers = options.providers && options.providers.length > 0 ? options.providers : ["mvola", "orange_money", "airtel_money", "papi"];
|
|
118
|
+
const envContent = generateEnvContent(providers);
|
|
119
|
+
const envExamplePath = path__default.default.join(targetDir, ".env.example");
|
|
120
|
+
const envPath = path__default.default.join(targetDir, ".env");
|
|
121
|
+
const configPath = path__default.default.join(targetDir, "madapay.config.json");
|
|
122
|
+
let envExampleCreated = false;
|
|
123
|
+
let envCreated = false;
|
|
124
|
+
fs__default.default.writeFileSync(envExamplePath, envContent, "utf8");
|
|
125
|
+
envExampleCreated = true;
|
|
126
|
+
if (!fs__default.default.existsSync(envPath) || options.force) {
|
|
127
|
+
fs__default.default.writeFileSync(envPath, envContent, "utf8");
|
|
128
|
+
envCreated = true;
|
|
129
|
+
}
|
|
130
|
+
const gitignoreUpdated = ensureGitignoreProtection(targetDir);
|
|
131
|
+
let configCreated = false;
|
|
132
|
+
if (!fs__default.default.existsSync(configPath) || options.force) {
|
|
133
|
+
const configData = {
|
|
134
|
+
$schema: "https://madapay.mg/schema/config.json",
|
|
135
|
+
version: "0.1.0",
|
|
136
|
+
framework: options.framework || "fastify",
|
|
137
|
+
storage: options.storage || "postgres",
|
|
138
|
+
providers,
|
|
139
|
+
defaultCurrency: "MGA",
|
|
140
|
+
defaultLocale: "fr"
|
|
141
|
+
};
|
|
142
|
+
fs__default.default.writeFileSync(configPath, JSON.stringify(configData, null, 2) + "\n", "utf8");
|
|
143
|
+
configCreated = true;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
envCreated,
|
|
147
|
+
envExampleCreated,
|
|
148
|
+
gitignoreUpdated,
|
|
149
|
+
configCreated,
|
|
150
|
+
targetDirectory: targetDir
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/bin.ts
|
|
155
|
+
var program = new commander.Command();
|
|
156
|
+
program.name("madapay").description("MadaPay CLI - Toolkit for Madagascar mobile money integrations").version("0.1.0");
|
|
157
|
+
program.command("init").description("Initialize MadaPay in the current or target directory").option("-d, --dir <directory>", "Target directory", ".").option(
|
|
158
|
+
"-p, --providers <providers>",
|
|
159
|
+
"Comma-separated providers (mvola,orange,airtel,papi,fiveone,alefa)"
|
|
160
|
+
).option(
|
|
161
|
+
"-f, --framework <framework>",
|
|
162
|
+
"Target framework (fastify, express, next, standalone)",
|
|
163
|
+
"fastify"
|
|
164
|
+
).option("-s, --storage <storage>", "Persistence storage (postgres, memory, sqlite)", "postgres").option("--force", "Overwrite existing .env and config files", false).action((options) => {
|
|
165
|
+
try {
|
|
166
|
+
const providers = options.providers ? options.providers.split(",").map((p) => p.trim()) : void 0;
|
|
167
|
+
const result = initProject({
|
|
168
|
+
directory: options.dir,
|
|
169
|
+
framework: options.framework,
|
|
170
|
+
providers,
|
|
171
|
+
storage: options.storage,
|
|
172
|
+
force: options.force
|
|
173
|
+
});
|
|
174
|
+
console.info("\u{1F680} MadaPay initialized successfully!");
|
|
175
|
+
console.info(`Target directory: ${result.targetDirectory}`);
|
|
176
|
+
if (result.envCreated) {
|
|
177
|
+
console.info(" \u2714 Generated .env with empty secrets and sandbox default");
|
|
178
|
+
} else {
|
|
179
|
+
console.info(" \u2714 Existing .env preserved (use --force to overwrite)");
|
|
180
|
+
}
|
|
181
|
+
console.info(" \u2714 Generated .env.example");
|
|
182
|
+
if (result.gitignoreUpdated) {
|
|
183
|
+
console.info(" \u2714 Verified .gitignore protection (.env excluded from git)");
|
|
184
|
+
}
|
|
185
|
+
if (result.configCreated) {
|
|
186
|
+
console.info(" \u2714 Created madapay.config.json");
|
|
187
|
+
}
|
|
188
|
+
} catch (err) {
|
|
189
|
+
console.error(`Error initializing MadaPay: ${err.message}`);
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
program.parse(process.argv);
|
|
194
|
+
//# sourceMappingURL=bin.cjs.map
|
|
195
|
+
//# sourceMappingURL=bin.cjs.map
|
package/dist/bin.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/bin.ts"],"names":["path","fs","Command"],"mappings":";;;;;;;;;;;;AAmBO,SAAS,mBAAmB,SAAA,EAA6B;AAC9D,EAAA,MAAM,KAAA,GAAkB;AAAA,IACtB,8CAAA;AAAA,IACA,oEAAA;AAAA,IACA,wEAAA;AAAA,IACA,EAAA;AAAA,IACA,qBAAA;AAAA,IACA,cAAA;AAAA,IACA,mBAAA;AAAA,IACA,WAAA;AAAA,IACA,EAAA;AAAA,IACA,0BAAA;AAAA,IACA,oEAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,eAAe,SAAA,CAAU,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,aAAa,CAAA;AAEzD,EAAA,IAAI,YAAA,CAAa,QAAA,CAAS,OAAO,CAAA,EAAG;AAClC,IAAA,KAAA,CAAM,IAAA;AAAA,MACJ,eAAA;AAAA,MACA,qBAAA;AAAA,MACA,wBAAA;AAAA,MACA,wBAAA;AAAA,MACA,2BAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,IACE,YAAA,CAAa,QAAA,CAAS,QAAQ,CAAA,IAC9B,YAAA,CAAa,QAAA,CAAS,cAAc,CAAA,IACpC,YAAA,CAAa,QAAA,CAAS,cAAc,CAAA,EACpC;AACA,IAAA,KAAA,CAAM,IAAA;AAAA,MACJ,2BAAA;AAAA,MACA,mBAAA;AAAA,MACA,uBAAA;AAAA,MACA,sBAAA;AAAA,MACA,4BAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,IACE,YAAA,CAAa,QAAA,CAAS,QAAQ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O,OAAA,CAAQ;AAAA,KAChB,CAAA;AAED,IAAA,OAAA,CAAQ,KAAK,6CAAsC,CAAA;AACnD,IAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,kBAAA,EAAqB,MAAA,CAAO,eAAe,CAAA,CAAE,CAAA;AAC1D,IAAA,IAAI,OAAO,UAAA,EAAY;AACrB,MAAA,OAAA,CAAQ,KAAK,gEAA2D,CAAA;AAAA,IAC1E,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,KAAK,6DAAwD,CAAA;AAAA,IACvE;AACA,IAAA,OAAA,CAAQ,KAAK,iCAA4B,CAAA;AACzC,IAAA,IAAI,OAAO,gBAAA,EAAkB;AAC3B,MAAA,OAAA,CAAQ,KAAK,kEAA6D,CAAA;AAAA,IAC5E;AACA,IAAA,IAAI,OAAO,aAAA,EAAe;AACxB,MAAA,OAAA,CAAQ,KAAK,sCAAiC,CAAA;AAAA,IAChD;AAAA,EACF,SAAS,GAAA,EAAU;AACjB,IAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,4BAAA,EAA+B,GAAA,CAAI,OAAO,CAAA,CAAE,CAAA;AAC1D,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAC,CAAA;AAEH,OAAA,CAAQ,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"bin.cjs","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface InitOptions {\n directory?: string;\n framework?: 'fastify' | 'express' | 'next' | 'standalone';\n providers?: string[];\n storage?: 'postgres' | 'memory' | 'sqlite';\n force?: boolean;\n}\n\nexport interface InitResult {\n envCreated: boolean;\n envExampleCreated: boolean;\n gitignoreUpdated: boolean;\n configCreated: boolean;\n targetDirectory: string;\n}\n\nexport function generateEnvContent(providers: string[]): string {\n const lines: string[] = [\n '# MadaPay Merchant Environment Configuration',\n '# All credentials MUST run strictly on your secure backend server.',\n '# NEVER expose these credentials to client browsers or mobile devices.',\n '',\n '# Merchant Identity',\n 'MERCHANT_ID=',\n 'MERCHANT_API_KEY=',\n 'PORT=3000',\n '',\n '# Persistence & Database',\n 'DATABASE_URL=postgresql://postgres:postgres@localhost:5432/madapay',\n '',\n ];\n\n const providerList = providers.map((p) => p.toLowerCase());\n\n if (providerList.includes('mvola')) {\n lines.push(\n '# Telma MVola',\n 'MVOLA_CONSUMER_KEY=',\n 'MVOLA_CONSUMER_SECRET=',\n 'MVOLA_MERCHANT_NUMBER=',\n 'MVOLA_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (\n providerList.includes('orange') ||\n providerList.includes('orange_money') ||\n providerList.includes('orange-money')\n ) {\n lines.push(\n '# Orange Money Madagascar',\n 'ORANGE_CLIENT_ID=',\n 'ORANGE_CLIENT_SECRET=',\n 'ORANGE_MERCHANT_KEY=',\n 'ORANGE_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (\n providerList.includes('airtel') ||\n providerList.includes('airtel_money') ||\n providerList.includes('airtel-money')\n ) {\n lines.push(\n '# Airtel Money Madagascar',\n 'AIRTEL_CLIENT_ID=',\n 'AIRTEL_CLIENT_SECRET=',\n 'AIRTEL_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (providerList.includes('papi')) {\n lines.push('# PAPI Aggregator', 'PAPI_API_KEY=', 'PAPI_ENVIRONMENT=sandbox', '');\n }\n\n if (providerList.includes('fiveone')) {\n lines.push(\n '# FiveOne Aggregator',\n 'FIVEONE_API_KEY=',\n 'FIVEONE_SECRET_KEY=',\n 'FIVEONE_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (providerList.includes('alefa')) {\n lines.push(\n '# Alefa Aggregator',\n 'ALEFA_API_KEY=',\n 'ALEFA_SECRET_KEY=',\n 'ALEFA_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Ensures target directory .gitignore exists and includes .env to protect secrets.\n */\nexport function ensureGitignoreProtection(targetDir: string): boolean {\n const gitignorePath = path.join(targetDir, '.gitignore');\n let updated = false;\n\n if (fs.existsSync(gitignorePath)) {\n const existing = fs.readFileSync(gitignorePath, 'utf8');\n const lines = existing.split(/\\r?\\n/).map((l) => l.trim());\n const needed = ['.env', '.env.local', '.env.*.local'];\n const missing = needed.filter((item) => !lines.includes(item));\n\n if (missing.length > 0) {\n const appendContent = `\\n# MadaPay secrets protection\\n${missing.join('\\n')}\\n`;\n fs.appendFileSync(gitignorePath, appendContent, 'utf8');\n updated = true;\n }\n } else {\n const defaultGitignore = [\n '# MadaPay secrets protection',\n '.env',\n '.env.local',\n '.env.*.local',\n 'node_modules',\n 'dist',\n '',\n ].join('\\n');\n fs.writeFileSync(gitignorePath, defaultGitignore, 'utf8');\n updated = true;\n }\n\n return updated;\n}\n\n/**\n * Initializes MadaPay configuration in the specified directory.\n */\nexport function initProject(options: InitOptions = {}): InitResult {\n const targetDir = path.resolve(process.cwd(), options.directory || '.');\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n const providers =\n options.providers && options.providers.length > 0\n ? options.providers\n : ['mvola', 'orange_money', 'airtel_money', 'papi'];\n\n const envContent = generateEnvContent(providers);\n\n const envExamplePath = path.join(targetDir, '.env.example');\n const envPath = path.join(targetDir, '.env');\n const configPath = path.join(targetDir, 'madapay.config.json');\n\n let envExampleCreated = false;\n let envCreated = false;\n\n // Always write or overwrite .env.example\n fs.writeFileSync(envExamplePath, envContent, 'utf8');\n envExampleCreated = true;\n\n // Write .env only if it doesn't exist or if force is specified\n if (!fs.existsSync(envPath) || options.force) {\n fs.writeFileSync(envPath, envContent, 'utf8');\n envCreated = true;\n }\n\n // Ensure .gitignore protects secrets\n const gitignoreUpdated = ensureGitignoreProtection(targetDir);\n\n // Write madapay.config.json\n let configCreated = false;\n if (!fs.existsSync(configPath) || options.force) {\n const configData = {\n $schema: 'https://madapay.mg/schema/config.json',\n version: '0.1.0',\n framework: options.framework || 'fastify',\n storage: options.storage || 'postgres',\n providers,\n defaultCurrency: 'MGA',\n defaultLocale: 'fr',\n };\n fs.writeFileSync(configPath, JSON.stringify(configData, null, 2) + '\\n', 'utf8');\n configCreated = true;\n }\n\n return {\n envCreated,\n envExampleCreated,\n gitignoreUpdated,\n configCreated,\n targetDirectory: targetDir,\n };\n}\n","#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { initProject } from './init.js';\n\nconst program = new Command();\n\nprogram\n .name('madapay')\n .description('MadaPay CLI - Toolkit for Madagascar mobile money integrations')\n .version('0.1.0');\n\nprogram\n .command('init')\n .description('Initialize MadaPay in the current or target directory')\n .option('-d, --dir <directory>', 'Target directory', '.')\n .option(\n '-p, --providers <providers>',\n 'Comma-separated providers (mvola,orange,airtel,papi,fiveone,alefa)',\n )\n .option(\n '-f, --framework <framework>',\n 'Target framework (fastify, express, next, standalone)',\n 'fastify',\n )\n .option('-s, --storage <storage>', 'Persistence storage (postgres, memory, sqlite)', 'postgres')\n .option('--force', 'Overwrite existing .env and config files', false)\n .action((options) => {\n try {\n const providers = options.providers\n ? options.providers.split(',').map((p: string) => p.trim())\n : undefined;\n\n const result = initProject({\n directory: options.dir,\n framework: options.framework,\n providers,\n storage: options.storage,\n force: options.force,\n });\n\n console.info('🚀 MadaPay initialized successfully!');\n console.info(`Target directory: ${result.targetDirectory}`);\n if (result.envCreated) {\n console.info(' ✔ Generated .env with empty secrets and sandbox default');\n } else {\n console.info(' ✔ Existing .env preserved (use --force to overwrite)');\n }\n console.info(' ✔ Generated .env.example');\n if (result.gitignoreUpdated) {\n console.info(' ✔ Verified .gitignore protection (.env excluded from git)');\n }\n if (result.configCreated) {\n console.info(' ✔ Created madapay.config.json');\n }\n } catch (err: any) {\n console.error(`Error initializing MadaPay: ${err.message}`);\n process.exit(1);\n }\n });\n\nprogram.parse(process.argv);\n"]}
|
package/dist/bin.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
function generateEnvContent(providers) {
|
|
7
|
+
const lines = [
|
|
8
|
+
"# MadaPay Merchant Environment Configuration",
|
|
9
|
+
"# All credentials MUST run strictly on your secure backend server.",
|
|
10
|
+
"# NEVER expose these credentials to client browsers or mobile devices.",
|
|
11
|
+
"",
|
|
12
|
+
"# Merchant Identity",
|
|
13
|
+
"MERCHANT_ID=",
|
|
14
|
+
"MERCHANT_API_KEY=",
|
|
15
|
+
"PORT=3000",
|
|
16
|
+
"",
|
|
17
|
+
"# Persistence & Database",
|
|
18
|
+
"DATABASE_URL=postgresql://postgres:postgres@localhost:5432/madapay",
|
|
19
|
+
""
|
|
20
|
+
];
|
|
21
|
+
const providerList = providers.map((p) => p.toLowerCase());
|
|
22
|
+
if (providerList.includes("mvola")) {
|
|
23
|
+
lines.push(
|
|
24
|
+
"# Telma MVola",
|
|
25
|
+
"MVOLA_CONSUMER_KEY=",
|
|
26
|
+
"MVOLA_CONSUMER_SECRET=",
|
|
27
|
+
"MVOLA_MERCHANT_NUMBER=",
|
|
28
|
+
"MVOLA_ENVIRONMENT=sandbox",
|
|
29
|
+
""
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (providerList.includes("orange") || providerList.includes("orange_money") || providerList.includes("orange-money")) {
|
|
33
|
+
lines.push(
|
|
34
|
+
"# Orange Money Madagascar",
|
|
35
|
+
"ORANGE_CLIENT_ID=",
|
|
36
|
+
"ORANGE_CLIENT_SECRET=",
|
|
37
|
+
"ORANGE_MERCHANT_KEY=",
|
|
38
|
+
"ORANGE_ENVIRONMENT=sandbox",
|
|
39
|
+
""
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if (providerList.includes("airtel") || providerList.includes("airtel_money") || providerList.includes("airtel-money")) {
|
|
43
|
+
lines.push(
|
|
44
|
+
"# Airtel Money Madagascar",
|
|
45
|
+
"AIRTEL_CLIENT_ID=",
|
|
46
|
+
"AIRTEL_CLIENT_SECRET=",
|
|
47
|
+
"AIRTEL_ENVIRONMENT=sandbox",
|
|
48
|
+
""
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (providerList.includes("papi")) {
|
|
52
|
+
lines.push("# PAPI Aggregator", "PAPI_API_KEY=", "PAPI_ENVIRONMENT=sandbox", "");
|
|
53
|
+
}
|
|
54
|
+
if (providerList.includes("fiveone")) {
|
|
55
|
+
lines.push(
|
|
56
|
+
"# FiveOne Aggregator",
|
|
57
|
+
"FIVEONE_API_KEY=",
|
|
58
|
+
"FIVEONE_SECRET_KEY=",
|
|
59
|
+
"FIVEONE_ENVIRONMENT=sandbox",
|
|
60
|
+
""
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (providerList.includes("alefa")) {
|
|
64
|
+
lines.push(
|
|
65
|
+
"# Alefa Aggregator",
|
|
66
|
+
"ALEFA_API_KEY=",
|
|
67
|
+
"ALEFA_SECRET_KEY=",
|
|
68
|
+
"ALEFA_ENVIRONMENT=sandbox",
|
|
69
|
+
""
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return lines.join("\n");
|
|
73
|
+
}
|
|
74
|
+
function ensureGitignoreProtection(targetDir) {
|
|
75
|
+
const gitignorePath = path.join(targetDir, ".gitignore");
|
|
76
|
+
let updated = false;
|
|
77
|
+
if (fs.existsSync(gitignorePath)) {
|
|
78
|
+
const existing = fs.readFileSync(gitignorePath, "utf8");
|
|
79
|
+
const lines = existing.split(/\r?\n/).map((l) => l.trim());
|
|
80
|
+
const needed = [".env", ".env.local", ".env.*.local"];
|
|
81
|
+
const missing = needed.filter((item) => !lines.includes(item));
|
|
82
|
+
if (missing.length > 0) {
|
|
83
|
+
const appendContent = `
|
|
84
|
+
# MadaPay secrets protection
|
|
85
|
+
${missing.join("\n")}
|
|
86
|
+
`;
|
|
87
|
+
fs.appendFileSync(gitignorePath, appendContent, "utf8");
|
|
88
|
+
updated = true;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
const defaultGitignore = [
|
|
92
|
+
"# MadaPay secrets protection",
|
|
93
|
+
".env",
|
|
94
|
+
".env.local",
|
|
95
|
+
".env.*.local",
|
|
96
|
+
"node_modules",
|
|
97
|
+
"dist",
|
|
98
|
+
""
|
|
99
|
+
].join("\n");
|
|
100
|
+
fs.writeFileSync(gitignorePath, defaultGitignore, "utf8");
|
|
101
|
+
updated = true;
|
|
102
|
+
}
|
|
103
|
+
return updated;
|
|
104
|
+
}
|
|
105
|
+
function initProject(options = {}) {
|
|
106
|
+
const targetDir = path.resolve(process.cwd(), options.directory || ".");
|
|
107
|
+
if (!fs.existsSync(targetDir)) {
|
|
108
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
109
|
+
}
|
|
110
|
+
const providers = options.providers && options.providers.length > 0 ? options.providers : ["mvola", "orange_money", "airtel_money", "papi"];
|
|
111
|
+
const envContent = generateEnvContent(providers);
|
|
112
|
+
const envExamplePath = path.join(targetDir, ".env.example");
|
|
113
|
+
const envPath = path.join(targetDir, ".env");
|
|
114
|
+
const configPath = path.join(targetDir, "madapay.config.json");
|
|
115
|
+
let envExampleCreated = false;
|
|
116
|
+
let envCreated = false;
|
|
117
|
+
fs.writeFileSync(envExamplePath, envContent, "utf8");
|
|
118
|
+
envExampleCreated = true;
|
|
119
|
+
if (!fs.existsSync(envPath) || options.force) {
|
|
120
|
+
fs.writeFileSync(envPath, envContent, "utf8");
|
|
121
|
+
envCreated = true;
|
|
122
|
+
}
|
|
123
|
+
const gitignoreUpdated = ensureGitignoreProtection(targetDir);
|
|
124
|
+
let configCreated = false;
|
|
125
|
+
if (!fs.existsSync(configPath) || options.force) {
|
|
126
|
+
const configData = {
|
|
127
|
+
$schema: "https://madapay.mg/schema/config.json",
|
|
128
|
+
version: "0.1.0",
|
|
129
|
+
framework: options.framework || "fastify",
|
|
130
|
+
storage: options.storage || "postgres",
|
|
131
|
+
providers,
|
|
132
|
+
defaultCurrency: "MGA",
|
|
133
|
+
defaultLocale: "fr"
|
|
134
|
+
};
|
|
135
|
+
fs.writeFileSync(configPath, JSON.stringify(configData, null, 2) + "\n", "utf8");
|
|
136
|
+
configCreated = true;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
envCreated,
|
|
140
|
+
envExampleCreated,
|
|
141
|
+
gitignoreUpdated,
|
|
142
|
+
configCreated,
|
|
143
|
+
targetDirectory: targetDir
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/bin.ts
|
|
148
|
+
var program = new Command();
|
|
149
|
+
program.name("madapay").description("MadaPay CLI - Toolkit for Madagascar mobile money integrations").version("0.1.0");
|
|
150
|
+
program.command("init").description("Initialize MadaPay in the current or target directory").option("-d, --dir <directory>", "Target directory", ".").option(
|
|
151
|
+
"-p, --providers <providers>",
|
|
152
|
+
"Comma-separated providers (mvola,orange,airtel,papi,fiveone,alefa)"
|
|
153
|
+
).option(
|
|
154
|
+
"-f, --framework <framework>",
|
|
155
|
+
"Target framework (fastify, express, next, standalone)",
|
|
156
|
+
"fastify"
|
|
157
|
+
).option("-s, --storage <storage>", "Persistence storage (postgres, memory, sqlite)", "postgres").option("--force", "Overwrite existing .env and config files", false).action((options) => {
|
|
158
|
+
try {
|
|
159
|
+
const providers = options.providers ? options.providers.split(",").map((p) => p.trim()) : void 0;
|
|
160
|
+
const result = initProject({
|
|
161
|
+
directory: options.dir,
|
|
162
|
+
framework: options.framework,
|
|
163
|
+
providers,
|
|
164
|
+
storage: options.storage,
|
|
165
|
+
force: options.force
|
|
166
|
+
});
|
|
167
|
+
console.info("\u{1F680} MadaPay initialized successfully!");
|
|
168
|
+
console.info(`Target directory: ${result.targetDirectory}`);
|
|
169
|
+
if (result.envCreated) {
|
|
170
|
+
console.info(" \u2714 Generated .env with empty secrets and sandbox default");
|
|
171
|
+
} else {
|
|
172
|
+
console.info(" \u2714 Existing .env preserved (use --force to overwrite)");
|
|
173
|
+
}
|
|
174
|
+
console.info(" \u2714 Generated .env.example");
|
|
175
|
+
if (result.gitignoreUpdated) {
|
|
176
|
+
console.info(" \u2714 Verified .gitignore protection (.env excluded from git)");
|
|
177
|
+
}
|
|
178
|
+
if (result.configCreated) {
|
|
179
|
+
console.info(" \u2714 Created madapay.config.json");
|
|
180
|
+
}
|
|
181
|
+
} catch (err) {
|
|
182
|
+
console.error(`Error initializing MadaPay: ${err.message}`);
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
program.parse(process.argv);
|
|
187
|
+
//# sourceMappingURL=bin.js.map
|
|
188
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/bin.ts"],"names":[],"mappings":";;;;;AAmBO,SAAS,mBAAmB,SAAA,EAA6B;AAC9D,EAAA,MAAM,KAAA,GAAkB;AAAA,IACtB,8CAAA;AAAA,IACA,oEAAA;AAAA,IACA,wEAAA;AAAA,IACA,EAAA;AAAA,IACA,qBAAA;AAAA,IACA,cAAA;AAAA,IACA,mBAAA;AAAA,IACA,WAAA;AAAA,IACA,EAAA;AAAA,IACA,0BAAA;AAAA,IACA,oEAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,MAAM,eAAe,SAAA,CAAU,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,aAAa,CAAA;AAEzD,EAAA,IAAI,YAAA,CAAa,QAAA,CAAS,OAAO,CAAA,EAAG;AAClC,IAAA,KAAA,CAAM,IAAA;AAAA,MACJ,eAAA;AAAA,MACA,qBAAA;AAAA,MACA,wBAAA;AAAA,MACA,wBAAA;AAAA,MACA,2BAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,IACE,YAAA,CAAa,QAAA,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CAAA,CAAE,GAAA,CAAI,CAAC,CAAA,KAAc,CAAA,CAAE,IAAA,EAAM,CAAA,GACxD,KAAA,CAAA;AAEJ,IAAA,MAAM,SAAS,WAAA,CAAY;AAAA,MACzB,WAAW,OAAA,CAAQ,GAAA;AAAA,MACnB,WAAW,OAAA,CAAQ,SAAA;AAAA,MACnB,SAAA;AAAA,MACA,SAAS,OAAA,CAAQ,OAAA;AAAA,MACjB,OAAO,OAAA,CAAQ;AAAA,KAChB,CAAA;AAED,IAAA,OAAA,CAAQ,KAAK,6CAAsC,CAAA;AACnD,IAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,kBAAA,EAAqB,MAAA,CAAO,eAAe,CAAA,CAAE,CAAA;AAC1D,IAAA,IAAI,OAAO,UAAA,EAAY;AACrB,MAAA,OAAA,CAAQ,KAAK,gEAA2D,CAAA;AAAA,IAC1E,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,KAAK,6DAAwD,CAAA;AAAA,IACvE;AACA,IAAA,OAAA,CAAQ,KAAK,iCAA4B,CAAA;AACzC,IAAA,IAAI,OAAO,gBAAA,EAAkB;AAC3B,MAAA,OAAA,CAAQ,KAAK,kEAA6D,CAAA;AAAA,IAC5E;AACA,IAAA,IAAI,OAAO,aAAA,EAAe;AACxB,MAAA,OAAA,CAAQ,KAAK,sCAAiC,CAAA;AAAA,IAChD;AAAA,EACF,SAAS,GAAA,EAAU;AACjB,IAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,4BAAA,EAA+B,GAAA,CAAI,OAAO,CAAA,CAAE,CAAA;AAC1D,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAC,CAAA;AAEH,OAAA,CAAQ,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"bin.js","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface InitOptions {\n directory?: string;\n framework?: 'fastify' | 'express' | 'next' | 'standalone';\n providers?: string[];\n storage?: 'postgres' | 'memory' | 'sqlite';\n force?: boolean;\n}\n\nexport interface InitResult {\n envCreated: boolean;\n envExampleCreated: boolean;\n gitignoreUpdated: boolean;\n configCreated: boolean;\n targetDirectory: string;\n}\n\nexport function generateEnvContent(providers: string[]): string {\n const lines: string[] = [\n '# MadaPay Merchant Environment Configuration',\n '# All credentials MUST run strictly on your secure backend server.',\n '# NEVER expose these credentials to client browsers or mobile devices.',\n '',\n '# Merchant Identity',\n 'MERCHANT_ID=',\n 'MERCHANT_API_KEY=',\n 'PORT=3000',\n '',\n '# Persistence & Database',\n 'DATABASE_URL=postgresql://postgres:postgres@localhost:5432/madapay',\n '',\n ];\n\n const providerList = providers.map((p) => p.toLowerCase());\n\n if (providerList.includes('mvola')) {\n lines.push(\n '# Telma MVola',\n 'MVOLA_CONSUMER_KEY=',\n 'MVOLA_CONSUMER_SECRET=',\n 'MVOLA_MERCHANT_NUMBER=',\n 'MVOLA_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (\n providerList.includes('orange') ||\n providerList.includes('orange_money') ||\n providerList.includes('orange-money')\n ) {\n lines.push(\n '# Orange Money Madagascar',\n 'ORANGE_CLIENT_ID=',\n 'ORANGE_CLIENT_SECRET=',\n 'ORANGE_MERCHANT_KEY=',\n 'ORANGE_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (\n providerList.includes('airtel') ||\n providerList.includes('airtel_money') ||\n providerList.includes('airtel-money')\n ) {\n lines.push(\n '# Airtel Money Madagascar',\n 'AIRTEL_CLIENT_ID=',\n 'AIRTEL_CLIENT_SECRET=',\n 'AIRTEL_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (providerList.includes('papi')) {\n lines.push('# PAPI Aggregator', 'PAPI_API_KEY=', 'PAPI_ENVIRONMENT=sandbox', '');\n }\n\n if (providerList.includes('fiveone')) {\n lines.push(\n '# FiveOne Aggregator',\n 'FIVEONE_API_KEY=',\n 'FIVEONE_SECRET_KEY=',\n 'FIVEONE_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (providerList.includes('alefa')) {\n lines.push(\n '# Alefa Aggregator',\n 'ALEFA_API_KEY=',\n 'ALEFA_SECRET_KEY=',\n 'ALEFA_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Ensures target directory .gitignore exists and includes .env to protect secrets.\n */\nexport function ensureGitignoreProtection(targetDir: string): boolean {\n const gitignorePath = path.join(targetDir, '.gitignore');\n let updated = false;\n\n if (fs.existsSync(gitignorePath)) {\n const existing = fs.readFileSync(gitignorePath, 'utf8');\n const lines = existing.split(/\\r?\\n/).map((l) => l.trim());\n const needed = ['.env', '.env.local', '.env.*.local'];\n const missing = needed.filter((item) => !lines.includes(item));\n\n if (missing.length > 0) {\n const appendContent = `\\n# MadaPay secrets protection\\n${missing.join('\\n')}\\n`;\n fs.appendFileSync(gitignorePath, appendContent, 'utf8');\n updated = true;\n }\n } else {\n const defaultGitignore = [\n '# MadaPay secrets protection',\n '.env',\n '.env.local',\n '.env.*.local',\n 'node_modules',\n 'dist',\n '',\n ].join('\\n');\n fs.writeFileSync(gitignorePath, defaultGitignore, 'utf8');\n updated = true;\n }\n\n return updated;\n}\n\n/**\n * Initializes MadaPay configuration in the specified directory.\n */\nexport function initProject(options: InitOptions = {}): InitResult {\n const targetDir = path.resolve(process.cwd(), options.directory || '.');\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n const providers =\n options.providers && options.providers.length > 0\n ? options.providers\n : ['mvola', 'orange_money', 'airtel_money', 'papi'];\n\n const envContent = generateEnvContent(providers);\n\n const envExamplePath = path.join(targetDir, '.env.example');\n const envPath = path.join(targetDir, '.env');\n const configPath = path.join(targetDir, 'madapay.config.json');\n\n let envExampleCreated = false;\n let envCreated = false;\n\n // Always write or overwrite .env.example\n fs.writeFileSync(envExamplePath, envContent, 'utf8');\n envExampleCreated = true;\n\n // Write .env only if it doesn't exist or if force is specified\n if (!fs.existsSync(envPath) || options.force) {\n fs.writeFileSync(envPath, envContent, 'utf8');\n envCreated = true;\n }\n\n // Ensure .gitignore protects secrets\n const gitignoreUpdated = ensureGitignoreProtection(targetDir);\n\n // Write madapay.config.json\n let configCreated = false;\n if (!fs.existsSync(configPath) || options.force) {\n const configData = {\n $schema: 'https://madapay.mg/schema/config.json',\n version: '0.1.0',\n framework: options.framework || 'fastify',\n storage: options.storage || 'postgres',\n providers,\n defaultCurrency: 'MGA',\n defaultLocale: 'fr',\n };\n fs.writeFileSync(configPath, JSON.stringify(configData, null, 2) + '\\n', 'utf8');\n configCreated = true;\n }\n\n return {\n envCreated,\n envExampleCreated,\n gitignoreUpdated,\n configCreated,\n targetDirectory: targetDir,\n };\n}\n","#!/usr/bin/env node\nimport { Command } from 'commander';\nimport { initProject } from './init.js';\n\nconst program = new Command();\n\nprogram\n .name('madapay')\n .description('MadaPay CLI - Toolkit for Madagascar mobile money integrations')\n .version('0.1.0');\n\nprogram\n .command('init')\n .description('Initialize MadaPay in the current or target directory')\n .option('-d, --dir <directory>', 'Target directory', '.')\n .option(\n '-p, --providers <providers>',\n 'Comma-separated providers (mvola,orange,airtel,papi,fiveone,alefa)',\n )\n .option(\n '-f, --framework <framework>',\n 'Target framework (fastify, express, next, standalone)',\n 'fastify',\n )\n .option('-s, --storage <storage>', 'Persistence storage (postgres, memory, sqlite)', 'postgres')\n .option('--force', 'Overwrite existing .env and config files', false)\n .action((options) => {\n try {\n const providers = options.providers\n ? options.providers.split(',').map((p: string) => p.trim())\n : undefined;\n\n const result = initProject({\n directory: options.dir,\n framework: options.framework,\n providers,\n storage: options.storage,\n force: options.force,\n });\n\n console.info('🚀 MadaPay initialized successfully!');\n console.info(`Target directory: ${result.targetDirectory}`);\n if (result.envCreated) {\n console.info(' ✔ Generated .env with empty secrets and sandbox default');\n } else {\n console.info(' ✔ Existing .env preserved (use --force to overwrite)');\n }\n console.info(' ✔ Generated .env.example');\n if (result.gitignoreUpdated) {\n console.info(' ✔ Verified .gitignore protection (.env excluded from git)');\n }\n if (result.configCreated) {\n console.info(' ✔ Created madapay.config.json');\n }\n } catch (err: any) {\n console.error(`Error initializing MadaPay: ${err.message}`);\n process.exit(1);\n }\n });\n\nprogram.parse(process.argv);\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
9
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
10
|
+
|
|
11
|
+
// src/init.ts
|
|
12
|
+
function generateEnvContent(providers) {
|
|
13
|
+
const lines = [
|
|
14
|
+
"# MadaPay Merchant Environment Configuration",
|
|
15
|
+
"# All credentials MUST run strictly on your secure backend server.",
|
|
16
|
+
"# NEVER expose these credentials to client browsers or mobile devices.",
|
|
17
|
+
"",
|
|
18
|
+
"# Merchant Identity",
|
|
19
|
+
"MERCHANT_ID=",
|
|
20
|
+
"MERCHANT_API_KEY=",
|
|
21
|
+
"PORT=3000",
|
|
22
|
+
"",
|
|
23
|
+
"# Persistence & Database",
|
|
24
|
+
"DATABASE_URL=postgresql://postgres:postgres@localhost:5432/madapay",
|
|
25
|
+
""
|
|
26
|
+
];
|
|
27
|
+
const providerList = providers.map((p) => p.toLowerCase());
|
|
28
|
+
if (providerList.includes("mvola")) {
|
|
29
|
+
lines.push(
|
|
30
|
+
"# Telma MVola",
|
|
31
|
+
"MVOLA_CONSUMER_KEY=",
|
|
32
|
+
"MVOLA_CONSUMER_SECRET=",
|
|
33
|
+
"MVOLA_MERCHANT_NUMBER=",
|
|
34
|
+
"MVOLA_ENVIRONMENT=sandbox",
|
|
35
|
+
""
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (providerList.includes("orange") || providerList.includes("orange_money") || providerList.includes("orange-money")) {
|
|
39
|
+
lines.push(
|
|
40
|
+
"# Orange Money Madagascar",
|
|
41
|
+
"ORANGE_CLIENT_ID=",
|
|
42
|
+
"ORANGE_CLIENT_SECRET=",
|
|
43
|
+
"ORANGE_MERCHANT_KEY=",
|
|
44
|
+
"ORANGE_ENVIRONMENT=sandbox",
|
|
45
|
+
""
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (providerList.includes("airtel") || providerList.includes("airtel_money") || providerList.includes("airtel-money")) {
|
|
49
|
+
lines.push(
|
|
50
|
+
"# Airtel Money Madagascar",
|
|
51
|
+
"AIRTEL_CLIENT_ID=",
|
|
52
|
+
"AIRTEL_CLIENT_SECRET=",
|
|
53
|
+
"AIRTEL_ENVIRONMENT=sandbox",
|
|
54
|
+
""
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (providerList.includes("papi")) {
|
|
58
|
+
lines.push("# PAPI Aggregator", "PAPI_API_KEY=", "PAPI_ENVIRONMENT=sandbox", "");
|
|
59
|
+
}
|
|
60
|
+
if (providerList.includes("fiveone")) {
|
|
61
|
+
lines.push(
|
|
62
|
+
"# FiveOne Aggregator",
|
|
63
|
+
"FIVEONE_API_KEY=",
|
|
64
|
+
"FIVEONE_SECRET_KEY=",
|
|
65
|
+
"FIVEONE_ENVIRONMENT=sandbox",
|
|
66
|
+
""
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (providerList.includes("alefa")) {
|
|
70
|
+
lines.push(
|
|
71
|
+
"# Alefa Aggregator",
|
|
72
|
+
"ALEFA_API_KEY=",
|
|
73
|
+
"ALEFA_SECRET_KEY=",
|
|
74
|
+
"ALEFA_ENVIRONMENT=sandbox",
|
|
75
|
+
""
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return lines.join("\n");
|
|
79
|
+
}
|
|
80
|
+
function ensureGitignoreProtection(targetDir) {
|
|
81
|
+
const gitignorePath = path__default.default.join(targetDir, ".gitignore");
|
|
82
|
+
let updated = false;
|
|
83
|
+
if (fs__default.default.existsSync(gitignorePath)) {
|
|
84
|
+
const existing = fs__default.default.readFileSync(gitignorePath, "utf8");
|
|
85
|
+
const lines = existing.split(/\r?\n/).map((l) => l.trim());
|
|
86
|
+
const needed = [".env", ".env.local", ".env.*.local"];
|
|
87
|
+
const missing = needed.filter((item) => !lines.includes(item));
|
|
88
|
+
if (missing.length > 0) {
|
|
89
|
+
const appendContent = `
|
|
90
|
+
# MadaPay secrets protection
|
|
91
|
+
${missing.join("\n")}
|
|
92
|
+
`;
|
|
93
|
+
fs__default.default.appendFileSync(gitignorePath, appendContent, "utf8");
|
|
94
|
+
updated = true;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
const defaultGitignore = [
|
|
98
|
+
"# MadaPay secrets protection",
|
|
99
|
+
".env",
|
|
100
|
+
".env.local",
|
|
101
|
+
".env.*.local",
|
|
102
|
+
"node_modules",
|
|
103
|
+
"dist",
|
|
104
|
+
""
|
|
105
|
+
].join("\n");
|
|
106
|
+
fs__default.default.writeFileSync(gitignorePath, defaultGitignore, "utf8");
|
|
107
|
+
updated = true;
|
|
108
|
+
}
|
|
109
|
+
return updated;
|
|
110
|
+
}
|
|
111
|
+
function initProject(options = {}) {
|
|
112
|
+
const targetDir = path__default.default.resolve(process.cwd(), options.directory || ".");
|
|
113
|
+
if (!fs__default.default.existsSync(targetDir)) {
|
|
114
|
+
fs__default.default.mkdirSync(targetDir, { recursive: true });
|
|
115
|
+
}
|
|
116
|
+
const providers = options.providers && options.providers.length > 0 ? options.providers : ["mvola", "orange_money", "airtel_money", "papi"];
|
|
117
|
+
const envContent = generateEnvContent(providers);
|
|
118
|
+
const envExamplePath = path__default.default.join(targetDir, ".env.example");
|
|
119
|
+
const envPath = path__default.default.join(targetDir, ".env");
|
|
120
|
+
const configPath = path__default.default.join(targetDir, "madapay.config.json");
|
|
121
|
+
let envExampleCreated = false;
|
|
122
|
+
let envCreated = false;
|
|
123
|
+
fs__default.default.writeFileSync(envExamplePath, envContent, "utf8");
|
|
124
|
+
envExampleCreated = true;
|
|
125
|
+
if (!fs__default.default.existsSync(envPath) || options.force) {
|
|
126
|
+
fs__default.default.writeFileSync(envPath, envContent, "utf8");
|
|
127
|
+
envCreated = true;
|
|
128
|
+
}
|
|
129
|
+
const gitignoreUpdated = ensureGitignoreProtection(targetDir);
|
|
130
|
+
let configCreated = false;
|
|
131
|
+
if (!fs__default.default.existsSync(configPath) || options.force) {
|
|
132
|
+
const configData = {
|
|
133
|
+
$schema: "https://madapay.mg/schema/config.json",
|
|
134
|
+
version: "0.1.0",
|
|
135
|
+
framework: options.framework || "fastify",
|
|
136
|
+
storage: options.storage || "postgres",
|
|
137
|
+
providers,
|
|
138
|
+
defaultCurrency: "MGA",
|
|
139
|
+
defaultLocale: "fr"
|
|
140
|
+
};
|
|
141
|
+
fs__default.default.writeFileSync(configPath, JSON.stringify(configData, null, 2) + "\n", "utf8");
|
|
142
|
+
configCreated = true;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
envCreated,
|
|
146
|
+
envExampleCreated,
|
|
147
|
+
gitignoreUpdated,
|
|
148
|
+
configCreated,
|
|
149
|
+
targetDirectory: targetDir
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
exports.ensureGitignoreProtection = ensureGitignoreProtection;
|
|
154
|
+
exports.generateEnvContent = generateEnvContent;
|
|
155
|
+
exports.initProject = initProject;
|
|
156
|
+
//# sourceMappingURL=index.cjs.map
|
|
157
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"names":["path","fs"],"mappings":";;;;;;;;;;;AAmBO,SAAS,mBAAmB,SAAA,EAA6B;AAC9D,EAAA,MAAM,KAAA,GAAkB;AAAA,IACtB,8CAAA;AAAA,IACA,oEAAA;AAAA,IACA,wEAAA;AAAA,IACA,EAAA;AAAA,IACA,qBAAA;AAAA,IACA,cAAA;AAAA,IACA,mB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EAAAC,mBAAA,CAAG,aAAA,CAAc,cAAA,EAAgB,UAAA,EAAY,MAAM,CAAA;AACnD,EAAA,iBAAA,GAAoB,IAAA;AAGpB,EAAA,IAAI,CAACA,mBAAA,CAAG,UAAA,CAAW,OAAO,CAAA,IAAK,QAAQ,KAAA,EAAO;AAC5C,IAAAA,mBAAA,CAAG,aAAA,CAAc,OAAA,EAAS,UAAA,EAAY,MAAM,CAAA;AAC5C,IAAA,UAAA,GAAa,IAAA;AAAA,EACf;AAGA,EAAA,MAAM,gBAAA,GAAmB,0BAA0B,SAAS,CAAA;AAG5D,EAAA,IAAI,aAAA,GAAgB,KAAA;AACpB,EAAA,IAAI,CAACA,mBAAA,CAAG,UAAA,CAAW,UAAU,CAAA,IAAK,QAAQ,KAAA,EAAO;AAC/C,IAAA,MAAM,UAAA,GAAa;AAAA,MACjB,OAAA,EAAS,uCAAA;AAAA,MACT,OAAA,EAAS,OAAA;AAAA,MACT,SAAA,EAAW,QAAQ,SAAA,IAAa,SAAA;AAAA,MAChC,OAAA,EAAS,QAAQ,OAAA,IAAW,UAAA;AAAA,MAC5B,SAAA;AAAA,MACA,eAAA,EAAiB,KAAA;AAAA,MACjB,aAAA,EAAe;AAAA,KACjB;AACA,IAAAA,mBAAA,CAAG,aAAA,CAAc,YAAY,IAAA,CAAK,SAAA,CAAU,YAAY,IAAA,EAAM,CAAC,CAAA,GAAI,IAAA,EAAM,MAAM,CAAA;AAC/E,IAAA,aAAA,GAAgB,IAAA;AAAA,EAClB;AAEA,EAAA,OAAO;AAAA,IACL,UAAA;AAAA,IACA,iBAAA;AAAA,IACA,gBAAA;AAAA,IACA,aAAA;AAAA,IACA,eAAA,EAAiB;AAAA,GACnB;AACF","file":"index.cjs","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface InitOptions {\n directory?: string;\n framework?: 'fastify' | 'express' | 'next' | 'standalone';\n providers?: string[];\n storage?: 'postgres' | 'memory' | 'sqlite';\n force?: boolean;\n}\n\nexport interface InitResult {\n envCreated: boolean;\n envExampleCreated: boolean;\n gitignoreUpdated: boolean;\n configCreated: boolean;\n targetDirectory: string;\n}\n\nexport function generateEnvContent(providers: string[]): string {\n const lines: string[] = [\n '# MadaPay Merchant Environment Configuration',\n '# All credentials MUST run strictly on your secure backend server.',\n '# NEVER expose these credentials to client browsers or mobile devices.',\n '',\n '# Merchant Identity',\n 'MERCHANT_ID=',\n 'MERCHANT_API_KEY=',\n 'PORT=3000',\n '',\n '# Persistence & Database',\n 'DATABASE_URL=postgresql://postgres:postgres@localhost:5432/madapay',\n '',\n ];\n\n const providerList = providers.map((p) => p.toLowerCase());\n\n if (providerList.includes('mvola')) {\n lines.push(\n '# Telma MVola',\n 'MVOLA_CONSUMER_KEY=',\n 'MVOLA_CONSUMER_SECRET=',\n 'MVOLA_MERCHANT_NUMBER=',\n 'MVOLA_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (\n providerList.includes('orange') ||\n providerList.includes('orange_money') ||\n providerList.includes('orange-money')\n ) {\n lines.push(\n '# Orange Money Madagascar',\n 'ORANGE_CLIENT_ID=',\n 'ORANGE_CLIENT_SECRET=',\n 'ORANGE_MERCHANT_KEY=',\n 'ORANGE_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (\n providerList.includes('airtel') ||\n providerList.includes('airtel_money') ||\n providerList.includes('airtel-money')\n ) {\n lines.push(\n '# Airtel Money Madagascar',\n 'AIRTEL_CLIENT_ID=',\n 'AIRTEL_CLIENT_SECRET=',\n 'AIRTEL_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (providerList.includes('papi')) {\n lines.push('# PAPI Aggregator', 'PAPI_API_KEY=', 'PAPI_ENVIRONMENT=sandbox', '');\n }\n\n if (providerList.includes('fiveone')) {\n lines.push(\n '# FiveOne Aggregator',\n 'FIVEONE_API_KEY=',\n 'FIVEONE_SECRET_KEY=',\n 'FIVEONE_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (providerList.includes('alefa')) {\n lines.push(\n '# Alefa Aggregator',\n 'ALEFA_API_KEY=',\n 'ALEFA_SECRET_KEY=',\n 'ALEFA_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Ensures target directory .gitignore exists and includes .env to protect secrets.\n */\nexport function ensureGitignoreProtection(targetDir: string): boolean {\n const gitignorePath = path.join(targetDir, '.gitignore');\n let updated = false;\n\n if (fs.existsSync(gitignorePath)) {\n const existing = fs.readFileSync(gitignorePath, 'utf8');\n const lines = existing.split(/\\r?\\n/).map((l) => l.trim());\n const needed = ['.env', '.env.local', '.env.*.local'];\n const missing = needed.filter((item) => !lines.includes(item));\n\n if (missing.length > 0) {\n const appendContent = `\\n# MadaPay secrets protection\\n${missing.join('\\n')}\\n`;\n fs.appendFileSync(gitignorePath, appendContent, 'utf8');\n updated = true;\n }\n } else {\n const defaultGitignore = [\n '# MadaPay secrets protection',\n '.env',\n '.env.local',\n '.env.*.local',\n 'node_modules',\n 'dist',\n '',\n ].join('\\n');\n fs.writeFileSync(gitignorePath, defaultGitignore, 'utf8');\n updated = true;\n }\n\n return updated;\n}\n\n/**\n * Initializes MadaPay configuration in the specified directory.\n */\nexport function initProject(options: InitOptions = {}): InitResult {\n const targetDir = path.resolve(process.cwd(), options.directory || '.');\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n const providers =\n options.providers && options.providers.length > 0\n ? options.providers\n : ['mvola', 'orange_money', 'airtel_money', 'papi'];\n\n const envContent = generateEnvContent(providers);\n\n const envExamplePath = path.join(targetDir, '.env.example');\n const envPath = path.join(targetDir, '.env');\n const configPath = path.join(targetDir, 'madapay.config.json');\n\n let envExampleCreated = false;\n let envCreated = false;\n\n // Always write or overwrite .env.example\n fs.writeFileSync(envExamplePath, envContent, 'utf8');\n envExampleCreated = true;\n\n // Write .env only if it doesn't exist or if force is specified\n if (!fs.existsSync(envPath) || options.force) {\n fs.writeFileSync(envPath, envContent, 'utf8');\n envCreated = true;\n }\n\n // Ensure .gitignore protects secrets\n const gitignoreUpdated = ensureGitignoreProtection(targetDir);\n\n // Write madapay.config.json\n let configCreated = false;\n if (!fs.existsSync(configPath) || options.force) {\n const configData = {\n $schema: 'https://madapay.mg/schema/config.json',\n version: '0.1.0',\n framework: options.framework || 'fastify',\n storage: options.storage || 'postgres',\n providers,\n defaultCurrency: 'MGA',\n defaultLocale: 'fr',\n };\n fs.writeFileSync(configPath, JSON.stringify(configData, null, 2) + '\\n', 'utf8');\n configCreated = true;\n }\n\n return {\n envCreated,\n envExampleCreated,\n gitignoreUpdated,\n configCreated,\n targetDirectory: targetDir,\n };\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface InitOptions {
|
|
2
|
+
directory?: string;
|
|
3
|
+
framework?: 'fastify' | 'express' | 'next' | 'standalone';
|
|
4
|
+
providers?: string[];
|
|
5
|
+
storage?: 'postgres' | 'memory' | 'sqlite';
|
|
6
|
+
force?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface InitResult {
|
|
9
|
+
envCreated: boolean;
|
|
10
|
+
envExampleCreated: boolean;
|
|
11
|
+
gitignoreUpdated: boolean;
|
|
12
|
+
configCreated: boolean;
|
|
13
|
+
targetDirectory: string;
|
|
14
|
+
}
|
|
15
|
+
declare function generateEnvContent(providers: string[]): string;
|
|
16
|
+
/**
|
|
17
|
+
* Ensures target directory .gitignore exists and includes .env to protect secrets.
|
|
18
|
+
*/
|
|
19
|
+
declare function ensureGitignoreProtection(targetDir: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes MadaPay configuration in the specified directory.
|
|
22
|
+
*/
|
|
23
|
+
declare function initProject(options?: InitOptions): InitResult;
|
|
24
|
+
|
|
25
|
+
export { type InitOptions, type InitResult, ensureGitignoreProtection, generateEnvContent, initProject };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface InitOptions {
|
|
2
|
+
directory?: string;
|
|
3
|
+
framework?: 'fastify' | 'express' | 'next' | 'standalone';
|
|
4
|
+
providers?: string[];
|
|
5
|
+
storage?: 'postgres' | 'memory' | 'sqlite';
|
|
6
|
+
force?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface InitResult {
|
|
9
|
+
envCreated: boolean;
|
|
10
|
+
envExampleCreated: boolean;
|
|
11
|
+
gitignoreUpdated: boolean;
|
|
12
|
+
configCreated: boolean;
|
|
13
|
+
targetDirectory: string;
|
|
14
|
+
}
|
|
15
|
+
declare function generateEnvContent(providers: string[]): string;
|
|
16
|
+
/**
|
|
17
|
+
* Ensures target directory .gitignore exists and includes .env to protect secrets.
|
|
18
|
+
*/
|
|
19
|
+
declare function ensureGitignoreProtection(targetDir: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes MadaPay configuration in the specified directory.
|
|
22
|
+
*/
|
|
23
|
+
declare function initProject(options?: InitOptions): InitResult;
|
|
24
|
+
|
|
25
|
+
export { type InitOptions, type InitResult, ensureGitignoreProtection, generateEnvContent, initProject };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
// src/init.ts
|
|
5
|
+
function generateEnvContent(providers) {
|
|
6
|
+
const lines = [
|
|
7
|
+
"# MadaPay Merchant Environment Configuration",
|
|
8
|
+
"# All credentials MUST run strictly on your secure backend server.",
|
|
9
|
+
"# NEVER expose these credentials to client browsers or mobile devices.",
|
|
10
|
+
"",
|
|
11
|
+
"# Merchant Identity",
|
|
12
|
+
"MERCHANT_ID=",
|
|
13
|
+
"MERCHANT_API_KEY=",
|
|
14
|
+
"PORT=3000",
|
|
15
|
+
"",
|
|
16
|
+
"# Persistence & Database",
|
|
17
|
+
"DATABASE_URL=postgresql://postgres:postgres@localhost:5432/madapay",
|
|
18
|
+
""
|
|
19
|
+
];
|
|
20
|
+
const providerList = providers.map((p) => p.toLowerCase());
|
|
21
|
+
if (providerList.includes("mvola")) {
|
|
22
|
+
lines.push(
|
|
23
|
+
"# Telma MVola",
|
|
24
|
+
"MVOLA_CONSUMER_KEY=",
|
|
25
|
+
"MVOLA_CONSUMER_SECRET=",
|
|
26
|
+
"MVOLA_MERCHANT_NUMBER=",
|
|
27
|
+
"MVOLA_ENVIRONMENT=sandbox",
|
|
28
|
+
""
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
if (providerList.includes("orange") || providerList.includes("orange_money") || providerList.includes("orange-money")) {
|
|
32
|
+
lines.push(
|
|
33
|
+
"# Orange Money Madagascar",
|
|
34
|
+
"ORANGE_CLIENT_ID=",
|
|
35
|
+
"ORANGE_CLIENT_SECRET=",
|
|
36
|
+
"ORANGE_MERCHANT_KEY=",
|
|
37
|
+
"ORANGE_ENVIRONMENT=sandbox",
|
|
38
|
+
""
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
if (providerList.includes("airtel") || providerList.includes("airtel_money") || providerList.includes("airtel-money")) {
|
|
42
|
+
lines.push(
|
|
43
|
+
"# Airtel Money Madagascar",
|
|
44
|
+
"AIRTEL_CLIENT_ID=",
|
|
45
|
+
"AIRTEL_CLIENT_SECRET=",
|
|
46
|
+
"AIRTEL_ENVIRONMENT=sandbox",
|
|
47
|
+
""
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (providerList.includes("papi")) {
|
|
51
|
+
lines.push("# PAPI Aggregator", "PAPI_API_KEY=", "PAPI_ENVIRONMENT=sandbox", "");
|
|
52
|
+
}
|
|
53
|
+
if (providerList.includes("fiveone")) {
|
|
54
|
+
lines.push(
|
|
55
|
+
"# FiveOne Aggregator",
|
|
56
|
+
"FIVEONE_API_KEY=",
|
|
57
|
+
"FIVEONE_SECRET_KEY=",
|
|
58
|
+
"FIVEONE_ENVIRONMENT=sandbox",
|
|
59
|
+
""
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (providerList.includes("alefa")) {
|
|
63
|
+
lines.push(
|
|
64
|
+
"# Alefa Aggregator",
|
|
65
|
+
"ALEFA_API_KEY=",
|
|
66
|
+
"ALEFA_SECRET_KEY=",
|
|
67
|
+
"ALEFA_ENVIRONMENT=sandbox",
|
|
68
|
+
""
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return lines.join("\n");
|
|
72
|
+
}
|
|
73
|
+
function ensureGitignoreProtection(targetDir) {
|
|
74
|
+
const gitignorePath = path.join(targetDir, ".gitignore");
|
|
75
|
+
let updated = false;
|
|
76
|
+
if (fs.existsSync(gitignorePath)) {
|
|
77
|
+
const existing = fs.readFileSync(gitignorePath, "utf8");
|
|
78
|
+
const lines = existing.split(/\r?\n/).map((l) => l.trim());
|
|
79
|
+
const needed = [".env", ".env.local", ".env.*.local"];
|
|
80
|
+
const missing = needed.filter((item) => !lines.includes(item));
|
|
81
|
+
if (missing.length > 0) {
|
|
82
|
+
const appendContent = `
|
|
83
|
+
# MadaPay secrets protection
|
|
84
|
+
${missing.join("\n")}
|
|
85
|
+
`;
|
|
86
|
+
fs.appendFileSync(gitignorePath, appendContent, "utf8");
|
|
87
|
+
updated = true;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
const defaultGitignore = [
|
|
91
|
+
"# MadaPay secrets protection",
|
|
92
|
+
".env",
|
|
93
|
+
".env.local",
|
|
94
|
+
".env.*.local",
|
|
95
|
+
"node_modules",
|
|
96
|
+
"dist",
|
|
97
|
+
""
|
|
98
|
+
].join("\n");
|
|
99
|
+
fs.writeFileSync(gitignorePath, defaultGitignore, "utf8");
|
|
100
|
+
updated = true;
|
|
101
|
+
}
|
|
102
|
+
return updated;
|
|
103
|
+
}
|
|
104
|
+
function initProject(options = {}) {
|
|
105
|
+
const targetDir = path.resolve(process.cwd(), options.directory || ".");
|
|
106
|
+
if (!fs.existsSync(targetDir)) {
|
|
107
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
108
|
+
}
|
|
109
|
+
const providers = options.providers && options.providers.length > 0 ? options.providers : ["mvola", "orange_money", "airtel_money", "papi"];
|
|
110
|
+
const envContent = generateEnvContent(providers);
|
|
111
|
+
const envExamplePath = path.join(targetDir, ".env.example");
|
|
112
|
+
const envPath = path.join(targetDir, ".env");
|
|
113
|
+
const configPath = path.join(targetDir, "madapay.config.json");
|
|
114
|
+
let envExampleCreated = false;
|
|
115
|
+
let envCreated = false;
|
|
116
|
+
fs.writeFileSync(envExamplePath, envContent, "utf8");
|
|
117
|
+
envExampleCreated = true;
|
|
118
|
+
if (!fs.existsSync(envPath) || options.force) {
|
|
119
|
+
fs.writeFileSync(envPath, envContent, "utf8");
|
|
120
|
+
envCreated = true;
|
|
121
|
+
}
|
|
122
|
+
const gitignoreUpdated = ensureGitignoreProtection(targetDir);
|
|
123
|
+
let configCreated = false;
|
|
124
|
+
if (!fs.existsSync(configPath) || options.force) {
|
|
125
|
+
const configData = {
|
|
126
|
+
$schema: "https://madapay.mg/schema/config.json",
|
|
127
|
+
version: "0.1.0",
|
|
128
|
+
framework: options.framework || "fastify",
|
|
129
|
+
storage: options.storage || "postgres",
|
|
130
|
+
providers,
|
|
131
|
+
defaultCurrency: "MGA",
|
|
132
|
+
defaultLocale: "fr"
|
|
133
|
+
};
|
|
134
|
+
fs.writeFileSync(configPath, JSON.stringify(configData, null, 2) + "\n", "utf8");
|
|
135
|
+
configCreated = true;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
envCreated,
|
|
139
|
+
envExampleCreated,
|
|
140
|
+
gitignoreUpdated,
|
|
141
|
+
configCreated,
|
|
142
|
+
targetDirectory: targetDir
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { ensureGitignoreProtection, generateEnvContent, initProject };
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
148
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"names":[],"mappings":";;;;AAmBO,SAAS,mBAAmB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 'node:path';\n\nexport interface InitOptions {\n directory?: string;\n framework?: 'fastify' | 'express' | 'next' | 'standalone';\n providers?: string[];\n storage?: 'postgres' | 'memory' | 'sqlite';\n force?: boolean;\n}\n\nexport interface InitResult {\n envCreated: boolean;\n envExampleCreated: boolean;\n gitignoreUpdated: boolean;\n configCreated: boolean;\n targetDirectory: string;\n}\n\nexport function generateEnvContent(providers: string[]): string {\n const lines: string[] = [\n '# MadaPay Merchant Environment Configuration',\n '# All credentials MUST run strictly on your secure backend server.',\n '# NEVER expose these credentials to client browsers or mobile devices.',\n '',\n '# Merchant Identity',\n 'MERCHANT_ID=',\n 'MERCHANT_API_KEY=',\n 'PORT=3000',\n '',\n '# Persistence & Database',\n 'DATABASE_URL=postgresql://postgres:postgres@localhost:5432/madapay',\n '',\n ];\n\n const providerList = providers.map((p) => p.toLowerCase());\n\n if (providerList.includes('mvola')) {\n lines.push(\n '# Telma MVola',\n 'MVOLA_CONSUMER_KEY=',\n 'MVOLA_CONSUMER_SECRET=',\n 'MVOLA_MERCHANT_NUMBER=',\n 'MVOLA_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (\n providerList.includes('orange') ||\n providerList.includes('orange_money') ||\n providerList.includes('orange-money')\n ) {\n lines.push(\n '# Orange Money Madagascar',\n 'ORANGE_CLIENT_ID=',\n 'ORANGE_CLIENT_SECRET=',\n 'ORANGE_MERCHANT_KEY=',\n 'ORANGE_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (\n providerList.includes('airtel') ||\n providerList.includes('airtel_money') ||\n providerList.includes('airtel-money')\n ) {\n lines.push(\n '# Airtel Money Madagascar',\n 'AIRTEL_CLIENT_ID=',\n 'AIRTEL_CLIENT_SECRET=',\n 'AIRTEL_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (providerList.includes('papi')) {\n lines.push('# PAPI Aggregator', 'PAPI_API_KEY=', 'PAPI_ENVIRONMENT=sandbox', '');\n }\n\n if (providerList.includes('fiveone')) {\n lines.push(\n '# FiveOne Aggregator',\n 'FIVEONE_API_KEY=',\n 'FIVEONE_SECRET_KEY=',\n 'FIVEONE_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n if (providerList.includes('alefa')) {\n lines.push(\n '# Alefa Aggregator',\n 'ALEFA_API_KEY=',\n 'ALEFA_SECRET_KEY=',\n 'ALEFA_ENVIRONMENT=sandbox',\n '',\n );\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Ensures target directory .gitignore exists and includes .env to protect secrets.\n */\nexport function ensureGitignoreProtection(targetDir: string): boolean {\n const gitignorePath = path.join(targetDir, '.gitignore');\n let updated = false;\n\n if (fs.existsSync(gitignorePath)) {\n const existing = fs.readFileSync(gitignorePath, 'utf8');\n const lines = existing.split(/\\r?\\n/).map((l) => l.trim());\n const needed = ['.env', '.env.local', '.env.*.local'];\n const missing = needed.filter((item) => !lines.includes(item));\n\n if (missing.length > 0) {\n const appendContent = `\\n# MadaPay secrets protection\\n${missing.join('\\n')}\\n`;\n fs.appendFileSync(gitignorePath, appendContent, 'utf8');\n updated = true;\n }\n } else {\n const defaultGitignore = [\n '# MadaPay secrets protection',\n '.env',\n '.env.local',\n '.env.*.local',\n 'node_modules',\n 'dist',\n '',\n ].join('\\n');\n fs.writeFileSync(gitignorePath, defaultGitignore, 'utf8');\n updated = true;\n }\n\n return updated;\n}\n\n/**\n * Initializes MadaPay configuration in the specified directory.\n */\nexport function initProject(options: InitOptions = {}): InitResult {\n const targetDir = path.resolve(process.cwd(), options.directory || '.');\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n const providers =\n options.providers && options.providers.length > 0\n ? options.providers\n : ['mvola', 'orange_money', 'airtel_money', 'papi'];\n\n const envContent = generateEnvContent(providers);\n\n const envExamplePath = path.join(targetDir, '.env.example');\n const envPath = path.join(targetDir, '.env');\n const configPath = path.join(targetDir, 'madapay.config.json');\n\n let envExampleCreated = false;\n let envCreated = false;\n\n // Always write or overwrite .env.example\n fs.writeFileSync(envExamplePath, envContent, 'utf8');\n envExampleCreated = true;\n\n // Write .env only if it doesn't exist or if force is specified\n if (!fs.existsSync(envPath) || options.force) {\n fs.writeFileSync(envPath, envContent, 'utf8');\n envCreated = true;\n }\n\n // Ensure .gitignore protects secrets\n const gitignoreUpdated = ensureGitignoreProtection(targetDir);\n\n // Write madapay.config.json\n let configCreated = false;\n if (!fs.existsSync(configPath) || options.force) {\n const configData = {\n $schema: 'https://madapay.mg/schema/config.json',\n version: '0.1.0',\n framework: options.framework || 'fastify',\n storage: options.storage || 'postgres',\n providers,\n defaultCurrency: 'MGA',\n defaultLocale: 'fr',\n };\n fs.writeFileSync(configPath, JSON.stringify(configData, null, 2) + '\\n', 'utf8');\n configCreated = true;\n }\n\n return {\n envCreated,\n envExampleCreated,\n gitignoreUpdated,\n configCreated,\n targetDirectory: targetDir,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@madapay/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Command-line tool for scaffolding and configuring MadaPay projects",
|
|
5
|
+
"author": "MadaPay Contributors",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"madapay": "./dist/bin.js"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": {
|
|
17
|
+
"import": "./dist/index.d.ts",
|
|
18
|
+
"require": "./dist/index.d.cts"
|
|
19
|
+
},
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/maheryAlucard/mada-pay.git",
|
|
35
|
+
"directory": "packages/cli"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"commander": "^12.1.0",
|
|
39
|
+
"@madapay/core": "0.1.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^22.13.10",
|
|
43
|
+
"tsup": "^8.4.0",
|
|
44
|
+
"typescript": "^5.8.2",
|
|
45
|
+
"vitest": "^3.0.7"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsup",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"lint": "eslint src"
|
|
52
|
+
}
|
|
6
53
|
}
|