@eventop/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 +44 -0
- package/package.json +36 -0
- package/src/client.js +98 -0
- package/src/client.ts +64 -0
- package/src/errors.js +61 -0
- package/src/errors.ts +31 -0
- package/src/index.js +33 -0
- package/src/index.ts +22 -0
- package/src/resources/checkout.js +67 -0
- package/src/resources/checkout.ts +22 -0
- package/src/resources/customers.js +0 -0
- package/src/resources/customers.ts +0 -0
- package/src/resources/subscriptions.js +67 -0
- package/src/resources/subscriptions.ts +24 -0
- package/src/resources/webhooks.js +28 -0
- package/src/resources/webhooks.ts +42 -0
- package/src/types.js +2 -0
- package/src/types.ts +49 -0
- package/tsconfig.json +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Sdk for event api
|
|
2
|
+
```javascript
|
|
3
|
+
import { Eventop } from '@eventop/sdk';
|
|
4
|
+
|
|
5
|
+
// Initialize client
|
|
6
|
+
const eventop = new Eventop({
|
|
7
|
+
apiKey: process.env.EVENTOP_API_KEY!, // sk_test_... or sk_live_...
|
|
8
|
+
// environment auto-detected from key prefix
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Create checkout session
|
|
12
|
+
const session = await eventop.checkout.create({
|
|
13
|
+
planId: 'premium-monthly',
|
|
14
|
+
customerEmail: 'user@example.com',
|
|
15
|
+
customerId: 'user_123',
|
|
16
|
+
successUrl: 'https://yourdomain.com/success',
|
|
17
|
+
cancelUrl: 'https://yourdomain.com/pricing',
|
|
18
|
+
metadata: {
|
|
19
|
+
userId: '123',
|
|
20
|
+
source: 'web',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
console.log('Checkout URL:', session.url);
|
|
25
|
+
|
|
26
|
+
// Verify webhook
|
|
27
|
+
app.post('/webhooks/eventop', express.raw({ type: 'application/json' }), (req, res) => {
|
|
28
|
+
const signature = req.headers['x-webhook-signature'] as string;
|
|
29
|
+
const payload = req.body.toString();
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const event = eventop.webhooks.constructEvent(
|
|
33
|
+
payload,
|
|
34
|
+
signature,
|
|
35
|
+
process.env.WEBHOOK_SECRET!,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
console.log('Received event:', event.event);
|
|
39
|
+
res.json({ received: true });
|
|
40
|
+
} catch (err) {
|
|
41
|
+
res.status(400).send('Webhook signature verification failed');
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eventop/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official SDK for Eventop on-chain subscriptions",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"solana",
|
|
7
|
+
"subscriptions",
|
|
8
|
+
"crypto",
|
|
9
|
+
"payments"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/eventop-s/sdk#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/eventop-s/sdk/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/eventop-s/sdk.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Eventop",
|
|
21
|
+
"type": "commonjs",
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"node-fetch": "^2.6.7"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^18.0.0",
|
|
33
|
+
"@types/node-fetch": "^2.6.2",
|
|
34
|
+
"typescript": "^5.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.EventopClient = void 0;
|
|
40
|
+
var node_fetch_1 = require("node-fetch");
|
|
41
|
+
var errors_1 = require("./errors");
|
|
42
|
+
var EventopClient = /** @class */ (function () {
|
|
43
|
+
function EventopClient(config) {
|
|
44
|
+
this.apiKey = config.apiKey;
|
|
45
|
+
// Set base URL based on environment
|
|
46
|
+
if (config.apiUrl) {
|
|
47
|
+
this.baseUrl = config.apiUrl;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
var env = config.environment || this.detectEnvironment();
|
|
51
|
+
this.baseUrl =
|
|
52
|
+
env === 'devnet'
|
|
53
|
+
? 'https://api-devnet.eventop.xyz'
|
|
54
|
+
: 'https://api.eventop.xyz';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
EventopClient.prototype.detectEnvironment = function () {
|
|
58
|
+
// Detect from API key prefix
|
|
59
|
+
if (this.apiKey.startsWith('sk_test_')) {
|
|
60
|
+
return 'devnet';
|
|
61
|
+
}
|
|
62
|
+
else if (this.apiKey.startsWith('sk_live_')) {
|
|
63
|
+
return 'mainnet';
|
|
64
|
+
}
|
|
65
|
+
throw new errors_1.AuthenticationError('Invalid API key format');
|
|
66
|
+
};
|
|
67
|
+
EventopClient.prototype.request = function (method, path, body) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
69
|
+
var url, headers, response, data;
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
url = "".concat(this.baseUrl).concat(path);
|
|
74
|
+
headers = {
|
|
75
|
+
'Authorization': "Bearer ".concat(this.apiKey),
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
};
|
|
78
|
+
return [4 /*yield*/, (0, node_fetch_1.default)(url, {
|
|
79
|
+
method: method,
|
|
80
|
+
headers: headers,
|
|
81
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
82
|
+
})];
|
|
83
|
+
case 1:
|
|
84
|
+
response = _a.sent();
|
|
85
|
+
return [4 /*yield*/, response.json()];
|
|
86
|
+
case 2:
|
|
87
|
+
data = _a.sent();
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
throw new errors_1.EventopError(data.message || 'Request failed', response.status, data.code);
|
|
90
|
+
}
|
|
91
|
+
return [2 /*return*/, data];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return EventopClient;
|
|
97
|
+
}());
|
|
98
|
+
exports.EventopClient = EventopClient;
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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://api-devnet.eventop.xyz'
|
|
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.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.NotFoundError = exports.InvalidRequestError = exports.AuthenticationError = exports.EventopError = void 0;
|
|
19
|
+
var EventopError = /** @class */ (function (_super) {
|
|
20
|
+
__extends(EventopError, _super);
|
|
21
|
+
function EventopError(message, statusCode, code) {
|
|
22
|
+
var _this = _super.call(this, message) || this;
|
|
23
|
+
_this.statusCode = statusCode;
|
|
24
|
+
_this.code = code;
|
|
25
|
+
_this.name = 'EventopError';
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
return EventopError;
|
|
29
|
+
}(Error));
|
|
30
|
+
exports.EventopError = EventopError;
|
|
31
|
+
var AuthenticationError = /** @class */ (function (_super) {
|
|
32
|
+
__extends(AuthenticationError, _super);
|
|
33
|
+
function AuthenticationError(message) {
|
|
34
|
+
if (message === void 0) { message = 'Invalid API key'; }
|
|
35
|
+
var _this = _super.call(this, message, 401, 'authentication_error') || this;
|
|
36
|
+
_this.name = 'AuthenticationError';
|
|
37
|
+
return _this;
|
|
38
|
+
}
|
|
39
|
+
return AuthenticationError;
|
|
40
|
+
}(EventopError));
|
|
41
|
+
exports.AuthenticationError = AuthenticationError;
|
|
42
|
+
var InvalidRequestError = /** @class */ (function (_super) {
|
|
43
|
+
__extends(InvalidRequestError, _super);
|
|
44
|
+
function InvalidRequestError(message) {
|
|
45
|
+
var _this = _super.call(this, message, 400, 'invalid_request') || this;
|
|
46
|
+
_this.name = 'InvalidRequestError';
|
|
47
|
+
return _this;
|
|
48
|
+
}
|
|
49
|
+
return InvalidRequestError;
|
|
50
|
+
}(EventopError));
|
|
51
|
+
exports.InvalidRequestError = InvalidRequestError;
|
|
52
|
+
var NotFoundError = /** @class */ (function (_super) {
|
|
53
|
+
__extends(NotFoundError, _super);
|
|
54
|
+
function NotFoundError(message) {
|
|
55
|
+
var _this = _super.call(this, message, 404, 'not_found') || this;
|
|
56
|
+
_this.name = 'NotFoundError';
|
|
57
|
+
return _this;
|
|
58
|
+
}
|
|
59
|
+
return NotFoundError;
|
|
60
|
+
}(EventopError));
|
|
61
|
+
exports.NotFoundError = NotFoundError;
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
var client_1 = require("./client");
|
|
19
|
+
var checkout_1 = require("./resources/checkout");
|
|
20
|
+
var subscriptions_1 = require("./resources/subscriptions");
|
|
21
|
+
var webhooks_1 = require("./resources/webhooks");
|
|
22
|
+
var Eventop = /** @class */ (function () {
|
|
23
|
+
function Eventop(config) {
|
|
24
|
+
var 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
|
+
return Eventop;
|
|
30
|
+
}());
|
|
31
|
+
exports.Eventop = Eventop;
|
|
32
|
+
__exportStar(require("./types"), exports);
|
|
33
|
+
__exportStar(require("./errors"), exports);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Checkout = void 0;
|
|
40
|
+
var Checkout = /** @class */ (function () {
|
|
41
|
+
function Checkout(client) {
|
|
42
|
+
this.client = client;
|
|
43
|
+
}
|
|
44
|
+
Checkout.prototype.create = function (params) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
return [2 /*return*/, this.client.request('POST', '/checkout/create', params)];
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
Checkout.prototype.get = function (sessionId) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
return [2 /*return*/, this.client.request('GET', "/checkout/".concat(sessionId))];
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
Checkout.prototype.cancel = function (sessionId) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
return [2 /*return*/, this.client.request('POST', "/checkout/".concat(sessionId, "/cancel"))];
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return Checkout;
|
|
66
|
+
}());
|
|
67
|
+
exports.Checkout = Checkout;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
File without changes
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Subscriptions = void 0;
|
|
40
|
+
var Subscriptions = /** @class */ (function () {
|
|
41
|
+
function Subscriptions(client) {
|
|
42
|
+
this.client = client;
|
|
43
|
+
}
|
|
44
|
+
Subscriptions.prototype.list = function () {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
return [2 /*return*/, this.client.request('GET', '/subscriptions')];
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
Subscriptions.prototype.get = function (subscriptionId) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
return [2 /*return*/, this.client.request('GET', "/subscriptions/".concat(subscriptionId))];
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
Subscriptions.prototype.cancel = function (subscriptionId) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
return [2 /*return*/, this.client.request('POST', "/subscriptions/".concat(subscriptionId, "/cancel"))];
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return Subscriptions;
|
|
66
|
+
}());
|
|
67
|
+
exports.Subscriptions = Subscriptions;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Webhooks = void 0;
|
|
4
|
+
var crypto = require("crypto");
|
|
5
|
+
var Webhooks = /** @class */ (function () {
|
|
6
|
+
function Webhooks(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
Webhooks.prototype.verifySignature = function (payload, signature, secret) {
|
|
10
|
+
var payloadString = typeof payload === 'string' ? payload : JSON.stringify(payload);
|
|
11
|
+
var expectedSignature = crypto
|
|
12
|
+
.createHmac('sha256', secret)
|
|
13
|
+
.update(payloadString)
|
|
14
|
+
.digest('hex');
|
|
15
|
+
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
|
|
16
|
+
};
|
|
17
|
+
Webhooks.prototype.constructEvent = function (payload, signature, secret) {
|
|
18
|
+
var payloadString = Buffer.isBuffer(payload)
|
|
19
|
+
? payload.toString('utf8')
|
|
20
|
+
: payload;
|
|
21
|
+
if (!this.verifySignature(payloadString, signature, secret)) {
|
|
22
|
+
throw new Error('Invalid webhook signature');
|
|
23
|
+
}
|
|
24
|
+
return JSON.parse(payloadString);
|
|
25
|
+
};
|
|
26
|
+
return Webhooks;
|
|
27
|
+
}());
|
|
28
|
+
exports.Webhooks = Webhooks;
|
|
@@ -0,0 +1,42 @@
|
|
|
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.js
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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
ADDED
|
File without changes
|