@xapps-platform/backend-kit 0.1.6 → 0.2.1

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 CHANGED
@@ -38,16 +38,62 @@ verify browser widget context server-side before exposing private runtime
38
38
  behavior:
39
39
 
40
40
  ```ts
41
- import { verifyBrowserWidgetContext } from "@xapps-platform/backend-kit";
41
+ import {
42
+ evaluateWidgetBootstrapOriginPolicy,
43
+ verifyBrowserWidgetContext,
44
+ } from "@xapps-platform/backend-kit";
45
+
46
+ const originPolicy = evaluateWidgetBootstrapOriginPolicy({
47
+ hostOrigin: request.body?.hostOrigin,
48
+ allowedOrigins: config.widgetBootstrap.allowedOrigins,
49
+ });
50
+
51
+ if (!originPolicy.ok) {
52
+ reply.code(originPolicy.code === "HOST_ORIGIN_REQUIRED" ? 400 : 403).send({
53
+ ok: false,
54
+ error: {
55
+ code: originPolicy.code,
56
+ message: originPolicy.message,
57
+ },
58
+ });
59
+ return;
60
+ }
42
61
 
43
62
  const verified = await verifyBrowserWidgetContext(gatewayClient, {
44
- hostOrigin: "https://tenant.example.test",
63
+ hostOrigin: originPolicy.hostOrigin,
45
64
  installationId: "inst_123",
46
65
  bindToolName: "submit_form",
47
66
  subjectId: "sub_123",
67
+ bootstrapTicket: request.body?.bootstrapTicket ?? null,
48
68
  });
49
69
  ```
50
70
 
71
+ Recommended shared local config contract for publisher-rendered bootstrap
72
+ routes:
73
+
74
+ - `widgetBootstrap.allowedOrigins`
75
+ - optional app env:
76
+ - `XAPPS_WIDGET_ALLOWED_ORIGINS=https://host.example.test,https://host-b.example.test`
77
+
78
+ This stays local/app-owned on purpose. The package helper standardizes the
79
+ policy behavior without forcing a repo-wide env parser or backend shape.
80
+
81
+ Recommended request-widget posture:
82
+
83
+ - treat the widget asset URL as a public/bootstrap shell
84
+ - keep request-capable UI blocked until widget context is verified server-side
85
+ - do not place private keys, secrets, or durable bearer tokens in `entry.url`
86
+ - direct raw browser hits should stay blocked instead of unlocking private runtime
87
+
88
+ Optional stronger bootstrap transport already supported:
89
+
90
+ - `widgets[].config.xapps.bootstrap_transport = "signed_ticket"`
91
+ - current first slice reuses the short-lived signed widget token as a bootstrap
92
+ ticket and carries it in the iframe URL hash
93
+ - browser widget code can forward it to your backend as `bootstrapTicket`
94
+ - the backend kit verification passthrough accepts that field without changing
95
+ the current default/public bootstrap contract
96
+
51
97
  This is now a real package, not a placeholder or extraction stub. Keep the
52
98
  public entry surface stable and split internal package code behind it.
53
99
 
@@ -90,6 +136,7 @@ The current package surface provides:
90
136
  - default route surface
91
137
  - default mode tree
92
138
  - payment runtime assembly
139
+ - higher-level XMS purchase workflow helpers
93
140
  - host-proxy service assembly
94
141
  - request-widget bootstrap verification passthrough
95
142
  - subject-profile sourcing hooks
@@ -102,6 +149,8 @@ Internal package structure is intentionally modular:
102
149
  option normalization and config shaping
103
150
  - `src/backend/paymentRuntime.ts`
104
151
  payment runtime assembly and payment-page API helpers
152
+ - `src/backend/xms.ts`
153
+ higher-level XMS purchase workflow helpers on top of the server SDK
105
154
  - `src/backend/modules.ts`
106
155
  backend module composition
107
156
  - `src/backend/modes/*`
@@ -120,6 +169,29 @@ Current route surface includes:
120
169
  - guard
121
170
  - subject profiles
122
171
 
172
+ Current workflow helpers also include:
173
+
174
+ - `normalizeXappMonetizationScopeKind(...)`
175
+ normalizes subject / installation / realm scope selection
176
+ - `resolveXappMonetizationScope(...)`
177
+ resolves scope fields from runtime context plus optional realm reference
178
+ - `resolveXappHostedPaymentDefinition(...)`
179
+ resolves a manifest payment definition into hosted session config, including delegated signing metadata
180
+ - `listXappHostedPaymentPresets(...)`
181
+ shapes manifest payment definitions into generic hosted-lane preset options for UI selectors
182
+ - `findXappHostedPaymentPreset(...)`
183
+ looks up one hosted-lane preset by `paymentGuardRef`
184
+ - `readXappMonetizationSnapshot(...)`
185
+ reads the common app-facing XMS state bundle: access, current subscription, and wallet accounts
186
+ - `consumeXappWalletCredits(...)`
187
+ consumes credits from one wallet account through the XMS API and returns the updated wallet, ledger entry, and refreshed access projection
188
+ - `startXappHostedPurchase(...)`
189
+ prepares a purchase intent and creates the lane-bootstrapped gateway payment session
190
+ - `finalizeXappHostedPurchase(...)`
191
+ finalizes a hosted purchase through the platform finalize endpoint, returning reconciliation and issued access state
192
+ - `activateXappPurchaseReference(...)`
193
+ prepares a purchase intent, creates a verified reference transaction, and issues access
194
+
123
195
  For hosted-integrator mode, the host API surface can also enforce explicit
124
196
  frontend-origin allowlists through `host.allowedOrigins`. Leave it empty for
125
197
  same-origin consumers; set it when the browser host runs on another domain and
@@ -0,0 +1,159 @@
1
+ type UnknownRecord = Record<string, unknown>;
2
+ type ScopeFieldsInput = {
3
+ subjectId?: string | null;
4
+ subject_id?: string | null;
5
+ installationId?: string | null;
6
+ installation_id?: string | null;
7
+ realmRef?: string | null;
8
+ realm_ref?: string | null;
9
+ };
10
+ type PreparePurchaseInput = ScopeFieldsInput & {
11
+ xappId: string;
12
+ offeringId?: string | null;
13
+ offering_id?: string | null;
14
+ packageId?: string | null;
15
+ package_id?: string | null;
16
+ priceId?: string | null;
17
+ price_id?: string | null;
18
+ sourceKind?: string | null;
19
+ source_kind?: string | null;
20
+ sourceRef?: string | null;
21
+ source_ref?: string | null;
22
+ paymentLane?: string | null;
23
+ payment_lane?: string | null;
24
+ paymentSessionId?: string | null;
25
+ payment_session_id?: string | null;
26
+ requestId?: string | null;
27
+ request_id?: string | null;
28
+ };
29
+ export type StartXappHostedPurchaseInput = PreparePurchaseInput & {
30
+ paymentGuardRef?: string | null;
31
+ payment_guard_ref?: string | null;
32
+ issuer?: string | null;
33
+ scheme?: string | null;
34
+ paymentScheme?: string | null;
35
+ payment_scheme?: string | null;
36
+ returnUrl?: string | null;
37
+ return_url?: string | null;
38
+ cancelUrl?: string | null;
39
+ cancel_url?: string | null;
40
+ xappsResume?: string | null;
41
+ xapps_resume?: string | null;
42
+ pageUrl?: string | null;
43
+ page_url?: string | null;
44
+ locale?: string | null;
45
+ metadata?: UnknownRecord | null;
46
+ };
47
+ export type FinalizeXappHostedPurchaseInput = {
48
+ xappId: string;
49
+ intentId?: string | null;
50
+ intent_id?: string | null;
51
+ };
52
+ export type ActivateXappPurchaseReferenceInput = PreparePurchaseInput & {
53
+ status?: string | null;
54
+ providerRef?: string | null;
55
+ provider_ref?: string | null;
56
+ evidenceRef?: string | null;
57
+ evidence_ref?: string | null;
58
+ settlementRef?: string | null;
59
+ settlement_ref?: string | null;
60
+ amount?: string | number | null;
61
+ currency?: string | null;
62
+ occurredAt?: string | null;
63
+ occurred_at?: string | null;
64
+ };
65
+ export type ReadXappMonetizationSnapshotInput = ScopeFieldsInput & {
66
+ xappId: string;
67
+ includeWalletAccounts?: boolean | null;
68
+ includeWalletLedger?: boolean | null;
69
+ walletAccountId?: string | null;
70
+ wallet_account_id?: string | null;
71
+ paymentSessionId?: string | null;
72
+ payment_session_id?: string | null;
73
+ requestId?: string | null;
74
+ request_id?: string | null;
75
+ settlementRef?: string | null;
76
+ settlement_ref?: string | null;
77
+ };
78
+ export type ConsumeXappWalletCreditsInput = {
79
+ xappId: string;
80
+ walletAccountId?: string | null;
81
+ wallet_account_id?: string | null;
82
+ amount: string;
83
+ sourceRef?: string | null;
84
+ source_ref?: string | null;
85
+ metadata?: UnknownRecord | null;
86
+ };
87
+ export type ResolveXappMonetizationScopeInput = {
88
+ scopeKind?: string | null;
89
+ scope_kind?: string | null;
90
+ context?: UnknownRecord | null;
91
+ realmRef?: string | null;
92
+ realm_ref?: string | null;
93
+ };
94
+ export type ResolveXappHostedPaymentDefinitionInput = {
95
+ manifest: UnknownRecord;
96
+ paymentGuardRef?: string | null;
97
+ payment_guard_ref?: string | null;
98
+ paymentScheme?: string | null;
99
+ payment_scheme?: string | null;
100
+ env?: Record<string, string | undefined>;
101
+ };
102
+ export type ListXappHostedPaymentPresetsInput = {
103
+ manifest: UnknownRecord;
104
+ };
105
+ type GatewayPurchaseFlowClient = {
106
+ prepareXappPurchaseIntent: (input: UnknownRecord) => Promise<UnknownRecord>;
107
+ createXappPurchasePaymentSession?: (input: UnknownRecord) => Promise<UnknownRecord>;
108
+ reconcileXappPurchasePaymentSession?: (input: UnknownRecord) => Promise<UnknownRecord>;
109
+ finalizeXappPurchasePaymentSession?: (input: UnknownRecord) => Promise<UnknownRecord>;
110
+ issueXappPurchaseAccess?: (input: UnknownRecord) => Promise<UnknownRecord>;
111
+ createXappPurchaseTransaction?: (input: UnknownRecord) => Promise<UnknownRecord>;
112
+ getXappMonetizationAccess?: (input: UnknownRecord) => Promise<UnknownRecord>;
113
+ getXappCurrentSubscription?: (input: UnknownRecord) => Promise<UnknownRecord>;
114
+ listXappWalletAccounts?: (input: UnknownRecord) => Promise<UnknownRecord>;
115
+ listXappWalletLedger?: (input: UnknownRecord) => Promise<UnknownRecord>;
116
+ consumeXappWalletCredits?: (input: UnknownRecord) => Promise<UnknownRecord>;
117
+ };
118
+ export declare function normalizeXappMonetizationScopeKind(value: unknown): "subject" | "installation" | "realm";
119
+ export declare function resolveXappMonetizationScope(input: ResolveXappMonetizationScopeInput): {
120
+ scope_kind: "subject" | "installation" | "realm";
121
+ scope_fields: UnknownRecord;
122
+ };
123
+ export declare function listXappHostedPaymentPresets(input: ListXappHostedPaymentPresetsInput): Array<{
124
+ key: string;
125
+ label: string;
126
+ description: string;
127
+ paymentGuardRef: string;
128
+ paymentScheme: string | null;
129
+ issuerMode: string;
130
+ delegated: boolean;
131
+ }>;
132
+ export declare function findXappHostedPaymentPreset(input: ListXappHostedPaymentPresetsInput & {
133
+ paymentGuardRef?: string | null;
134
+ payment_guard_ref?: string | null;
135
+ paymentScheme?: string | null;
136
+ payment_scheme?: string | null;
137
+ }): {
138
+ key: string;
139
+ label: string;
140
+ description: string;
141
+ paymentGuardRef: string;
142
+ paymentScheme: string | null;
143
+ issuerMode: string;
144
+ delegated: boolean;
145
+ };
146
+ export declare function resolveXappHostedPaymentDefinition(input: ResolveXappHostedPaymentDefinitionInput): {
147
+ paymentGuardRef: string;
148
+ issuerMode: string;
149
+ scheme: string | null;
150
+ metadata: UnknownRecord | null;
151
+ definition: UnknownRecord;
152
+ };
153
+ export declare function readXappMonetizationSnapshot(gatewayClient: GatewayPurchaseFlowClient, input: ReadXappMonetizationSnapshotInput): Promise<UnknownRecord>;
154
+ export declare function consumeXappWalletCredits(gatewayClient: GatewayPurchaseFlowClient, input: ConsumeXappWalletCreditsInput): Promise<UnknownRecord>;
155
+ export declare function startXappHostedPurchase(gatewayClient: GatewayPurchaseFlowClient, input: StartXappHostedPurchaseInput): Promise<UnknownRecord>;
156
+ export declare function finalizeXappHostedPurchase(gatewayClient: GatewayPurchaseFlowClient, input: FinalizeXappHostedPurchaseInput): Promise<UnknownRecord>;
157
+ export declare function activateXappPurchaseReference(gatewayClient: GatewayPurchaseFlowClient, input: ActivateXappPurchaseReferenceInput): Promise<UnknownRecord>;
158
+ export {};
159
+ //# sourceMappingURL=xms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xms.d.ts","sourceRoot":"","sources":["../../src/backend/xms.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7C,KAAK,gBAAgB,GAAG;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,KAAK,oBAAoB,GAAG,gBAAgB,GAAG;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,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AAsB,4BAA4B,CAChD,aAAa,EAAE,yBAAyB,EACxC,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,aAAa,CAAC,CA+CxB;AAED,wBAAsB,wBAAwB,CAC5C,aAAa,EAAE,yBAAyB,EACxC,KAAK,EAAE,6BAA6B,GACnC,OAAO,CAAC,aAAa,CAAC,CAiCxB;AAED,wBAAsB,uBAAuB,CAC3C,aAAa,EAAE,yBAAyB,EACxC,KAAK,EAAE,4BAA4B,GAClC,OAAO,CAAC,aAAa,CAAC,CAkCxB;AAED,wBAAsB,0BAA0B,CAC9C,aAAa,EAAE,yBAAyB,EACxC,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,aAAa,CAAC,CAgCxB;AAED,wBAAsB,6BAA6B,CACjD,aAAa,EAAE,yBAAyB,EACxC,KAAK,EAAE,kCAAkC,GACxC,OAAO,CAAC,aAAa,CAAC,CA0CxB"}
@@ -0,0 +1,429 @@
1
+ function readOptionalString(value) {
2
+ const normalized = String(value ?? "").trim();
3
+ return normalized ? normalized : void 0;
4
+ }
5
+ function readString(value) {
6
+ return String(value ?? "").trim();
7
+ }
8
+ function readLocalizedText(value, fallback = "") {
9
+ if (value && typeof value === "object" && !Array.isArray(value)) {
10
+ return readString(value.en) || readString(value.ro) || Object.values(value).map((item) => readString(item)).find(Boolean) || fallback;
11
+ }
12
+ return readString(value) || fallback;
13
+ }
14
+ function readMetadata(value) {
15
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
16
+ return void 0;
17
+ }
18
+ return value;
19
+ }
20
+ function requireGatewayMethod(gatewayClient, methodName) {
21
+ const method = gatewayClient[methodName];
22
+ if (typeof method !== "function") {
23
+ throw new TypeError(`gatewayClient must implement ${String(methodName)}`);
24
+ }
25
+ return method;
26
+ }
27
+ function requireIntentId(result, methodName) {
28
+ const preparedIntent = result.prepared_intent && typeof result.prepared_intent === "object" ? result.prepared_intent : null;
29
+ const intentId = readOptionalString(preparedIntent?.purchase_intent_id);
30
+ if (!intentId) {
31
+ throw new Error(`${methodName} returned a purchase intent without purchase_intent_id`);
32
+ }
33
+ return intentId;
34
+ }
35
+ function buildScopeFields(input) {
36
+ return {
37
+ ...readOptionalString(input.subjectId ?? input.subject_id) ? { subject_id: readOptionalString(input.subjectId ?? input.subject_id) } : {},
38
+ ...readOptionalString(input.installationId ?? input.installation_id) ? { installation_id: readOptionalString(input.installationId ?? input.installation_id) } : {},
39
+ ...readOptionalString(input.realmRef ?? input.realm_ref) ? { realm_ref: readOptionalString(input.realmRef ?? input.realm_ref) } : {}
40
+ };
41
+ }
42
+ function buildPreparePayload(input) {
43
+ return {
44
+ xappId: input.xappId,
45
+ offering_id: readOptionalString(input.offeringId ?? input.offering_id),
46
+ package_id: readOptionalString(input.packageId ?? input.package_id),
47
+ price_id: readOptionalString(input.priceId ?? input.price_id),
48
+ ...buildScopeFields(input),
49
+ source_kind: readOptionalString(input.sourceKind ?? input.source_kind),
50
+ source_ref: readOptionalString(input.sourceRef ?? input.source_ref),
51
+ payment_lane: readOptionalString(input.paymentLane ?? input.payment_lane),
52
+ payment_session_id: readOptionalString(input.paymentSessionId ?? input.payment_session_id),
53
+ request_id: readOptionalString(input.requestId ?? input.request_id)
54
+ };
55
+ }
56
+ function normalizeXappMonetizationScopeKind(value) {
57
+ const raw = readString(value).toLowerCase();
58
+ if (raw === "installation" || raw === "realm") return raw;
59
+ return "subject";
60
+ }
61
+ function resolveXappMonetizationScope(input) {
62
+ const scopeKind = normalizeXappMonetizationScopeKind(input.scopeKind ?? input.scope_kind);
63
+ const context = input.context && typeof input.context === "object" && !Array.isArray(input.context) ? input.context : {};
64
+ if (scopeKind === "installation") {
65
+ const installationId = readString(context.installation_id);
66
+ if (!installationId) {
67
+ throw new Error("Installation context is required for installation-scoped monetization");
68
+ }
69
+ return {
70
+ scope_kind: scopeKind,
71
+ scope_fields: { installation_id: installationId }
72
+ };
73
+ }
74
+ if (scopeKind === "realm") {
75
+ const realmRef = readString(input.realmRef ?? input.realm_ref);
76
+ if (!realmRef) {
77
+ throw new Error("realmRef is required for realm-scoped monetization");
78
+ }
79
+ return {
80
+ scope_kind: scopeKind,
81
+ scope_fields: { realm_ref: realmRef }
82
+ };
83
+ }
84
+ const subjectId = readString(context.subject_id);
85
+ if (!subjectId) {
86
+ throw new Error("Subject context is required for subject-scoped monetization");
87
+ }
88
+ return {
89
+ scope_kind: scopeKind,
90
+ scope_fields: { subject_id: subjectId }
91
+ };
92
+ }
93
+ function normalizePaymentIssuerMode(value) {
94
+ const raw = readString(value).toLowerCase();
95
+ if (raw === "gateway_managed" || raw === "tenant_delegated" || raw === "publisher_delegated" || raw === "owner_managed") {
96
+ return raw;
97
+ }
98
+ return "";
99
+ }
100
+ function formatPaymentIssuerModeLabel(issuerMode) {
101
+ const raw = normalizePaymentIssuerMode(issuerMode);
102
+ if (raw === "gateway_managed") return "Gateway managed";
103
+ if (raw === "tenant_delegated") return "Tenant delegated";
104
+ if (raw === "publisher_delegated") return "Publisher delegated";
105
+ if (raw === "owner_managed") return "Owner managed";
106
+ return "Unknown lane";
107
+ }
108
+ function formatPaymentSchemeLabel(value) {
109
+ const raw = readString(value).toLowerCase();
110
+ if (!raw) return "";
111
+ return raw.replace(/_/g, " ");
112
+ }
113
+ function buildHostedPaymentPresetDescription(definition) {
114
+ const paymentUi = readMetadata(definition.payment_ui) || {};
115
+ const copy = readMetadata(paymentUi.copy) || {};
116
+ const subtitle = readLocalizedText(copy.subtitle);
117
+ if (subtitle) return subtitle;
118
+ const title = readLocalizedText(copy.title);
119
+ if (title) return title;
120
+ const issuerMode = normalizePaymentIssuerMode(definition.payment_issuer_mode);
121
+ if (!issuerMode) return "Hosted payment lane from manifest definition.";
122
+ return `${issuerMode.replace(/_/g, " ")} hosted payment lane.`;
123
+ }
124
+ function listAcceptedPaymentSchemes(definition) {
125
+ const out = [];
126
+ const primary = readString(definition.payment_scheme).toLowerCase();
127
+ if (primary) out.push(primary);
128
+ const accepts = Array.isArray(definition.accepts) ? definition.accepts : [];
129
+ for (const item of accepts) {
130
+ if (!item || typeof item !== "object" || Array.isArray(item)) continue;
131
+ const scheme = readString(item.scheme).toLowerCase();
132
+ if (scheme && !out.includes(scheme)) out.push(scheme);
133
+ }
134
+ return out;
135
+ }
136
+ function buildHostedPaymentPresetDescriptionForScheme(definition, paymentScheme) {
137
+ const paymentUi = readMetadata(definition.payment_ui) || {};
138
+ const schemes = Array.isArray(paymentUi.schemes) ? paymentUi.schemes : [];
139
+ const schemeUi = schemes.find((item) => {
140
+ if (!item || typeof item !== "object" || Array.isArray(item)) return false;
141
+ return readString(item.scheme).toLowerCase() === paymentScheme;
142
+ });
143
+ if (schemeUi) {
144
+ const subtitle = readLocalizedText(schemeUi.subtitle);
145
+ if (subtitle) return subtitle;
146
+ const title = readLocalizedText(schemeUi.title);
147
+ if (title) return title;
148
+ }
149
+ return buildHostedPaymentPresetDescription(definition);
150
+ }
151
+ function findPaymentGuardDefinition(manifest, paymentGuardRef) {
152
+ const definitions = Array.isArray(manifest.payment_guard_definitions) ? manifest.payment_guard_definitions : Array.isArray(manifest.paymentGuardDefinitions) ? manifest.paymentGuardDefinitions : [];
153
+ for (const definition of definitions) {
154
+ if (!definition || typeof definition !== "object" || Array.isArray(definition)) continue;
155
+ if (readString(definition.name) === paymentGuardRef) {
156
+ return definition;
157
+ }
158
+ }
159
+ return null;
160
+ }
161
+ function listXappHostedPaymentPresets(input) {
162
+ const manifest = readMetadata(input.manifest) || {};
163
+ const definitions = Array.isArray(manifest.payment_guard_definitions) ? manifest.payment_guard_definitions : Array.isArray(manifest.paymentGuardDefinitions) ? manifest.paymentGuardDefinitions : [];
164
+ return definitions.flatMap((definition) => {
165
+ if (!definition || typeof definition !== "object" || Array.isArray(definition)) return null;
166
+ const record = definition;
167
+ const paymentGuardRef = readString(record.name);
168
+ const issuerMode = normalizePaymentIssuerMode(record.payment_issuer_mode);
169
+ if (!paymentGuardRef || !issuerMode) return null;
170
+ const schemes = listAcceptedPaymentSchemes(record);
171
+ return schemes.map((scheme, index) => {
172
+ const schemeLabel = formatPaymentSchemeLabel(scheme);
173
+ return {
174
+ key: `${paymentGuardRef}:${scheme || index}`,
175
+ label: schemeLabel ? `${formatPaymentIssuerModeLabel(issuerMode)} (${schemeLabel})` : formatPaymentIssuerModeLabel(issuerMode),
176
+ description: buildHostedPaymentPresetDescriptionForScheme(record, scheme),
177
+ paymentGuardRef,
178
+ paymentScheme: scheme || null,
179
+ issuerMode,
180
+ delegated: issuerMode === "tenant_delegated" || issuerMode === "publisher_delegated"
181
+ };
182
+ });
183
+ }).filter((item) => Boolean(item));
184
+ }
185
+ function findXappHostedPaymentPreset(input) {
186
+ const paymentGuardRef = readString(input.paymentGuardRef ?? input.payment_guard_ref);
187
+ const paymentScheme = readString(input.paymentScheme ?? input.payment_scheme).toLowerCase();
188
+ if (!paymentGuardRef) return null;
189
+ return listXappHostedPaymentPresets({ manifest: input.manifest }).find(
190
+ (item) => item.paymentGuardRef === paymentGuardRef && (!paymentScheme || readString(item.paymentScheme).toLowerCase() === paymentScheme)
191
+ ) || null;
192
+ }
193
+ function readDelegatedReturnSecret(issuerMode, env) {
194
+ if (issuerMode === "tenant_delegated") {
195
+ const secret_ref = readString(
196
+ env.TENANT_DELEGATED_PAYMENT_RETURN_SECRET_REF ?? env.XCONECT_TENANT_PAYMENT_RETURN_SECRET_REF ?? env.TENANT_PAYMENT_RETURN_SECRET_REF
197
+ );
198
+ const secret = readString(
199
+ env.TENANT_DELEGATED_PAYMENT_RETURN_SECRET ?? env.XCONECT_TENANT_PAYMENT_RETURN_SECRET ?? env.TENANT_PAYMENT_RETURN_SECRET
200
+ );
201
+ return {
202
+ ...secret_ref ? { secret_ref } : {},
203
+ ...secret ? { secret } : {}
204
+ };
205
+ }
206
+ if (issuerMode === "publisher_delegated") {
207
+ const secret_ref = readString(
208
+ env.PUBLISHER_DELEGATED_PAYMENT_RETURN_SECRET_REF ?? env.PUBLISHER_PAYMENT_RETURN_SECRET_REF
209
+ );
210
+ const secret = readString(
211
+ env.PUBLISHER_DELEGATED_PAYMENT_RETURN_SECRET ?? env.PUBLISHER_PAYMENT_RETURN_SECRET
212
+ );
213
+ return {
214
+ ...secret_ref ? { secret_ref } : {},
215
+ ...secret ? { secret } : {}
216
+ };
217
+ }
218
+ return {};
219
+ }
220
+ function resolveXappHostedPaymentDefinition(input) {
221
+ const paymentGuardRef = readString(input.paymentGuardRef ?? input.payment_guard_ref);
222
+ if (!paymentGuardRef) {
223
+ throw new Error("paymentGuardRef is required");
224
+ }
225
+ const definition = findPaymentGuardDefinition(input.manifest, paymentGuardRef);
226
+ if (!definition) {
227
+ throw new Error("Unknown payment lane. Choose one of the configured payment definitions.");
228
+ }
229
+ const issuerMode = normalizePaymentIssuerMode(definition.payment_issuer_mode);
230
+ if (!issuerMode) {
231
+ throw new Error(`Unsupported payment issuer mode for ${paymentGuardRef}`);
232
+ }
233
+ const requestedScheme = readString(input.paymentScheme ?? input.payment_scheme).toLowerCase();
234
+ const supportedSchemes = listAcceptedPaymentSchemes(definition);
235
+ const scheme = requestedScheme || supportedSchemes[0] || null;
236
+ if (requestedScheme && !supportedSchemes.includes(requestedScheme)) {
237
+ throw new Error(`Unsupported payment scheme ${requestedScheme} for ${paymentGuardRef}`);
238
+ }
239
+ const env = input.env || {};
240
+ if (issuerMode === "tenant_delegated" || issuerMode === "publisher_delegated") {
241
+ const signingSecret = readDelegatedReturnSecret(issuerMode, env);
242
+ if (!signingSecret.secret_ref && !signingSecret.secret) {
243
+ throw new Error(
244
+ issuerMode === "tenant_delegated" ? "Tenant-delegated payment return secret or secret ref is not configured." : "Publisher-delegated payment return secret or secret ref is not configured."
245
+ );
246
+ }
247
+ return {
248
+ paymentGuardRef,
249
+ issuerMode,
250
+ scheme,
251
+ definition,
252
+ metadata: {
253
+ payment_return_signing: {
254
+ issuer: issuerMode,
255
+ signing_lane: issuerMode,
256
+ resolver_source: "session_metadata_delegated",
257
+ ...signingSecret
258
+ }
259
+ }
260
+ };
261
+ }
262
+ return {
263
+ paymentGuardRef,
264
+ issuerMode,
265
+ scheme,
266
+ definition,
267
+ metadata: null
268
+ };
269
+ }
270
+ function buildSnapshotScopePayload(input) {
271
+ return {
272
+ xappId: input.xappId,
273
+ ...buildScopeFields(input)
274
+ };
275
+ }
276
+ async function readXappMonetizationSnapshot(gatewayClient, input) {
277
+ const getMonetizationAccess = requireGatewayMethod(gatewayClient, "getXappMonetizationAccess");
278
+ const getCurrentSubscription = requireGatewayMethod(gatewayClient, "getXappCurrentSubscription");
279
+ const listWalletAccounts = requireGatewayMethod(gatewayClient, "listXappWalletAccounts");
280
+ const scopePayload = buildSnapshotScopePayload(input);
281
+ const includeWalletAccounts = input.includeWalletAccounts !== false;
282
+ const includeWalletLedger = input.includeWalletLedger === true;
283
+ const [accessResult, currentSubscriptionResult, walletAccountsResult, walletLedgerResult] = await Promise.all([
284
+ getMonetizationAccess(scopePayload),
285
+ getCurrentSubscription(scopePayload),
286
+ includeWalletAccounts ? listWalletAccounts(scopePayload) : Promise.resolve(null),
287
+ includeWalletLedger ? requireGatewayMethod(
288
+ gatewayClient,
289
+ "listXappWalletLedger"
290
+ )({
291
+ xappId: input.xappId,
292
+ ...buildScopeFields(input),
293
+ wallet_account_id: readOptionalString(input.walletAccountId ?? input.wallet_account_id),
294
+ payment_session_id: readOptionalString(
295
+ input.paymentSessionId ?? input.payment_session_id
296
+ ),
297
+ request_id: readOptionalString(input.requestId ?? input.request_id),
298
+ settlement_ref: readOptionalString(input.settlementRef ?? input.settlement_ref)
299
+ }) : Promise.resolve(null)
300
+ ]);
301
+ return {
302
+ access_projection: accessResult?.access_projection && typeof accessResult.access_projection === "object" ? accessResult.access_projection : null,
303
+ current_subscription: currentSubscriptionResult?.current_subscription && typeof currentSubscriptionResult.current_subscription === "object" ? currentSubscriptionResult.current_subscription : null,
304
+ wallet_accounts: walletAccountsResult && Array.isArray(walletAccountsResult.items) ? walletAccountsResult.items : [],
305
+ wallet_ledger: walletLedgerResult && Array.isArray(walletLedgerResult.items) ? walletLedgerResult.items : []
306
+ };
307
+ }
308
+ async function consumeXappWalletCredits(gatewayClient, input) {
309
+ const consumeWalletCredits = requireGatewayMethod(gatewayClient, "consumeXappWalletCredits");
310
+ const walletAccountId = readOptionalString(input.walletAccountId ?? input.wallet_account_id);
311
+ if (!walletAccountId) {
312
+ throw new Error("walletAccountId is required");
313
+ }
314
+ const amount = readString(input.amount);
315
+ if (!amount) {
316
+ throw new Error("amount is required");
317
+ }
318
+ const consumed = await consumeWalletCredits({
319
+ xappId: input.xappId,
320
+ walletAccountId,
321
+ amount,
322
+ source_ref: readOptionalString(input.sourceRef ?? input.source_ref),
323
+ metadata: readMetadata(input.metadata)
324
+ });
325
+ return {
326
+ wallet_account: consumed?.wallet_account && typeof consumed.wallet_account === "object" ? consumed.wallet_account : null,
327
+ wallet_ledger: consumed?.wallet_ledger && typeof consumed.wallet_ledger === "object" ? consumed.wallet_ledger : null,
328
+ access_projection: consumed?.access_projection && typeof consumed.access_projection === "object" ? consumed.access_projection : null,
329
+ snapshot_id: readOptionalString(consumed?.snapshot_id) ?? null,
330
+ consumed
331
+ };
332
+ }
333
+ async function startXappHostedPurchase(gatewayClient, input) {
334
+ const preparePurchaseIntent = requireGatewayMethod(gatewayClient, "prepareXappPurchaseIntent");
335
+ const createPurchasePaymentSession = requireGatewayMethod(
336
+ gatewayClient,
337
+ "createXappPurchasePaymentSession"
338
+ );
339
+ const prepared = await preparePurchaseIntent(buildPreparePayload(input));
340
+ const intentId = requireIntentId(prepared, "prepareXappPurchaseIntent");
341
+ const paymentSession = await createPurchasePaymentSession({
342
+ xappId: input.xappId,
343
+ intentId,
344
+ payment_guard_ref: readOptionalString(input.paymentGuardRef ?? input.payment_guard_ref),
345
+ issuer: readOptionalString(input.issuer),
346
+ scheme: readOptionalString(input.scheme),
347
+ payment_scheme: readOptionalString(input.paymentScheme ?? input.payment_scheme),
348
+ return_url: readOptionalString(input.returnUrl ?? input.return_url),
349
+ cancel_url: readOptionalString(input.cancelUrl ?? input.cancel_url),
350
+ xapps_resume: readOptionalString(input.xappsResume ?? input.xapps_resume),
351
+ page_url: readOptionalString(input.pageUrl ?? input.page_url),
352
+ locale: readOptionalString(input.locale),
353
+ ...buildScopeFields(input),
354
+ metadata: readMetadata(input.metadata)
355
+ });
356
+ return {
357
+ prepared_intent: prepared?.prepared_intent && typeof prepared.prepared_intent === "object" ? prepared.prepared_intent : null,
358
+ payment_session: paymentSession?.payment_session && typeof paymentSession.payment_session === "object" ? paymentSession.payment_session : null,
359
+ payment_page_url: readOptionalString(paymentSession?.payment_page_url) ?? null
360
+ };
361
+ }
362
+ async function finalizeXappHostedPurchase(gatewayClient, input) {
363
+ const finalizePurchasePaymentSession = requireGatewayMethod(
364
+ gatewayClient,
365
+ "finalizeXappPurchasePaymentSession"
366
+ );
367
+ const intentId = readOptionalString(input.intentId ?? input.intent_id);
368
+ if (!intentId) {
369
+ throw new Error("intentId is required");
370
+ }
371
+ const finalized = await finalizePurchasePaymentSession({
372
+ xappId: input.xappId,
373
+ intentId
374
+ });
375
+ return {
376
+ prepared_intent: finalized?.prepared_intent && typeof finalized.prepared_intent === "object" ? finalized.prepared_intent : null,
377
+ payment_session: finalized?.payment_session && typeof finalized.payment_session === "object" ? finalized.payment_session : null,
378
+ transaction: finalized?.transaction && typeof finalized.transaction === "object" ? finalized.transaction : null,
379
+ access_projection: finalized?.access_projection && typeof finalized.access_projection === "object" ? finalized.access_projection : null,
380
+ issued: finalized
381
+ };
382
+ }
383
+ async function activateXappPurchaseReference(gatewayClient, input) {
384
+ const preparePurchaseIntent = requireGatewayMethod(gatewayClient, "prepareXappPurchaseIntent");
385
+ const createPurchaseTransaction = requireGatewayMethod(
386
+ gatewayClient,
387
+ "createXappPurchaseTransaction"
388
+ );
389
+ const issuePurchaseAccess = requireGatewayMethod(gatewayClient, "issueXappPurchaseAccess");
390
+ const prepared = await preparePurchaseIntent(buildPreparePayload(input));
391
+ const intentId = requireIntentId(prepared, "prepareXappPurchaseIntent");
392
+ const preparedIntent = prepared?.prepared_intent && typeof prepared.prepared_intent === "object" ? prepared.prepared_intent : null;
393
+ const preparedPrice = preparedIntent?.price && typeof preparedIntent.price === "object" ? preparedIntent.price : null;
394
+ const transaction = await createPurchaseTransaction({
395
+ xappId: input.xappId,
396
+ intentId,
397
+ status: readOptionalString(input.status) ?? "verified",
398
+ provider_ref: readOptionalString(input.providerRef ?? input.provider_ref),
399
+ evidence_ref: readOptionalString(input.evidenceRef ?? input.evidence_ref),
400
+ payment_session_id: readOptionalString(input.paymentSessionId ?? input.payment_session_id),
401
+ request_id: readOptionalString(input.requestId ?? input.request_id),
402
+ settlement_ref: readOptionalString(input.settlementRef ?? input.settlement_ref),
403
+ amount: input.amount ?? preparedPrice?.amount ?? void 0,
404
+ currency: readOptionalString(input.currency) ?? readOptionalString(preparedPrice?.currency),
405
+ occurred_at: readOptionalString(input.occurredAt ?? input.occurred_at)
406
+ });
407
+ const issued = await issuePurchaseAccess({
408
+ xappId: input.xappId,
409
+ intentId
410
+ });
411
+ return {
412
+ prepared_intent: preparedIntent,
413
+ transaction: transaction?.transaction && typeof transaction.transaction === "object" ? transaction.transaction : null,
414
+ issued
415
+ };
416
+ }
417
+ export {
418
+ activateXappPurchaseReference,
419
+ consumeXappWalletCredits,
420
+ finalizeXappHostedPurchase,
421
+ findXappHostedPaymentPreset,
422
+ listXappHostedPaymentPresets,
423
+ normalizeXappMonetizationScopeKind,
424
+ readXappMonetizationSnapshot,
425
+ resolveXappHostedPaymentDefinition,
426
+ resolveXappMonetizationScope,
427
+ startXappHostedPurchase
428
+ };
429
+ //# sourceMappingURL=xms.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/backend/xms.ts"],
4
+ "sourcesContent": ["type UnknownRecord = Record<string, unknown>;\n\ntype ScopeFieldsInput = {\n subjectId?: string | null;\n subject_id?: string | null;\n installationId?: string | null;\n installation_id?: string | null;\n realmRef?: string | null;\n realm_ref?: string | null;\n};\n\ntype PreparePurchaseInput = ScopeFieldsInput & {\n xappId: string;\n offeringId?: string | null;\n offering_id?: string | null;\n packageId?: string | null;\n package_id?: string | null;\n priceId?: string | null;\n price_id?: string | null;\n sourceKind?: string | null;\n source_kind?: string | null;\n sourceRef?: string | null;\n source_ref?: string | null;\n paymentLane?: string | null;\n payment_lane?: string | null;\n paymentSessionId?: string | null;\n payment_session_id?: string | null;\n requestId?: string | null;\n request_id?: string | null;\n};\n\nexport type StartXappHostedPurchaseInput = PreparePurchaseInput & {\n paymentGuardRef?: string | null;\n payment_guard_ref?: string | null;\n issuer?: string | null;\n scheme?: string | null;\n paymentScheme?: string | null;\n payment_scheme?: string | null;\n returnUrl?: string | null;\n return_url?: string | null;\n cancelUrl?: string | null;\n cancel_url?: string | null;\n xappsResume?: string | null;\n xapps_resume?: string | null;\n pageUrl?: string | null;\n page_url?: string | null;\n locale?: string | null;\n metadata?: UnknownRecord | null;\n};\n\nexport type FinalizeXappHostedPurchaseInput = {\n xappId: string;\n intentId?: string | null;\n intent_id?: string | null;\n};\n\nexport type ActivateXappPurchaseReferenceInput = PreparePurchaseInput & {\n status?: string | null;\n providerRef?: string | null;\n provider_ref?: string | null;\n evidenceRef?: string | null;\n evidence_ref?: string | null;\n settlementRef?: string | null;\n settlement_ref?: string | null;\n amount?: string | number | null;\n currency?: string | null;\n occurredAt?: string | null;\n occurred_at?: string | null;\n};\n\nexport type ReadXappMonetizationSnapshotInput = ScopeFieldsInput & {\n xappId: string;\n includeWalletAccounts?: boolean | null;\n includeWalletLedger?: boolean | null;\n walletAccountId?: string | null;\n wallet_account_id?: string | null;\n paymentSessionId?: string | null;\n payment_session_id?: string | null;\n requestId?: string | null;\n request_id?: string | null;\n settlementRef?: string | null;\n settlement_ref?: string | null;\n};\n\nexport type ConsumeXappWalletCreditsInput = {\n xappId: string;\n walletAccountId?: string | null;\n wallet_account_id?: string | null;\n amount: string;\n sourceRef?: string | null;\n source_ref?: string | null;\n metadata?: UnknownRecord | null;\n};\n\nexport type ResolveXappMonetizationScopeInput = {\n scopeKind?: string | null;\n scope_kind?: string | null;\n context?: UnknownRecord | null;\n realmRef?: string | null;\n realm_ref?: string | null;\n};\n\nexport type ResolveXappHostedPaymentDefinitionInput = {\n manifest: UnknownRecord;\n paymentGuardRef?: string | null;\n payment_guard_ref?: string | null;\n paymentScheme?: string | null;\n payment_scheme?: string | null;\n env?: Record<string, string | undefined>;\n};\n\nexport type ListXappHostedPaymentPresetsInput = {\n manifest: UnknownRecord;\n};\n\ntype GatewayPurchaseFlowClient = {\n prepareXappPurchaseIntent: (input: UnknownRecord) => Promise<UnknownRecord>;\n createXappPurchasePaymentSession?: (input: UnknownRecord) => Promise<UnknownRecord>;\n reconcileXappPurchasePaymentSession?: (input: UnknownRecord) => Promise<UnknownRecord>;\n finalizeXappPurchasePaymentSession?: (input: UnknownRecord) => Promise<UnknownRecord>;\n issueXappPurchaseAccess?: (input: UnknownRecord) => Promise<UnknownRecord>;\n createXappPurchaseTransaction?: (input: UnknownRecord) => Promise<UnknownRecord>;\n getXappMonetizationAccess?: (input: UnknownRecord) => Promise<UnknownRecord>;\n getXappCurrentSubscription?: (input: UnknownRecord) => Promise<UnknownRecord>;\n listXappWalletAccounts?: (input: UnknownRecord) => Promise<UnknownRecord>;\n listXappWalletLedger?: (input: UnknownRecord) => Promise<UnknownRecord>;\n consumeXappWalletCredits?: (input: UnknownRecord) => Promise<UnknownRecord>;\n};\n\nfunction readOptionalString(value: unknown): string | undefined {\n const normalized = String(value ?? \"\").trim();\n return normalized ? normalized : undefined;\n}\n\nfunction readString(value: unknown): string {\n return String(value ?? \"\").trim();\n}\n\nfunction readLocalizedText(value: unknown, fallback = \"\"): string {\n if (value && typeof value === \"object\" && !Array.isArray(value)) {\n return (\n readString((value as UnknownRecord).en) ||\n readString((value as UnknownRecord).ro) ||\n Object.values(value as UnknownRecord)\n .map((item) => readString(item))\n .find(Boolean) ||\n fallback\n );\n }\n return readString(value) || fallback;\n}\n\nfunction readMetadata(value: unknown): UnknownRecord | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as UnknownRecord;\n}\n\nfunction requireGatewayMethod<T extends keyof GatewayPurchaseFlowClient>(\n gatewayClient: GatewayPurchaseFlowClient,\n methodName: T,\n): NonNullable<GatewayPurchaseFlowClient[T]> {\n const method = gatewayClient[methodName];\n if (typeof method !== \"function\") {\n throw new TypeError(`gatewayClient must implement ${String(methodName)}`);\n }\n return method as NonNullable<GatewayPurchaseFlowClient[T]>;\n}\n\nfunction requireIntentId(result: UnknownRecord, methodName: string): string {\n const preparedIntent =\n result.prepared_intent && typeof result.prepared_intent === \"object\"\n ? (result.prepared_intent as UnknownRecord)\n : null;\n const intentId = readOptionalString(preparedIntent?.purchase_intent_id);\n if (!intentId) {\n throw new Error(`${methodName} returned a purchase intent without purchase_intent_id`);\n }\n return intentId;\n}\n\nfunction buildScopeFields(input: ScopeFieldsInput): UnknownRecord {\n return {\n ...(readOptionalString(input.subjectId ?? input.subject_id)\n ? { subject_id: readOptionalString(input.subjectId ?? input.subject_id) }\n : {}),\n ...(readOptionalString(input.installationId ?? input.installation_id)\n ? { installation_id: readOptionalString(input.installationId ?? input.installation_id) }\n : {}),\n ...(readOptionalString(input.realmRef ?? input.realm_ref)\n ? { realm_ref: readOptionalString(input.realmRef ?? input.realm_ref) }\n : {}),\n };\n}\n\nfunction buildPreparePayload(input: PreparePurchaseInput): UnknownRecord {\n return {\n xappId: input.xappId,\n offering_id: readOptionalString(input.offeringId ?? input.offering_id),\n package_id: readOptionalString(input.packageId ?? input.package_id),\n price_id: readOptionalString(input.priceId ?? input.price_id),\n ...buildScopeFields(input),\n source_kind: readOptionalString(input.sourceKind ?? input.source_kind),\n source_ref: readOptionalString(input.sourceRef ?? input.source_ref),\n payment_lane: readOptionalString(input.paymentLane ?? input.payment_lane),\n payment_session_id: readOptionalString(input.paymentSessionId ?? input.payment_session_id),\n request_id: readOptionalString(input.requestId ?? input.request_id),\n };\n}\n\nexport function normalizeXappMonetizationScopeKind(\n value: unknown,\n): \"subject\" | \"installation\" | \"realm\" {\n const raw = readString(value).toLowerCase();\n if (raw === \"installation\" || raw === \"realm\") return raw;\n return \"subject\";\n}\n\nexport function resolveXappMonetizationScope(input: ResolveXappMonetizationScopeInput): {\n scope_kind: \"subject\" | \"installation\" | \"realm\";\n scope_fields: UnknownRecord;\n} {\n const scopeKind = normalizeXappMonetizationScopeKind(input.scopeKind ?? input.scope_kind);\n const context =\n input.context && typeof input.context === \"object\" && !Array.isArray(input.context)\n ? input.context\n : {};\n if (scopeKind === \"installation\") {\n const installationId = readString(context.installation_id);\n if (!installationId) {\n throw new Error(\"Installation context is required for installation-scoped monetization\");\n }\n return {\n scope_kind: scopeKind,\n scope_fields: { installation_id: installationId },\n };\n }\n if (scopeKind === \"realm\") {\n const realmRef = readString(input.realmRef ?? input.realm_ref);\n if (!realmRef) {\n throw new Error(\"realmRef is required for realm-scoped monetization\");\n }\n return {\n scope_kind: scopeKind,\n scope_fields: { realm_ref: realmRef },\n };\n }\n const subjectId = readString(context.subject_id);\n if (!subjectId) {\n throw new Error(\"Subject context is required for subject-scoped monetization\");\n }\n return {\n scope_kind: scopeKind,\n scope_fields: { subject_id: subjectId },\n };\n}\n\nfunction normalizePaymentIssuerMode(value: unknown): string {\n const raw = readString(value).toLowerCase();\n if (\n raw === \"gateway_managed\" ||\n raw === \"tenant_delegated\" ||\n raw === \"publisher_delegated\" ||\n raw === \"owner_managed\"\n ) {\n return raw;\n }\n return \"\";\n}\n\nfunction formatPaymentIssuerModeLabel(issuerMode: string) {\n const raw = normalizePaymentIssuerMode(issuerMode);\n if (raw === \"gateway_managed\") return \"Gateway managed\";\n if (raw === \"tenant_delegated\") return \"Tenant delegated\";\n if (raw === \"publisher_delegated\") return \"Publisher delegated\";\n if (raw === \"owner_managed\") return \"Owner managed\";\n return \"Unknown lane\";\n}\n\nfunction formatPaymentSchemeLabel(value: unknown) {\n const raw = readString(value).toLowerCase();\n if (!raw) return \"\";\n return raw.replace(/_/g, \" \");\n}\n\nfunction buildHostedPaymentPresetDescription(definition: UnknownRecord) {\n const paymentUi = readMetadata(definition.payment_ui) || {};\n const copy = readMetadata(paymentUi.copy) || {};\n const subtitle = readLocalizedText(copy.subtitle);\n if (subtitle) return subtitle;\n const title = readLocalizedText(copy.title);\n if (title) return title;\n const issuerMode = normalizePaymentIssuerMode(definition.payment_issuer_mode);\n if (!issuerMode) return \"Hosted payment lane from manifest definition.\";\n return `${issuerMode.replace(/_/g, \" \")} hosted payment lane.`;\n}\n\nfunction listAcceptedPaymentSchemes(definition: UnknownRecord): string[] {\n const out: string[] = [];\n const primary = readString(definition.payment_scheme).toLowerCase();\n if (primary) out.push(primary);\n const accepts = Array.isArray(definition.accepts) ? definition.accepts : [];\n for (const item of accepts) {\n if (!item || typeof item !== \"object\" || Array.isArray(item)) continue;\n const scheme = readString((item as UnknownRecord).scheme).toLowerCase();\n if (scheme && !out.includes(scheme)) out.push(scheme);\n }\n return out;\n}\n\nfunction buildHostedPaymentPresetDescriptionForScheme(\n definition: UnknownRecord,\n paymentScheme: string,\n) {\n const paymentUi = readMetadata(definition.payment_ui) || {};\n const schemes = Array.isArray(paymentUi.schemes) ? paymentUi.schemes : [];\n const schemeUi = schemes.find((item) => {\n if (!item || typeof item !== \"object\" || Array.isArray(item)) return false;\n return readString((item as UnknownRecord).scheme).toLowerCase() === paymentScheme;\n }) as UnknownRecord | undefined;\n if (schemeUi) {\n const subtitle = readLocalizedText(schemeUi.subtitle);\n if (subtitle) return subtitle;\n const title = readLocalizedText(schemeUi.title);\n if (title) return title;\n }\n return buildHostedPaymentPresetDescription(definition);\n}\n\nfunction findPaymentGuardDefinition(\n manifest: UnknownRecord,\n paymentGuardRef: string,\n): UnknownRecord | null {\n const definitions = Array.isArray(manifest.payment_guard_definitions)\n ? manifest.payment_guard_definitions\n : Array.isArray((manifest as any).paymentGuardDefinitions)\n ? ((manifest as any).paymentGuardDefinitions as unknown[])\n : [];\n for (const definition of definitions) {\n if (!definition || typeof definition !== \"object\" || Array.isArray(definition)) continue;\n if (readString((definition as UnknownRecord).name) === paymentGuardRef) {\n return definition as UnknownRecord;\n }\n }\n return null;\n}\n\nexport function listXappHostedPaymentPresets(input: ListXappHostedPaymentPresetsInput): Array<{\n key: string;\n label: string;\n description: string;\n paymentGuardRef: string;\n paymentScheme: string | null;\n issuerMode: string;\n delegated: boolean;\n}> {\n const manifest = readMetadata(input.manifest) || {};\n const definitions = Array.isArray(manifest.payment_guard_definitions)\n ? manifest.payment_guard_definitions\n : Array.isArray((manifest as any).paymentGuardDefinitions)\n ? ((manifest as any).paymentGuardDefinitions as unknown[])\n : [];\n return definitions\n .flatMap((definition) => {\n if (!definition || typeof definition !== \"object\" || Array.isArray(definition)) return null;\n const record = definition as UnknownRecord;\n const paymentGuardRef = readString(record.name);\n const issuerMode = normalizePaymentIssuerMode(record.payment_issuer_mode);\n if (!paymentGuardRef || !issuerMode) return null;\n const schemes = listAcceptedPaymentSchemes(record);\n return schemes.map((scheme, index) => {\n const schemeLabel = formatPaymentSchemeLabel(scheme);\n return {\n key: `${paymentGuardRef}:${scheme || index}`,\n label: schemeLabel\n ? `${formatPaymentIssuerModeLabel(issuerMode)} (${schemeLabel})`\n : formatPaymentIssuerModeLabel(issuerMode),\n description: buildHostedPaymentPresetDescriptionForScheme(record, scheme),\n paymentGuardRef,\n paymentScheme: scheme || null,\n issuerMode,\n delegated: issuerMode === \"tenant_delegated\" || issuerMode === \"publisher_delegated\",\n };\n });\n })\n .filter((item): item is NonNullable<typeof item> => Boolean(item));\n}\n\nexport function findXappHostedPaymentPreset(\n input: ListXappHostedPaymentPresetsInput & {\n paymentGuardRef?: string | null;\n payment_guard_ref?: string | null;\n paymentScheme?: string | null;\n payment_scheme?: string | null;\n },\n) {\n const paymentGuardRef = readString(input.paymentGuardRef ?? input.payment_guard_ref);\n const paymentScheme = readString(input.paymentScheme ?? input.payment_scheme).toLowerCase();\n if (!paymentGuardRef) return null;\n return (\n listXappHostedPaymentPresets({ manifest: input.manifest }).find(\n (item) =>\n item.paymentGuardRef === paymentGuardRef &&\n (!paymentScheme || readString(item.paymentScheme).toLowerCase() === paymentScheme),\n ) || null\n );\n}\n\nfunction readDelegatedReturnSecret(\n issuerMode: string,\n env: Record<string, string | undefined>,\n): { secret?: string; secret_ref?: string } {\n if (issuerMode === \"tenant_delegated\") {\n const secret_ref = readString(\n env.TENANT_DELEGATED_PAYMENT_RETURN_SECRET_REF ??\n env.XCONECT_TENANT_PAYMENT_RETURN_SECRET_REF ??\n env.TENANT_PAYMENT_RETURN_SECRET_REF,\n );\n const secret = readString(\n env.TENANT_DELEGATED_PAYMENT_RETURN_SECRET ??\n env.XCONECT_TENANT_PAYMENT_RETURN_SECRET ??\n env.TENANT_PAYMENT_RETURN_SECRET,\n );\n return {\n ...(secret_ref ? { secret_ref } : {}),\n ...(secret ? { secret } : {}),\n };\n }\n if (issuerMode === \"publisher_delegated\") {\n const secret_ref = readString(\n env.PUBLISHER_DELEGATED_PAYMENT_RETURN_SECRET_REF ?? env.PUBLISHER_PAYMENT_RETURN_SECRET_REF,\n );\n const secret = readString(\n env.PUBLISHER_DELEGATED_PAYMENT_RETURN_SECRET ?? env.PUBLISHER_PAYMENT_RETURN_SECRET,\n );\n return {\n ...(secret_ref ? { secret_ref } : {}),\n ...(secret ? { secret } : {}),\n };\n }\n return {};\n}\n\nexport function resolveXappHostedPaymentDefinition(\n input: ResolveXappHostedPaymentDefinitionInput,\n): {\n paymentGuardRef: string;\n issuerMode: string;\n scheme: string | null;\n metadata: UnknownRecord | null;\n definition: UnknownRecord;\n} {\n const paymentGuardRef = readString(input.paymentGuardRef ?? input.payment_guard_ref);\n if (!paymentGuardRef) {\n throw new Error(\"paymentGuardRef is required\");\n }\n const definition = findPaymentGuardDefinition(input.manifest, paymentGuardRef);\n if (!definition) {\n throw new Error(\"Unknown payment lane. Choose one of the configured payment definitions.\");\n }\n const issuerMode = normalizePaymentIssuerMode(definition.payment_issuer_mode);\n if (!issuerMode) {\n throw new Error(`Unsupported payment issuer mode for ${paymentGuardRef}`);\n }\n const requestedScheme = readString(input.paymentScheme ?? input.payment_scheme).toLowerCase();\n const supportedSchemes = listAcceptedPaymentSchemes(definition);\n const scheme = requestedScheme || supportedSchemes[0] || null;\n if (requestedScheme && !supportedSchemes.includes(requestedScheme)) {\n throw new Error(`Unsupported payment scheme ${requestedScheme} for ${paymentGuardRef}`);\n }\n const env = input.env || {};\n if (issuerMode === \"tenant_delegated\" || issuerMode === \"publisher_delegated\") {\n const signingSecret = readDelegatedReturnSecret(issuerMode, env);\n if (!signingSecret.secret_ref && !signingSecret.secret) {\n throw new Error(\n issuerMode === \"tenant_delegated\"\n ? \"Tenant-delegated payment return secret or secret ref is not configured.\"\n : \"Publisher-delegated payment return secret or secret ref is not configured.\",\n );\n }\n return {\n paymentGuardRef,\n issuerMode,\n scheme,\n definition,\n metadata: {\n payment_return_signing: {\n issuer: issuerMode,\n signing_lane: issuerMode,\n resolver_source: \"session_metadata_delegated\",\n ...signingSecret,\n },\n },\n };\n }\n return {\n paymentGuardRef,\n issuerMode,\n scheme,\n definition,\n metadata: null,\n };\n}\n\nfunction buildSnapshotScopePayload(input: ScopeFieldsInput & { xappId: string }): UnknownRecord {\n return {\n xappId: input.xappId,\n ...buildScopeFields(input),\n };\n}\n\nexport async function readXappMonetizationSnapshot(\n gatewayClient: GatewayPurchaseFlowClient,\n input: ReadXappMonetizationSnapshotInput,\n): Promise<UnknownRecord> {\n const getMonetizationAccess = requireGatewayMethod(gatewayClient, \"getXappMonetizationAccess\");\n const getCurrentSubscription = requireGatewayMethod(gatewayClient, \"getXappCurrentSubscription\");\n const listWalletAccounts = requireGatewayMethod(gatewayClient, \"listXappWalletAccounts\");\n const scopePayload = buildSnapshotScopePayload(input);\n const includeWalletAccounts = input.includeWalletAccounts !== false;\n const includeWalletLedger = input.includeWalletLedger === true;\n\n const [accessResult, currentSubscriptionResult, walletAccountsResult, walletLedgerResult] =\n await Promise.all([\n getMonetizationAccess(scopePayload),\n getCurrentSubscription(scopePayload),\n includeWalletAccounts ? listWalletAccounts(scopePayload) : Promise.resolve(null),\n includeWalletLedger\n ? requireGatewayMethod(\n gatewayClient,\n \"listXappWalletLedger\",\n )({\n xappId: input.xappId,\n ...buildScopeFields(input),\n wallet_account_id: readOptionalString(input.walletAccountId ?? input.wallet_account_id),\n payment_session_id: readOptionalString(\n input.paymentSessionId ?? input.payment_session_id,\n ),\n request_id: readOptionalString(input.requestId ?? input.request_id),\n settlement_ref: readOptionalString(input.settlementRef ?? input.settlement_ref),\n })\n : Promise.resolve(null),\n ]);\n\n return {\n access_projection:\n accessResult?.access_projection && typeof accessResult.access_projection === \"object\"\n ? accessResult.access_projection\n : null,\n current_subscription:\n currentSubscriptionResult?.current_subscription &&\n typeof currentSubscriptionResult.current_subscription === \"object\"\n ? currentSubscriptionResult.current_subscription\n : null,\n wallet_accounts:\n walletAccountsResult && Array.isArray(walletAccountsResult.items)\n ? walletAccountsResult.items\n : [],\n wallet_ledger:\n walletLedgerResult && Array.isArray(walletLedgerResult.items) ? walletLedgerResult.items : [],\n };\n}\n\nexport async function consumeXappWalletCredits(\n gatewayClient: GatewayPurchaseFlowClient,\n input: ConsumeXappWalletCreditsInput,\n): Promise<UnknownRecord> {\n const consumeWalletCredits = requireGatewayMethod(gatewayClient, \"consumeXappWalletCredits\");\n const walletAccountId = readOptionalString(input.walletAccountId ?? input.wallet_account_id);\n if (!walletAccountId) {\n throw new Error(\"walletAccountId is required\");\n }\n const amount = readString(input.amount);\n if (!amount) {\n throw new Error(\"amount is required\");\n }\n const consumed = await consumeWalletCredits({\n xappId: input.xappId,\n walletAccountId,\n amount,\n source_ref: readOptionalString(input.sourceRef ?? input.source_ref),\n metadata: readMetadata(input.metadata),\n });\n return {\n wallet_account:\n consumed?.wallet_account && typeof consumed.wallet_account === \"object\"\n ? consumed.wallet_account\n : null,\n wallet_ledger:\n consumed?.wallet_ledger && typeof consumed.wallet_ledger === \"object\"\n ? consumed.wallet_ledger\n : null,\n access_projection:\n consumed?.access_projection && typeof consumed.access_projection === \"object\"\n ? consumed.access_projection\n : null,\n snapshot_id: readOptionalString(consumed?.snapshot_id) ?? null,\n consumed,\n };\n}\n\nexport async function startXappHostedPurchase(\n gatewayClient: GatewayPurchaseFlowClient,\n input: StartXappHostedPurchaseInput,\n): Promise<UnknownRecord> {\n const preparePurchaseIntent = requireGatewayMethod(gatewayClient, \"prepareXappPurchaseIntent\");\n const createPurchasePaymentSession = requireGatewayMethod(\n gatewayClient,\n \"createXappPurchasePaymentSession\",\n );\n const prepared = await preparePurchaseIntent(buildPreparePayload(input));\n const intentId = requireIntentId(prepared, \"prepareXappPurchaseIntent\");\n const paymentSession = await createPurchasePaymentSession({\n xappId: input.xappId,\n intentId,\n payment_guard_ref: readOptionalString(input.paymentGuardRef ?? input.payment_guard_ref),\n issuer: readOptionalString(input.issuer),\n scheme: readOptionalString(input.scheme),\n payment_scheme: readOptionalString(input.paymentScheme ?? input.payment_scheme),\n return_url: readOptionalString(input.returnUrl ?? input.return_url),\n cancel_url: readOptionalString(input.cancelUrl ?? input.cancel_url),\n xapps_resume: readOptionalString(input.xappsResume ?? input.xapps_resume),\n page_url: readOptionalString(input.pageUrl ?? input.page_url),\n locale: readOptionalString(input.locale),\n ...buildScopeFields(input),\n metadata: readMetadata(input.metadata),\n });\n return {\n prepared_intent:\n prepared?.prepared_intent && typeof prepared.prepared_intent === \"object\"\n ? prepared.prepared_intent\n : null,\n payment_session:\n paymentSession?.payment_session && typeof paymentSession.payment_session === \"object\"\n ? paymentSession.payment_session\n : null,\n payment_page_url: readOptionalString(paymentSession?.payment_page_url) ?? null,\n };\n}\n\nexport async function finalizeXappHostedPurchase(\n gatewayClient: GatewayPurchaseFlowClient,\n input: FinalizeXappHostedPurchaseInput,\n): Promise<UnknownRecord> {\n const finalizePurchasePaymentSession = requireGatewayMethod(\n gatewayClient,\n \"finalizeXappPurchasePaymentSession\",\n );\n const intentId = readOptionalString(input.intentId ?? input.intent_id);\n if (!intentId) {\n throw new Error(\"intentId is required\");\n }\n const finalized = await finalizePurchasePaymentSession({\n xappId: input.xappId,\n intentId,\n });\n return {\n prepared_intent:\n finalized?.prepared_intent && typeof finalized.prepared_intent === \"object\"\n ? finalized.prepared_intent\n : null,\n payment_session:\n finalized?.payment_session && typeof finalized.payment_session === \"object\"\n ? finalized.payment_session\n : null,\n transaction:\n finalized?.transaction && typeof finalized.transaction === \"object\"\n ? finalized.transaction\n : null,\n access_projection:\n finalized?.access_projection && typeof finalized.access_projection === \"object\"\n ? finalized.access_projection\n : null,\n issued: finalized,\n };\n}\n\nexport async function activateXappPurchaseReference(\n gatewayClient: GatewayPurchaseFlowClient,\n input: ActivateXappPurchaseReferenceInput,\n): Promise<UnknownRecord> {\n const preparePurchaseIntent = requireGatewayMethod(gatewayClient, \"prepareXappPurchaseIntent\");\n const createPurchaseTransaction = requireGatewayMethod(\n gatewayClient,\n \"createXappPurchaseTransaction\",\n );\n const issuePurchaseAccess = requireGatewayMethod(gatewayClient, \"issueXappPurchaseAccess\");\n const prepared = await preparePurchaseIntent(buildPreparePayload(input));\n const intentId = requireIntentId(prepared, \"prepareXappPurchaseIntent\");\n const preparedIntent =\n prepared?.prepared_intent && typeof prepared.prepared_intent === \"object\"\n ? (prepared.prepared_intent as UnknownRecord)\n : null;\n const preparedPrice =\n preparedIntent?.price && typeof preparedIntent.price === \"object\"\n ? (preparedIntent.price as UnknownRecord)\n : null;\n const transaction = await createPurchaseTransaction({\n xappId: input.xappId,\n intentId,\n status: readOptionalString(input.status) ?? \"verified\",\n provider_ref: readOptionalString(input.providerRef ?? input.provider_ref),\n evidence_ref: readOptionalString(input.evidenceRef ?? input.evidence_ref),\n payment_session_id: readOptionalString(input.paymentSessionId ?? input.payment_session_id),\n request_id: readOptionalString(input.requestId ?? input.request_id),\n settlement_ref: readOptionalString(input.settlementRef ?? input.settlement_ref),\n amount: input.amount ?? preparedPrice?.amount ?? undefined,\n currency: readOptionalString(input.currency) ?? readOptionalString(preparedPrice?.currency),\n occurred_at: readOptionalString(input.occurredAt ?? input.occurred_at),\n });\n const issued = await issuePurchaseAccess({\n xappId: input.xappId,\n intentId,\n });\n return {\n prepared_intent: preparedIntent,\n transaction:\n transaction?.transaction && typeof transaction.transaction === \"object\"\n ? transaction.transaction\n : null,\n issued,\n };\n}\n"],
5
+ "mappings": "AAiIA,SAAS,mBAAmB,OAAoC;AAC9D,QAAM,aAAa,OAAO,SAAS,EAAE,EAAE,KAAK;AAC5C,SAAO,aAAa,aAAa;AACnC;AAEA,SAAS,WAAW,OAAwB;AAC1C,SAAO,OAAO,SAAS,EAAE,EAAE,KAAK;AAClC;AAEA,SAAS,kBAAkB,OAAgB,WAAW,IAAY;AAChE,MAAI,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,GAAG;AAC/D,WACE,WAAY,MAAwB,EAAE,KACtC,WAAY,MAAwB,EAAE,KACtC,OAAO,OAAO,KAAsB,EACjC,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC,EAC9B,KAAK,OAAO,KACf;AAAA,EAEJ;AACA,SAAO,WAAW,KAAK,KAAK;AAC9B;AAEA,SAAS,aAAa,OAA2C;AAC/D,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;AAC/D,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,SAAS,qBACP,eACA,YAC2C;AAC3C,QAAM,SAAS,cAAc,UAAU;AACvC,MAAI,OAAO,WAAW,YAAY;AAChC,UAAM,IAAI,UAAU,gCAAgC,OAAO,UAAU,CAAC,EAAE;AAAA,EAC1E;AACA,SAAO;AACT;AAEA,SAAS,gBAAgB,QAAuB,YAA4B;AAC1E,QAAM,iBACJ,OAAO,mBAAmB,OAAO,OAAO,oBAAoB,WACvD,OAAO,kBACR;AACN,QAAM,WAAW,mBAAmB,gBAAgB,kBAAkB;AACtE,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,G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B;AAAA,IAChC;AAAA,IACA;AAAA,EACF;AACA,QAAM,sBAAsB,qBAAqB,eAAe,yBAAyB;AACzF,QAAM,WAAW,MAAM,sBAAsB,oBAAoB,KAAK,CAAC;AACvE,QAAM,WAAW,gBAAgB,UAAU,2BAA2B;AACtE,QAAM,iBACJ,UAAU,mBAAmB,OAAO,SAAS,oBAAoB,WAC5D,SAAS,kBACV;AACN,QAAM,gBACJ,gBAAgB,SAAS,OAAO,eAAe,UAAU,WACpD,eAAe,QAChB;AACN,QAAM,cAAc,MAAM,0BAA0B;AAAA,IAClD,QAAQ,MAAM;AAAA,IACd;AAAA,IACA,QAAQ,mBAAmB,MAAM,MAAM,KAAK;AAAA,IAC5C,cAAc,mBAAmB,MAAM,eAAe,MAAM,YAAY;AAAA,IACxE,cAAc,mBAAmB,MAAM,eAAe,MAAM,YAAY;AAAA,IACxE,oBAAoB,mBAAmB,MAAM,oBAAoB,MAAM,kBAAkB;AAAA,IACzF,YAAY,mBAAmB,MAAM,aAAa,MAAM,UAAU;AAAA,IAClE,gBAAgB,mBAAmB,MAAM,iBAAiB,MAAM,cAAc;AAAA,IAC9E,QAAQ,MAAM,UAAU,eAAe,UAAU;AAAA,IACjD,UAAU,mBAAmB,MAAM,QAAQ,KAAK,mBAAmB,eAAe,QAAQ;AAAA,IAC1F,aAAa,mBAAmB,MAAM,cAAc,MAAM,WAAW;AAAA,EACvE,CAAC;AACD,QAAM,SAAS,MAAM,oBAAoB;AAAA,IACvC,QAAQ,MAAM;AAAA,IACd;AAAA,EACF,CAAC;AACD,SAAO;AAAA,IACL,iBAAiB;AAAA,IACjB,aACE,aAAa,eAAe,OAAO,YAAY,gBAAgB,WAC3D,YAAY,cACZ;AAAA,IACN;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createGatewayExecutionModule, createHostReferenceModule, createReferenceSurfaceModule, createHostProxyService } from "./backend/modules.js";
2
2
  import { buildHostedGatewayPaymentUrl, buildModeHostedGatewayPaymentUrl, createPaymentEvidenceHandler, createPaymentRuntime, extractHostedPaymentSessionId, registerPaymentPageApiRoutes, registerPaymentPageAssetRoute } from "./backend/paymentRuntime.js";
3
+ import { activateXappPurchaseReference, consumeXappWalletCredits, finalizeXappHostedPurchase, findXappHostedPaymentPreset, listXappHostedPaymentPresets, normalizeXappMonetizationScopeKind, readXappMonetizationSnapshot, resolveXappHostedPaymentDefinition, resolveXappMonetizationScope, startXappHostedPurchase, type ActivateXappPurchaseReferenceInput, type ConsumeXappWalletCreditsInput, type FinalizeXappHostedPurchaseInput, type ListXappHostedPaymentPresetsInput, type ReadXappMonetizationSnapshotInput, type ResolveXappHostedPaymentDefinitionInput, type ResolveXappMonetizationScopeInput, type StartXappHostedPurchaseInput } from "./backend/xms.js";
3
4
  import { normalizeBackendKitOptions, resolvePlatformSecretRefFromEnv, type BackendKitNormalizedOptions, type StringRecord } from "./backend/options.js";
4
5
  type ReplyLike = {
5
6
  code: (statusCode: number) => {
@@ -44,16 +45,35 @@ export type BackendKit = {
44
45
  registerRoutes: (app: RegisterableApp) => Promise<void>;
45
46
  applyNotFoundHandler: (app: RegisterableApp) => void;
46
47
  };
48
+ export type { ActivateXappPurchaseReferenceInput, ConsumeXappWalletCreditsInput, FinalizeXappHostedPurchaseInput, ListXappHostedPaymentPresetsInput, ReadXappMonetizationSnapshotInput, ResolveXappHostedPaymentDefinitionInput, ResolveXappMonetizationScopeInput, StartXappHostedPurchaseInput, };
47
49
  export type VerifyBrowserWidgetContextInput = {
48
50
  hostOrigin: string;
51
+ bootstrapTicket?: string | null;
49
52
  installationId?: string | null;
50
53
  bindToolName?: string | null;
51
54
  toolName?: string | null;
52
55
  subjectId?: string | null;
53
56
  };
57
+ export type WidgetBootstrapOriginPolicyInput = {
58
+ hostOrigin: string | null | undefined;
59
+ allowedOrigins?: string[] | string | null | undefined;
60
+ };
61
+ export type WidgetBootstrapOriginPolicyResult = {
62
+ ok: true;
63
+ hostOrigin: string;
64
+ allowedOrigins: string[];
65
+ } | {
66
+ ok: false;
67
+ code: "HOST_ORIGIN_REQUIRED" | "HOST_ORIGIN_NOT_ALLOWED";
68
+ message: string;
69
+ hostOrigin: string | null;
70
+ allowedOrigins: string[];
71
+ };
72
+ export declare function normalizeWidgetBootstrapAllowedOrigins(value: string[] | string | null | undefined): string[];
73
+ export declare function evaluateWidgetBootstrapOriginPolicy(input: WidgetBootstrapOriginPolicyInput): WidgetBootstrapOriginPolicyResult;
54
74
  export declare function verifyBrowserWidgetContext(gatewayClient: {
55
75
  verifyBrowserWidgetContext: (input: VerifyBrowserWidgetContextInput) => Promise<Record<string, unknown>>;
56
76
  }, input: VerifyBrowserWidgetContextInput): Promise<Record<string, unknown>>;
57
77
  export declare function createBackendKit(input?: StringRecord, deps?: BackendKitDeps): Promise<BackendKit>;
58
- export { buildHostedGatewayPaymentUrl as buildHostedGatewayPaymentUrl, buildModeHostedGatewayPaymentUrl as buildModeHostedGatewayPaymentUrl, createGatewayExecutionModule, createHostReferenceModule, createReferenceSurfaceModule, createHostProxyService, createPaymentEvidenceHandler, createPaymentRuntime, extractHostedPaymentSessionId, normalizeBackendKitOptions, registerPaymentPageApiRoutes, registerPaymentPageAssetRoute, resolvePlatformSecretRefFromEnv, };
78
+ export { buildHostedGatewayPaymentUrl as buildHostedGatewayPaymentUrl, buildModeHostedGatewayPaymentUrl as buildModeHostedGatewayPaymentUrl, createGatewayExecutionModule, createHostReferenceModule, createReferenceSurfaceModule, createHostProxyService, activateXappPurchaseReference, consumeXappWalletCredits, createPaymentEvidenceHandler, createPaymentRuntime, extractHostedPaymentSessionId, finalizeXappHostedPurchase, findXappHostedPaymentPreset, listXappHostedPaymentPresets, normalizeXappMonetizationScopeKind, normalizeBackendKitOptions, readXappMonetizationSnapshot, registerPaymentPageApiRoutes, registerPaymentPageAssetRoute, resolveXappHostedPaymentDefinition, resolveXappMonetizationScope, resolvePlatformSecretRefFromEnv, startXappHostedPurchase, };
59
79
  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,GACxB,CAAC"}
package/dist/index.js CHANGED
@@ -13,10 +13,65 @@ import {
13
13
  registerPaymentPageApiRoutes,
14
14
  registerPaymentPageAssetRoute
15
15
  } from "./backend/paymentRuntime.js";
16
+ import {
17
+ activateXappPurchaseReference,
18
+ consumeXappWalletCredits,
19
+ finalizeXappHostedPurchase,
20
+ findXappHostedPaymentPreset,
21
+ listXappHostedPaymentPresets,
22
+ normalizeXappMonetizationScopeKind,
23
+ readXappMonetizationSnapshot,
24
+ resolveXappHostedPaymentDefinition,
25
+ resolveXappMonetizationScope,
26
+ startXappHostedPurchase
27
+ } from "./backend/xms.js";
16
28
  import {
17
29
  normalizeBackendKitOptions,
18
30
  resolvePlatformSecretRefFromEnv
19
31
  } from "./backend/options.js";
32
+ function normalizeOrigin(value) {
33
+ const raw = String(value || "").trim();
34
+ if (!raw) return null;
35
+ try {
36
+ const parsed = new URL(raw);
37
+ if (!parsed.protocol || !parsed.host) return null;
38
+ return parsed.origin;
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+ function normalizeWidgetBootstrapAllowedOrigins(value) {
44
+ const entries = Array.isArray(value) ? value : String(value || "").split(/[,\n]/);
45
+ const normalized = entries.map((entry) => normalizeOrigin(entry)).filter((entry) => Boolean(entry));
46
+ return Array.from(new Set(normalized));
47
+ }
48
+ function evaluateWidgetBootstrapOriginPolicy(input) {
49
+ const hostOrigin = normalizeOrigin(input.hostOrigin);
50
+ const allowedOrigins = normalizeWidgetBootstrapAllowedOrigins(input.allowedOrigins);
51
+ if (!hostOrigin) {
52
+ return {
53
+ ok: false,
54
+ code: "HOST_ORIGIN_REQUIRED",
55
+ message: "Host origin is required to verify browser widget context",
56
+ hostOrigin: null,
57
+ allowedOrigins
58
+ };
59
+ }
60
+ if (allowedOrigins.length > 0 && !allowedOrigins.includes(hostOrigin)) {
61
+ return {
62
+ ok: false,
63
+ code: "HOST_ORIGIN_NOT_ALLOWED",
64
+ message: "Host origin is not allowed for widget bootstrap verification",
65
+ hostOrigin,
66
+ allowedOrigins
67
+ };
68
+ }
69
+ return {
70
+ ok: true,
71
+ hostOrigin,
72
+ allowedOrigins
73
+ };
74
+ }
20
75
  async function verifyBrowserWidgetContext(gatewayClient, input) {
21
76
  return gatewayClient.verifyBrowserWidgetContext(input);
22
77
  }
@@ -69,8 +124,10 @@ async function createBackendKit(input = {}, deps = {}) {
69
124
  };
70
125
  }
71
126
  export {
127
+ activateXappPurchaseReference,
72
128
  buildHostedGatewayPaymentUrl,
73
129
  buildModeHostedGatewayPaymentUrl,
130
+ consumeXappWalletCredits,
74
131
  createBackendKit,
75
132
  createGatewayExecutionModule,
76
133
  createHostProxyService,
@@ -78,11 +135,21 @@ export {
78
135
  createPaymentEvidenceHandler,
79
136
  createPaymentRuntime,
80
137
  createReferenceSurfaceModule,
138
+ evaluateWidgetBootstrapOriginPolicy,
81
139
  extractHostedPaymentSessionId,
140
+ finalizeXappHostedPurchase,
141
+ findXappHostedPaymentPreset,
142
+ listXappHostedPaymentPresets,
82
143
  normalizeBackendKitOptions,
144
+ normalizeWidgetBootstrapAllowedOrigins,
145
+ normalizeXappMonetizationScopeKind,
146
+ readXappMonetizationSnapshot,
83
147
  registerPaymentPageApiRoutes,
84
148
  registerPaymentPageAssetRoute,
85
149
  resolvePlatformSecretRefFromEnv,
150
+ resolveXappHostedPaymentDefinition,
151
+ resolveXappMonetizationScope,
152
+ startXappHostedPurchase,
86
153
  verifyBrowserWidgetContext
87
154
  };
88
155
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import {\n createGatewayExecutionModule,\n createHostReferenceModule,\n createReferenceSurfaceModule,\n createHostProxyService,\n} from \"./backend/modules.js\";\nimport {\n buildHostedGatewayPaymentUrl,\n buildModeHostedGatewayPaymentUrl,\n createPaymentEvidenceHandler,\n createPaymentRuntime,\n extractHostedPaymentSessionId,\n registerPaymentPageApiRoutes,\n registerPaymentPageAssetRoute,\n} from \"./backend/paymentRuntime.js\";\nimport {\n normalizeBackendKitOptions,\n resolvePlatformSecretRefFromEnv,\n type BackendKitNormalizedOptions,\n type StringRecord,\n} from \"./backend/options.js\";\n\ntype ReplyLike = {\n code: (statusCode: number) => {\n send: (payload: unknown) => unknown;\n };\n};\n\ntype RegisterableApp = {\n setNotFoundHandler: (\n handler: (request: unknown, reply: ReplyLike) => Promise<unknown> | unknown,\n ) => void;\n};\n\ntype RouteModule = {\n registerRoutes: (app: RegisterableApp) => Promise<void> | void;\n};\n\ntype BackendKitDeps = {\n normalizeOptions?: (input: StringRecord) => BackendKitNormalizedOptions;\n createReferenceSurfaceModule?: (input: {\n gateway: BackendKitNormalizedOptions[\"gateway\"];\n branding: BackendKitNormalizedOptions[\"branding\"];\n enableReference: boolean;\n enableLifecycle: boolean;\n enableBridge: boolean;\n enabledModes: string[];\n reference: BackendKitNormalizedOptions[\"reference\"];\n }) => RouteModule;\n createHostReferenceModule?: (input: {\n gateway: BackendKitNormalizedOptions[\"gateway\"];\n branding: BackendKitNormalizedOptions[\"branding\"];\n reference: BackendKitNormalizedOptions[\"reference\"];\n enableLifecycle: boolean;\n enableBridge: boolean;\n allowedOrigins: string[];\n bootstrap: BackendKitNormalizedOptions[\"host\"][\"bootstrap\"];\n hostProxyService: unknown;\n }) => RouteModule;\n createGatewayExecutionModule?: (input: {\n enabledModes: string[];\n subjectProfiles: BackendKitNormalizedOptions[\"subjectProfiles\"];\n paymentRuntime: unknown;\n }) => RouteModule;\n};\n\nexport type BackendKit = {\n options: BackendKitNormalizedOptions;\n registerRoutes: (app: RegisterableApp) => Promise<void>;\n applyNotFoundHandler: (app: RegisterableApp) => void;\n};\n\nexport type VerifyBrowserWidgetContextInput = {\n hostOrigin: string;\n installationId?: string | null;\n bindToolName?: string | null;\n toolName?: string | null;\n subjectId?: string | null;\n};\n\nexport async function verifyBrowserWidgetContext(\n gatewayClient: {\n verifyBrowserWidgetContext: (\n input: VerifyBrowserWidgetContextInput,\n ) => Promise<Record<string, unknown>>;\n },\n input: VerifyBrowserWidgetContextInput,\n) {\n return gatewayClient.verifyBrowserWidgetContext(input);\n}\n\nexport async function createBackendKit(\n input: StringRecord = {},\n deps: BackendKitDeps = {},\n): Promise<BackendKit> {\n const normalizeOptions =\n typeof deps.normalizeOptions === \"function\" ? deps.normalizeOptions : null;\n const createReferenceSurfaceModuleDep =\n typeof deps.createReferenceSurfaceModule === \"function\"\n ? deps.createReferenceSurfaceModule\n : null;\n const createHostReferenceModuleDep =\n typeof deps.createHostReferenceModule === \"function\" ? deps.createHostReferenceModule : null;\n const createGatewayExecutionModuleDep =\n typeof deps.createGatewayExecutionModule === \"function\"\n ? deps.createGatewayExecutionModule\n : null;\n if (\n !normalizeOptions ||\n !createReferenceSurfaceModuleDep ||\n !createHostReferenceModuleDep ||\n !createGatewayExecutionModuleDep\n ) {\n throw new TypeError(\"backend kit dependencies are incomplete\");\n }\n\n const options = normalizeOptions(input);\n const paymentRuntime = await createPaymentRuntime(options, deps);\n\n const referenceSurfaceModule = createReferenceSurfaceModuleDep({\n gateway: options.gateway,\n branding: options.branding,\n enableReference: options.host.enableReference,\n enableLifecycle: options.host.enableLifecycle,\n enableBridge: options.host.enableBridge,\n enabledModes: options.payments.enabledModes,\n reference: options.reference,\n });\n const hostReferenceModule = createHostReferenceModuleDep({\n gateway: options.gateway,\n branding: options.branding,\n reference: options.reference,\n enableLifecycle: options.host.enableLifecycle,\n enableBridge: options.host.enableBridge,\n allowedOrigins: options.host.allowedOrigins,\n bootstrap: options.host.bootstrap,\n hostProxyService: options.overrides.hostProxyService,\n });\n const gatewayExecutionModule = createGatewayExecutionModuleDep({\n enabledModes: options.payments.enabledModes,\n subjectProfiles: options.subjectProfiles,\n paymentRuntime,\n });\n\n return {\n options,\n async registerRoutes(app) {\n await referenceSurfaceModule.registerRoutes(app);\n await hostReferenceModule.registerRoutes(app);\n await gatewayExecutionModule.registerRoutes(app);\n },\n applyNotFoundHandler(app) {\n app.setNotFoundHandler(async (_request, reply) =>\n reply.code(404).send({ message: \"Not found\" }),\n );\n },\n };\n}\n\nexport {\n buildHostedGatewayPaymentUrl as buildHostedGatewayPaymentUrl,\n buildModeHostedGatewayPaymentUrl as buildModeHostedGatewayPaymentUrl,\n createGatewayExecutionModule,\n createHostReferenceModule,\n createReferenceSurfaceModule,\n createHostProxyService,\n createPaymentEvidenceHandler,\n createPaymentRuntime,\n extractHostedPaymentSessionId,\n normalizeBackendKitOptions,\n registerPaymentPageApiRoutes,\n registerPaymentPageAssetRoute,\n resolvePlatformSecretRefFromEnv,\n};\n"],
5
- "mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AA4DP,eAAsB,2BACpB,eAKA,OACA;AACA,SAAO,cAAc,2BAA2B,KAAK;AACvD;AAEA,eAAsB,iBACpB,QAAsB,CAAC,GACvB,OAAuB,CAAC,GACH;AACrB,QAAM,mBACJ,OAAO,KAAK,qBAAqB,aAAa,KAAK,mBAAmB;AACxE,QAAM,kCACJ,OAAO,KAAK,iCAAiC,aACzC,KAAK,+BACL;AACN,QAAM,+BACJ,OAAO,KAAK,8BAA8B,aAAa,KAAK,4BAA4B;AAC1F,QAAM,kCACJ,OAAO,KAAK,iCAAiC,aACzC,KAAK,+BACL;AACN,MACE,CAAC,oBACD,CAAC,mCACD,CAAC,gCACD,CAAC,iCACD;AACA,UAAM,IAAI,UAAU,yCAAyC;AAAA,EAC/D;AAEA,QAAM,UAAU,iBAAiB,KAAK;AACtC,QAAM,iBAAiB,MAAM,qBAAqB,SAAS,IAAI;AAE/D,QAAM,yBAAyB,gCAAgC;AAAA,IAC7D,SAAS,QAAQ;AAAA,IACjB,UAAU,QAAQ;AAAA,IAClB,iBAAiB,QAAQ,KAAK;AAAA,IAC9B,iBAAiB,QAAQ,KAAK;AAAA,IAC9B,cAAc,QAAQ,KAAK;AAAA,IAC3B,cAAc,QAAQ,SAAS;AAAA,IAC/B,WAAW,QAAQ;AAAA,EACrB,CAAC;AACD,QAAM,sBAAsB,6BAA6B;AAAA,IACvD,SAAS,QAAQ;AAAA,IACjB,UAAU,QAAQ;AAAA,IAClB,WAAW,QAAQ;AAAA,IACnB,iBAAiB,QAAQ,KAAK;AAAA,IAC9B,cAAc,QAAQ,KAAK;AAAA,IAC3B,gBAAgB,QAAQ,KAAK;AAAA,IAC7B,WAAW,QAAQ,KAAK;AAAA,IACxB,kBAAkB,QAAQ,UAAU;AAAA,EACtC,CAAC;AACD,QAAM,yBAAyB,gCAAgC;AAAA,IAC7D,cAAc,QAAQ,SAAS;AAAA,IAC/B,iBAAiB,QAAQ;AAAA,IACzB;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA,MAAM,eAAe,KAAK;AACxB,YAAM,uBAAuB,eAAe,GAAG;AAC/C,YAAM,oBAAoB,eAAe,GAAG;AAC5C,YAAM,uBAAuB,eAAe,GAAG;AAAA,IACjD;AAAA,IACA,qBAAqB,KAAK;AACxB,UAAI;AAAA,QAAmB,OAAO,UAAU,UACtC,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,SAAS,YAAY,CAAC;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import {\n createGatewayExecutionModule,\n createHostReferenceModule,\n createReferenceSurfaceModule,\n createHostProxyService,\n} from \"./backend/modules.js\";\nimport {\n buildHostedGatewayPaymentUrl,\n buildModeHostedGatewayPaymentUrl,\n createPaymentEvidenceHandler,\n createPaymentRuntime,\n extractHostedPaymentSessionId,\n registerPaymentPageApiRoutes,\n registerPaymentPageAssetRoute,\n} from \"./backend/paymentRuntime.js\";\nimport {\n activateXappPurchaseReference,\n consumeXappWalletCredits,\n finalizeXappHostedPurchase,\n findXappHostedPaymentPreset,\n listXappHostedPaymentPresets,\n normalizeXappMonetizationScopeKind,\n readXappMonetizationSnapshot,\n resolveXappHostedPaymentDefinition,\n resolveXappMonetizationScope,\n startXappHostedPurchase,\n type ActivateXappPurchaseReferenceInput,\n type ConsumeXappWalletCreditsInput,\n type FinalizeXappHostedPurchaseInput,\n type ListXappHostedPaymentPresetsInput,\n type ReadXappMonetizationSnapshotInput,\n type ResolveXappHostedPaymentDefinitionInput,\n type ResolveXappMonetizationScopeInput,\n type StartXappHostedPurchaseInput,\n} from \"./backend/xms.js\";\nimport {\n normalizeBackendKitOptions,\n resolvePlatformSecretRefFromEnv,\n type BackendKitNormalizedOptions,\n type StringRecord,\n} from \"./backend/options.js\";\n\ntype ReplyLike = {\n code: (statusCode: number) => {\n send: (payload: unknown) => unknown;\n };\n};\n\ntype RegisterableApp = {\n setNotFoundHandler: (\n handler: (request: unknown, reply: ReplyLike) => Promise<unknown> | unknown,\n ) => void;\n};\n\ntype RouteModule = {\n registerRoutes: (app: RegisterableApp) => Promise<void> | void;\n};\n\ntype BackendKitDeps = {\n normalizeOptions?: (input: StringRecord) => BackendKitNormalizedOptions;\n createReferenceSurfaceModule?: (input: {\n gateway: BackendKitNormalizedOptions[\"gateway\"];\n branding: BackendKitNormalizedOptions[\"branding\"];\n enableReference: boolean;\n enableLifecycle: boolean;\n enableBridge: boolean;\n enabledModes: string[];\n reference: BackendKitNormalizedOptions[\"reference\"];\n }) => RouteModule;\n createHostReferenceModule?: (input: {\n gateway: BackendKitNormalizedOptions[\"gateway\"];\n branding: BackendKitNormalizedOptions[\"branding\"];\n reference: BackendKitNormalizedOptions[\"reference\"];\n enableLifecycle: boolean;\n enableBridge: boolean;\n allowedOrigins: string[];\n bootstrap: BackendKitNormalizedOptions[\"host\"][\"bootstrap\"];\n hostProxyService: unknown;\n }) => RouteModule;\n createGatewayExecutionModule?: (input: {\n enabledModes: string[];\n subjectProfiles: BackendKitNormalizedOptions[\"subjectProfiles\"];\n paymentRuntime: unknown;\n }) => RouteModule;\n};\n\nexport type BackendKit = {\n options: BackendKitNormalizedOptions;\n registerRoutes: (app: RegisterableApp) => Promise<void>;\n applyNotFoundHandler: (app: RegisterableApp) => void;\n};\n\nexport type {\n ActivateXappPurchaseReferenceInput,\n ConsumeXappWalletCreditsInput,\n FinalizeXappHostedPurchaseInput,\n ListXappHostedPaymentPresetsInput,\n ReadXappMonetizationSnapshotInput,\n ResolveXappHostedPaymentDefinitionInput,\n ResolveXappMonetizationScopeInput,\n StartXappHostedPurchaseInput,\n};\n\nexport type VerifyBrowserWidgetContextInput = {\n hostOrigin: string;\n bootstrapTicket?: string | null;\n installationId?: string | null;\n bindToolName?: string | null;\n toolName?: string | null;\n subjectId?: string | null;\n};\n\nexport type WidgetBootstrapOriginPolicyInput = {\n hostOrigin: string | null | undefined;\n allowedOrigins?: string[] | string | null | undefined;\n};\n\nexport type WidgetBootstrapOriginPolicyResult =\n | {\n ok: true;\n hostOrigin: string;\n allowedOrigins: string[];\n }\n | {\n ok: false;\n code: \"HOST_ORIGIN_REQUIRED\" | \"HOST_ORIGIN_NOT_ALLOWED\";\n message: string;\n hostOrigin: string | null;\n allowedOrigins: string[];\n };\n\nfunction normalizeOrigin(value: string | null | undefined) {\n const raw = String(value || \"\").trim();\n if (!raw) return null;\n try {\n const parsed = new URL(raw);\n if (!parsed.protocol || !parsed.host) return null;\n return parsed.origin;\n } catch {\n return null;\n }\n}\n\nexport function normalizeWidgetBootstrapAllowedOrigins(\n value: string[] | string | null | undefined,\n): string[] {\n const entries = Array.isArray(value) ? value : String(value || \"\").split(/[,\\n]/);\n const normalized = entries\n .map((entry) => normalizeOrigin(entry))\n .filter((entry): entry is string => Boolean(entry));\n return Array.from(new Set(normalized));\n}\n\nexport function evaluateWidgetBootstrapOriginPolicy(\n input: WidgetBootstrapOriginPolicyInput,\n): WidgetBootstrapOriginPolicyResult {\n const hostOrigin = normalizeOrigin(input.hostOrigin);\n const allowedOrigins = normalizeWidgetBootstrapAllowedOrigins(input.allowedOrigins);\n if (!hostOrigin) {\n return {\n ok: false,\n code: \"HOST_ORIGIN_REQUIRED\",\n message: \"Host origin is required to verify browser widget context\",\n hostOrigin: null,\n allowedOrigins,\n };\n }\n if (allowedOrigins.length > 0 && !allowedOrigins.includes(hostOrigin)) {\n return {\n ok: false,\n code: \"HOST_ORIGIN_NOT_ALLOWED\",\n message: \"Host origin is not allowed for widget bootstrap verification\",\n hostOrigin,\n allowedOrigins,\n };\n }\n return {\n ok: true,\n hostOrigin,\n allowedOrigins,\n };\n}\n\nexport async function verifyBrowserWidgetContext(\n gatewayClient: {\n verifyBrowserWidgetContext: (\n input: VerifyBrowserWidgetContextInput,\n ) => Promise<Record<string, unknown>>;\n },\n input: VerifyBrowserWidgetContextInput,\n) {\n return gatewayClient.verifyBrowserWidgetContext(input);\n}\n\nexport async function createBackendKit(\n input: StringRecord = {},\n deps: BackendKitDeps = {},\n): Promise<BackendKit> {\n const normalizeOptions =\n typeof deps.normalizeOptions === \"function\" ? deps.normalizeOptions : null;\n const createReferenceSurfaceModuleDep =\n typeof deps.createReferenceSurfaceModule === \"function\"\n ? deps.createReferenceSurfaceModule\n : null;\n const createHostReferenceModuleDep =\n typeof deps.createHostReferenceModule === \"function\" ? deps.createHostReferenceModule : null;\n const createGatewayExecutionModuleDep =\n typeof deps.createGatewayExecutionModule === \"function\"\n ? deps.createGatewayExecutionModule\n : null;\n if (\n !normalizeOptions ||\n !createReferenceSurfaceModuleDep ||\n !createHostReferenceModuleDep ||\n !createGatewayExecutionModuleDep\n ) {\n throw new TypeError(\"backend kit dependencies are incomplete\");\n }\n\n const options = normalizeOptions(input);\n const paymentRuntime = await createPaymentRuntime(options, deps);\n\n const referenceSurfaceModule = createReferenceSurfaceModuleDep({\n gateway: options.gateway,\n branding: options.branding,\n enableReference: options.host.enableReference,\n enableLifecycle: options.host.enableLifecycle,\n enableBridge: options.host.enableBridge,\n enabledModes: options.payments.enabledModes,\n reference: options.reference,\n });\n const hostReferenceModule = createHostReferenceModuleDep({\n gateway: options.gateway,\n branding: options.branding,\n reference: options.reference,\n enableLifecycle: options.host.enableLifecycle,\n enableBridge: options.host.enableBridge,\n allowedOrigins: options.host.allowedOrigins,\n bootstrap: options.host.bootstrap,\n hostProxyService: options.overrides.hostProxyService,\n });\n const gatewayExecutionModule = createGatewayExecutionModuleDep({\n enabledModes: options.payments.enabledModes,\n subjectProfiles: options.subjectProfiles,\n paymentRuntime,\n });\n\n return {\n options,\n async registerRoutes(app) {\n await referenceSurfaceModule.registerRoutes(app);\n await hostReferenceModule.registerRoutes(app);\n await gatewayExecutionModule.registerRoutes(app);\n },\n applyNotFoundHandler(app) {\n app.setNotFoundHandler(async (_request, reply) =>\n reply.code(404).send({ message: \"Not found\" }),\n );\n },\n };\n}\n\nexport {\n buildHostedGatewayPaymentUrl as buildHostedGatewayPaymentUrl,\n buildModeHostedGatewayPaymentUrl as buildModeHostedGatewayPaymentUrl,\n createGatewayExecutionModule,\n createHostReferenceModule,\n createReferenceSurfaceModule,\n createHostProxyService,\n activateXappPurchaseReference,\n consumeXappWalletCredits,\n createPaymentEvidenceHandler,\n createPaymentRuntime,\n extractHostedPaymentSessionId,\n finalizeXappHostedPurchase,\n findXappHostedPaymentPreset,\n listXappHostedPaymentPresets,\n normalizeXappMonetizationScopeKind,\n normalizeBackendKitOptions,\n readXappMonetizationSnapshot,\n registerPaymentPageApiRoutes,\n registerPaymentPageAssetRoute,\n resolveXappHostedPaymentDefinition,\n resolveXappMonetizationScope,\n resolvePlatformSecretRefFromEnv,\n startXappHostedPurchase,\n};\n"],
5
+ "mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AA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ACjD;AAAA,IACA,qBAAqB,KAAK;AACxB,UAAI;AAAA,QAAmB,OAAO,UAAU,UACtC,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,SAAS,YAAY,CAAC;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xapps-platform/backend-kit",
3
- "version": "0.1.6",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "author": "Daniel Vladescu <daniel.vladescu@gmail.com>",
6
6
  "description": "Modular Node backend kit for the current Xapps backend contract (tenant surface today, shared actor-adapter direction later)",
@@ -37,6 +37,6 @@
37
37
  "smoke": "npm run build && node examples/smoke/smoke.mjs"
38
38
  },
39
39
  "dependencies": {
40
- "@xapps-platform/server-sdk": "^0.1.0"
40
+ "@xapps-platform/server-sdk": "^0.2.0"
41
41
  }
42
42
  }