Skip to content

Commit 0849a55

Browse files
authored
Merge pull request #35 from warrant-dev/OssCleanup
Add OSS support
2 parents 98fe44e + b342659 commit 0849a55

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ const newUser = await warrantClient.User.create({
6666
});
6767
```
6868

69+
## Configuring the API Endpoint
70+
---
71+
The API endpoint the SDK makes requests to is configurable via the `endpoint` attribute when initializing the client:
72+
73+
```js
74+
import { WarrantClient } from "@warrantdev/warrant-node";
75+
76+
// Set api and authorize endpoints to http://localhost:8000
77+
const warrantClient = new WarrantClient({
78+
apiKey: "api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=",
79+
endpoint: "http://localhost:8000",
80+
});
81+
```
82+
6983
## Authorization
7084

7185
All access checks are performed based on an `object`, `relation` and `subject`. You can pass your own defined objects to the check methods by implementing the `WarrantObject` interface.

src/HttpClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ export default class ApiClient implements HttpClient {
9292
const fetchRequestOptions: FetchRequestOptions = {
9393
method,
9494
headers: {
95-
Authorization: `ApiKey ${this.config.apiKey}`,
9695
'User-Agent': `warrant-node/${version}`,
9796
'Content-Type': "application/json"
9897
},
9998
};
10099

101100
if (requestOptions?.apiKey) {
102101
fetchRequestOptions.headers['Authorization'] = `ApiKey ${requestOptions.apiKey}`;
102+
} else if (this.config.apiKey) {
103+
fetchRequestOptions.headers['Authorization'] = `ApiKey ${this.config.apiKey}`;
103104
}
104105

105106
if (requestOptions?.baseUrl) {

test/LiveTest.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var assert = require('assert');
44
// Uncomment .skip and add your API_KEY to run tests
55
describe.skip('Live Test', function () {
66
before(function () {
7-
this.warrant = new WarrantClient({ apiKey: "YOUR_KEY" });
7+
this.warrant = new WarrantClient({ apiKey: "", endpoint: "https://api.warrant.dev" });
88
});
99

1010
it('CRUD users', async function () {

0 commit comments

Comments
 (0)