@epam/statgpt-shared-toolkit 0.3.0-rc.7 → 0.3.0-rc.9

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