@xylabs/api 5.0.83 → 5.0.84

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
@@ -50,6 +50,8 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
50
50
 
51
51
  ***
52
52
 
53
+ Abstract base class for API clients that provides stage and token configuration.
54
+
53
55
  ## Constructors
54
56
 
55
57
  ### Constructor
@@ -106,12 +108,16 @@ abstract endPoint(): string;
106
108
 
107
109
  ***
108
110
 
111
+ Generic REST API endpoint wrapper that supports fetching and inserting typed data.
112
+
109
113
  ## Type Parameters
110
114
 
111
115
  ### T
112
116
 
113
117
  `T`
114
118
 
119
+ The type of data returned by the endpoint
120
+
115
121
  ## Constructors
116
122
 
117
123
  ### Constructor
@@ -202,16 +208,22 @@ insert(value): Promise<T>;
202
208
  function getApiStage(hostname): "beta" | "local" | "prod";
203
209
  ```
204
210
 
211
+ Determines the API stage based on the hostname.
212
+
205
213
  ## Parameters
206
214
 
207
215
  ### hostname
208
216
 
209
217
  `string`
210
218
 
219
+ The hostname to evaluate
220
+
211
221
  ## Returns
212
222
 
213
223
  `"beta"` \| `"local"` \| `"prod"`
214
224
 
225
+ The corresponding ApiStage (Local, Beta, or Prod)
226
+
215
227
  ### interfaces
216
228
 
217
229
  ### <a id="ApiConfig"></a>ApiConfig
@@ -220,6 +232,8 @@ function getApiStage(hostname): "beta" | "local" | "prod";
220
232
 
221
233
  ***
222
234
 
235
+ Configuration for connecting to an API, including domain, authentication, and user identification.
236
+
223
237
  ## Properties
224
238
 
225
239
  ### apiDomain
@@ -264,6 +278,8 @@ optional userid: string;
264
278
  type ApiStage = EnumValue<typeof ApiStage>;
265
279
  ```
266
280
 
281
+ A valid API stage value ('prod', 'beta', or 'local').
282
+
267
283
  ### variables
268
284
 
269
285
  ### <a id="ApiStage"></a>ApiStage
@@ -280,6 +296,8 @@ const ApiStage: Enum<{
280
296
  }>;
281
297
  ```
282
298
 
299
+ Deployment stage identifiers for API environments.
300
+
283
301
 
284
302
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
285
303
 
@@ -1,4 +1,5 @@
1
1
  import { ApiStage } from './ApiStage.ts';
2
+ /** Abstract base class for API clients that provides stage and token configuration. */
2
3
  declare abstract class ApiClient {
3
4
  protected stage?: ApiStage;
4
5
  protected token?: string | null;
@@ -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;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"}
1
+ {"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../../src/ApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,uFAAuF;AACvF,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"}
@@ -1,3 +1,4 @@
1
+ /** Configuration for connecting to an API, including domain, authentication, and user identification. */
1
2
  interface ApiConfig {
2
3
  apiDomain: string;
3
4
  apiKey?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ApiConfig.d.ts","sourceRoot":"","sources":["../../src/ApiConfig.ts"],"names":[],"mappings":"AAAA,UAAU,SAAS;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,YAAY,EAAE,SAAS,EAAE,CAAA"}
1
+ {"version":3,"file":"ApiConfig.d.ts","sourceRoot":"","sources":["../../src/ApiConfig.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,UAAU,SAAS;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,YAAY,EAAE,SAAS,EAAE,CAAA"}
@@ -1,4 +1,8 @@
1
1
  import type { ApiConfig } from './ApiConfig.ts';
2
+ /**
3
+ * Generic REST API endpoint wrapper that supports fetching and inserting typed data.
4
+ * @typeParam T - The type of data returned by the endpoint
5
+ */
2
6
  declare class ApiEndpoint<T> {
3
7
  private _value?;
4
8
  private config;
@@ -1 +1 @@
1
- {"version":3,"file":"ApiEndpoint.d.ts","sourceRoot":"","sources":["../../src/ApiEndpoint.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,cAAM,WAAW,CAAC,CAAC;IACjB,OAAO,CAAC,MAAM,CAAC,CAAG;IAClB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,IAAI,CAAQ;gBAER,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM;IAK3C,IAAI,KAAK,kBAER;IAED,OAAO,KAAK,OAAO,GAElB;IAED,OAAO,KAAK,GAAG,GAEd;IAEK,KAAK;IAUL,GAAG;IAIH,MAAM,CAAC,KAAK,EAAE,CAAC;CAStB;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
1
+ {"version":3,"file":"ApiEndpoint.d.ts","sourceRoot":"","sources":["../../src/ApiEndpoint.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C;;;GAGG;AACH,cAAM,WAAW,CAAC,CAAC;IACjB,OAAO,CAAC,MAAM,CAAC,CAAG;IAClB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,IAAI,CAAQ;gBAER,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM;IAK3C,IAAI,KAAK,kBAER;IAED,OAAO,KAAK,OAAO,GAElB;IAED,OAAO,KAAK,GAAG,GAEd;IAEK,KAAK;IAUL,GAAG;IAIH,MAAM,CAAC,KAAK,EAAE,CAAC;CAStB;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
@@ -1,9 +1,11 @@
1
1
  import type { EnumValue } from '@xylabs/enum';
2
2
  import { Enum } from '@xylabs/enum';
3
+ /** Deployment stage identifiers for API environments. */
3
4
  export declare const ApiStage: Enum<{
4
5
  Beta: "beta";
5
6
  Local: "local";
6
7
  Prod: "prod";
7
8
  }>;
9
+ /** A valid API stage value ('prod', 'beta', or 'local'). */
8
10
  export type ApiStage = EnumValue<typeof ApiStage>;
9
11
  //# sourceMappingURL=ApiStage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApiStage.d.ts","sourceRoot":"","sources":["../../src/ApiStage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,eAAO,MAAM,QAAQ;;;;EAInB,CAAA;AAEF,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,QAAQ,CAAC,CAAA"}
1
+ {"version":3,"file":"ApiStage.d.ts","sourceRoot":"","sources":["../../src/ApiStage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,yDAAyD;AACzD,eAAO,MAAM,QAAQ;;;;EAInB,CAAA;AAEF,4DAA4D;AAC5D,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,QAAQ,CAAC,CAAA"}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Determines the API stage based on the hostname.
3
+ * @param hostname - The hostname to evaluate
4
+ * @returns The corresponding ApiStage (Local, Beta, or Prod)
5
+ */
1
6
  declare const getApiStage: (hostname: string) => "beta" | "local" | "prod";
2
7
  export { getApiStage };
3
8
  //# sourceMappingURL=getApiStage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getApiStage.d.ts","sourceRoot":"","sources":["../../src/getApiStage.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,WAAW,GAAI,UAAU,MAAM,8BAQpC,CAAA;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
1
+ {"version":3,"file":"getApiStage.d.ts","sourceRoot":"","sources":["../../src/getApiStage.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,QAAA,MAAM,WAAW,GAAI,UAAU,MAAM,8BAQpC,CAAA;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
@@ -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 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 (hostname.startsWith('beta.')) {\n return ApiStage.Beta\n } else {\n return ApiStage.Prod\n }\n}\n\nexport { getApiStage }\n"],"mappings":";AACA,SAAS,YAAY;AAEd,IAAM,WAAW,KAAK;AAAA,EAC3B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AACR,CAAC;;;ACLD,IAAe,YAAf,MAAyB;AAAA,EACb;AAAA,EACA;AAAA,EAEV,YACE,OACA,OACA;AACA,SAAK,QAAQ,SAAS,SAAS;AAC/B,SAAK,QAAQ;AAAA,EACf;AAGF;;;ACfA,SAAS,mBAAmB;AAC5B,OAAO,WAAW;AAIlB,IAAM,cAAN,MAAqB;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,QAAmB,MAAc;AAC3C,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,IAAI,QAAQ;AACV,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAY,UAAU;AACpB,WAAO,YAAY,KAAK,OAAO,QAAQ,IAAI,SAAY,EAAE,eAAe,KAAK,OAAO,SAAS;AAAA,EAC/F;AAAA,EAEA,IAAY,MAAM;AAChB,WAAO,GAAG,KAAK,OAAO,SAAS,IAAI,KAAK,IAAI;AAAA,EAC9C;AAAA,EAEA,MAAM,QAAQ;AACZ,UAAM,WAAW,MAAM,MAAM,IAAO,KAAK,KAAK,EAAE,SAAS,KAAK,QAAQ,CAAC;AACvE,QAAI,SAAS,WAAW,KAAK;AAC3B,WAAK,SAAS,SAAS;AAAA,IACzB,OAAO;AACL,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,MAAM;AACV,WAAO,KAAK,UAAW,MAAM,KAAK,MAAM;AAAA,EAC1C;AAAA,EAEA,MAAM,OAAO,OAAU;AACrB,UAAM,WAAW,MAAM,MAAM,KAAQ,KAAK,KAAK,OAAO,EAAE,SAAS,KAAK,QAAQ,CAAC;AAC/E,QAAI,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":[]}
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\n/** Deployment stage identifiers for API environments. */\nexport const ApiStage = Enum({\n Beta: 'beta',\n Local: 'local',\n Prod: 'prod',\n})\n\n/** A valid API stage value ('prod', 'beta', or 'local'). */\nexport type ApiStage = EnumValue<typeof ApiStage>\n","import { ApiStage } from './ApiStage.ts'\n\n/** Abstract base class for API clients that provides stage and token configuration. */\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\n/**\n * Generic REST API endpoint wrapper that supports fetching and inserting typed data.\n * @typeParam T - The type of data returned by the endpoint\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\n/**\n * Determines the API stage based on the hostname.\n * @param hostname - The hostname to evaluate\n * @returns The corresponding ApiStage (Local, Beta, or Prod)\n */\nconst getApiStage = (hostname: string) => {\n if (hostname.startsWith('localhost')) {\n return ApiStage.Local\n } else if (hostname.startsWith('beta.')) {\n return ApiStage.Beta\n } else {\n return ApiStage.Pr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ACzB,OAAO;AACL,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AACA,WAAO,KAAK;AAAA,EACd;AACF;;;AC/CA,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.83",
3
+ "version": "5.0.84",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "xylabs",
@@ -41,12 +41,12 @@
41
41
  "!**/*.test.*"
42
42
  ],
43
43
  "dependencies": {
44
- "@xylabs/enum": "~5.0.83",
45
- "@xylabs/typeof": "~5.0.83"
44
+ "@xylabs/enum": "~5.0.84",
45
+ "@xylabs/typeof": "~5.0.84"
46
46
  },
47
47
  "devDependencies": {
48
- "@xylabs/ts-scripts-yarn3": "~7.4.11",
49
- "@xylabs/tsconfig": "~7.4.11",
48
+ "@xylabs/ts-scripts-yarn3": "~7.4.13",
49
+ "@xylabs/tsconfig": "~7.4.13",
50
50
  "axios": "^1.13.6",
51
51
  "typescript": "~5.9.3",
52
52
  "vitest": "~4.0.18"