@eventop/sdk 1.0.1 → 1.0.2
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/dist/cjs/client.js +52 -0
- package/dist/cjs/errors.js +33 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/resources/checkout.js +18 -0
- package/dist/cjs/resources/customers.js +1 -0
- package/dist/cjs/resources/subscriptions.js +18 -0
- package/dist/cjs/resources/webhooks.js +60 -0
- package/dist/cjs/types.js +2 -0
- package/dist/esm/client.js +45 -0
- package/dist/esm/errors.js +26 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/resources/checkout.js +14 -0
- package/dist/esm/resources/customers.js +1 -0
- package/dist/esm/resources/subscriptions.js +14 -0
- package/dist/esm/resources/webhooks.js +23 -0
- package/dist/esm/types.js +1 -0
- package/dist/types/client.d.ts +9 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/resources/checkout.d.ts +10 -0
- package/dist/types/resources/checkout.d.ts.map +1 -0
- package/dist/types/resources/customers.d.ts +1 -0
- package/dist/types/resources/customers.d.ts.map +1 -0
- package/dist/types/resources/subscriptions.d.ts +10 -0
- package/dist/types/resources/subscriptions.d.ts.map +1 -0
- package/dist/types/resources/webhooks.d.ts +9 -0
- package/dist/types/resources/webhooks.d.ts.map +1 -0
- package/dist/types/types.d.ts +44 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +44 -35
- package/src/client.ts +0 -64
- package/src/errors.ts +0 -31
- package/src/index.ts +0 -22
- package/src/resources/checkout.ts +0 -22
- package/src/resources/customers.ts +0 -0
- package/src/resources/subscriptions.ts +0 -24
- package/src/resources/webhooks.ts +0 -42
- package/src/types.ts +0 -49
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EventopClient = void 0;
|
|
7
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
class EventopClient {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.apiKey = config.apiKey;
|
|
12
|
+
// Set base URL based on environment
|
|
13
|
+
if (config.apiUrl) {
|
|
14
|
+
this.baseUrl = config.apiUrl;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const env = config.environment || this.detectEnvironment();
|
|
18
|
+
this.baseUrl =
|
|
19
|
+
env === 'devnet'
|
|
20
|
+
? 'https://eventop-server-app-production.up.railway.app'
|
|
21
|
+
: 'https://api.eventop.xyz';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
detectEnvironment() {
|
|
25
|
+
// Detect from API key prefix
|
|
26
|
+
if (this.apiKey.startsWith('sk_test_')) {
|
|
27
|
+
return 'devnet';
|
|
28
|
+
}
|
|
29
|
+
else if (this.apiKey.startsWith('sk_live_')) {
|
|
30
|
+
return 'mainnet';
|
|
31
|
+
}
|
|
32
|
+
throw new errors_1.AuthenticationError('Invalid API key format');
|
|
33
|
+
}
|
|
34
|
+
async request(method, path, body) {
|
|
35
|
+
const url = `${this.baseUrl}${path}`;
|
|
36
|
+
const headers = {
|
|
37
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
};
|
|
40
|
+
const response = await (0, node_fetch_1.default)(url, {
|
|
41
|
+
method,
|
|
42
|
+
headers,
|
|
43
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
44
|
+
});
|
|
45
|
+
const data = await response.json();
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new errors_1.EventopError(data.message || 'Request failed', response.status, data.code);
|
|
48
|
+
}
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.EventopClient = EventopClient;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotFoundError = exports.InvalidRequestError = exports.AuthenticationError = exports.EventopError = void 0;
|
|
4
|
+
class EventopError extends Error {
|
|
5
|
+
constructor(message, statusCode, code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.name = 'EventopError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.EventopError = EventopError;
|
|
13
|
+
class AuthenticationError extends EventopError {
|
|
14
|
+
constructor(message = 'Invalid API key') {
|
|
15
|
+
super(message, 401, 'authentication_error');
|
|
16
|
+
this.name = 'AuthenticationError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.AuthenticationError = AuthenticationError;
|
|
20
|
+
class InvalidRequestError extends EventopError {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(message, 400, 'invalid_request');
|
|
23
|
+
this.name = 'InvalidRequestError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.InvalidRequestError = InvalidRequestError;
|
|
27
|
+
class NotFoundError extends EventopError {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message, 404, 'not_found');
|
|
30
|
+
this.name = 'NotFoundError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.NotFoundError = NotFoundError;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Eventop = void 0;
|
|
18
|
+
const client_1 = require("./client");
|
|
19
|
+
const checkout_1 = require("./resources/checkout");
|
|
20
|
+
const subscriptions_1 = require("./resources/subscriptions");
|
|
21
|
+
const webhooks_1 = require("./resources/webhooks");
|
|
22
|
+
class Eventop {
|
|
23
|
+
constructor(config) {
|
|
24
|
+
const client = new client_1.EventopClient(config);
|
|
25
|
+
this.checkout = new checkout_1.Checkout(client);
|
|
26
|
+
this.subscriptions = new subscriptions_1.Subscriptions(client);
|
|
27
|
+
this.webhooks = new webhooks_1.Webhooks(client);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Eventop = Eventop;
|
|
31
|
+
__exportStar(require("./types"), exports);
|
|
32
|
+
__exportStar(require("./errors"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Checkout = void 0;
|
|
4
|
+
class Checkout {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async create(params) {
|
|
9
|
+
return this.client.request('POST', '/checkout/create', params);
|
|
10
|
+
}
|
|
11
|
+
async get(sessionId) {
|
|
12
|
+
return this.client.request('GET', `/checkout/${sessionId}`);
|
|
13
|
+
}
|
|
14
|
+
async cancel(sessionId) {
|
|
15
|
+
return this.client.request('POST', `/checkout/${sessionId}/cancel`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Checkout = Checkout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Subscriptions = void 0;
|
|
4
|
+
class Subscriptions {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async list() {
|
|
9
|
+
return this.client.request('GET', '/subscriptions');
|
|
10
|
+
}
|
|
11
|
+
async get(subscriptionId) {
|
|
12
|
+
return this.client.request('GET', `/subscriptions/${subscriptionId}`);
|
|
13
|
+
}
|
|
14
|
+
async cancel(subscriptionId) {
|
|
15
|
+
return this.client.request('POST', `/subscriptions/${subscriptionId}/cancel`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Subscriptions = Subscriptions;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Webhooks = void 0;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
class Webhooks {
|
|
39
|
+
constructor(client) {
|
|
40
|
+
this.client = client;
|
|
41
|
+
}
|
|
42
|
+
verifySignature(payload, signature, secret) {
|
|
43
|
+
const payloadString = typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
44
|
+
const expectedSignature = crypto
|
|
45
|
+
.createHmac('sha256', secret)
|
|
46
|
+
.update(payloadString)
|
|
47
|
+
.digest('hex');
|
|
48
|
+
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
|
|
49
|
+
}
|
|
50
|
+
constructEvent(payload, signature, secret) {
|
|
51
|
+
const payloadString = Buffer.isBuffer(payload)
|
|
52
|
+
? payload.toString('utf8')
|
|
53
|
+
: payload;
|
|
54
|
+
if (!this.verifySignature(payloadString, signature, secret)) {
|
|
55
|
+
throw new Error('Invalid webhook signature');
|
|
56
|
+
}
|
|
57
|
+
return JSON.parse(payloadString);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Webhooks = Webhooks;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { EventopError, AuthenticationError } from './errors';
|
|
3
|
+
export class EventopClient {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.apiKey = config.apiKey;
|
|
6
|
+
// Set base URL based on environment
|
|
7
|
+
if (config.apiUrl) {
|
|
8
|
+
this.baseUrl = config.apiUrl;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
const env = config.environment || this.detectEnvironment();
|
|
12
|
+
this.baseUrl =
|
|
13
|
+
env === 'devnet'
|
|
14
|
+
? 'https://eventop-server-app-production.up.railway.app'
|
|
15
|
+
: 'https://api.eventop.xyz';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
detectEnvironment() {
|
|
19
|
+
// Detect from API key prefix
|
|
20
|
+
if (this.apiKey.startsWith('sk_test_')) {
|
|
21
|
+
return 'devnet';
|
|
22
|
+
}
|
|
23
|
+
else if (this.apiKey.startsWith('sk_live_')) {
|
|
24
|
+
return 'mainnet';
|
|
25
|
+
}
|
|
26
|
+
throw new AuthenticationError('Invalid API key format');
|
|
27
|
+
}
|
|
28
|
+
async request(method, path, body) {
|
|
29
|
+
const url = `${this.baseUrl}${path}`;
|
|
30
|
+
const headers = {
|
|
31
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
};
|
|
34
|
+
const response = await fetch(url, {
|
|
35
|
+
method,
|
|
36
|
+
headers,
|
|
37
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
38
|
+
});
|
|
39
|
+
const data = await response.json();
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new EventopError(data.message || 'Request failed', response.status, data.code);
|
|
42
|
+
}
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class EventopError extends Error {
|
|
2
|
+
constructor(message, statusCode, code) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.statusCode = statusCode;
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = 'EventopError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class AuthenticationError extends EventopError {
|
|
10
|
+
constructor(message = 'Invalid API key') {
|
|
11
|
+
super(message, 401, 'authentication_error');
|
|
12
|
+
this.name = 'AuthenticationError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class InvalidRequestError extends EventopError {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message, 400, 'invalid_request');
|
|
18
|
+
this.name = 'InvalidRequestError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class NotFoundError extends EventopError {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message, 404, 'not_found');
|
|
24
|
+
this.name = 'NotFoundError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventopClient } from './client';
|
|
2
|
+
import { Checkout } from './resources/checkout';
|
|
3
|
+
import { Subscriptions } from './resources/subscriptions';
|
|
4
|
+
import { Webhooks } from './resources/webhooks';
|
|
5
|
+
export class Eventop {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
const client = new EventopClient(config);
|
|
8
|
+
this.checkout = new Checkout(client);
|
|
9
|
+
this.subscriptions = new Subscriptions(client);
|
|
10
|
+
this.webhooks = new Webhooks(client);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export * from './types';
|
|
14
|
+
export * from './errors';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class Checkout {
|
|
2
|
+
constructor(client) {
|
|
3
|
+
this.client = client;
|
|
4
|
+
}
|
|
5
|
+
async create(params) {
|
|
6
|
+
return this.client.request('POST', '/checkout/create', params);
|
|
7
|
+
}
|
|
8
|
+
async get(sessionId) {
|
|
9
|
+
return this.client.request('GET', `/checkout/${sessionId}`);
|
|
10
|
+
}
|
|
11
|
+
async cancel(sessionId) {
|
|
12
|
+
return this.client.request('POST', `/checkout/${sessionId}/cancel`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class Subscriptions {
|
|
2
|
+
constructor(client) {
|
|
3
|
+
this.client = client;
|
|
4
|
+
}
|
|
5
|
+
async list() {
|
|
6
|
+
return this.client.request('GET', '/subscriptions');
|
|
7
|
+
}
|
|
8
|
+
async get(subscriptionId) {
|
|
9
|
+
return this.client.request('GET', `/subscriptions/${subscriptionId}`);
|
|
10
|
+
}
|
|
11
|
+
async cancel(subscriptionId) {
|
|
12
|
+
return this.client.request('POST', `/subscriptions/${subscriptionId}/cancel`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
export class Webhooks {
|
|
3
|
+
constructor(client) {
|
|
4
|
+
this.client = client;
|
|
5
|
+
}
|
|
6
|
+
verifySignature(payload, signature, secret) {
|
|
7
|
+
const payloadString = typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
8
|
+
const expectedSignature = crypto
|
|
9
|
+
.createHmac('sha256', secret)
|
|
10
|
+
.update(payloadString)
|
|
11
|
+
.digest('hex');
|
|
12
|
+
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
|
|
13
|
+
}
|
|
14
|
+
constructEvent(payload, signature, secret) {
|
|
15
|
+
const payloadString = Buffer.isBuffer(payload)
|
|
16
|
+
? payload.toString('utf8')
|
|
17
|
+
: payload;
|
|
18
|
+
if (!this.verifySignature(payloadString, signature, secret)) {
|
|
19
|
+
throw new Error('Invalid webhook signature');
|
|
20
|
+
}
|
|
21
|
+
return JSON.parse(payloadString);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventopConfig } from './types';
|
|
2
|
+
export declare class EventopClient {
|
|
3
|
+
private apiKey;
|
|
4
|
+
private baseUrl;
|
|
5
|
+
constructor(config: EventopConfig);
|
|
6
|
+
private detectEnvironment;
|
|
7
|
+
request<T>(method: string, path: string, body?: any): Promise<T>;
|
|
8
|
+
}
|
|
9
|
+
//# 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,aAAa,EAAe,MAAM,SAAS,CAAC;AAGrD,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,aAAa;IAejC,OAAO,CAAC,iBAAiB;IAUnB,OAAO,CAAC,CAAC,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,GAAG,GACT,OAAO,CAAC,CAAC,CAAC;CA0Bd"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class EventopError extends Error {
|
|
2
|
+
statusCode?: number | undefined;
|
|
3
|
+
code?: string | undefined;
|
|
4
|
+
constructor(message: string, statusCode?: number | undefined, code?: string | undefined);
|
|
5
|
+
}
|
|
6
|
+
export declare class AuthenticationError extends EventopError {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class InvalidRequestError extends EventopError {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class NotFoundError extends EventopError {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IAG5B,UAAU,CAAC,EAAE,MAAM;IACnB,IAAI,CAAC,EAAE,MAAM;gBAFpB,OAAO,EAAE,MAAM,EACR,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,IAAI,CAAC,EAAE,MAAM,YAAA;CAKvB;AAED,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,OAAO,GAAE,MAA0B;CAIhD;AAED,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,aAAc,SAAQ,YAAY;gBACjC,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Checkout } from './resources/checkout';
|
|
2
|
+
import { Subscriptions } from './resources/subscriptions';
|
|
3
|
+
import { Webhooks } from './resources/webhooks';
|
|
4
|
+
import { EventopConfig } from './types';
|
|
5
|
+
export declare class Eventop {
|
|
6
|
+
checkout: Checkout;
|
|
7
|
+
subscriptions: Subscriptions;
|
|
8
|
+
webhooks: Webhooks;
|
|
9
|
+
constructor(config: EventopConfig);
|
|
10
|
+
}
|
|
11
|
+
export * from './types';
|
|
12
|
+
export * from './errors';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,OAAO;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC;gBAEd,MAAM,EAAE,aAAa;CAOlC;AAED,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EventopClient } from '../client';
|
|
2
|
+
import { CheckoutSessionParams, CheckoutSession } from '../types';
|
|
3
|
+
export declare class Checkout {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: EventopClient);
|
|
6
|
+
create(params: CheckoutSessionParams): Promise<CheckoutSession>;
|
|
7
|
+
get(sessionId: string): Promise<any>;
|
|
8
|
+
cancel(sessionId: string): Promise<any>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../../src/resources/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAElE,qBAAa,QAAQ;IACP,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAEnC,MAAM,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;IAQ/D,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIpC,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAG9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=customers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customers.d.ts","sourceRoot":"","sources":["../../../src/resources/customers.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EventopClient } from '../client';
|
|
2
|
+
import { Subscription } from '../types';
|
|
3
|
+
export declare class Subscriptions {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: EventopClient);
|
|
6
|
+
list(): Promise<Subscription[]>;
|
|
7
|
+
get(subscriptionId: string): Promise<Subscription>;
|
|
8
|
+
cancel(subscriptionId: string): Promise<any>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=subscriptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../../src/resources/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAEnC,IAAI,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAI/B,GAAG,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAOlD,MAAM,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CAMnD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventopClient } from '../client';
|
|
2
|
+
import { WebhookPayload } from '../types';
|
|
3
|
+
export declare class Webhooks {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: EventopClient);
|
|
6
|
+
verifySignature(payload: WebhookPayload | string, signature: string, secret: string): boolean;
|
|
7
|
+
constructEvent(payload: string | Buffer, signature: string, secret: string): WebhookPayload;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../../src/resources/webhooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,qBAAa,QAAQ;IACP,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAEzC,eAAe,CACb,OAAO,EAAE,cAAc,GAAG,MAAM,EAChC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO;IAeV,cAAc,CACZ,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,cAAc;CAWlB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type Environment = 'devnet' | 'mainnet';
|
|
2
|
+
export interface EventopConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
environment?: Environment;
|
|
5
|
+
apiUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CheckoutSessionParams {
|
|
8
|
+
planId: string;
|
|
9
|
+
customerEmail: string;
|
|
10
|
+
customerId?: string;
|
|
11
|
+
successUrl: string;
|
|
12
|
+
cancelUrl?: string;
|
|
13
|
+
metadata?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
export interface CheckoutSession {
|
|
16
|
+
sessionId: string;
|
|
17
|
+
url: string;
|
|
18
|
+
expiresAt: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Subscription {
|
|
21
|
+
subscriptionPda: string;
|
|
22
|
+
userWallet: string;
|
|
23
|
+
merchantWallet: string;
|
|
24
|
+
planId: string;
|
|
25
|
+
feeAmount: string;
|
|
26
|
+
paymentInterval: string;
|
|
27
|
+
isActive: boolean;
|
|
28
|
+
totalPaid: string;
|
|
29
|
+
paymentCount: number;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
cancelledAt?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Customer {
|
|
34
|
+
email: string;
|
|
35
|
+
customerId?: string;
|
|
36
|
+
walletAddress: string;
|
|
37
|
+
subscriptions: Subscription[];
|
|
38
|
+
}
|
|
39
|
+
export interface WebhookPayload {
|
|
40
|
+
event: string;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
data: any;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/C,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC;CACX"}
|
package/package.json
CHANGED
|
@@ -1,36 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
2
|
+
"name": "@eventop/sdk",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Official SDK for Eventop on-chain subscriptions",
|
|
5
|
+
"keywords": ["solana", "subscriptions", "crypto", "payments"],
|
|
6
|
+
"homepage": "https://github.com/eventop-s/sdk#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/eventop-s/sdk/issues"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/eventop-s/sdk.git"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Eventop",
|
|
16
|
+
"main": "./dist/cjs/index.js",
|
|
17
|
+
"module": "./dist/esm/index.js",
|
|
18
|
+
"types": "./dist/types/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"require": "./dist/cjs/index.js",
|
|
22
|
+
"import": "./dist/esm/index.js",
|
|
23
|
+
"types": "./dist/types/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "npm run build:cjs && npm run build:esm && npm run build:types",
|
|
32
|
+
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
33
|
+
"build:esm": "tsc --project tsconfig.esm.json",
|
|
34
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
35
|
+
"prepublishOnly": "npm run build"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"node-fetch": "^2.6.7"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^18.0.0",
|
|
42
|
+
"@types/node-fetch": "^2.6.2",
|
|
43
|
+
"typescript": "^5.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/client.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import fetch from 'node-fetch';
|
|
2
|
-
import { EventopConfig, Environment } from './types';
|
|
3
|
-
import { EventopError, AuthenticationError } from './errors';
|
|
4
|
-
|
|
5
|
-
export class EventopClient {
|
|
6
|
-
private apiKey: string;
|
|
7
|
-
private baseUrl: string;
|
|
8
|
-
|
|
9
|
-
constructor(config: EventopConfig) {
|
|
10
|
-
this.apiKey = config.apiKey;
|
|
11
|
-
|
|
12
|
-
// Set base URL based on environment
|
|
13
|
-
if (config.apiUrl) {
|
|
14
|
-
this.baseUrl = config.apiUrl;
|
|
15
|
-
} else {
|
|
16
|
-
const env = config.environment || this.detectEnvironment();
|
|
17
|
-
this.baseUrl =
|
|
18
|
-
env === 'devnet'
|
|
19
|
-
? 'https://eventop-server-app-production.up.railway.app'
|
|
20
|
-
: 'https://api.eventop.xyz';
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private detectEnvironment(): Environment {
|
|
25
|
-
// Detect from API key prefix
|
|
26
|
-
if (this.apiKey.startsWith('sk_test_')) {
|
|
27
|
-
return 'devnet';
|
|
28
|
-
} else if (this.apiKey.startsWith('sk_live_')) {
|
|
29
|
-
return 'mainnet';
|
|
30
|
-
}
|
|
31
|
-
throw new AuthenticationError('Invalid API key format');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async request<T>(
|
|
35
|
-
method: string,
|
|
36
|
-
path: string,
|
|
37
|
-
body?: any,
|
|
38
|
-
): Promise<T> {
|
|
39
|
-
const url = `${this.baseUrl}${path}`;
|
|
40
|
-
|
|
41
|
-
const headers: Record<string, string> = {
|
|
42
|
-
'Authorization': `Bearer ${this.apiKey}`,
|
|
43
|
-
'Content-Type': 'application/json',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const response = await fetch(url, {
|
|
47
|
-
method,
|
|
48
|
-
headers,
|
|
49
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const data = await response.json();
|
|
53
|
-
|
|
54
|
-
if (!response.ok) {
|
|
55
|
-
throw new EventopError(
|
|
56
|
-
data.message || 'Request failed',
|
|
57
|
-
response.status,
|
|
58
|
-
data.code,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return data as T;
|
|
63
|
-
}
|
|
64
|
-
}
|
package/src/errors.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export class EventopError extends Error {
|
|
2
|
-
constructor(
|
|
3
|
-
message: string,
|
|
4
|
-
public statusCode?: number,
|
|
5
|
-
public code?: string,
|
|
6
|
-
) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = 'EventopError';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class AuthenticationError extends EventopError {
|
|
13
|
-
constructor(message: string = 'Invalid API key') {
|
|
14
|
-
super(message, 401, 'authentication_error');
|
|
15
|
-
this.name = 'AuthenticationError';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class InvalidRequestError extends EventopError {
|
|
20
|
-
constructor(message: string) {
|
|
21
|
-
super(message, 400, 'invalid_request');
|
|
22
|
-
this.name = 'InvalidRequestError';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class NotFoundError extends EventopError {
|
|
27
|
-
constructor(message: string) {
|
|
28
|
-
super(message, 404, 'not_found');
|
|
29
|
-
this.name = 'NotFoundError';
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { EventopClient } from './client';
|
|
2
|
-
import { Checkout } from './resources/checkout';
|
|
3
|
-
import { Subscriptions } from './resources/subscriptions';
|
|
4
|
-
import { Webhooks } from './resources/webhooks';
|
|
5
|
-
import { EventopConfig } from './types';
|
|
6
|
-
|
|
7
|
-
export class Eventop {
|
|
8
|
-
public checkout: Checkout;
|
|
9
|
-
public subscriptions: Subscriptions;
|
|
10
|
-
public webhooks: Webhooks;
|
|
11
|
-
|
|
12
|
-
constructor(config: EventopConfig) {
|
|
13
|
-
const client = new EventopClient(config);
|
|
14
|
-
|
|
15
|
-
this.checkout = new Checkout(client);
|
|
16
|
-
this.subscriptions = new Subscriptions(client);
|
|
17
|
-
this.webhooks = new Webhooks(client);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export * from './types';
|
|
22
|
-
export * from './errors';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { EventopClient } from '../client';
|
|
2
|
-
import { CheckoutSessionParams, CheckoutSession } from '../types';
|
|
3
|
-
|
|
4
|
-
export class Checkout {
|
|
5
|
-
constructor(private client: EventopClient) {}
|
|
6
|
-
|
|
7
|
-
async create(params: CheckoutSessionParams): Promise<CheckoutSession> {
|
|
8
|
-
return this.client.request<CheckoutSession>(
|
|
9
|
-
'POST',
|
|
10
|
-
'/checkout/create',
|
|
11
|
-
params,
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async get(sessionId: string): Promise<any> {
|
|
16
|
-
return this.client.request('GET', `/checkout/${sessionId}`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async cancel(sessionId: string): Promise<any> {
|
|
20
|
-
return this.client.request('POST', `/checkout/${sessionId}/cancel`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
File without changes
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { EventopClient } from '../client';
|
|
2
|
-
import { Subscription } from '../types';
|
|
3
|
-
|
|
4
|
-
export class Subscriptions {
|
|
5
|
-
constructor(private client: EventopClient) {}
|
|
6
|
-
|
|
7
|
-
async list(): Promise<Subscription[]> {
|
|
8
|
-
return this.client.request<Subscription[]>('GET', '/subscriptions');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async get(subscriptionId: string): Promise<Subscription> {
|
|
12
|
-
return this.client.request<Subscription>(
|
|
13
|
-
'GET',
|
|
14
|
-
`/subscriptions/${subscriptionId}`,
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async cancel(subscriptionId: string): Promise<any> {
|
|
19
|
-
return this.client.request(
|
|
20
|
-
'POST',
|
|
21
|
-
`/subscriptions/${subscriptionId}/cancel`,
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as crypto from 'crypto';
|
|
2
|
-
import { EventopClient } from '../client';
|
|
3
|
-
import { WebhookPayload } from '../types';
|
|
4
|
-
|
|
5
|
-
export class Webhooks {
|
|
6
|
-
constructor(private client: EventopClient) {}
|
|
7
|
-
|
|
8
|
-
verifySignature(
|
|
9
|
-
payload: WebhookPayload | string,
|
|
10
|
-
signature: string,
|
|
11
|
-
secret: string,
|
|
12
|
-
): boolean {
|
|
13
|
-
const payloadString =
|
|
14
|
-
typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
15
|
-
|
|
16
|
-
const expectedSignature = crypto
|
|
17
|
-
.createHmac('sha256', secret)
|
|
18
|
-
.update(payloadString)
|
|
19
|
-
.digest('hex');
|
|
20
|
-
|
|
21
|
-
return crypto.timingSafeEqual(
|
|
22
|
-
Buffer.from(signature),
|
|
23
|
-
Buffer.from(expectedSignature),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructEvent(
|
|
28
|
-
payload: string | Buffer,
|
|
29
|
-
signature: string,
|
|
30
|
-
secret: string,
|
|
31
|
-
): WebhookPayload {
|
|
32
|
-
const payloadString = Buffer.isBuffer(payload)
|
|
33
|
-
? payload.toString('utf8')
|
|
34
|
-
: payload;
|
|
35
|
-
|
|
36
|
-
if (!this.verifySignature(payloadString, signature, secret)) {
|
|
37
|
-
throw new Error('Invalid webhook signature');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return JSON.parse(payloadString);
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export type Environment = 'devnet' | 'mainnet';
|
|
2
|
-
|
|
3
|
-
export interface EventopConfig {
|
|
4
|
-
apiKey: string;
|
|
5
|
-
environment?: Environment;
|
|
6
|
-
apiUrl?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface CheckoutSessionParams {
|
|
10
|
-
planId: string;
|
|
11
|
-
customerEmail: string;
|
|
12
|
-
customerId?: string;
|
|
13
|
-
successUrl: string;
|
|
14
|
-
cancelUrl?: string;
|
|
15
|
-
metadata?: Record<string, any>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface CheckoutSession {
|
|
19
|
-
sessionId: string;
|
|
20
|
-
url: string;
|
|
21
|
-
expiresAt: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface Subscription {
|
|
25
|
-
subscriptionPda: string;
|
|
26
|
-
userWallet: string;
|
|
27
|
-
merchantWallet: string;
|
|
28
|
-
planId: string;
|
|
29
|
-
feeAmount: string;
|
|
30
|
-
paymentInterval: string;
|
|
31
|
-
isActive: boolean;
|
|
32
|
-
totalPaid: string;
|
|
33
|
-
paymentCount: number;
|
|
34
|
-
createdAt: string;
|
|
35
|
-
cancelledAt?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface Customer {
|
|
39
|
-
email: string;
|
|
40
|
-
customerId?: string;
|
|
41
|
-
walletAddress: string;
|
|
42
|
-
subscriptions: Subscription[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface WebhookPayload {
|
|
46
|
-
event: string;
|
|
47
|
-
timestamp: number;
|
|
48
|
-
data: any;
|
|
49
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2016",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"rootDir": "./src",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true
|
|
11
|
-
},
|
|
12
|
-
"include": [
|
|
13
|
-
"src/**/*.ts"
|
|
14
|
-
],
|
|
15
|
-
"exclude": [
|
|
16
|
-
"node_modules"
|
|
17
|
-
]
|
|
18
|
-
}
|