@brownandroot/api 0.1.0 → 0.3.0
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/README.md +77 -0
- package/package.json +29 -24
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @brownandroot/api
|
|
2
|
+
|
|
3
|
+
TypeScript client for the Brown & Root APIHub employee data service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @brownandroot/api
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ApiHubClient } from '@brownandroot/api'
|
|
15
|
+
|
|
16
|
+
const client = new ApiHubClient({
|
|
17
|
+
baseUrl: 'https://your-apihub-url.com',
|
|
18
|
+
apiKey: 'your-api-key',
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Get all employees
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
const employees = await client.getEmployees()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Get a single employee
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const employee = await client.getEmployee(12345)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Search by name
|
|
37
|
+
|
|
38
|
+
Case-insensitive partial match:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const results = await client.searchByName('John')
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Get employees by supervisor
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const reports = await client.getBySupervisor(12345)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Get supervisor chain
|
|
51
|
+
|
|
52
|
+
Returns the chain of supervisors above an employee (excludes the employee themselves):
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const chain = await client.getSupervisorChain(12345)
|
|
56
|
+
// [directSupervisor, theirSupervisor, ...]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Types
|
|
60
|
+
|
|
61
|
+
The package exports the `Employee` interface and `ApiHubClientOptions`:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import type { Employee, ApiHubClientOptions } from '@brownandroot/api'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Error Handling
|
|
68
|
+
|
|
69
|
+
Methods throw an `Error` when the API returns a non-OK response. The error message contains the server's error detail or the HTTP status code.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
try {
|
|
73
|
+
const emp = await client.getEmployee(99999)
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error(err.message) // "Employee not found"
|
|
76
|
+
}
|
|
77
|
+
```
|
package/package.json
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@brownandroot/api",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@brownandroot/api",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/brownandroot/APIHub.git",
|
|
8
|
+
"directory": "src/client"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p tsconfig.json",
|
|
23
|
+
"prepublishOnly": "npm run build",
|
|
24
|
+
"publish:manual": "npm publish --access public"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|