@stackone/transport 1.7.0 → 1.8.2
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/dist/index.d.mts +753 -0
- package/dist/index.d.ts +753 -0
- package/dist/index.js +13540 -1
- package/dist/index.mjs +13516 -0
- package/package.json +28 -10
- package/dist/index.es.mjs +0 -1
- package/dist/types/authorization/authorizationHeaders.d.ts +0 -4
- package/dist/types/authorization/types.d.ts +0 -12
- package/dist/types/cacheClient/types.d.ts +0 -31
- package/dist/types/customErrors/index.d.ts +0 -3
- package/dist/types/customErrors/schemas.d.ts +0 -17
- package/dist/types/customErrors/types.d.ts +0 -4
- package/dist/types/errors/httpResponseError.d.ts +0 -6
- package/dist/types/httpClient/httpClient.d.ts +0 -37
- package/dist/types/httpClient/httpClientManager.d.ts +0 -10
- package/dist/types/httpClient/types.d.ts +0 -57
- package/dist/types/index.d.ts +0 -17
- package/dist/types/instanceManager/constants.d.ts +0 -1
- package/dist/types/instanceManager/index.d.ts +0 -15
- package/dist/types/lockManager/index.d.ts +0 -9
- package/dist/types/lockManager/types.d.ts +0 -6
- package/dist/types/memoryStore/constants.d.ts +0 -12
- package/dist/types/memoryStore/index.d.ts +0 -42
- package/dist/types/memoryStore/types.d.ts +0 -19
- package/dist/types/parsers/requestParameters.d.ts +0 -3
- package/dist/types/parsers/types.d.ts +0 -7
- package/dist/types/redisClient/index.d.ts +0 -69
- package/dist/types/redisClient/types.d.ts +0 -31
- package/dist/types/requestClient/requestClientFactory.d.ts +0 -4
- package/dist/types/requestClient/restClient.d.ts +0 -13
- package/dist/types/requestClient/types.d.ts +0 -14
- package/dist/types/scriptManager/index.d.ts +0 -21
- package/dist/types/scriptManager/types.d.ts +0 -8
- package/dist/types/validators/statusCodes.d.ts +0 -3
package/package.json
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/transport",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.
|
|
7
|
-
"types": "dist/
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"package.json",
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.mjs",
|
|
17
|
+
"require": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
13
21
|
"scripts": {
|
|
14
22
|
"clean": "rimraf dist",
|
|
15
23
|
"prebuild": "npm run clean",
|
|
16
|
-
"build": "
|
|
24
|
+
"build": "tsdown --env.NODE_ENV=production",
|
|
17
25
|
"prebuild:dev": "npm run clean",
|
|
18
|
-
"build:dev": "
|
|
26
|
+
"build:dev": "tsdown --format esm --format cjs --dts --env.NODE_ENV=development",
|
|
19
27
|
"code:format": "biome format ./src ./*.mjs",
|
|
20
28
|
"code:format:fix": "biome format --write ./src ./*.mjs",
|
|
21
29
|
"code:lint": "biome lint --error-on-warnings ./src ./*.mjs",
|
|
@@ -32,14 +40,24 @@
|
|
|
32
40
|
"author": "StackOne",
|
|
33
41
|
"license": "ISC",
|
|
34
42
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
43
|
+
"jsonpath": "^1.1.1",
|
|
44
|
+
"@stackone/expressions": "*",
|
|
37
45
|
"@stackone/logger": "*",
|
|
38
46
|
"@stackone/utils": "*",
|
|
39
|
-
"
|
|
47
|
+
"axios": "1.8.4",
|
|
48
|
+
"qs": "6.14.0",
|
|
40
49
|
"redis": "^4.7.0"
|
|
41
50
|
},
|
|
42
51
|
"devDependencies": {
|
|
43
|
-
"@types/qs": "6.9.18"
|
|
52
|
+
"@types/qs": "6.9.18",
|
|
53
|
+
"msw": "2.2.14",
|
|
54
|
+
"tsdown": "^0.12.9"
|
|
55
|
+
},
|
|
56
|
+
"tsdown": {
|
|
57
|
+
"dts": true,
|
|
58
|
+
"format": [
|
|
59
|
+
"esm",
|
|
60
|
+
"cjs"
|
|
61
|
+
]
|
|
44
62
|
}
|
|
45
|
-
}
|
|
63
|
+
}
|
package/dist/index.es.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{z as e}from"zod";import t from"axios";import s from"qs";import{notMissing as r,isMissing as a}from"@stackone/utils";import{safeEvaluate as i}from"@stackone/expressions";const n=e=>{switch(e.type){case"basic":return o(e);case"bearer":return c(e);default:throw new Error("Invalid authentication type")}},o=({username:e="",password:t="",encoding:s="base64"})=>{const r=s;return{authorization:`Basic ${Buffer.from(`${e}:${t}`).toString(r)}`}},c=({token:e,includeBearer:t=!0})=>({authorization:`${t?"Bearer ":""}${e}`}),h=e.object({receivedStatus:e.number(),targetStatus:e.number(),message:e.string().optional(),condition:e.string().optional()}),u={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",499:"Client Closed Request",500:"Internal server error",501:"Not Implemented",502:"Bad Gateway",503:"Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",510:"Not Extended",511:"Network Authentication Required"};class l extends Error{constructor(e,t){super(t),this.name="HttpResponseError",this.response=e,this.message=t??`HTTP error: ${e.status}`,Error.captureStackTrace&&Error.captureStackTrace(this,l)}toString(){const e=this.message?`: ${this.message}`:"";return`${this.name} [${this.response.status}]${e}`}}function d(e,t,s,r){if("a"===s&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===s?r:"a"===s?r.call(e):r?r.value:t.get(e)}var p,y,g,m,f,w;"function"==typeof SuppressedError&&SuppressedError;const S=()=>t.create({maxBodyLength:1/0});class T{constructor({transportInstance:e=S()}={}){p.add(this),y.set(this,void 0),function(e,t,s,r,a){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===r?a.call(e,s):a?a.value=s:t.set(e,s)}(this,y,e,"f")}async request({headers:e={},url:t,method:s="get",queryParams:r,maxRedirects:a=0,responseType:i,cacheTTL:n,context:o,payload:c,httpsAgent:h}){try{const n=new URLSearchParams(r).toString(),o=d(this,p,"m",g).call(this,e),u=await d(this,y,"f").request({headers:o,url:n?`${t}?${n}`:t,method:s,maxRedirects:a,responseType:i,data:d(this,p,"m",w).call(this,c,o),httpsAgent:h});return{data:u.data,status:u.status,headers:d(this,p,"m",m).call(this,u.headers),requestUrl:t,responseType:u?.config?.responseType,responseTime:new Date}}catch(e){throw e}}async get({headers:e,url:t,queryParams:s,maxRedirects:r,cacheTTL:a,context:i}){return this.request({url:t,method:"get",queryParams:s,headers:e,maxRedirects:r,cacheTTL:a,context:i})}async post({headers:e,url:t,maxRedirects:s,cacheTTL:r,context:a,payload:i}){return this.request({url:t,method:"post",headers:e,maxRedirects:s,cacheTTL:r,context:a,payload:i})}}y=new WeakMap,p=new WeakSet,g=function(e){if(!e)return{};const t={};return Object.keys(e).forEach((s=>{t[s.toLowerCase()]=e[s]||""})),t},m=function(e){if(!e)return{};const t={};return Object.keys(e).forEach((s=>{t[s]=e[s]||""})),t},f=function(e){return"application/x-www-form-urlencoded"===e["content-type"]},w=function(e,t){if(e)return d(this,p,"m",f).call(this,t)?s.stringify(e):e};const k=()=>new T;class v{static async getInstance({getHttpClient:e=k}={}){return this.httpClientInstance??=e(),this.httpClientInstance}static resetInstance(){this.httpClientInstance=null}}v.httpClientInstance=null;const q=["get","post","put","delete","patch"];class R{constructor(){this.locks=new Map}async withLock(e,t){await this.lock(e);try{return t()}finally{this.unlock(e)}}async lock(e){let t;const s=new Promise((e=>t=e)),r=this.locks.has(e),a=this.locks.get(e);if(r&&a){a.push({lock:s,unlock:t});const e=a.length-2;await a[e].lock}else this.locks.set(e,[{lock:s,unlock:t}])}unlock(e){const t=this.locks.has(e),s=this.locks.get(e);if(t&&s&&s.length>0){const e=s.shift()?.unlock;e?.()}0===this.queueLength(e)&&this.locks.delete(e)}queueLength(e){return this.locks.get(e)?.length}close(){this.locks.clear()}}var M;!function(e){e.MemoryStorePruneError="MemoryStorePruneError"}(M||(M={}));class x{constructor(e={}){this.lastAccessedAt=Date.now(),this.config=e,this.initialize(e)}initialize(e=this.config){this.instantiator=e?.instantiator??"Unknown",this.logger=e?.logger,this.dataStore=e?.dataStore??new Map,this.lockManager=e?.lockManager??new R,this.expiryMap=e?.expiryMap??new Map,this.evictionFrequency=e?.evictionFrequency??6e4,this.staleDataThreshold=e?.staleDataThreshold??6e5,this.truncateThreshold=e?.truncateThreshold??100,this.truncationPercentage=e?.truncationPercentage??10,this.typeGuard=e?.typeGuard,this.dispose=e?.dispose,this.startEvictionTask()}async getData(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,(async()=>this.dataStore.get(e)??null))}async setData({key:e,value:t,cacheTTL:s=60}){if(this.isReady()||this.initialize(),this.updateLastAccessedAt(),r(this.typeGuard)&&!this.typeGuard(t))return!1;const i=1e3*s,n=Date.now()+i;return await this.lockManager.withLock(e,(async()=>{(r(this.typeGuard)&&this.typeGuard(t)||a(this.typeGuard)&&this.typeGuardBypass(t))&&this.dataStore.set(e,t),this.expiryMap.set(e,n)})),!0}typeGuardBypass(e){return this.logger?.debug({category:"MemoryStore",message:`${this.instantiator} MemoryStore setting data without type guard - you should probably configure one`}),!0}async delete(e){return this.isReady()||this.initialize(),this.updateLastAccessedAt(),this.lockManager.withLock(e,(async()=>{if(this.dispose){const t=this.dataStore.get(e);await this.dispose(e,t)}return this.dataStore.delete(e)}))}async pruneExpiredKeys(){const e=this.dataStore.size,t=e>=this.truncateThreshold;if(e<=0)return;const s=[];let r=0;this.dataStore.forEach((async(e,a)=>{const i=Date.now(),n=this.expiryMap.get(a)??0,o=this.truncateThreshold*this.truncationPercentage/100;(n<=i||t&&r>=0&&r<=o)&&s.push(this.lockManager.withLock(a,(async()=>(this.dispose&&await this.dispose(a,e),this.dataStore.delete(a))))),r++})),await Promise.all(s);return{dataStoreSize:e,prunedDataStoreSize:this.dataStore.size}}startEvictionTask(){if(r(this.evictionInterval))return;const e=async()=>{let t;try{const s=this.lastAccessedAt+this.staleDataThreshold;if(s<Date.now())return this.logger?.warning({message:`Closing the ${this.instantiator}'s MemoryStore instance - received no requests for a while.`,category:"MemoryStore"}),void this.close();t=await this.pruneExpiredKeys(),this.evictionInterval=setTimeout(e,this.evictionFrequency)}catch(t){t instanceof Error&&this.logger?.error({message:"Error during pruning expired keys:",category:"MemoryStore",error:t,code:M.MemoryStorePruneError}),this.evictionInterval=setTimeout(e,this.evictionFrequency)}finally{if(r(t?.dataStoreSize)&&r(t?.prunedDataStoreSize)){const{dataStoreSize:e,prunedDataStoreSize:s}=t,r=e-s;this.logger?.debug({message:`Pruned ${r} expired keys, ${s} remain, scheduling next prune.`,category:"MemoryStore",context:{instantiator:this.instantiator}})}}};this.evictionInterval=setTimeout(e,this.evictionFrequency)}stopEvictionTask(){this.evictionInterval&&(clearTimeout(this.evictionInterval),this.evictionInterval=void 0)}updateLastAccessedAt(){this.lastAccessedAt=Date.now()}isReady(){return r(this.evictionInterval)&&r(this.dataStore)&&r(this.expiryMap)&&r(this.lockManager)}close(){this.stopEvictionTask(),this.dataStore.clear(),this.expiryMap.clear(),this.lockManager.close()}async listData({partialKey:e,cursor:t,limit:s}){const r=Array.from(this.dataStore.keys()).filter((t=>t.includes(e))),a=[],i=t?parseInt(t,10):0;for(let e=i;e<s+i;e++){const t=r[e];if(!t)break;const i=await this.getData(t);if(i&&a.push(i),a.length>=s)break}return{items:a,cursor:a.length<s?void 0:(i+s).toString()}}}class b{constructor(e){this.dataStore=null,this.initialize(e)}static getInstance(e){return a(b.instance)&&(b.instance=new b(e)),b.instance}initialize(e){this.dataStore=new x({instantiator:b.name,logger:e,typeGuard:e=>r(e)}),b.logger=e??null,b.logger?.info({category:b.name,message:"InstanceManager initialized."})}async get(e){return this.ensureReady(),await(b.getInstance().dataStore?.getData(e))??null}async set(e,t,s){return this.ensureReady(),await(b.getInstance().dataStore?.setData({key:e,value:t,cacheTTL:r(s)?s:300}))??!1}ensureReady(){this.isReady()||this.initialize()}isReady(){return r(this?.dataStore)}close(){b.instance=null,this.dataStore=null}}b.instance=null,b.logger=null,b.getInstance();const E=e=>e.reduce(((e,t)=>(Array.isArray(e[t.in][t.name])?e[t.in][t.name]=e[t.in][t.name].concat(t.value):"object"==typeof e[t.in][t.name]&&"object"==typeof t.value?e[t.in][t.name]={...e[t.in][t.name],...t.value}:e[t.in][t.name]="body"===t.in?t.value:String(t.value),e)),{query:{},body:{},headers:{}}),I=["query","body","headers"],P=e=>r(e)&&e>=200&&e<=299,L=e=>r(e)&&e>=400&&e<=599,A=e=>r(e)&&e>=100&&e<=199;class z{async performRequest({httpClient:e,url:t,method:s,headers:r,body:n,customErrorConfigs:o}){let c;try{c=await(e?.request({method:s,url:t,headers:r,maxRedirects:0,payload:n}))}catch(e){if(a(e?.response))throw e;c=e.response}const h=((e,t)=>{if(a(t)||0===t.length||a(e))return{data:e.data,status:e.status,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,message:e.message};const s=t?.filter((t=>t.receivedStatus===e.status));if(s?.length)for(const t of s){const s=t.condition,r=!0===i(s,e);if(a(s)||r)return{data:e.data,headers:e.headers,requestUrl:e.requestUrl,responseType:e.responseType,responseTime:e.responseTime,status:t.targetStatus,message:t?.message??u[t.targetStatus]??"Unknown error"}}return e})(c,o);if(L(h?.status))throw new l(h,h.message);return h}}class C{static build(e="rest"){if("rest"===e)return new z;throw new Error(`Unknown request client type: ${e}`)}}export{h as CUSTOM_ERROR_CONFIG_SCHEMA,T as HttpClient,v as HttpClientManager,u as HttpErrorMessages,q as HttpMethods,l as HttpResponseError,b as InstanceManager,R as LockManager,x as MemoryStore,C as RequestClientFactory,I as RequestParameterLocations,n as createAuthorizationHeaders,L as isFailedStatusCode,A as isInfoStatusCode,P as isSuccessStatusCode,E as parseRequestParameters};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type AuthenticationType = 'basic' | 'bearer';
|
|
2
|
-
export type BasicAuthorizationParams = {
|
|
3
|
-
type: 'basic';
|
|
4
|
-
username?: string;
|
|
5
|
-
password?: string;
|
|
6
|
-
encoding?: string;
|
|
7
|
-
};
|
|
8
|
-
export type BearerAuthorizationParams = {
|
|
9
|
-
type: 'bearer';
|
|
10
|
-
token: string;
|
|
11
|
-
includeBearer?: boolean;
|
|
12
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export interface ICacheClient<ClientType = unknown> {
|
|
2
|
-
getData<T>(key: string): Promise<T | null>;
|
|
3
|
-
listData<T>({ partialKey, limit, cursor, }: {
|
|
4
|
-
partialKey: string;
|
|
5
|
-
limit?: number;
|
|
6
|
-
cursor?: string;
|
|
7
|
-
}): Promise<{
|
|
8
|
-
items: T[] | null;
|
|
9
|
-
cursor?: string;
|
|
10
|
-
}>;
|
|
11
|
-
setData<T>({ key, value, cacheTTL, groupKey, }: {
|
|
12
|
-
key: string;
|
|
13
|
-
value: T;
|
|
14
|
-
cacheTTL: number;
|
|
15
|
-
groupKey?: string;
|
|
16
|
-
}): Promise<boolean>;
|
|
17
|
-
executeScript?<T>({ sha1, keys, args, }: {
|
|
18
|
-
sha1: string;
|
|
19
|
-
keys: string[];
|
|
20
|
-
args: string[];
|
|
21
|
-
}): Promise<T | null>;
|
|
22
|
-
loadScript?(script: string): Promise<string | null>;
|
|
23
|
-
increment?(key: string, cacheTTL: number): Promise<number | null>;
|
|
24
|
-
decrement?(key: string, cacheTTL: number): Promise<number | null>;
|
|
25
|
-
subscribe?<T extends boolean = false>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
|
|
26
|
-
unsubscribe?(pattern: string): Promise<boolean>;
|
|
27
|
-
publish?(channel: string, message: string): Promise<number | null>;
|
|
28
|
-
getClient?(): ClientType | null;
|
|
29
|
-
deleteData?(key: string): Promise<boolean>;
|
|
30
|
-
}
|
|
31
|
-
export type PubSubListener<ReturnsBuffer extends boolean = false> = <T extends ReturnsBuffer extends true ? Buffer : string>(message: T, channel: T) => unknown;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const CUSTOM_ERROR_CONFIG_SCHEMA: z.ZodObject<{
|
|
3
|
-
receivedStatus: z.ZodNumber;
|
|
4
|
-
targetStatus: z.ZodNumber;
|
|
5
|
-
message: z.ZodOptional<z.ZodString>;
|
|
6
|
-
condition: z.ZodOptional<z.ZodString>;
|
|
7
|
-
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
receivedStatus: number;
|
|
9
|
-
targetStatus: number;
|
|
10
|
-
message?: string | undefined;
|
|
11
|
-
condition?: string | undefined;
|
|
12
|
-
}, {
|
|
13
|
-
receivedStatus: number;
|
|
14
|
-
targetStatus: number;
|
|
15
|
-
message?: string | undefined;
|
|
16
|
-
condition?: string | undefined;
|
|
17
|
-
}>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import https from 'https';
|
|
3
|
-
import { HttpHeaders, HttpMethod, HttpQueryParams, HttpResponse, IHttpClient } from './types';
|
|
4
|
-
export declare class HttpClient implements IHttpClient {
|
|
5
|
-
#private;
|
|
6
|
-
constructor({ transportInstance, }?: {
|
|
7
|
-
transportInstance?: AxiosInstance;
|
|
8
|
-
});
|
|
9
|
-
request<P, T>({ headers, url, method, queryParams, maxRedirects, responseType, cacheTTL, context, payload, httpsAgent, }: {
|
|
10
|
-
headers?: HttpHeaders;
|
|
11
|
-
url: string;
|
|
12
|
-
method?: HttpMethod;
|
|
13
|
-
queryParams?: HttpQueryParams;
|
|
14
|
-
maxRedirects?: number;
|
|
15
|
-
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
|
|
16
|
-
cacheTTL?: number;
|
|
17
|
-
context?: unknown;
|
|
18
|
-
payload?: P;
|
|
19
|
-
httpsAgent?: https.Agent;
|
|
20
|
-
}): Promise<HttpResponse<T>>;
|
|
21
|
-
get<T>({ headers, url, queryParams, maxRedirects, cacheTTL, context, }: {
|
|
22
|
-
headers?: HttpHeaders;
|
|
23
|
-
url: string;
|
|
24
|
-
queryParams?: HttpQueryParams;
|
|
25
|
-
maxRedirects?: number;
|
|
26
|
-
cacheTTL?: number;
|
|
27
|
-
context?: unknown;
|
|
28
|
-
}): Promise<HttpResponse<T>>;
|
|
29
|
-
post<P, T>({ headers, url, maxRedirects, cacheTTL, context, payload, }: {
|
|
30
|
-
headers?: HttpHeaders;
|
|
31
|
-
url: string;
|
|
32
|
-
maxRedirects?: number;
|
|
33
|
-
cacheTTL?: number;
|
|
34
|
-
context?: unknown;
|
|
35
|
-
payload?: P;
|
|
36
|
-
}): Promise<HttpResponse<T>>;
|
|
37
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IHttpClient } from './types';
|
|
2
|
-
declare const buildHttpClientInstance: () => IHttpClient;
|
|
3
|
-
export declare class HttpClientManager {
|
|
4
|
-
private static httpClientInstance;
|
|
5
|
-
static getInstance({ getHttpClient, }?: {
|
|
6
|
-
getHttpClient?: typeof buildHttpClientInstance;
|
|
7
|
-
}): Promise<IHttpClient>;
|
|
8
|
-
static resetInstance(): void;
|
|
9
|
-
}
|
|
10
|
-
export {};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import https from 'https';
|
|
2
|
-
export type HttpHeaders = {
|
|
3
|
-
[key: string]: string;
|
|
4
|
-
};
|
|
5
|
-
export type HttpQueryParams = {
|
|
6
|
-
[key: string]: string;
|
|
7
|
-
};
|
|
8
|
-
export interface CertOptions {
|
|
9
|
-
certs?: string[];
|
|
10
|
-
keys?: string[];
|
|
11
|
-
}
|
|
12
|
-
export declare const HttpMethods: readonly ["get", "post", "put", "delete", "patch"];
|
|
13
|
-
export type HttpMethod = (typeof HttpMethods)[number];
|
|
14
|
-
export type HttpResponse<T = any> = {
|
|
15
|
-
data: T;
|
|
16
|
-
status: number;
|
|
17
|
-
headers: HttpHeaders;
|
|
18
|
-
requestUrl: string;
|
|
19
|
-
responseType?: string;
|
|
20
|
-
responseTime?: Date;
|
|
21
|
-
message?: string;
|
|
22
|
-
};
|
|
23
|
-
export type HttpParameters = {
|
|
24
|
-
query: HttpQueryParams;
|
|
25
|
-
body: Record<string, unknown>;
|
|
26
|
-
headers: HttpHeaders;
|
|
27
|
-
};
|
|
28
|
-
export interface IHttpClient {
|
|
29
|
-
request<P, T>({ headers, url, method, queryParams, maxRedirects, responseType, cacheTTL, context, payload, httpsAgent, }: {
|
|
30
|
-
headers?: HttpHeaders;
|
|
31
|
-
url: string;
|
|
32
|
-
method?: HttpMethod;
|
|
33
|
-
queryParams?: HttpQueryParams;
|
|
34
|
-
maxRedirects?: number;
|
|
35
|
-
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
|
|
36
|
-
cacheTTL?: number;
|
|
37
|
-
context?: unknown;
|
|
38
|
-
payload?: P;
|
|
39
|
-
httpsAgent?: https.Agent;
|
|
40
|
-
}): Promise<HttpResponse<T>>;
|
|
41
|
-
get<T>({ headers, url, queryParams, maxRedirects, cacheTTL, context, }: {
|
|
42
|
-
headers?: HttpHeaders;
|
|
43
|
-
url: string;
|
|
44
|
-
queryParams?: HttpQueryParams;
|
|
45
|
-
maxRedirects?: number;
|
|
46
|
-
cacheTTL?: number;
|
|
47
|
-
context?: unknown;
|
|
48
|
-
}): Promise<HttpResponse<T>>;
|
|
49
|
-
post<P, T>({ headers, url, maxRedirects, cacheTTL, context, payload, }: {
|
|
50
|
-
headers?: HttpHeaders;
|
|
51
|
-
url: string;
|
|
52
|
-
maxRedirects?: number;
|
|
53
|
-
cacheTTL?: number;
|
|
54
|
-
context?: unknown;
|
|
55
|
-
payload?: P;
|
|
56
|
-
}): Promise<HttpResponse<T>>;
|
|
57
|
-
}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export { createAuthorizationHeaders } from './authorization/authorizationHeaders';
|
|
2
|
-
export { CUSTOM_ERROR_CONFIG_SCHEMA } from './customErrors/schemas';
|
|
3
|
-
export { CustomErrorConfig, HttpErrorMessages } from './customErrors/types';
|
|
4
|
-
export { HttpResponseError } from './errors/httpResponseError';
|
|
5
|
-
export { HttpClient } from './httpClient/httpClient';
|
|
6
|
-
export { HttpClientManager } from './httpClient/httpClientManager';
|
|
7
|
-
export { HttpHeaders, HttpMethod, HttpMethods, HttpParameters, HttpQueryParams, HttpResponse, IHttpClient, } from './httpClient/types';
|
|
8
|
-
export { InstanceManager } from './instanceManager';
|
|
9
|
-
export { LockManager } from './lockManager';
|
|
10
|
-
export type { Lock, LockEntry, Unlock } from './lockManager/types';
|
|
11
|
-
export { MemoryStore } from './memoryStore';
|
|
12
|
-
export type { MemoryStoreConfig, PruneCount } from './memoryStore/types';
|
|
13
|
-
export { parseRequestParameters } from './parsers/requestParameters';
|
|
14
|
-
export { RequestParameter, RequestParameterLocations } from './parsers/types';
|
|
15
|
-
export { ICacheClient, PubSubListener } from './redisClient/types';
|
|
16
|
-
export { RequestClientFactory } from './requestClient/requestClientFactory';
|
|
17
|
-
export { isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, } from './validators/statusCodes';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_INSTANCE_TTL = 300;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ILogger } from '@stackone/logger';
|
|
2
|
-
export declare class InstanceManager {
|
|
3
|
-
private static instance;
|
|
4
|
-
private static logger;
|
|
5
|
-
private dataStore;
|
|
6
|
-
private constructor();
|
|
7
|
-
static getInstance(logger?: ILogger): InstanceManager;
|
|
8
|
-
private initialize;
|
|
9
|
-
get<T>(key: string): Promise<T | null>;
|
|
10
|
-
set<T>(key: string, value: T, cacheTTL?: number): Promise<boolean>;
|
|
11
|
-
private ensureReady;
|
|
12
|
-
isReady(): boolean;
|
|
13
|
-
close(): void;
|
|
14
|
-
}
|
|
15
|
-
export declare const instanceManager: InstanceManager;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare class LockManager {
|
|
2
|
-
private locks;
|
|
3
|
-
constructor();
|
|
4
|
-
withLock<T>(key: string, operation: () => Promise<T>): Promise<T>;
|
|
5
|
-
lock(key: string): Promise<void>;
|
|
6
|
-
unlock(key: string): void;
|
|
7
|
-
queueLength(key: string): number | undefined;
|
|
8
|
-
close(): void;
|
|
9
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const ONE_THOUSAND = 1000;
|
|
2
|
-
export declare const ONE_HUNDRED = 100;
|
|
3
|
-
export declare const ONE_MINUTE_IN_SECONDS = 60;
|
|
4
|
-
export declare const ONE_MINUTE_IN_MS = 60000;
|
|
5
|
-
export declare const DEFAULT_CACHE_TTL = 60;
|
|
6
|
-
export declare const DEFAULT_EVICTION_FREQUENCY = 60000;
|
|
7
|
-
export declare const DEFAULT_STALE_DATA_THRESHOLD: number;
|
|
8
|
-
export declare const DEFAULT_TRUNCATION_THRESHOLD = 100;
|
|
9
|
-
export declare const DEFAULT_TRUNCATION_PERCENTAGE = 10;
|
|
10
|
-
export declare enum MemoryStoreErrorCodes {
|
|
11
|
-
MemoryStorePruneError = "MemoryStorePruneError"
|
|
12
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ICacheClient } from '../redisClient/types';
|
|
2
|
-
import { MemoryStoreConfig, PruneCount } from './types';
|
|
3
|
-
export declare class MemoryStore<T> implements ICacheClient {
|
|
4
|
-
private config;
|
|
5
|
-
private instantiator;
|
|
6
|
-
private dataStore;
|
|
7
|
-
private lockManager;
|
|
8
|
-
private expiryMap;
|
|
9
|
-
private evictionFrequency;
|
|
10
|
-
private staleDataThreshold;
|
|
11
|
-
private truncateThreshold;
|
|
12
|
-
private truncationPercentage;
|
|
13
|
-
private logger?;
|
|
14
|
-
private typeGuard?;
|
|
15
|
-
private dispose?;
|
|
16
|
-
private evictionInterval?;
|
|
17
|
-
private lastAccessedAt;
|
|
18
|
-
constructor(config?: MemoryStoreConfig<T>);
|
|
19
|
-
private initialize;
|
|
20
|
-
getData<U = T>(key: string): Promise<U | null>;
|
|
21
|
-
setData<U = T>({ key, value, cacheTTL, }: {
|
|
22
|
-
key: string;
|
|
23
|
-
value: U;
|
|
24
|
-
cacheTTL?: number;
|
|
25
|
-
}): Promise<boolean>;
|
|
26
|
-
private typeGuardBypass;
|
|
27
|
-
delete(key: string): Promise<boolean>;
|
|
28
|
-
pruneExpiredKeys(): Promise<PruneCount | undefined>;
|
|
29
|
-
private startEvictionTask;
|
|
30
|
-
private stopEvictionTask;
|
|
31
|
-
private updateLastAccessedAt;
|
|
32
|
-
isReady(): boolean;
|
|
33
|
-
close(): void;
|
|
34
|
-
listData<T>({ partialKey, cursor, limit, }: {
|
|
35
|
-
partialKey: string;
|
|
36
|
-
cursor?: string;
|
|
37
|
-
limit: number;
|
|
38
|
-
}): Promise<{
|
|
39
|
-
items: T[] | null;
|
|
40
|
-
cursor?: string;
|
|
41
|
-
}>;
|
|
42
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ILogger } from '@stackone/logger';
|
|
2
|
-
import { LockManager } from '../lockManager';
|
|
3
|
-
export interface MemoryStoreConfig<T> {
|
|
4
|
-
instantiator?: string;
|
|
5
|
-
logger?: ILogger;
|
|
6
|
-
dataStore?: Map<string, T>;
|
|
7
|
-
lockManager?: LockManager;
|
|
8
|
-
expiryMap?: Map<string, number>;
|
|
9
|
-
evictionFrequency?: number;
|
|
10
|
-
staleDataThreshold?: number;
|
|
11
|
-
truncateThreshold?: number;
|
|
12
|
-
truncationPercentage?: number;
|
|
13
|
-
typeGuard?: (data: unknown) => data is T;
|
|
14
|
-
dispose?: (key: string, value: T) => Promise<void> | void;
|
|
15
|
-
}
|
|
16
|
-
export type PruneCount = {
|
|
17
|
-
dataStoreSize: number;
|
|
18
|
-
prunedDataStoreSize: number;
|
|
19
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const RequestParameterLocations: readonly ["query", "body", "headers"];
|
|
2
|
-
export type RequestParameterLocation = (typeof RequestParameterLocations)[number];
|
|
3
|
-
export type RequestParameter = {
|
|
4
|
-
name: string;
|
|
5
|
-
in: RequestParameterLocation;
|
|
6
|
-
value?: unknown;
|
|
7
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ILogger } from '@stackone/logger';
|
|
2
|
-
import * as redis from 'redis';
|
|
3
|
-
import { ICacheClient, PubSubListener } from '../cacheClient/types';
|
|
4
|
-
export declare enum ErrorCode {
|
|
5
|
-
RedisClientError = "RedisClientError",
|
|
6
|
-
RedisClientCommandError = "RedisClientCommandError",
|
|
7
|
-
RedisClientDeleteError = "RedisClientDeleteError",
|
|
8
|
-
RedisClientInvalidTTL = "RedisClientInvalidTTL",
|
|
9
|
-
RedisClientListError = "RedisClientListError",
|
|
10
|
-
RedisClientNotInitialized = "RedisClientNotInitialized",
|
|
11
|
-
RedisClientPublishError = "RedisClientPublishError",
|
|
12
|
-
RedisClientReadError = "RedisClientReadError",
|
|
13
|
-
RedisClientRedisNotReady = "RedisClientRedisNotReady",
|
|
14
|
-
RedisClientScriptError = "RedisClientScriptError",
|
|
15
|
-
RedisClientScriptExecuteError = "RedisClientScriptExecuteError",
|
|
16
|
-
RedisClientScriptLoadError = "RedisClientScriptLoadError",
|
|
17
|
-
RedisClientSubscribeError = "RedisClientSubscribeError",
|
|
18
|
-
RedisClientUnsubscribeError = "RedisClientUnsubscribeError",
|
|
19
|
-
RedisClientWriteError = "RedisClientWriteError"
|
|
20
|
-
}
|
|
21
|
-
export type RedisClientType = redis.RedisClientType;
|
|
22
|
-
export interface RedisClientConfig {
|
|
23
|
-
getRedisClient?: typeof redis.createClient;
|
|
24
|
-
host?: string;
|
|
25
|
-
port?: number;
|
|
26
|
-
tls?: boolean;
|
|
27
|
-
reconnect?: boolean;
|
|
28
|
-
database?: number;
|
|
29
|
-
}
|
|
30
|
-
export declare const buildRedisClientInstance: (config: RedisClientConfig, logger?: ILogger) => Promise<ICacheClient<RedisClientType> | undefined>;
|
|
31
|
-
export declare class RedisClient implements ICacheClient<RedisClientType> {
|
|
32
|
-
#private;
|
|
33
|
-
static build({ getRedisClient, host, port, tls, reconnect, database, }: RedisClientConfig, logger?: ILogger): Promise<ICacheClient<RedisClientType> | null>;
|
|
34
|
-
getData<T>(key: string): Promise<T | null>;
|
|
35
|
-
setData<T>({ key, value, cacheTTL, groupKey, }: {
|
|
36
|
-
key: string;
|
|
37
|
-
value: T;
|
|
38
|
-
cacheTTL: number;
|
|
39
|
-
groupKey?: string;
|
|
40
|
-
}): Promise<boolean>;
|
|
41
|
-
executeScript<T>({ sha1, keys, args, }: {
|
|
42
|
-
sha1: string;
|
|
43
|
-
keys: string[];
|
|
44
|
-
args: string[];
|
|
45
|
-
}): Promise<T | null>;
|
|
46
|
-
loadScript(script: string): Promise<string | null>;
|
|
47
|
-
increment(key: string, cacheTTL: number): Promise<number | null>;
|
|
48
|
-
decrement(key: string, cacheTTL: number): Promise<number | null>;
|
|
49
|
-
subscribe<T extends boolean>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
|
|
50
|
-
unsubscribe(pattern: string): Promise<boolean>;
|
|
51
|
-
publish(channel: string, message: string): Promise<number | null>;
|
|
52
|
-
getClient(): RedisClientType | null;
|
|
53
|
-
listData<T>({ partialKey, limit, cursor, }: {
|
|
54
|
-
partialKey: string;
|
|
55
|
-
limit: number;
|
|
56
|
-
cursor?: string;
|
|
57
|
-
}): Promise<{
|
|
58
|
-
items: T[] | null;
|
|
59
|
-
cursor?: string;
|
|
60
|
-
}>;
|
|
61
|
-
deleteData(key: string): Promise<boolean>;
|
|
62
|
-
}
|
|
63
|
-
type RedisEventListener = {
|
|
64
|
-
eventName: string;
|
|
65
|
-
listener: (...args: unknown[]) => void;
|
|
66
|
-
};
|
|
67
|
-
export declare const addRedisEventHandlers: (redisClient: redis.RedisClientType, handlers: RedisEventListener[]) => void;
|
|
68
|
-
export declare const getDefaultRedisListeners: (invoker?: string, logger?: ILogger) => RedisEventListener[];
|
|
69
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export interface ICacheClient<ClientType = unknown> {
|
|
2
|
-
getData<T>(key: string): Promise<T | null>;
|
|
3
|
-
listData<T>({ partialKey, limit, cursor, }: {
|
|
4
|
-
partialKey: string;
|
|
5
|
-
limit?: number;
|
|
6
|
-
cursor?: string;
|
|
7
|
-
}): Promise<{
|
|
8
|
-
items: T[] | null;
|
|
9
|
-
cursor?: string;
|
|
10
|
-
}>;
|
|
11
|
-
setData<T>({ key, value, cacheTTL, groupKey, }: {
|
|
12
|
-
key: string;
|
|
13
|
-
value: T;
|
|
14
|
-
cacheTTL: number;
|
|
15
|
-
groupKey?: string;
|
|
16
|
-
}): Promise<boolean>;
|
|
17
|
-
executeScript?<T>({ sha1, keys, args, }: {
|
|
18
|
-
sha1: string;
|
|
19
|
-
keys: string[];
|
|
20
|
-
args: string[];
|
|
21
|
-
}): Promise<T | null>;
|
|
22
|
-
loadScript?(script: string): Promise<string | null>;
|
|
23
|
-
increment?(key: string, cacheTTL: number): Promise<number | null>;
|
|
24
|
-
decrement?(key: string, cacheTTL: number): Promise<number | null>;
|
|
25
|
-
subscribe?<T extends boolean = false>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
|
|
26
|
-
unsubscribe?(pattern: string): Promise<boolean>;
|
|
27
|
-
publish?(channel: string, message: string): Promise<number | null>;
|
|
28
|
-
getClient?(): ClientType | null;
|
|
29
|
-
deleteData?(key: string): Promise<boolean>;
|
|
30
|
-
}
|
|
31
|
-
export type PubSubListener<ReturnsBuffer extends boolean = false> = <T extends ReturnsBuffer extends true ? Buffer : string>(message: T, channel: T) => unknown;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CustomErrorConfig } from '../customErrors/types';
|
|
2
|
-
import { HttpMethod, HttpResponse, IHttpClient } from '../httpClient/types';
|
|
3
|
-
import { IRequestClient } from './types';
|
|
4
|
-
export declare class RestClient implements IRequestClient {
|
|
5
|
-
performRequest({ httpClient, url, method, headers, body, customErrorConfigs, }: {
|
|
6
|
-
httpClient: IHttpClient;
|
|
7
|
-
url: string;
|
|
8
|
-
method: HttpMethod;
|
|
9
|
-
headers: Record<string, string>;
|
|
10
|
-
body: unknown;
|
|
11
|
-
customErrorConfigs?: CustomErrorConfig[];
|
|
12
|
-
}): Promise<HttpResponse>;
|
|
13
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { CustomErrorConfig } from '../customErrors/types';
|
|
2
|
-
import { HttpHeaders, HttpMethod, HttpQueryParams, HttpResponse, IHttpClient } from '../httpClient/types';
|
|
3
|
-
export interface IRequestClient {
|
|
4
|
-
performRequest: ({ httpClient, url, method, headers, body, customErrorConfigs, }: {
|
|
5
|
-
httpClient: IHttpClient;
|
|
6
|
-
url: string;
|
|
7
|
-
method: HttpMethod;
|
|
8
|
-
headers: HttpHeaders;
|
|
9
|
-
queryParams?: HttpQueryParams;
|
|
10
|
-
body: unknown;
|
|
11
|
-
customErrorConfigs?: CustomErrorConfig[];
|
|
12
|
-
}) => Promise<HttpResponse>;
|
|
13
|
-
}
|
|
14
|
-
export type RequestClientType = 'rest' | 'soap';
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ILogger } from '@stackone/logger';
|
|
2
|
-
import { ICacheClient } from '../cacheClient/types';
|
|
3
|
-
import { RedisClientConfig, RedisClientType } from '../redisClient';
|
|
4
|
-
import { ScriptManagerOptions, Scripts } from './types';
|
|
5
|
-
export declare enum ErrorCode {
|
|
6
|
-
ScriptManagerExecutionError = "ScriptManagerExecutionError",
|
|
7
|
-
ScriptManagerLoadingError = "ScriptManagerLoadingError"
|
|
8
|
-
}
|
|
9
|
-
export declare class ScriptManager<T extends string> {
|
|
10
|
-
protected cacheClient: ICacheClient<RedisClientType> | null;
|
|
11
|
-
protected scriptMap: Map<string, string>;
|
|
12
|
-
protected logger?: ILogger;
|
|
13
|
-
protected scripts: Scripts<T>;
|
|
14
|
-
protected redisClientConfig: RedisClientConfig;
|
|
15
|
-
constructor(preLoadScripts: Scripts<T>);
|
|
16
|
-
protected initialize({ redisClientConfig, logger, scriptMap }: ScriptManagerOptions<T>, ...args: unknown[]): Promise<void>;
|
|
17
|
-
protected additionalInitialization(..._args: unknown[]): Promise<void>;
|
|
18
|
-
protected loadScripts<U extends string>(scripts: Scripts<U>, scriptMap?: Map<U, string>): Promise<void>;
|
|
19
|
-
protected executeScript<X extends string, U>(method: X, keys: string[], args: string[]): Promise<U | null>;
|
|
20
|
-
protected isReady(): Promise<boolean>;
|
|
21
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ILogger } from '@stackone/logger';
|
|
2
|
-
import { RedisClientConfig } from '../redisClient';
|
|
3
|
-
export type Scripts<T extends string> = Record<T, string>;
|
|
4
|
-
export type ScriptManagerOptions<T extends string> = {
|
|
5
|
-
redisClientConfig: RedisClientConfig;
|
|
6
|
-
logger?: ILogger;
|
|
7
|
-
scriptMap?: Map<T, string>;
|
|
8
|
-
};
|