fauna-api 1.0.679 → 1.0.682
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.
|
@@ -48,5 +48,8 @@ export declare class WhatsApp extends Account {
|
|
|
48
48
|
readonly phone: string;
|
|
49
49
|
constructor(authorization: Credentials, raw: any);
|
|
50
50
|
}
|
|
51
|
+
/** Opens the provider's consent page in a popup and returns it, or `null` when the browser
|
|
52
|
+
* blocked the popup. The popup opens before the request so the browser still counts it as
|
|
53
|
+
* part of the click. */
|
|
51
54
|
export declare function linkPlatform(credentials: Credentials, integration: Platform): Promise<WindowProxy | null>;
|
|
52
55
|
export declare function getAccounts(credentials: Credentials): Promise<Account[]>;
|
package/dist/src/integrations.js
CHANGED
|
@@ -176,20 +176,32 @@ function wrapAccount(authorization, platform, raw) {
|
|
|
176
176
|
case Platform.WHATSAPP: return new WhatsApp(authorization, raw);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
+
/** Opens the provider's consent page in a popup and returns it, or `null` when the browser
|
|
180
|
+
* blocked the popup. The popup opens before the request so the browser still counts it as
|
|
181
|
+
* part of the click. */
|
|
179
182
|
export async function linkPlatform(credentials, integration) {
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
const popup = window.open("", "_blank", "width=500,height=600");
|
|
184
|
+
try {
|
|
185
|
+
const response = await fetch(`${Fauna.getURL()}/integrations/link`, {
|
|
186
|
+
method: "POST",
|
|
187
|
+
headers: {
|
|
188
|
+
"Content-Type": "application/json",
|
|
189
|
+
"Authorization": `Token ${credentials.token}`
|
|
190
|
+
},
|
|
191
|
+
body: JSON.stringify({ integration })
|
|
192
|
+
});
|
|
193
|
+
if (!response.ok) {
|
|
194
|
+
throw new Error(await response.text());
|
|
195
|
+
}
|
|
196
|
+
const { url } = await response.json();
|
|
197
|
+
if (popup)
|
|
198
|
+
popup.location.href = url;
|
|
199
|
+
return popup;
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
popup?.close();
|
|
203
|
+
throw err;
|
|
190
204
|
}
|
|
191
|
-
const { url } = await response.json();
|
|
192
|
-
return window.open(url, "_blank", "width=500,height=600");
|
|
193
205
|
}
|
|
194
206
|
export async function getAccounts(credentials) {
|
|
195
207
|
const response = await fetch(`${Fauna.getURL()}/integrations/accounts`, {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Fauna } from "fauna-api";
|
|
2
|
+
import { sendInformaticToast } from "./toast.js";
|
|
2
3
|
import gsap from "gsap";
|
|
3
4
|
// Brand logos as inline SVG (currentColor-free, real brand marks) so the
|
|
4
5
|
// connections panel reads as a polished product surface rather than generic
|
|
@@ -50,13 +51,17 @@ export function createConnections(credentials, options = {}) {
|
|
|
50
51
|
grid.className = 'connections-grid';
|
|
51
52
|
root.appendChild(grid);
|
|
52
53
|
function fail(err) {
|
|
53
|
-
|
|
54
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
55
|
+
if (options.onError)
|
|
56
|
+
options.onError(error);
|
|
57
|
+
else
|
|
58
|
+
void sendInformaticToast(error.message || 'Could not connect.', 'error');
|
|
54
59
|
}
|
|
55
60
|
async function connect(platform) {
|
|
56
61
|
try {
|
|
57
62
|
const popup = await Fauna.Integrations.linkPlatform(credentials, platform);
|
|
58
63
|
if (!popup)
|
|
59
|
-
return;
|
|
64
|
+
return fail(new Error('Allow popups for this site to connect.'));
|
|
60
65
|
// Refresh once the consent popup closes.
|
|
61
66
|
const timer = setInterval(async () => {
|
|
62
67
|
if (popup.closed) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fauna-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.682",
|
|
4
4
|
"description": "The Fauna SDK: accounts, Drive, groups, calendar, chats, payments and every Fauna app (Parrot, Marmot, Magpie, Cicada, Ant, Termite), plus React UI.",
|
|
5
5
|
"homepage": "https://docs.faunakit.com",
|
|
6
6
|
"repository": {
|