@epam/statgpt-shared-toolkit 0.2.0-rc.39 → 0.2.0-rc.40
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 +84 -50
- package/models/errors/http-error.d.ts +2 -0
- package/package.json +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/linkify/linkify.d.ts +18 -0
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 I={CHAT:"/api/chat"},N="CUSTOM_PERIOD",a={decimal:"0.0",decimalSymbol:",",digitGroupingSymbol:" "},u="application/json",O="Content-Type",c="Api-Key",A="X-CONVERSATION-ID",l="Ocp-Apim-Subscription-Key",S={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",h="share";class p extends Error{constructor(e){super(e.message),this.isHttpError=!0,this.name="HttpError",this.code=e.code,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"&&(t.code===void 0||typeof t.code=="string")}var _=(t=>(t.MONTH="month",t.DAY="day",t))(_||{}),d=(t=>(t.UK="uk",t.EN="en",t))(d||{}),R=(t=>(t.IN="in",t.BETWEEN="between",t))(R||{});function y(t,e){const n=t.split("/")[0],r=e.split("/").pop();return`${n}/${r}`}const H=t=>(t==null?void 0:t.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").replace(/-/g," "))||"";function f(t,e){return`${t==null?void 0:t[0]}/${e}/${t==null?void 0:t[1]}`}const P=(t,e)=>(Math.round(t*10**e)/10**e).toString(),U=(t,e)=>{const n=(e==null?void 0:e.decimal)||a.decimal,r=(e==null?void 0:e.decimalSymbol)||a.decimalSymbol,o=(e==null?void 0:e.digitGroupingSymbol)??a.digitGroupingSymbol,i=Number(t);if(i==null||Number.isNaN(i)||t===null||t==="")return"";const s=n.replace("0.",""),T=`${n==="0"?Math.trunc(i):P(i,s.length)} `.split(".");return T[0]=T[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,`$1${o}`),`${T.join(r)}`},b=t=>isNaN(Date.parse(t))?null:new Date(t),v=(t,e,n)=>{const r={[O]:(e==null?void 0:e.contentType)||u};return e!=null&&e.jwt?r.Authorization=`Bearer ${e.jwt}`:t&&(r[c]=t),e!=null&&e.chatReference&&(r[A]=e.chatReference),{...r,...n}},B=t=>{const e={...t};return e[c]&&(e[c]=e[c].substring(0,8)+"...[REDACTED]"),e.Authorization&&(e.Authorization="Bearer [REDACTED]"),e[l]&&(e[l]=e[l].substring(0,8)+"...[REDACTED]"),e},L=t=>({"Content-Type":`multipart/form-data; boundary=${t}`}),M=t=>(t==null?void 0:t.toLowerCase())==="true",m=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(o=>o!==e))==null?void 0:r.join("/")},x=t=>t.map(e=>({...e,name:e.name.split(/-\d+$/)[0]})),w=new Set([")","]","}",">",",",".","!","?",":",";"]);function g(t){let e=t.length;for(;e>0&&w.has(t[e-1]);)e--;return e===t.length?{cleanUrl:t,trailing:""}:{cleanUrl:t.slice(0,e),trailing:t.slice(e)}}function G(t){if(!t)return[{type:"text",value:""}];const e=[];let n=0;for(const r of t.matchAll(/\bhttps?:\/\/[^\s<>"']+/gi)){const o=r[0],i=r.index??0;i>n&&e.push({type:"text",value:t.slice(n,i)});const{cleanUrl:s,trailing:E}=g(o);s?e.push({type:"link",value:s}):e.push({type:"text",value:o}),E&&e.push({type:"text",value:E}),n=i+o.length}return n<t.length&&e.push({type:"text",value:t.slice(n)}),e.length?e:[{type:"text",value:t}]}exports.API_KEY_HEADER=c;exports.API_ROUTES=I;exports.APPLICATION_JSON=u;exports.CONTENT_TYPE_HEADER=O;exports.CUSTOM_PERIOD=N;exports.CalendarResolution=_;exports.HTTP_ERROR_CODES=S;exports.HttpError=p;exports.Locale=d;exports.OCP_APIM_SUBSCRIPTION_KEY_HEADER=l;exports.ONBOARDING_MODEL_POSTFIX=C;exports.QueryFilterType=R;exports.SHARE_CONVERSATION_ROUTE=h;exports.X_CONVERSATION_ID_HEADER=A;exports.cleanConversationNames=x;exports.defaultFormatNumbers=a;exports.formatNumberBySign=U;exports.getClearedConversationName=H;exports.getConversationId=f;exports.getConversationNavPath=y;exports.getConversationUrlWithoutLocale=$;exports.getHeaders=v;exports.getMultipartHeaders=L;exports.getTimePeriod=b;exports.isHttpError=D;exports.linkifyText=G;exports.parseBoolean=M;exports.sanitizeHeaders=B;exports.sendRequest=m;exports.splitTrailingPunctuation=g;
|
package/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const I = {
|
|
2
2
|
CHAT: "/api/chat"
|
|
3
|
-
},
|
|
3
|
+
}, S = "CUSTOM_PERIOD", a = {
|
|
4
4
|
decimal: "0.0",
|
|
5
5
|
decimalSymbol: ",",
|
|
6
6
|
digitGroupingSymbol: " "
|
|
7
|
-
},
|
|
7
|
+
}, T = "application/json", d = "Content-Type", l = "Api-Key", A = "X-CONVERSATION-ID", u = "Ocp-Apim-Subscription-Key", N = {
|
|
8
8
|
BAD_REQUEST: 400,
|
|
9
9
|
UNAUTHORIZED: 401,
|
|
10
10
|
FORBIDDEN: 403,
|
|
@@ -16,81 +16,115 @@ const g = {
|
|
|
16
16
|
BAD_GATEWAY: 502,
|
|
17
17
|
SERVICE_UNAVAILABLE: 503,
|
|
18
18
|
GATEWAY_TIMEOUT: 504
|
|
19
|
-
},
|
|
20
|
-
class
|
|
19
|
+
}, D = "onboarding", y = "share";
|
|
20
|
+
class C extends Error {
|
|
21
21
|
constructor(e) {
|
|
22
|
-
super(e.message), this.isHttpError = !0, this.name = "HttpError", this.status = e.status, this.details = e.details;
|
|
22
|
+
super(e.message), this.isHttpError = !0, this.name = "HttpError", this.code = e.code, this.status = e.status, this.details = e.details;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
return typeof t == "object" && t !== null && t.isHttpError === !0 && typeof t.status == "number" && typeof t.message == "string";
|
|
25
|
+
function f(t) {
|
|
26
|
+
return typeof t == "object" && t !== null && t.isHttpError === !0 && typeof t.status == "number" && typeof t.message == "string" && (t.code === void 0 || typeof t.code == "string");
|
|
27
27
|
}
|
|
28
|
-
var
|
|
29
|
-
function
|
|
28
|
+
var g = /* @__PURE__ */ ((t) => (t.MONTH = "month", t.DAY = "day", t))(g || {}), O = /* @__PURE__ */ ((t) => (t.UK = "uk", t.EN = "en", t))(O || {}), h = /* @__PURE__ */ ((t) => (t.IN = "in", t.BETWEEN = "between", t))(h || {});
|
|
29
|
+
function H(t, e) {
|
|
30
30
|
const n = t.split("/")[0], r = e.split("/").pop();
|
|
31
31
|
return `${n}/${r}`;
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const U = (t) => (t == null ? void 0 : t.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "").replace(/-/g, " ")) || "";
|
|
34
34
|
function b(t, e) {
|
|
35
35
|
return `${t == null ? void 0 : t[0]}/${e}/${t == null ? void 0 : t[1]}`;
|
|
36
36
|
}
|
|
37
|
-
const
|
|
38
|
-
const n = (e == null ? void 0 : e.decimal) ||
|
|
37
|
+
const R = (t, e) => (Math.round(t * 10 ** e) / 10 ** e).toString(), $ = (t, e) => {
|
|
38
|
+
const n = (e == null ? void 0 : e.decimal) || a.decimal, r = (e == null ? void 0 : e.decimalSymbol) || a.decimalSymbol, i = (e == null ? void 0 : e.digitGroupingSymbol) ?? a.digitGroupingSymbol, c = Number(t);
|
|
39
39
|
if (c == null || Number.isNaN(c) || t === null || t === "")
|
|
40
40
|
return "";
|
|
41
|
-
const
|
|
42
|
-
return
|
|
41
|
+
const s = n.replace("0.", ""), E = `${n === "0" ? Math.trunc(c) : R(c, s.length)} `.split(".");
|
|
42
|
+
return E[0] = E[0].replace(
|
|
43
43
|
/(\d)(?=(\d\d\d)+(?!\d))/g,
|
|
44
44
|
`$1${i}`
|
|
45
|
-
), `${
|
|
46
|
-
},
|
|
45
|
+
), `${E.join(r)}`;
|
|
46
|
+
}, x = (t) => isNaN(Date.parse(t)) ? null : new Date(t), B = (t, e, n) => {
|
|
47
47
|
const r = {
|
|
48
|
-
[
|
|
48
|
+
[d]: (e == null ? void 0 : e.contentType) || T
|
|
49
49
|
};
|
|
50
|
-
return e != null && e.jwt ? r.Authorization = `Bearer ${e.jwt}` : t && (r[
|
|
51
|
-
},
|
|
50
|
+
return e != null && e.jwt ? r.Authorization = `Bearer ${e.jwt}` : t && (r[l] = t), e != null && e.chatReference && (r[A] = e.chatReference), { ...r, ...n };
|
|
51
|
+
}, L = (t) => {
|
|
52
52
|
const e = { ...t };
|
|
53
|
-
return e[
|
|
54
|
-
},
|
|
53
|
+
return e[l] && (e[l] = e[l].substring(0, 8) + "...[REDACTED]"), e.Authorization && (e.Authorization = "Bearer [REDACTED]"), e[u] && (e[u] = e[u].substring(0, 8) + "...[REDACTED]"), e;
|
|
54
|
+
}, M = (t) => ({
|
|
55
55
|
"Content-Type": `multipart/form-data; boundary=${t}`
|
|
56
|
-
}),
|
|
56
|
+
}), v = (t) => (t == null ? void 0 : t.toLowerCase()) === "true", w = async (t, e, n) => await fetch(t, {
|
|
57
57
|
method: n.method || "GET",
|
|
58
58
|
headers: e,
|
|
59
59
|
body: n.body ? JSON.stringify(n.body) : void 0
|
|
60
|
-
}),
|
|
60
|
+
}), G = (t, e) => {
|
|
61
61
|
var n, r;
|
|
62
62
|
return (r = (n = t == null ? void 0 : t.split("/")) == null ? void 0 : n.filter((i) => i !== e)) == null ? void 0 : r.join("/");
|
|
63
63
|
}, Y = (t) => t.map((e) => ({
|
|
64
64
|
...e,
|
|
65
65
|
name: e.name.split(/-\d+$/)[0]
|
|
66
|
-
}))
|
|
66
|
+
})), p = /* @__PURE__ */ new Set([
|
|
67
|
+
")",
|
|
68
|
+
"]",
|
|
69
|
+
"}",
|
|
70
|
+
">",
|
|
71
|
+
",",
|
|
72
|
+
".",
|
|
73
|
+
"!",
|
|
74
|
+
"?",
|
|
75
|
+
":",
|
|
76
|
+
";"
|
|
77
|
+
]);
|
|
78
|
+
function _(t) {
|
|
79
|
+
let e = t.length;
|
|
80
|
+
for (; e > 0 && p.has(t[e - 1]); )
|
|
81
|
+
e--;
|
|
82
|
+
return e === t.length ? { cleanUrl: t, trailing: "" } : {
|
|
83
|
+
cleanUrl: t.slice(0, e),
|
|
84
|
+
trailing: t.slice(e)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function j(t) {
|
|
88
|
+
if (!t) return [{ type: "text", value: "" }];
|
|
89
|
+
const e = [];
|
|
90
|
+
let n = 0;
|
|
91
|
+
for (const r of t.matchAll(/\bhttps?:\/\/[^\s<>"']+/gi)) {
|
|
92
|
+
const i = r[0], c = r.index ?? 0;
|
|
93
|
+
c > n && e.push({ type: "text", value: t.slice(n, c) });
|
|
94
|
+
const { cleanUrl: s, trailing: o } = _(i);
|
|
95
|
+
s ? e.push({ type: "link", value: s }) : e.push({ type: "text", value: i }), o && e.push({ type: "text", value: o }), n = c + i.length;
|
|
96
|
+
}
|
|
97
|
+
return n < t.length && e.push({ type: "text", value: t.slice(n) }), e.length ? e : [{ type: "text", value: t }];
|
|
98
|
+
}
|
|
67
99
|
export {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
l as API_KEY_HEADER,
|
|
101
|
+
I as API_ROUTES,
|
|
102
|
+
T as APPLICATION_JSON,
|
|
103
|
+
d as CONTENT_TYPE_HEADER,
|
|
104
|
+
S as CUSTOM_PERIOD,
|
|
105
|
+
g as CalendarResolution,
|
|
106
|
+
N as HTTP_ERROR_CODES,
|
|
107
|
+
C as HttpError,
|
|
108
|
+
O as Locale,
|
|
109
|
+
u as OCP_APIM_SUBSCRIPTION_KEY_HEADER,
|
|
110
|
+
D as ONBOARDING_MODEL_POSTFIX,
|
|
111
|
+
h as QueryFilterType,
|
|
112
|
+
y as SHARE_CONVERSATION_ROUTE,
|
|
113
|
+
A as X_CONVERSATION_ID_HEADER,
|
|
82
114
|
Y as cleanConversationNames,
|
|
83
|
-
|
|
115
|
+
a as defaultFormatNumbers,
|
|
84
116
|
$ as formatNumberBySign,
|
|
85
|
-
|
|
117
|
+
U as getClearedConversationName,
|
|
86
118
|
b as getConversationId,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
119
|
+
H as getConversationNavPath,
|
|
120
|
+
G as getConversationUrlWithoutLocale,
|
|
121
|
+
B as getHeaders,
|
|
122
|
+
M as getMultipartHeaders,
|
|
123
|
+
x as getTimePeriod,
|
|
124
|
+
f as isHttpError,
|
|
125
|
+
j as linkifyText,
|
|
126
|
+
v as parseBoolean,
|
|
127
|
+
L as sanitizeHeaders,
|
|
128
|
+
w as sendRequest,
|
|
129
|
+
_ as splitTrailingPunctuation
|
|
96
130
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export interface HttpErrorPayload<D = unknown> {
|
|
2
2
|
status: number;
|
|
3
|
+
code?: string;
|
|
3
4
|
message: string;
|
|
4
5
|
details?: D;
|
|
5
6
|
}
|
|
6
7
|
export declare class HttpError<D = unknown> extends Error {
|
|
8
|
+
readonly code?: string;
|
|
7
9
|
readonly status: number;
|
|
8
10
|
readonly details?: D;
|
|
9
11
|
readonly isHttpError = true;
|
package/package.json
CHANGED
package/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type LinkifiedPart = {
|
|
2
|
+
type: 'text';
|
|
3
|
+
value: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: 'link';
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function splitTrailingPunctuation(url: string): {
|
|
9
|
+
cleanUrl: string;
|
|
10
|
+
trailing: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Splits input into text + link parts.
|
|
14
|
+
* - Only http/https are linkified.
|
|
15
|
+
* - Trailing punctuation is split off into a following text part.
|
|
16
|
+
*/
|
|
17
|
+
export declare function linkifyText(input: string): LinkifiedPart[];
|
|
18
|
+
export {};
|