@rikology/adonisjs-xendit 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/build/index.js ADDED
@@ -0,0 +1,70 @@
1
+ import { l as xendit_exception_exports } from "./xendit_exception-kaFnYOo7.js";
2
+ import { configure } from "./configure.js";
3
+ import { a as InvoiceClient, c as DirectDebitClient, i as QrisClient, l as CreditCardClient, n as VirtualAccountClient, o as EWalletClient, r as RetailOutletClient, s as DisbursementClient, t as XenditManager, u as BalanceClient } from "./xendit_manager-DOa0yE8A.js";
4
+ import { fileURLToPath } from "node:url";
5
+ import { dirname } from "node:path";
6
+ import { configProvider } from "@adonisjs/core";
7
+ import { InvalidArgumentsException } from "@adonisjs/core/exceptions";
8
+ import crypto from "node:crypto";
9
+ //#region stubs/main.ts
10
+ /**
11
+ * Path to the root directory where the stubs are stored.
12
+ * Computed from import.meta.url so it remains correct after bundling.
13
+ */
14
+ const stubsRoot = dirname(fileURLToPath(import.meta.url));
15
+ //#endregion
16
+ //#region src/define_config.ts
17
+ /**
18
+ * Defines the Xendit configuration for your AdonisJS application.
19
+ * This function returns a config provider that resolves the Xendit
20
+ * configuration lazily when the application boots.
21
+ *
22
+ * @param config - The Xendit configuration object
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { defineConfig } from '@rikology/adonisjs-xendit'
27
+ *
28
+ * export default defineConfig({
29
+ * secretKey: env.get('XENDIT_SECRET_KEY'),
30
+ * environment: 'sandbox',
31
+ * callbackToken: env.get('XENDIT_CALLBACK_TOKEN'),
32
+ * })
33
+ * ```
34
+ */
35
+ function defineConfig(config) {
36
+ /**
37
+ * Secret key should always be provided
38
+ */
39
+ if (!config.secretKey) throw new InvalidArgumentsException("Missing \"secretKey\" property in Xendit config");
40
+ /**
41
+ * Environment should be either "sandbox" or "production"
42
+ */
43
+ if (config.environment && !["sandbox", "production"].includes(config.environment)) throw new InvalidArgumentsException(`Invalid "environment" value "${config.environment}". Expected "sandbox" or "production"`);
44
+ return configProvider.create(async (_app) => {
45
+ return {
46
+ secretKey: config.secretKey,
47
+ environment: config.environment ?? "sandbox",
48
+ callbackToken: config.callbackToken,
49
+ timeoutMs: config.timeoutMs ?? 3e4
50
+ };
51
+ });
52
+ }
53
+ //#endregion
54
+ //#region src/webhook.ts
55
+ var XenditWebhook = class {
56
+ static verify(payload, callbackToken, signature) {
57
+ const expected = crypto.createHmac("sha256", callbackToken).update(payload).digest("hex");
58
+ const expectedBuffer = Buffer.from(expected);
59
+ const actualBuffer = Buffer.from(signature);
60
+ if (expectedBuffer.length !== actualBuffer.length) return false;
61
+ return crypto.timingSafeEqual(expectedBuffer, actualBuffer);
62
+ }
63
+ static parseEvent(payload) {
64
+ const parsed = JSON.parse(payload);
65
+ if (typeof parsed !== "object" || parsed === null || typeof parsed.event !== "string" || !("data" in parsed)) throw new TypeError("Invalid Xendit webhook payload");
66
+ return parsed;
67
+ }
68
+ };
69
+ //#endregion
70
+ export { BalanceClient, CreditCardClient, DirectDebitClient, DisbursementClient, EWalletClient, InvoiceClient, QrisClient, RetailOutletClient, VirtualAccountClient, XenditManager, XenditWebhook, configure, defineConfig, xendit_exception_exports as errors, stubsRoot };
@@ -0,0 +1,12 @@
1
+ import { type ApplicationService } from '@adonisjs/core/types';
2
+ import { XenditManager } from '../src/xendit_manager.ts';
3
+ declare module '@adonisjs/core/types' {
4
+ interface ContainerBindings {
5
+ 'xendit.manager': XenditManager;
6
+ }
7
+ }
8
+ export default class XenditProvider {
9
+ protected app: ApplicationService;
10
+ constructor(app: ApplicationService);
11
+ register(): void;
12
+ }
@@ -0,0 +1,19 @@
1
+ import { t as XenditManager } from "../xendit_manager-DOa0yE8A.js";
2
+ import { configProvider } from "@adonisjs/core";
3
+ import { RuntimeException } from "@adonisjs/core/exceptions";
4
+ //#region providers/xendit_provider.ts
5
+ var XenditProvider = class {
6
+ constructor(app) {
7
+ this.app = app;
8
+ }
9
+ register() {
10
+ this.app.container.singleton("xendit.manager", async () => {
11
+ const xenditConfigProvider = this.app.config.get("xendit", {});
12
+ const config = await configProvider.resolve(this.app, xenditConfigProvider);
13
+ if (!config || !config.secretKey) throw new RuntimeException("Invalid \"config/xendit.ts\" file. Make sure you are using the \"defineConfig\" method");
14
+ return new XenditManager(config);
15
+ });
16
+ }
17
+ };
18
+ //#endregion
19
+ export { XenditProvider as default };
@@ -0,0 +1,8 @@
1
+ import type { XenditHttpClient } from '../http_client.ts';
2
+ import type { Balance, BalanceAccountType } from '../types.ts';
3
+ export declare class BalanceClient {
4
+ #private;
5
+ constructor(http: XenditHttpClient);
6
+ get(): Promise<Balance>;
7
+ getByAccountType(accountType: BalanceAccountType): Promise<Balance>;
8
+ }
@@ -0,0 +1,10 @@
1
+ import type { XenditHttpClient } from '../http_client.ts';
2
+ import type { CreateCreditCardAuthRequest, CreditCardAuth, CreateCreditCardChargeRequest, CreditCardCharge, CreateCreditCardRefundRequest, CreditCardRefund } from '../types.ts';
3
+ export declare class CreditCardClient {
4
+ #private;
5
+ constructor(http: XenditHttpClient);
6
+ createAuthorization(data: CreateCreditCardAuthRequest): Promise<CreditCardAuth>;
7
+ createCharge(data: CreateCreditCardChargeRequest): Promise<CreditCardCharge>;
8
+ createRefund(chargeId: string, data: CreateCreditCardRefundRequest): Promise<CreditCardRefund>;
9
+ getCharge(chargeId: string): Promise<CreditCardCharge>;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { XenditHttpClient } from '../http_client.ts';
2
+ import type { CreateDirectDebitPaymentMethodRequest, ValidateDirectDebitOTPRequest, DirectDebitPaymentMethod, CreateDirectDebitPaymentRequest, DirectDebitPayment } from '../types.ts';
3
+ export declare class DirectDebitClient {
4
+ #private;
5
+ constructor(http: XenditHttpClient);
6
+ createPaymentMethod(data: CreateDirectDebitPaymentMethodRequest): Promise<DirectDebitPaymentMethod>;
7
+ validateOTP(paymentMethodId: string, data: ValidateDirectDebitOTPRequest): Promise<DirectDebitPaymentMethod>;
8
+ createPayment(data: CreateDirectDebitPaymentRequest): Promise<DirectDebitPayment>;
9
+ getPayment(paymentId: string): Promise<DirectDebitPayment>;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { XenditHttpClient, XenditRequestOptions } from '../http_client.ts';
2
+ import type { BatchDisbursement, CreateBatchDisbursementRequest, CreateDisbursementRequest, Disbursement, DisbursementBank } from '../types.ts';
3
+ export declare class DisbursementClient {
4
+ #private;
5
+ constructor(http: XenditHttpClient);
6
+ create(data: CreateDisbursementRequest, options?: Pick<XenditRequestOptions, 'idempotencyKey'>): Promise<Disbursement>;
7
+ getById(disbursementId: string): Promise<Disbursement>;
8
+ createBatch(data: CreateBatchDisbursementRequest, options?: Pick<XenditRequestOptions, 'idempotencyKey'>): Promise<BatchDisbursement>;
9
+ getAvailableBanks(): Promise<DisbursementBank[]>;
10
+ }
@@ -0,0 +1,11 @@
1
+ import type { XenditHttpClient } from '../http_client.ts';
2
+ import type { CreateEWalletChargeRequest, EWalletCharge } from '../types.ts';
3
+ export declare class EWalletClient {
4
+ #private;
5
+ constructor(http: XenditHttpClient);
6
+ createOvo(data: CreateEWalletChargeRequest): Promise<EWalletCharge>;
7
+ createDana(data: CreateEWalletChargeRequest): Promise<EWalletCharge>;
8
+ createLinkAja(data: CreateEWalletChargeRequest): Promise<EWalletCharge>;
9
+ createShopeepay(data: CreateEWalletChargeRequest): Promise<EWalletCharge>;
10
+ getStatus(chargeId: string): Promise<EWalletCharge>;
11
+ }
@@ -0,0 +1,12 @@
1
+ import type { XenditHttpClient } from '../http_client.ts';
2
+ import type { CreateInvoiceRequest, Invoice, ListInvoicesParams } from '../types.ts';
3
+ export declare class InvoiceClient {
4
+ #private;
5
+ constructor(http: XenditHttpClient);
6
+ create(data: CreateInvoiceRequest, options?: {
7
+ idempotencyKey?: string;
8
+ }): Promise<Invoice>;
9
+ getById(invoiceId: string): Promise<Invoice>;
10
+ list(params?: ListInvoicesParams): Promise<Invoice[]>;
11
+ expire(invoiceId: string): Promise<Invoice>;
12
+ }
@@ -0,0 +1,9 @@
1
+ import type { XenditHttpClient } from '../http_client.ts';
2
+ import type { CreateQRCodeRequest, QRCode, QRCodePayment, SimulateQRCodeRequest } from '../types.ts';
3
+ export declare class QrisClient {
4
+ #private;
5
+ constructor(http: XenditHttpClient);
6
+ create(data: CreateQRCodeRequest): Promise<QRCode>;
7
+ getById(qrId: string): Promise<QRCode>;
8
+ simulate(qrId: string, data: SimulateQRCodeRequest): Promise<QRCodePayment>;
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { XenditHttpClient } from '../http_client.ts';
2
+ import type { CreateRetailOutletRequest, RetailOutlet, UpdateRetailOutletRequest } from '../types.ts';
3
+ export declare class RetailOutletClient {
4
+ private readonly http;
5
+ constructor(http: XenditHttpClient);
6
+ create(data: CreateRetailOutletRequest): Promise<RetailOutlet>;
7
+ getById(paymentId: string): Promise<RetailOutlet>;
8
+ update(paymentId: string, data: UpdateRetailOutletRequest): Promise<RetailOutlet>;
9
+ }
@@ -0,0 +1,10 @@
1
+ import type { XenditHttpClient } from '../http_client.ts';
2
+ import type { CreateVirtualAccountRequest, UpdateVirtualAccountRequest, VirtualAccount, VAPayment } from '../types.ts';
3
+ export declare class VirtualAccountClient {
4
+ #private;
5
+ constructor(http: XenditHttpClient);
6
+ create(data: CreateVirtualAccountRequest): Promise<VirtualAccount>;
7
+ getById(vaId: string): Promise<VirtualAccount>;
8
+ update(vaId: string, data: UpdateVirtualAccountRequest): Promise<VirtualAccount>;
9
+ getPayment(vaId: string): Promise<VAPayment>;
10
+ }
@@ -0,0 +1,21 @@
1
+ import type { ConfigProvider } from '@adonisjs/core/types';
2
+ import type { XenditConfig } from './types.ts';
3
+ /**
4
+ * Defines the Xendit configuration for your AdonisJS application.
5
+ * This function returns a config provider that resolves the Xendit
6
+ * configuration lazily when the application boots.
7
+ *
8
+ * @param config - The Xendit configuration object
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { defineConfig } from '@rikology/adonisjs-xendit'
13
+ *
14
+ * export default defineConfig({
15
+ * secretKey: env.get('XENDIT_SECRET_KEY'),
16
+ * environment: 'sandbox',
17
+ * callbackToken: env.get('XENDIT_CALLBACK_TOKEN'),
18
+ * })
19
+ * ```
20
+ */
21
+ export declare function defineConfig(config: XenditConfig): ConfigProvider<XenditConfig>;
@@ -0,0 +1,15 @@
1
+ export interface XenditHttpClientOptions {
2
+ baseUrl: string;
3
+ secretKey: string;
4
+ timeoutMs?: number;
5
+ }
6
+ export interface XenditRequestOptions {
7
+ body?: Record<string, unknown>;
8
+ idempotencyKey?: string;
9
+ headers?: Record<string, string>;
10
+ }
11
+ export declare class XenditHttpClient {
12
+ #private;
13
+ constructor(options: XenditHttpClientOptions);
14
+ request<T>(method: string, path: string, options?: XenditRequestOptions): Promise<T>;
15
+ }