@1shotapi/1shotpay-common 0.1.0

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,697 @@
1
+ import { ResultAsync } from 'neverthrow';
2
+ import * as ts_brand from 'ts-brand';
3
+ import { Brand } from 'ts-brand';
4
+
5
+ declare enum EHttpStatusCode {
6
+ /**
7
+ * The server has received the request headers and the client should proceed to send the request body
8
+ * (in the case of a request for which a body needs to be sent; for example, a POST request).
9
+ * Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient.
10
+ * To have a server check the request's headers, a client must send Expect: 100-continue as a header in its initial request
11
+ * and receive a 100 Continue status code in response before sending the body. The response 417 Expectation Failed indicates the request should not be continued.
12
+ */
13
+ CONTINUE = 100,
14
+ /**
15
+ * The requester has asked the server to switch protocols and the server has agreed to do so.
16
+ */
17
+ SWITCHING_PROTOCOLS = 101,
18
+ /**
19
+ * A WebDAV request may contain many sub-requests involving file operations, requiring a long time to complete the request.
20
+ * This code indicates that the server has received and is processing the request, but no response is available yet.
21
+ * This prevents the client from timing out and assuming the request was lost.
22
+ */
23
+ PROCESSING = 102,
24
+ /**
25
+ * Standard response for successful HTTP requests.
26
+ * The actual response will depend on the request method used.
27
+ * In a GET request, the response will contain an entity corresponding to the requested resource.
28
+ * In a POST request, the response will contain an entity describing or containing the result of the action.
29
+ */
30
+ OK = 200,
31
+ /**
32
+ * The request has been fulfilled, resulting in the creation of a new resource.
33
+ */
34
+ CREATED = 201,
35
+ /**
36
+ * The request has been accepted for processing, but the processing has not been completed.
37
+ * The request might or might not be eventually acted upon, and may be disallowed when processing occurs.
38
+ */
39
+ ACCEPTED = 202,
40
+ /**
41
+ * SINCE HTTP/1.1
42
+ * The server is a transforming proxy that received a 200 OK from its origin,
43
+ * but is returning a modified version of the origin's response.
44
+ */
45
+ NON_AUTHORITATIVE_INFORMATION = 203,
46
+ /**
47
+ * The server successfully processed the request and is not returning any content.
48
+ */
49
+ NO_CONTENT = 204,
50
+ /**
51
+ * The server successfully processed the request, but is not returning any content.
52
+ * Unlike a 204 response, this response requires that the requester reset the document view.
53
+ */
54
+ RESET_CONTENT = 205,
55
+ /**
56
+ * The server is delivering only part of the resource (byte serving) due to a range header sent by the client.
57
+ * The range header is used by HTTP clients to enable resuming of interrupted downloads,
58
+ * or split a download into multiple simultaneous streams.
59
+ */
60
+ PARTIAL_CONTENT = 206,
61
+ /**
62
+ * The message body that follows is an XML message and can contain a number of separate response codes,
63
+ * depending on how many sub-requests were made.
64
+ */
65
+ MULTI_STATUS = 207,
66
+ /**
67
+ * The members of a DAV binding have already been enumerated in a preceding part of the (multistatus) response,
68
+ * and are not being included again.
69
+ */
70
+ ALREADY_REPORTED = 208,
71
+ /**
72
+ * The server has fulfilled a request for the resource,
73
+ * and the response is a representation of the result of one or more instance-manipulations applied to the current instance.
74
+ */
75
+ IM_USED = 226,
76
+ /**
77
+ * Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation).
78
+ * For example, this code could be used to present multiple video format options,
79
+ * to list files with different filename extensions, or to suggest word-sense disambiguation.
80
+ */
81
+ MULTIPLE_CHOICES = 300,
82
+ /**
83
+ * This and all future requests should be directed to the given URI.
84
+ */
85
+ MOVED_PERMANENTLY = 301,
86
+ /**
87
+ * This is an example of industry practice contradicting the standard.
88
+ * The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
89
+ * (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
90
+ * with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
91
+ * to distinguish between the two behaviours. However, some Web applications and frameworks
92
+ * use the 302 status code as if it were the 303.
93
+ */
94
+ FOUND = 302,
95
+ /**
96
+ * SINCE HTTP/1.1
97
+ * The response to the request can be found under another URI using a GET method.
98
+ * When received in response to a POST (or PUT/DELETE), the client should presume that
99
+ * the server has received the data and should issue a redirect with a separate GET message.
100
+ */
101
+ SEE_OTHER = 303,
102
+ /**
103
+ * Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.
104
+ * In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.
105
+ */
106
+ NOT_MODIFIED = 304,
107
+ /**
108
+ * SINCE HTTP/1.1
109
+ * The requested resource is available only through a proxy, the address for which is provided in the response.
110
+ * Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle responses with this status code, primarily for security reasons.
111
+ */
112
+ USE_PROXY = 305,
113
+ /**
114
+ * No longer used. Originally meant "Subsequent requests should use the specified proxy."
115
+ */
116
+ SWITCH_PROXY = 306,
117
+ /**
118
+ * SINCE HTTP/1.1
119
+ * In this case, the request should be repeated with another URI; however, future requests should still use the original URI.
120
+ * In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request.
121
+ * For example, a POST request should be repeated using another POST request.
122
+ */
123
+ TEMPORARY_REDIRECT = 307,
124
+ /**
125
+ * The request and all future requests should be repeated using another URI.
126
+ * 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.
127
+ * So, for example, submitting a form to a permanently redirected resource may continue smoothly.
128
+ */
129
+ PERMANENT_REDIRECT = 308,
130
+ /**
131
+ * The server cannot or will not process the request due to an apparent client error
132
+ * (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).
133
+ */
134
+ BAD_REQUEST = 400,
135
+ /**
136
+ * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet
137
+ * been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the
138
+ * requested resource. See Basic access authentication and Digest access authentication. 401 semantically means
139
+ * "unauthenticated",i.e. the user does not have the necessary credentials.
140
+ */
141
+ UNAUTHORIZED = 401,
142
+ /**
143
+ * Reserved for future use. The original intention was that this code might be used as part of some form of digital
144
+ * cash or micro payment scheme, but that has not happened, and this code is not usually used.
145
+ * Google Developers API uses this status if a particular developer has exceeded the daily limit on requests.
146
+ */
147
+ PAYMENT_REQUIRED = 402,
148
+ /**
149
+ * The request was valid, but the server is refusing action.
150
+ * The user might not have the necessary permissions for a resource.
151
+ */
152
+ FORBIDDEN = 403,
153
+ /**
154
+ * The requested resource could not be found but may be available in the future.
155
+ * Subsequent requests by the client are permissible.
156
+ */
157
+ NOT_FOUND = 404,
158
+ /**
159
+ * A request method is not supported for the requested resource;
160
+ * for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.
161
+ */
162
+ METHOD_NOT_ALLOWED = 405,
163
+ /**
164
+ * The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.
165
+ */
166
+ NOT_ACCEPTABLE = 406,
167
+ /**
168
+ * The client must first authenticate itself with the proxy.
169
+ */
170
+ PROXY_AUTHENTICATION_REQUIRED = 407,
171
+ /**
172
+ * The server timed out waiting for the request.
173
+ * According to HTTP specifications:
174
+ * "The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time."
175
+ */
176
+ REQUEST_TIMEOUT = 408,
177
+ /**
178
+ * Indicates that the request could not be processed because of conflict in the request,
179
+ * such as an edit conflict between multiple simultaneous updates.
180
+ */
181
+ CONFLICT = 409,
182
+ /**
183
+ * Indicates that the resource requested is no longer available and will not be available again.
184
+ * This should be used when a resource has been intentionally removed and the resource should be purged.
185
+ * Upon receiving a 410 status code, the client should not request the resource in the future.
186
+ * Clients such as search engines should remove the resource from their indices.
187
+ * Most use cases do not require clients and search engines to purge the resource, and a "404 Not Found" may be used instead.
188
+ */
189
+ GONE = 410,
190
+ /**
191
+ * The request did not specify the length of its content, which is required by the requested resource.
192
+ */
193
+ LENGTH_REQUIRED = 411,
194
+ /**
195
+ * The server does not meet one of the preconditions that the requester put on the request.
196
+ */
197
+ PRECONDITION_FAILED = 412,
198
+ /**
199
+ * The request is larger than the server is willing or able to process. Previously called "Request Entity Too Large".
200
+ */
201
+ PAYLOAD_TOO_LARGE = 413,
202
+ /**
203
+ * The URI provided was too long for the server to process. Often the result of too much data being encoded as a query-string of a GET request,
204
+ * in which case it should be converted to a POST request.
205
+ * Called "Request-URI Too Long" previously.
206
+ */
207
+ URI_TOO_LONG = 414,
208
+ /**
209
+ * The request entity has a media type which the server or resource does not support.
210
+ * For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.
211
+ */
212
+ UNSUPPORTED_MEDIA_TYPE = 415,
213
+ /**
214
+ * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.
215
+ * For example, if the client asked for a part of the file that lies beyond the end of the file.
216
+ * Called "Requested Range Not Satisfiable" previously.
217
+ */
218
+ RANGE_NOT_SATISFIABLE = 416,
219
+ /**
220
+ * The server cannot meet the requirements of the Expect request-header field.
221
+ */
222
+ EXPECTATION_FAILED = 417,
223
+ /**
224
+ * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol,
225
+ * and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by
226
+ * teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including Google.com.
227
+ */
228
+ I_AM_A_TEAPOT = 418,
229
+ /**
230
+ * The request was directed at a server that is not able to produce a response (for example because a connection reuse).
231
+ */
232
+ MISDIRECTED_REQUEST = 421,
233
+ /**
234
+ * The request was well-formed but was unable to be followed due to semantic errors.
235
+ */
236
+ UNPROCESSABLE_ENTITY = 422,
237
+ /**
238
+ * The resource that is being accessed is locked.
239
+ */
240
+ LOCKED = 423,
241
+ /**
242
+ * The request failed due to failure of a previous request (e.g., a PROPPATCH).
243
+ */
244
+ FAILED_DEPENDENCY = 424,
245
+ /**
246
+ * The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.
247
+ */
248
+ UPGRADE_REQUIRED = 426,
249
+ /**
250
+ * The origin server requires the request to be conditional.
251
+ * Intended to prevent "the 'lost update' problem, where a client
252
+ * GETs a resource's state, modifies it, and PUTs it back to the server,
253
+ * when meanwhile a third party has modified the state on the server, leading to a conflict."
254
+ */
255
+ PRECONDITION_REQUIRED = 428,
256
+ /**
257
+ * The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.
258
+ */
259
+ TOO_MANY_REQUESTS = 429,
260
+ /**
261
+ * The server is unwilling to process the request because either an individual header field,
262
+ * or all the header fields collectively, are too large.
263
+ */
264
+ REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
265
+ /**
266
+ * A server operator has received a legal demand to deny access to a resource or to a set of resources
267
+ * that includes the requested resource. The code 451 was chosen as a reference to the novel Fahrenheit 451.
268
+ */
269
+ UNAVAILABLE_FOR_LEGAL_REASONS = 451,
270
+ /**
271
+ * A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
272
+ */
273
+ INTERNAL_SERVER_ERROR = 500,
274
+ /**
275
+ * The server either does not recognize the request method, or it lacks the ability to fulfill the request.
276
+ * Usually this implies future availability (e.g., a new feature of a web-service API).
277
+ */
278
+ NOT_IMPLEMENTED = 501,
279
+ /**
280
+ * The server was acting as a gateway or proxy and received an invalid response from the upstream server.
281
+ */
282
+ BAD_GATEWAY = 502,
283
+ /**
284
+ * The server is currently unavailable (because it is overloaded or down for maintenance).
285
+ * Generally, this is a temporary state.
286
+ */
287
+ SERVICE_UNAVAILABLE = 503,
288
+ /**
289
+ * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
290
+ */
291
+ GATEWAY_TIMEOUT = 504,
292
+ /**
293
+ * The server does not support the HTTP protocol version used in the request
294
+ */
295
+ HTTP_VERSION_NOT_SUPPORTED = 505,
296
+ /**
297
+ * Transparent content negotiation for the request results in a circular reference.
298
+ */
299
+ VARIANT_ALSO_NEGOTIATES = 506,
300
+ /**
301
+ * The server is unable to store the representation needed to complete the request.
302
+ */
303
+ INSUFFICIENT_STORAGE = 507,
304
+ /**
305
+ * The server detected an infinite loop while processing the request.
306
+ */
307
+ LOOP_DETECTED = 508,
308
+ /**
309
+ * Further extensions to the request are required for the server to fulfill it.
310
+ */
311
+ NOT_EXTENDED = 510,
312
+ /**
313
+ * The client needs to authenticate to gain network access.
314
+ * Intended for use by intercepting proxies used to control access to the network (e.g., "captive portals" used
315
+ * to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).
316
+ */
317
+ NETWORK_AUTHENTICATION_REQUIRED = 511
318
+ }
319
+
320
+ declare enum ELocale {
321
+ English = "en",
322
+ Spanish = "es",
323
+ Turkish = "tr"
324
+ }
325
+
326
+ declare enum EPayLinkStatus {
327
+ Active = 0,
328
+ Paid = 1,
329
+ Expired = 2
330
+ }
331
+
332
+ /**
333
+ * API token for machine-to-machine authentication
334
+ */
335
+ type ApiToken = Brand<string, "ApiToken">;
336
+ declare const ApiToken: ts_brand.Brander<ApiToken>;
337
+
338
+ /**
339
+ * This is a string representation of a big number. These values can be directly converted to a bigint.
340
+ */
341
+ type BigNumberString = Brand<string, "BigNumberString">;
342
+ declare const BigNumberString: ts_brand.Brander<BigNumberString>;
343
+
344
+ /**
345
+ * This is base64 encoded string
346
+ */
347
+ type Base64String = Brand<string, "Base64String">;
348
+ declare const Base64String: ts_brand.Brander<Base64String>;
349
+
350
+ type DecimalAmount = Brand<number, "DecimalAmount">;
351
+ declare const DecimalAmount: ts_brand.Brander<DecimalAmount>;
352
+
353
+ /**
354
+ * This is a 20-byte Ethereum account address, prefixed with "0x".
355
+ */
356
+ type EVMAccountAddress = Brand<string, "EVMAccountAddress">;
357
+ declare const EVMAccountAddress: ts_brand.Brander<EVMAccountAddress>;
358
+
359
+ /**
360
+ * This is a 20-byte Ethereum contract address, prefixed with "0x".
361
+ */
362
+ type EVMContractAddress = Brand<string, "EVMContractAddress">;
363
+ declare const EVMContractAddress: ts_brand.Brander<EVMContractAddress>;
364
+
365
+ type HexString = Brand<string, "HexString">;
366
+ declare const HexString: ts_brand.Brander<HexString>;
367
+
368
+ /**
369
+ * An ISO 8601 date string, in the format YYYY-MM-DDTHH:MM:SS.SSSZ
370
+ * This is the same format as the ISO 8601 date string returned by the JavaScript Date object.
371
+ */
372
+ type ISO8601DateString = Brand<string, "ISO8601DateString">;
373
+ declare const ISO8601DateString: ts_brand.Brander<ISO8601DateString>;
374
+
375
+ /**
376
+ * This is a JWT, still in Base64 format.
377
+ */
378
+ type JsonWebToken = Brand<string, "JsonWebToken">;
379
+ declare const JsonWebToken: ts_brand.Brander<JsonWebToken>;
380
+
381
+ /**
382
+ * This is a hex encoded binary data string that contains Solidity Call Data. It is prefixed with a "0x".
383
+ */
384
+ type JSONString = Brand<string, "JSONString">;
385
+ declare const JSONString: ts_brand.Brander<JSONString>;
386
+
387
+ /**
388
+ * This is a Unix timestamp, in milliseconds, the default for javascript. Not seconds, which is the default for Unix
389
+ */
390
+ type MillisecondTimestamp = Brand<number, "MillisecondTimestamp">;
391
+ declare const MillisecondTimestamp: ts_brand.Brander<MillisecondTimestamp>;
392
+
393
+ /**
394
+ * This is a v7 UUID, like "123e4567-e89b-12d3-a456-426614174000"
395
+ */
396
+ type PayLinkId = Brand<string, "PayLinkId">;
397
+ declare const PayLinkId: ts_brand.Brander<PayLinkId>;
398
+
399
+ /**
400
+ * This is a v7 UUID, like "123e4567-e89b-12d3-a456-426614174000"
401
+ */
402
+ type PayLinkPaymentId = Brand<string, "PayLinkPaymentId">;
403
+ declare const PayLinkPaymentId: ts_brand.Brander<PayLinkPaymentId>;
404
+
405
+ /**
406
+ * The ID of a transaction from the Relayer API.
407
+ */
408
+ type RelayerTransactionId = Brand<string, "RelayerTransactionId">;
409
+ declare const RelayerTransactionId: ts_brand.Brander<RelayerTransactionId>;
410
+
411
+ /**
412
+ * This is an EVM ERC-712 signature, hex encoded and prefixed with 0x.
413
+ */
414
+ type Signature = Brand<string, "Signature">;
415
+ declare const Signature: ts_brand.Brander<Signature>;
416
+
417
+ /**
418
+ * A blockchain transaction hash.
419
+ */
420
+ type TransactionHash = Brand<string, "TransactionHash">;
421
+ declare const TransactionHash: ts_brand.Brander<TransactionHash>;
422
+
423
+ /**
424
+ * This is a Unix timestamp, in seconds. Not milliseconds, which is the default for JavaScript.
425
+ */
426
+ type UnixTimestamp = Brand<number, "UnixTimestamp">;
427
+ declare const UnixTimestamp: ts_brand.Brander<UnixTimestamp>;
428
+
429
+ /**
430
+ * This is a complete URL string, including the protocol, domain, and path. It can include a query string.
431
+ */
432
+ type URLString = Brand<string, "URLString">;
433
+ declare const URLString: ts_brand.Brander<URLString>;
434
+
435
+ type USDCAmount = Brand<number, "USDCAmount">;
436
+ declare const USDCAmount: ts_brand.Brander<USDCAmount>;
437
+
438
+ /**
439
+ * This is a v7 UUID, like "123e4567-e89b-12d3-a456-426614174000"
440
+ */
441
+ type UserId = Brand<string, "UserId">;
442
+ declare const UserId: ts_brand.Brander<UserId>;
443
+
444
+ /**
445
+ * A Username string. The DB supports up to 128 characters.
446
+ * It is used to identify a user in the system.
447
+ * It is not case sensitive and must be unique.
448
+ * It is not null.
449
+ * It is not empty.
450
+ * It is not a UUID.
451
+ * It is not a URL.
452
+ * It is not a JSON string.
453
+ */
454
+ type Username = Brand<string, "Username">;
455
+ declare const Username: ts_brand.Brander<Username>;
456
+
457
+ interface IERC3009TransferWithAuthorization {
458
+ from: EVMAccountAddress;
459
+ to: EVMAccountAddress;
460
+ value: BigNumberString;
461
+ validAfter: UnixTimestamp;
462
+ validBefore: UnixTimestamp;
463
+ nonce: HexString;
464
+ }
465
+ interface ISignedERC3009TransferWithAuthorization extends IERC3009TransferWithAuthorization {
466
+ signature: Signature;
467
+ }
468
+ interface IPermitTransfer {
469
+ owner: EVMAccountAddress;
470
+ spender: EVMAccountAddress;
471
+ value: BigNumberString;
472
+ nonce: BigNumberString;
473
+ deadline: UnixTimestamp;
474
+ }
475
+ interface ISignedPermitTransfer extends IPermitTransfer {
476
+ signature: Signature;
477
+ }
478
+
479
+ declare abstract class BaseError extends Error {
480
+ abstract readonly errorCode: string;
481
+ abstract readonly errorType: string;
482
+ abstract readonly httpStatus: EHttpStatusCode;
483
+ constructor(src: Error, errorType: string);
484
+ getErrorDetails(): {
485
+ name: string;
486
+ message: string;
487
+ errorCode: string;
488
+ errorType: string;
489
+ stack: string | undefined;
490
+ };
491
+ }
492
+
493
+ declare class AjaxError extends BaseError {
494
+ readonly errorCode: "ERR_AJAX";
495
+ readonly errorType = "AjaxError";
496
+ readonly httpStatus = EHttpStatusCode.INTERNAL_SERVER_ERROR;
497
+ constructor(src: Error);
498
+ static fromError(src: Error): AjaxError;
499
+ static isError(error: unknown): error is AjaxError;
500
+ }
501
+
502
+ declare class ProxyError extends BaseError {
503
+ readonly errorCode: "ERR_PROXY";
504
+ readonly errorType = "ProxyError";
505
+ readonly httpStatus = EHttpStatusCode.INTERNAL_SERVER_ERROR;
506
+ constructor(src: Error);
507
+ static fromError(src: Error): ProxyError;
508
+ static isError(error: unknown): error is ProxyError;
509
+ }
510
+
511
+ declare class RetryError extends BaseError {
512
+ readonly errorCode: "ERR_RETRY";
513
+ readonly errorType = "REtryError";
514
+ readonly httpStatus = EHttpStatusCode.I_AM_A_TEAPOT;
515
+ constructor(src: Error);
516
+ static fromError(src: Error): RetryError;
517
+ static isError(error: unknown): error is RetryError;
518
+ }
519
+
520
+ declare class ValidationError extends BaseError {
521
+ readonly errorCode: "ERR_VALIDATION";
522
+ readonly errorType = "ValidationError";
523
+ readonly httpStatus = EHttpStatusCode.BAD_REQUEST;
524
+ constructor(src: Error);
525
+ static fromError(src: Error): ValidationError;
526
+ static isError(error: unknown): error is ValidationError;
527
+ }
528
+
529
+ declare class OAuthTokenModel {
530
+ readonly access_token: JsonWebToken;
531
+ readonly token_type: "Bearer";
532
+ readonly expires_in: number;
533
+ constructor(access_token: JsonWebToken, token_type: "Bearer", expires_in: number);
534
+ }
535
+
536
+ interface IUserModel {
537
+ id: UserId;
538
+ username: Username;
539
+ accountAddress: EVMAccountAddress;
540
+ profileText: string | null;
541
+ profileImageUrl: URLString | null;
542
+ accountRecoveryDataCreated: boolean;
543
+ hasApiToken: boolean;
544
+ }
545
+
546
+ /**
547
+ * Request config based on fetch's RequestInit, excluding method and body.
548
+ * Use this to pass headers, signal, credentials, etc.
549
+ */
550
+ type IAjaxRequestConfig = Omit<RequestInit, "method" | "body">;
551
+ /**
552
+ * Body for POST / PUT. Can be fetch BodyInit or JSON-serializable data.
553
+ */
554
+ type IAjaxRequestBody = BodyInit | Record<string, unknown> | Array<Record<string, unknown>>;
555
+ /**
556
+ * Wrapper around fetch for HTTP calls. Kept abstract for testing.
557
+ * Implementations use fetch; no Axios or extra dependencies.
558
+ */
559
+ interface IAjaxUtils {
560
+ get<T>(url: URL | string, config?: IAjaxRequestConfig): ResultAsync<T, AjaxError>;
561
+ post<T>(url: URL | string, data?: IAjaxRequestBody, config?: IAjaxRequestConfig): ResultAsync<T, AjaxError>;
562
+ put<T>(url: URL | string, data: IAjaxRequestBody, config?: IAjaxRequestConfig): ResultAsync<T, AjaxError>;
563
+ delete<T>(url: URL | string, config?: IAjaxRequestConfig): ResultAsync<T, AjaxError>;
564
+ setDefaultToken(token: JsonWebToken): void;
565
+ }
566
+
567
+ /**
568
+ * Fetch-based implementation of IAjaxUtils.
569
+ * Uses the global fetch (browser or Node 18+).
570
+ */
571
+ declare class AjaxUtils implements IAjaxUtils {
572
+ private defaultToken;
573
+ setDefaultToken(token: JsonWebToken): void;
574
+ get<T>(url: URL | string, config?: IAjaxRequestConfig): ResultAsync<T, AjaxError>;
575
+ post<T>(url: URL | string, data?: IAjaxRequestBody, config?: IAjaxRequestConfig): ResultAsync<T, AjaxError>;
576
+ put<T>(url: URL | string, data: IAjaxRequestBody, config?: IAjaxRequestConfig): ResultAsync<T, AjaxError>;
577
+ delete<T>(url: URL | string, config?: IAjaxRequestConfig): ResultAsync<T, AjaxError>;
578
+ private mergeConfig;
579
+ private doFetch;
580
+ }
581
+
582
+ interface ITimeUtils {
583
+ getUnixNow(): UnixTimestamp;
584
+ getMillisecondNow(): MillisecondTimestamp;
585
+ getISO8601TimeString(time: MillisecondTimestamp): ISO8601DateString;
586
+ convertTimestampToISOString(unixTimestamp: UnixTimestamp): ISO8601DateString;
587
+ convertISOStringToTimestamp(isoString: ISO8601DateString): UnixTimestamp;
588
+ getUnixTodayStart(): UnixTimestamp;
589
+ getUnixTodayEnd(): UnixTimestamp;
590
+ getStartOfMonth(): UnixTimestamp;
591
+ }
592
+ declare const ITimeUtilsType: unique symbol;
593
+
594
+ declare class ObjectUtils {
595
+ static mergeDeep<T = unknown>(...objects: any[]): T;
596
+ /**
597
+ * This method is an improvement on JSON.stringify. It uses a stable stringify method so that objects will always generate the same
598
+ * hash, and it support a few non-serializeable types that are useful, such as BigInt, Map, and Set. The output is correct JSON
599
+ * but uses markup to support the non-native types and must be deserialized with the deserialize() method to get the same object
600
+ * back.
601
+ * @param obj
602
+ * @returns
603
+ */
604
+ static serialize(obj: unknown): JSONString;
605
+ static deserialize<T = Record<string, unknown>>(json: JSONString): ResultAsync<T, ValidationError>;
606
+ static deserializeUnsafe<T = Record<string, unknown>>(json: JSONString): T;
607
+ /**
608
+ * This object will convert an object with a Prototype into a generic object. This can be done by nulling the prototype but that's not
609
+ * really possible in Typescript, so we we do it differently by cloning the object. This means this is also one way of doing a deep
610
+ * copy of an object, but it will fail and instanceof() check.
611
+ * @param obj
612
+ * @returns
613
+ */
614
+ static toGenericObject<T = Record<string, unknown>>(obj: unknown): ResultAsync<T, ValidationError>;
615
+ static removeNullValues<T>(array: (T | null | undefined)[]): T[];
616
+ static getEnumKeyByValue<T extends Record<string, string | number>>(enumObj: T, value: number): string;
617
+ static getEnumKeyByValueSafely<T extends Record<string, string | number>>(enumObj: T, value: number): string;
618
+ static convertBigIntsToStrings<T>(input: T): any;
619
+ }
620
+
621
+ declare class TimeUtils implements ITimeUtils {
622
+ protected lastBlockchainCheck: UnixTimestamp | undefined;
623
+ protected lastBlockchainTimestamp: UnixTimestamp | undefined;
624
+ constructor();
625
+ getUnixNow(): UnixTimestamp;
626
+ getMillisecondNow(): MillisecondTimestamp;
627
+ getISO8601TimeString(time?: MillisecondTimestamp): ISO8601DateString;
628
+ convertTimestampToISOString(unixTimestamp: UnixTimestamp): ISO8601DateString;
629
+ convertISOStringToTimestamp(isoString: ISO8601DateString): UnixTimestamp;
630
+ getUnixTodayStart(): UnixTimestamp;
631
+ getUnixTodayEnd(): UnixTimestamp;
632
+ getStartOfMonth(): UnixTimestamp;
633
+ }
634
+
635
+ type X402PaymentRequirements = {
636
+ x402Version?: number;
637
+ version?: number;
638
+ resource?: {
639
+ url?: URLString;
640
+ description?: string;
641
+ mimeType?: string;
642
+ };
643
+ accepted?: unknown;
644
+ paymentRequirements?: unknown;
645
+ };
646
+ type X402AcceptedPayment = {
647
+ scheme?: string;
648
+ network?: string;
649
+ amount?: BigNumberString;
650
+ asset?: EVMContractAddress;
651
+ payTo?: EVMAccountAddress;
652
+ maxTimeoutSeconds?: number;
653
+ extra?: Record<string, unknown>;
654
+ };
655
+ type X402PaymentPayloadV2ExactEvm = {
656
+ x402Version: number;
657
+ resource: {
658
+ url: string;
659
+ description?: string;
660
+ mimeType?: string;
661
+ };
662
+ accepted: {
663
+ scheme: "exact";
664
+ network: string;
665
+ amount: BigNumberString;
666
+ asset: EVMContractAddress;
667
+ payTo: EVMAccountAddress;
668
+ maxTimeoutSeconds?: number;
669
+ extra?: Record<string, unknown>;
670
+ };
671
+ payload: {
672
+ signature: Signature;
673
+ authorization: IERC3009TransferWithAuthorization;
674
+ };
675
+ };
676
+ declare function x402ResolveRequestUrl(input: RequestInfo | URL): string;
677
+ declare function x402Base64EncodeUtf8(input: string): Base64String;
678
+ declare function x402Base64DecodeUtf8(input: Base64String): string;
679
+ declare function x402ParseJsonOrBase64Json(raw: string): unknown;
680
+ declare function x402NormalizeAcceptedPayments(req: X402PaymentRequirements): X402AcceptedPayment[];
681
+ declare function x402GetChainIdFromNetwork(network: string): number | null;
682
+ declare function x402IsUsdcOnBase(chainId: number, asset: EVMContractAddress): boolean;
683
+
684
+ /**
685
+ * @1shotapi/1shotpay-common
686
+ *
687
+ * Shared types and utilities for 1ShotPay client and server SDKs.
688
+ */
689
+
690
+ /**
691
+ * A simple helper function to convert a ResultAsync to a promise if you prefer to use async/await syntax.
692
+ * @param resultAsync A ResultAsync
693
+ * @returns A promise that resolves with the value of the ResultAsync if it is ok, or rejects with the error
694
+ */
695
+ declare function resultAsyncToPromise<T>(resultAsync: ResultAsync<T, Error>): Promise<T>;
696
+
697
+ export { AjaxError, AjaxUtils, ApiToken, Base64String, BaseError, BigNumberString, DecimalAmount, EHttpStatusCode, ELocale, EPayLinkStatus, EVMAccountAddress, EVMContractAddress, HexString, type IAjaxRequestBody, type IAjaxRequestConfig, type IAjaxUtils, type IERC3009TransferWithAuthorization, type IPermitTransfer, ISO8601DateString, type ISignedERC3009TransferWithAuthorization, type ISignedPermitTransfer, type ITimeUtils, ITimeUtilsType, type IUserModel, JSONString, JsonWebToken, MillisecondTimestamp, OAuthTokenModel, ObjectUtils, PayLinkId, PayLinkPaymentId, ProxyError, RelayerTransactionId, RetryError, Signature, TimeUtils, TransactionHash, URLString, USDCAmount, UnixTimestamp, UserId, Username, ValidationError, type X402AcceptedPayment, type X402PaymentPayloadV2ExactEvm, type X402PaymentRequirements, resultAsyncToPromise, x402Base64DecodeUtf8, x402Base64EncodeUtf8, x402GetChainIdFromNetwork, x402IsUsdcOnBase, x402NormalizeAcceptedPayments, x402ParseJsonOrBase64Json, x402ResolveRequestUrl };