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