@adonis-agora/config 0.0.0-stage → 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 (245) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/LICENSE +21 -0
  3. package/README.md +28 -2
  4. package/dist/assets/spa/assets/index-CAHRPNZj.js +50 -0
  5. package/dist/assets/spa/assets/index-CAHRPNZj.js.map +1 -0
  6. package/dist/assets/spa/assets/index-Cvjcgc6i.css +1 -0
  7. package/dist/assets/spa/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  8. package/dist/assets/spa/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  9. package/dist/assets/spa/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  10. package/dist/assets/spa/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  11. package/dist/assets/spa/assets/jetbrains-mono-latin-600-normal-BfsvjouI.woff +0 -0
  12. package/dist/assets/spa/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
  13. package/dist/assets/spa/assets/sora-latin-400-normal-CRt88UEn.woff2 +0 -0
  14. package/dist/assets/spa/assets/sora-latin-400-normal-OW7qkl5a.woff +0 -0
  15. package/dist/assets/spa/assets/sora-latin-500-normal-01eiPEn0.woff2 +0 -0
  16. package/dist/assets/spa/assets/sora-latin-500-normal-w58xtEt9.woff +0 -0
  17. package/dist/assets/spa/assets/sora-latin-600-normal-1_7fyUAY.woff +0 -0
  18. package/dist/assets/spa/assets/sora-latin-600-normal-Cdg4DaK0.woff2 +0 -0
  19. package/dist/assets/spa/assets/sora-latin-700-normal-9waGdLWo.woff2 +0 -0
  20. package/dist/assets/spa/assets/sora-latin-700-normal-BKPfQAnC.woff +0 -0
  21. package/dist/assets/spa/index.html +20 -0
  22. package/dist/commands/agora_doctor.d.ts +23 -0
  23. package/dist/commands/agora_doctor.d.ts.map +1 -0
  24. package/dist/commands/agora_doctor.js +120 -0
  25. package/dist/commands/agora_doctor.js.map +1 -0
  26. package/dist/commands/config.d.ts +100 -0
  27. package/dist/commands/config.d.ts.map +1 -0
  28. package/dist/commands/config.js +447 -0
  29. package/dist/commands/config.js.map +1 -0
  30. package/dist/commands/crypto.d.ts +17 -0
  31. package/dist/commands/crypto.d.ts.map +1 -0
  32. package/dist/commands/crypto.js +89 -0
  33. package/dist/commands/crypto.js.map +1 -0
  34. package/dist/commands/main.d.ts +16 -0
  35. package/dist/commands/main.d.ts.map +1 -0
  36. package/dist/commands/main.js +31 -0
  37. package/dist/commands/main.js.map +1 -0
  38. package/dist/commands/pull.d.ts +36 -0
  39. package/dist/commands/pull.d.ts.map +1 -0
  40. package/dist/commands/pull.js +262 -0
  41. package/dist/commands/pull.js.map +1 -0
  42. package/dist/commands/shared.d.ts +33 -0
  43. package/dist/commands/shared.d.ts.map +1 -0
  44. package/dist/commands/shared.js +134 -0
  45. package/dist/commands/shared.js.map +1 -0
  46. package/dist/commands/tenant_key.d.ts +22 -0
  47. package/dist/commands/tenant_key.d.ts.map +1 -0
  48. package/dist/commands/tenant_key.js +141 -0
  49. package/dist/commands/tenant_key.js.map +1 -0
  50. package/dist/configure.d.ts +13 -0
  51. package/dist/configure.d.ts.map +1 -0
  52. package/dist/configure.js +33 -0
  53. package/dist/configure.js.map +1 -0
  54. package/dist/providers/config_provider.d.ts +31 -0
  55. package/dist/providers/config_provider.d.ts.map +1 -0
  56. package/dist/providers/config_provider.js +458 -0
  57. package/dist/providers/config_provider.js.map +1 -0
  58. package/dist/services/main.d.ts +39 -0
  59. package/dist/services/main.d.ts.map +1 -0
  60. package/dist/services/main.js +67 -0
  61. package/dist/services/main.js.map +1 -0
  62. package/dist/src/admin.d.ts +110 -0
  63. package/dist/src/admin.d.ts.map +1 -0
  64. package/dist/src/admin.js +326 -0
  65. package/dist/src/admin.js.map +1 -0
  66. package/dist/src/bootstrap.d.ts +35 -0
  67. package/dist/src/bootstrap.d.ts.map +1 -0
  68. package/dist/src/bootstrap.js +35 -0
  69. package/dist/src/bootstrap.js.map +1 -0
  70. package/dist/src/crypto/secrets.d.ts +67 -0
  71. package/dist/src/crypto/secrets.d.ts.map +1 -0
  72. package/dist/src/crypto/secrets.js +100 -0
  73. package/dist/src/crypto/secrets.js.map +1 -0
  74. package/dist/src/crypto/tenant_keys.d.ts +49 -0
  75. package/dist/src/crypto/tenant_keys.d.ts.map +1 -0
  76. package/dist/src/crypto/tenant_keys.js +134 -0
  77. package/dist/src/crypto/tenant_keys.js.map +1 -0
  78. package/dist/src/crypto-kit/asymmetric.d.ts +61 -0
  79. package/dist/src/crypto-kit/asymmetric.d.ts.map +1 -0
  80. package/dist/src/crypto-kit/asymmetric.js +201 -0
  81. package/dist/src/crypto-kit/asymmetric.js.map +1 -0
  82. package/dist/src/crypto-kit/index.d.ts +5 -0
  83. package/dist/src/crypto-kit/index.d.ts.map +1 -0
  84. package/dist/src/crypto-kit/index.js +6 -0
  85. package/dist/src/crypto-kit/index.js.map +1 -0
  86. package/dist/src/crypto-kit/keyring.d.ts +52 -0
  87. package/dist/src/crypto-kit/keyring.d.ts.map +1 -0
  88. package/dist/src/crypto-kit/keyring.js +36 -0
  89. package/dist/src/crypto-kit/keyring.js.map +1 -0
  90. package/dist/src/crypto-kit/kms.d.ts +18 -0
  91. package/dist/src/crypto-kit/kms.d.ts.map +1 -0
  92. package/dist/src/crypto-kit/kms.js +29 -0
  93. package/dist/src/crypto-kit/kms.js.map +1 -0
  94. package/dist/src/crypto-kit/seal.d.ts +39 -0
  95. package/dist/src/crypto-kit/seal.d.ts.map +1 -0
  96. package/dist/src/crypto-kit/seal.js +159 -0
  97. package/dist/src/crypto-kit/seal.js.map +1 -0
  98. package/dist/src/dashboard/access_denied_page.d.ts +100 -0
  99. package/dist/src/dashboard/access_denied_page.d.ts.map +1 -0
  100. package/dist/src/dashboard/access_denied_page.js +262 -0
  101. package/dist/src/dashboard/access_denied_page.js.map +1 -0
  102. package/dist/src/dashboard/actor.d.ts +14 -0
  103. package/dist/src/dashboard/actor.d.ts.map +1 -0
  104. package/dist/src/dashboard/actor.js +60 -0
  105. package/dist/src/dashboard/actor.js.map +1 -0
  106. package/dist/src/dashboard/console.d.ts +71 -0
  107. package/dist/src/dashboard/console.d.ts.map +1 -0
  108. package/dist/src/dashboard/console.js +456 -0
  109. package/dist/src/dashboard/console.js.map +1 -0
  110. package/dist/src/dashboard/console_authorize.d.ts +91 -0
  111. package/dist/src/dashboard/console_authorize.d.ts.map +1 -0
  112. package/dist/src/dashboard/console_authorize.js +154 -0
  113. package/dist/src/dashboard/console_authorize.js.map +1 -0
  114. package/dist/src/dashboard/console_shell.d.ts +49 -0
  115. package/dist/src/dashboard/console_shell.d.ts.map +1 -0
  116. package/dist/src/dashboard/console_shell.js +183 -0
  117. package/dist/src/dashboard/console_shell.js.map +1 -0
  118. package/dist/src/dashboard/console_switcher.d.ts +92 -0
  119. package/dist/src/dashboard/console_switcher.d.ts.map +1 -0
  120. package/dist/src/dashboard/console_switcher.js +188 -0
  121. package/dist/src/dashboard/console_switcher.js.map +1 -0
  122. package/dist/src/dashboard/define_config.d.ts +54 -0
  123. package/dist/src/dashboard/define_config.d.ts.map +1 -0
  124. package/dist/src/dashboard/define_config.js +29 -0
  125. package/dist/src/dashboard/define_config.js.map +1 -0
  126. package/dist/src/dashboard/spa.d.ts +42 -0
  127. package/dist/src/dashboard/spa.d.ts.map +1 -0
  128. package/dist/src/dashboard/spa.js +51 -0
  129. package/dist/src/dashboard/spa.js.map +1 -0
  130. package/dist/src/define_config.d.ts +162 -0
  131. package/dist/src/define_config.d.ts.map +1 -0
  132. package/dist/src/define_config.js +53 -0
  133. package/dist/src/define_config.js.map +1 -0
  134. package/dist/src/dev_tools.d.ts +74 -0
  135. package/dist/src/dev_tools.d.ts.map +1 -0
  136. package/dist/src/dev_tools.js +414 -0
  137. package/dist/src/dev_tools.js.map +1 -0
  138. package/dist/src/diagnostics.d.ts +87 -0
  139. package/dist/src/diagnostics.d.ts.map +1 -0
  140. package/dist/src/diagnostics.js +35 -0
  141. package/dist/src/diagnostics.js.map +1 -0
  142. package/dist/src/doctor/agora_doctor.d.ts +116 -0
  143. package/dist/src/doctor/agora_doctor.d.ts.map +1 -0
  144. package/dist/src/doctor/agora_doctor.js +685 -0
  145. package/dist/src/doctor/agora_doctor.js.map +1 -0
  146. package/dist/src/doctor/checks.d.ts +8 -0
  147. package/dist/src/doctor/checks.d.ts.map +1 -0
  148. package/dist/src/doctor/checks.js +352 -0
  149. package/dist/src/doctor/checks.js.map +1 -0
  150. package/dist/src/doctor/index.d.ts +3 -0
  151. package/dist/src/doctor/index.d.ts.map +1 -0
  152. package/dist/src/doctor/index.js +3 -0
  153. package/dist/src/doctor/index.js.map +1 -0
  154. package/dist/src/env_file.d.ts +24 -0
  155. package/dist/src/env_file.d.ts.map +1 -0
  156. package/dist/src/env_file.js +74 -0
  157. package/dist/src/env_file.js.map +1 -0
  158. package/dist/src/http/control_plane.d.ts +93 -0
  159. package/dist/src/http/control_plane.d.ts.map +1 -0
  160. package/dist/src/http/control_plane.js +406 -0
  161. package/dist/src/http/control_plane.js.map +1 -0
  162. package/dist/src/http/list.d.ts +27 -0
  163. package/dist/src/http/list.d.ts.map +1 -0
  164. package/dist/src/http/list.js +75 -0
  165. package/dist/src/http/list.js.map +1 -0
  166. package/dist/src/index.d.ts +22 -0
  167. package/dist/src/index.d.ts.map +1 -0
  168. package/dist/src/index.js +21 -0
  169. package/dist/src/index.js.map +1 -0
  170. package/dist/src/runtime.d.ts +31 -0
  171. package/dist/src/runtime.d.ts.map +1 -0
  172. package/dist/src/runtime.js +2 -0
  173. package/dist/src/runtime.js.map +1 -0
  174. package/dist/src/services/accessor.d.ts +6 -0
  175. package/dist/src/services/accessor.d.ts.map +1 -0
  176. package/dist/src/services/accessor.js +15 -0
  177. package/dist/src/services/accessor.js.map +1 -0
  178. package/dist/src/sql.d.ts +40 -0
  179. package/dist/src/sql.d.ts.map +1 -0
  180. package/dist/src/sql.js +97 -0
  181. package/dist/src/sql.js.map +1 -0
  182. package/dist/src/store/lucid_store.d.ts +62 -0
  183. package/dist/src/store/lucid_store.d.ts.map +1 -0
  184. package/dist/src/store/lucid_store.js +393 -0
  185. package/dist/src/store/lucid_store.js.map +1 -0
  186. package/dist/src/store/memory_store.d.ts +47 -0
  187. package/dist/src/store/memory_store.d.ts.map +1 -0
  188. package/dist/src/store/memory_store.js +184 -0
  189. package/dist/src/store/memory_store.js.map +1 -0
  190. package/dist/src/store/schema.d.ts +18 -0
  191. package/dist/src/store/schema.d.ts.map +1 -0
  192. package/dist/src/store/schema.js +74 -0
  193. package/dist/src/store/schema.js.map +1 -0
  194. package/dist/src/store/store.d.ts +160 -0
  195. package/dist/src/store/store.d.ts.map +1 -0
  196. package/dist/src/store/store.js +254 -0
  197. package/dist/src/store/store.js.map +1 -0
  198. package/dist/src/telescope/dashboard.d.ts +16 -0
  199. package/dist/src/telescope/dashboard.d.ts.map +1 -0
  200. package/dist/src/telescope/dashboard.js +129 -0
  201. package/dist/src/telescope/dashboard.js.map +1 -0
  202. package/dist/src/telescope/data-providers.d.ts +19 -0
  203. package/dist/src/telescope/data-providers.d.ts.map +1 -0
  204. package/dist/src/telescope/data-providers.js +266 -0
  205. package/dist/src/telescope/data-providers.js.map +1 -0
  206. package/dist/src/telescope/extension.d.ts +23 -0
  207. package/dist/src/telescope/extension.d.ts.map +1 -0
  208. package/dist/src/telescope/extension.js +36 -0
  209. package/dist/src/telescope/extension.js.map +1 -0
  210. package/dist/src/telescope/index.d.ts +6 -0
  211. package/dist/src/telescope/index.d.ts.map +1 -0
  212. package/dist/src/telescope/index.js +5 -0
  213. package/dist/src/telescope/index.js.map +1 -0
  214. package/dist/src/telescope/register.d.ts +17 -0
  215. package/dist/src/telescope/register.d.ts.map +1 -0
  216. package/dist/src/telescope/register.js +28 -0
  217. package/dist/src/telescope/register.js.map +1 -0
  218. package/dist/src/telescope/telescope-sdk.d.ts +116 -0
  219. package/dist/src/telescope/telescope-sdk.d.ts.map +1 -0
  220. package/dist/src/telescope/telescope-sdk.js +8 -0
  221. package/dist/src/telescope/telescope-sdk.js.map +1 -0
  222. package/dist/src/testing/index.d.ts +22 -0
  223. package/dist/src/testing/index.d.ts.map +1 -0
  224. package/dist/src/testing/index.js +35 -0
  225. package/dist/src/testing/index.js.map +1 -0
  226. package/dist/src/topology/tenant_client.d.ts +178 -0
  227. package/dist/src/topology/tenant_client.d.ts.map +1 -0
  228. package/dist/src/topology/tenant_client.js +642 -0
  229. package/dist/src/topology/tenant_client.js.map +1 -0
  230. package/dist/src/topology/tenant_keyring.d.ts +65 -0
  231. package/dist/src/topology/tenant_keyring.d.ts.map +1 -0
  232. package/dist/src/topology/tenant_keyring.js +150 -0
  233. package/dist/src/topology/tenant_keyring.js.map +1 -0
  234. package/dist/src/topology/token.d.ts +9 -0
  235. package/dist/src/topology/token.d.ts.map +1 -0
  236. package/dist/src/topology/token.js +10 -0
  237. package/dist/src/topology/token.js.map +1 -0
  238. package/dist/src/topology/verify.d.ts +79 -0
  239. package/dist/src/topology/verify.d.ts.map +1 -0
  240. package/dist/src/topology/verify.js +131 -0
  241. package/dist/src/topology/verify.js.map +1 -0
  242. package/dist/stubs/config/config.stub +23 -0
  243. package/dist/stubs/database/migrations/create_config_tables.stub +31 -0
  244. package/dist/stubs/main.ts +6 -0
  245. package/package.json +126 -3
@@ -0,0 +1,65 @@
1
+ import type { SecretCodec } from '../crypto/secrets.js';
2
+ import { type OkpJwk } from '../crypto-kit/index.js';
3
+ /** Default location of a tenant's key file, relative to the app root. */
4
+ export declare const DEFAULT_TENANT_KEY_PATH = "storage/config-tenant-key.json";
5
+ export interface TenantKeyringOptions {
6
+ /** Absolute path of the key file (created with mode 0600 when missing). */
7
+ path: string;
8
+ /**
9
+ * The symmetric codec that seals the private keys at rest (the config crypto kit over APP_KEY).
10
+ * The control plane never sees this file or this key.
11
+ */
12
+ codec: SecretCodec;
13
+ /**
14
+ * AAD base for the sealed private keys, e.g. `config:tenant-key:<app>`; each key adds `:<kid>`,
15
+ * so a key file (or one key in it) cannot be moved to another app.
16
+ */
17
+ aad: string;
18
+ }
19
+ /** How this app's key stands, for the doctor and the CLI. */
20
+ export interface TenantKeyringStatus {
21
+ activeKid: string;
22
+ kids: string[];
23
+ path: string;
24
+ }
25
+ /**
26
+ * A tenant app's own X25519 key pair, for secrets the control plane must not read. The private
27
+ * keys never leave the app: they are sealed with the app's symmetric keyring at rest (mode 0600)
28
+ * and only the public halves are registered with the control plane.
29
+ *
30
+ * Rotation keeps the retired private keys, so values sealed to them still open while the CLI
31
+ * re-seals them to the new key. Nothing here is config-specific: it is the crypto kit's
32
+ * `generateKeyPair`/`sealTo`/`openWith` plus a small file.
33
+ */
34
+ export declare class TenantKeyring {
35
+ #private;
36
+ readonly path: string;
37
+ private constructor();
38
+ /**
39
+ * Reads the key file, creating a first key pair when it does not exist. A file that exists but
40
+ * cannot be opened is an error: silently generating a new key would strand every sealed value.
41
+ */
42
+ static load(options: TenantKeyringOptions): Promise<TenantKeyring>;
43
+ get activeKid(): string;
44
+ /** The private key new `sealTo` values use. */
45
+ get activePrivateKey(): OkpJwk;
46
+ status(): TenantKeyringStatus;
47
+ /** The public halves to register with the control plane, active first. */
48
+ publicKeys(): OkpJwk[];
49
+ /** Every private key, active first: the ring `openWith` searches by kid. */
50
+ privateKeys(): OkpJwk[];
51
+ /** Opens an `agora:pk1:…` value sealed to one of this app's keys. */
52
+ open(sealed: string, aad: string): string;
53
+ /** Seals a value to this app's active public key (the control plane cannot open it). */
54
+ seal(value: string, aad: string): string;
55
+ /**
56
+ * Adds a fresh active key pair, keeping the retired private keys (so values sealed to them still
57
+ * open until they are re-sealed). Persists the file before returning.
58
+ */
59
+ rotate(): Promise<OkpJwk>;
60
+ /** Writes the file atomically, mode 0600: a crash never leaves a truncated key file. */
61
+ save(): Promise<void>;
62
+ /** The AAD of a private key, exported for tests and for a future migration. */
63
+ aadFor(kid: string): string;
64
+ }
65
+ //# sourceMappingURL=tenant_keyring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant_keyring.d.ts","sourceRoot":"","sources":["../../../src/topology/tenant_keyring.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAmB,KAAK,MAAM,EAA+B,MAAM,wBAAwB,CAAC;AAEnG,yEAAyE;AACzE,eAAO,MAAM,uBAAuB,mCAAmC,CAAC;AAWxE,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,EAAE,WAAW,CAAC;IACnB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED,6DAA6D;AAC7D,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;GAQG;AACH,qBAAa,aAAa;;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAMtB,OAAO,eAUN;IAED;;;OAGG;IACH,OAAa,IAAI,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CAoDvE;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,+CAA+C;IAC/C,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAED,MAAM,IAAI,mBAAmB,CAM5B;IAED,0EAA0E;IAC1E,UAAU,IAAI,MAAM,EAAE,CAErB;IAED,4EAA4E;IAC5E,WAAW,IAAI,MAAM,EAAE,CAKtB;IAED,qEAAqE;IACrE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAExC;IAED,wFAAwF;IACxF,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvC;IAED;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAM9B;IAED,wFAAwF;IAClF,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAgB1B;IAED,+EAA+E;IAC/E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1B;CACF"}
@@ -0,0 +1,150 @@
1
+ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
2
+ import { dirname } from 'node:path';
3
+ import { generateKeyPair, openWith, publicJwk, sealTo } from '../crypto-kit/index.js';
4
+ /** Default location of a tenant's key file, relative to the app root. */
5
+ export const DEFAULT_TENANT_KEY_PATH = 'storage/config-tenant-key.json';
6
+ /**
7
+ * A tenant app's own X25519 key pair, for secrets the control plane must not read. The private
8
+ * keys never leave the app: they are sealed with the app's symmetric keyring at rest (mode 0600)
9
+ * and only the public halves are registered with the control plane.
10
+ *
11
+ * Rotation keeps the retired private keys, so values sealed to them still open while the CLI
12
+ * re-seals them to the new key. Nothing here is config-specific: it is the crypto kit's
13
+ * `generateKeyPair`/`sealTo`/`openWith` plus a small file.
14
+ */
15
+ export class TenantKeyring {
16
+ path;
17
+ #codec;
18
+ #aad;
19
+ #keys;
20
+ #activeKid;
21
+ constructor(options, keys, active) {
22
+ this.path = options.path;
23
+ this.#codec = options.codec;
24
+ this.#aad = options.aad;
25
+ this.#keys = keys;
26
+ this.#activeKid = active;
27
+ }
28
+ /**
29
+ * Reads the key file, creating a first key pair when it does not exist. A file that exists but
30
+ * cannot be opened is an error: silently generating a new key would strand every sealed value.
31
+ */
32
+ static async load(options) {
33
+ let text;
34
+ try {
35
+ text = await readFile(options.path, 'utf8');
36
+ }
37
+ catch (error) {
38
+ if (error.code !== 'ENOENT')
39
+ throw error;
40
+ }
41
+ if (text === undefined) {
42
+ const created = new TenantKeyring(options, [], '');
43
+ await created.rotate();
44
+ return created;
45
+ }
46
+ let file;
47
+ try {
48
+ file = JSON.parse(text);
49
+ }
50
+ catch {
51
+ throw new Error(`config: the tenant key file at ${options.path} is not valid JSON`);
52
+ }
53
+ if (file.v !== 1 || !Array.isArray(file.keys) || typeof file.active !== 'string') {
54
+ throw new Error(`config: the tenant key file at ${options.path} has an unknown shape`);
55
+ }
56
+ const keys = [];
57
+ for (const entry of file.keys) {
58
+ if (typeof entry.kid !== 'string' || typeof entry.sealed !== 'string') {
59
+ throw new Error(`config: the tenant key file at ${options.path} has a malformed key entry`);
60
+ }
61
+ let privateKey;
62
+ try {
63
+ privateKey = (await options.codec.open(entry.sealed, {
64
+ aad: `${options.aad}:${entry.kid}`,
65
+ }));
66
+ }
67
+ catch {
68
+ throw new Error(`config: cannot open the tenant private key "${entry.kid}" at ${options.path}; the app encryption key changed, or the file was copied from another app`);
69
+ }
70
+ if (privateKey?.kty !== 'OKP' ||
71
+ privateKey.crv !== 'X25519' ||
72
+ typeof privateKey.d !== 'string' ||
73
+ privateKey.kid !== entry.kid) {
74
+ throw new Error(`config: the tenant private key "${entry.kid}" at ${options.path} is not an X25519 private JWK`);
75
+ }
76
+ keys.push({ kid: entry.kid, privateKey });
77
+ }
78
+ if (keys.length === 0 || !keys.some((key) => key.kid === file.active)) {
79
+ throw new Error(`config: the tenant key file at ${options.path} has no active key`);
80
+ }
81
+ return new TenantKeyring(options, keys, file.active);
82
+ }
83
+ get activeKid() {
84
+ return this.#activeKid;
85
+ }
86
+ /** The private key new `sealTo` values use. */
87
+ get activePrivateKey() {
88
+ return this.#keys.find((key) => key.kid === this.#activeKid).privateKey;
89
+ }
90
+ status() {
91
+ return {
92
+ activeKid: this.#activeKid,
93
+ kids: this.#keys.map((key) => key.kid),
94
+ path: this.path,
95
+ };
96
+ }
97
+ /** The public halves to register with the control plane, active first. */
98
+ publicKeys() {
99
+ return this.#keys.map((key) => publicJwk(key.privateKey));
100
+ }
101
+ /** Every private key, active first: the ring `openWith` searches by kid. */
102
+ privateKeys() {
103
+ return [
104
+ this.activePrivateKey,
105
+ ...this.#keys.filter((key) => key.kid !== this.#activeKid).map((key) => key.privateKey),
106
+ ];
107
+ }
108
+ /** Opens an `agora:pk1:…` value sealed to one of this app's keys. */
109
+ open(sealed, aad) {
110
+ return openWith(this.privateKeys(), sealed, { aad });
111
+ }
112
+ /** Seals a value to this app's active public key (the control plane cannot open it). */
113
+ seal(value, aad) {
114
+ return sealTo(publicJwk(this.activePrivateKey), value, { aad });
115
+ }
116
+ /**
117
+ * Adds a fresh active key pair, keeping the retired private keys (so values sealed to them still
118
+ * open until they are re-sealed). Persists the file before returning.
119
+ */
120
+ async rotate() {
121
+ const pair = generateKeyPair('x25519');
122
+ this.#keys = [{ kid: pair.publicKey.kid, privateKey: pair.privateKey }, ...this.#keys];
123
+ this.#activeKid = pair.publicKey.kid;
124
+ await this.save();
125
+ return pair.publicKey;
126
+ }
127
+ /** Writes the file atomically, mode 0600: a crash never leaves a truncated key file. */
128
+ async save() {
129
+ await mkdir(dirname(this.path), { recursive: true });
130
+ const file = {
131
+ v: 1,
132
+ active: this.#activeKid,
133
+ keys: [],
134
+ };
135
+ for (const key of this.#keys) {
136
+ const sealed = await this.#codec.seal(key.privateKey, {
137
+ aad: `${this.#aad}:${key.kid}`,
138
+ });
139
+ file.keys.push({ kid: key.kid, sealed });
140
+ }
141
+ // The temp file is created 0600 and renamed over the target, so the mode is never wider.
142
+ await writeFile(`${this.path}.tmp`, `${JSON.stringify(file, null, 2)}\n`, { mode: 0o600 });
143
+ await rename(`${this.path}.tmp`, this.path);
144
+ }
145
+ /** The AAD of a private key, exported for tests and for a future migration. */
146
+ aadFor(kid) {
147
+ return `${this.#aad}:${kid}`;
148
+ }
149
+ }
150
+ //# sourceMappingURL=tenant_keyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant_keyring.js","sourceRoot":"","sources":["../../../src/topology/tenant_keyring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,WAA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AU;YACvB,IAAI,EAAE,EAAE;SACT,CAAC;QACF,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,UAAoC,EAAE;gBAC9E,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE;aAC/B,CAAC,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,yFAAyF;QACzF,MAAM,SAAS,CAAC,GAAG,IAAI,CAAC,IAAI,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3F,MAAM,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,+EAA+E;IAC/E,MAAM,CAAC,GAAW;QAChB,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ export { resolveTenantToken, type TenantToken, type TenantTokenSource, } from '@adonis-agora/config-client';
2
+ /** The resource (RFC 8707) every config control plane answers for: the `aud` of tenant tokens. */
3
+ export { CONFIG_RESOURCE } from '@adonis-agora/config-core';
4
+ /** What each control-plane endpoint requires in the token's `capabilities`. */
5
+ export declare const TENANT_SCOPES: {
6
+ readonly read: "config:read";
7
+ readonly secretsRead: "config:secrets:read";
8
+ };
9
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../../src/topology/token.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,iBAAiB,GACvB,MAAM,6BAA6B,CAAC;AAErC,kGAAkG;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,+EAA+E;AAC/E,eAAO,MAAM,aAAa;aACxB,IAAI;aACJ,WAAW;CACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { CONFIG_SCOPES } from '@adonis-agora/config-core';
2
+ export { resolveTenantToken, } from '@adonis-agora/config-client';
3
+ /** The resource (RFC 8707) every config control plane answers for: the `aud` of tenant tokens. */
4
+ export { CONFIG_RESOURCE } from '@adonis-agora/config-core';
5
+ /** What each control-plane endpoint requires in the token's `capabilities`. */
6
+ export const TENANT_SCOPES = {
7
+ read: CONFIG_SCOPES.read,
8
+ secretsRead: CONFIG_SCOPES.secretsRead,
9
+ };
10
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../../src/topology/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EACL,kBAAkB,GAGnB,MAAM,6BAA6B,CAAC;AAErC,kGAAkG;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,aAAa,CAAC,IAAI;IACxB,WAAW,EAAE,aAAa,CAAC,WAAW;CAC9B,CAAC"}
@@ -0,0 +1,79 @@
1
+ import type { HttpContext } from '@adonisjs/core/http';
2
+ /**
3
+ * What a control plane trusts about a request: derived from the verified token, never from the
4
+ * request. The shape every Agora control plane uses — `authkitTenantVerifier` from
5
+ * `@adonis-agora/authkit-client` returns it.
6
+ */
7
+ export interface VerifiedTenant {
8
+ /** The application (the partition). This is the ONLY source of the app a token may read. */
9
+ partition: string;
10
+ /** The environment the token may read. Default: the control plane's own environment. */
11
+ environment?: string;
12
+ /** The label (profile) the token may read. Default `main`. */
13
+ label?: string;
14
+ /** `config:read`, optionally `config:secrets:read`. Never empty. */
15
+ capabilities: string[];
16
+ /** The service-tenant client behind the token, when it says. */
17
+ clientId?: string;
18
+ /** Epoch ms after which streams opened with this token must close. */
19
+ expiresAt?: number;
20
+ }
21
+ /** What a verifier receives. Only `token` is trusted, once verified. */
22
+ export interface TenantAuthRequest {
23
+ /** The bearer token (or the shared secret). */
24
+ token?: string | undefined;
25
+ /** The partition the caller claims (`x-config-app`). Advisory only. */
26
+ partition?: string | undefined;
27
+ /** Same as `partition` (the wire name other libs use). Advisory only. */
28
+ tenant?: string | undefined;
29
+ /** The app the caller claims; the name this package uses for `partition`. */
30
+ app?: string | undefined;
31
+ environment?: string | undefined;
32
+ label?: string | undefined;
33
+ headers?: Readonly<Record<string, string | undefined>> | undefined;
34
+ }
35
+ /** The top-level `verifyTenant` contract. */
36
+ export type TenantVerifier = (request: TenantAuthRequest) => VerifiedTenant | null | Promise<VerifiedTenant | null>;
37
+ /** A class instance implementing `verify`. */
38
+ export interface TenantVerifierObject {
39
+ verify(request: TenantAuthRequest): VerifiedTenant | null | Promise<VerifiedTenant | null>;
40
+ }
41
+ /** A lazily imported verifier module: a verifier, a class, or an object with `verify`. */
42
+ export interface TenantVerifierModule {
43
+ default?: TenantVerifier | TenantVerifierObject | (new () => TenantVerifierObject);
44
+ verify?: TenantVerifier | TenantVerifierObject;
45
+ tenantVerifier?: TenantVerifier | TenantVerifierObject;
46
+ }
47
+ /** The accepted forms: a function, a class instance, a class, or a lazy `() => import(...)`. */
48
+ export type TenantVerifierInput = TenantVerifier | TenantVerifierObject | (new () => TenantVerifierObject) | (() => Promise<TenantVerifierModule> | TenantVerifierModule);
49
+ /**
50
+ * Validates a verifier's answer. `null` refuses; `{ partition, capabilities }` accepts; anything
51
+ * else throws, so a malformed answer is never taken for an accepted tenant. Capabilities are NOT
52
+ * defaulted: a verifier must say what the token may do.
53
+ */
54
+ export declare function checkVerifiedTenant(result: unknown): VerifiedTenant | null;
55
+ /**
56
+ * Turns any `verifyTenant` form into the function the control plane calls: a function, an object
57
+ * with `verify` (a class instance), a class, or a lazy import of one. Authkit's
58
+ * `authkitTenantVerifier()` is the function form and needs no wrapper.
59
+ */
60
+ export declare function resolveTenantVerifier(input: TenantVerifierInput): (request: TenantAuthRequest) => Promise<VerifiedTenant | null>;
61
+ export interface SharedSecretTenant {
62
+ secret: string;
63
+ environment?: string;
64
+ label?: string;
65
+ /** Default `['config:read']`. Add `config:secrets:read` only where secrets are needed. */
66
+ capabilities?: string[];
67
+ }
68
+ /**
69
+ * One shared secret per app, compared in constant time. The caller names its app with
70
+ * `x-config-app`; the secret proves it. Without authkit this is the whole auth story.
71
+ */
72
+ export declare function sharedSecretVerifier(options: {
73
+ partitions: Record<string, string | SharedSecretTenant>;
74
+ }): TenantVerifier;
75
+ /** The bearer token of a request (`authorization: Bearer`), or `x-api-key` for shared secrets. */
76
+ export declare function bearerToken(ctx: HttpContext): string | undefined;
77
+ /** The headers a verifier may need, lowercased. */
78
+ export declare function requestHeaders(ctx: HttpContext): Record<string, string | undefined>;
79
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/topology/verify.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;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;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAuB1E;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,mBAAmB,GACzB,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAuChE;AAcD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAC5C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAAC,CAAC;CACzD,GAAG,cAAc,CAejB;AAED,kGAAkG;AAClG,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAIhE;AAED,mDAAmD;AACnD,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CASnF"}
@@ -0,0 +1,131 @@
1
+ import { timingSafeEqual } from 'node:crypto';
2
+ import { CONFIG_SCOPES } from '@adonis-agora/config-core';
3
+ function hasVerify(value) {
4
+ return (!!value &&
5
+ (typeof value === 'object' || typeof value === 'function') &&
6
+ typeof value.verify === 'function');
7
+ }
8
+ function isVerifierClass(value) {
9
+ return (typeof value === 'function' &&
10
+ typeof value.prototype?.verify === 'function');
11
+ }
12
+ /**
13
+ * Validates a verifier's answer. `null` refuses; `{ partition, capabilities }` accepts; anything
14
+ * else throws, so a malformed answer is never taken for an accepted tenant. Capabilities are NOT
15
+ * defaulted: a verifier must say what the token may do.
16
+ */
17
+ export function checkVerifiedTenant(result) {
18
+ if (result === null || result === undefined)
19
+ return null;
20
+ const value = result;
21
+ if (typeof value === 'object' &&
22
+ typeof value.partition === 'string' &&
23
+ value.partition.length > 0 &&
24
+ Array.isArray(value.capabilities) &&
25
+ value.capabilities.every((capability) => typeof capability === 'string') &&
26
+ (value.environment === undefined || typeof value.environment === 'string') &&
27
+ (value.label === undefined || typeof value.label === 'string') &&
28
+ (value.clientId === undefined || typeof value.clientId === 'string') &&
29
+ (value.expiresAt === undefined || typeof value.expiresAt === 'number')) {
30
+ return value;
31
+ }
32
+ throw new TypeError(`[@adonis-agora/config] verifyTenant must return { partition: string, environment?: string, capabilities: string[] } or null${value && typeof result === 'object' && 'tenant' in value
33
+ ? ' (it returned `tenant`; rename it to `partition`)'
34
+ : ''}`);
35
+ }
36
+ /**
37
+ * Turns any `verifyTenant` form into the function the control plane calls: a function, an object
38
+ * with `verify` (a class instance), a class, or a lazy import of one. Authkit's
39
+ * `authkitTenantVerifier()` is the function form and needs no wrapper.
40
+ */
41
+ export function resolveTenantVerifier(input) {
42
+ if (isVerifierClass(input)) {
43
+ let instance;
44
+ return async (request) => {
45
+ instance ??= new input();
46
+ return checkVerifiedTenant(await instance.verify(request));
47
+ };
48
+ }
49
+ if (hasVerify(input)) {
50
+ return async (request) => checkVerifiedTenant(await input.verify(request));
51
+ }
52
+ if (typeof input !== 'function') {
53
+ throw new TypeError('[@adonis-agora/config] `verifyTenant` must be a function, an object with verify() (a class instance), or a lazy import of one');
54
+ }
55
+ // A verifier function — or a lazy import factory. Call it with the request; if what comes back is
56
+ // a module, remember the verifier inside it. Authkit's verifier is the plain-function case.
57
+ const fn = input;
58
+ let lazy;
59
+ return async (request) => {
60
+ if (lazy)
61
+ return (await lazy)(request);
62
+ const result = await fn(request);
63
+ const exported = result && typeof result === 'object' && 'default' in result
64
+ ? result.default
65
+ : undefined;
66
+ const named = exported ??
67
+ (result && typeof result === 'object'
68
+ ? (result.tenantVerifier ??
69
+ result.verify)
70
+ : undefined);
71
+ if (named !== undefined) {
72
+ lazy = Promise.resolve(resolveTenantVerifier(named));
73
+ return (await lazy)(request);
74
+ }
75
+ return checkVerifiedTenant(result);
76
+ };
77
+ }
78
+ /** Constant-time comparison that does not leak the length through an early return. */
79
+ function sameSecret(a, b) {
80
+ const left = Buffer.from(a);
81
+ const right = Buffer.from(b);
82
+ if (left.length !== right.length) {
83
+ // Still compare, so timing does not reveal where the difference is.
84
+ timingSafeEqual(left, left);
85
+ return false;
86
+ }
87
+ return timingSafeEqual(left, right);
88
+ }
89
+ /**
90
+ * One shared secret per app, compared in constant time. The caller names its app with
91
+ * `x-config-app`; the secret proves it. Without authkit this is the whole auth story.
92
+ */
93
+ export function sharedSecretVerifier(options) {
94
+ return (request) => {
95
+ const app = request.app ?? request.partition ?? request.tenant;
96
+ if (!request.token || !app)
97
+ return null;
98
+ const entry = options.partitions[app];
99
+ if (entry === undefined)
100
+ return null;
101
+ const config = typeof entry === 'string' ? { secret: entry } : entry;
102
+ if (!sameSecret(request.token, config.secret))
103
+ return null;
104
+ return {
105
+ partition: app,
106
+ capabilities: config.capabilities ?? [CONFIG_SCOPES.read],
107
+ ...(config.environment ? { environment: config.environment } : {}),
108
+ ...(config.label ? { label: config.label } : {}),
109
+ };
110
+ };
111
+ }
112
+ /** The bearer token of a request (`authorization: Bearer`), or `x-api-key` for shared secrets. */
113
+ export function bearerToken(ctx) {
114
+ const header = ctx.request.header('authorization');
115
+ if (header && /^bearer\s+/i.test(header))
116
+ return header.replace(/^bearer\s+/i, '').trim();
117
+ return ctx.request.header('x-api-key') ?? undefined;
118
+ }
119
+ /** The headers a verifier may need, lowercased. */
120
+ export function requestHeaders(ctx) {
121
+ const headers = ctx.request
122
+ .headers;
123
+ if (typeof headers !== 'function')
124
+ return {};
125
+ const out = {};
126
+ for (const [name, value] of Object.entries(headers())) {
127
+ out[name.toLowerCase()] = Array.isArray(value) ? value[0] : value;
128
+ }
129
+ return out;
130
+ }
131
+ //# sourceMappingURL=verify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify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C7C,MAAM,OAAO,GAAI,GAAG,CAAC,OAA4E;SAC9F,OAAO,CAAC;IACX,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,OAAO,EAAE,CAAC;IAC7C,MAAM,GAAG,GAAuC,EAAE,CAAC;IACnD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACpE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,23 @@
1
+ import env from '#start/env'
2
+ import { defineConfig } from '@adonis-agora/config'
3
+
4
+ /**
5
+ * This app reads its configuration from the Agora config server.
6
+ *
7
+ * The values reach `config/*.ts` only through the bootstrap entry in `bin/server.ts`
8
+ * (`import { bootstrapConfig } from '@adonis-agora/config/bootstrap'`), because config files load
9
+ * before any provider boots. Without it, values arrive at boot for controllers and services.
10
+ */
11
+ export default defineConfig({
12
+ topology: 'tenant',
13
+ tenant: {
14
+ url: env.get('CONFIG_URL'),
15
+ partition: env.get('CONFIG_APP'),
16
+ // With authkit: authkitTenantToken({ issuer, clientId, clientSecret, resource: 'urn:agora:config' })
17
+ token: env.get('CONFIG_TOKEN'),
18
+ environment: env.get('NODE_ENV'),
19
+ snapshotPath: 'storage/config/snapshot.json',
20
+ // On outside production: a Sail worktree's ports in .env.local win over the server's.
21
+ localEnv: env.get('NODE_ENV') !== 'production',
22
+ },
23
+ })
@@ -0,0 +1,31 @@
1
+ {{{
2
+ exports({ to: app.migrationsPath(`${new Date().getTime()}_create_config_tables.ts`) })
3
+ }}}
4
+ import { BaseSchema } from '@adonisjs/lucid/schema'
5
+ import { createConfigTables, dropConfigTables } from '@adonis-agora/config'
6
+
7
+ /**
8
+ * The config tables, for apps that run DDL explicitly.
9
+ *
10
+ * **You may not need this file.** `@adonis-agora/config` creates its tables at boot
11
+ * (`autoCreateSchema`, on by default), like the other Agora libraries. Keep this migration if you
12
+ * want migrations to own the schema, and set `autoCreateSchema: false` in config/config.ts. Both
13
+ * paths call the same `createConfigTables`.
14
+ *
15
+ * With `schema: 'agora'` in config/config.ts, pass the same one here:
16
+ * createConfigTables(db as never, { schema: 'agora' })
17
+ * (the schema is created first; the tables are named `agora.config_versions`, …).
18
+ */
19
+ export default class extends BaseSchema {
20
+ async up() {
21
+ this.defer(async (db) => {
22
+ await createConfigTables(db as never /* , { schema: 'agora' } */)
23
+ })
24
+ }
25
+
26
+ async down() {
27
+ this.defer(async (db) => {
28
+ await dropConfigTables(db as never /* , { schema: 'agora' } */)
29
+ })
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import { fileURLToPath } from 'node:url';
2
+
3
+ /** The directory holding this package's stubs (copied into `dist/stubs` at build time). */
4
+ export function stubsRoot(): string {
5
+ return fileURLToPath(new URL('../stubs', import.meta.url));
6
+ }