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