paylio 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Paylio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # Paylio Node.js SDK
2
+
3
+ Official Node.js/TypeScript client library for the [Paylio API](https://api.paylio.pro).
4
+
5
+ ## Requirements
6
+
7
+ - Node.js 18 or later
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install paylio
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### TypeScript
18
+
19
+ ```typescript
20
+ import { PaylioClient, AuthenticationError } from "paylio";
21
+
22
+ const client = new PaylioClient("sk_live_xxx");
23
+
24
+ // Retrieve current subscription
25
+ const sub = await client.subscription.retrieve("user_123");
26
+ console.log(sub.status, sub.plan.name);
27
+
28
+ // List subscription history
29
+ const history = await client.subscription.list("user_123", { page: 1, pageSize: 10 });
30
+ for (const item of history.items) {
31
+ console.log(item.plan_name);
32
+ }
33
+ console.log(history.hasMore);
34
+
35
+ // Cancel a subscription (safe default: at end of billing period)
36
+ const result = await client.subscription.cancel("sub_uuid");
37
+ console.log(result.success);
38
+
39
+ // Cancel immediately
40
+ await client.subscription.cancel("sub_uuid", { cancelNow: true });
41
+
42
+ client.close();
43
+ ```
44
+
45
+ ### JavaScript (CommonJS)
46
+
47
+ ```javascript
48
+ const { PaylioClient } = require("paylio");
49
+
50
+ const client = new PaylioClient("sk_live_xxx");
51
+ const sub = await client.subscription.retrieve("user_123");
52
+ console.log(sub.status);
53
+ client.close();
54
+ ```
55
+
56
+ ### Error Handling
57
+
58
+ ```typescript
59
+ import { PaylioClient, AuthenticationError, NotFoundError, PaylioError } from "paylio";
60
+
61
+ const client = new PaylioClient("sk_live_xxx");
62
+
63
+ try {
64
+ await client.subscription.retrieve("user_123");
65
+ } catch (error) {
66
+ if (error instanceof AuthenticationError) {
67
+ console.error("Invalid API key:", error.message);
68
+ } else if (error instanceof NotFoundError) {
69
+ console.error("Subscription not found:", error.message);
70
+ } else if (error instanceof PaylioError) {
71
+ console.error(`API error ${error.httpStatus}: ${error.message}`);
72
+ }
73
+ }
74
+
75
+ client.close();
76
+ ```
77
+
78
+ ### Custom Configuration
79
+
80
+ ```typescript
81
+ const client = new PaylioClient("sk_live_xxx", {
82
+ baseUrl: "https://custom.api.com/v1",
83
+ timeout: 60_000, // 60 seconds
84
+ });
85
+ ```
86
+
87
+ ## Error Types
88
+
89
+ | Error | HTTP Status | Description |
90
+ |---|---|---|
91
+ | `AuthenticationError` | 401 | Invalid or missing API key |
92
+ | `InvalidRequestError` | 400 | Bad request parameters |
93
+ | `NotFoundError` | 404 | Resource not found |
94
+ | `RateLimitError` | 429 | Rate limit exceeded |
95
+ | `APIError` | 5xx | Server error or unexpected response |
96
+ | `APIConnectionError` | — | Network or connection failure |
97
+
98
+ All errors extend `PaylioError`, which extends `Error`.
99
+
100
+ ## License
101
+
102
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,381 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ APIConnectionError: () => APIConnectionError,
24
+ APIError: () => APIError,
25
+ AuthenticationError: () => AuthenticationError,
26
+ InvalidRequestError: () => InvalidRequestError,
27
+ NotFoundError: () => NotFoundError,
28
+ PaginatedList: () => PaginatedList,
29
+ PaylioClient: () => PaylioClient,
30
+ PaylioError: () => PaylioError,
31
+ PaylioObject: () => PaylioObject,
32
+ RateLimitError: () => RateLimitError,
33
+ Subscription: () => Subscription,
34
+ SubscriptionCancel: () => SubscriptionCancel,
35
+ SubscriptionHistoryItem: () => SubscriptionHistoryItem,
36
+ VERSION: () => VERSION
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+
40
+ // src/errors.ts
41
+ var PaylioError = class extends Error {
42
+ httpStatus;
43
+ httpBody;
44
+ jsonBody;
45
+ headers;
46
+ code;
47
+ constructor(params) {
48
+ const msg = params?.message ?? "";
49
+ super(msg);
50
+ this.name = this.constructor.name;
51
+ this.message = msg;
52
+ this.httpStatus = params?.httpStatus;
53
+ this.httpBody = params?.httpBody;
54
+ this.jsonBody = params?.jsonBody;
55
+ this.headers = params?.headers ?? {};
56
+ this.code = params?.code;
57
+ }
58
+ toString() {
59
+ return this.message;
60
+ }
61
+ };
62
+ var APIError = class extends PaylioError {
63
+ };
64
+ var AuthenticationError = class extends PaylioError {
65
+ };
66
+ var InvalidRequestError = class extends PaylioError {
67
+ };
68
+ var NotFoundError = class extends PaylioError {
69
+ };
70
+ var RateLimitError = class extends PaylioError {
71
+ };
72
+ var APIConnectionError = class extends PaylioError {
73
+ };
74
+
75
+ // src/version.ts
76
+ var VERSION = "0.1.0";
77
+
78
+ // src/httpClient.ts
79
+ var DEFAULT_BASE_URL = "https://api.paylio.pro/flying/v1";
80
+ var DEFAULT_TIMEOUT = 3e4;
81
+ var HTTPClient = class {
82
+ _apiKey;
83
+ _baseUrl;
84
+ _timeout;
85
+ _fetchFn;
86
+ constructor(options) {
87
+ this._apiKey = options.apiKey;
88
+ this._baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
89
+ this._timeout = options.timeout ?? DEFAULT_TIMEOUT;
90
+ this._fetchFn = options.fetchFn ?? globalThis.fetch;
91
+ }
92
+ async request(method, path, options) {
93
+ const url = new URL(`${this._baseUrl}${path}`);
94
+ if (options?.params) {
95
+ for (const [key, value] of Object.entries(options.params)) {
96
+ url.searchParams.set(key, String(value));
97
+ }
98
+ }
99
+ const headers = this._buildHeaders();
100
+ const controller = new AbortController();
101
+ const timeoutId = setTimeout(() => controller.abort(), this._timeout);
102
+ let response;
103
+ try {
104
+ response = await this._fetchFn(url.toString(), {
105
+ method,
106
+ headers,
107
+ body: options?.jsonBody ? JSON.stringify(options.jsonBody) : void 0,
108
+ signal: controller.signal
109
+ });
110
+ } catch (error) {
111
+ if (error instanceof DOMException && error.name === "AbortError") {
112
+ throw new APIConnectionError({ message: "Request timed out" });
113
+ }
114
+ throw new APIConnectionError({
115
+ message: `Connection error: ${error instanceof Error ? error.message : String(error)}`
116
+ });
117
+ } finally {
118
+ clearTimeout(timeoutId);
119
+ }
120
+ return this._handleResponse(response);
121
+ }
122
+ _buildHeaders() {
123
+ return {
124
+ "X-API-Key": this._apiKey,
125
+ "Content-Type": "application/json",
126
+ Accept: "application/json",
127
+ "User-Agent": `paylio-node/${VERSION}`
128
+ };
129
+ }
130
+ async _handleResponse(response) {
131
+ const httpStatus = response.status;
132
+ const httpBody = await response.text();
133
+ const headers = {};
134
+ response.headers.forEach((value, key) => {
135
+ headers[key] = value;
136
+ });
137
+ let jsonBody;
138
+ try {
139
+ jsonBody = JSON.parse(httpBody);
140
+ } catch {
141
+ jsonBody = void 0;
142
+ }
143
+ if (httpStatus >= 200 && httpStatus < 300) {
144
+ if (!jsonBody) {
145
+ throw new APIError({
146
+ message: "Invalid JSON in response body",
147
+ httpStatus,
148
+ httpBody
149
+ });
150
+ }
151
+ return jsonBody;
152
+ }
153
+ let errorCode;
154
+ let errorMessage = httpBody;
155
+ if (jsonBody) {
156
+ const err = jsonBody["error"];
157
+ if (err && typeof err === "object" && !Array.isArray(err)) {
158
+ const errObj = err;
159
+ errorCode = typeof errObj["code"] === "string" ? errObj["code"] : void 0;
160
+ errorMessage = typeof errObj["message"] === "string" ? errObj["message"] : httpBody;
161
+ } else if (typeof err === "string") {
162
+ errorMessage = err;
163
+ } else if (typeof jsonBody["detail"] === "string") {
164
+ errorMessage = jsonBody["detail"];
165
+ }
166
+ }
167
+ const ErrorClass = errorClassForStatus(httpStatus);
168
+ throw new ErrorClass({
169
+ message: errorMessage,
170
+ httpStatus,
171
+ httpBody,
172
+ jsonBody,
173
+ headers,
174
+ code: errorCode
175
+ });
176
+ }
177
+ close() {
178
+ }
179
+ };
180
+ function errorClassForStatus(status) {
181
+ switch (status) {
182
+ case 401:
183
+ return AuthenticationError;
184
+ case 400:
185
+ return InvalidRequestError;
186
+ case 404:
187
+ return NotFoundError;
188
+ case 429:
189
+ return RateLimitError;
190
+ default:
191
+ return APIError;
192
+ }
193
+ }
194
+
195
+ // src/paylioObject.ts
196
+ var PaylioObject = class _PaylioObject {
197
+ /** @internal */
198
+ _data;
199
+ constructor(data) {
200
+ this._data = {};
201
+ if (data) {
202
+ for (const [key, value] of Object.entries(data)) {
203
+ this._data[key] = _PaylioObject._wrap(value);
204
+ }
205
+ }
206
+ return new Proxy(this, {
207
+ get(target, prop, receiver) {
208
+ if (typeof prop === "symbol" || typeof prop !== "string") {
209
+ return Reflect.get(target, prop, receiver);
210
+ }
211
+ if (prop in target && typeof target[prop] === "function") {
212
+ return target[prop].bind(target);
213
+ }
214
+ if (prop.startsWith("_")) {
215
+ return Reflect.get(target, prop, receiver);
216
+ }
217
+ if (prop in target._data) {
218
+ return target._data[prop];
219
+ }
220
+ return Reflect.get(target, prop, receiver);
221
+ },
222
+ set(target, prop, value) {
223
+ if (typeof prop === "string" && !prop.startsWith("_")) {
224
+ target._data[prop] = value;
225
+ return true;
226
+ }
227
+ return Reflect.set(target, prop, value);
228
+ }
229
+ });
230
+ }
231
+ static _wrap(value) {
232
+ if (value instanceof _PaylioObject) {
233
+ return value;
234
+ }
235
+ if (Array.isArray(value)) {
236
+ return value.map((item) => {
237
+ if (item instanceof _PaylioObject) return item;
238
+ if (item !== null && typeof item === "object" && !Array.isArray(item)) {
239
+ return new _PaylioObject(item);
240
+ }
241
+ return item;
242
+ });
243
+ }
244
+ if (value !== null && typeof value === "object") {
245
+ return new _PaylioObject(value);
246
+ }
247
+ return value;
248
+ }
249
+ get(key, defaultValue) {
250
+ return key in this._data ? this._data[key] : defaultValue;
251
+ }
252
+ toDict() {
253
+ const result = {};
254
+ for (const [key, value] of Object.entries(this._data)) {
255
+ if (value instanceof _PaylioObject) {
256
+ result[key] = value.toDict();
257
+ } else if (Array.isArray(value)) {
258
+ result[key] = value.map(
259
+ (item) => item instanceof _PaylioObject ? item.toDict() : item
260
+ );
261
+ } else {
262
+ result[key] = value;
263
+ }
264
+ }
265
+ return result;
266
+ }
267
+ static constructFrom(data) {
268
+ return new _PaylioObject(data);
269
+ }
270
+ toString() {
271
+ const id = this._data["id"];
272
+ if (id !== void 0 && id !== null) {
273
+ return `<${this.constructor.name} id=${id}>`;
274
+ }
275
+ return `<${this.constructor.name} ${JSON.stringify(this._data)}>`;
276
+ }
277
+ };
278
+
279
+ // src/resources/subscription.ts
280
+ var Subscription = class extends PaylioObject {
281
+ static OBJECT_NAME = "subscription";
282
+ };
283
+ var SubscriptionCancel = class extends PaylioObject {
284
+ static OBJECT_NAME = "subscription_cancel";
285
+ };
286
+ var SubscriptionHistoryItem = class extends PaylioObject {
287
+ static OBJECT_NAME = "subscription_history_item";
288
+ };
289
+ var PaginatedList = class extends PaylioObject {
290
+ static OBJECT_NAME = "list";
291
+ get hasMore() {
292
+ const page = this.get("page", 1);
293
+ const totalPages = this.get("total_pages", 1);
294
+ return page < totalPages;
295
+ }
296
+ };
297
+
298
+ // src/services/subscriptionService.ts
299
+ var SubscriptionService = class {
300
+ _http;
301
+ constructor(httpClient) {
302
+ this._http = httpClient;
303
+ }
304
+ async retrieve(userId) {
305
+ if (!userId || !userId.trim()) {
306
+ throw new Error("userId is required");
307
+ }
308
+ const data = await this._http.request("GET", `/subscription/${userId}`);
309
+ return new Subscription(data);
310
+ }
311
+ async list(userId, options) {
312
+ if (!userId || !userId.trim()) {
313
+ throw new Error("userId is required");
314
+ }
315
+ const params = {
316
+ page: options?.page ?? 1,
317
+ page_size: options?.pageSize ?? 20
318
+ };
319
+ const data = await this._http.request("GET", `/users/${userId}/subscriptions`, { params });
320
+ if (data["items"] && Array.isArray(data["items"])) {
321
+ data["items"] = data["items"].map(
322
+ (item) => new SubscriptionHistoryItem(item)
323
+ );
324
+ }
325
+ return new PaginatedList(data);
326
+ }
327
+ async cancel(subscriptionId, options) {
328
+ if (!subscriptionId || !subscriptionId.trim()) {
329
+ throw new Error("subscriptionId is required");
330
+ }
331
+ const cancelNow = options?.cancelNow ?? false;
332
+ const data = await this._http.request("POST", `/subscription/${subscriptionId}/cancel`, {
333
+ jsonBody: { cancel_at_period_end: !cancelNow }
334
+ });
335
+ return new SubscriptionCancel(data);
336
+ }
337
+ };
338
+
339
+ // src/client.ts
340
+ var PaylioClient = class {
341
+ _http;
342
+ subscription;
343
+ constructor(apiKey, options) {
344
+ if (!apiKey) {
345
+ throw new AuthenticationError({
346
+ message: "No API key provided. Set your API key when creating the PaylioClient: new PaylioClient('sk_live_xxx')"
347
+ });
348
+ }
349
+ this._http = new HTTPClient({
350
+ apiKey,
351
+ baseUrl: options?.baseUrl ?? DEFAULT_BASE_URL,
352
+ timeout: options?.timeout ?? DEFAULT_TIMEOUT,
353
+ fetchFn: options?.fetchFn
354
+ });
355
+ this.subscription = new SubscriptionService(this._http);
356
+ }
357
+ close() {
358
+ this._http.close();
359
+ }
360
+ [Symbol.dispose]() {
361
+ this.close();
362
+ }
363
+ };
364
+ // Annotate the CommonJS export names for ESM import in node:
365
+ 0 && (module.exports = {
366
+ APIConnectionError,
367
+ APIError,
368
+ AuthenticationError,
369
+ InvalidRequestError,
370
+ NotFoundError,
371
+ PaginatedList,
372
+ PaylioClient,
373
+ PaylioError,
374
+ PaylioObject,
375
+ RateLimitError,
376
+ Subscription,
377
+ SubscriptionCancel,
378
+ SubscriptionHistoryItem,
379
+ VERSION
380
+ });
381
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/version.ts","../src/httpClient.ts","../src/paylioObject.ts","../src/resources/subscription.ts","../src/services/subscriptionService.ts","../src/client.ts"],"sourcesContent":["export { PaylioClient } from \"./client.js\";\nexport type { PaylioClientOptions } from \"./client.js\";\n\nexport {\n PaylioError,\n APIError,\n APIConnectionError,\n AuthenticationError,\n InvalidRequestError,\n NotFoundError,\n RateLimitError,\n} from \"./errors.js\";\nexport type { PaylioErrorParams } from \"./errors.js\";\n\nexport { PaylioObject } from \"./paylioObject.js\";\n\nexport {\n Subscription,\n SubscriptionCancel,\n SubscriptionHistoryItem,\n PaginatedList,\n} from \"./resources/subscription.js\";\n\nexport { VERSION } from \"./version.js\";\n","export interface PaylioErrorParams {\n message?: string;\n httpStatus?: number;\n httpBody?: string;\n jsonBody?: Record<string, unknown>;\n headers?: Record<string, string>;\n code?: string;\n}\n\nexport class PaylioError extends Error {\n readonly httpStatus: number | undefined;\n readonly httpBody: string | undefined;\n readonly jsonBody: Record<string, unknown> | undefined;\n readonly headers: Record<string, string>;\n readonly code: string | undefined;\n\n constructor(params?: PaylioErrorParams) {\n const msg = params?.message ?? \"\";\n super(msg);\n this.name = this.constructor.name;\n this.message = msg;\n this.httpStatus = params?.httpStatus;\n this.httpBody = params?.httpBody;\n this.jsonBody = params?.jsonBody;\n this.headers = params?.headers ?? {};\n this.code = params?.code;\n }\n\n override toString(): string {\n return this.message;\n }\n}\n\n/** General API error (5xx or unexpected responses). */\nexport class APIError extends PaylioError {}\n\n/** Invalid or missing API key (401). */\nexport class AuthenticationError extends PaylioError {}\n\n/** Bad request parameters (400). */\nexport class InvalidRequestError extends PaylioError {}\n\n/** Resource not found (404). */\nexport class NotFoundError extends PaylioError {}\n\n/** Rate limit exceeded (429). */\nexport class RateLimitError extends PaylioError {}\n\n/** Network/connection failure. */\nexport class APIConnectionError extends PaylioError {}\n","export const VERSION = \"0.1.0\";\n","import {\n APIConnectionError,\n APIError,\n AuthenticationError,\n InvalidRequestError,\n NotFoundError,\n PaylioError,\n RateLimitError,\n} from \"./errors.js\";\nimport { VERSION } from \"./version.js\";\n\nexport const DEFAULT_BASE_URL = \"https://api.paylio.pro/flying/v1\";\nexport const DEFAULT_TIMEOUT = 30_000;\n\nexport interface HTTPClientOptions {\n apiKey: string;\n baseUrl?: string;\n timeout?: number;\n fetchFn?: typeof fetch;\n}\n\nexport class HTTPClient {\n private readonly _apiKey: string;\n private readonly _baseUrl: string;\n private readonly _timeout: number;\n private readonly _fetchFn: typeof fetch;\n\n constructor(options: HTTPClientOptions) {\n this._apiKey = options.apiKey;\n this._baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this._timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this._fetchFn = options.fetchFn ?? globalThis.fetch;\n }\n\n async request(\n method: string,\n path: string,\n options?: {\n params?: Record<string, string | number>;\n jsonBody?: Record<string, unknown>;\n },\n ): Promise<Record<string, unknown>> {\n const url = new URL(`${this._baseUrl}${path}`);\n if (options?.params) {\n for (const [key, value] of Object.entries(options.params)) {\n url.searchParams.set(key, String(value));\n }\n }\n\n const headers = this._buildHeaders();\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this._timeout);\n\n let response: Response;\n try {\n response = await this._fetchFn(url.toString(), {\n method,\n headers,\n body: options?.jsonBody ? JSON.stringify(options.jsonBody) : undefined,\n signal: controller.signal,\n });\n } catch (error: unknown) {\n if (error instanceof DOMException && error.name === \"AbortError\") {\n throw new APIConnectionError({ message: \"Request timed out\" });\n }\n throw new APIConnectionError({\n message: `Connection error: ${error instanceof Error ? error.message : String(error)}`,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n\n return this._handleResponse(response);\n }\n\n private _buildHeaders(): Record<string, string> {\n return {\n \"X-API-Key\": this._apiKey,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n \"User-Agent\": `paylio-node/${VERSION}`,\n };\n }\n\n private async _handleResponse(response: Response): Promise<Record<string, unknown>> {\n const httpStatus = response.status;\n const httpBody = await response.text();\n const headers: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n let jsonBody: Record<string, unknown> | undefined;\n try {\n jsonBody = JSON.parse(httpBody) as Record<string, unknown>;\n } catch {\n jsonBody = undefined;\n }\n\n if (httpStatus >= 200 && httpStatus < 300) {\n if (!jsonBody) {\n throw new APIError({\n message: \"Invalid JSON in response body\",\n httpStatus,\n httpBody,\n });\n }\n return jsonBody;\n }\n\n // Extract error details — handle all 3 backend response formats:\n // {\"error\": {\"code\": \"...\", \"message\": \"...\"}} (public API v1)\n // {\"error\": \"string\"} (legacy API)\n // {\"detail\": \"string\"} (FastAPI / dashboard)\n let errorCode: string | undefined;\n let errorMessage: string = httpBody;\n\n if (jsonBody) {\n const err = jsonBody[\"error\"];\n if (err && typeof err === \"object\" && !Array.isArray(err)) {\n const errObj = err as Record<string, unknown>;\n errorCode = typeof errObj[\"code\"] === \"string\" ? errObj[\"code\"] : undefined;\n errorMessage =\n typeof errObj[\"message\"] === \"string\" ? (errObj[\"message\"] as string) : httpBody;\n } else if (typeof err === \"string\") {\n errorMessage = err;\n } else if (typeof jsonBody[\"detail\"] === \"string\") {\n errorMessage = jsonBody[\"detail\"] as string;\n }\n }\n\n const ErrorClass = errorClassForStatus(httpStatus);\n throw new ErrorClass({\n message: errorMessage,\n httpStatus,\n httpBody,\n jsonBody,\n headers,\n code: errorCode,\n });\n }\n\n close(): void {\n // No-op for fetch-based client. Included for API parity with Python SDK.\n }\n}\n\nfunction errorClassForStatus(status: number): typeof PaylioError {\n switch (status) {\n case 401:\n return AuthenticationError;\n case 400:\n return InvalidRequestError;\n case 404:\n return NotFoundError;\n case 429:\n return RateLimitError;\n default:\n return APIError;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Base class for Paylio API response objects.\n *\n * Supports both dot-style and bracket-style access:\n * (obj as any).status // dot access\n * obj[\"status\"] // bracket access (via Proxy)\n */\nexport class PaylioObject {\n /** @internal */\n readonly _data: Record<string, unknown>;\n\n constructor(data?: Record<string, unknown>) {\n this._data = {};\n if (data) {\n for (const [key, value] of Object.entries(data)) {\n this._data[key] = PaylioObject._wrap(value);\n }\n }\n\n return new Proxy(this, {\n get(target, prop, receiver) {\n // Let class methods and internals resolve normally via prototype chain\n if (typeof prop === \"symbol\" || typeof prop !== \"string\") {\n return Reflect.get(target, prop, receiver);\n }\n // Prioritize own methods over data keys\n if (prop in target && typeof (target as any)[prop] === \"function\") {\n return (target as any)[prop].bind(target);\n }\n // Internal properties (starting with _) go to the real object\n if (prop.startsWith(\"_\")) {\n return Reflect.get(target, prop, receiver);\n }\n // Data keys\n if (prop in target._data) {\n return target._data[prop];\n }\n // Fallback to prototype chain (constructor, etc.)\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, value) {\n if (typeof prop === \"string\" && !prop.startsWith(\"_\")) {\n target._data[prop] = value;\n return true;\n }\n return Reflect.set(target, prop, value);\n },\n });\n }\n\n static _wrap(value: unknown): unknown {\n if (value instanceof PaylioObject) {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((item) => {\n if (item instanceof PaylioObject) return item;\n if (item !== null && typeof item === \"object\" && !Array.isArray(item)) {\n return new PaylioObject(item as Record<string, unknown>);\n }\n return item;\n });\n }\n if (value !== null && typeof value === \"object\") {\n return new PaylioObject(value as Record<string, unknown>);\n }\n return value;\n }\n\n get(key: string, defaultValue?: unknown): unknown {\n return key in this._data ? this._data[key] : defaultValue;\n }\n\n toDict(): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(this._data)) {\n if (value instanceof PaylioObject) {\n result[key] = value.toDict();\n } else if (Array.isArray(value)) {\n result[key] = value.map((item: any) =>\n item instanceof PaylioObject ? item.toDict() : item,\n );\n } else {\n result[key] = value;\n }\n }\n return result;\n }\n\n static constructFrom(data: Record<string, unknown>): PaylioObject {\n return new PaylioObject(data);\n }\n\n toString(): string {\n const id = this._data[\"id\"];\n if (id !== undefined && id !== null) {\n return `<${this.constructor.name} id=${id}>`;\n }\n return `<${this.constructor.name} ${JSON.stringify(this._data)}>`;\n }\n}\n","import { PaylioObject } from \"../paylioObject.js\";\n\nexport class Subscription extends PaylioObject {\n static readonly OBJECT_NAME = \"subscription\";\n}\n\nexport class SubscriptionCancel extends PaylioObject {\n static readonly OBJECT_NAME = \"subscription_cancel\";\n}\n\nexport class SubscriptionHistoryItem extends PaylioObject {\n static readonly OBJECT_NAME = \"subscription_history_item\";\n}\n\nexport class PaginatedList extends PaylioObject {\n static readonly OBJECT_NAME = \"list\";\n\n get hasMore(): boolean {\n const page = this.get(\"page\", 1) as number;\n const totalPages = this.get(\"total_pages\", 1) as number;\n return page < totalPages;\n }\n}\n","import type { HTTPClient } from \"../httpClient.js\";\nimport {\n PaginatedList,\n Subscription,\n SubscriptionCancel,\n SubscriptionHistoryItem,\n} from \"../resources/subscription.js\";\n\nexport class SubscriptionService {\n private readonly _http: HTTPClient;\n\n constructor(httpClient: HTTPClient) {\n this._http = httpClient;\n }\n\n async retrieve(userId: string): Promise<Subscription> {\n if (!userId || !userId.trim()) {\n throw new Error(\"userId is required\");\n }\n const data = await this._http.request(\"GET\", `/subscription/${userId}`);\n return new Subscription(data);\n }\n\n async list(\n userId: string,\n options?: { page?: number; pageSize?: number },\n ): Promise<PaginatedList> {\n if (!userId || !userId.trim()) {\n throw new Error(\"userId is required\");\n }\n\n const params = {\n page: options?.page ?? 1,\n page_size: options?.pageSize ?? 20,\n };\n\n const data = await this._http.request(\"GET\", `/users/${userId}/subscriptions`, { params });\n\n // Convert items to typed objects\n if (data[\"items\"] && Array.isArray(data[\"items\"])) {\n data[\"items\"] = (data[\"items\"] as Record<string, unknown>[]).map(\n (item) => new SubscriptionHistoryItem(item),\n );\n }\n\n return new PaginatedList(data);\n }\n\n async cancel(\n subscriptionId: string,\n options?: { cancelNow?: boolean },\n ): Promise<SubscriptionCancel> {\n if (!subscriptionId || !subscriptionId.trim()) {\n throw new Error(\"subscriptionId is required\");\n }\n\n const cancelNow = options?.cancelNow ?? false;\n const data = await this._http.request(\"POST\", `/subscription/${subscriptionId}/cancel`, {\n jsonBody: { cancel_at_period_end: !cancelNow },\n });\n return new SubscriptionCancel(data);\n }\n}\n","import { AuthenticationError } from \"./errors.js\";\nimport { DEFAULT_BASE_URL, DEFAULT_TIMEOUT, HTTPClient } from \"./httpClient.js\";\nimport { SubscriptionService } from \"./services/subscriptionService.js\";\n\nexport interface PaylioClientOptions {\n baseUrl?: string;\n timeout?: number;\n fetchFn?: typeof fetch;\n}\n\nexport class PaylioClient {\n private readonly _http: HTTPClient;\n readonly subscription: SubscriptionService;\n\n constructor(apiKey: string, options?: PaylioClientOptions) {\n if (!apiKey) {\n throw new AuthenticationError({\n message:\n \"No API key provided. Set your API key when creating \" +\n \"the PaylioClient: new PaylioClient('sk_live_xxx')\",\n });\n }\n\n this._http = new HTTPClient({\n apiKey,\n baseUrl: options?.baseUrl ?? DEFAULT_BASE_URL,\n timeout: options?.timeout ?? DEFAULT_TIMEOUT,\n fetchFn: options?.fetchFn,\n });\n\n this.subscription = new SubscriptionService(this._http);\n }\n\n close(): void {\n this._http.close();\n }\n\n [Symbol.dispose](): void {\n this.close();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,cAAN,cAA0B,MAAM;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAA4B;AACtC,UAAM,MAAM,QAAQ,WAAW;AAC/B,UAAM,GAAG;AACT,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,UAAU;AACf,SAAK,aAAa,QAAQ;AAC1B,SAAK,WAAW,QAAQ;AACxB,SAAK,WAAW,QAAQ;AACxB,SAAK,UAAU,QAAQ,WAAW,CAAC;AACnC,SAAK,OAAO,QAAQ;AAAA,EACtB;AAAA,EAES,WAAmB;AAC1B,WAAO,KAAK;AAAA,EACd;AACF;AAGO,IAAM,WAAN,cAAuB,YAAY;AAAC;AAGpC,IAAM,sBAAN,cAAkC,YAAY;AAAC;AAG/C,IAAM,sBAAN,cAAkC,YAAY;AAAC;AAG/C,IAAM,gBAAN,cAA4B,YAAY;AAAC;AAGzC,IAAM,iBAAN,cAA6B,YAAY;AAAC;AAG1C,IAAM,qBAAN,cAAiC,YAAY;AAAC;;;ACjD9C,IAAM,UAAU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,QAC3D,CAAC,SAAS,IAAI,wBAAwB,IAAI;AAAA,MAC5C;AAAA,IACF;AAEA,WAAO,IAAI,cAAc,IAAI;AAAA,EAC/B;AAAA,EAEA,MAAM,OACJ,gBACA,SAC6B;AAC7B,QAAI,CAAC,kBAAkB,CAAC,eAAe,KAAK,GAAG;AAC7C,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC9C;AAEA,UAAM,YAAY,SAAS,aAAa;AACxC,UAAM,OAAO,MAAM,KAAK,MAAM,QAAQ,QAAQ,iBAAiB,cAAc,WAAW;AAAA,MACtF,UAAU,EAAE,sBAAsB,CAAC,UAAU;AAAA,IAC/C,CAAC;AACD,WAAO,IAAI,mBAAmB,IAAI;AAAA,EACpC;AACF;;;ACpDO,IAAM,eAAN,MAAmB;AAAA,EACP;AAAA,EACR;AAAA,EAET,YAAY,QAAgB,SAA+B;AACzD,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,oBAAoB;AAAA,QAC5B,SACE;AAAA,MAEJ,CAAC;AAAA,IACH;AAEA,SAAK,QAAQ,IAAI,WAAW;AAAA,MAC1B;AAAA,MACA,SAAS,SAAS,WAAW;AAAA,MAC7B,SAAS,SAAS,WAAW;AAAA,MAC7B,SAAS,SAAS;AAAA,IACpB,CAAC;AAED,SAAK,eAAe,IAAI,oBAAoB,KAAK,KAAK;AAAA,EACxD;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA,EAEA,CAAC,OAAO,OAAO,IAAU;AACvB,SAAK,MAAM;AAAA,EACb;AACF;","names":[]}
@@ -0,0 +1,118 @@
1
+ interface HTTPClientOptions {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ timeout?: number;
5
+ fetchFn?: typeof fetch;
6
+ }
7
+ declare class HTTPClient {
8
+ private readonly _apiKey;
9
+ private readonly _baseUrl;
10
+ private readonly _timeout;
11
+ private readonly _fetchFn;
12
+ constructor(options: HTTPClientOptions);
13
+ request(method: string, path: string, options?: {
14
+ params?: Record<string, string | number>;
15
+ jsonBody?: Record<string, unknown>;
16
+ }): Promise<Record<string, unknown>>;
17
+ private _buildHeaders;
18
+ private _handleResponse;
19
+ close(): void;
20
+ }
21
+
22
+ /**
23
+ * Base class for Paylio API response objects.
24
+ *
25
+ * Supports both dot-style and bracket-style access:
26
+ * (obj as any).status // dot access
27
+ * obj["status"] // bracket access (via Proxy)
28
+ */
29
+ declare class PaylioObject {
30
+ /** @internal */
31
+ readonly _data: Record<string, unknown>;
32
+ constructor(data?: Record<string, unknown>);
33
+ static _wrap(value: unknown): unknown;
34
+ get(key: string, defaultValue?: unknown): unknown;
35
+ toDict(): Record<string, unknown>;
36
+ static constructFrom(data: Record<string, unknown>): PaylioObject;
37
+ toString(): string;
38
+ }
39
+
40
+ declare class Subscription extends PaylioObject {
41
+ static readonly OBJECT_NAME = "subscription";
42
+ }
43
+ declare class SubscriptionCancel extends PaylioObject {
44
+ static readonly OBJECT_NAME = "subscription_cancel";
45
+ }
46
+ declare class SubscriptionHistoryItem extends PaylioObject {
47
+ static readonly OBJECT_NAME = "subscription_history_item";
48
+ }
49
+ declare class PaginatedList extends PaylioObject {
50
+ static readonly OBJECT_NAME = "list";
51
+ get hasMore(): boolean;
52
+ }
53
+
54
+ declare class SubscriptionService {
55
+ private readonly _http;
56
+ constructor(httpClient: HTTPClient);
57
+ retrieve(userId: string): Promise<Subscription>;
58
+ list(userId: string, options?: {
59
+ page?: number;
60
+ pageSize?: number;
61
+ }): Promise<PaginatedList>;
62
+ cancel(subscriptionId: string, options?: {
63
+ cancelNow?: boolean;
64
+ }): Promise<SubscriptionCancel>;
65
+ }
66
+
67
+ interface PaylioClientOptions {
68
+ baseUrl?: string;
69
+ timeout?: number;
70
+ fetchFn?: typeof fetch;
71
+ }
72
+ declare class PaylioClient {
73
+ private readonly _http;
74
+ readonly subscription: SubscriptionService;
75
+ constructor(apiKey: string, options?: PaylioClientOptions);
76
+ close(): void;
77
+ [Symbol.dispose](): void;
78
+ }
79
+
80
+ interface PaylioErrorParams {
81
+ message?: string;
82
+ httpStatus?: number;
83
+ httpBody?: string;
84
+ jsonBody?: Record<string, unknown>;
85
+ headers?: Record<string, string>;
86
+ code?: string;
87
+ }
88
+ declare class PaylioError extends Error {
89
+ readonly httpStatus: number | undefined;
90
+ readonly httpBody: string | undefined;
91
+ readonly jsonBody: Record<string, unknown> | undefined;
92
+ readonly headers: Record<string, string>;
93
+ readonly code: string | undefined;
94
+ constructor(params?: PaylioErrorParams);
95
+ toString(): string;
96
+ }
97
+ /** General API error (5xx or unexpected responses). */
98
+ declare class APIError extends PaylioError {
99
+ }
100
+ /** Invalid or missing API key (401). */
101
+ declare class AuthenticationError extends PaylioError {
102
+ }
103
+ /** Bad request parameters (400). */
104
+ declare class InvalidRequestError extends PaylioError {
105
+ }
106
+ /** Resource not found (404). */
107
+ declare class NotFoundError extends PaylioError {
108
+ }
109
+ /** Rate limit exceeded (429). */
110
+ declare class RateLimitError extends PaylioError {
111
+ }
112
+ /** Network/connection failure. */
113
+ declare class APIConnectionError extends PaylioError {
114
+ }
115
+
116
+ declare const VERSION = "0.1.0";
117
+
118
+ export { APIConnectionError, APIError, AuthenticationError, InvalidRequestError, NotFoundError, PaginatedList, PaylioClient, type PaylioClientOptions, PaylioError, type PaylioErrorParams, PaylioObject, RateLimitError, Subscription, SubscriptionCancel, SubscriptionHistoryItem, VERSION };
@@ -0,0 +1,118 @@
1
+ interface HTTPClientOptions {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ timeout?: number;
5
+ fetchFn?: typeof fetch;
6
+ }
7
+ declare class HTTPClient {
8
+ private readonly _apiKey;
9
+ private readonly _baseUrl;
10
+ private readonly _timeout;
11
+ private readonly _fetchFn;
12
+ constructor(options: HTTPClientOptions);
13
+ request(method: string, path: string, options?: {
14
+ params?: Record<string, string | number>;
15
+ jsonBody?: Record<string, unknown>;
16
+ }): Promise<Record<string, unknown>>;
17
+ private _buildHeaders;
18
+ private _handleResponse;
19
+ close(): void;
20
+ }
21
+
22
+ /**
23
+ * Base class for Paylio API response objects.
24
+ *
25
+ * Supports both dot-style and bracket-style access:
26
+ * (obj as any).status // dot access
27
+ * obj["status"] // bracket access (via Proxy)
28
+ */
29
+ declare class PaylioObject {
30
+ /** @internal */
31
+ readonly _data: Record<string, unknown>;
32
+ constructor(data?: Record<string, unknown>);
33
+ static _wrap(value: unknown): unknown;
34
+ get(key: string, defaultValue?: unknown): unknown;
35
+ toDict(): Record<string, unknown>;
36
+ static constructFrom(data: Record<string, unknown>): PaylioObject;
37
+ toString(): string;
38
+ }
39
+
40
+ declare class Subscription extends PaylioObject {
41
+ static readonly OBJECT_NAME = "subscription";
42
+ }
43
+ declare class SubscriptionCancel extends PaylioObject {
44
+ static readonly OBJECT_NAME = "subscription_cancel";
45
+ }
46
+ declare class SubscriptionHistoryItem extends PaylioObject {
47
+ static readonly OBJECT_NAME = "subscription_history_item";
48
+ }
49
+ declare class PaginatedList extends PaylioObject {
50
+ static readonly OBJECT_NAME = "list";
51
+ get hasMore(): boolean;
52
+ }
53
+
54
+ declare class SubscriptionService {
55
+ private readonly _http;
56
+ constructor(httpClient: HTTPClient);
57
+ retrieve(userId: string): Promise<Subscription>;
58
+ list(userId: string, options?: {
59
+ page?: number;
60
+ pageSize?: number;
61
+ }): Promise<PaginatedList>;
62
+ cancel(subscriptionId: string, options?: {
63
+ cancelNow?: boolean;
64
+ }): Promise<SubscriptionCancel>;
65
+ }
66
+
67
+ interface PaylioClientOptions {
68
+ baseUrl?: string;
69
+ timeout?: number;
70
+ fetchFn?: typeof fetch;
71
+ }
72
+ declare class PaylioClient {
73
+ private readonly _http;
74
+ readonly subscription: SubscriptionService;
75
+ constructor(apiKey: string, options?: PaylioClientOptions);
76
+ close(): void;
77
+ [Symbol.dispose](): void;
78
+ }
79
+
80
+ interface PaylioErrorParams {
81
+ message?: string;
82
+ httpStatus?: number;
83
+ httpBody?: string;
84
+ jsonBody?: Record<string, unknown>;
85
+ headers?: Record<string, string>;
86
+ code?: string;
87
+ }
88
+ declare class PaylioError extends Error {
89
+ readonly httpStatus: number | undefined;
90
+ readonly httpBody: string | undefined;
91
+ readonly jsonBody: Record<string, unknown> | undefined;
92
+ readonly headers: Record<string, string>;
93
+ readonly code: string | undefined;
94
+ constructor(params?: PaylioErrorParams);
95
+ toString(): string;
96
+ }
97
+ /** General API error (5xx or unexpected responses). */
98
+ declare class APIError extends PaylioError {
99
+ }
100
+ /** Invalid or missing API key (401). */
101
+ declare class AuthenticationError extends PaylioError {
102
+ }
103
+ /** Bad request parameters (400). */
104
+ declare class InvalidRequestError extends PaylioError {
105
+ }
106
+ /** Resource not found (404). */
107
+ declare class NotFoundError extends PaylioError {
108
+ }
109
+ /** Rate limit exceeded (429). */
110
+ declare class RateLimitError extends PaylioError {
111
+ }
112
+ /** Network/connection failure. */
113
+ declare class APIConnectionError extends PaylioError {
114
+ }
115
+
116
+ declare const VERSION = "0.1.0";
117
+
118
+ export { APIConnectionError, APIError, AuthenticationError, InvalidRequestError, NotFoundError, PaginatedList, PaylioClient, type PaylioClientOptions, PaylioError, type PaylioErrorParams, PaylioObject, RateLimitError, Subscription, SubscriptionCancel, SubscriptionHistoryItem, VERSION };
package/dist/index.mjs ADDED
@@ -0,0 +1,341 @@
1
+ // src/errors.ts
2
+ var PaylioError = class extends Error {
3
+ httpStatus;
4
+ httpBody;
5
+ jsonBody;
6
+ headers;
7
+ code;
8
+ constructor(params) {
9
+ const msg = params?.message ?? "";
10
+ super(msg);
11
+ this.name = this.constructor.name;
12
+ this.message = msg;
13
+ this.httpStatus = params?.httpStatus;
14
+ this.httpBody = params?.httpBody;
15
+ this.jsonBody = params?.jsonBody;
16
+ this.headers = params?.headers ?? {};
17
+ this.code = params?.code;
18
+ }
19
+ toString() {
20
+ return this.message;
21
+ }
22
+ };
23
+ var APIError = class extends PaylioError {
24
+ };
25
+ var AuthenticationError = class extends PaylioError {
26
+ };
27
+ var InvalidRequestError = class extends PaylioError {
28
+ };
29
+ var NotFoundError = class extends PaylioError {
30
+ };
31
+ var RateLimitError = class extends PaylioError {
32
+ };
33
+ var APIConnectionError = class extends PaylioError {
34
+ };
35
+
36
+ // src/version.ts
37
+ var VERSION = "0.1.0";
38
+
39
+ // src/httpClient.ts
40
+ var DEFAULT_BASE_URL = "https://api.paylio.pro/flying/v1";
41
+ var DEFAULT_TIMEOUT = 3e4;
42
+ var HTTPClient = class {
43
+ _apiKey;
44
+ _baseUrl;
45
+ _timeout;
46
+ _fetchFn;
47
+ constructor(options) {
48
+ this._apiKey = options.apiKey;
49
+ this._baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
50
+ this._timeout = options.timeout ?? DEFAULT_TIMEOUT;
51
+ this._fetchFn = options.fetchFn ?? globalThis.fetch;
52
+ }
53
+ async request(method, path, options) {
54
+ const url = new URL(`${this._baseUrl}${path}`);
55
+ if (options?.params) {
56
+ for (const [key, value] of Object.entries(options.params)) {
57
+ url.searchParams.set(key, String(value));
58
+ }
59
+ }
60
+ const headers = this._buildHeaders();
61
+ const controller = new AbortController();
62
+ const timeoutId = setTimeout(() => controller.abort(), this._timeout);
63
+ let response;
64
+ try {
65
+ response = await this._fetchFn(url.toString(), {
66
+ method,
67
+ headers,
68
+ body: options?.jsonBody ? JSON.stringify(options.jsonBody) : void 0,
69
+ signal: controller.signal
70
+ });
71
+ } catch (error) {
72
+ if (error instanceof DOMException && error.name === "AbortError") {
73
+ throw new APIConnectionError({ message: "Request timed out" });
74
+ }
75
+ throw new APIConnectionError({
76
+ message: `Connection error: ${error instanceof Error ? error.message : String(error)}`
77
+ });
78
+ } finally {
79
+ clearTimeout(timeoutId);
80
+ }
81
+ return this._handleResponse(response);
82
+ }
83
+ _buildHeaders() {
84
+ return {
85
+ "X-API-Key": this._apiKey,
86
+ "Content-Type": "application/json",
87
+ Accept: "application/json",
88
+ "User-Agent": `paylio-node/${VERSION}`
89
+ };
90
+ }
91
+ async _handleResponse(response) {
92
+ const httpStatus = response.status;
93
+ const httpBody = await response.text();
94
+ const headers = {};
95
+ response.headers.forEach((value, key) => {
96
+ headers[key] = value;
97
+ });
98
+ let jsonBody;
99
+ try {
100
+ jsonBody = JSON.parse(httpBody);
101
+ } catch {
102
+ jsonBody = void 0;
103
+ }
104
+ if (httpStatus >= 200 && httpStatus < 300) {
105
+ if (!jsonBody) {
106
+ throw new APIError({
107
+ message: "Invalid JSON in response body",
108
+ httpStatus,
109
+ httpBody
110
+ });
111
+ }
112
+ return jsonBody;
113
+ }
114
+ let errorCode;
115
+ let errorMessage = httpBody;
116
+ if (jsonBody) {
117
+ const err = jsonBody["error"];
118
+ if (err && typeof err === "object" && !Array.isArray(err)) {
119
+ const errObj = err;
120
+ errorCode = typeof errObj["code"] === "string" ? errObj["code"] : void 0;
121
+ errorMessage = typeof errObj["message"] === "string" ? errObj["message"] : httpBody;
122
+ } else if (typeof err === "string") {
123
+ errorMessage = err;
124
+ } else if (typeof jsonBody["detail"] === "string") {
125
+ errorMessage = jsonBody["detail"];
126
+ }
127
+ }
128
+ const ErrorClass = errorClassForStatus(httpStatus);
129
+ throw new ErrorClass({
130
+ message: errorMessage,
131
+ httpStatus,
132
+ httpBody,
133
+ jsonBody,
134
+ headers,
135
+ code: errorCode
136
+ });
137
+ }
138
+ close() {
139
+ }
140
+ };
141
+ function errorClassForStatus(status) {
142
+ switch (status) {
143
+ case 401:
144
+ return AuthenticationError;
145
+ case 400:
146
+ return InvalidRequestError;
147
+ case 404:
148
+ return NotFoundError;
149
+ case 429:
150
+ return RateLimitError;
151
+ default:
152
+ return APIError;
153
+ }
154
+ }
155
+
156
+ // src/paylioObject.ts
157
+ var PaylioObject = class _PaylioObject {
158
+ /** @internal */
159
+ _data;
160
+ constructor(data) {
161
+ this._data = {};
162
+ if (data) {
163
+ for (const [key, value] of Object.entries(data)) {
164
+ this._data[key] = _PaylioObject._wrap(value);
165
+ }
166
+ }
167
+ return new Proxy(this, {
168
+ get(target, prop, receiver) {
169
+ if (typeof prop === "symbol" || typeof prop !== "string") {
170
+ return Reflect.get(target, prop, receiver);
171
+ }
172
+ if (prop in target && typeof target[prop] === "function") {
173
+ return target[prop].bind(target);
174
+ }
175
+ if (prop.startsWith("_")) {
176
+ return Reflect.get(target, prop, receiver);
177
+ }
178
+ if (prop in target._data) {
179
+ return target._data[prop];
180
+ }
181
+ return Reflect.get(target, prop, receiver);
182
+ },
183
+ set(target, prop, value) {
184
+ if (typeof prop === "string" && !prop.startsWith("_")) {
185
+ target._data[prop] = value;
186
+ return true;
187
+ }
188
+ return Reflect.set(target, prop, value);
189
+ }
190
+ });
191
+ }
192
+ static _wrap(value) {
193
+ if (value instanceof _PaylioObject) {
194
+ return value;
195
+ }
196
+ if (Array.isArray(value)) {
197
+ return value.map((item) => {
198
+ if (item instanceof _PaylioObject) return item;
199
+ if (item !== null && typeof item === "object" && !Array.isArray(item)) {
200
+ return new _PaylioObject(item);
201
+ }
202
+ return item;
203
+ });
204
+ }
205
+ if (value !== null && typeof value === "object") {
206
+ return new _PaylioObject(value);
207
+ }
208
+ return value;
209
+ }
210
+ get(key, defaultValue) {
211
+ return key in this._data ? this._data[key] : defaultValue;
212
+ }
213
+ toDict() {
214
+ const result = {};
215
+ for (const [key, value] of Object.entries(this._data)) {
216
+ if (value instanceof _PaylioObject) {
217
+ result[key] = value.toDict();
218
+ } else if (Array.isArray(value)) {
219
+ result[key] = value.map(
220
+ (item) => item instanceof _PaylioObject ? item.toDict() : item
221
+ );
222
+ } else {
223
+ result[key] = value;
224
+ }
225
+ }
226
+ return result;
227
+ }
228
+ static constructFrom(data) {
229
+ return new _PaylioObject(data);
230
+ }
231
+ toString() {
232
+ const id = this._data["id"];
233
+ if (id !== void 0 && id !== null) {
234
+ return `<${this.constructor.name} id=${id}>`;
235
+ }
236
+ return `<${this.constructor.name} ${JSON.stringify(this._data)}>`;
237
+ }
238
+ };
239
+
240
+ // src/resources/subscription.ts
241
+ var Subscription = class extends PaylioObject {
242
+ static OBJECT_NAME = "subscription";
243
+ };
244
+ var SubscriptionCancel = class extends PaylioObject {
245
+ static OBJECT_NAME = "subscription_cancel";
246
+ };
247
+ var SubscriptionHistoryItem = class extends PaylioObject {
248
+ static OBJECT_NAME = "subscription_history_item";
249
+ };
250
+ var PaginatedList = class extends PaylioObject {
251
+ static OBJECT_NAME = "list";
252
+ get hasMore() {
253
+ const page = this.get("page", 1);
254
+ const totalPages = this.get("total_pages", 1);
255
+ return page < totalPages;
256
+ }
257
+ };
258
+
259
+ // src/services/subscriptionService.ts
260
+ var SubscriptionService = class {
261
+ _http;
262
+ constructor(httpClient) {
263
+ this._http = httpClient;
264
+ }
265
+ async retrieve(userId) {
266
+ if (!userId || !userId.trim()) {
267
+ throw new Error("userId is required");
268
+ }
269
+ const data = await this._http.request("GET", `/subscription/${userId}`);
270
+ return new Subscription(data);
271
+ }
272
+ async list(userId, options) {
273
+ if (!userId || !userId.trim()) {
274
+ throw new Error("userId is required");
275
+ }
276
+ const params = {
277
+ page: options?.page ?? 1,
278
+ page_size: options?.pageSize ?? 20
279
+ };
280
+ const data = await this._http.request("GET", `/users/${userId}/subscriptions`, { params });
281
+ if (data["items"] && Array.isArray(data["items"])) {
282
+ data["items"] = data["items"].map(
283
+ (item) => new SubscriptionHistoryItem(item)
284
+ );
285
+ }
286
+ return new PaginatedList(data);
287
+ }
288
+ async cancel(subscriptionId, options) {
289
+ if (!subscriptionId || !subscriptionId.trim()) {
290
+ throw new Error("subscriptionId is required");
291
+ }
292
+ const cancelNow = options?.cancelNow ?? false;
293
+ const data = await this._http.request("POST", `/subscription/${subscriptionId}/cancel`, {
294
+ jsonBody: { cancel_at_period_end: !cancelNow }
295
+ });
296
+ return new SubscriptionCancel(data);
297
+ }
298
+ };
299
+
300
+ // src/client.ts
301
+ var PaylioClient = class {
302
+ _http;
303
+ subscription;
304
+ constructor(apiKey, options) {
305
+ if (!apiKey) {
306
+ throw new AuthenticationError({
307
+ message: "No API key provided. Set your API key when creating the PaylioClient: new PaylioClient('sk_live_xxx')"
308
+ });
309
+ }
310
+ this._http = new HTTPClient({
311
+ apiKey,
312
+ baseUrl: options?.baseUrl ?? DEFAULT_BASE_URL,
313
+ timeout: options?.timeout ?? DEFAULT_TIMEOUT,
314
+ fetchFn: options?.fetchFn
315
+ });
316
+ this.subscription = new SubscriptionService(this._http);
317
+ }
318
+ close() {
319
+ this._http.close();
320
+ }
321
+ [Symbol.dispose]() {
322
+ this.close();
323
+ }
324
+ };
325
+ export {
326
+ APIConnectionError,
327
+ APIError,
328
+ AuthenticationError,
329
+ InvalidRequestError,
330
+ NotFoundError,
331
+ PaginatedList,
332
+ PaylioClient,
333
+ PaylioError,
334
+ PaylioObject,
335
+ RateLimitError,
336
+ Subscription,
337
+ SubscriptionCancel,
338
+ SubscriptionHistoryItem,
339
+ VERSION
340
+ };
341
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/version.ts","../src/httpClient.ts","../src/paylioObject.ts","../src/resources/subscription.ts","../src/services/subscriptionService.ts","../src/client.ts"],"sourcesContent":["export interface PaylioErrorParams {\n message?: string;\n httpStatus?: number;\n httpBody?: string;\n jsonBody?: Record<string, unknown>;\n headers?: Record<string, string>;\n code?: string;\n}\n\nexport class PaylioError extends Error {\n readonly httpStatus: number | undefined;\n readonly httpBody: string | undefined;\n readonly jsonBody: Record<string, unknown> | undefined;\n readonly headers: Record<string, string>;\n readonly code: string | undefined;\n\n constructor(params?: PaylioErrorParams) {\n const msg = params?.message ?? \"\";\n super(msg);\n this.name = this.constructor.name;\n this.message = msg;\n this.httpStatus = params?.httpStatus;\n this.httpBody = params?.httpBody;\n this.jsonBody = params?.jsonBody;\n this.headers = params?.headers ?? {};\n this.code = params?.code;\n }\n\n override toString(): string {\n return this.message;\n }\n}\n\n/** General API error (5xx or unexpected responses). */\nexport class APIError extends PaylioError {}\n\n/** Invalid or missing API key (401). */\nexport class AuthenticationError extends PaylioError {}\n\n/** Bad request parameters (400). */\nexport class InvalidRequestError extends PaylioError {}\n\n/** Resource not found (404). */\nexport class NotFoundError extends PaylioError {}\n\n/** Rate limit exceeded (429). */\nexport class RateLimitError extends PaylioError {}\n\n/** Network/connection failure. */\nexport class APIConnectionError extends PaylioError {}\n","export const VERSION = \"0.1.0\";\n","import {\n APIConnectionError,\n APIError,\n AuthenticationError,\n InvalidRequestError,\n NotFoundError,\n PaylioError,\n RateLimitError,\n} from \"./errors.js\";\nimport { VERSION } from \"./version.js\";\n\nexport const DEFAULT_BASE_URL = \"https://api.paylio.pro/flying/v1\";\nexport const DEFAULT_TIMEOUT = 30_000;\n\nexport interface HTTPClientOptions {\n apiKey: string;\n baseUrl?: string;\n timeout?: number;\n fetchFn?: typeof fetch;\n}\n\nexport class HTTPClient {\n private readonly _apiKey: string;\n private readonly _baseUrl: string;\n private readonly _timeout: number;\n private readonly _fetchFn: typeof fetch;\n\n constructor(options: HTTPClientOptions) {\n this._apiKey = options.apiKey;\n this._baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this._timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this._fetchFn = options.fetchFn ?? globalThis.fetch;\n }\n\n async request(\n method: string,\n path: string,\n options?: {\n params?: Record<string, string | number>;\n jsonBody?: Record<string, unknown>;\n },\n ): Promise<Record<string, unknown>> {\n const url = new URL(`${this._baseUrl}${path}`);\n if (options?.params) {\n for (const [key, value] of Object.entries(options.params)) {\n url.searchParams.set(key, String(value));\n }\n }\n\n const headers = this._buildHeaders();\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this._timeout);\n\n let response: Response;\n try {\n response = await this._fetchFn(url.toString(), {\n method,\n headers,\n body: options?.jsonBody ? JSON.stringify(options.jsonBody) : undefined,\n signal: controller.signal,\n });\n } catch (error: unknown) {\n if (error instanceof DOMException && error.name === \"AbortError\") {\n throw new APIConnectionError({ message: \"Request timed out\" });\n }\n throw new APIConnectionError({\n message: `Connection error: ${error instanceof Error ? error.message : String(error)}`,\n });\n } finally {\n clearTimeout(timeoutId);\n }\n\n return this._handleResponse(response);\n }\n\n private _buildHeaders(): Record<string, string> {\n return {\n \"X-API-Key\": this._apiKey,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n \"User-Agent\": `paylio-node/${VERSION}`,\n };\n }\n\n private async _handleResponse(response: Response): Promise<Record<string, unknown>> {\n const httpStatus = response.status;\n const httpBody = await response.text();\n const headers: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n let jsonBody: Record<string, unknown> | undefined;\n try {\n jsonBody = JSON.parse(httpBody) as Record<string, unknown>;\n } catch {\n jsonBody = undefined;\n }\n\n if (httpStatus >= 200 && httpStatus < 300) {\n if (!jsonBody) {\n throw new APIError({\n message: \"Invalid JSON in response body\",\n httpStatus,\n httpBody,\n });\n }\n return jsonBody;\n }\n\n // Extract error details — handle all 3 backend response formats:\n // {\"error\": {\"code\": \"...\", \"message\": \"...\"}} (public API v1)\n // {\"error\": \"string\"} (legacy API)\n // {\"detail\": \"string\"} (FastAPI / dashboard)\n let errorCode: string | undefined;\n let errorMessage: string = httpBody;\n\n if (jsonBody) {\n const err = jsonBody[\"error\"];\n if (err && typeof err === \"object\" && !Array.isArray(err)) {\n const errObj = err as Record<string, unknown>;\n errorCode = typeof errObj[\"code\"] === \"string\" ? errObj[\"code\"] : undefined;\n errorMessage =\n typeof errObj[\"message\"] === \"string\" ? (errObj[\"message\"] as string) : httpBody;\n } else if (typeof err === \"string\") {\n errorMessage = err;\n } else if (typeof jsonBody[\"detail\"] === \"string\") {\n errorMessage = jsonBody[\"detail\"] as string;\n }\n }\n\n const ErrorClass = errorClassForStatus(httpStatus);\n throw new ErrorClass({\n message: errorMessage,\n httpStatus,\n httpBody,\n jsonBody,\n headers,\n code: errorCode,\n });\n }\n\n close(): void {\n // No-op for fetch-based client. Included for API parity with Python SDK.\n }\n}\n\nfunction errorClassForStatus(status: number): typeof PaylioError {\n switch (status) {\n case 401:\n return AuthenticationError;\n case 400:\n return InvalidRequestError;\n case 404:\n return NotFoundError;\n case 429:\n return RateLimitError;\n default:\n return APIError;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Base class for Paylio API response objects.\n *\n * Supports both dot-style and bracket-style access:\n * (obj as any).status // dot access\n * obj[\"status\"] // bracket access (via Proxy)\n */\nexport class PaylioObject {\n /** @internal */\n readonly _data: Record<string, unknown>;\n\n constructor(data?: Record<string, unknown>) {\n this._data = {};\n if (data) {\n for (const [key, value] of Object.entries(data)) {\n this._data[key] = PaylioObject._wrap(value);\n }\n }\n\n return new Proxy(this, {\n get(target, prop, receiver) {\n // Let class methods and internals resolve normally via prototype chain\n if (typeof prop === \"symbol\" || typeof prop !== \"string\") {\n return Reflect.get(target, prop, receiver);\n }\n // Prioritize own methods over data keys\n if (prop in target && typeof (target as any)[prop] === \"function\") {\n return (target as any)[prop].bind(target);\n }\n // Internal properties (starting with _) go to the real object\n if (prop.startsWith(\"_\")) {\n return Reflect.get(target, prop, receiver);\n }\n // Data keys\n if (prop in target._data) {\n return target._data[prop];\n }\n // Fallback to prototype chain (constructor, etc.)\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, value) {\n if (typeof prop === \"string\" && !prop.startsWith(\"_\")) {\n target._data[prop] = value;\n return true;\n }\n return Reflect.set(target, prop, value);\n },\n });\n }\n\n static _wrap(value: unknown): unknown {\n if (value instanceof PaylioObject) {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((item) => {\n if (item instanceof PaylioObject) return item;\n if (item !== null && typeof item === \"object\" && !Array.isArray(item)) {\n return new PaylioObject(item as Record<string, unknown>);\n }\n return item;\n });\n }\n if (value !== null && typeof value === \"object\") {\n return new PaylioObject(value as Record<string, unknown>);\n }\n return value;\n }\n\n get(key: string, defaultValue?: unknown): unknown {\n return key in this._data ? this._data[key] : defaultValue;\n }\n\n toDict(): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(this._data)) {\n if (value instanceof PaylioObject) {\n result[key] = value.toDict();\n } else if (Array.isArray(value)) {\n result[key] = value.map((item: any) =>\n item instanceof PaylioObject ? item.toDict() : item,\n );\n } else {\n result[key] = value;\n }\n }\n return result;\n }\n\n static constructFrom(data: Record<string, unknown>): PaylioObject {\n return new PaylioObject(data);\n }\n\n toString(): string {\n const id = this._data[\"id\"];\n if (id !== undefined && id !== null) {\n return `<${this.constructor.name} id=${id}>`;\n }\n return `<${this.constructor.name} ${JSON.stringify(this._data)}>`;\n }\n}\n","import { PaylioObject } from \"../paylioObject.js\";\n\nexport class Subscription extends PaylioObject {\n static readonly OBJECT_NAME = \"subscription\";\n}\n\nexport class SubscriptionCancel extends PaylioObject {\n static readonly OBJECT_NAME = \"subscription_cancel\";\n}\n\nexport class SubscriptionHistoryItem extends PaylioObject {\n static readonly OBJECT_NAME = \"subscription_history_item\";\n}\n\nexport class PaginatedList extends PaylioObject {\n static readonly OBJECT_NAME = \"list\";\n\n get hasMore(): boolean {\n const page = this.get(\"page\", 1) as number;\n const totalPages = this.get(\"total_pages\", 1) as number;\n return page < totalPages;\n }\n}\n","import type { HTTPClient } from \"../httpClient.js\";\nimport {\n PaginatedList,\n Subscription,\n SubscriptionCancel,\n SubscriptionHistoryItem,\n} from \"../resources/subscription.js\";\n\nexport class SubscriptionService {\n private readonly _http: HTTPClient;\n\n constructor(httpClient: HTTPClient) {\n this._http = httpClient;\n }\n\n async retrieve(userId: string): Promise<Subscription> {\n if (!userId || !userId.trim()) {\n throw new Error(\"userId is required\");\n }\n const data = await this._http.request(\"GET\", `/subscription/${userId}`);\n return new Subscription(data);\n }\n\n async list(\n userId: string,\n options?: { page?: number; pageSize?: number },\n ): Promise<PaginatedList> {\n if (!userId || !userId.trim()) {\n throw new Error(\"userId is required\");\n }\n\n const params = {\n page: options?.page ?? 1,\n page_size: options?.pageSize ?? 20,\n };\n\n const data = await this._http.request(\"GET\", `/users/${userId}/subscriptions`, { params });\n\n // Convert items to typed objects\n if (data[\"items\"] && Array.isArray(data[\"items\"])) {\n data[\"items\"] = (data[\"items\"] as Record<string, unknown>[]).map(\n (item) => new SubscriptionHistoryItem(item),\n );\n }\n\n return new PaginatedList(data);\n }\n\n async cancel(\n subscriptionId: string,\n options?: { cancelNow?: boolean },\n ): Promise<SubscriptionCancel> {\n if (!subscriptionId || !subscriptionId.trim()) {\n throw new Error(\"subscriptionId is required\");\n }\n\n const cancelNow = options?.cancelNow ?? false;\n const data = await this._http.request(\"POST\", `/subscription/${subscriptionId}/cancel`, {\n jsonBody: { cancel_at_period_end: !cancelNow },\n });\n return new SubscriptionCancel(data);\n }\n}\n","import { AuthenticationError } from \"./errors.js\";\nimport { DEFAULT_BASE_URL, DEFAULT_TIMEOUT, HTTPClient } from \"./httpClient.js\";\nimport { SubscriptionService } from \"./services/subscriptionService.js\";\n\nexport interface PaylioClientOptions {\n baseUrl?: string;\n timeout?: number;\n fetchFn?: typeof fetch;\n}\n\nexport class PaylioClient {\n private readonly _http: HTTPClient;\n readonly subscription: SubscriptionService;\n\n constructor(apiKey: string, options?: PaylioClientOptions) {\n if (!apiKey) {\n throw new AuthenticationError({\n message:\n \"No API key provided. Set your API key when creating \" +\n \"the PaylioClient: new PaylioClient('sk_live_xxx')\",\n });\n }\n\n this._http = new HTTPClient({\n apiKey,\n baseUrl: options?.baseUrl ?? DEFAULT_BASE_URL,\n timeout: options?.timeout ?? DEFAULT_TIMEOUT,\n fetchFn: options?.fetchFn,\n });\n\n this.subscription = new SubscriptionService(this._http);\n }\n\n close(): void {\n this._http.close();\n }\n\n [Symbol.dispose](): void {\n this.close();\n }\n}\n"],"mappings":";AASO,IAAM,cAAN,cAA0B,MAAM;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAA4B;AACtC,UAAM,MAAM,QAAQ,WAAW;AAC/B,UAAM,GAAG;AACT,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,UAAU;AACf,SAAK,aAAa,QAAQ;AAC1B,SAA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I,oBAAoB,KAAK,KAAK;AAAA,EACxD;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAM;AAAA,EACnB;AAAA,EAEA,CAAC,OAAO,OAAO,IAAU;AACvB,SAAK,MAAM;AAAA,EACb;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "paylio",
3
+ "version": "0.1.0",
4
+ "description": "Node.js/TypeScript client library for the Paylio API",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.mjs",
10
+ "require": "./dist/index.cjs"
11
+ }
12
+ },
13
+ "main": "./dist/index.cjs",
14
+ "module": "./dist/index.mjs",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "scripts": {
23
+ "build": "tsup",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest",
26
+ "test:coverage": "vitest run --coverage",
27
+ "lint": "eslint src/ tests/",
28
+ "lint:fix": "eslint --fix src/ tests/",
29
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
30
+ "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
31
+ "typecheck": "tsc --noEmit",
32
+ "prepublishOnly": "npm run build"
33
+ },
34
+ "keywords": [
35
+ "paylio",
36
+ "api",
37
+ "sdk",
38
+ "subscription",
39
+ "billing"
40
+ ],
41
+ "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/paylio-org/paylio-node.git"
45
+ },
46
+ "devDependencies": {
47
+ "@eslint/js": "^10.0.0",
48
+ "@vitest/coverage-istanbul": "^4.0.0",
49
+ "eslint": "^10.0.0",
50
+ "prettier": "^3.2.0",
51
+ "tsup": "^8.0.0",
52
+ "typescript": "^5.4.0",
53
+ "typescript-eslint": "^8.0.0",
54
+ "vitest": "^4.0.0"
55
+ },
56
+ "overrides": {
57
+ "minimatch": ">=10.2.1"
58
+ }
59
+ }