xendit-fn 1.0.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +442 -0
  3. package/lib/index.cjs +1588 -0
  4. package/lib/index.d.cts +9574 -0
  5. package/lib/index.d.ts +7 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.esm.d.ts +9574 -0
  8. package/lib/index.esm.js +1544 -0
  9. package/lib/sdk/axios.d.ts +3 -0
  10. package/lib/sdk/axios.d.ts.map +1 -0
  11. package/lib/sdk/card/index.d.ts +2 -0
  12. package/lib/sdk/card/index.d.ts.map +1 -0
  13. package/lib/sdk/card/schema.d.ts +586 -0
  14. package/lib/sdk/card/schema.d.ts.map +1 -0
  15. package/lib/sdk/common.d.ts +28 -0
  16. package/lib/sdk/common.d.ts.map +1 -0
  17. package/lib/sdk/customer/index.d.ts +7 -0
  18. package/lib/sdk/customer/index.d.ts.map +1 -0
  19. package/lib/sdk/customer/schema.d.ts +5933 -0
  20. package/lib/sdk/customer/schema.d.ts.map +1 -0
  21. package/lib/sdk/ewallet/create.d.ts +173 -0
  22. package/lib/sdk/ewallet/create.d.ts.map +1 -0
  23. package/lib/sdk/ewallet/schema.d.ts +783 -0
  24. package/lib/sdk/ewallet/schema.d.ts.map +1 -0
  25. package/lib/sdk/index.d.ts +2201 -0
  26. package/lib/sdk/index.d.ts.map +1 -0
  27. package/lib/sdk/invoice/index.d.ts +8 -0
  28. package/lib/sdk/invoice/index.d.ts.map +1 -0
  29. package/lib/sdk/invoice/schema.d.ts +2198 -0
  30. package/lib/sdk/invoice/schema.d.ts.map +1 -0
  31. package/lib/sdk/payment-method/index.d.ts +7 -0
  32. package/lib/sdk/payment-method/index.d.ts.map +1 -0
  33. package/lib/sdk/payment-method/schema.d.ts +990 -0
  34. package/lib/sdk/payment-method/schema.d.ts.map +1 -0
  35. package/lib/utils/errors.d.ts +58 -0
  36. package/lib/utils/errors.d.ts.map +1 -0
  37. package/lib/utils/index.d.ts +6 -0
  38. package/lib/utils/index.d.ts.map +1 -0
  39. package/lib/utils/pagination.d.ts +134 -0
  40. package/lib/utils/pagination.d.ts.map +1 -0
  41. package/lib/utils/rate-limit.d.ts +90 -0
  42. package/lib/utils/rate-limit.d.ts.map +1 -0
  43. package/lib/utils/type-guards.d.ts +13 -0
  44. package/lib/utils/type-guards.d.ts.map +1 -0
  45. package/lib/utils/webhook.d.ts +101 -0
  46. package/lib/utils/webhook.d.ts.map +1 -0
  47. package/package.json +83 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/sdk/payment-method/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,uBAAuB,uLAOlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAGxE,eAAO,MAAM,yBAAyB,0IAMpC,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAG5E,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;EAS/B,CAAC;AAGH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;EAMtC,CAAC;AAGH,eAAO,MAAM,uBAAuB;;;;;;;;;EAGlC,CAAC;AAGH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAaxC,CAAC;AAGH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAU3C,CAAC;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAC9C,OAAO,gCAAgC,CACxC,CAAC;AAGF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG1C,CAAC;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,+BAA+B,CACvC,CAAC"}
@@ -0,0 +1,58 @@
1
+ import type { AxiosError } from "axios";
2
+ import { z } from "zod";
3
+ export interface XenditError {
4
+ code: string;
5
+ message: string;
6
+ details?: Record<string, unknown>;
7
+ }
8
+ export declare const XenditErrorSchema: z.ZodObject<{
9
+ error_code: z.ZodString;
10
+ message: z.ZodString;
11
+ errors: z.ZodOptional<z.ZodArray<z.ZodObject<{
12
+ field: z.ZodOptional<z.ZodString>;
13
+ message: z.ZodString;
14
+ }, "strip", z.ZodTypeAny, {
15
+ message: string;
16
+ field?: string | undefined;
17
+ }, {
18
+ message: string;
19
+ field?: string | undefined;
20
+ }>, "many">>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ error_code: string;
23
+ message: string;
24
+ errors?: {
25
+ message: string;
26
+ field?: string | undefined;
27
+ }[] | undefined;
28
+ }, {
29
+ error_code: string;
30
+ message: string;
31
+ errors?: {
32
+ message: string;
33
+ field?: string | undefined;
34
+ }[] | undefined;
35
+ }>;
36
+ export declare class XenditApiError extends Error {
37
+ readonly code: string;
38
+ readonly details?: Record<string, unknown>;
39
+ readonly statusCode?: number;
40
+ constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
41
+ }
42
+ export declare class ValidationError extends Error {
43
+ readonly field?: string;
44
+ readonly validationErrors: z.ZodIssue[];
45
+ constructor(message: string, validationErrors: z.ZodIssue[], field?: string);
46
+ }
47
+ export declare class AuthenticationError extends XenditApiError {
48
+ constructor(message?: string);
49
+ }
50
+ export declare class NotFoundError extends XenditApiError {
51
+ constructor(message?: string);
52
+ }
53
+ export declare class RateLimitError extends XenditApiError {
54
+ constructor(message?: string);
55
+ }
56
+ export declare const handleAxiosError: (error: AxiosError) => never;
57
+ export declare const validateInput: <T>(schema: z.ZodSchema<T>, data: unknown, fieldName?: string) => T;
58
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW5B,CAAC;AAEH,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAGlC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAapC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAgB,KAAK,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAgB,gBAAgB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;gBAEnC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM;CAU5E;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,GAAE,MAAgC;CAItD;AAED,qBAAa,aAAc,SAAQ,cAAc;gBACnC,OAAO,GAAE,MAA6B;CAInD;AAED,qBAAa,cAAe,SAAQ,cAAc;gBACpC,OAAO,GAAE,MAA8B;CAIpD;AAED,eAAO,MAAM,gBAAgB,UAAW,UAAU,KAAG,KAmBpD,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,CAAC,UACrB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAChB,OAAO,cACD,MAAM,KACjB,CAUF,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./errors";
2
+ export * from "./type-guards";
3
+ export * from "./webhook";
4
+ export * from "./pagination";
5
+ export * from "./rate-limit";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAG9B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,134 @@
1
+ import { z } from "zod";
2
+ import { AxiosInstance } from "axios";
3
+ export declare const PaginationMetaSchema: z.ZodObject<{
4
+ has_more: z.ZodBoolean;
5
+ after_id: z.ZodOptional<z.ZodString>;
6
+ before_id: z.ZodOptional<z.ZodString>;
7
+ total_count: z.ZodOptional<z.ZodNumber>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ has_more: boolean;
10
+ after_id?: string | undefined;
11
+ before_id?: string | undefined;
12
+ total_count?: number | undefined;
13
+ }, {
14
+ has_more: boolean;
15
+ after_id?: string | undefined;
16
+ before_id?: string | undefined;
17
+ total_count?: number | undefined;
18
+ }>;
19
+ export type PaginationMeta = z.infer<typeof PaginationMetaSchema>;
20
+ export declare const PaginatedResponseSchema: <T extends z.ZodType>(itemSchema: T) => z.ZodObject<{
21
+ data: z.ZodArray<T, "many">;
22
+ has_more: z.ZodBoolean;
23
+ after_id: z.ZodOptional<z.ZodString>;
24
+ before_id: z.ZodOptional<z.ZodString>;
25
+ total_count: z.ZodOptional<z.ZodNumber>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ data: T["_output"][];
28
+ has_more: boolean;
29
+ after_id?: string | undefined;
30
+ before_id?: string | undefined;
31
+ total_count?: number | undefined;
32
+ }, {
33
+ data: T["_input"][];
34
+ has_more: boolean;
35
+ after_id?: string | undefined;
36
+ before_id?: string | undefined;
37
+ total_count?: number | undefined;
38
+ }>;
39
+ export type PaginatedResponse<T> = {
40
+ data: T[];
41
+ has_more: boolean;
42
+ after_id?: string;
43
+ before_id?: string;
44
+ total_count?: number;
45
+ };
46
+ export interface PaginationOptions {
47
+ /**
48
+ * Maximum number of items to return per page
49
+ * @default 10
50
+ */
51
+ limit?: number;
52
+ /**
53
+ * Return items after this ID (for forward pagination)
54
+ */
55
+ after_id?: string;
56
+ /**
57
+ * Return items before this ID (for backward pagination)
58
+ */
59
+ before_id?: string;
60
+ }
61
+ export interface AutoPaginationOptions extends PaginationOptions {
62
+ /**
63
+ * Maximum number of pages to fetch (safety limit)
64
+ * @default 100
65
+ */
66
+ maxPages?: number;
67
+ /**
68
+ * Maximum number of total items to fetch
69
+ */
70
+ maxItems?: number;
71
+ }
72
+ /**
73
+ * Helper to build pagination query parameters
74
+ */
75
+ export declare function buildPaginationParams(options: PaginationOptions): Record<string, string>;
76
+ /**
77
+ * Generic paginated API fetcher
78
+ */
79
+ export declare function fetchPaginated<T>(axiosInstance: AxiosInstance, endpoint: string, itemSchema: z.ZodType<T>, options?: PaginationOptions): Promise<PaginatedResponse<T>>;
80
+ /**
81
+ * Auto-paginate through all pages and return all items
82
+ */
83
+ export declare function fetchAllPages<T>(axiosInstance: AxiosInstance, endpoint: string, itemSchema: z.ZodType<T>, options?: AutoPaginationOptions): Promise<T[]>;
84
+ /**
85
+ * Create a paginator iterator for streaming through pages
86
+ */
87
+ export declare function createPaginator<T>(axiosInstance: AxiosInstance, endpoint: string, itemSchema: z.ZodType<T>, initialOptions?: PaginationOptions): {
88
+ /**
89
+ * Get the next page
90
+ */
91
+ next(): Promise<{
92
+ value: PaginatedResponse<T>;
93
+ done: boolean;
94
+ }>;
95
+ /**
96
+ * Reset the paginator to start from the beginning
97
+ */
98
+ reset(options?: PaginationOptions): void;
99
+ /**
100
+ * Check if there are more pages available
101
+ */
102
+ hasMore(): boolean;
103
+ };
104
+ /**
105
+ * Async iterator for easy for-await-of usage
106
+ */
107
+ export declare function iteratePages<T>(axiosInstance: AxiosInstance, endpoint: string, itemSchema: z.ZodType<T>, options?: PaginationOptions): AsyncIterableIterator<PaginatedResponse<T>>;
108
+ /**
109
+ * Async iterator for individual items across all pages
110
+ */
111
+ export declare function iterateItems<T>(axiosInstance: AxiosInstance, endpoint: string, itemSchema: z.ZodType<T>, options?: AutoPaginationOptions): AsyncIterableIterator<T>;
112
+ /**
113
+ * Utility for search and filtering with pagination
114
+ */
115
+ export interface SearchPaginationOptions extends PaginationOptions {
116
+ /**
117
+ * Search query
118
+ */
119
+ query?: string;
120
+ /**
121
+ * Filter parameters
122
+ */
123
+ filters?: Record<string, any>;
124
+ /**
125
+ * Sort field
126
+ */
127
+ sort_by?: string;
128
+ /**
129
+ * Sort direction
130
+ */
131
+ sort_direction?: "asc" | "desc";
132
+ }
133
+ export declare function buildSearchParams(options: SearchPaginationOptions): Record<string, string>;
134
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../src/utils/pagination.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAiB,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AAK,GAAG,MAAM,CAAC;CACjC;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,uBAAuB,GAC/B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBxB"}
@@ -0,0 +1,90 @@
1
+ import { AxiosInstance, InternalAxiosRequestConfig, AxiosResponse, AxiosError } from "axios";
2
+ /**
3
+ * Rate limiting configuration
4
+ */
5
+ export interface RateLimitConfig {
6
+ /**
7
+ * Maximum number of requests per window
8
+ * @default 100
9
+ */
10
+ maxRequests?: number;
11
+ /**
12
+ * Time window in milliseconds
13
+ * @default 60000 (1 minute)
14
+ */
15
+ windowMs?: number;
16
+ /**
17
+ * Delay between requests in milliseconds
18
+ * @default 0
19
+ */
20
+ requestDelayMs?: number;
21
+ /**
22
+ * Maximum number of retry attempts when rate limited
23
+ * @default 3
24
+ */
25
+ maxRetries?: number;
26
+ /**
27
+ * Base delay for exponential backoff in milliseconds
28
+ * @default 1000
29
+ */
30
+ baseRetryDelayMs?: number;
31
+ /**
32
+ * Maximum retry delay in milliseconds
33
+ * @default 30000
34
+ */
35
+ maxRetryDelayMs?: number;
36
+ }
37
+ /**
38
+ * Rate limiter implementation using token bucket algorithm
39
+ */
40
+ export declare class RateLimiter {
41
+ private tokens;
42
+ private lastRefill;
43
+ private readonly config;
44
+ constructor(config?: RateLimitConfig);
45
+ /**
46
+ * Refill tokens based on elapsed time
47
+ */
48
+ private refillTokens;
49
+ /**
50
+ * Check if a request can be made
51
+ */
52
+ canMakeRequest(): boolean;
53
+ /**
54
+ * Consume a token for a request
55
+ */
56
+ consumeToken(): boolean;
57
+ /**
58
+ * Get time until next token is available
59
+ */
60
+ getWaitTime(): number;
61
+ /**
62
+ * Wait for a token to become available
63
+ */
64
+ waitForToken(): Promise<void>;
65
+ /**
66
+ * Sleep for specified milliseconds
67
+ */
68
+ private sleep;
69
+ }
70
+ /**
71
+ * Axios interceptor for rate limiting
72
+ */
73
+ export declare function createRateLimitInterceptor(rateLimiter: RateLimiter): {
74
+ request: (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig<any>>;
75
+ response: (response: AxiosResponse) => AxiosResponse<any, any>;
76
+ responseError: (error: AxiosError) => Promise<never>;
77
+ };
78
+ /**
79
+ * Basic retry interceptor - simplified for compatibility
80
+ */
81
+ export declare function createRetryInterceptor(_config?: RateLimitConfig): (error: AxiosError) => Promise<any>;
82
+ /**
83
+ * Setup rate limiting and retry logic for an Axios instance
84
+ */
85
+ export declare function setupRateLimit(axiosInstance: AxiosInstance, config?: RateLimitConfig): void;
86
+ /**
87
+ * Create a rate-limited axios instance
88
+ */
89
+ export declare function createRateLimitedAxios(baseURL: string, apiKey: string, config?: RateLimitConfig): AxiosInstance;
90
+ //# sourceMappingURL=rate-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/utils/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAc,EACZ,aAAa,EACb,0BAA0B,EAC1B,aAAa,EACb,UAAU,EACX,MAAM,OAAO,CAAC;AAEf;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;gBAEvC,MAAM,GAAE,eAAoB;IAcxC;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB;;OAEG;IACH,cAAc,IAAI,OAAO;IAKzB;;OAEG;IACH,YAAY,IAAI,OAAO;IASvB;;OAEG;IACH,WAAW,IAAI,MAAM;IASrB;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAOnC;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW;sBAEvC,0BAA0B;yBAgB7B,aAAa;2BAcL,UAAU;EAkB1C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,eAAoB,WAC7C,UAAU,KAAG,OAAO,CAAC,GAAG,CAAC,CAS/C;AAgBD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,aAAa,EAAE,aAAa,EAC5B,MAAM,GAAE,eAAoB,GAC3B,IAAI,CAsBN;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,eAAoB,GAC3B,aAAa,CAYf"}
@@ -0,0 +1,13 @@
1
+ import type { Country, Currency, Phone } from "../sdk/common";
2
+ import type { CustomerType } from "../sdk/customer/schema";
3
+ import type { CheckoutMethod } from "../sdk/ewallet/schema";
4
+ export declare function isValidPhone(value: string): value is Phone;
5
+ export declare function isValidCountry(value: string): value is Country;
6
+ export declare function isValidCurrency(value: string): value is Currency;
7
+ export declare function isValidCustomerType(value: string): value is CustomerType;
8
+ export declare function isValidCheckoutMethod(value: string): value is CheckoutMethod;
9
+ export declare function isNotNullOrUndefined<T>(value: T | null | undefined): value is T;
10
+ export declare function isValidUrl(value: string): boolean;
11
+ export declare function isValidEmail(value: string): boolean;
12
+ export declare function isValidDateString(value: string): boolean;
13
+ //# sourceMappingURL=type-guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,KAAK,CAO1D;AAGD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,OAAO,CAE9D;AAGD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,QAAQ,CAEhE;AAGD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,YAAY,CAExE;AAGD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,cAAc,CAE5E;AAGD,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAC1B,KAAK,IAAI,CAAC,CAEZ;AAGD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOjD;AAGD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGnD;AAGD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGxD"}
@@ -0,0 +1,101 @@
1
+ import { z } from "zod";
2
+ export declare const WebhookEventTypeSchema: z.ZodUnion<[z.ZodLiteral<"invoice.paid">, z.ZodLiteral<"invoice.expired">, z.ZodLiteral<"payment.succeeded">, z.ZodLiteral<"payment.failed">, z.ZodLiteral<"ewallet.charge.succeeded">, z.ZodLiteral<"ewallet.charge.pending">, z.ZodLiteral<"ewallet.charge.failed">, z.ZodLiteral<"payment_method.activate">, z.ZodLiteral<"payment_method.expire">, z.ZodLiteral<"customer.created">, z.ZodLiteral<"customer.updated">]>;
3
+ export type WebhookEventType = z.infer<typeof WebhookEventTypeSchema>;
4
+ export declare const WebhookEventSchema: z.ZodObject<{
5
+ id: z.ZodString;
6
+ event: z.ZodUnion<[z.ZodLiteral<"invoice.paid">, z.ZodLiteral<"invoice.expired">, z.ZodLiteral<"payment.succeeded">, z.ZodLiteral<"payment.failed">, z.ZodLiteral<"ewallet.charge.succeeded">, z.ZodLiteral<"ewallet.charge.pending">, z.ZodLiteral<"ewallet.charge.failed">, z.ZodLiteral<"payment_method.activate">, z.ZodLiteral<"payment_method.expire">, z.ZodLiteral<"customer.created">, z.ZodLiteral<"customer.updated">]>;
7
+ api_version: z.ZodString;
8
+ created: z.ZodString;
9
+ business_id: z.ZodString;
10
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ data: Record<string, unknown>;
13
+ id: string;
14
+ created: string;
15
+ business_id: string;
16
+ event: "invoice.paid" | "invoice.expired" | "payment.succeeded" | "payment.failed" | "ewallet.charge.succeeded" | "ewallet.charge.pending" | "ewallet.charge.failed" | "payment_method.activate" | "payment_method.expire" | "customer.created" | "customer.updated";
17
+ api_version: string;
18
+ }, {
19
+ data: Record<string, unknown>;
20
+ id: string;
21
+ created: string;
22
+ business_id: string;
23
+ event: "invoice.paid" | "invoice.expired" | "payment.succeeded" | "payment.failed" | "ewallet.charge.succeeded" | "ewallet.charge.pending" | "ewallet.charge.failed" | "payment_method.activate" | "payment_method.expire" | "customer.created" | "customer.updated";
24
+ api_version: string;
25
+ }>;
26
+ export type WebhookEvent = z.infer<typeof WebhookEventSchema>;
27
+ export interface WebhookVerificationOptions {
28
+ /**
29
+ * Webhook callback token from Xendit Dashboard
30
+ */
31
+ callbackToken: string;
32
+ /**
33
+ * Raw request body as received from Xendit
34
+ */
35
+ requestBody: string | Buffer;
36
+ /**
37
+ * X-Callback-Token header from the webhook request
38
+ */
39
+ receivedToken: string;
40
+ }
41
+ /**
42
+ * Verify webhook signature from Xendit
43
+ * @param options Verification options
44
+ * @returns true if signature is valid, false otherwise
45
+ */
46
+ export declare function verifyWebhookSignature(options: WebhookVerificationOptions): boolean;
47
+ /**
48
+ * Advanced webhook signature verification using HMAC
49
+ * @param options Verification options with HMAC
50
+ * @returns true if signature is valid, false otherwise
51
+ */
52
+ export declare function verifyWebhookHmac(options: {
53
+ secret: string;
54
+ requestBody: string | Buffer;
55
+ signature: string;
56
+ }): boolean;
57
+ /**
58
+ * Parse and validate webhook event
59
+ * @param rawEvent Raw webhook event data
60
+ * @returns Parsed and validated webhook event
61
+ */
62
+ export declare function parseWebhookEvent(rawEvent: unknown): WebhookEvent;
63
+ /**
64
+ * Type-safe webhook event handler
65
+ */
66
+ export interface WebhookHandlers {
67
+ "invoice.paid"?: (event: WebhookEvent) => void | Promise<void>;
68
+ "invoice.expired"?: (event: WebhookEvent) => void | Promise<void>;
69
+ "payment.succeeded"?: (event: WebhookEvent) => void | Promise<void>;
70
+ "payment.failed"?: (event: WebhookEvent) => void | Promise<void>;
71
+ "ewallet.charge.succeeded"?: (event: WebhookEvent) => void | Promise<void>;
72
+ "ewallet.charge.pending"?: (event: WebhookEvent) => void | Promise<void>;
73
+ "ewallet.charge.failed"?: (event: WebhookEvent) => void | Promise<void>;
74
+ "payment_method.activate"?: (event: WebhookEvent) => void | Promise<void>;
75
+ "payment_method.expire"?: (event: WebhookEvent) => void | Promise<void>;
76
+ "customer.created"?: (event: WebhookEvent) => void | Promise<void>;
77
+ "customer.updated"?: (event: WebhookEvent) => void | Promise<void>;
78
+ [key: string]: ((event: WebhookEvent) => void | Promise<void>) | undefined;
79
+ }
80
+ /**
81
+ * Handle webhook events with type-safe handlers
82
+ * @param event Webhook event
83
+ * @param handlers Event handlers
84
+ */
85
+ export declare function handleWebhookEvent(event: WebhookEvent, handlers: WebhookHandlers): Promise<void>;
86
+ /**
87
+ * Create a webhook processor with built-in verification
88
+ */
89
+ export declare function createWebhookProcessor(options: {
90
+ callbackToken?: string;
91
+ hmacSecret?: string;
92
+ }): {
93
+ /**
94
+ * Process a webhook request
95
+ */
96
+ processWebhook(requestBody: string | Buffer, headers: Record<string, string>, handlers: WebhookHandlers): Promise<{
97
+ success: boolean;
98
+ error?: string;
99
+ }>;
100
+ };
101
+ //# sourceMappingURL=webhook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/utils/webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,sBAAsB,6ZAYjC,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAGtE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;EAO7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAG9D,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAKT;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAYV;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,GAAG,YAAY,CAQjE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,iBAAiB,CAAC,EAAE,CAAC,KAAK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AAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;IAEG;;OAEG;gCAEY,MAAM,GAAG,MAAM,WACnB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,YACrB,eAAe,GACxB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;EAqDnD"}
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "xendit-fn",
3
+ "description": "Modern TypeScript SDK for Xendit payment gateway with built-in type safety, error handling, and production-ready features",
4
+ "keywords": [
5
+ "xendit",
6
+ "sdk",
7
+ "typescript",
8
+ "payments",
9
+ "fintech",
10
+ "e-wallet",
11
+ "invoice",
12
+ "payment-gateway",
13
+ "api-client"
14
+ ],
15
+ "author": {
16
+ "name": "phtn",
17
+ "url": "https://github.com/phtn"
18
+ },
19
+ "version": "1.0.0",
20
+ "type": "module",
21
+ "main": "./lib/index.cjs",
22
+ "module": "./lib/index.esm.js",
23
+ "types": "./lib/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./lib/index.esm.js",
27
+ "require": "./lib/index.cjs",
28
+ "types": "./lib/index.d.ts"
29
+ }
30
+ },
31
+ "files": [
32
+ "lib/**/*",
33
+ "README.md",
34
+ "LICENSE",
35
+ "package.json"
36
+ ],
37
+ "scripts": {
38
+ "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:types",
39
+ "build:esm": "bunchee src/index.ts -o lib/index.esm.js --format esm",
40
+ "build:cjs": "bunchee src/index.ts -o lib/index.cjs --format cjs",
41
+ "build:types": "tsc --emitDeclarationOnly",
42
+ "dev": "bunchee src/index.ts --watch",
43
+ "typecheck": "tsc --noEmit",
44
+ "lint": "eslint src/",
45
+ "lint:fix": "eslint src/ --fix",
46
+ "format": "prettier --write \"src/**/*.{ts,js,json}\"",
47
+ "format:check": "prettier --check \"src/**/*.{ts,js,json}\"",
48
+ "test": "echo \"Tests will be added in next version\" && exit 0",
49
+ "clean": "rm -rf lib/ dist/",
50
+ "prepublishOnly": "npm run validate && npm run build",
51
+ "validate": "npm run typecheck && npm run lint && npm run format:check"
52
+ },
53
+ "devDependencies": {
54
+ "@eslint/eslintrc": "^3.3.1",
55
+ "@eslint/js": "^9.34.0",
56
+ "@types/bun": "latest",
57
+ "@types/eslint": "^9.6.1",
58
+ "@typescript-eslint/eslint-plugin": "^8.41.0",
59
+ "@typescript-eslint/parser": "^8.41.0",
60
+ "bunchee": "^5.6.2",
61
+ "eslint": "^9.34.0",
62
+ "prettier": "^3.6.2"
63
+ },
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "https://github.com/phtn/xendit-fn.git"
67
+ },
68
+ "homepage": "https://github.com/phtn/xendit-fn#readme",
69
+ "bugs": {
70
+ "url": "https://github.com/phtn/xendit-fn/issues"
71
+ },
72
+ "engines": {
73
+ "node": ">=16.0.0"
74
+ },
75
+ "peerDependencies": {
76
+ "typescript": "^5.6.2"
77
+ },
78
+ "dependencies": {
79
+ "axios": "^1.11.0",
80
+ "zod": "^3.25.76"
81
+ },
82
+ "license": "MIT"
83
+ }