Open History to see the last commit
1import * as Schema from "effect/Schema";
2import { TrimmedNonEmptyString } from "./baseSchemas.ts";
3import { BrowserProfileId } from "./browserProfile.ts";
4
5const BROWSER_IMPORT_SOURCE_IDS = [
6 "chrome",
7 "edge",
8 "brave",
9 "vivaldi",
10 "opera",
11 "arc",
12 "helium",
13 "firefox",
14 "safari",
15] as const;
16
17export const BrowserImportSourceId = Schema.Literals(BROWSER_IMPORT_SOURCE_IDS);
18export type BrowserImportSourceId = typeof BrowserImportSourceId.Type;
19
20export const BrowserImportUnavailableReason = Schema.Literals([
21 "notInstalled",
22 "needsKeychainApproval",
23 "keychainItemMissing",
24 "needsFullDiskAccess",
25 "browserRunning",
26 "unsupportedPlatform",
27]);
28export type BrowserImportUnavailableReason = typeof BrowserImportUnavailableReason.Type;
29
30export const BrowserImportFailureReason = Schema.Literals([
31 ...BrowserImportUnavailableReason.literals,
32 "keychainUnavailable",
33 "unknownSource",
34 "unknownSourceProfile",
35 "sessionUnavailable",
36 "profileNotSaved",
37 "profileLimitReached",
38 "readFailed",
39]);
40export type BrowserImportFailureReason = typeof BrowserImportFailureReason.Type;
41
42export const BrowserImportSourceProfile = Schema.Struct({
43 directory: TrimmedNonEmptyString,
44 name: TrimmedNonEmptyString,
45 cookieCount: Schema.optional(Schema.Int),
46});
47export type BrowserImportSourceProfile = typeof BrowserImportSourceProfile.Type;
48
49export const BrowserImportSource = Schema.Struct({
50 id: BrowserImportSourceId,
51 name: TrimmedNonEmptyString,
52 profiles: Schema.Array(BrowserImportSourceProfile),
53 unavailable: Schema.optional(BrowserImportUnavailableReason),
54});
55export type BrowserImportSource = typeof BrowserImportSource.Type;
56
57export const BrowserImportInput = Schema.Struct({
58 sourceId: BrowserImportSourceId,
59 sourceProfileDirectory: TrimmedNonEmptyString,
60 targetProfileId: BrowserProfileId,
61});
62export type BrowserImportInput = typeof BrowserImportInput.Type;
63
64export const DesktopPreviewImportCookiesInputSchema = Schema.Struct({
65 environmentId: TrimmedNonEmptyString,
66 sourceId: BrowserImportSourceId,
67 sourceProfileDirectory: TrimmedNonEmptyString,
68 targetProfileId: BrowserProfileId,
69});
70
71export const BrowserImportResult = Schema.Struct({
72 imported: Schema.Int,
73 skipped: Schema.Int,
74 skippedDomains: Schema.Array(Schema.String),
75});
76export type BrowserImportResult = typeof BrowserImportResult.Type;
77
78const BROWSER_IMPORT_UNAVAILABLE_COPY: Readonly<Record<BrowserImportUnavailableReason, string>> = {
79 notInstalled: "Not installed on this machine.",
80 needsKeychainApproval: "Needs Keychain access to read its cookies.",
81 keychainItemMissing:
82 "No encryption key in your Keychain — sign in to that browser once, then retry.",
83 needsFullDiskAccess:
84 "Give T3 Code Full Disk Access in System Settings → Privacy & Security, then retry.",
85 browserRunning: "Quit the browser first so its cookie database can be read.",
86 unsupportedPlatform: "Importing from this browser isn't possible on this platform.",
87};
88
89export const BROWSER_IMPORT_FAILURE_COPY: Readonly<Record<BrowserImportFailureReason, string>> = {
90 ...BROWSER_IMPORT_UNAVAILABLE_COPY,
91 keychainUnavailable:
92 "The system keyring could not be accessed. Make sure your desktop keyring is running and unlocked, then retry.",
93 unknownSource: "That browser is no longer available to import from.",
94 unknownSourceProfile: "That browser profile no longer exists.",
95 sessionUnavailable: "The target profile could not be opened.",
96 profileNotSaved: "The cookies were imported, but the new profile couldn't be saved. Try again.",
97 profileLimitReached:
98 "You've reached the profile limit. Delete a profile or import into an existing one.",
99 readFailed: "The browser's cookie database could not be read.",
100};