@pawabase/client 0.0.0-stage → 0.1.3

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 +92 -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,162 @@
1
+ import { Definitions, Service, seg, type Api, type Body } from "./base.js";
2
+
3
+ /** Flows: graphs of blocks that run on a trigger (HTTP, event, schedule, resource change, webhook, manual). */
4
+ export class Flows extends Definitions {
5
+ protected override readonly kind = "flows";
6
+
7
+ /** Run a flow now as an operator (or `asUser`): `{ status, run_id, result, response, trace }`. `entry` picks a trigger node. */
8
+ run(name: string, input?: unknown, options: { asUser?: Body; entry?: string } = {}): Promise<Api> {
9
+ return this.post(seg(this.kind, name, "run"), { input, as_user: options.asUser ?? null, entry: options.entry ?? null });
10
+ }
11
+
12
+ /** Check a flow's graph without saving it: the problems, node by node. */
13
+ validate(definition: Body): Promise<Api> {
14
+ return this.project("POST", "/flows/validate", { body: { definition } });
15
+ }
16
+
17
+ /** The catalogue of blocks a flow can use, with their configuration fields. */
18
+ blocks(): Promise<Api> {
19
+ return this.project("GET", "/blocks");
20
+ }
21
+
22
+ runs(options: { flow?: string; status?: string; limit?: number; after?: string } = {}): Promise<Api> {
23
+ return this.get("/flow-runs", options);
24
+ }
25
+
26
+ /** One run with its per-block trace. */
27
+ runDetail(runId: string): Promise<Api> {
28
+ return this.get(seg("flow-runs", runId));
29
+ }
30
+ }
31
+
32
+ /** Cron and interval schedules that run a flow or function, or emit an event. */
33
+ export class Schedules extends Definitions {
34
+ protected override readonly kind = "schedules";
35
+
36
+ /** Fire a schedule now, exactly as the scheduler would. */
37
+ run(name: string): Promise<Api> {
38
+ return this.post(seg(this.kind, name, "run"));
39
+ }
40
+ }
41
+
42
+ /** Event subscriptions: which events run which flow or function, or reach which realtime channel. */
43
+ export class Subscriptions extends Definitions {
44
+ protected override readonly kind = "subscriptions";
45
+ }
46
+
47
+ /** The event bus: emit, and inspect what happened to each event. */
48
+ export class Events extends Service {
49
+ /** Publish an event: every subscription, flow and webhook listening for it runs. */
50
+ emit(name: string, payload?: unknown): Promise<Api> {
51
+ return this.post("/events", { name, payload });
52
+ }
53
+
54
+ list(options: { name?: string; limit?: number; after?: string } = {}): Promise<Api> {
55
+ return this.get("/events", options);
56
+ }
57
+
58
+ /** One event with every consumer it reached and how that went. */
59
+ detail(eventId: string): Promise<Api> {
60
+ return this.get(seg("events", eventId));
61
+ }
62
+
63
+ /** Which event names exist and who consumes each. */
64
+ graph(): Promise<Api> {
65
+ return this.get("/events-graph");
66
+ }
67
+ }
68
+
69
+ /** Outbound webhooks: endpoints that receive signed events, with retries. */
70
+ export class Webhooks extends Definitions {
71
+ protected override readonly kind = "webhooks";
72
+
73
+ /** Send one test event to an endpoint (one attempt, not retried). */
74
+ test(name: string): Promise<Api> {
75
+ return this.post(seg(this.kind, name, "test"));
76
+ }
77
+
78
+ /** Delivery history. `status`: `pending`, `retrying`, `delivered`, `failed`. */
79
+ deliveries(options: { status?: string; endpoint?: string; limit?: number } = {}): Promise<Api> {
80
+ return this.get("/webhook-deliveries", options);
81
+ }
82
+
83
+ redeliver(deliveryId: string): Promise<Api> {
84
+ return this.post(seg("webhook-deliveries", deliveryId, "redeliver"));
85
+ }
86
+
87
+ /** Send many again: by `ids`, or every delivery matching a filter (up to `limit`, 100 by default). `dryRun` only counts. */
88
+ redeliverMany(options: { ids?: string[]; status?: string; endpoint?: string; event?: string; sinceMinutes?: number; limit?: number; dryRun?: boolean } = {}): Promise<Api> {
89
+ return this.post("/webhook-deliveries/redeliver", {
90
+ ids: options.ids,
91
+ status: options.status ?? "failed",
92
+ endpoint: options.endpoint,
93
+ event: options.event,
94
+ since_minutes: options.sinceMinutes,
95
+ limit: options.limit ?? 100,
96
+ dry_run: options.dryRun ?? false,
97
+ });
98
+ }
99
+ }
100
+
101
+ /** Inbound hooks: URLs other services call (signature-checked), each starting a flow or function. */
102
+ export class InboundHooks extends Definitions {
103
+ protected override readonly kind = "inbound-hooks";
104
+
105
+ /** The public URL to give the sender. */
106
+ url(slug: string): Promise<Api> {
107
+ return this.get(seg(this.kind, slug, "url"));
108
+ }
109
+ }
110
+
111
+ /** Background work: jobs, failures and replays, queues, workers and how failed work is retried. */
112
+ export class Jobs extends Service {
113
+ /** `status`: `queued`, `active`, `retrying`, `succeeded`, `failed`. */
114
+ list(options: { status?: string; queue?: string; limit?: number } = {}): Promise<Api> {
115
+ return this.get("/jobs", options);
116
+ }
117
+
118
+ detail(jobId: string): Promise<Api> {
119
+ return this.get(seg("jobs", jobId));
120
+ }
121
+
122
+ retry(jobId: string): Promise<Api> {
123
+ return this.post(seg("jobs", jobId, "retry"));
124
+ }
125
+
126
+ /** Queue recorded jobs again: named `ids`, or every job matching the filter (failed by default; `limit` 200). `dryRun` only counts. */
127
+ replay(options: { ids?: string[]; status?: string; queue?: string; job?: string; sinceMinutes?: number; limit?: number; dryRun?: boolean } = {}): Promise<Api> {
128
+ return this.post("/jobs/replay", {
129
+ ids: options.ids ?? [],
130
+ status: options.status ?? "failed",
131
+ queue: options.queue,
132
+ job: options.job,
133
+ since_minutes: options.sinceMinutes,
134
+ limit: options.limit ?? 200,
135
+ dry_run: options.dryRun ?? false,
136
+ });
137
+ }
138
+
139
+ /** Jobs that gave up after their retries. */
140
+ failed(): Promise<Api> {
141
+ return this.get("/failed-jobs");
142
+ }
143
+
144
+ dismissFailed(jobId: string): Promise<Api> {
145
+ return this.del(seg("failed-jobs", jobId));
146
+ }
147
+
148
+ /** Queues with depth and job counts. */
149
+ queues(): Promise<Api> {
150
+ return this.get("/queues");
151
+ }
152
+
153
+ /** The processes taking jobs (installation-wide). */
154
+ workers(): Promise<Api> {
155
+ return this.project("GET", "/workers");
156
+ }
157
+
158
+ /** How each kind of background work is retried: attempts and the wait before each retry. */
159
+ retryPolicies(): Promise<Api> {
160
+ return this.project("GET", "/retry-policies");
161
+ }
162
+ }
@@ -0,0 +1,83 @@
1
+ import type { HttpClient } from "../http.js";
2
+ import type { QueryValue } from "../util.js";
3
+
4
+ /** What the management plane answers: a JSON document (lists are `{ data: [...] }`). */
5
+ export type Api = Record<string, any>;
6
+ export type Query = Record<string, QueryValue | QueryValue[]>;
7
+ export type Body = Record<string, unknown>;
8
+
9
+ /** URL path segments, each encoded: `seg("flows", name, "run")` → `/flows/<name>/run`. */
10
+ export function seg(...parts: Array<string | number>): string {
11
+ return "/" + parts.map((part) => encodeURIComponent(String(part))).join("/");
12
+ }
13
+
14
+ /** Everything a management service shares: the environment a call is for, and the five verbs. */
15
+ export class Service {
16
+ constructor(
17
+ protected readonly http: HttpClient,
18
+ private readonly environmentName: string,
19
+ ) {}
20
+
21
+ /** The environment this service manages. */
22
+ get environment(): string {
23
+ return this.environmentName;
24
+ }
25
+
26
+ protected path(suffix = ""): string {
27
+ return `/platform/v1/envs/${encodeURIComponent(this.environmentName)}${suffix}`;
28
+ }
29
+
30
+ protected get<T = Api>(suffix = "", query?: Query): Promise<T> {
31
+ return this.http.request<T>({ path: this.path(suffix), ...(query ? { query } : {}) });
32
+ }
33
+
34
+ protected post<T = Api>(suffix = "", body?: unknown, query?: Query): Promise<T> {
35
+ return this.http.request<T>({ method: "POST", path: this.path(suffix), body, ...(query ? { query } : {}) });
36
+ }
37
+
38
+ protected put<T = Api>(suffix: string, body?: unknown, query?: Query): Promise<T> {
39
+ return this.http.request<T>({ method: "PUT", path: this.path(suffix), body, ...(query ? { query } : {}) });
40
+ }
41
+
42
+ protected patch<T = Api>(suffix: string, body?: unknown, query?: Query): Promise<T> {
43
+ return this.http.request<T>({ method: "PATCH", path: this.path(suffix), body, ...(query ? { query } : {}) });
44
+ }
45
+
46
+ protected del<T = Api>(suffix: string, query?: Query, body?: unknown): Promise<T> {
47
+ return this.http.request<T>({ method: "DELETE", path: this.path(suffix), ...(query ? { query } : {}), ...(body !== undefined ? { body } : {}) });
48
+ }
49
+
50
+ /** A call that is not scoped to an environment (`/platform/v1/...`). */
51
+ protected project<T = Api>(method: string, suffix: string, options: { body?: unknown; query?: Query; parse?: "json" | "text" | "response" } = {}): Promise<T> {
52
+ return this.http.request<T>({ method, path: `/platform/v1${suffix}`, ...options });
53
+ }
54
+ }
55
+
56
+ /**
57
+ * A kind of definition an environment holds (`flows`, `policies`, `webhooks`…): list, get, create, replace, remove.
58
+ * Pass `branch` to work on a feature branch's draft instead of the live environment. A definition is addressed by its name
59
+ * (inbound hooks: their slug).
60
+ */
61
+ export class Definitions extends Service {
62
+ protected readonly kind: string = "";
63
+
64
+ list(options: { branch?: string } = {}): Promise<Api> {
65
+ return this.get(seg(this.kind), { branch: options.branch });
66
+ }
67
+
68
+ getOne(key: string, options: { branch?: string } = {}): Promise<Api> {
69
+ return this.get(seg(this.kind, key), { branch: options.branch });
70
+ }
71
+
72
+ create(body: Body, options: { branch?: string } = {}): Promise<Api> {
73
+ return this.post(seg(this.kind), body, { branch: options.branch });
74
+ }
75
+
76
+ replace(key: string, body: Body, options: { branch?: string } = {}): Promise<Api> {
77
+ return this.put(seg(this.kind, key), body, { branch: options.branch });
78
+ }
79
+
80
+ remove(key: string, options: { branch?: string } = {}): Promise<Api> {
81
+ return this.del(seg(this.kind, key), { branch: options.branch });
82
+ }
83
+ }
@@ -0,0 +1,159 @@
1
+ import { Definitions, Service, seg, type Api, type Body, type Query } from "./base.js";
2
+
3
+ /**
4
+ * Resources: the tables your API serves, with fields, relations, per-operation policies and indexes.
5
+ *
6
+ * ```ts
7
+ * await m.resources.create({ name: "posts", fields: [{ name: "title", type: "string", required: true }],
8
+ * operations: { list: { enabled: true, policy: "public" } } });
9
+ * await m.resources.migrate("posts");
10
+ * ```
11
+ */
12
+ export class Resources extends Definitions {
13
+ protected override readonly kind = "resources";
14
+
15
+ /** Browse a resource's records as an operator (policies do not apply). Extra keys are passed as query parameters (`filter[field]`…). */
16
+ records(name: string, options: { limit?: number; offset?: number; filters?: Query } = {}): Promise<Api> {
17
+ return this.get(seg(this.kind, name, "records"), { limit: options.limit, offset: options.offset, ...options.filters });
18
+ }
19
+
20
+ insert(name: string, values: Body): Promise<Api> {
21
+ return this.post(seg(this.kind, name, "records"), values);
22
+ }
23
+
24
+ updateRecord(name: string, recordId: string | number, values: Body): Promise<Api> {
25
+ return this.patch(seg(this.kind, name, "records", recordId), values);
26
+ }
27
+
28
+ deleteRecord(name: string, recordId: string | number): Promise<Api> {
29
+ return this.del(seg(this.kind, name, "records", recordId));
30
+ }
31
+
32
+ /** Every record, for a file download. */
33
+ export(name: string, options: { format?: string } = {}): Promise<Api> {
34
+ return this.get(seg(this.kind, name, "export"), { format: options.format });
35
+ }
36
+
37
+ /** Add or update records from parsed rows: `{ created, updated, failed, errors }`. */
38
+ importRecords(name: string, rows: Body[], options: { key?: string; mode?: string; dryRun?: boolean } = {}): Promise<Api> {
39
+ return this.post(seg(this.kind, name, "import"), { rows, key: options.key, mode: options.mode, dry_run: options.dryRun });
40
+ }
41
+
42
+ /** The resource's compiled routes. */
43
+ openapi(name: string): Promise<Api> {
44
+ return this.get(seg(this.kind, name, "openapi"));
45
+ }
46
+
47
+ /** Create the resource's table, or add what its definition gained. Returns the statements it ran. */
48
+ migrate(name: string): Promise<Api> {
49
+ return this.post(seg(this.kind, name, "migrate"));
50
+ }
51
+
52
+ /** What applying the definition would change. */
53
+ schemaPlan(name: string): Promise<Api> {
54
+ return this.get(seg(this.kind, name, "schema"));
55
+ }
56
+
57
+ schemaApply(name: string, body: Body = {}): Promise<Api> {
58
+ return this.post(seg(this.kind, name, "schema", "apply"), body);
59
+ }
60
+
61
+ /** Take the table as it is now as the starting point and put what changed in the definition. */
62
+ schemaAcknowledge(name: string, body: Body = {}): Promise<Api> {
63
+ return this.post(seg(this.kind, name, "schema", "acknowledge"), body);
64
+ }
65
+
66
+ /** Remove what migrations kept for a rollback. */
67
+ schemaPurge(name: string, body: Body = {}): Promise<Api> {
68
+ return this.post(seg(this.kind, name, "schema", "purge"), body);
69
+ }
70
+
71
+ migrations(name: string): Promise<Api> {
72
+ return this.get(seg(this.kind, name, "migrations"));
73
+ }
74
+
75
+ rollbackMigration(name: string, migrationId: string): Promise<Api> {
76
+ return this.post(seg(this.kind, name, "migrations", migrationId, "rollback"));
77
+ }
78
+
79
+ /** A table's indexes: declared, field, hand-made and system. */
80
+ indexes(name: string): Promise<Api> {
81
+ return this.get(seg(this.kind, name, "indexes"));
82
+ }
83
+
84
+ /** Drop an index made outside Pawabase. */
85
+ dropIndex(name: string, index: string, body: Body = {}): Promise<Api> {
86
+ return this.post(seg(this.kind, name, "indexes", index, "drop"), body);
87
+ }
88
+ }
89
+
90
+ /** The whole database against its definitions. */
91
+ export class Schema extends Service {
92
+ /** Every resource's table against its definition. */
93
+ overview(): Promise<Api> {
94
+ return this.get("/schema");
95
+ }
96
+
97
+ /** Tables in the database that no resource is defined for. */
98
+ unmappedTables(): Promise<Api> {
99
+ return this.get("/schema/tables");
100
+ }
101
+ }
102
+
103
+ /** Named access policies (conditions) that resources, buckets, channels and functions refer to. */
104
+ export class Policies extends Definitions {
105
+ protected override readonly kind = "policies";
106
+ }
107
+
108
+ /** Reusable data shapes referred to by resource fields. */
109
+ export class Schemas extends Definitions {
110
+ protected override readonly kind = "schemas";
111
+ }
112
+
113
+ /** Transformers that reshape a field's value on the way out (hide, mask, format). */
114
+ export class Transformers extends Definitions {
115
+ protected override readonly kind = "transformers";
116
+ }
117
+
118
+ /** Custom HTTP routes under `/rest` that run a flow. */
119
+ export class Routes extends Definitions {
120
+ protected override readonly kind = "routes";
121
+ }
122
+
123
+ /** The environment's database: tables, rows and the SQL console (one statement at a time; reads are read-only in the database itself). */
124
+ export class Database extends Service {
125
+ info(): Promise<Api> {
126
+ return this.get("/database");
127
+ }
128
+
129
+ /** A table's columns, indexes and foreign keys. */
130
+ table(table: string): Promise<Api> {
131
+ return this.get(seg("database", "tables", table));
132
+ }
133
+
134
+ rows(table: string, options: { limit?: number; offset?: number; sort?: string; filters?: Query } = {}): Promise<Api> {
135
+ return this.get(seg("database", "tables", table, "rows"), { limit: options.limit, offset: options.offset, sort: options.sort, ...options.filters });
136
+ }
137
+
138
+ /** Run one statement. A write needs `allowWrite`; it is audited and clears the environment's caches. */
139
+ query(sql: string, params: unknown[] = [], options: { allowWrite?: boolean } = {}): Promise<Api> {
140
+ return this.post("/database/query", { sql, params, allow_write: options.allowWrite ?? false });
141
+ }
142
+ }
143
+
144
+ /** The runtime capabilities a function sees, called remotely (what `pawabase emulate` uses). */
145
+ export class Runtime extends Service {
146
+ call(method: string, args: unknown[] = [], kwargs: Body = {}, options: { asUser?: Body; branch?: string } = {}): Promise<Api> {
147
+ return this.post("/runtime/call", { method, args, kwargs, as_user: options.asUser ?? null, branch: options.branch ?? null });
148
+ }
149
+
150
+ /** `fetch`, `insert`, `execute`, `begin`, `commit`…, optionally inside a transaction (`tx`). */
151
+ sql(op: string, fields: Body = {}): Promise<Api> {
152
+ return this.post("/runtime/db", { op, ...fields });
153
+ }
154
+
155
+ /** Who a user access token belongs to. */
156
+ identify(token: string | null): Promise<Api> {
157
+ return this.post("/runtime/identify", { token });
158
+ }
159
+ }
@@ -0,0 +1,79 @@
1
+ import { Definitions, Service, seg, type Api } from "./base.js";
2
+
3
+ /**
4
+ * Storage administration: buckets, the objects in them, temporary share links and signed URLs. (Reading and writing files as
5
+ * your app does is `client.storage`; this is the operator's view and works with a secret key regardless of policies.)
6
+ */
7
+ export class Buckets extends Definitions {
8
+ protected override readonly kind = "buckets";
9
+
10
+ /** One page of the bucket's objects: `{ files, prefixes, cursor }`. */
11
+ objects(bucket: string, options: { prefix?: string; cursor?: string; limit?: number } = {}): Promise<Api> {
12
+ return this.get(seg(this.kind, bucket, "objects"), options);
13
+ }
14
+
15
+ /** One object's details and a way to read it. */
16
+ object(bucket: string, key: string): Promise<Api> {
17
+ return this.get(seg(this.kind, bucket, "object"), { key });
18
+ }
19
+
20
+ putObject(bucket: string, key: string, content: Blob | ArrayBuffer | Uint8Array | string, contentType = "application/octet-stream"): Promise<Api> {
21
+ return this.http.request({
22
+ method: "PUT",
23
+ path: this.path(seg(this.kind, bucket, "object")),
24
+ query: { key },
25
+ body: content,
26
+ headers: { "content-type": contentType },
27
+ });
28
+ }
29
+
30
+ deleteObject(bucket: string, key: string): Promise<Api> {
31
+ return this.del(seg(this.kind, bucket, "objects", key));
32
+ }
33
+
34
+ /** Rename or move an object inside the bucket. */
35
+ moveObject(bucket: string, source: string, target: string): Promise<Api> {
36
+ return this.post(seg(this.kind, bucket, "object", "move"), { source, target });
37
+ }
38
+
39
+ /** A temporary signed link to one object (`GET` to read, `PUT` to upload). */
40
+ sign(bucket: string, key: string, options: { method?: "GET" | "PUT"; expiresIn?: number; contentType?: string; maxBytes?: number } = {}): Promise<Api> {
41
+ return this.post(seg(this.kind, bucket, "sign"), {
42
+ key,
43
+ method: options.method ?? "GET",
44
+ expires_in: options.expiresIn ?? 300,
45
+ content_type: options.contentType,
46
+ max_bytes: options.maxBytes,
47
+ });
48
+ }
49
+
50
+ shares(bucket: string): Promise<Api> {
51
+ return this.get(seg(this.kind, bucket, "shares"));
52
+ }
53
+
54
+ /** A link to one object for people with no account. `permissions`: `view`, `download`, `both`. The URL is in the answer. */
55
+ createShare(bucket: string, key: string, options: { expiresIn?: number; permissions?: "view" | "download" | "both"; label?: string } = {}): Promise<Api> {
56
+ return this.post(seg(this.kind, bucket, "shares"), {
57
+ key,
58
+ expires_in: options.expiresIn ?? 3600,
59
+ permissions: options.permissions ?? "both",
60
+ label: options.label ?? "",
61
+ });
62
+ }
63
+
64
+ revokeShare(bucket: string, shareId: string): Promise<Api> {
65
+ return this.del(seg(this.kind, bucket, "shares", shareId));
66
+ }
67
+ }
68
+
69
+ /** The environment's response cache. */
70
+ export class Cache extends Service {
71
+ stats(): Promise<Api> {
72
+ return this.get("/cache");
73
+ }
74
+
75
+ /** Drop cached responses by tag (`resource:posts`) or for whole resources. */
76
+ invalidate(options: { tags?: string[]; resources?: string[] } = {}): Promise<Api> {
77
+ return this.post("/cache/invalidate", { tags: options.tags ?? [], resources: options.resources ?? [] });
78
+ }
79
+ }
@@ -0,0 +1,69 @@
1
+ import { Service, seg, type Api, type Body } from "./base.js";
2
+
3
+ /** Deployed functions (Python or TypeScript; a project's functions are one language). */
4
+ export class Functions extends Service {
5
+ /** Functions visible to the environment (and `branch`), each saying whether it came from a branch, a deployment or mounted code. */
6
+ list(options: { branch?: string } = {}): Promise<Api> {
7
+ return this.get("/functions", options);
8
+ }
9
+
10
+ /** Run a function now as an operator (or `asUser`), bypassing its HTTP policy: `{ status, result | error }`. */
11
+ run(name: string, input?: unknown, options: { branch?: string; asUser?: Body } = {}): Promise<Api> {
12
+ return this.post(seg("functions", name, "invoke"), { input, branch: options.branch ?? null, as_user: options.asUser ?? null });
13
+ }
14
+
15
+ /** Upload a base64 `.tar.gz` bundle (`functions/*.py` or `functions/*.ts`) and activate it. The `pawabase deploy` command builds the bundle. */
16
+ deploy(archive: string, options: { branch?: string; manifest?: Body; runtime?: string; limits?: Body } = {}): Promise<Api> {
17
+ return this.post("/function-deployments", {
18
+ archive,
19
+ branch: options.branch ?? "main",
20
+ manifest: options.manifest ?? {},
21
+ runtime: options.runtime ?? "python3.11",
22
+ limits: options.limits ?? {},
23
+ });
24
+ }
25
+
26
+ deployments(options: { branch?: string; limit?: number } = {}): Promise<Api> {
27
+ return this.get("/function-deployments", { limit: 50, ...options });
28
+ }
29
+
30
+ deployment(deploymentId: string): Promise<Api> {
31
+ return this.get(seg("function-deployments", deploymentId));
32
+ }
33
+
34
+ /** Make an earlier deployment the active one again (a rollback). */
35
+ activate(deploymentId: string): Promise<Api> {
36
+ return this.post(seg("function-deployments", deploymentId, "activate"));
37
+ }
38
+
39
+ removeDeployment(deploymentId: string): Promise<Api> {
40
+ return this.del(seg("function-deployments", deploymentId));
41
+ }
42
+
43
+ branches(): Promise<Api> {
44
+ return this.get("/function-branches");
45
+ }
46
+
47
+ /** Delete the functions deployed on `branch`. The environment's own are untouched. */
48
+ removeBranch(branch: string): Promise<Api> {
49
+ return this.del(seg("function-branches", branch));
50
+ }
51
+
52
+ runs(options: { function?: string; branch?: string; status?: string; after?: string; limit?: number } = {}): Promise<Api> {
53
+ return this.get("/function-runs", { limit: 50, ...options });
54
+ }
55
+
56
+ /** One run with its input, output, error and logs. */
57
+ runDetail(runId: string): Promise<Api> {
58
+ return this.get(seg("function-runs", runId));
59
+ }
60
+
61
+ /** The files of the live deployment. */
62
+ source(options: { branch?: string } = {}): Promise<Api> {
63
+ return this.get("/function-source", options);
64
+ }
65
+
66
+ sourceFile(path: string, options: { branch?: string } = {}): Promise<Api> {
67
+ return this.get("/function-source/file", { path, ...options });
68
+ }
69
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * The management plane of one environment, with that environment's secret key (`pb_sk_…`).
3
+ *
4
+ * ```ts
5
+ * import { createClient } from "@pawabase/client";
6
+ * import { manage } from "@pawabase/client/manage";
7
+ *
8
+ * const pawabase = createClient({ url, apiKey: "pb_sk_…", environment: "production" });
9
+ * const m = manage(pawabase);
10
+ * await m.secrets.set("STRIPE_KEY", "sk_live_…");
11
+ * await manage(pawabase, "staging").flows.list(); // the same API for another environment the key may manage
12
+ * ```
13
+ */
14
+ import type { PawabaseClient } from "../client.js";
15
+ import { ConfigError } from "../errors.js";
16
+ import { isSecretKey } from "../util.js";
17
+ import { Domains, Firewall, Keys, Secrets } from "./access.js";
18
+ import { Events, Flows, InboundHooks, Jobs, Schedules, Subscriptions, Webhooks } from "./automation.js";
19
+ import { Database, Policies, Resources, Routes, Runtime, Schema, Schemas, Transformers } from "./data.js";
20
+ import { Buckets, Cache } from "./files.js";
21
+ import { Functions } from "./functions.js";
22
+ import { Backups, Environments, Releases } from "./lifecycle.js";
23
+ import { Mail, MailTemplates } from "./mail.js";
24
+ import { Alarms, Health, Observability, StatusPage } from "./observe.js";
25
+ import { Dashboards, RealtimeChannels } from "./realtime.js";
26
+
27
+ export class Manage {
28
+ // data
29
+ readonly resources: Resources;
30
+ readonly schema: Schema;
31
+ readonly policies: Policies;
32
+ readonly schemas: Schemas;
33
+ readonly transformers: Transformers;
34
+ readonly routes: Routes;
35
+ readonly database: Database;
36
+ readonly runtime: Runtime;
37
+ // automation
38
+ readonly flows: Flows;
39
+ readonly schedules: Schedules;
40
+ readonly subscriptions: Subscriptions;
41
+ readonly events: Events;
42
+ readonly webhooks: Webhooks;
43
+ readonly inboundHooks: InboundHooks;
44
+ readonly jobs: Jobs;
45
+ readonly functions: Functions;
46
+ // files and mail
47
+ readonly buckets: Buckets;
48
+ readonly cache: Cache;
49
+ readonly mail: Mail;
50
+ readonly mailTemplates: MailTemplates;
51
+ // realtime and dashboards
52
+ readonly realtimeChannels: RealtimeChannels;
53
+ readonly dashboards: Dashboards;
54
+ // access
55
+ readonly keys: Keys;
56
+ readonly secrets: Secrets;
57
+ readonly domains: Domains;
58
+ readonly firewall: Firewall;
59
+ // observe
60
+ readonly observability: Observability;
61
+ readonly alarms: Alarms;
62
+ readonly statusPage: StatusPage;
63
+ readonly health: Health;
64
+ // lifecycle
65
+ readonly environments: Environments;
66
+ readonly releases: Releases;
67
+ readonly backups: Backups;
68
+
69
+ constructor(
70
+ private readonly client: PawabaseClient<any>,
71
+ readonly environment: string,
72
+ ) {
73
+ const http = client.http;
74
+ this.resources = new Resources(http, environment);
75
+ this.schema = new Schema(http, environment);
76
+ this.policies = new Policies(http, environment);
77
+ this.schemas = new Schemas(http, environment);
78
+ this.transformers = new Transformers(http, environment);
79
+ this.routes = new Routes(http, environment);
80
+ this.database = new Database(http, environment);
81
+ this.runtime = new Runtime(http, environment);
82
+ this.flows = new Flows(http, environment);
83
+ this.schedules = new Schedules(http, environment);
84
+ this.subscriptions = new Subscriptions(http, environment);
85
+ this.events = new Events(http, environment);
86
+ this.webhooks = new Webhooks(http, environment);
87
+ this.inboundHooks = new InboundHooks(http, environment);
88
+ this.jobs = new Jobs(http, environment);
89
+ this.functions = new Functions(http, environment);
90
+ this.buckets = new Buckets(http, environment);
91
+ this.cache = new Cache(http, environment);
92
+ this.mail = new Mail(http, environment);
93
+ this.mailTemplates = new MailTemplates(http, environment);
94
+ this.realtimeChannels = new RealtimeChannels(http, environment);
95
+ this.dashboards = new Dashboards(http, environment);
96
+ this.keys = new Keys(http, environment);
97
+ this.secrets = new Secrets(http, environment);
98
+ this.domains = new Domains(http, environment);
99
+ this.firewall = new Firewall(http, environment);
100
+ this.observability = new Observability(http, environment);
101
+ this.alarms = new Alarms(http, environment);
102
+ this.statusPage = new StatusPage(http, environment);
103
+ this.health = new Health(http, environment);
104
+ this.environments = new Environments(http, environment);
105
+ this.releases = new Releases(http, environment);
106
+ this.backups = new Backups(http, environment);
107
+ }
108
+
109
+ /** The same services for another environment the key may manage. */
110
+ withEnvironment(name: string): Manage {
111
+ return new Manage(this.client, name);
112
+ }
113
+ }
114
+
115
+ /** The management plane of the client's environment (or `environment`). Needs a secret key. */
116
+ export function manage(client: PawabaseClient<any>, environment?: string): Manage {
117
+ if (!isSecretKey(client.options.apiKey)) {
118
+ throw new ConfigError("The management plane needs a secret key (pb_sk_…).");
119
+ }
120
+ return new Manage(client, environment ?? client.options.environment ?? "development");
121
+ }
122
+
123
+ export * from "./access.js";
124
+ export * from "./automation.js";
125
+ export * from "./base.js";
126
+ export * from "./data.js";
127
+ export * from "./files.js";
128
+ export * from "./functions.js";
129
+ export * from "./lifecycle.js";
130
+ export * from "./mail.js";
131
+ export * from "./observe.js";
132
+ export * from "./realtime.js";