@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
|
@@ -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,28 +0,0 @@
|
|
|
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;
|
|
@@ -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
|
File without changes
|
|
File without changes
|