@astra-pay/sdk 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.
- package/README.md +107 -0
- package/build/client.d.ts +16 -0
- package/build/client.d.ts.map +1 -0
- package/build/client.js +87 -0
- package/build/client.js.map +1 -0
- package/build/errors.d.ts +6 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +11 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +7 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -0
- package/build/payments.d.ts +15 -0
- package/build/payments.d.ts.map +1 -0
- package/build/payments.js +34 -0
- package/build/payments.js.map +1 -0
- package/build/products.d.ts +17 -0
- package/build/products.d.ts.map +1 -0
- package/build/products.js +28 -0
- package/build/products.js.map +1 -0
- package/build/types.d.ts +146 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/build/webhooks.d.ts +17 -0
- package/build/webhooks.d.ts.map +1 -0
- package/build/webhooks.js +28 -0
- package/build/webhooks.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# @astra-pay/sdk
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the [AstraPay](https://pay.byastra.ai) crypto payment API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @astra-pay/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @astra-pay/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { AstraPayClient } from "@astra-pay/sdk";
|
|
17
|
+
|
|
18
|
+
const client = new AstraPayClient("ap_live_...");
|
|
19
|
+
|
|
20
|
+
// Create a payment
|
|
21
|
+
const payment = await client.payments.create({
|
|
22
|
+
amount: 25,
|
|
23
|
+
token: "USDC",
|
|
24
|
+
network: "BASE",
|
|
25
|
+
});
|
|
26
|
+
console.log(payment.checkout_url);
|
|
27
|
+
|
|
28
|
+
// List payments
|
|
29
|
+
const { data, meta } = await client.payments.list({ status: "PENDING" });
|
|
30
|
+
|
|
31
|
+
// Create a product
|
|
32
|
+
const product = await client.products.create({
|
|
33
|
+
name: "Pro Plan",
|
|
34
|
+
price: 49,
|
|
35
|
+
currency_type: "FIAT",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Register a webhook
|
|
39
|
+
const webhook = await client.webhooks.create({
|
|
40
|
+
url: "https://example.com/webhook",
|
|
41
|
+
events: ["payment.completed"],
|
|
42
|
+
});
|
|
43
|
+
console.log(webhook.secret); // Store this securely
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API Reference
|
|
47
|
+
|
|
48
|
+
### `new AstraPayClient(apiKey, options?)`
|
|
49
|
+
|
|
50
|
+
| Option | Default | Description |
|
|
51
|
+
| --------- | --------------------------- | --------------- |
|
|
52
|
+
| `baseUrl` | `https://apipay.byastra.ai` | API base URL |
|
|
53
|
+
| `prefix` | `/v1` | API path prefix |
|
|
54
|
+
|
|
55
|
+
### Payments
|
|
56
|
+
|
|
57
|
+
| Method | Description |
|
|
58
|
+
| -------------------------------- | ------------------------ |
|
|
59
|
+
| `client.payments.create(params)` | Create a payment |
|
|
60
|
+
| `client.payments.get(id)` | Get payment by ID |
|
|
61
|
+
| `client.payments.list(params?)` | List payments |
|
|
62
|
+
| `client.payments.cancel(id)` | Cancel a pending payment |
|
|
63
|
+
|
|
64
|
+
### Products
|
|
65
|
+
|
|
66
|
+
| Method | Description |
|
|
67
|
+
| ------------------------------------ | ----------------- |
|
|
68
|
+
| `client.products.create(params)` | Create a product |
|
|
69
|
+
| `client.products.get(id)` | Get product by ID |
|
|
70
|
+
| `client.products.list()` | List all products |
|
|
71
|
+
| `client.products.update(id, params)` | Update a product |
|
|
72
|
+
| `client.products.delete(id)` | Delete a product |
|
|
73
|
+
|
|
74
|
+
### Webhooks
|
|
75
|
+
|
|
76
|
+
| Method | Description |
|
|
77
|
+
| ------------------------------------ | ----------------- |
|
|
78
|
+
| `client.webhooks.create(params)` | Create a webhook |
|
|
79
|
+
| `client.webhooks.get(id)` | Get webhook by ID |
|
|
80
|
+
| `client.webhooks.list()` | List all webhooks |
|
|
81
|
+
| `client.webhooks.update(id, params)` | Update a webhook |
|
|
82
|
+
| `client.webhooks.delete(id)` | Delete a webhook |
|
|
83
|
+
|
|
84
|
+
## Error Handling
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { AstraPayClient, AstraPayError } from "@astra-pay/sdk";
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
await client.payments.get("invalid-id");
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (err instanceof AstraPayError) {
|
|
93
|
+
console.log(err.status); // 404
|
|
94
|
+
console.log(err.code); // "NOT_FOUND"
|
|
95
|
+
console.log(err.message); // "Payment not found"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Requirements
|
|
101
|
+
|
|
102
|
+
- Node.js >= 18.0.0 (uses native `fetch`)
|
|
103
|
+
- Zero runtime dependencies
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PaymentsResource } from "./payments.js";
|
|
2
|
+
import { ProductsResource } from "./products.js";
|
|
3
|
+
import { WebhooksResource } from "./webhooks.js";
|
|
4
|
+
import type { ClientOptions } from "./types.js";
|
|
5
|
+
export declare class AstraPayClient {
|
|
6
|
+
readonly payments: PaymentsResource;
|
|
7
|
+
readonly products: ProductsResource;
|
|
8
|
+
readonly webhooks: WebhooksResource;
|
|
9
|
+
private readonly apiKey;
|
|
10
|
+
private readonly baseUrl;
|
|
11
|
+
private readonly prefix;
|
|
12
|
+
constructor(apiKey: string, options?: ClientOptions);
|
|
13
|
+
/** @internal — used by resource classes. Not part of the public API. */
|
|
14
|
+
_request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMhD,qBAAa,cAAc;IACzB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IAEpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa;IAenD,wEAAwE;IAClE,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CA0E5E"}
|
package/build/client.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { AstraPayError } from "./errors.js";
|
|
2
|
+
import { PaymentsResource } from "./payments.js";
|
|
3
|
+
import { ProductsResource } from "./products.js";
|
|
4
|
+
import { WebhooksResource } from "./webhooks.js";
|
|
5
|
+
const DEFAULT_BASE_URL = "https://apipay.byastra.ai";
|
|
6
|
+
const DEFAULT_PREFIX = "/v1";
|
|
7
|
+
const REQUEST_TIMEOUT_MS = 10_000;
|
|
8
|
+
export class AstraPayClient {
|
|
9
|
+
payments;
|
|
10
|
+
products;
|
|
11
|
+
webhooks;
|
|
12
|
+
apiKey;
|
|
13
|
+
baseUrl;
|
|
14
|
+
prefix;
|
|
15
|
+
constructor(apiKey, options) {
|
|
16
|
+
if (!apiKey) {
|
|
17
|
+
throw new Error("API key is required. Generate one at https://pay.byastra.ai/settings → API Keys.");
|
|
18
|
+
}
|
|
19
|
+
this.apiKey = apiKey;
|
|
20
|
+
this.baseUrl = (options?.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
21
|
+
this.prefix = options?.prefix ?? DEFAULT_PREFIX;
|
|
22
|
+
this.payments = new PaymentsResource(this);
|
|
23
|
+
this.products = new ProductsResource(this);
|
|
24
|
+
this.webhooks = new WebhooksResource(this);
|
|
25
|
+
}
|
|
26
|
+
/** @internal — used by resource classes. Not part of the public API. */
|
|
27
|
+
async _request(method, path, body) {
|
|
28
|
+
const url = `${this.baseUrl}${this.prefix}${path}`;
|
|
29
|
+
const headers = {
|
|
30
|
+
"X-Api-Key": this.apiKey,
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
};
|
|
33
|
+
let res;
|
|
34
|
+
try {
|
|
35
|
+
res = await fetch(url, {
|
|
36
|
+
method,
|
|
37
|
+
headers,
|
|
38
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
39
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (err instanceof DOMException && err.name === "TimeoutError") {
|
|
44
|
+
throw new AstraPayError(`Request timed out after ${REQUEST_TIMEOUT_MS}ms: ${method} ${path}`, 0, "TIMEOUT");
|
|
45
|
+
}
|
|
46
|
+
throw new AstraPayError(`Network error: ${err instanceof Error ? err.message : String(err)}`, 0, "NETWORK_ERROR");
|
|
47
|
+
}
|
|
48
|
+
let data;
|
|
49
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
50
|
+
if (contentType.includes("application/json")) {
|
|
51
|
+
try {
|
|
52
|
+
data = await res.json();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
data = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
data = await res.text().catch(() => null);
|
|
60
|
+
}
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
const errBody = data;
|
|
63
|
+
let message = `API error ${res.status}`;
|
|
64
|
+
let code = "UNKNOWN";
|
|
65
|
+
if (errBody && typeof errBody === "object") {
|
|
66
|
+
if ("error" in errBody && errBody.error) {
|
|
67
|
+
message = errBody.error.message ?? message;
|
|
68
|
+
code = errBody.error.code ?? code;
|
|
69
|
+
}
|
|
70
|
+
else if ("message" in errBody && errBody.message) {
|
|
71
|
+
message = errBody.message;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
throw new AstraPayError(message, res.status, code);
|
|
75
|
+
}
|
|
76
|
+
// Strip the API's response wrapper (success, statusCode) added by ExternalApiResponseInterceptor
|
|
77
|
+
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
78
|
+
const obj = data;
|
|
79
|
+
if ("success" in obj && "statusCode" in obj) {
|
|
80
|
+
delete obj.success;
|
|
81
|
+
delete obj.statusCode;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,MAAM,gBAAgB,G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3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,MAAM,CAAS;IACf,IAAI,CAAS;IAEtB,YAAY,OAAe,EAAE,MAAc,EAAE,IAAY;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AstraPayClient } from "./client.js";
|
|
2
|
+
export { AstraPayError } from "./errors.js";
|
|
3
|
+
export { PaymentsResource } from "./payments.js";
|
|
4
|
+
export { ProductsResource } from "./products.js";
|
|
5
|
+
export { WebhooksResource } from "./webhooks.js";
|
|
6
|
+
export type { ClientOptions, Token, Network, PaymentStatus, CurrencyType, WebhookEvent, Payment, CreatePaymentParams, ListPaymentsParams, PaginationMeta, PaginatedResponse, Product, CreateProductParams, UpdateProductParams, Webhook, WebhookWithSecret, CreateWebhookParams, UpdateWebhookParams, DeleteResult, } from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,YAAY,EAEV,aAAa,EAEb,KAAK,EACL,OAAO,EACP,aAAa,EACb,YAAY,EACZ,YAAY,EAEZ,OAAO,EACP,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EAEjB,OAAO,EACP,mBAAmB,EACnB,mBAAmB,EAEnB,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EAEnB,YAAY,GACb,MAAM,YAAY,CAAC"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AstraPayClient } from "./client.js";
|
|
2
|
+
export { AstraPayError } from "./errors.js";
|
|
3
|
+
export { PaymentsResource } from "./payments.js";
|
|
4
|
+
export { ProductsResource } from "./products.js";
|
|
5
|
+
export { WebhooksResource } from "./webhooks.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AstraPayClient } from "./client.js";
|
|
2
|
+
import type { Payment, CreatePaymentParams, ListPaymentsParams, PaginatedResponse } from "./types.js";
|
|
3
|
+
export declare class PaymentsResource {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: AstraPayClient);
|
|
6
|
+
/** Create a new crypto payment. Returns a checkout URL the customer can use to pay. */
|
|
7
|
+
create(params: CreatePaymentParams): Promise<Payment>;
|
|
8
|
+
/** Get the status and details of a payment by its ID or short ID. */
|
|
9
|
+
get(id: string): Promise<Payment>;
|
|
10
|
+
/** List payments with optional filters for status and search. */
|
|
11
|
+
list(params?: ListPaymentsParams): Promise<PaginatedResponse<Payment>>;
|
|
12
|
+
/** Cancel a pending payment by its ID. */
|
|
13
|
+
cancel(id: string): Promise<Payment>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,qBAAa,gBAAgB;IACf,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAE1C,uFAAuF;IACjF,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D,qEAAqE;IAC/D,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvC,iEAAiE;IAC3D,IAAI,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAY5E,0CAA0C;IACpC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAG3C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export class PaymentsResource {
|
|
2
|
+
client;
|
|
3
|
+
constructor(client) {
|
|
4
|
+
this.client = client;
|
|
5
|
+
}
|
|
6
|
+
/** Create a new crypto payment. Returns a checkout URL the customer can use to pay. */
|
|
7
|
+
async create(params) {
|
|
8
|
+
return this.client._request("POST", "/api/payments", params);
|
|
9
|
+
}
|
|
10
|
+
/** Get the status and details of a payment by its ID or short ID. */
|
|
11
|
+
async get(id) {
|
|
12
|
+
return this.client._request("GET", `/api/payments/${id}`);
|
|
13
|
+
}
|
|
14
|
+
/** List payments with optional filters for status and search. */
|
|
15
|
+
async list(params) {
|
|
16
|
+
const searchParams = new URLSearchParams();
|
|
17
|
+
if (params?.status)
|
|
18
|
+
searchParams.set("status", params.status);
|
|
19
|
+
if (params?.search)
|
|
20
|
+
searchParams.set("search", params.search);
|
|
21
|
+
if (params?.page)
|
|
22
|
+
searchParams.set("page", String(params.page));
|
|
23
|
+
if (params?.pageSize)
|
|
24
|
+
searchParams.set("pageSize", String(params.pageSize));
|
|
25
|
+
const query = searchParams.toString();
|
|
26
|
+
const path = query ? `/api/payments?${query}` : "/api/payments";
|
|
27
|
+
return this.client._request("GET", path);
|
|
28
|
+
}
|
|
29
|
+
/** Cancel a pending payment by its ID. */
|
|
30
|
+
async cancel(id) {
|
|
31
|
+
return this.client._request("POST", `/api/payments/${id}/cancel`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.js","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,gBAAgB;IACP;IAApB,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAE9C,uFAAuF;IACvF,KAAK,CAAC,MAAM,CAAC,MAA2B;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAU,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;IACxE,CAAC;IAED,qEAAqE;IACrE,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAU,KAAK,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,iEAAiE;IACjE,KAAK,CAAC,IAAI,CAAC,MAA2B;QACpC,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAC;QAC3C,IAAI,MAAM,EAAE,MAAM;YAAE,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9D,IAAI,MAAM,EAAE,MAAM;YAAE,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9D,IAAI,MAAM,EAAE,IAAI;YAAE,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAChE,IAAI,MAAM,EAAE,QAAQ;YAAE,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE5E,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;QAChE,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAA6B,KAAK,EAAE,IAAI,CAAC,CAAC;IACvE,CAAC;IAED,0CAA0C;IAC1C,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAU,MAAM,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AstraPayClient } from "./client.js";
|
|
2
|
+
import type { Product, CreateProductParams, UpdateProductParams, DeleteResult } from "./types.js";
|
|
3
|
+
export declare class ProductsResource {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: AstraPayClient);
|
|
6
|
+
/** Create a new product with a price. Products generate shareable payment links. */
|
|
7
|
+
create(params: CreateProductParams): Promise<Product>;
|
|
8
|
+
/** Get a product by its ID. */
|
|
9
|
+
get(id: string): Promise<Product>;
|
|
10
|
+
/** List all products for the authenticated merchant. */
|
|
11
|
+
list(): Promise<Product[]>;
|
|
12
|
+
/** Update an existing product's details. */
|
|
13
|
+
update(id: string, params: UpdateProductParams): Promise<Product>;
|
|
14
|
+
/** Delete a product by its ID. */
|
|
15
|
+
delete(id: string): Promise<DeleteResult>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=products.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"products.d.ts","sourceRoot":"","sources":["../src/products.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,qBAAa,gBAAgB;IACf,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAE1C,oFAAoF;IAC9E,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D,+BAA+B;IACzB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvC,wDAAwD;IAClD,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAQhC,4CAA4C;IACtC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAQvE,kCAAkC;IAC5B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAGhD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class ProductsResource {
|
|
2
|
+
client;
|
|
3
|
+
constructor(client) {
|
|
4
|
+
this.client = client;
|
|
5
|
+
}
|
|
6
|
+
/** Create a new product with a price. Products generate shareable payment links. */
|
|
7
|
+
async create(params) {
|
|
8
|
+
return this.client._request("POST", "/api/products", params);
|
|
9
|
+
}
|
|
10
|
+
/** Get a product by its ID. */
|
|
11
|
+
async get(id) {
|
|
12
|
+
return this.client._request("GET", `/api/products/${id}`);
|
|
13
|
+
}
|
|
14
|
+
/** List all products for the authenticated merchant. */
|
|
15
|
+
async list() {
|
|
16
|
+
const res = await this.client._request("GET", "/api/products");
|
|
17
|
+
return res.data;
|
|
18
|
+
}
|
|
19
|
+
/** Update an existing product's details. */
|
|
20
|
+
async update(id, params) {
|
|
21
|
+
return this.client._request("PATCH", `/api/products/${id}`, params);
|
|
22
|
+
}
|
|
23
|
+
/** Delete a product by its ID. */
|
|
24
|
+
async delete(id) {
|
|
25
|
+
return this.client._request("DELETE", `/api/products/${id}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=products.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"products.js","sourceRoot":"","sources":["../src/products.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,gBAAgB;IACP;IAApB,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAE9C,oFAAoF;IACpF,KAAK,CAAC,MAAM,CAAC,MAA2B;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAU,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;IACxE,CAAC;IAED,+BAA+B;IAC/B,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAU,KAAK,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,wDAAwD;IACxD,KAAK,CAAC,IAAI;QACR,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CACpC,KAAK,EACL,eAAe,CAChB,CAAC;QACF,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,4CAA4C;IAC5C,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,MAA2B;QAClD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CACzB,OAAO,EACP,iBAAiB,EAAE,EAAE,EACrB,MAAM,CACP,CAAC;IACJ,CAAC;IAED,kCAAkC;IAClC,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAe,QAAQ,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export type Token = "USDC" | "USDT" | "DAI" | "ETH" | "BNB" | "POL";
|
|
2
|
+
export type Network = "BASE" | "ERC20" | "BEP20" | "ARB" | "POL";
|
|
3
|
+
export type PaymentStatus = "pending" | "completed" | "partially_paid" | "expired" | "canceled";
|
|
4
|
+
export type CurrencyType = "FIAT" | "CRYPTO";
|
|
5
|
+
export type WebhookEvent = "payment.completed" | "payment.expired" | "payment.canceled" | "payment.partially_paid";
|
|
6
|
+
export interface ClientOptions {
|
|
7
|
+
/** Base URL of the AstraPay API. Default: `https://apipay.byastra.ai` */
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
/** API path prefix. Default: `/v1` */
|
|
10
|
+
prefix?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Payment {
|
|
13
|
+
id: string;
|
|
14
|
+
short_id: string;
|
|
15
|
+
amount: number;
|
|
16
|
+
token: string;
|
|
17
|
+
network: string;
|
|
18
|
+
status: PaymentStatus;
|
|
19
|
+
checkout_url: string;
|
|
20
|
+
transaction_hash: string | null;
|
|
21
|
+
customer_email: string | null;
|
|
22
|
+
customer_name: string | null;
|
|
23
|
+
metadata: Record<string, unknown> | null;
|
|
24
|
+
test_mode: boolean;
|
|
25
|
+
redirect_url: string | null;
|
|
26
|
+
cancel_url: string | null;
|
|
27
|
+
expires_at: string | null;
|
|
28
|
+
created_at: string | null;
|
|
29
|
+
}
|
|
30
|
+
export interface CreatePaymentParams {
|
|
31
|
+
/** Amount in USD (required if no product_id) */
|
|
32
|
+
amount?: number;
|
|
33
|
+
/** Product ID to charge for (required if no amount) */
|
|
34
|
+
product_id?: string;
|
|
35
|
+
/** Crypto token to accept. Default: USDC */
|
|
36
|
+
token?: Token;
|
|
37
|
+
/** Blockchain network. Default: BASE */
|
|
38
|
+
network?: Network;
|
|
39
|
+
/** Customer email address */
|
|
40
|
+
customer_email?: string;
|
|
41
|
+
/** Customer name */
|
|
42
|
+
customer_name?: string;
|
|
43
|
+
/** URL to redirect customer after successful payment */
|
|
44
|
+
redirect_url?: string;
|
|
45
|
+
/** URL to redirect if payment is canceled */
|
|
46
|
+
cancel_url?: string;
|
|
47
|
+
/** Custom metadata key-value pairs */
|
|
48
|
+
metadata?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
export interface ListPaymentsParams {
|
|
51
|
+
/** Filter by payment status */
|
|
52
|
+
status?: "PENDING" | "COMPLETED" | "PARTIALLY_PAID" | "EXPIRED" | "CANCELED";
|
|
53
|
+
/** Search term (customer email, name, or ID) */
|
|
54
|
+
search?: string;
|
|
55
|
+
/** Page number (default 1) */
|
|
56
|
+
page?: number;
|
|
57
|
+
/** Results per page (default 10) */
|
|
58
|
+
pageSize?: number;
|
|
59
|
+
}
|
|
60
|
+
export interface PaginationMeta {
|
|
61
|
+
page: number;
|
|
62
|
+
pageSize: number;
|
|
63
|
+
totalItems: number;
|
|
64
|
+
totalPages: number;
|
|
65
|
+
hasNextPage: boolean;
|
|
66
|
+
hasPreviousPage: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface PaginatedResponse<T> {
|
|
69
|
+
data: T[];
|
|
70
|
+
meta: PaginationMeta;
|
|
71
|
+
}
|
|
72
|
+
export interface Product {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
description: string | null;
|
|
76
|
+
price: number;
|
|
77
|
+
currency_type: CurrencyType;
|
|
78
|
+
token: string | null;
|
|
79
|
+
network: string | null;
|
|
80
|
+
active: boolean;
|
|
81
|
+
share_link: string | null;
|
|
82
|
+
created_at: string | null;
|
|
83
|
+
updated_at: string | null;
|
|
84
|
+
}
|
|
85
|
+
export interface CreateProductParams {
|
|
86
|
+
/** Product name */
|
|
87
|
+
name: string;
|
|
88
|
+
/** Product description */
|
|
89
|
+
description?: string;
|
|
90
|
+
/** Price (in USD for FIAT, or token amount for CRYPTO) */
|
|
91
|
+
price: number;
|
|
92
|
+
/** FIAT for USD pricing, CRYPTO for token-denominated pricing */
|
|
93
|
+
currency_type: CurrencyType;
|
|
94
|
+
/** Crypto token (required if currency_type is CRYPTO) */
|
|
95
|
+
token?: Token;
|
|
96
|
+
/** Blockchain network (required if currency_type is CRYPTO) */
|
|
97
|
+
network?: Network;
|
|
98
|
+
/** Whether the product is active (default true) */
|
|
99
|
+
active?: boolean;
|
|
100
|
+
}
|
|
101
|
+
export interface UpdateProductParams {
|
|
102
|
+
/** New product name */
|
|
103
|
+
name?: string;
|
|
104
|
+
/** New product description */
|
|
105
|
+
description?: string;
|
|
106
|
+
/** New price */
|
|
107
|
+
price?: number;
|
|
108
|
+
/** FIAT or CRYPTO */
|
|
109
|
+
currency_type?: CurrencyType;
|
|
110
|
+
/** Crypto token */
|
|
111
|
+
token?: Token;
|
|
112
|
+
/** Blockchain network */
|
|
113
|
+
network?: Network;
|
|
114
|
+
/** Whether the product is active */
|
|
115
|
+
active?: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface Webhook {
|
|
118
|
+
id: string;
|
|
119
|
+
url: string;
|
|
120
|
+
events: WebhookEvent[];
|
|
121
|
+
active: boolean;
|
|
122
|
+
created_at: string | null;
|
|
123
|
+
updated_at: string | null;
|
|
124
|
+
}
|
|
125
|
+
export interface WebhookWithSecret extends Webhook {
|
|
126
|
+
/** Signing secret — only returned on create. Store it securely. */
|
|
127
|
+
secret: string;
|
|
128
|
+
}
|
|
129
|
+
export interface CreateWebhookParams {
|
|
130
|
+
/** Webhook endpoint URL (must be HTTPS) */
|
|
131
|
+
url: string;
|
|
132
|
+
/** Events to subscribe to */
|
|
133
|
+
events: WebhookEvent[];
|
|
134
|
+
}
|
|
135
|
+
export interface UpdateWebhookParams {
|
|
136
|
+
/** New webhook URL */
|
|
137
|
+
url?: string;
|
|
138
|
+
/** New events to subscribe to */
|
|
139
|
+
events?: WebhookEvent[];
|
|
140
|
+
/** Enable or disable the webhook */
|
|
141
|
+
active?: boolean;
|
|
142
|
+
}
|
|
143
|
+
export interface DeleteResult {
|
|
144
|
+
deleted: true;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEpE,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC;AAEjE,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,WAAW,GACX,gBAAgB,GAChB,SAAS,GACT,UAAU,CAAC;AAEf,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE7C,MAAM,MAAM,YAAY,GACpB,mBAAmB,GACnB,iBAAiB,GACjB,kBAAkB,GAClB,wBAAwB,CAAC;AAI7B,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ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E,KAAK,CAAC;IACd,yBAAyB;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oCAAoC;IACpC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAID,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAkB,SAAQ,OAAO;IAChD,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,6BAA6B;IAC7B,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,sBAAsB;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;IACxB,oCAAoC;IACpC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,IAAI,CAAC;CACf"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,uEAAuE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AstraPayClient } from "./client.js";
|
|
2
|
+
import type { Webhook, WebhookWithSecret, CreateWebhookParams, UpdateWebhookParams, DeleteResult } from "./types.js";
|
|
3
|
+
export declare class WebhooksResource {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: AstraPayClient);
|
|
6
|
+
/** Register a webhook URL to receive payment event notifications. Returns a signing secret. */
|
|
7
|
+
create(params: CreateWebhookParams): Promise<WebhookWithSecret>;
|
|
8
|
+
/** Get details of a webhook by its ID. */
|
|
9
|
+
get(id: string): Promise<Webhook>;
|
|
10
|
+
/** List all registered webhooks for the authenticated merchant. */
|
|
11
|
+
list(): Promise<Webhook[]>;
|
|
12
|
+
/** Update a webhook's URL, events, or active status. */
|
|
13
|
+
update(id: string, params: UpdateWebhookParams): Promise<Webhook>;
|
|
14
|
+
/** Delete a webhook by its ID. */
|
|
15
|
+
delete(id: string): Promise<DeleteResult>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,qBAAa,gBAAgB;IACf,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAE1C,+FAA+F;IACzF,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQrE,0CAA0C;IACpC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvC,mEAAmE;IAC7D,IAAI,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAQhC,wDAAwD;IAClD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAQvE,kCAAkC;IAC5B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAGhD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class WebhooksResource {
|
|
2
|
+
client;
|
|
3
|
+
constructor(client) {
|
|
4
|
+
this.client = client;
|
|
5
|
+
}
|
|
6
|
+
/** Register a webhook URL to receive payment event notifications. Returns a signing secret. */
|
|
7
|
+
async create(params) {
|
|
8
|
+
return this.client._request("POST", "/api/webhooks", params);
|
|
9
|
+
}
|
|
10
|
+
/** Get details of a webhook by its ID. */
|
|
11
|
+
async get(id) {
|
|
12
|
+
return this.client._request("GET", `/api/webhooks/${id}`);
|
|
13
|
+
}
|
|
14
|
+
/** List all registered webhooks for the authenticated merchant. */
|
|
15
|
+
async list() {
|
|
16
|
+
const res = await this.client._request("GET", "/api/webhooks");
|
|
17
|
+
return res.data;
|
|
18
|
+
}
|
|
19
|
+
/** Update a webhook's URL, events, or active status. */
|
|
20
|
+
async update(id, params) {
|
|
21
|
+
return this.client._request("PATCH", `/api/webhooks/${id}`, params);
|
|
22
|
+
}
|
|
23
|
+
/** Delete a webhook by its ID. */
|
|
24
|
+
async delete(id) {
|
|
25
|
+
return this.client._request("DELETE", `/api/webhooks/${id}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,gBAAgB;IACP;IAApB,YAAoB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAE9C,+FAA+F;IAC/F,KAAK,CAAC,MAAM,CAAC,MAA2B;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CACzB,MAAM,EACN,eAAe,EACf,MAAM,CACP,CAAC;IACJ,CAAC;IAED,0CAA0C;IAC1C,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAU,KAAK,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,mEAAmE;IACnE,KAAK,CAAC,IAAI;QACR,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CACpC,KAAK,EACL,eAAe,CAChB,CAAC;QACF,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAED,wDAAwD;IACxD,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,MAA2B;QAClD,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CACzB,OAAO,EACP,iBAAiB,EAAE,EAAE,EACrB,MAAM,CACP,CAAC;IACJ,CAAC;IAED,kCAAkC;IAClC,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAe,QAAQ,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@astra-pay/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official TypeScript SDK for the AstraPay crypto payment API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./build/index.js",
|
|
7
|
+
"types": "./build/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./build/index.d.ts",
|
|
11
|
+
"import": "./build/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"build"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"prepublishOnly": "yarn build"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18.0.0"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"astrapay",
|
|
27
|
+
"sdk",
|
|
28
|
+
"crypto",
|
|
29
|
+
"payments",
|
|
30
|
+
"typescript",
|
|
31
|
+
"api"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^22.0.0",
|
|
36
|
+
"typescript": "^5.7.0"
|
|
37
|
+
}
|
|
38
|
+
}
|