@epam/statgpt-shared-toolkit 0.1.0-rc.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 EPAM Systems
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Shared Toolkit
2
+
3
+ This library contains shared utilities, helper functions,
4
+ and common logic used across multiple modules in the StatGPT portal frontend.
5
+ It promotes code reuse and consistency throughout the project.
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/mit)
8
+ [![Typescript](https://img.shields.io/badge/Typescript-5+-61dafb.svg)](https://www.typescriptlang.org/)
9
+
10
+
11
+ ## Table of Contents
12
+
13
+ - [Features](#features)
14
+ - [Installation](#installation)
15
+ - [Usage](#usage)
16
+ - [Contributing](#contributing)
17
+ - [Security](#security)
18
+ - [License](#license)
19
+
20
+ ## Features
21
+
22
+ - Common utility functions
23
+ - Shared type definitions
24
+ - Reusable helpers for data processing and formatting
25
+ - Navigation path utilities
26
+ - Lightweight and minimal dependencies
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install @epam/statgpt-shared-toolkit
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```typescript
37
+ import { getConversationNavPath } from '@epam/statgpt-shared-toolkit';
38
+
39
+ const navPath = getConversationNavPath(folderId, conversationKey);
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ We welcome contributions! Please see our [Contributing Guide](https://github.com/epam/statgpt-portal-frontend/blob/development/CONTRIBUTING.md) for details on:
45
+
46
+ - Testing requirements
47
+ - Pull request process
48
+
49
+
50
+ ## Security
51
+
52
+ If you discover a security vulnerability, please refer to our [Security Policy](https://github.com/epam/statgpt-portal-frontend/blob/development/SECURITY.md).
53
+
54
+
55
+ ## License
56
+
57
+ [MIT](https://github.com/epam/statgpt-portal-frontend/blob/development/LICENSE) - see the [LICENSE](https://github.com/epam/statgpt-portal-frontend/blob/development/LICENSE) file for details.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * API route constants for Next.js app routes
3
+ */
4
+ export declare const API_ROUTES: {
5
+ readonly CHAT: "/api/chat";
6
+ };
@@ -0,0 +1 @@
1
+ export declare const CUSTOM_PERIOD = "CUSTOM_PERIOD";
@@ -0,0 +1,2 @@
1
+ import { FormatNumbersType } from '../models/format-numbers-type';
2
+ export declare const defaultFormatNumbers: FormatNumbersType;
@@ -0,0 +1,4 @@
1
+ export declare const APPLICATION_JSON = "application/json";
2
+ export declare const CONTENT_TYPE_HEADER = "Content-Type";
3
+ export declare const API_KEY_HEADER = "Api-Key";
4
+ export declare const X_CONVERSATION_ID_HEADER = "X-CONVERSATION-ID";
@@ -0,0 +1,4 @@
1
+ export * from './api-urls';
2
+ export * from './calendar';
3
+ export * from './format-numbers-default';
4
+ export * from './headers';
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './constants';
2
+ export * from './models';
3
+ export * from './types';
4
+ export * from './utils';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S={CHAT:"/api/chat"},s="CUSTOM_PERIOD",o={decimal:"0.0",decimalSymbol:",",digitGroupingSymbol:" "},d="application/json",E="Content-Type",c="Api-Key",u="X-CONVERSATION-ID";var g=(e=>(e.MONTH="month",e.DAY="day",e))(g||{}),T=(e=>(e.UK="uk",e.EN="en",e))(T||{}),C=(e=>(e.IN="in",e.BETWEEN="between",e))(C||{});function O(e,t){const n=e.split("/")[0],r=t.split("/").pop();return`${n}/${r}`}const I=e=>(e==null?void 0:e.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").replace(/-/g," "))||"";function N(e,t){return`${e==null?void 0:e[0]}/${t}/${e==null?void 0:e[1]}`}const _=(e,t)=>(Math.round(e*10**t)/10**t).toFixed(t),y=(e,t)=>{const n=(t==null?void 0:t.decimal)||o.decimal,r=(t==null?void 0:t.decimalSymbol)||o.decimalSymbol,a=(t==null?void 0:t.digitGroupingSymbol)??o.digitGroupingSymbol,i=Number(e);if(i==null||Number.isNaN(i)||e===null||e==="")return"";const A=n.replace("0.",""),l=`${n==="0"?Math.trunc(i):_(i,A.length)} `.split(".");return l[0]=l[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g,`$1${a}`),`${l.join(r)}`},R=e=>isNaN(Date.parse(e))?null:new Date(e),D=(e,t,n)=>{const r={[E]:(t==null?void 0:t.contentType)||d};return t!=null&&t.jwt?r.Authorization=`Bearer ${t.jwt}`:e&&(r[c]=e),t!=null&&t.chatReference&&(r[u]=t.chatReference),{...r,...n}},h=e=>{const t={...e};return t[c]&&(t[c]=t[c].substring(0,8)+"...[REDACTED]"),t.Authorization&&(t.Authorization="Bearer [REDACTED]"),t},b=e=>(e==null?void 0:e.toLowerCase())==="true",H=async(e,t,n)=>await fetch(e,{method:n.method||"GET",headers:t,body:n.body?JSON.stringify(n.body):void 0}),$=(e,t)=>{var n,r;return(r=(n=e==null?void 0:e.split("/"))==null?void 0:n.filter(a=>a!==t))==null?void 0:r.join("/")};exports.API_KEY_HEADER=c;exports.API_ROUTES=S;exports.APPLICATION_JSON=d;exports.CONTENT_TYPE_HEADER=E;exports.CUSTOM_PERIOD=s;exports.CalendarResolution=g;exports.Locale=T;exports.QueryFilterType=C;exports.X_CONVERSATION_ID_HEADER=u;exports.defaultFormatNumbers=o;exports.formatNumberBySign=y;exports.getClearedConversationName=I;exports.getConversationId=N;exports.getConversationNavPath=O;exports.getConversationUrlWithoutLocale=$;exports.getHeaders=D;exports.getTimePeriod=R;exports.parseBoolean=b;exports.sanitizeHeaders=h;exports.sendRequest=H;
package/index.mjs ADDED
@@ -0,0 +1,63 @@
1
+ const h = {
2
+ CHAT: "/api/chat"
3
+ }, D = "CUSTOM_PERIOD", o = {
4
+ decimal: "0.0",
5
+ decimalSymbol: ",",
6
+ digitGroupingSymbol: " "
7
+ }, E = "application/json", g = "Content-Type", i = "Api-Key", S = "X-CONVERSATION-ID";
8
+ var a = /* @__PURE__ */ ((t) => (t.MONTH = "month", t.DAY = "day", t))(a || {}), A = /* @__PURE__ */ ((t) => (t.UK = "uk", t.EN = "en", t))(A || {}), T = /* @__PURE__ */ ((t) => (t.IN = "in", t.BETWEEN = "between", t))(T || {});
9
+ function I(t, e) {
10
+ const n = t.split("/")[0], c = e.split("/").pop();
11
+ return `${n}/${c}`;
12
+ }
13
+ const O = (t) => (t == null ? void 0 : t.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "-").replace(/^-+|-+$/g, "").replace(/-/g, " ")) || "";
14
+ function R(t, e) {
15
+ return `${t == null ? void 0 : t[0]}/${e}/${t == null ? void 0 : t[1]}`;
16
+ }
17
+ const C = (t, e) => (Math.round(t * 10 ** e) / 10 ** e).toFixed(e), N = (t, e) => {
18
+ const n = (e == null ? void 0 : e.decimal) || o.decimal, c = (e == null ? void 0 : e.decimalSymbol) || o.decimalSymbol, d = (e == null ? void 0 : e.digitGroupingSymbol) ?? o.digitGroupingSymbol, r = Number(t);
19
+ if (r == null || Number.isNaN(r) || t === null || t === "")
20
+ return "";
21
+ const u = n.replace("0.", ""), l = `${n === "0" ? Math.trunc(r) : C(r, u.length)} `.split(".");
22
+ return l[0] = l[0].replace(
23
+ /(\d)(?=(\d\d\d)+(?!\d))/g,
24
+ `$1${d}`
25
+ ), `${l.join(c)}`;
26
+ }, _ = (t) => isNaN(Date.parse(t)) ? null : new Date(t), $ = (t, e, n) => {
27
+ const c = {
28
+ [g]: (e == null ? void 0 : e.contentType) || E
29
+ };
30
+ return e != null && e.jwt ? c.Authorization = `Bearer ${e.jwt}` : t && (c[i] = t), e != null && e.chatReference && (c[S] = e.chatReference), { ...c, ...n };
31
+ }, b = (t) => {
32
+ const e = { ...t };
33
+ return e[i] && (e[i] = e[i].substring(0, 8) + "...[REDACTED]"), e.Authorization && (e.Authorization = "Bearer [REDACTED]"), e;
34
+ }, s = (t) => (t == null ? void 0 : t.toLowerCase()) === "true", p = async (t, e, n) => await fetch(t, {
35
+ method: n.method || "GET",
36
+ headers: e,
37
+ body: n.body ? JSON.stringify(n.body) : void 0
38
+ }), w = (t, e) => {
39
+ var n, c;
40
+ return (c = (n = t == null ? void 0 : t.split("/")) == null ? void 0 : n.filter((d) => d !== e)) == null ? void 0 : c.join("/");
41
+ };
42
+ export {
43
+ i as API_KEY_HEADER,
44
+ h as API_ROUTES,
45
+ E as APPLICATION_JSON,
46
+ g as CONTENT_TYPE_HEADER,
47
+ D as CUSTOM_PERIOD,
48
+ a as CalendarResolution,
49
+ A as Locale,
50
+ T as QueryFilterType,
51
+ S as X_CONVERSATION_ID_HEADER,
52
+ o as defaultFormatNumbers,
53
+ N as formatNumberBySign,
54
+ O as getClearedConversationName,
55
+ R as getConversationId,
56
+ I as getConversationNavPath,
57
+ w as getConversationUrlWithoutLocale,
58
+ $ as getHeaders,
59
+ _ as getTimePeriod,
60
+ s as parseBoolean,
61
+ b as sanitizeHeaders,
62
+ p as sendRequest
63
+ };
@@ -0,0 +1,7 @@
1
+ import { API_KEY_HEADER, CONTENT_TYPE_HEADER, X_CONVERSATION_ID_HEADER } from '../constants/headers';
2
+ export interface ApiHeaders {
3
+ Authorization?: string;
4
+ [CONTENT_TYPE_HEADER]?: string;
5
+ [API_KEY_HEADER]?: string;
6
+ [X_CONVERSATION_ID_HEADER]?: string;
7
+ }
@@ -0,0 +1,33 @@
1
+ import { QueryFilterType } from '../types/query-filter-type';
2
+ export interface DataQuery {
3
+ title?: string;
4
+ urn: string;
5
+ metadata: {
6
+ countryDimension: string;
7
+ indicatorDimensions: string[];
8
+ };
9
+ filters: QueryFilter[];
10
+ }
11
+ export interface JsonDataQuery {
12
+ urn: string;
13
+ metadata: {
14
+ country_dimension?: string;
15
+ countryDimension: string;
16
+ indicator_dimensions?: string[];
17
+ indicatorDimensions: string[];
18
+ };
19
+ filters: JsonQueryFilter[];
20
+ }
21
+ export interface QueryFilter {
22
+ componentCode: string;
23
+ operator: QueryFilterType;
24
+ values: string[];
25
+ }
26
+ export interface JsonQueryFilter extends QueryFilter {
27
+ component_code: string;
28
+ }
29
+ export interface QueryFilterDetails {
30
+ id: string;
31
+ title?: string;
32
+ valuesTitles?: string[];
33
+ }
@@ -0,0 +1,5 @@
1
+ export interface FormatNumbersType {
2
+ decimal: string;
3
+ decimalSymbol: string;
4
+ digitGroupingSymbol: string;
5
+ }
@@ -0,0 +1,6 @@
1
+ export * from './api';
2
+ export * from './data-query';
3
+ export * from './format-numbers-type';
4
+ export * from './log-data';
5
+ export * from './request-options';
6
+ export * from './time-range';
@@ -0,0 +1,6 @@
1
+ export interface LogData {
2
+ method: string;
3
+ url: string;
4
+ headers: Record<string, string>;
5
+ body?: unknown;
6
+ }
@@ -0,0 +1,8 @@
1
+ export interface RequestOptions {
2
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
3
+ body?: unknown;
4
+ headers?: Record<string, string>;
5
+ jwt?: string;
6
+ chatReference?: string;
7
+ signal?: AbortSignal;
8
+ }
@@ -0,0 +1,8 @@
1
+ export interface TimeRange {
2
+ startPeriod: Date | null;
3
+ endPeriod: Date | null;
4
+ }
5
+ export interface TimeRangeOptions {
6
+ value: number | string;
7
+ title: string;
8
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@epam/statgpt-shared-toolkit",
3
+ "version": "0.1.0-rc.0",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./index.mjs",
8
+ "require": "./index.cjs",
9
+ "types": "./index.d.ts"
10
+ }
11
+ },
12
+ "main": "./index.cjs",
13
+ "browser": "./index.mjs",
14
+ "module": "./index.mjs",
15
+ "types": "./index.d.ts",
16
+ "dependencies": {
17
+ "@epam/ai-dial-shared": "^0.34.0"
18
+ }
19
+ }
@@ -0,0 +1,4 @@
1
+ export declare enum CalendarResolution {
2
+ MONTH = "month",
3
+ DAY = "day"
4
+ }
@@ -0,0 +1,3 @@
1
+ export * from './calendar';
2
+ export * from './locale';
3
+ export * from './query-filter-type';
@@ -0,0 +1,4 @@
1
+ export declare enum Locale {
2
+ UK = "uk",
3
+ EN = "en"
4
+ }
@@ -0,0 +1,4 @@
1
+ export declare enum QueryFilterType {
2
+ IN = "in",
3
+ BETWEEN = "between"
4
+ }
@@ -0,0 +1 @@
1
+ export declare function getConversationNavPath(folderId: string, conversationKey: string): string;
@@ -0,0 +1,2 @@
1
+ import { ConversationInfo } from '@epam/ai-dial-shared';
2
+ export declare const cleanConversationNames: (conversations: ConversationInfo[]) => ConversationInfo[];
@@ -0,0 +1 @@
1
+ export declare const getClearedConversationName: (conversationName?: string) => string;
@@ -0,0 +1 @@
1
+ export declare function getConversationId(idParams: string[], locale: string): string;
@@ -0,0 +1 @@
1
+ export declare const getConversationUrlWithoutLocale: (resourceUrl: string, locale: string) => string;
@@ -0,0 +1,2 @@
1
+ import { FormatNumbersType } from '../models/format-numbers-type';
2
+ export declare const formatNumberBySign: (num: string, formatNumbers: FormatNumbersType) => string;
@@ -0,0 +1 @@
1
+ export declare const getTimePeriod: (timePeriod: string) => Date | null;
@@ -0,0 +1,7 @@
1
+ import { ApiHeaders } from '../models/api';
2
+ export declare const getHeaders: (apiKey?: string, options?: {
3
+ jwt?: string;
4
+ chatReference?: string;
5
+ contentType?: string;
6
+ }, optionsHeaders?: Record<string, string>) => Record<string, string>;
7
+ export declare const sanitizeHeaders: (headers: ApiHeaders) => Record<string, string>;
@@ -0,0 +1,9 @@
1
+ export * from './conversation-id-to-navigation';
2
+ export * from './conversation-name';
3
+ export * from './conversation-navigation-to-id';
4
+ export * from './format-numbers';
5
+ export * from './get-time-period';
6
+ export * from './headers';
7
+ export * from './parse-boolean';
8
+ export * from './send-request';
9
+ export * from './conversation-url';
@@ -0,0 +1 @@
1
+ export declare const parseBoolean: (value: string | undefined) => boolean;
@@ -0,0 +1,2 @@
1
+ import { RequestOptions } from '../models/request-options';
2
+ export declare const sendRequest: (url: string, headers: Record<string, string>, options: RequestOptions) => Promise<Response>;