@plyaz/types 1.38.0 → 1.38.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,6 +39,7 @@ export type * from './pubsub/types';
39
39
  export type * from './hooks/types';
40
40
  export type * from './services/types';
41
41
  export type * from './encryption/types';
42
+ export type * from './upload';
42
43
  export type * from './endpoints/types';
43
44
  export type * from './endpoints/health/types';
44
45
  export type * from './endpoints/campaigns/types';
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Upload Types
3
+ * Types for upload functionality with progress tracking
4
+ */
5
+ import type { RetryConfig } from '../retry';
6
+ /**
7
+ * Upload error details passed to onError handler
8
+ */
9
+ export interface UploadError {
10
+ /** Error message */
11
+ message: string;
12
+ /** HTTP status code (if available) */
13
+ status?: number;
14
+ /** HTTP status text (if available) */
15
+ statusText?: string;
16
+ /** Original error object */
17
+ cause?: Error;
18
+ /** Whether the error is retryable */
19
+ retryable: boolean;
20
+ /** Current retry attempt (0 = first attempt) */
21
+ attempt: number;
22
+ /** Maximum retry attempts configured */
23
+ maxAttempts: number;
24
+ }
25
+ /**
26
+ * Error handler callback for upload errors
27
+ */
28
+ export type UploadErrorHandler = (error: UploadError) => void;
29
+ /**
30
+ * Upload progress event data
31
+ */
32
+ export interface UploadProgressEvent {
33
+ /** Bytes uploaded so far */
34
+ loaded: number;
35
+ /** Total bytes to upload */
36
+ total: number;
37
+ /** Percentage complete (0-100) */
38
+ percentage: number;
39
+ /** Upload speed in bytes per second */
40
+ speed?: number;
41
+ /** Estimated time remaining in seconds */
42
+ estimatedTimeRemaining?: number;
43
+ }
44
+ /**
45
+ * Progress callback function
46
+ */
47
+ export type UploadProgressCallback = (event: UploadProgressEvent) => void;
48
+ /**
49
+ * Options for uploadWithProgress function
50
+ */
51
+ export interface UploadWithProgressOptions {
52
+ /** Target URL to upload to */
53
+ url: string;
54
+ /** Data to upload (Buffer in Node.js, Blob/ArrayBuffer in browser) */
55
+ data: globalThis.Buffer | Blob | ArrayBuffer | Uint8Array;
56
+ /** HTTP method (default: PUT) */
57
+ method?: 'PUT' | 'POST';
58
+ /** Additional headers to send (merged with global config headers if useGlobalConfig is true) */
59
+ headers?: Record<string, string>;
60
+ /** Content-Type header (default: application/octet-stream) */
61
+ contentType?: string;
62
+ /** Progress callback */
63
+ onProgress?: UploadProgressCallback;
64
+ /** Abort signal for cancellation */
65
+ abortSignal?: AbortSignal;
66
+ /** Chunk size for progress reporting in bytes (default: 65536 = 64KB) */
67
+ chunkSize?: number;
68
+ /** Minimum time between progress events in ms (default: 100) */
69
+ throttleMs?: number;
70
+ /**
71
+ * Whether to use global API client configuration.
72
+ * When true, merges config from getGlobalConfig() with provided options.
73
+ * Affects: headers, timeout, baseURL, retry, onError, withCredentials
74
+ * Default: true
75
+ */
76
+ useGlobalConfig?: boolean;
77
+ /**
78
+ * Timeout in milliseconds. If not provided and useGlobalConfig is true,
79
+ * uses timeout from global config.
80
+ */
81
+ timeout?: number;
82
+ /**
83
+ * Base URL to prepend to relative URLs.
84
+ * If url starts with '/', baseURL will be prepended.
85
+ * If not provided and useGlobalConfig is true, uses baseURL from global config.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * uploadWithProgress({
90
+ * baseURL: 'https://api.example.com',
91
+ * url: '/upload', // becomes https://api.example.com/upload
92
+ * data: buffer,
93
+ * });
94
+ * ```
95
+ */
96
+ baseURL?: string;
97
+ /**
98
+ * Retry configuration for failed uploads.
99
+ * Set to false to disable retries.
100
+ * If not provided and useGlobalConfig is true, uses retry from global config.
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * uploadWithProgress({
105
+ * url: 'https://api.example.com/upload',
106
+ * data: buffer,
107
+ * retry: {
108
+ * attempts: 3,
109
+ * delay: 1000,
110
+ * backoff: 2,
111
+ * },
112
+ * });
113
+ * ```
114
+ */
115
+ retry?: RetryConfig | false;
116
+ /**
117
+ * Error handler callback called on upload errors.
118
+ * Called for each error including retries.
119
+ * If not provided and useGlobalConfig is true, uses onError from global config.
120
+ */
121
+ onError?: UploadErrorHandler;
122
+ /**
123
+ * Include credentials (cookies) in cross-origin requests.
124
+ * Only applicable in browser environments.
125
+ * If not provided and useGlobalConfig is true, uses withCredentials from global config.
126
+ */
127
+ withCredentials?: boolean;
128
+ }
129
+ /**
130
+ * Result from uploadWithProgress function
131
+ */
132
+ export interface UploadWithProgressResult {
133
+ /** HTTP status code */
134
+ status: number;
135
+ /** HTTP status text */
136
+ statusText: string;
137
+ /** Response body (if any) */
138
+ data?: string;
139
+ /** Response headers */
140
+ headers?: Record<string, string>;
141
+ /** Whether the upload was successful (2xx status) */
142
+ success: boolean;
143
+ /** Number of retry attempts made (0 = succeeded on first attempt) */
144
+ attempts?: number;
145
+ }
146
+ /**
147
+ * Upload state for tracking
148
+ */
149
+ export type UploadStatus = 'pending' | 'uploading' | 'completed' | 'failed' | 'aborted';
150
+ /**
151
+ * Internal upload state tracking
152
+ */
153
+ export interface UploadState {
154
+ /** Current status */
155
+ status: UploadStatus;
156
+ /** Start time of upload */
157
+ startTime: number;
158
+ /** Bytes uploaded */
159
+ bytesUploaded: number;
160
+ /** Total bytes */
161
+ totalBytes: number;
162
+ /** Last progress update time */
163
+ lastProgressTime: number;
164
+ /** Last bytes uploaded (for speed calculation) */
165
+ lastBytesUploaded: number;
166
+ /** Error if failed */
167
+ error?: Error;
168
+ }
169
+ /**
170
+ * Merged configuration for upload operations
171
+ * Created by combining global config with per-request options
172
+ */
173
+ export interface MergedUploadConfig {
174
+ /** Headers to send with the upload */
175
+ headers: Record<string, string>;
176
+ /** Timeout in milliseconds */
177
+ timeout: number;
178
+ /** Base URL to prepend to relative URLs */
179
+ baseURL?: string;
180
+ /** Retry configuration or false to disable */
181
+ retry: RetryConfig | false;
182
+ /** Error handler callback */
183
+ onError?: UploadErrorHandler;
184
+ /** Include credentials in cross-origin requests */
185
+ withCredentials: boolean;
186
+ }
187
+ /**
188
+ * Context for retry operations
189
+ */
190
+ export interface RetryContext {
191
+ /** Merged upload configuration */
192
+ config: MergedUploadConfig;
193
+ /** Maximum number of retry attempts */
194
+ maxAttempts: number;
195
+ /** Current attempt number (0-based) */
196
+ attempt: number;
197
+ }
198
+ /**
199
+ * Parameters for retry error notification
200
+ */
201
+ export interface RetryErrorParams {
202
+ /** Retry context */
203
+ ctx: RetryContext;
204
+ /** Error message */
205
+ message: string;
206
+ /** HTTP status code */
207
+ status?: number;
208
+ /** HTTP status text */
209
+ statusText?: string;
210
+ /** Original error cause */
211
+ cause?: Error;
212
+ }
@@ -1,6 +1,7 @@
1
1
  import type { CurrencyCode } from '../../../../locale/types';
2
2
  import type { PAYMENT_METHOD, PAYMENT_PROVIDER_TYPE } from '../../../provider';
3
- import type { Money } from '../../../transaction';
3
+ import type { FeeBreakdown, Money } from '../../../transaction';
4
+ import type { ProviderFeeConfiguration } from '../types';
4
5
  import type { FEE_CONTEXT, FEE_TYPE } from './enum';
5
6
  export interface CalculateFeeParams {
6
7
  amount: Money;
@@ -11,14 +12,6 @@ export interface CalculateFeeParams {
11
12
  expedite?: boolean;
12
13
  highRisk?: boolean;
13
14
  }
14
- export interface FeeMetadata {
15
- processingRate?: number;
16
- platformRate?: number;
17
- crossBorderRate?: number;
18
- conversionRate?: number;
19
- calculatedAt: Date;
20
- ruleVersion?: string;
21
- }
22
15
  /**
23
16
  * Unified Fee Rule
24
17
  */
@@ -36,3 +29,31 @@ export interface FeeRule<TMetadata extends object = {}> {
36
29
  maxLimit?: number;
37
30
  metadata?: TMetadata;
38
31
  }
32
+ export type HandlerParams = CalculateFeeParams;
33
+ export type FeeSection = Partial<{
34
+ processingFee: Money;
35
+ platformFee: Money;
36
+ crossBorderFee: Money;
37
+ currencyConversionFee: Money;
38
+ riskFee: Money;
39
+ complianceFee: Money;
40
+ expediteFee: Money;
41
+ networkFee: Money;
42
+ gasFee: Money;
43
+ chargebackFee: Money;
44
+ refundFee: Money;
45
+ }>;
46
+ export type FeeMetadata = Partial<{
47
+ calculatedAt: Date;
48
+ processingRate: number;
49
+ platformRate: number;
50
+ crossBorderRate: number;
51
+ conversionRate: number;
52
+ }>;
53
+ export interface ApplyFeeRuleType {
54
+ config: FeeRule;
55
+ params: CalculateFeeParams;
56
+ fees: Partial<FeeBreakdown>;
57
+ metadata: FeeMetadata;
58
+ calculation: ProviderFeeConfiguration['calculation'];
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plyaz/types",
3
- "version": "1.38.0",
3
+ "version": "1.38.2",
4
4
  "author": "Redeemer Pace",
5
5
  "license": "ISC",
6
6
  "description": "Provides shared TypeScript types and schema utilities for validation and parsing in the @playz ecosystem.",