@epam/statgpt-shared-toolkit 0.2.0-rc.37 → 0.2.0-rc.39
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/index.js +1 -1
- package/index.mjs +50 -46
- package/models/errors/http-error.d.ts +2 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S={CHAT:"/api/chat"},d="CUSTOM_PERIOD",i={decimal:"0.0",decimalSymbol:",",digitGroupingSymbol:" "},O="application/json",T="Content-Type",E="Api-Key",_="X-CONVERSATION-ID",c="Ocp-Apim-Subscription-Key",N={BAD_REQUEST:400,UNAUTHORIZED:401,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,CONFLICT:409,TOO_MANY_REQUESTS:429,INTERNAL_SERVER_ERROR:500,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504},C="onboarding",I="share";class g extends Error{constructor(e){super(e.message),this.isHttpError=!0,this.name="HttpError",this.status=e.status,this.details=e.details}}function D(t){return typeof t=="object"&&t!==null&&t.isHttpError===!0&&typeof t.status=="number"&&typeof t.message=="string"}var A=(t=>(t.MONTH="month",t.DAY="day",t))(A||{}),R=(t=>(t.UK="uk",t.EN="en",t))(R||{}),l=(t=>(t.IN="in",t.BETWEEN="between",t))(l||{});function H(t,e){const n=t.split("/")[0],r=e.split("/").pop();return`${n}/${r}`}const p=t=>(t==null?void 0:t.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").replace(/-/g," "))||"";function y(t,e){return`${t==null?void 0:t[0]}/${e}/${t==null?void 0:t[1]}`}const h=(t,e)=>(Math.round(t*10**e)/10**e).toString(),b=(t,e)=>{const n=(e==null?void 0:e.decimal)||i.decimal,r=(e==null?void 0:e.decimalSymbol)||i.decimalSymbol,s=(e==null?void 0:e.digitGroupingSymbol)??i.digitGroupingSymbol,o=Number(t);if(o==null||Number.isNaN(o)||t===null||t==="")return"";const u=n.replace("0.",""),a=`${n==="0"?Math.trunc(o):h(o,u.length)} `.split(".");return a[0]=a[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,`$1${s}`),`${a.join(r)}`},P=t=>isNaN(Date.parse(t))?null:new Date(t),B=(t,e,n)=>{const r={[T]:(e==null?void 0:e.contentType)||O};return e!=null&&e.jwt?r.Authorization=`Bearer ${e.jwt}`:t&&(r[E]=t),e!=null&&e.chatReference&&(r[_]=e.chatReference),{...r,...n}},M=t=>{const e={...t};return e[E]&&(e[E]=e[E].substring(0,8)+"...[REDACTED]"),e.Authorization&&(e.Authorization="Bearer [REDACTED]"),e[c]&&(e[c]=e[c].substring(0,8)+"...[REDACTED]"),e},L=t=>({"Content-Type":`multipart/form-data; boundary=${t}`}),U=t=>(t==null?void 0:t.toLowerCase())==="true",f=async(t,e,n)=>await fetch(t,{method:n.method||"GET",headers:e,body:n.body?JSON.stringify(n.body):void 0}),$=(t,e)=>{var n,r;return(r=(n=t==null?void 0:t.split("/"))==null?void 0:n.filter(s=>s!==e))==null?void 0:r.join("/")},m=t=>t.map(e=>({...e,name:e.name.split(/-\d+$/)[0]}));exports.API_KEY_HEADER=E;exports.API_ROUTES=S;exports.APPLICATION_JSON=O;exports.CONTENT_TYPE_HEADER=T;exports.CUSTOM_PERIOD=d;exports.CalendarResolution=A;exports.HTTP_ERROR_CODES=N;exports.HttpError=g;exports.Locale=R;exports.OCP_APIM_SUBSCRIPTION_KEY_HEADER=c;exports.ONBOARDING_MODEL_POSTFIX=C;exports.QueryFilterType=l;exports.SHARE_CONVERSATION_ROUTE=I;exports.X_CONVERSATION_ID_HEADER=_;exports.cleanConversationNames=m;exports.defaultFormatNumbers=i;exports.formatNumberBySign=b;exports.getClearedConversationName=p;exports.getConversationId=y;exports.getConversationNavPath=H;exports.getConversationUrlWithoutLocale=$;exports.getHeaders=B;exports.getMultipartHeaders=L;exports.getTimePeriod=P;exports.isHttpError=D;exports.parseBoolean=U;exports.sanitizeHeaders=M;exports.sendRequest=f;
|
package/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const g = {
|
|
2
2
|
CHAT: "/api/chat"
|
|
3
|
-
},
|
|
3
|
+
}, D = "CUSTOM_PERIOD", s = {
|
|
4
4
|
decimal: "0.0",
|
|
5
5
|
decimalSymbol: ",",
|
|
6
6
|
digitGroupingSymbol: " "
|
|
7
|
-
},
|
|
7
|
+
}, u = "application/json", A = "Content-Type", E = "Api-Key", a = "X-CONVERSATION-ID", O = "Ocp-Apim-Subscription-Key", I = {
|
|
8
8
|
BAD_REQUEST: 400,
|
|
9
9
|
UNAUTHORIZED: 401,
|
|
10
10
|
FORBIDDEN: 403,
|
|
@@ -16,77 +16,81 @@ const D = {
|
|
|
16
16
|
BAD_GATEWAY: 502,
|
|
17
17
|
SERVICE_UNAVAILABLE: 503,
|
|
18
18
|
GATEWAY_TIMEOUT: 504
|
|
19
|
-
},
|
|
20
|
-
class
|
|
19
|
+
}, N = "onboarding", C = "share";
|
|
20
|
+
class p extends Error {
|
|
21
21
|
constructor(e) {
|
|
22
|
-
super(e.message), this.name = "HttpError", this.status = e.status, this.details = e.details;
|
|
22
|
+
super(e.message), this.isHttpError = !0, this.name = "HttpError", this.status = e.status, this.details = e.details;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const n = t.split("/")[0], c = e.split("/").pop();
|
|
28
|
-
return `${n}/${c}`;
|
|
25
|
+
function h(t) {
|
|
26
|
+
return typeof t == "object" && t !== null && t.isHttpError === !0 && typeof t.status == "number" && typeof t.message == "string";
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
function
|
|
28
|
+
var l = /* @__PURE__ */ ((t) => (t.MONTH = "month", t.DAY = "day", t))(l || {}), R = /* @__PURE__ */ ((t) => (t.UK = "uk", t.EN = "en", t))(R || {}), d = /* @__PURE__ */ ((t) => (t.IN = "in", t.BETWEEN = "between", t))(d || {});
|
|
29
|
+
function y(t, e) {
|
|
30
|
+
const n = t.split("/")[0], r = e.split("/").pop();
|
|
31
|
+
return `${n}/${r}`;
|
|
32
|
+
}
|
|
33
|
+
const H = (t) => (t == null ? void 0 : t.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "").replace(/-/g, " ")) || "";
|
|
34
|
+
function b(t, e) {
|
|
32
35
|
return `${t == null ? void 0 : t[0]}/${e}/${t == null ? void 0 : t[1]}`;
|
|
33
36
|
}
|
|
34
|
-
const
|
|
35
|
-
const n = (e == null ? void 0 : e.decimal) ||
|
|
36
|
-
if (
|
|
37
|
+
const _ = (t, e) => (Math.round(t * 10 ** e) / 10 ** e).toString(), $ = (t, e) => {
|
|
38
|
+
const n = (e == null ? void 0 : e.decimal) || s.decimal, r = (e == null ? void 0 : e.decimalSymbol) || s.decimalSymbol, i = (e == null ? void 0 : e.digitGroupingSymbol) ?? s.digitGroupingSymbol, c = Number(t);
|
|
39
|
+
if (c == null || Number.isNaN(c) || t === null || t === "")
|
|
37
40
|
return "";
|
|
38
|
-
const
|
|
41
|
+
const T = n.replace("0.", ""), o = `${n === "0" ? Math.trunc(c) : _(c, T.length)} `.split(".");
|
|
39
42
|
return o[0] = o[0].replace(
|
|
40
43
|
/(\d)(?=(\d\d\d)+(?!\d))/g,
|
|
41
44
|
`$1${i}`
|
|
42
|
-
), `${o.join(
|
|
43
|
-
},
|
|
44
|
-
const
|
|
45
|
-
[
|
|
45
|
+
), `${o.join(r)}`;
|
|
46
|
+
}, B = (t) => isNaN(Date.parse(t)) ? null : new Date(t), L = (t, e, n) => {
|
|
47
|
+
const r = {
|
|
48
|
+
[A]: (e == null ? void 0 : e.contentType) || u
|
|
46
49
|
};
|
|
47
|
-
return e != null && e.jwt ?
|
|
48
|
-
},
|
|
50
|
+
return e != null && e.jwt ? r.Authorization = `Bearer ${e.jwt}` : t && (r[E] = t), e != null && e.chatReference && (r[a] = e.chatReference), { ...r, ...n };
|
|
51
|
+
}, M = (t) => {
|
|
49
52
|
const e = { ...t };
|
|
50
|
-
return e[E] && (e[E] = e[E].substring(0, 8) + "...[REDACTED]"), e.Authorization && (e.Authorization = "Bearer [REDACTED]"), e[
|
|
51
|
-
},
|
|
53
|
+
return e[E] && (e[E] = e[E].substring(0, 8) + "...[REDACTED]"), e.Authorization && (e.Authorization = "Bearer [REDACTED]"), e[O] && (e[O] = e[O].substring(0, 8) + "...[REDACTED]"), e;
|
|
54
|
+
}, f = (t) => ({
|
|
52
55
|
"Content-Type": `multipart/form-data; boundary=${t}`
|
|
53
56
|
}), U = (t) => (t == null ? void 0 : t.toLowerCase()) === "true", G = async (t, e, n) => await fetch(t, {
|
|
54
57
|
method: n.method || "GET",
|
|
55
58
|
headers: e,
|
|
56
59
|
body: n.body ? JSON.stringify(n.body) : void 0
|
|
57
60
|
}), w = (t, e) => {
|
|
58
|
-
var n,
|
|
59
|
-
return (
|
|
61
|
+
var n, r;
|
|
62
|
+
return (r = (n = t == null ? void 0 : t.split("/")) == null ? void 0 : n.filter((i) => i !== e)) == null ? void 0 : r.join("/");
|
|
60
63
|
}, Y = (t) => t.map((e) => ({
|
|
61
64
|
...e,
|
|
62
65
|
name: e.name.split(/-\d+$/)[0]
|
|
63
66
|
}));
|
|
64
67
|
export {
|
|
65
68
|
E as API_KEY_HEADER,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
g as API_ROUTES,
|
|
70
|
+
u as APPLICATION_JSON,
|
|
71
|
+
A as CONTENT_TYPE_HEADER,
|
|
72
|
+
D as CUSTOM_PERIOD,
|
|
73
|
+
l as CalendarResolution,
|
|
74
|
+
I as HTTP_ERROR_CODES,
|
|
75
|
+
p as HttpError,
|
|
76
|
+
R as Locale,
|
|
77
|
+
O as OCP_APIM_SUBSCRIPTION_KEY_HEADER,
|
|
78
|
+
N as ONBOARDING_MODEL_POSTFIX,
|
|
79
|
+
d as QueryFilterType,
|
|
77
80
|
C as SHARE_CONVERSATION_ROUTE,
|
|
78
|
-
|
|
81
|
+
a as X_CONVERSATION_ID_HEADER,
|
|
79
82
|
Y as cleanConversationNames,
|
|
80
|
-
|
|
83
|
+
s as defaultFormatNumbers,
|
|
81
84
|
$ as formatNumberBySign,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
H as getClearedConversationName,
|
|
86
|
+
b as getConversationId,
|
|
87
|
+
y as getConversationNavPath,
|
|
85
88
|
w as getConversationUrlWithoutLocale,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
L as getHeaders,
|
|
90
|
+
f as getMultipartHeaders,
|
|
91
|
+
B as getTimePeriod,
|
|
92
|
+
h as isHttpError,
|
|
89
93
|
U as parseBoolean,
|
|
90
|
-
|
|
94
|
+
M as sanitizeHeaders,
|
|
91
95
|
G as sendRequest
|
|
92
96
|
};
|
|
@@ -6,5 +6,7 @@ export interface HttpErrorPayload<D = unknown> {
|
|
|
6
6
|
export declare class HttpError<D = unknown> extends Error {
|
|
7
7
|
readonly status: number;
|
|
8
8
|
readonly details?: D;
|
|
9
|
+
readonly isHttpError = true;
|
|
9
10
|
constructor(payload: HttpErrorPayload<D>);
|
|
10
11
|
}
|
|
12
|
+
export declare function isHttpError(e: unknown): e is HttpError;
|