@w6w/sdk 0.3.0 → 0.5.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 (100) hide show
  1. package/README.md +5 -5
  2. package/dist/mod.d.ts +2 -2
  3. package/dist/mod.js +2 -2
  4. package/dist/src/client.d.ts +34 -6
  5. package/dist/src/client.d.ts.map +1 -1
  6. package/dist/src/client.js +34 -5
  7. package/dist/src/client.js.map +1 -1
  8. package/dist/src/config.d.ts +2 -2
  9. package/dist/src/config.js +2 -2
  10. package/dist/src/connections.d.ts +2 -2
  11. package/dist/src/connections.js +1 -1
  12. package/dist/src/console/api-calls.d.ts +80 -0
  13. package/dist/src/console/api-calls.d.ts.map +1 -0
  14. package/dist/src/console/api-calls.js +69 -0
  15. package/dist/src/console/api-calls.js.map +1 -0
  16. package/dist/src/console/apps.d.ts +689 -0
  17. package/dist/src/console/apps.d.ts.map +1 -0
  18. package/dist/src/console/apps.js +402 -0
  19. package/dist/src/console/apps.js.map +1 -0
  20. package/dist/src/console/auth.d.ts +241 -0
  21. package/dist/src/console/auth.d.ts.map +1 -0
  22. package/dist/src/console/auth.js +173 -0
  23. package/dist/src/console/auth.js.map +1 -0
  24. package/dist/src/console/connections.d.ts +188 -0
  25. package/dist/src/console/connections.d.ts.map +1 -0
  26. package/dist/src/console/connections.js +182 -0
  27. package/dist/src/console/connections.js.map +1 -0
  28. package/dist/src/console/dashboard.d.ts +102 -0
  29. package/dist/src/console/dashboard.d.ts.map +1 -0
  30. package/dist/src/console/dashboard.js +59 -0
  31. package/dist/src/console/dashboard.js.map +1 -0
  32. package/dist/src/console/endpoints.d.ts +264 -0
  33. package/dist/src/console/endpoints.d.ts.map +1 -0
  34. package/dist/src/console/endpoints.js +164 -0
  35. package/dist/src/console/endpoints.js.map +1 -0
  36. package/dist/src/console/functions.d.ts +165 -0
  37. package/dist/src/console/functions.d.ts.map +1 -0
  38. package/dist/src/console/functions.js +117 -0
  39. package/dist/src/console/functions.js.map +1 -0
  40. package/dist/src/console/mod.d.ts +131 -0
  41. package/dist/src/console/mod.d.ts.map +1 -0
  42. package/dist/src/console/mod.js +121 -0
  43. package/dist/src/console/mod.js.map +1 -0
  44. package/dist/src/console/projects.d.ts +107 -0
  45. package/dist/src/console/projects.d.ts.map +1 -0
  46. package/dist/src/console/projects.js +97 -0
  47. package/dist/src/console/projects.js.map +1 -0
  48. package/dist/src/console/reliability.d.ts +149 -0
  49. package/dist/src/console/reliability.d.ts.map +1 -0
  50. package/dist/src/console/reliability.js +56 -0
  51. package/dist/src/console/reliability.js.map +1 -0
  52. package/dist/src/console/saved-tests.d.ts +198 -0
  53. package/dist/src/console/saved-tests.d.ts.map +1 -0
  54. package/dist/src/console/saved-tests.js +172 -0
  55. package/dist/src/console/saved-tests.js.map +1 -0
  56. package/dist/src/console/schedules.d.ts +127 -0
  57. package/dist/src/console/schedules.d.ts.map +1 -0
  58. package/dist/src/console/schedules.js +118 -0
  59. package/dist/src/console/schedules.js.map +1 -0
  60. package/dist/src/console/step-tests.d.ts +159 -0
  61. package/dist/src/console/step-tests.d.ts.map +1 -0
  62. package/dist/src/console/step-tests.js +129 -0
  63. package/dist/src/console/step-tests.js.map +1 -0
  64. package/dist/src/console/subscriptions.d.ts +199 -0
  65. package/dist/src/console/subscriptions.d.ts.map +1 -0
  66. package/dist/src/console/subscriptions.js +191 -0
  67. package/dist/src/console/subscriptions.js.map +1 -0
  68. package/dist/src/console/tenant-oauth-apps.d.ts +188 -0
  69. package/dist/src/console/tenant-oauth-apps.d.ts.map +1 -0
  70. package/dist/src/console/tenant-oauth-apps.js +152 -0
  71. package/dist/src/console/tenant-oauth-apps.js.map +1 -0
  72. package/dist/src/console/tokens.d.ts +159 -0
  73. package/dist/src/console/tokens.d.ts.map +1 -0
  74. package/dist/src/console/tokens.js +145 -0
  75. package/dist/src/console/tokens.js.map +1 -0
  76. package/dist/src/console/vault.d.ts +188 -0
  77. package/dist/src/console/vault.d.ts.map +1 -0
  78. package/dist/src/console/vault.js +164 -0
  79. package/dist/src/console/vault.js.map +1 -0
  80. package/dist/src/console/workflows.d.ts +243 -0
  81. package/dist/src/console/workflows.d.ts.map +1 -0
  82. package/dist/src/console/workflows.js +205 -0
  83. package/dist/src/console/workflows.js.map +1 -0
  84. package/dist/src/documents.d.ts +2 -2
  85. package/dist/src/documents.js +1 -1
  86. package/dist/src/http.d.ts +32 -2
  87. package/dist/src/http.d.ts.map +1 -1
  88. package/dist/src/http.js +11 -2
  89. package/dist/src/http.js.map +1 -1
  90. package/dist/src/me.d.ts +2 -2
  91. package/dist/src/me.js +1 -1
  92. package/dist/src/run.d.ts +1 -1
  93. package/dist/src/types.d.ts +2 -2
  94. package/dist/src/types.d.ts.map +1 -1
  95. package/dist/src/vars.d.ts +2 -2
  96. package/dist/src/vars.js +1 -1
  97. package/dist/src/version.js +1 -1
  98. package/dist/src/workflows.d.ts +2 -2
  99. package/dist/src/workflows.js +1 -1
  100. package/package.json +5 -1
@@ -0,0 +1,199 @@
1
+ /**
2
+ * `client.console.subscriptions.*` — (trigger → workflow) bindings, relocated
3
+ * from the studio's own API client.
4
+ *
5
+ * **Studio-internal, not the published partner contract.** This namespace
6
+ * lives under the `console` subpath export (`@w6w/sdk/console`), excluded from
7
+ * `endpoints.json` and from the root barrel (`mod.ts`) — see `docs/console.md`
8
+ * and HITL-1 in this task's contract. `@w6w/sdk`'s instance-state mechanism
9
+ * pin still applies here exactly as it does to every other namespace
10
+ * (`docs/implementation.md` §MECHANISM PIN — instance state, never globals):
11
+ * this class holds no state of its own beyond the injected host, so two
12
+ * clients in one process never share a credential.
13
+ *
14
+ * Seven methods, relocated from `packages/studio/src/api/client.ts:253-286`'s
15
+ * single `// Subscriptions` comment block — field-for-field, not redesigned:
16
+ * `listSubscriptions` → `list`, `listSubscriptionsForWorkflow` →
17
+ * `listForWorkflow`, `getSubscription` → `get`, `createSubscription` →
18
+ * `create`, `deleteSubscription` → `delete`, `listSubscriptionEvents` →
19
+ * `listEvents`, `requeueTriggerEvent` → `requeueEvent`.
20
+ *
21
+ * **Four of these seven have zero callers anywhere in studio or `@w6w/ui`**
22
+ * (`listForWorkflow`, `get`, `listEvents`, `requeueEvent`) — HITL-4's pinned
23
+ * default, re-confirmed this pass. They are still built to full type
24
+ * fidelity (real implementation, JSDoc, `@throws`) for SDK/wrapper coverage;
25
+ * only the test bar for them is deliberately lighter, mirroring
26
+ * `console.apps`'s/`console.functions`' identical treatment of their own
27
+ * zero-caller methods.
28
+ *
29
+ * **`webhookUrl` is a real server-side field this module deliberately does
30
+ * NOT model.** For a subscription whose `appId === "@w6w/webhook"`, the
31
+ * server enriches the response with a `webhookUrl` field computed from a
32
+ * config value genuinely distinct from studio's own `apiBaseUrl()`
33
+ * (`internal-triggers.ts:123-127`, `config.ts:27,259`). Studio's current
34
+ * `Subscription` type never modeled this and no in-boundary code reads it
35
+ * (`SubscriptionsPage.tsx` computes its own webhook URL client-side
36
+ * independently) — this is a deliberate, verified omission, not an
37
+ * oversight: whatever extra field the server sends is silently ignored,
38
+ * exactly as today.
39
+ *
40
+ * Subscriptions are account-level, never scoped by `project` — so
41
+ * `SubscriptionsHost` needs only the transport, mirroring `VarsHost`/
42
+ * `ProjectsHost`, not `DocumentsHost`.
43
+ *
44
+ * @module
45
+ */
46
+ import { type HttpResponse, type RequestOptions } from "../http.ts";
47
+ /**
48
+ * The slice of `W6WClient` this namespace needs: the transport, and nothing
49
+ * else. Structural rather than a concrete client type, so the namespace stays
50
+ * independently constructible in a test and this module never imports the
51
+ * client back — mirrors `VarsHost` in `../vars.ts`.
52
+ */
53
+ export interface SubscriptionsHost {
54
+ /** Perform one request. */
55
+ request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
56
+ }
57
+ /**
58
+ * A (trigger → workflow) binding. Field-for-field per
59
+ * `packages/studio/src/api/types.ts:72-83` — this module does not redesign
60
+ * the shape, only gives it a second home. Deliberately does NOT carry
61
+ * `webhookUrl` — see this module's header.
62
+ */
63
+ export interface Subscription {
64
+ id: string;
65
+ appId: string;
66
+ triggerKey: string;
67
+ connectionId: string | null;
68
+ workflowId: string;
69
+ params: Record<string, unknown>;
70
+ state: Record<string, unknown>;
71
+ enabled: boolean;
72
+ createdAt: string;
73
+ updatedAt: string;
74
+ }
75
+ /**
76
+ * The body of `create`, forwarded verbatim as the whole POST body.
77
+ * Field-for-field per `packages/studio/src/api/client.ts:267-271`.
78
+ */
79
+ export interface SubscriptionCreateInput {
80
+ workflowId: string;
81
+ connectionId?: string | null;
82
+ params?: Record<string, unknown>;
83
+ }
84
+ /** The lifecycle a delivered trigger event can be in. */
85
+ export type TriggerEventStatus = "received" | "dispatching" | "dispatched" | "failed";
86
+ /**
87
+ * Metadata-only view of a delivered trigger event. Field-for-field per
88
+ * `packages/studio/src/api/types.ts:85-96`.
89
+ */
90
+ export interface TriggerEventSummary {
91
+ id: string;
92
+ subscriptionId: string;
93
+ status: TriggerEventStatus;
94
+ attempts: number;
95
+ receivedAt: string;
96
+ dispatchedAt: string | null;
97
+ runId: string | null;
98
+ }
99
+ /**
100
+ * The `console.subscriptions` namespace on a `W6WClient`.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const subs = await client.console.subscriptions.list();
105
+ * const sub = await client.console.subscriptions.create("app_x", "new-message", {
106
+ * workflowId: "wf_1",
107
+ * });
108
+ * await client.console.subscriptions.delete(sub.id);
109
+ * ```
110
+ */
111
+ export declare class SubscriptionsApi {
112
+ #private;
113
+ /**
114
+ * @param host - The client this namespace issues requests through.
115
+ */
116
+ constructor(host: SubscriptionsHost);
117
+ /**
118
+ * List every subscription the caller can see.
119
+ *
120
+ * @returns The subscriptions, unwrapped from the `subscriptions` envelope.
121
+ * @throws {ApiError} On any non-2xx.
122
+ */
123
+ list(): Promise<Subscription[]>;
124
+ /**
125
+ * List the subscriptions bound to one workflow.
126
+ *
127
+ * **Dead code (HITL-4)** — zero call sites anywhere in studio or
128
+ * `@w6w/ui`. Built for SDK completeness only; see this module's header.
129
+ *
130
+ * @param workflowId - The `wf_…` id.
131
+ * @returns The subscriptions, unwrapped from the `subscriptions` envelope.
132
+ * @throws {ApiError} On any non-2xx.
133
+ */
134
+ listForWorkflow(workflowId: string): Promise<Subscription[]>;
135
+ /**
136
+ * Fetch one subscription.
137
+ *
138
+ * **Dead code (HITL-4)** — zero call sites anywhere in studio or
139
+ * `@w6w/ui`. Built for SDK completeness only; see this module's header.
140
+ * Unlike `console.schedules.get`, this method throws `ApiError` on a 404
141
+ * rather than resolving `null` — there is no precedent on this domain to
142
+ * preserve, and this package's default `get` behavior is to throw.
143
+ *
144
+ * @param id - The `sub_…` id.
145
+ * @returns The subscription, unwrapped from the `subscription` envelope.
146
+ * @throws {ApiError} `404 unknown_subscription` when there is no such id.
147
+ */
148
+ get(id: string): Promise<Subscription>;
149
+ /**
150
+ * Bind a trigger to a workflow.
151
+ *
152
+ * @param appId - The app declaring the trigger.
153
+ * @param triggerKey - The trigger's key, as declared by the app's manifest.
154
+ * @param input - The subscription to create; forwarded verbatim as the whole body.
155
+ * @returns The created subscription, unwrapped from the `subscription` envelope (the server answers `201`).
156
+ * @throws {ApiError} `404 unknown_trigger`/`unknown_workflow` on a bad app/trigger/workflow id.
157
+ */
158
+ create(appId: string, triggerKey: string, input: SubscriptionCreateInput): Promise<Subscription>;
159
+ /**
160
+ * Remove a subscription.
161
+ *
162
+ * Returns nothing: the server's `{ok: true}` carries no information a
163
+ * caller can use, mirroring `projects.delete`/`schedules.delete`'s
164
+ * established discard-to-void convention (not `apps.delete`'s
165
+ * informative-`{removed: number}` exception).
166
+ *
167
+ * @param id - The `sub_…` id.
168
+ * @throws {ApiError} `404 unknown_subscription` when there is no such id.
169
+ */
170
+ delete(id: string): Promise<void>;
171
+ /**
172
+ * List a subscription's delivered trigger events, newest first.
173
+ *
174
+ * **Dead code (HITL-4)** — zero call sites anywhere in studio or
175
+ * `@w6w/ui`. Built for SDK completeness only; see this module's header. No
176
+ * `limit` parameter is exposed — the server applies its own default of 50
177
+ * (`trigger-manager.ts:109`) and no studio caller ever sent one.
178
+ *
179
+ * @param id - The `sub_…` id.
180
+ * @returns The events, unwrapped from the `events` envelope.
181
+ * @throws {ApiError} On any non-2xx.
182
+ */
183
+ listEvents(id: string): Promise<TriggerEventSummary[]>;
184
+ /**
185
+ * Re-queue a `failed`-status trigger event for another delivery attempt —
186
+ * a dead-letter re-dispatch.
187
+ *
188
+ * **Dead code (HITL-4)** — zero call sites anywhere in studio or
189
+ * `@w6w/ui`. Built for SDK completeness only; see this module's header.
190
+ * Returns nothing: the server's `{ok: true}` carries no information a
191
+ * caller can use, mirroring `projects.delete`/`schedules.delete`'s
192
+ * established discard-to-void convention.
193
+ *
194
+ * @param eventId - The trigger event's id.
195
+ * @throws {ApiError} `404 requeue_failed` when the event doesn't exist or isn't in `failed` status.
196
+ */
197
+ requeueEvent(eventId: string): Promise<void>;
198
+ }
199
+ //# sourceMappingURL=subscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../../src/console/subscriptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAQ,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAG1E;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,2BAA2B;IAC3B,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,C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MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvC;;;;;;;;;;;OAWG;IACG,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAQ5D;;;;;;;;;;;;OAYG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAMnD"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * `client.console.subscriptions.*` — (trigger → workflow) bindings, relocated
3
+ * from the studio's own API client.
4
+ *
5
+ * **Studio-internal, not the published partner contract.** This namespace
6
+ * lives under the `console` subpath export (`@w6w/sdk/console`), excluded from
7
+ * `endpoints.json` and from the root barrel (`mod.ts`) — see `docs/console.md`
8
+ * and HITL-1 in this task's contract. `@w6w/sdk`'s instance-state mechanism
9
+ * pin still applies here exactly as it does to every other namespace
10
+ * (`docs/implementation.md` §MECHANISM PIN — instance state, never globals):
11
+ * this class holds no state of its own beyond the injected host, so two
12
+ * clients in one process never share a credential.
13
+ *
14
+ * Seven methods, relocated from `packages/studio/src/api/client.ts:253-286`'s
15
+ * single `// Subscriptions` comment block — field-for-field, not redesigned:
16
+ * `listSubscriptions` → `list`, `listSubscriptionsForWorkflow` →
17
+ * `listForWorkflow`, `getSubscription` → `get`, `createSubscription` →
18
+ * `create`, `deleteSubscription` → `delete`, `listSubscriptionEvents` →
19
+ * `listEvents`, `requeueTriggerEvent` → `requeueEvent`.
20
+ *
21
+ * **Four of these seven have zero callers anywhere in studio or `@w6w/ui`**
22
+ * (`listForWorkflow`, `get`, `listEvents`, `requeueEvent`) — HITL-4's pinned
23
+ * default, re-confirmed this pass. They are still built to full type
24
+ * fidelity (real implementation, JSDoc, `@throws`) for SDK/wrapper coverage;
25
+ * only the test bar for them is deliberately lighter, mirroring
26
+ * `console.apps`'s/`console.functions`' identical treatment of their own
27
+ * zero-caller methods.
28
+ *
29
+ * **`webhookUrl` is a real server-side field this module deliberately does
30
+ * NOT model.** For a subscription whose `appId === "@w6w/webhook"`, the
31
+ * server enriches the response with a `webhookUrl` field computed from a
32
+ * config value genuinely distinct from studio's own `apiBaseUrl()`
33
+ * (`internal-triggers.ts:123-127`, `config.ts:27,259`). Studio's current
34
+ * `Subscription` type never modeled this and no in-boundary code reads it
35
+ * (`SubscriptionsPage.tsx` computes its own webhook URL client-side
36
+ * independently) — this is a deliberate, verified omission, not an
37
+ * oversight: whatever extra field the server sends is silently ignored,
38
+ * exactly as today.
39
+ *
40
+ * Subscriptions are account-level, never scoped by `project` — so
41
+ * `SubscriptionsHost` needs only the transport, mirroring `VarsHost`/
42
+ * `ProjectsHost`, not `DocumentsHost`.
43
+ *
44
+ * @module
45
+ */
46
+ import { path } from "../http.js";
47
+ import { unwrap } from "../types.js";
48
+ /**
49
+ * The `console.subscriptions` namespace on a `W6WClient`.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const subs = await client.console.subscriptions.list();
54
+ * const sub = await client.console.subscriptions.create("app_x", "new-message", {
55
+ * workflowId: "wf_1",
56
+ * });
57
+ * await client.console.subscriptions.delete(sub.id);
58
+ * ```
59
+ */
60
+ export class SubscriptionsApi {
61
+ #host;
62
+ /**
63
+ * @param host - The client this namespace issues requests through.
64
+ */
65
+ constructor(host) {
66
+ this.#host = host;
67
+ }
68
+ /**
69
+ * List every subscription the caller can see.
70
+ *
71
+ * @returns The subscriptions, unwrapped from the `subscriptions` envelope.
72
+ * @throws {ApiError} On any non-2xx.
73
+ */
74
+ async list() {
75
+ const res = await this.#host.request({
76
+ method: "GET",
77
+ path: "/subscriptions",
78
+ });
79
+ return unwrap(res, "subscriptions");
80
+ }
81
+ /**
82
+ * List the subscriptions bound to one workflow.
83
+ *
84
+ * **Dead code (HITL-4)** — zero call sites anywhere in studio or
85
+ * `@w6w/ui`. Built for SDK completeness only; see this module's header.
86
+ *
87
+ * @param workflowId - The `wf_…` id.
88
+ * @returns The subscriptions, unwrapped from the `subscriptions` envelope.
89
+ * @throws {ApiError} On any non-2xx.
90
+ */
91
+ async listForWorkflow(workflowId) {
92
+ const res = await this.#host.request({
93
+ method: "GET",
94
+ path: path `/workflows/${workflowId}/subscriptions`,
95
+ });
96
+ return unwrap(res, "subscriptions");
97
+ }
98
+ /**
99
+ * Fetch one subscription.
100
+ *
101
+ * **Dead code (HITL-4)** — zero call sites anywhere in studio or
102
+ * `@w6w/ui`. Built for SDK completeness only; see this module's header.
103
+ * Unlike `console.schedules.get`, this method throws `ApiError` on a 404
104
+ * rather than resolving `null` — there is no precedent on this domain to
105
+ * preserve, and this package's default `get` behavior is to throw.
106
+ *
107
+ * @param id - The `sub_…` id.
108
+ * @returns The subscription, unwrapped from the `subscription` envelope.
109
+ * @throws {ApiError} `404 unknown_subscription` when there is no such id.
110
+ */
111
+ async get(id) {
112
+ const res = await this.#host.request({
113
+ method: "GET",
114
+ path: path `/subscriptions/${id}`,
115
+ });
116
+ return unwrap(res, "subscription");
117
+ }
118
+ /**
119
+ * Bind a trigger to a workflow.
120
+ *
121
+ * @param appId - The app declaring the trigger.
122
+ * @param triggerKey - The trigger's key, as declared by the app's manifest.
123
+ * @param input - The subscription to create; forwarded verbatim as the whole body.
124
+ * @returns The created subscription, unwrapped from the `subscription` envelope (the server answers `201`).
125
+ * @throws {ApiError} `404 unknown_trigger`/`unknown_workflow` on a bad app/trigger/workflow id.
126
+ */
127
+ async create(appId, triggerKey, input) {
128
+ const res = await this.#host.request({
129
+ method: "POST",
130
+ path: path `/apps/${appId}/triggers/${triggerKey}/subscriptions`,
131
+ body: input,
132
+ });
133
+ return unwrap(res, "subscription");
134
+ }
135
+ /**
136
+ * Remove a subscription.
137
+ *
138
+ * Returns nothing: the server's `{ok: true}` carries no information a
139
+ * caller can use, mirroring `projects.delete`/`schedules.delete`'s
140
+ * established discard-to-void convention (not `apps.delete`'s
141
+ * informative-`{removed: number}` exception).
142
+ *
143
+ * @param id - The `sub_…` id.
144
+ * @throws {ApiError} `404 unknown_subscription` when there is no such id.
145
+ */
146
+ async delete(id) {
147
+ await this.#host.request({
148
+ method: "DELETE",
149
+ path: path `/subscriptions/${id}`,
150
+ });
151
+ }
152
+ /**
153
+ * List a subscription's delivered trigger events, newest first.
154
+ *
155
+ * **Dead code (HITL-4)** — zero call sites anywhere in studio or
156
+ * `@w6w/ui`. Built for SDK completeness only; see this module's header. No
157
+ * `limit` parameter is exposed — the server applies its own default of 50
158
+ * (`trigger-manager.ts:109`) and no studio caller ever sent one.
159
+ *
160
+ * @param id - The `sub_…` id.
161
+ * @returns The events, unwrapped from the `events` envelope.
162
+ * @throws {ApiError} On any non-2xx.
163
+ */
164
+ async listEvents(id) {
165
+ const res = await this.#host.request({
166
+ method: "GET",
167
+ path: path `/subscriptions/${id}/events`,
168
+ });
169
+ return unwrap(res, "events");
170
+ }
171
+ /**
172
+ * Re-queue a `failed`-status trigger event for another delivery attempt —
173
+ * a dead-letter re-dispatch.
174
+ *
175
+ * **Dead code (HITL-4)** — zero call sites anywhere in studio or
176
+ * `@w6w/ui`. Built for SDK completeness only; see this module's header.
177
+ * Returns nothing: the server's `{ok: true}` carries no information a
178
+ * caller can use, mirroring `projects.delete`/`schedules.delete`'s
179
+ * established discard-to-void convention.
180
+ *
181
+ * @param eventId - The trigger event's id.
182
+ * @throws {ApiError} `404 requeue_failed` when the event doesn't exist or isn't in `failed` status.
183
+ */
184
+ async requeueEvent(eventId) {
185
+ await this.#host.request({
186
+ method: "POST",
187
+ path: path `/trigger-events/${eventId}/requeue`,
188
+ });
189
+ }
190
+ }
191
+ //# sourceMappingURL=subscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../../src/console/subscriptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,EAAqB,IAAI,EAAuB,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA2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H,OAAO,MAAM,CAAe,GAAG,EAAE,cAAc,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU;YAChC,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,IAAI,CAAA,kBAAkB,EAAE,EAAE;SACjC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU;YAC5C,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI,CAAA,kBAAkB,EAAE,SAAS;SACxC,CAAC,CAAC;QACH,OAAO,MAAM,CAAwB,GAAG,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe;QAChC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAU;YAChC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAA,mBAAmB,OAAO,UAAU;SAC/C,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,188 @@
1
+ /**
2
+ * `client.console.tenantOAuthApps.*` — a tenant administrator's own OAuth
3
+ * client overrides (list, upsert, remove) for the apps their tenant connects
4
+ * to.
5
+ *
6
+ * **Studio-internal, not the published partner contract.** This namespace
7
+ * lives under the `console` subpath export (`@w6w/sdk/console`), excluded from
8
+ * `endpoints.json` and from the root barrel (`mod.ts`) — see `docs/console.md`.
9
+ * `@w6w/sdk`'s instance-state mechanism pin still applies here exactly as it
10
+ * does to every other namespace (`docs/implementation.md` §MECHANISM PIN —
11
+ * instance state, never globals): this class holds no state of its own beyond
12
+ * the injected host, so two clients in one process never share a credential.
13
+ *
14
+ * **The tenant is never a parameter here.** These three routes are scoped by
15
+ * the caller's own credential (the tenant claim on the bearer) plus a
16
+ * server-side tenant-admin check — unlike the operator family
17
+ * (`GET/PUT/DELETE /tenants/:id/oauth-app…`, `api/admin/tenants.ts:307-309`),
18
+ * which takes the tenant in the path and requires an operator. A `tenant`
19
+ * argument on any method below would be a tenant-selection affordance the
20
+ * server does not offer, so there is none.
21
+ *
22
+ * **Nothing here can read a client secret back.** {@linkcode
23
+ * TenantOAuthAppSummary} carries `hasClientSecret: boolean` and no secret
24
+ * field, mirroring the server's own summary projection
25
+ * (`packages/server/packages/db/repos/tenant_oauth_app.ts:26-37`, whose
26
+ * decrypting sibling `TenantOAuthApp` is entitled to exactly one caller in the
27
+ * BLL). That makes "no method on this namespace can ever resolve a stored
28
+ * secret" a compile-time fact rather than a runtime convention.
29
+ *
30
+ * **Response shapes are flat, no envelope key to peel with `unwrap()`** —
31
+ * mirroring `console/auth.ts:29-32` for this whole family. `list` returns the
32
+ * whole body deliberately, because `callbackUrl` rides beside `configs` and an
33
+ * `unwrap(res, "configs")` would silently drop it; `put` reaches one level in
34
+ * for `body.config`, which is the shape the server answers with (W4).
35
+ *
36
+ * **Wire shapes are planner pins, not reverse-engineered from a merged route.**
37
+ * `plan-B.md` § WIRE PINS W3–W5 fix `GET /tenant/oauth-apps`,
38
+ * `PUT /tenant/oauth-app/:app/:authKey` and
39
+ * `DELETE /tenant/oauth-app/:app/:authKey`; the tenant-scoped handlers are
40
+ * added by a sibling node on the server, against the same pins. The domain
41
+ * rules those handlers enforce already exist and are readable today in
42
+ * `packages/server/packages/bll/tenant-oauth-app.ts` — in particular
43
+ * `effectiveRow` (`:281-296`), which is what makes {@linkcode
44
+ * SetTenantOAuthAppInput}'s omission rule load-bearing rather than cosmetic.
45
+ * See {@linkcode SetTenantOAuthAppInput}.
46
+ *
47
+ * @module
48
+ */
49
+ import { type HttpResponse, type RequestOptions } from "../http.ts";
50
+ /**
51
+ * The slice of `W6WClient` this namespace needs: the transport, and nothing
52
+ * else. Structural rather than a concrete client type, so the namespace stays
53
+ * independently constructible in a test and this module never imports the
54
+ * client back — mirrors `AuthHost` in `./auth.ts`.
55
+ */
56
+ export interface TenantOAuthAppsHost {
57
+ /** Perform one request. */
58
+ request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
59
+ }
60
+ /**
61
+ * One tenant OAuth client override, as the tenant-scoped routes project it
62
+ * (W3/W4). A summary only: it names whether a secret is stored, never the
63
+ * secret — the server's own summary row has no `clientSecret` column on it
64
+ * either (`db/repos/tenant_oauth_app.ts:26-37`).
65
+ */
66
+ export interface TenantOAuthAppSummary {
67
+ /** The app this override applies to. */
68
+ appId: string;
69
+ /** The app manifest's `oauth2` auth method key. */
70
+ authKey: string;
71
+ /** The tenant's OAuth client id, or `null` when never set / cleared. */
72
+ clientId: string | null;
73
+ /**
74
+ * The redirect URI registered with the provider, as stored **server-side**.
75
+ * Read-only here: it is derived by the server, never sent by this client —
76
+ * {@linkcode SetTenantOAuthAppInput} carries no `redirectUri` key.
77
+ */
78
+ redirectUri: string | null;
79
+ /** Provider-specific extras (scopes, audience, …). `{}` when none. */
80
+ extra: Record<string, unknown>;
81
+ /** Whether a client secret is stored. **Never the secret itself.** */
82
+ hasClientSecret: boolean;
83
+ /** Whether the override is switched off (the host's own client is used instead). */
84
+ disabled: boolean;
85
+ }
86
+ /** `GET /tenant/oauth-apps` → 200 (W3). */
87
+ export interface TenantOAuthAppsResponse {
88
+ /** Every override this tenant has, in the server's order. */
89
+ configs: TenantOAuthAppSummary[];
90
+ /** This host's OAuth callback, derived SERVER-SIDE. Display it; never assemble it. */
91
+ callbackUrl: string;
92
+ }
93
+ /**
94
+ * The body `put` sends (W4) — **built by OMISSION, key by key.**
95
+ *
96
+ * Every field is optional and every one of them means "set this field to this
97
+ * value", including `null`, which means "clear it". Absence means "leave
98
+ * whatever is stored alone": the server merges the request over the stored row
99
+ * (`bll/tenant-oauth-app.ts:281-296`'s `effectiveRow`, which tests each field
100
+ * with `!== undefined`), so a key that is not sent is a key that is not
101
+ * touched.
102
+ *
103
+ * **Sending a key you did not mean to set is destructive, and one of them is
104
+ * destructive SILENTLY.** `hasClientSecret` is computed as
105
+ * `input.clientSecret !== null` (`:291-293`), so an empty-string
106
+ * `clientSecret: ""` satisfies the enabled-override invariant at `:332` and the
107
+ * stored ciphertext is overwritten with an empty secret — no error anywhere.
108
+ * The neighbouring fields fail loudly instead (`clientId: ""` at `:324`,
109
+ * `redirectUri` at `:313-322`). That asymmetry is the entire reason this type
110
+ * has no required field and this module builds the body key by key: omit what
111
+ * the user did not touch, never send `""`.
112
+ *
113
+ * **No `redirectUri` and no `force`.** Neither exists on this surface — the
114
+ * callback URL is derived server-side (W3's `callbackUrl`) and the operator's
115
+ * `?force` affordance is not offered to a tenant admin (W4). A field the SDK
116
+ * declares is a field a form will fill, so neither is declared, and
117
+ * {@linkcode toSetBody} additionally refuses to forward either at runtime.
118
+ */
119
+ export interface SetTenantOAuthAppInput {
120
+ /** The OAuth client id. `null` clears it. */
121
+ clientId?: string | null;
122
+ /**
123
+ * The OAuth client secret, write-only. `null` clears it. Sending `""` IS
124
+ * carried to the wire and IS destructive (silently overwrites the stored
125
+ * secret) — omit this key instead of sending `""` when not changing it.
126
+ */
127
+ clientSecret?: string | null;
128
+ /** Provider-specific extras. `null` clears them to `{}`. */
129
+ extra?: Record<string, unknown> | null;
130
+ /** Whether to switch the override off. */
131
+ disabled?: boolean;
132
+ }
133
+ /**
134
+ * The `console.tenantOAuthApps` namespace on a `W6WClient` — the caller's own
135
+ * tenant, never a tenant of its choosing.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * const { configs, callbackUrl } = await client.console.tenantOAuthApps.list();
140
+ * // Register `callbackUrl` with the provider — never assemble it client-side.
141
+ * await client.console.tenantOAuthApps.put("sendgrid", "oauth2", { clientId: "abc" });
142
+ * await client.console.tenantOAuthApps.remove("sendgrid", "oauth2");
143
+ * ```
144
+ */
145
+ export declare class TenantOAuthAppsApi {
146
+ #private;
147
+ /**
148
+ * @param host - The client this namespace issues requests through.
149
+ */
150
+ constructor(host: TenantOAuthAppsHost);
151
+ /**
152
+ * List the caller's tenant's OAuth overrides, plus this host's callback URL.
153
+ *
154
+ * Returns the body VERBATIM rather than unwrapping `configs`: `callbackUrl`
155
+ * rides beside it and is the one value a caller cannot compute for itself.
156
+ *
157
+ * @returns Every override for this tenant, and the server-derived callback URL.
158
+ * @throws {ApiError} `403` when the caller does not administer its tenant.
159
+ */
160
+ list(): Promise<TenantOAuthAppsResponse>;
161
+ /**
162
+ * Create or update one override, sending **only the fields `input` sets**.
163
+ *
164
+ * @param appId - The app id.
165
+ * @param authKey - The app manifest's `oauth2` auth method key.
166
+ * @param input - The fields to set; an omitted field is left untouched server-side.
167
+ * @returns The stored summary (the server answers `201 { config }`). Never carries a secret.
168
+ * @throws {ApiError} `403` when the caller does not administer its tenant;
169
+ * `404 unknown_app` when the app does not exist or does not support a tenant
170
+ * OAuth client; `400 invalid_config`/`invalid_redirect_uri` when the merged
171
+ * row would be an enabled override missing a required field.
172
+ */
173
+ put(appId: string, authKey: string, input: SetTenantOAuthAppInput): Promise<TenantOAuthAppSummary>;
174
+ /**
175
+ * Remove one override; the tenant falls back to the host's own OAuth client.
176
+ *
177
+ * Resolves `void`, discarding the server's uninformative `{ok: true}` —
178
+ * mirroring `projects.delete`/`schedules.delete`, not `apps.delete` (which
179
+ * keeps a genuinely informative count).
180
+ *
181
+ * @param appId - The app id.
182
+ * @param authKey - The app manifest's `oauth2` auth method key.
183
+ * @throws {ApiError} `403` when the caller does not administer its tenant;
184
+ * `404 unknown_tenant_oauth_app` when there is no override to remove.
185
+ */
186
+ remove(appId: string, authKey: string): Promise<void>;
187
+ }
188
+ //# sourceMappingURL=tenant-oauth-apps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant-oauth-apps.d.ts","sourceRoot":"","sources":["../../../src/console/tenant-oauth-apps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;A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