@krainovsd/js-helpers 0.15.3 → 0.16.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/lib/cjs/index.cjs +658 -569
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/{lib/api/middlewares/console-post-middleware.js → api/after/logger-after-handler.js} +4 -4
- package/lib/esm/api/after/logger-after-handler.js.map +1 -0
- package/lib/esm/api/api.constants.js +23 -0
- package/lib/esm/api/api.constants.js.map +1 -0
- package/lib/esm/api/api.js +343 -0
- package/lib/esm/api/api.js.map +1 -0
- package/lib/esm/{lib/api/middlewares/console-middleware.js → api/before/logger-before-handler.js} +4 -4
- package/lib/esm/api/before/logger-before-handler.js.map +1 -0
- package/lib/esm/api/before/oauth-before-handler.js +56 -0
- package/lib/esm/api/before/oauth-before-handler.js.map +1 -0
- package/lib/esm/{lib/api/oauth/token.js → api/oauth.js} +30 -10
- package/lib/esm/api/oauth.js.map +1 -0
- package/lib/esm/constants/errors.js +16 -0
- package/lib/esm/constants/errors.js.map +1 -0
- package/lib/esm/constants/index.js +27 -0
- package/lib/esm/constants/index.js.map +1 -0
- package/lib/esm/index.js +9 -8
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/lib/colors/get-color-format.js +1 -2
- package/lib/esm/lib/colors/get-color-format.js.map +1 -1
- package/lib/esm/lib/colors/take-opacity-colors.js +1 -2
- package/lib/esm/lib/colors/take-opacity-colors.js.map +1 -1
- package/lib/esm/lib/colors/transform-to-color.js +1 -2
- package/lib/esm/lib/colors/transform-to-color.js.map +1 -1
- package/lib/esm/lib/date/get-date-by-rules.js +1 -2
- package/lib/esm/lib/date/get-date-by-rules.js.map +1 -1
- package/lib/esm/lib/date/is-yesterday.js +0 -1
- package/lib/esm/lib/date/is-yesterday.js.map +1 -1
- package/lib/esm/lib/utils/build-query-string.js.map +1 -1
- package/lib/esm/lib/utils/{create-url-with-params.js → create-url-with-queries.js} +3 -3
- package/lib/esm/lib/utils/create-url-with-queries.js.map +1 -0
- package/lib/esm/lib/utils/field-view-format.js +1 -2
- package/lib/esm/lib/utils/field-view-format.js.map +1 -1
- package/lib/index.d.ts +224 -170
- package/package.json +4 -2
- package/lib/esm/constants/api.js +0 -10
- package/lib/esm/constants/api.js.map +0 -1
- package/lib/esm/constants/colors.js +0 -9
- package/lib/esm/constants/colors.js.map +0 -1
- package/lib/esm/constants/date.js +0 -11
- package/lib/esm/constants/date.js.map +0 -1
- package/lib/esm/constants/fields.js +0 -11
- package/lib/esm/constants/fields.js.map +0 -1
- package/lib/esm/lib/api/constants.js +0 -4
- package/lib/esm/lib/api/constants.js.map +0 -1
- package/lib/esm/lib/api/core.js +0 -191
- package/lib/esm/lib/api/core.js.map +0 -1
- package/lib/esm/lib/api/middlewares/console-middleware.js.map +0 -1
- package/lib/esm/lib/api/middlewares/console-post-middleware.js.map +0 -1
- package/lib/esm/lib/api/middlewares/index.js +0 -65
- package/lib/esm/lib/api/middlewares/index.js.map +0 -1
- package/lib/esm/lib/api/middlewares/oauth-middleware.js +0 -75
- package/lib/esm/lib/api/middlewares/oauth-middleware.js.map +0 -1
- package/lib/esm/lib/api/oauth/token.js.map +0 -1
- package/lib/esm/lib/api/oauth/user.js +0 -35
- package/lib/esm/lib/api/oauth/user.js.map +0 -1
- package/lib/esm/lib/utils/create-url-with-params.js.map +0 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,66 +1,140 @@
|
|
|
1
|
-
import { Response as Response$1, Headers as Headers$1, RequestInfo, RequestInit } from 'node-fetch';
|
|
2
1
|
import { Dayjs } from 'dayjs';
|
|
2
|
+
import { Response as Response$1, RequestInfo, RequestInit, Headers as Headers$1 } from 'node-fetch';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly Seconds: "seconds";
|
|
9
|
-
readonly Minutes: "minutes";
|
|
10
|
-
readonly Hours: "hours";
|
|
4
|
+
type DownloadFileOptions = {
|
|
5
|
+
data: Blob;
|
|
6
|
+
fileName: string;
|
|
7
|
+
mimeType: string;
|
|
11
8
|
};
|
|
9
|
+
declare function downloadFile({ data, fileName, mimeType }: DownloadFileOptions): null;
|
|
10
|
+
|
|
11
|
+
declare function downloadJson(data: unknown, name: string): null | undefined;
|
|
12
12
|
|
|
13
|
-
declare
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
declare function readFile(file: File): Promise<unknown>;
|
|
14
|
+
|
|
15
|
+
type PositionPlacements = "bottom-center" | "bottom-left" | "bottom-right" | "right-center" | "right-top" | "right-bottom" | "top-left" | "top-center" | "top-right" | "left-center" | "left-top" | "left-bottom" | "flex";
|
|
16
|
+
type VisiblePosition = {
|
|
17
|
+
top: number;
|
|
18
|
+
left: number;
|
|
19
|
+
right: number;
|
|
20
|
+
bottom: number;
|
|
21
|
+
placement: PositionPlacements;
|
|
22
|
+
};
|
|
23
|
+
type InitialPosition = {
|
|
24
|
+
targetNode?: HTMLElement;
|
|
25
|
+
position?: {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
};
|
|
16
31
|
};
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
type GetVisiblePositionOptions = {
|
|
33
|
+
node: HTMLElement;
|
|
34
|
+
initialPosition?: InitialPosition;
|
|
35
|
+
visibleArea?: HTMLElement;
|
|
36
|
+
placement?: Exclude<PositionPlacements, "flex">;
|
|
37
|
+
stepX?: number;
|
|
38
|
+
stepY?: number;
|
|
39
|
+
flex?: boolean;
|
|
40
|
+
nested?: boolean;
|
|
19
41
|
};
|
|
42
|
+
declare function getVisiblePosition({ initialPosition, node, visibleArea, placement, stepX, stepY, flex, nested, }: GetVisiblePositionOptions): VisiblePosition;
|
|
20
43
|
|
|
21
|
-
declare
|
|
22
|
-
declare const IS_BUN: boolean;
|
|
23
|
-
declare const IS_DENO: boolean;
|
|
24
|
-
declare const IS_NODE: boolean;
|
|
25
|
-
declare const IS_WEB_WORKER: boolean;
|
|
26
|
-
declare const IS_BROWSER: boolean;
|
|
44
|
+
declare function getQueryValues<K extends string>(keys: K[]): Record<K, string | string[] | undefined> | null;
|
|
27
45
|
|
|
28
|
-
declare
|
|
29
|
-
readonly Hex: "HEX";
|
|
30
|
-
readonly Rgb: "RGB";
|
|
31
|
-
readonly Rgba: "RGBA";
|
|
32
|
-
readonly Hsl: "HSL";
|
|
33
|
-
};
|
|
46
|
+
declare function execAnimation(element: HTMLElement | null | undefined, className: string, autoCloseDelay?: number): Promise<unknown>;
|
|
34
47
|
|
|
35
|
-
declare
|
|
36
|
-
readonly Date: "date";
|
|
37
|
-
readonly Time: "time";
|
|
38
|
-
readonly DateTime: "dateTime";
|
|
39
|
-
readonly String: "string";
|
|
40
|
-
readonly Number: "number";
|
|
41
|
-
readonly Array: "array";
|
|
42
|
-
};
|
|
48
|
+
declare function copyToClipboard(textToCopy: string): Promise<boolean>;
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
declare function extractQueries(): Record<string, string[] | undefined>;
|
|
51
|
+
|
|
52
|
+
declare function getColorFormat(color: string): "HEX" | "RGB" | "RGBA" | "HSL" | undefined;
|
|
53
|
+
|
|
54
|
+
declare function takeOpacityColors(color: string | undefined, opacities: number[]): string[];
|
|
55
|
+
|
|
56
|
+
declare function transformHEXtoRGB(hex: string): string;
|
|
57
|
+
|
|
58
|
+
declare function transformRGBtoRGBA(rgb: string, opacity: number): string;
|
|
47
59
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
declare function transformRGBAtoRGB(rgba: string): string;
|
|
61
|
+
|
|
62
|
+
declare const RESPONSE_DATA_SYMBOL: unique symbol;
|
|
63
|
+
declare const REQUEST_ERROR: {
|
|
64
|
+
readonly HTTP_ERROR: "http";
|
|
65
|
+
readonly NETWORK_ERROR: "network";
|
|
66
|
+
readonly TIMEOUT_ERROR: "timeout";
|
|
67
|
+
readonly ABORT_ERROR: "abort";
|
|
68
|
+
readonly VALIDATION_ERROR: "validation";
|
|
69
|
+
readonly CACHE_ERROR: "cache";
|
|
70
|
+
readonly UNKNOWN_ERROR: "unknown";
|
|
71
|
+
};
|
|
72
|
+
declare class OauthState {
|
|
73
|
+
private _fetching;
|
|
74
|
+
get fetching(): boolean;
|
|
75
|
+
set fetching(value: boolean);
|
|
76
|
+
}
|
|
77
|
+
declare const OAUTH_STATE: OauthState;
|
|
78
|
+
|
|
79
|
+
type RequestQueryValue = string | number | boolean;
|
|
80
|
+
type RequestQuery = Record<string, RequestQueryValue | RequestQueryValue[] | null | undefined>;
|
|
81
|
+
type RequestHeader = Record<string, string | string[] | undefined>;
|
|
82
|
+
type RequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
|
|
83
|
+
type RequestError = ValueOf<typeof REQUEST_ERROR>;
|
|
51
84
|
type RequestInterface<IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming> = {
|
|
52
85
|
path: string;
|
|
53
86
|
method: RequestMethod;
|
|
54
87
|
body?: Outcoming;
|
|
55
|
-
|
|
56
|
-
headers?:
|
|
88
|
+
queries?: RequestQuery;
|
|
89
|
+
headers?: RequestHeader;
|
|
90
|
+
/** A count of milliseconds before start request */
|
|
57
91
|
delay?: number;
|
|
92
|
+
/** A value that will be returned immediately */
|
|
58
93
|
mock?: (() => IncomingApi) | IncomingApi;
|
|
94
|
+
/** A value that will be returned after error */
|
|
59
95
|
defaultResponse?: (() => IncomingApi) | IncomingApi;
|
|
60
|
-
|
|
96
|
+
/** A boolean to download file after response */
|
|
97
|
+
download?: boolean;
|
|
61
98
|
signal?: AbortSignal;
|
|
99
|
+
/** A token for Authorization header */
|
|
62
100
|
token?: string;
|
|
101
|
+
/** A boolean to activate oauth flow and then retry */
|
|
63
102
|
refetchNoAuth?: boolean;
|
|
103
|
+
/** A handlers before start request that rewrite global's handlers */
|
|
104
|
+
beforeHandlers?: BeforeHandler[];
|
|
105
|
+
/** A handlers after stop request that rewrite global's handlers */
|
|
106
|
+
afterHandlers?: AfterHandler[];
|
|
107
|
+
/** A handlers before start request with global's handlers */
|
|
108
|
+
additionalBeforeHandlers?: BeforeHandler[];
|
|
109
|
+
/** A handlers after stop request with global's handlers */
|
|
110
|
+
additionalAfterHandlers?: AfterHandler[];
|
|
111
|
+
/** An error handler */
|
|
112
|
+
onError?: (type: RequestError, error: ResponseError) => void;
|
|
113
|
+
/** An array of retries strategy where the number is the delay before retry, and size is the count of retries */
|
|
114
|
+
retries?: number[];
|
|
115
|
+
/** A count of millisecond before timeout error */
|
|
116
|
+
timeout?: number;
|
|
117
|
+
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
|
|
118
|
+
cache?: RequestCache;
|
|
119
|
+
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */
|
|
120
|
+
credentials?: RequestCredentials;
|
|
121
|
+
/** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
|
|
122
|
+
integrity?: string;
|
|
123
|
+
/** A boolean to set request's keepalive. */
|
|
124
|
+
keepalive?: boolean;
|
|
125
|
+
/** A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. */
|
|
126
|
+
mode?: RequestMode;
|
|
127
|
+
priority?: RequestPriority;
|
|
128
|
+
/** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
|
|
129
|
+
redirect?: RequestRedirect;
|
|
130
|
+
/** A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. */
|
|
131
|
+
referrer?: string;
|
|
132
|
+
/** A referrer policy to set request's referrerPolicy. */
|
|
133
|
+
referrerPolicy?: ReferrerPolicy;
|
|
134
|
+
/** A boolean to support gzip/deflate content encoding. (only NodeFetch) */
|
|
135
|
+
compress?: boolean | undefined;
|
|
136
|
+
/** A maximum redirect count. (only NodeFetch) */
|
|
137
|
+
follow?: number | undefined;
|
|
64
138
|
} & RequestTransformIncoming<IncomingApi, Incoming> & RequestTransformOutcoming<Outcoming, OutcomingApi>;
|
|
65
139
|
type RequestTransformOutcoming<Outcoming, OutcomingApi> = IsEqual<OutcomingApi, Outcoming> extends true ? {
|
|
66
140
|
transformOutcomingData?: never;
|
|
@@ -72,176 +146,156 @@ type RequestTransformIncoming<IncomingApi, Incoming> = IsEqual<Incoming, Incomin
|
|
|
72
146
|
} : {
|
|
73
147
|
transformIncomingData: (data: IncomingApi) => Incoming;
|
|
74
148
|
};
|
|
75
|
-
type
|
|
76
|
-
type
|
|
77
|
-
type PostMiddlewareType = ValueOf<typeof POST_API_MIDDLEWARES>;
|
|
78
|
-
type ActivePostMiddleware = PostMiddlewareType[];
|
|
79
|
-
type LoggerPostMiddlewareOptions = {
|
|
80
|
-
filter?: (response: Response | Response$1 | undefined) => boolean;
|
|
81
|
-
filterStatus?: (status: number) => boolean;
|
|
82
|
-
filterUrl?: (url: string) => boolean;
|
|
83
|
-
filterHeaders?: (headers: Headers | Headers$1) => boolean;
|
|
84
|
-
};
|
|
85
|
-
type PostMiddlewareOptions = {
|
|
86
|
-
logger?: LoggerPostMiddlewareOptions;
|
|
87
|
-
};
|
|
88
|
-
type MiddlewareType = ValueOf<typeof API_MIDDLEWARES>;
|
|
89
|
-
type ActiveMiddleware = MiddlewareType[];
|
|
90
|
-
type LoggerMiddlewareOptions = {
|
|
91
|
-
filter?: (request: RequestInterface<unknown, unknown, unknown, unknown>) => boolean;
|
|
92
|
-
filterPath?: (path: string) => boolean;
|
|
93
|
-
filterMethod?: (method: RequestMethod) => boolean;
|
|
94
|
-
filterParams?: (params?: ParamsType) => boolean;
|
|
95
|
-
filterHeaders?: (headers?: Record<string, string | undefined>) => boolean;
|
|
96
|
-
};
|
|
97
|
-
type MiddlewaresOptions = {
|
|
98
|
-
logger?: LoggerMiddlewareOptions;
|
|
99
|
-
};
|
|
100
|
-
type AuthUserUpdateRequestOptions<User extends Record<string, unknown>> = AuthUserRequestOptions & {
|
|
101
|
-
userRequest?: () => Promise<User | null | undefined>;
|
|
102
|
-
oauthUrl: () => string;
|
|
103
|
-
errorUrl: string;
|
|
104
|
-
};
|
|
105
|
-
type AuthUserRequestOptions = {
|
|
106
|
-
authUserUrl: string;
|
|
107
|
-
};
|
|
149
|
+
type BeforeHandler = <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<unknown>;
|
|
150
|
+
type AfterHandler = <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>, response: Response | Response$1 | undefined) => Promise<unknown>;
|
|
108
151
|
type OauthOptions = {
|
|
152
|
+
/** A name of expires token in localstorage */
|
|
109
153
|
expiresTokenStorageName: string;
|
|
154
|
+
/** A name of flag in query for oauth flow window */
|
|
110
155
|
onlyRefreshTokenWindowQueryName: string;
|
|
156
|
+
/** An url of start oauth flow window */
|
|
111
157
|
refreshTokenWindowUrl?: (() => string) | string;
|
|
158
|
+
/** An error handle that call if oauth flow window wasn't open */
|
|
112
159
|
onWindowOpenError?: () => void;
|
|
160
|
+
/** A name of token in localstorage */
|
|
113
161
|
tokenStorageName?: string;
|
|
162
|
+
/** An url for refresh token */
|
|
114
163
|
tokenRequest?: () => Promise<string | null | undefined>;
|
|
164
|
+
/** A number of millisecond for waiting oauth flow window before force close it */
|
|
115
165
|
wait?: number;
|
|
166
|
+
/** An interval for check closable property by oauth flow window in ms */
|
|
116
167
|
closeObserveInterval?: number;
|
|
117
168
|
};
|
|
118
169
|
type GetOauthTokenOptions = {
|
|
170
|
+
/** An url of start oauth flow */
|
|
119
171
|
oauthUrl: (() => string) | string;
|
|
172
|
+
/** A name of expires token in localstorage */
|
|
120
173
|
expiresTokenStorageName: string;
|
|
174
|
+
/** A name of expires token in query */
|
|
121
175
|
expiresTokenQueryName: string;
|
|
176
|
+
/** A name of flag in query for oauth flow window */
|
|
122
177
|
onlyRefreshTokenWindowQueryName: string;
|
|
123
178
|
};
|
|
124
179
|
type GetOauthTokenFromOtherWindowOptions = {
|
|
180
|
+
/** An url of start oauth flow window */
|
|
125
181
|
refreshTokenWindowUrl?: (() => string) | string;
|
|
182
|
+
/** A name of flag in query for oauth flow window */
|
|
126
183
|
onlyRefreshTokenWindowQueryName: string;
|
|
184
|
+
/** A name of expires token in localstorage */
|
|
127
185
|
expiresTokenStorageName: string;
|
|
186
|
+
/** An error handle that call if oauth flow window wasn't open */
|
|
128
187
|
onWindowOpenError?: () => void;
|
|
188
|
+
/** A number of millisecond for waiting oauth flow window before force close it */
|
|
129
189
|
wait?: number;
|
|
190
|
+
/** An interval for check closable property by oauth flow window in ms */
|
|
130
191
|
closeObserveInterval?: number;
|
|
131
192
|
};
|
|
132
193
|
|
|
133
|
-
type DateType = ValueOf<typeof DATE_TYPES>;
|
|
134
|
-
type DateGetterRule = {
|
|
135
|
-
increment: number;
|
|
136
|
-
type: DateType;
|
|
137
|
-
};
|
|
138
|
-
type DayJS = Dayjs;
|
|
139
|
-
|
|
140
|
-
type FieldType = ValueOf<typeof FIELD_TYPES>;
|
|
141
|
-
|
|
142
|
-
type ColorFormat = ValueOf<typeof COLOR_FORMATS>;
|
|
143
|
-
|
|
144
|
-
type ResponseErrorOptions = {
|
|
145
|
-
message: string;
|
|
146
|
-
status: number;
|
|
147
|
-
code?: number;
|
|
148
|
-
description?: unknown;
|
|
149
|
-
headers?: Record<string, string>;
|
|
150
|
-
};
|
|
151
|
-
declare class ResponseError extends Error {
|
|
152
|
-
status: number;
|
|
153
|
-
code?: number;
|
|
154
|
-
description?: unknown;
|
|
155
|
-
headers?: Record<string, string>;
|
|
156
|
-
constructor({ message, status, description, code, headers }: ResponseErrorOptions);
|
|
157
|
-
}
|
|
158
194
|
type CreateRequestClientInstance = {
|
|
159
195
|
client: ((url: URL | RequestInfo, init?: RequestInit) => Promise<Response$1>) | typeof fetch;
|
|
160
196
|
oauthOptions?: OauthOptions;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
postMiddlewaresOptions?: PostMiddlewareOptions;
|
|
166
|
-
customPostMiddlewares?: PostMiddleware[];
|
|
197
|
+
beforeHandlers?: BeforeHandler[];
|
|
198
|
+
afterHandlers?: AfterHandler[];
|
|
199
|
+
retries?: number[];
|
|
200
|
+
timeout?: number;
|
|
167
201
|
};
|
|
168
202
|
type RequestInstance = {
|
|
169
203
|
<IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>): Promise<Incoming>;
|
|
170
|
-
|
|
171
|
-
};
|
|
172
|
-
declare function
|
|
173
|
-
|
|
174
|
-
|
|
204
|
+
recreate: (options: CreateRequestClientInstance) => void;
|
|
205
|
+
};
|
|
206
|
+
declare function createFetchClient(options: CreateRequestClientInstance): {
|
|
207
|
+
requestWithArrayResponse: <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<[ResponseError, RequestError, Response | Response$1 | null] | [Incoming, null, Response | Response$1 | null]>;
|
|
208
|
+
requestWithObjectResponse: <IncomingApi, Incoming = IncomingApi, Outcoming = unknown, OutcomingApi = Outcoming>(request: RequestInterface<IncomingApi, Incoming, Outcoming, OutcomingApi>) => Promise<{
|
|
209
|
+
data: ResponseError;
|
|
210
|
+
error: RequestError;
|
|
211
|
+
response: Response | Response$1 | null;
|
|
212
|
+
} | {
|
|
175
213
|
data: Incoming;
|
|
176
|
-
|
|
177
|
-
|
|
214
|
+
error: null;
|
|
215
|
+
response: Response | Response$1 | null;
|
|
178
216
|
}>;
|
|
179
|
-
|
|
217
|
+
recreate: (options: CreateRequestClientInstance) => void;
|
|
180
218
|
};
|
|
181
219
|
|
|
182
220
|
declare function getOauthTokenFromOtherWindow(options: GetOauthTokenFromOtherWindowOptions): Promise<void>;
|
|
221
|
+
declare function refetchAfterOauth<T>(options: OauthOptions, refetch: () => Promise<T>): Promise<T>;
|
|
183
222
|
declare function getOauthToken(options: GetOauthTokenOptions): string | null;
|
|
184
223
|
|
|
185
|
-
|
|
186
|
-
|
|
224
|
+
type LoggerAfterHandlerOptions = {
|
|
225
|
+
filter?: (response: Response | Response$1 | undefined) => boolean;
|
|
226
|
+
filterStatus?: (status: number) => boolean;
|
|
227
|
+
filterUrl?: (url: string) => boolean;
|
|
228
|
+
filterHeaders?: (headers: Headers | Headers$1) => boolean;
|
|
229
|
+
};
|
|
230
|
+
declare function loggerAfterHandler(options?: LoggerAfterHandlerOptions): AfterHandler;
|
|
187
231
|
|
|
188
|
-
type
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
232
|
+
type LoggerBeforeHandlerOptions = {
|
|
233
|
+
filter?: (request: RequestInterface<unknown, unknown, unknown, unknown>) => boolean;
|
|
234
|
+
filterPath?: (path: string) => boolean;
|
|
235
|
+
filterMethod?: (method: RequestMethod) => boolean;
|
|
236
|
+
filterParams?: (params?: RequestQuery) => boolean;
|
|
237
|
+
filterHeaders?: (headers?: RequestHeader) => boolean;
|
|
192
238
|
};
|
|
193
|
-
declare function
|
|
239
|
+
declare function loggerBeforeHandler(options?: LoggerBeforeHandlerOptions): BeforeHandler;
|
|
194
240
|
|
|
195
|
-
declare
|
|
241
|
+
declare const oauthBeforeHandler: (options: OauthOptions) => BeforeHandler;
|
|
196
242
|
|
|
197
|
-
|
|
243
|
+
type ResponseErrorOptions = {
|
|
244
|
+
message: string;
|
|
245
|
+
status: number;
|
|
246
|
+
code?: number;
|
|
247
|
+
description?: unknown;
|
|
248
|
+
headers?: RequestHeader;
|
|
249
|
+
};
|
|
250
|
+
declare class ResponseError extends Error {
|
|
251
|
+
status: number;
|
|
252
|
+
code?: number;
|
|
253
|
+
description?: unknown;
|
|
254
|
+
headers?: RequestHeader;
|
|
255
|
+
constructor({ message, status, description, code, headers }: ResponseErrorOptions);
|
|
256
|
+
}
|
|
198
257
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
258
|
+
declare const IS_JEST: boolean;
|
|
259
|
+
declare const IS_BUN: boolean;
|
|
260
|
+
declare const IS_DENO: boolean;
|
|
261
|
+
declare const IS_NODE: boolean;
|
|
262
|
+
declare const IS_WEB_WORKER: boolean;
|
|
263
|
+
declare const IS_BROWSER: boolean;
|
|
264
|
+
|
|
265
|
+
declare const COLOR_FORMATS: {
|
|
266
|
+
readonly Hex: "HEX";
|
|
267
|
+
readonly Rgb: "RGB";
|
|
268
|
+
readonly Rgba: "RGBA";
|
|
269
|
+
readonly Hsl: "HSL";
|
|
206
270
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
};
|
|
271
|
+
declare const DATE_TYPES: {
|
|
272
|
+
readonly Days: "days";
|
|
273
|
+
readonly Months: "months";
|
|
274
|
+
readonly Years: "years";
|
|
275
|
+
readonly Seconds: "seconds";
|
|
276
|
+
readonly Minutes: "minutes";
|
|
277
|
+
readonly Hours: "hours";
|
|
215
278
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
flex?: boolean;
|
|
224
|
-
nested?: boolean;
|
|
279
|
+
declare const FIELD_TYPES: {
|
|
280
|
+
readonly Date: "date";
|
|
281
|
+
readonly Time: "time";
|
|
282
|
+
readonly DateTime: "dateTime";
|
|
283
|
+
readonly String: "string";
|
|
284
|
+
readonly Number: "number";
|
|
285
|
+
readonly Array: "array";
|
|
225
286
|
};
|
|
226
|
-
declare function getVisiblePosition({ initialPosition, node, visibleArea, placement, stepX, stepY, flex, nested, }: GetVisiblePositionOptions): VisiblePosition;
|
|
227
287
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
declare function transformHEXtoRGB(hex: string): string;
|
|
241
|
-
|
|
242
|
-
declare function transformRGBtoRGBA(rgb: string, opacity: number): string;
|
|
243
|
-
|
|
244
|
-
declare function transformRGBAtoRGB(rgba: string): string;
|
|
288
|
+
type Maybe<T> = T | undefined | null;
|
|
289
|
+
type ValueOf<T> = T extends {} ? T[keyof T] : unknown;
|
|
290
|
+
type IsEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
|
|
291
|
+
type ColorFormat = ValueOf<typeof COLOR_FORMATS>;
|
|
292
|
+
type DateType = ValueOf<typeof DATE_TYPES>;
|
|
293
|
+
type DateGetterRule = {
|
|
294
|
+
increment: number;
|
|
295
|
+
type: DateType;
|
|
296
|
+
};
|
|
297
|
+
type DayJS = Dayjs;
|
|
298
|
+
type FieldType = ValueOf<typeof FIELD_TYPES>;
|
|
245
299
|
|
|
246
300
|
declare function transformToColor(currentColor: unknown, defaultColor?: string, defaultFormat?: ColorFormat): string;
|
|
247
301
|
|
|
@@ -290,15 +344,15 @@ declare function transformToNumber(value: unknown): number;
|
|
|
290
344
|
|
|
291
345
|
type CreateURLOptionsInterface = {
|
|
292
346
|
baseURL: string;
|
|
293
|
-
params?:
|
|
347
|
+
params?: RequestQuery;
|
|
294
348
|
};
|
|
295
|
-
declare function
|
|
349
|
+
declare function createURLWithQueries(options: CreateURLOptionsInterface): string;
|
|
296
350
|
|
|
297
351
|
declare function trimUrl(url: string): string;
|
|
298
352
|
|
|
299
353
|
declare function arrayToMapByKey<T extends Record<string, unknown>>(array: T[], key: keyof T): Record<string, T>;
|
|
300
354
|
|
|
301
|
-
declare function buildQueryString(params:
|
|
355
|
+
declare function buildQueryString(params: RequestQuery): string;
|
|
302
356
|
|
|
303
357
|
declare function syncObjectValues(oldObj: Record<string, unknown>, newObj: Record<string, unknown>, exception?: string[]): void;
|
|
304
358
|
|
|
@@ -399,5 +453,5 @@ declare function throttle<TArgs extends any[]>({ interval }: {
|
|
|
399
453
|
|
|
400
454
|
declare function type(value: unknown): string;
|
|
401
455
|
|
|
402
|
-
export {
|
|
403
|
-
export type {
|
|
456
|
+
export { COLOR_FORMATS, DATE_TYPES, FIELD_TYPES, IS_BROWSER, IS_BUN, IS_DENO, IS_JEST, IS_NODE, IS_WEB_WORKER, OAUTH_STATE, REQUEST_ERROR, RESPONSE_DATA_SYMBOL, ResponseError, arrayToMapByKey, buildQueryString, checkType, cloneDeep, copyToClipboard, createFetchClient, createGlobalId, createLocalIdGenerator, createURLWithQueries, dateDifference, dateFormat, debounce, declination, difference, differenceBy, differenceWith, downloadFile, downloadJson, execAnimation, extractQueries, fieldViewFormat, getByPath, getCallerFunctionName, getColorFormat, getDateByRules, getFileNameFromHeader, getOauthToken, getOauthTokenFromOtherWindow, getQueryValues, getRandomColor, getToday, getTomorrow, getVisiblePosition, getYesterday, isArray, isBoolean, isDate, isEqual, isId, isNull, isNullable, isNumber, isObject, isPrimitive, isString, isToday, isTomorrow, isUndefined, isYesterday, joinPaths, jsonParse, limitStreamOfRequests, loggerAfterHandler, loggerBeforeHandler, oauthBeforeHandler, randomNumber, randomString, readFile, refetchAfterOauth, setByPath, speedTest, startWith, syncObjectValues, takeOpacityColors, throttle, transformHEXtoRGB, transformRGBAtoRGB, transformRGBtoRGBA, transformToColor, transformToDayjs, transformToNumber, translit, trimUrl, type, wait, waitUntil };
|
|
457
|
+
export type { AfterHandler, BeforeHandler, ColorFormat, DateGetterRule, DateType, DayJS, FieldType, GetOauthTokenFromOtherWindowOptions, GetOauthTokenOptions, IsEqual, LoggerAfterHandlerOptions, LoggerBeforeHandlerOptions, Maybe, OauthOptions, PositionPlacements, RequestError, RequestHeader, RequestInstance, RequestInterface, RequestMethod, RequestQuery, RequestQueryValue, RequestTransformIncoming, RequestTransformOutcoming, ValueOf, VisiblePosition };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krainovsd/js-helpers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Krainov helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "KrainovSD <denislosev48@gmail.com>",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
31
|
"publish-package": "npm run lint && npm run build && npm publish",
|
|
32
|
+
"dev": "vite --host --force",
|
|
32
33
|
"clear": "rm -rf ./lib",
|
|
33
34
|
"build-dev": "npm run clear && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --no-stdin --environment BUILD:development,NODE_ENV:development",
|
|
34
35
|
"build": "npm run clear && npm run build:types && npm run build:js",
|
|
@@ -63,6 +64,7 @@
|
|
|
63
64
|
"jest": "29.7.0",
|
|
64
65
|
"node-fetch": "2.7.0",
|
|
65
66
|
"@types/node-fetch": "2.6.12",
|
|
66
|
-
"ts-jest": "29.2.5"
|
|
67
|
+
"ts-jest": "29.2.5",
|
|
68
|
+
"vite": "6.2.1"
|
|
67
69
|
}
|
|
68
70
|
}
|
package/lib/esm/constants/api.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sources":["../../../src/constants/api.ts"],"sourcesContent":["export const API_MIDDLEWARES = {\n Oauth: \"oauth\",\n Logger: \"logger\",\n} as const;\n\nexport const POST_API_MIDDLEWARES = {\n Logger: \"logger\",\n} as const;\n"],"names":[],"mappings":"AAAa,MAAA,eAAe,GAAG;AAC7B,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,MAAM,EAAE,QAAQ;;AAGL,MAAA,oBAAoB,GAAG;AAClC,IAAA,MAAM,EAAE,QAAQ;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"colors.js","sources":["../../../src/constants/colors.ts"],"sourcesContent":["export const COLOR_FORMATS = {\n Hex: \"HEX\",\n Rgb: \"RGB\",\n Rgba: \"RGBA\",\n Hsl: \"HSL\",\n} as const;\n"],"names":[],"mappings":"AAAa,MAAA,aAAa,GAAG;AAC3B,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,GAAG,EAAE,KAAK;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sources":["../../../src/constants/date.ts"],"sourcesContent":["export const DATE_TYPES = {\n Days: \"days\",\n Months: \"months\",\n Years: \"years\",\n Seconds: \"seconds\",\n Minutes: \"minutes\",\n Hours: \"hours\",\n} as const;\n"],"names":[],"mappings":"AAAa,MAAA,UAAU,GAAG;AACxB,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,KAAK,EAAE,OAAO;AACd,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,KAAK,EAAE,OAAO;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","sources":["../../../src/constants/fields.ts"],"sourcesContent":["export const FIELD_TYPES = {\n Date: \"date\",\n Time: \"time\",\n DateTime: \"dateTime\",\n String: \"string\",\n Number: \"number\",\n Array: \"array\",\n} as const;\n"],"names":[],"mappings":"AAAa,MAAA,WAAW,GAAG;AACzB,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,KAAK,EAAE,OAAO;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../src/lib/api/constants.ts"],"sourcesContent":["export const RESPONSE_DATA_SYMBOL = Symbol(\"response data\");\n"],"names":[],"mappings":"MAAa,oBAAoB,GAAG,MAAM,CAAC,eAAe;;;;"}
|