aipp-node 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ interface AippConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ interface ChargeParams {
6
+ amountSats: number;
7
+ memo?: string;
8
+ }
9
+ interface ChargeResponse {
10
+ payment_request: string;
11
+ payment_hash: string;
12
+ amount_sats: number;
13
+ }
14
+ interface ChargeStatus {
15
+ status: 'pending' | 'settled';
16
+ payment_hash: string;
17
+ amount_sats: number;
18
+ }
19
+ interface AippErrorResponse {
20
+ error: string;
21
+ code?: string;
22
+ }
23
+ interface PayoutResponse {
24
+ message: string;
25
+ amount_sats?: number;
26
+ }
27
+
28
+ declare class Aipp {
29
+ private apiKey;
30
+ private baseUrl;
31
+ constructor(config: AippConfig);
32
+ private request;
33
+ /**
34
+ * Creates a new Lightning Invoice
35
+ */
36
+ createCharge(params: ChargeParams): Promise<ChargeResponse>;
37
+ /**
38
+ * Checks the status of an existing charge
39
+ */
40
+ getCharge(paymentHash: string): Promise<ChargeStatus>;
41
+ /**
42
+ * Triggers a manual withdrawal of your merchant balance
43
+ */
44
+ payout(): Promise<PayoutResponse>;
45
+ }
46
+
47
+ export { Aipp, type AippConfig, type AippErrorResponse, type ChargeParams, type ChargeResponse, type ChargeStatus, type PayoutResponse };
@@ -0,0 +1,47 @@
1
+ interface AippConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+ interface ChargeParams {
6
+ amountSats: number;
7
+ memo?: string;
8
+ }
9
+ interface ChargeResponse {
10
+ payment_request: string;
11
+ payment_hash: string;
12
+ amount_sats: number;
13
+ }
14
+ interface ChargeStatus {
15
+ status: 'pending' | 'settled';
16
+ payment_hash: string;
17
+ amount_sats: number;
18
+ }
19
+ interface AippErrorResponse {
20
+ error: string;
21
+ code?: string;
22
+ }
23
+ interface PayoutResponse {
24
+ message: string;
25
+ amount_sats?: number;
26
+ }
27
+
28
+ declare class Aipp {
29
+ private apiKey;
30
+ private baseUrl;
31
+ constructor(config: AippConfig);
32
+ private request;
33
+ /**
34
+ * Creates a new Lightning Invoice
35
+ */
36
+ createCharge(params: ChargeParams): Promise<ChargeResponse>;
37
+ /**
38
+ * Checks the status of an existing charge
39
+ */
40
+ getCharge(paymentHash: string): Promise<ChargeStatus>;
41
+ /**
42
+ * Triggers a manual withdrawal of your merchant balance
43
+ */
44
+ payout(): Promise<PayoutResponse>;
45
+ }
46
+
47
+ export { Aipp, type AippConfig, type AippErrorResponse, type ChargeParams, type ChargeResponse, type ChargeStatus, type PayoutResponse };
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
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
+ Aipp: () => Aipp
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/client.ts
28
+ var Aipp = class {
29
+ apiKey;
30
+ baseUrl;
31
+ constructor(config) {
32
+ if (!config.apiKey) {
33
+ throw new Error("AIPP: apiKey is required");
34
+ }
35
+ this.apiKey = config.apiKey;
36
+ this.baseUrl = config.baseUrl || "https://aipp.dev";
37
+ }
38
+ async request(endpoint, options = {}) {
39
+ const url = `${this.baseUrl}${endpoint}`;
40
+ const headers = {
41
+ "Content-Type": "application/json",
42
+ "X-Api-Key": this.apiKey,
43
+ ...options.headers
44
+ };
45
+ const response = await fetch(url, { ...options, headers });
46
+ if (!response.ok) {
47
+ let errorData;
48
+ try {
49
+ errorData = await response.json();
50
+ } catch (err) {
51
+ throw new Error(`AIPP API Error: ${response.status} ${response.statusText}`);
52
+ }
53
+ throw new Error(`AIPP API Error: ${errorData.error || response.statusText}`);
54
+ }
55
+ return response.json();
56
+ }
57
+ /**
58
+ * Creates a new Lightning Invoice
59
+ */
60
+ async createCharge(params) {
61
+ if (!params.amountSats || params.amountSats <= 0) {
62
+ throw new Error("AIPP: amountSats must be greater than 0");
63
+ }
64
+ return this.request("/invoice/create", {
65
+ method: "POST",
66
+ body: JSON.stringify({
67
+ amount_sats: params.amountSats,
68
+ memo: params.memo
69
+ })
70
+ });
71
+ }
72
+ /**
73
+ * Checks the status of an existing charge
74
+ */
75
+ async getCharge(paymentHash) {
76
+ if (!paymentHash) {
77
+ throw new Error("AIPP: paymentHash is required");
78
+ }
79
+ return this.request(`/invoice/status/${paymentHash}`, {
80
+ method: "GET"
81
+ });
82
+ }
83
+ /**
84
+ * Triggers a manual withdrawal of your merchant balance
85
+ */
86
+ async payout() {
87
+ return this.request("/merchant/payout", {
88
+ method: "POST"
89
+ });
90
+ }
91
+ };
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ Aipp
95
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,68 @@
1
+ // src/client.ts
2
+ var Aipp = class {
3
+ apiKey;
4
+ baseUrl;
5
+ constructor(config) {
6
+ if (!config.apiKey) {
7
+ throw new Error("AIPP: apiKey is required");
8
+ }
9
+ this.apiKey = config.apiKey;
10
+ this.baseUrl = config.baseUrl || "https://aipp.dev";
11
+ }
12
+ async request(endpoint, options = {}) {
13
+ const url = `${this.baseUrl}${endpoint}`;
14
+ const headers = {
15
+ "Content-Type": "application/json",
16
+ "X-Api-Key": this.apiKey,
17
+ ...options.headers
18
+ };
19
+ const response = await fetch(url, { ...options, headers });
20
+ if (!response.ok) {
21
+ let errorData;
22
+ try {
23
+ errorData = await response.json();
24
+ } catch (err) {
25
+ throw new Error(`AIPP API Error: ${response.status} ${response.statusText}`);
26
+ }
27
+ throw new Error(`AIPP API Error: ${errorData.error || response.statusText}`);
28
+ }
29
+ return response.json();
30
+ }
31
+ /**
32
+ * Creates a new Lightning Invoice
33
+ */
34
+ async createCharge(params) {
35
+ if (!params.amountSats || params.amountSats <= 0) {
36
+ throw new Error("AIPP: amountSats must be greater than 0");
37
+ }
38
+ return this.request("/invoice/create", {
39
+ method: "POST",
40
+ body: JSON.stringify({
41
+ amount_sats: params.amountSats,
42
+ memo: params.memo
43
+ })
44
+ });
45
+ }
46
+ /**
47
+ * Checks the status of an existing charge
48
+ */
49
+ async getCharge(paymentHash) {
50
+ if (!paymentHash) {
51
+ throw new Error("AIPP: paymentHash is required");
52
+ }
53
+ return this.request(`/invoice/status/${paymentHash}`, {
54
+ method: "GET"
55
+ });
56
+ }
57
+ /**
58
+ * Triggers a manual withdrawal of your merchant balance
59
+ */
60
+ async payout() {
61
+ return this.request("/merchant/payout", {
62
+ method: "POST"
63
+ });
64
+ }
65
+ };
66
+ export {
67
+ Aipp
68
+ };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "aipp-node",
3
+ "version": "1.0.1",
4
+ "description": "Official Node.js SDK for AIPP - The Lightning Network Split-Payment Gateway",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsup src/index.ts --format cjs,esm --dts",
10
+ "test": "vitest run"
11
+ },
12
+ "keywords": [
13
+ "aipp",
14
+ "bitcoin",
15
+ "lightning",
16
+ "payments",
17
+ "l402",
18
+ "ai"
19
+ ],
20
+ "author": "AIPP",
21
+ "license": "MIT",
22
+ "devDependencies": {
23
+ "@types/node": "^20.0.0",
24
+ "tsup": "^8.0.0",
25
+ "typescript": "^5.0.0",
26
+ "vitest": "^1.0.0"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/aippde/aipp-key.git"
31
+ }
32
+ }
package/src/client.ts ADDED
@@ -0,0 +1,74 @@
1
+ import { AippConfig, ChargeParams, ChargeResponse, ChargeStatus, AippErrorResponse } from './types';
2
+
3
+ export class Aipp {
4
+ private apiKey: string;
5
+ private baseUrl: string;
6
+
7
+ constructor(config: AippConfig) {
8
+ if (!config.apiKey) {
9
+ throw new Error('AIPP: apiKey is required');
10
+ }
11
+ this.apiKey = config.apiKey;
12
+ this.baseUrl = config.baseUrl || 'https://aipp.dev';
13
+ }
14
+
15
+ private async request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
16
+ const url = `${this.baseUrl}${endpoint}`;
17
+ const headers = {
18
+ 'Content-Type': 'application/json',
19
+ 'X-Api-Key': this.apiKey,
20
+ ...options.headers,
21
+ };
22
+
23
+ const response = await fetch(url, { ...options, headers });
24
+
25
+ if (!response.ok) {
26
+ let errorData: AippErrorResponse;
27
+ try {
28
+ errorData = await response.json();
29
+ } catch (err) {
30
+ throw new Error(`AIPP API Error: ${response.status} ${response.statusText}`);
31
+ }
32
+ throw new Error(`AIPP API Error: ${errorData.error || response.statusText}`);
33
+ }
34
+
35
+ return response.json() as Promise<T>;
36
+ }
37
+
38
+ /**
39
+ * Creates a new Lightning Invoice
40
+ */
41
+ async createCharge(params: ChargeParams): Promise<ChargeResponse> {
42
+ if (!params.amountSats || params.amountSats <= 0) {
43
+ throw new Error('AIPP: amountSats must be greater than 0');
44
+ }
45
+ return this.request<ChargeResponse>('/invoice/create', {
46
+ method: 'POST',
47
+ body: JSON.stringify({
48
+ amount_sats: params.amountSats,
49
+ memo: params.memo,
50
+ }),
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Checks the status of an existing charge
56
+ */
57
+ async getCharge(paymentHash: string): Promise<ChargeStatus> {
58
+ if (!paymentHash) {
59
+ throw new Error('AIPP: paymentHash is required');
60
+ }
61
+ return this.request<ChargeStatus>(`/invoice/status/${paymentHash}`, {
62
+ method: 'GET',
63
+ });
64
+ }
65
+
66
+ /**
67
+ * Triggers a manual withdrawal of your merchant balance
68
+ */
69
+ async payout(): Promise<import('./types').PayoutResponse> {
70
+ return this.request<import('./types').PayoutResponse>('/merchant/payout', {
71
+ method: 'POST',
72
+ });
73
+ }
74
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './client';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,31 @@
1
+ export interface AippConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
5
+
6
+ export interface ChargeParams {
7
+ amountSats: number;
8
+ memo?: string;
9
+ }
10
+
11
+ export interface ChargeResponse {
12
+ payment_request: string;
13
+ payment_hash: string;
14
+ amount_sats: number;
15
+ }
16
+
17
+ export interface ChargeStatus {
18
+ status: 'pending' | 'settled';
19
+ payment_hash: string;
20
+ amount_sats: number;
21
+ }
22
+
23
+ export interface AippErrorResponse {
24
+ error: string;
25
+ code?: string;
26
+ }
27
+
28
+ export interface PayoutResponse {
29
+ message: string;
30
+ amount_sats?: number;
31
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2022",
4
+ "module": "esnext",
5
+ "moduleResolution": "node",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "declaration": true,
11
+ "outDir": "dist"
12
+ },
13
+ "include": ["src"]
14
+ }