Skip to content

Commit

Permalink
feat: additional environment options (#10)
Browse files Browse the repository at this point in the history
* feat: additional environment options

* refactor: simplify options into single url string
  • Loading branch information
trs authored Dec 7, 2023
1 parent 342a20d commit 8bf491a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/chargebee.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export interface ChargebeeModuleOptions {
site: string;
apiKey: string;
override?: {
url?: string;
timeout?: number;
};
}
13 changes: 13 additions & 0 deletions src/chargebee.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ function configureChargebee(options: ChargebeeModuleOptions) {
client.configure({
site: options.site,
api_key: options.apiKey,
...(options.override?.url ? extractURLOptions(options.override.url) : {}),
...(options.override?.timeout ? { timeout: options.override.timeout } : {}),
});
return client;
}

function extractURLOptions(urlStr: string) {
const url = new URL(urlStr);

return {
hostSuffix: "." + url.host,
apiPath: url.pathname,
protocol: url.protocol.replace(":", ""),
port: url.port,
};
}

0 comments on commit 8bf491a

Please sign in to comment.