@plural_pinelabs/mpp-seller-sdk 0.1.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 +1 -0
- package/dist/config/environments.d.ts +8 -0
- package/dist/config/environments.d.ts.map +1 -0
- package/dist/config/environments.js +11 -0
- package/dist/config/environments.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +8 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/generic.d.ts +29 -0
- package/dist/middleware/generic.d.ts.map +1 -0
- package/dist/middleware/generic.js +161 -0
- package/dist/middleware/generic.js.map +1 -0
- package/dist/middleware/index.d.ts +3 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +6 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/server/auth-manager.d.ts +19 -0
- package/dist/server/auth-manager.d.ts.map +1 -0
- package/dist/server/auth-manager.js +110 -0
- package/dist/server/auth-manager.js.map +1 -0
- package/dist/server/capture-client.d.ts +13 -0
- package/dist/server/capture-client.d.ts.map +1 -0
- package/dist/server/capture-client.js +134 -0
- package/dist/server/capture-client.js.map +1 -0
- package/dist/server/challenge-generator.d.ts +10 -0
- package/dist/server/challenge-generator.d.ts.map +1 -0
- package/dist/server/challenge-generator.js +60 -0
- package/dist/server/challenge-generator.js.map +1 -0
- package/dist/server/credential-verifier.d.ts +10 -0
- package/dist/server/credential-verifier.d.ts.map +1 -0
- package/dist/server/credential-verifier.js +142 -0
- package/dist/server/credential-verifier.js.map +1 -0
- package/dist/server/grant-token-verifier.d.ts +15 -0
- package/dist/server/grant-token-verifier.d.ts.map +1 -0
- package/dist/server/grant-token-verifier.js +155 -0
- package/dist/server/grant-token-verifier.js.map +1 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +22 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/plural-mpp.d.ts +26 -0
- package/dist/server/plural-mpp.d.ts.map +1 -0
- package/dist/server/plural-mpp.js +50 -0
- package/dist/server/plural-mpp.js.map +1 -0
- package/dist/server/receipt-builder.d.ts +5 -0
- package/dist/server/receipt-builder.d.ts.map +1 -0
- package/dist/server/receipt-builder.js +45 -0
- package/dist/server/receipt-builder.js.map +1 -0
- package/dist/types/auth.d.ts +12 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +3 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/capture.d.ts +51 -0
- package/dist/types/capture.d.ts.map +1 -0
- package/dist/types/capture.js +3 -0
- package/dist/types/capture.js.map +1 -0
- package/dist/types/challenge.d.ts +27 -0
- package/dist/types/challenge.d.ts.map +1 -0
- package/dist/types/challenge.js +3 -0
- package/dist/types/challenge.js.map +1 -0
- package/dist/types/config.d.ts +34 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +3 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/credential.d.ts +25 -0
- package/dist/types/credential.d.ts.map +1 -0
- package/dist/types/credential.js +3 -0
- package/dist/types/credential.js.map +1 -0
- package/dist/types/errors.d.ts +30 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +25 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/grantex.d.ts +27 -0
- package/dist/types/grantex.d.ts.map +1 -0
- package/dist/types/grantex.js +3 -0
- package/dist/types/grantex.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/base64url.d.ts +6 -0
- package/dist/utils/base64url.d.ts.map +1 -0
- package/dist/utils/base64url.js +25 -0
- package/dist/utils/base64url.js.map +1 -0
- package/dist/utils/errors.d.ts +16 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +46 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/fetch-helpers.d.ts +19 -0
- package/dist/utils/fetch-helpers.d.ts.map +1 -0
- package/dist/utils/fetch-helpers.js +108 -0
- package/dist/utils/fetch-helpers.js.map +1 -0
- package/dist/utils/hmac-sig.d.ts +3 -0
- package/dist/utils/hmac-sig.d.ts.map +1 -0
- package/dist/utils/hmac-sig.js +13 -0
- package/dist/utils/hmac-sig.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/validation.d.ts +3 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +27 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requestWithRetry = requestWithRetry;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
6
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
7
|
+
const DEFAULT_INITIAL_RETRY_DELAY_MS = 500;
|
|
8
|
+
function isRetriableStatus(status) {
|
|
9
|
+
return status === 429 || status >= 500;
|
|
10
|
+
}
|
|
11
|
+
function retryDelayMs(attempt, initial, headers) {
|
|
12
|
+
if (headers) {
|
|
13
|
+
const retryAfter = headers.get("Retry-After");
|
|
14
|
+
if (retryAfter) {
|
|
15
|
+
const seconds = parseFloat(retryAfter);
|
|
16
|
+
if (seconds > 0)
|
|
17
|
+
return Math.round(seconds * 1000);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const base = initial * 2 ** attempt;
|
|
21
|
+
const jitter = base * 0.25 * (Math.random() * 2 - 1);
|
|
22
|
+
return Math.max(0, Math.round(base + jitter));
|
|
23
|
+
}
|
|
24
|
+
function sleep(ms) {
|
|
25
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
26
|
+
}
|
|
27
|
+
async function requestWithRetry(opts) {
|
|
28
|
+
const effectiveTimeout = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
29
|
+
const effectiveMax = opts.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
30
|
+
const effectiveInitial = opts.initialRetryDelayMs ?? DEFAULT_INITIAL_RETRY_DELAY_MS;
|
|
31
|
+
const requestId = (0, node_crypto_1.randomUUID)();
|
|
32
|
+
const reqHeaders = { ...opts.headers };
|
|
33
|
+
reqHeaders["X-Request-Id"] ??= requestId;
|
|
34
|
+
let lastError = null;
|
|
35
|
+
for (let attempt = 0; attempt <= effectiveMax; attempt++) {
|
|
36
|
+
const isRetry = attempt > 0;
|
|
37
|
+
const start = Date.now();
|
|
38
|
+
if (opts.logger) {
|
|
39
|
+
try {
|
|
40
|
+
if (isRetry) {
|
|
41
|
+
opts.logger.info(`↻ ${opts.method} ${opts.url} retry ${attempt}/${effectiveMax}`, { attempt, requestId });
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
opts.logger.debug(`→ ${opts.method} ${opts.url}`, {
|
|
45
|
+
timeoutMs: effectiveTimeout,
|
|
46
|
+
requestId,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// logger failure is non-fatal
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
const timer = setTimeout(() => controller.abort(), effectiveTimeout);
|
|
57
|
+
const response = await fetch(opts.url, {
|
|
58
|
+
method: opts.method,
|
|
59
|
+
headers: reqHeaders,
|
|
60
|
+
body: opts.body,
|
|
61
|
+
signal: controller.signal,
|
|
62
|
+
});
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
const durationMs = Date.now() - start;
|
|
65
|
+
if (isRetriableStatus(response.status) && attempt < effectiveMax) {
|
|
66
|
+
const delay = retryDelayMs(attempt, effectiveInitial, response.headers);
|
|
67
|
+
if (opts.logger) {
|
|
68
|
+
try {
|
|
69
|
+
opts.logger.info(`← ${opts.method} ${opts.url} ${response.status} (retriable, waiting ${delay}ms)`, { durationMs, retryInMs: delay });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// non-fatal
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
await sleep(delay);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (opts.logger) {
|
|
79
|
+
try {
|
|
80
|
+
opts.logger.debug(`← ${opts.method} ${opts.url} ${response.status}`, { durationMs, requestId });
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// non-fatal
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return response;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
lastError = err;
|
|
90
|
+
const durationMs = Date.now() - start;
|
|
91
|
+
if (attempt < effectiveMax) {
|
|
92
|
+
const delay = retryDelayMs(attempt, effectiveInitial, null);
|
|
93
|
+
if (opts.logger) {
|
|
94
|
+
try {
|
|
95
|
+
opts.logger.info(`✗ ${opts.method} ${opts.url} (error, waiting ${delay}ms)`, { durationMs, retryInMs: delay, error: String(err) });
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// non-fatal
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
await sleep(delay);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
throw lastError ?? new Error(`Request failed after ${effectiveMax + 1} attempts`);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=fetch-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-helpers.js","sourceRoot":"","sources":["../../src/utils/fetch-helpers.ts"],"names":[],"mappings":";;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,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;YAEtC,IAAI,OAAO,GAAG,YAAY,EAAE,CAAC;gBAC3B,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;gBAC5D,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;oBAChB,IAAI,CAAC;wBACH,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,KAAK,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,oBAAoB,KAAK,KAAK,EAC1D,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CACrD,CAAC;oBACJ,CAAC;oBAAC,MAAM,CAAC;wBACP,YAAY;oBACd,CAAC;gBACH,CAAC;gBACD,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;gBACnB,SAAS;YACX,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,wBAAwB,YAAY,GAAG,CAAC,WAAW,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function computeHmacSha256(key: string, data: string): string;
|
|
2
|
+
export declare function computeChallengeId(secretKey: string, realm: string, method: string, intent: string, requestBase64: string, expires: string): string;
|
|
3
|
+
//# sourceMappingURL=hmac-sig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac-sig.d.ts","sourceRoot":"","sources":["../../src/utils/hmac-sig.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,MAAM,CAGR"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeHmacSha256 = computeHmacSha256;
|
|
4
|
+
exports.computeChallengeId = computeChallengeId;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
function computeHmacSha256(key, data) {
|
|
7
|
+
return (0, node_crypto_1.createHmac)("sha256", key).update(data).digest("hex");
|
|
8
|
+
}
|
|
9
|
+
function computeChallengeId(secretKey, realm, method, intent, requestBase64, expires) {
|
|
10
|
+
const payload = `${realm}|${method}|${intent}|${requestBase64}|${expires}`;
|
|
11
|
+
return `ch_${computeHmacSha256(secretKey, payload)}`;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=hmac-sig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac-sig.js","sourceRoot":"","sources":["../../src/utils/hmac-sig.ts"],"names":[],"mappings":";;AAEA,8CAEC;AAED,gDAUC;AAhBD,6CAAyC;AAEzC,SAAgB,iBAAiB,CAAC,GAAW,EAAE,IAAY;IACzD,OAAO,IAAA,wBAAU,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED,SAAgB,kBAAkB,CAChC,SAAiB,EACjB,KAAa,EACb,MAAc,EACd,MAAc,EACd,aAAqB,EACrB,OAAe;IAEf,MAAM,OAAO,GAAG,GAAG,KAAK,IAAI,MAAM,IAAI,MAAM,IAAI,aAAa,IAAI,OAAO,EAAE,CAAC;IAC3E,OAAO,MAAM,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { MppError, MppCaptureError, MppVerificationError } from "./errors.js";
|
|
2
|
+
export { encode, decode, encodeJson, decodeJson, isBase64Url } from "./base64url.js";
|
|
3
|
+
export { computeHmacSha256, computeChallengeId } from "./hmac-sig.js";
|
|
4
|
+
export { requestWithRetry } from "./fetch-helpers.js";
|
|
5
|
+
export type { RequestWithRetryOptions, FetchResponse } from "./fetch-helpers.js";
|
|
6
|
+
export { validateConfig } from "./validation.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateConfig = exports.requestWithRetry = exports.computeChallengeId = exports.computeHmacSha256 = exports.isBase64Url = exports.decodeJson = exports.encodeJson = exports.decode = exports.encode = exports.MppVerificationError = exports.MppCaptureError = exports.MppError = void 0;
|
|
4
|
+
var errors_js_1 = require("./errors.js");
|
|
5
|
+
Object.defineProperty(exports, "MppError", { enumerable: true, get: function () { return errors_js_1.MppError; } });
|
|
6
|
+
Object.defineProperty(exports, "MppCaptureError", { enumerable: true, get: function () { return errors_js_1.MppCaptureError; } });
|
|
7
|
+
Object.defineProperty(exports, "MppVerificationError", { enumerable: true, get: function () { return errors_js_1.MppVerificationError; } });
|
|
8
|
+
var base64url_js_1 = require("./base64url.js");
|
|
9
|
+
Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return base64url_js_1.encode; } });
|
|
10
|
+
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return base64url_js_1.decode; } });
|
|
11
|
+
Object.defineProperty(exports, "encodeJson", { enumerable: true, get: function () { return base64url_js_1.encodeJson; } });
|
|
12
|
+
Object.defineProperty(exports, "decodeJson", { enumerable: true, get: function () { return base64url_js_1.decodeJson; } });
|
|
13
|
+
Object.defineProperty(exports, "isBase64Url", { enumerable: true, get: function () { return base64url_js_1.isBase64Url; } });
|
|
14
|
+
var hmac_sig_js_1 = require("./hmac-sig.js");
|
|
15
|
+
Object.defineProperty(exports, "computeHmacSha256", { enumerable: true, get: function () { return hmac_sig_js_1.computeHmacSha256; } });
|
|
16
|
+
Object.defineProperty(exports, "computeChallengeId", { enumerable: true, get: function () { return hmac_sig_js_1.computeChallengeId; } });
|
|
17
|
+
var fetch_helpers_js_1 = require("./fetch-helpers.js");
|
|
18
|
+
Object.defineProperty(exports, "requestWithRetry", { enumerable: true, get: function () { return fetch_helpers_js_1.requestWithRetry; } });
|
|
19
|
+
var validation_js_1 = require("./validation.js");
|
|
20
|
+
Object.defineProperty(exports, "validateConfig", { enumerable: true, get: function () { return validation_js_1.validateConfig; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,yCAA8E;AAArE,qGAAA,QAAQ,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,iHAAA,oBAAoB,OAAA;AACxD,+CAAqF;AAA5E,sGAAA,MAAM,OAAA;AAAE,sGAAA,MAAM,OAAA;AAAE,0GAAA,UAAU,OAAA;AAAE,0GAAA,UAAU,OAAA;AAAE,2GAAA,WAAW,OAAA;AAC5D,6CAAsE;AAA7D,gHAAA,iBAAiB,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAC9C,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AAEzB,iDAAiD;AAAxC,+GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAwB/D"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateConfig = validateConfig;
|
|
4
|
+
function validateConfig(config) {
|
|
5
|
+
if (!config.clientId || typeof config.clientId !== "string") {
|
|
6
|
+
throw new Error("PluralSellerConfig: clientId is required and must be a non-empty string");
|
|
7
|
+
}
|
|
8
|
+
if (!config.clientSecret || typeof config.clientSecret !== "string") {
|
|
9
|
+
throw new Error("PluralSellerConfig: clientSecret is required and must be a non-empty string");
|
|
10
|
+
}
|
|
11
|
+
if (!config.challengeSecretKey || typeof config.challengeSecretKey !== "string") {
|
|
12
|
+
throw new Error("PluralSellerConfig: challengeSecretKey is required and must be a non-empty string");
|
|
13
|
+
}
|
|
14
|
+
if (config.baseUrl != null && typeof config.baseUrl !== "string") {
|
|
15
|
+
throw new Error("PluralSellerConfig: baseUrl must be a string");
|
|
16
|
+
}
|
|
17
|
+
if (config.requestTimeoutMs != null && (typeof config.requestTimeoutMs !== "number" || config.requestTimeoutMs <= 0)) {
|
|
18
|
+
throw new Error("PluralSellerConfig: requestTimeoutMs must be a positive number");
|
|
19
|
+
}
|
|
20
|
+
if (config.maxRetries != null && (typeof config.maxRetries !== "number" || config.maxRetries < 0)) {
|
|
21
|
+
throw new Error("PluralSellerConfig: maxRetries must be a non-negative number");
|
|
22
|
+
}
|
|
23
|
+
if (config.initialRetryDelayMs != null && (typeof config.initialRetryDelayMs !== "number" || config.initialRetryDelayMs <= 0)) {
|
|
24
|
+
throw new Error("PluralSellerConfig: initialRetryDelayMs must be a positive number");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;AAEA,wCAwBC;AAxBD,SAAgB,cAAc,CAAC,MAA0B;IACvD,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC7F,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IACjG,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,kBAAkB,IAAI,OAAO,MAAM,CAAC,kBAAkB,KAAK,QAAQ,EAAE,CAAC;QAChF,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,MAAM,CAAC,gBAAgB,IAAI,IAAI,IAAI,CAAC,OAAO,MAAM,CAAC,gBAAgB,KAAK,QAAQ,IAAI,MAAM,CAAC,gBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC;QACrH,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACpF,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,IAAI,IAAI,IAAI,CAAC,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC;QAClG,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,MAAM,CAAC,mBAAmB,IAAI,IAAI,IAAI,CAAC,OAAO,MAAM,CAAC,mBAAmB,KAAK,QAAQ,IAAI,MAAM,CAAC,mBAAmB,IAAI,CAAC,CAAC,EAAE,CAAC;QAC9H,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plural_pinelabs/mpp-seller-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Plural MPP Seller SDK — x402 Machine Payments Protocol server middleware (TypeScript)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"clean": "rm -rf dist",
|
|
11
|
+
"prepublishOnly": "npm run build",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"test:watch": "vitest"
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["mpp", "x402", "payment", "seller", "plural", "upi", "sbmd", "machine-payments"],
|
|
16
|
+
"author": "Plural",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"jose": "^5.2.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^20.11.0",
|
|
23
|
+
"typescript": "^5.3.0",
|
|
24
|
+
"vitest": "^1.2.0"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|