@facto-to/connect 0.0.1-beta.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.
@@ -0,0 +1,206 @@
1
+ import { ExchangeLinkCodeResponse } from '@facto-to/engine-wire';
2
+
3
+ interface FactoExpressCheckoutOrder {
4
+ label: string;
5
+ amountLabel: string;
6
+ shippingLabel?: string;
7
+ }
8
+ interface FactoExpressCheckoutSetup {
9
+ walletAddress: string;
10
+ routeLabel: string;
11
+ ready: boolean;
12
+ }
13
+ type FactoMerchantCheckoutSetupStatus = 'needs_merchant_login' | 'needs_facto_link' | 'finish_facto_setup' | 'needs_mandate_authorization' | 'ready' | 'paying' | 'terminal';
14
+ interface FactoMerchantPaymentOption {
15
+ paymentOptionId: string;
16
+ label: string;
17
+ ready: boolean;
18
+ isDefault: boolean;
19
+ chainId: number;
20
+ chainLabel: string;
21
+ protocolLabel: string;
22
+ assetSymbol: string;
23
+ spendMode: string;
24
+ blockingReason?: string;
25
+ }
26
+ interface FactoMerchantCheckoutSetupState {
27
+ buttonLabel: 'Pay with Facto';
28
+ setupStatus: FactoMerchantCheckoutSetupStatus;
29
+ message: string;
30
+ paymentReady: boolean;
31
+ mandateReady: boolean;
32
+ paymentOptions?: FactoMerchantPaymentOption[];
33
+ selectedPaymentOptionId?: string;
34
+ paymentStatus?: string;
35
+ blockingReason?: string;
36
+ }
37
+ interface FactoExpressCheckoutPaymentResult {
38
+ message?: string;
39
+ }
40
+ type FactoExpressCheckoutSetupResult = FactoExpressCheckoutSetup | FactoLinkCompleteResponse | FactoMerchantCheckoutSetupState | null | undefined;
41
+ interface FactoExpressCheckoutOptions {
42
+ container: HTMLElement | string;
43
+ order: FactoExpressCheckoutOrder;
44
+ getPaymentSetup: () => Promise<FactoExpressCheckoutSetupResult> | FactoExpressCheckoutSetupResult;
45
+ startPaymentSetup: () => Promise<FactoExpressCheckoutSetupResult> | FactoExpressCheckoutSetupResult;
46
+ submitPayment: (setup: FactoExpressCheckoutSetup) => Promise<FactoExpressCheckoutPaymentResult | void> | FactoExpressCheckoutPaymentResult | void;
47
+ buttonLabel?: string;
48
+ brandLabel?: string;
49
+ environmentLabel?: string;
50
+ onStatusChange?: (status: FactoExpressCheckoutStatus) => void;
51
+ }
52
+ interface FactoExpressCheckoutStatus {
53
+ kind: 'idle' | 'checking' | 'setup' | 'ready' | 'paying' | 'success' | 'error';
54
+ message: string;
55
+ }
56
+ interface FactoExpressCheckoutHandle {
57
+ open(): Promise<void>;
58
+ close(): void;
59
+ update(options: Partial<Omit<FactoExpressCheckoutOptions, 'container'>>): void;
60
+ destroy(): void;
61
+ }
62
+ declare function createFactoExpressCheckout(options: FactoExpressCheckoutOptions): FactoExpressCheckoutHandle;
63
+
64
+ /**
65
+ * @facto-to/connect
66
+ *
67
+ * Browser SDK for merchant pages to launch the Facto-owned Connect Journey.
68
+ * The public client hides popup and postMessage details behind
69
+ * connect({ fetchLinkSession, completeLink }).
70
+ *
71
+ * The low-level popup transport remains exported for the current internal demo
72
+ * and tests, but partner documentation should use the high-level client.
73
+ */
74
+
75
+ declare const FACTO_LINK_CONNECTED = "facto.externalLink.connected";
76
+ declare const FACTO_LINK_READY = "facto.externalLink.ready";
77
+ declare const FACTO_LINK_FAILED = "facto.externalLink.failed";
78
+ declare const FACTO_LINK_CLOSE_REQUESTED = "facto.externalLink.closeRequested";
79
+ type FactoConnectMessageType = typeof FACTO_LINK_CONNECTED | typeof FACTO_LINK_READY | typeof FACTO_LINK_FAILED | typeof FACTO_LINK_CLOSE_REQUESTED;
80
+ type FactoConnectEventKind = 'connected' | 'ready';
81
+ interface FactoConnectCodeEvent {
82
+ kind: FactoConnectEventKind;
83
+ code: string;
84
+ state: string;
85
+ }
86
+ interface FactoConnectFailureEvent {
87
+ state: string;
88
+ reason?: string;
89
+ }
90
+ interface FactoConnectTransportOptions {
91
+ connectUrl: string;
92
+ state: string;
93
+ origin?: string;
94
+ windowName?: string;
95
+ windowFeatures?: string;
96
+ onConnected?: (result: FactoConnectCodeEvent) => void;
97
+ onReady?: (result: FactoConnectCodeEvent) => void;
98
+ onFailed?: (error: FactoConnectFailureEvent) => void;
99
+ onClose?: () => void;
100
+ }
101
+ interface FactoConnectHandle {
102
+ open(): void;
103
+ close(): void;
104
+ }
105
+ interface FactoConnectOptions {
106
+ appId: string;
107
+ connectBaseUrl?: string;
108
+ timeoutMs?: number;
109
+ popupName?: string;
110
+ popupFeatures?: string;
111
+ telemetry?: FactoConnectTelemetry;
112
+ }
113
+ interface FactoConnectTelemetry {
114
+ track(event: FactoConnectTelemetryEvent): void;
115
+ }
116
+ interface FactoConnectTelemetryEvent {
117
+ type: 'connect_started' | 'link_session_requested' | 'link_session_received' | 'popup_opened' | 'popup_blocked' | 'journey_ready' | 'journey_exit' | 'code_received' | 'link_complete_started' | 'link_complete_succeeded' | 'link_complete_failed' | 'connect_timeout';
118
+ appId: string;
119
+ sessionId?: string;
120
+ state?: string;
121
+ details?: Record<string, unknown>;
122
+ }
123
+ interface FactoConnectClient {
124
+ connect(request: FactoConnectRequest): Promise<FactoConnectResult>;
125
+ close(reason?: string): void;
126
+ }
127
+ interface FactoConnectRequest {
128
+ fetchLinkSession: () => Promise<FactoLinkSession>;
129
+ completeLink: (input: FactoLinkCompleteInput) => Promise<FactoLinkCompleteResponse>;
130
+ requestedScopes?: string[];
131
+ metadata?: Record<string, unknown>;
132
+ onConnected?: (event: FactoConnectCodeEvent) => void;
133
+ onReady?: (event: FactoConnectCodeEvent) => void;
134
+ onExit?: (event: FactoConnectExitEvent) => void;
135
+ onError?: (error: FactoConnectError) => void;
136
+ }
137
+ interface FactoLinkSession {
138
+ sessionId?: string;
139
+ appId?: string;
140
+ state: string;
141
+ nonce?: string;
142
+ connectUrl?: string;
143
+ iframeUrl?: string;
144
+ expiresAt: string;
145
+ expectedOrigin?: string;
146
+ }
147
+ interface FactoLinkCompleteInput {
148
+ sessionId?: string;
149
+ state: string;
150
+ nonce?: string;
151
+ code: string;
152
+ }
153
+ /**
154
+ * What the merchant's `completeLink` callback hands back: their own backend's
155
+ * relay of the engine `ExchangeLinkCodeResponse`.
156
+ *
157
+ * Pre-GA engine deployments and older merchant backends relay partial bodies,
158
+ * so every wire field except `pipelineReady` is tolerated as absent. Whatever
159
+ * arrives here, `connect()` only ever resolves `FactoConnectResult`.
160
+ */
161
+ type FactoLinkCompleteResponse = Partial<ExchangeLinkCodeResponse> & Pick<ExchangeLinkCodeResponse, 'pipelineReady'> & {
162
+ /** Legacy marker kept for source compatibility; not part of the wire. */
163
+ linked?: true;
164
+ /** Route summary consumed by the legacy express-checkout callback. */
165
+ pipeline?: FactoPipelineSummary | null;
166
+ };
167
+ /**
168
+ * Merchant-safe result of `createFactoConnect(...).connect(...)`.
169
+ *
170
+ * Exactly the wire-derived subset a browser caller is allowed to see. The
171
+ * legacy identity fields `factoUserId`, `factoServerWalletAddress`, and
172
+ * `cardRef` are server-side only and are stripped before this resolves — do not
173
+ * widen this type to reintroduce them.
174
+ */
175
+ type FactoConnectResult = Pick<ExchangeLinkCodeResponse, 'pipelineReady'> & Partial<Pick<ExchangeLinkCodeResponse, 'appId' | 'userLinkRef' | 'grantStatus' | 'scopes'>>;
176
+ interface FactoPipelineSummary {
177
+ selectedPipelineId: string;
178
+ chainId: number;
179
+ protocolId: string;
180
+ assetSymbol?: string;
181
+ spendMode: string;
182
+ }
183
+ interface FactoConnectExitEvent {
184
+ reason: 'user_exit' | 'timeout';
185
+ state?: string;
186
+ }
187
+ type FactoConnectErrorCode = 'POPUP_BLOCKED' | 'USER_EXIT' | 'LINK_SESSION_EXPIRED' | 'INVALID_LINK_SESSION' | 'CONNECT_APP_FAILED' | 'LINK_COMPLETE_FAILED' | 'TIMEOUT' | 'UNKNOWN';
188
+ declare class FactoConnectError extends Error {
189
+ readonly code: FactoConnectErrorCode;
190
+ readonly retryable: boolean;
191
+ readonly status?: number;
192
+ readonly details?: unknown;
193
+ constructor(code: FactoConnectErrorCode, message: string, options: {
194
+ retryable: boolean;
195
+ status?: number;
196
+ details?: unknown;
197
+ });
198
+ }
199
+ declare function createFactoConnectTransport(options: FactoConnectTransportOptions): FactoConnectHandle;
200
+ declare function createFactoConnect(options: FactoConnectOptions): FactoConnectClient;
201
+ declare function createFactoConnect(options: FactoConnectTransportOptions): FactoConnectHandle;
202
+ declare const FactoConnect: {
203
+ create: typeof createFactoConnect;
204
+ };
205
+
206
+ export { FACTO_LINK_CLOSE_REQUESTED, FACTO_LINK_CONNECTED, FACTO_LINK_FAILED, FACTO_LINK_READY, FactoConnect, type FactoConnectClient, type FactoConnectCodeEvent, FactoConnectError, type FactoConnectErrorCode, type FactoConnectEventKind, type FactoConnectExitEvent, type FactoConnectFailureEvent, type FactoConnectHandle, type FactoConnectMessageType, type FactoConnectOptions, type FactoConnectRequest, type FactoConnectResult, type FactoConnectTelemetry, type FactoConnectTelemetryEvent, type FactoConnectTransportOptions, type FactoExpressCheckoutHandle, type FactoExpressCheckoutOptions, type FactoExpressCheckoutOrder, type FactoExpressCheckoutPaymentResult, type FactoExpressCheckoutSetup, type FactoExpressCheckoutSetupResult, type FactoExpressCheckoutStatus, type FactoLinkCompleteInput, type FactoLinkCompleteResponse, type FactoLinkSession, type FactoMerchantCheckoutSetupState, type FactoMerchantCheckoutSetupStatus, type FactoMerchantPaymentOption, type FactoPipelineSummary, createFactoConnect, createFactoConnectTransport, createFactoExpressCheckout, createFactoConnect as default };