@solvapay/server 1.0.7 → 1.0.8-preview.2

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/index.cjs CHANGED
@@ -4317,6 +4317,7 @@ __export(index_exports, {
4317
4317
  activatePlanCore: () => activatePlanCore,
4318
4318
  buildAuthInfoFromBearer: () => buildAuthInfoFromBearer,
4319
4319
  cancelPurchaseCore: () => cancelPurchaseCore,
4320
+ checkPurchaseCore: () => checkPurchaseCore,
4320
4321
  createCheckoutSessionCore: () => createCheckoutSessionCore,
4321
4322
  createCustomerSessionCore: () => createCustomerSessionCore,
4322
4323
  createMcpOAuthBridge: () => createMcpOAuthBridge,
@@ -4331,8 +4332,10 @@ __export(index_exports, {
4331
4332
  getCustomerBalanceCore: () => getCustomerBalanceCore,
4332
4333
  getCustomerRefFromBearerAuthHeader: () => getCustomerRefFromBearerAuthHeader,
4333
4334
  getCustomerRefFromJwtPayload: () => getCustomerRefFromJwtPayload,
4335
+ getMerchantCore: () => getMerchantCore,
4334
4336
  getOAuthAuthorizationServerResponse: () => getOAuthAuthorizationServerResponse,
4335
4337
  getOAuthProtectedResourceResponse: () => getOAuthProtectedResourceResponse,
4338
+ getProductCore: () => getProductCore,
4336
4339
  handleRouteError: () => handleRouteError,
4337
4340
  isErrorResult: () => isErrorResult,
4338
4341
  jsonSchemaToZodRawShape: () => jsonSchemaToZodRawShape,
@@ -4342,12 +4345,13 @@ __export(index_exports, {
4342
4345
  reactivatePurchaseCore: () => reactivatePurchaseCore,
4343
4346
  registerVirtualToolsMcpImpl: () => registerVirtualToolsMcpImpl,
4344
4347
  syncCustomerCore: () => syncCustomerCore,
4348
+ trackUsageCore: () => trackUsageCore,
4345
4349
  verifyWebhook: () => verifyWebhook,
4346
4350
  withRetry: () => withRetry
4347
4351
  });
4348
4352
  module.exports = __toCommonJS(index_exports);
4349
4353
  var import_node_crypto = __toESM(require("crypto"), 1);
4350
- var import_core6 = require("@solvapay/core");
4354
+ var import_core8 = require("@solvapay/core");
4351
4355
 
4352
4356
  // src/client.ts
4353
4357
  var import_core = require("@solvapay/core");
@@ -4455,6 +4459,36 @@ function createSolvaPayClient(opts) {
4455
4459
  purchases: customer.purchases || []
4456
4460
  };
4457
4461
  },
4462
+ // GET: /v1/sdk/merchant
4463
+ async getMerchant() {
4464
+ const url = `${base}/v1/sdk/merchant`;
4465
+ const res = await fetch(url, {
4466
+ method: "GET",
4467
+ headers
4468
+ });
4469
+ if (!res.ok) {
4470
+ const error = await res.text();
4471
+ log(`\u274C API Error: ${res.status} - ${error}`);
4472
+ throw new import_core.SolvaPayError(`Get merchant failed (${res.status}): ${error}`);
4473
+ }
4474
+ return res.json();
4475
+ },
4476
+ // GET: /v1/sdk/products/{productRef}
4477
+ async getProduct(productRef) {
4478
+ const url = `${base}/v1/sdk/products/${encodeURIComponent(productRef)}`;
4479
+ const res = await fetch(url, {
4480
+ method: "GET",
4481
+ headers
4482
+ });
4483
+ if (!res.ok) {
4484
+ const error = await res.text();
4485
+ log(`\u274C API Error: ${res.status} - ${error}`);
4486
+ throw new import_core.SolvaPayError(`Get product failed (${res.status}): ${error}`);
4487
+ }
4488
+ const result = await res.json();
4489
+ const data = result.data || {};
4490
+ return { ...data, ...result };
4491
+ },
4458
4492
  // Product management methods (primarily for integration tests)
4459
4493
  // GET: /v1/sdk/products
4460
4494
  async listProducts() {
@@ -6060,7 +6094,8 @@ var McpBearerAuthError = class extends Error {
6060
6094
  function base64UrlDecode(input) {
6061
6095
  const normalized = input.replace(/-/g, "+").replace(/_/g, "/");
6062
6096
  const padded = normalized.padEnd(normalized.length + (4 - normalized.length % 4) % 4, "=");
6063
- return Buffer.from(padded, "base64").toString("utf8");
6097
+ const bytes = Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));
6098
+ return new TextDecoder().decode(bytes);
6064
6099
  }
6065
6100
  function extractBearerToken(authorization) {
6066
6101
  if (!authorization) return null;
@@ -6701,7 +6736,7 @@ async function activatePlanCore(request, body, options = {}) {
6701
6736
 
6702
6737
  // src/helpers/plans.ts
6703
6738
  var import_core5 = require("@solvapay/core");
6704
- async function listPlansCore(request) {
6739
+ async function listPlansCore(request, options = {}) {
6705
6740
  try {
6706
6741
  const url = new URL(request.url);
6707
6742
  const productRef = url.searchParams.get("productRef");
@@ -6711,19 +6746,20 @@ async function listPlansCore(request) {
6711
6746
  status: 400
6712
6747
  };
6713
6748
  }
6714
- const config = (0, import_core5.getSolvaPayConfig)();
6715
- const solvapaySecretKey = config.apiKey;
6716
- const solvapayApiBaseUrl = config.apiBaseUrl;
6717
- if (!solvapaySecretKey) {
6749
+ const apiClient = options.solvaPay?.apiClient ?? (() => {
6750
+ const config = (0, import_core5.getSolvaPayConfig)();
6751
+ if (!config.apiKey) return null;
6752
+ return createSolvaPayClient({
6753
+ apiKey: config.apiKey,
6754
+ apiBaseUrl: config.apiBaseUrl
6755
+ });
6756
+ })();
6757
+ if (!apiClient) {
6718
6758
  return {
6719
6759
  error: "Server configuration error: SolvaPay secret key not configured",
6720
6760
  status: 500
6721
6761
  };
6722
6762
  }
6723
- const apiClient = createSolvaPayClient({
6724
- apiKey: solvapaySecretKey,
6725
- apiBaseUrl: solvapayApiBaseUrl
6726
- });
6727
6763
  if (!apiClient.listPlans) {
6728
6764
  return {
6729
6765
  error: "List plans method not available",
@@ -6740,6 +6776,159 @@ async function listPlansCore(request) {
6740
6776
  }
6741
6777
  }
6742
6778
 
6779
+ // src/helpers/merchant.ts
6780
+ var import_core6 = require("@solvapay/core");
6781
+ async function getMerchantCore(_request, options = {}) {
6782
+ try {
6783
+ const apiClient = options.solvaPay?.apiClient ?? (() => {
6784
+ const config = (0, import_core6.getSolvaPayConfig)();
6785
+ if (!config.apiKey) return null;
6786
+ return createSolvaPayClient({
6787
+ apiKey: config.apiKey,
6788
+ apiBaseUrl: config.apiBaseUrl
6789
+ });
6790
+ })();
6791
+ if (!apiClient) {
6792
+ return {
6793
+ error: "Server configuration error: SolvaPay secret key not configured",
6794
+ status: 500
6795
+ };
6796
+ }
6797
+ if (!apiClient.getMerchant) {
6798
+ return {
6799
+ error: "Get merchant method not available",
6800
+ status: 500
6801
+ };
6802
+ }
6803
+ const merchant = await apiClient.getMerchant();
6804
+ return merchant;
6805
+ } catch (error) {
6806
+ return handleRouteError(error, "Get merchant", "Failed to fetch merchant");
6807
+ }
6808
+ }
6809
+
6810
+ // src/helpers/product.ts
6811
+ var import_core7 = require("@solvapay/core");
6812
+ async function getProductCore(request, options = {}) {
6813
+ try {
6814
+ const url = new URL(request.url);
6815
+ const productRef = url.searchParams.get("productRef");
6816
+ if (!productRef) {
6817
+ return {
6818
+ error: "Missing required parameter: productRef",
6819
+ status: 400
6820
+ };
6821
+ }
6822
+ const apiClient = options.solvaPay?.apiClient ?? (() => {
6823
+ const config = (0, import_core7.getSolvaPayConfig)();
6824
+ if (!config.apiKey) return null;
6825
+ return createSolvaPayClient({
6826
+ apiKey: config.apiKey,
6827
+ apiBaseUrl: config.apiBaseUrl
6828
+ });
6829
+ })();
6830
+ if (!apiClient) {
6831
+ return {
6832
+ error: "Server configuration error: SolvaPay secret key not configured",
6833
+ status: 500
6834
+ };
6835
+ }
6836
+ if (!apiClient.getProduct) {
6837
+ return {
6838
+ error: "Get product method not available",
6839
+ status: 500
6840
+ };
6841
+ }
6842
+ const product = await apiClient.getProduct(productRef);
6843
+ return product;
6844
+ } catch (error) {
6845
+ return handleRouteError(error, "Get product", "Failed to fetch product");
6846
+ }
6847
+ }
6848
+
6849
+ // src/helpers/purchase.ts
6850
+ async function checkPurchaseCore(request, options = {}) {
6851
+ try {
6852
+ const userResult = await getAuthenticatedUserCore(request, {
6853
+ includeEmail: options.includeEmail,
6854
+ includeName: options.includeName
6855
+ });
6856
+ if (isErrorResult(userResult)) {
6857
+ return userResult;
6858
+ }
6859
+ const { userId, email, name } = userResult;
6860
+ const solvaPay = options.solvaPay || createSolvaPay();
6861
+ const cachedCustomerRef = request.headers.get("x-solvapay-customer-ref");
6862
+ if (cachedCustomerRef) {
6863
+ try {
6864
+ const customer = await solvaPay.getCustomer({ customerRef: cachedCustomerRef });
6865
+ if (customer && customer.customerRef) {
6866
+ if (customer.externalRef && customer.externalRef === userId) {
6867
+ const filteredPurchases = (customer.purchases || []).filter(
6868
+ (p) => p.status === "active"
6869
+ );
6870
+ return {
6871
+ customerRef: customer.customerRef,
6872
+ email: customer.email,
6873
+ name: customer.name,
6874
+ purchases: filteredPurchases
6875
+ };
6876
+ }
6877
+ }
6878
+ } catch {
6879
+ }
6880
+ }
6881
+ try {
6882
+ const customerRef = await solvaPay.ensureCustomer(userId, userId, {
6883
+ email: email || void 0,
6884
+ name: name || void 0
6885
+ });
6886
+ const customer = await solvaPay.getCustomer({ customerRef });
6887
+ const filteredPurchases = (customer.purchases || []).filter((p) => p.status === "active");
6888
+ return {
6889
+ customerRef: customer.customerRef || userId,
6890
+ email: customer.email,
6891
+ name: customer.name,
6892
+ purchases: filteredPurchases
6893
+ };
6894
+ } catch {
6895
+ return {
6896
+ customerRef: userId,
6897
+ purchases: []
6898
+ };
6899
+ }
6900
+ } catch (error) {
6901
+ return handleRouteError(error, "Check purchase", "Failed to check purchase");
6902
+ }
6903
+ }
6904
+
6905
+ // src/helpers/usage.ts
6906
+ async function trackUsageCore(request, body, options = {}) {
6907
+ try {
6908
+ const userResult = await getAuthenticatedUserCore(request);
6909
+ if (isErrorResult(userResult)) {
6910
+ return userResult;
6911
+ }
6912
+ const { userId, email, name } = userResult;
6913
+ const solvaPay = options.solvaPay || createSolvaPay();
6914
+ const customerRef = await solvaPay.ensureCustomer(userId, userId, {
6915
+ email: email || void 0,
6916
+ name: name || void 0
6917
+ });
6918
+ await solvaPay.trackUsage({
6919
+ customerRef,
6920
+ actionType: body.actionType,
6921
+ units: body.units,
6922
+ productRef: body.productRef,
6923
+ description: body.description,
6924
+ metadata: body.metadata
6925
+ });
6926
+ return { success: true };
6927
+ } catch (error) {
6928
+ return handleRouteError(error, "Track usage", "Track usage failed");
6929
+ }
6930
+ }
6931
+
6743
6932
  // src/index.ts
6744
6933
  function verifyWebhook({
6745
6934
  body,
@@ -6747,34 +6936,34 @@ function verifyWebhook({
6747
6936
  secret
6748
6937
  }) {
6749
6938
  const toleranceSec = 300;
6750
- if (!signature) throw new import_core6.SolvaPayError("Missing webhook signature");
6939
+ if (!signature) throw new import_core8.SolvaPayError("Missing webhook signature");
6751
6940
  const parts = signature.split(",");
6752
6941
  const tPart = parts.find((p) => p.startsWith("t="));
6753
6942
  const v1Part = parts.find((p) => p.startsWith("v1="));
6754
6943
  if (!tPart || !v1Part) {
6755
- throw new import_core6.SolvaPayError("Malformed webhook signature");
6944
+ throw new import_core8.SolvaPayError("Malformed webhook signature");
6756
6945
  }
6757
6946
  const timestamp = parseInt(tPart.slice(2), 10);
6758
6947
  const receivedHmac = v1Part.slice(3);
6759
6948
  if (Number.isNaN(timestamp) || !receivedHmac) {
6760
- throw new import_core6.SolvaPayError("Malformed webhook signature");
6949
+ throw new import_core8.SolvaPayError("Malformed webhook signature");
6761
6950
  }
6762
6951
  if (toleranceSec > 0) {
6763
6952
  const age = Math.abs(Math.floor(Date.now() / 1e3) - timestamp);
6764
6953
  if (age > toleranceSec) {
6765
- throw new import_core6.SolvaPayError("Webhook signature timestamp too old");
6954
+ throw new import_core8.SolvaPayError("Webhook signature timestamp too old");
6766
6955
  }
6767
6956
  }
6768
6957
  const expectedHmac = import_node_crypto.default.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
6769
6958
  if (receivedHmac.length !== expectedHmac.length) {
6770
- throw new import_core6.SolvaPayError("Invalid webhook signature");
6959
+ throw new import_core8.SolvaPayError("Invalid webhook signature");
6771
6960
  }
6772
6961
  const ok = import_node_crypto.default.timingSafeEqual(Buffer.from(expectedHmac), Buffer.from(receivedHmac));
6773
- if (!ok) throw new import_core6.SolvaPayError("Invalid webhook signature");
6962
+ if (!ok) throw new import_core8.SolvaPayError("Invalid webhook signature");
6774
6963
  try {
6775
6964
  return JSON.parse(body);
6776
6965
  } catch {
6777
- throw new import_core6.SolvaPayError("Invalid webhook payload: body is not valid JSON");
6966
+ throw new import_core8.SolvaPayError("Invalid webhook payload: body is not valid JSON");
6778
6967
  }
6779
6968
  }
6780
6969
  // Annotate the CommonJS export names for ESM import in node:
@@ -6785,6 +6974,7 @@ function verifyWebhook({
6785
6974
  activatePlanCore,
6786
6975
  buildAuthInfoFromBearer,
6787
6976
  cancelPurchaseCore,
6977
+ checkPurchaseCore,
6788
6978
  createCheckoutSessionCore,
6789
6979
  createCustomerSessionCore,
6790
6980
  createMcpOAuthBridge,
@@ -6799,8 +6989,10 @@ function verifyWebhook({
6799
6989
  getCustomerBalanceCore,
6800
6990
  getCustomerRefFromBearerAuthHeader,
6801
6991
  getCustomerRefFromJwtPayload,
6992
+ getMerchantCore,
6802
6993
  getOAuthAuthorizationServerResponse,
6803
6994
  getOAuthProtectedResourceResponse,
6995
+ getProductCore,
6804
6996
  handleRouteError,
6805
6997
  isErrorResult,
6806
6998
  jsonSchemaToZodRawShape,
@@ -6810,6 +7002,7 @@ function verifyWebhook({
6810
7002
  reactivatePurchaseCore,
6811
7003
  registerVirtualToolsMcpImpl,
6812
7004
  syncCustomerCore,
7005
+ trackUsageCore,
6813
7006
  verifyWebhook,
6814
7007
  withRetry
6815
7008
  });
package/dist/index.d.cts CHANGED
@@ -2488,6 +2488,26 @@ interface ProcessPaymentResult {
2488
2488
  status: 'completed';
2489
2489
  }
2490
2490
  type ActivatePlanResult = components['schemas']['ActivatePlanResponseDto'];
2491
+ /**
2492
+ * SDK-facing merchant identity (source: GET /v1/sdk/merchant).
2493
+ *
2494
+ * Hand-typed here until the OpenAPI generator picks up the new endpoint.
2495
+ * Fields match `SdkMerchantResponseDto` on the backend.
2496
+ */
2497
+ type SdkMerchantResponse = {
2498
+ displayName: string;
2499
+ legalName: string;
2500
+ supportEmail?: string;
2501
+ supportUrl?: string;
2502
+ termsUrl?: string;
2503
+ privacyUrl?: string;
2504
+ country?: string;
2505
+ defaultCurrency?: string;
2506
+ statementDescriptor?: string;
2507
+ logoUrl?: string;
2508
+ };
2509
+ /** SDK-facing product projection. Sourced from the existing OpenAPI spec. */
2510
+ type SdkProductResponse = components['schemas']['SdkProductResponse'];
2491
2511
  type McpBootstrapPlanInput = NonNullable<components['schemas']['McpBootstrapDto']['plans']>[number];
2492
2512
  type ToolPlanMappingInput = NonNullable<components['schemas']['McpBootstrapDto']['tools']>[number];
2493
2513
  type McpBootstrapRequest = components['schemas']['McpBootstrapDto'];
@@ -2556,6 +2576,13 @@ interface SolvaPayClient {
2556
2576
  externalRef?: string;
2557
2577
  email?: string;
2558
2578
  }): Promise<CustomerResponseMapped>;
2579
+ /**
2580
+ * SDK-facing merchant identity (GET /v1/sdk/merchant).
2581
+ * Returns the subset of provider fields safe for browser consumption —
2582
+ * used by `<MandateText>`, `<CheckoutSummary>`, and trust signals.
2583
+ */
2584
+ getMerchant?(): Promise<SdkMerchantResponse>;
2585
+ getProduct?(productRef: string): Promise<SdkProductResponse>;
2559
2586
  listProducts?(): Promise<Array<{
2560
2587
  reference: string;
2561
2588
  name: string;
@@ -4116,13 +4143,85 @@ declare function activatePlanCore(request: Request, body: {
4116
4143
 
4117
4144
  type Plan = components['schemas']['Plan'];
4118
4145
  /**
4119
- * List plans - core implementation
4146
+ * List plans - core implementation.
4147
+ *
4148
+ * Pass `options.solvaPay` to route through a pre-configured SolvaPay instance
4149
+ * (e.g. stub-backed in examples). When omitted, the helper reads
4150
+ * `SOLVAPAY_SECRET_KEY` from environment and constructs a real API client.
4120
4151
  */
4121
- declare function listPlansCore(request: Request): Promise<{
4152
+ declare function listPlansCore(request: Request, options?: {
4153
+ solvaPay?: SolvaPay;
4154
+ }): Promise<{
4122
4155
  plans: Plan[];
4123
4156
  productRef: string;
4124
4157
  } | ErrorResult>;
4125
4158
 
4159
+ /**
4160
+ * Merchant Helper (Core)
4161
+ *
4162
+ * Generic helper for GET /api/merchant — returns the SDK-facing merchant
4163
+ * identity used by `<MandateText>`, `<CheckoutSummary>`, and trust signals.
4164
+ * Works with standard Web API Request (Express, Fastify, Next.js, Edge).
4165
+ */
4166
+
4167
+ declare function getMerchantCore(_request: Request, options?: {
4168
+ solvaPay?: SolvaPay;
4169
+ }): Promise<SdkMerchantResponse | ErrorResult>;
4170
+
4171
+ /**
4172
+ * Product Helper (Core)
4173
+ *
4174
+ * Generic helper for GET /api/get-product?productRef=...
4175
+ * Returns a single product by reference, used by the `useProduct` React hook.
4176
+ */
4177
+
4178
+ declare function getProductCore(request: Request, options?: {
4179
+ solvaPay?: SolvaPay;
4180
+ }): Promise<SdkProductResponse | ErrorResult>;
4181
+
4182
+ interface PurchaseCheckResult {
4183
+ customerRef: string;
4184
+ email?: string;
4185
+ name?: string;
4186
+ purchases: Array<{
4187
+ reference: string;
4188
+ productName?: string;
4189
+ productRef?: string;
4190
+ status?: string;
4191
+ startDate?: string;
4192
+ planSnapshot?: {
4193
+ meterId?: string;
4194
+ limit?: number;
4195
+ freeUnits?: number;
4196
+ };
4197
+ usage?: {
4198
+ used?: number;
4199
+ overageUnits?: number;
4200
+ overageCost?: number;
4201
+ periodStart?: string;
4202
+ periodEnd?: string;
4203
+ };
4204
+ [key: string]: unknown;
4205
+ }>;
4206
+ }
4207
+ declare function checkPurchaseCore(request: Request, options?: {
4208
+ solvaPay?: SolvaPay;
4209
+ includeEmail?: boolean;
4210
+ includeName?: boolean;
4211
+ }): Promise<PurchaseCheckResult | ErrorResult>;
4212
+
4213
+ declare function trackUsageCore(request: Request, body: {
4214
+ actionType?: 'transaction' | 'api_call' | 'hour' | 'email' | 'storage' | 'custom';
4215
+ units?: number;
4216
+ productRef?: string;
4217
+ description?: string;
4218
+ metadata?: Record<string, unknown>;
4219
+ }, options?: {
4220
+ solvaPay?: SolvaPay;
4221
+ }): Promise<{
4222
+ success: true;
4223
+ } | ErrorResult>;
4224
+
4126
4225
  /**
4127
4226
  * SolvaPay Server SDK
4128
4227
  *
@@ -4178,4 +4277,4 @@ declare function verifyWebhook({ body, signature, secret, }: {
4178
4277
  secret: string;
4179
4278
  }): WebhookEvent;
4180
4279
 
4181
- export { type ActivatePlanResult, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type McpAdapterOptions, McpBearerAuthError, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpServerLike, type McpToolExtra, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableFunction, type PayableOptions, type PaywallArgs, PaywallError, type PaywallMetadata, type PaywallStructuredContent, type PaywallToolResult, type ProcessPaymentResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildAuthInfoFromBearer, cancelPurchaseCore, type components, createCheckoutSessionCore, createCustomerSessionCore, createMcpOAuthBridge, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, decodeJwtPayload, extractBearerToken, getAuthenticatedUserCore, getCustomerBalanceCore, getCustomerRefFromBearerAuthHeader, getCustomerRefFromJwtPayload, getOAuthAuthorizationServerResponse, getOAuthProtectedResourceResponse, handleRouteError, isErrorResult, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, syncCustomerCore, verifyWebhook, withRetry };
4280
+ export { type ActivatePlanResult, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type McpAdapterOptions, McpBearerAuthError, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpServerLike, type McpToolExtra, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableFunction, type PayableOptions, type PaywallArgs, PaywallError, type PaywallMetadata, type PaywallStructuredContent, type PaywallToolResult, type ProcessPaymentResult, type PurchaseCheckResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildAuthInfoFromBearer, cancelPurchaseCore, checkPurchaseCore, type components, createCheckoutSessionCore, createCustomerSessionCore, createMcpOAuthBridge, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, decodeJwtPayload, extractBearerToken, getAuthenticatedUserCore, getCustomerBalanceCore, getCustomerRefFromBearerAuthHeader, getCustomerRefFromJwtPayload, getMerchantCore, getOAuthAuthorizationServerResponse, getOAuthProtectedResourceResponse, getProductCore, handleRouteError, isErrorResult, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };
package/dist/index.d.ts CHANGED
@@ -2488,6 +2488,26 @@ interface ProcessPaymentResult {
2488
2488
  status: 'completed';
2489
2489
  }
2490
2490
  type ActivatePlanResult = components['schemas']['ActivatePlanResponseDto'];
2491
+ /**
2492
+ * SDK-facing merchant identity (source: GET /v1/sdk/merchant).
2493
+ *
2494
+ * Hand-typed here until the OpenAPI generator picks up the new endpoint.
2495
+ * Fields match `SdkMerchantResponseDto` on the backend.
2496
+ */
2497
+ type SdkMerchantResponse = {
2498
+ displayName: string;
2499
+ legalName: string;
2500
+ supportEmail?: string;
2501
+ supportUrl?: string;
2502
+ termsUrl?: string;
2503
+ privacyUrl?: string;
2504
+ country?: string;
2505
+ defaultCurrency?: string;
2506
+ statementDescriptor?: string;
2507
+ logoUrl?: string;
2508
+ };
2509
+ /** SDK-facing product projection. Sourced from the existing OpenAPI spec. */
2510
+ type SdkProductResponse = components['schemas']['SdkProductResponse'];
2491
2511
  type McpBootstrapPlanInput = NonNullable<components['schemas']['McpBootstrapDto']['plans']>[number];
2492
2512
  type ToolPlanMappingInput = NonNullable<components['schemas']['McpBootstrapDto']['tools']>[number];
2493
2513
  type McpBootstrapRequest = components['schemas']['McpBootstrapDto'];
@@ -2556,6 +2576,13 @@ interface SolvaPayClient {
2556
2576
  externalRef?: string;
2557
2577
  email?: string;
2558
2578
  }): Promise<CustomerResponseMapped>;
2579
+ /**
2580
+ * SDK-facing merchant identity (GET /v1/sdk/merchant).
2581
+ * Returns the subset of provider fields safe for browser consumption —
2582
+ * used by `<MandateText>`, `<CheckoutSummary>`, and trust signals.
2583
+ */
2584
+ getMerchant?(): Promise<SdkMerchantResponse>;
2585
+ getProduct?(productRef: string): Promise<SdkProductResponse>;
2559
2586
  listProducts?(): Promise<Array<{
2560
2587
  reference: string;
2561
2588
  name: string;
@@ -4116,13 +4143,85 @@ declare function activatePlanCore(request: Request, body: {
4116
4143
 
4117
4144
  type Plan = components['schemas']['Plan'];
4118
4145
  /**
4119
- * List plans - core implementation
4146
+ * List plans - core implementation.
4147
+ *
4148
+ * Pass `options.solvaPay` to route through a pre-configured SolvaPay instance
4149
+ * (e.g. stub-backed in examples). When omitted, the helper reads
4150
+ * `SOLVAPAY_SECRET_KEY` from environment and constructs a real API client.
4120
4151
  */
4121
- declare function listPlansCore(request: Request): Promise<{
4152
+ declare function listPlansCore(request: Request, options?: {
4153
+ solvaPay?: SolvaPay;
4154
+ }): Promise<{
4122
4155
  plans: Plan[];
4123
4156
  productRef: string;
4124
4157
  } | ErrorResult>;
4125
4158
 
4159
+ /**
4160
+ * Merchant Helper (Core)
4161
+ *
4162
+ * Generic helper for GET /api/merchant — returns the SDK-facing merchant
4163
+ * identity used by `<MandateText>`, `<CheckoutSummary>`, and trust signals.
4164
+ * Works with standard Web API Request (Express, Fastify, Next.js, Edge).
4165
+ */
4166
+
4167
+ declare function getMerchantCore(_request: Request, options?: {
4168
+ solvaPay?: SolvaPay;
4169
+ }): Promise<SdkMerchantResponse | ErrorResult>;
4170
+
4171
+ /**
4172
+ * Product Helper (Core)
4173
+ *
4174
+ * Generic helper for GET /api/get-product?productRef=...
4175
+ * Returns a single product by reference, used by the `useProduct` React hook.
4176
+ */
4177
+
4178
+ declare function getProductCore(request: Request, options?: {
4179
+ solvaPay?: SolvaPay;
4180
+ }): Promise<SdkProductResponse | ErrorResult>;
4181
+
4182
+ interface PurchaseCheckResult {
4183
+ customerRef: string;
4184
+ email?: string;
4185
+ name?: string;
4186
+ purchases: Array<{
4187
+ reference: string;
4188
+ productName?: string;
4189
+ productRef?: string;
4190
+ status?: string;
4191
+ startDate?: string;
4192
+ planSnapshot?: {
4193
+ meterId?: string;
4194
+ limit?: number;
4195
+ freeUnits?: number;
4196
+ };
4197
+ usage?: {
4198
+ used?: number;
4199
+ overageUnits?: number;
4200
+ overageCost?: number;
4201
+ periodStart?: string;
4202
+ periodEnd?: string;
4203
+ };
4204
+ [key: string]: unknown;
4205
+ }>;
4206
+ }
4207
+ declare function checkPurchaseCore(request: Request, options?: {
4208
+ solvaPay?: SolvaPay;
4209
+ includeEmail?: boolean;
4210
+ includeName?: boolean;
4211
+ }): Promise<PurchaseCheckResult | ErrorResult>;
4212
+
4213
+ declare function trackUsageCore(request: Request, body: {
4214
+ actionType?: 'transaction' | 'api_call' | 'hour' | 'email' | 'storage' | 'custom';
4215
+ units?: number;
4216
+ productRef?: string;
4217
+ description?: string;
4218
+ metadata?: Record<string, unknown>;
4219
+ }, options?: {
4220
+ solvaPay?: SolvaPay;
4221
+ }): Promise<{
4222
+ success: true;
4223
+ } | ErrorResult>;
4224
+
4126
4225
  /**
4127
4226
  * SolvaPay Server SDK
4128
4227
  *
@@ -4178,4 +4277,4 @@ declare function verifyWebhook({ body, signature, secret, }: {
4178
4277
  secret: string;
4179
4278
  }): WebhookEvent;
4180
4279
 
4181
- export { type ActivatePlanResult, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type McpAdapterOptions, McpBearerAuthError, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpServerLike, type McpToolExtra, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableFunction, type PayableOptions, type PaywallArgs, PaywallError, type PaywallMetadata, type PaywallStructuredContent, type PaywallToolResult, type ProcessPaymentResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildAuthInfoFromBearer, cancelPurchaseCore, type components, createCheckoutSessionCore, createCustomerSessionCore, createMcpOAuthBridge, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, decodeJwtPayload, extractBearerToken, getAuthenticatedUserCore, getCustomerBalanceCore, getCustomerRefFromBearerAuthHeader, getCustomerRefFromJwtPayload, getOAuthAuthorizationServerResponse, getOAuthProtectedResourceResponse, handleRouteError, isErrorResult, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, syncCustomerCore, verifyWebhook, withRetry };
4280
+ export { type ActivatePlanResult, type AuthenticatedUser, type ConfigureMcpPlansRequest, type ConfigureMcpPlansResponse, type CreateSolvaPayConfig, type CustomerBalanceResult, type CustomerResponseMapped, type CustomerWebhookObject, type ErrorResult, type HttpAdapterOptions, type LimitActivationBalance, type LimitActivationProduct, type LimitPlanSummary, type McpAdapterOptions, McpBearerAuthError, type McpBootstrapPlanInput, type McpBootstrapRequest, type McpBootstrapResponse, type McpServerLike, type McpToolExtra, type McpToolPlanMappingInput, type NextAdapterOptions, type OneTimePurchaseInfo, type PayableFunction, type PayableOptions, type PaywallArgs, PaywallError, type PaywallMetadata, type PaywallStructuredContent, type PaywallToolResult, type ProcessPaymentResult, type PurchaseCheckResult, type RegisterVirtualToolsMcpOptions, type RetryOptions, type SdkMerchantResponse, type SdkProductResponse, type ServerClientOptions, type SolvaPay, type SolvaPayClient, type ToolPlanMappingInput, VIRTUAL_TOOL_DEFINITIONS, type VirtualToolDefinition, type VirtualToolsOptions, type WebhookEvent, type WebhookEventForType, type WebhookEventObjectMap, type WebhookEventType, type WebhookProduct, activatePlanCore, buildAuthInfoFromBearer, cancelPurchaseCore, checkPurchaseCore, type components, createCheckoutSessionCore, createCustomerSessionCore, createMcpOAuthBridge, createPaymentIntentCore, createSolvaPay, createSolvaPayClient, createTopupPaymentIntentCore, createVirtualTools, decodeJwtPayload, extractBearerToken, getAuthenticatedUserCore, getCustomerBalanceCore, getCustomerRefFromBearerAuthHeader, getCustomerRefFromJwtPayload, getMerchantCore, getOAuthAuthorizationServerResponse, getOAuthProtectedResourceResponse, getProductCore, handleRouteError, isErrorResult, jsonSchemaToZodRawShape, listPlansCore, paywallErrorToClientPayload, processPaymentIntentCore, reactivatePurchaseCore, registerVirtualToolsMcpImpl, syncCustomerCore, trackUsageCore, verifyWebhook, withRetry };