@nvwa-app/sdk-core 6.10.0 → 6.12.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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _nvwa_app_postgrest_js from '@nvwa-app/postgrest-js';
|
|
2
2
|
import { PostgrestClient } from '@nvwa-app/postgrest-js';
|
|
3
3
|
import { NvwaFetch, URL, RequestInfo, RequestInit, Response, Headers } from '@nvwa-app/nvwa-http-polyfill';
|
|
4
|
+
export { Headers, NvwaFetch, Request, RequestInfo, RequestInit, Response, URL } from '@nvwa-app/nvwa-http-polyfill';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Payment 纯前端能力:仅「发起支付」。
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _nvwa_app_postgrest_js from '@nvwa-app/postgrest-js';
|
|
2
2
|
import { PostgrestClient } from '@nvwa-app/postgrest-js';
|
|
3
3
|
import { NvwaFetch, URL, RequestInfo, RequestInit, Response, Headers } from '@nvwa-app/nvwa-http-polyfill';
|
|
4
|
+
export { Headers, NvwaFetch, Request, RequestInfo, RequestInit, Response, URL } from '@nvwa-app/nvwa-http-polyfill';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Payment 纯前端能力:仅「发起支付」。
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var T=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var M=(r,t)=>{for(var e in t)T(r,e,{get:t[e],enumerable:!0})},D=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of J(t))!z.call(r,n)&&n!==e&&T(r,n,{get:()=>t[n],enumerable:!(s=B(t,n))||s.enumerable});return r};var Y=r=>D(T({},"__esModule",{value:!0}),r);var ot={};M(ot,{AuthClient:()=>E,CURRENT_JWT_KEY:()=>c,ENTITIES_BASE_PATH:()=>q,FILE_STORAGE_BASE_PATH:()=>$,GENERATE_UPLOAD_URL_PATH:()=>I,LOGIN_TOKEN_KEY:()=>f,LOGIN_USER_PROFILE_KEY:()=>w,NvwaEdgeFunctions:()=>S,NvwaFileStorage:()=>k,NvwaHttpClient:()=>_,OverlayManager:()=>A,SET_AUTH_TOKEN_HEADER:()=>R,createPostgrestClient:()=>rt,getSourceLocationFromDOM:()=>it,normalizePayParams:()=>nt,requestPaymentFromOrderResult:()=>at});module.exports=Y(ot);var S=class{constructor(t,e=""){this.http=t,this.baseUrl=e.replace(/\/$/,"")}async invoke(t,e){let s=this.baseUrl?`${this.baseUrl}/functions/${t}`:`/functions/${t}`;return await(await this.http.fetch(s,{method:e.method||"POST",body:e.body,headers:e.headers})).json()}};var c="nvwa_current_jwt",f="nvwa_login_token",w="nvwa_user_profile",R="set-auth-token",K=typeof fetch<"u"?(r,t)=>fetch(r,t):()=>{throw new Error("AuthClient requires fetch")},E=class{constructor(t,e={}){this.baseUrl=t.replace(/\/$/,""),this.authPath=(e.authPath??"/auth").replace(/^\//,""),this.fetchImpl=e.fetchImpl??K,this.storage=e.storage??null,this.credentials=e.credentials??"omit",typeof console<"u"&&(console.warn("[NvwaAuth] init baseUrl:",this.baseUrl||"(empty)"),(!this.baseUrl||!this.baseUrl.startsWith("http://")&&!this.baseUrl.startsWith("https://"))&&console.warn("[NvwaAuth] baseUrl \u5E94\u4E3A\u5B8C\u6574\u5730\u5740\uFF08\u5982 https://xxx.nvwa.app\uFF09\uFF0C\u5426\u5219\u5C0F\u7A0B\u5E8F request \u4F1A\u62A5 invalid url"))}async currentUser(){if(this.storage){let s=await this.storage.get(w);if(s!=null)return s}let{data:t}=await this.getSession(),e=t?.user??null;return e&&this.storage&&await this.storage.set(w,e),e}async getCurrentJwt(){if(this.storage){let e=await this.storage.get(c);if(e!=null)return e;let s=await this.storage.get(f),{data:n}=await this.getToken(s??void 0);return n?.token?(await this.storage.set(c,n.token),n.token):null}let{data:t}=await this.getToken();return t?.token??null}async persistLogin(t,e){if(!this.storage)return;let n=e?.headers.get(R)?.trim()||t.token||t.session?.token;n&&await this.storage.set(f,n),t.user&&await this.storage.set(w,t.user);let i=n??await this.storage.get(f),{data:a}=await this.getToken(i??void 0);a?.token&&await this.storage.set(c,a.token)}async clearLogin(){this.storage&&(await this.storage.remove(f),await this.storage.remove(w),await this.storage.remove(c))}getGoogleOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("google/openplatform/login")}?${e.toString()}`}startGoogleOpenPlatformLogin(t){let e=this.getGoogleOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startGoogleOpenPlatformLogin requires a browser environment with location")}async completeGoogleOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeGoogleOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithGoogleExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithGoogleExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("google/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):null;return!i?.token||!i.user?{error:{message:"invalid_google_login_response",status:502}}:(this.storage&&(await this.storage.set(c,i.token),await this.storage.set(f,i.token),await this.storage.set(w,i.user)),{data:i})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getGoogleOpenPlatformIdentity(){try{let t={};if(this.storage){let i=await this.storage.get(c);i!=null&&(t.Authorization=`Bearer ${i}`)}let e=await this.fetchImpl(this.url("google/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let n=s?JSON.parse(s):null;return n?.sub?{data:n}:{error:{message:"invalid_google_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}getGithubOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("github/openplatform/login")}?${e.toString()}`}startGithubOpenPlatformLogin(t){let e=this.getGithubOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startGithubOpenPlatformLogin requires a browser environment with location")}async completeGithubOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeGithubOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithGithubExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithGithubExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("github/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):null;return!i?.token||!i.user?{error:{message:"invalid_github_login_response",status:502}}:(this.storage&&(await this.storage.set(c,i.token),await this.storage.set(f,i.token),await this.storage.set(w,i.user)),{data:i})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getGithubOpenPlatformIdentity(){try{let t={};if(this.storage){let i=await this.storage.get(c);i!=null&&(t.Authorization=`Bearer ${i}`)}let e=await this.fetchImpl(this.url("github/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let n=s?JSON.parse(s):null;return n?.sub?{data:n}:{error:{message:"invalid_github_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}getWechatWebsiteOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("wechat-website/openplatform/login")}?${e.toString()}`}startWechatWebsiteOpenPlatformLogin(t){let e=this.getWechatWebsiteOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startWechatWebsiteOpenPlatformLogin requires a browser environment with location")}async completeWechatWebsiteOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeWechatWebsiteOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithWechatWebsiteExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithWechatWebsiteExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("wechat-website/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):null;return!i?.token||!i.user?{error:{message:"invalid_wechat_website_login_response",status:502}}:(this.storage&&(await this.storage.set(c,i.token),await this.storage.set(f,i.token),await this.storage.set(w,i.user)),{data:i})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getWechatWebsiteOpenPlatformIdentity(){try{let t={};if(this.storage){let i=await this.storage.get(c);i!=null&&(t.Authorization=`Bearer ${i}`)}let e=await this.fetchImpl(this.url("wechat-website/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let n=s?JSON.parse(s):null;return n?.sub?{data:n}:{error:{message:"invalid_wechat_website_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}url(t){let s=`${`${this.baseUrl.replace(/\/+$/,"")}/${this.authPath.replace(/^\/+/,"")}`}/${t.replace(/^\/+/,"")}`;return typeof console<"u"&&(console.warn("[NvwaAuth] request URL:",s),!s.startsWith("http://")&&!s.startsWith("https://")&&console.warn("[NvwaAuth] URL \u975E\u5B8C\u6574\u5730\u5740\uFF0C\u5C0F\u7A0B\u5E8F\u4F1A\u62A5 invalid url\uFF0C\u8BF7\u68C0\u67E5 Nvwa \u6784\u9020\u65F6\u4F20\u5165\u7684 baseUrl")),s}async getSession(){try{let t={};if(this.storage){let n=await this.storage.get(f)??await this.storage.get(c);n!=null&&(t.Authorization=`Bearer ${n}`)}let e=await this.fetchImpl(this.url("session"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}});return e.ok?{data:await e.json()}:{data:null,error:{message:await e.text()||e.statusText,status:e.status}}}catch(t){return{data:null,error:{message:t instanceof Error?t.message:String(t),status:0}}}}async signInWithEmail(t,e){try{let s=await this.fetchImpl(this.url("sign-in/email"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:this.credentials,body:JSON.stringify({email:t,password:e})}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):void 0;return i&&await this.persistLogin({user:i.user,session:i.session},s),{data:i}}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async signOut(){try{let t={};if(this.storage){let s=await this.storage.get(f)??await this.storage.get(c);s!=null&&(t.Authorization=`Bearer ${s}`)}let e=await this.fetchImpl(this.url("sign-out"),{method:"POST",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}});return await this.clearLogin(),e.ok?{}:{error:{message:await e.text()||e.statusText,status:e.status}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}async signUp(t){let e=await this.postJson("sign-up/email",t);return e.data&&await this.persistLogin(e.data,e.response),e}async getToken(t){try{let e={};if(t)e.Authorization=`Bearer ${t}`;else if(this.storage){let a=await this.storage.get(f)??await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("token"),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):void 0;return{data:i?.token!=null?{token:i.token}:void 0}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async signInWithUsername(t,e){let s=await this.postJson("sign-in/username",{username:t,password:e});return s.data&&await this.persistLogin(s.data,s.response),s}async signInWithPhoneNumber(t,e,s){let n=await this.postJson("sign-in/phone-number",{phoneNumber:t,password:e,rememberMe:s});return n.data&&await this.persistLogin(n.data,n.response),n}async sendPhoneNumberOtp(t){let e=await this.postJson("phone-number/send-otp",{phoneNumber:t});return e.error?{error:e.error}:{}}async verifyPhoneNumber(t,e){let s=await this.postJson("phone-number/verify",{phoneNumber:t,code:e});return s.data&&await this.persistLogin(s.data,s.response),s}async loginWithWeChatCode(t,e){try{let s={"Content-Type":"application/json"};if(this.storage){let o=await this.storage.get(c);o!=null&&(s.Authorization=`Bearer ${o}`)}let n=await this.fetchImpl(this.url("wechat/openplatform/sign-in"),{method:"POST",headers:s,credentials:this.credentials,body:JSON.stringify({code:t,applicationCode:e})}),i=await n.text();if(!n.ok)return{error:{message:i||n.statusText,status:n.status}};let a=i?JSON.parse(i):null;return!a?.token||!a.user?{error:{message:"invalid_wechat_login_response",status:502}}:(this.storage&&(await this.storage.set(c,a.token),await this.storage.set(f,a.token),await this.storage.set(w,a.user)),{data:a})}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async loginWithAlipayCode(t,e){try{let s={"Content-Type":"application/json"};if(this.storage){let o=await this.storage.get(c);o!=null&&(s.Authorization=`Bearer ${o}`)}let n=await this.fetchImpl(this.url("alipay/openplatform/sign-in"),{method:"POST",headers:s,credentials:this.credentials,body:JSON.stringify({code:t,applicationCode:e})}),i=await n.text();if(!n.ok)return{error:{message:i||n.statusText,status:n.status}};let a=i?JSON.parse(i):null;return!a?.token||!a.user?{error:{message:"invalid_alipay_login_response",status:502}}:(this.storage&&(await this.storage.set(c,a.token),await this.storage.set(f,a.token),await this.storage.set(w,a.user)),{data:a})}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async getWeChatOpenPlatformIdentity(t){try{let e={};if(this.storage){let o=await this.storage.get(c);o!=null&&(e.Authorization=`Bearer ${o}`)}let s=t?.trim()?`?applicationCode=${encodeURIComponent(t.trim())}`:"",n=await this.fetchImpl(this.url(`wechat/openplatform/identity${s}`),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),i=await n.text();if(!n.ok)return{error:{message:i||n.statusText,status:n.status}};let a=i?JSON.parse(i):null;return!a?.openid||!a.appId?{error:{message:"invalid_wechat_identity_response",status:502}}:{data:a}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getAlipayOpenPlatformIdentity(t){try{let e={};if(this.storage){let o=await this.storage.get(c);o!=null&&(e.Authorization=`Bearer ${o}`)}let s=t?.trim()?`?applicationCode=${encodeURIComponent(t.trim())}`:"",n=await this.fetchImpl(this.url(`alipay/openplatform/identity${s}`),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),i=await n.text();if(!n.ok)return{error:{message:i||n.statusText,status:n.status}};let a=i?JSON.parse(i):null;return!a?.openid||!a.appId?{error:{message:"invalid_alipay_identity_response",status:502}}:{data:a}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async postJson(t,e){try{let s=await this.fetchImpl(this.url(t),{method:"POST",headers:{"Content-Type":"application/json"},credentials:this.credentials,body:JSON.stringify(e)}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):void 0;return{data:i?.data??i??void 0,response:s}}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}};var U=require("@nvwa-app/nvwa-http-polyfill"),_=class{constructor(t,e,s){this.storage=t,this.customFetch=e,this.handleUnauthorized=s}async fetch(t,e){return await this.customFetch(t,e)}async fetchWithAuth(t,e){let s=await this.storage.get(c),n=new U.Headers(e?.headers);s&&n.set("Authorization",`Bearer ${s}`);let i=e?.method||"GET";if((i==="POST"||i==="PUT"||i==="PATCH")&&e?.body){let o=n.get("Content-Type");(!o||o.includes("text/plain"))&&n.set("Content-Type","application/json")}let a=await this.customFetch(t,{...e,headers:n});if(a.status===401)throw this.handleUnauthorized(),new Error("\u672A\u767B\u5F55");return a}};var N=require("@nvwa-app/nvwa-http-polyfill"),$="/storage",I=$+"/generateUploadUrl",k=class{constructor(t,e){this.baseUrl=t,this.http=e}async uploadFile(t){let e=await this.http.fetch(this.baseUrl+I,{method:"POST",body:{fileName:t.name||t.fileName,fileSize:t.size||t.fileSize,fileType:t.type||t.fileType}}),{url:s}=await e.json();if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");let n=await this.http.fetch(s,{method:"PUT",body:t,headers:new N.Headers({"Content-Type":t.type||t.fileType||"application/octet-stream"})}),{url:i}=await n.json();return{url:i.split("?")[0]}}};var y=require("@nvwa-app/nvwa-http-polyfill"),V=class extends Error{constructor(r){super(r.message),this.name="PostgrestError",this.details=r.details,this.hint=r.hint,this.code=r.code}},X=class{constructor(r){var t,e,s;this.shouldThrowOnError=!1,this.method=r.method,this.url=r.url,this.headers=new y.Headers(r.headers),this.schema=r.schema,this.body=r.body,this.shouldThrowOnError=(t=r.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=r.signal,this.isMaybeSingle=(e=r.isMaybeSingle)!==null&&e!==void 0?e:!1,this.urlLengthLimit=(s=r.urlLengthLimit)!==null&&s!==void 0?s:8e3,r.fetch?this.fetch=r.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(r,t){return this.headers=new y.Headers(this.headers),this.headers.set(r,t),this}then(r,t){var e=this;this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,n=s(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async i=>{let a=null,o=null,h=null,u=i.status,l=i.statusText;if(i.ok){var p,m;if(e.method!=="HEAD"){var d;let v=await i.text();v===""||(e.headers.get("Accept")==="text/csv"||e.headers.get("Accept")&&(!((d=e.headers.get("Accept"))===null||d===void 0)&&d.includes("application/vnd.pgrst.plan+text"))?o=v:o=JSON.parse(v))}let g=(p=e.headers.get("Prefer"))===null||p===void 0?void 0:p.match(/count=(exact|planned|estimated)/),b=(m=i.headers.get("content-range"))===null||m===void 0?void 0:m.split("/");g&&b&&b.length>1&&(h=parseInt(b[1])),e.isMaybeSingle&&Array.isArray(o)&&(o.length>1?(a={code:"PGRST116",details:`Results contain ${o.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},o=null,h=null,u=406,l="Not Acceptable"):o.length===1?o=o[0]:o=null)}else{let g=await i.text();try{a=JSON.parse(g),Array.isArray(a)&&i.status===404&&(o=[],a=null,u=200,l="OK")}catch{i.status===404&&g===""?(u=204,l="No Content"):a={message:g}}if(a&&e.shouldThrowOnError)throw new V(a)}return{error:a,data:o,count:h,status:u,statusText:l}});return this.shouldThrowOnError||(n=n.catch(i=>{var a;let o="",h="",u="",l=i?.cause;if(l){var p,m,d,g;let F=(p=l?.message)!==null&&p!==void 0?p:"",C=(m=l?.code)!==null&&m!==void 0?m:"";o=`${(d=i?.name)!==null&&d!==void 0?d:"FetchError"}: ${i?.message}`,o+=`
|
|
1
|
+
"use strict";var x=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var X=Object.prototype.hasOwnProperty;var Q=(r,t)=>{for(var e in t)x(r,e,{get:t[e],enumerable:!0})},Z=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of V(t))!X.call(r,i)&&i!==e&&x(r,i,{get:()=>t[i],enumerable:!(s=K(t,i))||s.enumerable});return r};var tt=r=>Z(x({},"__esModule",{value:!0}),r);var ft={};Q(ft,{AuthClient:()=>E,CURRENT_JWT_KEY:()=>c,ENTITIES_BASE_PATH:()=>D,FILE_STORAGE_BASE_PATH:()=>q,GENERATE_UPLOAD_URL_PATH:()=>F,Headers:()=>f,LOGIN_TOKEN_KEY:()=>y,LOGIN_USER_PROFILE_KEY:()=>P,NvwaEdgeFunctions:()=>A,NvwaFileStorage:()=>C,NvwaHttpClient:()=>$,OverlayManager:()=>I,Request:()=>_,Response:()=>k,SET_AUTH_TOKEN_HEADER:()=>U,URL:()=>O,createPostgrestClient:()=>pt,getSourceLocationFromDOM:()=>dt,normalizePayParams:()=>gt,requestPaymentFromOrderResult:()=>mt});module.exports=tt(ft);var f=class j{constructor(t){if(this.headerMap=new Map,t){if(t instanceof j)t.forEach((e,s)=>this.set(s,e));else if(Array.isArray(t))for(let[e,s]of t)this.set(e,String(s));else if(typeof t=="object")for(let e of Object.keys(t))this.set(e,String(t[e]))}}append(t,e){let s=t.toLowerCase(),i=this.headerMap.get(s);this.headerMap.set(s,i?`${i}, ${e}`:e)}set(t,e){this.headerMap.set(t.toLowerCase(),String(e))}get(t){return this.headerMap.get(t.toLowerCase())??null}has(t){return this.headerMap.has(t.toLowerCase())}delete(t){this.headerMap.delete(t.toLowerCase())}forEach(t){for(let[e,s]of this.headerMap.entries())t(s,e,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}},et=class H{constructor(t){if(this.params=new Map,t){if(typeof t=="string")this.parseString(t);else if(t instanceof H)this.params=new Map(t.params);else if(Array.isArray(t))for(let[e,s]of t)this.append(e,s);else if(t&&typeof t=="object")for(let[e,s]of Object.entries(t))this.set(e,s)}}parseString(t){t.startsWith("?")&&(t=t.slice(1));let e=t.split("&");for(let s of e)if(s){let[i,n]=s.split("=");i&&this.append(decodeURIComponent(i),n?decodeURIComponent(n):"")}}append(t,e){let s=this.params.get(t)||[];s.push(e),this.params.set(t,s)}delete(t){this.params.delete(t)}get(t){let e=this.params.get(t);return e?e[0]:null}getAll(t){return this.params.get(t)||[]}has(t){return this.params.has(t)}set(t,e){this.params.set(t,[e])}sort(){let t=Array.from(this.params.entries()).sort(([e],[s])=>e.localeCompare(s));this.params=new Map(t)}toString(){let t=[];for(let[e,s]of this.params.entries())for(let i of s)t.push(`${encodeURIComponent(e)}=${encodeURIComponent(i)}`);return t.join("&")}forEach(t){for(let[e,s]of this.params.entries())for(let i of s)t(i,e,this)}keys(){return this.params.keys()}values(){let t=[];for(let e of this.params.values())t.push(...e);return t[Symbol.iterator]()}entries(){let t=[];for(let[e,s]of this.params.entries())for(let i of s)t.push([e,i]);return t[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}},O=class T{constructor(t,e){let s;if(t instanceof T)s=t.href;else if(e){let n=e instanceof T?e.href:e;s=this.resolve(n,t)}else s=t;let i=this.parseUrl(s);this.href=s,this.origin=`${i.protocol}//${i.host}`,this.protocol=i.protocol,this.username=i.username,this.password=i.password,this.host=i.host,this.hostname=i.hostname,this.port=i.port,this.pathname=i.pathname,this.search=i.search,this.searchParams=new et(i.search),this.hash=i.hash}resolve(t,e){if(e.startsWith("http://")||e.startsWith("https://"))return e;if(e.startsWith("//"))return`${this.parseUrl(t).protocol}${e}`;if(e.startsWith("/")){let n=this.parseUrl(t);return`${n.protocol}//${n.host}${e}`}let s=this.parseUrl(t),i=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${i}${e}`}parseUrl(t){let e=t.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!e)throw new TypeError("Invalid URL");let s=e[2]||"",i=e[4]||"",n=e[5]||"/",a=e[7]?`?${e[7]}`:"",o=e[9]?`#${e[9]}`:"";if(!s&&!i&&!n.startsWith("/")&&!n.includes("/")&&!n.includes("."))throw new TypeError("Invalid URL");let h=i.match(/^([^@]*)@(.+)$/),u="",l="",p=i;if(h){let b=h[1];p=h[2];let w=b.match(/^([^:]*):?(.*)$/);w&&(u=w[1]||"",l=w[2]||"")}let d=p.match(/^([^:]+):?(\d*)$/),g=d?d[1]:p,m=d&&d[2]?d[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:p,hostname:g,port:m,pathname:n,search:a,hash:o}}toString(){let t=this.searchParams.toString(),e=t?`?${t}`:"";return`${this.protocol}//${this.host}${this.pathname}${e}${this.hash}`}toJSON(){return this.toString()}},_=class W{constructor(t,e){if(typeof t=="string")this.url=t;else if(t?.url)this.url=String(t.url);else if(typeof t?.toString=="function")this.url=String(t.toString());else throw new Error("Invalid input for Request");this.method=(e?.method||"GET").toUpperCase(),this.headers=e?.headers instanceof f?e.headers:new f(e?.headers),this.body=e?.body,this.timeout=e?.timeout,this.signal=e?.signal||void 0}clone(){return new W(this.url,{method:this.method,headers:this.headers,body:this.body,timeout:this.timeout})}toString(){return this.url}},k=class{constructor(r,t){this.bodyData=r,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=st(t?.headers),this.ok=this.status>=200&&this.status<300}async text(){return typeof this.bodyData=="string"?this.bodyData:this.bodyData==null?"":typeof this.bodyData=="object"?JSON.stringify(this.bodyData):String(this.bodyData)}async json(){if(typeof this.bodyData=="string")try{return JSON.parse(this.bodyData)}catch{}return this.bodyData}async arrayBuffer(){let r=await this.text();return new TextEncoder().encode(r).buffer}};function st(r){return r?new f(r):new f}var rt=class{constructor(){this._aborted=!1,this.listeners=new Set,this.onabort=null}get aborted(){return this._aborted}_trigger(){if(!this._aborted){if(this._aborted=!0,typeof this.onabort=="function")try{this.onabort()}catch{}for(let r of Array.from(this.listeners))try{r()}catch{}this.listeners.clear()}}addEventListener(r,t){if(this._aborted){try{t()}catch{}return}this.listeners.add(t)}removeEventListener(r,t){this.listeners.delete(t)}toString(){return"[object AbortSignal]"}},G=class{constructor(){this._signal=new rt}get signal(){return this._signal}abort(){this._signal._trigger()}toString(){return"[object AbortController]"}};var A=class{constructor(t,e=""){this.http=t,this.baseUrl=e.replace(/\/$/,"")}async invoke(t,e){let s=this.baseUrl?`${this.baseUrl}/functions/${t}`:`/functions/${t}`;return await(await this.http.fetch(s,{method:e.method||"POST",body:e.body,headers:e.headers})).json()}};var c="nvwa_current_jwt",y="nvwa_login_token",P="nvwa_user_profile",U="set-auth-token",it=typeof fetch<"u"?(r,t)=>fetch(r,t):()=>{throw new Error("AuthClient requires fetch")},E=class{constructor(t,e={}){this.baseUrl=t.replace(/\/$/,""),this.authPath=(e.authPath??"/auth").replace(/^\//,""),this.fetchImpl=e.fetchImpl??it,this.storage=e.storage??null,this.credentials=e.credentials??"omit",typeof console<"u"&&(console.warn("[NvwaAuth] init baseUrl:",this.baseUrl||"(empty)"),(!this.baseUrl||!this.baseUrl.startsWith("http://")&&!this.baseUrl.startsWith("https://"))&&console.warn("[NvwaAuth] baseUrl \u5E94\u4E3A\u5B8C\u6574\u5730\u5740\uFF08\u5982 https://xxx.nvwa.app\uFF09\uFF0C\u5426\u5219\u5C0F\u7A0B\u5E8F request \u4F1A\u62A5 invalid url"))}async currentUser(){if(this.storage){let s=await this.storage.get(P);if(s!=null)return s}let{data:t}=await this.getSession(),e=t?.user??null;return e&&this.storage&&await this.storage.set(P,e),e}async getCurrentJwt(){if(this.storage){let e=await this.storage.get(c);if(e!=null)return e;let s=await this.storage.get(y),{data:i}=await this.getToken(s??void 0);return i?.token?(await this.storage.set(c,i.token),i.token):null}let{data:t}=await this.getToken();return t?.token??null}async persistLogin(t,e){if(!this.storage)return;let i=e?.headers.get(U)?.trim()||t.token||t.session?.token;i&&await this.storage.set(y,i),t.user&&await this.storage.set(P,t.user);let n=i??await this.storage.get(y),{data:a}=await this.getToken(n??void 0);a?.token&&await this.storage.set(c,a.token)}async clearLogin(){this.storage&&(await this.storage.remove(y),await this.storage.remove(P),await this.storage.remove(c))}getGoogleOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("google/openplatform/login")}?${e.toString()}`}startGoogleOpenPlatformLogin(t){let e=this.getGoogleOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startGoogleOpenPlatformLogin requires a browser environment with location")}async completeGoogleOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeGoogleOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithGoogleExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithGoogleExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("google/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):null;return!n?.token||!n.user?{error:{message:"invalid_google_login_response",status:502}}:(this.storage&&(await this.storage.set(c,n.token),await this.storage.set(y,n.token),await this.storage.set(P,n.user)),{data:n})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getGoogleOpenPlatformIdentity(){try{let t={};if(this.storage){let n=await this.storage.get(c);n!=null&&(t.Authorization=`Bearer ${n}`)}let e=await this.fetchImpl(this.url("google/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let i=s?JSON.parse(s):null;return i?.sub?{data:i}:{error:{message:"invalid_google_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}getGithubOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("github/openplatform/login")}?${e.toString()}`}startGithubOpenPlatformLogin(t){let e=this.getGithubOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startGithubOpenPlatformLogin requires a browser environment with location")}async completeGithubOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeGithubOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithGithubExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithGithubExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("github/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):null;return!n?.token||!n.user?{error:{message:"invalid_github_login_response",status:502}}:(this.storage&&(await this.storage.set(c,n.token),await this.storage.set(y,n.token),await this.storage.set(P,n.user)),{data:n})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getGithubOpenPlatformIdentity(){try{let t={};if(this.storage){let n=await this.storage.get(c);n!=null&&(t.Authorization=`Bearer ${n}`)}let e=await this.fetchImpl(this.url("github/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let i=s?JSON.parse(s):null;return i?.sub?{data:i}:{error:{message:"invalid_github_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}getWechatWebsiteOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("wechat-website/openplatform/login")}?${e.toString()}`}startWechatWebsiteOpenPlatformLogin(t){let e=this.getWechatWebsiteOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startWechatWebsiteOpenPlatformLogin requires a browser environment with location")}async completeWechatWebsiteOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeWechatWebsiteOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithWechatWebsiteExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithWechatWebsiteExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("wechat-website/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):null;return!n?.token||!n.user?{error:{message:"invalid_wechat_website_login_response",status:502}}:(this.storage&&(await this.storage.set(c,n.token),await this.storage.set(y,n.token),await this.storage.set(P,n.user)),{data:n})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getWechatWebsiteOpenPlatformIdentity(){try{let t={};if(this.storage){let n=await this.storage.get(c);n!=null&&(t.Authorization=`Bearer ${n}`)}let e=await this.fetchImpl(this.url("wechat-website/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let i=s?JSON.parse(s):null;return i?.sub?{data:i}:{error:{message:"invalid_wechat_website_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}url(t){let s=`${`${this.baseUrl.replace(/\/+$/,"")}/${this.authPath.replace(/^\/+/,"")}`}/${t.replace(/^\/+/,"")}`;return typeof console<"u"&&(console.warn("[NvwaAuth] request URL:",s),!s.startsWith("http://")&&!s.startsWith("https://")&&console.warn("[NvwaAuth] URL \u975E\u5B8C\u6574\u5730\u5740\uFF0C\u5C0F\u7A0B\u5E8F\u4F1A\u62A5 invalid url\uFF0C\u8BF7\u68C0\u67E5 Nvwa \u6784\u9020\u65F6\u4F20\u5165\u7684 baseUrl")),s}async getSession(){try{let t={};if(this.storage){let i=await this.storage.get(y)??await this.storage.get(c);i!=null&&(t.Authorization=`Bearer ${i}`)}let e=await this.fetchImpl(this.url("session"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}});return e.ok?{data:await e.json()}:{data:null,error:{message:await e.text()||e.statusText,status:e.status}}}catch(t){return{data:null,error:{message:t instanceof Error?t.message:String(t),status:0}}}}async signInWithEmail(t,e){try{let s=await this.fetchImpl(this.url("sign-in/email"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:this.credentials,body:JSON.stringify({email:t,password:e})}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):void 0;return n&&await this.persistLogin({user:n.user,session:n.session},s),{data:n}}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async signOut(){try{let t={};if(this.storage){let s=await this.storage.get(y)??await this.storage.get(c);s!=null&&(t.Authorization=`Bearer ${s}`)}let e=await this.fetchImpl(this.url("sign-out"),{method:"POST",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}});return await this.clearLogin(),e.ok?{}:{error:{message:await e.text()||e.statusText,status:e.status}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}async signUp(t){let e=await this.postJson("sign-up/email",t);return e.data&&await this.persistLogin(e.data,e.response),e}async getToken(t){try{let e={};if(t)e.Authorization=`Bearer ${t}`;else if(this.storage){let a=await this.storage.get(y)??await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("token"),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):void 0;return{data:n?.token!=null?{token:n.token}:void 0}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async signInWithUsername(t,e){let s=await this.postJson("sign-in/username",{username:t,password:e});return s.data&&await this.persistLogin(s.data,s.response),s}async signInWithPhoneNumber(t,e,s){let i=await this.postJson("sign-in/phone-number",{phoneNumber:t,password:e,rememberMe:s});return i.data&&await this.persistLogin(i.data,i.response),i}async sendPhoneNumberOtp(t){let e=await this.postJson("phone-number/send-otp",{phoneNumber:t});return e.error?{error:e.error}:{}}async verifyPhoneNumber(t,e){let s=await this.postJson("phone-number/verify",{phoneNumber:t,code:e});return s.data&&await this.persistLogin(s.data,s.response),s}async loginWithWeChatCode(t,e){try{let s={"Content-Type":"application/json"};if(this.storage){let o=await this.storage.get(c);o!=null&&(s.Authorization=`Bearer ${o}`)}let i=await this.fetchImpl(this.url("wechat/openplatform/sign-in"),{method:"POST",headers:s,credentials:this.credentials,body:JSON.stringify({code:t,applicationCode:e})}),n=await i.text();if(!i.ok)return{error:{message:n||i.statusText,status:i.status}};let a=n?JSON.parse(n):null;return!a?.token||!a.user?{error:{message:"invalid_wechat_login_response",status:502}}:(this.storage&&(await this.storage.set(c,a.token),await this.storage.set(y,a.token),await this.storage.set(P,a.user)),{data:a})}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async loginWithAlipayCode(t,e){try{let s={"Content-Type":"application/json"};if(this.storage){let o=await this.storage.get(c);o!=null&&(s.Authorization=`Bearer ${o}`)}let i=await this.fetchImpl(this.url("alipay/openplatform/sign-in"),{method:"POST",headers:s,credentials:this.credentials,body:JSON.stringify({code:t,applicationCode:e})}),n=await i.text();if(!i.ok)return{error:{message:n||i.statusText,status:i.status}};let a=n?JSON.parse(n):null;return!a?.token||!a.user?{error:{message:"invalid_alipay_login_response",status:502}}:(this.storage&&(await this.storage.set(c,a.token),await this.storage.set(y,a.token),await this.storage.set(P,a.user)),{data:a})}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async getWeChatOpenPlatformIdentity(t){try{let e={};if(this.storage){let o=await this.storage.get(c);o!=null&&(e.Authorization=`Bearer ${o}`)}let s=t?.trim()?`?applicationCode=${encodeURIComponent(t.trim())}`:"",i=await this.fetchImpl(this.url(`wechat/openplatform/identity${s}`),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),n=await i.text();if(!i.ok)return{error:{message:n||i.statusText,status:i.status}};let a=n?JSON.parse(n):null;return!a?.openid||!a.appId?{error:{message:"invalid_wechat_identity_response",status:502}}:{data:a}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getAlipayOpenPlatformIdentity(t){try{let e={};if(this.storage){let o=await this.storage.get(c);o!=null&&(e.Authorization=`Bearer ${o}`)}let s=t?.trim()?`?applicationCode=${encodeURIComponent(t.trim())}`:"",i=await this.fetchImpl(this.url(`alipay/openplatform/identity${s}`),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),n=await i.text();if(!i.ok)return{error:{message:n||i.statusText,status:i.status}};let a=n?JSON.parse(n):null;return!a?.openid||!a.appId?{error:{message:"invalid_alipay_identity_response",status:502}}:{data:a}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async postJson(t,e){try{let s=await this.fetchImpl(this.url(t),{method:"POST",headers:{"Content-Type":"application/json"},credentials:this.credentials,body:JSON.stringify(e)}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):void 0;return{data:n?.data??n??void 0,response:s}}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}};var $=class{constructor(t,e,s){this.storage=t,this.customFetch=e,this.handleUnauthorized=s}async fetch(t,e){return await this.customFetch(t,e)}async fetchWithAuth(t,e){let s=await this.storage.get(c),i=new f(e?.headers);s&&i.set("Authorization",`Bearer ${s}`);let n=e?.method||"GET";if((n==="POST"||n==="PUT"||n==="PATCH")&&e?.body){let o=i.get("Content-Type");(!o||o.includes("text/plain"))&&i.set("Content-Type","application/json")}let a=await this.customFetch(t,{...e,headers:i});if(a.status===401)throw this.handleUnauthorized(),new Error("\u672A\u767B\u5F55");return a}};var q="/storage",F=q+"/generateUploadUrl",C=class{constructor(t,e){this.baseUrl=t,this.http=e}async uploadFile(t){let e=await this.http.fetch(this.baseUrl+F,{method:"POST",body:{fileName:t.name||t.fileName,fileSize:t.size||t.fileSize,fileType:t.type||t.fileType}}),{url:s}=await e.json();if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");let i=await this.http.fetch(s,{method:"PUT",body:t,headers:new f({"Content-Type":t.type||t.fileType||"application/octet-stream"})}),{url:n}=await i.json();return{url:n.split("?")[0]}}};var nt=class extends Error{constructor(r){super(r.message),this.name="PostgrestError",this.details=r.details,this.hint=r.hint,this.code=r.code}},at=class{constructor(r){var t,e,s;this.shouldThrowOnError=!1,this.method=r.method,this.url=r.url,this.headers=new f(r.headers),this.schema=r.schema,this.body=r.body,this.shouldThrowOnError=(t=r.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=r.signal,this.isMaybeSingle=(e=r.isMaybeSingle)!==null&&e!==void 0?e:!1,this.urlLengthLimit=(s=r.urlLengthLimit)!==null&&s!==void 0?s:8e3,r.fetch?this.fetch=r.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(r,t){return this.headers=new f(this.headers),this.headers.set(r,t),this}then(r,t){var e=this;this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,i=s(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async n=>{let a=null,o=null,h=null,u=n.status,l=n.statusText;if(n.ok){var p,d;if(e.method!=="HEAD"){var g;let w=await n.text();w===""||(e.headers.get("Accept")==="text/csv"||e.headers.get("Accept")&&(!((g=e.headers.get("Accept"))===null||g===void 0)&&g.includes("application/vnd.pgrst.plan+text"))?o=w:o=JSON.parse(w))}let m=(p=e.headers.get("Prefer"))===null||p===void 0?void 0:p.match(/count=(exact|planned|estimated)/),b=(d=n.headers.get("content-range"))===null||d===void 0?void 0:d.split("/");m&&b&&b.length>1&&(h=parseInt(b[1])),e.isMaybeSingle&&Array.isArray(o)&&(o.length>1?(a={code:"PGRST116",details:`Results contain ${o.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},o=null,h=null,u=406,l="Not Acceptable"):o.length===1?o=o[0]:o=null)}else{let m=await n.text();try{a=JSON.parse(m),Array.isArray(a)&&n.status===404&&(o=[],a=null,u=200,l="OK")}catch{n.status===404&&m===""?(u=204,l="No Content"):a={message:m}}if(a&&e.shouldThrowOnError)throw new nt(a)}return{error:a,data:o,count:h,status:u,statusText:l}});return this.shouldThrowOnError||(i=i.catch(n=>{var a;let o="",h="",u="",l=n?.cause;if(l){var p,d,g,m;let Y=(p=l?.message)!==null&&p!==void 0?p:"",N=(d=l?.code)!==null&&d!==void 0?d:"";o=`${(g=n?.name)!==null&&g!==void 0?g:"FetchError"}: ${n?.message}`,o+=`
|
|
2
2
|
|
|
3
|
-
Caused by: ${(
|
|
4
|
-
${l.stack}`)}else{var b;o=(b=i?.stack)!==null&&b!==void 0?b:""}let v=this.url.toString().length;return i?.name==="AbortError"||i?.code==="ABORT_ERR"?(u="",h="Request was aborted (timeout or manual cancellation)",v>this.urlLengthLimit&&(h+=`. Note: Your request URL is ${v} characters, which may exceed server limits. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [many IDs])), consider using an RPC function to pass values server-side.`)):(l?.name==="HeadersOverflowError"||l?.code==="UND_ERR_HEADERS_OVERFLOW")&&(u="",h="HTTP headers exceeded server limits (typically 16KB)",v>this.urlLengthLimit&&(h+=`. Your request URL is ${v} characters. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [200+ IDs])), consider using an RPC function instead.`)),{error:{message:`${(a=i?.name)!==null&&a!==void 0?a:"FetchError"}: ${i?.message}`,details:o,hint:h,code:u},data:null,count:null,status:0,statusText:""}})),n.then(r,t)}returns(){return this}overrideTypes(){return this}},Q=class extends X{select(r){let t=!1,e=(r??"*").split("").map(s=>/\s/.test(s)&&!t?"":(s==='"'&&(t=!t),s)).join("");return this.url.searchParams.set("select",e),this.headers.append("Prefer","return=representation"),this}order(r,{ascending:t=!0,nullsFirst:e,foreignTable:s,referencedTable:n=s}={}){let i=n?`${n}.order`:"order",a=this.url.searchParams.get(i);return this.url.searchParams.set(i,`${a?`${a},`:""}${r}.${t?"asc":"desc"}${e===void 0?"":e?".nullsfirst":".nullslast"}`),this}limit(r,{foreignTable:t,referencedTable:e=t}={}){let s=typeof e>"u"?"limit":`${e}.limit`;return this.url.searchParams.set(s,`${r}`),this}range(r,t,{foreignTable:e,referencedTable:s=e}={}){let n=typeof s>"u"?"offset":`${s}.offset`,i=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(n,`${r}`),this.url.searchParams.set(i,`${t-r+1}`),this}abortSignal(r){return this.signal=r,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:r=!1,verbose:t=!1,settings:e=!1,buffers:s=!1,wal:n=!1,format:i="text"}={}){var a;let o=[r?"analyze":null,t?"verbose":null,e?"settings":null,s?"buffers":null,n?"wal":null].filter(Boolean).join("|"),h=(a=this.headers.get("Accept"))!==null&&a!==void 0?a:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${i}; for="${h}"; options=${o};`),i==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(r){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${r}`),this}},j=new RegExp("[,()]"),O=class extends Q{eq(r,t){return this.url.searchParams.append(r,`eq.${t}`),this}neq(r,t){return this.url.searchParams.append(r,`neq.${t}`),this}gt(r,t){return this.url.searchParams.append(r,`gt.${t}`),this}gte(r,t){return this.url.searchParams.append(r,`gte.${t}`),this}lt(r,t){return this.url.searchParams.append(r,`lt.${t}`),this}lte(r,t){return this.url.searchParams.append(r,`lte.${t}`),this}like(r,t){return this.url.searchParams.append(r,`like.${t}`),this}likeAllOf(r,t){return this.url.searchParams.append(r,`like(all).{${t.join(",")}}`),this}likeAnyOf(r,t){return this.url.searchParams.append(r,`like(any).{${t.join(",")}}`),this}ilike(r,t){return this.url.searchParams.append(r,`ilike.${t}`),this}ilikeAllOf(r,t){return this.url.searchParams.append(r,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(r,t){return this.url.searchParams.append(r,`ilike(any).{${t.join(",")}}`),this}regexMatch(r,t){return this.url.searchParams.append(r,`match.${t}`),this}regexIMatch(r,t){return this.url.searchParams.append(r,`imatch.${t}`),this}is(r,t){return this.url.searchParams.append(r,`is.${t}`),this}isDistinct(r,t){return this.url.searchParams.append(r,`isdistinct.${t}`),this}in(r,t){let e=Array.from(new Set(t)).map(s=>typeof s=="string"&&j.test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(r,`in.(${e})`),this}notIn(r,t){let e=Array.from(new Set(t)).map(s=>typeof s=="string"&&j.test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(r,`not.in.(${e})`),this}contains(r,t){return typeof t=="string"?this.url.searchParams.append(r,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(r,`cs.{${t.join(",")}}`):this.url.searchParams.append(r,`cs.${JSON.stringify(t)}`),this}containedBy(r,t){return typeof t=="string"?this.url.searchParams.append(r,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(r,`cd.{${t.join(",")}}`):this.url.searchParams.append(r,`cd.${JSON.stringify(t)}`),this}rangeGt(r,t){return this.url.searchParams.append(r,`sr.${t}`),this}rangeGte(r,t){return this.url.searchParams.append(r,`nxl.${t}`),this}rangeLt(r,t){return this.url.searchParams.append(r,`sl.${t}`),this}rangeLte(r,t){return this.url.searchParams.append(r,`nxr.${t}`),this}rangeAdjacent(r,t){return this.url.searchParams.append(r,`adj.${t}`),this}overlaps(r,t){return typeof t=="string"?this.url.searchParams.append(r,`ov.${t}`):this.url.searchParams.append(r,`ov.{${t.join(",")}}`),this}textSearch(r,t,{config:e,type:s}={}){let n="";s==="plain"?n="pl":s==="phrase"?n="ph":s==="websearch"&&(n="w");let i=e===void 0?"":`(${e})`;return this.url.searchParams.append(r,`${n}fts${i}.${t}`),this}match(r){return Object.entries(r).filter(([t,e])=>e!==void 0).forEach(([t,e])=>{this.url.searchParams.append(t,`eq.${e}`)}),this}not(r,t,e){return this.url.searchParams.append(r,`not.${t}.${e}`),this}or(r,{foreignTable:t,referencedTable:e=t}={}){let s=e?`${e}.or`:"or";return this.url.searchParams.append(s,`(${r})`),this}filter(r,t,e){return this.url.searchParams.append(r,`${t}.${e}`),this}},Z=class{constructor(r,{headers:t={},schema:e,fetch:s,urlLengthLimit:n=8e3}){this.url=r,this.headers=new y.Headers(t),this.schema=e,this.fetch=s,this.urlLengthLimit=n}cloneRequestState(){return{url:new y.URL(this.url.toString()),headers:new y.Headers(this.headers)}}select(r,t){let{head:e=!1,count:s}=t??{},n=e?"HEAD":"GET",i=!1,a=(r??"*").split("").map(u=>/\s/.test(u)&&!i?"":(u==='"'&&(i=!i),u)).join(""),{url:o,headers:h}=this.cloneRequestState();return o.searchParams.set("select",a),s&&h.append("Prefer",`count=${s}`),new O({method:n,url:o,headers:h,schema:this.schema,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}insert(r,{count:t,defaultToNull:e=!0}={}){var s;let n="POST",{url:i,headers:a}=this.cloneRequestState();if(t&&a.append("Prefer",`count=${t}`),e||a.append("Prefer","missing=default"),Array.isArray(r)){let o=r.reduce((h,u)=>h.concat(Object.keys(u)),[]);if(o.length>0){let h=[...new Set(o)].map(u=>`"${u}"`);i.searchParams.set("columns",h.join(","))}}return new O({method:n,url:i,headers:a,schema:this.schema,body:r,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch,urlLengthLimit:this.urlLengthLimit})}upsert(r,{onConflict:t,ignoreDuplicates:e=!1,count:s,defaultToNull:n=!0}={}){var i;let a="POST",{url:o,headers:h}=this.cloneRequestState();if(h.append("Prefer",`resolution=${e?"ignore":"merge"}-duplicates`),t!==void 0&&o.searchParams.set("on_conflict",t),s&&h.append("Prefer",`count=${s}`),n||h.append("Prefer","missing=default"),Array.isArray(r)){let u=r.reduce((l,p)=>l.concat(Object.keys(p)),[]);if(u.length>0){let l=[...new Set(u)].map(p=>`"${p}"`);o.searchParams.set("columns",l.join(","))}}return new O({method:a,url:o,headers:h,schema:this.schema,body:r,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch,urlLengthLimit:this.urlLengthLimit})}update(r,{count:t}={}){var e;let s="PATCH",{url:n,headers:i}=this.cloneRequestState();return t&&i.append("Prefer",`count=${t}`),new O({method:s,url:n,headers:i,schema:this.schema,body:r,fetch:(e=this.fetch)!==null&&e!==void 0?e:fetch,urlLengthLimit:this.urlLengthLimit})}delete({count:r}={}){var t;let e="DELETE",{url:s,headers:n}=this.cloneRequestState();return r&&n.append("Prefer",`count=${r}`),new O({method:e,url:s,headers:n,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch,urlLengthLimit:this.urlLengthLimit})}};function L(r){"@babel/helpers - typeof";return L=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},L(r)}function tt(r,t){if(L(r)!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var s=e.call(r,t||"default");if(L(s)!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function et(r){var t=tt(r,"string");return L(t)=="symbol"?t:t+""}function st(r,t,e){return(t=et(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function H(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(r);t&&(s=s.filter(function(n){return Object.getOwnPropertyDescriptor(r,n).enumerable})),e.push.apply(e,s)}return e}function x(r){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?H(Object(e),!0).forEach(function(s){st(r,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):H(Object(e)).forEach(function(s){Object.defineProperty(r,s,Object.getOwnPropertyDescriptor(e,s))})}return r}var W=class G{constructor(t,{headers:e={},schema:s,fetch:n,timeout:i,urlLengthLimit:a=8e3}={}){this.url=t,this.headers=new y.Headers(e),this.schemaName=s,this.urlLengthLimit=a;let o=n??globalThis.fetch;i!==void 0&&i>0?this.fetch=(h,u)=>{let l=new y.AbortController,p=setTimeout(()=>l.abort(),i),m=u?.signal;if(m){if(m.aborted)return clearTimeout(p),o(h,u);let d=()=>{clearTimeout(p),l.abort()};return m.addEventListener("abort",d,{once:!0}),o(h,x(x({},u),{},{signal:l.signal})).finally(()=>{clearTimeout(p),m.removeEventListener("abort",d)})}return o(h,x(x({},u),{},{signal:l.signal})).finally(()=>clearTimeout(p))}:this.fetch=o}from(t){if(!t||typeof t!="string"||t.trim()==="")throw new Error("Invalid relation name: relation must be a non-empty string.");return new Z(new y.URL(`${this.url}/${t}`),{headers:new y.Headers(this.headers),schema:this.schemaName,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}schema(t){return new G(this.url,{headers:this.headers,schema:t,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}rpc(t,e={},{head:s=!1,get:n=!1,count:i}={}){var a;let o,h=new y.URL(`${this.url}/rpc/${t}`),u,l=d=>d!==null&&typeof d=="object"&&(!Array.isArray(d)||d.some(l)),p=s&&Object.values(e).some(l);p?(o="POST",u=e):s||n?(o=s?"HEAD":"GET",Object.entries(e).filter(([d,g])=>g!==void 0).map(([d,g])=>[d,Array.isArray(g)?`{${g.join(",")}}`:`${g}`]).forEach(([d,g])=>{h.searchParams.append(d,g)})):(o="POST",u=e);let m=new y.Headers(this.headers);return p?m.set("Prefer",i?`count=${i},return=minimal`:"return=minimal"):i&&m.set("Prefer",`count=${i}`),new O({method:o,url:h,headers:m,schema:this.schemaName,body:u,fetch:(a=this.fetch)!==null&&a!==void 0?a:fetch,urlLengthLimit:this.urlLengthLimit})}};var q="/entities",rt=(r,t)=>new W(r+q,{fetch:t.fetchWithAuth.bind(t)});var A=class{constructor(){this.hoverOverlay=null;this.selectedOverlay=null;this.tooltip=null;this.hoverElement=null;this.selectedElement=null;this.hoverUpdateHandler=null;this.selectedUpdateHandler=null;this.createStyles()}createStyles(){if(document.getElementById("__nvwa-inspector-overlay-style"))return;let t=document.createElement("style");t.id="__nvwa-inspector-overlay-style",t.textContent=`
|
|
3
|
+
Caused by: ${(m=l?.name)!==null&&m!==void 0?m:"Error"}: ${Y}`,N&&(o+=` (${N})`),l?.stack&&(o+=`
|
|
4
|
+
${l.stack}`)}else{var b;o=(b=n?.stack)!==null&&b!==void 0?b:""}let w=this.url.toString().length;return n?.name==="AbortError"||n?.code==="ABORT_ERR"?(u="",h="Request was aborted (timeout or manual cancellation)",w>this.urlLengthLimit&&(h+=`. Note: Your request URL is ${w} characters, which may exceed server limits. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [many IDs])), consider using an RPC function to pass values server-side.`)):(l?.name==="HeadersOverflowError"||l?.code==="UND_ERR_HEADERS_OVERFLOW")&&(u="",h="HTTP headers exceeded server limits (typically 16KB)",w>this.urlLengthLimit&&(h+=`. Your request URL is ${w} characters. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [200+ IDs])), consider using an RPC function instead.`)),{error:{message:`${(a=n?.name)!==null&&a!==void 0?a:"FetchError"}: ${n?.message}`,details:o,hint:h,code:u},data:null,count:null,status:0,statusText:""}})),i.then(r,t)}returns(){return this}overrideTypes(){return this}},ot=class extends at{select(r){let t=!1,e=(r??"*").split("").map(s=>/\s/.test(s)&&!t?"":(s==='"'&&(t=!t),s)).join("");return this.url.searchParams.set("select",e),this.headers.append("Prefer","return=representation"),this}order(r,{ascending:t=!0,nullsFirst:e,foreignTable:s,referencedTable:i=s}={}){let n=i?`${i}.order`:"order",a=this.url.searchParams.get(n);return this.url.searchParams.set(n,`${a?`${a},`:""}${r}.${t?"asc":"desc"}${e===void 0?"":e?".nullsfirst":".nullslast"}`),this}limit(r,{foreignTable:t,referencedTable:e=t}={}){let s=typeof e>"u"?"limit":`${e}.limit`;return this.url.searchParams.set(s,`${r}`),this}range(r,t,{foreignTable:e,referencedTable:s=e}={}){let i=typeof s>"u"?"offset":`${s}.offset`,n=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(i,`${r}`),this.url.searchParams.set(n,`${t-r+1}`),this}abortSignal(r){return this.signal=r,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:r=!1,verbose:t=!1,settings:e=!1,buffers:s=!1,wal:i=!1,format:n="text"}={}){var a;let o=[r?"analyze":null,t?"verbose":null,e?"settings":null,s?"buffers":null,i?"wal":null].filter(Boolean).join("|"),h=(a=this.headers.get("Accept"))!==null&&a!==void 0?a:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${n}; for="${h}"; options=${o};`),n==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(r){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${r}`),this}},M=new RegExp("[,()]"),L=class extends ot{eq(r,t){return this.url.searchParams.append(r,`eq.${t}`),this}neq(r,t){return this.url.searchParams.append(r,`neq.${t}`),this}gt(r,t){return this.url.searchParams.append(r,`gt.${t}`),this}gte(r,t){return this.url.searchParams.append(r,`gte.${t}`),this}lt(r,t){return this.url.searchParams.append(r,`lt.${t}`),this}lte(r,t){return this.url.searchParams.append(r,`lte.${t}`),this}like(r,t){return this.url.searchParams.append(r,`like.${t}`),this}likeAllOf(r,t){return this.url.searchParams.append(r,`like(all).{${t.join(",")}}`),this}likeAnyOf(r,t){return this.url.searchParams.append(r,`like(any).{${t.join(",")}}`),this}ilike(r,t){return this.url.searchParams.append(r,`ilike.${t}`),this}ilikeAllOf(r,t){return this.url.searchParams.append(r,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(r,t){return this.url.searchParams.append(r,`ilike(any).{${t.join(",")}}`),this}regexMatch(r,t){return this.url.searchParams.append(r,`match.${t}`),this}regexIMatch(r,t){return this.url.searchParams.append(r,`imatch.${t}`),this}is(r,t){return this.url.searchParams.append(r,`is.${t}`),this}isDistinct(r,t){return this.url.searchParams.append(r,`isdistinct.${t}`),this}in(r,t){let e=Array.from(new Set(t)).map(s=>typeof s=="string"&&M.test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(r,`in.(${e})`),this}notIn(r,t){let e=Array.from(new Set(t)).map(s=>typeof s=="string"&&M.test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(r,`not.in.(${e})`),this}contains(r,t){return typeof t=="string"?this.url.searchParams.append(r,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(r,`cs.{${t.join(",")}}`):this.url.searchParams.append(r,`cs.${JSON.stringify(t)}`),this}containedBy(r,t){return typeof t=="string"?this.url.searchParams.append(r,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(r,`cd.{${t.join(",")}}`):this.url.searchParams.append(r,`cd.${JSON.stringify(t)}`),this}rangeGt(r,t){return this.url.searchParams.append(r,`sr.${t}`),this}rangeGte(r,t){return this.url.searchParams.append(r,`nxl.${t}`),this}rangeLt(r,t){return this.url.searchParams.append(r,`sl.${t}`),this}rangeLte(r,t){return this.url.searchParams.append(r,`nxr.${t}`),this}rangeAdjacent(r,t){return this.url.searchParams.append(r,`adj.${t}`),this}overlaps(r,t){return typeof t=="string"?this.url.searchParams.append(r,`ov.${t}`):this.url.searchParams.append(r,`ov.{${t.join(",")}}`),this}textSearch(r,t,{config:e,type:s}={}){let i="";s==="plain"?i="pl":s==="phrase"?i="ph":s==="websearch"&&(i="w");let n=e===void 0?"":`(${e})`;return this.url.searchParams.append(r,`${i}fts${n}.${t}`),this}match(r){return Object.entries(r).filter(([t,e])=>e!==void 0).forEach(([t,e])=>{this.url.searchParams.append(t,`eq.${e}`)}),this}not(r,t,e){return this.url.searchParams.append(r,`not.${t}.${e}`),this}or(r,{foreignTable:t,referencedTable:e=t}={}){let s=e?`${e}.or`:"or";return this.url.searchParams.append(s,`(${r})`),this}filter(r,t,e){return this.url.searchParams.append(r,`${t}.${e}`),this}},lt=class{constructor(r,{headers:t={},schema:e,fetch:s,urlLengthLimit:i=8e3}){this.url=r,this.headers=new f(t),this.schema=e,this.fetch=s,this.urlLengthLimit=i}cloneRequestState(){return{url:new O(this.url.toString()),headers:new f(this.headers)}}select(r,t){let{head:e=!1,count:s}=t??{},i=e?"HEAD":"GET",n=!1,a=(r??"*").split("").map(u=>/\s/.test(u)&&!n?"":(u==='"'&&(n=!n),u)).join(""),{url:o,headers:h}=this.cloneRequestState();return o.searchParams.set("select",a),s&&h.append("Prefer",`count=${s}`),new L({method:i,url:o,headers:h,schema:this.schema,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}insert(r,{count:t,defaultToNull:e=!0}={}){var s;let i="POST",{url:n,headers:a}=this.cloneRequestState();if(t&&a.append("Prefer",`count=${t}`),e||a.append("Prefer","missing=default"),Array.isArray(r)){let o=r.reduce((h,u)=>h.concat(Object.keys(u)),[]);if(o.length>0){let h=[...new Set(o)].map(u=>`"${u}"`);n.searchParams.set("columns",h.join(","))}}return new L({method:i,url:n,headers:a,schema:this.schema,body:r,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch,urlLengthLimit:this.urlLengthLimit})}upsert(r,{onConflict:t,ignoreDuplicates:e=!1,count:s,defaultToNull:i=!0}={}){var n;let a="POST",{url:o,headers:h}=this.cloneRequestState();if(h.append("Prefer",`resolution=${e?"ignore":"merge"}-duplicates`),t!==void 0&&o.searchParams.set("on_conflict",t),s&&h.append("Prefer",`count=${s}`),i||h.append("Prefer","missing=default"),Array.isArray(r)){let u=r.reduce((l,p)=>l.concat(Object.keys(p)),[]);if(u.length>0){let l=[...new Set(u)].map(p=>`"${p}"`);o.searchParams.set("columns",l.join(","))}}return new L({method:a,url:o,headers:h,schema:this.schema,body:r,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch,urlLengthLimit:this.urlLengthLimit})}update(r,{count:t}={}){var e;let s="PATCH",{url:i,headers:n}=this.cloneRequestState();return t&&n.append("Prefer",`count=${t}`),new L({method:s,url:i,headers:n,schema:this.schema,body:r,fetch:(e=this.fetch)!==null&&e!==void 0?e:fetch,urlLengthLimit:this.urlLengthLimit})}delete({count:r}={}){var t;let e="DELETE",{url:s,headers:i}=this.cloneRequestState();return r&&i.append("Prefer",`count=${r}`),new L({method:e,url:s,headers:i,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch,urlLengthLimit:this.urlLengthLimit})}};function S(r){"@babel/helpers - typeof";return S=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},S(r)}function ht(r,t){if(S(r)!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var s=e.call(r,t||"default");if(S(s)!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function ut(r){var t=ht(r,"string");return S(t)=="symbol"?t:t+""}function ct(r,t,e){return(t=ut(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function J(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(r);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),e.push.apply(e,s)}return e}function R(r){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?J(Object(e),!0).forEach(function(s){ct(r,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):J(Object(e)).forEach(function(s){Object.defineProperty(r,s,Object.getOwnPropertyDescriptor(e,s))})}return r}var B=class z{constructor(t,{headers:e={},schema:s,fetch:i,timeout:n,urlLengthLimit:a=8e3}={}){this.url=t,this.headers=new f(e),this.schemaName=s,this.urlLengthLimit=a;let o=i??globalThis.fetch;n!==void 0&&n>0?this.fetch=(h,u)=>{let l=new G,p=setTimeout(()=>l.abort(),n),d=u?.signal;if(d){if(d.aborted)return clearTimeout(p),o(h,u);let g=()=>{clearTimeout(p),l.abort()};return d.addEventListener("abort",g,{once:!0}),o(h,R(R({},u),{},{signal:l.signal})).finally(()=>{clearTimeout(p),d.removeEventListener("abort",g)})}return o(h,R(R({},u),{},{signal:l.signal})).finally(()=>clearTimeout(p))}:this.fetch=o}from(t){if(!t||typeof t!="string"||t.trim()==="")throw new Error("Invalid relation name: relation must be a non-empty string.");return new lt(new O(`${this.url}/${t}`),{headers:new f(this.headers),schema:this.schemaName,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}schema(t){return new z(this.url,{headers:this.headers,schema:t,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}rpc(t,e={},{head:s=!1,get:i=!1,count:n}={}){var a;let o,h=new O(`${this.url}/rpc/${t}`),u,l=g=>g!==null&&typeof g=="object"&&(!Array.isArray(g)||g.some(l)),p=s&&Object.values(e).some(l);p?(o="POST",u=e):s||i?(o=s?"HEAD":"GET",Object.entries(e).filter(([g,m])=>m!==void 0).map(([g,m])=>[g,Array.isArray(m)?`{${m.join(",")}}`:`${m}`]).forEach(([g,m])=>{h.searchParams.append(g,m)})):(o="POST",u=e);let d=new f(this.headers);return p?d.set("Prefer",n?`count=${n},return=minimal`:"return=minimal"):n&&d.set("Prefer",`count=${n}`),new L({method:o,url:h,headers:d,schema:this.schemaName,body:u,fetch:(a=this.fetch)!==null&&a!==void 0?a:fetch,urlLengthLimit:this.urlLengthLimit})}};var D="/entities",pt=(r,t)=>new B(r+D,{fetch:t.fetchWithAuth.bind(t)});var I=class{constructor(){this.hoverOverlay=null;this.selectedOverlay=null;this.tooltip=null;this.hoverElement=null;this.selectedElement=null;this.hoverUpdateHandler=null;this.selectedUpdateHandler=null;this.createStyles()}createStyles(){if(document.getElementById("__nvwa-inspector-overlay-style"))return;let t=document.createElement("style");t.id="__nvwa-inspector-overlay-style",t.textContent=`
|
|
5
5
|
.__nvwa-inspector-overlay {
|
|
6
6
|
position: absolute;
|
|
7
7
|
pointer-events: none;
|
|
@@ -33,4 +33,4 @@ ${l.stack}`)}else{var b;o=(b=i?.stack)!==null&&b!==void 0?b:""}let v=this.url.to
|
|
|
33
33
|
max-width: 400px;
|
|
34
34
|
word-break: break-all;
|
|
35
35
|
}
|
|
36
|
-
`,document.head.appendChild(t)}createTooltip(){return this.tooltip?this.tooltip:(this.tooltip=document.createElement("div"),this.tooltip.id="__nvwa-inspector-tooltip",document.body.appendChild(this.tooltip),this.tooltip)}createOverlay(t){let e=document.createElement("div");return e.className=`__nvwa-inspector-overlay __nvwa-inspector-overlay-${t}`,document.body.appendChild(e),e}updateOverlayPosition(t,e){if(!e.isConnected)return;let s=e.getBoundingClientRect(),
|
|
36
|
+
`,document.head.appendChild(t)}createTooltip(){return this.tooltip?this.tooltip:(this.tooltip=document.createElement("div"),this.tooltip.id="__nvwa-inspector-tooltip",document.body.appendChild(this.tooltip),this.tooltip)}createOverlay(t){let e=document.createElement("div");return e.className=`__nvwa-inspector-overlay __nvwa-inspector-overlay-${t}`,document.body.appendChild(e),e}updateOverlayPosition(t,e){if(!e.isConnected)return;let s=e.getBoundingClientRect(),i=window.scrollX||window.pageXOffset,n=window.scrollY||window.pageYOffset;s.width>0&&s.height>0?(t.style.left=`${s.left+i}px`,t.style.top=`${s.top+n}px`,t.style.width=`${s.width}px`,t.style.height=`${s.height}px`,t.style.display="block"):t.style.display="none"}removeOverlay(t){t&&t.parentNode&&t.parentNode.removeChild(t)}highlightElement(t,e){if(!t.isConnected)return;if(this.hoverElement===t&&this.hoverOverlay){this.updateOverlayPosition(this.hoverOverlay,t);let o=this.createTooltip();e?o.textContent=e:o.textContent=`<${t.tagName.toLowerCase()}> (\u65E0 source location)`,o.style.display="block";let h=t.getBoundingClientRect();o.style.left=`${h.left+window.scrollX}px`,o.style.top=`${h.top+window.scrollY-o.offsetHeight-8}px`,h.top<o.offsetHeight+8&&(o.style.top=`${h.bottom+window.scrollY+8}px`);return}this.hoverOverlay&&(this.removeOverlay(this.hoverOverlay),this.hoverOverlay=null);let s=this.createOverlay("hover");this.updateOverlayPosition(s,t),this.hoverOverlay=s,this.hoverElement=t;let i=()=>{this.hoverOverlay&&this.hoverElement&&this.hoverElement.isConnected&&this.updateOverlayPosition(this.hoverOverlay,this.hoverElement)};this.hoverUpdateHandler&&(window.removeEventListener("scroll",this.hoverUpdateHandler,!0),window.removeEventListener("resize",this.hoverUpdateHandler)),this.hoverUpdateHandler=i,window.addEventListener("scroll",i,!0),window.addEventListener("resize",i);let n=this.createTooltip();e?n.textContent=e:n.textContent=`<${t.tagName.toLowerCase()}> (\u65E0 source location)`,n.style.display="block";let a=t.getBoundingClientRect();n.style.left=`${a.left+window.scrollX}px`,n.style.top=`${a.top+window.scrollY-n.offsetHeight-8}px`,a.top<n.offsetHeight+8&&(n.style.top=`${a.bottom+window.scrollY+8}px`)}selectElement(t,e){if(!t.isConnected)return;if(this.selectedElement===t&&this.selectedOverlay){this.updateOverlayPosition(this.selectedOverlay,t);return}this.selectedOverlay&&(this.removeOverlay(this.selectedOverlay),this.selectedOverlay=null);let s=this.createOverlay("selected");this.updateOverlayPosition(s,t),this.selectedOverlay=s,this.selectedElement=t;let i=()=>{this.selectedOverlay&&this.selectedElement&&this.selectedElement.isConnected&&this.updateOverlayPosition(this.selectedOverlay,this.selectedElement)};this.selectedUpdateHandler&&(window.removeEventListener("scroll",this.selectedUpdateHandler,!0),window.removeEventListener("resize",this.selectedUpdateHandler)),this.selectedUpdateHandler=i,window.addEventListener("scroll",i,!0),window.addEventListener("resize",i)}removeHighlight(){this.hoverOverlay&&(this.removeOverlay(this.hoverOverlay),this.hoverOverlay=null),this.hoverElement&&(this.hoverElement=null),this.tooltip&&(this.tooltip.style.display="none"),this.hoverUpdateHandler&&(window.removeEventListener("scroll",this.hoverUpdateHandler,!0),window.removeEventListener("resize",this.hoverUpdateHandler),this.hoverUpdateHandler=null)}clearSelection(){this.selectedOverlay&&(this.removeOverlay(this.selectedOverlay),this.selectedOverlay=null),this.selectedElement&&(this.selectedElement=null),this.selectedUpdateHandler&&(window.removeEventListener("scroll",this.selectedUpdateHandler,!0),window.removeEventListener("resize",this.selectedUpdateHandler),this.selectedUpdateHandler=null)}cleanup(){this.removeHighlight(),this.clearSelection(),this.tooltip&&this.tooltip.parentNode&&(this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null);let t=document.getElementById("__nvwa-inspector-overlay-style");t&&t.parentNode&&t.parentNode.removeChild(t)}};function dt(r="root"){if(typeof document>"u")return null;let t=document.getElementById(r)||document.body;if(!t)return null;let e=t.querySelector("[data-source-location]");if(e){let s=e.getAttribute("data-source-location");if(s)return s}if(t.firstElementChild){let i=t.firstElementChild.getAttribute("data-source-location");if(i)return i}return null}function gt(r){let t=r;if(typeof t.kind=="string")return t;if(typeof t.tradeNO=="string")return{kind:"alipay_miniprogram",tradeNO:t.tradeNO};if(typeof t.clientSecret=="string")return{kind:"stripe_client_secret",clientSecret:t.clientSecret};if(typeof t.redirectUrl=="string")return{kind:"redirect_url",redirectUrl:t.redirectUrl};if(typeof t.formHtml=="string")return{kind:"alipay_page",formHtml:t.formHtml};if(typeof t.codeUrl=="string")return{kind:"wechat_native_qr",codeUrl:t.codeUrl};let e=t.jsapiPayParams??t;return typeof e.timeStamp=="string"&&typeof e.nonceStr=="string"&&typeof e.package=="string"&&typeof e.paySign=="string"&&typeof e.appId=="string"?{kind:"wechat_jsapi",mode:"jsapi",jsapiPayParams:{appId:e.appId,timeStamp:e.timeStamp,nonceStr:e.nonceStr,package:e.package,signType:e.signType??"RSA",paySign:e.paySign}}:null}function mt(r,t,e){return t.requestPayment(r.payParams,e)}0&&(module.exports={AuthClient,CURRENT_JWT_KEY,ENTITIES_BASE_PATH,FILE_STORAGE_BASE_PATH,GENERATE_UPLOAD_URL_PATH,Headers,LOGIN_TOKEN_KEY,LOGIN_USER_PROFILE_KEY,NvwaEdgeFunctions,NvwaFileStorage,NvwaHttpClient,OverlayManager,Request,Response,SET_AUTH_TOKEN_HEADER,URL,createPostgrestClient,getSourceLocationFromDOM,normalizePayParams,requestPaymentFromOrderResult});
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var _=class{constructor(t,e=""){this.http=t,this.baseUrl=e.replace(/\/$/,"")}async invoke(t,e){let s=this.baseUrl?`${this.baseUrl}/functions/${t}`:`/functions/${t}`;return await(await this.http.fetch(s,{method:e.method||"POST",body:e.body,headers:e.headers})).json()}};var c="nvwa_current_jwt",f="nvwa_login_token",y="nvwa_user_profile",k="set-auth-token",W=typeof fetch<"u"?(r,t)=>fetch(r,t):()=>{throw new Error("AuthClient requires fetch")},T=class{constructor(t,e={}){this.baseUrl=t.replace(/\/$/,""),this.authPath=(e.authPath??"/auth").replace(/^\//,""),this.fetchImpl=e.fetchImpl??W,this.storage=e.storage??null,this.credentials=e.credentials??"omit",typeof console<"u"&&(console.warn("[NvwaAuth] init baseUrl:",this.baseUrl||"(empty)"),(!this.baseUrl||!this.baseUrl.startsWith("http://")&&!this.baseUrl.startsWith("https://"))&&console.warn("[NvwaAuth] baseUrl \u5E94\u4E3A\u5B8C\u6574\u5730\u5740\uFF08\u5982 https://xxx.nvwa.app\uFF09\uFF0C\u5426\u5219\u5C0F\u7A0B\u5E8F request \u4F1A\u62A5 invalid url"))}async currentUser(){if(this.storage){let s=await this.storage.get(y);if(s!=null)return s}let{data:t}=await this.getSession(),e=t?.user??null;return e&&this.storage&&await this.storage.set(y,e),e}async getCurrentJwt(){if(this.storage){let e=await this.storage.get(c);if(e!=null)return e;let s=await this.storage.get(f),{data:n}=await this.getToken(s??void 0);return n?.token?(await this.storage.set(c,n.token),n.token):null}let{data:t}=await this.getToken();return t?.token??null}async persistLogin(t,e){if(!this.storage)return;let n=e?.headers.get(k)?.trim()||t.token||t.session?.token;n&&await this.storage.set(f,n),t.user&&await this.storage.set(y,t.user);let i=n??await this.storage.get(f),{data:a}=await this.getToken(i??void 0);a?.token&&await this.storage.set(c,a.token)}async clearLogin(){this.storage&&(await this.storage.remove(f),await this.storage.remove(y),await this.storage.remove(c))}getGoogleOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("google/openplatform/login")}?${e.toString()}`}startGoogleOpenPlatformLogin(t){let e=this.getGoogleOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startGoogleOpenPlatformLogin requires a browser environment with location")}async completeGoogleOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeGoogleOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithGoogleExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithGoogleExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("google/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):null;return!i?.token||!i.user?{error:{message:"invalid_google_login_response",status:502}}:(this.storage&&(await this.storage.set(c,i.token),await this.storage.set(f,i.token),await this.storage.set(y,i.user)),{data:i})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getGoogleOpenPlatformIdentity(){try{let t={};if(this.storage){let i=await this.storage.get(c);i!=null&&(t.Authorization=`Bearer ${i}`)}let e=await this.fetchImpl(this.url("google/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let n=s?JSON.parse(s):null;return n?.sub?{data:n}:{error:{message:"invalid_google_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}getGithubOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("github/openplatform/login")}?${e.toString()}`}startGithubOpenPlatformLogin(t){let e=this.getGithubOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startGithubOpenPlatformLogin requires a browser environment with location")}async completeGithubOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeGithubOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithGithubExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithGithubExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("github/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):null;return!i?.token||!i.user?{error:{message:"invalid_github_login_response",status:502}}:(this.storage&&(await this.storage.set(c,i.token),await this.storage.set(f,i.token),await this.storage.set(y,i.user)),{data:i})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getGithubOpenPlatformIdentity(){try{let t={};if(this.storage){let i=await this.storage.get(c);i!=null&&(t.Authorization=`Bearer ${i}`)}let e=await this.fetchImpl(this.url("github/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let n=s?JSON.parse(s):null;return n?.sub?{data:n}:{error:{message:"invalid_github_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}getWechatWebsiteOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("wechat-website/openplatform/login")}?${e.toString()}`}startWechatWebsiteOpenPlatformLogin(t){let e=this.getWechatWebsiteOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startWechatWebsiteOpenPlatformLogin requires a browser environment with location")}async completeWechatWebsiteOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeWechatWebsiteOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithWechatWebsiteExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithWechatWebsiteExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("wechat-website/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):null;return!i?.token||!i.user?{error:{message:"invalid_wechat_website_login_response",status:502}}:(this.storage&&(await this.storage.set(c,i.token),await this.storage.set(f,i.token),await this.storage.set(y,i.user)),{data:i})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getWechatWebsiteOpenPlatformIdentity(){try{let t={};if(this.storage){let i=await this.storage.get(c);i!=null&&(t.Authorization=`Bearer ${i}`)}let e=await this.fetchImpl(this.url("wechat-website/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let n=s?JSON.parse(s):null;return n?.sub?{data:n}:{error:{message:"invalid_wechat_website_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}url(t){let s=`${`${this.baseUrl.replace(/\/+$/,"")}/${this.authPath.replace(/^\/+/,"")}`}/${t.replace(/^\/+/,"")}`;return typeof console<"u"&&(console.warn("[NvwaAuth] request URL:",s),!s.startsWith("http://")&&!s.startsWith("https://")&&console.warn("[NvwaAuth] URL \u975E\u5B8C\u6574\u5730\u5740\uFF0C\u5C0F\u7A0B\u5E8F\u4F1A\u62A5 invalid url\uFF0C\u8BF7\u68C0\u67E5 Nvwa \u6784\u9020\u65F6\u4F20\u5165\u7684 baseUrl")),s}async getSession(){try{let t={};if(this.storage){let n=await this.storage.get(f)??await this.storage.get(c);n!=null&&(t.Authorization=`Bearer ${n}`)}let e=await this.fetchImpl(this.url("session"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}});return e.ok?{data:await e.json()}:{data:null,error:{message:await e.text()||e.statusText,status:e.status}}}catch(t){return{data:null,error:{message:t instanceof Error?t.message:String(t),status:0}}}}async signInWithEmail(t,e){try{let s=await this.fetchImpl(this.url("sign-in/email"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:this.credentials,body:JSON.stringify({email:t,password:e})}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):void 0;return i&&await this.persistLogin({user:i.user,session:i.session},s),{data:i}}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async signOut(){try{let t={};if(this.storage){let s=await this.storage.get(f)??await this.storage.get(c);s!=null&&(t.Authorization=`Bearer ${s}`)}let e=await this.fetchImpl(this.url("sign-out"),{method:"POST",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}});return await this.clearLogin(),e.ok?{}:{error:{message:await e.text()||e.statusText,status:e.status}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}async signUp(t){let e=await this.postJson("sign-up/email",t);return e.data&&await this.persistLogin(e.data,e.response),e}async getToken(t){try{let e={};if(t)e.Authorization=`Bearer ${t}`;else if(this.storage){let a=await this.storage.get(f)??await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("token"),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):void 0;return{data:i?.token!=null?{token:i.token}:void 0}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async signInWithUsername(t,e){let s=await this.postJson("sign-in/username",{username:t,password:e});return s.data&&await this.persistLogin(s.data,s.response),s}async signInWithPhoneNumber(t,e,s){let n=await this.postJson("sign-in/phone-number",{phoneNumber:t,password:e,rememberMe:s});return n.data&&await this.persistLogin(n.data,n.response),n}async sendPhoneNumberOtp(t){let e=await this.postJson("phone-number/send-otp",{phoneNumber:t});return e.error?{error:e.error}:{}}async verifyPhoneNumber(t,e){let s=await this.postJson("phone-number/verify",{phoneNumber:t,code:e});return s.data&&await this.persistLogin(s.data,s.response),s}async loginWithWeChatCode(t,e){try{let s={"Content-Type":"application/json"};if(this.storage){let o=await this.storage.get(c);o!=null&&(s.Authorization=`Bearer ${o}`)}let n=await this.fetchImpl(this.url("wechat/openplatform/sign-in"),{method:"POST",headers:s,credentials:this.credentials,body:JSON.stringify({code:t,applicationCode:e})}),i=await n.text();if(!n.ok)return{error:{message:i||n.statusText,status:n.status}};let a=i?JSON.parse(i):null;return!a?.token||!a.user?{error:{message:"invalid_wechat_login_response",status:502}}:(this.storage&&(await this.storage.set(c,a.token),await this.storage.set(f,a.token),await this.storage.set(y,a.user)),{data:a})}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async loginWithAlipayCode(t,e){try{let s={"Content-Type":"application/json"};if(this.storage){let o=await this.storage.get(c);o!=null&&(s.Authorization=`Bearer ${o}`)}let n=await this.fetchImpl(this.url("alipay/openplatform/sign-in"),{method:"POST",headers:s,credentials:this.credentials,body:JSON.stringify({code:t,applicationCode:e})}),i=await n.text();if(!n.ok)return{error:{message:i||n.statusText,status:n.status}};let a=i?JSON.parse(i):null;return!a?.token||!a.user?{error:{message:"invalid_alipay_login_response",status:502}}:(this.storage&&(await this.storage.set(c,a.token),await this.storage.set(f,a.token),await this.storage.set(y,a.user)),{data:a})}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async getWeChatOpenPlatformIdentity(t){try{let e={};if(this.storage){let o=await this.storage.get(c);o!=null&&(e.Authorization=`Bearer ${o}`)}let s=t?.trim()?`?applicationCode=${encodeURIComponent(t.trim())}`:"",n=await this.fetchImpl(this.url(`wechat/openplatform/identity${s}`),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),i=await n.text();if(!n.ok)return{error:{message:i||n.statusText,status:n.status}};let a=i?JSON.parse(i):null;return!a?.openid||!a.appId?{error:{message:"invalid_wechat_identity_response",status:502}}:{data:a}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getAlipayOpenPlatformIdentity(t){try{let e={};if(this.storage){let o=await this.storage.get(c);o!=null&&(e.Authorization=`Bearer ${o}`)}let s=t?.trim()?`?applicationCode=${encodeURIComponent(t.trim())}`:"",n=await this.fetchImpl(this.url(`alipay/openplatform/identity${s}`),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),i=await n.text();if(!n.ok)return{error:{message:i||n.statusText,status:n.status}};let a=i?JSON.parse(i):null;return!a?.openid||!a.appId?{error:{message:"invalid_alipay_identity_response",status:502}}:{data:a}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async postJson(t,e){try{let s=await this.fetchImpl(this.url(t),{method:"POST",headers:{"Content-Type":"application/json"},credentials:this.credentials,body:JSON.stringify(e)}),n=await s.text();if(!s.ok)return{error:{message:n||s.statusText,status:s.status}};let i=n?JSON.parse(n):void 0;return{data:i?.data??i??void 0,response:s}}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}};import{Headers as G}from"@nvwa-app/nvwa-http-polyfill";var A=class{constructor(t,e,s){this.storage=t,this.customFetch=e,this.handleUnauthorized=s}async fetch(t,e){return await this.customFetch(t,e)}async fetchWithAuth(t,e){let s=await this.storage.get(c),n=new G(e?.headers);s&&n.set("Authorization",`Bearer ${s}`);let i=e?.method||"GET";if((i==="POST"||i==="PUT"||i==="PATCH")&&e?.body){let o=n.get("Content-Type");(!o||o.includes("text/plain"))&&n.set("Content-Type","application/json")}let a=await this.customFetch(t,{...e,headers:n});if(a.status===401)throw this.handleUnauthorized(),new Error("\u672A\u767B\u5F55");return a}};import{Headers as q}from"@nvwa-app/nvwa-http-polyfill";var F="/storage",B=F+"/generateUploadUrl",C=class{constructor(t,e){this.baseUrl=t,this.http=e}async uploadFile(t){let e=await this.http.fetch(this.baseUrl+B,{method:"POST",body:{fileName:t.name||t.fileName,fileSize:t.size||t.fileSize,fileType:t.type||t.fileType}}),{url:s}=await e.json();if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");let n=await this.http.fetch(s,{method:"PUT",body:t,headers:new q({"Content-Type":t.type||t.fileType||"application/octet-stream"})}),{url:i}=await n.json();return{url:i.split("?")[0]}}};import{AbortController as J,Headers as O,URL as S}from"@nvwa-app/nvwa-http-polyfill";var z=class extends Error{constructor(r){super(r.message),this.name="PostgrestError",this.details=r.details,this.hint=r.hint,this.code=r.code}},M=class{constructor(r){var t,e,s;this.shouldThrowOnError=!1,this.method=r.method,this.url=r.url,this.headers=new O(r.headers),this.schema=r.schema,this.body=r.body,this.shouldThrowOnError=(t=r.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=r.signal,this.isMaybeSingle=(e=r.isMaybeSingle)!==null&&e!==void 0?e:!1,this.urlLengthLimit=(s=r.urlLengthLimit)!==null&&s!==void 0?s:8e3,r.fetch?this.fetch=r.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(r,t){return this.headers=new O(this.headers),this.headers.set(r,t),this}then(r,t){var e=this;this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,n=s(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async i=>{let a=null,o=null,h=null,u=i.status,l=i.statusText;if(i.ok){var p,m;if(e.method!=="HEAD"){var d;let w=await i.text();w===""||(e.headers.get("Accept")==="text/csv"||e.headers.get("Accept")&&(!((d=e.headers.get("Accept"))===null||d===void 0)&&d.includes("application/vnd.pgrst.plan+text"))?o=w:o=JSON.parse(w))}let g=(p=e.headers.get("Prefer"))===null||p===void 0?void 0:p.match(/count=(exact|planned|estimated)/),b=(m=i.headers.get("content-range"))===null||m===void 0?void 0:m.split("/");g&&b&&b.length>1&&(h=parseInt(b[1])),e.isMaybeSingle&&Array.isArray(o)&&(o.length>1?(a={code:"PGRST116",details:`Results contain ${o.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},o=null,h=null,u=406,l="Not Acceptable"):o.length===1?o=o[0]:o=null)}else{let g=await i.text();try{a=JSON.parse(g),Array.isArray(a)&&i.status===404&&(o=[],a=null,u=200,l="OK")}catch{i.status===404&&g===""?(u=204,l="No Content"):a={message:g}}if(a&&e.shouldThrowOnError)throw new z(a)}return{error:a,data:o,count:h,status:u,statusText:l}});return this.shouldThrowOnError||(n=n.catch(i=>{var a;let o="",h="",u="",l=i?.cause;if(l){var p,m,d,g;let H=(p=l?.message)!==null&&p!==void 0?p:"",R=(m=l?.code)!==null&&m!==void 0?m:"";o=`${(d=i?.name)!==null&&d!==void 0?d:"FetchError"}: ${i?.message}`,o+=`
|
|
1
|
+
var f=class k{constructor(t){if(this.headerMap=new Map,t){if(t instanceof k)t.forEach((e,s)=>this.set(s,e));else if(Array.isArray(t))for(let[e,s]of t)this.set(e,String(s));else if(typeof t=="object")for(let e of Object.keys(t))this.set(e,String(t[e]))}}append(t,e){let s=t.toLowerCase(),i=this.headerMap.get(s);this.headerMap.set(s,i?`${i}, ${e}`:e)}set(t,e){this.headerMap.set(t.toLowerCase(),String(e))}get(t){return this.headerMap.get(t.toLowerCase())??null}has(t){return this.headerMap.has(t.toLowerCase())}delete(t){this.headerMap.delete(t.toLowerCase())}forEach(t){for(let[e,s]of this.headerMap.entries())t(s,e,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}},z=class A{constructor(t){if(this.params=new Map,t){if(typeof t=="string")this.parseString(t);else if(t instanceof A)this.params=new Map(t.params);else if(Array.isArray(t))for(let[e,s]of t)this.append(e,s);else if(t&&typeof t=="object")for(let[e,s]of Object.entries(t))this.set(e,s)}}parseString(t){t.startsWith("?")&&(t=t.slice(1));let e=t.split("&");for(let s of e)if(s){let[i,n]=s.split("=");i&&this.append(decodeURIComponent(i),n?decodeURIComponent(n):"")}}append(t,e){let s=this.params.get(t)||[];s.push(e),this.params.set(t,s)}delete(t){this.params.delete(t)}get(t){let e=this.params.get(t);return e?e[0]:null}getAll(t){return this.params.get(t)||[]}has(t){return this.params.has(t)}set(t,e){this.params.set(t,[e])}sort(){let t=Array.from(this.params.entries()).sort(([e],[s])=>e.localeCompare(s));this.params=new Map(t)}toString(){let t=[];for(let[e,s]of this.params.entries())for(let i of s)t.push(`${encodeURIComponent(e)}=${encodeURIComponent(i)}`);return t.join("&")}forEach(t){for(let[e,s]of this.params.entries())for(let i of s)t(i,e,this)}keys(){return this.params.keys()}values(){let t=[];for(let e of this.params.values())t.push(...e);return t[Symbol.iterator]()}entries(){let t=[];for(let[e,s]of this.params.entries())for(let i of s)t.push([e,i]);return t[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}},L=class x{constructor(t,e){let s;if(t instanceof x)s=t.href;else if(e){let n=e instanceof x?e.href:e;s=this.resolve(n,t)}else s=t;let i=this.parseUrl(s);this.href=s,this.origin=`${i.protocol}//${i.host}`,this.protocol=i.protocol,this.username=i.username,this.password=i.password,this.host=i.host,this.hostname=i.hostname,this.port=i.port,this.pathname=i.pathname,this.search=i.search,this.searchParams=new z(i.search),this.hash=i.hash}resolve(t,e){if(e.startsWith("http://")||e.startsWith("https://"))return e;if(e.startsWith("//"))return`${this.parseUrl(t).protocol}${e}`;if(e.startsWith("/")){let n=this.parseUrl(t);return`${n.protocol}//${n.host}${e}`}let s=this.parseUrl(t),i=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${i}${e}`}parseUrl(t){let e=t.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!e)throw new TypeError("Invalid URL");let s=e[2]||"",i=e[4]||"",n=e[5]||"/",a=e[7]?`?${e[7]}`:"",o=e[9]?`#${e[9]}`:"";if(!s&&!i&&!n.startsWith("/")&&!n.includes("/")&&!n.includes("."))throw new TypeError("Invalid URL");let h=i.match(/^([^@]*)@(.+)$/),u="",l="",p=i;if(h){let b=h[1];p=h[2];let y=b.match(/^([^:]*):?(.*)$/);y&&(u=y[1]||"",l=y[2]||"")}let d=p.match(/^([^:]+):?(\d*)$/),g=d?d[1]:p,m=d&&d[2]?d[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:p,hostname:g,port:m,pathname:n,search:a,hash:o}}toString(){let t=this.searchParams.toString(),e=t?`?${t}`:"";return`${this.protocol}//${this.host}${this.pathname}${e}${this.hash}`}toJSON(){return this.toString()}},U=class ${constructor(t,e){if(typeof t=="string")this.url=t;else if(t?.url)this.url=String(t.url);else if(typeof t?.toString=="function")this.url=String(t.toString());else throw new Error("Invalid input for Request");this.method=(e?.method||"GET").toUpperCase(),this.headers=e?.headers instanceof f?e.headers:new f(e?.headers),this.body=e?.body,this.timeout=e?.timeout,this.signal=e?.signal||void 0}clone(){return new $(this.url,{method:this.method,headers:this.headers,body:this.body,timeout:this.timeout})}toString(){return this.url}},C=class{constructor(r,t){this.bodyData=r,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=D(t?.headers),this.ok=this.status>=200&&this.status<300}async text(){return typeof this.bodyData=="string"?this.bodyData:this.bodyData==null?"":typeof this.bodyData=="object"?JSON.stringify(this.bodyData):String(this.bodyData)}async json(){if(typeof this.bodyData=="string")try{return JSON.parse(this.bodyData)}catch{}return this.bodyData}async arrayBuffer(){let r=await this.text();return new TextEncoder().encode(r).buffer}};function D(r){return r?new f(r):new f}var Y=class{constructor(){this._aborted=!1,this.listeners=new Set,this.onabort=null}get aborted(){return this._aborted}_trigger(){if(!this._aborted){if(this._aborted=!0,typeof this.onabort=="function")try{this.onabort()}catch{}for(let r of Array.from(this.listeners))try{r()}catch{}this.listeners.clear()}}addEventListener(r,t){if(this._aborted){try{t()}catch{}return}this.listeners.add(t)}removeEventListener(r,t){this.listeners.delete(t)}toString(){return"[object AbortSignal]"}},I=class{constructor(){this._signal=new Y}get signal(){return this._signal}abort(){this._signal._trigger()}toString(){return"[object AbortController]"}};var N=class{constructor(t,e=""){this.http=t,this.baseUrl=e.replace(/\/$/,"")}async invoke(t,e){let s=this.baseUrl?`${this.baseUrl}/functions/${t}`:`/functions/${t}`;return await(await this.http.fetch(s,{method:e.method||"POST",body:e.body,headers:e.headers})).json()}};var c="nvwa_current_jwt",w="nvwa_login_token",O="nvwa_user_profile",j="set-auth-token",K=typeof fetch<"u"?(r,t)=>fetch(r,t):()=>{throw new Error("AuthClient requires fetch")},T=class{constructor(t,e={}){this.baseUrl=t.replace(/\/$/,""),this.authPath=(e.authPath??"/auth").replace(/^\//,""),this.fetchImpl=e.fetchImpl??K,this.storage=e.storage??null,this.credentials=e.credentials??"omit",typeof console<"u"&&(console.warn("[NvwaAuth] init baseUrl:",this.baseUrl||"(empty)"),(!this.baseUrl||!this.baseUrl.startsWith("http://")&&!this.baseUrl.startsWith("https://"))&&console.warn("[NvwaAuth] baseUrl \u5E94\u4E3A\u5B8C\u6574\u5730\u5740\uFF08\u5982 https://xxx.nvwa.app\uFF09\uFF0C\u5426\u5219\u5C0F\u7A0B\u5E8F request \u4F1A\u62A5 invalid url"))}async currentUser(){if(this.storage){let s=await this.storage.get(O);if(s!=null)return s}let{data:t}=await this.getSession(),e=t?.user??null;return e&&this.storage&&await this.storage.set(O,e),e}async getCurrentJwt(){if(this.storage){let e=await this.storage.get(c);if(e!=null)return e;let s=await this.storage.get(w),{data:i}=await this.getToken(s??void 0);return i?.token?(await this.storage.set(c,i.token),i.token):null}let{data:t}=await this.getToken();return t?.token??null}async persistLogin(t,e){if(!this.storage)return;let i=e?.headers.get(j)?.trim()||t.token||t.session?.token;i&&await this.storage.set(w,i),t.user&&await this.storage.set(O,t.user);let n=i??await this.storage.get(w),{data:a}=await this.getToken(n??void 0);a?.token&&await this.storage.set(c,a.token)}async clearLogin(){this.storage&&(await this.storage.remove(w),await this.storage.remove(O),await this.storage.remove(c))}getGoogleOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("google/openplatform/login")}?${e.toString()}`}startGoogleOpenPlatformLogin(t){let e=this.getGoogleOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startGoogleOpenPlatformLogin requires a browser environment with location")}async completeGoogleOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeGoogleOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithGoogleExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithGoogleExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("google/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):null;return!n?.token||!n.user?{error:{message:"invalid_google_login_response",status:502}}:(this.storage&&(await this.storage.set(c,n.token),await this.storage.set(w,n.token),await this.storage.set(O,n.user)),{data:n})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getGoogleOpenPlatformIdentity(){try{let t={};if(this.storage){let n=await this.storage.get(c);n!=null&&(t.Authorization=`Bearer ${n}`)}let e=await this.fetchImpl(this.url("google/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let i=s?JSON.parse(s):null;return i?.sub?{data:i}:{error:{message:"invalid_google_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}getGithubOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("github/openplatform/login")}?${e.toString()}`}startGithubOpenPlatformLogin(t){let e=this.getGithubOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startGithubOpenPlatformLogin requires a browser environment with location")}async completeGithubOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeGithubOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithGithubExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithGithubExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("github/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):null;return!n?.token||!n.user?{error:{message:"invalid_github_login_response",status:502}}:(this.storage&&(await this.storage.set(c,n.token),await this.storage.set(w,n.token),await this.storage.set(O,n.user)),{data:n})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getGithubOpenPlatformIdentity(){try{let t={};if(this.storage){let n=await this.storage.get(c);n!=null&&(t.Authorization=`Bearer ${n}`)}let e=await this.fetchImpl(this.url("github/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let i=s?JSON.parse(s):null;return i?.sub?{data:i}:{error:{message:"invalid_github_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}getWechatWebsiteOpenPlatformLoginUrl(t){let e=new URLSearchParams({return_url:t});return`${this.url("wechat-website/openplatform/login")}?${e.toString()}`}startWechatWebsiteOpenPlatformLogin(t){let e=this.getWechatWebsiteOpenPlatformLoginUrl(t);if(typeof globalThis<"u"&&"location"in globalThis){globalThis.location.href=e;return}throw new Error("startWechatWebsiteOpenPlatformLogin requires a browser environment with location")}async completeWechatWebsiteOpenPlatformLoginFromCurrentUrl(t){let e;if(t!=null&&t!=="")e=t;else if(typeof globalThis<"u"&&"location"in globalThis)e=globalThis.location.href;else return{error:{message:"completeWechatWebsiteOpenPlatformLoginFromCurrentUrl requires url or browser location",status:0}};let s;try{s=new URL(e).searchParams.get("exchange_code")}catch{return{error:{message:"invalid_callback_url",status:400}}}return s?.trim()?await this.loginWithWechatWebsiteExchangeCode(s.trim()):{error:{message:"missing_exchange_code",status:400}}}async loginWithWechatWebsiteExchangeCode(t){try{let e={"Content-Type":"application/json"};if(this.storage){let a=await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("wechat-website/openplatform/sign-in"),{method:"POST",headers:e,credentials:this.credentials,body:JSON.stringify({exchangeCode:t})}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):null;return!n?.token||!n.user?{error:{message:"invalid_wechat_website_login_response",status:502}}:(this.storage&&(await this.storage.set(c,n.token),await this.storage.set(w,n.token),await this.storage.set(O,n.user)),{data:n})}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getWechatWebsiteOpenPlatformIdentity(){try{let t={};if(this.storage){let n=await this.storage.get(c);n!=null&&(t.Authorization=`Bearer ${n}`)}let e=await this.fetchImpl(this.url("wechat-website/openplatform/identity"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}}),s=await e.text();if(!e.ok)return{error:{message:s||e.statusText,status:e.status}};let i=s?JSON.parse(s):null;return i?.sub?{data:i}:{error:{message:"invalid_wechat_website_identity_response",status:502}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}url(t){let s=`${`${this.baseUrl.replace(/\/+$/,"")}/${this.authPath.replace(/^\/+/,"")}`}/${t.replace(/^\/+/,"")}`;return typeof console<"u"&&(console.warn("[NvwaAuth] request URL:",s),!s.startsWith("http://")&&!s.startsWith("https://")&&console.warn("[NvwaAuth] URL \u975E\u5B8C\u6574\u5730\u5740\uFF0C\u5C0F\u7A0B\u5E8F\u4F1A\u62A5 invalid url\uFF0C\u8BF7\u68C0\u67E5 Nvwa \u6784\u9020\u65F6\u4F20\u5165\u7684 baseUrl")),s}async getSession(){try{let t={};if(this.storage){let i=await this.storage.get(w)??await this.storage.get(c);i!=null&&(t.Authorization=`Bearer ${i}`)}let e=await this.fetchImpl(this.url("session"),{method:"GET",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}});return e.ok?{data:await e.json()}:{data:null,error:{message:await e.text()||e.statusText,status:e.status}}}catch(t){return{data:null,error:{message:t instanceof Error?t.message:String(t),status:0}}}}async signInWithEmail(t,e){try{let s=await this.fetchImpl(this.url("sign-in/email"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:this.credentials,body:JSON.stringify({email:t,password:e})}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):void 0;return n&&await this.persistLogin({user:n.user,session:n.session},s),{data:n}}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async signOut(){try{let t={};if(this.storage){let s=await this.storage.get(w)??await this.storage.get(c);s!=null&&(t.Authorization=`Bearer ${s}`)}let e=await this.fetchImpl(this.url("sign-out"),{method:"POST",credentials:this.credentials,...Object.keys(t).length?{headers:t}:{}});return await this.clearLogin(),e.ok?{}:{error:{message:await e.text()||e.statusText,status:e.status}}}catch(t){return{error:{message:t instanceof Error?t.message:String(t),status:0}}}}async signUp(t){let e=await this.postJson("sign-up/email",t);return e.data&&await this.persistLogin(e.data,e.response),e}async getToken(t){try{let e={};if(t)e.Authorization=`Bearer ${t}`;else if(this.storage){let a=await this.storage.get(w)??await this.storage.get(c);a!=null&&(e.Authorization=`Bearer ${a}`)}let s=await this.fetchImpl(this.url("token"),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):void 0;return{data:n?.token!=null?{token:n.token}:void 0}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async signInWithUsername(t,e){let s=await this.postJson("sign-in/username",{username:t,password:e});return s.data&&await this.persistLogin(s.data,s.response),s}async signInWithPhoneNumber(t,e,s){let i=await this.postJson("sign-in/phone-number",{phoneNumber:t,password:e,rememberMe:s});return i.data&&await this.persistLogin(i.data,i.response),i}async sendPhoneNumberOtp(t){let e=await this.postJson("phone-number/send-otp",{phoneNumber:t});return e.error?{error:e.error}:{}}async verifyPhoneNumber(t,e){let s=await this.postJson("phone-number/verify",{phoneNumber:t,code:e});return s.data&&await this.persistLogin(s.data,s.response),s}async loginWithWeChatCode(t,e){try{let s={"Content-Type":"application/json"};if(this.storage){let o=await this.storage.get(c);o!=null&&(s.Authorization=`Bearer ${o}`)}let i=await this.fetchImpl(this.url("wechat/openplatform/sign-in"),{method:"POST",headers:s,credentials:this.credentials,body:JSON.stringify({code:t,applicationCode:e})}),n=await i.text();if(!i.ok)return{error:{message:n||i.statusText,status:i.status}};let a=n?JSON.parse(n):null;return!a?.token||!a.user?{error:{message:"invalid_wechat_login_response",status:502}}:(this.storage&&(await this.storage.set(c,a.token),await this.storage.set(w,a.token),await this.storage.set(O,a.user)),{data:a})}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async loginWithAlipayCode(t,e){try{let s={"Content-Type":"application/json"};if(this.storage){let o=await this.storage.get(c);o!=null&&(s.Authorization=`Bearer ${o}`)}let i=await this.fetchImpl(this.url("alipay/openplatform/sign-in"),{method:"POST",headers:s,credentials:this.credentials,body:JSON.stringify({code:t,applicationCode:e})}),n=await i.text();if(!i.ok)return{error:{message:n||i.statusText,status:i.status}};let a=n?JSON.parse(n):null;return!a?.token||!a.user?{error:{message:"invalid_alipay_login_response",status:502}}:(this.storage&&(await this.storage.set(c,a.token),await this.storage.set(w,a.token),await this.storage.set(O,a.user)),{data:a})}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}async getWeChatOpenPlatformIdentity(t){try{let e={};if(this.storage){let o=await this.storage.get(c);o!=null&&(e.Authorization=`Bearer ${o}`)}let s=t?.trim()?`?applicationCode=${encodeURIComponent(t.trim())}`:"",i=await this.fetchImpl(this.url(`wechat/openplatform/identity${s}`),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),n=await i.text();if(!i.ok)return{error:{message:n||i.statusText,status:i.status}};let a=n?JSON.parse(n):null;return!a?.openid||!a.appId?{error:{message:"invalid_wechat_identity_response",status:502}}:{data:a}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async getAlipayOpenPlatformIdentity(t){try{let e={};if(this.storage){let o=await this.storage.get(c);o!=null&&(e.Authorization=`Bearer ${o}`)}let s=t?.trim()?`?applicationCode=${encodeURIComponent(t.trim())}`:"",i=await this.fetchImpl(this.url(`alipay/openplatform/identity${s}`),{method:"GET",credentials:this.credentials,...Object.keys(e).length?{headers:e}:{}}),n=await i.text();if(!i.ok)return{error:{message:n||i.statusText,status:i.status}};let a=n?JSON.parse(n):null;return!a?.openid||!a.appId?{error:{message:"invalid_alipay_identity_response",status:502}}:{data:a}}catch(e){return{error:{message:e instanceof Error?e.message:String(e),status:0}}}}async postJson(t,e){try{let s=await this.fetchImpl(this.url(t),{method:"POST",headers:{"Content-Type":"application/json"},credentials:this.credentials,body:JSON.stringify(e)}),i=await s.text();if(!s.ok)return{error:{message:i||s.statusText,status:s.status}};let n=i?JSON.parse(i):void 0;return{data:n?.data??n??void 0,response:s}}catch(s){return{error:{message:s instanceof Error?s.message:String(s),status:0}}}}};var H=class{constructor(t,e,s){this.storage=t,this.customFetch=e,this.handleUnauthorized=s}async fetch(t,e){return await this.customFetch(t,e)}async fetchWithAuth(t,e){let s=await this.storage.get(c),i=new f(e?.headers);s&&i.set("Authorization",`Bearer ${s}`);let n=e?.method||"GET";if((n==="POST"||n==="PUT"||n==="PATCH")&&e?.body){let o=i.get("Content-Type");(!o||o.includes("text/plain"))&&i.set("Content-Type","application/json")}let a=await this.customFetch(t,{...e,headers:i});if(a.status===401)throw this.handleUnauthorized(),new Error("\u672A\u767B\u5F55");return a}};var V="/storage",X=V+"/generateUploadUrl",W=class{constructor(t,e){this.baseUrl=t,this.http=e}async uploadFile(t){let e=await this.http.fetch(this.baseUrl+X,{method:"POST",body:{fileName:t.name||t.fileName,fileSize:t.size||t.fileSize,fileType:t.type||t.fileType}}),{url:s}=await e.json();if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");let i=await this.http.fetch(s,{method:"PUT",body:t,headers:new f({"Content-Type":t.type||t.fileType||"application/octet-stream"})}),{url:n}=await i.json();return{url:n.split("?")[0]}}};var Q=class extends Error{constructor(r){super(r.message),this.name="PostgrestError",this.details=r.details,this.hint=r.hint,this.code=r.code}},Z=class{constructor(r){var t,e,s;this.shouldThrowOnError=!1,this.method=r.method,this.url=r.url,this.headers=new f(r.headers),this.schema=r.schema,this.body=r.body,this.shouldThrowOnError=(t=r.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=r.signal,this.isMaybeSingle=(e=r.isMaybeSingle)!==null&&e!==void 0?e:!1,this.urlLengthLimit=(s=r.urlLengthLimit)!==null&&s!==void 0?s:8e3,r.fetch?this.fetch=r.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(r,t){return this.headers=new f(this.headers),this.headers.set(r,t),this}then(r,t){var e=this;this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,i=s(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async n=>{let a=null,o=null,h=null,u=n.status,l=n.statusText;if(n.ok){var p,d;if(e.method!=="HEAD"){var g;let y=await n.text();y===""||(e.headers.get("Accept")==="text/csv"||e.headers.get("Accept")&&(!((g=e.headers.get("Accept"))===null||g===void 0)&&g.includes("application/vnd.pgrst.plan+text"))?o=y:o=JSON.parse(y))}let m=(p=e.headers.get("Prefer"))===null||p===void 0?void 0:p.match(/count=(exact|planned|estimated)/),b=(d=n.headers.get("content-range"))===null||d===void 0?void 0:d.split("/");m&&b&&b.length>1&&(h=parseInt(b[1])),e.isMaybeSingle&&Array.isArray(o)&&(o.length>1?(a={code:"PGRST116",details:`Results contain ${o.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},o=null,h=null,u=406,l="Not Acceptable"):o.length===1?o=o[0]:o=null)}else{let m=await n.text();try{a=JSON.parse(m),Array.isArray(a)&&n.status===404&&(o=[],a=null,u=200,l="OK")}catch{n.status===404&&m===""?(u=204,l="No Content"):a={message:m}}if(a&&e.shouldThrowOnError)throw new Q(a)}return{error:a,data:o,count:h,status:u,statusText:l}});return this.shouldThrowOnError||(i=i.catch(n=>{var a;let o="",h="",u="",l=n?.cause;if(l){var p,d,g,m;let B=(p=l?.message)!==null&&p!==void 0?p:"",_=(d=l?.code)!==null&&d!==void 0?d:"";o=`${(g=n?.name)!==null&&g!==void 0?g:"FetchError"}: ${n?.message}`,o+=`
|
|
2
2
|
|
|
3
|
-
Caused by: ${(
|
|
4
|
-
${l.stack}`)}else{var b;o=(b=i?.stack)!==null&&b!==void 0?b:""}let w=this.url.toString().length;return i?.name==="AbortError"||i?.code==="ABORT_ERR"?(u="",h="Request was aborted (timeout or manual cancellation)",w>this.urlLengthLimit&&(h+=`. Note: Your request URL is ${w} characters, which may exceed server limits. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [many IDs])), consider using an RPC function to pass values server-side.`)):(l?.name==="HeadersOverflowError"||l?.code==="UND_ERR_HEADERS_OVERFLOW")&&(u="",h="HTTP headers exceeded server limits (typically 16KB)",w>this.urlLengthLimit&&(h+=`. Your request URL is ${w} characters. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [200+ IDs])), consider using an RPC function instead.`)),{error:{message:`${(a=i?.name)!==null&&a!==void 0?a:"FetchError"}: ${i?.message}`,details:o,hint:h,code:u},data:null,count:null,status:0,statusText:""}})),n.then(r,t)}returns(){return this}overrideTypes(){return this}},D=class extends M{select(r){let t=!1,e=(r??"*").split("").map(s=>/\s/.test(s)&&!t?"":(s==='"'&&(t=!t),s)).join("");return this.url.searchParams.set("select",e),this.headers.append("Prefer","return=representation"),this}order(r,{ascending:t=!0,nullsFirst:e,foreignTable:s,referencedTable:n=s}={}){let i=n?`${n}.order`:"order",a=this.url.searchParams.get(i);return this.url.searchParams.set(i,`${a?`${a},`:""}${r}.${t?"asc":"desc"}${e===void 0?"":e?".nullsfirst":".nullslast"}`),this}limit(r,{foreignTable:t,referencedTable:e=t}={}){let s=typeof e>"u"?"limit":`${e}.limit`;return this.url.searchParams.set(s,`${r}`),this}range(r,t,{foreignTable:e,referencedTable:s=e}={}){let n=typeof s>"u"?"offset":`${s}.offset`,i=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(n,`${r}`),this.url.searchParams.set(i,`${t-r+1}`),this}abortSignal(r){return this.signal=r,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:r=!1,verbose:t=!1,settings:e=!1,buffers:s=!1,wal:n=!1,format:i="text"}={}){var a;let o=[r?"analyze":null,t?"verbose":null,e?"settings":null,s?"buffers":null,n?"wal":null].filter(Boolean).join("|"),h=(a=this.headers.get("Accept"))!==null&&a!==void 0?a:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${i}; for="${h}"; options=${o};`),i==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(r){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${r}`),this}},U=new RegExp("[,()]"),L=class extends D{eq(r,t){return this.url.searchParams.append(r,`eq.${t}`),this}neq(r,t){return this.url.searchParams.append(r,`neq.${t}`),this}gt(r,t){return this.url.searchParams.append(r,`gt.${t}`),this}gte(r,t){return this.url.searchParams.append(r,`gte.${t}`),this}lt(r,t){return this.url.searchParams.append(r,`lt.${t}`),this}lte(r,t){return this.url.searchParams.append(r,`lte.${t}`),this}like(r,t){return this.url.searchParams.append(r,`like.${t}`),this}likeAllOf(r,t){return this.url.searchParams.append(r,`like(all).{${t.join(",")}}`),this}likeAnyOf(r,t){return this.url.searchParams.append(r,`like(any).{${t.join(",")}}`),this}ilike(r,t){return this.url.searchParams.append(r,`ilike.${t}`),this}ilikeAllOf(r,t){return this.url.searchParams.append(r,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(r,t){return this.url.searchParams.append(r,`ilike(any).{${t.join(",")}}`),this}regexMatch(r,t){return this.url.searchParams.append(r,`match.${t}`),this}regexIMatch(r,t){return this.url.searchParams.append(r,`imatch.${t}`),this}is(r,t){return this.url.searchParams.append(r,`is.${t}`),this}isDistinct(r,t){return this.url.searchParams.append(r,`isdistinct.${t}`),this}in(r,t){let e=Array.from(new Set(t)).map(s=>typeof s=="string"&&U.test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(r,`in.(${e})`),this}notIn(r,t){let e=Array.from(new Set(t)).map(s=>typeof s=="string"&&U.test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(r,`not.in.(${e})`),this}contains(r,t){return typeof t=="string"?this.url.searchParams.append(r,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(r,`cs.{${t.join(",")}}`):this.url.searchParams.append(r,`cs.${JSON.stringify(t)}`),this}containedBy(r,t){return typeof t=="string"?this.url.searchParams.append(r,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(r,`cd.{${t.join(",")}}`):this.url.searchParams.append(r,`cd.${JSON.stringify(t)}`),this}rangeGt(r,t){return this.url.searchParams.append(r,`sr.${t}`),this}rangeGte(r,t){return this.url.searchParams.append(r,`nxl.${t}`),this}rangeLt(r,t){return this.url.searchParams.append(r,`sl.${t}`),this}rangeLte(r,t){return this.url.searchParams.append(r,`nxr.${t}`),this}rangeAdjacent(r,t){return this.url.searchParams.append(r,`adj.${t}`),this}overlaps(r,t){return typeof t=="string"?this.url.searchParams.append(r,`ov.${t}`):this.url.searchParams.append(r,`ov.{${t.join(",")}}`),this}textSearch(r,t,{config:e,type:s}={}){let n="";s==="plain"?n="pl":s==="phrase"?n="ph":s==="websearch"&&(n="w");let i=e===void 0?"":`(${e})`;return this.url.searchParams.append(r,`${n}fts${i}.${t}`),this}match(r){return Object.entries(r).filter(([t,e])=>e!==void 0).forEach(([t,e])=>{this.url.searchParams.append(t,`eq.${e}`)}),this}not(r,t,e){return this.url.searchParams.append(r,`not.${t}.${e}`),this}or(r,{foreignTable:t,referencedTable:e=t}={}){let s=e?`${e}.or`:"or";return this.url.searchParams.append(s,`(${r})`),this}filter(r,t,e){return this.url.searchParams.append(r,`${t}.${e}`),this}},Y=class{constructor(r,{headers:t={},schema:e,fetch:s,urlLengthLimit:n=8e3}){this.url=r,this.headers=new O(t),this.schema=e,this.fetch=s,this.urlLengthLimit=n}cloneRequestState(){return{url:new S(this.url.toString()),headers:new O(this.headers)}}select(r,t){let{head:e=!1,count:s}=t??{},n=e?"HEAD":"GET",i=!1,a=(r??"*").split("").map(u=>/\s/.test(u)&&!i?"":(u==='"'&&(i=!i),u)).join(""),{url:o,headers:h}=this.cloneRequestState();return o.searchParams.set("select",a),s&&h.append("Prefer",`count=${s}`),new L({method:n,url:o,headers:h,schema:this.schema,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}insert(r,{count:t,defaultToNull:e=!0}={}){var s;let n="POST",{url:i,headers:a}=this.cloneRequestState();if(t&&a.append("Prefer",`count=${t}`),e||a.append("Prefer","missing=default"),Array.isArray(r)){let o=r.reduce((h,u)=>h.concat(Object.keys(u)),[]);if(o.length>0){let h=[...new Set(o)].map(u=>`"${u}"`);i.searchParams.set("columns",h.join(","))}}return new L({method:n,url:i,headers:a,schema:this.schema,body:r,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch,urlLengthLimit:this.urlLengthLimit})}upsert(r,{onConflict:t,ignoreDuplicates:e=!1,count:s,defaultToNull:n=!0}={}){var i;let a="POST",{url:o,headers:h}=this.cloneRequestState();if(h.append("Prefer",`resolution=${e?"ignore":"merge"}-duplicates`),t!==void 0&&o.searchParams.set("on_conflict",t),s&&h.append("Prefer",`count=${s}`),n||h.append("Prefer","missing=default"),Array.isArray(r)){let u=r.reduce((l,p)=>l.concat(Object.keys(p)),[]);if(u.length>0){let l=[...new Set(u)].map(p=>`"${p}"`);o.searchParams.set("columns",l.join(","))}}return new L({method:a,url:o,headers:h,schema:this.schema,body:r,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch,urlLengthLimit:this.urlLengthLimit})}update(r,{count:t}={}){var e;let s="PATCH",{url:n,headers:i}=this.cloneRequestState();return t&&i.append("Prefer",`count=${t}`),new L({method:s,url:n,headers:i,schema:this.schema,body:r,fetch:(e=this.fetch)!==null&&e!==void 0?e:fetch,urlLengthLimit:this.urlLengthLimit})}delete({count:r}={}){var t;let e="DELETE",{url:s,headers:n}=this.cloneRequestState();return r&&n.append("Prefer",`count=${r}`),new L({method:e,url:s,headers:n,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch,urlLengthLimit:this.urlLengthLimit})}};function E(r){"@babel/helpers - typeof";return E=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},E(r)}function K(r,t){if(E(r)!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var s=e.call(r,t||"default");if(E(s)!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function V(r){var t=K(r,"string");return E(t)=="symbol"?t:t+""}function X(r,t,e){return(t=V(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function N(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(r);t&&(s=s.filter(function(n){return Object.getOwnPropertyDescriptor(r,n).enumerable})),e.push.apply(e,s)}return e}function x(r){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?N(Object(e),!0).forEach(function(s){X(r,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):N(Object(e)).forEach(function(s){Object.defineProperty(r,s,Object.getOwnPropertyDescriptor(e,s))})}return r}var $=class I{constructor(t,{headers:e={},schema:s,fetch:n,timeout:i,urlLengthLimit:a=8e3}={}){this.url=t,this.headers=new O(e),this.schemaName=s,this.urlLengthLimit=a;let o=n??globalThis.fetch;i!==void 0&&i>0?this.fetch=(h,u)=>{let l=new J,p=setTimeout(()=>l.abort(),i),m=u?.signal;if(m){if(m.aborted)return clearTimeout(p),o(h,u);let d=()=>{clearTimeout(p),l.abort()};return m.addEventListener("abort",d,{once:!0}),o(h,x(x({},u),{},{signal:l.signal})).finally(()=>{clearTimeout(p),m.removeEventListener("abort",d)})}return o(h,x(x({},u),{},{signal:l.signal})).finally(()=>clearTimeout(p))}:this.fetch=o}from(t){if(!t||typeof t!="string"||t.trim()==="")throw new Error("Invalid relation name: relation must be a non-empty string.");return new Y(new S(`${this.url}/${t}`),{headers:new O(this.headers),schema:this.schemaName,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}schema(t){return new I(this.url,{headers:this.headers,schema:t,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}rpc(t,e={},{head:s=!1,get:n=!1,count:i}={}){var a;let o,h=new S(`${this.url}/rpc/${t}`),u,l=d=>d!==null&&typeof d=="object"&&(!Array.isArray(d)||d.some(l)),p=s&&Object.values(e).some(l);p?(o="POST",u=e):s||n?(o=s?"HEAD":"GET",Object.entries(e).filter(([d,g])=>g!==void 0).map(([d,g])=>[d,Array.isArray(g)?`{${g.join(",")}}`:`${g}`]).forEach(([d,g])=>{h.searchParams.append(d,g)})):(o="POST",u=e);let m=new O(this.headers);return p?m.set("Prefer",i?`count=${i},return=minimal`:"return=minimal"):i&&m.set("Prefer",`count=${i}`),new L({method:o,url:h,headers:m,schema:this.schemaName,body:u,fetch:(a=this.fetch)!==null&&a!==void 0?a:fetch,urlLengthLimit:this.urlLengthLimit})}};var Q="/entities",Tt=(r,t)=>new $(r+Q,{fetch:t.fetchWithAuth.bind(t)});var j=class{constructor(){this.hoverOverlay=null;this.selectedOverlay=null;this.tooltip=null;this.hoverElement=null;this.selectedElement=null;this.hoverUpdateHandler=null;this.selectedUpdateHandler=null;this.createStyles()}createStyles(){if(document.getElementById("__nvwa-inspector-overlay-style"))return;let t=document.createElement("style");t.id="__nvwa-inspector-overlay-style",t.textContent=`
|
|
3
|
+
Caused by: ${(m=l?.name)!==null&&m!==void 0?m:"Error"}: ${B}`,_&&(o+=` (${_})`),l?.stack&&(o+=`
|
|
4
|
+
${l.stack}`)}else{var b;o=(b=n?.stack)!==null&&b!==void 0?b:""}let y=this.url.toString().length;return n?.name==="AbortError"||n?.code==="ABORT_ERR"?(u="",h="Request was aborted (timeout or manual cancellation)",y>this.urlLengthLimit&&(h+=`. Note: Your request URL is ${y} characters, which may exceed server limits. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [many IDs])), consider using an RPC function to pass values server-side.`)):(l?.name==="HeadersOverflowError"||l?.code==="UND_ERR_HEADERS_OVERFLOW")&&(u="",h="HTTP headers exceeded server limits (typically 16KB)",y>this.urlLengthLimit&&(h+=`. Your request URL is ${y} characters. If selecting many fields, consider using views. If filtering with large arrays (e.g., .in('id', [200+ IDs])), consider using an RPC function instead.`)),{error:{message:`${(a=n?.name)!==null&&a!==void 0?a:"FetchError"}: ${n?.message}`,details:o,hint:h,code:u},data:null,count:null,status:0,statusText:""}})),i.then(r,t)}returns(){return this}overrideTypes(){return this}},tt=class extends Z{select(r){let t=!1,e=(r??"*").split("").map(s=>/\s/.test(s)&&!t?"":(s==='"'&&(t=!t),s)).join("");return this.url.searchParams.set("select",e),this.headers.append("Prefer","return=representation"),this}order(r,{ascending:t=!0,nullsFirst:e,foreignTable:s,referencedTable:i=s}={}){let n=i?`${i}.order`:"order",a=this.url.searchParams.get(n);return this.url.searchParams.set(n,`${a?`${a},`:""}${r}.${t?"asc":"desc"}${e===void 0?"":e?".nullsfirst":".nullslast"}`),this}limit(r,{foreignTable:t,referencedTable:e=t}={}){let s=typeof e>"u"?"limit":`${e}.limit`;return this.url.searchParams.set(s,`${r}`),this}range(r,t,{foreignTable:e,referencedTable:s=e}={}){let i=typeof s>"u"?"offset":`${s}.offset`,n=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(i,`${r}`),this.url.searchParams.set(n,`${t-r+1}`),this}abortSignal(r){return this.signal=r,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:r=!1,verbose:t=!1,settings:e=!1,buffers:s=!1,wal:i=!1,format:n="text"}={}){var a;let o=[r?"analyze":null,t?"verbose":null,e?"settings":null,s?"buffers":null,i?"wal":null].filter(Boolean).join("|"),h=(a=this.headers.get("Accept"))!==null&&a!==void 0?a:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${n}; for="${h}"; options=${o};`),n==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(r){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${r}`),this}},G=new RegExp("[,()]"),S=class extends tt{eq(r,t){return this.url.searchParams.append(r,`eq.${t}`),this}neq(r,t){return this.url.searchParams.append(r,`neq.${t}`),this}gt(r,t){return this.url.searchParams.append(r,`gt.${t}`),this}gte(r,t){return this.url.searchParams.append(r,`gte.${t}`),this}lt(r,t){return this.url.searchParams.append(r,`lt.${t}`),this}lte(r,t){return this.url.searchParams.append(r,`lte.${t}`),this}like(r,t){return this.url.searchParams.append(r,`like.${t}`),this}likeAllOf(r,t){return this.url.searchParams.append(r,`like(all).{${t.join(",")}}`),this}likeAnyOf(r,t){return this.url.searchParams.append(r,`like(any).{${t.join(",")}}`),this}ilike(r,t){return this.url.searchParams.append(r,`ilike.${t}`),this}ilikeAllOf(r,t){return this.url.searchParams.append(r,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(r,t){return this.url.searchParams.append(r,`ilike(any).{${t.join(",")}}`),this}regexMatch(r,t){return this.url.searchParams.append(r,`match.${t}`),this}regexIMatch(r,t){return this.url.searchParams.append(r,`imatch.${t}`),this}is(r,t){return this.url.searchParams.append(r,`is.${t}`),this}isDistinct(r,t){return this.url.searchParams.append(r,`isdistinct.${t}`),this}in(r,t){let e=Array.from(new Set(t)).map(s=>typeof s=="string"&&G.test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(r,`in.(${e})`),this}notIn(r,t){let e=Array.from(new Set(t)).map(s=>typeof s=="string"&&G.test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(r,`not.in.(${e})`),this}contains(r,t){return typeof t=="string"?this.url.searchParams.append(r,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(r,`cs.{${t.join(",")}}`):this.url.searchParams.append(r,`cs.${JSON.stringify(t)}`),this}containedBy(r,t){return typeof t=="string"?this.url.searchParams.append(r,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(r,`cd.{${t.join(",")}}`):this.url.searchParams.append(r,`cd.${JSON.stringify(t)}`),this}rangeGt(r,t){return this.url.searchParams.append(r,`sr.${t}`),this}rangeGte(r,t){return this.url.searchParams.append(r,`nxl.${t}`),this}rangeLt(r,t){return this.url.searchParams.append(r,`sl.${t}`),this}rangeLte(r,t){return this.url.searchParams.append(r,`nxr.${t}`),this}rangeAdjacent(r,t){return this.url.searchParams.append(r,`adj.${t}`),this}overlaps(r,t){return typeof t=="string"?this.url.searchParams.append(r,`ov.${t}`):this.url.searchParams.append(r,`ov.{${t.join(",")}}`),this}textSearch(r,t,{config:e,type:s}={}){let i="";s==="plain"?i="pl":s==="phrase"?i="ph":s==="websearch"&&(i="w");let n=e===void 0?"":`(${e})`;return this.url.searchParams.append(r,`${i}fts${n}.${t}`),this}match(r){return Object.entries(r).filter(([t,e])=>e!==void 0).forEach(([t,e])=>{this.url.searchParams.append(t,`eq.${e}`)}),this}not(r,t,e){return this.url.searchParams.append(r,`not.${t}.${e}`),this}or(r,{foreignTable:t,referencedTable:e=t}={}){let s=e?`${e}.or`:"or";return this.url.searchParams.append(s,`(${r})`),this}filter(r,t,e){return this.url.searchParams.append(r,`${t}.${e}`),this}},et=class{constructor(r,{headers:t={},schema:e,fetch:s,urlLengthLimit:i=8e3}){this.url=r,this.headers=new f(t),this.schema=e,this.fetch=s,this.urlLengthLimit=i}cloneRequestState(){return{url:new L(this.url.toString()),headers:new f(this.headers)}}select(r,t){let{head:e=!1,count:s}=t??{},i=e?"HEAD":"GET",n=!1,a=(r??"*").split("").map(u=>/\s/.test(u)&&!n?"":(u==='"'&&(n=!n),u)).join(""),{url:o,headers:h}=this.cloneRequestState();return o.searchParams.set("select",a),s&&h.append("Prefer",`count=${s}`),new S({method:i,url:o,headers:h,schema:this.schema,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}insert(r,{count:t,defaultToNull:e=!0}={}){var s;let i="POST",{url:n,headers:a}=this.cloneRequestState();if(t&&a.append("Prefer",`count=${t}`),e||a.append("Prefer","missing=default"),Array.isArray(r)){let o=r.reduce((h,u)=>h.concat(Object.keys(u)),[]);if(o.length>0){let h=[...new Set(o)].map(u=>`"${u}"`);n.searchParams.set("columns",h.join(","))}}return new S({method:i,url:n,headers:a,schema:this.schema,body:r,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch,urlLengthLimit:this.urlLengthLimit})}upsert(r,{onConflict:t,ignoreDuplicates:e=!1,count:s,defaultToNull:i=!0}={}){var n;let a="POST",{url:o,headers:h}=this.cloneRequestState();if(h.append("Prefer",`resolution=${e?"ignore":"merge"}-duplicates`),t!==void 0&&o.searchParams.set("on_conflict",t),s&&h.append("Prefer",`count=${s}`),i||h.append("Prefer","missing=default"),Array.isArray(r)){let u=r.reduce((l,p)=>l.concat(Object.keys(p)),[]);if(u.length>0){let l=[...new Set(u)].map(p=>`"${p}"`);o.searchParams.set("columns",l.join(","))}}return new S({method:a,url:o,headers:h,schema:this.schema,body:r,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch,urlLengthLimit:this.urlLengthLimit})}update(r,{count:t}={}){var e;let s="PATCH",{url:i,headers:n}=this.cloneRequestState();return t&&n.append("Prefer",`count=${t}`),new S({method:s,url:i,headers:n,schema:this.schema,body:r,fetch:(e=this.fetch)!==null&&e!==void 0?e:fetch,urlLengthLimit:this.urlLengthLimit})}delete({count:r}={}){var t;let e="DELETE",{url:s,headers:i}=this.cloneRequestState();return r&&i.append("Prefer",`count=${r}`),new S({method:e,url:s,headers:i,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch,urlLengthLimit:this.urlLengthLimit})}};function E(r){"@babel/helpers - typeof";return E=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},E(r)}function st(r,t){if(E(r)!="object"||!r)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var s=e.call(r,t||"default");if(E(s)!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function rt(r){var t=st(r,"string");return E(t)=="symbol"?t:t+""}function it(r,t,e){return(t=rt(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function q(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(r);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),e.push.apply(e,s)}return e}function R(r){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?q(Object(e),!0).forEach(function(s){it(r,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):q(Object(e)).forEach(function(s){Object.defineProperty(r,s,Object.getOwnPropertyDescriptor(e,s))})}return r}var F=class M{constructor(t,{headers:e={},schema:s,fetch:i,timeout:n,urlLengthLimit:a=8e3}={}){this.url=t,this.headers=new f(e),this.schemaName=s,this.urlLengthLimit=a;let o=i??globalThis.fetch;n!==void 0&&n>0?this.fetch=(h,u)=>{let l=new I,p=setTimeout(()=>l.abort(),n),d=u?.signal;if(d){if(d.aborted)return clearTimeout(p),o(h,u);let g=()=>{clearTimeout(p),l.abort()};return d.addEventListener("abort",g,{once:!0}),o(h,R(R({},u),{},{signal:l.signal})).finally(()=>{clearTimeout(p),d.removeEventListener("abort",g)})}return o(h,R(R({},u),{},{signal:l.signal})).finally(()=>clearTimeout(p))}:this.fetch=o}from(t){if(!t||typeof t!="string"||t.trim()==="")throw new Error("Invalid relation name: relation must be a non-empty string.");return new et(new L(`${this.url}/${t}`),{headers:new f(this.headers),schema:this.schemaName,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}schema(t){return new M(this.url,{headers:this.headers,schema:t,fetch:this.fetch,urlLengthLimit:this.urlLengthLimit})}rpc(t,e={},{head:s=!1,get:i=!1,count:n}={}){var a;let o,h=new L(`${this.url}/rpc/${t}`),u,l=g=>g!==null&&typeof g=="object"&&(!Array.isArray(g)||g.some(l)),p=s&&Object.values(e).some(l);p?(o="POST",u=e):s||i?(o=s?"HEAD":"GET",Object.entries(e).filter(([g,m])=>m!==void 0).map(([g,m])=>[g,Array.isArray(m)?`{${m.join(",")}}`:`${m}`]).forEach(([g,m])=>{h.searchParams.append(g,m)})):(o="POST",u=e);let d=new f(this.headers);return p?d.set("Prefer",n?`count=${n},return=minimal`:"return=minimal"):n&&d.set("Prefer",`count=${n}`),new S({method:o,url:h,headers:d,schema:this.schemaName,body:u,fetch:(a=this.fetch)!==null&&a!==void 0?a:fetch,urlLengthLimit:this.urlLengthLimit})}};var nt="/entities",qt=(r,t)=>new F(r+nt,{fetch:t.fetchWithAuth.bind(t)});var J=class{constructor(){this.hoverOverlay=null;this.selectedOverlay=null;this.tooltip=null;this.hoverElement=null;this.selectedElement=null;this.hoverUpdateHandler=null;this.selectedUpdateHandler=null;this.createStyles()}createStyles(){if(document.getElementById("__nvwa-inspector-overlay-style"))return;let t=document.createElement("style");t.id="__nvwa-inspector-overlay-style",t.textContent=`
|
|
5
5
|
.__nvwa-inspector-overlay {
|
|
6
6
|
position: absolute;
|
|
7
7
|
pointer-events: none;
|
|
@@ -33,4 +33,4 @@ ${l.stack}`)}else{var b;o=(b=i?.stack)!==null&&b!==void 0?b:""}let w=this.url.to
|
|
|
33
33
|
max-width: 400px;
|
|
34
34
|
word-break: break-all;
|
|
35
35
|
}
|
|
36
|
-
`,document.head.appendChild(t)}createTooltip(){return this.tooltip?this.tooltip:(this.tooltip=document.createElement("div"),this.tooltip.id="__nvwa-inspector-tooltip",document.body.appendChild(this.tooltip),this.tooltip)}createOverlay(t){let e=document.createElement("div");return e.className=`__nvwa-inspector-overlay __nvwa-inspector-overlay-${t}`,document.body.appendChild(e),e}updateOverlayPosition(t,e){if(!e.isConnected)return;let s=e.getBoundingClientRect(),
|
|
36
|
+
`,document.head.appendChild(t)}createTooltip(){return this.tooltip?this.tooltip:(this.tooltip=document.createElement("div"),this.tooltip.id="__nvwa-inspector-tooltip",document.body.appendChild(this.tooltip),this.tooltip)}createOverlay(t){let e=document.createElement("div");return e.className=`__nvwa-inspector-overlay __nvwa-inspector-overlay-${t}`,document.body.appendChild(e),e}updateOverlayPosition(t,e){if(!e.isConnected)return;let s=e.getBoundingClientRect(),i=window.scrollX||window.pageXOffset,n=window.scrollY||window.pageYOffset;s.width>0&&s.height>0?(t.style.left=`${s.left+i}px`,t.style.top=`${s.top+n}px`,t.style.width=`${s.width}px`,t.style.height=`${s.height}px`,t.style.display="block"):t.style.display="none"}removeOverlay(t){t&&t.parentNode&&t.parentNode.removeChild(t)}highlightElement(t,e){if(!t.isConnected)return;if(this.hoverElement===t&&this.hoverOverlay){this.updateOverlayPosition(this.hoverOverlay,t);let o=this.createTooltip();e?o.textContent=e:o.textContent=`<${t.tagName.toLowerCase()}> (\u65E0 source location)`,o.style.display="block";let h=t.getBoundingClientRect();o.style.left=`${h.left+window.scrollX}px`,o.style.top=`${h.top+window.scrollY-o.offsetHeight-8}px`,h.top<o.offsetHeight+8&&(o.style.top=`${h.bottom+window.scrollY+8}px`);return}this.hoverOverlay&&(this.removeOverlay(this.hoverOverlay),this.hoverOverlay=null);let s=this.createOverlay("hover");this.updateOverlayPosition(s,t),this.hoverOverlay=s,this.hoverElement=t;let i=()=>{this.hoverOverlay&&this.hoverElement&&this.hoverElement.isConnected&&this.updateOverlayPosition(this.hoverOverlay,this.hoverElement)};this.hoverUpdateHandler&&(window.removeEventListener("scroll",this.hoverUpdateHandler,!0),window.removeEventListener("resize",this.hoverUpdateHandler)),this.hoverUpdateHandler=i,window.addEventListener("scroll",i,!0),window.addEventListener("resize",i);let n=this.createTooltip();e?n.textContent=e:n.textContent=`<${t.tagName.toLowerCase()}> (\u65E0 source location)`,n.style.display="block";let a=t.getBoundingClientRect();n.style.left=`${a.left+window.scrollX}px`,n.style.top=`${a.top+window.scrollY-n.offsetHeight-8}px`,a.top<n.offsetHeight+8&&(n.style.top=`${a.bottom+window.scrollY+8}px`)}selectElement(t,e){if(!t.isConnected)return;if(this.selectedElement===t&&this.selectedOverlay){this.updateOverlayPosition(this.selectedOverlay,t);return}this.selectedOverlay&&(this.removeOverlay(this.selectedOverlay),this.selectedOverlay=null);let s=this.createOverlay("selected");this.updateOverlayPosition(s,t),this.selectedOverlay=s,this.selectedElement=t;let i=()=>{this.selectedOverlay&&this.selectedElement&&this.selectedElement.isConnected&&this.updateOverlayPosition(this.selectedOverlay,this.selectedElement)};this.selectedUpdateHandler&&(window.removeEventListener("scroll",this.selectedUpdateHandler,!0),window.removeEventListener("resize",this.selectedUpdateHandler)),this.selectedUpdateHandler=i,window.addEventListener("scroll",i,!0),window.addEventListener("resize",i)}removeHighlight(){this.hoverOverlay&&(this.removeOverlay(this.hoverOverlay),this.hoverOverlay=null),this.hoverElement&&(this.hoverElement=null),this.tooltip&&(this.tooltip.style.display="none"),this.hoverUpdateHandler&&(window.removeEventListener("scroll",this.hoverUpdateHandler,!0),window.removeEventListener("resize",this.hoverUpdateHandler),this.hoverUpdateHandler=null)}clearSelection(){this.selectedOverlay&&(this.removeOverlay(this.selectedOverlay),this.selectedOverlay=null),this.selectedElement&&(this.selectedElement=null),this.selectedUpdateHandler&&(window.removeEventListener("scroll",this.selectedUpdateHandler,!0),window.removeEventListener("resize",this.selectedUpdateHandler),this.selectedUpdateHandler=null)}cleanup(){this.removeHighlight(),this.clearSelection(),this.tooltip&&this.tooltip.parentNode&&(this.tooltip.parentNode.removeChild(this.tooltip),this.tooltip=null);let t=document.getElementById("__nvwa-inspector-overlay-style");t&&t.parentNode&&t.parentNode.removeChild(t)}};function Jt(r="root"){if(typeof document>"u")return null;let t=document.getElementById(r)||document.body;if(!t)return null;let e=t.querySelector("[data-source-location]");if(e){let s=e.getAttribute("data-source-location");if(s)return s}if(t.firstElementChild){let i=t.firstElementChild.getAttribute("data-source-location");if(i)return i}return null}function Dt(r){let t=r;if(typeof t.kind=="string")return t;if(typeof t.tradeNO=="string")return{kind:"alipay_miniprogram",tradeNO:t.tradeNO};if(typeof t.clientSecret=="string")return{kind:"stripe_client_secret",clientSecret:t.clientSecret};if(typeof t.redirectUrl=="string")return{kind:"redirect_url",redirectUrl:t.redirectUrl};if(typeof t.formHtml=="string")return{kind:"alipay_page",formHtml:t.formHtml};if(typeof t.codeUrl=="string")return{kind:"wechat_native_qr",codeUrl:t.codeUrl};let e=t.jsapiPayParams??t;return typeof e.timeStamp=="string"&&typeof e.nonceStr=="string"&&typeof e.package=="string"&&typeof e.paySign=="string"&&typeof e.appId=="string"?{kind:"wechat_jsapi",mode:"jsapi",jsapiPayParams:{appId:e.appId,timeStamp:e.timeStamp,nonceStr:e.nonceStr,package:e.package,signType:e.signType??"RSA",paySign:e.paySign}}:null}function Yt(r,t,e){return t.requestPayment(r.payParams,e)}export{T as AuthClient,c as CURRENT_JWT_KEY,nt as ENTITIES_BASE_PATH,V as FILE_STORAGE_BASE_PATH,X as GENERATE_UPLOAD_URL_PATH,f as Headers,w as LOGIN_TOKEN_KEY,O as LOGIN_USER_PROFILE_KEY,N as NvwaEdgeFunctions,W as NvwaFileStorage,H as NvwaHttpClient,J as OverlayManager,U as Request,C as Response,j as SET_AUTH_TOKEN_HEADER,L as URL,qt as createPostgrestClient,Jt as getSourceLocationFromDOM,Dt as normalizePayParams,Yt as requestPaymentFromOrderResult};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nvwa-app/sdk-core",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.12.0",
|
|
4
4
|
"description": "NVWA跨端通用工具类核心接口",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"splitting": false,
|
|
53
53
|
"shims": true,
|
|
54
54
|
"noExternal": [
|
|
55
|
-
"@nvwa-app/postgrest-js"
|
|
55
|
+
"@nvwa-app/postgrest-js",
|
|
56
|
+
"@nvwa-app/nvwa-http-polyfill"
|
|
56
57
|
]
|
|
57
58
|
},
|
|
58
59
|
"keywords": [
|