Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 114 additions & 4 deletions bun.lock

Large diffs are not rendered by default.

Binary file added desktop/assets/dev-app-icon-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion desktop/scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const build = async () => {
const run = () => {
console.log("Running...");

const proc = Bun.spawn(["bun", "electron", "build/index.js"]);
const proc = Bun.spawn(["bun", "electron", "build/index.js"], {
stdout: "inherit",
});

return () => {
console.log("Killing...");
Expand Down
14 changes: 11 additions & 3 deletions desktop/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { app, BrowserWindow } from "electron";
import { app, BrowserWindow, nativeImage, NativeImage } from "electron";
import { isMacOS } from "./utils";

app.whenReady().then(() => {
// Set dev icon
if (isMacOS) {
let image = nativeImage.createFromPath("./assets/dev-app-icon-256.png");
app.dock?.setIcon(image);
}

const mainWindow = new BrowserWindow({
width: 800,
height: 600,
transparent: true,
trafficLightPosition: {
x: 14,
y: 14,
x: 16,
y: 16,
},

frame: true,
Expand All @@ -17,5 +24,6 @@ app.whenReady().then(() => {
titleBarStyle: "hidden",
vibrancy: "popover",
});

mainWindow.loadURL("http://localhost:8001/app");
});
3 changes: 3 additions & 0 deletions desktop/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { platform } from "os";
const p = platform();
export const isMacOS = p == "darwin";
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
"workspaces": [
"server",
"web",
"web/packages/*",
"scripts"
],
"scripts": {
"generate:proto": "cd scripts && bun run generate",
"dev:server": "cd server && bun run dev",
"dev:web": "cd web && bun run dev",
"dev:desktop": "cd desktop && bun run dev",
"typecheck": "cd server && bun run typecheck",
"dev": "cd server && bun run dev",
"test": "cd server && bun test",
"lint": "bunx oxlint@latest"
},
"devDependencies": {
"@types/bun": "^1.3.5",
"oxlint": "^0.16.0"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"private": true,
"scripts": {
"proto:generate-ts": "npx protoc --plugin=./node_modules/.bin/protoc-gen-ts --ts_out=../server/packages/protocol/src --proto_path ../proto/ ../proto/core.proto ../proto/server.proto",
"proto:generate-web": "npx protoc --plugin=./node_modules/.bin/protoc-gen-ts --ts_out=../web/packages/protocol/src --proto_path ../proto/ ../proto/core.proto ../proto/client.proto",
"proto:generate-swift": "npx protoc --swift_opt=Visibility=Public --swift_out ../apple/InlineKit/Sources/InlineProtocol/ --proto_path ../proto/ ../proto/core.proto ../proto/client.proto",
"generate": "bun run proto:generate-ts && bun run proto:generate-swift"
"generate": "bun run proto:generate-ts && bun run proto:generate-web && bun run proto:generate-swift"
},
"dependencies": {},
"devDependencies": {
Expand Down
38 changes: 30 additions & 8 deletions server/src/libs/apn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import APN from "apn"
import { Log } from "@in/server/utils/log"

// Configure APN provider
let apnProvider: APN.Provider | undefined
Expand All @@ -9,14 +10,35 @@ export const getApnProvider = () => {
}

if (!apnProvider) {
apnProvider = new APN.Provider({
token: {
key: Buffer.from(process.env["APN_KEY"] ?? "", "base64").toString("utf-8"),
keyId: process.env["APN_KEY_ID"] as string,
teamId: process.env["APN_TEAM_ID"] as string,
},
production: process.env["NODE_ENV"] === "production",
})
const rawKey = process.env["APN_KEY"]
const keyId = process.env["APN_KEY_ID"]
const teamId = process.env["APN_TEAM_ID"]

if (!rawKey || !keyId || !teamId) {
Log.shared.warn("APN credentials are missing", {
hasKey: !!rawKey,
hasKeyId: !!keyId,
hasTeamId: !!teamId,
})
return undefined
}

const key =
rawKey.includes("BEGIN PRIVATE KEY") ? rawKey.replace(/\\n/g, "\n") : Buffer.from(rawKey, "base64").toString("utf-8")

try {
apnProvider = new APN.Provider({
token: {
key,
keyId,
teamId,
},
production: process.env["NODE_ENV"] === "production",
})
} catch (error) {
Log.shared.error("Failed to initialize APN provider", { error })
return undefined
}
}
return apnProvider
}
Expand Down
55 changes: 44 additions & 11 deletions server/src/libs/apnFailures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
type RecordValue = Record<string, unknown>

const isRecord = (value: unknown): value is RecordValue => typeof value === "object" && value !== null
const isError = (value: unknown): value is Error =>
value instanceof Error ||
(isRecord(value) && typeof value["message"] === "string" && typeof value["stack"] === "string")

const extractErrorDetails = (value: unknown): { errorCode?: string; errorMessage?: string } => {
if (typeof value === "string") return { errorMessage: value }
if (isError(value)) {
const code =
isRecord(value) && typeof value["code"] === "string" ? (value["code"] as string) : undefined
return { errorCode: code, errorMessage: value.message }
}
if (!isRecord(value)) return {}

const errorCode = typeof value["code"] === "string" ? value["code"] : undefined
const errorMessage = typeof value["message"] === "string" ? value["message"] : undefined
return { errorCode, errorMessage }
}

export type ApnFailureSummary = {
status?: number
Expand All @@ -14,6 +31,15 @@ export type ApnFailureSummary = {
const suppressedReasons = new Set(["BadDeviceToken", "Unregistered", "DeviceTokenNotForTopic", "TopicDisallowed"])

export const summarizeApnFailure = (failure: unknown): ApnFailureSummary => {
if (typeof failure === "string") {
return { errorMessage: failure }
}

if (isError(failure)) {
const { errorCode, errorMessage } = extractErrorDetails(failure)
return { errorCode, errorMessage }
}

if (!isRecord(failure)) return {}

const status = typeof failure["status"] === "number" ? failure["status"] : undefined
Expand All @@ -23,24 +49,32 @@ export const summarizeApnFailure = (failure: unknown): ApnFailureSummary => {
let errorCode: string | undefined
let errorMessage: string | undefined

if (typeof failure["reason"] === "string") reason = failure["reason"]
const rawTimestamp = failure["timestamp"]
if (typeof rawTimestamp === "number") {
timestamp = rawTimestamp
} else if (typeof rawTimestamp === "string") {
const parsed = Number(rawTimestamp)
if (Number.isFinite(parsed)) timestamp = parsed
}

const response = failure["response"]
if (isRecord(response)) {
if (typeof response["reason"] === "string") reason = response["reason"]
const rawTimestamp = response["timestamp"]
if (typeof rawTimestamp === "number") {
timestamp = rawTimestamp
} else if (typeof rawTimestamp === "string") {
const parsed = Number(rawTimestamp)
const responseTimestamp = response["timestamp"]
if (typeof responseTimestamp === "number") {
timestamp = responseTimestamp
} else if (typeof responseTimestamp === "string") {
const parsed = Number(responseTimestamp)
if (Number.isFinite(parsed)) timestamp = parsed
}
}

const error = failure["error"]
if (isRecord(error)) {
if (!reason && typeof error["reason"] === "string") reason = error["reason"]
if (typeof error["code"] === "string") errorCode = error["code"]
if (typeof error["message"] === "string") errorMessage = error["message"]
}
if (isRecord(error) && !reason && typeof error["reason"] === "string") reason = error["reason"]
const extracted = extractErrorDetails(error)
if (extracted.errorCode) errorCode = extracted.errorCode
if (extracted.errorMessage) errorMessage = extracted.errorMessage

return { status, reason, timestamp, errorCode, errorMessage }
}
Expand All @@ -56,4 +90,3 @@ export const shouldInvalidateTokenForApnFailure = (summary: ApnFailureSummary):
if (!summary.reason) return false
return suppressedReasons.has(summary.reason)
}

10 changes: 7 additions & 3 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"dev": "vite dev",
"build": "vite build",
"start": "bun run .output/server/index.mjs",
"typecheck": "tsc"
"typecheck": "tsc",
"test": "vitest run",
"test:watch": "vitest"
},
"dependencies": {
"@inline/client": "workspace:*",
"@stylexjs/babel-plugin": "^0.16.0",
"@stylexjs/postcss-plugin": "^0.16.0",
"@stylexjs/stylex": "^0.16.0",
Expand All @@ -20,7 +23,7 @@
"framer-motion": "^11.18.1",
"isbot": "^5.1.17",
"motion": "^12.23.22",
"nitro": "^3.0.1-alpha.1",
"nitro": "latest",
"react": "^19.1.1",
"react-dom": "^19.1.1",
"react-markdown": "^9.0.3",
Expand All @@ -36,6 +39,7 @@
"typescript": "^5.7.2",
"vite": "^7.1.7",
"vite-plugin-stylex": "^0.13.0",
"vite-tsconfig-paths": "^5.1.4"
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^4.0.16"
}
}
20 changes: 20 additions & 0 deletions web/packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@inline/auth",
"private": true,
"version": "0.0.0",
"type": "module",
"types": "./src/index.ts",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
}
},
"dependencies": {
"react": "^19.1.1"
},
"devDependencies": {
"@types/react": "^19.0.1",
"typescript": "^5.7.2"
}
}
Loading
Loading