@anker-in/campaign-ui 0.5.19 → 0.5.21
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/cjs/components/credits/context/hooks/useUploadReceipt.js +1 -1
- package/dist/cjs/components/credits/context/hooks/useUploadReceipt.js.map +3 -3
- package/dist/esm/components/credits/context/hooks/useUploadReceipt.js +1 -1
- package/dist/esm/components/credits/context/hooks/useUploadReceipt.js.map +3 -3
- package/package.json +1 -1
- package/src/components/credits/context/hooks/useUploadReceipt.tsx +3 -15
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var l=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var l=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(e,t)=>{for(var r in t)a(e,r,{get:t[r],enumerable:!0})},s=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!f.call(e,o)&&o!==r&&a(e,o,{get:()=>t[o],enumerable:!(n=m(t,o))||n.enumerable});return e};var h=(e,t,r)=>(r=e!=null?l(_(e)):{},s(t||!e||!e.__esModule?a(r,"default",{value:e,enumerable:!0}):r,e)),k=e=>s(a({},"__esModule",{value:!0}),e);var R={};g(R,{useUploadReceipt:()=>C});module.exports=k(R);var d=h(require("swr/mutation")),c=require("../../../../lib"),u=require("../provider");const v=e=>e&&(e.data?e.data:e),C=()=>{const{locale:e}=(0,c.useHeadlessContext)(),{apiBaseUrl:t}=(0,u.useCreditsContext)(),r=async(n,{arg:{orderName:o}})=>{const p=await(await fetch(`${t||""}/api/multipass/mktsrv/v1/credit/upload_third_party_order`,{credentials:"include",method:"POST",headers:{"Content-Type":"application/json","current-language":e},body:JSON.stringify({order_name:o})})).json(),i=v(p);return{ok:i?.code===0,code:i?.code??-1}};return(0,d.default)(`${t||""}/api/multipass/mktsrv/v1/credit/upload_third_party_order`,r)};
|
|
2
2
|
//# sourceMappingURL=useUploadReceipt.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useUploadReceipt.tsx"],
|
|
4
|
-
"sourcesContent": ["import useSWRMutation from 'swr/mutation'\nimport { useHeadlessContext } from '../../../../lib'\nimport { useCreditsContext } from '../provider'\n\
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA2B,2BAC3BC,EAAmC,2BACnCC,EAAkC,
|
|
6
|
-
"names": ["useUploadReceipt_exports", "__export", "useUploadReceipt", "__toCommonJS", "import_mutation", "import_lib", "import_provider", "normalizeResponseData", "responseData", "
|
|
4
|
+
"sourcesContent": ["import useSWRMutation from 'swr/mutation'\nimport { useHeadlessContext } from '../../../../lib'\nimport { useCreditsContext } from '../provider'\n\nconst normalizeResponseData = (responseData: any) => {\n if (!responseData) return responseData\n\n // \u517C\u5BB9\u90E8\u5206\u4ED3\u5E93\u7684\u4EE3\u7801\u4F1A\u5BF9\u8FD4\u56DE\u8FDB\u884C\u5C01\u88C5\n if (responseData.data) {\n return responseData.data\n }\n return responseData\n}\n\nexport const useUploadReceipt = () => {\n const { locale } = useHeadlessContext()\n const { apiBaseUrl } = useCreditsContext()\n\n const uploadReceipt = async (\n _: any,\n { arg: { orderName } }: { arg: { orderName: string } }\n ): Promise<{\n ok: boolean\n code: number\n }> => {\n const response = await fetch(`${apiBaseUrl || ''}/api/multipass/mktsrv/v1/credit/upload_third_party_order`, {\n credentials: 'include',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': locale,\n },\n body: JSON.stringify({\n order_name: orderName,\n }),\n })\n const result = await response.json()\n const normalizedData = normalizeResponseData(result)\n return {\n ok: normalizedData?.code === 0,\n code: normalizedData?.code ?? -1,\n }\n }\n\n return useSWRMutation(`${apiBaseUrl || ''}/api/multipass/mktsrv/v1/credit/upload_third_party_order`, uploadReceipt)\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA2B,2BAC3BC,EAAmC,2BACnCC,EAAkC,uBAElC,MAAMC,EAAyBC,GACxBA,IAGDA,EAAa,KACRA,EAAa,KAEfA,GAGIN,EAAmB,IAAM,CACpC,KAAM,CAAE,OAAAO,CAAO,KAAI,sBAAmB,EAChC,CAAE,WAAAC,CAAW,KAAI,qBAAkB,EAEnCC,EAAgB,MACpBC,EACA,CAAE,IAAK,CAAE,UAAAC,CAAU,CAAE,IAIjB,CAYJ,MAAMC,EAAS,MAXE,MAAM,MAAM,GAAGJ,GAAc,EAAE,2DAA4D,CAC1G,YAAa,UACb,OAAQ,OACR,QAAS,CACP,eAAgB,mBAChB,mBAAoBD,CACtB,EACA,KAAM,KAAK,UAAU,CACnB,WAAYI,CACd,CAAC,CACH,CAAC,GAC6B,KAAK,EAC7BE,EAAiBR,EAAsBO,CAAM,EACnD,MAAO,CACL,GAAIC,GAAgB,OAAS,EAC7B,KAAMA,GAAgB,MAAQ,EAChC,CACF,EAEA,SAAO,EAAAC,SAAe,GAAGN,GAAc,EAAE,2DAA4DC,CAAa,CACpH",
|
|
6
|
+
"names": ["useUploadReceipt_exports", "__export", "useUploadReceipt", "__toCommonJS", "import_mutation", "import_lib", "import_provider", "normalizeResponseData", "responseData", "locale", "apiBaseUrl", "uploadReceipt", "_", "orderName", "result", "normalizedData", "useSWRMutation"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import i from"swr/mutation";import{useHeadlessContext as s}from"../../../../lib";import{useCreditsContext as d}from"../provider";const c=
|
|
1
|
+
import i from"swr/mutation";import{useHeadlessContext as s}from"../../../../lib";import{useCreditsContext as d}from"../provider";const c=e=>e&&(e.data?e.data:e),_=()=>{const{locale:e}=s(),{apiBaseUrl:t}=d(),o=async(u,{arg:{orderName:a}})=>{const n=await(await fetch(`${t||""}/api/multipass/mktsrv/v1/credit/upload_third_party_order`,{credentials:"include",method:"POST",headers:{"Content-Type":"application/json","current-language":e},body:JSON.stringify({order_name:a})})).json(),r=c(n);return{ok:r?.code===0,code:r?.code??-1}};return i(`${t||""}/api/multipass/mktsrv/v1/credit/upload_third_party_order`,o)};export{_ as useUploadReceipt};
|
|
2
2
|
//# sourceMappingURL=useUploadReceipt.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/components/credits/context/hooks/useUploadReceipt.tsx"],
|
|
4
|
-
"sourcesContent": ["import useSWRMutation from 'swr/mutation'\nimport { useHeadlessContext } from '../../../../lib'\nimport { useCreditsContext } from '../provider'\n\
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAoB,eAC3B,OAAS,sBAAAC,MAA0B,kBACnC,OAAS,qBAAAC,MAAyB,
|
|
6
|
-
"names": ["useSWRMutation", "useHeadlessContext", "useCreditsContext", "normalizeResponseData", "responseData", "
|
|
4
|
+
"sourcesContent": ["import useSWRMutation from 'swr/mutation'\nimport { useHeadlessContext } from '../../../../lib'\nimport { useCreditsContext } from '../provider'\n\nconst normalizeResponseData = (responseData: any) => {\n if (!responseData) return responseData\n\n // \u517C\u5BB9\u90E8\u5206\u4ED3\u5E93\u7684\u4EE3\u7801\u4F1A\u5BF9\u8FD4\u56DE\u8FDB\u884C\u5C01\u88C5\n if (responseData.data) {\n return responseData.data\n }\n return responseData\n}\n\nexport const useUploadReceipt = () => {\n const { locale } = useHeadlessContext()\n const { apiBaseUrl } = useCreditsContext()\n\n const uploadReceipt = async (\n _: any,\n { arg: { orderName } }: { arg: { orderName: string } }\n ): Promise<{\n ok: boolean\n code: number\n }> => {\n const response = await fetch(`${apiBaseUrl || ''}/api/multipass/mktsrv/v1/credit/upload_third_party_order`, {\n credentials: 'include',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'current-language': locale,\n },\n body: JSON.stringify({\n order_name: orderName,\n }),\n })\n const result = await response.json()\n const normalizedData = normalizeResponseData(result)\n return {\n ok: normalizedData?.code === 0,\n code: normalizedData?.code ?? -1,\n }\n }\n\n return useSWRMutation(`${apiBaseUrl || ''}/api/multipass/mktsrv/v1/credit/upload_third_party_order`, uploadReceipt)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAoB,eAC3B,OAAS,sBAAAC,MAA0B,kBACnC,OAAS,qBAAAC,MAAyB,cAElC,MAAMC,EAAyBC,GACxBA,IAGDA,EAAa,KACRA,EAAa,KAEfA,GAGIC,EAAmB,IAAM,CACpC,KAAM,CAAE,OAAAC,CAAO,EAAIL,EAAmB,EAChC,CAAE,WAAAM,CAAW,EAAIL,EAAkB,EAEnCM,EAAgB,MACpBC,EACA,CAAE,IAAK,CAAE,UAAAC,CAAU,CAAE,IAIjB,CAYJ,MAAMC,EAAS,MAXE,MAAM,MAAM,GAAGJ,GAAc,EAAE,2DAA4D,CAC1G,YAAa,UACb,OAAQ,OACR,QAAS,CACP,eAAgB,mBAChB,mBAAoBD,CACtB,EACA,KAAM,KAAK,UAAU,CACnB,WAAYI,CACd,CAAC,CACH,CAAC,GAC6B,KAAK,EAC7BE,EAAiBT,EAAsBQ,CAAM,EACnD,MAAO,CACL,GAAIC,GAAgB,OAAS,EAC7B,KAAMA,GAAgB,MAAQ,EAChC,CACF,EAEA,OAAOZ,EAAe,GAAGO,GAAc,EAAE,2DAA4DC,CAAa,CACpH",
|
|
6
|
+
"names": ["useSWRMutation", "useHeadlessContext", "useCreditsContext", "normalizeResponseData", "responseData", "useUploadReceipt", "locale", "apiBaseUrl", "uploadReceipt", "_", "orderName", "result", "normalizedData"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -2,25 +2,13 @@ import useSWRMutation from 'swr/mutation'
|
|
|
2
2
|
import { useHeadlessContext } from '../../../../lib'
|
|
3
3
|
import { useCreditsContext } from '../provider'
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* 统一处理 ALPC 接口返回的数据结构
|
|
7
|
-
* 兼容一层 data 和两层 data 的场景:
|
|
8
|
-
* - 两层 data: {data: {data: ..., code: 0}} → 剥掉外层,返回内层 {data: ..., code: 0}
|
|
9
|
-
* - 一层 data: {data: ..., code: 0} → 直接返回,不做处理
|
|
10
|
-
*
|
|
11
|
-
* 判断两层的依据:responseData.data.data 存在(外层 data 内部还有一层 data)
|
|
12
|
-
*/
|
|
13
5
|
const normalizeResponseData = (responseData: any) => {
|
|
14
6
|
if (!responseData) return responseData
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (inner && typeof inner === 'object' && !Array.isArray(inner) && 'data' in inner) {
|
|
20
|
-
return inner
|
|
8
|
+
// 兼容部分仓库的代码会对返回进行封装
|
|
9
|
+
if (responseData.data) {
|
|
10
|
+
return responseData.data
|
|
21
11
|
}
|
|
22
|
-
|
|
23
|
-
// 一层结构,直接返回
|
|
24
12
|
return responseData
|
|
25
13
|
}
|
|
26
14
|
|