@xylabs/api
Advanced tools
Comparing version 2.11.3 to 2.11.4
import { ApiStage } from './ApiStage'; | ||
declare abstract class ApiClient { | ||
protected token?: string | null | undefined; | ||
protected stage?: ApiStage | undefined; | ||
constructor(token?: string | null | undefined, stage?: ApiStage | undefined); | ||
protected token?: string | null; | ||
protected stage?: ApiStage; | ||
constructor(token?: string | null, stage?: ApiStage); | ||
abstract endPoint(): string; | ||
@@ -7,0 +7,0 @@ } |
@@ -7,7 +7,7 @@ import { ApiConfig } from './ApiConfig'; | ||
constructor(config: ApiConfig, path: string); | ||
get value(): T | undefined; | ||
get value(): T; | ||
private get headers(); | ||
private get url(); | ||
fetch(): Promise<T>; | ||
get(): Promise<T | NonNullable<T>>; | ||
get(): Promise<T>; | ||
insert(value: T): Promise<T>; | ||
@@ -14,0 +14,0 @@ } |
@@ -1,18 +0,117 @@ | ||
'use strict'; | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var ApiClient = require('./ApiClient.js'); | ||
var ApiEndpoint = require('./ApiEndpoint.js'); | ||
var ApiStage = require('./ApiStage.js'); | ||
var getApiStage = require('./getApiStage.js'); | ||
require('axios'); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
ApiClient: () => ApiClient, | ||
ApiEndpoint: () => ApiEndpoint, | ||
ApiStage: () => ApiStage, | ||
getApiStage: () => getApiStage | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/ApiStage.ts | ||
var ApiStage = /* @__PURE__ */ ((ApiStage2) => { | ||
ApiStage2["Beta"] = "beta"; | ||
ApiStage2["Local"] = "local"; | ||
ApiStage2["Prod"] = "prod"; | ||
return ApiStage2; | ||
})(ApiStage || {}); | ||
// src/ApiClient.ts | ||
var ApiClient = class { | ||
constructor(token, stage) { | ||
this.token = token; | ||
this.stage = stage; | ||
this.stage = stage ?? "prod" /* Prod */; | ||
this.token = token; | ||
} | ||
}; | ||
exports.ApiClient = ApiClient.ApiClient; | ||
exports.ApiEndpoint = ApiEndpoint.ApiEndpoint; | ||
Object.defineProperty(exports, 'ApiStage', { | ||
enumerable: true, | ||
get: function () { return ApiStage.ApiStage; } | ||
// src/ApiEndpoint.ts | ||
var import_axios = __toESM(require("axios")); | ||
var ApiEndpoint = class { | ||
_value; | ||
config; | ||
path; | ||
constructor(config, path) { | ||
this.config = config; | ||
this.path = path; | ||
} | ||
get value() { | ||
return this._value; | ||
} | ||
get headers() { | ||
return this.config.jwtToken ? { Authorization: this.config.jwtToken } : void 0; | ||
} | ||
get url() { | ||
return `${this.config.apiDomain}/${this.path}`; | ||
} | ||
async fetch() { | ||
const response = await import_axios.default.get(this.url, { headers: this.headers }); | ||
if (response.status === 200) { | ||
this._value = response.data; | ||
} else { | ||
throw Error("Unexpected Status Code"); | ||
} | ||
return this._value; | ||
} | ||
async get() { | ||
return this._value ?? await this.fetch(); | ||
} | ||
async insert(value) { | ||
const response = await import_axios.default.post(this.url, value, { headers: this.headers }); | ||
if (response.status === 200) { | ||
this._value = response.data; | ||
} else { | ||
throw Error("Unexpected Status Code"); | ||
} | ||
return this._value; | ||
} | ||
}; | ||
// src/getApiStage.ts | ||
var getApiStage = (hostname) => { | ||
if (hostname.startsWith("localhost")) { | ||
return "local" /* Local */; | ||
} else if (hostname.startsWith("beta.")) { | ||
return "beta" /* Beta */; | ||
} else { | ||
return "prod" /* Prod */; | ||
} | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ApiClient, | ||
ApiEndpoint, | ||
ApiStage, | ||
getApiStage | ||
}); | ||
exports.getApiStage = getApiStage.getApiStage; | ||
//# sourceMappingURL=index.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -57,4 +57,4 @@ { | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^3.0.0", | ||
"@xylabs/tsconfig": "^3.0.0", | ||
"@xylabs/ts-scripts-yarn3": "^3.0.20", | ||
"@xylabs/tsconfig": "^3.0.20", | ||
"typescript": "^5.2.2" | ||
@@ -70,4 +70,4 @@ }, | ||
"sideEffects": false, | ||
"version": "2.11.3", | ||
"version": "2.11.4", | ||
"packageManager": "yarn@3.3.1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31820
37
1