@anker-in/campaign-ui 0.5.19 → 0.5.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/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 +2 -13
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var g=(t,r)=>{for(var e in r)a(t,e,{get:r[e],enumerable:!0})},d=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of y(r))!_.call(t,o)&&o!==e&&a(t,o,{get:()=>r[o],enumerable:!(n=m(r,o))||n.enumerable});return t};var h=(t,r,e)=>(e=t!=null?p(f(t)):{},d(r||!t||!t.__esModule?a(e,"default",{value:t,enumerable:!0}):e,t)),b=t=>d(a({},"__esModule",{value:!0}),t);var C={};g(C,{useUploadReceipt:()=>v});module.exports=b(C);var s=h(require("swr/mutation")),c=require("../../../../lib"),u=require("../provider");const k=t=>t&&(typeof t.data=="object"&&!Array.isArray(t.data)&&"data"in t.data?t.data:t),v=()=>{const{locale:t}=(0,c.useHeadlessContext)(),{apiBaseUrl:r}=(0,u.useCreditsContext)(),e=async(n,{arg:{orderName:o}})=>{const l=await(await fetch(`${r||""}/api/multipass/mktsrv/v1/credit/upload_third_party_order`,{credentials:"include",method:"POST",headers:{"Content-Type":"application/json","current-language":t},body:JSON.stringify({order_name:o})})).json(),i=k(l);return{ok:i?.code===0,code:i?.code??-1}};return(0,s.default)(`${r||""}/api/multipass/mktsrv/v1/credit/upload_third_party_order`,e)};
|
|
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 if (typeof responseData.data === 'object' && !Array.isArray(responseData.data) && 'data' in responseData.data) {\n return responseData.data\n }\n\n // \u4E00\u5C42\u7ED3\u6784\uFF0C\u76F4\u63A5\u8FD4\u56DE\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,IAED,OAAOA,EAAa,MAAS,UAAY,CAAC,MAAM,QAAQA,EAAa,IAAI,GAAK,SAAUA,EAAa,KAChGA,EAAa,KAIfA,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
|
|
1
|
+
import i from"swr/mutation";import{useHeadlessContext as d}from"../../../../lib";import{useCreditsContext as s}from"../provider";const c=t=>t&&(typeof t.data=="object"&&!Array.isArray(t.data)&&"data"in t.data?t.data:t),f=()=>{const{locale:t}=d(),{apiBaseUrl:r}=s(),o=async(u,{arg:{orderName:a}})=>{const n=await(await fetch(`${r||""}/api/multipass/mktsrv/v1/credit/upload_third_party_order`,{credentials:"include",method:"POST",headers:{"Content-Type":"application/json","current-language":t},body:JSON.stringify({order_name:a})})).json(),e=c(n);return{ok:e?.code===0,code:e?.code??-1}};return i(`${r||""}/api/multipass/mktsrv/v1/credit/upload_third_party_order`,o)};export{f 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 if (typeof responseData.data === 'object' && !Array.isArray(responseData.data) && 'data' in responseData.data) {\n return responseData.data\n }\n\n // \u4E00\u5C42\u7ED3\u6784\uFF0C\u76F4\u63A5\u8FD4\u56DE\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,IAED,OAAOA,EAAa,MAAS,UAAY,CAAC,MAAM,QAAQA,EAAa,IAAI,GAAK,SAAUA,EAAa,KAChGA,EAAa,KAIfA,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,22 +2,11 @@ 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
|
-
// 两层结构:外层 data 是对象,且其内部还有 data 字段
|
|
19
|
-
if (inner && typeof inner === 'object' && !Array.isArray(inner) && 'data' in inner) {
|
|
20
|
-
return inner
|
|
8
|
+
if (typeof responseData.data === 'object' && !Array.isArray(responseData.data) && 'data' in responseData.data) {
|
|
9
|
+
return responseData.data
|
|
21
10
|
}
|
|
22
11
|
|
|
23
12
|
// 一层结构,直接返回
|