2.1.1 add init + update versions of dependencies
This commit is contained in:
parent
0a2a0128ef
commit
0a32cc32a6
11
env.d.ts
vendored
11
env.d.ts
vendored
@ -1,11 +0,0 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_REACT_APP_DOMAIN: string;
|
||||
readonly VITE_API_KEY: string;
|
||||
// Добавьте другие переменные окружения, которые вы используете
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
@ -1,12 +1,15 @@
|
||||
import { UserAccount, UserName } from "../model/account";
|
||||
import { makeRequest } from "./makeRequest";
|
||||
import { getDomain } from "../config/domain";
|
||||
|
||||
|
||||
const apiUrl = import.meta.env.VITE__APP_DOMAIN + "/customer";
|
||||
function getApiUrl(): string {
|
||||
return getDomain() + "/customer";
|
||||
}
|
||||
|
||||
export function patchUserAccount(user: UserName, version:string | undefined) {
|
||||
return makeRequest<UserName, UserAccount>({
|
||||
url: `${apiUrl + (version ? `/${version}` : "")}/account`,
|
||||
url: `${getApiUrl() + (version ? `/${version}` : "")}/account`,
|
||||
contentType: true,
|
||||
method: "PATCH",
|
||||
useToken: true,
|
||||
@ -17,7 +20,7 @@ export function patchUserAccount(user: UserName, version:string | undefined) {
|
||||
|
||||
export function createUserAccount(signal: AbortSignal, url: string | undefined, version: string) {
|
||||
return makeRequest<never, UserAccount>({
|
||||
url: url || `${apiUrl + (version.length > 0 ? `/${version}` : "")}/account`,
|
||||
url: url || `${getApiUrl() + (version.length > 0 ? `/${version}` : "")}/account`,
|
||||
contentType: true,
|
||||
method: "POST",
|
||||
useToken: true,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import axios, { AxiosResponse, Method, ResponseType } from "axios";
|
||||
import { getAuthToken, setAuthToken } from "../stores/auth";
|
||||
import { getDomain } from "../config/domain";
|
||||
|
||||
|
||||
export async function makeRequest<TRequest = unknown, TResponse = unknown>({
|
||||
@ -66,7 +67,7 @@ export async function makeRequest<TRequest = unknown, TResponse = unknown>({
|
||||
|
||||
function refresh(token: string) {
|
||||
|
||||
return axios<never, AxiosResponse<{ accessToken: string; }>>(import.meta.env.VITE__APP_DOMAIN + "/auth/refresh", {
|
||||
return axios<never, AxiosResponse<{ accessToken: string; }>>(getDomain() + "/auth/refresh", {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Tariff } from "../model/tariff";
|
||||
import { makeRequest } from "./makeRequest";
|
||||
import { getDomain } from "../config/domain";
|
||||
|
||||
|
||||
export function getTariffById(tariffId:string){
|
||||
return makeRequest<never, Tariff>({
|
||||
url: import.meta.env.VITE__APP_DOMAIN + `/strator/tariff/${tariffId}`,
|
||||
url: getDomain() + `/strator/tariff/${tariffId}`,
|
||||
method: "get",
|
||||
useToken: true,
|
||||
});
|
||||
|
||||
22
lib/config/domain.ts
Normal file
22
lib/config/domain.ts
Normal file
@ -0,0 +1,22 @@
|
||||
let domain: string = "";
|
||||
let isDevelopment: boolean = false;
|
||||
|
||||
export function setDomain(newDomain: string): void {
|
||||
domain = newDomain;
|
||||
}
|
||||
|
||||
export function getDomain(): string {
|
||||
if (!domain) {
|
||||
throw new Error("Домен не инициализирован. Вызовите init() перед использованием библиотеки.");
|
||||
}
|
||||
return domain;
|
||||
}
|
||||
|
||||
export function setIsDevelopment(value: boolean): void {
|
||||
isDevelopment = value;
|
||||
}
|
||||
|
||||
export function getIsDevelopment(): boolean {
|
||||
return isDevelopment;
|
||||
}
|
||||
|
||||
12
lib/config/init.ts
Normal file
12
lib/config/init.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { setDomain, setIsDevelopment } from "./domain";
|
||||
|
||||
export interface InitOptions {
|
||||
domain: string;
|
||||
isDevelopment?: boolean;
|
||||
}
|
||||
|
||||
export function init(options: InitOptions): void {
|
||||
setDomain(options.domain);
|
||||
setIsDevelopment(options.isDevelopment ?? false);
|
||||
}
|
||||
|
||||
7
lib/env.d.ts
vendored
7
lib/env.d.ts
vendored
@ -1,7 +0,0 @@
|
||||
export declare global {
|
||||
namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
readonly NODE_ENV: 'development' | 'production' | 'test';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,12 @@
|
||||
import { useRef, useLayoutEffect, useEffect } from "react";
|
||||
import { GetTariffsResponse, Tariff } from "../model/tariff";
|
||||
import { makeRequest } from "../api/makeRequest";
|
||||
import { getDomain } from "../config/domain";
|
||||
|
||||
|
||||
export function useAllTariffsFetcher({
|
||||
enabled = true,
|
||||
baseUrl = import.meta.env.VITE__APP_DOMAIN + "/strator/tariff",
|
||||
baseUrl = getDomain() + "/strator/tariff",
|
||||
onSuccess,
|
||||
onError,
|
||||
}: {
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import { useEffect, useLayoutEffect, useRef } from "react";
|
||||
import { makeRequest } from "../api";
|
||||
import { Privilege } from "../model";
|
||||
import { getDomain } from "../config/domain";
|
||||
|
||||
|
||||
export function usePrivilegeFetcher({
|
||||
onSuccess,
|
||||
url = import.meta.env.VITE__APP_DOMAIN + "/strator/privilege",
|
||||
url = getDomain() + "/strator/privilege",
|
||||
onError,
|
||||
}: {
|
||||
onSuccess: (response: Privilege[]) => void;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export * from "./api";
|
||||
export * from "./components";
|
||||
export * from "./config/init";
|
||||
export * from "./decorators";
|
||||
export * from "./hooks";
|
||||
export * from "./model";
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { isAxiosError } from "axios";
|
||||
import { getIsDevelopment } from "../config/domain";
|
||||
|
||||
|
||||
const translateMessage: Record<string, string> = {
|
||||
@ -24,7 +25,7 @@ export function getMessageFromFetchError(error: any, defaultMessage = "Что-т
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === "development") return rawMessage ?? error.message ?? defaultMessage;
|
||||
if (getIsDevelopment()) return rawMessage ?? error.message ?? defaultMessage;
|
||||
|
||||
return defaultMessage;
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { getIsDevelopment } from "../config/domain";
|
||||
|
||||
export const devlog: typeof console.log = (...args) => {
|
||||
if (process.env.NODE_ENV === "development") console.log(...args);
|
||||
if (getIsDevelopment()) console.log(...args);
|
||||
};
|
||||
15
package.json
15
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@frontend/kitui",
|
||||
"version": "2.0.2",
|
||||
"version": "2.1.1",
|
||||
"description": "test",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
@ -64,12 +64,13 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@emotion/styled": "^11.14.0",
|
||||
"@mui/icons-material": "^6.4.7",
|
||||
"@mui/material": "^6.4.6",
|
||||
"axios": "^1.8.2",
|
||||
"@emotion/styled": "^11.14.1",
|
||||
"@mui/icons-material": "^7.3.5",
|
||||
"@mui/material": "^7.3.5",
|
||||
"axios": "^1.13.1",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-router-dom": "^7.3.0",
|
||||
"zustand": "^5.0.3"
|
||||
"zustand": "^5.0.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,8 +23,7 @@
|
||||
},
|
||||
"include": [
|
||||
"src",
|
||||
"lib",
|
||||
"env.d.ts"
|
||||
"lib"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user