recurrente-js 1.0.3 → 1.0.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.
- package/dist/scripts/generate-context.cjs +152 -0
- package/dist/scripts/generate-context.d.cts +1 -0
- package/dist/{api → src/api}/recurrente-webhooks.js +0 -6
- package/dist/{api → src/api}/recurrente.d.ts +1 -12
- package/dist/{api → src/api}/recurrente.js +20 -43
- package/dist/src/config/axiosInstance.d.ts +8 -0
- package/dist/src/config/axiosInstance.js +48 -0
- package/dist/{types → src/types}/globals.d.ts +54 -0
- package/package.json +3 -2
- package/dist/config/axiosInstance.d.ts +0 -3
- package/dist/config/axiosInstance.js +0 -65
- /package/dist/{api → src/api}/recurrente-webhooks.d.ts +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{index.js → src/index.js} +0 -0
- /package/dist/{types → src/types}/globals.js +0 -0
- /package/dist/{utils → src/utils}/conversion.d.ts +0 -0
- /package/dist/{utils → src/utils}/conversion.js +0 -0
- /package/dist/{webhooks.d.ts → src/webhooks.d.ts} +0 -0
- /package/dist/{webhooks.js → src/webhooks.js} +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
// --- Configuration ---
|
|
18
|
+
const OUTPUT_DIR = "ai-context";
|
|
19
|
+
const ALLOWED_EXTENSIONS = [
|
|
20
|
+
".ts",
|
|
21
|
+
".tsx",
|
|
22
|
+
".js",
|
|
23
|
+
".jsx",
|
|
24
|
+
".json",
|
|
25
|
+
".md",
|
|
26
|
+
".css",
|
|
27
|
+
".prisma",
|
|
28
|
+
".env.example",
|
|
29
|
+
".sql",
|
|
30
|
+
".gitignore",
|
|
31
|
+
];
|
|
32
|
+
// CORRECTED: This list is now for both files and directories.
|
|
33
|
+
const IGNORED_ITEMS = [
|
|
34
|
+
"node_modules",
|
|
35
|
+
".next",
|
|
36
|
+
".vercel",
|
|
37
|
+
"dist",
|
|
38
|
+
"build",
|
|
39
|
+
".git",
|
|
40
|
+
".cache",
|
|
41
|
+
"scripts",
|
|
42
|
+
"react-email-starter",
|
|
43
|
+
"package-lock.json", // This will now be correctly ignored
|
|
44
|
+
];
|
|
45
|
+
// --------------------
|
|
46
|
+
/**
|
|
47
|
+
* Recursively finds all files in a directory that match the allowed extensions.
|
|
48
|
+
*/
|
|
49
|
+
function getAllFiles(dirPath, arrayOfFiles = []) {
|
|
50
|
+
const items = node_fs_1.default.readdirSync(dirPath, { withFileTypes: true });
|
|
51
|
+
for (const item of items) {
|
|
52
|
+
// *** FIX: Check EVERY item (file or directory) against the ignore list first ***
|
|
53
|
+
if (IGNORED_ITEMS.includes(item.name)) {
|
|
54
|
+
continue; // Skip this item entirely
|
|
55
|
+
}
|
|
56
|
+
const fullPath = node_path_1.default.join(dirPath, item.name);
|
|
57
|
+
if (item.isDirectory()) {
|
|
58
|
+
// The ignore check is already done, so we just recurse.
|
|
59
|
+
getAllFiles(fullPath, arrayOfFiles);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// It's a file. The ignore check was already done.
|
|
63
|
+
// Now, we just check its extension.
|
|
64
|
+
if (ALLOWED_EXTENSIONS.includes(node_path_1.default.extname(item.name))) {
|
|
65
|
+
arrayOfFiles.push(fullPath);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return arrayOfFiles;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generates a timestamp string in the format YYYYMMDD_HHMMSS.
|
|
73
|
+
*/
|
|
74
|
+
function getFormattedTimestamp() {
|
|
75
|
+
const now = new Date();
|
|
76
|
+
const YYYY = now.getFullYear();
|
|
77
|
+
const MM = String(now.getMonth() + 1).padStart(2, "0");
|
|
78
|
+
const DD = String(now.getDate()).padStart(2, "0");
|
|
79
|
+
const HH = String(now.getHours()).padStart(2, "0");
|
|
80
|
+
const mm = String(now.getMinutes()).padStart(2, "0");
|
|
81
|
+
const ss = String(now.getSeconds()).padStart(2, "0");
|
|
82
|
+
return `${YYYY}${MM}${DD}_${HH}${mm}${ss}`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Main script logic.
|
|
86
|
+
*/
|
|
87
|
+
function main() {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const targetPath = process.argv[2];
|
|
90
|
+
if (!targetPath) {
|
|
91
|
+
console.error("❌ Error: Please provide a file or directory path as an argument.");
|
|
92
|
+
console.log(" Example: npm run context -- .");
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
const fullPath = node_path_1.default.resolve(targetPath);
|
|
96
|
+
if (!node_fs_1.default.existsSync(fullPath)) {
|
|
97
|
+
console.error(`❌ Error: Path not found: ${fullPath}`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
let filesToProcess = [];
|
|
101
|
+
const stats = node_fs_1.default.statSync(fullPath);
|
|
102
|
+
if (stats.isDirectory()) {
|
|
103
|
+
console.log(`🔎 Scanning directory: ${targetPath}`);
|
|
104
|
+
filesToProcess = getAllFiles(fullPath);
|
|
105
|
+
}
|
|
106
|
+
else if (stats.isFile()) {
|
|
107
|
+
// *** FIX: Also check if a single targeted file is on the ignore list ***
|
|
108
|
+
if (IGNORED_ITEMS.includes(node_path_1.default.basename(fullPath))) {
|
|
109
|
+
console.log(`🟡 File '${targetPath}' is in the ignore list. Exiting.`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
console.log(`🎯 Targeting single file: ${targetPath}`);
|
|
113
|
+
if (ALLOWED_EXTENSIONS.includes(node_path_1.default.extname(fullPath))) {
|
|
114
|
+
filesToProcess = [fullPath];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (filesToProcess.length === 0) {
|
|
118
|
+
console.log("🟡 No relevant files found to process. Exiting.");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
console.log(`📚 Found ${filesToProcess.length} file(s) to process.`);
|
|
122
|
+
const outputData = {
|
|
123
|
+
metadata: {
|
|
124
|
+
sourcePath: targetPath,
|
|
125
|
+
timestamp: new Date().toISOString(),
|
|
126
|
+
fileCount: filesToProcess.length,
|
|
127
|
+
},
|
|
128
|
+
files: {},
|
|
129
|
+
};
|
|
130
|
+
for (const file of filesToProcess) {
|
|
131
|
+
const relativePath = node_path_1.default.relative(process.cwd(), file);
|
|
132
|
+
try {
|
|
133
|
+
const content = node_fs_1.default.readFileSync(file, "utf-8");
|
|
134
|
+
outputData.files[relativePath] = content;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.warn(`⚠️ Could not read file: ${relativePath}`, error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Ensure the output directory exists
|
|
141
|
+
if (!node_fs_1.default.existsSync(OUTPUT_DIR)) {
|
|
142
|
+
node_fs_1.default.mkdirSync(OUTPUT_DIR);
|
|
143
|
+
}
|
|
144
|
+
const baseName = node_path_1.default.basename(targetPath).replace(/[.\\/]/g, "_");
|
|
145
|
+
const timestamp = getFormattedTimestamp();
|
|
146
|
+
const outputFilename = `context-${baseName}-${timestamp}.json`;
|
|
147
|
+
const outputFilePath = node_path_1.default.join(OUTPUT_DIR, outputFilename);
|
|
148
|
+
node_fs_1.default.writeFileSync(outputFilePath, JSON.stringify(outputData, null, 2));
|
|
149
|
+
console.log(`\n✅ Success! Context saved to: ${outputFilePath}`);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
main().catch(console.error);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.handleWebhookEvent = handleWebhookEvent;
|
|
7
4
|
exports.verifySvixSignature = verifySvixSignature;
|
|
8
5
|
exports.registerWebhookHandler = registerWebhookHandler;
|
|
9
6
|
const svix_1 = require("svix");
|
|
10
7
|
const conversion_1 = require("../utils/conversion");
|
|
11
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
12
|
-
// Load environment variables from .env file if they are not already set
|
|
13
|
-
dotenv_1.default.config();
|
|
14
8
|
/**
|
|
15
9
|
* A record to store the user-registered webhook handlers.
|
|
16
10
|
* Each event type is mapped to its corresponding handler function.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProductSubscription, CreateSubscriptionResponse, SubscriptionStatusResponse, CreateProductRequest, CreateProductResponse, GetProductResponse, GetAllProductsResponse, UpdateProductRequest
|
|
1
|
+
import { ProductSubscription, CreateSubscriptionResponse, SubscriptionStatusResponse, CreateProductRequest, CreateProductResponse, GetProductResponse, GetAllProductsResponse, UpdateProductRequest } from '../types/globals';
|
|
2
2
|
/**
|
|
3
3
|
* Recurrente API utility for managing product subscriptions, cancellations, and product deletions.
|
|
4
4
|
*
|
|
@@ -127,16 +127,5 @@ declare const recurrente: {
|
|
|
127
127
|
* @see getSubscription
|
|
128
128
|
*/
|
|
129
129
|
getSubscription: (subscriptionId: string) => Promise<SubscriptionStatusResponse>;
|
|
130
|
-
/**
|
|
131
|
-
* Creates a new checkout session.
|
|
132
|
-
*
|
|
133
|
-
* @function
|
|
134
|
-
* @memberof recurrente.checkouts
|
|
135
|
-
* @see createCheckout
|
|
136
|
-
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
137
|
-
* @returns {Promise<CreateCheckoutResponse>} A promise that resolves with the checkout ID and URL.
|
|
138
|
-
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
139
|
-
*/
|
|
140
|
-
createCheckout: (checkoutData: CreateCheckoutRequest) => Promise<CreateCheckoutResponse>;
|
|
141
130
|
};
|
|
142
131
|
export default recurrente;
|
|
@@ -13,30 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const axios_1 = __importDefault(require("axios"));
|
|
16
|
-
|
|
16
|
+
// CHANGED: We now import the factory function instead of the direct instance.
|
|
17
|
+
const axiosInstance_1 = require("../config/axiosInstance");
|
|
17
18
|
const conversion_1 = require("../utils/conversion");
|
|
18
|
-
// TODO: Implement namespaces
|
|
19
|
-
/**
|
|
20
|
-
* Creates a new checkout session.
|
|
21
|
-
*
|
|
22
|
-
* This function takes checkout data, including items (by product_id or details),
|
|
23
|
-
* converts it to snake_case, and sends it to the API to create a new checkout session.
|
|
24
|
-
* It returns the checkout ID and the URL for redirection.
|
|
25
|
-
*
|
|
26
|
-
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
27
|
-
* @returns {Promise<CreateCheckoutResponse>} The response containing the checkout ID and URL.
|
|
28
|
-
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
29
|
-
*/
|
|
30
|
-
const createCheckout = (checkoutData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
try {
|
|
32
|
-
const checkoutDataInSnakeCase = (0, conversion_1.toSnakeCase)(checkoutData);
|
|
33
|
-
const response = yield axiosInstance_1.default.post('/checkouts/', checkoutDataInSnakeCase);
|
|
34
|
-
return (0, conversion_1.toCamelCase)(response.data);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
throw handleAxiosError(error);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
19
|
/**
|
|
41
20
|
* Creates a new product with a one-time payment.
|
|
42
21
|
*
|
|
@@ -50,8 +29,9 @@ const createCheckout = (checkoutData) => __awaiter(void 0, void 0, void 0, funct
|
|
|
50
29
|
*/
|
|
51
30
|
const createProduct = (productData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
31
|
try {
|
|
32
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
53
33
|
const productDataInSnakeCase = (0, conversion_1.toSnakeCase)(productData);
|
|
54
|
-
const response = yield
|
|
34
|
+
const response = yield client.post('/products/', productDataInSnakeCase);
|
|
55
35
|
return (0, conversion_1.toCamelCase)(response.data); // Return the created product's details
|
|
56
36
|
}
|
|
57
37
|
catch (error) {
|
|
@@ -71,7 +51,8 @@ const createProduct = (productData) => __awaiter(void 0, void 0, void 0, functio
|
|
|
71
51
|
*/
|
|
72
52
|
const getProduct = (productId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
53
|
try {
|
|
74
|
-
const
|
|
54
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
55
|
+
const response = yield client.get(`/products/${productId}`);
|
|
75
56
|
return (0, conversion_1.toCamelCase)(response.data);
|
|
76
57
|
}
|
|
77
58
|
catch (error) {
|
|
@@ -91,7 +72,8 @@ const getProduct = (productId) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
91
72
|
*/
|
|
92
73
|
const getAllProducts = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (page = 1) {
|
|
93
74
|
try {
|
|
94
|
-
const
|
|
75
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
76
|
+
const response = yield client.get(`/products?page=${page}`);
|
|
95
77
|
return (0, conversion_1.toCamelCase)(response.data);
|
|
96
78
|
}
|
|
97
79
|
catch (error) {
|
|
@@ -112,8 +94,9 @@ const getAllProducts = (...args_1) => __awaiter(void 0, [...args_1], void 0, fun
|
|
|
112
94
|
*/
|
|
113
95
|
const updateProduct = (productId, productData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
96
|
try {
|
|
97
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
115
98
|
const productDataInSnakeCase = (0, conversion_1.toSnakeCase)(productData);
|
|
116
|
-
const response = yield
|
|
99
|
+
const response = yield client.patch(`/products/${productId}`, productDataInSnakeCase);
|
|
117
100
|
return (0, conversion_1.toCamelCase)(response.data); // Return the updated product's details
|
|
118
101
|
}
|
|
119
102
|
catch (error) {
|
|
@@ -133,8 +116,9 @@ const updateProduct = (productId, productData) => __awaiter(void 0, void 0, void
|
|
|
133
116
|
*/
|
|
134
117
|
const createSubscription = (productData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
118
|
try {
|
|
119
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
136
120
|
const productDataInSnakeCase = (0, conversion_1.toSnakeCase)(productData);
|
|
137
|
-
const response = yield
|
|
121
|
+
const response = yield client.post('/products/', productDataInSnakeCase);
|
|
138
122
|
return (0, conversion_1.toCamelCase)(response.data); // Return the success response only
|
|
139
123
|
}
|
|
140
124
|
catch (error) {
|
|
@@ -154,7 +138,8 @@ const createSubscription = (productData) => __awaiter(void 0, void 0, void 0, fu
|
|
|
154
138
|
*/
|
|
155
139
|
const cancelSubscription = (subscriptionId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
140
|
try {
|
|
157
|
-
const
|
|
141
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
142
|
+
const response = yield client.delete(`/subscriptions/${subscriptionId}`);
|
|
158
143
|
return {
|
|
159
144
|
message: `Subscription canceled successfully. Status: ${response.status}`,
|
|
160
145
|
};
|
|
@@ -175,7 +160,8 @@ const cancelSubscription = (subscriptionId) => __awaiter(void 0, void 0, void 0,
|
|
|
175
160
|
*/
|
|
176
161
|
const deleteProduct = (productId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
162
|
try {
|
|
178
|
-
|
|
163
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
164
|
+
yield client.delete(`/products/${productId}`);
|
|
179
165
|
return { message: 'Product deleted successfully' };
|
|
180
166
|
}
|
|
181
167
|
catch (error) {
|
|
@@ -194,7 +180,8 @@ const deleteProduct = (productId) => __awaiter(void 0, void 0, void 0, function*
|
|
|
194
180
|
*/
|
|
195
181
|
const getSubscription = (subscriptionId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
196
182
|
try {
|
|
197
|
-
const
|
|
183
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
184
|
+
const response = yield client.get(`/subscriptions/${subscriptionId}`);
|
|
198
185
|
return (0, conversion_1.toCamelCase)(response.data);
|
|
199
186
|
}
|
|
200
187
|
catch (error) {
|
|
@@ -242,7 +229,8 @@ function handleAxiosError(error) {
|
|
|
242
229
|
*/
|
|
243
230
|
const test = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
244
231
|
try {
|
|
245
|
-
const
|
|
232
|
+
const client = (0, axiosInstance_1.getClient)(); // <-- Get client instance at runtime
|
|
233
|
+
const response = yield client.get('/test');
|
|
246
234
|
return {
|
|
247
235
|
message: `Test request succeeded. Status: ${response.data.message}`,
|
|
248
236
|
};
|
|
@@ -373,16 +361,5 @@ const recurrente = {
|
|
|
373
361
|
* @see getSubscription
|
|
374
362
|
*/
|
|
375
363
|
getSubscription,
|
|
376
|
-
/**
|
|
377
|
-
* Creates a new checkout session.
|
|
378
|
-
*
|
|
379
|
-
* @function
|
|
380
|
-
* @memberof recurrente.checkouts
|
|
381
|
-
* @see createCheckout
|
|
382
|
-
* @param {CreateCheckoutRequest} checkoutData - The details for the checkout session.
|
|
383
|
-
* @returns {Promise<CreateCheckoutResponse>} A promise that resolves with the checkout ID and URL.
|
|
384
|
-
* @throws {ErrorResponse} Throws an error if the checkout creation fails.
|
|
385
|
-
*/
|
|
386
|
-
createCheckout,
|
|
387
364
|
};
|
|
388
365
|
exports.default = recurrente;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type AxiosInstance } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Factory function to get a configured Axios instance for Recurrente.
|
|
4
|
+
* It uses a singleton pattern to ensure the client is only created once per server instance.
|
|
5
|
+
* @returns {AxiosInstance} The configured Axios client.
|
|
6
|
+
* @throws {Error} If environment variables are missing AT RUNTIME.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getClient(): AxiosInstance;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getClient = getClient;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
// 1. This variable will hold our single client instance. It starts as null.
|
|
9
|
+
let _clientInstance = null;
|
|
10
|
+
/**
|
|
11
|
+
* Factory function to get a configured Axios instance for Recurrente.
|
|
12
|
+
* It uses a singleton pattern to ensure the client is only created once per server instance.
|
|
13
|
+
* @returns {AxiosInstance} The configured Axios client.
|
|
14
|
+
* @throws {Error} If environment variables are missing AT RUNTIME.
|
|
15
|
+
*/
|
|
16
|
+
function getClient() {
|
|
17
|
+
// 2. If the instance already exists, return it immediately.
|
|
18
|
+
if (_clientInstance) {
|
|
19
|
+
return _clientInstance;
|
|
20
|
+
}
|
|
21
|
+
// 3. If it doesn't exist, this is the first time the function is called.
|
|
22
|
+
// Now, and only now, do we read the environment variables.
|
|
23
|
+
const baseURL = process.env.RECURRENTE_BASE_URL;
|
|
24
|
+
const publicKey = process.env.RECURRENTE_PUBLIC_KEY;
|
|
25
|
+
const secretKey = process.env.RECURRENTE_SECRET_KEY;
|
|
26
|
+
// 4. Validate the secrets. This will throw a clear error at runtime if they are missing.
|
|
27
|
+
if (!baseURL) {
|
|
28
|
+
throw new Error('Missing Recurrente base URL at runtime. Check your environment variables.');
|
|
29
|
+
}
|
|
30
|
+
if (!publicKey) {
|
|
31
|
+
throw new Error('Missing Recurrente Public Key at runtime. Check your environment variables.');
|
|
32
|
+
}
|
|
33
|
+
if (!secretKey) {
|
|
34
|
+
throw new Error('Missing Recurrente Secret Key at runtime. Check your environment variables.');
|
|
35
|
+
}
|
|
36
|
+
// 5. Create the new Axios instance.
|
|
37
|
+
const client = axios_1.default.create({
|
|
38
|
+
baseURL: `${baseURL}/api`,
|
|
39
|
+
headers: {
|
|
40
|
+
'X-PUBLIC-KEY': publicKey,
|
|
41
|
+
'X-SECRET-KEY': secretKey,
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
// 6. Store the newly created instance in our private variable and return it.
|
|
46
|
+
_clientInstance = client;
|
|
47
|
+
return _clientInstance;
|
|
48
|
+
}
|
|
@@ -1333,3 +1333,57 @@ export type RecurrenteWebhookEvent = PaymentIntentSucceeded | PaymentIntentFaile
|
|
|
1333
1333
|
* @param event - The webhook event object.
|
|
1334
1334
|
*/
|
|
1335
1335
|
export type WebhookHandler<T> = (event: T) => void;
|
|
1336
|
+
/**
|
|
1337
|
+
* Represents the payload for creating a refund.
|
|
1338
|
+
*/
|
|
1339
|
+
export interface CreateRefundRequest {
|
|
1340
|
+
/**
|
|
1341
|
+
* The ID of the payment intent (`pa_...`) to be refunded.
|
|
1342
|
+
* @required
|
|
1343
|
+
*/
|
|
1344
|
+
paymentIntentId: string;
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Represents the response after successfully creating a refund.
|
|
1348
|
+
*/
|
|
1349
|
+
export interface CreateRefundResponse {
|
|
1350
|
+
/**
|
|
1351
|
+
* The unique identifier for the refund object (e.g., "re_...").
|
|
1352
|
+
* @required
|
|
1353
|
+
*/
|
|
1354
|
+
id: string;
|
|
1355
|
+
/**
|
|
1356
|
+
* The status of the refund.
|
|
1357
|
+
* @required
|
|
1358
|
+
*/
|
|
1359
|
+
status: 'succeeded' | 'pending' | 'failed';
|
|
1360
|
+
/**
|
|
1361
|
+
* The customer associated with the refunded payment.
|
|
1362
|
+
* @required
|
|
1363
|
+
*/
|
|
1364
|
+
customer: {
|
|
1365
|
+
id: string;
|
|
1366
|
+
email: string;
|
|
1367
|
+
fullName: string;
|
|
1368
|
+
};
|
|
1369
|
+
/**
|
|
1370
|
+
* The amount in cents that was refunded to your account balance.
|
|
1371
|
+
* @required
|
|
1372
|
+
*/
|
|
1373
|
+
accountRefundedAmountInCents: number;
|
|
1374
|
+
/**
|
|
1375
|
+
* The amount in cents that was refunded to the customer.
|
|
1376
|
+
* @required
|
|
1377
|
+
*/
|
|
1378
|
+
customerRefundedAmountInCents: number;
|
|
1379
|
+
/**
|
|
1380
|
+
* The currency of the refund.
|
|
1381
|
+
* @required
|
|
1382
|
+
*/
|
|
1383
|
+
currency: string;
|
|
1384
|
+
/**
|
|
1385
|
+
* The timestamp of when the refund was created.
|
|
1386
|
+
* @required
|
|
1387
|
+
*/
|
|
1388
|
+
createdAt: string;
|
|
1389
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "recurrente-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/globals.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"prepare": "npm.cmd run compile",
|
|
21
21
|
"pretest": "npm.cmd run compile",
|
|
22
22
|
"posttest": "npm.cmd run lint",
|
|
23
|
-
"dev": "nodemon -w *.ts -e ts -x ts-node --files -H -T ./src/index.ts"
|
|
23
|
+
"dev": "nodemon -w *.ts -e ts -x ts-node --files -H -T ./src/index.ts",
|
|
24
|
+
"context": "ts-node scripts/generate-context.cts"
|
|
24
25
|
},
|
|
25
26
|
"author": "Axel Aguilar",
|
|
26
27
|
"license": "MIT",
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const axios_1 = __importDefault(require("axios"));
|
|
40
|
-
const dotenv = __importStar(require("dotenv"));
|
|
41
|
-
// Load environment variables from .env file
|
|
42
|
-
dotenv.config();
|
|
43
|
-
const baseURL = process.env.RECURRENTE_BASE_URL;
|
|
44
|
-
const publicKey = process.env.RECURRENTE_PUBLIC_KEY;
|
|
45
|
-
const secretKey = process.env.RECURRENTE_SECRET_KEY;
|
|
46
|
-
if (!baseURL) {
|
|
47
|
-
throw new Error('Missing Recurrente base URL');
|
|
48
|
-
}
|
|
49
|
-
if (!publicKey) {
|
|
50
|
-
throw new Error('Missing Recurrente Public Key');
|
|
51
|
-
}
|
|
52
|
-
if (!secretKey) {
|
|
53
|
-
throw new Error('Missing Recurrente Secret Key');
|
|
54
|
-
}
|
|
55
|
-
// Create an Axios instance with configuration
|
|
56
|
-
const client = axios_1.default.create({
|
|
57
|
-
baseURL: `${baseURL}/api`,
|
|
58
|
-
headers: {
|
|
59
|
-
'X-PUBLIC-KEY': publicKey,
|
|
60
|
-
'X-SECRET-KEY': secretKey,
|
|
61
|
-
'Content-Type': 'application/json',
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
// Export the Axios instance for use in other parts of the package
|
|
65
|
-
exports.default = client;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|