@xylabs/api 5.0.2 → 5.0.4
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ApiStage } from './ApiStage.ts';
|
|
2
2
|
declare abstract class ApiClient {
|
|
3
|
-
protected
|
|
4
|
-
protected
|
|
5
|
-
constructor(token?: string | null
|
|
3
|
+
protected stage?: ApiStage;
|
|
4
|
+
protected token?: string | null;
|
|
5
|
+
constructor(token?: string | null, stage?: ApiStage);
|
|
6
6
|
abstract endPoint(): string;
|
|
7
7
|
}
|
|
8
8
|
export { ApiClient };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../../src/ApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,uBAAe,SAAS;
|
|
1
|
+
{"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../../src/ApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,uBAAe,SAAS;IACtB,SAAS,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;IAC1B,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;gBAG7B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,KAAK,CAAC,EAAE,QAAQ;IAMlB,QAAQ,CAAC,QAAQ,IAAI,MAAM;CAC5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ApiStage.ts","../../src/ApiClient.ts","../../src/ApiEndpoint.ts","../../src/getApiStage.ts"],"sourcesContent":["import type { EnumValue } from '@xylabs/enum'\nimport { Enum } from '@xylabs/enum'\n\nexport const ApiStage = Enum({\n Beta: 'beta',\n Local: 'local',\n Prod: 'prod',\n})\n\nexport type ApiStage = EnumValue<typeof ApiStage>\n","import { ApiStage } from './ApiStage.ts'\n\nabstract class ApiClient {\n constructor(\n
|
|
1
|
+
{"version":3,"sources":["../../src/ApiStage.ts","../../src/ApiClient.ts","../../src/ApiEndpoint.ts","../../src/getApiStage.ts"],"sourcesContent":["import type { EnumValue } from '@xylabs/enum'\nimport { Enum } from '@xylabs/enum'\n\nexport const ApiStage = Enum({\n Beta: 'beta',\n Local: 'local',\n Prod: 'prod',\n})\n\nexport type ApiStage = EnumValue<typeof ApiStage>\n","import { ApiStage } from './ApiStage.ts'\n\nabstract class ApiClient {\n protected stage?: ApiStage\n protected token?: string | null\n\n constructor(\n token?: string | null,\n stage?: ApiStage,\n ) {\n this.stage = stage ?? ApiStage.Prod\n this.token = token\n }\n\n abstract endPoint(): string\n}\n\nexport { ApiClient }\n","import { isUndefined } from '@xylabs/typeof'\nimport axios from 'axios'\n\nimport type { ApiConfig } from './ApiConfig.ts'\n\nclass ApiEndpoint<T> {\n private _value?: T\n private config: ApiConfig\n private path: string\n\n constructor(config: ApiConfig, path: string) {\n this.config = config\n this.path = path\n }\n\n get value() {\n return this._value\n }\n\n private get headers() {\n return isUndefined(this.config.jwtToken) ? undefined : { Authorization: this.config.jwtToken }\n }\n\n private get url() {\n return `${this.config.apiDomain}/${this.path}`\n }\n\n async fetch() {\n const response = await axios.get<T>(this.url, { headers: this.headers })\n if (response.status === 200) {\n this._value = response.data\n } else {\n throw new Error('Unexpected Status Code')\n }\n return this._value\n }\n\n async get() {\n return this._value ?? (await this.fetch())\n }\n\n async insert(value: T) {\n const response = await axios.post<T>(this.url, value, { headers: this.headers })\n if (response.status === 200) {\n this._value = response.data\n } else {\n throw new Error('Unexpected Status Code')\n }\n return this._value\n }\n}\n\nexport { ApiEndpoint }\n","import { ApiStage } from './ApiStage.ts'\n\nconst getApiStage = (hostname: string) => {\n if (hostname.startsWith('localhost')) {\n return ApiStage.Local\n } else if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I,SAAS,WAAW,KAAK;AAC3B,WAAK,SAAS,SAAS;AAAA,IACzB,OAAO;AACL,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AACA,WAAO,KAAK;AAAA,EACd;AACF;;;AChDA,IAAM,cAAc,CAAC,aAAqB;AACxC,MAAI,SAAS,WAAW,WAAW,GAAG;AACpC,WAAO,SAAS;AAAA,EAClB,WAAW,SAAS,WAAW,OAAO,GAAG;AACvC,WAAO,SAAS;AAAA,EAClB,OAAO;AACL,WAAO,SAAS;AAAA,EAClB;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/api",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"src"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@xylabs/enum": "~5.0.
|
|
45
|
-
"@xylabs/typeof": "~5.0.
|
|
44
|
+
"@xylabs/enum": "~5.0.4",
|
|
45
|
+
"@xylabs/typeof": "~5.0.4",
|
|
46
46
|
"axios": "~1.11.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@xylabs/ts-scripts-yarn3": "~7.0
|
|
50
|
-
"@xylabs/tsconfig": "~7.0
|
|
49
|
+
"@xylabs/ts-scripts-yarn3": "~7.1.0",
|
|
50
|
+
"@xylabs/tsconfig": "~7.1.0",
|
|
51
51
|
"typescript": "~5.9.2",
|
|
52
52
|
"vitest": "~3.2.4"
|
|
53
53
|
},
|
package/src/ApiClient.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { ApiStage } from './ApiStage.ts'
|
|
2
2
|
|
|
3
3
|
abstract class ApiClient {
|
|
4
|
+
protected stage?: ApiStage
|
|
5
|
+
protected token?: string | null
|
|
6
|
+
|
|
4
7
|
constructor(
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
token?: string | null,
|
|
9
|
+
stage?: ApiStage,
|
|
7
10
|
) {
|
|
8
11
|
this.stage = stage ?? ApiStage.Prod
|
|
9
12
|
this.token = token
|