@blocklet/payment-broker-client 1.20.17

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.
Files changed (157) hide show
  1. package/examples/README.md +277 -0
  2. package/examples/browser/README.md +119 -0
  3. package/examples/browser/simple-example.js +223 -0
  4. package/examples/nodejs/README.md +180 -0
  5. package/examples/nodejs/deploy-example.mjs +200 -0
  6. package/examples/nodejs/package.json +30 -0
  7. package/lib/adapters/config/browser.d.ts +12 -0
  8. package/lib/adapters/config/browser.d.ts.map +1 -0
  9. package/lib/adapters/config/browser.js +48 -0
  10. package/lib/adapters/config/browser.js.map +1 -0
  11. package/lib/adapters/config/node.d.ts +13 -0
  12. package/lib/adapters/config/node.d.ts.map +1 -0
  13. package/lib/adapters/config/node.js +62 -0
  14. package/lib/adapters/config/node.js.map +1 -0
  15. package/lib/adapters/http/browser.d.ts +12 -0
  16. package/lib/adapters/http/browser.d.ts.map +1 -0
  17. package/lib/adapters/http/browser.js +50 -0
  18. package/lib/adapters/http/browser.js.map +1 -0
  19. package/lib/adapters/http/node.d.ts +12 -0
  20. package/lib/adapters/http/node.d.ts.map +1 -0
  21. package/lib/adapters/http/node.js +30 -0
  22. package/lib/adapters/http/node.js.map +1 -0
  23. package/lib/browser/adapters/config/browser.d.ts +12 -0
  24. package/lib/browser/adapters/config/browser.d.ts.map +1 -0
  25. package/lib/browser/adapters/config/node.d.ts +13 -0
  26. package/lib/browser/adapters/config/node.d.ts.map +1 -0
  27. package/lib/browser/adapters/http/browser.d.ts +12 -0
  28. package/lib/browser/adapters/http/browser.d.ts.map +1 -0
  29. package/lib/browser/adapters/http/node.d.ts +12 -0
  30. package/lib/browser/adapters/http/node.d.ts.map +1 -0
  31. package/lib/browser/browser/factory.d.ts +19 -0
  32. package/lib/browser/browser/factory.d.ts.map +1 -0
  33. package/lib/browser/browser/index.d.ts +9 -0
  34. package/lib/browser/browser/index.d.ts.map +1 -0
  35. package/lib/browser/core/client.d.ts +29 -0
  36. package/lib/browser/core/client.d.ts.map +1 -0
  37. package/lib/browser/core/deployment.d.ts +20 -0
  38. package/lib/browser/core/deployment.d.ts.map +1 -0
  39. package/lib/browser/core/errors.d.ts +15 -0
  40. package/lib/browser/core/errors.d.ts.map +1 -0
  41. package/lib/browser/core/index.d.ts +10 -0
  42. package/lib/browser/core/index.d.ts.map +1 -0
  43. package/lib/browser/core/interfaces.d.ts +24 -0
  44. package/lib/browser/core/interfaces.d.ts.map +1 -0
  45. package/lib/browser/core/logger.d.ts +8 -0
  46. package/lib/browser/core/logger.d.ts.map +1 -0
  47. package/lib/browser/core/polling.d.ts +23 -0
  48. package/lib/browser/core/polling.d.ts.map +1 -0
  49. package/lib/browser/core/session.d.ts +31 -0
  50. package/lib/browser/core/session.d.ts.map +1 -0
  51. package/lib/browser/core/types.d.ts +175 -0
  52. package/lib/browser/core/types.d.ts.map +1 -0
  53. package/lib/browser/core/utils.d.ts +27 -0
  54. package/lib/browser/core/utils.d.ts.map +1 -0
  55. package/lib/browser/factory.d.ts +19 -0
  56. package/lib/browser/factory.d.ts.map +1 -0
  57. package/lib/browser/factory.js +30 -0
  58. package/lib/browser/factory.js.map +1 -0
  59. package/lib/browser/index.d.ts +8 -0
  60. package/lib/browser/index.d.ts.map +1 -0
  61. package/lib/browser/index.js +973 -0
  62. package/lib/browser/index.js.map +1 -0
  63. package/lib/browser/node/factory.d.ts +9 -0
  64. package/lib/browser/node/factory.d.ts.map +1 -0
  65. package/lib/browser/node/index.d.ts +8 -0
  66. package/lib/browser/node/index.d.ts.map +1 -0
  67. package/lib/core/client.d.ts +29 -0
  68. package/lib/core/client.d.ts.map +1 -0
  69. package/lib/core/client.js +150 -0
  70. package/lib/core/client.js.map +1 -0
  71. package/lib/core/deployment.d.ts +20 -0
  72. package/lib/core/deployment.d.ts.map +1 -0
  73. package/lib/core/deployment.js +184 -0
  74. package/lib/core/deployment.js.map +1 -0
  75. package/lib/core/errors.d.ts +15 -0
  76. package/lib/core/errors.d.ts.map +1 -0
  77. package/lib/core/errors.js +21 -0
  78. package/lib/core/errors.js.map +1 -0
  79. package/lib/core/index.d.ts +10 -0
  80. package/lib/core/index.d.ts.map +1 -0
  81. package/lib/core/index.js +32 -0
  82. package/lib/core/index.js.map +1 -0
  83. package/lib/core/interfaces.d.ts +24 -0
  84. package/lib/core/interfaces.d.ts.map +1 -0
  85. package/lib/core/interfaces.js +4 -0
  86. package/lib/core/interfaces.js.map +1 -0
  87. package/lib/core/logger.d.ts +8 -0
  88. package/lib/core/logger.d.ts.map +1 -0
  89. package/lib/core/logger.js +39 -0
  90. package/lib/core/logger.js.map +1 -0
  91. package/lib/core/polling.d.ts +23 -0
  92. package/lib/core/polling.d.ts.map +1 -0
  93. package/lib/core/polling.js +97 -0
  94. package/lib/core/polling.js.map +1 -0
  95. package/lib/core/session.d.ts +31 -0
  96. package/lib/core/session.d.ts.map +1 -0
  97. package/lib/core/session.js +202 -0
  98. package/lib/core/session.js.map +1 -0
  99. package/lib/core/types.d.ts +175 -0
  100. package/lib/core/types.d.ts.map +1 -0
  101. package/lib/core/types.js +48 -0
  102. package/lib/core/types.js.map +1 -0
  103. package/lib/core/utils.d.ts +27 -0
  104. package/lib/core/utils.d.ts.map +1 -0
  105. package/lib/core/utils.js +181 -0
  106. package/lib/core/utils.js.map +1 -0
  107. package/lib/index.d.ts +484 -0
  108. package/lib/index.d.ts.map +1 -0
  109. package/lib/index.esm.js +969 -0
  110. package/lib/index.esm.js.map +1 -0
  111. package/lib/index.js +984 -0
  112. package/lib/index.js.map +1 -0
  113. package/lib/node/adapters/config/browser.d.ts +12 -0
  114. package/lib/node/adapters/config/browser.d.ts.map +1 -0
  115. package/lib/node/adapters/config/node.d.ts +13 -0
  116. package/lib/node/adapters/config/node.d.ts.map +1 -0
  117. package/lib/node/adapters/http/browser.d.ts +12 -0
  118. package/lib/node/adapters/http/browser.d.ts.map +1 -0
  119. package/lib/node/adapters/http/node.d.ts +12 -0
  120. package/lib/node/adapters/http/node.d.ts.map +1 -0
  121. package/lib/node/browser/factory.d.ts +19 -0
  122. package/lib/node/browser/factory.d.ts.map +1 -0
  123. package/lib/node/browser/index.d.ts +9 -0
  124. package/lib/node/browser/index.d.ts.map +1 -0
  125. package/lib/node/core/client.d.ts +29 -0
  126. package/lib/node/core/client.d.ts.map +1 -0
  127. package/lib/node/core/deployment.d.ts +20 -0
  128. package/lib/node/core/deployment.d.ts.map +1 -0
  129. package/lib/node/core/errors.d.ts +15 -0
  130. package/lib/node/core/errors.d.ts.map +1 -0
  131. package/lib/node/core/index.d.ts +10 -0
  132. package/lib/node/core/index.d.ts.map +1 -0
  133. package/lib/node/core/interfaces.d.ts +24 -0
  134. package/lib/node/core/interfaces.d.ts.map +1 -0
  135. package/lib/node/core/logger.d.ts +8 -0
  136. package/lib/node/core/logger.d.ts.map +1 -0
  137. package/lib/node/core/polling.d.ts +23 -0
  138. package/lib/node/core/polling.d.ts.map +1 -0
  139. package/lib/node/core/session.d.ts +31 -0
  140. package/lib/node/core/session.d.ts.map +1 -0
  141. package/lib/node/core/types.d.ts +175 -0
  142. package/lib/node/core/types.d.ts.map +1 -0
  143. package/lib/node/core/utils.d.ts +27 -0
  144. package/lib/node/core/utils.d.ts.map +1 -0
  145. package/lib/node/factory.d.ts +9 -0
  146. package/lib/node/factory.d.ts.map +1 -0
  147. package/lib/node/factory.js +34 -0
  148. package/lib/node/factory.js.map +1 -0
  149. package/lib/node/index.d.ts +8 -0
  150. package/lib/node/index.d.ts.map +1 -0
  151. package/lib/node/index.js +984 -0
  152. package/lib/node/index.js.map +1 -0
  153. package/lib/node/node/factory.d.ts +9 -0
  154. package/lib/node/node/factory.d.ts.map +1 -0
  155. package/lib/node/node/index.d.ts +8 -0
  156. package/lib/node/node/index.d.ts.map +1 -0
  157. package/package.json +98 -0
package/lib/index.d.ts ADDED
@@ -0,0 +1,484 @@
1
+ interface PollOptions$1 {
2
+ checkCondition: () => Promise<any>;
3
+ stepName?: string;
4
+ interval?: number;
5
+ maxAttempts?: number;
6
+ backoffStrategy?: 'linear' | 'exponential';
7
+ onProgress?: (attempt: number, maxAttempts: number) => void;
8
+ }
9
+ declare class PollingManager$1 {
10
+ private baseInterval;
11
+ private maxAttempts;
12
+ private backoffStrategy;
13
+ constructor(options?: {
14
+ baseInterval?: number;
15
+ maxAttempts?: number;
16
+ backoffStrategy?: 'linear' | 'exponential';
17
+ });
18
+ poll<T>(options: PollOptions$1): Promise<T>;
19
+ private calculateWaitTime;
20
+ pollWithTimeout<T>(options: PollOptions$1, timeoutMs: number): Promise<T>;
21
+ pollBatch<T>(items: T[], checkCondition: (item: T) => Promise<boolean>, options?: Omit<PollOptions$1, 'checkCondition'>): Promise<T[]>;
22
+ }
23
+
24
+ /**
25
+ * HTTP request interface - abstracts HTTP implementation for different environments
26
+ */
27
+ interface HttpClient$1 {
28
+ get(url: string): Promise<any>;
29
+ post(url: string, data: any): Promise<any>;
30
+ }
31
+ /**
32
+ * Configuration provider interface - abstracts configuration retrieval for different environments
33
+ * Only responsible for getting raw blocklet information, unified processing logic is in SessionManager
34
+ */
35
+ interface ConfigProvider$1 {
36
+ getBlockletInfo(): Promise<any>;
37
+ }
38
+ /**
39
+ * Unified manager dependencies
40
+ */
41
+ interface ManagerDependencies$1 {
42
+ httpClient: HttpClient$1;
43
+ configProvider: ConfigProvider$1;
44
+ pollingManager: PollingManager$1;
45
+ }
46
+
47
+ type DeploymentStep$1 = 'creating_session' | 'waiting_payment' | 'installation_started' | 'installing' | 'starting_service' | 'getting_urls' | 'getting_vendors' | 'completed' | 'cancelled';
48
+ interface BrokerConfig$1 {
49
+ baseUrl: string;
50
+ authToken?: string;
51
+ paymentLinkKey?: string;
52
+ api?: any;
53
+ timeout?: number;
54
+ polling?: {
55
+ interval?: number;
56
+ maxAttempts?: number;
57
+ backoffStrategy?: 'linear' | 'exponential';
58
+ };
59
+ }
60
+ declare const STEPS$1: {
61
+ readonly PAYMENT_PENDING: "payment_pending";
62
+ readonly PAYMENT_COMPLETED: "payment_completed";
63
+ readonly INSTALLATION_STARTING: "installation_starting";
64
+ readonly INSTALLATION_COMPLETED: "installation_completed";
65
+ readonly SERVICE_STARTING: "service_starting";
66
+ readonly SERVICE_READY: "service_ready";
67
+ readonly ACCESS_PREPARING: "access_preparing";
68
+ readonly ACCESS_READY: "access_ready";
69
+ };
70
+ interface DeploymentHooks$1 {
71
+ [STEPS$1.PAYMENT_PENDING]?: (data: {
72
+ sessionId?: string;
73
+ paymentUrl?: string;
74
+ linkId?: string;
75
+ isResuming?: boolean;
76
+ }) => void;
77
+ [STEPS$1.PAYMENT_COMPLETED]?: (data: {
78
+ sessionId: string;
79
+ vendors: VendorInfo$1[];
80
+ }) => void;
81
+ [STEPS$1.INSTALLATION_STARTING]?: (data: {
82
+ vendors: VendorInfo$1[];
83
+ }) => void;
84
+ [STEPS$1.INSTALLATION_COMPLETED]?: (data: {
85
+ vendors: VendorInfo$1[];
86
+ progress?: number;
87
+ }) => void;
88
+ [STEPS$1.SERVICE_STARTING]?: (data: {
89
+ vendors: VendorInfo$1[];
90
+ }) => void;
91
+ [STEPS$1.SERVICE_READY]?: (data: {
92
+ vendors: VendorInfo$1[];
93
+ }) => void;
94
+ [STEPS$1.ACCESS_PREPARING]?: (data: {
95
+ sessionId: string;
96
+ }) => void;
97
+ [STEPS$1.ACCESS_READY]?: (data: {
98
+ sessionId: string;
99
+ appUrl?: string;
100
+ dashboardUrl?: string;
101
+ subscriptionUrl?: string;
102
+ homeUrl?: string;
103
+ }) => void;
104
+ }
105
+ interface DeploymentOptions$1 {
106
+ cachedCheckoutId?: string;
107
+ cachedPaymentUrl?: string;
108
+ needShortUrl?: boolean;
109
+ page_info: {
110
+ success_message: {
111
+ en: string;
112
+ zh: string;
113
+ };
114
+ };
115
+ [key: string]: any;
116
+ hooks?: DeploymentHooks$1;
117
+ onError?: (error: DeploymentError$1, step?: DeploymentStep$1) => void;
118
+ }
119
+ interface PaymentSession$1 {
120
+ id: string;
121
+ paymentUrl: string;
122
+ status: 'pending' | 'paid' | 'expired' | 'cancelled';
123
+ linkId: string;
124
+ vendorDid: string;
125
+ amount?: number;
126
+ currency?: string;
127
+ createdAt: string;
128
+ updatedAt: string;
129
+ expiresAt: string;
130
+ paidAt?: string;
131
+ metadata?: Record<string, any>;
132
+ }
133
+ interface VendorInfo$1 {
134
+ id: string;
135
+ name: string;
136
+ status: 'pending' | 'installing' | 'starting' | 'running' | 'failed';
137
+ progress: number;
138
+ appUrl?: string;
139
+ dashboardUrl?: string;
140
+ homeUrl?: string;
141
+ token?: string;
142
+ subscriptionUrl?: string;
143
+ metadata?: Record<string, any>;
144
+ details?: Record<string, any>;
145
+ }
146
+ interface DeploymentResult$1 {
147
+ success: boolean;
148
+ sessionId: string;
149
+ status?: string;
150
+ vendors?: VendorInfo$1[];
151
+ appUrl?: string;
152
+ homeUrl?: string;
153
+ dashboardUrl?: string;
154
+ token?: string;
155
+ subscriptionUrl?: string;
156
+ duration?: number;
157
+ startTime?: string;
158
+ endTime?: string;
159
+ metadata?: Record<string, any>;
160
+ data?: any;
161
+ completedAt?: string;
162
+ }
163
+ interface DeploymentError$1 extends Error {
164
+ code: ErrorCode$1;
165
+ step?: DeploymentStep$1;
166
+ sessionId?: string;
167
+ paymentUrl?: string;
168
+ linkId?: string;
169
+ timestamp?: string;
170
+ details?: Record<string, any>;
171
+ recovery?: {
172
+ canRetry?: boolean;
173
+ retryAfter?: number;
174
+ suggestions?: string[];
175
+ };
176
+ }
177
+ type ErrorCode$1 = 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'PAYMENT_ERROR' | 'VALIDATION_ERROR' | 'SESSION_ERROR' | 'DEPLOYMENT_ERROR' | 'VENDOR_ERROR' | 'INSTALLATION_ERROR' | 'SERVICE_ERROR' | 'ACCESS_ERROR' | 'CONFIG_ERROR' | 'UNKNOWN_ERROR';
178
+
179
+ /**
180
+ * Unified BrokerClient class
181
+ * Uses dependency injection to support different environment implementations
182
+ */
183
+ declare class BrokerClient {
184
+ private config;
185
+ private sessionManager;
186
+ private deploymentManager;
187
+ private isDeploying;
188
+ private currentDeployment;
189
+ constructor(config: Partial<BrokerConfig$1>, dependencies: ManagerDependencies$1);
190
+ deploy(options: DeploymentOptions$1): Promise<DeploymentResult$1>;
191
+ createSession(options?: Partial<DeploymentOptions$1>): Promise<PaymentSession$1>;
192
+ getSessionStatus(sessionId: string): Promise<any>;
193
+ cancelDeployment(): void;
194
+ getDeploymentStatus(): {
195
+ isDeploying: boolean;
196
+ result?: DeploymentResult$1 | null;
197
+ error?: DeploymentError$1 | null;
198
+ sessionId?: string;
199
+ duration?: number;
200
+ };
201
+ updateConfig(newConfig: Partial<BrokerConfig$1>): void;
202
+ getConfig(): BrokerConfig$1;
203
+ private validateConfig;
204
+ }
205
+
206
+ /**
207
+ * Creates a Node.js specific BrokerClient instance
208
+ * @param config - Partial configuration for the broker client
209
+ * @returns Configured BrokerClient instance with Node.js dependencies
210
+ */
211
+ declare function createNodeBrokerClient(config: Partial<BrokerConfig$1>): BrokerClient;
212
+
213
+ type DeploymentStatus = 'initializing' | 'creating_session' | 'payment_required' | 'payment_processing' | 'payment_completed' | 'installing' | 'starting_service' | 'getting_urls' | 'completed' | 'failed' | 'cancelled';
214
+ type DeploymentStep = 'creating_session' | 'waiting_payment' | 'installation_started' | 'installing' | 'starting_service' | 'getting_urls' | 'getting_vendors' | 'completed' | 'cancelled';
215
+ interface BrokerConfig {
216
+ baseUrl: string;
217
+ authToken?: string;
218
+ paymentLinkKey?: string;
219
+ api?: any;
220
+ timeout?: number;
221
+ polling?: {
222
+ interval?: number;
223
+ maxAttempts?: number;
224
+ backoffStrategy?: 'linear' | 'exponential';
225
+ };
226
+ }
227
+ declare const STEPS: {
228
+ readonly PAYMENT_PENDING: "payment_pending";
229
+ readonly PAYMENT_COMPLETED: "payment_completed";
230
+ readonly INSTALLATION_STARTING: "installation_starting";
231
+ readonly INSTALLATION_COMPLETED: "installation_completed";
232
+ readonly SERVICE_STARTING: "service_starting";
233
+ readonly SERVICE_READY: "service_ready";
234
+ readonly ACCESS_PREPARING: "access_preparing";
235
+ readonly ACCESS_READY: "access_ready";
236
+ };
237
+ interface DeploymentHooks {
238
+ [STEPS.PAYMENT_PENDING]?: (data: {
239
+ sessionId?: string;
240
+ paymentUrl?: string;
241
+ linkId?: string;
242
+ isResuming?: boolean;
243
+ }) => void;
244
+ [STEPS.PAYMENT_COMPLETED]?: (data: {
245
+ sessionId: string;
246
+ vendors: VendorInfo[];
247
+ }) => void;
248
+ [STEPS.INSTALLATION_STARTING]?: (data: {
249
+ vendors: VendorInfo[];
250
+ }) => void;
251
+ [STEPS.INSTALLATION_COMPLETED]?: (data: {
252
+ vendors: VendorInfo[];
253
+ progress?: number;
254
+ }) => void;
255
+ [STEPS.SERVICE_STARTING]?: (data: {
256
+ vendors: VendorInfo[];
257
+ }) => void;
258
+ [STEPS.SERVICE_READY]?: (data: {
259
+ vendors: VendorInfo[];
260
+ }) => void;
261
+ [STEPS.ACCESS_PREPARING]?: (data: {
262
+ sessionId: string;
263
+ }) => void;
264
+ [STEPS.ACCESS_READY]?: (data: {
265
+ sessionId: string;
266
+ appUrl?: string;
267
+ dashboardUrl?: string;
268
+ subscriptionUrl?: string;
269
+ homeUrl?: string;
270
+ }) => void;
271
+ }
272
+ interface DeploymentOptions {
273
+ cachedCheckoutId?: string;
274
+ cachedPaymentUrl?: string;
275
+ needShortUrl?: boolean;
276
+ page_info: {
277
+ success_message: {
278
+ en: string;
279
+ zh: string;
280
+ };
281
+ };
282
+ [key: string]: any;
283
+ hooks?: DeploymentHooks;
284
+ onError?: (error: DeploymentError, step?: DeploymentStep) => void;
285
+ }
286
+ interface PaymentSession {
287
+ id: string;
288
+ paymentUrl: string;
289
+ status: 'pending' | 'paid' | 'expired' | 'cancelled';
290
+ linkId: string;
291
+ vendorDid: string;
292
+ amount?: number;
293
+ currency?: string;
294
+ createdAt: string;
295
+ updatedAt: string;
296
+ expiresAt: string;
297
+ paidAt?: string;
298
+ metadata?: Record<string, any>;
299
+ }
300
+ interface VendorInfo {
301
+ id: string;
302
+ name: string;
303
+ status: 'pending' | 'installing' | 'starting' | 'running' | 'failed';
304
+ progress: number;
305
+ appUrl?: string;
306
+ dashboardUrl?: string;
307
+ homeUrl?: string;
308
+ token?: string;
309
+ subscriptionUrl?: string;
310
+ metadata?: Record<string, any>;
311
+ details?: Record<string, any>;
312
+ }
313
+ interface DeploymentResult {
314
+ success: boolean;
315
+ sessionId: string;
316
+ status?: string;
317
+ vendors?: VendorInfo[];
318
+ appUrl?: string;
319
+ homeUrl?: string;
320
+ dashboardUrl?: string;
321
+ token?: string;
322
+ subscriptionUrl?: string;
323
+ duration?: number;
324
+ startTime?: string;
325
+ endTime?: string;
326
+ metadata?: Record<string, any>;
327
+ data?: any;
328
+ completedAt?: string;
329
+ }
330
+ interface DeploymentError extends Error {
331
+ code: ErrorCode;
332
+ step?: DeploymentStep;
333
+ sessionId?: string;
334
+ paymentUrl?: string;
335
+ linkId?: string;
336
+ timestamp?: string;
337
+ details?: Record<string, any>;
338
+ recovery?: {
339
+ canRetry?: boolean;
340
+ retryAfter?: number;
341
+ suggestions?: string[];
342
+ };
343
+ }
344
+ type ErrorCode = 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'PAYMENT_ERROR' | 'VALIDATION_ERROR' | 'SESSION_ERROR' | 'DEPLOYMENT_ERROR' | 'VENDOR_ERROR' | 'INSTALLATION_ERROR' | 'SERVICE_ERROR' | 'ACCESS_ERROR' | 'CONFIG_ERROR' | 'UNKNOWN_ERROR';
345
+ interface DeploymentEvent {
346
+ type: string;
347
+ timestamp: string;
348
+ data?: any;
349
+ }
350
+ type DeploymentEventType = 'session.created' | 'payment.required' | 'payment.started' | 'payment.completed' | 'payment.failed' | 'installation.started' | 'installation.progress' | 'installation.completed' | 'service.started' | 'service.failed' | 'deployment.completed' | 'deployment.failed' | 'deployment.cancelled';
351
+ type PartialExcept<T, K extends keyof T> = Partial<T> & Pick<T, K>;
352
+ type DeepPartial<T> = {
353
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
354
+ };
355
+ declare const DEFAULT_CONFIG: {
356
+ timeout: number;
357
+ polling: {
358
+ interval: number;
359
+ maxAttempts: number;
360
+ backoffStrategy: "linear";
361
+ };
362
+ };
363
+ declare const API_ENDPOINTS: {
364
+ createCheckout: string;
365
+ paymentPage: string;
366
+ orderStatus: string;
367
+ orderDetail: string;
368
+ vendors: string;
369
+ };
370
+ declare const DEPLOYMENT_STEPS: {
371
+ readonly CREATING_SESSION: "creating_session";
372
+ readonly WAITING_PAYMENT: "waiting_payment";
373
+ readonly INSTALLING: "installing";
374
+ readonly STARTING_SERVICE: "starting_service";
375
+ readonly GETTING_URLS: "getting_urls";
376
+ readonly COMPLETED: "completed";
377
+ };
378
+ declare const ERROR_CODES: {
379
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
380
+ readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
381
+ readonly PAYMENT_ERROR: "PAYMENT_ERROR";
382
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
383
+ readonly SESSION_ERROR: "SESSION_ERROR";
384
+ readonly DEPLOYMENT_ERROR: "DEPLOYMENT_ERROR";
385
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
386
+ };
387
+
388
+ declare function createDeploymentError(message: string, code: ErrorCode, options?: {
389
+ step?: DeploymentStep;
390
+ sessionId?: string;
391
+ paymentUrl?: string;
392
+ linkId?: string;
393
+ details?: Record<string, any>;
394
+ recovery?: {
395
+ canRetry?: boolean;
396
+ retryAfter?: number;
397
+ suggestions?: string[];
398
+ };
399
+ }): DeploymentError;
400
+ declare function isDeploymentError(error: any): error is DeploymentError;
401
+
402
+ declare const httpUtils: {
403
+ request(url: string, options?: RequestInit): Promise<any>;
404
+ get(url: string, headers?: Record<string, string>): any;
405
+ post(url: string, data?: any, headers?: Record<string, string>): any;
406
+ put(url: string, data?: any, headers?: Record<string, string>): any;
407
+ delete(url: string, headers?: Record<string, string>): any;
408
+ };
409
+ declare const urlUtils: {
410
+ join(...parts: string[]): string;
411
+ addParams(url: string, params: Record<string, any>): string;
412
+ replaceParams(url: string, params: Record<string, string>): string;
413
+ isValidUrl(url: string): boolean;
414
+ };
415
+ declare const timeUtils: {
416
+ formatDuration(ms: number): string;
417
+ sleep(ms: number): Promise<void>;
418
+ timeout<T>(promise: Promise<T>, ms: number): Promise<T>;
419
+ now(): string;
420
+ };
421
+ declare const objectUtils: {
422
+ deepMerge<T extends Record<string, any>>(target: T, ...sources: Partial<T>[]): T;
423
+ isObject(item: any): item is Record<string, any>;
424
+ pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
425
+ omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
426
+ deepClone<T>(obj: T): T;
427
+ };
428
+
429
+ interface PollOptions {
430
+ checkCondition: () => Promise<any>;
431
+ stepName?: string;
432
+ interval?: number;
433
+ maxAttempts?: number;
434
+ backoffStrategy?: 'linear' | 'exponential';
435
+ onProgress?: (attempt: number, maxAttempts: number) => void;
436
+ }
437
+ declare class PollingManager {
438
+ private baseInterval;
439
+ private maxAttempts;
440
+ private backoffStrategy;
441
+ constructor(options?: {
442
+ baseInterval?: number;
443
+ maxAttempts?: number;
444
+ backoffStrategy?: 'linear' | 'exponential';
445
+ });
446
+ poll<T>(options: PollOptions): Promise<T>;
447
+ private calculateWaitTime;
448
+ pollWithTimeout<T>(options: PollOptions, timeoutMs: number): Promise<T>;
449
+ pollBatch<T>(items: T[], checkCondition: (item: T) => Promise<boolean>, options?: Omit<PollOptions, 'checkCondition'>): Promise<T[]>;
450
+ }
451
+
452
+ declare const logger: {
453
+ debug: (message: string, data?: any) => void;
454
+ info: (message: string, data?: any) => void;
455
+ warn: (message: string, data?: any) => void;
456
+ error: (message: string, data?: any) => void;
457
+ };
458
+ //# sourceMappingURL=logger.d.ts.map
459
+
460
+ /**
461
+ * HTTP request interface - abstracts HTTP implementation for different environments
462
+ */
463
+ interface HttpClient {
464
+ get(url: string): Promise<any>;
465
+ post(url: string, data: any): Promise<any>;
466
+ }
467
+ /**
468
+ * Configuration provider interface - abstracts configuration retrieval for different environments
469
+ * Only responsible for getting raw blocklet information, unified processing logic is in SessionManager
470
+ */
471
+ interface ConfigProvider {
472
+ getBlockletInfo(): Promise<any>;
473
+ }
474
+ /**
475
+ * Unified manager dependencies
476
+ */
477
+ interface ManagerDependencies {
478
+ httpClient: HttpClient;
479
+ configProvider: ConfigProvider;
480
+ pollingManager: PollingManager;
481
+ }
482
+
483
+ export { API_ENDPOINTS, createNodeBrokerClient as BrokerClient, DEFAULT_CONFIG, DEPLOYMENT_STEPS, ERROR_CODES, PollingManager, STEPS, createDeploymentError, httpUtils, isDeploymentError, logger, objectUtils, timeUtils, urlUtils };
484
+ export type { BrokerConfig, ConfigProvider, DeepPartial, DeploymentError, DeploymentEvent, DeploymentEventType, DeploymentHooks, DeploymentOptions, DeploymentResult, DeploymentStatus, DeploymentStep, ErrorCode, HttpClient, ManagerDependencies, PartialExcept, PaymentSession, PollOptions, VendorInfo };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,eAAe,CAAC;AAClD,cAAc,mBAAmB,CAAC"}