@eventop/sdk 1.0.0 → 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/{src → dist/cjs}/index.js +8 -9
- 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/client.js +63 -0
- package/dist/errors.js +33 -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/index.js +32 -0
- package/dist/resources/checkout.js +33 -0
- package/dist/resources/customers.js +1 -0
- package/dist/resources/subscriptions.js +33 -0
- package/dist/resources/webhooks.js +60 -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/dist/types.js +2 -0
- package/package.json +44 -35
- package/src/client.js +0 -98
- package/src/client.ts +0 -64
- package/src/errors.js +0 -61
- package/src/errors.ts +0 -31
- package/src/index.ts +0 -22
- package/src/resources/checkout.js +0 -67
- package/src/resources/checkout.ts +0 -22
- package/src/resources/customers.js +0 -0
- package/src/resources/customers.ts +0 -0
- package/src/resources/subscriptions.js +0 -67
- package/src/resources/subscriptions.ts +0 -24
- package/src/resources/webhooks.js +0 -28
- package/src/resources/webhooks.ts +0 -42
- package/src/types.ts +0 -49
- package/tsconfig.json +0 -0
- /package/{src → dist/cjs}/types.js +0 -0
|
@@ -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;
|
|
@@ -15,19 +15,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Eventop = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
25
|
this.checkout = new checkout_1.Checkout(client);
|
|
26
26
|
this.subscriptions = new subscriptions_1.Subscriptions(client);
|
|
27
27
|
this.webhooks = new webhooks_1.Webhooks(client);
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
}());
|
|
29
|
+
}
|
|
31
30
|
exports.Eventop = Eventop;
|
|
32
31
|
__exportStar(require("./types"), exports);
|
|
33
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;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.EventopClient = void 0;
|
|
16
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
17
|
+
const errors_1 = require("./errors");
|
|
18
|
+
class EventopClient {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.apiKey = config.apiKey;
|
|
21
|
+
// Set base URL based on environment
|
|
22
|
+
if (config.apiUrl) {
|
|
23
|
+
this.baseUrl = config.apiUrl;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const env = config.environment || this.detectEnvironment();
|
|
27
|
+
this.baseUrl =
|
|
28
|
+
env === 'devnet'
|
|
29
|
+
? 'https://eventop-server-app-production.up.railway.app'
|
|
30
|
+
: 'https://api.eventop.xyz';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
detectEnvironment() {
|
|
34
|
+
// Detect from API key prefix
|
|
35
|
+
if (this.apiKey.startsWith('sk_test_')) {
|
|
36
|
+
return 'devnet';
|
|
37
|
+
}
|
|
38
|
+
else if (this.apiKey.startsWith('sk_live_')) {
|
|
39
|
+
return 'mainnet';
|
|
40
|
+
}
|
|
41
|
+
throw new errors_1.AuthenticationError('Invalid API key format');
|
|
42
|
+
}
|
|
43
|
+
request(method, path, body) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const url = `${this.baseUrl}${path}`;
|
|
46
|
+
const headers = {
|
|
47
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
48
|
+
'Content-Type': 'application/json',
|
|
49
|
+
};
|
|
50
|
+
const response = yield (0, node_fetch_1.default)(url, {
|
|
51
|
+
method,
|
|
52
|
+
headers,
|
|
53
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
54
|
+
});
|
|
55
|
+
const data = yield response.json();
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
throw new errors_1.EventopError(data.message || 'Request failed', response.status, data.code);
|
|
58
|
+
}
|
|
59
|
+
return data;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.EventopClient = EventopClient;
|
package/dist/errors.js
ADDED
|
@@ -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,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 {};
|
package/dist/index.js
ADDED
|
@@ -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,33 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Checkout = void 0;
|
|
13
|
+
class Checkout {
|
|
14
|
+
constructor(client) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
}
|
|
17
|
+
create(params) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return this.client.request('POST', '/checkout/create', params);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
get(sessionId) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return this.client.request('GET', `/checkout/${sessionId}`);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
cancel(sessionId) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return this.client.request('POST', `/checkout/${sessionId}/cancel`);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Checkout = Checkout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Subscriptions = void 0;
|
|
13
|
+
class Subscriptions {
|
|
14
|
+
constructor(client) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
}
|
|
17
|
+
list() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return this.client.request('GET', '/subscriptions');
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
get(subscriptionId) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return this.client.request('GET', `/subscriptions/${subscriptionId}`);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
cancel(subscriptionId) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
return this.client.request('POST', `/subscriptions/${subscriptionId}/cancel`);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
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,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"}
|