Node SDK Configuration
Constructor
import AccruPay from '@accrupay/node';
const accrupay = new AccruPay({
apiSecret: process.env.ACCRUPAY_API_SECRET!,
environment: 'production',
enableTelemetry: true,
onAuthError: () => {
console.error('Auth failed — rotate API key');
},
onGraphQLError: (errors) => {
for (const err of errors) {
console.error(`[GraphQL] ${err.message}`, err.extensions);
}
},
onNetworkError: (error) => {
console.error('Network error:', error.message);
},
});
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
apiSecret | string | Yes | — | Secret API key. Never expose client-side. |
environment | 'production' | 'qa' | No | 'production' | Target environment. Use 'qa' for development/sandbox testing (routes to api.qa.pay.accru.co). |
url | string | No | — | Override the GraphQL endpoint URL. Useful for self-hosted deployments. |
enableTelemetry | boolean | No | true | Send anonymized usage data to AccruPay. See Telemetry. |
onAuthError | () => void | No | — | Called on an authentication failure (UNAUTHORIZED). Receives no argument. |
onGraphQLError | (errors: ReadonlyArray<GraphQLFormattedError>) => void | No | — | Called when response.errors[] is non-empty. |
onNetworkError | (error: Error) => void | No | — | Called on transport-level failures (DNS, timeout, etc.). |
Create a single AccruPay instance and export it as a module singleton. The client manages its own connection pool.
Error callbacks
onAuthError
Fires when the API returns an authentication failure (UNAUTHORIZED GraphQL extension code). Receives no argument.
onAuthError: () => {
// Re-initialize the client with the new secret after rotation.
console.error('Authentication failed — re-initialize with a valid apiSecret');
}
A fired onAuthError means every subsequent call will also fail until you re-initialize the client with a valid apiSecret.
onGraphQLError
Fires when the GraphQL response body contains an errors array. Each entry is a GraphQLFormattedError (GraphQL spec) with an extensions.code (a fixed framework code or a namespaced @domain/REASON AppError key).
import type { GraphQLFormattedError } from 'graphql';
onGraphQLError: (errors: ReadonlyArray<GraphQLFormattedError>) => {
for (const err of errors) {
const code = err.extensions?.code as string | undefined;
switch (code) {
case 'GRAPHQL_VALIDATION_FAILED':
// Surface to caller
break;
default:
// Log and alert
console.error(`[${code}] ${err.message}`);
}
}
}
onNetworkError
Fires on transport-level failures before a GraphQL response is received (DNS resolution failure, connection refused, timeout).
onNetworkError: (error: Error) => {
// Implement retry / circuit-breaker logic here.
metrics.increment('accrupay.network_error');
}
onNetworkError does not fire for GraphQL-level errors (those go to onGraphQLError). Wire both callbacks to get complete error coverage.
Telemetry
When enableTelemetry is true (the default), the SDK sends:
- SDK version string
- Method names called (e.g.
clientSessions.payments.start) - Runtime environment identifier
No customer data, amounts, or billing fields are included. To opt out:
const accrupay = new AccruPay({
apiSecret: process.env.ACCRUPAY_API_SECRET!,
enableTelemetry: false,
});
TypeScript types
The SDK exports the GraphQL enums and schema types (TRANSACTION_PROVIDER, CURRENCY, COUNTRY_ISO_2, BillingDataSchema, MerchantTransaction, etc.). The constructor options are typed inline — there is no separately exported config type. To reuse the options shape, derive it from the constructor:
type AccruPayOptions = ConstructorParameters<typeof AccruPay>[0];
function buildClient(options: AccruPayOptions) {
return new AccruPay(options);
}