@onairosofficial/onairos-capacitor 0.1.3 → 0.1.5
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/OnairosofficialOnairosCapacitor.podspec +1 -1
- package/README.md +1 -1
- package/dist/onairos.capacitor.esm.js +509 -1
- package/dist/onairos.capacitor.esm.turbopack.js +509 -1
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosChatGPTNativePlugin.swift +187 -945
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosRNScrapers.swift +1800 -0
- package/ios/Sources/OnairosNativeConnectorsPlugin/OnairosSpotifyNativePlugin.swift +180 -629
- package/onairos.d.ts +24 -0
- package/package.json +5 -2
- package/src/assets/connectors/Linkedinicon.png +0 -0
- package/src/assets/connectors/Redditicon.png +0 -0
- package/src/assets/connectors/YouTubeicon2.png +0 -0
- package/src/assets/connectors/chatgpt.png +0 -0
- package/src/assets/connectors/claude.png +0 -0
- package/src/assets/connectors/instagram.png +0 -0
- package/src/assets/connectors/netflix.png +0 -0
- package/src/assets/connectors/pinterest.png +0 -0
- package/src/assets/connectors/sephora.png +0 -0
- package/src/assets/connectors/spotify.png +0 -0
- package/src/assets/connectors/tiktok.png +0 -0
- package/src/assets/permissions/onairos.png +0 -0
- package/src/assets/permissions/personalization.png +0 -0
- package/src/assets/permissions/public-profile-person.png +0 -0
- package/src/assets/permissions/raw-memories.png +0 -0
- package/src/capacitorConnectorCatalog.js +2 -6
- package/src/components/DataRequest.jsx +96 -532
- package/src/components/EmailAuth.jsx +4 -116
- package/src/components/PinSetup.jsx +39 -226
- package/src/components/SDKDesignPreview.jsx +33 -0
- package/src/components/SessionUserBar.jsx +2 -1
- package/src/components/TrainingScreen.jsx +18 -12
- package/src/components/UniversalOnboarding.jsx +191 -424
- package/src/components/WelcomeScreen.jsx +19 -12
- package/src/components/parity/NativeConnections.jsx +136 -0
- package/src/components/parity/NativeScreens.jsx +48 -0
- package/src/components/ui/PageLayout.jsx +7 -3
- package/src/nativeImport/ConnectorLoading.jsx +13 -0
- package/src/nativeImport/CustomImportSession.js +115 -0
- package/src/nativeImport/ImportIcon.jsx +29 -0
- package/src/nativeImport/ImportProgress.jsx +24 -0
- package/src/nativeImport/ImportStatus.jsx +9 -0
- package/src/nativeImport/NativeChatImport.jsx +28 -0
- package/src/nativeImport/NativeImportSession.js +123 -0
- package/src/nativeImport/NativeScraperImport.jsx +57 -0
- package/src/nativeImport/SmartFilter.jsx +28 -0
- package/src/nativeImport/customPayload.js +37 -0
- package/src/nativeImport/netflixExport.js +30 -0
- package/src/nativeImport/netflixHistory.js +28 -0
- package/src/nativeImport/netflixSession.js +59 -0
- package/src/nativeImport/rawHandoff.js +7 -0
- package/src/nativeImport/rn/config/api.js +5 -0
- package/src/nativeImport/rn/services/apiKeyService.js +2 -0
- package/src/nativeImport/rn/services/hingePayload.js +37 -0
- package/src/nativeImport/rn/services/nativeConversationImport.js +138 -0
- package/src/nativeImport/rn/services/nativeFileTransfer.js +127 -0
- package/src/nativeImport/rn/services/nativeRawRedaction.js +136 -0
- package/src/nativeImport/rn/services/netflixPayload.js +70 -0
- package/src/nativeImport/rn/services/rawMemoryPolicy.js +38 -0
- package/src/nativeImport/rn/services/sephoraPayload.js +166 -0
- package/src/nativeImport/rn/services/spotifyPayload.js +99 -0
- package/src/nativeImport/rn/source-manifest.json +45 -0
- package/src/nativeImport/rn/utils/importedFiles.js +74 -0
- package/src/nativeImport/rn/utils/nativeImportDates.js +45 -0
- package/src/nativeImport/rn/utils/nativeImportFileReceiver.js +51 -0
- package/src/nativeImport/rn/utils/nativeImportMetadata.js +74 -0
- package/src/nativeImport/rn/utils/nativeImportTopics.js +56 -0
- package/src/nativeImport/rn/utils/rawExportDelivery.js +12 -0
- package/src/nativeImport/rn/utils/webviewScripts/chatgptDiscovery.js +99 -0
- package/src/nativeImport/rn/utils/webviewScripts/claude.js +349 -0
- package/src/nativeImport/rn/utils/webviewScripts/gemini.js +356 -0
- package/src/nativeImport/rn/utils/webviewScripts/hinge.js +375 -0
- package/src/nativeImport/rn/utils/webviewScripts/instagram.js +152 -0
- package/src/nativeImport/rn/utils/webviewScripts/linkedin.js +825 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeChatGPTImport.js +202 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeChatGPTSession.js +63 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeImportFiles.js +132 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeImportProviders.js +80 -0
- package/src/nativeImport/rn/utils/webviewScripts/nativeLoginViewport.js +28 -0
- package/src/nativeImport/rn/utils/webviewScripts/netflix.js +257 -0
- package/src/nativeImport/rn/utils/webviewScripts/sephora.js +862 -0
- package/src/nativeImport/rn/utils/webviewScripts/sephoraSession.js +160 -0
- package/src/nativeImport/rn/utils/webviewScripts/spotify.js +1868 -0
- package/src/nativeImport/rn/utils/webviewScripts/telegram.js +630 -0
- package/src/nativeImport/rn/utils/webviewScripts/tiktok.js +2920 -0
- package/src/onairos.capacitor.jsx +14 -2
- package/src/onairos.core.jsx +3 -0
- package/src/onairosButton.jsx +23 -17
- package/src/styles/onairos-fonts.css +20 -0
- package/src/styles/onairos-native.css +709 -0
- package/src/styles/onairos-rn-parity.css +175 -0
- package/src/styles/sdkCssRegistry.js +83 -1
- package/src/styles/tailwind.capacitor.css +6 -0
- package/src/utils/capacitorPlugins.js +20 -12
- package/src/utils/nativeConnectorSession.js +18 -0
- package/src/utils/parityPolicy.js +41 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Synced from RN services/nativeFileTransfer.ts by scripts/sync-rn-connectors.cjs.
|
|
2
|
+
import { API_CONFIG, getUserAuthHeaders } from "../config/api.js";
|
|
3
|
+
import { getApiKey } from "./apiKeyService.js";
|
|
4
|
+
async function createNativeFileTransfer(platform, conversationIds, signal) {
|
|
5
|
+
const base = (API_CONFIG.getBaseUrl ? API_CONFIG.getBaseUrl() : API_CONFIG.BASE_URL).replace(/\/$/, "");
|
|
6
|
+
const sessionExpired = () => Object.assign(new Error("Your Onairos login expired. Please sign in again."), { code: "ONAIROS_SESSION_EXPIRED" });
|
|
7
|
+
const headers = {
|
|
8
|
+
...await getUserAuthHeaders().catch(() => {
|
|
9
|
+
throw sessionExpired();
|
|
10
|
+
}),
|
|
11
|
+
"x-api-key": getApiKey() || "",
|
|
12
|
+
"Content-Type": "application/json"
|
|
13
|
+
};
|
|
14
|
+
const root = `${base}/api/connectors/${encodeURIComponent(
|
|
15
|
+
platform
|
|
16
|
+
)}/hosted-import/native-files/session`;
|
|
17
|
+
let sessionId = "", uploadToken = "", ended = false;
|
|
18
|
+
async function call(body, cancel = false) {
|
|
19
|
+
const timeoutController = new AbortController(), abort = () => timeoutController.abort();
|
|
20
|
+
if (!cancel) {
|
|
21
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
22
|
+
if (signal.aborted) abort();
|
|
23
|
+
}
|
|
24
|
+
const timer = setTimeout(abort, 6e4);
|
|
25
|
+
try {
|
|
26
|
+
if (!cancel) {
|
|
27
|
+
const current = await getUserAuthHeaders().catch(() => {
|
|
28
|
+
throw sessionExpired();
|
|
29
|
+
});
|
|
30
|
+
if (current.Authorization !== headers.Authorization) throw sessionExpired();
|
|
31
|
+
}
|
|
32
|
+
if (timeoutController.signal.aborted) throw new Error("File transfer cancelled.");
|
|
33
|
+
const response = await fetch(sessionId ? `${root}/${sessionId}` : root, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
...headers,
|
|
37
|
+
...uploadToken ? { "x-native-import-upload-token": uploadToken } : {}
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify(body),
|
|
40
|
+
signal: timeoutController.signal
|
|
41
|
+
});
|
|
42
|
+
if (response.status === 401) throw sessionExpired();
|
|
43
|
+
const result = await response.json();
|
|
44
|
+
if (!response.ok || !result.success) {
|
|
45
|
+
const code = typeof result?.code === "string" && result.code ? result.code : "FILE_TRANSFER_FAILED";
|
|
46
|
+
throw Object.assign(new Error(code), {
|
|
47
|
+
code,
|
|
48
|
+
status: response.status
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
} finally {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
signal.removeEventListener("abort", abort);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const initial = await call({ includeFiles: true, conversationIds });
|
|
58
|
+
sessionId = initial.sessionId;
|
|
59
|
+
uploadToken = initial.uploadToken;
|
|
60
|
+
return {
|
|
61
|
+
async begin(file) {
|
|
62
|
+
return (await call({ action: "begin", file })).fileId;
|
|
63
|
+
},
|
|
64
|
+
async chunk(fileId, index, data) {
|
|
65
|
+
await call({ action: "chunk", fileId, index, data });
|
|
66
|
+
},
|
|
67
|
+
async finish(fileId) {
|
|
68
|
+
return (await call({ action: "finish", fileId })).file;
|
|
69
|
+
},
|
|
70
|
+
async complete() {
|
|
71
|
+
const result = await call({ action: "complete" });
|
|
72
|
+
ended = true;
|
|
73
|
+
return {
|
|
74
|
+
...result.fileDelivery,
|
|
75
|
+
manifestUrl: new URL(result.fileDelivery.manifestUrl, base).toString()
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
async cancel() {
|
|
79
|
+
if (ended) return;
|
|
80
|
+
ended = true;
|
|
81
|
+
await call({ action: "cancel" }, true);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function deliveryHeaders(delivery, url) {
|
|
86
|
+
const base = new URL(delivery.manifestUrl), target = new URL(url, base);
|
|
87
|
+
if (base.protocol !== "https:" || target.origin !== base.origin || target.username || target.password || target.hash || !(target.pathname === base.pathname || target.pathname.startsWith(base.pathname + "/")))
|
|
88
|
+
throw new Error("Untrusted file download URL");
|
|
89
|
+
if (delivery.expiresAt <= Date.now() || delivery.authorization.header !== "x-onairos-file-token" || !delivery.authorization.token)
|
|
90
|
+
throw new Error("File delivery expired or invalid");
|
|
91
|
+
return {
|
|
92
|
+
url: target.toString(),
|
|
93
|
+
headers: { "x-onairos-file-token": delivery.authorization.token }
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function listHostedImportFiles(delivery) {
|
|
97
|
+
const request = deliveryHeaders(delivery, delivery.manifestUrl);
|
|
98
|
+
const response = await fetch(request.url, {
|
|
99
|
+
headers: request.headers,
|
|
100
|
+
redirect: "error"
|
|
101
|
+
});
|
|
102
|
+
if (!response.ok)
|
|
103
|
+
throw new Error(`File manifest failed (${response.status})`);
|
|
104
|
+
return response.json();
|
|
105
|
+
}
|
|
106
|
+
async function downloadHostedImportFile(delivery, file, { range } = {}) {
|
|
107
|
+
if (!file.downloadable || !file.downloadUrl)
|
|
108
|
+
throw new Error("File is unavailable");
|
|
109
|
+
const request = deliveryHeaders(delivery, file.downloadUrl);
|
|
110
|
+
const response = await fetch(request.url, {
|
|
111
|
+
redirect: "error",
|
|
112
|
+
headers: { ...request.headers, ...range ? { Range: range } : {} }
|
|
113
|
+
});
|
|
114
|
+
if (!response.ok)
|
|
115
|
+
throw new Error(`File download failed (${response.status})`);
|
|
116
|
+
return {
|
|
117
|
+
file,
|
|
118
|
+
bytes: await response.arrayBuffer(),
|
|
119
|
+
contentType: response.headers.get("content-type") || file.mimeType,
|
|
120
|
+
contentRange: response.headers.get("content-range")
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
createNativeFileTransfer,
|
|
125
|
+
downloadHostedImportFile,
|
|
126
|
+
listHostedImportFiles
|
|
127
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Synced from RN services/nativeRawRedaction.ts by scripts/sync-rn-connectors.cjs.
|
|
2
|
+
import { API_CONFIG, getUserAuthHeaders } from "../config/api.js";
|
|
3
|
+
import { getApiKey } from "./apiKeyService.js";
|
|
4
|
+
const REQUEST_TIMEOUT_MS = 3e4;
|
|
5
|
+
const JOB_TIMEOUT_MS = 66e4;
|
|
6
|
+
const fail = (code = "PII_REDACTION_FAILED", status) => Object.assign(new Error("Raw-memory privacy processing did not complete."), { code, status });
|
|
7
|
+
async function protectNativeRawExport(payload, signal, expectedAuthorization) {
|
|
8
|
+
if (signal.aborted) throw fail("HOSTED_IMPORT_CANCELLED");
|
|
9
|
+
const headers = await getUserAuthHeaders().catch(() => {
|
|
10
|
+
throw fail("SDK_LOGIN_TOKEN_INVALID", 401);
|
|
11
|
+
});
|
|
12
|
+
const apiKey = getApiKey();
|
|
13
|
+
if (!apiKey) throw fail("RAW_MEMORIES_NOT_OFFERED", 403);
|
|
14
|
+
if (expectedAuthorization && headers.Authorization !== expectedAuthorization) throw fail("SDK_LOGIN_TOKEN_INVALID", 401);
|
|
15
|
+
const control = new AbortController();
|
|
16
|
+
const abort = () => control.abort();
|
|
17
|
+
signal.addEventListener("abort", abort);
|
|
18
|
+
if (signal.aborted) abort();
|
|
19
|
+
const timeout = setTimeout(abort, JOB_TIMEOUT_MS);
|
|
20
|
+
const base = (API_CONFIG.getBaseUrl ? API_CONFIG.getBaseUrl() : API_CONFIG.BASE_URL).replace(/\/$/, "");
|
|
21
|
+
const jobsUrl = `${base}/api/connectors/${payload.platform}/hosted-import/redact-export/jobs`;
|
|
22
|
+
const authHeaders = { ...headers, "x-api-key": apiKey, "Content-Type": "application/json" };
|
|
23
|
+
let jobId;
|
|
24
|
+
let completed = false;
|
|
25
|
+
const assertActive = () => {
|
|
26
|
+
if (signal.aborted) throw fail("HOSTED_IMPORT_CANCELLED");
|
|
27
|
+
if (control.signal.aborted) throw fail();
|
|
28
|
+
};
|
|
29
|
+
const checkAccount = async () => {
|
|
30
|
+
assertActive();
|
|
31
|
+
const current = await getUserAuthHeaders().catch(() => {
|
|
32
|
+
throw fail("SDK_LOGIN_TOKEN_INVALID", 401);
|
|
33
|
+
});
|
|
34
|
+
assertActive();
|
|
35
|
+
if (current.Authorization !== headers.Authorization || getApiKey() !== apiKey) throw fail("SDK_LOGIN_TOKEN_INVALID", 401);
|
|
36
|
+
};
|
|
37
|
+
const wait = (ms) => new Promise((resolve, reject) => {
|
|
38
|
+
const cancel = () => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
control.signal.removeEventListener("abort", cancel);
|
|
41
|
+
reject(fail(signal.aborted ? "HOSTED_IMPORT_CANCELLED" : "PII_REDACTION_FAILED"));
|
|
42
|
+
};
|
|
43
|
+
const timer = setTimeout(() => {
|
|
44
|
+
control.signal.removeEventListener("abort", cancel);
|
|
45
|
+
resolve();
|
|
46
|
+
}, ms);
|
|
47
|
+
control.signal.addEventListener("abort", cancel);
|
|
48
|
+
if (control.signal.aborted) cancel();
|
|
49
|
+
});
|
|
50
|
+
const request = async (method, url, body, timeoutMs = REQUEST_TIMEOUT_MS) => {
|
|
51
|
+
await checkAccount();
|
|
52
|
+
const attempt = new AbortController();
|
|
53
|
+
const cancel = () => attempt.abort();
|
|
54
|
+
control.signal.addEventListener("abort", cancel);
|
|
55
|
+
if (control.signal.aborted) cancel();
|
|
56
|
+
const timer = setTimeout(cancel, timeoutMs);
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch(url, { method, headers: authHeaders, signal: attempt.signal, ...body ? { body } : {} });
|
|
59
|
+
const result = await response.json().catch(() => null);
|
|
60
|
+
assertActive();
|
|
61
|
+
if (attempt.signal.aborted) throw fail();
|
|
62
|
+
if (!response.ok || result?.success !== true) {
|
|
63
|
+
const error = fail(typeof result?.code === "string" ? result.code : "PII_REDACTION_FAILED", response.status);
|
|
64
|
+
const retryAfter = response.headers?.get("Retry-After");
|
|
65
|
+
const seconds = retryAfter ? Number(retryAfter) : NaN;
|
|
66
|
+
const delay = Number.isFinite(seconds) ? seconds * 1e3 : retryAfter ? Date.parse(retryAfter) - Date.now() : NaN;
|
|
67
|
+
throw Object.assign(error, { retryAfterMs: Number.isFinite(delay) ? Math.max(2e3, delay) : 2e3 });
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
} catch (cause) {
|
|
71
|
+
assertActive();
|
|
72
|
+
if (cause?.code) throw cause;
|
|
73
|
+
throw fail();
|
|
74
|
+
} finally {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
control.signal.removeEventListener("abort", cancel);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
const created = await request("POST", jobsUrl, JSON.stringify(payload));
|
|
81
|
+
if (typeof created.jobId !== "string" || !/^[a-f0-9-]{36}$/.test(created.jobId) || created.status !== "processing") throw fail();
|
|
82
|
+
jobId = created.jobId;
|
|
83
|
+
let pollMs = 2e3;
|
|
84
|
+
while (true) {
|
|
85
|
+
await wait(pollMs);
|
|
86
|
+
let result;
|
|
87
|
+
try {
|
|
88
|
+
result = await request("GET", `${jobsUrl}/${jobId}/status`);
|
|
89
|
+
} catch (cause) {
|
|
90
|
+
const error = cause;
|
|
91
|
+
assertActive();
|
|
92
|
+
if (error.status === 429 || [502, 503, 504].includes(error.status || 0) || error.code === "PII_REDACTION_FAILED" && error.status === void 0) {
|
|
93
|
+
pollMs = Math.min(JOB_TIMEOUT_MS, Math.max(2e3, error.retryAfterMs || 2e3));
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
throw cause;
|
|
97
|
+
}
|
|
98
|
+
await checkAccount();
|
|
99
|
+
if (result.jobId !== jobId) throw fail();
|
|
100
|
+
pollMs = Number.isFinite(result.pollIntervalMs) ? Math.min(1e4, Math.max(1e3, result.pollIntervalMs)) : 2e3;
|
|
101
|
+
if (result.status === "processing") continue;
|
|
102
|
+
if (result.status !== "complete") throw fail(["SMART_FILTER_RECEIPT_REQUIRED", "HOSTED_IMPORT_SESSION_EXPIRED"].includes(result.code) ? result.code : "PII_REDACTION_FAILED");
|
|
103
|
+
let delivered;
|
|
104
|
+
try {
|
|
105
|
+
delivered = await request("GET", `${jobsUrl}/${jobId}`, void 0, JOB_TIMEOUT_MS);
|
|
106
|
+
} catch (cause) {
|
|
107
|
+
if (cause?.code === "PII_REDACTION_FAILED") throw fail("RAW_EXPORT_DELIVERY_FAILED", cause?.status);
|
|
108
|
+
throw cause;
|
|
109
|
+
}
|
|
110
|
+
await checkAccount();
|
|
111
|
+
if (delivered.jobId !== jobId || delivered.status !== "complete") throw fail("RAW_EXPORT_DELIVERY_FAILED");
|
|
112
|
+
const output = delivered.ephemeralPayload;
|
|
113
|
+
if (!output?.piiReceipt || output.piiReceipt.status !== "passed" || typeof output.piiReceipt.outputSha256 !== "string" || output.platform !== payload.platform || output.ephemeral !== true || output.persisted !== false || !Array.isArray(output.conversations) || output.conversations.length !== payload.conversations.length || output.conversations.some((chat, index) => !chat?.piiReceipt || chat.piiReceipt.status !== "passed" || chat.conversationId !== payload.conversations[index].conversationId)) throw fail("SMART_FILTER_RECEIPT_REQUIRED");
|
|
114
|
+
assertActive();
|
|
115
|
+
completed = true;
|
|
116
|
+
return output;
|
|
117
|
+
}
|
|
118
|
+
} finally {
|
|
119
|
+
clearTimeout(timeout);
|
|
120
|
+
signal.removeEventListener("abort", abort);
|
|
121
|
+
if (jobId) {
|
|
122
|
+
const cleanup = new AbortController();
|
|
123
|
+
const timer = setTimeout(() => cleanup.abort(), 5e3);
|
|
124
|
+
try {
|
|
125
|
+
await fetch(`${jobsUrl}/${jobId}`, { method: "DELETE", headers: authHeaders, signal: cleanup.signal });
|
|
126
|
+
} catch {
|
|
127
|
+
} finally {
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (completed) await checkAccount();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
protectNativeRawExport
|
|
136
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Generated pure mapping from RN services/netflixDataService.ts.
|
|
2
|
+
export function buildPayload(data){
|
|
3
|
+
const Platform={OS:"ios"};
|
|
4
|
+
const mobileMetadata = {
|
|
5
|
+
platform: Platform.OS,
|
|
6
|
+
source: "webview-api",
|
|
7
|
+
appVersion: "1.0.0",
|
|
8
|
+
osVersion: Platform.OS === "ios" ? "17.0" : Platform.OS,
|
|
9
|
+
deviceModel: Platform.OS === "ios" ? "iPhone" : "Android",
|
|
10
|
+
isOfflineSync: false,
|
|
11
|
+
extractedAt: (/* @__PURE__ */new Date()).toISOString(),
|
|
12
|
+
tokenExpiry: data.tokenExpiry
|
|
13
|
+
};
|
|
14
|
+
const requestBody = {
|
|
15
|
+
platform: "mobile-netflix",
|
|
16
|
+
dataType: "streaming",
|
|
17
|
+
data: {
|
|
18
|
+
viewingHistory: (data.viewingHistory?.items || []).map(item => ({
|
|
19
|
+
videoId: item.videoId,
|
|
20
|
+
title: item.title,
|
|
21
|
+
type: item.type,
|
|
22
|
+
seriesTitle: item.seriesTitle,
|
|
23
|
+
seasonNumber: item.seasonNumber,
|
|
24
|
+
episodeNumber: item.episodeNumber,
|
|
25
|
+
watchedAt: item.watchedAt,
|
|
26
|
+
watchDuration: item.watchDuration,
|
|
27
|
+
totalDuration: item.totalDuration,
|
|
28
|
+
percentWatched: item.percentWatched,
|
|
29
|
+
imageUrl: item.imageUrl,
|
|
30
|
+
genres: item.genres,
|
|
31
|
+
date: item.date
|
|
32
|
+
})),
|
|
33
|
+
myList: (data.myList || []).map(item => ({
|
|
34
|
+
videoId: item.videoId,
|
|
35
|
+
title: item.title,
|
|
36
|
+
type: item.type,
|
|
37
|
+
addedAt: item.addedAt,
|
|
38
|
+
imageUrl: item.imageUrl,
|
|
39
|
+
genres: item.genres,
|
|
40
|
+
maturityRating: item.maturityRating,
|
|
41
|
+
year: item.year
|
|
42
|
+
})),
|
|
43
|
+
ratings: (data.ratings || []).map(rating => ({
|
|
44
|
+
videoId: rating.videoId,
|
|
45
|
+
title: rating.title,
|
|
46
|
+
rating: rating.rating,
|
|
47
|
+
ratedAt: rating.ratedAt
|
|
48
|
+
})),
|
|
49
|
+
profile: data.profile ? {
|
|
50
|
+
profileId: data.profile.profileId,
|
|
51
|
+
profileName: data.profile.profileName,
|
|
52
|
+
maturityLevel: data.profile.maturityLevel,
|
|
53
|
+
language: data.profile.language,
|
|
54
|
+
subtitlePreferences: data.profile.subtitlePreferences,
|
|
55
|
+
autoplayPreferences: data.profile.autoplayPreferences
|
|
56
|
+
} : null,
|
|
57
|
+
netflixProfileId: data.profileId || data.profile?.profileId
|
|
58
|
+
},
|
|
59
|
+
summary: {
|
|
60
|
+
viewingHistoryCount: data.viewingHistory?.items?.length || 0,
|
|
61
|
+
myListCount: data.myList?.length || 0,
|
|
62
|
+
ratingsCount: data.ratings?.length || 0,
|
|
63
|
+
thumbsUpCount: (data.ratings || []).filter(r => r.rating === "thumbs_up").length,
|
|
64
|
+
thumbsDownCount: (data.ratings || []).filter(r => r.rating === "thumbs_down").length,
|
|
65
|
+
profileName: data.profile?.profileName || "unknown"
|
|
66
|
+
},
|
|
67
|
+
mobileMetadata
|
|
68
|
+
};
|
|
69
|
+
return requestBody;
|
|
70
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Synced from RN services/rawMemoryPolicy.ts by scripts/sync-rn-connectors.cjs.
|
|
2
|
+
import { API_CONFIG } from "../config/api.js";
|
|
3
|
+
import { getApiKey } from "./apiKeyService.js";
|
|
4
|
+
async function requireRawMemoryAccess(platform, signal) {
|
|
5
|
+
const apiKey = getApiKey();
|
|
6
|
+
if (!apiKey) throw Object.assign(new Error("Initialize this app with an approved developer API key first."), { code: "IMPORT_APP_NOT_INITIALIZED" });
|
|
7
|
+
const controller = new AbortController();
|
|
8
|
+
const abort = () => controller.abort();
|
|
9
|
+
signal?.addEventListener("abort", abort);
|
|
10
|
+
if (signal?.aborted) controller.abort();
|
|
11
|
+
const timeout = setTimeout(abort, 15e3);
|
|
12
|
+
try {
|
|
13
|
+
const base = API_CONFIG.getBaseUrl ? API_CONFIG.getBaseUrl() : API_CONFIG.BASE_URL;
|
|
14
|
+
const response = await fetch(`${base}/api/raw-memories/policy`, {
|
|
15
|
+
headers: { "x-api-key": apiKey },
|
|
16
|
+
signal: controller.signal
|
|
17
|
+
});
|
|
18
|
+
const policy = await response.json().catch(() => null);
|
|
19
|
+
if (!response.ok) throw Object.assign(new Error("Import access check failed."), {
|
|
20
|
+
code: response.status === 401 || response.status === 403 ? "IMPORT_APP_ACCESS_DENIED" : "IMPORT_POLICY_UNAVAILABLE",
|
|
21
|
+
status: response.status
|
|
22
|
+
});
|
|
23
|
+
if (!response.ok || policy?.offered !== true || !Array.isArray(policy.connectorPlatforms) || !policy.connectorPlatforms.some((value) => typeof value === "string" && value.toLowerCase() === platform)) {
|
|
24
|
+
throw Object.assign(new Error("Raw memories are not enabled for this app and connector."), { code: "IMPORT_APP_ACCESS_DENIED", status: response.status });
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (signal?.aborted || error?.code) throw error;
|
|
28
|
+
throw Object.assign(new Error("Import access check is unavailable."), {
|
|
29
|
+
code: controller.signal.aborted ? "IMPORT_POLICY_TIMEOUT" : "IMPORT_POLICY_UNAVAILABLE"
|
|
30
|
+
});
|
|
31
|
+
} finally {
|
|
32
|
+
clearTimeout(timeout);
|
|
33
|
+
signal?.removeEventListener("abort", abort);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
requireRawMemoryAccess
|
|
38
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Generated pure mapping from RN services/sephoraDataService.ts.
|
|
2
|
+
export function buildPayload(data){
|
|
3
|
+
const Platform={OS:"ios"};
|
|
4
|
+
const mobileMetadata = {
|
|
5
|
+
platform: Platform.OS,
|
|
6
|
+
source: "webview-api",
|
|
7
|
+
appVersion: "1.0.0",
|
|
8
|
+
osVersion: Platform.OS === "ios" ? "17.0" : Platform.OS,
|
|
9
|
+
deviceModel: Platform.OS === "ios" ? "iPhone" : "Android",
|
|
10
|
+
isOfflineSync: false,
|
|
11
|
+
extractedAt: (/* @__PURE__ */new Date()).toISOString(),
|
|
12
|
+
tokenExpiry: data.tokenExpiry
|
|
13
|
+
};
|
|
14
|
+
const parseCurrencyNumber = value => {
|
|
15
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
16
|
+
if (typeof value === "string") {
|
|
17
|
+
const cleaned = value.replace(/[^0-9.-]/g, "");
|
|
18
|
+
const parsed = Number(cleaned);
|
|
19
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
22
|
+
};
|
|
23
|
+
const normalizeOrderDate = value => {
|
|
24
|
+
if (!value) return void 0;
|
|
25
|
+
if (typeof value === "string") return value;
|
|
26
|
+
if (typeof value === "number") return new Date(value).toISOString();
|
|
27
|
+
return void 0;
|
|
28
|
+
};
|
|
29
|
+
const purchases = data.purchases || data.orders || [];
|
|
30
|
+
const normalizedPurchases = purchases.map(order => {
|
|
31
|
+
const normalizedOrderDate = normalizeOrderDate(order.orderDate || order.date || order.purchaseDate);
|
|
32
|
+
const normalizedItems = (order.items || []).map(item => ({
|
|
33
|
+
skuId: typeof item.skuId === "string" ? item.skuId : String(item.skuId || ""),
|
|
34
|
+
productId: item.productId,
|
|
35
|
+
name: item.name,
|
|
36
|
+
brand: item.brand,
|
|
37
|
+
price: parseCurrencyNumber(item.price),
|
|
38
|
+
quantity: item.quantity
|
|
39
|
+
})).filter(item => !!item.skuId && !!item.name);
|
|
40
|
+
const explicitTotal = parseCurrencyNumber(order.total || order.orderTotal);
|
|
41
|
+
const computedTotal = normalizedItems.reduce((sum, item) => sum + item.price * (Number(item.quantity) > 0 ? Number(item.quantity) : 1), 0);
|
|
42
|
+
return {
|
|
43
|
+
orderId: order.orderId,
|
|
44
|
+
orderDate: normalizedOrderDate,
|
|
45
|
+
// Keep legacy aliases for backend compatibility.
|
|
46
|
+
date: normalizedOrderDate,
|
|
47
|
+
purchaseDate: normalizedOrderDate,
|
|
48
|
+
total: explicitTotal > 0 ? explicitTotal : computedTotal,
|
|
49
|
+
channel: order.channel || (order.isOnline ? "online" : void 0),
|
|
50
|
+
status: order.status || "completed",
|
|
51
|
+
items: normalizedItems
|
|
52
|
+
};
|
|
53
|
+
}).filter(order => !!order.orderId && !!order.orderDate && order.items.length > 0);
|
|
54
|
+
const flattenedPurchasedItems = normalizedPurchases.reduce((acc, order) => {
|
|
55
|
+
const mappedItems = (order.items || []).map(item => ({
|
|
56
|
+
orderId: order.orderId,
|
|
57
|
+
date: order.orderDate,
|
|
58
|
+
purchaseDate: order.orderDate,
|
|
59
|
+
isOnline: order.channel ? order.channel.toLowerCase() !== "store" : true,
|
|
60
|
+
quantity: item.quantity || 1,
|
|
61
|
+
sku: {
|
|
62
|
+
skuId: item.skuId,
|
|
63
|
+
productId: item.productId,
|
|
64
|
+
displayName: item.name,
|
|
65
|
+
productName: item.name,
|
|
66
|
+
brandName: item.brand,
|
|
67
|
+
listPrice: item.price
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
return acc.concat(mappedItems);
|
|
71
|
+
}, []);
|
|
72
|
+
const normalizedBasketSubtotal = parseCurrencyNumber(data.basket?.subtotal || data.basket?.total || 0);
|
|
73
|
+
const requestBody = {
|
|
74
|
+
// Keep the canonical SDK platform identifier for backend routing.
|
|
75
|
+
platform: "mobile-sephora",
|
|
76
|
+
platformAlias: "sephora",
|
|
77
|
+
connectorPlatform: "mobile-sephora",
|
|
78
|
+
dataType: "ecommerce",
|
|
79
|
+
data: {
|
|
80
|
+
basket: {
|
|
81
|
+
items: (data.basket?.items || []).map(item => ({
|
|
82
|
+
skuId: item.skuId || item.id,
|
|
83
|
+
productId: item.productId,
|
|
84
|
+
name: item.name,
|
|
85
|
+
brand: item.brand,
|
|
86
|
+
price: parseCurrencyNumber(item.price),
|
|
87
|
+
quantity: item.quantity,
|
|
88
|
+
size: item.size,
|
|
89
|
+
imageUrl: item.imageUrl
|
|
90
|
+
})),
|
|
91
|
+
subtotal: normalizedBasketSubtotal,
|
|
92
|
+
// Legacy alias some backend paths still look for.
|
|
93
|
+
total: normalizedBasketSubtotal,
|
|
94
|
+
biPoints: data.basket?.biPoints || 0,
|
|
95
|
+
itemCount: data.basket?.items?.length || 0
|
|
96
|
+
},
|
|
97
|
+
// Legacy alias: some backend counters look for bag instead of basket.
|
|
98
|
+
bag: {
|
|
99
|
+
items: (data.basket?.items || []).map(item => ({
|
|
100
|
+
skuId: item.skuId || item.id,
|
|
101
|
+
productId: item.productId,
|
|
102
|
+
name: item.name,
|
|
103
|
+
brand: item.brand,
|
|
104
|
+
price: parseCurrencyNumber(item.price),
|
|
105
|
+
quantity: item.quantity
|
|
106
|
+
})),
|
|
107
|
+
total: normalizedBasketSubtotal,
|
|
108
|
+
itemCount: data.basket?.items?.length || 0
|
|
109
|
+
},
|
|
110
|
+
loves: (data.loves || []).map(love => ({
|
|
111
|
+
skuId: love.skuId || love.id,
|
|
112
|
+
productId: love.productId,
|
|
113
|
+
name: love.name,
|
|
114
|
+
brand: love.brand,
|
|
115
|
+
category: love.category,
|
|
116
|
+
price: parseCurrencyNumber(love.price),
|
|
117
|
+
salePrice: parseCurrencyNumber(love.salePrice),
|
|
118
|
+
rating: love.rating,
|
|
119
|
+
reviewCount: love.reviewCount,
|
|
120
|
+
isInStock: love.isInStock,
|
|
121
|
+
isOnSale: love.isOnSale,
|
|
122
|
+
imageUrl: love.imageUrl,
|
|
123
|
+
addedAt: love.addedAt
|
|
124
|
+
})),
|
|
125
|
+
// Legacy aliases seen in older backend pipelines.
|
|
126
|
+
lovedProducts: (data.loves || []).map(love => ({
|
|
127
|
+
skuId: love.skuId || love.id,
|
|
128
|
+
productId: love.productId,
|
|
129
|
+
name: love.name,
|
|
130
|
+
brand: love.brand,
|
|
131
|
+
type: "love"
|
|
132
|
+
})),
|
|
133
|
+
purchases: normalizedPurchases,
|
|
134
|
+
// Legacy alias (older backend parser uses `orders` + `date`).
|
|
135
|
+
orders: normalizedPurchases,
|
|
136
|
+
purchaseHistory: normalizedPurchases,
|
|
137
|
+
// Legacy alias matching Sephora API shape consumed by backend parsers.
|
|
138
|
+
purchasedItems: flattenedPurchasedItems,
|
|
139
|
+
purchasedItemsCount: flattenedPurchasedItems.length,
|
|
140
|
+
profile: data.profile ? {
|
|
141
|
+
profileId: data.profile.profileId,
|
|
142
|
+
firstName: data.profile.firstName,
|
|
143
|
+
vibStatus: data.profile.vibStatus,
|
|
144
|
+
beautyInsider: data.profile.beautyInsider,
|
|
145
|
+
preferences: data.profile.preferences,
|
|
146
|
+
preferredStore: data.profile.preferredStore
|
|
147
|
+
} : null,
|
|
148
|
+
sephoraProfileId: data.profileId || data.profile?.profileId
|
|
149
|
+
},
|
|
150
|
+
summary: {
|
|
151
|
+
basketItemCount: data.basket?.items?.length || 0,
|
|
152
|
+
basketSubtotal: normalizedBasketSubtotal,
|
|
153
|
+
basketTotal: normalizedBasketSubtotal,
|
|
154
|
+
biPoints: data.profile?.beautyInsider?.points || data.basket?.biPoints || 0,
|
|
155
|
+
lovedProductCount: data.loves?.length || 0,
|
|
156
|
+
purchaseCount: normalizedPurchases.length,
|
|
157
|
+
orderCount: normalizedPurchases.length,
|
|
158
|
+
purchasesCount: normalizedPurchases.length,
|
|
159
|
+
purchasedItemsCount: flattenedPurchasedItems.length,
|
|
160
|
+
totalPurchasedItems: normalizedPurchases.reduce((sum, order) => sum + (order.items?.length || 0), 0),
|
|
161
|
+
vibStatus: data.profile?.vibStatus || "unknown"
|
|
162
|
+
},
|
|
163
|
+
mobileMetadata
|
|
164
|
+
};
|
|
165
|
+
return requestBody;
|
|
166
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Generated pure mapping from RN services/spotifyDataService.ts.
|
|
2
|
+
export function buildPayload(data){
|
|
3
|
+
const Platform={OS:"ios"};
|
|
4
|
+
const mobileMetadata = {
|
|
5
|
+
platform: Platform.OS,
|
|
6
|
+
source: "webview-api",
|
|
7
|
+
appVersion: "1.0.0",
|
|
8
|
+
osVersion: Platform.OS === "ios" ? "17.0" : Platform.OS,
|
|
9
|
+
deviceModel: Platform.OS === "ios" ? "iPhone" : "Android",
|
|
10
|
+
isOfflineSync: false,
|
|
11
|
+
extractedAt: (/* @__PURE__ */new Date()).toISOString(),
|
|
12
|
+
tokenExpiry: data.tokenExpiry
|
|
13
|
+
};
|
|
14
|
+
const savedTracksPayload = (data.savedTracks || []).map(track => ({
|
|
15
|
+
trackId: track.trackId,
|
|
16
|
+
name: track.name,
|
|
17
|
+
artists: track.artists,
|
|
18
|
+
album: track.album,
|
|
19
|
+
albumId: track.albumId,
|
|
20
|
+
duration: track.duration,
|
|
21
|
+
savedAt: track.savedAt,
|
|
22
|
+
explicit: track.explicit,
|
|
23
|
+
popularity: track.popularity
|
|
24
|
+
}));
|
|
25
|
+
const topTracksPayload = (data.topItems?.tracks || []).map(track => ({
|
|
26
|
+
trackId: track.trackId,
|
|
27
|
+
name: track.name,
|
|
28
|
+
artists: track.artists,
|
|
29
|
+
album: track.album,
|
|
30
|
+
imageUrl: track.imageUrl,
|
|
31
|
+
popularity: track.popularity
|
|
32
|
+
}));
|
|
33
|
+
const topArtistsPayload = (data.topItems?.artists || []).map(artist => ({
|
|
34
|
+
artistId: artist.artistId,
|
|
35
|
+
name: artist.name,
|
|
36
|
+
genres: artist.genres,
|
|
37
|
+
imageUrl: artist.imageUrl,
|
|
38
|
+
popularity: artist.popularity,
|
|
39
|
+
followers: artist.followers
|
|
40
|
+
}));
|
|
41
|
+
const recentlyPlayedPayload = (data.recentlyPlayed?.items || []).map(track => ({
|
|
42
|
+
trackId: track.trackId,
|
|
43
|
+
name: track.name,
|
|
44
|
+
artists: track.artists,
|
|
45
|
+
album: track.album,
|
|
46
|
+
playedAt: track.playedAt
|
|
47
|
+
}));
|
|
48
|
+
const requestBody = {
|
|
49
|
+
platform: "mobile-spotify",
|
|
50
|
+
dataType: "streaming",
|
|
51
|
+
data: {
|
|
52
|
+
savedTracks: savedTracksPayload,
|
|
53
|
+
topTracks: topTracksPayload,
|
|
54
|
+
topArtists: topArtistsPayload,
|
|
55
|
+
topItems: {
|
|
56
|
+
tracks: topTracksPayload,
|
|
57
|
+
artists: topArtistsPayload,
|
|
58
|
+
timeRange: data.topItems?.timeRange || "medium_term"
|
|
59
|
+
},
|
|
60
|
+
recentlyPlayed: recentlyPlayedPayload,
|
|
61
|
+
playlists: (data.playlists || []).map(playlist => ({
|
|
62
|
+
playlistId: playlist.playlistId,
|
|
63
|
+
name: playlist.name,
|
|
64
|
+
description: playlist.description,
|
|
65
|
+
isPublic: playlist.isPublic,
|
|
66
|
+
trackCount: playlist.trackCount,
|
|
67
|
+
owner: playlist.owner
|
|
68
|
+
})),
|
|
69
|
+
savedAlbums: (data.savedAlbums || []).map(album => ({
|
|
70
|
+
albumId: album.albumId,
|
|
71
|
+
name: album.name,
|
|
72
|
+
artists: album.artists,
|
|
73
|
+
releaseDate: album.releaseDate,
|
|
74
|
+
trackCount: album.trackCount,
|
|
75
|
+
savedAt: album.savedAt
|
|
76
|
+
})),
|
|
77
|
+
profile: data.profile ? {
|
|
78
|
+
userId: data.profile.userId,
|
|
79
|
+
displayName: data.profile.displayName,
|
|
80
|
+
country: data.profile.country,
|
|
81
|
+
subscription: data.profile.subscription,
|
|
82
|
+
followers: data.profile.followers
|
|
83
|
+
} : null,
|
|
84
|
+
spotifyUserId: data.userId || data.profile?.userId
|
|
85
|
+
},
|
|
86
|
+
summary: {
|
|
87
|
+
savedTracksCount: savedTracksPayload.length,
|
|
88
|
+
topTracksCount: topTracksPayload.length,
|
|
89
|
+
topArtistsCount: topArtistsPayload.length,
|
|
90
|
+
recentlyPlayedCount: recentlyPlayedPayload.length,
|
|
91
|
+
playlistCount: data.playlists?.length || 0,
|
|
92
|
+
savedAlbumsCount: data.savedAlbums?.length || 0,
|
|
93
|
+
subscription: data.profile?.subscription || "unknown",
|
|
94
|
+
displayName: data.profile?.displayName || "unknown"
|
|
95
|
+
},
|
|
96
|
+
mobileMetadata
|
|
97
|
+
};
|
|
98
|
+
return requestBody;
|
|
99
|
+
}
|