Skip to content
Open
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
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,38 @@ export const manifest: PaperclipPluginManifestV1 = {
type: 'object',
title: 'GitHub Token Secrets',
additionalProperties: {
type: 'string'
oneOf: [
{ type: 'string' },
{
type: 'object',
properties: {
type: { const: 'secret_ref' },
secretId: { type: 'string' },
version: { oneOf: [{ const: 'latest' }, { type: 'integer', minimum: 1 }] }
},
required: ['type', 'secretId'],
additionalProperties: false
}
]
}
},
paperclipBoardApiTokenRefs: {
type: 'object',
title: 'Paperclip Board Token Secrets',
additionalProperties: {
type: 'string'
oneOf: [
{ type: 'string' },
{
type: 'object',
properties: {
type: { const: 'secret_ref' },
secretId: { type: 'string' },
version: { oneOf: [{ const: 'latest' }, { type: 'integer', minimum: 1 }] }
},
required: ['type', 'secretId'],
additionalProperties: false
}
]
}
},
paperclipApiBaseUrl: {
Expand Down
13 changes: 8 additions & 5 deletions src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { normalizeCompanyAssigneeOptionsResponse, type GitHubSyncAssigneeOption
import { buildPaperclipUrl, fetchJson, fetchPaperclipHealth, resolveCliAuthPollUrl } from './http.ts';
import { resolveInstalledGitHubSyncPluginId, resolvePluginSettingsHref } from './plugin-installation.ts';
import {
createPluginConfigSecretRef,
mergePluginConfig,
type GitHubSyncPluginConfig,
normalizePaperclipApiBaseUrl,
Expand Down Expand Up @@ -12021,16 +12022,17 @@ export function GitHubSyncSettingsPage(): React.JSX.Element {

const secretName = `github_sync_${companyId.replace(/[^a-z0-9]+/gi, '_').toLowerCase()}`;
const secret = await resolveOrCreateCompanySecret(companyId, secretName, trimmedToken);
const secretRef = createPluginConfigSecretRef(secret.id);

await patchPluginConfig(pluginId, {
githubTokenRefs: {
[companyId]: secret.id
[companyId]: secretRef
}
});
await saveRegistration({
companyId,
githubTokenRefs: {
[companyId]: secret.id
[companyId]: secretRef
},
githubTokenLogin: validation.login
});
Expand All @@ -12039,7 +12041,7 @@ export function GitHubSyncSettingsPage(): React.JSX.Element {
try {
await ensureGitHubTokenAvailable({
companyId,
githubTokenRef: secret.id,
githubTokenRef: secretRef,
token: trimmedToken
});
} catch (error) {
Expand Down Expand Up @@ -12128,15 +12130,16 @@ export function GitHubSyncSettingsPage(): React.JSX.Element {
const boardIdentity = await fetchBoardAccessIdentity(boardApiToken);
const secretName = `paperclip_board_api_${companyId.replace(/[^a-z0-9]+/gi, '_').toLowerCase()}`;
const secret = await resolveOrCreateCompanySecret(companyId, secretName, boardApiToken);
const secretRef = createPluginConfigSecretRef(secret.id);

await patchPluginConfig(pluginId, {
paperclipBoardApiTokenRefs: {
[companyId]: secret.id
[companyId]: secretRef
}
});
await updateBoardAccess({
companyId,
paperclipBoardApiTokenRef: secret.id,
paperclipBoardApiTokenRef: secretRef,
paperclipBoardAccess: {
authorization: {
bearer: boardApiToken
Expand Down
51 changes: 45 additions & 6 deletions src/ui/plugin-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
export type PluginConfigBoardTokenRefs = Record<string, string>;
export type PluginConfigGitHubTokenRefs = Record<string, string>;
export interface PluginConfigSecretRef {
type: 'secret_ref';
secretId: string;
version?: number | 'latest';
}

export type PluginConfigSecretReference = string | PluginConfigSecretRef;
export type PluginConfigBoardTokenRefs = Record<string, PluginConfigSecretReference>;
export type PluginConfigGitHubTokenRefs = Record<string, PluginConfigSecretReference>;

export interface GitHubSyncPluginConfig extends Record<string, unknown> {
githubTokenRefs?: PluginConfigGitHubTokenRefs;
Expand All @@ -11,6 +18,38 @@ function normalizeOptionalString(value: unknown): string | undefined {
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
}

export function createPluginConfigSecretRef(secretId: string): PluginConfigSecretRef {
return { type: 'secret_ref', secretId };
}

export function normalizePluginConfigSecretRef(value: unknown): PluginConfigSecretReference | undefined {
const stringRef = normalizeOptionalString(value);
if (stringRef) {
return stringRef;
}

if (!value || typeof value !== 'object' || Array.isArray(value)) {
return undefined;
}

const record = value as Record<string, unknown>;
const secretId = normalizeOptionalString(record.secretId);
if (record.type !== 'secret_ref' || !secretId) {
return undefined;
}

const version = record.version === 'latest'
? 'latest' as const
: typeof record.version === 'number' && Number.isSafeInteger(record.version) && record.version > 0
? record.version
: undefined;
return {
type: 'secret_ref',
secretId,
...(version ? { version } : {})
};
}

export function normalizePaperclipApiBaseUrl(value: unknown): string | undefined {
const normalizedValue = normalizeOptionalString(value);
if (!normalizedValue) {
Expand All @@ -32,12 +71,12 @@ export function normalizePluginConfigBoardTokenRefs(value: unknown): PluginConfi
const entries = Object.entries(value as Record<string, unknown>)
.map(([companyId, secretRef]) => {
const normalizedCompanyId = normalizeOptionalString(companyId);
const normalizedSecretRef = normalizeOptionalString(secretRef);
const normalizedSecretRef = normalizePluginConfigSecretRef(secretRef);
return normalizedCompanyId && normalizedSecretRef
? [normalizedCompanyId, normalizedSecretRef] as const
: null;
})
.filter((entry): entry is readonly [string, string] => Boolean(entry));
.filter((entry): entry is readonly [string, PluginConfigSecretReference] => Boolean(entry));

if (entries.length === 0) {
return undefined;
Expand All @@ -54,12 +93,12 @@ export function normalizePluginConfigGitHubTokenRefs(value: unknown): PluginConf
const entries = Object.entries(value as Record<string, unknown>)
.map(([companyId, secretRef]) => {
const normalizedCompanyId = normalizeOptionalString(companyId);
const normalizedSecretRef = normalizeOptionalString(secretRef);
const normalizedSecretRef = normalizePluginConfigSecretRef(secretRef);
return normalizedCompanyId && normalizedSecretRef
? [normalizedCompanyId, normalizedSecretRef] as const
: null;
})
.filter((entry): entry is readonly [string, string] => Boolean(entry));
.filter((entry): entry is readonly [string, PluginConfigSecretReference] => Boolean(entry));

if (entries.length === 0) {
return undefined;
Expand Down
Loading