@creopse/react 0.0.19 → 0.0.20
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/dist/{content-j9XJsmqN.js → content-BoknRW3o.js} +34 -28
- package/dist/{content-CGhgyzQQ.cjs → content-qfcmWHIZ.cjs} +34 -28
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/types/core/api.d.ts +2 -0
- package/types/hooks/api.d.ts +18 -16
- package/types/hooks/config.d.ts +0 -4
- package/types/types/api.d.ts +12 -5
- package/types/types/plugin.d.ts +0 -1
|
@@ -2499,6 +2499,18 @@ const {
|
|
|
2499
2499
|
getAdapter,
|
|
2500
2500
|
mergeConfig
|
|
2501
2501
|
} = axios;
|
|
2502
|
+
const api = axios.create({
|
|
2503
|
+
withCredentials: true,
|
|
2504
|
+
xsrfCookieName: "XSRF-TOKEN",
|
|
2505
|
+
xsrfHeaderName: "X-XSRF-TOKEN"
|
|
2506
|
+
});
|
|
2507
|
+
api.interceptors.request.use((config) => {
|
|
2508
|
+
const token2 = document.cookie.split("; ").find((row) => row.startsWith("XSRF-TOKEN="))?.split("=")[1];
|
|
2509
|
+
if (token2) {
|
|
2510
|
+
config.headers["X-XSRF-TOKEN"] = decodeURIComponent(token2);
|
|
2511
|
+
}
|
|
2512
|
+
return config;
|
|
2513
|
+
});
|
|
2502
2514
|
var MediaFileType;
|
|
2503
2515
|
(function(MediaFileType2) {
|
|
2504
2516
|
MediaFileType2[MediaFileType2["DOCUMENT"] = 1] = "DOCUMENT";
|
|
@@ -6810,15 +6822,12 @@ const useConfig = () => {
|
|
|
6810
6822
|
return {
|
|
6811
6823
|
...config,
|
|
6812
6824
|
apiBaseUrl,
|
|
6813
|
-
apiUrl: `${apiBaseUrl}/api
|
|
6814
|
-
apiRequestHeaders: {
|
|
6815
|
-
"X-API-Key": config.xApiKey
|
|
6816
|
-
}
|
|
6825
|
+
apiUrl: `${apiBaseUrl}/api`
|
|
6817
6826
|
};
|
|
6818
6827
|
}, [config]);
|
|
6819
6828
|
};
|
|
6820
6829
|
const useApi = () => {
|
|
6821
|
-
const { apiUrl,
|
|
6830
|
+
const { apiUrl, apiBaseUrl, debug } = useConfig();
|
|
6822
6831
|
const handleError = useCallback(
|
|
6823
6832
|
(error) => {
|
|
6824
6833
|
if (debug) {
|
|
@@ -6837,32 +6846,29 @@ const useApi = () => {
|
|
|
6837
6846
|
[debug]
|
|
6838
6847
|
);
|
|
6839
6848
|
const request = useCallback(
|
|
6840
|
-
async (payload,
|
|
6849
|
+
async (payload, accessForbiddenCallback) => {
|
|
6841
6850
|
let success = false;
|
|
6842
6851
|
let response = null;
|
|
6843
6852
|
let error = null;
|
|
6844
6853
|
try {
|
|
6845
|
-
|
|
6846
|
-
if (accessToken) {
|
|
6847
|
-
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
6848
|
-
}
|
|
6849
|
-
response = await axios.request({
|
|
6854
|
+
response = await api.request({
|
|
6850
6855
|
method: payload.method || "get",
|
|
6851
6856
|
params: payload.params || {},
|
|
6852
6857
|
data: payload.data || {},
|
|
6853
6858
|
url: payload.url || "/",
|
|
6854
|
-
baseURL: apiUrl,
|
|
6855
|
-
headers
|
|
6859
|
+
baseURL: payload.useApiBaseUrl ? apiBaseUrl : apiUrl,
|
|
6860
|
+
headers: payload.headers,
|
|
6861
|
+
...payload.responseType && { responseType: payload.responseType }
|
|
6856
6862
|
});
|
|
6857
6863
|
success = true;
|
|
6858
6864
|
} catch (err) {
|
|
6859
6865
|
error = err;
|
|
6860
6866
|
success = false;
|
|
6861
|
-
if (err.response
|
|
6867
|
+
if (err.response?.status == 401) {
|
|
6862
6868
|
accessForbiddenCallback?.();
|
|
6863
|
-
} else {
|
|
6864
|
-
|
|
6865
|
-
}
|
|
6869
|
+
} else if (err.response?.status == 419) {
|
|
6870
|
+
console.error("CSRF token mismatch");
|
|
6871
|
+
} else handleError(err);
|
|
6866
6872
|
}
|
|
6867
6873
|
return {
|
|
6868
6874
|
success,
|
|
@@ -6871,9 +6877,9 @@ const useApi = () => {
|
|
|
6871
6877
|
error
|
|
6872
6878
|
};
|
|
6873
6879
|
},
|
|
6874
|
-
[
|
|
6880
|
+
[apiBaseUrl, apiUrl, handleError]
|
|
6875
6881
|
);
|
|
6876
|
-
const
|
|
6882
|
+
const postItemRequest = useCallback(
|
|
6877
6883
|
async (payload) => {
|
|
6878
6884
|
const task = await request({
|
|
6879
6885
|
url: `/${payload.routeBase}`,
|
|
@@ -6884,7 +6890,7 @@ const useApi = () => {
|
|
|
6884
6890
|
},
|
|
6885
6891
|
[request]
|
|
6886
6892
|
);
|
|
6887
|
-
const
|
|
6893
|
+
const deleteItemRequest = useCallback(
|
|
6888
6894
|
async (payload) => {
|
|
6889
6895
|
const task = await request({
|
|
6890
6896
|
url: `/${payload.routeBase}/${payload.id}`,
|
|
@@ -6894,7 +6900,7 @@ const useApi = () => {
|
|
|
6894
6900
|
},
|
|
6895
6901
|
[request]
|
|
6896
6902
|
);
|
|
6897
|
-
const
|
|
6903
|
+
const putItemRequest = useCallback(
|
|
6898
6904
|
async (payload) => {
|
|
6899
6905
|
const task = await request({
|
|
6900
6906
|
url: `/${payload.routeBase}/${payload.id}`,
|
|
@@ -6905,7 +6911,7 @@ const useApi = () => {
|
|
|
6905
6911
|
},
|
|
6906
6912
|
[request]
|
|
6907
6913
|
);
|
|
6908
|
-
const
|
|
6914
|
+
const getAllItemsRequest = useCallback(
|
|
6909
6915
|
async (payload) => {
|
|
6910
6916
|
const task = await request({
|
|
6911
6917
|
url: `/${payload.routeBase}`
|
|
@@ -6914,7 +6920,7 @@ const useApi = () => {
|
|
|
6914
6920
|
},
|
|
6915
6921
|
[request]
|
|
6916
6922
|
);
|
|
6917
|
-
const
|
|
6923
|
+
const getItemRequest = useCallback(
|
|
6918
6924
|
async (payload) => {
|
|
6919
6925
|
const task = await request({
|
|
6920
6926
|
url: `/${payload.routeBase}/${payload.id}`
|
|
@@ -6925,11 +6931,11 @@ const useApi = () => {
|
|
|
6925
6931
|
);
|
|
6926
6932
|
return {
|
|
6927
6933
|
request,
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6934
|
+
getItemRequest,
|
|
6935
|
+
postItemRequest,
|
|
6936
|
+
putItemRequest,
|
|
6937
|
+
deleteItemRequest,
|
|
6938
|
+
getAllItemsRequest,
|
|
6933
6939
|
handleError
|
|
6934
6940
|
};
|
|
6935
6941
|
};
|
|
@@ -2500,6 +2500,18 @@ const {
|
|
|
2500
2500
|
getAdapter,
|
|
2501
2501
|
mergeConfig
|
|
2502
2502
|
} = axios;
|
|
2503
|
+
const api = axios.create({
|
|
2504
|
+
withCredentials: true,
|
|
2505
|
+
xsrfCookieName: "XSRF-TOKEN",
|
|
2506
|
+
xsrfHeaderName: "X-XSRF-TOKEN"
|
|
2507
|
+
});
|
|
2508
|
+
api.interceptors.request.use((config) => {
|
|
2509
|
+
const token2 = document.cookie.split("; ").find((row) => row.startsWith("XSRF-TOKEN="))?.split("=")[1];
|
|
2510
|
+
if (token2) {
|
|
2511
|
+
config.headers["X-XSRF-TOKEN"] = decodeURIComponent(token2);
|
|
2512
|
+
}
|
|
2513
|
+
return config;
|
|
2514
|
+
});
|
|
2503
2515
|
var MediaFileType;
|
|
2504
2516
|
(function(MediaFileType2) {
|
|
2505
2517
|
MediaFileType2[MediaFileType2["DOCUMENT"] = 1] = "DOCUMENT";
|
|
@@ -6811,15 +6823,12 @@ const useConfig = () => {
|
|
|
6811
6823
|
return {
|
|
6812
6824
|
...config,
|
|
6813
6825
|
apiBaseUrl,
|
|
6814
|
-
apiUrl: `${apiBaseUrl}/api
|
|
6815
|
-
apiRequestHeaders: {
|
|
6816
|
-
"X-API-Key": config.xApiKey
|
|
6817
|
-
}
|
|
6826
|
+
apiUrl: `${apiBaseUrl}/api`
|
|
6818
6827
|
};
|
|
6819
6828
|
}, [config]);
|
|
6820
6829
|
};
|
|
6821
6830
|
const useApi = () => {
|
|
6822
|
-
const { apiUrl,
|
|
6831
|
+
const { apiUrl, apiBaseUrl, debug } = useConfig();
|
|
6823
6832
|
const handleError = React.useCallback(
|
|
6824
6833
|
(error) => {
|
|
6825
6834
|
if (debug) {
|
|
@@ -6838,32 +6847,29 @@ const useApi = () => {
|
|
|
6838
6847
|
[debug]
|
|
6839
6848
|
);
|
|
6840
6849
|
const request = React.useCallback(
|
|
6841
|
-
async (payload,
|
|
6850
|
+
async (payload, accessForbiddenCallback) => {
|
|
6842
6851
|
let success = false;
|
|
6843
6852
|
let response = null;
|
|
6844
6853
|
let error = null;
|
|
6845
6854
|
try {
|
|
6846
|
-
|
|
6847
|
-
if (accessToken) {
|
|
6848
|
-
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
6849
|
-
}
|
|
6850
|
-
response = await axios.request({
|
|
6855
|
+
response = await api.request({
|
|
6851
6856
|
method: payload.method || "get",
|
|
6852
6857
|
params: payload.params || {},
|
|
6853
6858
|
data: payload.data || {},
|
|
6854
6859
|
url: payload.url || "/",
|
|
6855
|
-
baseURL: apiUrl,
|
|
6856
|
-
headers
|
|
6860
|
+
baseURL: payload.useApiBaseUrl ? apiBaseUrl : apiUrl,
|
|
6861
|
+
headers: payload.headers,
|
|
6862
|
+
...payload.responseType && { responseType: payload.responseType }
|
|
6857
6863
|
});
|
|
6858
6864
|
success = true;
|
|
6859
6865
|
} catch (err) {
|
|
6860
6866
|
error = err;
|
|
6861
6867
|
success = false;
|
|
6862
|
-
if (err.response
|
|
6868
|
+
if (err.response?.status == 401) {
|
|
6863
6869
|
accessForbiddenCallback?.();
|
|
6864
|
-
} else {
|
|
6865
|
-
|
|
6866
|
-
}
|
|
6870
|
+
} else if (err.response?.status == 419) {
|
|
6871
|
+
console.error("CSRF token mismatch");
|
|
6872
|
+
} else handleError(err);
|
|
6867
6873
|
}
|
|
6868
6874
|
return {
|
|
6869
6875
|
success,
|
|
@@ -6872,9 +6878,9 @@ const useApi = () => {
|
|
|
6872
6878
|
error
|
|
6873
6879
|
};
|
|
6874
6880
|
},
|
|
6875
|
-
[
|
|
6881
|
+
[apiBaseUrl, apiUrl, handleError]
|
|
6876
6882
|
);
|
|
6877
|
-
const
|
|
6883
|
+
const postItemRequest = React.useCallback(
|
|
6878
6884
|
async (payload) => {
|
|
6879
6885
|
const task = await request({
|
|
6880
6886
|
url: `/${payload.routeBase}`,
|
|
@@ -6885,7 +6891,7 @@ const useApi = () => {
|
|
|
6885
6891
|
},
|
|
6886
6892
|
[request]
|
|
6887
6893
|
);
|
|
6888
|
-
const
|
|
6894
|
+
const deleteItemRequest = React.useCallback(
|
|
6889
6895
|
async (payload) => {
|
|
6890
6896
|
const task = await request({
|
|
6891
6897
|
url: `/${payload.routeBase}/${payload.id}`,
|
|
@@ -6895,7 +6901,7 @@ const useApi = () => {
|
|
|
6895
6901
|
},
|
|
6896
6902
|
[request]
|
|
6897
6903
|
);
|
|
6898
|
-
const
|
|
6904
|
+
const putItemRequest = React.useCallback(
|
|
6899
6905
|
async (payload) => {
|
|
6900
6906
|
const task = await request({
|
|
6901
6907
|
url: `/${payload.routeBase}/${payload.id}`,
|
|
@@ -6906,7 +6912,7 @@ const useApi = () => {
|
|
|
6906
6912
|
},
|
|
6907
6913
|
[request]
|
|
6908
6914
|
);
|
|
6909
|
-
const
|
|
6915
|
+
const getAllItemsRequest = React.useCallback(
|
|
6910
6916
|
async (payload) => {
|
|
6911
6917
|
const task = await request({
|
|
6912
6918
|
url: `/${payload.routeBase}`
|
|
@@ -6915,7 +6921,7 @@ const useApi = () => {
|
|
|
6915
6921
|
},
|
|
6916
6922
|
[request]
|
|
6917
6923
|
);
|
|
6918
|
-
const
|
|
6924
|
+
const getItemRequest = React.useCallback(
|
|
6919
6925
|
async (payload) => {
|
|
6920
6926
|
const task = await request({
|
|
6921
6927
|
url: `/${payload.routeBase}/${payload.id}`
|
|
@@ -6926,11 +6932,11 @@ const useApi = () => {
|
|
|
6926
6932
|
);
|
|
6927
6933
|
return {
|
|
6928
6934
|
request,
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6935
|
+
getItemRequest,
|
|
6936
|
+
postItemRequest,
|
|
6937
|
+
putItemRequest,
|
|
6938
|
+
deleteItemRequest,
|
|
6939
|
+
getAllItemsRequest,
|
|
6934
6940
|
handleError
|
|
6935
6941
|
};
|
|
6936
6942
|
};
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const content = require("../content-
|
|
3
|
+
const content = require("../content-qfcmWHIZ.cjs");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const useNewsletter = () => {
|
|
6
6
|
const { request } = content.useApi();
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as useApi } from "../content-
|
|
2
|
-
import { f, a, u, b } from "../content-
|
|
1
|
+
import { e as useApi } from "../content-BoknRW3o.js";
|
|
2
|
+
import { f, a, u, b } from "../content-BoknRW3o.js";
|
|
3
3
|
import { useState, useCallback } from "react";
|
|
4
4
|
const useNewsletter = () => {
|
|
5
5
|
const { request } = useApi();
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
|
-
const content = require("./content-
|
|
4
|
+
const content = require("./content-qfcmWHIZ.cjs");
|
|
5
5
|
const react = require("@inertiajs/react");
|
|
6
6
|
const reactDom = require("react-dom");
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import React__default, { useState, useEffect, createContext, useRef, useLayoutEffect, useId, useContext, useInsertionEffect, useMemo, useCallback, Children, isValidElement, Fragment, createElement, forwardRef, Component } from "react";
|
|
3
|
-
import { u as useHelper, a as useContent, b as useProps, P as PropsContext, R as ResolveSectionsContext, c as cloneDeep, s as slideToId, E as EditorMessageType, d as RouterContext, C as ConfigContext } from "./content-
|
|
3
|
+
import { u as useHelper, a as useContent, b as useProps, P as PropsContext, R as ResolveSectionsContext, c as cloneDeep, s as slideToId, E as EditorMessageType, d as RouterContext, C as ConfigContext } from "./content-BoknRW3o.js";
|
|
4
4
|
import { router } from "@inertiajs/react";
|
|
5
5
|
import { createPortal } from "react-dom";
|
|
6
6
|
var jsxRuntime = { exports: {} };
|
package/package.json
CHANGED
package/types/hooks/api.d.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Payload, Response } from '@/types/api';
|
|
2
|
+
import type { AxiosError } from 'axios';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* A hook that provides a way to make API requests.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
* @returns {Object} An object containing the following methods:
|
|
6
|
+
* The hook provides the following methods:
|
|
7
7
|
* - `request`: Makes an API request with the given payload.
|
|
8
|
-
* - `
|
|
9
|
-
* - `
|
|
10
|
-
* - `
|
|
11
|
-
* - `
|
|
12
|
-
* - `
|
|
8
|
+
* - `getItemRequest`: Makes a GET request to the specified API endpoint with the given payload.
|
|
9
|
+
* - `postItemRequest`: Makes a POST request to the specified API endpoint with the given payload.
|
|
10
|
+
* - `putItemRequest`: Makes a PUT request to the specified API endpoint with the given payload.
|
|
11
|
+
* - `deleteItemRequest`: Makes a DELETE request to the specified API endpoint with the given payload.
|
|
12
|
+
* - `getAllItemsRequest`: Makes a GET request to the specified API endpoint with the given payload.
|
|
13
13
|
* - `handleError`: Handles an error from the API.
|
|
14
|
+
*
|
|
15
|
+
* @returns {Object} An object containing the methods listed above.
|
|
14
16
|
*/
|
|
15
17
|
export declare const useApi: () => {
|
|
16
|
-
request: (payload: Payload,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
handleError: (error:
|
|
18
|
+
request: <T = any>(payload: Payload, accessForbiddenCallback?: () => void) => Promise<Response<T>>;
|
|
19
|
+
getItemRequest: <T = any>(payload: Payload) => Promise<Response<T>>;
|
|
20
|
+
postItemRequest: <T = any>(payload: Payload) => Promise<Response<T>>;
|
|
21
|
+
putItemRequest: <T = any>(payload: Payload) => Promise<Response<T>>;
|
|
22
|
+
deleteItemRequest: <T = any>(payload: Payload) => Promise<Response<T>>;
|
|
23
|
+
getAllItemsRequest: <T = any>(payload: Payload) => Promise<Response<T>>;
|
|
24
|
+
handleError: (error: AxiosError) => void;
|
|
23
25
|
};
|
package/types/hooks/config.d.ts
CHANGED
|
@@ -10,12 +10,8 @@
|
|
|
10
10
|
export declare const useConfig: () => {
|
|
11
11
|
apiBaseUrl: string;
|
|
12
12
|
apiUrl: string;
|
|
13
|
-
apiRequestHeaders: {
|
|
14
|
-
'X-API-Key': string;
|
|
15
|
-
};
|
|
16
13
|
debug: boolean;
|
|
17
14
|
appUrl: string;
|
|
18
|
-
xApiKey: string;
|
|
19
15
|
locale: string;
|
|
20
16
|
fallbackLocale: string;
|
|
21
17
|
encryptionKey: string;
|
package/types/types/api.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
import type { ResponseType } from 'axios';
|
|
1
2
|
export type Method = 'get' | 'post' | 'put' | 'delete';
|
|
2
3
|
export interface Payload {
|
|
3
4
|
method?: Method;
|
|
4
5
|
routeBase?: string;
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
responseType?: ResponseType;
|
|
7
|
+
params?: Record<string, any>;
|
|
8
|
+
data?: Record<string, any>;
|
|
7
9
|
url?: string;
|
|
8
10
|
id?: string;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
useApiBaseUrl?: boolean;
|
|
9
13
|
}
|
|
10
|
-
export interface
|
|
14
|
+
export interface Response<T> {
|
|
11
15
|
success: boolean;
|
|
12
16
|
failure: boolean;
|
|
13
|
-
result:
|
|
14
|
-
|
|
17
|
+
result: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
data?: T;
|
|
20
|
+
};
|
|
21
|
+
error?: any;
|
|
15
22
|
}
|