@xylabs/api 5.0.80 → 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 CHANGED
@@ -62,7 +62,7 @@ new ApiClient(token?, stage?): ApiClient;
62
62
 
63
63
  #### token?
64
64
 
65
- `null` | `string`
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
- ### token?
77
+ ### stage?
78
78
 
79
79
  ```ts
80
- protected optional token: null | string;
80
+ protected optional stage: ApiStage;
81
81
  ```
82
82
 
83
83
  ***
84
84
 
85
- ### stage?
85
+ ### token?
86
86
 
87
87
  ```ts
88
- protected optional stage: ApiStage;
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(): undefined | T;
144
+ get value(): T | undefined;
145
145
  ```
146
146
 
147
147
  #### Returns
148
148
 
149
- `undefined` \| `T`
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.80",
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.80",
48
- "@xylabs/typeof": "~5.0.80"
44
+ "@xylabs/enum": "~5.0.81",
45
+ "@xylabs/typeof": "~5.0.81"
49
46
  },
50
47
  "devDependencies": {
51
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
52
- "@xylabs/tsconfig": "~7.3.2",
53
- "axios": "^1.13.5",
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
@@ -1,8 +0,0 @@
1
- interface ApiConfig {
2
- apiDomain: string
3
- apiKey?: string
4
- jwtToken?: string
5
- userid?: string
6
- }
7
-
8
- export type { ApiConfig }
@@ -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
@@ -1,10 +0,0 @@
1
- import type { EnumValue } from '@xylabs/enum'
2
- import { Enum } from '@xylabs/enum'
3
-
4
- export const ApiStage = Enum({
5
- Beta: 'beta',
6
- Local: 'local',
7
- Prod: 'prod',
8
- })
9
-
10
- export type ApiStage = EnumValue<typeof ApiStage>
@@ -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 }
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './ApiClient.ts'
2
- export * from './ApiConfig.ts'
3
- export * from './ApiEndpoint.ts'
4
- export * from './ApiStage.ts'
5
- export * from './getApiStage.ts'