From a2bcb918bdb2760b5e8970056924e0c792788924 Mon Sep 17 00:00:00 2001 From: "dobby-yivi-agent[bot]" <275734547+dobby-yivi-agent[bot]@users.noreply.github.com> Date: Tue, 2 Jun 2026 23:39:21 +0000 Subject: [PATCH 1/2] fix(metrics): send pg4ol + live ADDIN_VERSION in client-version header The Yivi-hosting dialog's PostGuard client was constructing its own headers object with the v0.2.0-rewrite-era `pg4outlook` token and a hardcoded `ADDIN_VERSION = "0.1.0"`. PR #11 already fixed the token in the taskpane via `clientHeaders()`, but the dialog runtime reintroduced the bug. As a result, all dialog-flow encrypt requests were: - attributed to a non-existent client-id in PKG's per-client Prometheus counter, and - missing `X-Cryptify-Source: outlook`, so cryptify's `detect_channel` fell back to website-channel classification for dialog uploads. The taskpane compose and read views had the same stale `0.1.0` literal, so every release reported the same client version regardless of the actual deployed build. Fix both at the source: - yivi-dialog: drop the inline headers literal and call `clientHeaders(ADDIN_VERSION)` like the taskpane already does. - webpack: inject `process.env.ADDIN_VERSION` from `package.json` via the existing DefinePlugin. release-please bumps `package.json` natively, so this stays in sync without extra config. - pkg-client: export `ADDIN_VERSION` as the single source of truth. - compose-view / read-view / yivi-dialog: import the constant; remove the three `const ADDIN_VERSION = "0.1.0"` literals. Closes #103. --- src/lib/pkg-client.ts | 3 +++ src/taskpane/compose-view.ts | 10 +++++++--- src/taskpane/read-view.ts | 4 +--- src/yivi-dialog/yivi-dialog.ts | 14 ++++++++------ webpack.config.js | 6 ++++++ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/lib/pkg-client.ts b/src/lib/pkg-client.ts index a8e9bf3..46ec106 100644 --- a/src/lib/pkg-client.ts +++ b/src/lib/pkg-client.ts @@ -8,6 +8,9 @@ export const POSTGUARD_WEBSITE_URL: string = process.env.POSTGUARD_WEBSITE_URL a // OnMessageSend launchevent runtime to construct the Yivi dialog URL — // window.location is unreliable there on New Outlook for Mac. export const ADDIN_PUBLIC_URL: string = process.env.ADDIN_PUBLIC_URL as string; +// Injected from package.json at build time so the fourth field of the +// client-version header tracks the deployed release automatically. +export const ADDIN_VERSION: string = process.env.ADDIN_VERSION as string; export const CLIENT_NAME = "Outlook"; export const CLIENT_ID = "pg4ol"; diff --git a/src/taskpane/compose-view.ts b/src/taskpane/compose-view.ts index a937566..51ba0a6 100644 --- a/src/taskpane/compose-view.ts +++ b/src/taskpane/compose-view.ts @@ -23,7 +23,13 @@ import { import { toBase64 } from "../lib/encoding"; import { EMAIL_ATTRIBUTE_TYPE } from "../lib/attributes"; import { Policy, MimeAttachment } from "../lib/types"; -import { PKG_URL, CRYPTIFY_URL, POSTGUARD_WEBSITE_URL, clientHeaders } from "../lib/pkg-client"; +import { + PKG_URL, + CRYPTIFY_URL, + POSTGUARD_WEBSITE_URL, + ADDIN_VERSION, + clientHeaders, +} from "../lib/pkg-client"; import { POSTGUARD_ENCRYPTED_FILENAME } from "../lib/mime"; import { buildSignAttributes, getEncryptionEnabled } from "../lib/settings"; import { t } from "../lib/i18n"; @@ -36,8 +42,6 @@ import { import { mountPolicyPanel } from "./policy-editor"; import { showView, setStatus, showError } from "./taskpane"; -const ADDIN_VERSION = "0.1.0"; - // Internet-header keys shared with the OnMessageSend handler. Custom header // names must be x-prefixed. // diff --git a/src/taskpane/read-view.ts b/src/taskpane/read-view.ts index fbfa31b..0106ea4 100644 --- a/src/taskpane/read-view.ts +++ b/src/taskpane/read-view.ts @@ -26,13 +26,11 @@ import { readMimeHeader, } from "../lib/mime"; import { Badge, FriendlySender } from "../lib/types"; -import { PKG_URL, CRYPTIFY_URL, clientHeaders } from "../lib/pkg-client"; +import { PKG_URL, CRYPTIFY_URL, ADDIN_VERSION, clientHeaders } from "../lib/pkg-client"; import { t } from "../lib/i18n"; import { stringifyError } from "../lib/stringify-error"; import { showView, setStatus, showError } from "./taskpane"; -const ADDIN_VERSION = "0.1.0"; - interface ReadState { ciphertext: Uint8Array | null; recipientEmail: string; diff --git a/src/yivi-dialog/yivi-dialog.ts b/src/yivi-dialog/yivi-dialog.ts index 5f50685..76c49d9 100644 --- a/src/yivi-dialog/yivi-dialog.ts +++ b/src/yivi-dialog/yivi-dialog.ts @@ -10,7 +10,13 @@ import { PostGuard, buildMime, UploadSessionExpiredError } from "@e4a/pg-js"; import { toBase64, fromBase64 } from "../lib/encoding"; -import { PKG_URL, CRYPTIFY_URL, POSTGUARD_WEBSITE_URL } from "../lib/pkg-client"; +import { + PKG_URL, + CRYPTIFY_URL, + POSTGUARD_WEBSITE_URL, + ADDIN_VERSION, + clientHeaders, +} from "../lib/pkg-client"; import { ChunkAssembler, chunkPayload, isChunkMessage, ChunkMessage } from "../lib/dialog-chunk"; import { stringifyError } from "../lib/stringify-error"; import { @@ -19,8 +25,6 @@ import { probeAndClearPendingUpload, } from "../lib/pending-upload"; -const ADDIN_VERSION = "0.1.0"; - interface AttachmentPayload { name: string; type: string; @@ -131,9 +135,7 @@ async function runEncryption(req: EncryptRequest): Promise { const pg = new PostGuard({ pkgUrl: PKG_URL, cryptifyUrl: CRYPTIFY_URL, - headers: { - "X-PostGuard-Client-Version": `Outlook,1.0,pg4outlook,${ADDIN_VERSION}`, - }, + headers: clientHeaders(ADDIN_VERSION), } as never); const recipients = [...req.to, ...req.cc].map((email) => diff --git a/webpack.config.js b/webpack.config.js index 39bebe3..748b47e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,6 +6,8 @@ const HtmlWebpackPlugin = require("html-webpack-plugin"); const webpack = require("webpack"); require("dotenv").config(); +const { version: PACKAGE_VERSION } = require("./package.json"); + const urlDev = "https://localhost:3000/"; const urlProd = process.env.ADDIN_PUBLIC_URL || "https://addin.postguard.eu/"; @@ -92,6 +94,10 @@ module.exports = async (env, options) => { // override (JSRuntime.Url) where window.location is an Office- // internal URL, not the add-in origin. "process.env.ADDIN_PUBLIC_URL": JSON.stringify(dev ? urlDev : urlProd), + // Fourth field of the X-PostGuard-Client-Version header. Sourced + // from package.json so release-please's version bumps flow through + // automatically — no separate constant to forget to update. + "process.env.ADDIN_VERSION": JSON.stringify(PACKAGE_VERSION), }), new HtmlWebpackPlugin({ filename: "taskpane.html", From f83dd9e1700c36afd927b90fd2d2f93476822534 Mon Sep 17 00:00:00 2001 From: "dobby-yivi-agent[bot]" <275734547+dobby-yivi-agent[bot]@users.noreply.github.com> Date: Tue, 2 Jun 2026 23:44:27 +0000 Subject: [PATCH 2/2] docs: list ADDIN_VERSION as the fifth build-time value in CLAUDE.md The build-time-configuration section enumerated four URLs baked in via webpack DefinePlugin. This PR adds ADDIN_VERSION as a fifth value, sourced from package.json instead of .env; update the section to match. --- CLAUDE.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 6c03c80..f8d1f68 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -20,14 +20,15 @@ There are no automated tests in this project. ## Build-time configuration -Four URLs are baked into the bundle via webpack `DefinePlugin` (see `webpack.config.js`): +Five values are baked into the bundle via webpack `DefinePlugin` (see `webpack.config.js`): - `PKG_URL` — PostGuard Key Generation server. - `CRYPTIFY_URL` — Cryptify file-share service. - `POSTGUARD_WEBSITE_URL` — used by the SDK envelope for the browser fallback link. - `ADDIN_PUBLIC_URL` — the add-in's own public origin (e.g. `https://addin.postguard.eu/`). Used by `launchevent.ts` to build the Yivi dialog URL; `window.location` is unreliable in the launchevent runtime on New Outlook for Mac. Webpack picks `urlDev` in dev mode and `urlProd` (overridable via this env var) otherwise. +- `ADDIN_VERSION` — the deployed extension version, read from `package.json` at build time. Stamped into the fourth field of `X-PostGuard-Client-Version` so PKG metrics can distinguish current vs. historical clients. release-please's `release-type: node` bumps `package.json` natively, so this stays in sync without extra config. -These are read from `.env` (copy `.env.example`) or fall back to staging defaults. They are accessed through `src/lib/pkg-client.ts` — do not read `process.env` elsewhere. +The URLs are read from `.env` (copy `.env.example`) or fall back to staging defaults; `ADDIN_VERSION` is sourced from `package.json`. All five are accessed through `src/lib/pkg-client.ts` — do not read `process.env` elsewhere. The webpack config also rewrites `https://localhost:3000/` → `ADDIN_PUBLIC_URL` (default `https://addin.postguard.eu/`) inside `manifest.xml` when building in non-development mode, so the *same* manifest is used for dev sideloading and production hosting.