@vantageos/backend-doctor 0.1.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.
Files changed (108) hide show
  1. package/README.md +88 -0
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.js +94 -0
  4. package/dist/contract.d.ts +18 -0
  5. package/dist/contract.js +29 -0
  6. package/dist/coverage-cli.d.ts +2 -0
  7. package/dist/coverage-cli.js +17 -0
  8. package/dist/coverage.d.ts +32 -0
  9. package/dist/coverage.js +77 -0
  10. package/dist/detectors/oracle-axis1.d.ts +86 -0
  11. package/dist/detectors/oracle-axis1.js +221 -0
  12. package/dist/detectors/oracle-axis2.d.ts +22 -0
  13. package/dist/detectors/oracle-axis2.js +149 -0
  14. package/dist/detectors/predicates.d.ts +19 -0
  15. package/dist/detectors/predicates.js +334 -0
  16. package/dist/detectors/shared.d.ts +56 -0
  17. package/dist/detectors/shared.js +103 -0
  18. package/dist/detectors/source/_scan.d.ts +43 -0
  19. package/dist/detectors/source/_scan.js +82 -0
  20. package/dist/detectors/source/backfill.d.ts +27 -0
  21. package/dist/detectors/source/backfill.js +211 -0
  22. package/dist/detectors/source/contract.d.ts +33 -0
  23. package/dist/detectors/source/contract.js +385 -0
  24. package/dist/detectors/source/identity.d.ts +47 -0
  25. package/dist/detectors/source/identity.js +410 -0
  26. package/dist/detectors/source/jobs.d.ts +10 -0
  27. package/dist/detectors/source/jobs.js +209 -0
  28. package/dist/detectors/source/lifecycle.d.ts +6 -0
  29. package/dist/detectors/source/lifecycle.js +147 -0
  30. package/dist/detectors/source/readbudget.d.ts +6 -0
  31. package/dist/detectors/source/readbudget.js +133 -0
  32. package/dist/detectors/source/refusal.d.ts +6 -0
  33. package/dist/detectors/source/refusal.js +125 -0
  34. package/dist/detectors/source/security.d.ts +37 -0
  35. package/dist/detectors/source/security.js +392 -0
  36. package/dist/detectors/source/writesafety.d.ts +14 -0
  37. package/dist/detectors/source/writesafety.js +345 -0
  38. package/dist/detectors/standard/_doc.d.ts +66 -0
  39. package/dist/detectors/standard/_doc.js +152 -0
  40. package/dist/detectors/standard/r41-frontier.d.ts +58 -0
  41. package/dist/detectors/standard/r41-frontier.js +176 -0
  42. package/dist/detectors/standard/r46-returns-validator.d.ts +61 -0
  43. package/dist/detectors/standard/r46-returns-validator.js +474 -0
  44. package/dist/detectors/standard/standard-doc.d.ts +12 -0
  45. package/dist/detectors/standard/standard-doc.js +271 -0
  46. package/dist/detectors/structural.d.ts +14 -0
  47. package/dist/detectors/structural.js +83 -0
  48. package/dist/engine-types.d.ts +10 -0
  49. package/dist/engine-types.js +1 -0
  50. package/dist/not-checkable.d.ts +22 -0
  51. package/dist/not-checkable.js +37 -0
  52. package/dist/oracle.d.ts +33 -0
  53. package/dist/oracle.js +133 -0
  54. package/dist/registry.d.ts +11 -0
  55. package/dist/registry.js +140 -0
  56. package/dist/report.d.ts +35 -0
  57. package/dist/report.js +138 -0
  58. package/dist/severity.d.ts +30 -0
  59. package/dist/severity.js +121 -0
  60. package/dist/tally.d.ts +57 -0
  61. package/dist/tally.js +152 -0
  62. package/dist/trigger.d.ts +47 -0
  63. package/dist/trigger.js +143 -0
  64. package/fixtures/backend-standard-51ec7af1.md +648 -0
  65. package/fixtures/backend-standard-a9d7877b.md +629 -0
  66. package/fixtures/mcp-app-standard-a74a042b.md +279 -0
  67. package/fixtures/mcp-extension-standard-a74a042b.md +259 -0
  68. package/fixtures/mcp-server-standard-a74a042b.md +434 -0
  69. package/fixtures/mcp-standard-a74a042b.md +354 -0
  70. package/fixtures/vp-1200-green/.pin +1 -0
  71. package/fixtures/vp-1200-green/convex/migrations.ts +350 -0
  72. package/fixtures/vp-1200-green/convex/schema.ts +1243 -0
  73. package/fixtures/vp-1200-red/.pin +1 -0
  74. package/fixtures/vp-1200-red/convex/migrations.ts +239 -0
  75. package/fixtures/vp-1200-red/convex/schema.ts +1243 -0
  76. package/fixtures/vp-by-tool-day158.csv +190 -0
  77. package/fixtures/vp-convex/.github/workflows/npm-publish.yml +163 -0
  78. package/fixtures/vp-convex/.pin +1 -0
  79. package/fixtures/vp-convex/bun.lock +783 -0
  80. package/fixtures/vp-convex/convex/auth.config.ts +8 -0
  81. package/fixtures/vp-convex/convex/briefingNotes.ts +321 -0
  82. package/fixtures/vp-convex/convex/convex.config.ts +14 -0
  83. package/fixtures/vp-convex/convex/credentials.ts +591 -0
  84. package/fixtures/vp-convex/convex/crons.ts +72 -0
  85. package/fixtures/vp-convex/convex/dashboard.ts +199 -0
  86. package/fixtures/vp-convex/convex/gumroadWebhook.ts +815 -0
  87. package/fixtures/vp-convex/convex/issues.ts +544 -0
  88. package/fixtures/vp-convex/convex/kb.ts +305 -0
  89. package/fixtures/vp-convex/convex/kbMutations.ts +192 -0
  90. package/fixtures/vp-convex/convex/kbShared.ts +56 -0
  91. package/fixtures/vp-convex/convex/licenses.ts +443 -0
  92. package/fixtures/vp-convex/convex/memories.ts +406 -0
  93. package/fixtures/vp-convex/convex/memoriesScoped.ts +220 -0
  94. package/fixtures/vp-convex/convex/messages.ts +971 -0
  95. package/fixtures/vp-convex/convex/migrations.ts +239 -0
  96. package/fixtures/vp-convex/convex/missionTemplates.ts +369 -0
  97. package/fixtures/vp-convex/convex/oauth.ts +1608 -0
  98. package/fixtures/vp-convex/convex/oauthMigrations.ts +96 -0
  99. package/fixtures/vp-convex/convex/okfBundleNode.ts +1031 -0
  100. package/fixtures/vp-convex/convex/recurringTasks.ts +386 -0
  101. package/fixtures/vp-convex/convex/schema.ts +1229 -0
  102. package/fixtures/vp-convex/convex/tasks.ts +2782 -0
  103. package/fixtures/vp-r31-green/.pin +1 -0
  104. package/fixtures/vp-r31-green/convex/migrations.ts +350 -0
  105. package/fixtures/vp-r31-red/.pin +1 -0
  106. package/fixtures/vp-r31-red/convex/migrations.ts +286 -0
  107. package/fixtures/vr-by-tool-day159.csv +89 -0
  108. package/package.json +39 -0
@@ -0,0 +1,96 @@
1
+ /**
2
+ * convex/oauthMigrations.ts
3
+ *
4
+ * One-off migration mutations for OAuth schema changes.
5
+ * All migrations are gated by BEARER_SECRET_MASTER and MUST NOT be auto-run.
6
+ * Pi triggers each via master curl. Document required curl in PR body.
7
+ *
8
+ * Migrations:
9
+ * backfillTokenEndpointAuthMethod — D-CROSS-1 (Day 91)
10
+ * Sets tokenEndpointAuthMethod="client_secret_basic" on all oauth_clients
11
+ * rows where the field is absent (null/undefined). RFC 7591 §2 default.
12
+ *
13
+ * Required curl (Pi runs after deploy):
14
+ * curl -X POST https://<CONVEX_URL>/api/mutation \
15
+ * -H "Content-Type: application/json" \
16
+ * -d '{"path":"oauthMigrations:backfillTokenEndpointAuthMethod","args":{"callerToken":"<BEARER_SECRET_MASTER>"}}'
17
+ *
18
+ * Mirror: Theta VCRM convex/oauthMigrations.ts (backfillTokenEndpointAuthMethod)
19
+ * Directive: D-CROSS-1 msg jn75b55wpq16fmkbph4n7j7v3n87z8km
20
+ * Mission: k57c7s478gw1a3e5gmhdeptg5n87z78n
21
+ */
22
+
23
+ import { v } from "convex/values";
24
+ import { mutation } from "./_generated/server";
25
+
26
+ // ─────────────────────────────────────────────────────────────────────────────
27
+ // Master-token gate (inline constant-time compare — mirrors convex/oauth.ts:23-45)
28
+ // Keeping inline in migrations file for isolation (no cross-file import).
29
+ // ─────────────────────────────────────────────────────────────────────────────
30
+
31
+ async function requireMasterAuth(callerToken: string): Promise<void> {
32
+ const masterToken = process.env.BEARER_SECRET_MASTER;
33
+ if (!masterToken) {
34
+ throw new Error("BEARER_SECRET_MASTER env var is not configured");
35
+ }
36
+ const encoder = new TextEncoder();
37
+ const aBytes = encoder.encode(callerToken);
38
+ const bBytes = encoder.encode(masterToken);
39
+ // Constant-time comparison: length mismatch guarded by dummy HMAC to avoid
40
+ // branch-timing leak (pattern from convex/oauth.ts timingSafeEqual).
41
+ if (aBytes.length !== bBytes.length) {
42
+ const dummy = new Uint8Array(aBytes.length);
43
+ const aKey = await crypto.subtle.importKey(
44
+ "raw",
45
+ aBytes,
46
+ { name: "HMAC", hash: "SHA-256" },
47
+ false,
48
+ ["sign"],
49
+ );
50
+ await crypto.subtle.sign("HMAC", aKey, dummy);
51
+ throw new Error("Unauthorized: invalid master token");
52
+ }
53
+ let diff = 0;
54
+ for (let i = 0; i < aBytes.length; i++) {
55
+ diff |= aBytes[i] ^ bBytes[i];
56
+ }
57
+ if (diff !== 0) {
58
+ throw new Error("Unauthorized: invalid master token");
59
+ }
60
+ }
61
+
62
+ // ─────────────────────────────────────────────────────────────────────────────
63
+ // backfillTokenEndpointAuthMethod
64
+ //
65
+ // Sets tokenEndpointAuthMethod="client_secret_basic" on all oauth_clients rows
66
+ // where the field is absent (undefined/null). Safe to re-run (idempotent).
67
+ // Rows with any existing value (e.g. "none") are NOT touched.
68
+ //
69
+ // RFC 7591 §2: "If omitted, the default is 'client_secret_basic'."
70
+ // Mirror: Theta VCRM convex/oauthMigrations.ts backfillTokenEndpointAuthMethod
71
+ // ─────────────────────────────────────────────────────────────────────────────
72
+
73
+ export const backfillTokenEndpointAuthMethod = mutation({
74
+ args: { callerToken: v.string() },
75
+ returns: v.object({ scanned: v.number(), backfilled: v.number() }),
76
+ handler: async (ctx, args) => {
77
+ await requireMasterAuth(args.callerToken);
78
+
79
+ const clients = await ctx.db.query("oauth_clients").collect();
80
+ let backfilled = 0;
81
+
82
+ for (const c of clients) {
83
+ if (
84
+ c.tokenEndpointAuthMethod === undefined ||
85
+ c.tokenEndpointAuthMethod === null
86
+ ) {
87
+ await ctx.db.patch(c._id, {
88
+ tokenEndpointAuthMethod: "client_secret_basic",
89
+ });
90
+ backfilled++;
91
+ }
92
+ }
93
+
94
+ return { scanned: clients.length, backfilled };
95
+ },
96
+ });