@solvapay/server 1.0.1-preview.3 → 1.0.1-preview.4
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 -1
- package/dist/edge.d.ts +511 -1347
- package/dist/edge.js +66 -15
- package/dist/index.cjs +67 -15
- package/dist/index.d.cts +514 -1347
- package/dist/index.d.ts +514 -1347
- package/dist/index.js +66 -15
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -163,6 +163,21 @@ function createSolvaPayClient(opts) {
|
|
|
163
163
|
}
|
|
164
164
|
return await res.json();
|
|
165
165
|
},
|
|
166
|
+
// PUT: /v1/sdk/products/{productRef}/mcp/plans
|
|
167
|
+
async configureMcpPlans(productRef, params) {
|
|
168
|
+
const url = `${base}/v1/sdk/products/${productRef}/mcp/plans`;
|
|
169
|
+
const res = await fetch(url, {
|
|
170
|
+
method: "PUT",
|
|
171
|
+
headers,
|
|
172
|
+
body: JSON.stringify(params)
|
|
173
|
+
});
|
|
174
|
+
if (!res.ok) {
|
|
175
|
+
const error = await res.text();
|
|
176
|
+
log(`\u274C API Error: ${res.status} - ${error}`);
|
|
177
|
+
throw new SolvaPayError(`Configure MCP plans failed (${res.status}): ${error}`);
|
|
178
|
+
}
|
|
179
|
+
return await res.json();
|
|
180
|
+
},
|
|
166
181
|
// DELETE: /v1/sdk/products/{productRef}
|
|
167
182
|
async deleteProduct(productRef) {
|
|
168
183
|
const url = `${base}/v1/sdk/products/${productRef}`;
|
|
@@ -561,6 +576,24 @@ var PaywallError = class extends Error {
|
|
|
561
576
|
this.name = "PaywallError";
|
|
562
577
|
}
|
|
563
578
|
};
|
|
579
|
+
function paywallErrorToClientPayload(error) {
|
|
580
|
+
const sc = error.structuredContent;
|
|
581
|
+
const base = {
|
|
582
|
+
success: false,
|
|
583
|
+
error: sc.kind === "activation_required" ? "Activation required" : "Payment required",
|
|
584
|
+
product: sc.product,
|
|
585
|
+
checkoutUrl: sc.checkoutUrl,
|
|
586
|
+
message: sc.message
|
|
587
|
+
};
|
|
588
|
+
if (sc.kind === "activation_required") {
|
|
589
|
+
base.kind = "activation_required";
|
|
590
|
+
if (sc.plans !== void 0) base.plans = sc.plans;
|
|
591
|
+
if (sc.balance !== void 0) base.balance = sc.balance;
|
|
592
|
+
if (sc.productDetails !== void 0) base.productDetails = sc.productDetails;
|
|
593
|
+
if (sc.confirmationUrl !== void 0) base.confirmationUrl = sc.confirmationUrl;
|
|
594
|
+
}
|
|
595
|
+
return base;
|
|
596
|
+
}
|
|
564
597
|
var sharedCustomerLookupDeduplicator = createRequestDeduplicator({
|
|
565
598
|
cacheTTL: 6e4,
|
|
566
599
|
// Cache results for 60 seconds (reduces API calls significantly)
|
|
@@ -620,6 +653,7 @@ var SolvaPayPaywall = class {
|
|
|
620
653
|
let withinLimits;
|
|
621
654
|
let remaining;
|
|
622
655
|
let checkoutUrl;
|
|
656
|
+
let lastLimitsCheck;
|
|
623
657
|
const hasFreshCachedLimits = cachedLimits && now - cachedLimits.timestamp < this.limitsCacheTTL;
|
|
624
658
|
if (hasFreshCachedLimits) {
|
|
625
659
|
checkoutUrl = cachedLimits.checkoutUrl;
|
|
@@ -646,6 +680,7 @@ var SolvaPayPaywall = class {
|
|
|
646
680
|
...configuredPlanRef ? { planRef: configuredPlanRef } : {},
|
|
647
681
|
meterName: usageType
|
|
648
682
|
});
|
|
683
|
+
lastLimitsCheck = limitsCheck;
|
|
649
684
|
withinLimits = limitsCheck.withinLimits;
|
|
650
685
|
remaining = limitsCheck.remaining;
|
|
651
686
|
checkoutUrl = limitsCheck.checkoutUrl;
|
|
@@ -674,6 +709,20 @@ var SolvaPayPaywall = class {
|
|
|
674
709
|
requestId,
|
|
675
710
|
latencyMs2
|
|
676
711
|
);
|
|
712
|
+
if (lastLimitsCheck?.activationRequired) {
|
|
713
|
+
const confirmationUrl = lastLimitsCheck.confirmationUrl;
|
|
714
|
+
const payCheckoutUrl = confirmationUrl || lastLimitsCheck.checkoutUrl || checkoutUrl || "";
|
|
715
|
+
throw new PaywallError("Activation required", {
|
|
716
|
+
kind: "activation_required",
|
|
717
|
+
product,
|
|
718
|
+
message: "Product activation is required before this tool can be used.",
|
|
719
|
+
checkoutUrl: payCheckoutUrl,
|
|
720
|
+
confirmationUrl,
|
|
721
|
+
plans: lastLimitsCheck.plans,
|
|
722
|
+
balance: lastLimitsCheck.balance,
|
|
723
|
+
productDetails: lastLimitsCheck.product
|
|
724
|
+
});
|
|
725
|
+
}
|
|
677
726
|
throw new PaywallError("Payment required", {
|
|
678
727
|
kind: "payment_required",
|
|
679
728
|
product,
|
|
@@ -776,7 +825,8 @@ var SolvaPayPaywall = class {
|
|
|
776
825
|
this.customerCreationAttempts.add(customerRef);
|
|
777
826
|
try {
|
|
778
827
|
const createParams = {
|
|
779
|
-
email: options?.email || `${customerRef}-${Date.now()}@auto-created.local
|
|
828
|
+
email: options?.email || `${customerRef}-${Date.now()}@auto-created.local`,
|
|
829
|
+
metadata: {}
|
|
780
830
|
};
|
|
781
831
|
if (options?.name) {
|
|
782
832
|
createParams.name = options.name;
|
|
@@ -800,7 +850,10 @@ var SolvaPayPaywall = class {
|
|
|
800
850
|
return searchResult.customerRef;
|
|
801
851
|
}
|
|
802
852
|
} catch (lookupError) {
|
|
803
|
-
this.log(
|
|
853
|
+
this.log(
|
|
854
|
+
`\u26A0\uFE0F Failed to lookup existing customer by externalRef after 409:`,
|
|
855
|
+
lookupError instanceof Error ? lookupError.message : lookupError
|
|
856
|
+
);
|
|
804
857
|
}
|
|
805
858
|
}
|
|
806
859
|
const isEmailConflict = errorMessage.includes("email") || errorMessage.includes("identifier email");
|
|
@@ -823,7 +876,8 @@ var SolvaPayPaywall = class {
|
|
|
823
876
|
try {
|
|
824
877
|
const retryParams = {
|
|
825
878
|
email: `${customerRef}-${Date.now()}@auto-created.local`,
|
|
826
|
-
externalRef
|
|
879
|
+
externalRef,
|
|
880
|
+
metadata: {}
|
|
827
881
|
};
|
|
828
882
|
if (options?.name) {
|
|
829
883
|
retryParams.name = options.name;
|
|
@@ -1144,17 +1198,7 @@ var McpAdapter = class {
|
|
|
1144
1198
|
content: [
|
|
1145
1199
|
{
|
|
1146
1200
|
type: "text",
|
|
1147
|
-
text: JSON.stringify(
|
|
1148
|
-
{
|
|
1149
|
-
success: false,
|
|
1150
|
-
error: "Payment required",
|
|
1151
|
-
product: error.structuredContent.product,
|
|
1152
|
-
checkoutUrl: error.structuredContent.checkoutUrl,
|
|
1153
|
-
message: error.structuredContent.message
|
|
1154
|
-
},
|
|
1155
|
-
null,
|
|
1156
|
-
2
|
|
1157
|
-
)
|
|
1201
|
+
text: JSON.stringify(paywallErrorToClientPayload(error), null, 2)
|
|
1158
1202
|
}
|
|
1159
1203
|
],
|
|
1160
1204
|
isError: true,
|
|
@@ -1457,7 +1501,7 @@ function createSolvaPay(config) {
|
|
|
1457
1501
|
if (!apiClient.createCustomer) {
|
|
1458
1502
|
throw new SolvaPayError2("createCustomer is not available on this API client");
|
|
1459
1503
|
}
|
|
1460
|
-
return apiClient.createCustomer(params);
|
|
1504
|
+
return apiClient.createCustomer({ ...params, metadata: params.metadata ?? {} });
|
|
1461
1505
|
},
|
|
1462
1506
|
getCustomer(params) {
|
|
1463
1507
|
return apiClient.getCustomer(params);
|
|
@@ -1478,6 +1522,12 @@ function createSolvaPay(config) {
|
|
|
1478
1522
|
}
|
|
1479
1523
|
return apiClient.bootstrapMcpProduct(params);
|
|
1480
1524
|
},
|
|
1525
|
+
configureMcpPlans(productRef, params) {
|
|
1526
|
+
if (!apiClient.configureMcpPlans) {
|
|
1527
|
+
throw new SolvaPayError2("configureMcpPlans is not available on this API client");
|
|
1528
|
+
}
|
|
1529
|
+
return apiClient.configureMcpPlans(productRef, params);
|
|
1530
|
+
},
|
|
1481
1531
|
getVirtualTools(options) {
|
|
1482
1532
|
return createVirtualTools(apiClient, options);
|
|
1483
1533
|
},
|
|
@@ -2128,6 +2178,7 @@ export {
|
|
|
2128
2178
|
isErrorResult,
|
|
2129
2179
|
jsonSchemaToZodRawShape,
|
|
2130
2180
|
listPlansCore,
|
|
2181
|
+
paywallErrorToClientPayload,
|
|
2131
2182
|
processPaymentIntentCore,
|
|
2132
2183
|
registerVirtualToolsMcpImpl,
|
|
2133
2184
|
syncCustomerCore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solvapay/server",
|
|
3
|
-
"version": "1.0.1-preview.
|
|
3
|
+
"version": "1.0.1-preview.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
},
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@solvapay/core": "1.0.1-preview.
|
|
40
|
+
"@solvapay/core": "1.0.1-preview.4"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@modelcontextprotocol/sdk": "^1.28.0",
|
|
44
44
|
"zod": "^3.25.0 || ^4.0.0",
|
|
45
|
-
"@solvapay/auth": "1.0.1-preview.
|
|
45
|
+
"@solvapay/auth": "1.0.1-preview.4"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"@modelcontextprotocol/sdk": {
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"tsx": "^4.21.0",
|
|
61
61
|
"typescript": "^5.9.3",
|
|
62
62
|
"vitest": "^4.1.2",
|
|
63
|
+
"@solvapay/auth": "1.0.1-preview.4",
|
|
63
64
|
"@solvapay/demo-services": "0.0.0",
|
|
64
|
-
"@solvapay/test-utils": "^0.0.0"
|
|
65
|
-
"@solvapay/auth": "1.0.1-preview.3"
|
|
65
|
+
"@solvapay/test-utils": "^0.0.0"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "tsup src/index.ts --format esm,cjs --dts --tsconfig tsconfig.build.json && tsup src/edge.ts --format esm --dts --tsconfig tsconfig.build.json",
|