@embarkai/ui-kit 0.4.24 → 0.4.26
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/iframe/index.html +1 -1
- package/dist/iframe/main.js +119 -28
- package/dist/index.cjs +26253 -6
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +26159 -86
- package/dist/styles.css +1 -1
- package/package.json +1 -4
- package/dist/auth-KSSZW2NZ.js +0 -115
- package/dist/auth-WPQMCF4N.cjs +0 -115
- package/dist/chunk-47XANJVP.js +0 -20163
- package/dist/chunk-6QTXBMNL.js +0 -1091
- package/dist/chunk-DACL62OU.cjs +0 -29
- package/dist/chunk-DBFKMKYT.js +0 -29
- package/dist/chunk-DW3342W5.cjs +0 -20163
- package/dist/chunk-IBH4PFA3.cjs +0 -1515
- package/dist/chunk-O3DVVB7K.cjs +0 -1091
- package/dist/chunk-PIZB3BDS.js +0 -1515
- package/dist/clients-DH5SX5FS.js +0 -78
- package/dist/clients-IO5M2UJG.cjs +0 -78
- package/dist/cloudStorage-SXE7HVID.cjs +0 -207
- package/dist/cloudStorage-WASWQ4KL.js +0 -207
- package/dist/hyperbridge-6CO7NULG.js +0 -930
- package/dist/hyperbridge-OPUF7VNS.cjs +0 -930
- package/dist/iframe-manager-LJUXSMW2.js +0 -14
- package/dist/iframe-manager-QMSGWWFA.cjs +0 -14
- package/dist/passkey-AS5MMN6X.cjs +0 -19
- package/dist/passkey-FG3L2F7K.js +0 -19
- package/dist/passkey-R5DNDC3P.js +0 -13
- package/dist/passkey-UX6CJ6LS.cjs +0 -13
- package/dist/profile-U27AANIS.js +0 -14
- package/dist/profile-X2IOH3GP.cjs +0 -14
- package/dist/vaultClient-K7QTKKLN.cjs +0 -50
- package/dist/vaultClient-NB6LJPRV.js +0 -50
package/dist/clients-DH5SX5FS.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
COMPAT_CREATE_ABI,
|
|
3
|
-
FUNDER_PK,
|
|
4
|
-
MAX_BUNDLER_VERIFICATION_GAS,
|
|
5
|
-
PAYMASTER_POSTOP_GAS,
|
|
6
|
-
PAYMASTER_POSTOP_GAS_LIMIT,
|
|
7
|
-
PAYMASTER_VERIFICATION_GAS,
|
|
8
|
-
PAYMASTER_VERIFICATION_GAS_LIMIT,
|
|
9
|
-
SALT_ZERO,
|
|
10
|
-
SALT_ZERO_UINT256,
|
|
11
|
-
changeNickname,
|
|
12
|
-
checkNicknameAvailability,
|
|
13
|
-
createAccountSession,
|
|
14
|
-
deployAccount,
|
|
15
|
-
depositForSmartAccount,
|
|
16
|
-
entryPointDepositAbi,
|
|
17
|
-
executeAbi,
|
|
18
|
-
executeBatchAbi,
|
|
19
|
-
getAllSmartAccounts,
|
|
20
|
-
getBundlerClient,
|
|
21
|
-
getDashboardApiUrl,
|
|
22
|
-
getEntryPointDeposit,
|
|
23
|
-
getExplorerUrl,
|
|
24
|
-
getNicknameInfo,
|
|
25
|
-
getShareVaultUrl,
|
|
26
|
-
getSmartAccountForChain,
|
|
27
|
-
getTssUrl,
|
|
28
|
-
lumiaBeamTestnet,
|
|
29
|
-
lumiaPrisma,
|
|
30
|
-
prepareBatchUserOperation,
|
|
31
|
-
prepareUserOperation,
|
|
32
|
-
registerSmartAccountAddress,
|
|
33
|
-
resolveNickname,
|
|
34
|
-
sendBatchUserOperation,
|
|
35
|
-
sendUserOperation,
|
|
36
|
-
signTypedData
|
|
37
|
-
} from "./chunk-47XANJVP.js";
|
|
38
|
-
import "./chunk-6QTXBMNL.js";
|
|
39
|
-
import "./chunk-PIZB3BDS.js";
|
|
40
|
-
import "./chunk-DBFKMKYT.js";
|
|
41
|
-
export {
|
|
42
|
-
COMPAT_CREATE_ABI,
|
|
43
|
-
FUNDER_PK,
|
|
44
|
-
MAX_BUNDLER_VERIFICATION_GAS,
|
|
45
|
-
PAYMASTER_POSTOP_GAS,
|
|
46
|
-
PAYMASTER_POSTOP_GAS_LIMIT,
|
|
47
|
-
PAYMASTER_VERIFICATION_GAS,
|
|
48
|
-
PAYMASTER_VERIFICATION_GAS_LIMIT,
|
|
49
|
-
SALT_ZERO,
|
|
50
|
-
SALT_ZERO_UINT256,
|
|
51
|
-
changeNickname,
|
|
52
|
-
checkNicknameAvailability,
|
|
53
|
-
createAccountSession,
|
|
54
|
-
deployAccount,
|
|
55
|
-
depositForSmartAccount,
|
|
56
|
-
entryPointDepositAbi,
|
|
57
|
-
executeAbi,
|
|
58
|
-
executeBatchAbi,
|
|
59
|
-
getAllSmartAccounts,
|
|
60
|
-
getBundlerClient,
|
|
61
|
-
getDashboardApiUrl,
|
|
62
|
-
getEntryPointDeposit,
|
|
63
|
-
getExplorerUrl,
|
|
64
|
-
getNicknameInfo,
|
|
65
|
-
getShareVaultUrl,
|
|
66
|
-
getSmartAccountForChain,
|
|
67
|
-
getTssUrl,
|
|
68
|
-
lumiaBeamTestnet,
|
|
69
|
-
lumiaPrisma,
|
|
70
|
-
prepareBatchUserOperation,
|
|
71
|
-
prepareUserOperation,
|
|
72
|
-
registerSmartAccountAddress,
|
|
73
|
-
resolveNickname,
|
|
74
|
-
sendBatchUserOperation,
|
|
75
|
-
sendUserOperation,
|
|
76
|
-
signTypedData
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=clients-DH5SX5FS.js.map
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var _chunkDW3342W5cjs = require('./chunk-DW3342W5.cjs');
|
|
38
|
-
require('./chunk-O3DVVB7K.cjs');
|
|
39
|
-
require('./chunk-IBH4PFA3.cjs');
|
|
40
|
-
require('./chunk-DACL62OU.cjs');
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
exports.COMPAT_CREATE_ABI = _chunkDW3342W5cjs.COMPAT_CREATE_ABI; exports.FUNDER_PK = _chunkDW3342W5cjs.FUNDER_PK; exports.MAX_BUNDLER_VERIFICATION_GAS = _chunkDW3342W5cjs.MAX_BUNDLER_VERIFICATION_GAS; exports.PAYMASTER_POSTOP_GAS = _chunkDW3342W5cjs.PAYMASTER_POSTOP_GAS; exports.PAYMASTER_POSTOP_GAS_LIMIT = _chunkDW3342W5cjs.PAYMASTER_POSTOP_GAS_LIMIT; exports.PAYMASTER_VERIFICATION_GAS = _chunkDW3342W5cjs.PAYMASTER_VERIFICATION_GAS; exports.PAYMASTER_VERIFICATION_GAS_LIMIT = _chunkDW3342W5cjs.PAYMASTER_VERIFICATION_GAS_LIMIT; exports.SALT_ZERO = _chunkDW3342W5cjs.SALT_ZERO; exports.SALT_ZERO_UINT256 = _chunkDW3342W5cjs.SALT_ZERO_UINT256; exports.changeNickname = _chunkDW3342W5cjs.changeNickname; exports.checkNicknameAvailability = _chunkDW3342W5cjs.checkNicknameAvailability; exports.createAccountSession = _chunkDW3342W5cjs.createAccountSession; exports.deployAccount = _chunkDW3342W5cjs.deployAccount; exports.depositForSmartAccount = _chunkDW3342W5cjs.depositForSmartAccount; exports.entryPointDepositAbi = _chunkDW3342W5cjs.entryPointDepositAbi; exports.executeAbi = _chunkDW3342W5cjs.executeAbi; exports.executeBatchAbi = _chunkDW3342W5cjs.executeBatchAbi; exports.getAllSmartAccounts = _chunkDW3342W5cjs.getAllSmartAccounts; exports.getBundlerClient = _chunkDW3342W5cjs.getBundlerClient; exports.getDashboardApiUrl = _chunkDW3342W5cjs.getDashboardApiUrl; exports.getEntryPointDeposit = _chunkDW3342W5cjs.getEntryPointDeposit; exports.getExplorerUrl = _chunkDW3342W5cjs.getExplorerUrl; exports.getNicknameInfo = _chunkDW3342W5cjs.getNicknameInfo; exports.getShareVaultUrl = _chunkDW3342W5cjs.getShareVaultUrl; exports.getSmartAccountForChain = _chunkDW3342W5cjs.getSmartAccountForChain; exports.getTssUrl = _chunkDW3342W5cjs.getTssUrl; exports.lumiaBeamTestnet = _chunkDW3342W5cjs.lumiaBeamTestnet; exports.lumiaPrisma = _chunkDW3342W5cjs.lumiaPrisma; exports.prepareBatchUserOperation = _chunkDW3342W5cjs.prepareBatchUserOperation; exports.prepareUserOperation = _chunkDW3342W5cjs.prepareUserOperation; exports.registerSmartAccountAddress = _chunkDW3342W5cjs.registerSmartAccountAddress; exports.resolveNickname = _chunkDW3342W5cjs.resolveNickname; exports.sendBatchUserOperation = _chunkDW3342W5cjs.sendBatchUserOperation; exports.sendUserOperation = _chunkDW3342W5cjs.sendUserOperation; exports.signTypedData = _chunkDW3342W5cjs.signTypedData;
|
|
78
|
-
//# sourceMappingURL=clients-IO5M2UJG.cjs.map
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('./chunk-DACL62OU.cjs');
|
|
2
|
-
|
|
3
|
-
// src/internal/cloudStorage.ts
|
|
4
|
-
var GoogleDriveProvider = class {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.name = "Google Drive";
|
|
7
|
-
this.id = "google-drive";
|
|
8
|
-
this.icon = "\u{1F4C1}";
|
|
9
|
-
// Can be replaced with proper icon
|
|
10
|
-
this.accessToken = null;
|
|
11
|
-
this.CLIENT_ID = "41560291859-hjqblt3jb80e268i0nafeu4m89eomhg3.apps.googleusercontent.com";
|
|
12
|
-
this.DISCOVERY_DOC = "https://www.googleapis.com/discovery/v1/apis/drive/v3/rest";
|
|
13
|
-
this.SCOPES = "https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.appdata";
|
|
14
|
-
this.gapiInitialized = false;
|
|
15
|
-
this.gisInitialized = false;
|
|
16
|
-
this.initializeAPIs();
|
|
17
|
-
}
|
|
18
|
-
async initializeAPIs() {
|
|
19
|
-
if (!window.gapi) {
|
|
20
|
-
await this.loadScript("https://apis.google.com/js/api.js");
|
|
21
|
-
}
|
|
22
|
-
if (!_optionalChain([window, 'access', _ => _.google, 'optionalAccess', _2 => _2.accounts])) {
|
|
23
|
-
await this.loadScript("https://accounts.google.com/gsi/client");
|
|
24
|
-
}
|
|
25
|
-
if (!this.gapiInitialized) {
|
|
26
|
-
await new Promise((resolve) => {
|
|
27
|
-
window.gapi.load("client", resolve);
|
|
28
|
-
});
|
|
29
|
-
await window.gapi.client.init({
|
|
30
|
-
discoveryDocs: [this.DISCOVERY_DOC]
|
|
31
|
-
});
|
|
32
|
-
this.gapiInitialized = true;
|
|
33
|
-
}
|
|
34
|
-
if (!this.gisInitialized) {
|
|
35
|
-
this.gisInitialized = true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
loadScript(src) {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
if (document.querySelector(`script[src="${src}"]`)) {
|
|
41
|
-
resolve();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const script = document.createElement("script");
|
|
45
|
-
script.src = src;
|
|
46
|
-
script.onload = () => resolve();
|
|
47
|
-
script.onerror = () => reject(new Error(`Failed to load ${src}`));
|
|
48
|
-
document.head.appendChild(script);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
isAvailable() {
|
|
52
|
-
return !!this.CLIENT_ID && typeof window !== "undefined";
|
|
53
|
-
}
|
|
54
|
-
async authenticate() {
|
|
55
|
-
if (!this.isAvailable()) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
"Google Drive integration is not available in this environment"
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
await this.initializeAPIs();
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
try {
|
|
63
|
-
const tokenClient = window.google.accounts.oauth2.initTokenClient({
|
|
64
|
-
client_id: this.CLIENT_ID,
|
|
65
|
-
scope: this.SCOPES,
|
|
66
|
-
callback: (response) => {
|
|
67
|
-
if (response.error) {
|
|
68
|
-
console.error("[GoogleDrive] Authentication error:", response.error);
|
|
69
|
-
reject(new Error(`Google Drive authentication failed: ${response.error}`));
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.accessToken = response.access_token;
|
|
73
|
-
window.gapi.client.setToken({ access_token: this.accessToken });
|
|
74
|
-
resolve(true);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
tokenClient.requestAccessToken({ prompt: "consent" });
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error("[GoogleDrive] Authentication initialization failed:", error);
|
|
80
|
-
reject(new Error(`Google Drive authentication setup failed: ${error}`));
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
isAuthenticated() {
|
|
85
|
-
return !!this.accessToken;
|
|
86
|
-
}
|
|
87
|
-
async signOut() {
|
|
88
|
-
if (this.accessToken) {
|
|
89
|
-
_optionalChain([window, 'access', _3 => _3.google, 'optionalAccess', _4 => _4.accounts, 'access', _5 => _5.oauth2, 'access', _6 => _6.revoke, 'call', _7 => _7(this.accessToken)]);
|
|
90
|
-
this.accessToken = null;
|
|
91
|
-
_optionalChain([window, 'access', _8 => _8.gapi, 'optionalAccess', _9 => _9.client, 'access', _10 => _10.setToken, 'call', _11 => _11(null)]);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async upload(fileName, content, usePrivateStorage = true) {
|
|
95
|
-
if (!this.isAuthenticated()) {
|
|
96
|
-
throw new Error("Not authenticated with Google Drive");
|
|
97
|
-
}
|
|
98
|
-
await this.initializeAPIs();
|
|
99
|
-
if (usePrivateStorage) {
|
|
100
|
-
try {
|
|
101
|
-
const fileId = await this.uploadToAppDataFolder(fileName, content);
|
|
102
|
-
return fileId;
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.warn("[GoogleDrive] AppDataFolder upload failed, trying fallback to regular folder:", error);
|
|
105
|
-
const fileId = await this.uploadToAppFolder(fileName, content);
|
|
106
|
-
return fileId;
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
try {
|
|
110
|
-
const fileId = await this.uploadToAppFolder(fileName, content);
|
|
111
|
-
return fileId;
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error("[GoogleDrive] Upload failed:", error);
|
|
114
|
-
throw new Error(
|
|
115
|
-
`Failed to upload to Google Drive: ${error instanceof Error ? error.message : String(error)}`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
async uploadToAppDataFolder(fileName, content) {
|
|
121
|
-
const metadata = {
|
|
122
|
-
name: fileName,
|
|
123
|
-
parents: ["appDataFolder"]
|
|
124
|
-
// Store in app-specific folder for privacy
|
|
125
|
-
};
|
|
126
|
-
return this.performUpload(metadata, content);
|
|
127
|
-
}
|
|
128
|
-
async uploadToAppFolder(fileName, content) {
|
|
129
|
-
const folderName = "EmbarkAI Wallet Backups";
|
|
130
|
-
const folderId = await this.findOrCreateFolder(folderName);
|
|
131
|
-
const metadata = {
|
|
132
|
-
name: fileName,
|
|
133
|
-
parents: [folderId]
|
|
134
|
-
};
|
|
135
|
-
return this.performUpload(metadata, content);
|
|
136
|
-
}
|
|
137
|
-
async findOrCreateFolder(folderName) {
|
|
138
|
-
const searchResponse = await fetch(
|
|
139
|
-
`https://www.googleapis.com/drive/v3/files?q=name='${folderName}' and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
140
|
-
{
|
|
141
|
-
headers: { Authorization: `Bearer ${this.accessToken}` },
|
|
142
|
-
credentials: "include"
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
if (!searchResponse.ok) {
|
|
146
|
-
throw new Error(`Failed to search for folder: ${searchResponse.status}`);
|
|
147
|
-
}
|
|
148
|
-
const searchResult = await searchResponse.json();
|
|
149
|
-
if (searchResult.files && searchResult.files.length > 0) {
|
|
150
|
-
return searchResult.files[0].id;
|
|
151
|
-
}
|
|
152
|
-
const createResponse = await fetch("https://www.googleapis.com/drive/v3/files", {
|
|
153
|
-
method: "POST",
|
|
154
|
-
headers: {
|
|
155
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
156
|
-
"Content-Type": "application/json"
|
|
157
|
-
},
|
|
158
|
-
credentials: "include",
|
|
159
|
-
body: JSON.stringify({
|
|
160
|
-
name: folderName,
|
|
161
|
-
mimeType: "application/vnd.google-apps.folder"
|
|
162
|
-
})
|
|
163
|
-
});
|
|
164
|
-
if (!createResponse.ok) {
|
|
165
|
-
throw new Error(`Failed to create folder: ${createResponse.status}`);
|
|
166
|
-
}
|
|
167
|
-
const createResult = await createResponse.json();
|
|
168
|
-
return createResult.id;
|
|
169
|
-
}
|
|
170
|
-
async performUpload(metadata, content) {
|
|
171
|
-
const form = new FormData();
|
|
172
|
-
form.append("metadata", new Blob([JSON.stringify(metadata)], { type: "application/json" }));
|
|
173
|
-
form.append("file", new Blob([content], { type: "application/json" }));
|
|
174
|
-
const response = await fetch(
|
|
175
|
-
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
|
|
176
|
-
{
|
|
177
|
-
method: "POST",
|
|
178
|
-
headers: {
|
|
179
|
-
Authorization: `Bearer ${this.accessToken}`
|
|
180
|
-
},
|
|
181
|
-
credentials: "include",
|
|
182
|
-
body: form
|
|
183
|
-
}
|
|
184
|
-
);
|
|
185
|
-
if (!response.ok) {
|
|
186
|
-
const errorText = await response.text();
|
|
187
|
-
throw new Error(
|
|
188
|
-
`Google Drive upload failed: ${response.status} ${response.statusText} - ${errorText}`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
const result = await response.json();
|
|
192
|
-
return result.id;
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
function getAvailableCloudProviders() {
|
|
196
|
-
const providers = [];
|
|
197
|
-
const googleDrive = new GoogleDriveProvider();
|
|
198
|
-
if (googleDrive.isAvailable()) {
|
|
199
|
-
providers.push(googleDrive);
|
|
200
|
-
}
|
|
201
|
-
return providers;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
exports.GoogleDriveProvider = GoogleDriveProvider; exports.getAvailableCloudProviders = getAvailableCloudProviders;
|
|
207
|
-
//# sourceMappingURL=cloudStorage-SXE7HVID.cjs.map
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import "./chunk-DBFKMKYT.js";
|
|
2
|
-
|
|
3
|
-
// src/internal/cloudStorage.ts
|
|
4
|
-
var GoogleDriveProvider = class {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.name = "Google Drive";
|
|
7
|
-
this.id = "google-drive";
|
|
8
|
-
this.icon = "\u{1F4C1}";
|
|
9
|
-
// Can be replaced with proper icon
|
|
10
|
-
this.accessToken = null;
|
|
11
|
-
this.CLIENT_ID = "41560291859-hjqblt3jb80e268i0nafeu4m89eomhg3.apps.googleusercontent.com";
|
|
12
|
-
this.DISCOVERY_DOC = "https://www.googleapis.com/discovery/v1/apis/drive/v3/rest";
|
|
13
|
-
this.SCOPES = "https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.appdata";
|
|
14
|
-
this.gapiInitialized = false;
|
|
15
|
-
this.gisInitialized = false;
|
|
16
|
-
this.initializeAPIs();
|
|
17
|
-
}
|
|
18
|
-
async initializeAPIs() {
|
|
19
|
-
if (!window.gapi) {
|
|
20
|
-
await this.loadScript("https://apis.google.com/js/api.js");
|
|
21
|
-
}
|
|
22
|
-
if (!window.google?.accounts) {
|
|
23
|
-
await this.loadScript("https://accounts.google.com/gsi/client");
|
|
24
|
-
}
|
|
25
|
-
if (!this.gapiInitialized) {
|
|
26
|
-
await new Promise((resolve) => {
|
|
27
|
-
window.gapi.load("client", resolve);
|
|
28
|
-
});
|
|
29
|
-
await window.gapi.client.init({
|
|
30
|
-
discoveryDocs: [this.DISCOVERY_DOC]
|
|
31
|
-
});
|
|
32
|
-
this.gapiInitialized = true;
|
|
33
|
-
}
|
|
34
|
-
if (!this.gisInitialized) {
|
|
35
|
-
this.gisInitialized = true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
loadScript(src) {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
if (document.querySelector(`script[src="${src}"]`)) {
|
|
41
|
-
resolve();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const script = document.createElement("script");
|
|
45
|
-
script.src = src;
|
|
46
|
-
script.onload = () => resolve();
|
|
47
|
-
script.onerror = () => reject(new Error(`Failed to load ${src}`));
|
|
48
|
-
document.head.appendChild(script);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
isAvailable() {
|
|
52
|
-
return !!this.CLIENT_ID && typeof window !== "undefined";
|
|
53
|
-
}
|
|
54
|
-
async authenticate() {
|
|
55
|
-
if (!this.isAvailable()) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
"Google Drive integration is not available in this environment"
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
await this.initializeAPIs();
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
try {
|
|
63
|
-
const tokenClient = window.google.accounts.oauth2.initTokenClient({
|
|
64
|
-
client_id: this.CLIENT_ID,
|
|
65
|
-
scope: this.SCOPES,
|
|
66
|
-
callback: (response) => {
|
|
67
|
-
if (response.error) {
|
|
68
|
-
console.error("[GoogleDrive] Authentication error:", response.error);
|
|
69
|
-
reject(new Error(`Google Drive authentication failed: ${response.error}`));
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.accessToken = response.access_token;
|
|
73
|
-
window.gapi.client.setToken({ access_token: this.accessToken });
|
|
74
|
-
resolve(true);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
tokenClient.requestAccessToken({ prompt: "consent" });
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error("[GoogleDrive] Authentication initialization failed:", error);
|
|
80
|
-
reject(new Error(`Google Drive authentication setup failed: ${error}`));
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
isAuthenticated() {
|
|
85
|
-
return !!this.accessToken;
|
|
86
|
-
}
|
|
87
|
-
async signOut() {
|
|
88
|
-
if (this.accessToken) {
|
|
89
|
-
window.google?.accounts.oauth2.revoke(this.accessToken);
|
|
90
|
-
this.accessToken = null;
|
|
91
|
-
window.gapi?.client.setToken(null);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async upload(fileName, content, usePrivateStorage = true) {
|
|
95
|
-
if (!this.isAuthenticated()) {
|
|
96
|
-
throw new Error("Not authenticated with Google Drive");
|
|
97
|
-
}
|
|
98
|
-
await this.initializeAPIs();
|
|
99
|
-
if (usePrivateStorage) {
|
|
100
|
-
try {
|
|
101
|
-
const fileId = await this.uploadToAppDataFolder(fileName, content);
|
|
102
|
-
return fileId;
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.warn("[GoogleDrive] AppDataFolder upload failed, trying fallback to regular folder:", error);
|
|
105
|
-
const fileId = await this.uploadToAppFolder(fileName, content);
|
|
106
|
-
return fileId;
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
try {
|
|
110
|
-
const fileId = await this.uploadToAppFolder(fileName, content);
|
|
111
|
-
return fileId;
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error("[GoogleDrive] Upload failed:", error);
|
|
114
|
-
throw new Error(
|
|
115
|
-
`Failed to upload to Google Drive: ${error instanceof Error ? error.message : String(error)}`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
async uploadToAppDataFolder(fileName, content) {
|
|
121
|
-
const metadata = {
|
|
122
|
-
name: fileName,
|
|
123
|
-
parents: ["appDataFolder"]
|
|
124
|
-
// Store in app-specific folder for privacy
|
|
125
|
-
};
|
|
126
|
-
return this.performUpload(metadata, content);
|
|
127
|
-
}
|
|
128
|
-
async uploadToAppFolder(fileName, content) {
|
|
129
|
-
const folderName = "EmbarkAI Wallet Backups";
|
|
130
|
-
const folderId = await this.findOrCreateFolder(folderName);
|
|
131
|
-
const metadata = {
|
|
132
|
-
name: fileName,
|
|
133
|
-
parents: [folderId]
|
|
134
|
-
};
|
|
135
|
-
return this.performUpload(metadata, content);
|
|
136
|
-
}
|
|
137
|
-
async findOrCreateFolder(folderName) {
|
|
138
|
-
const searchResponse = await fetch(
|
|
139
|
-
`https://www.googleapis.com/drive/v3/files?q=name='${folderName}' and mimeType='application/vnd.google-apps.folder' and trashed=false`,
|
|
140
|
-
{
|
|
141
|
-
headers: { Authorization: `Bearer ${this.accessToken}` },
|
|
142
|
-
credentials: "include"
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
if (!searchResponse.ok) {
|
|
146
|
-
throw new Error(`Failed to search for folder: ${searchResponse.status}`);
|
|
147
|
-
}
|
|
148
|
-
const searchResult = await searchResponse.json();
|
|
149
|
-
if (searchResult.files && searchResult.files.length > 0) {
|
|
150
|
-
return searchResult.files[0].id;
|
|
151
|
-
}
|
|
152
|
-
const createResponse = await fetch("https://www.googleapis.com/drive/v3/files", {
|
|
153
|
-
method: "POST",
|
|
154
|
-
headers: {
|
|
155
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
156
|
-
"Content-Type": "application/json"
|
|
157
|
-
},
|
|
158
|
-
credentials: "include",
|
|
159
|
-
body: JSON.stringify({
|
|
160
|
-
name: folderName,
|
|
161
|
-
mimeType: "application/vnd.google-apps.folder"
|
|
162
|
-
})
|
|
163
|
-
});
|
|
164
|
-
if (!createResponse.ok) {
|
|
165
|
-
throw new Error(`Failed to create folder: ${createResponse.status}`);
|
|
166
|
-
}
|
|
167
|
-
const createResult = await createResponse.json();
|
|
168
|
-
return createResult.id;
|
|
169
|
-
}
|
|
170
|
-
async performUpload(metadata, content) {
|
|
171
|
-
const form = new FormData();
|
|
172
|
-
form.append("metadata", new Blob([JSON.stringify(metadata)], { type: "application/json" }));
|
|
173
|
-
form.append("file", new Blob([content], { type: "application/json" }));
|
|
174
|
-
const response = await fetch(
|
|
175
|
-
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
|
|
176
|
-
{
|
|
177
|
-
method: "POST",
|
|
178
|
-
headers: {
|
|
179
|
-
Authorization: `Bearer ${this.accessToken}`
|
|
180
|
-
},
|
|
181
|
-
credentials: "include",
|
|
182
|
-
body: form
|
|
183
|
-
}
|
|
184
|
-
);
|
|
185
|
-
if (!response.ok) {
|
|
186
|
-
const errorText = await response.text();
|
|
187
|
-
throw new Error(
|
|
188
|
-
`Google Drive upload failed: ${response.status} ${response.statusText} - ${errorText}`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
const result = await response.json();
|
|
192
|
-
return result.id;
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
function getAvailableCloudProviders() {
|
|
196
|
-
const providers = [];
|
|
197
|
-
const googleDrive = new GoogleDriveProvider();
|
|
198
|
-
if (googleDrive.isAvailable()) {
|
|
199
|
-
providers.push(googleDrive);
|
|
200
|
-
}
|
|
201
|
-
return providers;
|
|
202
|
-
}
|
|
203
|
-
export {
|
|
204
|
-
GoogleDriveProvider,
|
|
205
|
-
getAvailableCloudProviders
|
|
206
|
-
};
|
|
207
|
-
//# sourceMappingURL=cloudStorage-WASWQ4KL.js.map
|