{"_id":"@dhaba/safepay-ts","name":"@dhaba/safepay-ts","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.3":{"name":"@dhaba/safepay-ts","version":"0.0.3","author":{"name":"Dhaba"},"type":"module","tshy":{"sourceDialects":["@dhaba/safepay-ts/source"],"exports":{".":"./src/index.ts","./package.json":"./package.json","./types":"./src/types/index.ts","./models/errors":"./src/models/errors/index.ts","./models":"./src/models/index.ts","./models/operations":"./src/models/operations/index.ts","./*.js":"./src/*.ts","./*":"./src/*.ts"}},"sideEffects":false,"scripts":{"lint":"eslint --cache --max-warnings=0 src","build":"tshy","prepublishOnly":"npm run build"},"peerDependencies":{"zod":"^3"},"devDependencies":{"@eslint/js":"^9.19.0","eslint":"^9.19.0","globals":"^15.14.0","tshy":"^2.0.0","typescript":"^5.4.5","typescript-eslint":"^8.22.0","zod":"^3.25.17"},"dependencies":{},"exports":{".":{"import":{"@dhaba/safepay-ts/source":"./src/index.ts","types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json","./types":{"import":{"@dhaba/safepay-ts/source":"./src/types/index.ts","types":"./dist/esm/types/index.d.ts","default":"./dist/esm/types/index.js"},"require":{"types":"./dist/commonjs/types/index.d.ts","default":"./dist/commonjs/types/index.js"}},"./models/errors":{"import":{"@dhaba/safepay-ts/source":"./src/models/errors/index.ts","types":"./dist/esm/models/errors/index.d.ts","default":"./dist/esm/models/errors/index.js"},"require":{"types":"./dist/commonjs/models/errors/index.d.ts","default":"./dist/commonjs/models/errors/index.js"}},"./models":{"import":{"@dhaba/safepay-ts/source":"./src/models/index.ts","types":"./dist/esm/models/index.d.ts","default":"./dist/esm/models/index.js"},"require":{"types":"./dist/commonjs/models/index.d.ts","default":"./dist/commonjs/models/index.js"}},"./models/operations":{"import":{"@dhaba/safepay-ts/source":"./src/models/operations/index.ts","types":"./dist/esm/models/operations/index.d.ts","default":"./dist/esm/models/operations/index.js"},"require":{"types":"./dist/commonjs/models/operations/index.d.ts","default":"./dist/commonjs/models/operations/index.js"}},"./*.js":{"import":{"@dhaba/safepay-ts/source":"./src/*.ts","types":"./dist/esm/*.d.ts","default":"./dist/esm/*.js"},"require":{"types":"./dist/commonjs/*.d.ts","default":"./dist/commonjs/*.js"}},"./*":{"import":{"@dhaba/safepay-ts/source":"./src/*.ts","types":"./dist/esm/*.d.ts","default":"./dist/esm/*.js"},"require":{"types":"./dist/commonjs/*.d.ts","default":"./dist/commonjs/*.js"}}},"main":"./dist/commonjs/index.js","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","gitHead":"3a98ea093daf48489040cac6e82d92e853713418","description":"Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@dhaba/safepay-ts* API.","_id":"@dhaba/safepay-ts@0.0.3","_nodeVersion":"16.20.2","_npmVersion":"8.19.4","dist":{"integrity":"sha512-UkAPA8YSYBVUfQb/J6izwPUoa0V831Rv2B8SHhv+1ZJyQkmBlZPBOwiXxPCuNTkaWeoBbRNkRyrZNA22zQk2pg==","shasum":"1a92e32b601a0c3758c3506054dd614b47b5efa2","tarball":"https://registry.npmjs.org/@dhaba/safepay-ts/-/safepay-ts-0.0.3.tgz","fileCount":1133,"unpackedSize":4366271,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCmvvwp1+SNhDY+vBp886KOT5lgkdkN/gv8xsyeOH+BDAIgVXvEZAluXAnSZE+BzozgGPtkRM2VTlB/SK/iaIJM7kc="}]},"_npmUser":{"name":"draco1js","email":"aayan.asultan@gmail.com"},"directories":{},"maintainers":[{"name":"draco1js","email":"aayan.asultan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/safepay-ts_0.0.3_1752366175693_0.6897503924504222"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-13T00:22:55.600Z","0.0.3":"2025-07-13T00:22:55.882Z","modified":"2025-07-13T00:22:56.178Z"},"maintainers":[{"name":"draco1js","email":"aayan.asultan@gmail.com"}],"description":"Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@dhaba/safepay-ts* API.","author":{"name":"Dhaba"},"readme":"# @dhaba/safepay-ts\n\nDeveloper-friendly & type-safe Typescript SDK specifically catered to leverage *@dhaba/safepay-ts* API.\n\n<div align=\"left\">\n    <a href=\"https://www.speakeasy.com/?utm_source=@dhaba/safepay-ts&utm_campaign=typescript\"><img src=\"https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454\" /></a>\n    <a href=\"https://opensource.org/licenses/MIT\">\n        <img src=\"https://img.shields.io/badge/License-MIT-blue.svg\" style=\"width: 100px; height: 28px;\" />\n    </a>\n</div>\n\n\n<br /><br />\n> [!IMPORTANT]\n> This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your [workspace](https://app.speakeasy.com/org/dhaba/safepay-api). Delete this section before > publishing to a package manager.\n\n<!-- Start Summary [summary] -->\n## Summary\n\nSafepay: Safepay is a regulated payments service provider that enables developers to orchestrate money movement between customers and businesses with ease and speed. The Safepay API makes it simple for businesses and financial platforms to create payment sessions, manage subscriptions, issue invoices and exchange value by sending and receiving money. Our API is based upon REST principles, returns JSON responses, and uses standard HTTP response codes.\n\nSafepay offers two environments to developers - `production` and `sandbox` . Any transaction performed in our `sandbox` environment will not have any financial impact. We also provide test credentials for payment instruments that can be used while integrating.\n\nTo begin integrating, we recommend you sign up for our sandbox account - its free to do so and will give you access to all of Safepay's APIs. Once you've completed your integration, please reach out to a member of our team who will guide you on how to create a production account and complete our onboarding process.\n<!-- End Summary [summary] -->\n\n<!-- Start Table of Contents [toc] -->\n## Table of Contents\n<!-- $toc-max-depth=2 -->\n* [@dhaba/safepay-ts](#dhabasafepay-ts)\n  * [SDK Installation](#sdk-installation)\n  * [Requirements](#requirements)\n  * [SDK Example Usage](#sdk-example-usage)\n  * [Available Resources and Operations](#available-resources-and-operations)\n  * [Standalone functions](#standalone-functions)\n  * [Retries](#retries)\n  * [Error Handling](#error-handling)\n  * [Server Selection](#server-selection)\n  * [Custom HTTP Client](#custom-http-client)\n  * [Debugging](#debugging)\n* [Development](#development)\n  * [Maturity](#maturity)\n  * [Contributions](#contributions)\n\n<!-- End Table of Contents [toc] -->\n\n<!-- Start SDK Installation [installation] -->\n## SDK Installation\n\n> [!TIP]\n> To finish publishing your SDK to npm and others you must [run your first generation action](https://www.speakeasy.com/docs/github-setup#step-by-step-guide).\n\n\nThe SDK can be installed with either [npm](https://www.npmjs.com/), [pnpm](https://pnpm.io/), [bun](https://bun.sh/) or [yarn](https://classic.yarnpkg.com/en/) package managers.\n\n### NPM\n\n```bash\nnpm add <UNSET>\n```\n\n### PNPM\n\n```bash\npnpm add <UNSET>\n```\n\n### Bun\n\n```bash\nbun add <UNSET>\n```\n\n### Yarn\n\n```bash\nyarn add <UNSET> zod\n\n# Note that Yarn does not install peer dependencies automatically. You will need\n# to install zod as shown above.\n```\n\n> [!NOTE]\n> This package is published with CommonJS and ES Modules (ESM) support.\n<!-- End SDK Installation [installation] -->\n\n<!-- Start Requirements [requirements] -->\n## Requirements\n\nFor supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).\n<!-- End Requirements [requirements] -->\n\n<!-- Start SDK Example Usage [usage] -->\n## SDK Example Usage\n\n### Example\n\n```typescript\nimport { Safepay } from \"@dhaba/safepay-ts\";\n\nconst safepay = new Safepay();\n\nasync function run() {\n  const result = await safepay.auth.createMerchantJwt({});\n\n  console.log(result);\n}\n\nrun();\n\n```\n<!-- End SDK Example Usage [usage] -->\n\n<!-- Start Available Resources and Operations [operations] -->\n## Available Resources and Operations\n\n<details open>\n<summary>Available methods</summary>\n\n### [addresses](docs/sdks/addresses/README.md)\n\n* [create](docs/sdks/addresses/README.md#create) - Create Address\n\n### [apiKeys](docs/sdks/apikeys/README.md)\n\n* [create](docs/sdks/apikeys/README.md#create) - Create API Key\n\n### [apiSettings](docs/sdks/apisettings/README.md)\n\n* [getApiKey](docs/sdks/apisettings/README.md#getapikey) - Find Api Key\n* [updateKey](docs/sdks/apisettings/README.md#updatekey) - Update Api Key\n\n### [auth](docs/sdks/auth/README.md)\n\n* [createMerchantJwt](docs/sdks/auth/README.md#createmerchantjwt) - Create Merchant JWT\n* [login](docs/sdks/auth/README.md#login) - Create Shopper JWT Using Password\n\n### [clientTransactions](docs/sdks/clienttransactions/README.md)\n\n* [search](docs/sdks/clienttransactions/README.md#search) - Search Transactions\n\n### [company](docs/sdks/company/README.md)\n\n* [login](docs/sdks/company/README.md#login) - Login Company\n\n### [customers](docs/sdks/customers/README.md)\n\n* [create](docs/sdks/customers/README.md#create) - Create Customer\n* [list](docs/sdks/customers/README.md#list) - List Customers\n\n### [invoices](docs/sdks/invoices/README.md)\n\n* [createQuickLink](docs/sdks/invoices/README.md#createquicklink) - Create\n\n### [meta](docs/sdks/meta/README.md)\n\n* [getCountry](docs/sdks/meta/README.md#getcountry) - Country\n* [listCountries](docs/sdks/meta/README.md#listcountries) - Countries\n\n### [orderPayments](docs/sdks/orderpayments/README.md)\n\n* [create](docs/sdks/orderpayments/README.md#create) - Payment\n\n### [passport](docs/sdks/passport/README.md)\n\n* [generateToken](docs/sdks/passport/README.md#generatetoken) - Generate Time-Based Token\n\n### [payments](docs/sdks/payments/README.md)\n\n* [search](docs/sdks/payments/README.md#search) - Search Payments\n\n### [plans](docs/sdks/plans/README.md)\n\n* [create](docs/sdks/plans/README.md#create) - Create Plan\n* [search](docs/sdks/plans/README.md#search) - Search Plans\n\n### [quickLinks](docs/sdks/quicklinks/README.md)\n\n* [create](docs/sdks/quicklinks/README.md#create) - Create Quick Link\n* [search](docs/sdks/quicklinks/README.md#search) - Search Quick Links\n\n\n### [shoppers](docs/sdks/shoppers/README.md)\n\n* [createSafepay](docs/sdks/shoppers/README.md#createsafepay) - Create Safepay Shopper\n\n### [subscriptions](docs/sdks/subscriptions/README.md)\n\n* [search](docs/sdks/subscriptions/README.md#search) - Search Subscriptions\n\n### [users](docs/sdks/users/README.md)\n\n* [createGuestJwt](docs/sdks/users/README.md#createguestjwt) - Create Guest JWT\n* [exists](docs/sdks/users/README.md#exists) - Safepay Shopper Exists\n* [findSafepayShopper](docs/sdks/users/README.md#findsafepayshopper) - Find Safepay Shopper\n\n### [userWallets](docs/sdks/userwallets/README.md)\n\n* [listPaymentMethods](docs/sdks/userwallets/README.md#listpaymentmethods) - List Payment Methods\n\n### [webhooks](docs/sdks/webhooks/README.md)\n\n* [test](docs/sdks/webhooks/README.md#test) - Test Webhook\n\n</details>\n<!-- End Available Resources and Operations [operations] -->\n\n<!-- Start Standalone functions [standalone-funcs] -->\n## Standalone functions\n\nAll the methods listed above are available as standalone functions. These\nfunctions are ideal for use in applications running in the browser, serverless\nruntimes or other environments where application bundle size is a primary\nconcern. When using a bundler to build your application, all unused\nfunctionality will be either excluded from the final bundle or tree-shaken away.\n\nTo read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).\n\n<details>\n\n<summary>Available standalone functions</summary>\n\n- [`addressesCreate`](docs/sdks/addresses/README.md#create) - Create Address\n- [`apiKeysCreate`](docs/sdks/apikeys/README.md#create) - Create API Key\n- [`apiSettingsGetApiKey`](docs/sdks/apisettings/README.md#getapikey) - Find Api Key\n- [`apiSettingsUpdateKey`](docs/sdks/apisettings/README.md#updatekey) - Update Api Key\n- [`authCreateMerchantJwt`](docs/sdks/auth/README.md#createmerchantjwt) - Create Merchant JWT\n- [`authLogin`](docs/sdks/auth/README.md#login) - Create Shopper JWT Using Password\n- [`clientTransactionsSearch`](docs/sdks/clienttransactions/README.md#search) - Search Transactions\n- [`companyLogin`](docs/sdks/company/README.md#login) - Login Company\n- [`customersCreate`](docs/sdks/customers/README.md#create) - Create Customer\n- [`customersList`](docs/sdks/customers/README.md#list) - List Customers\n- [`invoicesCreateQuickLink`](docs/sdks/invoices/README.md#createquicklink) - Create\n- [`metaGetCountry`](docs/sdks/meta/README.md#getcountry) - Country\n- [`metaListCountries`](docs/sdks/meta/README.md#listcountries) - Countries\n- [`orderPaymentsCreate`](docs/sdks/orderpayments/README.md#create) - Payment\n- [`passportGenerateToken`](docs/sdks/passport/README.md#generatetoken) - Generate Time-Based Token\n- [`paymentsSearch`](docs/sdks/payments/README.md#search) - Search Payments\n- [`plansCreate`](docs/sdks/plans/README.md#create) - Create Plan\n- [`plansSearch`](docs/sdks/plans/README.md#search) - Search Plans\n- [`quickLinksCreate`](docs/sdks/quicklinks/README.md#create) - Create Quick Link\n- [`quickLinksSearch`](docs/sdks/quicklinks/README.md#search) - Search Quick Links\n- [`shoppersCreateSafepay`](docs/sdks/shoppers/README.md#createsafepay) - Create Safepay Shopper\n- [`subscriptionsSearch`](docs/sdks/subscriptions/README.md#search) - Search Subscriptions\n- [`usersCreateGuestJwt`](docs/sdks/users/README.md#createguestjwt) - Create Guest JWT\n- [`usersExists`](docs/sdks/users/README.md#exists) - Safepay Shopper Exists\n- [`usersFindSafepayShopper`](docs/sdks/users/README.md#findsafepayshopper) - Find Safepay Shopper\n- [`userWalletsListPaymentMethods`](docs/sdks/userwallets/README.md#listpaymentmethods) - List Payment Methods\n- [`webhooksTest`](docs/sdks/webhooks/README.md#test) - Test Webhook\n\n</details>\n<!-- End Standalone functions [standalone-funcs] -->\n\n<!-- Start Retries [retries] -->\n## Retries\n\nSome of the endpoints in this SDK support retries.  If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API.  However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.\n\nTo change the default retry strategy for a single API call, simply provide a retryConfig object to the call:\n```typescript\nimport { Safepay } from \"@dhaba/safepay-ts\";\n\nconst safepay = new Safepay();\n\nasync function run() {\n  const result = await safepay.auth.createMerchantJwt({}, {\n    retries: {\n      strategy: \"backoff\",\n      backoff: {\n        initialInterval: 1,\n        maxInterval: 50,\n        exponent: 1.1,\n        maxElapsedTime: 100,\n      },\n      retryConnectionErrors: false,\n    },\n  });\n\n  console.log(result);\n}\n\nrun();\n\n```\n\nIf you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:\n```typescript\nimport { Safepay } from \"@dhaba/safepay-ts\";\n\nconst safepay = new Safepay({\n  retryConfig: {\n    strategy: \"backoff\",\n    backoff: {\n      initialInterval: 1,\n      maxInterval: 50,\n      exponent: 1.1,\n      maxElapsedTime: 100,\n    },\n    retryConnectionErrors: false,\n  },\n});\n\nasync function run() {\n  const result = await safepay.auth.createMerchantJwt({});\n\n  console.log(result);\n}\n\nrun();\n\n```\n<!-- End Retries [retries] -->\n\n<!-- Start Error Handling [errors] -->\n## Error Handling\n\n[`SafepayError`](./src/models/errors/safepayerror.ts) is the base class for all HTTP error responses. It has the following properties:\n\n| Property            | Type       | Description                                                                             |\n| ------------------- | ---------- | --------------------------------------------------------------------------------------- |\n| `error.message`     | `string`   | Error message                                                                           |\n| `error.statusCode`  | `number`   | HTTP response status code eg `404`                                                      |\n| `error.headers`     | `Headers`  | HTTP response headers                                                                   |\n| `error.body`        | `string`   | HTTP body. Can be empty string if no body is returned.                                  |\n| `error.rawResponse` | `Response` | Raw HTTP response                                                                       |\n| `error.data$`       |            | Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |\n\n### Example\n```typescript\nimport { Safepay } from \"@dhaba/safepay-ts\";\nimport * as errors from \"@dhaba/safepay-ts/models/errors\";\n\nconst safepay = new Safepay();\n\nasync function run() {\n  try {\n    const result = await safepay.auth.createMerchantJwt({});\n\n    console.log(result);\n  } catch (error) {\n    // The base class for HTTP error responses\n    if (error instanceof errors.SafepayError) {\n      console.log(error.message);\n      console.log(error.statusCode);\n      console.log(error.body);\n      console.log(error.headers);\n\n      // Depending on the method different errors may be thrown\n      if (\n        error instanceof errors.PostAuthV1CompanyAuthenticateUnauthorizedError\n      ) {\n        console.log(error.data$.data); // any\n        console.log(error.data$.status); // models.Status\n      }\n    }\n  }\n}\n\nrun();\n\n```\n\n### Error Classes\n**Primary error:**\n* [`SafepayError`](./src/models/errors/safepayerror.ts): The base class for HTTP error responses.\n\n<details><summary>Less common errors (19)</summary>\n\n<br />\n\n**Network errors:**\n* [`ConnectionError`](./src/models/errors/httpclienterrors.ts): HTTP client was unable to make a request to a server.\n* [`RequestTimeoutError`](./src/models/errors/httpclienterrors.ts): HTTP request timed out due to an AbortSignal signal.\n* [`RequestAbortedError`](./src/models/errors/httpclienterrors.ts): HTTP request was aborted by the client.\n* [`InvalidRequestError`](./src/models/errors/httpclienterrors.ts): Any input used to create a request is invalid.\n* [`UnexpectedClientError`](./src/models/errors/httpclienterrors.ts): Unrecognised or unexpected error.\n\n\n**Inherit from [`SafepayError`](./src/models/errors/safepayerror.ts)**:\n* [`PostAuthV1CompanyAuthenticateUnauthorizedError`](./src/models/errors/postauthv1companyauthenticateunauthorizederror.ts): 401. Status code `401`. Applicable to 16 of 27 methods.*\n* [`PostClientApiSettingsV1BadRequestError`](./src/models/errors/postclientapisettingsv1badrequesterror.ts): 400. Status code `400`. Applicable to 5 of 27 methods.*\n* [`ErrorT`](./src/models/errors/errort.ts): Applicable to 5 of 27 methods.*\n* [`ExpectationFailedError`](./src/models/errors/expectationfailederror.ts): 417. Status code `417`. Applicable to 4 of 27 methods.*\n* [`PostClientPlansV1BadRequestError`](./src/models/errors/postclientplansv1badrequesterror.ts): 400. Status code `400`. Applicable to 2 of 27 methods.*\n* [`PostAuthV2UserLoginUnauthorizedError`](./src/models/errors/postauthv2userloginunauthorizederror.ts): 401. Status code `401`. Applicable to 2 of 27 methods.*\n* [`PostAuthV2UserLoginBadRequestError`](./src/models/errors/postauthv2userloginbadrequesterror.ts): 400. Status code `400`. Applicable to 1 of 27 methods.*\n* [`PostClientHooksV2TestBadRequestError`](./src/models/errors/postclienthooksv2testbadrequesterror.ts): 400. Status code `400`. Applicable to 1 of 27 methods.*\n* [`GetUserV2ExistsBadRequestError`](./src/models/errors/getuserv2existsbadrequesterror.ts): 400. Status code `400`. Applicable to 1 of 27 methods.*\n* [`NotFoundError`](./src/models/errors/notfounderror.ts): 404. Status code `404`. Applicable to 1 of 27 methods.*\n* [`ConflictError`](./src/models/errors/conflicterror.ts): 409. Status code `409`. Applicable to 1 of 27 methods.*\n* [`PostClientPlansV1InternalServerError`](./src/models/errors/postclientplansv1internalservererror.ts): 500. Status code `500`. Applicable to 1 of 27 methods.*\n* [`PostOrderPaymentsV3InternalServerError`](./src/models/errors/postorderpaymentsv3internalservererror.ts): 500. Status code `500`. Applicable to 1 of 27 methods.*\n* [`ResponseValidationError`](./src/models/errors/responsevalidationerror.ts): Type mismatch between the data returned from the server and the structure expected by the SDK. See `error.rawValue` for the raw value and `error.pretty()` for a nicely formatted multi-line string.\n\n</details>\n\n\\* Check [the method documentation](#available-resources-and-operations) to see if the error is applicable.\n<!-- End Error Handling [errors] -->\n\n<!-- Start Server Selection [server] -->\n## Server Selection\n\n### Select Server by Index\n\nYou can override the default server globally by passing a server index to the `serverIdx: number` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:\n\n| #   | Server                            | Description            |\n| --- | --------------------------------- | ---------------------- |\n| 0   | `https://api.sandbox.safepay.com` | Sandbox environment    |\n| 1   | `https://api.safepay.com`         | Production environment |\n\n#### Example\n\n```typescript\nimport { Safepay } from \"@dhaba/safepay-ts\";\n\nconst safepay = new Safepay({\n  serverIdx: 1,\n});\n\nasync function run() {\n  const result = await safepay.auth.createMerchantJwt({});\n\n  console.log(result);\n}\n\nrun();\n\n```\n\n### Override Server URL Per-Client\n\nThe default server can also be overridden globally by passing a URL to the `serverURL: string` optional parameter when initializing the SDK client instance. For example:\n```typescript\nimport { Safepay } from \"@dhaba/safepay-ts\";\n\nconst safepay = new Safepay({\n  serverURL: \"https://api.safepay.com\",\n});\n\nasync function run() {\n  const result = await safepay.auth.createMerchantJwt({});\n\n  console.log(result);\n}\n\nrun();\n\n```\n<!-- End Server Selection [server] -->\n\n<!-- Start Custom HTTP Client [http-client] -->\n## Custom HTTP Client\n\nThe TypeScript SDK makes API calls using an `HTTPClient` that wraps the native\n[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). This\nclient is a thin wrapper around `fetch` and provides the ability to attach hooks\naround the request lifecycle that can be used to modify the request or handle\nerrors and response.\n\nThe `HTTPClient` constructor takes an optional `fetcher` argument that can be\nused to integrate a third-party HTTP client or when writing tests to mock out\nthe HTTP client and feed in fixtures.\n\nThe following example shows how to use the `\"beforeRequest\"` hook to to add a\ncustom header and a timeout to requests and how to use the `\"requestError\"` hook\nto log errors:\n\n```typescript\nimport { Safepay } from \"@dhaba/safepay-ts\";\nimport { HTTPClient } from \"@dhaba/safepay-ts/lib/http\";\n\nconst httpClient = new HTTPClient({\n  // fetcher takes a function that has the same signature as native `fetch`.\n  fetcher: (request) => {\n    return fetch(request);\n  }\n});\n\nhttpClient.addHook(\"beforeRequest\", (request) => {\n  const nextRequest = new Request(request, {\n    signal: request.signal || AbortSignal.timeout(5000)\n  });\n\n  nextRequest.headers.set(\"x-custom-header\", \"custom value\");\n\n  return nextRequest;\n});\n\nhttpClient.addHook(\"requestError\", (error, request) => {\n  console.group(\"Request Error\");\n  console.log(\"Reason:\", `${error}`);\n  console.log(\"Endpoint:\", `${request.method} ${request.url}`);\n  console.groupEnd();\n});\n\nconst sdk = new Safepay({ httpClient });\n```\n<!-- End Custom HTTP Client [http-client] -->\n\n<!-- Start Debugging [debug] -->\n## Debugging\n\nYou can setup your SDK to emit debug logs for SDK requests and responses.\n\nYou can pass a logger that matches `console`'s interface as an SDK option.\n\n> [!WARNING]\n> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.\n\n```typescript\nimport { Safepay } from \"@dhaba/safepay-ts\";\n\nconst sdk = new Safepay({ debugLogger: console });\n```\n\nYou can also enable a default debug logger by setting an environment variable `SAFEPAY_DEBUG` to true.\n<!-- End Debugging [debug] -->\n\n<!-- Placeholder for Future Speakeasy SDK Sections -->\n\n# Development\n\n## Maturity\n\nThis SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage\nto a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally\nlooking for the latest version.\n\n## Contributions\n\nWhile we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. \nWe look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release. \n\n### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=@dhaba/safepay-ts&utm_campaign=typescript)\n","readmeFilename":"README.md","_rev":"1-38b7557bedbe192b12079050792a8f50"}