@obb871001/api-integration-sdk 1.0.5 → 1.0.8

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/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "@obb871001/api-integration-sdk",
3
3
  "private": false,
4
- "version": "1.0.5",
4
+ "version": "1.0.8",
5
5
  "description": "集成API",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
8
8
  "type": "module",
9
9
  "exports": {
10
10
  ".": {
11
- "import": "./src/index.js",
11
+ "import": "./dist/index.js",
12
12
  "require": "./dist/index.cjs"
13
13
  }
14
14
  },
15
15
  "files": [
16
- "src",
17
16
  "dist",
18
17
  "README.md"
19
18
  ],
package/src/App.css DELETED
@@ -1,42 +0,0 @@
1
- #root {
2
- max-width: 1280px;
3
- margin: 0 auto;
4
- padding: 2rem;
5
- text-align: center;
6
- }
7
-
8
- .logo {
9
- height: 6em;
10
- padding: 1.5em;
11
- will-change: filter;
12
- transition: filter 300ms;
13
- }
14
- .logo:hover {
15
- filter: drop-shadow(0 0 2em #646cffaa);
16
- }
17
- .logo.react:hover {
18
- filter: drop-shadow(0 0 2em #61dafbaa);
19
- }
20
-
21
- @keyframes logo-spin {
22
- from {
23
- transform: rotate(0deg);
24
- }
25
- to {
26
- transform: rotate(360deg);
27
- }
28
- }
29
-
30
- @media (prefers-reduced-motion: no-preference) {
31
- a:nth-of-type(2) .logo {
32
- animation: logo-spin infinite 20s linear;
33
- }
34
- }
35
-
36
- .card {
37
- padding: 2em;
38
- }
39
-
40
- .read-the-docs {
41
- color: #888;
42
- }
package/src/App.jsx DELETED
@@ -1,7 +0,0 @@
1
- import "./App.css";
2
-
3
- function App() {
4
- return <></>;
5
- }
6
-
7
- export default App;
package/src/api/client.js DELETED
@@ -1,59 +0,0 @@
1
- import axios from "axios";
2
-
3
- /**
4
- * 建立 axios instance(可選擇性注入 getToken / 其他攔截器)
5
- * @param {Object} options
6
- * @param {string} options.baseURL
7
- * @param {() => (string|undefined|Promise<string|undefined>)} [options.getToken]
8
- * @param {number} [options.timeoutMs=15000]
9
- * @param {import('axios').AxiosInstance} [options.axiosInstance] - 若有外部共用 instance,可直接注入
10
- * @param {string} [options.currency] - 預設貨幣代碼(可用於自訂攔截器)
11
- * @param {string} [options.lng] - 預設語言代碼(可用於自訂攔截器)
12
- * @param {(error:any, ctx:{instance:any}) => any} [options.onError] - 統一錯誤處理(可回傳 Promise.reject(error))
13
- * @returns {import('axios').AxiosInstance}
14
- */
15
- export function createAxiosClient({
16
- baseURL,
17
- getToken,
18
- timeoutMs = 15000,
19
- axiosInstance,
20
- currency,
21
- lng,
22
- onError,
23
- } = {}) {
24
- const instance =
25
- axiosInstance ??
26
- axios.create({
27
- baseURL: baseURL,
28
- timeout: timeoutMs,
29
- headers: { "Content-Type": "application/json" },
30
- });
31
-
32
- instance.interceptors.request.use(async (config) => {
33
- if (getToken) {
34
- const token = await getToken();
35
- if (token) {
36
- config.headers = config.headers || {};
37
- config.headers.Authorization = `Bearer ${token}`;
38
- }
39
- }
40
- return config;
41
- });
42
-
43
- instance.interceptors.request.use((config) => {
44
- config.headers.Currency = currency;
45
- config.headers[`currency-code`] = currency;
46
- config.headers[`lang`] = lng;
47
- });
48
-
49
- // Response: 統一錯誤處理(交由外部決定)
50
- instance.interceptors.response.use(
51
- (res) => res,
52
- (err) => {
53
- if (onError) return onError(err, { instance });
54
- return Promise.reject(err);
55
- }
56
- );
57
-
58
- return instance;
59
- }
@@ -1,19 +0,0 @@
1
- import { useQueries } from "@tanstack/react-query";
2
- import React from "react";
3
- import useUserApi from "../services/useUserApi.jsx";
4
-
5
- const usePeriodicDataUpdater = () => {
6
- const { userInfoApi } = useUserApi();
7
- const { data, isFetching } = useQueries({
8
- queries: [
9
- {
10
- queryKey: ["getMemberInfo"],
11
- queryFn: userInfoApi,
12
- refetchInterval: 50000,
13
- },
14
- ],
15
- });
16
- return { data, isFetching };
17
- };
18
-
19
- export default usePeriodicDataUpdater;
@@ -1,10 +0,0 @@
1
- import React, { createContext, useContext } from "react";
2
-
3
- const ApiCtx = createContext(null);
4
-
5
- export const useAxios = () => {
6
- const ctx = useContext(ApiCtx);
7
-
8
- if (!ctx) throw new Error("useAxios must be used inside <ApiProvider>");
9
- return ctx.client;
10
- };
package/src/index.css DELETED
@@ -1,68 +0,0 @@
1
- :root {
2
- font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
3
- line-height: 1.5;
4
- font-weight: 400;
5
-
6
- color-scheme: light dark;
7
- color: rgba(255, 255, 255, 0.87);
8
- background-color: #242424;
9
-
10
- font-synthesis: none;
11
- text-rendering: optimizeLegibility;
12
- -webkit-font-smoothing: antialiased;
13
- -moz-osx-font-smoothing: grayscale;
14
- }
15
-
16
- a {
17
- font-weight: 500;
18
- color: #646cff;
19
- text-decoration: inherit;
20
- }
21
- a:hover {
22
- color: #535bf2;
23
- }
24
-
25
- body {
26
- margin: 0;
27
- display: flex;
28
- place-items: center;
29
- min-width: 320px;
30
- min-height: 100vh;
31
- }
32
-
33
- h1 {
34
- font-size: 3.2em;
35
- line-height: 1.1;
36
- }
37
-
38
- button {
39
- border-radius: 8px;
40
- border: 1px solid transparent;
41
- padding: 0.6em 1.2em;
42
- font-size: 1em;
43
- font-weight: 500;
44
- font-family: inherit;
45
- background-color: #1a1a1a;
46
- cursor: pointer;
47
- transition: border-color 0.25s;
48
- }
49
- button:hover {
50
- border-color: #646cff;
51
- }
52
- button:focus,
53
- button:focus-visible {
54
- outline: 4px auto -webkit-focus-ring-color;
55
- }
56
-
57
- @media (prefers-color-scheme: light) {
58
- :root {
59
- color: #213547;
60
- background-color: #ffffff;
61
- }
62
- a:hover {
63
- color: #747bff;
64
- }
65
- button {
66
- background-color: #f9f9f9;
67
- }
68
- }
package/src/index.js DELETED
@@ -1,4 +0,0 @@
1
- export * from "./function/usePeriodicDataUpdater.js";
2
- export * from "./services/index.js";
3
- export * from "./hooks/useAxios.js";
4
- export * from "./provider.jsx";
package/src/main.jsx DELETED
@@ -1,10 +0,0 @@
1
- import { StrictMode } from 'react'
2
- import { createRoot } from 'react-dom/client'
3
- import './index.css'
4
- import App from './App.jsx'
5
-
6
- createRoot(document.getElementById('root')).render(
7
- <StrictMode>
8
- <App />
9
- </StrictMode>,
10
- )
package/src/provider.jsx DELETED
@@ -1,15 +0,0 @@
1
- import { useMemo } from "react";
2
- import { createAxiosClient } from "./api/client";
3
-
4
- /**
5
- * ApiProvider props:
6
- * - baseURL: string
7
- * - getToken?: () => string | undefined | Promise<string | undefined>
8
- * - timeoutMs?: number
9
- * - axiosInstance?: AxiosInstance // 注入你自己的 axios(可共用攔截器)
10
- * - onError?: (error, ctx) => any // 全域錯誤處理
11
- */
12
- export default function ApiProvider({ children, ...opts }) {
13
- const client = useMemo(() => createAxiosClient(opts), [opts]);
14
- return <ApiCtx.Provider value={{ client }}>{children}</ApiCtx.Provider>;
15
- }
@@ -1,2 +0,0 @@
1
- export * from "./useCommonApi.jsx";
2
- export * from "./useUserApi.jsx";
@@ -1,28 +0,0 @@
1
- import React, { useCallback } from "react";
2
- import { useAxios } from "../hooks/useAxios";
3
-
4
- const useCommonApi = () => {
5
- const axios = useAxios();
6
-
7
- /**
8
- * @description 取得輪播圖資訊
9
- * @return {Promise<Object>} 輪播圖資訊
10
- */
11
- const carouselApi = useCallback(async () => {
12
- const { data } = await axios.get("/carousels");
13
- return data;
14
- }, [axios]);
15
-
16
- /**
17
- * @description 取得跑馬燈資訊
18
- * @return {Promise<Object>} 跑馬燈資訊
19
- */
20
- const marqueeApi = useCallback(async () => {
21
- const { data } = await axios.get("/marquees");
22
- return data;
23
- }, [axios]);
24
-
25
- return { carouselApi, marqueeApi };
26
- };
27
-
28
- export default useCommonApi;
@@ -1,78 +0,0 @@
1
- import React, { useCallback } from "react";
2
- import { useAxios } from "../hooks/useAxios";
3
-
4
- /**
5
- * @description 使用者相關 API
6
- * @returns {Object} API 方法集合
7
- * @property {Function} machineLoginApi 機台登入 API
8
- * @property {Function} userInfoApi 取得使用者資訊 API
9
- */
10
- const useUserApi = () => {
11
- const axios = useAxios();
12
-
13
- /**
14
- * @description 機台登入
15
- * @param {Object} params
16
- * @param {string} params.mac_address 機台 MAC 地址
17
- * @param {string} params.app_version 應用程式版本
18
- * @param {string} params.anydesk_id 遠端協助軟體 ID
19
- */
20
- const machineLoginApi = useCallback(
21
- async (params) => {
22
- const { mac_address = "", app_version = "", anydesk_id = "" } = params;
23
- const { data } = await axios.post("/cash-register/login", {
24
- mac_address,
25
- app_version,
26
- anydesk_id,
27
- });
28
- return data;
29
- },
30
- [axios]
31
- );
32
-
33
- /**
34
- * @description 取得使用者資訊
35
- * @return {Promise<Object>} 使用者資訊
36
- */
37
- const userInfoApi = useCallback(async () => {
38
- const { data } = await axios.get("/getMemberInfo");
39
- return data;
40
- }, [axios]);
41
-
42
- /**
43
- * @description 取得使用者遊戲列表
44
- * @return {Promise<Object>} 使用者遊戲列表
45
- */
46
- const userGameListApi = useCallback(async () => {
47
- const { data } = await axios.get("/getGameList");
48
- return data;
49
- }, [axios]);
50
-
51
- /**
52
- * @description 取得即時匯率資訊
53
- * @return {Promise<Object>} 即時匯率資訊
54
- */
55
- const userCurrencyExchangeApi = useCallback(async () => {
56
- const { data } = await axios.get("/getNowCurrencyExchange");
57
- return data;
58
- }, [axios]);
59
-
60
- /**
61
- * @description 取得使用者最愛遊戲列表
62
- * @return {Promise<Object>} 使用者最愛遊戲列表
63
- */
64
- const userFavoriteGameApi = useCallback(async () => {
65
- const { data } = await axios.get("/getFavoriteGame");
66
- return data;
67
- }, [axios]);
68
-
69
- return {
70
- machineLoginApi,
71
- userInfoApi,
72
- userGameListApi,
73
- userFavoriteGameApi,
74
- userCurrencyExchangeApi,
75
- };
76
- };
77
-
78
- export default useUserApi;