@inkress/admin-sdk 1.1.41 → 1.1.43
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +168 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +168 -6
- package/dist/index.js.map +1 -1
- package/dist/resources/public.d.ts +1 -1
- package/dist/resources/public.d.ts.map +1 -1
- package/dist/resources/webhook-urls.d.ts +85 -1
- package/dist/resources/webhook-urls.d.ts.map +1 -1
- package/dist/types/resources.d.ts +15 -17
- package/dist/types/resources.d.ts.map +1 -1
- package/dist/types.d.ts +25 -22
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ export declare class InkressSDK {
|
|
|
98
98
|
}
|
|
99
99
|
export * from './types';
|
|
100
100
|
export * from './client';
|
|
101
|
+
export type { WebhookPayload, WebhookVerificationOptions, IncomingWebhookRequest, } from './resources/webhook-urls';
|
|
101
102
|
export { InkressSDK as default };
|
|
102
103
|
export type { OrderQueryParams, ProductQueryParams, UserQueryParams, MerchantQueryParams, CategoryQueryParams, BillingPlanQueryParams, SubscriptionQueryParams, PaymentLinkQueryParams, FinancialAccountQueryParams, FinancialRequestQueryParams, WebhookUrlQueryParams, TokenQueryParams, AddressQueryParams, CurrencyQueryParams, ExchangeRateQueryParams, FeeQueryParams, PaymentMethodQueryParams, TransactionEntryQueryParams, OrderFilterParams, ProductFilterParams, UserFilterParams, MerchantFilterParams, CategoryFilterParams, BillingPlanFilterParams, SubscriptionFilterParams, PaymentLinkFilterParams, FinancialAccountFilterParams, FinancialRequestFilterParams, WebhookUrlFilterParams, TokenFilterParams, AddressFilterParams, CurrencyFilterParams, ExchangeRateFilterParams, FeeFilterParams, PaymentMethodFilterParams, TransactionEntryFilterParams, OrderListResponse, ProductListResponse, UserListResponse, MerchantListResponse, CategoryListResponse, BillingPlanListResponse, SubscriptionListResponse, PaymentLinkListResponse, FinancialAccountListResponse, FinancialRequestListResponse, WebhookUrlListResponse, TokenListResponse, AddressListResponse, CurrencyListResponse, ExchangeRateListResponse, FeeListResponse, PaymentMethodListResponse, TransactionEntryListResponse, PageInfo, } from './types/resources';
|
|
103
104
|
export { ORDER_FIELD_TYPES, PRODUCT_FIELD_TYPES, USER_FIELD_TYPES, MERCHANT_FIELD_TYPES, CATEGORY_FIELD_TYPES, BILLING_PLAN_FIELD_TYPES, SUBSCRIPTION_FIELD_TYPES, PAYMENT_LINK_FIELD_TYPES, FINANCIAL_ACCOUNT_FIELD_TYPES, FINANCIAL_REQUEST_FIELD_TYPES, WEBHOOK_URL_FIELD_TYPES, TOKEN_FIELD_TYPES, ADDRESS_FIELD_TYPES, CURRENCY_FIELD_TYPES, EXCHANGE_RATE_FIELD_TYPES, FEE_FIELD_TYPES, PAYMENT_METHOD_FIELD_TYPES, TRANSACTION_ENTRY_FIELD_TYPES, } from './types/resources';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAA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,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,4BAA4B,EAC5B,4BAA4B,EAC5B,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAG5B,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC7B,6BAA6B,EAC7B,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,EACzB,eAAe,EACf,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,4BAA4B,EAC5B,4BAA4B,EAC5B,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAC5B,KAAK,SAAS,GACf,MAAM,wBAAwB,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1913,7 +1913,7 @@ const ORDER_FIELD_TYPES = {
|
|
|
1913
1913
|
status_on: 'number',
|
|
1914
1914
|
uid: 'string',
|
|
1915
1915
|
cart_id: 'number',
|
|
1916
|
-
|
|
1916
|
+
currency_code: 'string',
|
|
1917
1917
|
customer_id: 'number',
|
|
1918
1918
|
payment_link_id: 'number',
|
|
1919
1919
|
billing_plan_id: 'number',
|
|
@@ -1941,7 +1941,7 @@ const PRODUCT_FIELD_TYPES = {
|
|
|
1941
1941
|
tag_ids: 'array',
|
|
1942
1942
|
uid: 'string',
|
|
1943
1943
|
category_id: 'number',
|
|
1944
|
-
|
|
1944
|
+
currency_code: 'string',
|
|
1945
1945
|
user_id: 'number',
|
|
1946
1946
|
inserted_at: 'date',
|
|
1947
1947
|
updated_at: 'date',
|
|
@@ -2033,7 +2033,7 @@ const BILLING_PLAN_FIELD_TYPES = {
|
|
|
2033
2033
|
payout_value_limit: 'number',
|
|
2034
2034
|
payout_percentage_limit: 'number',
|
|
2035
2035
|
uid: 'string',
|
|
2036
|
-
|
|
2036
|
+
currency_code: 'string',
|
|
2037
2037
|
payment_provider_id: 'number',
|
|
2038
2038
|
inserted_at: 'date',
|
|
2039
2039
|
updated_at: 'date',
|
|
@@ -2074,7 +2074,7 @@ const PAYMENT_LINK_FIELD_TYPES = {
|
|
|
2074
2074
|
status: 'number',
|
|
2075
2075
|
kind: 'number',
|
|
2076
2076
|
customer_id: 'number',
|
|
2077
|
-
|
|
2077
|
+
currency_code: 'string',
|
|
2078
2078
|
order_id: 'number',
|
|
2079
2079
|
inserted_at: 'date',
|
|
2080
2080
|
updated_at: 'date',
|
|
@@ -2118,7 +2118,7 @@ const FINANCIAL_REQUEST_FIELD_TYPES = {
|
|
|
2118
2118
|
merchant_id: 'number',
|
|
2119
2119
|
requester_id: 'number',
|
|
2120
2120
|
reviewer_id: 'number',
|
|
2121
|
-
|
|
2121
|
+
currency_code: 'string',
|
|
2122
2122
|
evidence_file_id: 'number',
|
|
2123
2123
|
inserted_at: 'date',
|
|
2124
2124
|
updated_at: 'date',
|
|
@@ -2212,7 +2212,6 @@ const FEE_FIELD_TYPES = {
|
|
|
2212
2212
|
currency_code: 'string',
|
|
2213
2213
|
hash: 'string',
|
|
2214
2214
|
fee_set_id: 'number',
|
|
2215
|
-
currency_id: 'number',
|
|
2216
2215
|
user_id: 'number',
|
|
2217
2216
|
inserted_at: 'date',
|
|
2218
2217
|
updated_at: 'date',
|
|
@@ -3838,6 +3837,15 @@ class FinancialRequestsResource {
|
|
|
3838
3837
|
}
|
|
3839
3838
|
}
|
|
3840
3839
|
|
|
3840
|
+
let crypto;
|
|
3841
|
+
try {
|
|
3842
|
+
if (typeof require !== 'undefined') {
|
|
3843
|
+
crypto = require('crypto');
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
catch (_a) {
|
|
3847
|
+
// Fallback for environments without Node.js crypto
|
|
3848
|
+
}
|
|
3841
3849
|
class WebhookUrlsResource {
|
|
3842
3850
|
constructor(client) {
|
|
3843
3851
|
this.client = client;
|
|
@@ -3897,6 +3905,160 @@ class WebhookUrlsResource {
|
|
|
3897
3905
|
createQueryBuilder() {
|
|
3898
3906
|
return new WebhookUrlQueryBuilder(this);
|
|
3899
3907
|
}
|
|
3908
|
+
// ============================================================================
|
|
3909
|
+
// WEBHOOK VERIFICATION METHODS
|
|
3910
|
+
// ============================================================================
|
|
3911
|
+
/**
|
|
3912
|
+
* Verify webhook signature using HMAC SHA256
|
|
3913
|
+
* Inkress webhooks use the format: crypto.mac(:hmac, :sha256, secret, body) |> Base.encode64()
|
|
3914
|
+
*/
|
|
3915
|
+
verifySignature(body, signature, secret) {
|
|
3916
|
+
if (!crypto) {
|
|
3917
|
+
throw new Error('Node.js crypto module not available. Cannot verify webhook signature.');
|
|
3918
|
+
}
|
|
3919
|
+
try {
|
|
3920
|
+
// Generate expected signature using HMAC SHA256
|
|
3921
|
+
const expectedSignature = crypto
|
|
3922
|
+
.createHmac('sha256', secret)
|
|
3923
|
+
.update(body, 'utf8')
|
|
3924
|
+
.digest('base64');
|
|
3925
|
+
// Use constant-time comparison to prevent timing attacks
|
|
3926
|
+
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expectedSignature));
|
|
3927
|
+
}
|
|
3928
|
+
catch (error) {
|
|
3929
|
+
return false;
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3932
|
+
/**
|
|
3933
|
+
* Parse webhook payload from a string
|
|
3934
|
+
*/
|
|
3935
|
+
parsePayload(payload) {
|
|
3936
|
+
try {
|
|
3937
|
+
const parsed = JSON.parse(payload);
|
|
3938
|
+
if (!parsed.id || !parsed.timestamp || !parsed.event) {
|
|
3939
|
+
throw new Error('Invalid webhook payload structure: missing required fields (id, timestamp, or event)');
|
|
3940
|
+
}
|
|
3941
|
+
return parsed;
|
|
3942
|
+
}
|
|
3943
|
+
catch (error) {
|
|
3944
|
+
if (error instanceof Error) {
|
|
3945
|
+
throw new Error(`Failed to parse webhook payload: ${error.message}`);
|
|
3946
|
+
}
|
|
3947
|
+
throw new Error('Failed to parse webhook payload');
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3950
|
+
/**
|
|
3951
|
+
* Verify and parse an incoming webhook request
|
|
3952
|
+
* This method clones the request body, validates the signature, and returns the parsed payload
|
|
3953
|
+
*
|
|
3954
|
+
* @param request - The incoming HTTP request object with headers and body
|
|
3955
|
+
* @param secret - Your webhook secret for signature verification
|
|
3956
|
+
* @param options - Optional verification options (e.g., timestamp tolerance)
|
|
3957
|
+
* @returns Promise that resolves to the parsed webhook payload
|
|
3958
|
+
* @throws Error if signature verification fails or payload is invalid
|
|
3959
|
+
*
|
|
3960
|
+
* @example
|
|
3961
|
+
* ```typescript
|
|
3962
|
+
* // Express.js example
|
|
3963
|
+
* app.post('/webhooks', async (req, res) => {
|
|
3964
|
+
* try {
|
|
3965
|
+
* const payload = await sdk.webhookUrls.verifyRequest(
|
|
3966
|
+
* { headers: req.headers, body: req.body },
|
|
3967
|
+
* 'your-webhook-secret'
|
|
3968
|
+
* );
|
|
3969
|
+
*
|
|
3970
|
+
* // Process the webhook
|
|
3971
|
+
* console.log('Received webhook:', payload.event.type);
|
|
3972
|
+
*
|
|
3973
|
+
* res.status(200).json({ received: true });
|
|
3974
|
+
* } catch (error) {
|
|
3975
|
+
* console.error('Webhook verification failed:', error);
|
|
3976
|
+
* res.status(400).json({ error: error.message });
|
|
3977
|
+
* }
|
|
3978
|
+
* });
|
|
3979
|
+
* ```
|
|
3980
|
+
*/
|
|
3981
|
+
async verifyRequest(request, secret, options) {
|
|
3982
|
+
// Extract signature from headers (case-insensitive)
|
|
3983
|
+
const signature = request.headers['x-inkress-webhook-signature'] ||
|
|
3984
|
+
request.headers['X-Inkress-Webhook-Signature'];
|
|
3985
|
+
if (!signature || typeof signature !== 'string') {
|
|
3986
|
+
throw new Error('Missing X-Inkress-Webhook-Signature header');
|
|
3987
|
+
}
|
|
3988
|
+
// Clone and ensure body is a string
|
|
3989
|
+
let body;
|
|
3990
|
+
if (typeof request.body === 'string') {
|
|
3991
|
+
body = request.body;
|
|
3992
|
+
}
|
|
3993
|
+
else if (request.body && typeof request.body === 'object') {
|
|
3994
|
+
body = JSON.stringify(request.body);
|
|
3995
|
+
}
|
|
3996
|
+
else {
|
|
3997
|
+
throw new Error('Invalid request body format: body must be a string or object');
|
|
3998
|
+
}
|
|
3999
|
+
// Verify signature
|
|
4000
|
+
const isValid = this.verifySignature(body, signature, secret);
|
|
4001
|
+
if (!isValid) {
|
|
4002
|
+
throw new Error('Webhook signature verification failed: signature does not match');
|
|
4003
|
+
}
|
|
4004
|
+
// Parse the payload
|
|
4005
|
+
const payload = this.parsePayload(body);
|
|
4006
|
+
// Optional: Verify timestamp tolerance
|
|
4007
|
+
if (options === null || options === void 0 ? void 0 : options.tolerance) {
|
|
4008
|
+
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
4009
|
+
const timeDifference = Math.abs(currentTimestamp - payload.timestamp);
|
|
4010
|
+
if (timeDifference > options.tolerance) {
|
|
4011
|
+
throw new Error(`Webhook timestamp outside tolerance window: ${timeDifference}s (max: ${options.tolerance}s)`);
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
return payload;
|
|
4015
|
+
}
|
|
4016
|
+
/**
|
|
4017
|
+
* Verify webhook signature only (without parsing)
|
|
4018
|
+
* Useful for custom verification flows
|
|
4019
|
+
*
|
|
4020
|
+
* @param body - The raw webhook request body as a string
|
|
4021
|
+
* @param signature - The signature from X-Inkress-Webhook-Signature header
|
|
4022
|
+
* @param secret - Your webhook secret
|
|
4023
|
+
* @returns Promise that resolves to true if valid, rejects with error if invalid
|
|
4024
|
+
*/
|
|
4025
|
+
async verify(body, signature, secret) {
|
|
4026
|
+
if (!this.verifySignature(body, signature, secret)) {
|
|
4027
|
+
throw new Error('Webhook signature verification failed');
|
|
4028
|
+
}
|
|
4029
|
+
return true;
|
|
4030
|
+
}
|
|
4031
|
+
/**
|
|
4032
|
+
* Generate webhook signature for testing
|
|
4033
|
+
* Matches Inkress signature generation: crypto.mac(:hmac, :sha256, secret, body) |> Base.encode64()
|
|
4034
|
+
*
|
|
4035
|
+
* @example
|
|
4036
|
+
* ```typescript
|
|
4037
|
+
* const testBody = JSON.stringify({ id: '123', timestamp: Date.now(), event: {...} });
|
|
4038
|
+
* const signature = sdk.webhookUrls.generateSignature(testBody, 'your-secret');
|
|
4039
|
+
* ```
|
|
4040
|
+
*/
|
|
4041
|
+
generateSignature(body, secret) {
|
|
4042
|
+
if (!crypto) {
|
|
4043
|
+
throw new Error('Node.js crypto module not available. Cannot generate signature.');
|
|
4044
|
+
}
|
|
4045
|
+
return crypto
|
|
4046
|
+
.createHmac('sha256', secret)
|
|
4047
|
+
.update(body, 'utf8')
|
|
4048
|
+
.digest('base64');
|
|
4049
|
+
}
|
|
4050
|
+
/**
|
|
4051
|
+
* Extract event data from webhook payload with type safety
|
|
4052
|
+
*
|
|
4053
|
+
* @example
|
|
4054
|
+
* ```typescript
|
|
4055
|
+
* const payload = await sdk.webhookUrls.verifyRequest(request, secret);
|
|
4056
|
+
* const orderData = sdk.webhookUrls.extractEventData<Order>(payload);
|
|
4057
|
+
* ```
|
|
4058
|
+
*/
|
|
4059
|
+
extractEventData(payload) {
|
|
4060
|
+
return payload.event.data;
|
|
4061
|
+
}
|
|
3900
4062
|
}
|
|
3901
4063
|
|
|
3902
4064
|
/**
|