diff --git a/packages/croft-click/src/lib/data/projects.ts b/packages/croft-click/src/lib/data/projects.ts index a772375..2ddb8a1 100644 --- a/packages/croft-click/src/lib/data/projects.ts +++ b/packages/croft-click/src/lib/data/projects.ts @@ -38,5 +38,15 @@ export const projects: Project[] = [ 'Convert ATProto richtext-block documents from Leaflet, Pckt, and Offprint to Markdown in your browser.', accent: '#c4b5fd', logo: '/bismuth.svg' + }, + { + name: 'Opal', + slug: 'opal', + url: 'https://opal.croft.click', + heading: 'Microblog → Bluesky', + description: + 'Convert your posts from Twitter, Mastodon, Threads, and Nostr to AT Protocol Bluesky posts. Original timestamps preserved.', + accent: '#a7f3d0', + logo: '/opal.svg' } ]; diff --git a/packages/croft-click/static/opal.svg b/packages/croft-click/static/opal.svg new file mode 100644 index 0000000..b3544e6 --- /dev/null +++ b/packages/croft-click/static/opal.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/packages/opal-web/.svelte-kit/ambient.d.ts b/packages/opal-web/.svelte-kit/ambient.d.ts new file mode 100644 index 0000000..e4f9eac --- /dev/null +++ b/packages/opal-web/.svelte-kit/ambient.d.ts @@ -0,0 +1,338 @@ + +// this file is generated — do not edit it + + +/// + +/** + * This module provides access to environment variables that are injected _statically_ into your bundle at build time and are limited to _private_ access. + * + * | | Runtime | Build time | + * | ------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | + * | Private | [`$env/dynamic/private`](https://svelte.dev/docs/kit/$env-dynamic-private) | [`$env/static/private`](https://svelte.dev/docs/kit/$env-static-private) | + * | Public | [`$env/dynamic/public`](https://svelte.dev/docs/kit/$env-dynamic-public) | [`$env/static/public`](https://svelte.dev/docs/kit/$env-static-public) | + * + * Static environment variables are [loaded by Vite](https://vitejs.dev/guide/env-and-mode.html#env-files) from `.env` files and `process.env` at build time and then statically injected into your bundle at build time, enabling optimisations like dead code elimination. + * + * **_Private_ access:** + * + * - This module cannot be imported into client-side code + * - This module only includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://svelte.dev/docs/kit/configuration#env) _and do_ start with [`config.kit.env.privatePrefix`](https://svelte.dev/docs/kit/configuration#env) (if configured) + * + * For example, given the following build time environment: + * + * ```env + * ENVIRONMENT=production + * PUBLIC_BASE_URL=http://site.com + * ``` + * + * With the default `publicPrefix` and `privatePrefix`: + * + * ```ts + * import { ENVIRONMENT, PUBLIC_BASE_URL } from '$env/static/private'; + * + * console.log(ENVIRONMENT); // => "production" + * console.log(PUBLIC_BASE_URL); // => throws error during build + * ``` + * + * The above values will be the same _even if_ different values for `ENVIRONMENT` or `PUBLIC_BASE_URL` are set at runtime, as they are statically replaced in your code with their build time values. + */ +declare module '$env/static/private' { + export const GC_INITIAL_HEAP_SIZE: string; + export const USER_CWD: string; + export const LETTA_RESTORE_ENABLED_CHANNELS: string; + export const NIX_PROFILES: string; + export const PERSIST_CWD: string; + export const NODE: string; + export const INIT_CWD: string; + export const TERM: string; + export const SHELL: string; + export const TMPDIR: string; + export const GIT_CONFIG_VALUE_0: string; + export const npm_config_npm_globalconfig: string; + export const NODE_OPTIONS: string; + export const ORIGINAL_XDG_CURRENT_DESKTOP: string; + export const MallocNanoZone: string; + export const LETTA_MEMFS_GIT_PROXY_BASE_URL: string; + export const VIPSHOME: string; + export const npm_config_registry: string; + export const GIT_TERMINAL_PROMPT: string; + export const USER: string; + export const LETTA_CHANNEL_RUNTIME_ROOT: string; + export const COMMAND_MODE: string; + export const PNPM_SCRIPT_SRC_DIR: string; + export const LETTA_DESKTOP_DEBUG_PANEL: string; + export const npm_config_globalconfig: string; + export const SSH_AUTH_SOCK: string; + export const __CF_USER_TEXT_ENCODING: string; + export const npm_execpath: string; + export const PAGER: string; + export const ELECTRON_RUN_AS_NODE: string; + export const npm_config_frozen_lockfile: string; + export const npm_config_verify_deps_before_run: string; + export const XDG_CONFIG_DIRS: string; + export const LETTA_CONVERSATION_ID: string; + export const PATH: string; + export const TERMINFO_DIRS: string; + export const npm_package_json: string; + export const STARSHIP_CONFIG: string; + export const GIT_CONFIG_KEY_0: string; + export const __CFBundleIdentifier: string; + export const PWD: string; + export const npm_command: string; + export const npm_lifecycle_event: string; + export const EDITOR: string; + export const npm_config__jsr_registry: string; + export const npm_package_name: string; + export const LETTA_BASE_URL: string; + export const GIT_CONFIG_COUNT: string; + export const NODE_PATH: string; + export const XPC_FLAGS: string; + export const NIX_SSL_CERT_FILE: string; + export const npm_config_node_gyp: string; + export const GCM_INTERACTIVE: string; + export const XPC_SERVICE_NAME: string; + export const pnpm_config_verify_deps_before_run: string; + export const npm_package_version: string; + export const SSH_ASKPASS: string; + export const AGENT_ID: string; + export const SHLVL: string; + export const MANPAGER: string; + export const HOME: string; + export const LETTA_AGENT_ID: string; + export const npm_config_store_dir: string; + export const LOGNAME: string; + export const LETTA_API_KEY: string; + export const npm_lifecycle_script: string; + export const XDG_DATA_DIRS: string; + export const CONVERSATION_ID: string; + export const npm_config_user_agent: string; + export const GIT_ASKPASS: string; + export const OSLogRateLimit: string; + export const GIT_PAGER: string; + export const __HM_SESS_VARS_SOURCED: string; + export const npm_node_execpath: string; + export const __HM_ZSH_SESS_VARS_SOURCED: string; + export const NIX_USER_PROFILE_DIR: string; + export const __NIX_DARWIN_SET_ENVIRONMENT_DONE: string; +} + +/** + * This module provides access to environment variables that are injected _statically_ into your bundle at build time and are _publicly_ accessible. + * + * | | Runtime | Build time | + * | ------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | + * | Private | [`$env/dynamic/private`](https://svelte.dev/docs/kit/$env-dynamic-private) | [`$env/static/private`](https://svelte.dev/docs/kit/$env-static-private) | + * | Public | [`$env/dynamic/public`](https://svelte.dev/docs/kit/$env-dynamic-public) | [`$env/static/public`](https://svelte.dev/docs/kit/$env-static-public) | + * + * Static environment variables are [loaded by Vite](https://vitejs.dev/guide/env-and-mode.html#env-files) from `.env` files and `process.env` at build time and then statically injected into your bundle at build time, enabling optimisations like dead code elimination. + * + * **_Public_ access:** + * + * - This module _can_ be imported into client-side code + * - **Only** variables that begin with [`config.kit.env.publicPrefix`](https://svelte.dev/docs/kit/configuration#env) (which defaults to `PUBLIC_`) are included + * + * For example, given the following build time environment: + * + * ```env + * ENVIRONMENT=production + * PUBLIC_BASE_URL=http://site.com + * ``` + * + * With the default `publicPrefix` and `privatePrefix`: + * + * ```ts + * import { ENVIRONMENT, PUBLIC_BASE_URL } from '$env/static/public'; + * + * console.log(ENVIRONMENT); // => throws error during build + * console.log(PUBLIC_BASE_URL); // => "http://site.com" + * ``` + * + * The above values will be the same _even if_ different values for `ENVIRONMENT` or `PUBLIC_BASE_URL` are set at runtime, as they are statically replaced in your code with their build time values. + */ +declare module '$env/static/public' { + +} + +/** + * This module provides access to environment variables set _dynamically_ at runtime and that are limited to _private_ access. + * + * | | Runtime | Build time | + * | ------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | + * | Private | [`$env/dynamic/private`](https://svelte.dev/docs/kit/$env-dynamic-private) | [`$env/static/private`](https://svelte.dev/docs/kit/$env-static-private) | + * | Public | [`$env/dynamic/public`](https://svelte.dev/docs/kit/$env-dynamic-public) | [`$env/static/public`](https://svelte.dev/docs/kit/$env-static-public) | + * + * Dynamic environment variables are defined by the platform you're running on. For example if you're using [`adapter-node`](https://github.com/sveltejs/kit/tree/main/packages/adapter-node) (or running [`vite preview`](https://svelte.dev/docs/kit/cli)), this is equivalent to `process.env`. + * + * **_Private_ access:** + * + * - This module cannot be imported into client-side code + * - This module includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://svelte.dev/docs/kit/configuration#env) _and do_ start with [`config.kit.env.privatePrefix`](https://svelte.dev/docs/kit/configuration#env) (if configured) + * + * > [!NOTE] In `dev`, `$env/dynamic` includes environment variables from `.env`. In `prod`, this behavior will depend on your adapter. + * + * > [!NOTE] To get correct types, environment variables referenced in your code should be declared (for example in an `.env` file), even if they don't have a value until the app is deployed: + * > + * > ```env + * > MY_FEATURE_FLAG= + * > ``` + * > + * > You can override `.env` values from the command line like so: + * > + * > ```sh + * > MY_FEATURE_FLAG="enabled" npm run dev + * > ``` + * + * For example, given the following runtime environment: + * + * ```env + * ENVIRONMENT=production + * PUBLIC_BASE_URL=http://site.com + * ``` + * + * With the default `publicPrefix` and `privatePrefix`: + * + * ```ts + * import { env } from '$env/dynamic/private'; + * + * console.log(env.ENVIRONMENT); // => "production" + * console.log(env.PUBLIC_BASE_URL); // => undefined + * ``` + */ +declare module '$env/dynamic/private' { + export const env: { + GC_INITIAL_HEAP_SIZE: string; + USER_CWD: string; + LETTA_RESTORE_ENABLED_CHANNELS: string; + NIX_PROFILES: string; + PERSIST_CWD: string; + NODE: string; + INIT_CWD: string; + TERM: string; + SHELL: string; + TMPDIR: string; + GIT_CONFIG_VALUE_0: string; + npm_config_npm_globalconfig: string; + NODE_OPTIONS: string; + ORIGINAL_XDG_CURRENT_DESKTOP: string; + MallocNanoZone: string; + LETTA_MEMFS_GIT_PROXY_BASE_URL: string; + VIPSHOME: string; + npm_config_registry: string; + GIT_TERMINAL_PROMPT: string; + USER: string; + LETTA_CHANNEL_RUNTIME_ROOT: string; + COMMAND_MODE: string; + PNPM_SCRIPT_SRC_DIR: string; + LETTA_DESKTOP_DEBUG_PANEL: string; + npm_config_globalconfig: string; + SSH_AUTH_SOCK: string; + __CF_USER_TEXT_ENCODING: string; + npm_execpath: string; + PAGER: string; + ELECTRON_RUN_AS_NODE: string; + npm_config_frozen_lockfile: string; + npm_config_verify_deps_before_run: string; + XDG_CONFIG_DIRS: string; + LETTA_CONVERSATION_ID: string; + PATH: string; + TERMINFO_DIRS: string; + npm_package_json: string; + STARSHIP_CONFIG: string; + GIT_CONFIG_KEY_0: string; + __CFBundleIdentifier: string; + PWD: string; + npm_command: string; + npm_lifecycle_event: string; + EDITOR: string; + npm_config__jsr_registry: string; + npm_package_name: string; + LETTA_BASE_URL: string; + GIT_CONFIG_COUNT: string; + NODE_PATH: string; + XPC_FLAGS: string; + NIX_SSL_CERT_FILE: string; + npm_config_node_gyp: string; + GCM_INTERACTIVE: string; + XPC_SERVICE_NAME: string; + pnpm_config_verify_deps_before_run: string; + npm_package_version: string; + SSH_ASKPASS: string; + AGENT_ID: string; + SHLVL: string; + MANPAGER: string; + HOME: string; + LETTA_AGENT_ID: string; + npm_config_store_dir: string; + LOGNAME: string; + LETTA_API_KEY: string; + npm_lifecycle_script: string; + XDG_DATA_DIRS: string; + CONVERSATION_ID: string; + npm_config_user_agent: string; + GIT_ASKPASS: string; + OSLogRateLimit: string; + GIT_PAGER: string; + __HM_SESS_VARS_SOURCED: string; + npm_node_execpath: string; + __HM_ZSH_SESS_VARS_SOURCED: string; + NIX_USER_PROFILE_DIR: string; + __NIX_DARWIN_SET_ENVIRONMENT_DONE: string; + [key: `PUBLIC_${string}`]: undefined; + [key: `${string}`]: string | undefined; + } +} + +/** + * This module provides access to environment variables set _dynamically_ at runtime and that are _publicly_ accessible. + * + * | | Runtime | Build time | + * | ------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | + * | Private | [`$env/dynamic/private`](https://svelte.dev/docs/kit/$env-dynamic-private) | [`$env/static/private`](https://svelte.dev/docs/kit/$env-static-private) | + * | Public | [`$env/dynamic/public`](https://svelte.dev/docs/kit/$env-dynamic-public) | [`$env/static/public`](https://svelte.dev/docs/kit/$env-static-public) | + * + * Dynamic environment variables are defined by the platform you're running on. For example if you're using [`adapter-node`](https://github.com/sveltejs/kit/tree/main/packages/adapter-node) (or running [`vite preview`](https://svelte.dev/docs/kit/cli)), this is equivalent to `process.env`. + * + * **_Public_ access:** + * + * - This module _can_ be imported into client-side code + * - **Only** variables that begin with [`config.kit.env.publicPrefix`](https://svelte.dev/docs/kit/configuration#env) (which defaults to `PUBLIC_`) are included + * + * > [!NOTE] In `dev`, `$env/dynamic` includes environment variables from `.env`. In `prod`, this behavior will depend on your adapter. + * + * > [!NOTE] To get correct types, environment variables referenced in your code should be declared (for example in an `.env` file), even if they don't have a value until the app is deployed: + * > + * > ```env + * > MY_FEATURE_FLAG= + * > ``` + * > + * > You can override `.env` values from the command line like so: + * > + * > ```sh + * > MY_FEATURE_FLAG="enabled" npm run dev + * > ``` + * + * For example, given the following runtime environment: + * + * ```env + * ENVIRONMENT=production + * PUBLIC_BASE_URL=http://example.com + * ``` + * + * With the default `publicPrefix` and `privatePrefix`: + * + * ```ts + * import { env } from '$env/dynamic/public'; + * console.log(env.ENVIRONMENT); // => undefined, not public + * console.log(env.PUBLIC_BASE_URL); // => "http://example.com" + * ``` + * + * ``` + * + * ``` + */ +declare module '$env/dynamic/public' { + export const env: { + [key: `PUBLIC_${string}`]: string | undefined; + } +} diff --git a/packages/opal-web/.svelte-kit/non-ambient.d.ts b/packages/opal-web/.svelte-kit/non-ambient.d.ts new file mode 100644 index 0000000..0d0464d --- /dev/null +++ b/packages/opal-web/.svelte-kit/non-ambient.d.ts @@ -0,0 +1,44 @@ + +// this file is generated — do not edit it + + +declare module "svelte/elements" { + export interface HTMLAttributes { + 'data-sveltekit-keepfocus'?: true | '' | 'off' | undefined | null; + 'data-sveltekit-noscroll'?: true | '' | 'off' | undefined | null; + 'data-sveltekit-preload-code'?: + | true + | '' + | 'eager' + | 'viewport' + | 'hover' + | 'tap' + | 'off' + | undefined + | null; + 'data-sveltekit-preload-data'?: true | '' | 'hover' | 'tap' | 'off' | undefined | null; + 'data-sveltekit-reload'?: true | '' | 'off' | undefined | null; + 'data-sveltekit-replacestate'?: true | '' | 'off' | undefined | null; + } +} + +export {}; + + +declare module "$app/types" { + type MatcherParam = M extends (param : string) => param is (infer U extends string) ? U : string; + + export interface AppTypes { + RouteId(): "/" | "/import"; + RouteParams(): { + + }; + LayoutParams(): { + "/": Record; + "/import": Record + }; + Pathname(): "/" | "/import"; + ResolvedPathname(): `${"" | `/${string}`}${ReturnType}`; + Asset(): "/client-metadata.json" | "/logo/Opal.svg" | "/robots.txt" | string & {}; + } +} \ No newline at end of file diff --git a/packages/opal-web/.svelte-kit/tsconfig.json b/packages/opal-web/.svelte-kit/tsconfig.json new file mode 100644 index 0000000..ebd6856 --- /dev/null +++ b/packages/opal-web/.svelte-kit/tsconfig.json @@ -0,0 +1,58 @@ +{ + "compilerOptions": { + "paths": { + "$lib": [ + "../src/lib" + ], + "$lib/*": [ + "../src/lib/*" + ], + "$app/types": [ + "./types/index.d.ts" + ] + }, + "rootDirs": [ + "..", + "./types" + ], + "verbatimModuleSyntax": true, + "isolatedModules": true, + "lib": [ + "esnext", + "DOM", + "DOM.Iterable" + ], + "moduleResolution": "bundler", + "module": "esnext", + "noEmit": true, + "target": "esnext", + "types": [ + "node" + ] + }, + "include": [ + "ambient.d.ts", + "non-ambient.d.ts", + "./types/**/$types.d.ts", + "../vite.config.js", + "../vite.config.ts", + "../src/**/*.js", + "../src/**/*.ts", + "../src/**/*.svelte", + "../test/**/*.js", + "../test/**/*.ts", + "../test/**/*.svelte", + "../tests/**/*.js", + "../tests/**/*.ts", + "../tests/**/*.svelte" + ], + "exclude": [ + "../node_modules/**", + "../src/service-worker.js", + "../src/service-worker/**/*.js", + "../src/service-worker.ts", + "../src/service-worker/**/*.ts", + "../src/service-worker.d.ts", + "../src/service-worker/**/*.d.ts" + ] +} \ No newline at end of file diff --git a/packages/opal-web/.svelte-kit/types/route_meta_data.json b/packages/opal-web/.svelte-kit/types/route_meta_data.json new file mode 100644 index 0000000..e0ef782 --- /dev/null +++ b/packages/opal-web/.svelte-kit/types/route_meta_data.json @@ -0,0 +1,4 @@ +{ + "/": [], + "/import": [] +} \ No newline at end of file diff --git a/packages/opal-web/.svelte-kit/types/src/routes/$types.d.ts b/packages/opal-web/.svelte-kit/types/src/routes/$types.d.ts new file mode 100644 index 0000000..4fa6215 --- /dev/null +++ b/packages/opal-web/.svelte-kit/types/src/routes/$types.d.ts @@ -0,0 +1,23 @@ +import type * as Kit from '@sveltejs/kit'; + +type Expand = T extends infer O ? { [K in keyof O]: O[K] } : never; +type MatcherParam = M extends (param : string) => param is (infer U extends string) ? U : string; +type RouteParams = { }; +type RouteId = '/'; +type MaybeWithVoid = {} extends T ? T | void : T; +export type RequiredKeys = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K; }[keyof T]; +type OutputDataShape = MaybeWithVoid> & Partial> & Record> +type EnsureDefined = T extends null | undefined ? {} : T; +type OptionalUnion, A extends keyof U = U extends U ? keyof U : never> = U extends unknown ? { [P in Exclude]?: never } & U : never; +export type Snapshot = Kit.Snapshot; +type PageParentData = EnsureDefined; +type LayoutRouteId = RouteId | "/" | "/import" | null +type LayoutParams = RouteParams & { } +type LayoutParentData = EnsureDefined<{}>; + +export type PageServerData = null; +export type PageData = Expand; +export type PageProps = { params: RouteParams; data: PageData } +export type LayoutServerData = null; +export type LayoutData = Expand; +export type LayoutProps = { params: LayoutParams; data: LayoutData; children: import("svelte").Snippet } \ No newline at end of file diff --git a/packages/opal-web/.svelte-kit/types/src/routes/import/$types.d.ts b/packages/opal-web/.svelte-kit/types/src/routes/import/$types.d.ts new file mode 100644 index 0000000..a54d646 --- /dev/null +++ b/packages/opal-web/.svelte-kit/types/src/routes/import/$types.d.ts @@ -0,0 +1,17 @@ +import type * as Kit from '@sveltejs/kit'; + +type Expand = T extends infer O ? { [K in keyof O]: O[K] } : never; +type MatcherParam = M extends (param : string) => param is (infer U extends string) ? U : string; +type RouteParams = { }; +type RouteId = '/import'; +type MaybeWithVoid = {} extends T ? T | void : T; +export type RequiredKeys = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K; }[keyof T]; +type OutputDataShape = MaybeWithVoid> & Partial> & Record> +type EnsureDefined = T extends null | undefined ? {} : T; +type OptionalUnion, A extends keyof U = U extends U ? keyof U : never> = U extends unknown ? { [P in Exclude]?: never } & U : never; +export type Snapshot = Kit.Snapshot; +type PageParentData = EnsureDefined; + +export type PageServerData = null; +export type PageData = Expand; +export type PageProps = { params: RouteParams; data: PageData } \ No newline at end of file diff --git a/packages/opal-web/package.json b/packages/opal-web/package.json new file mode 100644 index 0000000..bf6d86b --- /dev/null +++ b/packages/opal-web/package.json @@ -0,0 +1,61 @@ +{ + "name": "@ewanc26/opal-web", + "version": "0.1.0", + "description": "Web frontend for Opal — convert microblog posts from Twitter, Mastodon, Threads, and Nostr to AT Protocol", + "author": "Ewan Croft", + "license": "AGPL-3.0-only", + "private": true, + "type": "module", + "keywords": [ + "atproto", + "bluesky", + "twitter", + "mastodon", + "threads", + "nostr", + "svelte", + "sveltekit" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/ewanc26/pkgs.git", + "directory": "packages/opal-web" + }, + "homepage": "https://github.com/ewanc26/pkgs/tree/main/packages/opal-web", + "bugs": { + "url": "https://github.com/ewanc26/pkgs/issues" + }, + "scripts": { + "dev": "vite dev", + "prebuild": "pnpm --filter @ewanc26/opal build", + "build": "vite build", + "preview": "vite preview", + "prepare": "svelte-kit sync || echo ''", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "lint": "prettier --check .", + "format": "prettier --write ." + }, + "dependencies": { + "@atproto/api": "^0.19.3", + "@atproto/common-web": "^0.4.12", + "@atproto/oauth-client-browser": "^0.3.41", + "@ewanc26/landing-ui": "workspace:*", + "@ewanc26/opal": "workspace:*", + "@lucide/svelte": "^0.575.0" + }, + "devDependencies": { + "@sveltejs/adapter-vercel": "^6.3.1", + "@sveltejs/kit": "^2.50.2", + "@sveltejs/vite-plugin-svelte": "^6.2.4", + "@tailwindcss/vite": "^4.1.18", + "prettier": "^3.8.1", + "prettier-plugin-svelte": "^3.4.1", + "prettier-plugin-tailwindcss": "^0.7.2", + "svelte": "^5.51.0", + "svelte-check": "^4.3.6", + "tailwindcss": "^4.1.18", + "typescript": "^5.9.3", + "vercel": "^50.44.0", + "vite": "^7.3.1" + } +} diff --git a/packages/opal-web/src/app.d.ts b/packages/opal-web/src/app.d.ts new file mode 100644 index 0000000..dff60d8 --- /dev/null +++ b/packages/opal-web/src/app.d.ts @@ -0,0 +1,8 @@ +/// + +declare global { + const __WEB_VERSION__: string; + const __CLI_VERSION__: string; +} + +export {}; diff --git a/packages/opal-web/src/app.html b/packages/opal-web/src/app.html new file mode 100644 index 0000000..10d29b0 --- /dev/null +++ b/packages/opal-web/src/app.html @@ -0,0 +1,32 @@ + + + + + + + + + + Opal + + + + + + + + + + + + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/packages/opal-web/src/lib/config.ts b/packages/opal-web/src/lib/config.ts new file mode 100644 index 0000000..38cea0e --- /dev/null +++ b/packages/opal-web/src/lib/config.ts @@ -0,0 +1,3 @@ +/** Opal accent colour — opal green fire */ +export const ACCENT = '#a7f3d0'; +export const ACCENT_DARK = '#065f46'; diff --git a/packages/opal-web/src/lib/index.ts b/packages/opal-web/src/lib/index.ts new file mode 100644 index 0000000..1baf5cb --- /dev/null +++ b/packages/opal-web/src/lib/index.ts @@ -0,0 +1,2 @@ +// Re-exports from workspace packages are done directly in components. +// This file exists for any future opal-web-specific exports. diff --git a/packages/opal-web/src/lib/types.ts b/packages/opal-web/src/lib/types.ts new file mode 100644 index 0000000..e297f3e --- /dev/null +++ b/packages/opal-web/src/lib/types.ts @@ -0,0 +1 @@ +export type { MicroblogPost, ConvertResult, Platform } from '@ewanc26/opal'; diff --git a/packages/opal-web/src/routes/+layout.svelte b/packages/opal-web/src/routes/+layout.svelte new file mode 100644 index 0000000..d28e2c5 --- /dev/null +++ b/packages/opal-web/src/routes/+layout.svelte @@ -0,0 +1,25 @@ + + + + + + + + {@render children()} + diff --git a/packages/opal-web/src/routes/+page.svelte b/packages/opal-web/src/routes/+page.svelte new file mode 100644 index 0000000..a47e55d --- /dev/null +++ b/packages/opal-web/src/routes/+page.svelte @@ -0,0 +1,64 @@ + + + + Opal — Convert your microblog posts to Bluesky + + + + + + + + + + + + + + + + {#snippet heading()} + Bring your microblog posts
to the open web. + {/snippet} + + {#snippet sub()} + Opal converts your posts from Twitter, Mastodon, Threads, and Nostr into + Bluesky + posts — so your words stay with you, not the platforms. + {/snippet} +
diff --git a/packages/opal-web/src/routes/import/+page.svelte b/packages/opal-web/src/routes/import/+page.svelte new file mode 100644 index 0000000..1b56481 --- /dev/null +++ b/packages/opal-web/src/routes/import/+page.svelte @@ -0,0 +1,536 @@ + + + + Opal — Convert to Bluesky + + + + + +
+
+ Opal +

+ Convert microblog posts to Bluesky — own your words, not the platforms' +

+
+ +
+ {#key step} +
+ {#if step === 0} + +
+

Choose a platform

+

Where are your posts coming from?

+
+ + + + +
+
+ {:else if step === 1} + +
+

Sign in with ATProto

+

Authenticate with your Bluesky account to publish posts.

+
+

OAuth authentication will be available here.

+

For now, use the CLI for publishing.

+
+
+ + +
+
+ {:else if step === 2} + +
+

Upload your export

+

+ {#if platform === 'twitter'} + Upload your tweets.js file from the Twitter data export. + {:else if platform === 'mastodon'} + Upload your outbox.json from the Mastodon export. + {:else if platform === 'threads'} + Upload your Threads JSON export file. + {:else if platform === 'nostr'} + Upload your Nostr events JSON file. + {/if} +

+
+ { + const target = e.target as HTMLInputElement; + if (target.files?.[0]) handleFile(target.files[0]); + }} + /> +
+ {#if importError} +

{importError}

+ {/if} +
+ +
+
+ {:else if step === 3} + +
+

Review posts

+ {#if convertResult} +

+ {convertResult.posts.length} posts found. + {convertResult.skipped} skipped. + {#if convertResult.errors.length > 0} + {convertResult.errors.length} errors. + {/if} +

+
+ {#each convertResult.posts.slice(0, 20) as post, i} + + {/each} + {#if convertResult.posts.length > 20} +

…and {convertResult.posts.length - 20} more

+ {/if} +
+ {/if} +
+ + +
+
+ {:else if step === 4} + +
+

{isRunning ? 'Importing…' : 'Done'}

+ {#if progress} +
+
+
+

{progress.current} / {progress.total}

+ {/if} +
+ {#each logs as log} +

{log.message}

+ {/each} +
+
+ {#if isRunning} + + {:else} + + {/if} +
+
+ {/if} +
+ {/key} +
+ + +
+ + diff --git a/packages/opal-web/src/routes/layout.css b/packages/opal-web/src/routes/layout.css new file mode 100644 index 0000000..d4b5078 --- /dev/null +++ b/packages/opal-web/src/routes/layout.css @@ -0,0 +1 @@ +@import 'tailwindcss'; diff --git a/packages/opal-web/static/client-metadata.json b/packages/opal-web/static/client-metadata.json new file mode 100644 index 0000000..425a71e --- /dev/null +++ b/packages/opal-web/static/client-metadata.json @@ -0,0 +1,12 @@ +{ + "client_id": "https://opal.croft.click/client-metadata.json", + "client_name": "Opal", + "client_uri": "https://opal.croft.click", + "redirect_uris": ["https://opal.croft.click/import"], + "scope": "atproto", + "grant_types": ["authorization_code", "refresh_token"], + "response_types": ["code"], + "token_endpoint_auth_method": "none", + "application_type": "web", + "dpop_bound_access_tokens": true +} diff --git a/packages/opal-web/static/logo/Opal.svg b/packages/opal-web/static/logo/Opal.svg new file mode 100644 index 0000000..b3544e6 --- /dev/null +++ b/packages/opal-web/static/logo/Opal.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/packages/opal-web/static/robots.txt b/packages/opal-web/static/robots.txt new file mode 100644 index 0000000..d5570a9 --- /dev/null +++ b/packages/opal-web/static/robots.txt @@ -0,0 +1,5 @@ +User-agent: * +Allow: / +Disallow: /import + +Sitemap: https://opal.croft.click/sitemap.xml diff --git a/packages/opal-web/svelte.config.js b/packages/opal-web/svelte.config.js new file mode 100644 index 0000000..d7eb974 --- /dev/null +++ b/packages/opal-web/svelte.config.js @@ -0,0 +1,14 @@ +import adapter from '@sveltejs/adapter-vercel'; +import { fileURLToPath } from 'url'; +import { dirname, resolve } from 'path'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +/** @type {import('@sveltejs/kit').Config} */ +const config = { + kit: { + adapter: adapter({ runtime: 'nodejs22.x' }), + }, +}; + +export default config; diff --git a/packages/opal-web/tsconfig.json b/packages/opal-web/tsconfig.json new file mode 100644 index 0000000..bbeba3a --- /dev/null +++ b/packages/opal-web/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "rewriteRelativeImportExtensions": true, + "allowJs": true, + "checkJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "moduleResolution": "bundler" + } +} diff --git a/packages/opal-web/vercel.json b/packages/opal-web/vercel.json new file mode 100644 index 0000000..9fbd3a0 --- /dev/null +++ b/packages/opal-web/vercel.json @@ -0,0 +1,6 @@ +{ + "framework": "sveltekit", + "buildCommand": "pnpm build", + "installCommand": "cd ../.. && pnpm install", + "outputDirectory": ".vercel/output" +} diff --git a/packages/opal-web/vite.config.ts b/packages/opal-web/vite.config.ts new file mode 100644 index 0000000..30e7555 --- /dev/null +++ b/packages/opal-web/vite.config.ts @@ -0,0 +1,32 @@ +import tailwindcss from '@tailwindcss/vite'; +import { sveltekit } from '@sveltejs/kit/vite'; +import { defineConfig } from 'vite'; +import { readFileSync } from 'fs'; +import { resolve } from 'path'; + +const webPkg = JSON.parse(readFileSync(resolve('package.json'), 'utf-8')); +const cliPkg = JSON.parse(readFileSync(resolve('../opal/package.json'), 'utf-8')); + +export default defineConfig({ + plugins: [tailwindcss(), sveltekit()], + + server: { + host: '127.0.0.1', + port: 5174, + }, + + define: { + global: 'globalThis', + __WEB_VERSION__: JSON.stringify(webPkg.version), + __CLI_VERSION__: JSON.stringify(cliPkg.version), + }, + + optimizeDeps: { + include: ['@atproto/api', '@atproto/common-web'], + }, + + build: { + target: 'es2022', + chunkSizeWarningLimit: 2000, + }, +}); diff --git a/packages/opal/LICENCE b/packages/opal/LICENCE new file mode 100644 index 0000000..be3f7b2 --- /dev/null +++ b/packages/opal/LICENCE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/packages/opal/README.md b/packages/opal/README.md new file mode 100644 index 0000000..d341bc7 --- /dev/null +++ b/packages/opal/README.md @@ -0,0 +1,80 @@ +# opal + +Convert microblog posts from Twitter, Mastodon, Threads, and Nostr to AT Protocol Bluesky posts. + +--- + +## Installation + +```bash +pnpm add @ewanc26/opal +``` + +--- + +## Usage + +```bash +# Convert Twitter archive +opal --source twitter --input tweets.js --output posts.json + +# Convert Mastodon outbox +opal --source mastodon --input outbox.json --output posts.json + +# Convert and publish to Bluesky +opal --source twitter --input tweets.js --publish + +# Dry run +opal --source twitter --input tweets.js --publish --dry-run +``` + +```typescript +import { convert } from '@ewanc26/opal'; + +const result = await convert({ + source: 'twitter', + input: './tweets.js', +}); + +console.log(result.posts); // MicroblogPost[] +console.log(result.skipped); // number of skipped posts +console.log(result.errors); // parsing errors +``` + +--- + +## Supported Platforms + +| Platform | Input format | Notes | +|----------|-------------|-------| +| Twitter/X | `tweets.js` from data export | Text, media refs, replies, quotes | +| Mastodon | `outbox.json` (ActivityPub) or CSV export | HTML stripped to plain text | +| Threads | JSON export | Limited data available from Meta | +| Nostr | Event JSON array (kind 1) | Text notes, reply/quote tags | + +--- + +## API + +| Function | Description | +|----------|-------------| +| `convert(opts)` | Parse and convert posts from a platform export | +| `convertTwitter(data)` | Parse Twitter archive data | +| `convertMastodon(data)` | Parse Mastodon outbox/CSV data | +| `convertThreads(data)` | Parse Threads export data | +| `convertNostr(data)` | Parse Nostr event data | + +--- + +## Notes + +- Posts exceeding the 300-grapheme AT Protocol limit are truncated with a link to the original +- HTML content from Mastodon is stripped to plain text +- Links, mentions, and hashtags are converted to ATProto facets where possible +- Original timestamps are preserved using TID generation + +--- + +Part of the @ewanc26/pkgs monorepo. + +License: AGPL-3.0-only diff --git a/packages/opal/package.json b/packages/opal/package.json new file mode 100644 index 0000000..b96d74c --- /dev/null +++ b/packages/opal/package.json @@ -0,0 +1,68 @@ +{ + "name": "@ewanc26/opal", + "version": "0.1.0", + "description": "Convert microblog posts from Twitter, Mastodon, Threads, and Nostr to AT Protocol Bluesky posts", + "author": "Ewan Croft", + "license": "AGPL-3.0-only", + "type": "module", + "keywords": [ + "atproto", + "bluesky", + "twitter", + "mastodon", + "threads", + "nostr", + "converter", + "cli" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/ewanc26/pkgs.git", + "directory": "packages/opal" + }, + "homepage": "https://github.com/ewanc26/pkgs/tree/main/packages/opal", + "bugs": { + "url": "https://github.com/ewanc26/pkgs/issues" + }, + "publishConfig": { + "access": "public" + }, + "files": [ + "dist", + "README.md", + "LICENCE" + ], + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "main": "./dist/index.cjs", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", + "bin": { + "opal": "./dist/bin.js" + }, + "scripts": { + "build": "tsup", + "dev": "tsup --watch", + "type-check": "tsc --noEmit", + "test": "pnpm run build && node --test dist/tests/**/*.test.js", + "clean": "rm -rf dist" + }, + "dependencies": { + "@atproto/api": "^0.19.3", + "@atproto/oauth-client-node": "^0.3.16", + "@ewanc26/tid": "workspace:*", + "chalk": "^5.6.2", + "cli-progress": "^3.12.0", + "ora": "^9.0.0" + }, + "devDependencies": { + "@types/node": "^25.5.0", + "tsup": "^8.5.1", + "typescript": "^5.9.3" + } +} diff --git a/packages/opal/src/bin.ts b/packages/opal/src/bin.ts new file mode 100644 index 0000000..588ba8d --- /dev/null +++ b/packages/opal/src/bin.ts @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +import { runCLI } from './cli.js'; + +runCLI(); diff --git a/packages/opal/src/cli.ts b/packages/opal/src/cli.ts new file mode 100644 index 0000000..65f9d93 --- /dev/null +++ b/packages/opal/src/cli.ts @@ -0,0 +1,120 @@ +/** + * CLI for @ewanc26/opal. + * + * Usage: + * opal --source --input [--output ] [--publish] [--dry-run] + */ + +import { resolve } from 'node:path'; +import { writeFile } from 'node:fs/promises'; +import { convert } from './convert.js'; +import type { ConvertOptions, Platform } from './types.js'; + +const VALID_SOURCES: Platform[] = ['twitter', 'mastodon', 'threads', 'nostr']; + +function parseArgs(argv: string[]): Partial & { help?: boolean } { + const opts: Record = {}; + for (let i = 2; i < argv.length; i++) { + const arg = argv[i]; + if (arg === '--help' || arg === '-h') { + return { help: true }; + } + if (arg === '--dry-run') { + opts.dryRun = true; + continue; + } + if (arg === '--publish') { + opts.publish = true; + continue; + } + if (arg.startsWith('--') && i + 1 < argv.length) { + const key = arg.slice(2); + opts[key] = argv[++i]; + } + } + return opts as any; +} + +function printHelp(): void { + console.log(` +opal — Convert microblog posts to AT Protocol Bluesky posts + +Usage: + opal --source --input [options] + +Platforms: + twitter Twitter/X archive (tweets.js) + mastodon Mastodon outbox (outbox.json) + threads Threads export (JSON) + nostr Nostr events (JSON array) + +Options: + --source Source platform (required) + --input Input file path (required) + --output Write converted JSON to file + --publish Publish to AT Protocol after conversion + --dry-run Show what would be published without publishing + -h, --help Show this help message + +Examples: + opal --source twitter --input tweets.js --output posts.json + opal --source mastodon --input outbox.json --publish + opal --source nostr --input events.json --publish --dry-run +`.trim()); +} + +export async function runCLI(): Promise { + const args = parseArgs(process.argv); + + if (args.help) { + printHelp(); + return; + } + + if (!args.source || !args.input) { + console.error('Error: --source and --input are required'); + printHelp(); + process.exit(1); + } + + if (!VALID_SOURCES.includes(args.source as Platform)) { + console.error(`Error: invalid source "${args.source}". Must be one of: ${VALID_SOURCES.join(', ')}`); + process.exit(1); + } + + const opts: ConvertOptions = { + source: args.source as Platform, + input: resolve(args.input), + output: args.output ? resolve(args.output) : undefined, + publish: args.publish ?? false, + dryRun: args.dryRun ?? false, + }; + + console.log(`Opal — converting ${opts.source} export…`); + console.log(` Input: ${opts.input}`); + + const result = await convert(opts); + + console.log(` Posts: ${result.posts.length}`); + console.log(` Skipped: ${result.skipped}`); + + if (result.errors.length > 0) { + console.log(` Errors: ${result.errors.length}`); + for (const err of result.errors.slice(0, 5)) { + console.log(` - ${err}`); + } + if (result.errors.length > 5) { + console.log(` …and ${result.errors.length - 5} more`); + } + } + + if (opts.output) { + await writeFile(opts.output, JSON.stringify(result, null, 2)); + console.log(` Output: ${opts.output}`); + } + + if (opts.publish) { + console.log('\nPublishing is not yet implemented in the CLI.'); + console.log('Use opal-web for browser-based publishing, or pipe the JSON output to your own tool.'); + } +} diff --git a/packages/opal/src/convert.ts b/packages/opal/src/convert.ts new file mode 100644 index 0000000..fd6ab58 --- /dev/null +++ b/packages/opal/src/convert.ts @@ -0,0 +1,51 @@ +/** + * Main conversion dispatcher — reads input, delegates to the correct + * platform parser, and returns a normalised ConvertResult. + */ + +import { readFile } from 'node:fs/promises'; +import type { ConvertOptions, ConvertResult, Platform } from './types.js'; +import { convertTwitter } from './twitter.js'; +import { convertMastodon } from './mastodon.js'; +import { convertThreads } from './threads.js'; +import { convertNostr } from './nostr.js'; + +const parsers: Record ConvertResult> = { + twitter: convertTwitter, + mastodon: convertMastodon, + threads: convertThreads, + nostr: convertNostr, +}; + +/** + * Parse a platform export file and convert to normalised MicroblogPost[]. + */ +export async function convert(opts: ConvertOptions): Promise { + const raw = await readFile(opts.input, 'utf-8'); + const data = parseRaw(raw, opts.source); + const parser = parsers[opts.source]; + return parser(data); +} + +/** + * Pre-process raw file content before passing to the parser. + * Twitter archives wrap data in `window.YTD.tweets.part0 = [...]` + * which isn't valid JSON on its own. + */ +function parseRaw(raw: string, source: Platform): unknown { + if (source === 'twitter') { + // Twitter archives assign to a JS variable — extract the JSON array + const match = raw.match(/\[[\s\S]*\]/); + if (!match) { + throw new Error('Could not extract tweet array from Twitter archive file'); + } + return JSON.parse(match[0]); + } + + return JSON.parse(raw); +} + +export { convertTwitter } from './twitter.js'; +export { convertMastodon } from './mastodon.js'; +export { convertThreads } from './threads.js'; +export { convertNostr } from './nostr.js'; diff --git a/packages/opal/src/index.ts b/packages/opal/src/index.ts new file mode 100644 index 0000000..b1e10da --- /dev/null +++ b/packages/opal/src/index.ts @@ -0,0 +1,46 @@ +/** + * @ewanc26/opal + * + * Convert microblog posts from Twitter, Mastodon, Threads, and Nostr + * to AT Protocol Bluesky posts. + */ + +// Conversion +export { convert } from './convert.js'; +export { convertTwitter } from './twitter.js'; +export { convertMastodon } from './mastodon.js'; +export { convertThreads } from './threads.js'; +export { convertNostr } from './nostr.js'; + +// Utilities +export { + stripHtml, + countGraphemes, + truncateForAtProto, + parseTwitterTimestamp, + parseUnixTimestamp, + textToByteSlice, + linkFacet, + mentionFacet, + tagFacet, + MAX_GRAPHEME_COUNT, +} from './utils.js'; + +// Types +export type { + Platform, + MicroblogPost, + ConvertResult, + ConvertOptions, + Facet, + FacetFeature, + ByteSlice, + TwitterTweet, + TwitterMediaEntity, + MastodonOutboxItem, + MastodonStatus, + MastodonAttachment, + MastodonTag, + ThreadsPost, + NostrEvent, +} from './types.js'; diff --git a/packages/opal/src/mastodon.ts b/packages/opal/src/mastodon.ts new file mode 100644 index 0000000..3339693 --- /dev/null +++ b/packages/opal/src/mastodon.ts @@ -0,0 +1,73 @@ +/** + * Mastodon outbox/CSV parser. + * + * Parses ActivityPub outbox JSON (OrderedCollection) from a Mastodon export. + * CSV export support can be added later. + */ + +import type { MastodonOutboxItem, ConvertResult, MicroblogPost, Facet } from './types.js'; +import { stripHtml, truncateForAtProto, tagFacet } from './utils.js'; + +export function convertMastodon(data: unknown): ConvertResult { + const outbox = data as { orderedItems?: MastodonOutboxItem[] }; + const items = outbox.orderedItems ?? (data as MastodonOutboxItem[]); + const posts: MicroblogPost[] = []; + const errors: string[] = []; + let skipped = 0; + + for (const item of items) { + try { + // Only process Create activities with Note objects + if (item.type !== 'Create' || !item.object) { + continue; + } + + const status = item.object; + if (status.type !== 'Note') { + continue; + } + + const text = stripHtml(status.content).trim(); + if (!text) { + skipped++; + continue; + } + + const facets: Facet[] = []; + + // Convert hashtags + if (status.tag) { + for (const tag of status.tag) { + if (tag.type === 'Hashtag' && tag.name) { + // Mastodon hashtags include the # prefix + const tagName = tag.name.startsWith('#') ? tag.name : `#${tag.name}`; + const charIndex = text.indexOf(tagName); + if (charIndex !== -1) { + facets.push(tagFacet(text, charIndex, charIndex + tagName.length, tagName.slice(1))); + } + } + } + } + + const { text: finalText, truncated } = truncateForAtProto(text); + + const post: MicroblogPost = { + text: finalText, + createdAt: status.published, + platform: 'mastodon', + originalId: status.id, + facets: facets.length > 0 ? facets : undefined, + truncated, + mediaUris: status.attachment?.map((a) => a.url), + replyTo: status.inReplyTo, + }; + + posts.push(post); + } catch (err) { + errors.push(`Mastodon item: ${(err as Error).message}`); + skipped++; + } + } + + return { posts, skipped, errors }; +} diff --git a/packages/opal/src/nostr.ts b/packages/opal/src/nostr.ts new file mode 100644 index 0000000..08f3990 --- /dev/null +++ b/packages/opal/src/nostr.ts @@ -0,0 +1,88 @@ +/** + * Nostr event parser. + * + * Parses an array of Nostr events (kind 1 = text notes). + * Events are typically exported from a Nostr client as a JSON array. + */ + +import type { NostrEvent, ConvertResult, MicroblogPost, Facet } from './types.js'; +import { parseUnixTimestamp, truncateForAtProto, linkFacet, tagFacet } from './utils.js'; + +export function convertNostr(data: unknown): ConvertResult { + const events = Array.isArray(data) ? (data as NostrEvent[]) : []; + const posts: MicroblogPost[] = []; + const errors: string[] = []; + let skipped = 0; + + for (const event of events) { + try { + // Only process text notes (kind 1) + if (event.kind !== 1) { + continue; + } + + const text = event.content?.trim(); + if (!text) { + skipped++; + continue; + } + + const facets: Facet[] = []; + + // Parse tags for reply and quote references + let replyTo: string | undefined; + let quoteUri: string | undefined; + + for (const tag of event.tags) { + // ["e", "", "", ""] + if (tag[0] === 'e' && tag.length >= 4) { + const marker = tag[3]; + if (marker === 'reply' || marker === 'root') { + replyTo = `nostr:${tag[1]}`; + } else if (marker === 'mention') { + quoteUri = `nostr:${tag[1]}`; + } + } + + // ["t", ""] + if (tag[0] === 't' && tag[1]) { + const tagName = tag[1].startsWith('#') ? tag[1] : `#${tag[1]}`; + const charIndex = text.indexOf(tagName); + if (charIndex !== -1) { + facets.push(tagFacet(text, charIndex, charIndex + tagName.length, tag[1])); + } + } + + // ["r", ""] + if (tag[0] === 'r' && tag[1]) { + const url = tag[1]; + const charIndex = text.indexOf(url); + if (charIndex !== -1) { + facets.push(linkFacet(text, charIndex, charIndex + url.length, url)); + } + } + } + + const { text: finalText, truncated } = truncateForAtProto(text); + + const post: MicroblogPost = { + text: finalText, + createdAt: parseUnixTimestamp(event.created_at), + platform: 'nostr', + originalId: event.id, + originalUrl: `nostr:nevent1${event.id}`, + facets: facets.length > 0 ? facets : undefined, + truncated, + replyTo, + quoteUri, + }; + + posts.push(post); + } catch (err) { + errors.push(`Nostr event ${event.id}: ${(err as Error).message}`); + skipped++; + } + } + + return { posts, skipped, errors }; +} diff --git a/packages/opal/src/threads.ts b/packages/opal/src/threads.ts new file mode 100644 index 0000000..8df6c62 --- /dev/null +++ b/packages/opal/src/threads.ts @@ -0,0 +1,46 @@ +/** + * Threads export parser. + * + * Meta's data export for Threads is limited. This parser handles + * whatever JSON structure is available. + */ + +import type { ThreadsPost, ConvertResult, MicroblogPost } from './types.js'; +import { truncateForAtProto } from './utils.js'; + +export function convertThreads(data: unknown): ConvertResult { + const threadPosts = Array.isArray(data) ? (data as ThreadsPost[]) : []; + const posts: MicroblogPost[] = []; + const errors: string[] = []; + let skipped = 0; + + for (const post of threadPosts) { + try { + const text = post.text?.trim(); + if (!text) { + skipped++; + continue; + } + + const { text: finalText, truncated } = truncateForAtProto(text); + + const result: MicroblogPost = { + text: finalText, + createdAt: post.timestamp, + platform: 'threads', + originalId: post.id, + truncated, + mediaUris: post.media?.map((m) => m.uri), + replyTo: post.parent_id ? `threads:${post.parent_id}` : undefined, + quoteUri: post.quote_id ? `threads:${post.quote_id}` : undefined, + }; + + posts.push(result); + } catch (err) { + errors.push(`Threads post ${post.id}: ${(err as Error).message}`); + skipped++; + } + } + + return { posts, skipped, errors }; +} diff --git a/packages/opal/src/twitter.ts b/packages/opal/src/twitter.ts new file mode 100644 index 0000000..f4a42c2 --- /dev/null +++ b/packages/opal/src/twitter.ts @@ -0,0 +1,78 @@ +/** + * Twitter/X archive parser. + * + * Parses the `tweets.js` file from a Twitter data export. + * The file assigns to `window.YTD.tweets.part0` — the convert dispatcher + * already extracts the JSON array before passing it here. + */ + +import type { TwitterTweet, ConvertResult, MicroblogPost, Facet } from './types.js'; +import { parseTwitterTimestamp, truncateForAtProto, linkFacet, tagFacet, twitterUrl } from './utils.js'; + +export function convertTwitter(data: unknown): ConvertResult { + const tweets = data as TwitterTweet[]; + const posts: MicroblogPost[] = []; + const errors: string[] = []; + let skipped = 0; + + for (const tweet of tweets) { + try { + // Skip retweets — they're someone else's content + if (tweet.retweeted_status) { + skipped++; + continue; + } + + const text = tweet.full_text?.trim(); + if (!text) { + skipped++; + continue; + } + + const facets: Facet[] = []; + + // Convert Twitter entities to ATProto facets + if (tweet.entities) { + // URLs — replace t.co links with expanded URLs + if (tweet.entities.urls) { + for (const url of tweet.entities.urls) { + facets.push(linkFacet(text, url.indices[0], url.indices[1], url.expanded_url)); + } + } + + // Hashtags + if (tweet.entities.hashtags) { + for (const hashtag of tweet.entities.hashtags) { + facets.push(tagFacet(text, hashtag.indices[0], hashtag.indices[1] + 1, hashtag.text)); + } + } + } + + const { text: finalText, truncated } = truncateForAtProto(text); + + const post: MicroblogPost = { + text: finalText, + createdAt: parseTwitterTimestamp(tweet.created_at), + platform: 'twitter', + originalId: tweet.id_str, + originalUrl: twitterUrl('_', tweet.id_str), // username filled in by caller if known + facets: facets.length > 0 ? facets : undefined, + truncated, + mediaUris: tweet.entities?.media?.map((m) => m.media_url_https), + replyTo: tweet.in_reply_to_status_id_str + ? `twitter:status:${tweet.in_reply_to_status_id_str}` + : undefined, + quoteUri: tweet.quoted_status_id_str + ? twitterUrl('_', tweet.quoted_status_id_str) + : undefined, + }; + + posts.push(post); + } catch (err) { + errors.push(`Twitter tweet ${tweet.id_str}: ${(err as Error).message}`); + skipped++; + } + } + + return { posts, skipped, errors }; +} diff --git a/packages/opal/src/types.ts b/packages/opal/src/types.ts new file mode 100644 index 0000000..d74098e --- /dev/null +++ b/packages/opal/src/types.ts @@ -0,0 +1,151 @@ +/** + * Shared types for @ewanc26/opal. + * + * MicroblogPost is the normalised intermediate format — all platform parsers + * produce this. The publisher then converts these into app.bsky.feed.post records. + */ + +// ─── Platform sources ──────────────────────────────────────────────────────── + +export type Platform = 'twitter' | 'mastodon' | 'threads' | 'nostr'; + +// ─── Normalised post ───────────────────────────────────────────────────────── + +export interface MicroblogPost { + /** Plain text content (HTML already stripped for Mastodon) */ + text: string; + /** ISO 8601 timestamp of the original post */ + createdAt: string; + /** Local file paths or URLs for media attachments */ + mediaUris?: string[]; + /** URI of parent post (for threading) */ + replyTo?: string; + /** URI of quoted post */ + quoteUri?: string; + /** Source platform */ + platform: Platform; + /** Platform-specific post ID */ + originalId: string; + /** Link to original post on the source platform */ + originalUrl?: string; + /** Pre-computed ATProto facets (links, mentions, hashtags) */ + facets?: Facet[]; + /** Whether this post was truncated to fit the 300-grapheme limit */ + truncated?: boolean; +} + +// ─── ATProto facet types ──────────────────────────────────────────────────── + +export interface ByteSlice { + byteStart: number; + byteEnd: number; +} + +export type FacetFeature = + | { $type: 'app.bsky.richtext.facet#link'; uri: string } + | { $type: 'app.bsky.richtext.facet#mention'; did: string } + | { $type: 'app.bsky.richtext.facet#tag'; tag: string }; + +export interface Facet { + index: ByteSlice; + features: FacetFeature[]; +} + +// ─── Conversion result ────────────────────────────────────────────────────── + +export interface ConvertResult { + posts: MicroblogPost[]; + /** Number of posts skipped (empty, too long, duplicates) */ + skipped: number; + /** Parsing errors */ + errors: string[]; +} + +// ─── Conversion options ───────────────────────────────────────────────────── + +export interface ConvertOptions { + source: Platform; + /** Path to input file, or raw string/JSON data */ + input: string; + /** Path to write converted JSON output */ + output?: string; + /** Whether to publish to AT Protocol after conversion */ + publish?: boolean; + /** Dry run — show what would be published without actually publishing */ + dryRun?: boolean; +} + +// ─── Platform-specific input types ────────────────────────────────────────── + +/** Twitter archive tweet object (from tweets.js) */ +export interface TwitterTweet { + id_str: string; + full_text: string; + created_at: string; // "Tue Jun 15 20:32:00 +0000 2021" + in_reply_to_status_id_str?: string; + in_reply_to_user_id_str?: string; + quoted_status_id_str?: string; + entities?: { + media?: TwitterMediaEntity[]; + urls?: { url: string; expanded_url: string; indices: [number, number] }[]; + hashtags?: { text: string; indices: [number, number] }[]; + user_mentions?: { screen_name: string; id_str: string; indices: [number, number] }[]; + }; + retweeted_status?: TwitterTweet; +} + +export interface TwitterMediaEntity { + media_url_https: string; + type: 'photo' | 'video' | 'animated_gif'; + url: string; + indices: [number, number]; +} + +/** Mastodon outbox item */ +export interface MastodonOutboxItem { + type: string; + object: MastodonStatus; +} + +export interface MastodonStatus { + type: string; + id: string; + content: string; // HTML + published: string; // ISO 8601 + inReplyTo?: string; + attachment?: MastodonAttachment[]; + tag?: MastodonTag[]; +} + +export interface MastodonAttachment { + type: 'Document'; + mediaType?: string; + url: string; + name?: string; +} + +export interface MastodonTag { + type: 'Hashtag' | 'Mention'; + name?: string; + href?: string; +} + +/** Threads export post (limited schema) */ +export interface ThreadsPost { + id: string; + text?: string; + timestamp: string; // ISO 8601 + media?: { uri: string; type: string }[]; + parent_id?: string; + quote_id?: string; +} + +/** Nostr event (kind 1 = text note) */ +export interface NostrEvent { + id: string; + kind: number; + content: string; + created_at: number; // Unix timestamp + tags: string[][]; + pubkey: string; +} diff --git a/packages/opal/src/utils.ts b/packages/opal/src/utils.ts new file mode 100644 index 0000000..20734e0 --- /dev/null +++ b/packages/opal/src/utils.ts @@ -0,0 +1,142 @@ +/** + * Shared utility functions for @ewanc26/opal. + */ + +import type { Facet, ByteSlice } from './types.js'; + +/** Maximum grapheme count for an AT Protocol post */ +export const MAX_GRAPHEME_COUNT = 300; + +/** + * Strip HTML tags and decode common entities. + * Used for Mastodon content which arrives as HTML. + */ +export function stripHtml(html: string): string { + return html + // Replace
and
with newlines + .replace(//gi, '\n') + // Replace

with newlines + .replace(/<\/p>/gi, '\n') + // Remove all other HTML tags + .replace(/<[^>]+>/g, '') + // Decode common HTML entities + .replace(/&/g, '&') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/"/g, '"') + .replace(/'/g, "'") + .replace(/'/g, "'") + .replace(/'/g, "'") + // Collapse multiple newlines + .replace(/\n{3,}/g, '\n\n') + .trim(); +} + +/** + * Count graphemes in a string (Unicode-aware). + * Uses Intl.Segmenter where available, falls back to [...spread]. + */ +export function countGraphemes(text: string): number { + if (typeof Intl !== 'undefined' && Intl.Segmenter) { + const segmenter = new Intl.Segmenter('en', { granularity: 'grapheme' }); + return [...segmenter.segment(text)].length; + } + return [...text].length; +} + +/** + * Truncate text to fit within the AT Protocol grapheme limit. + * If the text is too long, truncates and appends an ellipsis. + * Returns the truncated text and whether truncation occurred. + */ +export function truncateForAtProto(text: string): { text: string; truncated: boolean } { + const count = countGraphemes(text); + if (count <= MAX_GRAPHEME_COUNT) { + return { text, truncated: false }; + } + + // Truncate with ellipsis — leave room for "…" + const target = MAX_GRAPHEME_COUNT - 1; + const chars = [...text]; + return { + text: chars.slice(0, target).join('') + '…', + truncated: true, + }; +} + +/** + * Convert a Twitter timestamp ("Tue Jun 15 20:32:00 +0000 2021") to ISO 8601. + */ +export function parseTwitterTimestamp(ts: string): string { + // Twitter format: "Day Mon DD HH:MM:SS +ZZZZ YYYY" + const date = new Date(ts); + if (isNaN(date.getTime())) { + throw new Error(`Invalid Twitter timestamp: ${ts}`); + } + return date.toISOString(); +} + +/** + * Convert a Unix timestamp (Nostr) to ISO 8601. + */ +export function parseUnixTimestamp(ts: number): string { + return new Date(ts * 1000).toISOString(); +} + +/** + * Build a Twitter web URL from a tweet ID and username. + */ +export function twitterUrl(username: string, id: string): string { + return `https://x.com/${username}/status/${id}`; +} + +/** + * Build a Mastodon web URL from a status ID and instance. + */ +export function mastodonUrl(instance: string, id: string): string { + return `https://${instance}/status/${id}`; +} + +/** + * Compute UTF-8 byte offsets for a facet. + * AT Protocol facets use byte offsets, not character offsets. + */ +export function textToByteSlice(text: string, startChar: number, endChar: number): ByteSlice { + const encoder = new TextEncoder(); + const before = [...text].slice(0, startChar).join(''); + const match = [...text].slice(startChar, endChar).join(''); + return { + byteStart: encoder.encode(before).byteLength, + byteEnd: encoder.encode(before + match).byteLength, + }; +} + +/** + * Create a link facet at the given character range. + */ +export function linkFacet(text: string, startChar: number, endChar: number, uri: string): Facet { + return { + index: textToByteSlice(text, startChar, endChar), + features: [{ $type: 'app.bsky.richtext.facet#link', uri }], + }; +} + +/** + * Create a mention facet at the given character range. + */ +export function mentionFacet(text: string, startChar: number, endChar: number, did: string): Facet { + return { + index: textToByteSlice(text, startChar, endChar), + features: [{ $type: 'app.bsky.richtext.facet#mention', did }], + }; +} + +/** + * Create a tag facet at the given character range. + */ +export function tagFacet(text: string, startChar: number, endChar: number, tag: string): Facet { + return { + index: textToByteSlice(text, startChar, endChar), + features: [{ $type: 'app.bsky.richtext.facet#tag', tag }], + }; +} diff --git a/packages/opal/tsconfig.json b/packages/opal/tsconfig.json new file mode 100644 index 0000000..9322948 --- /dev/null +++ b/packages/opal/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "node16", + "moduleResolution": "node16", + "lib": ["ES2022"], + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} diff --git a/packages/opal/tsup.config.ts b/packages/opal/tsup.config.ts new file mode 100644 index 0000000..aef2f07 --- /dev/null +++ b/packages/opal/tsup.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig({ + entry: ['src/index.ts', 'src/bin.ts'], + format: ['esm', 'cjs'], + dts: { resolve: true }, + clean: true, + sourcemap: true, + splitting: false, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd85754..0ba8c30 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -414,6 +414,98 @@ importers: specifier: ^5.9.3 version: 5.9.3 + packages/opal: + dependencies: + '@atproto/api': + specifier: ^0.19.3 + version: 0.19.8 + '@atproto/oauth-client-node': + specifier: ^0.3.16 + version: 0.3.17 + '@ewanc26/tid': + specifier: workspace:* + version: link:../tid + chalk: + specifier: ^5.6.2 + version: 5.6.2 + cli-progress: + specifier: ^3.12.0 + version: 3.12.0 + ora: + specifier: ^9.0.0 + version: 9.3.0 + devDependencies: + '@types/node': + specifier: ^25.5.0 + version: 25.6.0 + tsup: + specifier: ^8.5.1 + version: 8.5.1(jiti@2.6.1)(postcss@8.5.9)(tsx@4.21.0)(typescript@5.9.3) + typescript: + specifier: ^5.9.3 + version: 5.9.3 + + packages/opal-web: + dependencies: + '@atproto/api': + specifier: ^0.19.3 + version: 0.19.8 + '@atproto/common-web': + specifier: ^0.4.12 + version: 0.4.20 + '@atproto/oauth-client-browser': + specifier: ^0.3.41 + version: 0.3.41 + '@ewanc26/landing-ui': + specifier: workspace:* + version: link:../landing-ui + '@ewanc26/opal': + specifier: workspace:* + version: link:../opal + '@lucide/svelte': + specifier: ^0.575.0 + version: 0.575.0(svelte@5.55.4) + devDependencies: + '@sveltejs/adapter-vercel': + specifier: ^6.3.1 + version: 6.3.3(@sveltejs/kit@2.57.1(@sveltejs/vite-plugin-svelte@6.2.4(svelte@5.55.4)(vite@7.3.2(@types/node@25.6.0)(jiti@2.6.1)(lightningcss@1.32.0)(tsx@4.21.0)))(svelte@5.55.4)(typescript@5.9.3)(vite@7.3.2(@types/node@25.6.0)(jiti@2.6.1)(lightningcss@1.32.0)(tsx@4.21.0)))(rollup@4.60.1) + '@sveltejs/kit': + specifier: ^2.50.2 + version: 2.57.1(@sveltejs/vite-plugin-svelte@6.2.4(svelte@5.55.4)(vite@7.3.2(@types/node@25.6.0)(jiti@2.6.1)(lightningcss@1.32.0)(tsx@4.21.0)))(svelte@5.55.4)(typescript@5.9.3)(vite@7.3.2(@types/node@25.6.0)(jiti@2.6.1)(lightningcss@1.32.0)(tsx@4.21.0)) + '@sveltejs/vite-plugin-svelte': + specifier: ^6.2.4 + version: 6.2.4(svelte@5.55.4)(vite@7.3.2(@types/node@25.6.0)(jiti@2.6.1)(lightningcss@1.32.0)(tsx@4.21.0)) + '@tailwindcss/vite': + specifier: ^4.1.18 + version: 4.2.2(vite@7.3.2(@types/node@25.6.0)(jiti@2.6.1)(lightningcss@1.32.0)(tsx@4.21.0)) + prettier: + specifier: ^3.8.1 + version: 3.8.3 + prettier-plugin-svelte: + specifier: ^3.4.1 + version: 3.5.1(prettier@3.8.3)(svelte@5.55.4) + prettier-plugin-tailwindcss: + specifier: ^0.7.2 + version: 0.7.2(prettier-plugin-svelte@3.5.1(prettier@3.8.3)(svelte@5.55.4))(prettier@3.8.3) + svelte: + specifier: ^5.51.0 + version: 5.55.4 + svelte-check: + specifier: ^4.3.6 + version: 4.4.6(picomatch@4.0.4)(svelte@5.55.4)(typescript@5.9.3) + tailwindcss: + specifier: ^4.1.18 + version: 4.2.2 + typescript: + specifier: ^5.9.3 + version: 5.9.3 + vercel: + specifier: ^50.44.0 + version: 50.44.0(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)(rollup@4.60.1)(typescript@5.9.3) + vite: + specifier: ^7.3.1 + version: 7.3.2(@types/node@25.6.0)(jiti@2.6.1)(lightningcss@1.32.0)(tsx@4.21.0) + packages/pds-landing: dependencies: '@ewanc26/ui':