paperclip-github-plugin 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/worker.js CHANGED
@@ -1414,7 +1414,11 @@ var PULL_REQUEST_ASSET_EXTENSION_BY_MIME_TYPE = {
1414
1414
  "application/gzip": "gz",
1415
1415
  "application/octet-stream": "bin"
1416
1416
  };
1417
+ var COMPANY_SCOPE_DENIED_SYNC_MESSAGE = "Paperclip denied GitHub Sync worker access for this company because it has no saved GitHub Sync plugin config. Open GitHub Sync settings inside the company and save settings once so the host registers it.";
1417
1418
  var pluginRuntimeContext = null;
1419
+ var rememberedTrustedConfigByCompanyId = /* @__PURE__ */ new Map();
1420
+ var rememberedTrustedInstanceConfig = null;
1421
+ var reportedTrustedConfigReadFailures = /* @__PURE__ */ new Set();
1418
1422
  function isPendingWakeApplied(pendingWake, status, assignee) {
1419
1423
  return (!pendingWake.nextStatus || pendingWake.nextStatus === status) && assignee?.kind === "agent" && assignee.id === pendingWake.assigneeAgentId;
1420
1424
  }
@@ -1586,11 +1590,29 @@ var GITHUB_PULL_REQUEST_CI_CONTEXTS_QUERY = `
1586
1590
  nodes {
1587
1591
  __typename
1588
1592
  ... on CheckRun {
1593
+ name
1589
1594
  status
1590
1595
  conclusion
1596
+ startedAt
1597
+ completedAt
1598
+ checkSuite {
1599
+ createdAt
1600
+ app {
1601
+ id
1602
+ slug
1603
+ }
1604
+ workflowRun {
1605
+ workflow {
1606
+ id
1607
+ }
1608
+ }
1609
+ }
1591
1610
  }
1592
1611
  ... on StatusContext {
1612
+ context
1593
1613
  state
1614
+ createdAt
1615
+ updatedAt
1594
1616
  }
1595
1617
  }
1596
1618
  }
@@ -1662,11 +1684,29 @@ var GITHUB_REPOSITORY_OPEN_PULL_REQUEST_STATUSES_QUERY = `
1662
1684
  nodes {
1663
1685
  __typename
1664
1686
  ... on CheckRun {
1687
+ name
1665
1688
  status
1666
1689
  conclusion
1690
+ startedAt
1691
+ completedAt
1692
+ checkSuite {
1693
+ createdAt
1694
+ app {
1695
+ id
1696
+ slug
1697
+ }
1698
+ workflowRun {
1699
+ workflow {
1700
+ id
1701
+ }
1702
+ }
1703
+ }
1667
1704
  }
1668
1705
  ... on StatusContext {
1706
+ context
1669
1707
  state
1708
+ createdAt
1709
+ updatedAt
1670
1710
  }
1671
1711
  }
1672
1712
  }
@@ -1756,11 +1796,29 @@ var GITHUB_PROJECT_PULL_REQUEST_INSIGHT_FIELDS = `
1756
1796
  nodes {
1757
1797
  __typename
1758
1798
  ... on CheckRun {
1799
+ name
1759
1800
  status
1760
1801
  conclusion
1802
+ startedAt
1803
+ completedAt
1804
+ checkSuite {
1805
+ createdAt
1806
+ app {
1807
+ id
1808
+ slug
1809
+ }
1810
+ workflowRun {
1811
+ workflow {
1812
+ id
1813
+ }
1814
+ }
1815
+ }
1761
1816
  }
1762
1817
  ... on StatusContext {
1818
+ context
1763
1819
  state
1820
+ createdAt
1821
+ updatedAt
1764
1822
  }
1765
1823
  }
1766
1824
  }
@@ -1810,11 +1868,29 @@ var GITHUB_PROJECT_PULL_REQUEST_METRICS_FIELDS = `
1810
1868
  nodes {
1811
1869
  __typename
1812
1870
  ... on CheckRun {
1871
+ name
1813
1872
  status
1814
1873
  conclusion
1874
+ startedAt
1875
+ completedAt
1876
+ checkSuite {
1877
+ createdAt
1878
+ app {
1879
+ id
1880
+ slug
1881
+ }
1882
+ workflowRun {
1883
+ workflow {
1884
+ id
1885
+ }
1886
+ }
1887
+ }
1815
1888
  }
1816
1889
  ... on StatusContext {
1890
+ context
1817
1891
  state
1892
+ createdAt
1893
+ updatedAt
1818
1894
  }
1819
1895
  }
1820
1896
  }
@@ -2222,9 +2298,18 @@ function getErrorMessage(error) {
2222
2298
  }
2223
2299
  return String(error);
2224
2300
  }
2225
- function isPluginSecretReferenceDisabledError(error) {
2301
+ function isCompanyScopeDeniedError(error) {
2302
+ const message = getErrorMessage(error).toLowerCase();
2303
+ const errorName = error instanceof Error ? error.name : "";
2304
+ return errorName === "InvocationScopeDeniedError" || message.includes("invocationscopedenied") || message.includes("company context is required") || message.includes("companyid is required for plugin secret resolution");
2305
+ }
2306
+ function isPluginSecretReferenceUnavailableError(error) {
2226
2307
  const message = getErrorMessage(error).toLowerCase();
2227
- return message.includes("plugin secret reference") && message.includes("disabled") || message.includes("company-scoped plugin config lands");
2308
+ const code = getErrorCode(error)?.toLowerCase();
2309
+ return (
2310
+ // Paperclip 2026.626 rejected every plugin secret ref.
2311
+ message.includes("plugin secret reference") && message.includes("disabled") || message.includes("company-scoped plugin config lands") || code === "binding_missing" || message.includes("not bound to plugin") || message.includes("invalid secret reference for plugin") || isCompanyScopeDeniedError(error)
2312
+ );
2228
2313
  }
2229
2314
  function getErrorCause(error) {
2230
2315
  if (!error || typeof error !== "object" || !("cause" in error)) {
@@ -2566,9 +2651,42 @@ function buildGitHubRepositoryTokenCapabilityAudit(params) {
2566
2651
  warnings
2567
2652
  };
2568
2653
  }
2654
+ var SECRET_ID_UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
2655
+ function isPlainRecord(value) {
2656
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2657
+ }
2658
+ function isSecretRefBinding(value) {
2659
+ return isPlainRecord(value) && value.type === "secret_ref" && typeof value.secretId === "string" && Boolean(value.secretId.trim());
2660
+ }
2569
2661
  function normalizeSecretRef(value) {
2662
+ if (isSecretRefBinding(value)) {
2663
+ return value.secretId.trim();
2664
+ }
2570
2665
  return typeof value === "string" && value.trim() ? value.trim() : void 0;
2571
2666
  }
2667
+ function isLegacySecretRefString(value) {
2668
+ return typeof value === "string" && SECRET_ID_UUID_PATTERN.test(value.trim());
2669
+ }
2670
+ function toSecretRefBinding(secretId) {
2671
+ return { type: "secret_ref", secretId };
2672
+ }
2673
+ function getGitHubTokenRefConfigPath(companyId) {
2674
+ return `githubTokenRefs.${companyId}`;
2675
+ }
2676
+ function getPaperclipBoardApiTokenRefConfigPath(companyId) {
2677
+ return `paperclipBoardApiTokenRefs.${companyId}`;
2678
+ }
2679
+ function readCompanyScopedConfigValue(config, key, companyId) {
2680
+ const map = config[key];
2681
+ return isPlainRecord(map) ? map[companyId] : void 0;
2682
+ }
2683
+ async function resolvePluginSecret(ctx, secretId, options = {}) {
2684
+ const companyId = normalizeCompanyId(options.companyId);
2685
+ return ctx.secrets.resolve(toSecretRefBinding(secretId), {
2686
+ ...companyId ? { companyId } : {},
2687
+ ...options.configPath ? { configPath: options.configPath } : {}
2688
+ });
2689
+ }
2572
2690
  function normalizeGitHubLowercaseString(value) {
2573
2691
  if (typeof value !== "string") {
2574
2692
  return void 0;
@@ -3480,7 +3598,7 @@ function extractGitHubLinksFromCommentBody(body) {
3480
3598
  async function buildToolbarSyncState(ctx, input) {
3481
3599
  const companyId = typeof input.companyId === "string" && input.companyId.trim() ? input.companyId.trim() : void 0;
3482
3600
  const settings = await getActiveOrCurrentSyncState(ctx, companyId);
3483
- const config = await getResolvedConfig(ctx);
3601
+ const config = await getResolvedConfig(ctx, companyId);
3484
3602
  const githubTokenConfigured = hasConfiguredGithubToken(settings, config, companyId);
3485
3603
  const entityId = typeof input.entityId === "string" && input.entityId.trim() ? input.entityId.trim() : void 0;
3486
3604
  const entityType = typeof input.entityType === "string" && input.entityType.trim() ? input.entityType.trim() : void 0;
@@ -4277,7 +4395,7 @@ async function createUnexpectedSyncErrorResult(ctx, trigger, error, companyId) {
4277
4395
  });
4278
4396
  const message = isGitHubRateLimitError(error) ? buildSyncFailureMessage(error, {
4279
4397
  phase: "configuration"
4280
- }) : getErrorMessage(error).trim() || "Unable to run GitHub sync.";
4398
+ }) : isCompanyScopeDeniedError(error) ? COMPANY_SCOPE_DENIED_SYNC_MESSAGE : getErrorMessage(error).trim() || "Unable to run GitHub sync.";
4281
4399
  return saveSettingsSyncState(
4282
4400
  ctx,
4283
4401
  settings,
@@ -4561,7 +4679,10 @@ async function clearExternalCompanyPaperclipBoardApiTokenFallback(ctx, companyId
4561
4679
  }
4562
4680
  async function shouldSeedExternalPaperclipBoardTokenFallback(ctx, companyId, secretRef) {
4563
4681
  try {
4564
- return !(await ctx.secrets.resolve(secretRef)).trim();
4682
+ return !(await resolvePluginSecret(ctx, secretRef, {
4683
+ companyId,
4684
+ configPath: getPaperclipBoardApiTokenRefConfigPath(companyId)
4685
+ })).trim();
4565
4686
  } catch (error) {
4566
4687
  ctx.logger.warn("Unable to resolve the saved Paperclip board API token while checking worker fallback necessity.", {
4567
4688
  companyId,
@@ -5968,12 +6089,45 @@ function sliceProjectPullRequestNumbers(pullRequestNumbers, pageIndex, pageSize
5968
6089
  hasPreviousPage: normalizedPageIndex > 0
5969
6090
  };
5970
6091
  }
6092
+ function getGitHubCiContextAttemptTimestamp(context) {
6093
+ const value = context.type === "checkRun" ? context.startedAt ?? context.createdAt : context.updatedAt ?? context.createdAt;
6094
+ if (!value) {
6095
+ return void 0;
6096
+ }
6097
+ const timestamp = Date.parse(value);
6098
+ return Number.isFinite(timestamp) ? timestamp : void 0;
6099
+ }
6100
+ function getEffectiveGitHubCiContexts(contexts) {
6101
+ const ungroupedContexts = [];
6102
+ const latestContexts = /* @__PURE__ */ new Map();
6103
+ for (const context of contexts) {
6104
+ const timestamp = getGitHubCiContextAttemptTimestamp(context);
6105
+ if (!context.identity || timestamp === void 0) {
6106
+ ungroupedContexts.push(context);
6107
+ continue;
6108
+ }
6109
+ const existing = latestContexts.get(context.identity);
6110
+ if (!existing) {
6111
+ latestContexts.set(context.identity, { contexts: [context], timestamp });
6112
+ continue;
6113
+ }
6114
+ if (timestamp > existing.timestamp) {
6115
+ latestContexts.set(context.identity, { contexts: [context], timestamp });
6116
+ continue;
6117
+ }
6118
+ if (timestamp === existing.timestamp) {
6119
+ existing.contexts.push(context);
6120
+ }
6121
+ }
6122
+ return [...ungroupedContexts, ...[...latestContexts.values()].flatMap(({ contexts: latest }) => latest)];
6123
+ }
5971
6124
  function classifyGitHubPullRequestCiState(contexts) {
5972
- if (contexts.length === 0) {
6125
+ const effectiveContexts = getEffectiveGitHubCiContexts(contexts);
6126
+ if (effectiveContexts.length === 0) {
5973
6127
  return "unfinished";
5974
6128
  }
5975
6129
  let hasPendingContext = false;
5976
- for (const context of contexts) {
6130
+ for (const context of effectiveContexts) {
5977
6131
  if (context.type === "statusContext") {
5978
6132
  const state = context.state?.toUpperCase();
5979
6133
  if (!state) {
@@ -6855,17 +7009,32 @@ function extractGitHubCiContextRecords(nodes) {
6855
7009
  continue;
6856
7010
  }
6857
7011
  if (node.__typename === "CheckRun") {
7012
+ const app = node.checkSuite?.app;
7013
+ const appId = typeof app?.id === "string" && app.id.trim() ? app.id.trim() : void 0;
7014
+ const appSlug = typeof app?.slug === "string" && app.slug.trim() ? app.slug.trim() : void 0;
7015
+ const producerIdentity = appId ? `app:${appId}` : appSlug ? `appSlug:${appSlug}` : void 0;
7016
+ const workflowId = node.checkSuite?.workflowRun?.workflow?.id?.trim();
6858
7017
  contexts.push({
6859
7018
  type: "checkRun",
7019
+ // A rendered check name is stable only within its producer and workflow.
7020
+ // If GitHub omits workflow provenance, retain the context instead of
7021
+ // accidentally hiding a distinct required check with the same name.
7022
+ ...typeof node.name === "string" && node.name.trim() && producerIdentity && workflowId ? { identity: `checkRun:${producerIdentity}:${workflowId}:${node.name.trim()}` } : {},
6860
7023
  status: node.status ?? void 0,
6861
- conclusion: node.conclusion ?? void 0
7024
+ conclusion: node.conclusion ?? void 0,
7025
+ startedAt: node.startedAt ?? void 0,
7026
+ completedAt: node.completedAt ?? void 0,
7027
+ createdAt: node.checkSuite?.createdAt ?? void 0
6862
7028
  });
6863
7029
  continue;
6864
7030
  }
6865
7031
  if (node.__typename === "StatusContext") {
6866
7032
  contexts.push({
6867
7033
  type: "statusContext",
6868
- state: node.state ?? void 0
7034
+ ...typeof node.context === "string" && node.context.trim() ? { identity: `statusContext:${node.context.trim()}` } : {},
7035
+ state: node.state ?? void 0,
7036
+ createdAt: node.createdAt ?? void 0,
7037
+ updatedAt: node.updatedAt ?? void 0
6869
7038
  });
6870
7039
  }
6871
7040
  }
@@ -7057,26 +7226,7 @@ async function getGitHubPullRequestCiSnapshot(octokit, repository, pullRequestNu
7057
7226
  headSha = responseHeadSha.trim().toLowerCase();
7058
7227
  }
7059
7228
  const connection = response.repository?.pullRequest?.statusCheckRollup?.contexts;
7060
- const nodes = connection?.nodes ?? [];
7061
- for (const node of nodes) {
7062
- if (!node?.__typename) {
7063
- continue;
7064
- }
7065
- if (node.__typename === "CheckRun") {
7066
- contexts.push({
7067
- type: "checkRun",
7068
- status: node.status ?? void 0,
7069
- conclusion: node.conclusion ?? void 0
7070
- });
7071
- continue;
7072
- }
7073
- if (node.__typename === "StatusContext") {
7074
- contexts.push({
7075
- type: "statusContext",
7076
- state: node.state ?? void 0
7077
- });
7078
- }
7079
- }
7229
+ contexts.push(...extractGitHubCiContextRecords(connection?.nodes ?? []));
7080
7230
  after = getPageCursor(connection?.pageInfo);
7081
7231
  } while (after);
7082
7232
  return {
@@ -11618,9 +11768,62 @@ async function synchronizePaperclipPullRequestIssueStatuses(ctx, octokit, mappin
11618
11768
  updatedStatusesCount
11619
11769
  };
11620
11770
  }
11621
- async function getResolvedConfig(ctx) {
11771
+ function rememberTrustedConfig(companyId, value) {
11772
+ const record = isPlainRecord(value) ? { ...value } : {};
11773
+ const normalizedCompanyId = normalizeCompanyId(companyId);
11774
+ if (normalizedCompanyId) {
11775
+ rememberedTrustedConfigByCompanyId.set(normalizedCompanyId, record);
11776
+ } else {
11777
+ rememberedTrustedInstanceConfig = record;
11778
+ }
11779
+ }
11780
+ function getRememberedConfiguredCompanyIds() {
11781
+ return [...rememberedTrustedConfigByCompanyId.keys()].sort((left, right) => left.localeCompare(right));
11782
+ }
11783
+ function mergeRememberedTrustedConfig() {
11784
+ const merged = { ...rememberedTrustedInstanceConfig ?? {} };
11785
+ for (const companyId of getRememberedConfiguredCompanyIds()) {
11786
+ const config = rememberedTrustedConfigByCompanyId.get(companyId) ?? {};
11787
+ for (const [key, value] of Object.entries(config)) {
11788
+ const existing = merged[key];
11789
+ if (isPlainRecord(existing) && isPlainRecord(value)) {
11790
+ merged[key] = { ...existing, ...value };
11791
+ } else if (existing === void 0) {
11792
+ merged[key] = value;
11793
+ }
11794
+ }
11795
+ }
11796
+ return merged;
11797
+ }
11798
+ async function readTrustedConfig(ctx, companyId) {
11799
+ const normalizedCompanyId = normalizeCompanyId(companyId);
11800
+ try {
11801
+ const value = await ctx.config.get(normalizedCompanyId);
11802
+ const record = isPlainRecord(value) ? value : {};
11803
+ if (normalizedCompanyId) {
11804
+ rememberedTrustedConfigByCompanyId.set(normalizedCompanyId, { ...record });
11805
+ }
11806
+ return record;
11807
+ } catch (error) {
11808
+ const remembered = normalizedCompanyId ? rememberedTrustedConfigByCompanyId.get(normalizedCompanyId) : mergeRememberedTrustedConfig();
11809
+ const warningKey = `${normalizedCompanyId ?? "<instance>"}:${getErrorMessage(error)}`;
11810
+ if (!reportedTrustedConfigReadFailures.has(warningKey)) {
11811
+ reportedTrustedConfigReadFailures.add(warningKey);
11812
+ ctx.logger.warn(
11813
+ "GitHub Sync could not read company-scoped plugin config from the Paperclip host; using the last config the host delivered for this scope.",
11814
+ {
11815
+ companyId: normalizedCompanyId ?? null,
11816
+ usingDeliveredConfig: Boolean(remembered && Object.keys(remembered).length > 0),
11817
+ error: getErrorMessage(error)
11818
+ }
11819
+ );
11820
+ }
11821
+ return remembered ?? {};
11822
+ }
11823
+ }
11824
+ async function getResolvedConfig(ctx, companyId) {
11622
11825
  const [savedConfig, externalConfig] = await Promise.all([
11623
- ctx.config.get(),
11826
+ readTrustedConfig(ctx, companyId),
11624
11827
  readExternalConfig(ctx)
11625
11828
  ]);
11626
11829
  return {
@@ -11632,7 +11835,8 @@ function getConfiguredGithubTokenSource(settings, config, companyId) {
11632
11835
  const normalizedCompanyId = normalizeCompanyId(companyId);
11633
11836
  const companyFallbackToken = normalizedCompanyId ? normalizeGitHubToken(config.githubTokensByCompanyId?.[normalizedCompanyId]) : void 0;
11634
11837
  const hasScopedGitHubTokenRefs = hasAnyScopedValue(settings?.githubTokenRefs) || hasAnyScopedValue(config.githubTokenRefs);
11635
- const secretRef = normalizedCompanyId ? normalizeSecretRef(config.githubTokenRefs?.[normalizedCompanyId]) ?? normalizeSecretRef(settings?.githubTokenRefs?.[normalizedCompanyId]) ?? (!hasScopedGitHubTokenRefs ? normalizeGitHubTokenRef(config.githubTokenRef) ?? normalizeGitHubTokenRef(settings?.githubTokenRef) : void 0) : normalizeGitHubTokenRef(config.githubTokenRef) ?? normalizeGitHubTokenRef(settings?.githubTokenRef) ?? (() => {
11838
+ const companyScopedSecretRef = normalizedCompanyId ? normalizeSecretRef(config.githubTokenRefs?.[normalizedCompanyId]) ?? normalizeSecretRef(settings?.githubTokenRefs?.[normalizedCompanyId]) : void 0;
11839
+ const secretRef = normalizedCompanyId ? companyScopedSecretRef ?? (!hasScopedGitHubTokenRefs ? normalizeGitHubTokenRef(config.githubTokenRef) ?? normalizeGitHubTokenRef(settings?.githubTokenRef) : void 0) : normalizeGitHubTokenRef(config.githubTokenRef) ?? normalizeGitHubTokenRef(settings?.githubTokenRef) ?? (() => {
11636
11840
  const configuredRefs = [
11637
11841
  ...Object.values(config.githubTokenRefs ?? {}),
11638
11842
  ...Object.values(settings?.githubTokenRefs ?? {})
@@ -11643,6 +11847,7 @@ function getConfiguredGithubTokenSource(settings, config, companyId) {
11643
11847
  if (secretRef) {
11644
11848
  return {
11645
11849
  secretRef,
11850
+ ...normalizedCompanyId && companyScopedSecretRef === secretRef ? { configPath: getGitHubTokenRefConfigPath(normalizedCompanyId) } : {},
11646
11851
  ...companyFallbackToken ? { fallbackToken: companyFallbackToken } : {}
11647
11852
  };
11648
11853
  }
@@ -11742,12 +11947,15 @@ async function resolvePaperclipApiAuthTokens(ctx, settings, config, mappings) {
11742
11947
  continue;
11743
11948
  }
11744
11949
  try {
11745
- const token = (await ctx.secrets.resolve(secretRef)).trim();
11950
+ const token = (await resolvePluginSecret(ctx, secretRef, {
11951
+ companyId,
11952
+ configPath: getPaperclipBoardApiTokenRefConfigPath(companyId)
11953
+ })).trim();
11746
11954
  if (token) {
11747
11955
  tokensByCompanyId.set(companyId, token);
11748
11956
  }
11749
11957
  } catch (error) {
11750
- if (fallbackToken && isPluginSecretReferenceDisabledError(error)) {
11958
+ if (fallbackToken && isPluginSecretReferenceUnavailableError(error)) {
11751
11959
  ctx.logger.warn("GitHub Sync is using a worker-local Paperclip board token fallback because plugin secret refs are unavailable in this host.", {
11752
11960
  companyId,
11753
11961
  secretRef,
@@ -11767,17 +11975,20 @@ async function resolvePaperclipApiAuthTokens(ctx, settings, config, mappings) {
11767
11975
  }
11768
11976
  async function resolveGithubToken(ctx, options = {}) {
11769
11977
  const settings = options.settings ?? normalizeSettings(await ctx.state.get(SETTINGS_SCOPE));
11770
- const config = options.config ?? await getResolvedConfig(ctx);
11978
+ const config = options.config ?? await getResolvedConfig(ctx, options.companyId);
11771
11979
  const configuredTokenSource = getConfiguredGithubTokenSource(settings, config, options.companyId);
11772
11980
  if (configuredTokenSource.secretRef) {
11773
11981
  try {
11774
- const token = (await ctx.secrets.resolve(configuredTokenSource.secretRef)).trim();
11982
+ const token = (await resolvePluginSecret(ctx, configuredTokenSource.secretRef, {
11983
+ companyId: options.companyId,
11984
+ ...configuredTokenSource.configPath ? { configPath: configuredTokenSource.configPath } : {}
11985
+ })).trim();
11775
11986
  if (token) {
11776
11987
  return token;
11777
11988
  }
11778
11989
  return configuredTokenSource.fallbackToken ?? "";
11779
11990
  } catch (error) {
11780
- if (configuredTokenSource.fallbackToken && isPluginSecretReferenceDisabledError(error)) {
11991
+ if (configuredTokenSource.fallbackToken && isPluginSecretReferenceUnavailableError(error)) {
11781
11992
  ctx.logger.warn("GitHub Sync is using a worker-local company token fallback because plugin secret refs are unavailable in this host.", {
11782
11993
  companyId: normalizeCompanyId(options.companyId),
11783
11994
  secretRef: configuredTokenSource.secretRef,
@@ -14061,7 +14272,7 @@ async function buildProjectPullRequestsPageData(ctx, input) {
14061
14272
  };
14062
14273
  }
14063
14274
  const scope = await requireProjectPullRequestScope(ctx, input, projectMappings);
14064
- const config = await getResolvedConfig(ctx);
14275
+ const config = await getResolvedConfig(ctx, scope.companyId);
14065
14276
  if (!hasConfiguredGithubToken(settings, config, scope.companyId)) {
14066
14277
  return {
14067
14278
  status: "missing_token",
@@ -14252,7 +14463,7 @@ async function buildProjectPullRequestMetricsData(ctx, input) {
14252
14463
  failingPullRequests: 0
14253
14464
  };
14254
14465
  }
14255
- const config = await getResolvedConfig(ctx);
14466
+ const config = await getResolvedConfig(ctx, companyId);
14256
14467
  if (!hasConfiguredGithubToken(settings, config, companyId)) {
14257
14468
  return {
14258
14469
  status: "missing_token",
@@ -14301,7 +14512,7 @@ async function buildProjectPullRequestCountData(ctx, input) {
14301
14512
  totalOpenPullRequests: 0
14302
14513
  };
14303
14514
  }
14304
- const config = await getResolvedConfig(ctx);
14515
+ const config = await getResolvedConfig(ctx, companyId);
14305
14516
  if (!hasConfiguredGithubToken(settings, config, companyId)) {
14306
14517
  return {
14307
14518
  status: "missing_token",
@@ -14338,7 +14549,7 @@ async function buildSettingsTokenPermissionAuditData(ctx, input) {
14338
14549
  };
14339
14550
  }
14340
14551
  const settings = normalizeSettings(await ctx.state.get(SETTINGS_SCOPE));
14341
- const config = await getResolvedConfig(ctx);
14552
+ const config = await getResolvedConfig(ctx, requestedCompanyId);
14342
14553
  if (!hasConfiguredGithubToken(settings, config, requestedCompanyId)) {
14343
14554
  return {
14344
14555
  status: "missing_token",
@@ -15322,7 +15533,7 @@ async function listScheduledSyncTargets(ctx, settings) {
15322
15533
  async function performSync(ctx, trigger, options = {}) {
15323
15534
  const targetCompanyId = normalizeCompanyId(options.target?.companyId);
15324
15535
  const baseSettings = normalizeSettings(await ctx.state.get(SETTINGS_SCOPE));
15325
- const config = await getResolvedConfig(ctx);
15536
+ const config = await getResolvedConfig(ctx, targetCompanyId);
15326
15537
  const settings = materializeScopedSettings(baseSettings, config, targetCompanyId);
15327
15538
  const importRegistry = normalizeImportRegistry(await ctx.state.get(IMPORT_REGISTRY_SCOPE));
15328
15539
  const remoteActionRegistry = normalizeRemoteActionRegistry(await ctx.state.get(REMOTE_ACTION_REGISTRY_SCOPE));
@@ -16245,11 +16456,11 @@ async function startSync(ctx, trigger, options = {}) {
16245
16456
  return quickResult2 ?? await getActiveOrCurrentSyncState(ctx);
16246
16457
  }
16247
16458
  await reconcileOrphanedRunningSyncState(ctx, options.target?.companyId);
16459
+ const targetCompanyId = normalizeCompanyId(options.target?.companyId);
16248
16460
  const [config, persistedSettings] = await Promise.all([
16249
- getResolvedConfig(ctx),
16461
+ getResolvedConfig(ctx, targetCompanyId),
16250
16462
  ctx.state.get(SETTINGS_SCOPE).then((value) => normalizeSettings(value))
16251
16463
  ]);
16252
- const targetCompanyId = normalizeCompanyId(options.target?.companyId);
16253
16464
  const token = await resolveGithubToken(ctx, {
16254
16465
  companyId: targetCompanyId,
16255
16466
  config,
@@ -17719,6 +17930,19 @@ var __testing = {
17719
17930
  }
17720
17931
  };
17721
17932
  var plugin = definePlugin({
17933
+ // GitHub Sync serves every company on the instance from one worker; Paperclip 2026.831 delivers
17934
+ // one company-scoped config per configured company and rejects that fan-out unless the plugin
17935
+ // declares it keys config by company.
17936
+ multiCompanyConfig: true,
17937
+ async onConfigChanged(newConfig, context) {
17938
+ const companyId = normalizeCompanyId(context?.companyId) ?? null;
17939
+ rememberTrustedConfig(companyId, newConfig);
17940
+ clearGitHubRepositoryTokenCapabilityAudits();
17941
+ pluginRuntimeContext?.logger.debug("GitHub Sync received company-scoped plugin config.", {
17942
+ companyId,
17943
+ configKeys: Object.keys(isPlainRecord(newConfig) ? newConfig : {})
17944
+ });
17945
+ },
17722
17946
  async setup(ctx) {
17723
17947
  pluginRuntimeContext = ctx;
17724
17948
  ctx.data.register("settings.registration", async (input) => {
@@ -17729,15 +17953,24 @@ var plugin = definePlugin({
17729
17953
  const saved = await ctx.state.get(SETTINGS_SCOPE);
17730
17954
  const importRegistry = normalizeImportRegistry(await ctx.state.get(IMPORT_REGISTRY_SCOPE));
17731
17955
  const normalizedSettings = normalizeSettings(saved);
17732
- const [config, trustedConfig] = await Promise.all([
17733
- getResolvedConfig(ctx),
17734
- ctx.config.get().then((value) => normalizeConfig(value))
17956
+ const [config, rawTrustedConfig] = await Promise.all([
17957
+ getResolvedConfig(ctx, requestedCompanyId),
17958
+ readTrustedConfig(ctx, requestedCompanyId)
17735
17959
  ]);
17960
+ const trustedConfig = normalizeConfig(rawTrustedConfig);
17736
17961
  const githubTokenConfigured = hasConfiguredGithubToken(normalizedSettings, config, requestedCompanyId);
17737
17962
  const configuredGitHubTokenRef = getConfiguredGitHubTokenRef(trustedConfig, requestedCompanyId);
17738
17963
  const savedGitHubTokenRef = getSavedGitHubTokenRef(normalizedSettings, requestedCompanyId);
17739
17964
  const configuredBoardTokenRef = getConfiguredPaperclipBoardApiTokenRef(trustedConfig, requestedCompanyId);
17740
17965
  const savedBoardTokenRef = getSavedPaperclipBoardApiTokenRef(normalizedSettings, requestedCompanyId);
17966
+ const configuredGitHubTokenRefIsLegacy = Boolean(
17967
+ requestedCompanyId && isLegacySecretRefString(readCompanyScopedConfigValue(rawTrustedConfig, "githubTokenRefs", requestedCompanyId))
17968
+ );
17969
+ const configuredBoardTokenRefIsLegacy = Boolean(
17970
+ requestedCompanyId && isLegacySecretRefString(
17971
+ readCompanyScopedConfigValue(rawTrustedConfig, "paperclipBoardApiTokenRefs", requestedCompanyId)
17972
+ )
17973
+ );
17741
17974
  const settingsForResponse = sanitizeSettingsForCurrentSetup(
17742
17975
  materializeScopedSettings(normalizedSettings, config, requestedCompanyId),
17743
17976
  {
@@ -17758,10 +17991,12 @@ var plugin = definePlugin({
17758
17991
  githubTokenConfigured,
17759
17992
  paperclipBoardAccessConfigured: requestedCompanyId ? hasConfiguredPaperclipBoardAccess(settingsForResponse, config, requestedCompanyId) : hasConfiguredPaperclipBoardAccessForMappings(settingsForResponse, config, scopedMappings),
17760
17993
  ...savedGitHubTokenRef ? { githubTokenConfigSyncRef: savedGitHubTokenRef } : {},
17761
- githubTokenNeedsConfigSync: Boolean(savedGitHubTokenRef && configuredGitHubTokenRef !== savedGitHubTokenRef),
17994
+ githubTokenNeedsConfigSync: Boolean(
17995
+ savedGitHubTokenRef && (configuredGitHubTokenRef !== savedGitHubTokenRef || configuredGitHubTokenRefIsLegacy)
17996
+ ),
17762
17997
  ...savedBoardTokenRef ? { paperclipBoardAccessConfigSyncRef: savedBoardTokenRef } : {},
17763
17998
  paperclipBoardAccessNeedsConfigSync: Boolean(
17764
- savedBoardTokenRef && configuredBoardTokenRef !== savedBoardTokenRef
17999
+ savedBoardTokenRef && (configuredBoardTokenRef !== savedBoardTokenRef || configuredBoardTokenRefIsLegacy)
17765
18000
  )
17766
18001
  };
17767
18002
  });
@@ -17852,9 +18087,9 @@ var plugin = definePlugin({
17852
18087
  });
17853
18088
  ctx.actions.register("settings.saveRegistration", async (input, actionContext) => {
17854
18089
  const previous = normalizeSettings(await ctx.state.get(SETTINGS_SCOPE));
17855
- const config = await getResolvedConfig(ctx);
17856
18090
  const record = normalizeActionRecord(input, actionContext);
17857
18091
  const requestedCompanyId = normalizeCompanyId(record.companyId);
18092
+ const config = await getResolvedConfig(ctx, requestedCompanyId);
17858
18093
  const requestedGitHubTokenLogin = "githubTokenLogin" in record ? normalizeOptionalString2(record.githubTokenLogin) : void 0;
17859
18094
  const hasMappingsPatch = "mappings" in record;
17860
18095
  const hasAdvancedSettingsPatch = "advancedSettings" in record;
@@ -17957,15 +18192,15 @@ var plugin = definePlugin({
17957
18192
  });
17958
18193
  ctx.actions.register("settings.updateBoardAccess", async (input, actionContext) => {
17959
18194
  const previous = normalizeSettings(await ctx.state.get(SETTINGS_SCOPE));
17960
- const [config, trustedConfig] = await Promise.all([
17961
- getResolvedConfig(ctx),
17962
- ctx.config.get().then((value) => normalizeConfig(value))
17963
- ]);
17964
18195
  const record = normalizeActionRecord(input, actionContext);
17965
18196
  const companyId = normalizeCompanyId(record.companyId);
17966
18197
  if (!companyId) {
17967
18198
  throw new Error("A company id is required to update Paperclip board access.");
17968
18199
  }
18200
+ const [config, trustedConfig] = await Promise.all([
18201
+ getResolvedConfig(ctx, companyId),
18202
+ readTrustedConfig(ctx, companyId).then((value) => normalizeConfig(value))
18203
+ ]);
17969
18204
  const nextSecretRef = normalizeSecretRef(record.paperclipBoardApiTokenRef);
17970
18205
  const boardAccessRecord = record.paperclipBoardAccess && typeof record.paperclipBoardAccess === "object" ? record.paperclipBoardAccess : {};
17971
18206
  const boardAuthorizationRecord = boardAccessRecord.authorization && typeof boardAccessRecord.authorization === "object" ? boardAccessRecord.authorization : {};
@@ -18059,7 +18294,10 @@ var plugin = definePlugin({
18059
18294
  throw new Error("A validated GitHub token is required to prepare the worker token fallback.");
18060
18295
  }
18061
18296
  try {
18062
- const resolvedToken = (await ctx.secrets.resolve(githubTokenRef)).trim();
18297
+ const resolvedToken = (await resolvePluginSecret(ctx, githubTokenRef, {
18298
+ companyId,
18299
+ configPath: getGitHubTokenRefConfigPath(companyId)
18300
+ })).trim();
18063
18301
  if (resolvedToken) {
18064
18302
  return {
18065
18303
  secretResolvable: true,
@@ -18067,7 +18305,7 @@ var plugin = definePlugin({
18067
18305
  };
18068
18306
  }
18069
18307
  } catch (error) {
18070
- if (!isPluginSecretReferenceDisabledError(error)) {
18308
+ if (!isPluginSecretReferenceUnavailableError(error)) {
18071
18309
  throw error;
18072
18310
  }
18073
18311
  await writeExternalCompanyGitHubTokenFallback(ctx, companyId, token);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "paperclip-github-plugin",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "Paperclip plugin for synchronizing GitHub issues into Paperclip projects.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
- "packageManager": "pnpm@11.9.0",
7
+ "packageManager": "pnpm@11.11.0",
8
8
  "engines": {
9
- "node": ">=20"
9
+ "node": ">=24.11.0"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@octokit/rest": "^22.0.1",
44
- "@paperclipai/plugin-sdk": "^2026.626.0",
44
+ "@paperclipai/plugin-sdk": "^2026.831.1",
45
45
  "react": "^19.2.7",
46
46
  "react-markdown": "^10.1.0",
47
47
  "rehype-raw": "^7.0.0",
@@ -49,11 +49,11 @@
49
49
  "remark-gfm": "^4.0.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/node": "24.13.2",
52
+ "@types/node": "24.13.3",
53
53
  "@types/react": "19.2.17",
54
54
  "esbuild": "0.28.1",
55
55
  "playwright": "1.61.1",
56
- "tsx": "4.22.4",
56
+ "tsx": "4.23.1",
57
57
  "typescript": "6.0.3"
58
58
  }
59
59
  }