@epam/statgpt-shared-toolkit 0.4.0-rc.3 → 0.4.0-rc.30
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 +70 -62
- package/models/index.d.ts +0 -1
- package/package.json +1 -1
- package/utils/index.d.ts +0 -1
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("date-fns"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("date-fns"),f={CHAT:"/api/chat"},R="CUSTOM_PERIOD",l={decimal:"0.0",decimalSymbol:",",digitGroupingSymbol:" "},A="application/json",T="Content-Type",a="Api-Key",N="X-CONVERSATION-ID",u="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},y="onboarding",v="share";class D 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 U(t){const e=t;return typeof t=="object"&&t!==null&&e.isHttpError===!0&&typeof e.status=="number"&&typeof e.message=="string"&&(e.code===void 0||typeof e.code=="string")}var C=(t=>(t.MONTH="month",t.DAY="day",t))(C||{}),O=(t=>(t.UK="uk",t.EN="en",t))(O||{}),_=(t=>(t.IN="in",t.BETWEEN="between",t))(_||{});function b(t,e){const n=t.split("/")[0],r=e.split("/").pop();return`${n}/${r}`}const g=t=>t.messages.flatMap(e=>{const n=e.custom_content?.attachments??[],r=e.custom_content?.stages?.flatMap(({attachments:o})=>o??[])??[];return[...n,...r]}),P=t=>t.endsWith("/"),H=t=>{const e=t.toLowerCase();return e.startsWith("http://")||e.startsWith("https://")},h=t=>!!t&&!H(t)&&!P(t),M=t=>[...new Set(g(t).map(e=>e.url).filter(e=>!!e).filter(e=>h(e)))],p=(t,e)=>t?.map(n=>({...n,url:n.url?e[n.url]??n.url:n.url})),F=(t,e)=>({...t,messages:t.messages.map(n=>({...n,custom_content:n.custom_content?{...n.custom_content,attachments:p(n.custom_content.attachments,e),stages:n.custom_content.stages?.map(r=>({...r,attachments:p(r.attachments,e)}))}:n.custom_content}))}),m=t=>t?.split(/-\d+$/)[0]??"",B=t=>new RegExp("\\p{L}","u").test(t)||new RegExp("\\p{N}","u").test(t),L=t=>{if(!t)return"";const e=t.toLowerCase(),n=[];let r="";for(const o of e)B(o)?r+=o:r&&(n.push(r),r="");return r&&n.push(r),n.join(" ")};function w(t,e){return`${t?.[0]}/${e}/${t?.[1]}`}const x=(t,e)=>(Math.round(t*10**e)/10**e).toString(),$=(t,e)=>{const n=e?.decimal||l.decimal,r=e?.decimalSymbol||l.decimalSymbol,o=e?.digitGroupingSymbol??l.digitGroupingSymbol,s=Number(t);if(s==null||Number.isNaN(s)||t===null||t==="")return"";const i=n.replace("0.",""),E=`${n==="0"?Math.trunc(s):x(s,i.length)} `.split(".");return E[0]=E[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,`$1${o}`),`${E.join(r)}`},G=t=>{if(!t.includes("T")){for(const n of V){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},V=["yyyy-MM-dd","MM-dd-yyyy"],Y=(t,e,n)=>{const r={};return e?.contentType!==null&&(r[T]=e?.contentType||A),e?.jwt?r.Authorization=`Bearer ${e.jwt}`:t&&(r[a]=t),e?.chatReference&&(r[N]=e.chatReference),{...r,...n}},j=t=>{const e={...t};return e[a]&&(e[a]=e[a].substring(0,8)+"...[REDACTED]"),e.Authorization&&(e.Authorization="Bearer [REDACTED]"),e[u]&&(e[u]=e[u].substring(0,8)+"...[REDACTED]"),e},W=t=>({"Content-Type":`multipart/form-data; boundary=${t}`}),z=t=>t?.toLowerCase()==="true",K=async(t,e,n)=>await fetch(t,{method:n.method||"GET",headers:e,body:n.body?JSON.stringify(n.body):void 0}),k=(t,e)=>t?.split("/")?.filter(n=>n!==e)?.join("/"),X=t=>t.replace(/^conversations\//,""),q=t=>t.split("/").slice(0,-1).join("/"),J=t=>m(decodeURIComponent(t.split("/").at(-1)??"")),Q=t=>t.map(e=>({...e,name:m(e.name)})),Z=new Set([")","]","}",">",",",".","!","?",":",";"]);function I(t){let e=t.length;for(;e>0&&Z.has(t[e-1]);)e--;return e===t.length?{cleanUrl:t,trailing:""}:{cleanUrl:t.slice(0,e),trailing:t.slice(e)}}function tt(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],s=r.index??0;s>n&&e.push({type:"text",value:t.slice(n,s)});const{cleanUrl:i,trailing:d}=I(o);i?e.push({type:"link",value:i}):e.push({type:"text",value:o}),d&&e.push({type:"text",value:d}),n=s+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=a;exports.API_ROUTES=f;exports.APPLICATION_JSON=A;exports.CONTENT_TYPE_HEADER=T;exports.CUSTOM_PERIOD=R;exports.CalendarResolution=C;exports.HTTP_ERROR_CODES=S;exports.HttpError=D;exports.Locale=O;exports.OCP_APIM_SUBSCRIPTION_KEY_HEADER=u;exports.ONBOARDING_MODEL_POSTFIX=y;exports.QueryFilterType=_;exports.SHARE_CONVERSATION_ROUTE=v;exports.X_CONVERSATION_ID_HEADER=N;exports.cleanConversationNames=Q;exports.defaultFormatNumbers=l;exports.deleteConversationNamePostfix=m;exports.formatNumberBySign=$;exports.getClearedConversationName=L;exports.getConversationAttachmentUrls=M;exports.getConversationAttachments=g;exports.getConversationFolderIdFromConversationId=q;exports.getConversationId=w;exports.getConversationIdFromResourceUrl=X;exports.getConversationNameFromConversationId=J;exports.getConversationNavPath=b;exports.getConversationUrlWithoutLocale=k;exports.getHeaders=Y;exports.getMultipartHeaders=W;exports.getTimePeriod=G;exports.isDialFileAttachmentUrl=h;exports.isHttpError=U;exports.linkifyText=tt;exports.parseBoolean=z;exports.replaceConversationAttachmentUrls=F;exports.sanitizeHeaders=j;exports.sendRequest=K;exports.splitTrailingPunctuation=I;
|
package/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { parse as h, isValid as
|
|
2
|
-
const
|
|
1
|
+
import { parse as h, isValid as m, parseISO as f } from "date-fns";
|
|
2
|
+
const H = {
|
|
3
3
|
CHAT: "/api/chat"
|
|
4
|
-
},
|
|
4
|
+
}, w = "CUSTOM_PERIOD", u = {
|
|
5
5
|
decimal: "0.0",
|
|
6
6
|
decimalSymbol: ",",
|
|
7
7
|
digitGroupingSymbol: " "
|
|
8
|
-
},
|
|
8
|
+
}, A = "application/json", T = "Content-Type", i = "Api-Key", N = "X-CONVERSATION-ID", d = "Ocp-Apim-Subscription-Key", x = {
|
|
9
9
|
BAD_REQUEST: 400,
|
|
10
10
|
UNAUTHORIZED: 401,
|
|
11
11
|
FORBIDDEN: 403,
|
|
@@ -17,17 +17,18 @@ const M = {
|
|
|
17
17
|
BAD_GATEWAY: 502,
|
|
18
18
|
SERVICE_UNAVAILABLE: 503,
|
|
19
19
|
GATEWAY_TIMEOUT: 504
|
|
20
|
-
}, B = "onboarding",
|
|
21
|
-
class
|
|
20
|
+
}, B = "onboarding", L = "share";
|
|
21
|
+
class P extends Error {
|
|
22
22
|
constructor(e) {
|
|
23
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;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
function $(t) {
|
|
27
|
-
|
|
27
|
+
const e = t;
|
|
28
|
+
return typeof t == "object" && t !== null && e.isHttpError === !0 && typeof e.status == "number" && typeof e.message == "string" && (e.code === void 0 || typeof e.code == "string");
|
|
28
29
|
}
|
|
29
|
-
var
|
|
30
|
-
function
|
|
30
|
+
var g = /* @__PURE__ */ ((t) => (t.MONTH = "month", t.DAY = "day", t))(g || {}), O = /* @__PURE__ */ ((t) => (t.UK = "uk", t.EN = "en", t))(O || {}), _ = /* @__PURE__ */ ((t) => (t.IN = "in", t.BETWEEN = "between", t))(_ || {});
|
|
31
|
+
function F(t, e) {
|
|
31
32
|
const n = t.split("/")[0], r = e.split("/").pop();
|
|
32
33
|
return `${n}/${r}`;
|
|
33
34
|
}
|
|
@@ -39,14 +40,14 @@ const I = (t) => t.messages.flatMap((e) => {
|
|
|
39
40
|
}), C = (t) => t.endsWith("/"), y = (t) => {
|
|
40
41
|
const e = t.toLowerCase();
|
|
41
42
|
return e.startsWith("http://") || e.startsWith("https://");
|
|
42
|
-
}, R = (t) => !!t && !y(t) && !C(t),
|
|
43
|
+
}, R = (t) => !!t && !y(t) && !C(t), G = (t) => [
|
|
43
44
|
...new Set(
|
|
44
45
|
I(t).map((e) => e.url).filter((e) => !!e).filter((e) => R(e))
|
|
45
46
|
)
|
|
46
47
|
], p = (t, e) => t?.map((n) => ({
|
|
47
48
|
...n,
|
|
48
49
|
url: n.url ? e[n.url] ?? n.url : n.url
|
|
49
|
-
})),
|
|
50
|
+
})), j = (t, e) => ({
|
|
50
51
|
...t,
|
|
51
52
|
messages: t.messages.map((n) => ({
|
|
52
53
|
...n,
|
|
@@ -65,48 +66,55 @@ const I = (t) => t.messages.flatMap((e) => {
|
|
|
65
66
|
}))
|
|
66
67
|
} : n.custom_content
|
|
67
68
|
}))
|
|
68
|
-
}), E = (t) => t?.split(/-\d+$/)[0] ?? "",
|
|
69
|
-
|
|
69
|
+
}), E = (t) => t?.split(/-\d+$/)[0] ?? "", S = (t) => new RegExp("\\p{L}", "u").test(t) || new RegExp("\\p{N}", "u").test(t), W = (t) => {
|
|
70
|
+
if (!t) return "";
|
|
71
|
+
const e = t.toLowerCase(), n = [];
|
|
72
|
+
let r = "";
|
|
73
|
+
for (const s of e)
|
|
74
|
+
S(s) ? r += s : r && (n.push(r), r = "");
|
|
75
|
+
return r && n.push(r), n.join(" ");
|
|
76
|
+
};
|
|
77
|
+
function V(t, e) {
|
|
70
78
|
return `${t?.[0]}/${e}/${t?.[1]}`;
|
|
71
79
|
}
|
|
72
|
-
const
|
|
80
|
+
const D = (t, e) => (Math.round(t * 10 ** e) / 10 ** e).toString(), Y = (t, e) => {
|
|
73
81
|
const n = e?.decimal || u.decimal, r = e?.decimalSymbol || u.decimalSymbol, s = e?.digitGroupingSymbol ?? u.digitGroupingSymbol, o = Number(t);
|
|
74
82
|
if (o == null || Number.isNaN(o) || t === null || t === "")
|
|
75
83
|
return "";
|
|
76
|
-
const
|
|
84
|
+
const c = n.replace("0.", ""), l = `${n === "0" ? Math.trunc(o) : D(o, c.length)} `.split(".");
|
|
77
85
|
return l[0] = l[0].replace(
|
|
78
86
|
/(\d)(?=(\d\d\d)+(?!\d))/g,
|
|
79
87
|
`$1${s}`
|
|
80
88
|
), `${l.join(r)}`;
|
|
81
|
-
},
|
|
89
|
+
}, z = (t) => {
|
|
82
90
|
if (!t.includes("T")) {
|
|
83
|
-
for (const n of
|
|
91
|
+
for (const n of b) {
|
|
84
92
|
const r = h(t, n, /* @__PURE__ */ new Date());
|
|
85
|
-
if (
|
|
93
|
+
if (m(r))
|
|
86
94
|
return r;
|
|
87
95
|
}
|
|
88
96
|
return null;
|
|
89
97
|
}
|
|
90
|
-
const e =
|
|
91
|
-
return
|
|
92
|
-
},
|
|
98
|
+
const e = f(t);
|
|
99
|
+
return m(e) ? e : null;
|
|
100
|
+
}, b = ["yyyy-MM-dd", "MM-dd-yyyy"], k = (t, e, n) => {
|
|
93
101
|
const r = {};
|
|
94
|
-
return e?.contentType !== null && (r[
|
|
95
|
-
},
|
|
102
|
+
return e?.contentType !== null && (r[T] = e?.contentType || A), e?.jwt ? r.Authorization = `Bearer ${e.jwt}` : t && (r[i] = t), e?.chatReference && (r[N] = e.chatReference), { ...r, ...n };
|
|
103
|
+
}, K = (t) => {
|
|
96
104
|
const e = { ...t };
|
|
97
|
-
return e[
|
|
98
|
-
},
|
|
105
|
+
return e[i] && (e[i] = e[i].substring(0, 8) + "...[REDACTED]"), e.Authorization && (e.Authorization = "Bearer [REDACTED]"), e[d] && (e[d] = e[d].substring(0, 8) + "...[REDACTED]"), e;
|
|
106
|
+
}, X = (t) => ({
|
|
99
107
|
"Content-Type": `multipart/form-data; boundary=${t}`
|
|
100
|
-
}),
|
|
108
|
+
}), J = (t) => t?.toLowerCase() === "true", q = async (t, e, n) => await fetch(t, {
|
|
101
109
|
method: n.method || "GET",
|
|
102
110
|
headers: e,
|
|
103
111
|
body: n.body ? JSON.stringify(n.body) : void 0
|
|
104
|
-
}),
|
|
112
|
+
}), Q = (t, e) => t?.split("/")?.filter((n) => n !== e)?.join("/"), Z = (t) => t.replace(/^conversations\//, ""), tt = (t) => t.split("/").slice(0, -1).join("/"), et = (t) => E(
|
|
105
113
|
decodeURIComponent(t.split("/").at(-1) ?? "")
|
|
106
|
-
),
|
|
114
|
+
), nt = (t) => t.map((e) => ({
|
|
107
115
|
...e,
|
|
108
116
|
name: E(e.name)
|
|
109
|
-
})),
|
|
117
|
+
})), U = /* @__PURE__ */ new Set([
|
|
110
118
|
")",
|
|
111
119
|
"]",
|
|
112
120
|
"}",
|
|
@@ -120,62 +128,62 @@ const S = (t, e) => (Math.round(t * 10 ** e) / 10 ** e).toString(), V = (t, e) =
|
|
|
120
128
|
]);
|
|
121
129
|
function v(t) {
|
|
122
130
|
let e = t.length;
|
|
123
|
-
for (; e > 0 &&
|
|
131
|
+
for (; e > 0 && U.has(t[e - 1]); )
|
|
124
132
|
e--;
|
|
125
133
|
return e === t.length ? { cleanUrl: t, trailing: "" } : {
|
|
126
134
|
cleanUrl: t.slice(0, e),
|
|
127
135
|
trailing: t.slice(e)
|
|
128
136
|
};
|
|
129
137
|
}
|
|
130
|
-
function
|
|
138
|
+
function rt(t) {
|
|
131
139
|
if (!t) return [{ type: "text", value: "" }];
|
|
132
140
|
const e = [];
|
|
133
141
|
let n = 0;
|
|
134
142
|
for (const r of t.matchAll(/\bhttps?:\/\/[^\s<>"']+/gi)) {
|
|
135
143
|
const s = r[0], o = r.index ?? 0;
|
|
136
144
|
o > n && e.push({ type: "text", value: t.slice(n, o) });
|
|
137
|
-
const { cleanUrl:
|
|
138
|
-
|
|
145
|
+
const { cleanUrl: c, trailing: a } = v(s);
|
|
146
|
+
c ? e.push({ type: "link", value: c }) : e.push({ type: "text", value: s }), a && e.push({ type: "text", value: a }), n = o + s.length;
|
|
139
147
|
}
|
|
140
148
|
return n < t.length && e.push({ type: "text", value: t.slice(n) }), e.length ? e : [{ type: "text", value: t }];
|
|
141
149
|
}
|
|
142
150
|
export {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
i as API_KEY_HEADER,
|
|
152
|
+
H as API_ROUTES,
|
|
153
|
+
A as APPLICATION_JSON,
|
|
154
|
+
T as CONTENT_TYPE_HEADER,
|
|
155
|
+
w as CUSTOM_PERIOD,
|
|
156
|
+
g as CalendarResolution,
|
|
149
157
|
x as HTTP_ERROR_CODES,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
P as HttpError,
|
|
159
|
+
O as Locale,
|
|
160
|
+
d as OCP_APIM_SUBSCRIPTION_KEY_HEADER,
|
|
153
161
|
B as ONBOARDING_MODEL_POSTFIX,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
162
|
+
_ as QueryFilterType,
|
|
163
|
+
L as SHARE_CONVERSATION_ROUTE,
|
|
164
|
+
N as X_CONVERSATION_ID_HEADER,
|
|
165
|
+
nt as cleanConversationNames,
|
|
158
166
|
u as defaultFormatNumbers,
|
|
159
167
|
E as deleteConversationNamePostfix,
|
|
160
|
-
|
|
168
|
+
Y as formatNumberBySign,
|
|
161
169
|
W as getClearedConversationName,
|
|
162
|
-
|
|
170
|
+
G as getConversationAttachmentUrls,
|
|
163
171
|
I as getConversationAttachments,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
tt as getConversationFolderIdFromConversationId,
|
|
173
|
+
V as getConversationId,
|
|
174
|
+
Z as getConversationIdFromResourceUrl,
|
|
175
|
+
et as getConversationNameFromConversationId,
|
|
176
|
+
F as getConversationNavPath,
|
|
177
|
+
Q as getConversationUrlWithoutLocale,
|
|
178
|
+
k as getHeaders,
|
|
179
|
+
X as getMultipartHeaders,
|
|
180
|
+
z as getTimePeriod,
|
|
173
181
|
R as isDialFileAttachmentUrl,
|
|
174
182
|
$ as isHttpError,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
rt as linkifyText,
|
|
184
|
+
J as parseBoolean,
|
|
185
|
+
j as replaceConversationAttachmentUrls,
|
|
186
|
+
K as sanitizeHeaders,
|
|
187
|
+
q as sendRequest,
|
|
180
188
|
v as splitTrailingPunctuation
|
|
181
189
|
};
|
package/models/index.d.ts
CHANGED
package/package.json
CHANGED