@marginfront/sdk 0.1.1 → 0.2.0
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/README.md +2 -2
- package/dist/{chunk-UIM2U5MX.mjs → chunk-V74ZGXDQ.mjs} +6 -4
- package/dist/cli/index.js +75 -7
- package/dist/cli/index.mjs +70 -4
- package/dist/index.js +6 -4
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -336,7 +336,7 @@ mf verify [options]
|
|
|
336
336
|
|
|
337
337
|
Options:
|
|
338
338
|
--api-key <key> API key (mf_sk_* or mf_pk_*)
|
|
339
|
-
--base-url <url> API base URL (default: https://api.
|
|
339
|
+
--base-url <url> API base URL (default: https://api.marginfront.com/v1)
|
|
340
340
|
--debug Enable debug output
|
|
341
341
|
```
|
|
342
342
|
|
|
@@ -349,7 +349,7 @@ mf track-event [options]
|
|
|
349
349
|
|
|
350
350
|
Options:
|
|
351
351
|
--api-key <key> API key (mf_sk_*)
|
|
352
|
-
--base-url <url> API base URL (default: https://api.
|
|
352
|
+
--base-url <url> API base URL (default: https://api.marginfront.com/v1)
|
|
353
353
|
--customer-id <id> Customer external ID
|
|
354
354
|
--agent-id <id> Agent UUID
|
|
355
355
|
--signal <name> Signal name (e.g. CALL_MINUTES)
|
|
@@ -128,8 +128,10 @@ function parseApiError(error) {
|
|
|
128
128
|
const err = error;
|
|
129
129
|
const message = err.message || "Unknown error";
|
|
130
130
|
const statusCode = err.response?.status;
|
|
131
|
-
const
|
|
131
|
+
const rawData = err.response?.data;
|
|
132
|
+
const responseData = rawData && typeof rawData === "object" && !Array.isArray(rawData) ? rawData : {};
|
|
132
133
|
const requestId = err.config?.headers?.["X-Request-ID"] || "unknown";
|
|
134
|
+
const safeString = (v) => typeof v === "string" && v.length > 0 ? v : void 0;
|
|
133
135
|
const metadata = {
|
|
134
136
|
requestId,
|
|
135
137
|
url: err.config?.url,
|
|
@@ -145,8 +147,8 @@ function parseApiError(error) {
|
|
|
145
147
|
}
|
|
146
148
|
return createErrorFromResponse(
|
|
147
149
|
statusCode,
|
|
148
|
-
responseData
|
|
149
|
-
responseData
|
|
150
|
+
safeString(responseData["message"]) ?? safeString(responseData["error"]) ?? message,
|
|
151
|
+
responseData["errors"],
|
|
150
152
|
metadata
|
|
151
153
|
);
|
|
152
154
|
}
|
|
@@ -234,7 +236,7 @@ function validateApiKey(apiKey) {
|
|
|
234
236
|
|
|
235
237
|
// src/utils/http.ts
|
|
236
238
|
import axios from "axios";
|
|
237
|
-
var DEFAULT_BASE_URL = "https://api
|
|
239
|
+
var DEFAULT_BASE_URL = "https://api.marginfront.com/v1";
|
|
238
240
|
var DEFAULT_TIMEOUT = 3e4;
|
|
239
241
|
var DEFAULT_RETRIES = 0;
|
|
240
242
|
var DEFAULT_RETRY_DELAY = 300;
|
package/dist/cli/index.js
CHANGED
|
@@ -162,8 +162,10 @@ function parseApiError(error) {
|
|
|
162
162
|
const err = error;
|
|
163
163
|
const message = err.message || "Unknown error";
|
|
164
164
|
const statusCode = err.response?.status;
|
|
165
|
-
const
|
|
165
|
+
const rawData = err.response?.data;
|
|
166
|
+
const responseData = rawData && typeof rawData === "object" && !Array.isArray(rawData) ? rawData : {};
|
|
166
167
|
const requestId = err.config?.headers?.["X-Request-ID"] || "unknown";
|
|
168
|
+
const safeString = (v) => typeof v === "string" && v.length > 0 ? v : void 0;
|
|
167
169
|
const metadata = {
|
|
168
170
|
requestId,
|
|
169
171
|
url: err.config?.url,
|
|
@@ -179,14 +181,14 @@ function parseApiError(error) {
|
|
|
179
181
|
}
|
|
180
182
|
return createErrorFromResponse(
|
|
181
183
|
statusCode,
|
|
182
|
-
responseData
|
|
183
|
-
responseData
|
|
184
|
+
safeString(responseData["message"]) ?? safeString(responseData["error"]) ?? message,
|
|
185
|
+
responseData["errors"],
|
|
184
186
|
metadata
|
|
185
187
|
);
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
// src/utils/http.ts
|
|
189
|
-
var DEFAULT_BASE_URL = "https://api
|
|
191
|
+
var DEFAULT_BASE_URL = "https://api.marginfront.com/v1";
|
|
190
192
|
var DEFAULT_TIMEOUT = 3e4;
|
|
191
193
|
var DEFAULT_RETRIES = 0;
|
|
192
194
|
var DEFAULT_RETRY_DELAY = 300;
|
|
@@ -1317,7 +1319,7 @@ function loadCliEnv() {
|
|
|
1317
1319
|
|
|
1318
1320
|
// src/cli/commands/verify.ts
|
|
1319
1321
|
function verifyCommand() {
|
|
1320
|
-
return new import_commander.Command("verify").description("Verify an API key and display organization details").option("--api-key <key>", "API key (mf_sk_* or mf_pk_*)").option("--base-url <url>", "API base URL (default: https://api.
|
|
1322
|
+
return new import_commander.Command("verify").description("Verify an API key and display organization details").option("--api-key <key>", "API key (mf_sk_* or mf_pk_*)").option("--base-url <url>", "API base URL (default: https://api.marginfront.com/v1)").option("--debug", "Enable debug output").action(async (options) => {
|
|
1321
1323
|
const env = loadCliEnv();
|
|
1322
1324
|
const apiKey = options.apiKey ?? env["MF_API_KEY"];
|
|
1323
1325
|
const baseUrl = options.baseUrl ?? env["MF_BASE_URL"];
|
|
@@ -1346,7 +1348,7 @@ function verifyCommand() {
|
|
|
1346
1348
|
// src/cli/commands/track-event.ts
|
|
1347
1349
|
var import_commander2 = require("commander");
|
|
1348
1350
|
function trackEventCommand() {
|
|
1349
|
-
return new import_commander2.Command("track-event").description("Send a usage event to the MarginFront API").option("--api-key <key>", "API key (mf_sk_*)").option("--base-url <url>", "API base URL (default: https://api.
|
|
1351
|
+
return new import_commander2.Command("track-event").description("Send a usage event to the MarginFront API").option("--api-key <key>", "API key (mf_sk_*)").option("--base-url <url>", "API base URL (default: https://api.marginfront.com/v1)").option("--customer-id <id>", "Customer external ID").option("--agent-id <id>", "Agent UUID").option("--signal <name>", "Signal name (e.g. CALL_MINUTES)").option("--quantity <number>", "Quantity to record (default: 1)", "1").option("--metadata <json>", "Optional metadata as a JSON string").option("--debug", "Enable debug output").action(async (options) => {
|
|
1350
1352
|
const env = loadCliEnv();
|
|
1351
1353
|
const apiKey = options.apiKey ?? env["MF_API_KEY"];
|
|
1352
1354
|
const baseUrl = options.baseUrl ?? env["MF_BASE_URL"];
|
|
@@ -1397,12 +1399,78 @@ function trackEventCommand() {
|
|
|
1397
1399
|
});
|
|
1398
1400
|
}
|
|
1399
1401
|
|
|
1402
|
+
// package.json
|
|
1403
|
+
var package_default = {
|
|
1404
|
+
name: "@marginfront/sdk",
|
|
1405
|
+
version: "0.2.0",
|
|
1406
|
+
description: "Official Node.js SDK for MarginFront - usage-based billing, invoicing, and analytics",
|
|
1407
|
+
main: "dist/index.js",
|
|
1408
|
+
module: "dist/index.mjs",
|
|
1409
|
+
types: "dist/index.d.ts",
|
|
1410
|
+
exports: {
|
|
1411
|
+
".": {
|
|
1412
|
+
types: "./dist/index.d.ts",
|
|
1413
|
+
import: "./dist/index.mjs",
|
|
1414
|
+
require: "./dist/index.js"
|
|
1415
|
+
}
|
|
1416
|
+
},
|
|
1417
|
+
bin: {
|
|
1418
|
+
mf: "dist/cli/index.js"
|
|
1419
|
+
},
|
|
1420
|
+
files: [
|
|
1421
|
+
"dist"
|
|
1422
|
+
],
|
|
1423
|
+
scripts: {
|
|
1424
|
+
build: "tsup src/index.ts src/cli/index.ts --format cjs,esm --dts --clean",
|
|
1425
|
+
test: "vitest",
|
|
1426
|
+
lint: "eslint src/",
|
|
1427
|
+
prepublishOnly: "npm run build"
|
|
1428
|
+
},
|
|
1429
|
+
keywords: [
|
|
1430
|
+
"marginfront",
|
|
1431
|
+
"billing",
|
|
1432
|
+
"usage-based",
|
|
1433
|
+
"invoicing",
|
|
1434
|
+
"sdk",
|
|
1435
|
+
"api",
|
|
1436
|
+
"metering",
|
|
1437
|
+
"subscriptions"
|
|
1438
|
+
],
|
|
1439
|
+
author: "MarginFront",
|
|
1440
|
+
license: "MIT",
|
|
1441
|
+
repository: {
|
|
1442
|
+
type: "git",
|
|
1443
|
+
url: "https://github.com/Lowcountry-AI/platform",
|
|
1444
|
+
directory: "packages/sdk"
|
|
1445
|
+
},
|
|
1446
|
+
homepage: "https://marginfront.com",
|
|
1447
|
+
bugs: {
|
|
1448
|
+
url: "https://github.com/Lowcountry-AI/platform/issues"
|
|
1449
|
+
},
|
|
1450
|
+
engines: {
|
|
1451
|
+
node: ">=16.0.0"
|
|
1452
|
+
},
|
|
1453
|
+
dependencies: {
|
|
1454
|
+
axios: "^1.6.0",
|
|
1455
|
+
commander: "^12.0.0"
|
|
1456
|
+
},
|
|
1457
|
+
devDependencies: {
|
|
1458
|
+
"@types/node": "^20.0.0",
|
|
1459
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
1460
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
1461
|
+
eslint: "^8.57.1",
|
|
1462
|
+
tsup: "^8.0.0",
|
|
1463
|
+
typescript: "^5.3.0",
|
|
1464
|
+
vitest: "^1.0.0"
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
|
|
1400
1468
|
// src/cli/index.ts
|
|
1401
1469
|
var WARNING = `
|
|
1402
1470
|
\x1B[33m\u26A0\uFE0F CLI mode \u2014 for testing only.\x1B[0m
|
|
1403
1471
|
\x1B[33m .env.marginfront.cli is NOT used when the SDK is imported as a library.\x1B[0m
|
|
1404
1472
|
`;
|
|
1405
|
-
var program = new import_commander3.Command().name("mf").description("MarginFront SDK CLI (testing tool)").version(
|
|
1473
|
+
var program = new import_commander3.Command().name("mf").description("MarginFront SDK CLI (testing tool)").version(package_default.version).hook("preAction", () => {
|
|
1406
1474
|
console.log(WARNING);
|
|
1407
1475
|
});
|
|
1408
1476
|
program.addCommand(verifyCommand());
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
MarginFrontClient
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-V74ZGXDQ.mjs";
|
|
5
5
|
|
|
6
6
|
// src/cli/index.ts
|
|
7
7
|
import { Command as Command3 } from "commander";
|
|
@@ -35,7 +35,7 @@ function loadCliEnv() {
|
|
|
35
35
|
|
|
36
36
|
// src/cli/commands/verify.ts
|
|
37
37
|
function verifyCommand() {
|
|
38
|
-
return new Command("verify").description("Verify an API key and display organization details").option("--api-key <key>", "API key (mf_sk_* or mf_pk_*)").option("--base-url <url>", "API base URL (default: https://api.
|
|
38
|
+
return new Command("verify").description("Verify an API key and display organization details").option("--api-key <key>", "API key (mf_sk_* or mf_pk_*)").option("--base-url <url>", "API base URL (default: https://api.marginfront.com/v1)").option("--debug", "Enable debug output").action(async (options) => {
|
|
39
39
|
const env = loadCliEnv();
|
|
40
40
|
const apiKey = options.apiKey ?? env["MF_API_KEY"];
|
|
41
41
|
const baseUrl = options.baseUrl ?? env["MF_BASE_URL"];
|
|
@@ -64,7 +64,7 @@ function verifyCommand() {
|
|
|
64
64
|
// src/cli/commands/track-event.ts
|
|
65
65
|
import { Command as Command2 } from "commander";
|
|
66
66
|
function trackEventCommand() {
|
|
67
|
-
return new Command2("track-event").description("Send a usage event to the MarginFront API").option("--api-key <key>", "API key (mf_sk_*)").option("--base-url <url>", "API base URL (default: https://api.
|
|
67
|
+
return new Command2("track-event").description("Send a usage event to the MarginFront API").option("--api-key <key>", "API key (mf_sk_*)").option("--base-url <url>", "API base URL (default: https://api.marginfront.com/v1)").option("--customer-id <id>", "Customer external ID").option("--agent-id <id>", "Agent UUID").option("--signal <name>", "Signal name (e.g. CALL_MINUTES)").option("--quantity <number>", "Quantity to record (default: 1)", "1").option("--metadata <json>", "Optional metadata as a JSON string").option("--debug", "Enable debug output").action(async (options) => {
|
|
68
68
|
const env = loadCliEnv();
|
|
69
69
|
const apiKey = options.apiKey ?? env["MF_API_KEY"];
|
|
70
70
|
const baseUrl = options.baseUrl ?? env["MF_BASE_URL"];
|
|
@@ -115,12 +115,78 @@ function trackEventCommand() {
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
// package.json
|
|
119
|
+
var package_default = {
|
|
120
|
+
name: "@marginfront/sdk",
|
|
121
|
+
version: "0.2.0",
|
|
122
|
+
description: "Official Node.js SDK for MarginFront - usage-based billing, invoicing, and analytics",
|
|
123
|
+
main: "dist/index.js",
|
|
124
|
+
module: "dist/index.mjs",
|
|
125
|
+
types: "dist/index.d.ts",
|
|
126
|
+
exports: {
|
|
127
|
+
".": {
|
|
128
|
+
types: "./dist/index.d.ts",
|
|
129
|
+
import: "./dist/index.mjs",
|
|
130
|
+
require: "./dist/index.js"
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
bin: {
|
|
134
|
+
mf: "dist/cli/index.js"
|
|
135
|
+
},
|
|
136
|
+
files: [
|
|
137
|
+
"dist"
|
|
138
|
+
],
|
|
139
|
+
scripts: {
|
|
140
|
+
build: "tsup src/index.ts src/cli/index.ts --format cjs,esm --dts --clean",
|
|
141
|
+
test: "vitest",
|
|
142
|
+
lint: "eslint src/",
|
|
143
|
+
prepublishOnly: "npm run build"
|
|
144
|
+
},
|
|
145
|
+
keywords: [
|
|
146
|
+
"marginfront",
|
|
147
|
+
"billing",
|
|
148
|
+
"usage-based",
|
|
149
|
+
"invoicing",
|
|
150
|
+
"sdk",
|
|
151
|
+
"api",
|
|
152
|
+
"metering",
|
|
153
|
+
"subscriptions"
|
|
154
|
+
],
|
|
155
|
+
author: "MarginFront",
|
|
156
|
+
license: "MIT",
|
|
157
|
+
repository: {
|
|
158
|
+
type: "git",
|
|
159
|
+
url: "https://github.com/Lowcountry-AI/platform",
|
|
160
|
+
directory: "packages/sdk"
|
|
161
|
+
},
|
|
162
|
+
homepage: "https://marginfront.com",
|
|
163
|
+
bugs: {
|
|
164
|
+
url: "https://github.com/Lowcountry-AI/platform/issues"
|
|
165
|
+
},
|
|
166
|
+
engines: {
|
|
167
|
+
node: ">=16.0.0"
|
|
168
|
+
},
|
|
169
|
+
dependencies: {
|
|
170
|
+
axios: "^1.6.0",
|
|
171
|
+
commander: "^12.0.0"
|
|
172
|
+
},
|
|
173
|
+
devDependencies: {
|
|
174
|
+
"@types/node": "^20.0.0",
|
|
175
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
176
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
177
|
+
eslint: "^8.57.1",
|
|
178
|
+
tsup: "^8.0.0",
|
|
179
|
+
typescript: "^5.3.0",
|
|
180
|
+
vitest: "^1.0.0"
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
118
184
|
// src/cli/index.ts
|
|
119
185
|
var WARNING = `
|
|
120
186
|
\x1B[33m\u26A0\uFE0F CLI mode \u2014 for testing only.\x1B[0m
|
|
121
187
|
\x1B[33m .env.marginfront.cli is NOT used when the SDK is imported as a library.\x1B[0m
|
|
122
188
|
`;
|
|
123
|
-
var program = new Command3().name("mf").description("MarginFront SDK CLI (testing tool)").version(
|
|
189
|
+
var program = new Command3().name("mf").description("MarginFront SDK CLI (testing tool)").version(package_default.version).hook("preAction", () => {
|
|
124
190
|
console.log(WARNING);
|
|
125
191
|
});
|
|
126
192
|
program.addCommand(verifyCommand());
|
package/dist/index.js
CHANGED
|
@@ -184,8 +184,10 @@ function parseApiError(error) {
|
|
|
184
184
|
const err = error;
|
|
185
185
|
const message = err.message || "Unknown error";
|
|
186
186
|
const statusCode = err.response?.status;
|
|
187
|
-
const
|
|
187
|
+
const rawData = err.response?.data;
|
|
188
|
+
const responseData = rawData && typeof rawData === "object" && !Array.isArray(rawData) ? rawData : {};
|
|
188
189
|
const requestId = err.config?.headers?.["X-Request-ID"] || "unknown";
|
|
190
|
+
const safeString = (v) => typeof v === "string" && v.length > 0 ? v : void 0;
|
|
189
191
|
const metadata = {
|
|
190
192
|
requestId,
|
|
191
193
|
url: err.config?.url,
|
|
@@ -201,14 +203,14 @@ function parseApiError(error) {
|
|
|
201
203
|
}
|
|
202
204
|
return createErrorFromResponse(
|
|
203
205
|
statusCode,
|
|
204
|
-
responseData
|
|
205
|
-
responseData
|
|
206
|
+
safeString(responseData["message"]) ?? safeString(responseData["error"]) ?? message,
|
|
207
|
+
responseData["errors"],
|
|
206
208
|
metadata
|
|
207
209
|
);
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
// src/utils/http.ts
|
|
211
|
-
var DEFAULT_BASE_URL = "https://api
|
|
213
|
+
var DEFAULT_BASE_URL = "https://api.marginfront.com/v1";
|
|
212
214
|
var DEFAULT_TIMEOUT = 3e4;
|
|
213
215
|
var DEFAULT_RETRIES = 0;
|
|
214
216
|
var DEFAULT_RETRY_DELAY = 300;
|
package/dist/index.mjs
CHANGED