@arinova-ai/spaces-sdk 0.1.3 → 0.1.4
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.ts +17 -0
- package/dist/index.js +36 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,23 @@ export declare class Arinova {
|
|
|
64
64
|
* Returns the token response on success.
|
|
65
65
|
*/
|
|
66
66
|
login(): Promise<TokenResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Connect to Arinova — auto-detects iframe vs standalone.
|
|
69
|
+
* In iframe: listens for postMessage from parent (Arinova Chat).
|
|
70
|
+
* Standalone: falls back to PKCE login popup.
|
|
71
|
+
*/
|
|
72
|
+
connect(options?: {
|
|
73
|
+
timeout?: number;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
user: TokenResponse["user"];
|
|
76
|
+
accessToken: string;
|
|
77
|
+
agents: {
|
|
78
|
+
id: string;
|
|
79
|
+
name: string;
|
|
80
|
+
description: string | null;
|
|
81
|
+
avatarUrl: string | null;
|
|
82
|
+
}[];
|
|
83
|
+
}>;
|
|
67
84
|
/**
|
|
68
85
|
* Handle the OAuth callback (call this on your redirect_uri page).
|
|
69
86
|
* Reads code and state from URL, exchanges for token.
|
package/dist/index.js
CHANGED
|
@@ -89,6 +89,42 @@ export class Arinova {
|
|
|
89
89
|
}, 300000);
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Connect to Arinova — auto-detects iframe vs standalone.
|
|
94
|
+
* In iframe: listens for postMessage from parent (Arinova Chat).
|
|
95
|
+
* Standalone: falls back to PKCE login popup.
|
|
96
|
+
*/
|
|
97
|
+
async connect(options) {
|
|
98
|
+
const timeout = options?.timeout ?? 5000;
|
|
99
|
+
const inIframe = typeof window !== "undefined" && window.self !== window.top;
|
|
100
|
+
if (!inIframe) {
|
|
101
|
+
const token = await this.login();
|
|
102
|
+
return { user: token.user, accessToken: token.access_token, agents: [] };
|
|
103
|
+
}
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
let settled = false;
|
|
106
|
+
const timer = setTimeout(() => {
|
|
107
|
+
if (!settled) {
|
|
108
|
+
settled = true;
|
|
109
|
+
window.removeEventListener("message", handler);
|
|
110
|
+
reject(new Error("connect timeout"));
|
|
111
|
+
}
|
|
112
|
+
}, timeout);
|
|
113
|
+
const handler = (event) => {
|
|
114
|
+
if (event.data?.type !== "arinova:auth")
|
|
115
|
+
return;
|
|
116
|
+
if (settled)
|
|
117
|
+
return;
|
|
118
|
+
settled = true;
|
|
119
|
+
clearTimeout(timer);
|
|
120
|
+
window.removeEventListener("message", handler);
|
|
121
|
+
const payload = event.data.payload;
|
|
122
|
+
this.accessToken = payload.accessToken;
|
|
123
|
+
resolve(payload);
|
|
124
|
+
};
|
|
125
|
+
window.addEventListener("message", handler);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
92
128
|
/**
|
|
93
129
|
* Handle the OAuth callback (call this on your redirect_uri page).
|
|
94
130
|
* Reads code and state from URL, exchanges for token.
|