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