@pawabase/client 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 (243) hide show
  1. package/README.md +313 -2
  2. package/dist/cjs/admin.d.ts +187 -0
  3. package/dist/cjs/admin.d.ts.map +1 -0
  4. package/dist/cjs/admin.js +235 -0
  5. package/dist/cjs/admin.js.map +1 -0
  6. package/dist/cjs/auth.d.ts +448 -0
  7. package/dist/cjs/auth.d.ts.map +1 -0
  8. package/dist/cjs/auth.js +1016 -0
  9. package/dist/cjs/auth.js.map +1 -0
  10. package/dist/cjs/client.d.ts +103 -0
  11. package/dist/cjs/client.d.ts.map +1 -0
  12. package/dist/cjs/client.js +144 -0
  13. package/dist/cjs/client.js.map +1 -0
  14. package/dist/cjs/data.d.ts +220 -0
  15. package/dist/cjs/data.d.ts.map +1 -0
  16. package/dist/cjs/data.js +490 -0
  17. package/dist/cjs/data.js.map +1 -0
  18. package/dist/cjs/errors.d.ts +167 -0
  19. package/dist/cjs/errors.d.ts.map +1 -0
  20. package/dist/cjs/errors.js +316 -0
  21. package/dist/cjs/errors.js.map +1 -0
  22. package/dist/cjs/files.d.ts +80 -0
  23. package/dist/cjs/files.d.ts.map +1 -0
  24. package/dist/cjs/files.js +167 -0
  25. package/dist/cjs/files.js.map +1 -0
  26. package/dist/cjs/functions.d.ts +66 -0
  27. package/dist/cjs/functions.d.ts.map +1 -0
  28. package/dist/cjs/functions.js +109 -0
  29. package/dist/cjs/functions.js.map +1 -0
  30. package/dist/cjs/http.d.ts +101 -0
  31. package/dist/cjs/http.d.ts.map +1 -0
  32. package/dist/cjs/http.js +249 -0
  33. package/dist/cjs/http.js.map +1 -0
  34. package/dist/cjs/index.d.ts +22 -0
  35. package/dist/cjs/index.d.ts.map +1 -0
  36. package/dist/cjs/index.js +45 -0
  37. package/dist/cjs/index.js.map +1 -0
  38. package/dist/cjs/manage/access.d.ts +136 -0
  39. package/dist/cjs/manage/access.d.ts.map +1 -0
  40. package/dist/cjs/manage/access.js +162 -0
  41. package/dist/cjs/manage/access.js.map +1 -0
  42. package/dist/cjs/manage/automation.d.ts +106 -0
  43. package/dist/cjs/manage/automation.d.ts.map +1 -0
  44. package/dist/cjs/manage/automation.js +144 -0
  45. package/dist/cjs/manage/automation.js.map +1 -0
  46. package/dist/cjs/manage/base.d.ts +52 -0
  47. package/dist/cjs/manage/base.d.ts.map +1 -0
  48. package/dist/cjs/manage/base.js +69 -0
  49. package/dist/cjs/manage/base.js.map +1 -0
  50. package/dist/cjs/manage/data.d.ts +100 -0
  51. package/dist/cjs/manage/data.d.ts.map +1 -0
  52. package/dist/cjs/manage/data.js +141 -0
  53. package/dist/cjs/manage/data.js.map +1 -0
  54. package/dist/cjs/manage/files.d.ts +45 -0
  55. package/dist/cjs/manage/files.d.ts.map +1 -0
  56. package/dist/cjs/manage/files.js +73 -0
  57. package/dist/cjs/manage/files.js.map +1 -0
  58. package/dist/cjs/manage/functions.d.ts +48 -0
  59. package/dist/cjs/manage/functions.d.ts.map +1 -0
  60. package/dist/cjs/manage/functions.js +61 -0
  61. package/dist/cjs/manage/functions.js.map +1 -0
  62. package/dist/cjs/manage/index.d.ts +76 -0
  63. package/dist/cjs/manage/index.d.ts.map +1 -0
  64. package/dist/cjs/manage/index.js +134 -0
  65. package/dist/cjs/manage/index.js.map +1 -0
  66. package/dist/cjs/manage/lifecycle.d.ts +128 -0
  67. package/dist/cjs/manage/lifecycle.d.ts.map +1 -0
  68. package/dist/cjs/manage/lifecycle.js +167 -0
  69. package/dist/cjs/manage/lifecycle.js.map +1 -0
  70. package/dist/cjs/manage/mail.d.ts +16 -0
  71. package/dist/cjs/manage/mail.d.ts.map +1 -0
  72. package/dist/cjs/manage/mail.js +24 -0
  73. package/dist/cjs/manage/mail.js.map +1 -0
  74. package/dist/cjs/manage/observe.d.ts +149 -0
  75. package/dist/cjs/manage/observe.d.ts.map +1 -0
  76. package/dist/cjs/manage/observe.js +168 -0
  77. package/dist/cjs/manage/observe.js.map +1 -0
  78. package/dist/cjs/manage/realtime.d.ts +52 -0
  79. package/dist/cjs/manage/realtime.d.ts.map +1 -0
  80. package/dist/cjs/manage/realtime.js +71 -0
  81. package/dist/cjs/manage/realtime.js.map +1 -0
  82. package/dist/cjs/package.json +1 -0
  83. package/dist/cjs/realtime.d.ts +207 -0
  84. package/dist/cjs/realtime.d.ts.map +1 -0
  85. package/dist/cjs/realtime.js +704 -0
  86. package/dist/cjs/realtime.js.map +1 -0
  87. package/dist/cjs/session-store.d.ts +16 -0
  88. package/dist/cjs/session-store.d.ts.map +1 -0
  89. package/dist/cjs/session-store.js +37 -0
  90. package/dist/cjs/session-store.js.map +1 -0
  91. package/dist/cjs/typegen.d.ts +26 -0
  92. package/dist/cjs/typegen.d.ts.map +1 -0
  93. package/dist/cjs/typegen.js +167 -0
  94. package/dist/cjs/typegen.js.map +1 -0
  95. package/dist/cjs/types.d.ts +178 -0
  96. package/dist/cjs/types.d.ts.map +1 -0
  97. package/dist/cjs/types.js +4 -0
  98. package/dist/cjs/types.js.map +1 -0
  99. package/dist/cjs/util.d.ts +27 -0
  100. package/dist/cjs/util.d.ts.map +1 -0
  101. package/dist/cjs/util.js +115 -0
  102. package/dist/cjs/util.js.map +1 -0
  103. package/dist/cjs/version.d.ts +2 -0
  104. package/dist/cjs/version.d.ts.map +1 -0
  105. package/dist/cjs/version.js +5 -0
  106. package/dist/cjs/version.js.map +1 -0
  107. package/dist/esm/admin.d.ts +187 -0
  108. package/dist/esm/admin.d.ts.map +1 -0
  109. package/dist/esm/admin.js +222 -0
  110. package/dist/esm/admin.js.map +1 -0
  111. package/dist/esm/auth.d.ts +448 -0
  112. package/dist/esm/auth.d.ts.map +1 -0
  113. package/dist/esm/auth.js +1012 -0
  114. package/dist/esm/auth.js.map +1 -0
  115. package/dist/esm/cli/gen-types.d.ts +2 -0
  116. package/dist/esm/cli/gen-types.d.ts.map +1 -0
  117. package/dist/esm/cli/gen-types.js +100 -0
  118. package/dist/esm/cli/gen-types.js.map +1 -0
  119. package/dist/esm/client.d.ts +103 -0
  120. package/dist/esm/client.d.ts.map +1 -0
  121. package/dist/esm/client.js +139 -0
  122. package/dist/esm/client.js.map +1 -0
  123. package/dist/esm/data.d.ts +220 -0
  124. package/dist/esm/data.d.ts.map +1 -0
  125. package/dist/esm/data.js +485 -0
  126. package/dist/esm/data.js.map +1 -0
  127. package/dist/esm/errors.d.ts +167 -0
  128. package/dist/esm/errors.d.ts.map +1 -0
  129. package/dist/esm/errors.js +293 -0
  130. package/dist/esm/errors.js.map +1 -0
  131. package/dist/esm/files.d.ts +80 -0
  132. package/dist/esm/files.d.ts.map +1 -0
  133. package/dist/esm/files.js +162 -0
  134. package/dist/esm/files.js.map +1 -0
  135. package/dist/esm/functions.d.ts +66 -0
  136. package/dist/esm/functions.d.ts.map +1 -0
  137. package/dist/esm/functions.js +103 -0
  138. package/dist/esm/functions.js.map +1 -0
  139. package/dist/esm/http.d.ts +101 -0
  140. package/dist/esm/http.d.ts.map +1 -0
  141. package/dist/esm/http.js +245 -0
  142. package/dist/esm/http.js.map +1 -0
  143. package/dist/esm/index.d.ts +22 -0
  144. package/dist/esm/index.d.ts.map +1 -0
  145. package/dist/esm/index.js +12 -0
  146. package/dist/esm/index.js.map +1 -0
  147. package/dist/esm/manage/access.d.ts +136 -0
  148. package/dist/esm/manage/access.d.ts.map +1 -0
  149. package/dist/esm/manage/access.js +155 -0
  150. package/dist/esm/manage/access.js.map +1 -0
  151. package/dist/esm/manage/automation.d.ts +106 -0
  152. package/dist/esm/manage/automation.d.ts.map +1 -0
  153. package/dist/esm/manage/automation.js +134 -0
  154. package/dist/esm/manage/automation.js.map +1 -0
  155. package/dist/esm/manage/base.d.ts +52 -0
  156. package/dist/esm/manage/base.d.ts.map +1 -0
  157. package/dist/esm/manage/base.js +63 -0
  158. package/dist/esm/manage/base.js.map +1 -0
  159. package/dist/esm/manage/data.d.ts +100 -0
  160. package/dist/esm/manage/data.d.ts.map +1 -0
  161. package/dist/esm/manage/data.js +130 -0
  162. package/dist/esm/manage/data.js.map +1 -0
  163. package/dist/esm/manage/files.d.ts +45 -0
  164. package/dist/esm/manage/files.d.ts.map +1 -0
  165. package/dist/esm/manage/files.js +68 -0
  166. package/dist/esm/manage/files.js.map +1 -0
  167. package/dist/esm/manage/functions.d.ts +48 -0
  168. package/dist/esm/manage/functions.d.ts.map +1 -0
  169. package/dist/esm/manage/functions.js +57 -0
  170. package/dist/esm/manage/functions.js.map +1 -0
  171. package/dist/esm/manage/index.d.ts +76 -0
  172. package/dist/esm/manage/index.d.ts.map +1 -0
  173. package/dist/esm/manage/index.js +115 -0
  174. package/dist/esm/manage/index.js.map +1 -0
  175. package/dist/esm/manage/lifecycle.d.ts +128 -0
  176. package/dist/esm/manage/lifecycle.d.ts.map +1 -0
  177. package/dist/esm/manage/lifecycle.js +161 -0
  178. package/dist/esm/manage/lifecycle.js.map +1 -0
  179. package/dist/esm/manage/mail.d.ts +16 -0
  180. package/dist/esm/manage/mail.d.ts.map +1 -0
  181. package/dist/esm/manage/mail.js +19 -0
  182. package/dist/esm/manage/mail.js.map +1 -0
  183. package/dist/esm/manage/observe.d.ts +149 -0
  184. package/dist/esm/manage/observe.d.ts.map +1 -0
  185. package/dist/esm/manage/observe.js +161 -0
  186. package/dist/esm/manage/observe.js.map +1 -0
  187. package/dist/esm/manage/realtime.d.ts +52 -0
  188. package/dist/esm/manage/realtime.d.ts.map +1 -0
  189. package/dist/esm/manage/realtime.js +66 -0
  190. package/dist/esm/manage/realtime.js.map +1 -0
  191. package/dist/esm/package.json +1 -0
  192. package/dist/esm/realtime.d.ts +207 -0
  193. package/dist/esm/realtime.d.ts.map +1 -0
  194. package/dist/esm/realtime.js +699 -0
  195. package/dist/esm/realtime.js.map +1 -0
  196. package/dist/esm/session-store.d.ts +16 -0
  197. package/dist/esm/session-store.d.ts.map +1 -0
  198. package/dist/esm/session-store.js +32 -0
  199. package/dist/esm/session-store.js.map +1 -0
  200. package/dist/esm/typegen.d.ts +26 -0
  201. package/dist/esm/typegen.d.ts.map +1 -0
  202. package/dist/esm/typegen.js +163 -0
  203. package/dist/esm/typegen.js.map +1 -0
  204. package/dist/esm/types.d.ts +178 -0
  205. package/dist/esm/types.d.ts.map +1 -0
  206. package/dist/esm/types.js +3 -0
  207. package/dist/esm/types.js.map +1 -0
  208. package/dist/esm/util.d.ts +27 -0
  209. package/dist/esm/util.d.ts.map +1 -0
  210. package/dist/esm/util.js +102 -0
  211. package/dist/esm/util.js.map +1 -0
  212. package/dist/esm/version.d.ts +2 -0
  213. package/dist/esm/version.d.ts.map +1 -0
  214. package/dist/esm/version.js +2 -0
  215. package/dist/esm/version.js.map +1 -0
  216. package/package.json +84 -4
  217. package/src/admin.ts +311 -0
  218. package/src/auth.ts +1180 -0
  219. package/src/cli/gen-types.ts +105 -0
  220. package/src/client.ts +189 -0
  221. package/src/data.ts +576 -0
  222. package/src/errors.ts +330 -0
  223. package/src/files.ts +208 -0
  224. package/src/functions.ts +131 -0
  225. package/src/http.ts +354 -0
  226. package/src/index.ts +56 -0
  227. package/src/manage/access.ts +206 -0
  228. package/src/manage/automation.ts +162 -0
  229. package/src/manage/base.ts +83 -0
  230. package/src/manage/data.ts +159 -0
  231. package/src/manage/files.ts +79 -0
  232. package/src/manage/functions.ts +69 -0
  233. package/src/manage/index.ts +132 -0
  234. package/src/manage/lifecycle.ts +208 -0
  235. package/src/manage/mail.ts +22 -0
  236. package/src/manage/observe.ts +226 -0
  237. package/src/manage/realtime.ts +95 -0
  238. package/src/realtime.ts +765 -0
  239. package/src/session-store.ts +36 -0
  240. package/src/typegen.ts +192 -0
  241. package/src/types.ts +195 -0
  242. package/src/util.ts +114 -0
  243. package/src/version.ts +1 -0
@@ -0,0 +1,208 @@
1
+ import { Service, seg, type Api, type Body } from "./base.js";
2
+
3
+ type When = Date | string;
4
+ const iso = (value?: When): string | undefined => (value instanceof Date ? value.toISOString() : value);
5
+
6
+ /** The project's environments (`development`, `production`, previews…). Most calls here are not scoped to the client's environment. */
7
+ export class Environments extends Service {
8
+ list(): Promise<Api> {
9
+ return this.project("GET", "/envs");
10
+ }
11
+
12
+ /** A new environment, optionally with another's definitions copied in. */
13
+ create(name: string, options: { copyFrom?: string } = {}): Promise<Api> {
14
+ return this.project("POST", "/envs", { body: { name, copy_from: options.copyFrom } });
15
+ }
16
+
17
+ getOne(name?: string): Promise<Api> {
18
+ return this.project("GET", `/envs/${encodeURIComponent(name ?? this.environment)}`);
19
+ }
20
+
21
+ /** Change an environment's infrastructure, sign-in settings or settings; each is merged in. */
22
+ update(name: string, changes: { infra?: Body; auth?: Body; settings?: Body; isDefault?: boolean }): Promise<Api> {
23
+ return this.project("PATCH", `/envs/${encodeURIComponent(name)}`, {
24
+ body: { infra: changes.infra, auth: changes.auth, settings: changes.settings, is_default: changes.isDefault },
25
+ });
26
+ }
27
+
28
+ deleteEnvironment(name: string): Promise<Api> {
29
+ return this.project("DELETE", `/envs/${encodeURIComponent(name)}`);
30
+ }
31
+
32
+ /** A short-lived copy for a branch or pull request (`ref`: lowercase letters, digits and hyphens); it expires by itself. */
33
+ createPreview(ref: string, options: { name?: string; expiresInHours?: number; infra?: Body; auth?: Body; settings?: Body } = {}): Promise<Api> {
34
+ return this.post("/previews", {
35
+ ref,
36
+ name: options.name,
37
+ expires_in_hours: options.expiresInHours ?? 72,
38
+ infra: options.infra ?? {},
39
+ auth: options.auth ?? {},
40
+ settings: options.settings,
41
+ });
42
+ }
43
+
44
+ deletePreview(preview: string): Promise<Api> {
45
+ return this.del(seg("previews", preview));
46
+ }
47
+
48
+ /** Copy this environment's definitions (never secrets or keys) to `to`. `include` limits the kinds (`flows`, `policies`, `resources`…). */
49
+ promote(to: string, options: { include?: string[] } = {}): Promise<Api> {
50
+ return this.post("/promote", { to, include: options.include });
51
+ }
52
+
53
+ /** Export definitions, roles and settings as a document another project can apply. */
54
+ blueprint(): Promise<Api> {
55
+ return this.get("/blueprint");
56
+ }
57
+
58
+ /** Build new environments from a blueprint; each must not exist yet. */
59
+ applyBlueprint(blueprint: Body, environments: string[] = ["development", "production"]): Promise<Api> {
60
+ return this.project("POST", "/blueprints/apply", { body: { blueprint, environments } });
61
+ }
62
+
63
+ /** Re-read the deployed function code now. */
64
+ reloadCode(): Promise<Api> {
65
+ return this.project("POST", "/code/reload");
66
+ }
67
+ }
68
+
69
+ /** Feature branches of the definitions, immutable revisions, API versions and releases. */
70
+ export class Releases extends Service {
71
+ branches(): Promise<Api> {
72
+ return this.get("/branches");
73
+ }
74
+
75
+ createBranch(name: string, options: { fromBranch?: string; fromRevision?: string; protected?: boolean } = {}): Promise<Api> {
76
+ return this.post("/branches", { name, from_branch: options.fromBranch, from_revision: options.fromRevision, protected: options.protected ?? false });
77
+ }
78
+
79
+ /** The branch's definitions as they stand now. */
80
+ draft(branch: string): Promise<Api> {
81
+ return this.get(seg("branches", branch, "draft"));
82
+ }
83
+
84
+ merge(branch: string, options: { target?: string; force?: boolean } = {}): Promise<Api> {
85
+ return this.post(seg("branches", branch, "merge"), { target: options.target ?? "main", force: options.force ?? false });
86
+ }
87
+
88
+ revisions(): Promise<Api> {
89
+ return this.get("/revisions");
90
+ }
91
+
92
+ revision(revisionId: string): Promise<Api> {
93
+ return this.get(seg("revisions", revisionId));
94
+ }
95
+
96
+ /** Freeze the branch's draft as a revision. */
97
+ commit(branch: string, message = ""): Promise<Api> {
98
+ return this.post(seg("branches", branch, "revisions"), { message });
99
+ }
100
+
101
+ apiVersions(): Promise<Api> {
102
+ return this.get("/api-versions");
103
+ }
104
+
105
+ createApiVersion(name: string, options: { isDefault?: boolean } = {}): Promise<Api> {
106
+ return this.post("/api-versions", { name, is_default: options.isDefault ?? false });
107
+ }
108
+
109
+ /** `status`: draft, active, deprecated, sunset, disabled. */
110
+ updateApiVersion(name: string, changes: { status?: string; isDefault?: boolean; sunsetAt?: When }): Promise<Api> {
111
+ return this.patch(seg("api-versions", name), { status: changes.status, is_default: changes.isDefault, sunset_at: iso(changes.sunsetAt) });
112
+ }
113
+
114
+ rollbackApiVersion(name: string): Promise<Api> {
115
+ return this.post(seg("api-versions", name, "rollback"));
116
+ }
117
+
118
+ releases(): Promise<Api> {
119
+ return this.get("/releases");
120
+ }
121
+
122
+ /** Make a revision the live definitions of an API version. */
123
+ release(revisionId: string, apiVersion: string, name: string, options: { notes?: string; allowBreaking?: boolean } = {}): Promise<Api> {
124
+ return this.post("/releases", { revision_id: revisionId, api_version: apiVersion, name, notes: options.notes ?? "", allow_breaking: options.allowBreaking ?? false });
125
+ }
126
+
127
+ activate(releaseId: string): Promise<Api> {
128
+ return this.post(seg("releases", releaseId, "activate"));
129
+ }
130
+
131
+ deployments(): Promise<Api> {
132
+ return this.get("/deployments");
133
+ }
134
+ }
135
+
136
+ export interface RestoreOptions {
137
+ /** Parts to restore: `definitions`, `settings`, `users`, `data`. Default: every part the file holds. */
138
+ include?: string[];
139
+ /** `merge` adds and updates; `replace` first removes what the chosen parts hold and needs `confirm`. */
140
+ strategy?: "merge" | "replace";
141
+ dryRun?: boolean;
142
+ /** For `replace`: the environment's name, typed out. */
143
+ confirm?: string;
144
+ }
145
+
146
+ /** Whole-environment backups you download, stored snapshots, and restores. */
147
+ export class Backups extends Service {
148
+ /** A backup document: `definitions`, `settings`, `users` and, with `data`, rows (up to `maxRows` per table). */
149
+ download(options: { include?: string[]; data?: boolean; maxRows?: number } = {}): Promise<Api> {
150
+ return this.get("/backup", { include: options.include?.join(","), data: options.data ? "true" : undefined, max_rows: options.maxRows });
151
+ }
152
+
153
+ /** Put a downloaded backup back. */
154
+ restore(backup: Body, options: RestoreOptions = {}): Promise<Api> {
155
+ return this.post("/restore", { backup, include: options.include, strategy: options.strategy ?? "merge", dry_run: options.dryRun ?? false, confirm: options.confirm });
156
+ }
157
+
158
+ /** Automatic snapshots: `frequency` hourly, daily (at `hour` UTC) or weekly (on `weekday`, 0 = Monday); older ones are pruned past `keepLast` and `keepDays`. */
159
+ setSchedule(options: { enabled?: boolean; frequency?: "hourly" | "daily" | "weekly"; hour?: number; weekday?: number; keepLast?: number; keepDays?: number; include?: string[] } = {}): Promise<Api> {
160
+ return this.put("/backup-schedule", {
161
+ enabled: options.enabled ?? true,
162
+ frequency: options.frequency ?? "daily",
163
+ hour: options.hour ?? 3,
164
+ weekday: options.weekday ?? 0,
165
+ keep_last: options.keepLast ?? 7,
166
+ keep_days: options.keepDays ?? 30,
167
+ include: options.include ?? [],
168
+ });
169
+ }
170
+
171
+ snapshots(): Promise<Api> {
172
+ return this.get("/snapshots");
173
+ }
174
+
175
+ /** Take a snapshot now and keep it. */
176
+ snapshot(name = "", options: { note?: string; include?: string[] } = {}): Promise<Api> {
177
+ return this.post("/snapshots", { name, note: options.note ?? "", include: options.include });
178
+ }
179
+
180
+ /** Rename it, annotate it, or pin it so pruning keeps it. */
181
+ updateSnapshot(snapshotId: string, changes: { name?: string; note?: string; pinned?: boolean }): Promise<Api> {
182
+ return this.patch(seg("snapshots", snapshotId), changes);
183
+ }
184
+
185
+ removeSnapshot(snapshotId: string): Promise<Api> {
186
+ return this.del(seg("snapshots", snapshotId));
187
+ }
188
+
189
+ downloadSnapshot(snapshotId: string): Promise<Api> {
190
+ return this.get(seg("snapshots", snapshotId, "download"));
191
+ }
192
+
193
+ /** Check the stored snapshot is intact. */
194
+ verifySnapshot(snapshotId: string): Promise<Api> {
195
+ return this.post(seg("snapshots", snapshotId, "verify"));
196
+ }
197
+
198
+ /** Restore a snapshot; a snapshot of the current state is taken first unless `safetySnapshot` is `false`. */
199
+ restoreSnapshot(snapshotId: string, options: RestoreOptions & { safetySnapshot?: boolean } = {}): Promise<Api> {
200
+ return this.post(seg("snapshots", snapshotId, "restore"), {
201
+ include: options.include,
202
+ strategy: options.strategy ?? "merge",
203
+ dry_run: options.dryRun ?? false,
204
+ confirm: options.confirm,
205
+ safety_snapshot: options.safetySnapshot ?? true,
206
+ });
207
+ }
208
+ }
@@ -0,0 +1,22 @@
1
+ import { Definitions, Service, type Api } from "./base.js";
2
+
3
+ /** Templates (subject, HTML, text) for the mail flows, functions and sign-in send. */
4
+ export class MailTemplates extends Definitions {
5
+ protected override readonly kind = "mail-templates";
6
+ }
7
+
8
+ export class Mail extends Service {
9
+ /** The delivery settings in effect (the password is never returned) and whether mail is being delivered. */
10
+ config(): Promise<Api> {
11
+ return this.get("/mail/config");
12
+ }
13
+
14
+ /** Messages sent or suppressed. `status`: `sent`, `failed`, `suppressed`. */
15
+ log(options: { status?: string; limit?: number } = {}): Promise<Api> {
16
+ return this.get("/mail/log", options);
17
+ }
18
+
19
+ sendTest(to: string[]): Promise<Api> {
20
+ return this.post("/mail/test", { to });
21
+ }
22
+ }
@@ -0,0 +1,226 @@
1
+ import { Service, seg, type Api } from "./base.js";
2
+
3
+ type When = Date | string;
4
+ const iso = (value?: When): string | undefined => (value instanceof Date ? value.toISOString() : value);
5
+
6
+ export class Observability extends Service {
7
+ /** The environment at a glance: traffic, errors, latency, workers, storage. */
8
+ overview(options: { range?: string } = {}): Promise<Api> {
9
+ return this.get("/overview", options);
10
+ }
11
+
12
+ /** Traffic over a `range` (`1h`, `24h`, `7d`…) or between `from` and `to`. */
13
+ analytics(options: { range?: string; from?: When; to?: When } = {}): Promise<Api> {
14
+ return this.get("/analytics", { range: options.range, from: iso(options.from), to: iso(options.to) });
15
+ }
16
+
17
+ /** Recent requests. `status` is an exact code or a class (`5xx`); `search` matches the path. */
18
+ requests(options: { status?: string; method?: string; search?: string; requestId?: string; limit?: number } = {}): Promise<Api> {
19
+ const { requestId, ...rest } = options;
20
+ return this.get("/requests", { ...rest, request_id: requestId });
21
+ }
22
+
23
+ /** One request: its logs, database calls, spans, and the traceback if it failed. */
24
+ request(requestId: string): Promise<Api> {
25
+ return this.get(seg("requests", requestId));
26
+ }
27
+
28
+ /** Search application and access logs. `after` continues from the last entry you saw. */
29
+ logs(options: { q?: string; minutes?: number; limit?: number; after?: When } = {}): Promise<Api> {
30
+ return this.get("/logs", { q: options.q || undefined, minutes: options.minutes ?? 60, limit: options.limit ?? 200, after: iso(options.after) });
31
+ }
32
+
33
+ errors(options: { minutes?: number } = {}): Promise<Api> {
34
+ return this.get("/observability/errors", options);
35
+ }
36
+
37
+ /** Per-route traffic, latency and errors. */
38
+ routes(options: { minutes?: number; limit?: number; sort?: string } = {}): Promise<Api> {
39
+ return this.get("/observability/routes", options);
40
+ }
41
+
42
+ route(method: string, route: string, options: { minutes?: number } = {}): Promise<Api> {
43
+ return this.get("/observability/routes/detail", { method, route, ...options });
44
+ }
45
+
46
+ /** CPU, memory and connection figures over time. */
47
+ system(options: { minutes?: number } = {}): Promise<Api> {
48
+ return this.get("/observability/system", options);
49
+ }
50
+
51
+ /** Findings the platform spotted: slow routes, missing indexes, noisy errors. */
52
+ advisor(options: { minutes?: number } = {}): Promise<Api> {
53
+ return this.get("/advisor", options);
54
+ }
55
+
56
+ /** Counters per minute. */
57
+ metrics(options: { name?: string; minutes?: number } = {}): Promise<Api> {
58
+ return this.get("/metrics", options);
59
+ }
60
+
61
+ /** The metrics you can chart or alarm on. */
62
+ metricCatalog(): Promise<Api> {
63
+ return this.get("/metric-catalog");
64
+ }
65
+
66
+ /** One metric over time; `comparePrevious` adds the span before it. */
67
+ metricSeries(metric = "requests", options: { minutes?: number; period?: number; comparePrevious?: boolean } = {}): Promise<Api> {
68
+ return this.get("/metric-series", { metric, minutes: options.minutes ?? 60, period: options.period, compare: options.comparePrevious ? "previous" : undefined });
69
+ }
70
+
71
+ workers(): Promise<Api> {
72
+ return this.get("/workers");
73
+ }
74
+
75
+ /** What the environment is running with. */
76
+ configuration(): Promise<Api> {
77
+ return this.get("/configuration");
78
+ }
79
+
80
+ capacity(): Promise<Api> {
81
+ return this.get("/capacity");
82
+ }
83
+ }
84
+
85
+ export interface AlarmInput {
86
+ name: string;
87
+ /** A name from {@link Observability.metricCatalog}. */
88
+ metric: string;
89
+ threshold: number;
90
+ comparison?: "gt" | "gte" | "lt" | "lte";
91
+ windowMinutes?: number;
92
+ breachesNeeded?: number;
93
+ recipients?: string[];
94
+ description?: string;
95
+ enabled?: boolean;
96
+ renotifyMinutes?: number;
97
+ }
98
+
99
+ /** Alarms on a metric: when it crosses `threshold` for `breachesNeeded` checks in a row, `recipients` are mailed. */
100
+ export class Alarms extends Service {
101
+ list(): Promise<Api> {
102
+ return this.get("/alarms");
103
+ }
104
+
105
+ create(alarm: AlarmInput): Promise<Api> {
106
+ return this.post("/alarms", {
107
+ name: alarm.name,
108
+ metric: alarm.metric,
109
+ threshold: alarm.threshold,
110
+ comparison: alarm.comparison ?? "gt",
111
+ window_minutes: alarm.windowMinutes ?? 5,
112
+ breaches_needed: alarm.breachesNeeded ?? 1,
113
+ recipients: alarm.recipients ?? [],
114
+ description: alarm.description ?? "",
115
+ enabled: alarm.enabled ?? true,
116
+ renotify_minutes: alarm.renotifyMinutes ?? 0,
117
+ });
118
+ }
119
+
120
+ /** Change some fields, using the server's names (`mute_minutes: 60` silences it for an hour, `0` un-mutes). */
121
+ update(alarmId: string, changes: Record<string, unknown>): Promise<Api> {
122
+ return this.patch(seg("alarms", alarmId), changes);
123
+ }
124
+
125
+ remove(alarmId: string): Promise<Api> {
126
+ return this.del(seg("alarms", alarmId));
127
+ }
128
+
129
+ /** Evaluate it now. */
130
+ check(alarmId: string): Promise<Api> {
131
+ return this.post(seg("alarms", alarmId, "check"));
132
+ }
133
+
134
+ /** Send the notification mail now. */
135
+ test(alarmId: string): Promise<Api> {
136
+ return this.post(seg("alarms", alarmId, "test"));
137
+ }
138
+
139
+ /** When alarms fired and recovered: one alarm's, or all. */
140
+ history(alarmId?: string): Promise<Api> {
141
+ return alarmId ? this.get(seg("alarms", alarmId, "events")) : this.get("/alarm-events");
142
+ }
143
+ }
144
+
145
+ export interface StatusComponent {
146
+ name: string;
147
+ /** `gateway`, `api`, `auth`, `realtime`, `workers` (measured) or `manual`. */
148
+ source?: string;
149
+ description?: string;
150
+ }
151
+
152
+ /** The public status page and its incidents. */
153
+ export class StatusPage extends Service {
154
+ page(): Promise<Api> {
155
+ return this.get("/status-page");
156
+ }
157
+
158
+ configure(options: { enabled?: boolean; title?: string; description?: string; contactUrl?: string; components?: StatusComponent[] } = {}): Promise<Api> {
159
+ return this.put("/status-page", {
160
+ enabled: options.enabled ?? true,
161
+ title: options.title ?? "Status",
162
+ description: options.description ?? "",
163
+ contact_url: options.contactUrl ?? "",
164
+ components: options.components ?? [],
165
+ });
166
+ }
167
+
168
+ incidents(): Promise<Api> {
169
+ return this.get("/incidents");
170
+ }
171
+
172
+ /** `status`: investigating, identified, monitoring, resolved. `impact`: none, minor, major, critical. */
173
+ openIncident(title: string, options: { message?: string; status?: string; impact?: string; components?: string[] } = {}): Promise<Api> {
174
+ return this.post("/incidents", {
175
+ title,
176
+ message: options.message ?? "",
177
+ status: options.status ?? "investigating",
178
+ impact: options.impact ?? "minor",
179
+ components: options.components ?? [],
180
+ });
181
+ }
182
+
183
+ updateIncident(incidentId: string, message: string, options: { status: string; impact?: string }): Promise<Api> {
184
+ return this.post(seg("incidents", incidentId, "updates"), { status: options.status, message, impact: options.impact });
185
+ }
186
+
187
+ removeIncident(incidentId: string): Promise<Api> {
188
+ return this.del(seg("incidents", incidentId));
189
+ }
190
+ }
191
+
192
+ export interface AuditFilter {
193
+ action?: string;
194
+ actor?: string;
195
+ target?: string;
196
+ since?: When;
197
+ until?: When;
198
+ env?: string;
199
+ }
200
+
201
+ /** Service health, plan usage and the platform's own audit trail. */
202
+ export class Health extends Service {
203
+ /** Each service (database, cache, queue, storage, mail…) with its state, latency and error rate. */
204
+ services(): Promise<Api> {
205
+ return this.get("/service-health");
206
+ }
207
+
208
+ /** Each plan limit and how much of it is used. */
209
+ usage(): Promise<Api> {
210
+ return this.get("/plan-usage");
211
+ }
212
+
213
+ retryPolicies(): Promise<Api> {
214
+ return this.project("GET", "/retry-policies");
215
+ }
216
+
217
+ /** Management-plane changes: who did what, to what, when. */
218
+ audit(filter: AuditFilter = {}): Promise<Api> {
219
+ return this.project("GET", "/audit", { query: { ...filter, since: iso(filter.since), until: iso(filter.until) } });
220
+ }
221
+
222
+ /** The audit trail as a file's contents (`jsonl` or `csv`), for the same filters as {@link audit}. */
223
+ exportAudit(filter: AuditFilter & { format?: "jsonl" | "csv" } = {}): Promise<string> {
224
+ return this.project<string>("GET", "/audit/export", { query: { ...filter, format: filter.format ?? "jsonl", since: iso(filter.since), until: iso(filter.until) }, parse: "text" });
225
+ }
226
+ }
@@ -0,0 +1,95 @@
1
+ import { type Api, Service, seg } from "./base.js";
2
+
3
+ export type ChannelKind = "public" | "private" | "presence" | "protected" | "ephemeral" | "durable";
4
+
5
+ export interface ChannelRule {
6
+ kind?: ChannelKind;
7
+ /** The policy that decides who may subscribe. Default `authenticated`. */
8
+ subscribe?: string;
9
+ /** The policy that decides who may publish. Default `authenticated`. */
10
+ publish?: string;
11
+ presence?: boolean;
12
+ /** How many recent messages are kept (0 to 1000). */
13
+ history?: number;
14
+ /** A limit of `0` means none. */
15
+ messageSizeLimit?: number;
16
+ publishRateLimit?: number;
17
+ subscriptionLimit?: number;
18
+ retentionSeconds?: number;
19
+ description?: string;
20
+ }
21
+
22
+ const wire = (rule: ChannelRule): Record<string, unknown> => {
23
+ const map: Record<string, unknown> = {
24
+ kind: rule.kind,
25
+ subscribe: rule.subscribe,
26
+ publish: rule.publish,
27
+ presence: rule.presence,
28
+ history: rule.history,
29
+ message_size_limit: rule.messageSizeLimit,
30
+ publish_rate_limit: rule.publishRateLimit,
31
+ subscription_limit: rule.subscriptionLimit,
32
+ retention_seconds: rule.retentionSeconds,
33
+ description: rule.description,
34
+ };
35
+ return Object.fromEntries(Object.entries(map).filter(([, value]) => value !== undefined));
36
+ };
37
+
38
+ /** Durable channel rules: a channel name pattern (`chat:*`), its kind, who may subscribe and publish, presence, history and limits. */
39
+ export class RealtimeChannels extends Service {
40
+ list(): Promise<Api> {
41
+ return this.get("/realtime-channels");
42
+ }
43
+
44
+ /** Add a rule for channels matching `pattern`. */
45
+ create(pattern: string, rule: ChannelRule = {}): Promise<Api> {
46
+ return this.post("/realtime-channels", { pattern, ...wire(rule) });
47
+ }
48
+
49
+ update(channelId: string, changes: ChannelRule): Promise<Api> {
50
+ return this.patch(seg("realtime-channels", channelId), wire(changes));
51
+ }
52
+
53
+ remove(channelId: string): Promise<Api> {
54
+ return this.del(seg("realtime-channels", channelId));
55
+ }
56
+ }
57
+
58
+ /** Dashboards: read-only boards over your data, defined as JSON, optionally published at a public address. */
59
+ export class Dashboards extends Service {
60
+ list(): Promise<Api> {
61
+ return this.get("/dashboards");
62
+ }
63
+
64
+ /** One dashboard with its full definition. */
65
+ getOne(dashboardId: string): Promise<Api> {
66
+ return this.get(seg("dashboards", dashboardId));
67
+ }
68
+
69
+ /** Make a dashboard (`name`: lowercase letters, digits and dashes). The definition is checked; a problem comes back as a 422 with the list. */
70
+ create(name: string, options: { definition?: Record<string, unknown>; title?: string; description?: string; enabled?: boolean } = {}): Promise<Api> {
71
+ return this.post("/dashboards", {
72
+ name,
73
+ title: options.title ?? "",
74
+ description: options.description ?? "",
75
+ definition: options.definition ?? { pages: [] },
76
+ enabled: options.enabled ?? true,
77
+ });
78
+ }
79
+
80
+ update(dashboardId: string, changes: { title?: string; description?: string; definition?: Record<string, unknown>; enabled?: boolean }): Promise<Api> {
81
+ return this.patch(seg("dashboards", dashboardId), Object.fromEntries(Object.entries(changes).filter(([, value]) => value !== undefined)));
82
+ }
83
+
84
+ remove(dashboardId: string): Promise<Api> {
85
+ return this.del(seg("dashboards", dashboardId));
86
+ }
87
+
88
+ /** Turn the public page on or off. Turning it on needs the environment's publishable key once (it is sealed and never returned). */
89
+ publish(dashboardId: string, options: { public: boolean; publishableKey?: string }): Promise<Api> {
90
+ return this.put(seg("dashboards", dashboardId, "publish"), {
91
+ public: options.public,
92
+ ...(options.publishableKey ? { publishable_key: options.publishableKey } : {}),
93
+ });
94
+ }
95
+ }