@bty/feed_app-runtime-sdk 0.0.8 → 0.0.9
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/ai/index.js +2 -3
- package/dist/chunk-AKZVV563.js +1 -0
- package/dist/chunk-ALNJCFV4.js +1 -0
- package/dist/device/index.d.ts +260 -0
- package/dist/device/index.js +1 -0
- package/dist/react/index.d.ts +5 -1
- package/dist/react/index.js +1 -1
- package/dist/types-DryABknE.d.ts +23 -0
- package/dist/user/index.d.ts +2 -2
- package/dist/user/index.js +1 -1
- package/package.json +9 -1
- package/dist/chunk-IOHVFMVA.js +0 -1
- package/dist/types-CLujY9ck.d.ts +0 -15
package/dist/ai/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export{g as AbortedError,s as AiError,c as AuthRequiredError,E as BadInputError,d as NetworkError,C as QuotaExceededError,R as RateLimitError,x as ServerError,Ce as anthropic,oe as configureRuntime,ye as openai};
|
|
1
|
+
import {d as d$1,c}from'../chunk-AKZVV563.js';import {a}from'../chunk-ALNJCFV4.js';import {createParser}from'eventsource-parser';var O={version:"0.0.9"};var m="/v1/feed-app/runtime/ai",E=`${m}/chat/completions`,_=`${m}/messages`,v=`${m}/images/generations`,I=`${m}/audio/speech`,B=`${m}/video/generations`,M="Authorization",H="x-bty-extend",N="x-bty-app",D=O.version;var j=()=>{};async function*U(e){let t=e.getReader(),r=new TextDecoder,n=[],s=createParser({onEvent(c){n.push({event:c.event||"message",data:c.data});},onRetry:j,onComment:j}),a=false;try{for(;;){let{done:c,value:u}=await t.read();for(u&&s.feed(r.decode(u,{stream:!0}));n.length>0;)yield n.shift();if(c){for(s.reset({consume:!0});n.length>0;)yield n.shift();a=!0;return}}}finally{if(!a)try{await t.cancel();}catch{}t.releaseLock();}}async function*G(e){for await(let t of U(e)){if(t.data==="[DONE]")return;t.data&&(yield JSON.parse(t.data));}}async function*q(e){for await(let t of U(e))t.data&&(yield JSON.parse(t.data));}var Q="https://reactus-api.happyseeds.ai",J=e=>{try{let t=e();if(typeof t=="string"&&t.length>0)return t}catch{}},X=()=>J(()=>typeof __BTY_RUNTIME_API_BASE_URL__=="string"?__BTY_RUNTIME_API_BASE_URL__:void 0),z=()=>J(()=>typeof __BTY_RUNTIME_PROJECT_ID__=="string"?__BTY_RUNTIME_PROJECT_ID__:void 0),T={apiBaseUrl:(X()??Q).replace(/\/+$/,""),projectId:z()??""},W=e=>{T={...T,...e,...e.apiBaseUrl?{apiBaseUrl:e.apiBaseUrl.replace(/\/+$/,"")}:{}};},f=()=>T;var o=class extends Error{status;code;body;constructor(t,r,n,s=null){super(t),this.name="AiError",this.code=r,this.status=n,this.body=s;}},i=class extends o{constructor(t="Auth required",r=null){super(t,"auth_required",401,r),this.name="AuthRequiredError";}},h=class extends o{constructor(t="Rate limit exceeded",r=null){super(t,"rate_limit",429,r),this.name="RateLimitError";}},g=class extends o{constructor(t="Quota exceeded",r=null){super(t,"quota_exceeded",402,r),this.name="QuotaExceededError";}},y=class extends o{constructor(t,r=400,n=null){super(t,"bad_input",r,n),this.name="BadInputError";}},A=class extends o{constructor(t,r=500,n=null){super(t,"server",r,n),this.name="ServerError";}},p=class extends o{constructor(t="Network error",r){super(t,"network",-1,r),this.name="NetworkError";}},l=class extends o{constructor(t="Request aborted"){super(t,"aborted",-1,null),this.name="AbortedError";}},V=e=>typeof e=="object"&&e!==null,Z=(e,t)=>{if(typeof e=="string")return e||t;if(!V(e))return t;let r=e.message;if(typeof r=="string"&&r.length>0)return r;let n=e.error;if(typeof n=="string"&&n.length>0)return n;if(V(n)&&typeof n.message=="string"&&n.message.length>0)return n.message;let s=e.detail;return typeof s=="string"&&s.length>0?s:t},x=(e,t)=>{let r=Z(t,`HTTP ${e}`);return e===401||e===403?new i(r,t):e===402?new g(r,t):e===429?new h(r,t):e>=400&&e<500?new y(r,e,t):e>=500?new A(r,e,t):new o(r,"unknown",e,t)};var ee=e=>JSON.stringify({"sdk-version":D,...e}),$=async(e={})=>{let t=await c(),r=new Headers;t&&r.set(M,`Bearer ${t}`),r.set(H,ee(e.extend));let{projectId:n}=f();if(n&&r.set(N,n),e.contentType&&r.set("Content-Type",e.contentType),e.accept&&r.set("Accept",e.accept),e.extra)for(let[s,a]of Object.entries(e.extra))r.set(s,a);return r};var te="feed-app-runtime-sdk:auth-required",w=e=>{a()&&window.dispatchEvent(new CustomEvent(te,{detail:e}));};var re=e=>e instanceof DOMException&&e.name==="AbortError",ne=async e=>{let t=e.headers.get("content-type")??"";try{return t.includes("application/json")?await e.json():await e.text()}catch{return null}},se=e=>typeof e=="object"&&e!==null,oe=(e,t)=>{if(!se(e)||typeof e.success!="boolean")return e;if(e.success)return e.data;let r=typeof e.code=="number"?e.code:t;throw x(r,e)},L=async(e,t)=>{let{apiBaseUrl:r}=f(),n=`${r}${e}`,s=await $(t),a;try{a=await fetch(n,{method:t.method??"POST",headers:s,body:t.body,signal:t.signal});}catch(u){throw re(u)?new l:new p("Failed to reach AI backend",u)}if(a.ok)return a;let c=await ne(a);throw x(a.status,c)},P=async(e,t={})=>{try{return await L(e,t)}catch(r){if(r instanceof i&&!t.skipAuthRetry&&!t.signal?.aborted){if(!await d$1())throw w({reason:"refresh_failed",error:r}),r;try{return await L(e,{...t,skipAuthRetry:!0})}catch(s){throw s instanceof i&&w({reason:"retry_rejected",error:s}),s}}throw r}},d=async(e,t,r={})=>{let n=await P(e,{...r,method:"POST",contentType:"application/json",body:JSON.stringify(t)});return oe(await n.json(),n.status)};var C=async(e,t,r={})=>{let n=await P(e,{...r,method:"POST",contentType:"application/json",accept:"text/event-stream",body:JSON.stringify(t)});if(!n.body)throw new p("Streaming response has no body");return n.body},F=async(e,t,r={})=>await(await P(e,{...r,method:"POST",contentType:"application/json",body:JSON.stringify(t)})).blob();var R=e=>{let{signal:t,headers:r,...n}=e;return {transport:{signal:t,extra:r},payload:n}},ae=(async e=>{let{transport:t,payload:r}=R(e);if(e.stream){let n=await C(E,r,t);return G(n)}return await d(E,r,t)}),ie={create:ae},ce={async generate(e){let{transport:t,payload:r}=R(e);return d(v,r,t)}},pe={speech:{async create(e){let{transport:t,payload:r}=R(e);return F(I,r,t)}}},de={generations:{async create(e){let{transport:t,payload:r}=R(e);return d(B,r,t)}}},ue={chat:{completions:ie},images:ce,audio:pe,video:de};var me=e=>{let{signal:t,headers:r,...n}=e;return {transport:{signal:t,extra:r},payload:n}},le=(async e=>{let{transport:t,payload:r}=me(e);if(e.stream){let n=await C(_,r,t);return q(n)}return await d(_,r,t)}),fe={messages:{create:le}};
|
|
2
|
+
export{l as AbortedError,o as AiError,i as AuthRequiredError,y as BadInputError,p as NetworkError,g as QuotaExceededError,h as RateLimitError,A as ServerError,fe as anthropic,W as configureRuntime,ue as openai};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a as a$1,b,j as j$1,d,f,g,k,o,m,v,q,x,e,s,r,w,c as c$1,p,l,n,h,i}from'./chunk-ALNJCFV4.js';var E=e=>typeof e=="object"&&e!==null,a=(e,n)=>{if(e)for(let t of n){let r=e[t];if(typeof r=="string"&&r.length>0)return r}},$=(e,n)=>{if(e)for(let t of n){let r=e[t];if(typeof r=="string"&&r.length>0||typeof r=="number"&&Number.isFinite(r))return r}},u=e=>{if(!E(e))return null;let n=E(e.credentials)?e.credentials:void 0,t=E(e.user)?e.user:void 0,r=a(e,["uid","userId","id"])??a(n,["uid","userId","id"])??a(t,["uid","userId","id"]),o=a(e,["token","authToken"])??a(n,["token","authToken"]);return !r||!o?null:{uid:r,token:o}},c=e=>{if(!E(e))return null;let n=E(e.data)?e.data:e,t=$(n,["userId","id","uid"]);if(t===void 0)return null;let r=a(n,["username","nickname","nickName","name"]),o=a(n,["nickname","nickName","username"]);return {...n,userId:t,...r?{username:r}:{},...o?{nickname:o}:{}}};var ee=e=>typeof e!="object"||e===null?false:typeof Reflect.get(e,"type")=="string",H=false,V=()=>{!a$1()||H||(H=true,d(),Reflect.set(window,f,e=>{u(e)&&b.emit(j$1,e);}),Reflect.set(window,g,e=>{c(e)&&b.emit(k,e);}),window.addEventListener("message",e=>{let n=e.data;if(ee(n))switch(n.type){case m:b.emit("iframe.credentials",n);break;case o:b.emit("iframe.userinfo",n);break}}));};var j=(e,n,t)=>new Promise(r=>{let o=false,f=i=>{o||(o=true,y(),clearTimeout(T),r(i));},y=b.on(n,i=>{let g=t(i);g&&f(g);}),T=setTimeout(()=>f(null),q);try{window.parent.postMessage({type:e,timestamp:Date.now()},"*");}catch{f(null);}}),G=()=>j(l,"iframe.credentials",u),Q=()=>j(n,"iframe.userinfo",c);var J=async(e$1,n,t,r$1)=>{let o=e$1.platform==="Android"?await x(e,{pollIntervalMs:r,timeoutMs:s}):w(e);if(!o)return null;let f=c$1(t);return new Promise(y=>{let T=false,i=d=>{T||(T=true,g(),Y(),clearTimeout(Z),y(d));},g=b.on(f,d=>{let p=r$1(d);p&&i(p);}),Y=b.on(t,d=>{let p=r$1(d);p&&i(p);}),Z=setTimeout(()=>i(null),p);try{o.postMessage({command:n,parameters:JSON.stringify({timestamp:Date.now(),endpoint:f})});}catch{i(null);}})},z=e=>J(e,h,j$1,u),K=e=>J(e,i,k,c);V();var C=null,I=null,R=new Set,ne=e=>{switch(e.type){case "native_app":return e.meetsMinVersion?z(e):Promise.resolve(null);case "iframe":return G();case "web":return Promise.resolve(null)}},re=e=>{switch(e.type){case "native_app":return e.meetsMinVersion?K(e):Promise.resolve(null);case "iframe":return Q();case "web":return Promise.resolve(null)}},W=e=>{let n=C?.token??"",t=e?.token??"";if(C=e,n!==t)for(let r of R)try{r();}catch{}},Ne=()=>C?.token??"",ve=e=>(R.add(e),()=>{R.delete(e);}),X=()=>I||(I=ne(v()).then(e=>(e&&W(e),e)).finally(()=>{I=null;}),I);a$1()&&b.on(j$1,e=>{let n=u(e);n&&W(n);});var te=async()=>a$1()?C?C.token:(await X())?.token??"":"",Pe=async()=>a$1()?(await X())?.token??"":"",se=async()=>a$1()?re(v()):null;export{Ne as a,ve as b,te as c,Pe as d,se as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=()=>typeof window<"u"&&typeof document<"u";var _="hostRuntime",p=class{listeners=new Map;on(e,t){let s=this.listeners.get(e),r=s??new Set;return s||this.listeners.set(e,r),r.add(t),()=>{r.delete(t),r.size===0&&this.listeners.delete(e);}}emit(e,t){let s=this.listeners.get(e);if(s)for(let r of s)r(t);}},R=new p,a=0,A=n=>(a+=1,`${n}.${a}`),l=false,I=()=>{if(!o()||l)return;l=true,Reflect.set(window,_,{receiveMessage(e){if(!e)return;let t=e.endpoint;t&&R.emit(t,e.data??e);}});};var E="HostApp",v="hostListener";var O="processUserCredentials",L="processUserInfo",H="user.getCredentials",b="user.getUserInfo",P="user.credentials",U="user.info",k="user-credentials-request",y="user-credentials-response",F="user-info-request",h="user-info-response",f={iOS:[1,6,7],Android:[1,1,8]},C=3e3,D=500,V=50,B=1500;var d=n=>{let e=n.split(".").map(t=>Number.parseInt(t,10));return [e[0]??0,e[1]??0,e[2]??0]},m=(n,e)=>{for(let t=0;t<3;t++){if(n[t]>e[t])return true;if(n[t]<e[t])return false}return true};var N=new RegExp(`${E}\\/(\\d+\\.\\d+\\.\\d+)\\/(\\d+)\\/(iOS|Android)`),g=n=>{let e=n.match(N);if(!e)return null;let[,t,s,r]=e;if(!t||!s||r!=="iOS"&&r!=="Android")return null;let i=m(d(t),f[r]);return {type:"native_app",platform:r,appVersion:t,buildNumber:s,meetsMinVersion:i}},Q=()=>{if(!o())return {type:"web",meetsMinVersion:false};let n=g(navigator.userAgent??"");return n||(window.parent!==window?{type:"iframe",meetsMinVersion:false}:{type:"web",meetsMinVersion:false})};var S=n=>typeof n!="object"||n===null?false:typeof Reflect.get(n,"postMessage")=="function",T=n=>{let e=Reflect.get(window,"webkit");if(typeof e=="object"&&e!==null){let s=Reflect.get(e,"messageHandlers");if(typeof s=="object"&&s!==null){let r=Reflect.get(s,n);if(S(r))return r}}let t=Reflect.get(window,n);return S(t)?t:null},X=(n,e={})=>{let{pollIntervalMs:t=50,timeoutMs:s=1500}=e;return new Promise(r=>{let i=Date.now(),u=()=>{let c=T(n);if(c){r(c);return}if(Date.now()-i>=s){r(null);return}setTimeout(u,t);};u();})};export{o as a,R as b,A as c,I as d,v as e,O as f,L as g,H as h,b as i,P as j,U as k,k as l,y as m,F as n,h as o,C as p,D as q,V as r,B as s,d as t,m as u,Q as v,T as w,X as x};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { A as AppEnvironment } from '../types-DryABknE.js';
|
|
2
|
+
|
|
3
|
+
type HapticImpactStrength = "light" | "medium" | "heavy" | "soft" | "rigid";
|
|
4
|
+
type HapticNotificationKind = "success" | "warning" | "error";
|
|
5
|
+
interface PositionRequestOptions {
|
|
6
|
+
enableHighAccuracy?: boolean;
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
maximumAgeMs?: number;
|
|
9
|
+
}
|
|
10
|
+
interface PositionSample {
|
|
11
|
+
latitude: number;
|
|
12
|
+
longitude: number;
|
|
13
|
+
accuracyMeters: number;
|
|
14
|
+
altitudeMeters?: number;
|
|
15
|
+
altitudeAccuracyMeters?: number;
|
|
16
|
+
headingDegrees?: number;
|
|
17
|
+
speedMetersPerSecond?: number;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
}
|
|
20
|
+
interface Vector3 {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
z: number;
|
|
24
|
+
}
|
|
25
|
+
interface MotionSample {
|
|
26
|
+
acceleration?: Vector3;
|
|
27
|
+
accelerationWithGravity: Vector3;
|
|
28
|
+
rotationRate: {
|
|
29
|
+
alpha: number;
|
|
30
|
+
beta: number;
|
|
31
|
+
gamma: number;
|
|
32
|
+
};
|
|
33
|
+
attitude?: {
|
|
34
|
+
yaw: number;
|
|
35
|
+
pitch: number;
|
|
36
|
+
roll: number;
|
|
37
|
+
};
|
|
38
|
+
timestamp: number;
|
|
39
|
+
}
|
|
40
|
+
interface OrientationSample {
|
|
41
|
+
alpha: number;
|
|
42
|
+
beta: number;
|
|
43
|
+
gamma: number;
|
|
44
|
+
timestamp: number;
|
|
45
|
+
}
|
|
46
|
+
interface MotionWatchOptions {
|
|
47
|
+
autoRequestPermission?: boolean;
|
|
48
|
+
}
|
|
49
|
+
type CameraFacing = "front" | "back";
|
|
50
|
+
type PhotoQuality = "low" | "medium" | "high";
|
|
51
|
+
type PhotoFormat = "jpeg" | "png" | "webp";
|
|
52
|
+
interface PhotoCaptureOptions {
|
|
53
|
+
quality?: PhotoQuality;
|
|
54
|
+
format?: PhotoFormat;
|
|
55
|
+
width?: number;
|
|
56
|
+
height?: number;
|
|
57
|
+
camera?: CameraFacing;
|
|
58
|
+
}
|
|
59
|
+
interface CapturedPhoto {
|
|
60
|
+
blob: Blob;
|
|
61
|
+
dataUrl: string;
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
|
+
}
|
|
65
|
+
interface StreamOptions {
|
|
66
|
+
camera?: CameraFacing;
|
|
67
|
+
width?: number;
|
|
68
|
+
height?: number;
|
|
69
|
+
}
|
|
70
|
+
interface PickFilesOptions {
|
|
71
|
+
accept?: string[];
|
|
72
|
+
multiple?: boolean;
|
|
73
|
+
directory?: boolean;
|
|
74
|
+
}
|
|
75
|
+
interface PickedFiles {
|
|
76
|
+
files: File[];
|
|
77
|
+
paths: string[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
declare const camera: {
|
|
81
|
+
isSupported(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Open the camera, capture one photo, close the stream. The native bridge
|
|
84
|
+
* variant runs the host App's full-screen capture UI (better quality, save
|
|
85
|
+
* to gallery, etc.); the web fallback does a headless `getUserMedia +
|
|
86
|
+
* canvas` shot. Returns null on permission denial, hardware absence, or
|
|
87
|
+
* any failure on either path.
|
|
88
|
+
*
|
|
89
|
+
* Must be called inside a user-gesture handler to satisfy autoplay /
|
|
90
|
+
* permission requirements on iOS Safari and modern Android browsers.
|
|
91
|
+
*/
|
|
92
|
+
capturePhoto(opts?: PhotoCaptureOptions): Promise<CapturedPhoto | null>;
|
|
93
|
+
/**
|
|
94
|
+
* Open a live MediaStream — for QR scanning, AR overlays, or any case
|
|
95
|
+
* where a single still photo is not enough. Web-only by design: streaming
|
|
96
|
+
* raw video frames through a JS bridge is impractical, and host Apps that
|
|
97
|
+
* need camera access usually push it through capturePhoto's full-screen UI
|
|
98
|
+
* instead.
|
|
99
|
+
*
|
|
100
|
+
* Returns null when getUserMedia is unavailable or the user denies access.
|
|
101
|
+
* Caller must invoke `camera.stopStream(stream)` when done.
|
|
102
|
+
*/
|
|
103
|
+
openStream(opts?: StreamOptions): Promise<MediaStream | null>;
|
|
104
|
+
stopStream(stream: MediaStream): void;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
declare const files: {
|
|
108
|
+
/**
|
|
109
|
+
* Whether the modern picker (File System Access API or native bridge) is
|
|
110
|
+
* available. False does not mean files cannot be picked — `<input
|
|
111
|
+
* type=file>` still works in any browser via the lib's legacy fallback; it
|
|
112
|
+
* just lacks path / write-back.
|
|
113
|
+
*/
|
|
114
|
+
isPickerSupported(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Pick one or more files. Returns null on user cancel or unavailability.
|
|
117
|
+
* `paths` is populated only when the native bridge serves the request;
|
|
118
|
+
* web fallbacks have no path concept.
|
|
119
|
+
*/
|
|
120
|
+
pickFiles(opts?: PickFilesOptions): Promise<PickedFiles | null>;
|
|
121
|
+
/**
|
|
122
|
+
* Save a Blob to a file the user nominates. Native handler can prompt for
|
|
123
|
+
* a directory and write in place; web fallback uses the File System Access
|
|
124
|
+
* save dialog when available, otherwise triggers an anchor download.
|
|
125
|
+
*
|
|
126
|
+
* Returns once the save has been initiated. There is no progress callback —
|
|
127
|
+
* Blobs in web platforms write atomically.
|
|
128
|
+
*/
|
|
129
|
+
saveFile(blob: Blob, filename: string): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Read the contents of a File / Blob as a UTF-8 string. Pure web — does
|
|
132
|
+
* not consult the native bridge. The blob already lives in the page's
|
|
133
|
+
* memory by the time this is called.
|
|
134
|
+
*/
|
|
135
|
+
readAsText(file: File | Blob): Promise<string>;
|
|
136
|
+
/**
|
|
137
|
+
* Read the contents of a File / Blob as a base64 data URL — useful for
|
|
138
|
+
* `<img src>` previews. Pure web.
|
|
139
|
+
*/
|
|
140
|
+
readAsDataUrl(file: File | Blob): Promise<string>;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
declare const geolocation: {
|
|
144
|
+
isSupported(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Single position read. Returns null on permission denial, timeout, or
|
|
147
|
+
* absence of geolocation hardware. Default timeout is the browser/native
|
|
148
|
+
* default; pass `timeoutMs` to override.
|
|
149
|
+
*/
|
|
150
|
+
getCurrentPosition(opts?: PositionRequestOptions): Promise<PositionSample | null>;
|
|
151
|
+
/**
|
|
152
|
+
* Continuous position updates. Returns a synchronous cleanup function —
|
|
153
|
+
* native subscription may be still warming up; cleanup is safe to call
|
|
154
|
+
* before that resolves, the subscription will be torn down as soon as it
|
|
155
|
+
* is installed.
|
|
156
|
+
*/
|
|
157
|
+
watchPosition(onSample: (sample: PositionSample) => void, opts?: PositionRequestOptions): () => void;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
declare const haptics: {
|
|
161
|
+
/**
|
|
162
|
+
* Whether at least one path can fire haptics in the current environment.
|
|
163
|
+
* Conservative — returns true if `navigator.vibrate` exists OR we're inside
|
|
164
|
+
* a native_app host. Does not guarantee any specific call will succeed
|
|
165
|
+
* (permissions, hardware capabilities, native version, ...).
|
|
166
|
+
*/
|
|
167
|
+
isSupported(): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Tactile "tap" feedback. Maps to UIImpactFeedbackGenerator on iOS and
|
|
170
|
+
* VibrationEffect.EFFECT_CLICK / EFFECT_HEAVY_CLICK on Android (native
|
|
171
|
+
* bridge); a short navigator.vibrate pulse on the web. Default `medium`.
|
|
172
|
+
*/
|
|
173
|
+
impact(strength?: HapticImpactStrength): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* "Tick" feedback for changing a selected item (segmented control, picker).
|
|
176
|
+
* Maps to UISelectionFeedbackGenerator on iOS; a very short pulse on web.
|
|
177
|
+
*/
|
|
178
|
+
selection(): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Status feedback after a discrete action (form submit, transaction).
|
|
181
|
+
* Maps to UINotificationFeedbackGenerator on iOS; a small multi-segment
|
|
182
|
+
* pattern on web.
|
|
183
|
+
*/
|
|
184
|
+
notification(kind: HapticNotificationKind): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Low-level Android-style pattern. Number = single pulse in ms; array =
|
|
187
|
+
* alternating vibrate/pause durations. Native bridge forwards verbatim;
|
|
188
|
+
* iOS handler may approximate by mapping pattern length/intensity to its
|
|
189
|
+
* Impact generator.
|
|
190
|
+
*/
|
|
191
|
+
vibrate(pattern: number | number[]): Promise<void>;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
declare const sensors: {
|
|
195
|
+
isMotionSupported(): boolean;
|
|
196
|
+
isOrientationSupported(): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Ask the host (native App or iOS Safari) for permission to read motion
|
|
199
|
+
* data. **Must be called inside a user-gesture handler on iOS Safari** —
|
|
200
|
+
* a non-gesture invocation silently resolves to false. The native-bridge
|
|
201
|
+
* variant has no such gesture requirement because the App's own iOS
|
|
202
|
+
* permission prompt is independent of the web view's gesture stack.
|
|
203
|
+
*/
|
|
204
|
+
requestMotionPermission(): Promise<boolean>;
|
|
205
|
+
/**
|
|
206
|
+
* Subscribe to device motion samples. Native handler streams sensor-rate
|
|
207
|
+
* data through the bridge; web fallback uses the `devicemotion` event.
|
|
208
|
+
*
|
|
209
|
+
* iOS Safari requires a permission grant before the event fires. Pass
|
|
210
|
+
* `autoRequestPermission: true` from inside a click handler if you want
|
|
211
|
+
* the subscription to also request permission as part of setup.
|
|
212
|
+
*/
|
|
213
|
+
watchMotion(onSample: (s: MotionSample) => void, opts?: MotionWatchOptions): () => void;
|
|
214
|
+
/**
|
|
215
|
+
* Subscribe to device orientation samples. Mirrors watchMotion but uses
|
|
216
|
+
* the `deviceorientation` event on the web fallback path.
|
|
217
|
+
*/
|
|
218
|
+
watchOrientation(onSample: (s: OrientationSample) => void): () => void;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
type DeviceFeature = "haptics" | "geolocation" | "sensors" | "camera" | "files";
|
|
222
|
+
|
|
223
|
+
declare const meetsFeatureMinVersion: (feature: DeviceFeature, env: AppEnvironment) => boolean;
|
|
224
|
+
|
|
225
|
+
declare const device: {
|
|
226
|
+
haptics: {
|
|
227
|
+
isSupported(): boolean;
|
|
228
|
+
impact(strength?: HapticImpactStrength): Promise<void>;
|
|
229
|
+
selection(): Promise<void>;
|
|
230
|
+
notification(kind: HapticNotificationKind): Promise<void>;
|
|
231
|
+
vibrate(pattern: number | number[]): Promise<void>;
|
|
232
|
+
};
|
|
233
|
+
geolocation: {
|
|
234
|
+
isSupported(): boolean;
|
|
235
|
+
getCurrentPosition(opts?: PositionRequestOptions): Promise<PositionSample | null>;
|
|
236
|
+
watchPosition(onSample: (sample: PositionSample) => void, opts?: PositionRequestOptions): () => void;
|
|
237
|
+
};
|
|
238
|
+
sensors: {
|
|
239
|
+
isMotionSupported(): boolean;
|
|
240
|
+
isOrientationSupported(): boolean;
|
|
241
|
+
requestMotionPermission(): Promise<boolean>;
|
|
242
|
+
watchMotion(onSample: (s: MotionSample) => void, opts?: MotionWatchOptions): () => void;
|
|
243
|
+
watchOrientation(onSample: (s: OrientationSample) => void): () => void;
|
|
244
|
+
};
|
|
245
|
+
camera: {
|
|
246
|
+
isSupported(): boolean;
|
|
247
|
+
capturePhoto(opts?: PhotoCaptureOptions): Promise<CapturedPhoto | null>;
|
|
248
|
+
openStream(opts?: StreamOptions): Promise<MediaStream | null>;
|
|
249
|
+
stopStream(stream: MediaStream): void;
|
|
250
|
+
};
|
|
251
|
+
files: {
|
|
252
|
+
isPickerSupported(): boolean;
|
|
253
|
+
pickFiles(opts?: PickFilesOptions): Promise<PickedFiles | null>;
|
|
254
|
+
saveFile(blob: Blob, filename: string): Promise<void>;
|
|
255
|
+
readAsText(file: File | Blob): Promise<string>;
|
|
256
|
+
readAsDataUrl(file: File | Blob): Promise<string>;
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export { type CameraFacing, type CapturedPhoto, type DeviceFeature, type HapticImpactStrength, type HapticNotificationKind, type MotionSample, type MotionWatchOptions, type OrientationSample, type PhotoCaptureOptions, type PhotoFormat, type PhotoQuality, type PickFilesOptions, type PickedFiles, type PositionRequestOptions, type PositionSample, type StreamOptions, type Vector3, camera, device, files, geolocation, haptics, meetsFeatureMinVersion, sensors };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a,d as d$1,u as u$1,t,v,c,b,x,e,s,r,w}from'../chunk-ALNJCFV4.js';import {fileSave,directoryOpen,fileOpen}from'browser-fs-access';var L=false,S=()=>{!a()||L||(L=true,d$1());};var B="device.haptics",M="device.geolocation",H="device.sensors.motion",V="device.sensors.orientation",W="device.sensors.permission",G="device.camera",R="device.files",q="device.haptics.impact",j="device.haptics.selection",z="device.haptics.notification",K="device.haptics.vibrate",Q="device.geolocation.get",J="device.geolocation.watch.start",Y="device.geolocation.watch.stop",$="device.sensors.motion.start",X="device.sensors.motion.stop",Z="device.sensors.orientation.start",ee="device.sensors.orientation.stop",te="device.sensors.requestPermission",ne="device.camera.capture",oe="device.files.pick",ie="device.files.save";var re={haptics:{iOS:null,Android:null},geolocation:{iOS:null,Android:null},sensors:{iOS:null,Android:null},camera:{iOS:null,Android:null},files:{iOS:null,Android:null}};var C=(e,n)=>{if(n.type!=="native_app"||!n.platform||!n.appVersion)return false;let t$1=re[e][n.platform];return t$1?u$1(t(n.appVersion),t$1):false},I=e=>JSON.stringify(e),ae=(e,n)=>{if(typeof e!="object"||e===null||Reflect.get(e,"ok")!==true)return null;let o=Reflect.get(e,"result");return n(o)},se=async e$1=>e$1.platform==="Android"?x(e,{pollIntervalMs:r,timeoutMs:s}):w(e),p=async e=>{if(!a())return null;S();let n=v();if(!C(e.feature,n))return null;let t=await se(n);if(!t)return null;let o=c(e.endpointPrefix),i=e.timeoutMs??3e3;return new Promise(r=>{let a=false,l=v=>{a||(a=true,c(),clearTimeout(m),r(v));},c=b.on(o,v=>{let g=ae(v,e.parseResult);l(g);}),m=setTimeout(()=>l(null),i);try{t.postMessage({command:e.command,parameters:I({endpoint:o,timestamp:Date.now(),payload:e.payload})});}catch{l(null);}})},E=async e=>{if(!a())return null;S();let n=v();if(!C(e.feature,n))return null;let t=await se(n);if(!t)return null;let o=c(e.endpointPrefix),i=b.on(o,r=>{let a=ae(r,e.parseEvent);a&&e.onEvent(a);});try{t.postMessage({command:e.startCommand,parameters:I({endpoint:o,timestamp:Date.now(),payload:e.payload})});}catch{return i(),null}return ()=>{i();try{t.postMessage({command:e.stopCommand,parameters:I({endpoint:o,timestamp:Date.now(),payload:null})});}catch{}}};var d=async e=>{if(!a())return e.safeDefault;let n=await e.native();if(n!==null)return n;try{let t=await e.web();if(t!==null)return t}catch{}return e.safeDefault};var le=e=>e==="front"?"user":"environment",_e={low:.5,medium:.8,high:.95},Te=e=>{let n=e.indexOf(",");if(n<0)return null;let t=e.slice(5,n),o=e.slice(n+1),r=/^([^;]+)/.exec(t)?.[1]??"application/octet-stream";try{if(/;base64/.test(t)){let l=atob(o),c=new Uint8Array(l.length);for(let m=0;m<l.length;m++)c[m]=l.charCodeAt(m);return new Blob([c],{type:r})}return new Blob([decodeURIComponent(o)],{type:r})}catch{return null}},be=e=>{if(typeof e!="object"||e===null)return null;let n=Reflect.get(e,"dataUrl"),t=Reflect.get(e,"width"),o=Reflect.get(e,"height");if(typeof n!="string"||n.length===0||typeof t!="number"||typeof o!="number")return null;let i=Te(n);return i?{blob:i,dataUrl:n,width:t,height:o}:null},Me=async e=>{if(!a()||!navigator.mediaDevices?.getUserMedia)return null;let n=null;try{n=await navigator.mediaDevices.getUserMedia({video:{facingMode:le(e?.camera),width:e?.width,height:e?.height}});let t=document.createElement("video");t.srcObject=n,t.muted=!0,t.playsInline=!0,await t.play(),await new Promise(h=>{requestAnimationFrame(()=>h());});let o=e?.width??t.videoWidth??640,i=e?.height??t.videoHeight??480,r=document.createElement("canvas");r.width=o,r.height=i;let a=r.getContext("2d");if(!a)return null;a.drawImage(t,0,0,o,i);let c=`image/${e?.format??"jpeg"}`,m=_e[e?.quality??"medium"],v=r.toDataURL(c,m),g=await new Promise(h=>{r.toBlob(he=>h(he),c,m);});return g?{blob:g,dataUrl:v,width:o,height:i}:null}catch{return null}finally{if(n)for(let t of n.getTracks())t.stop();}},ce={isSupported(){return a()?!!navigator.mediaDevices?.getUserMedia:false},capturePhoto(e){return d({native:()=>p({feature:"camera",command:ne,endpointPrefix:G,payload:e??{},parseResult:be,timeoutMs:6e4}),web:()=>Me(e),safeDefault:null})},async openStream(e){if(!a()||!navigator.mediaDevices?.getUserMedia)return null;try{return await navigator.mediaDevices.getUserMedia({video:{facingMode:le(e?.camera),width:e?.width,height:e?.height}})}catch{return null}},stopStream(e){try{for(let n of e.getTracks())n.stop();}catch{}}};var me=(e,n)=>{let t=atob(e),o=new Uint8Array(t.length);for(let i=0;i<t.length;i++)o[i]=t.charCodeAt(i);return new Blob([o],{type:n})},Ce=e=>{let n=null;if(e.dataUrl){let t=e.dataUrl.indexOf(",");if(t>0){let o=e.dataUrl.slice(5,t),i=e.dataUrl.slice(t+1),r=/^([^;]+)/.exec(o)?.[1]??"application/octet-stream";try{n=/;base64/.test(o)?me(i,r):new Blob([decodeURIComponent(i)],{type:r});}catch{n=null;}}}else e.base64&&(n=me(e.base64,e.mime??"application/octet-stream"));return n?new File([n],e.name,{type:e.mime??n.type,lastModified:Date.now()}):null},Ae=e=>{if(typeof e!="object"||e===null)return null;let n=Reflect.get(e,"files");if(!Array.isArray(n))return null;let t=[],o=[];for(let r of n){if(typeof r!="object"||r===null)continue;let a=r,l=Ce(a);l&&(t.push(l),typeof a.path=="string"&&o.push(a.path));}if(t.length===0)return null;let i=Reflect.get(e,"paths");if(Array.isArray(i)){o.length=0;for(let r of i)typeof r=="string"&&o.push(r);}return {files:t,paths:o}},Ne=e=>{let n=[],t=[];if(!e)return {mimeTypes:n,extensions:t};for(let o of e)for(let i of o.split(",")){let r=i.trim();r&&(r.startsWith(".")?t.push(r):n.push(r));}return {mimeTypes:n,extensions:t}},De=e=>e instanceof DOMException&&e.name==="AbortError",we=async e=>{if(!a())return null;try{if(e?.directory){let i=await directoryOpen({recursive:!0});return i.length>0?{files:i,paths:[]}:null}let{mimeTypes:n,extensions:t}=Ne(e?.accept);if(e?.multiple){let i=await fileOpen({mimeTypes:n,extensions:t,multiple:!0});return i.length>0?{files:i,paths:[]}:null}return {files:[await fileOpen({mimeTypes:n,extensions:t})],paths:[]}}catch(n){return De(n),null}},xe=async(e,n)=>{if(a())try{await fileSave(e,{fileName:n});}catch{}},pe={isPickerSupported(){return a()?typeof window.showOpenFilePicker=="function":false},pickFiles(e){return d({native:()=>p({feature:"files",command:oe,endpointPrefix:R,payload:e??{},parseResult:Ae,timeoutMs:6e4}),web:()=>we(e),safeDefault:null})},async saveFile(e,n){!a()||await p({feature:"files",command:ie,endpointPrefix:R,payload:{filename:n,mime:e.type,size:e.size},parseResult:()=>true,timeoutMs:6e4})||await xe(e,n);},readAsText(e){return typeof e.text=="function"?e.text():new Promise((n,t)=>{let o=new FileReader;o.onload=()=>{n(typeof o.result=="string"?o.result:"");},o.onerror=()=>t(o.error),o.readAsText(e);})},readAsDataUrl(e){return new Promise((n,t)=>{let o=new FileReader;o.onload=()=>{n(typeof o.result=="string"?o.result:"");},o.onerror=()=>t(o.error),o.readAsDataURL(e);})}};var f=(e,...n)=>{for(let t of n){let o=Reflect.get(e,t);if(typeof o=="number"&&!Number.isNaN(o))return o}},de=e=>{if(typeof e!="object"||e===null)return null;let n=f(e,"latitude"),t=f(e,"longitude"),o=f(e,"accuracyMeters","accuracy");if(n===void 0||t===void 0||o===void 0)return null;let i={latitude:n,longitude:t,accuracyMeters:o,timestamp:f(e,"timestamp")??Date.now()},r=f(e,"altitudeMeters","altitude");r!==void 0&&(i.altitudeMeters=r);let a=f(e,"altitudeAccuracyMeters","altitudeAccuracy");a!==void 0&&(i.altitudeAccuracyMeters=a);let l=f(e,"headingDegrees","heading");l!==void 0&&(i.headingDegrees=l);let c=f(e,"speedMetersPerSecond","speed");return c!==void 0&&(i.speedMetersPerSecond=c),i},fe=e=>({latitude:e.coords.latitude,longitude:e.coords.longitude,accuracyMeters:e.coords.accuracy,altitudeMeters:e.coords.altitude??void 0,altitudeAccuracyMeters:e.coords.altitudeAccuracy??void 0,headingDegrees:e.coords.heading??void 0,speedMetersPerSecond:e.coords.speed??void 0,timestamp:e.timestamp}),ve=e=>e?{enableHighAccuracy:e.enableHighAccuracy,timeout:e.timeoutMs,maximumAge:e.maximumAgeMs}:void 0,Fe=e=>!a()||!navigator.geolocation?Promise.resolve(null):new Promise(n=>{navigator.geolocation.getCurrentPosition(t=>n(fe(t)),()=>n(null),ve(e));}),Se={isSupported(){return a()?!!navigator.geolocation:false},getCurrentPosition(e){return d({native:()=>p({feature:"geolocation",command:Q,endpointPrefix:M,payload:e??{},parseResult:de,timeoutMs:e?.timeoutMs}),web:()=>Fe(e),safeDefault:null})},watchPosition(e,n){let t=false,o=null,i=null;return E({feature:"geolocation",startCommand:J,stopCommand:Y,endpointPrefix:M,payload:n??{},parseEvent:de,onEvent:r=>{t||e(r);}}).then(r=>{if(t){r?.();return}if(r){o=r;return}if(!(!a()||!navigator.geolocation))try{i=navigator.geolocation.watchPosition(a=>{t||e(fe(a));},()=>{},ve(n));}catch{}}),()=>{if(t=true,o&&o(),i!==null&&a()&&navigator.geolocation)try{navigator.geolocation.clearWatch(i);}catch{}}}};var ke={light:10,medium:20,heavy:40,soft:15,rigid:30},Ue={success:[20,60,20],warning:[40,40,40],error:[50,30,100]},Le=e=>{if(typeof navigator>"u"||typeof navigator.vibrate!="function")return false;try{return navigator.vibrate(e)}catch{return false}},O=(e,n,t)=>d({native:()=>p({feature:"haptics",command:e,endpointPrefix:B,payload:n,parseResult:()=>true}),web:async()=>Le(t),safeDefault:false}),Ee={isSupported(){return a()?typeof navigator<"u"&&"vibrate"in navigator:false},async impact(e="medium"){await O(q,{strength:e},ke[e]);},async selection(){await O(j,{},8);},async notification(e){await O(z,{kind:e},Ue[e]);},async vibrate(e){await O(K,{pattern:e},e);}};var Pe=()=>typeof DeviceMotionEvent>"u"?false:typeof DeviceMotionEvent.requestPermission=="function",ge=async()=>{if(!Pe())return true;try{let e=DeviceMotionEvent.requestPermission;return e?await e()==="granted":!0}catch{return false}},u=(e,...n)=>{for(let t of n){let o=Reflect.get(e,t);if(typeof o=="number"&&!Number.isNaN(o))return o}},A=(e,n)=>{let t=Reflect.get(e,n);if(typeof t!="object"||t===null)return;let o=u(t,"x"),i=u(t,"y"),r=u(t,"z");if(!(o===void 0||i===void 0||r===void 0))return {x:o,y:i,z:r}},Be=e=>{if(typeof e!="object"||e===null)return null;let n=A(e,"accelerationWithGravity")??A(e,"accelerationIncludingGravity");if(!n)return null;let t=Reflect.get(e,"rotationRate"),o={alpha:0,beta:0,gamma:0};typeof t=="object"&&t!==null&&(o={alpha:u(t,"alpha")??0,beta:u(t,"beta")??0,gamma:u(t,"gamma")??0});let i={accelerationWithGravity:n,rotationRate:o,timestamp:u(e,"timestamp")??Date.now()},r=A(e,"acceleration");r&&(i.acceleration=r);let a=Reflect.get(e,"attitude");if(typeof a=="object"&&a!==null){let l=u(a,"yaw"),c=u(a,"pitch"),m=u(a,"roll");l!==void 0&&c!==void 0&&m!==void 0&&(i.attitude={yaw:l,pitch:c,roll:m});}return i},He=e=>{if(typeof e!="object"||e===null)return null;let n=u(e,"alpha"),t=u(e,"beta"),o=u(e,"gamma");return n===void 0||t===void 0||o===void 0?null:{alpha:n,beta:t,gamma:o,timestamp:u(e,"timestamp")??Date.now()}},Ve=e=>{let n=e.accelerationIncludingGravity,t=e.acceleration,o=e.rotationRate,i={accelerationWithGravity:{x:n?.x??0,y:n?.y??0,z:n?.z??0},rotationRate:{alpha:o?.alpha??0,beta:o?.beta??0,gamma:o?.gamma??0},timestamp:e.timeStamp||Date.now()};return t&&(t.x!==null||t.y!==null||t.z!==null)&&(i.acceleration={x:t.x??0,y:t.y??0,z:t.z??0}),i},We=e=>({alpha:e.alpha??0,beta:e.beta??0,gamma:e.gamma??0,timestamp:e.timeStamp||Date.now()}),Oe={isMotionSupported(){return a()?typeof DeviceMotionEvent<"u":false},isOrientationSupported(){return a()?typeof DeviceOrientationEvent<"u":false},async requestMotionPermission(){if(!a())return false;let e=await p({feature:"sensors",command:te,endpointPrefix:W,payload:{},parseResult:n=>{if(typeof n=="boolean")return n;if(typeof n=="object"&&n!==null){let t=Reflect.get(n,"granted");if(typeof t=="boolean")return t}return null}});return e!==null?e:ge()},watchMotion(e,n){let t=false,o=null,i=null,r=()=>{if(t||!a())return;let l=c=>{t||e(Ve(c));};window.addEventListener("devicemotion",l),i=l;};return (async()=>{let l=await E({feature:"sensors",startCommand:$,stopCommand:X,endpointPrefix:H,payload:n??{},parseEvent:Be,onEvent:c=>{t||e(c);}});if(t){l?.();return}if(l){o=l;return}n?.autoRequestPermission&&Pe()&&(!await ge()||t)||r();})(),()=>{t=true,o&&o(),i&&a()&&(window.removeEventListener("devicemotion",i),i=null);}},watchOrientation(e){let n=false,t=null,o=null,i=()=>{if(n||!a())return;let a$1=l=>{n||e(We(l));};window.addEventListener("deviceorientation",a$1),o=a$1;};return (async()=>{let a=await E({feature:"sensors",startCommand:Z,stopCommand:ee,endpointPrefix:V,payload:{},parseEvent:He,onEvent:l=>{n||e(l);}});if(n){a?.();return}if(a){t=a;return}i();})(),()=>{n=true,t&&t(),o&&a()&&(window.removeEventListener("deviceorientation",o),o=null);}}};S();var Ct={haptics:Ee,geolocation:Se,sensors:Oe,camera:ce,files:pe};export{ce as camera,Ct as device,pe as files,Se as geolocation,Ee as haptics,C as meetsFeatureMinVersion,Oe as sensors};
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { U as UserInfo } from '../types-
|
|
1
|
+
import { U as UserInfo } from '../types-DryABknE.js';
|
|
2
2
|
|
|
3
3
|
interface UseAuthTokenResult {
|
|
4
4
|
token: string;
|
|
@@ -10,6 +10,10 @@ interface UseAuthTokenResult {
|
|
|
10
10
|
/**
|
|
11
11
|
* 鉴权 token。挂载时拉一次,业务需要刷新时调用 refetch。
|
|
12
12
|
*
|
|
13
|
+
* Token 通过 `useSyncExternalStore` 订阅 SDK 内部凭证缓存——宿主通过桥
|
|
14
|
+
* (EP_CREDENTIALS) 推送新 token、或 AI 模块 401 自动 refresh 后,组件会
|
|
15
|
+
* 自动 re-render,业务不必手动 refetch。
|
|
16
|
+
*
|
|
13
17
|
* 注意:token 是字符串,不是 Credentials。如果你需要 userId,配合
|
|
14
18
|
* `useUserInfo()` 用。
|
|
15
19
|
*/
|
package/dist/react/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b,
|
|
1
|
+
import {b,a,c,e}from'../chunk-AKZVV563.js';import'../chunk-ALNJCFV4.js';import {useSyncExternalStore,useState,useCallback,useEffect}from'react';var d="",k=()=>{let u=useSyncExternalStore(b,a,()=>d),[o,e]=useState(()=>a()===""),t=useCallback(()=>{e(true),c().then(()=>e(false));},[]);return useEffect(()=>{if(a()!==""){e(false);return}let s=true;return c().then(()=>{s&&e(false);}),()=>{s=false;}},[]),{token:u,loading:o,refetch:t}};var I=()=>{let[u,o]=useState(null),[e$1,t]=useState(true),s=useCallback(()=>{t(true),e().then(r=>{o(r),t(false);});},[]);return useEffect(()=>{let r=true;return e().then(c=>{r&&(o(c),t(false));}),()=>{r=false;}},[]),{user:u,loading:e$1,refetch:s}};export{k as useAuthToken,I as useUserInfo};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface Credentials {
|
|
2
|
+
uid: string;
|
|
3
|
+
token: string;
|
|
4
|
+
}
|
|
5
|
+
interface UserInfo {
|
|
6
|
+
userId: string | number;
|
|
7
|
+
username?: string;
|
|
8
|
+
nickname?: string;
|
|
9
|
+
avatar?: string | null;
|
|
10
|
+
phone?: string | null;
|
|
11
|
+
email?: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
type AppEnvironmentType = "native_app" | "iframe" | "web";
|
|
15
|
+
interface AppEnvironment {
|
|
16
|
+
type: AppEnvironmentType;
|
|
17
|
+
platform?: "iOS" | "Android";
|
|
18
|
+
appVersion?: string;
|
|
19
|
+
buildNumber?: string;
|
|
20
|
+
meetsMinVersion: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type { AppEnvironment as A, Credentials as C, UserInfo as U };
|
package/dist/user/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as UserInfo } from '../types-
|
|
2
|
-
export { C as Credentials } from '../types-
|
|
1
|
+
import { U as UserInfo } from '../types-DryABknE.js';
|
|
2
|
+
export { C as Credentials } from '../types-DryABknE.js';
|
|
3
3
|
|
|
4
4
|
declare const getAuthTokenAsync: () => Promise<string>;
|
|
5
5
|
declare const getUserInfoAsync: () => Promise<UserInfo | null>;
|
package/dist/user/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{c as getAuthTokenAsync,e as getUserInfoAsync}from'../chunk-AKZVV563.js';import'../chunk-ALNJCFV4.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bty/feed_app-runtime-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"browser": true,
|
|
6
6
|
"description": "Runtime SDK for feed-app template: auth / AI capabilities, multi-environment bridge (native App / iframe / web).",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"types": "./dist/react/index.d.ts",
|
|
22
22
|
"import": "./dist/react/index.js"
|
|
23
23
|
},
|
|
24
|
+
"./device": {
|
|
25
|
+
"types": "./dist/device/index.d.ts",
|
|
26
|
+
"import": "./dist/device/index.js"
|
|
27
|
+
},
|
|
24
28
|
"./package.json": "./package.json"
|
|
25
29
|
},
|
|
26
30
|
"publishConfig": {
|
|
@@ -52,5 +56,9 @@
|
|
|
52
56
|
"typescript": "catalog:",
|
|
53
57
|
"vite": "catalog:",
|
|
54
58
|
"vitest": "^2.1.8"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"browser-fs-access": "^0.38.0",
|
|
62
|
+
"eventsource-parser": "^3.1.0"
|
|
55
63
|
}
|
|
56
64
|
}
|
package/dist/chunk-IOHVFMVA.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var i=()=>typeof window<"u"&&typeof document<"u";var se="hostRuntime",g=class{listeners=new Map;on(n,t){let r=this.listeners.get(n),s=r??new Set;return r||this.listeners.set(n,s),s.add(t),()=>{s.delete(t),s.size===0&&this.listeners.delete(n);}}emit(n,t){let r=this.listeners.get(n);if(r)for(let s of r)s(t);}},o=new g,y=0,N=e=>(y+=1,`${e}.${y}`),k=false,v=()=>{if(!i()||k)return;k=true,Reflect.set(window,se,{receiveMessage(n){if(!n)return;let t=n.endpoint;t&&o.emit(t,n.data??n);}});};var _=e=>typeof e=="object"&&e!==null,f=(e,n)=>{if(e)for(let t of n){let r=e[t];if(typeof r=="string"&&r.length>0)return r}},oe=(e,n)=>{if(e)for(let t of n){let r=e[t];if(typeof r=="string"&&r.length>0||typeof r=="number"&&Number.isFinite(r))return r}},a=e=>{if(!_(e))return null;let n=_(e.credentials)?e.credentials:void 0,t=_(e.user)?e.user:void 0,r=f(e,["uid","userId","id"])??f(n,["uid","userId","id"])??f(t,["uid","userId","id"]),s=f(e,["token","authToken"])??f(n,["token","authToken"]);return !r||!s?null:{uid:r,token:s}},m=e=>{if(!_(e))return null;let n=_(e.data)?e.data:e,t=oe(n,["userId","id","uid"]);if(t===void 0)return null;let r=f(n,["username","nickname","nickName","name"]),s=f(n,["nickname","nickName","username"]);return {...n,userId:t,...r?{username:r}:{},...s?{nickname:s}:{}}};var O="HostApp",A="hostListener";var U="processUserCredentials",P="processUserInfo",x="user.getCredentials",L="user.getUserInfo",d="user.credentials",R="user.info",h="user-credentials-request",b="user-credentials-response",F="user-info-request",H="user-info-response",D={iOS:[1,6,7],Android:[1,1,8]},q=3e3,B=500,V=50,j=1500;var ie=e=>typeof e!="object"||e===null?false:typeof Reflect.get(e,"type")=="string",G=false,Q=()=>{!i()||G||(G=true,v(),Reflect.set(window,U,e=>{a(e)&&o.emit(d,e);}),Reflect.set(window,P,e=>{m(e)&&o.emit(R,e);}),window.addEventListener("message",e=>{let n=e.data;if(ie(n))switch(n.type){case b:o.emit("iframe.credentials",n);break;case H:o.emit("iframe.userinfo",n);break}}));};var ue=new RegExp(`${O}\\/(\\d+\\.\\d+\\.\\d+)\\/(\\d+)\\/(iOS|Android)`),le=e=>{let n=e.split(".").map(t=>Number.parseInt(t,10));return [n[0]??0,n[1]??0,n[2]??0]},ae=(e,n)=>{for(let t=0;t<3;t++){if(e[t]>n[t])return true;if(e[t]<n[t])return false}return true},ce=e=>{let n=e.match(ue);if(!n)return null;let[,t,r,s]=n;if(!t||!r||s!=="iOS"&&s!=="Android")return null;let u=ae(le(t),D[s]);return {type:"native_app",platform:s,appVersion:t,buildNumber:r,meetsMinVersion:u}},w=()=>{if(!i())return {type:"web",meetsMinVersion:false};let e=ce(navigator.userAgent??"");return e||(window.parent!==window?{type:"iframe",meetsMinVersion:false}:{type:"web",meetsMinVersion:false})};var $=(e,n,t)=>new Promise(r=>{let s=false,u=l=>{s||(s=true,p(),clearTimeout(c),r(l));},p=o.on(n,l=>{let T=t(l);T&&u(T);}),c=setTimeout(()=>u(null),B);try{window.parent.postMessage({type:e,timestamp:Date.now()},"*");}catch{u(null);}}),K=()=>$(h,"iframe.credentials",a),z=()=>$(F,"iframe.userinfo",m);var J=e=>typeof e!="object"||e===null?false:typeof Reflect.get(e,"postMessage")=="function",M=e=>{let n=Reflect.get(window,"webkit");if(typeof n=="object"&&n!==null){let r=Reflect.get(n,"messageHandlers");if(typeof r=="object"&&r!==null){let s=Reflect.get(r,e);if(J(s))return s}}let t=Reflect.get(window,e);return J(t)?t:null},X=(e,n={})=>{let{pollIntervalMs:t=50,timeoutMs:r=1500}=n;return new Promise(s=>{let u=Date.now(),p=()=>{let c=M(e);if(c){s(c);return}if(Date.now()-u>=r){s(null);return}setTimeout(p,t);};p();})};var W=async(e,n,t,r)=>{let s=e.platform==="Android"?await X(A,{pollIntervalMs:V,timeoutMs:j}):M(A);if(!s)return null;let u=N(t);return new Promise(p=>{let c=false,l=E=>{c||(c=true,T(),te(),clearTimeout(re),p(E));},T=o.on(u,E=>{let I=r(E);I&&l(I);}),te=o.on(t,E=>{let I=r(E);I&&l(I);}),re=setTimeout(()=>l(null),q);try{s.postMessage({command:n,parameters:JSON.stringify({timestamp:Date.now(),endpoint:u})});}catch{l(null);}})},Y=e=>W(e,x,d,a),Z=e=>W(e,L,R,m);Q();var C=null,S=null,fe=e=>{switch(e.type){case "native_app":return e.meetsMinVersion?Y(e):Promise.resolve(null);case "iframe":return K();case "web":return Promise.resolve(null)}},pe=e=>{switch(e.type){case "native_app":return e.meetsMinVersion?Z(e):Promise.resolve(null);case "iframe":return z();case "web":return Promise.resolve(null)}},ee=e=>{C=e;},ne=()=>S||(S=fe(w()).then(e=>(e&&ee(e),e)).finally(()=>{S=null;}),S);i()&&o.on(d,e=>{let n=a(e);n&&ee(n);});var me=async()=>i()?C?C.token:(await ne())?.token??"":"",$e=async()=>i()?(await ne())?.token??"":"",de=async()=>i()?pe(w()):null;export{i as a,me as b,$e as c,de as d};
|
package/dist/types-CLujY9ck.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
interface Credentials {
|
|
2
|
-
uid: string;
|
|
3
|
-
token: string;
|
|
4
|
-
}
|
|
5
|
-
interface UserInfo {
|
|
6
|
-
userId: string | number;
|
|
7
|
-
username?: string;
|
|
8
|
-
nickname?: string;
|
|
9
|
-
avatar?: string | null;
|
|
10
|
-
phone?: string | null;
|
|
11
|
-
email?: string;
|
|
12
|
-
[key: string]: unknown;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type { Credentials as C, UserInfo as U };
|