@xylabs/api 5.0.79 → 5.0.81
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 +7 -7
- package/package.json +6 -9
- package/src/ApiClient.ts +0 -18
- package/src/ApiConfig.ts +0 -8
- package/src/ApiEndpoint.ts +0 -53
- package/src/ApiStage.ts +0 -10
- package/src/getApiStage.ts +0 -13
- package/src/index.ts +0 -5
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ new ApiClient(token?, stage?): ApiClient;
|
|
|
62
62
|
|
|
63
63
|
#### token?
|
|
64
64
|
|
|
65
|
-
`
|
|
65
|
+
`string` | `null`
|
|
66
66
|
|
|
67
67
|
#### stage?
|
|
68
68
|
|
|
@@ -74,18 +74,18 @@ new ApiClient(token?, stage?): ApiClient;
|
|
|
74
74
|
|
|
75
75
|
## Properties
|
|
76
76
|
|
|
77
|
-
###
|
|
77
|
+
### stage?
|
|
78
78
|
|
|
79
79
|
```ts
|
|
80
|
-
protected optional
|
|
80
|
+
protected optional stage: ApiStage;
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
***
|
|
84
84
|
|
|
85
|
-
###
|
|
85
|
+
### token?
|
|
86
86
|
|
|
87
87
|
```ts
|
|
88
|
-
protected optional
|
|
88
|
+
protected optional token: string | null;
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
## Methods
|
|
@@ -141,12 +141,12 @@ new ApiEndpoint<T>(config, path): ApiEndpoint<T>;
|
|
|
141
141
|
### Get Signature
|
|
142
142
|
|
|
143
143
|
```ts
|
|
144
|
-
get value():
|
|
144
|
+
get value(): T | undefined;
|
|
145
145
|
```
|
|
146
146
|
|
|
147
147
|
#### Returns
|
|
148
148
|
|
|
149
|
-
`
|
|
149
|
+
`T` \| `undefined`
|
|
150
150
|
|
|
151
151
|
## Methods
|
|
152
152
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/api",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.81",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -28,29 +28,26 @@
|
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/neutral/index.d.ts",
|
|
31
|
-
"source": "./src/index.ts",
|
|
32
31
|
"default": "./dist/neutral/index.mjs"
|
|
33
32
|
},
|
|
34
33
|
"./package.json": "./package.json"
|
|
35
34
|
},
|
|
36
35
|
"module": "./dist/neutral/index.mjs",
|
|
37
|
-
"source": "./src/index.ts",
|
|
38
36
|
"types": "./dist/neutral/index.d.ts",
|
|
39
37
|
"files": [
|
|
40
38
|
"dist",
|
|
41
|
-
"src",
|
|
42
39
|
"!**/*.bench.*",
|
|
43
40
|
"!**/*.spec.*",
|
|
44
41
|
"!**/*.test.*"
|
|
45
42
|
],
|
|
46
43
|
"dependencies": {
|
|
47
|
-
"@xylabs/enum": "~5.0.
|
|
48
|
-
"@xylabs/typeof": "~5.0.
|
|
44
|
+
"@xylabs/enum": "~5.0.81",
|
|
45
|
+
"@xylabs/typeof": "~5.0.81"
|
|
49
46
|
},
|
|
50
47
|
"devDependencies": {
|
|
51
|
-
"@xylabs/ts-scripts-yarn3": "~7.
|
|
52
|
-
"@xylabs/tsconfig": "~7.
|
|
53
|
-
"axios": "^1.13.
|
|
48
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.11",
|
|
49
|
+
"@xylabs/tsconfig": "~7.4.11",
|
|
50
|
+
"axios": "^1.13.6",
|
|
54
51
|
"typescript": "~5.9.3",
|
|
55
52
|
"vitest": "~4.0.18"
|
|
56
53
|
},
|
package/src/ApiClient.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ApiStage } from './ApiStage.ts'
|
|
2
|
-
|
|
3
|
-
abstract class ApiClient {
|
|
4
|
-
protected stage?: ApiStage
|
|
5
|
-
protected token?: string | null
|
|
6
|
-
|
|
7
|
-
constructor(
|
|
8
|
-
token?: string | null,
|
|
9
|
-
stage?: ApiStage,
|
|
10
|
-
) {
|
|
11
|
-
this.stage = stage ?? ApiStage.Prod
|
|
12
|
-
this.token = token
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
abstract endPoint(): string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { ApiClient }
|
package/src/ApiConfig.ts
DELETED
package/src/ApiEndpoint.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { isUndefined } from '@xylabs/typeof'
|
|
2
|
-
import axios from 'axios'
|
|
3
|
-
|
|
4
|
-
import type { ApiConfig } from './ApiConfig.ts'
|
|
5
|
-
|
|
6
|
-
class ApiEndpoint<T> {
|
|
7
|
-
private _value?: T
|
|
8
|
-
private config: ApiConfig
|
|
9
|
-
private path: string
|
|
10
|
-
|
|
11
|
-
constructor(config: ApiConfig, path: string) {
|
|
12
|
-
this.config = config
|
|
13
|
-
this.path = path
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get value() {
|
|
17
|
-
return this._value
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
private get headers() {
|
|
21
|
-
return isUndefined(this.config.jwtToken) ? undefined : { Authorization: this.config.jwtToken }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private get url() {
|
|
25
|
-
return `${this.config.apiDomain}/${this.path}`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async fetch() {
|
|
29
|
-
const response = await axios.get<T>(this.url, { headers: this.headers })
|
|
30
|
-
if (response.status === 200) {
|
|
31
|
-
this._value = response.data
|
|
32
|
-
} else {
|
|
33
|
-
throw new Error('Unexpected Status Code')
|
|
34
|
-
}
|
|
35
|
-
return this._value
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async get() {
|
|
39
|
-
return this._value ?? (await this.fetch())
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async insert(value: T) {
|
|
43
|
-
const response = await axios.post<T>(this.url, value, { headers: this.headers })
|
|
44
|
-
if (response.status === 200) {
|
|
45
|
-
this._value = response.data
|
|
46
|
-
} else {
|
|
47
|
-
throw new Error('Unexpected Status Code')
|
|
48
|
-
}
|
|
49
|
-
return this._value
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export { ApiEndpoint }
|
package/src/ApiStage.ts
DELETED
package/src/getApiStage.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ApiStage } from './ApiStage.ts'
|
|
2
|
-
|
|
3
|
-
const getApiStage = (hostname: string) => {
|
|
4
|
-
if (hostname.startsWith('localhost')) {
|
|
5
|
-
return ApiStage.Local
|
|
6
|
-
} else if (hostname.startsWith('beta.')) {
|
|
7
|
-
return ApiStage.Beta
|
|
8
|
-
} else {
|
|
9
|
-
return ApiStage.Prod
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { getApiStage }
|