@productcraft/platform-auth 0.1.3 → 1.0.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.
package/dist/index.cjs CHANGED
@@ -1,16 +1,1818 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var core = require('@productcraft/core');
4
6
 
5
- // src/index.ts
6
- var PlatformAuth = class {
7
- /** The underlying typed client. v0 surface — every endpoint reachable. */
8
- client;
9
- constructor(config = {}) {
10
- this.client = core.makeClient(core.PC_BASE_URL.platformAuth, config);
7
+ // src/_generated/client.ts
8
+
9
+ // src/_generated/resources.ts
10
+ function fillActor(params, bound) {
11
+ if (bound.actor_id === void 0) return params;
12
+ const p = params ?? {};
13
+ return p.actor_id === void 0 ? { ...p, actor_id: bound.actor_id } : p;
14
+ }
15
+ function formData(fields) {
16
+ const form = new FormData();
17
+ for (const [k, v] of Object.entries(fields ?? {})) {
18
+ if (v === void 0 || v === null) continue;
19
+ if (v instanceof Blob) form.append(k, v);
20
+ else form.append(k, typeof v === "object" ? JSON.stringify(v) : String(v));
21
+ }
22
+ return form;
23
+ }
24
+ var APIResource = class {
25
+ _client;
26
+ /** Path parameters (and `actor_id`) bound by the enclosing scope. */
27
+ _b;
28
+ constructor(client, bound = {}) {
29
+ this._client = client;
30
+ this._b = bound;
31
+ }
32
+ };
33
+ var AccountResource = class extends APIResource {
34
+ /**
35
+ * Delete the calling account. Auto-promotes the oldest admin (or oldest non-self member) to owner in any workspace where the departing account is the sole owner. Linked provider grants that require server-side revocation (Sign in with Apple) are revoked with the provider.
36
+ *
37
+ * @param options - Per-request options.
38
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
39
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: The session lacks the required action for self-account deletion (defence-in-depth — the route is guarded but the cookie may be present without action access).
40
+ * @throws {NotFoundError} 404 NOT_FOUND: No account row exists for the session principal. Should never fire for a valid session — surfaced for SDKs.
41
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
42
+ * @see DELETE /v1/account
43
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-account
44
+ * @example
45
+ * ```ts
46
+ * await platform.account.erase();
47
+ * ```
48
+ */
49
+ erase(options) {
50
+ return this._client.request({ method: "DELETE", path: "/v1/account" }, options);
51
+ }
52
+ };
53
+ var ApiKeysResource = class extends APIResource {
54
+ /**
55
+ * Describe the workspace key making this request: its name, workspace, expiry and what it may do in plain sentences. Call it with `Authorization: Bearer pcft_live_…` to test a key right after minting it.
56
+ *
57
+ * @param options - Per-request options.
58
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No bearer, or the key is unknown, revoked or expired.
59
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, WORKSPACE_KEY_REQUIRED: Signed in with a session or another token instead of a workspace key (`WORKSPACE_KEY_REQUIRED`). Send the `pcft_live_…` key as the bearer.
60
+ * @throws {NotFoundError} 404 NOT_FOUND, PAK_NOT_FOUND: The key was deleted while the request was in flight (`PAK_NOT_FOUND`).
61
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
62
+ * @see GET /v1/api-keys/self
63
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-api-keys-self
64
+ * @example
65
+ * ```ts
66
+ * const apiKeySelf = await platform.apiKeys.self();
67
+ * ```
68
+ */
69
+ self(options) {
70
+ return this._client.request({ method: "GET", path: "/v1/api-keys/self" }, options);
71
+ }
72
+ };
73
+ var AuthPasswordResource = class extends APIResource {
74
+ /**
75
+ * Request a password reset email. Neither the response nor its timing reveals whether the email matched an account.
76
+ *
77
+ * @param params - `PlatformAuth.AuthPasswordRequestResetParams`.
78
+ * @param options - Per-request options.
79
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Body failed validation (`email` missing or not an email address). Depends only on the request shape, never on whether an account exists.
80
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: more than 10 requests/min from this IP (strict `auth` bucket). `Retry-After` header set. Per-IP limit: rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
81
+ * @see POST /v1/auth/password/request-reset
82
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-auth-password-request-reset
83
+ * @example
84
+ * ```ts
85
+ * await platform.auth.password.requestReset({ email: "user@example.com" });
86
+ * ```
87
+ */
88
+ requestReset(params, options) {
89
+ return this._client.request({ method: "POST", path: "/v1/auth/password/request-reset", body: params, public: true }, options);
90
+ }
91
+ /**
92
+ * Reset password using the email-delivered reset token.
93
+ *
94
+ * @param params - `PlatformAuth.AuthPasswordResetParams`.
95
+ * @param options - Per-request options.
96
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR, PASSWORD_RESET_INVALID: Body failed validation, the new password fails the password policy, or the reset token is invalid or expired (`PASSWORD_RESET_INVALID`).
97
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: more than 10 requests/min from this IP (strict `auth` bucket). `Retry-After` header set. Per-IP limit: rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
98
+ * @see POST /v1/auth/password/reset
99
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-auth-password-reset
100
+ * @example
101
+ * ```ts
102
+ * await platform.auth.password.reset({ new_password: "MyNewPassword123", token: "123456" });
103
+ * ```
104
+ */
105
+ reset(params, options) {
106
+ return this._client.request({ method: "POST", path: "/v1/auth/password/reset", body: params, public: true }, options);
107
+ }
108
+ };
109
+ var AuthResource = class extends APIResource {
110
+ #password;
111
+ get password() {
112
+ return this.#password ??= new AuthPasswordResource(this._client, this._b);
113
+ }
114
+ /**
115
+ * Logout by revoking refresh token
116
+ *
117
+ * @param params - `PlatformAuth.AuthLogoutParams`.
118
+ * @param options - Per-request options.
119
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Validation failed or invalid token
120
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
121
+ * @see POST /v1/auth/logout
122
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-auth-logout
123
+ * @example
124
+ * ```ts
125
+ * await platform.auth.logout({ refresh_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." });
126
+ * ```
127
+ */
128
+ logout(params, options) {
129
+ return this._client.request({ method: "POST", path: "/v1/auth/logout", body: params, public: true }, options);
130
+ }
131
+ /**
132
+ * Revoke the server-side session tied to the caller’s current access token
133
+ *
134
+ * @param options - Per-request options.
135
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing or invalid access token
136
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
137
+ * @see POST /v1/auth/logout-current
138
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-auth-logout-current
139
+ * @example
140
+ * ```ts
141
+ * await platform.auth.logoutCurrent();
142
+ * ```
143
+ */
144
+ logoutCurrent(options) {
145
+ return this._client.request({ method: "POST", path: "/v1/auth/logout-current" }, options);
146
+ }
147
+ /**
148
+ * Refresh access token using refresh token
149
+ *
150
+ * @param params - `PlatformAuth.AuthRefreshParams`.
151
+ * @param options - Per-request options.
152
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Validation failed or invalid token
153
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
154
+ * @see POST /v1/auth/refresh
155
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-auth-refresh
156
+ * @example
157
+ * ```ts
158
+ * const token = await platform.auth.refresh({ refresh_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." });
159
+ * ```
160
+ */
161
+ refresh(params, options) {
162
+ return this._client.request({ method: "POST", path: "/v1/auth/refresh", body: params, public: true }, options);
163
+ }
164
+ /**
165
+ * Sign in with email/username and password
166
+ *
167
+ * Every failed attempt answers `401 INVALID_CREDENTIALS`, whatever went wrong: unknown identifier, wrong password, an account with no password credential, an account locked out through a different identifier, an account an operator has blocked, and a wrong password against a suspended or deactivated account. The responses are deliberately identical in body, timing, DB round trips and Redis ops, so signin is not an account-existence oracle. See core/block/CLAUDE.md.
168
+ *
169
+ * @param params - `PlatformAuth.AuthSigninParams`.
170
+ * @param options - Per-request options.
171
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Validation failed
172
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, INVALID_CREDENTIALS: Invalid credentials (`INVALID_CREDENTIALS`). Returned for every failed attempt, including a correct password offered while the account is locked out or blocked, and a wrong password against a suspended or deactivated account. The body never says which.
173
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, ACCOUNT_SUSPENDED, ACCOUNT_DEACTIVATED: The account is suspended (`ACCOUNT_SUSPENDED`) or deactivated (`ACCOUNT_DEACTIVATED`). Only reachable once the caller has proven the password — a wrong password against such an account is a 401.
174
+ * @throws {RateLimitError} 429 RATE_LIMITED, TOO_MANY_ATTEMPTS: Too many attempts for this identifier (`TOO_MANY_ATTEMPTS`). Two counters produce it, both keyed purely by the submitted identifier: a burst limit of 5 attempts per minute, and a 15-minute lock after 4 failed attempts. Both fire on the same attempt for a registered and an unregistered identifier. Per-IP limit: rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
175
+ * @see POST /v1/auth/signin
176
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-auth-signin
177
+ * @example
178
+ * ```ts
179
+ * const token = await platform.auth.signin({ identifier: "user@example.com", password: "MySecurePassword123" });
180
+ * ```
181
+ */
182
+ signin(params, options) {
183
+ return this._client.request({ method: "POST", path: "/v1/auth/signin", body: params, public: true }, options);
184
+ }
185
+ /**
186
+ * Create a new account and sign in
187
+ *
188
+ * @param params - `PlatformAuth.AuthSignupParams`.
189
+ * @param options - Per-request options.
190
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Validation failed
191
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
192
+ * @see POST /v1/auth/signup
193
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-auth-signup
194
+ * @example
195
+ * ```ts
196
+ * const token = await platform.auth.signup({ email: "user@example.com", password: "MySecurePassword123", username: "john_doe" });
197
+ * ```
198
+ */
199
+ signup(params, options) {
200
+ return this._client.request({ method: "POST", path: "/v1/auth/signup", body: params, public: true }, options);
201
+ }
202
+ };
203
+ var IntrospectWorkspacesResource = class extends APIResource {
204
+ /**
205
+ * Introspect caller's membership + effective policy + enabled services in a workspace
206
+ *
207
+ * @param workspaceId - Id of the workspace.
208
+ * @param options - Per-request options.
209
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session. Also a session that has been signed out (`SESSION_REVOKED`).
210
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id). Known workspaces the caller is not a member of answer 200 with `is_member: false`.
211
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
212
+ * @see GET /v1/introspect/workspaces/{workspace_id}
213
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-introspect-workspaces-workspace-id
214
+ * @example
215
+ * ```ts
216
+ * const introspectWorkspace = await platform.introspect.workspaces.retrieve("workspace");
217
+ * ```
218
+ */
219
+ retrieve(workspaceId, options) {
220
+ return this._client.request({ method: "GET", path: "/v1/introspect/workspaces/{workspace_id}", pathParams: { workspace_id: workspaceId } }, options);
221
+ }
222
+ };
223
+ var IntrospectResource = class extends APIResource {
224
+ #workspaces;
225
+ get workspaces() {
226
+ return this.#workspaces ??= new IntrospectWorkspacesResource(this._client, this._b);
227
+ }
228
+ /**
229
+ * Resolve a Platform API Key (PAK) to its workspace + IAM-style policy. Downstream services use this with a 60s LRU cache and evaluate the policy via @repo/authz-nestjs evaluatePolicy().
230
+ *
231
+ * @param options - Per-request options.
232
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing or malformed `Authorization: Bearer` header, or the PAK is unknown, revoked or expired.
233
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
234
+ * @see POST /v1/introspect/api-key
235
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-introspect-api-key
236
+ * @example
237
+ * ```ts
238
+ * const introspectApiKey = await platform.introspect.apiKey();
239
+ * ```
240
+ */
241
+ apiKey(options) {
242
+ return this._client.request({ method: "POST", path: "/v1/introspect/api-key" }, options);
243
+ }
244
+ /**
245
+ * Introspect current user with workspace list
246
+ *
247
+ * @param options - Per-request options.
248
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: more than 60 requests/min from this IP (default bucket). Anonymous callers, and callers whose session has been signed out, otherwise get 200 with `is_authenticated: false`, never 401. Per-IP limit: rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
249
+ * @see GET /v1/introspect
250
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-introspect
251
+ * @example
252
+ * ```ts
253
+ * const introspect = await platform.introspect.retrieve();
254
+ * ```
255
+ */
256
+ retrieve(options) {
257
+ return this._client.request({ method: "GET", path: "/v1/introspect" }, options);
258
+ }
259
+ };
260
+ var MeAvatarResource = class extends APIResource {
261
+ /**
262
+ * Clear the caller's avatar and delete the stored object.
263
+ *
264
+ * @param options - Per-request options.
265
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No session.
266
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
267
+ * @see DELETE /v1/me/avatar
268
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-me-avatar
269
+ * @example
270
+ * ```ts
271
+ * await platform.me.avatar.clear();
272
+ * ```
273
+ */
274
+ clear(options) {
275
+ return this._client.request({ method: "DELETE", path: "/v1/me/avatar" }, options);
276
+ }
277
+ /**
278
+ * Upload (or replace) the caller's avatar. PNG/JPEG/WEBP only — SVG is rejected because user-uploaded SVG from a productcraft.co origin is a stored-XSS vector. ≤2 MB. Magic bytes are sniffed; a mislabeled file is rejected.
279
+ *
280
+ * @param params - `PlatformAuth.MeAvatarUploadParams`.
281
+ * @param options - Per-request options.
282
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Invalid file: wrong mimetype, oversized, or content does not match the declared type.
283
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No session.
284
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
285
+ * @see POST /v1/me/avatar
286
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-me-avatar
287
+ * @example
288
+ * ```ts
289
+ * const avatarUrl = await platform.me.avatar.upload({ file: new File(["…"], "image.png", { type: "image/png" }) });
290
+ * ```
291
+ */
292
+ upload(params, options) {
293
+ return this._client.request({ method: "POST", path: "/v1/me/avatar", body: formData(params) }, options);
294
+ }
295
+ };
296
+ var MeHiddenGuidesResource = class extends APIResource {
297
+ /**
298
+ * Hide a getting-started guide for the caller.
299
+ *
300
+ * Idempotent: hiding a guide that is already hidden returns it unchanged, with its first `hidden_at`. At most 200 are kept; hiding one more drops the oldest.
301
+ *
302
+ * @param key - The guide: a surface name, optionally followed by `:` and a resource id, e.g. `dashboard:<workspace id>` or `all`.
303
+ * @param options - Per-request options.
304
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: The key is not a valid guide key.
305
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No session.
306
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: The caller authenticated with a non-human principal (e.g. a workspace API key). Hidden guides are a person's console preference.
307
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
308
+ * @see PUT /v1/me/hidden-guides/{key}
309
+ * @see https://productcraft.co/docs/platform/api-reference#put-v1-me-hidden-guides-key
310
+ * @example
311
+ * ```ts
312
+ * const hiddenGuide = await platform.me.hiddenGuides.hide("key");
313
+ * ```
314
+ */
315
+ hide(key, options) {
316
+ return this._client.request({ method: "PUT", path: "/v1/me/hidden-guides/{key}", pathParams: { key } }, options);
317
+ }
318
+ /**
319
+ * List the getting-started guides the caller has hidden.
320
+ *
321
+ * Every guide the caller has hidden in the console, newest first. Hiding is presentation only: the setup status behind a guide is unchanged.
322
+ *
323
+ * @param options - Per-request options.
324
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No session.
325
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: The caller authenticated with a non-human principal (e.g. a workspace API key). Hidden guides are a person's console preference.
326
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
327
+ * @see GET /v1/me/hidden-guides
328
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-me-hidden-guides
329
+ * @example
330
+ * ```ts
331
+ * const hiddenGuides = await platform.me.hiddenGuides.list();
332
+ * ```
333
+ */
334
+ list(options) {
335
+ return this._client.request({ method: "GET", path: "/v1/me/hidden-guides" }, options);
336
+ }
337
+ /**
338
+ * Show every getting-started guide again.
339
+ *
340
+ * Removes every hidden guide for the caller, `all` included. Idempotent.
341
+ *
342
+ * @param options - Per-request options.
343
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No session.
344
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: The caller authenticated with a non-human principal (e.g. a workspace API key). Hidden guides are a person's console preference.
345
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
346
+ * @see DELETE /v1/me/hidden-guides
347
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-me-hidden-guides
348
+ * @example
349
+ * ```ts
350
+ * await platform.me.hiddenGuides.reset();
351
+ * ```
352
+ */
353
+ reset(options) {
354
+ return this._client.request({ method: "DELETE", path: "/v1/me/hidden-guides" }, options);
355
+ }
356
+ /**
357
+ * Show a hidden getting-started guide again.
358
+ *
359
+ * Idempotent: showing a guide that is not hidden is a no-op.
360
+ *
361
+ * @param key - The guide: a surface name, optionally followed by `:` and a resource id, e.g. `dashboard:<workspace id>` or `all`.
362
+ * @param options - Per-request options.
363
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: The key is not a valid guide key.
364
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No session.
365
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: The caller authenticated with a non-human principal (e.g. a workspace API key). Hidden guides are a person's console preference.
366
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
367
+ * @see DELETE /v1/me/hidden-guides/{key}
368
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-me-hidden-guides-key
369
+ * @example
370
+ * ```ts
371
+ * await platform.me.hiddenGuides.unhide("key");
372
+ * ```
373
+ */
374
+ unhide(key, options) {
375
+ return this._client.request({ method: "DELETE", path: "/v1/me/hidden-guides/{key}", pathParams: { key } }, options);
376
+ }
377
+ };
378
+ var MeProfileResource = class extends APIResource {
379
+ /**
380
+ * Update the caller's profile. Currently only `displayName` is editable. An empty body is a no-op that returns the current profile. Cookie/JWT only — this is a human-self-service surface, not a PAK-mutation surface.
381
+ *
382
+ * @param params - `PlatformAuth.MeProfileUpdateParams`.
383
+ * @param options - Per-request options.
384
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Validation failed (e.g. displayName outside 1-128 chars).
385
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No session.
386
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: The caller authenticated with a non-human principal (e.g. PAK). Profile is per-human; only the human owner can mutate their own row.
387
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
388
+ * @see PATCH /v1/me/profile
389
+ * @see https://productcraft.co/docs/platform/api-reference#patch-v1-me-profile
390
+ * @example
391
+ * ```ts
392
+ * const meProfile = await platform.me.profile.update({ display_name: "string" });
393
+ * ```
394
+ */
395
+ update(params, options) {
396
+ return this._client.request({ method: "PATCH", path: "/v1/me/profile", body: params }, options);
397
+ }
398
+ };
399
+ var MeResource = class extends APIResource {
400
+ #avatar;
401
+ #hiddenGuides;
402
+ #profile;
403
+ get avatar() {
404
+ return this.#avatar ??= new MeAvatarResource(this._client, this._b);
405
+ }
406
+ get hiddenGuides() {
407
+ return this.#hiddenGuides ??= new MeHiddenGuidesResource(this._client, this._b);
408
+ }
409
+ get profile() {
410
+ return this.#profile ??= new MeProfileResource(this._client, this._b);
411
+ }
412
+ /**
413
+ * Read the caller's account profile.
414
+ *
415
+ * @param options - Per-request options.
416
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: No session.
417
+ * @throws {NotFoundError} 404 NOT_FOUND: No account row for the session principal. Should never fire for a valid session — surfaced for SDKs.
418
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
419
+ * @see GET /v1/me
420
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-me
421
+ * @example
422
+ * ```ts
423
+ * const meProfile = await platform.me.retrieve();
424
+ * ```
425
+ */
426
+ retrieve(options) {
427
+ return this._client.request({ method: "GET", path: "/v1/me" }, options);
428
+ }
429
+ };
430
+ var OauthConnectionsResource = class extends APIResource {
431
+ /**
432
+ * Disconnect a client
433
+ *
434
+ * Revokes the whole grant family — the grant, its authorization codes, its refresh tokens and every live access token — in one transaction.
435
+ *
436
+ * @param grantId - Id of the grant.
437
+ * @param options - Per-request options.
438
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
439
+ * @throws {NotFoundError} 404 NOT_FOUND: No such connection for this human.
440
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
441
+ * @see DELETE /v1/oauth/connections/{grant_id}
442
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-oauth-connections-grant-id
443
+ * @example
444
+ * ```ts
445
+ * await platform.oauth.connections.delete("3f0c1a2b-4c5d-4e6f-8a9b-0c1d2e3f4a5b");
446
+ * ```
447
+ */
448
+ delete(grantId, options) {
449
+ return this._client.request({ method: "DELETE", path: "/v1/oauth/connections/{grant_id}", pathParams: { grant_id: grantId } }, options);
450
+ }
451
+ /**
452
+ * List clients this human has connected
453
+ *
454
+ * The user-facing half of revocation: which third-party clients hold a grant, in which workspace, carrying which policy.
455
+ *
456
+ * @param params - `PlatformAuth.OauthConnectionListParams`.
457
+ * @param options - Per-request options.
458
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`.
459
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
460
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
461
+ * @see GET /v1/oauth/connections
462
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-oauth-connections
463
+ * @example
464
+ * ```ts
465
+ * for await (const connection of platform.oauth.connections.list()) {
466
+ * console.log(connection);
467
+ * }
468
+ * const page = await platform.oauth.connections.list({}, { timeout: 5_000 });
469
+ * ```
470
+ */
471
+ list(params, options) {
472
+ return this._client.list({ method: "GET", path: "/v1/oauth/connections", query: params }, options);
473
+ }
474
+ };
475
+ var OauthWorkspacesConnectionsResource = class extends APIResource {
476
+ /**
477
+ * Disconnect a client on behalf of the workspace
478
+ *
479
+ * Revokes the whole grant family for a grant made by any member of this workspace — the lever a workspace owner needs when an employee leaves and their MCP client is still running. Requires `workspace.connection.revoke`.
480
+ *
481
+ * @param workspaceId - Id of the workspace.
482
+ * @param grantId - Id of the grant.
483
+ * @param options - Per-request options.
484
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
485
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Not a member, or lacks `workspace.connection.revoke`.
486
+ * @throws {NotFoundError} 404 NOT_FOUND: No such connection in this workspace.
487
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
488
+ * @see DELETE /v1/oauth/workspaces/{workspace_id}/connections/{grant_id}
489
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-oauth-workspaces-workspace-id-connections-grant-id
490
+ * @example
491
+ * ```ts
492
+ * await platform.oauth.workspaces.connections.delete("3f0c1a2b-4c5d-4e6f-8a9b-0c1d2e3f4a5b", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6");
493
+ * ```
494
+ */
495
+ delete(workspaceId, grantId, options) {
496
+ return this._client.request({ method: "DELETE", path: "/v1/oauth/workspaces/{workspace_id}/connections/{grant_id}", pathParams: { workspace_id: workspaceId, grant_id: grantId } }, options);
497
+ }
498
+ /**
499
+ * List every client connected to a workspace
500
+ *
501
+ * The workspace-side half of revocation, for owners and admins: every grant made against this workspace, by any member, including grants made by people who have since left. Requires `workspace.connection.read`.
502
+ *
503
+ * @param workspaceId - Id of the workspace.
504
+ * @param params - `PlatformAuth.OauthWorkspaceConnectionListParams`.
505
+ * @param options - Per-request options.
506
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`.
507
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
508
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Not a member, or lacks `workspace.connection.read`.
509
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
510
+ * @see GET /v1/oauth/workspaces/{workspace_id}/connections
511
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-oauth-workspaces-workspace-id-connections
512
+ * @example
513
+ * ```ts
514
+ * for await (const connection of platform.oauth.workspaces.connections.list("3f0c1a2b-4c5d-4e6f-8a9b-0c1d2e3f4a5b")) {
515
+ * console.log(connection);
516
+ * }
517
+ * const page = await platform.oauth.workspaces.connections.list("3f0c1a2b-4c5d-4e6f-8a9b-0c1d2e3f4a5b", {}, { timeout: 5_000 });
518
+ * ```
519
+ */
520
+ list(workspaceId, params, options) {
521
+ return this._client.list({ method: "GET", path: "/v1/oauth/workspaces/{workspace_id}/connections", pathParams: { workspace_id: workspaceId }, query: params }, options);
522
+ }
523
+ /**
524
+ * Lift a workspace revocation so the member may reconnect
525
+ *
526
+ * A workspace revocation is durable: the member re-running the connect flow does not undo it, so an administrator has to. This clears the block only — every token minted under the old grant stays revoked and the member still has to approve a fresh consent screen. Requires `workspace.connection.revoke`.
527
+ *
528
+ * @param workspaceId - Id of the workspace.
529
+ * @param grantId - Id of the grant.
530
+ * @param options - Per-request options.
531
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session, or a session that has been signed out (`SESSION_REVOKED`).
532
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Not a member, or lacks `workspace.connection.revoke`.
533
+ * @throws {NotFoundError} 404 NOT_FOUND: No such connection in this workspace.
534
+ * @throws {ConflictError} 409 CONFLICT: The connection was not revoked by an administrator — there is nothing to lift.
535
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
536
+ * @see POST /v1/oauth/workspaces/{workspace_id}/connections/{grant_id}/restore
537
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-oauth-workspaces-workspace-id-connections-grant-id-restore
538
+ * @example
539
+ * ```ts
540
+ * await platform.oauth.workspaces.connections.restore("3f0c1a2b-4c5d-4e6f-8a9b-0c1d2e3f4a5b", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6");
541
+ * ```
542
+ */
543
+ restore(workspaceId, grantId, options) {
544
+ return this._client.request({ method: "POST", path: "/v1/oauth/workspaces/{workspace_id}/connections/{grant_id}/restore", pathParams: { workspace_id: workspaceId, grant_id: grantId } }, options);
545
+ }
546
+ };
547
+ var OauthWorkspacesResource = class extends APIResource {
548
+ #connections;
549
+ get connections() {
550
+ return this.#connections ??= new OauthWorkspacesConnectionsResource(this._client, this._b);
551
+ }
552
+ };
553
+ var OauthResource = class extends APIResource {
554
+ #connections;
555
+ #workspaces;
556
+ get connections() {
557
+ return this.#connections ??= new OauthConnectionsResource(this._client, this._b);
558
+ }
559
+ get workspaces() {
560
+ return this.#workspaces ??= new OauthWorkspacesResource(this._client, this._b);
561
+ }
562
+ };
563
+ var SessionsResource = class extends APIResource {
564
+ /**
565
+ * Revoke one of the caller's own sessions. Takes effect immediately — the refresh token stops working straight away, not at the end of its window.
566
+ *
567
+ * @param id - Id of the session.
568
+ * @param options - Per-request options.
569
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: `id` is not a UUID.
570
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Unauthorized
571
+ * @throws {NotFoundError} 404 NOT_FOUND: No such session, or it belongs to somebody else — deliberately the same response, so this cannot be used to probe which session ids exist.
572
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
573
+ * @see DELETE /v1/session/{id}
574
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-session-id
575
+ * @example
576
+ * ```ts
577
+ * const revokeSession = await platform.sessions.delete("3f0c1a2b-4c5d-4e6f-8a9b-0c1d2e3f4a5b");
578
+ * ```
579
+ */
580
+ delete(id, options) {
581
+ return this._client.request({ method: "DELETE", path: "/v1/session/{id}", pathParams: { id } }, options);
582
+ }
583
+ /**
584
+ * List active sessions
585
+ *
586
+ * @param options - Per-request options.
587
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Unauthorized
588
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
589
+ * @see GET /v1/session
590
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-session
591
+ * @example
592
+ * ```ts
593
+ * const result = await platform.sessions.list();
594
+ * ```
595
+ */
596
+ list(options) {
597
+ return this._client.request({ method: "GET", path: "/v1/session" }, options);
598
+ }
599
+ /**
600
+ * Sign out every other session of the caller, keeping the one this request was made with. Takes effect immediately for the revoked sessions. Idempotent: a repeat call revokes 0.
601
+ *
602
+ * @param options - Per-request options.
603
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Unauthorized
604
+ * @throws {ConflictError} 409 CONFLICT: The access token maps to no session (minted before sessions tracked token ids), so the current session cannot be kept. Sign in again.
605
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
606
+ * @see POST /v1/session/revoke-others
607
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-session-revoke-others
608
+ * @example
609
+ * ```ts
610
+ * const revokeOtherSessions = await platform.sessions.revokeOthers();
611
+ * ```
612
+ */
613
+ revokeOthers(options) {
614
+ return this._client.request({ method: "POST", path: "/v1/session/revoke-others" }, options);
615
+ }
616
+ };
617
+ var StatsResource = class extends APIResource {
618
+ /**
619
+ * Workspace stats
620
+ *
621
+ * Member count, active platform API keys, admin changes in the window with a daily series, the last admin change and the last API-key use, for the console dashboard.
622
+ *
623
+ * Admin changes are workspace audit events that record a mutation. Reads (any action ending `.read`), sign-ins (`auth.signin.succeeded`) and MCP tool-call rows (`workspace.mcp_tool.*`) are not counted, so opening the console does not move the numbers. Days are UTC. Counts and timestamps only: no actor identifiers. Cached for up to 60 seconds (`generated_at`).
624
+ *
625
+ * @param params - `PlatformAuth.StatsRetrieveParams`.
626
+ * @param options - Per-request options.
627
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: `window` is not one of 1d, 7d, 30d, or `workspaceId` is the slug of a workspace the caller can read rather than its UUID.
628
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
629
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of the workspace (`NOT_A_MEMBER`) or lacks `workspace.audit.read` on it.
630
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found: no workspace has this id (or slug). Same answer as the service's other workspace routes.
631
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
632
+ * @see GET /v1/workspaces/{workspace_id}/stats
633
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-id-stats
634
+ * @example
635
+ * ```ts
636
+ * const workspaceStats = await platform.stats.retrieve();
637
+ * ```
638
+ */
639
+ retrieve(params, options) {
640
+ return this._client.request({ method: "GET", path: "/v1/workspaces/{workspace_id}/stats", query: params }, options);
641
+ }
642
+ };
643
+ var VerificationResource = class extends APIResource {
644
+ /**
645
+ * Resend verification email
646
+ *
647
+ * @param options - Per-request options.
648
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Unauthorized
649
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
650
+ * @see POST /v1/verification/resend
651
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-verification-resend
652
+ * @example
653
+ * ```ts
654
+ * const feedback = await platform.verification.resend();
655
+ * ```
656
+ */
657
+ resend(options) {
658
+ return this._client.request({ method: "POST", path: "/v1/verification/resend" }, options);
659
+ }
660
+ /**
661
+ * Verify an email code
662
+ *
663
+ * @param params - `PlatformAuth.VerificationVerifyParams`.
664
+ * @param options - Per-request options.
665
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Invalid or expired verification code
666
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
667
+ * @see POST /v1/verification/verify
668
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-verification-verify
669
+ * @example
670
+ * ```ts
671
+ * const feedback = await platform.verification.verify({ code: "a1b2c3d4…" });
672
+ * ```
673
+ */
674
+ verify(params, options) {
675
+ return this._client.request({ method: "POST", path: "/v1/verification/verify", body: params, public: true }, options);
676
+ }
677
+ };
678
+ var WellKnownResource = class extends APIResource {
679
+ /**
680
+ * Public JWKS for verifying platform-issued JWTs (issuer `https://api.auth.productcraft.co`).
681
+ *
682
+ * @param options - Per-request options.
683
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
684
+ * @see GET /.well-known/jwks.json
685
+ * @see https://productcraft.co/docs/platform/api-reference#get-well-known-jwks-json
686
+ * @example
687
+ * ```ts
688
+ * const jwks = await platform.wellKnown.jwks();
689
+ * ```
690
+ */
691
+ jwks(options) {
692
+ return this._client.request({ method: "GET", path: "/.well-known/jwks.json", public: true }, options);
693
+ }
694
+ /**
695
+ * OAuth 2.1 authorization server metadata (RFC 8414)
696
+ *
697
+ * Discovery document for third-party clients (Claude Desktop, Cursor, the ProductCraft MCP server). PKCE with `S256` is mandatory; no other code-challenge method is advertised or accepted. `scopes_supported` lists **presets**, not scopes: authority is the policy document on the grant (`authority_model`).
698
+ *
699
+ * @param options - Per-request options.
700
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
701
+ * @see GET /.well-known/oauth-authorization-server
702
+ * @see https://productcraft.co/docs/platform/api-reference#get-well-known-oauth-authorization-server
703
+ * @example
704
+ * ```ts
705
+ * const authorizationServerMetadata = await platform.wellKnown.oauthAuthorizationServer();
706
+ * ```
707
+ */
708
+ oauthAuthorizationServer(options) {
709
+ return this._client.request({ method: "GET", path: "/.well-known/oauth-authorization-server", public: true }, options);
710
+ }
711
+ };
712
+ var WorkspacesApiKeysPresetsResource = class extends APIResource {
713
+ /**
714
+ * List the ready-made permission sets a workspace key can be minted with (`preset` on create), each with a label, a description and what it allows in this workspace, in plain sentences. A preset a key has already used reads its stored policy, so edits show.
715
+ *
716
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
717
+ * @param options - Per-request options.
718
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, malformed or invalid session.
719
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.apikey.read`.
720
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found.
721
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
722
+ * @see GET /v1/workspaces/{workspace_slug}/api-keys/presets
723
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-api-keys-presets
724
+ * @example
725
+ * ```ts
726
+ * for await (const preset of platform.workspaces.apiKeys.presets.list("workspace")) {
727
+ * console.log(preset);
728
+ * }
729
+ * ```
730
+ */
731
+ list(workspaceSlug, options) {
732
+ return this._client.list({ method: "GET", path: "/v1/workspaces/{workspace_slug}/api-keys/presets", pathParams: { workspace_slug: workspaceSlug } }, options);
733
+ }
734
+ };
735
+ var WorkspacesApiKeysResource = class extends APIResource {
736
+ #presets;
737
+ get presets() {
738
+ return this.#presets ??= new WorkspacesApiKeysPresetsResource(this._client, this._b);
739
+ }
740
+ /**
741
+ * Mint a new PAK. Choose what it can do with `preset` (a ready-made set such as `mail-send`) or `policy_ids` (managed policies you wrote), never both. The plaintext `token` is returned ONCE — store it now, then call `GET /v1/api-keys/self` with it to check what it can do. The minter can grant at most their own effective permissions. Cookie/JWT only — PAKs cannot mint other PAKs. Send an `Idempotency-Key` to make a retry safe: a retry of a mint that succeeded mints nothing and answers `409 PAK_ALREADY_MINTED` with that key's `id` (the token itself is never cached).
742
+ *
743
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
744
+ * @param params - `PlatformAuth.WorkspaceApiKeyCreateParams`.
745
+ * @param options - Per-request options (an Idempotency-Key is sent automatically; override with `idempotencyKey`).
746
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR, PAK_NAME_REQUIRED, PAK_NAME_TOO_LONG: Body failed validation (`VALIDATION_ERROR`): neither or both of `policy_ids` and `preset`, an unknown `preset`, an empty `policy_ids`, more than 25 policies, or a blank/overlong `name` (`PAK_NAME_REQUIRED` / `PAK_NAME_TOO_LONG`).
747
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing, malformed or invalid session. Also a session that has been signed out (`SESSION_REVOKED`).
748
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is a PAK (`pcft_live_*`) — mint requires a human-issued session; or is not a member (`NOT_A_MEMBER`), lacks `workspace.apikey.create`, or cannot grant one or more actions in the chosen preset or policies.
749
+ * @throws {NotFoundError} 404 NOT_FOUND, POLICY_NOT_FOUND: Workspace not found, or one of `policy_ids` does not exist in this workspace (`POLICY_NOT_FOUND`).
750
+ * @throws {ConflictError} 409 CONFLICT, PAK_ALREADY_MINTED, IDEMPOTENCY_KEY_REUSE, IDEMPOTENCY_IN_PROGRESS: `PAK_ALREADY_MINTED`: this `Idempotency-Key` already minted a key (its `id` is in `details`); the token was shown once, so rotate that key for a new one. Idempotency: `IDEMPOTENCY_KEY_REUSE` when this `Idempotency-Key` was already used with a different body or route; `IDEMPOTENCY_IN_PROGRESS` while another request with the same key is still running (retry after `Retry-After` seconds, with the same key).
751
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
752
+ * @see POST /v1/workspaces/{workspace_slug}/api-keys
753
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-workspace-slug-api-keys
754
+ * @example
755
+ * ```ts
756
+ * const mintPak = await platform.workspaces.apiKeys.create("workspace", { name: "Production social client" });
757
+ * ```
758
+ */
759
+ create(workspaceSlug, params, options) {
760
+ return this._client.request({ method: "POST", path: "/v1/workspaces/{workspace_slug}/api-keys", pathParams: { workspace_slug: workspaceSlug }, body: params, idempotent: true }, options);
761
+ }
762
+ /**
763
+ * Revoke a PAK. Default behaviour: introspect returns null on the next upstream call; downstream services fail-closed within the 60s cache TTL window. Pass `?force=true` to additionally publish a Redis fan-out that evicts the matching cache entry across every PAK-consuming service immediately — use it when rotating a leaked PAK and the 60s window matters.
764
+ *
765
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
766
+ * @param id - Id of the api key.
767
+ * @param params - `PlatformAuth.WorkspaceApiKeyDeleteParams`.
768
+ * @param options - Per-request options.
769
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: `id` is not a UUID.
770
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only). Also a session that has been signed out (`SESSION_REVOKED`).
771
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.apikey.delete`.
772
+ * @throws {NotFoundError} 404 NOT_FOUND, PAK_NOT_FOUND: Workspace not found, or PAK not found in this workspace (`PAK_NOT_FOUND`). Revoking an already-revoked PAK is a 204 no-op.
773
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
774
+ * @see DELETE /v1/workspaces/{workspace_slug}/api-keys/{id}
775
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-workspaces-workspace-slug-api-keys-id
776
+ * @example
777
+ * ```ts
778
+ * await platform.workspaces.apiKeys.delete("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6");
779
+ * ```
780
+ */
781
+ delete(workspaceSlug, id, params, options) {
782
+ return this._client.request({ method: "DELETE", path: "/v1/workspaces/{workspace_slug}/api-keys/{id}", pathParams: { workspace_slug: workspaceSlug, id }, query: params }, options);
783
+ }
784
+ /**
785
+ * List the API keys in this workspace
786
+ *
787
+ * Newest first, as the standard cursor-paginated `{data, pagination}` envelope (20 per page, at most 100). Plaintext tokens are never returned, only prefixes and metadata.
788
+ *
789
+ * **Deprecated legacy shape:** a request that sends neither `limit` nor `cursor` gets a bare JSON array of every key (capped at 1000), unless its `User-Agent` is a ProductCraft SDK (`productcraft-…`), which always gets the envelope. The array is kept only for `@productcraft/platform-auth` 0.0.x clients and is removed in the platform API's next major version; send `limit` (or use an SDK).
790
+ *
791
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
792
+ * @param params - `PlatformAuth.WorkspaceApiKeyListParams`.
793
+ * @param options - Per-request options.
794
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`, or `include_revoked` is not `true` or `false` (`VALIDATION_ERROR`).
795
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
796
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
797
+ * @see GET /v1/workspaces/{workspace_slug}/api-keys
798
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-api-keys
799
+ * @example
800
+ * ```ts
801
+ * for await (const apiKey of platform.workspaces.apiKeys.list("workspace")) {
802
+ * console.log(apiKey);
803
+ * }
804
+ * const page = await platform.workspaces.apiKeys.list("workspace", {}, { timeout: 5_000 });
805
+ * ```
806
+ */
807
+ list(workspaceSlug, params, options) {
808
+ return this._client.list({ method: "GET", path: "/v1/workspaces/{workspace_slug}/api-keys", pathParams: { workspace_slug: workspaceSlug }, query: params }, options);
809
+ }
810
+ /**
811
+ * Describe the key a mint with this `preset` or these `policy_ids` would create, without creating anything: what it could do in plain sentences, and whether you may mint it. Read-only, so it takes no `Idempotency-Key`. Powers the review step of the console key wizard.
812
+ *
813
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
814
+ * @param params - `PlatformAuth.WorkspaceApiKeyPreviewParams`.
815
+ * @param options - Per-request options.
816
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Body failed validation (`VALIDATION_ERROR`): neither or both of `policy_ids` and `preset`, an unknown `preset`, or an empty or oversized `policy_ids`.
817
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing, malformed or invalid session. Also a session that has been signed out (`SESSION_REVOKED`).
818
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is a PAK, is not a member (`NOT_A_MEMBER`), or lacks `workspace.apikey.create`. A key you could not mint is NOT a 403 here: it comes back with `grantable: false`.
819
+ * @throws {NotFoundError} 404 NOT_FOUND, POLICY_NOT_FOUND: Workspace not found, or one of `policy_ids` does not exist in this workspace (`POLICY_NOT_FOUND`).
820
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
821
+ * @see POST /v1/workspaces/{workspace_slug}/api-keys/preview
822
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-workspace-slug-api-keys-preview
823
+ * @example
824
+ * ```ts
825
+ * const pakGrantPreview = await platform.workspaces.apiKeys.preview("workspace", { policy_ids: ["11111111-1111-1111-1111-111111111111"] });
826
+ * ```
827
+ */
828
+ preview(workspaceSlug, params, options) {
829
+ return this._client.request({ method: "POST", path: "/v1/workspaces/{workspace_slug}/api-keys/preview", pathParams: { workspace_slug: workspaceSlug }, body: params }, options);
830
+ }
831
+ /**
832
+ * Get a single PAK by id.
833
+ *
834
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
835
+ * @param id - Id of the api key.
836
+ * @param options - Per-request options.
837
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: `id` is not a UUID.
838
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only).
839
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.apikey.read`.
840
+ * @throws {NotFoundError} 404 NOT_FOUND, PAK_NOT_FOUND: Workspace not found, or PAK not found in this workspace (`PAK_NOT_FOUND`).
841
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
842
+ * @see GET /v1/workspaces/{workspace_slug}/api-keys/{id}
843
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-api-keys-id
844
+ * @example
845
+ * ```ts
846
+ * const publicApiKey = await platform.workspaces.apiKeys.retrieve("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6");
847
+ * ```
848
+ */
849
+ retrieve(workspaceSlug, id, options) {
850
+ return this._client.request({ method: "GET", path: "/v1/workspaces/{workspace_slug}/api-keys/{id}", pathParams: { workspace_slug: workspaceSlug, id } }, options);
851
+ }
852
+ /**
853
+ * Mint a replacement for an existing PAK, carrying its name, description and policy bindings over. The outgoing key keeps working for `grace_hours` (24 by default) so a fleet can roll over without downtime. The plaintext `token` is returned ONCE. Cookie/JWT only — a PAK cannot rotate a PAK, for the same reason it cannot mint one.
854
+ *
855
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
856
+ * @param id - Id of the api key.
857
+ * @param params - `PlatformAuth.WorkspaceApiKeyRotateParams`.
858
+ * @param options - Per-request options.
859
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session, or a session that has been signed out (`SESSION_REVOKED`).
860
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Caller is a PAK (`pcft_live_*`), or cannot grant one or more actions in the bindings being carried across.
861
+ * @throws {NotFoundError} 404 NOT_FOUND: PAK not found in this workspace.
862
+ * @throws {ConflictError} 409 CONFLICT, PAK_REVOKED, PAK_EXPIRED: The key is revoked (`PAK_REVOKED`), already expired (`PAK_EXPIRED`), or has no policy bindings to carry across.
863
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
864
+ * @see POST /v1/workspaces/{workspace_slug}/api-keys/{id}/rotate
865
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-workspace-slug-api-keys-id-rotate
866
+ * @example
867
+ * ```ts
868
+ * const rotatePak = await platform.workspaces.apiKeys.rotate("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6", { grace_hours: 24 });
869
+ * ```
870
+ */
871
+ rotate(workspaceSlug, id, params, options) {
872
+ return this._client.request({ method: "POST", path: "/v1/workspaces/{workspace_slug}/api-keys/{id}/rotate", pathParams: { workspace_slug: workspaceSlug, id }, body: params }, options);
873
+ }
874
+ /**
875
+ * Update a PAK’s name or description (does not touch bindings).
876
+ *
877
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
878
+ * @param id - Id of the api key.
879
+ * @param params - `PlatformAuth.WorkspaceApiKeyUpdateParams`.
880
+ * @param options - Per-request options.
881
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR, PAK_NAME_REQUIRED: `id` is not a UUID, body failed validation, or `name` is blank (`PAK_NAME_REQUIRED`).
882
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only). Also a session that has been signed out (`SESSION_REVOKED`).
883
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.apikey.update`.
884
+ * @throws {NotFoundError} 404 NOT_FOUND, PAK_NOT_FOUND: Workspace not found, or PAK not found in this workspace (`PAK_NOT_FOUND`).
885
+ * @throws {ConflictError} 409 CONFLICT, PAK_REVOKED: PAK is revoked (`PAK_REVOKED`).
886
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
887
+ * @see PATCH /v1/workspaces/{workspace_slug}/api-keys/{id}
888
+ * @see https://productcraft.co/docs/platform/api-reference#patch-v1-workspaces-workspace-slug-api-keys-id
889
+ * @example
890
+ * ```ts
891
+ * const publicApiKey = await platform.workspaces.apiKeys.update("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6", { description: "string" });
892
+ * ```
893
+ */
894
+ update(workspaceSlug, id, params, options) {
895
+ return this._client.request({ method: "PATCH", path: "/v1/workspaces/{workspace_slug}/api-keys/{id}", pathParams: { workspace_slug: workspaceSlug, id }, body: params }, options);
896
+ }
897
+ /**
898
+ * Replace the managed-policy bindings on a PAK. Re-runs caller-narrowing on the merged union of statements.
899
+ *
900
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
901
+ * @param id - Id of the api key.
902
+ * @param params - `PlatformAuth.WorkspaceApiKeyUpdateBindingsParams`.
903
+ * @param options - Per-request options.
904
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: One of: bound > 25 policies; merged > 200 statements; one of the policy ids does not exist or lives in a different workspace.
905
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session, or a session that has been signed out (`SESSION_REVOKED`).
906
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Caller cannot grant one or more actions in the merged statement set.
907
+ * @throws {NotFoundError} 404 NOT_FOUND: PAK not found in this workspace.
908
+ * @throws {ConflictError} 409 CONFLICT: Empty bindings — revoke the PAK instead of leaving it unbound.
909
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
910
+ * @see PATCH /v1/workspaces/{workspace_slug}/api-keys/{id}/bindings
911
+ * @see https://productcraft.co/docs/platform/api-reference#patch-v1-workspaces-workspace-slug-api-keys-id-bindings
912
+ * @example
913
+ * ```ts
914
+ * const publicApiKey = await platform.workspaces.apiKeys.updateBindings("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6", { policy_ids: ["string"] });
915
+ * ```
916
+ */
917
+ updateBindings(workspaceSlug, id, params, options) {
918
+ return this._client.request({ method: "PATCH", path: "/v1/workspaces/{workspace_slug}/api-keys/{id}/bindings", pathParams: { workspace_slug: workspaceSlug, id }, body: params }, options);
919
+ }
920
+ };
921
+ var WorkspacesAuditFeedResource = class extends APIResource {
922
+ /**
923
+ * Unified workspace audit feed (cursor-paginated)
924
+ *
925
+ * Audit timeline for workspace-scoped events — workspace, member, role, invite, service-activation, PAK and OAuth-consent mutations, plus successful sign-ins and completed password resets. Per-app Auth rows are NOT merged in: they live in another database with no cursor that spans both, and they are served by `GET /v1/apps/:appId/audit-logs` (paginated), `.../audit-logs/export` (streamed) and the per-app audit sink. The `sources` field reports that explicitly rather than implying a pending follow-up.
926
+ *
927
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
928
+ * @param params - `PlatformAuth.WorkspaceAuditFeedListParams`.
929
+ * @param options - Per-request options.
930
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Invalid query params — `actor_id` is not a well-formed UUID, or `cursor` is not a cursor this endpoint minted. `since`/`until` that do not parse as ISO-8601 are ignored rather than rejected, and `sources` silently drops unknown names; an empty result set after those filters still returns 200.
931
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
932
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: The caller is signed in but lacks `workspace.audit.read` for this workspace.
933
+ * @throws {NotFoundError} 404 NOT_FOUND: The `:workspaceSlug` path param does not resolve to a workspace the caller can see.
934
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
935
+ * @see GET /v1/workspaces/{workspace_slug}/audit-feed
936
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-audit-feed
937
+ * @example
938
+ * ```ts
939
+ * for await (const auditFeed of platform.workspaces.auditFeed.list("workspace")) {
940
+ * console.log(auditFeed);
941
+ * }
942
+ * const page = await platform.workspaces.auditFeed.list("workspace", {}, { timeout: 5_000 });
943
+ * ```
944
+ */
945
+ list(workspaceSlug, params, options) {
946
+ return this._client.list({ method: "GET", path: "/v1/workspaces/{workspace_slug}/audit-feed", pathParams: { workspace_slug: workspaceSlug }, query: fillActor(params, this._b) }, options);
947
+ }
948
+ };
949
+ var WorkspacesAuditLogsResource = class extends APIResource {
950
+ /**
951
+ * Stream the workspace audit log as NDJSON or CSV, applying the same `?action=` / `?actor_id=` / `?since=` / `?until=` filters as the list. Newest first. Reading the export is itself audited.
952
+ *
953
+ * The response is streamed: rows are walked in keyset batches and written as they are read, so neither the service nor the client holds the whole log. This is the SOC 2 / GDPR export the platform docs promise. Hard cap of 1,000,000 rows per call; a wider request is refused with 413 before any body is written, so a truncated file can never masquerade as a complete one.
954
+ *
955
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
956
+ * @param params - `PlatformAuth.WorkspaceAuditLogExportParams`.
957
+ * @param options - Per-request options.
958
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Unknown `format`, or malformed `since` / `until`.
959
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
960
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Caller lacks `workspace.audit.read`.
961
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found.
962
+ * @throws {APIError} 413 PAYLOAD_TOO_LARGE: More than 1,000,000 rows match. Narrow the window with `since` / `until` and retry.
963
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
964
+ * @see GET /v1/workspaces/{workspace_slug}/audit-logs/export
965
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-audit-logs-export
966
+ * @example
967
+ * ```ts
968
+ * const response = await platform.workspaces.auditLogs.export("workspace");
969
+ * const text = await response.text();
970
+ * ```
971
+ */
972
+ export(workspaceSlug, params, options) {
973
+ return this._client.request({ method: "GET", path: "/v1/workspaces/{workspace_slug}/audit-logs/export", pathParams: { workspace_slug: workspaceSlug }, query: fillActor(params, this._b), raw: true }, options);
974
+ }
975
+ /**
976
+ * List workspace audit log entries, newest first. Filter by `?action=`, `?actor_id=`, and/or the `?since=` / `?until=` date range. 20/page (max 100), cursor-paginated.
977
+ *
978
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
979
+ * @param params - `PlatformAuth.WorkspaceAuditLogListParams`.
980
+ * @param options - Per-request options.
981
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`, `since`, or `until`.
982
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
983
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
984
+ * @see GET /v1/workspaces/{workspace_slug}/audit-logs
985
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-audit-logs
986
+ * @example
987
+ * ```ts
988
+ * for await (const auditLog of platform.workspaces.auditLogs.list("workspace")) {
989
+ * console.log(auditLog);
990
+ * }
991
+ * const page = await platform.workspaces.auditLogs.list("workspace", {}, { timeout: 5_000 });
992
+ * ```
993
+ */
994
+ list(workspaceSlug, params, options) {
995
+ return this._client.list({ method: "GET", path: "/v1/workspaces/{workspace_slug}/audit-logs", pathParams: { workspace_slug: workspaceSlug }, query: fillActor(params, this._b) }, options);
996
+ }
997
+ };
998
+ var WorkspacesAvatarResource = class extends APIResource {
999
+ /**
1000
+ * Clear the workspace avatar and delete the stored object. Gated by `workspace.settings.update`.
1001
+ *
1002
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1003
+ * @param options - Per-request options.
1004
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing or invalid session.
1005
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.settings.update`.
1006
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id).
1007
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1008
+ * @see DELETE /v1/workspaces/{workspace_slug}/avatar
1009
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-workspaces-workspace-slug-avatar
1010
+ * @example
1011
+ * ```ts
1012
+ * await platform.workspaces.avatar.clear("workspace");
1013
+ * ```
1014
+ */
1015
+ clear(workspaceSlug, options) {
1016
+ return this._client.request({ method: "DELETE", path: "/v1/workspaces/{workspace_slug}/avatar", pathParams: { workspace_slug: workspaceSlug } }, options);
1017
+ }
1018
+ /**
1019
+ * Upload (or replace) the workspace identity avatar. Gated by `workspace.settings.update` (owner + admin). PNG/JPEG/WEBP only, ≤2 MB, magic-byte sniffed. SVG is rejected (stored-XSS).
1020
+ *
1021
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1022
+ * @param params - `PlatformAuth.WorkspaceAvatarUploadParams`.
1023
+ * @param options - Per-request options.
1024
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
1025
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Caller is not a member of this workspace, or lacks workspace.settings.update.
1026
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1027
+ * @see POST /v1/workspaces/{workspace_slug}/avatar
1028
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-workspace-slug-avatar
1029
+ * @example
1030
+ * ```ts
1031
+ * const workspaceAvatarUrl = await platform.workspaces.avatar.upload("workspace", { file: new File(["…"], "image.png", { type: "image/png" }) });
1032
+ * ```
1033
+ */
1034
+ upload(workspaceSlug, params, options) {
1035
+ return this._client.request({ method: "POST", path: "/v1/workspaces/{workspace_slug}/avatar", pathParams: { workspace_slug: workspaceSlug }, body: formData(params) }, options);
1036
+ }
1037
+ };
1038
+ var WorkspacesInvitesResource = class extends APIResource {
1039
+ /**
1040
+ * Accept a workspace invite by code. Cookie/JWT only — invite acceptance binds a human identity to a workspace.
1041
+ *
1042
+ * @param params - `PlatformAuth.WorkspaceInviteAcceptParams`.
1043
+ * @param options - Per-request options.
1044
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Body failed validation (`code` missing or empty).
1045
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session. Also a session that has been signed out (`SESSION_REVOKED`).
1046
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, EMAIL_NOT_VERIFIED, INVITE_EMAIL_MISMATCH: Caller is a PAK (`pcft_live_*`), email not verified (`EMAIL_NOT_VERIFIED`), or the invite is restricted to a different email (`INVITE_EMAIL_MISMATCH`).
1047
+ * @throws {NotFoundError} 404 NOT_FOUND, INVITE_INVALID: Invite code not found (`INVITE_INVALID`).
1048
+ * @throws {ConflictError} 409 CONFLICT, ALREADY_A_MEMBER: Caller is already a member of this workspace (`ALREADY_A_MEMBER`).
1049
+ * @throws {APIError} 410 GONE, INVITE_REVOKED, INVITE_EXPIRED, INVITE_EXHAUSTED: Invite revoked (`INVITE_REVOKED`), expired (`INVITE_EXPIRED`) or out of uses (`INVITE_EXHAUSTED`).
1050
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: more than 10 requests/min from this IP (strict `auth` bucket). `Retry-After` header set. Per-IP limit: rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1051
+ * @see POST /v1/workspaces/invites/accept
1052
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-invites-accept
1053
+ * @example
1054
+ * ```ts
1055
+ * const workspace = await platform.workspaces.invites.accept({ code: "inv_…" });
1056
+ * ```
1057
+ */
1058
+ accept(params, options) {
1059
+ return this._client.request({ method: "POST", path: "/v1/workspaces/invites/accept", body: params }, options);
1060
+ }
1061
+ /**
1062
+ * Create a workspace invite link. Cookie/JWT only — invites bring new humans into the workspace.
1063
+ *
1064
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1065
+ * @param params - `PlatformAuth.WorkspaceInviteCreateParams`.
1066
+ * @param options - Per-request options (an Idempotency-Key is sent automatically; override with `idempotencyKey`).
1067
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Body failed validation.
1068
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session. Also a session that has been signed out (`SESSION_REVOKED`).
1069
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, EMAIL_NOT_VERIFIED, NOT_A_MEMBER, OWNER_ROLE_REQUIRED, MEMBER_RANK_EXCEEDED: Caller is a PAK (`pcft_live_*`), email not verified (`EMAIL_NOT_VERIFIED`), not a member (`NOT_A_MEMBER`), lacks `workspace.member.invite`, a non-owner tried to invite an owner (`OWNER_ROLE_REQUIRED`), or the role holds permissions the caller does not (`MEMBER_RANK_EXCEEDED`).
1070
+ * @throws {NotFoundError} 404 NOT_FOUND, ROLE_NOT_FOUND: Workspace not found, or role not found in this workspace (`ROLE_NOT_FOUND`).
1071
+ * @throws {ConflictError} 409 CONFLICT, IDEMPOTENCY_KEY_REUSE, IDEMPOTENCY_IN_PROGRESS: Idempotency: `IDEMPOTENCY_KEY_REUSE` when this `Idempotency-Key` was already used with a different body or route; `IDEMPOTENCY_IN_PROGRESS` while another request with the same key is still running (retry after `Retry-After` seconds, with the same key).
1072
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1073
+ * @see POST /v1/workspaces/{workspace_slug}/invites
1074
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-workspace-slug-invites
1075
+ * @example
1076
+ * ```ts
1077
+ * const workspaceInvite = await platform.workspaces.invites.create("workspace", { email: "alice@example.com" });
1078
+ * ```
1079
+ */
1080
+ create(workspaceSlug, params, options) {
1081
+ return this._client.request({ method: "POST", path: "/v1/workspaces/{workspace_slug}/invites", pathParams: { workspace_slug: workspaceSlug }, body: params, idempotent: true }, options);
1082
+ }
1083
+ /**
1084
+ * Revoke a workspace invite. Cookie/JWT only.
1085
+ *
1086
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1087
+ * @param inviteId - Id of the invite.
1088
+ * @param options - Per-request options.
1089
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session. Also a session that has been signed out (`SESSION_REVOKED`).
1090
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is a PAK (`pcft_live_*`), not a member of the invite’s workspace (`NOT_A_MEMBER`), or lacks `workspace.member.invite`.
1091
+ * @throws {NotFoundError} 404 NOT_FOUND, INVITE_NOT_FOUND: Workspace not found, or invite not found (`INVITE_NOT_FOUND`).
1092
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1093
+ * @see DELETE /v1/workspaces/{workspace_slug}/invites/{invite_id}
1094
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-workspaces-workspace-slug-invites-invite-id
1095
+ * @example
1096
+ * ```ts
1097
+ * await platform.workspaces.invites.delete("workspace", "invite");
1098
+ * ```
1099
+ */
1100
+ delete(workspaceSlug, inviteId, options) {
1101
+ return this._client.request({ method: "DELETE", path: "/v1/workspaces/{workspace_slug}/invites/{invite_id}", pathParams: { workspace_slug: workspaceSlug, invite_id: inviteId } }, options);
1102
+ }
1103
+ /**
1104
+ * List workspace invites, newest first. Cursor-paginated.
1105
+ *
1106
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1107
+ * @param params - `PlatformAuth.WorkspaceInviteListParams`.
1108
+ * @param options - Per-request options.
1109
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`.
1110
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing or invalid session.
1111
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.member.invite`.
1112
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id).
1113
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1114
+ * @see GET /v1/workspaces/{workspace_slug}/invites
1115
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-invites
1116
+ * @example
1117
+ * ```ts
1118
+ * for await (const invite of platform.workspaces.invites.list("workspace")) {
1119
+ * console.log(invite);
1120
+ * }
1121
+ * const page = await platform.workspaces.invites.list("workspace", {}, { timeout: 5_000 });
1122
+ * ```
1123
+ */
1124
+ list(workspaceSlug, params, options) {
1125
+ return this._client.list({ method: "GET", path: "/v1/workspaces/{workspace_slug}/invites", pathParams: { workspace_slug: workspaceSlug }, query: params }, options);
1126
+ }
1127
+ };
1128
+ var WorkspacesMembersResource = class extends APIResource {
1129
+ /**
1130
+ * Remove a member from a workspace (or self-leave)
1131
+ *
1132
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1133
+ * @param accountId - Id of the account.
1134
+ * @param options - Per-request options.
1135
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session. Also a session that has been signed out (`SESSION_REVOKED`).
1136
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER, MEMBER_RANK_EXCEEDED: Caller is not a member of this workspace (`NOT_A_MEMBER`), lacks `workspace.member.remove` (not required for self-leave), or the target outranks the caller (`MEMBER_RANK_EXCEEDED`: only an owner can remove an owner, and the target role's permissions must all be held by the caller).
1137
+ * @throws {NotFoundError} 404 NOT_FOUND, NOT_A_MEMBER: Workspace not found, or target account is not a member (`NOT_A_MEMBER`).
1138
+ * @throws {ConflictError} 409 CONFLICT, LAST_MEMBER, SOLE_OWNER: Target is the last member (`LAST_MEMBER`) or the sole owner (`SOLE_OWNER`).
1139
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1140
+ * @see DELETE /v1/workspaces/{workspace_slug}/members/{account_id}
1141
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-workspaces-workspace-slug-members-account-id
1142
+ * @example
1143
+ * ```ts
1144
+ * await platform.workspaces.members.delete("workspace", "account");
1145
+ * ```
1146
+ */
1147
+ delete(workspaceSlug, accountId, options) {
1148
+ return this._client.request({ method: "DELETE", path: "/v1/workspaces/{workspace_slug}/members/{account_id}", pathParams: { workspace_slug: workspaceSlug, account_id: accountId } }, options);
1149
+ }
1150
+ /**
1151
+ * List workspace members, oldest join first. Narrow with `?q=` (name / username / email substring) and/or `?role=`. Cursor-paginated.
1152
+ *
1153
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1154
+ * @param params - `PlatformAuth.WorkspaceMemberListParams`.
1155
+ * @param options - Per-request options.
1156
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`.
1157
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing or invalid session.
1158
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.member.read`.
1159
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id).
1160
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1161
+ * @see GET /v1/workspaces/{workspace_slug}/members
1162
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-members
1163
+ * @example
1164
+ * ```ts
1165
+ * for await (const member of platform.workspaces.members.list("workspace")) {
1166
+ * console.log(member);
1167
+ * }
1168
+ * const page = await platform.workspaces.members.list("workspace", {}, { timeout: 5_000 });
1169
+ * ```
1170
+ */
1171
+ list(workspaceSlug, params, options) {
1172
+ return this._client.list({ method: "GET", path: "/v1/workspaces/{workspace_slug}/members", pathParams: { workspace_slug: workspaceSlug }, query: params }, options);
1173
+ }
1174
+ /**
1175
+ * Update a member's role. Body: { roleId } or { role: "owner"|"admin"|"member" }.
1176
+ *
1177
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1178
+ * @param accountId - Id of the account.
1179
+ * @param params - `PlatformAuth.WorkspaceMemberUpdateRoleParams`.
1180
+ * @param options - Per-request options.
1181
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Body failed validation.
1182
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session. Also a session that has been signed out (`SESSION_REVOKED`).
1183
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER, OWNER_ROLE_REQUIRED, MEMBER_RANK_EXCEEDED: Caller is not a member of this workspace (`NOT_A_MEMBER`), lacks `workspace.member.update-role`, a non-owner tried to assign the owner role or change an owner (`OWNER_ROLE_REQUIRED`), or a non-owner tried to change a role to or from one holding permissions the caller lacks (`MEMBER_RANK_EXCEEDED`). Admins may make admins, never owners.
1184
+ * @throws {NotFoundError} 404 NOT_FOUND, NOT_A_MEMBER, ROLE_NOT_FOUND: Workspace not found, target account is not a member (`NOT_A_MEMBER`), or role not found in this workspace (`ROLE_NOT_FOUND`).
1185
+ * @throws {ConflictError} 409 CONFLICT, SOLE_OWNER: Would demote the only owner (`SOLE_OWNER`). Assign another owner first.
1186
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1187
+ * @see PATCH /v1/workspaces/{workspace_slug}/members/{account_id}/role
1188
+ * @see https://productcraft.co/docs/platform/api-reference#patch-v1-workspaces-workspace-slug-members-account-id-role
1189
+ * @example
1190
+ * ```ts
1191
+ * const updateMemberRole = await platform.workspaces.members.updateRole("workspace", "account", { role: "owner" });
1192
+ * ```
1193
+ */
1194
+ updateRole(workspaceSlug, accountId, params, options) {
1195
+ return this._client.request({ method: "PATCH", path: "/v1/workspaces/{workspace_slug}/members/{account_id}/role", pathParams: { workspace_slug: workspaceSlug, account_id: accountId }, body: params }, options);
1196
+ }
1197
+ };
1198
+ var WorkspacesPoliciesActionsResource = class extends APIResource {
1199
+ /**
1200
+ * List every known workspace action (catalog of statement actions).
1201
+ *
1202
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1203
+ * @param options - Per-request options.
1204
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only).
1205
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.policy.read`.
1206
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id).
1207
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1208
+ * @see GET /v1/workspaces/{workspace_slug}/policies/actions/catalog
1209
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-policies-actions-catalog
1210
+ * @example
1211
+ * ```ts
1212
+ * const workspaceActionCatalog = await platform.workspaces.policies.actions.catalog("workspace");
1213
+ * ```
1214
+ */
1215
+ catalog(workspaceSlug, options) {
1216
+ return this._client.request({ method: "GET", path: "/v1/workspaces/{workspace_slug}/policies/actions/catalog", pathParams: { workspace_slug: workspaceSlug } }, options);
1217
+ }
1218
+ };
1219
+ var WorkspacesPoliciesResource = class extends APIResource {
1220
+ #actions;
1221
+ get actions() {
1222
+ return this.#actions ??= new WorkspacesPoliciesActionsResource(this._client, this._b);
1223
+ }
1224
+ /**
1225
+ * Create a managed policy. Cookie/JWT only — policy authoring is a human-admin surface.
1226
+ *
1227
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1228
+ * @param params - `PlatformAuth.WorkspacePolicyCreateParams`.
1229
+ * @param options - Per-request options (an Idempotency-Key is sent automatically; override with `idempotencyKey`).
1230
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Invalid policy shape, name, or condition block.
1231
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session, or a session that has been signed out (`SESSION_REVOKED`).
1232
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member (`NOT_A_MEMBER`), lacks `workspace.policy.create` (owner and admin hold it by default), or the policy grants an action the caller does not hold.
1233
+ * @throws {ConflictError} 409 CONFLICT, IDEMPOTENCY_KEY_REUSE, IDEMPOTENCY_IN_PROGRESS: Name already in use, or the workspace already has 100 policies. Idempotency: `IDEMPOTENCY_KEY_REUSE` when this `Idempotency-Key` was already used with a different body or route; `IDEMPOTENCY_IN_PROGRESS` while another request with the same key is still running (retry after `Retry-After` seconds, with the same key).
1234
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1235
+ * @see POST /v1/workspaces/{workspace_slug}/policies
1236
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-workspace-slug-policies
1237
+ * @example
1238
+ * ```ts
1239
+ * const managedPolicy = await platform.workspaces.policies.create("workspace", {
1240
+ * name: "mail-readonly",
1241
+ * policy: [{ actions: ["mail.read", "mail.list"], effect: "allow", resources: ["*"] }],
1242
+ * });
1243
+ * ```
1244
+ */
1245
+ create(workspaceSlug, params, options) {
1246
+ return this._client.request({ method: "POST", path: "/v1/workspaces/{workspace_slug}/policies", pathParams: { workspace_slug: workspaceSlug }, body: params, idempotent: true }, options);
1247
+ }
1248
+ /**
1249
+ * Delete a managed policy. Cascades: API keys lose the binding (deny-all if no other bindings remain); roles fall back to their inline policy column. Owners and admins; a policy bound to a role, or a preset policy, only an owner can delete. Cookie/JWT only.
1250
+ *
1251
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1252
+ * @param policyId - Id of the policy.
1253
+ * @param options - Per-request options.
1254
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session, or a session that has been signed out (`SESSION_REVOKED`).
1255
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, OWNER_ROLE_REQUIRED: Caller lacks `workspace.policy.delete`, or is not an owner and the policy is bound to a role or is a preset policy (`OWNER_ROLE_REQUIRED`).
1256
+ * @throws {NotFoundError} 404 NOT_FOUND, POLICY_NOT_FOUND: Policy not found in this workspace (`POLICY_NOT_FOUND`).
1257
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1258
+ * @see DELETE /v1/workspaces/{workspace_slug}/policies/{policy_id}
1259
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-workspaces-workspace-slug-policies-policy-id
1260
+ * @example
1261
+ * ```ts
1262
+ * const managedPolicyDeleted = await platform.workspaces.policies.delete("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6");
1263
+ * ```
1264
+ */
1265
+ delete(workspaceSlug, policyId, options) {
1266
+ return this._client.request({ method: "DELETE", path: "/v1/workspaces/{workspace_slug}/policies/{policy_id}", pathParams: { workspace_slug: workspaceSlug, policy_id: policyId } }, options);
1267
+ }
1268
+ /**
1269
+ * List managed policies in a workspace, alphabetically. 20/page (max 100), cursor-paginated.
1270
+ *
1271
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1272
+ * @param params - `PlatformAuth.WorkspacePolicyListParams`.
1273
+ * @param options - Per-request options.
1274
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`.
1275
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
1276
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1277
+ * @see GET /v1/workspaces/{workspace_slug}/policies
1278
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-policies
1279
+ * @example
1280
+ * ```ts
1281
+ * for await (const policy of platform.workspaces.policies.list("workspace")) {
1282
+ * console.log(policy);
1283
+ * }
1284
+ * const page = await platform.workspaces.policies.list("workspace", {}, { timeout: 5_000 });
1285
+ * ```
1286
+ */
1287
+ list(workspaceSlug, params, options) {
1288
+ return this._client.list({ method: "GET", path: "/v1/workspaces/{workspace_slug}/policies", pathParams: { workspace_slug: workspaceSlug }, query: params }, options);
1289
+ }
1290
+ /**
1291
+ * Get a managed policy by id
1292
+ *
1293
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1294
+ * @param policyId - Id of the policy.
1295
+ * @param options - Per-request options.
1296
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
1297
+ * @throws {NotFoundError} 404 NOT_FOUND: Policy not found in this workspace.
1298
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1299
+ * @see GET /v1/workspaces/{workspace_slug}/policies/{policy_id}
1300
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-policies-policy-id
1301
+ * @example
1302
+ * ```ts
1303
+ * const managedPolicyDetail = await platform.workspaces.policies.retrieve("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6");
1304
+ * ```
1305
+ */
1306
+ retrieve(workspaceSlug, policyId, options) {
1307
+ return this._client.request({ method: "GET", path: "/v1/workspaces/{workspace_slug}/policies/{policy_id}", pathParams: { workspace_slug: workspaceSlug, policy_id: policyId } }, options);
1308
+ }
1309
+ /**
1310
+ * Update a managed policy. Owners and admins; a policy bound to a role, or a preset policy, only an owner can edit. Cookie/JWT only — policy authoring is a human-admin surface.
1311
+ *
1312
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1313
+ * @param policyId - Id of the policy.
1314
+ * @param params - `PlatformAuth.WorkspacePolicyUpdateParams`.
1315
+ * @param options - Per-request options.
1316
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Invalid policy shape, name, or condition block.
1317
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session, or a session that has been signed out (`SESSION_REVOKED`).
1318
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, OWNER_ROLE_REQUIRED: Caller lacks `workspace.policy.update`, cannot grant one or more requested actions, or is not an owner and the policy is bound to a role or is a preset policy (`OWNER_ROLE_REQUIRED`).
1319
+ * @throws {NotFoundError} 404 NOT_FOUND, POLICY_NOT_FOUND: Policy not found in this workspace (`POLICY_NOT_FOUND`).
1320
+ * @throws {ConflictError} 409 CONFLICT, POLICY_NAME_TAKEN: Name already in use (`POLICY_NAME_TAKEN`).
1321
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1322
+ * @see PATCH /v1/workspaces/{workspace_slug}/policies/{policy_id}
1323
+ * @see https://productcraft.co/docs/platform/api-reference#patch-v1-workspaces-workspace-slug-policies-policy-id
1324
+ * @example
1325
+ * ```ts
1326
+ * const managedPolicyDetail = await platform.workspaces.policies.update("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6", { description: "Read-only access to all Mail resources" });
1327
+ * ```
1328
+ */
1329
+ update(workspaceSlug, policyId, params, options) {
1330
+ return this._client.request({ method: "PATCH", path: "/v1/workspaces/{workspace_slug}/policies/{policy_id}", pathParams: { workspace_slug: workspaceSlug, policy_id: policyId }, body: params }, options);
1331
+ }
1332
+ };
1333
+ var WorkspacesRolesResource = class extends APIResource {
1334
+ /**
1335
+ * Create a new custom role. Cookie/JWT only — role authoring is a human-admin surface.
1336
+ *
1337
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1338
+ * @param params - `PlatformAuth.WorkspaceRoleCreateParams`.
1339
+ * @param options - Per-request options (an Idempotency-Key is sent automatically; override with `idempotencyKey`).
1340
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR, POLICY_INVALID: Body failed validation, invalid role name, malformed policy, both `policy_id` and `policy` sent, or an action pattern matches no known permission (`POLICY_INVALID`).
1341
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only). Also a session that has been signed out (`SESSION_REVOKED`).
1342
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER, ACTIONS_NOT_GRANTABLE: Caller is not a member of this workspace (`NOT_A_MEMBER`), lacks `workspace.role.create`, or the policy grants actions the caller does not hold (`ACTIONS_NOT_GRANTABLE`).
1343
+ * @throws {NotFoundError} 404 NOT_FOUND, POLICY_NOT_FOUND: Workspace not found, or `policy_id` not found in this workspace (`POLICY_NOT_FOUND`).
1344
+ * @throws {ConflictError} 409 CONFLICT, ROLE_NAME_TAKEN, IDEMPOTENCY_KEY_REUSE, IDEMPOTENCY_IN_PROGRESS: Role name already in use or reserved for a system role (`ROLE_NAME_TAKEN`). Idempotency: `IDEMPOTENCY_KEY_REUSE` when this `Idempotency-Key` was already used with a different body or route; `IDEMPOTENCY_IN_PROGRESS` while another request with the same key is still running (retry after `Retry-After` seconds, with the same key).
1345
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1346
+ * @see POST /v1/workspaces/{workspace_slug}/roles
1347
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-workspace-slug-roles
1348
+ * @example
1349
+ * ```ts
1350
+ * const workspaceRole = await platform.workspaces.roles.create("workspace", { name: "BillingAdmin" });
1351
+ * ```
1352
+ */
1353
+ create(workspaceSlug, params, options) {
1354
+ return this._client.request({ method: "POST", path: "/v1/workspaces/{workspace_slug}/roles", pathParams: { workspace_slug: workspaceSlug }, body: params, idempotent: true }, options);
1355
+ }
1356
+ /**
1357
+ * Delete a custom role (fails if it has members). Cookie/JWT only — role authoring is a human-admin surface.
1358
+ *
1359
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1360
+ * @param roleId - Id of the role.
1361
+ * @param options - Per-request options.
1362
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: `roleId` is not a UUID.
1363
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only). Also a session that has been signed out (`SESSION_REVOKED`).
1364
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.role.delete`.
1365
+ * @throws {NotFoundError} 404 NOT_FOUND, ROLE_NOT_FOUND: Workspace not found, or role not found in this workspace (`ROLE_NOT_FOUND`).
1366
+ * @throws {ConflictError} 409 CONFLICT, ROLE_SYSTEM_IMMUTABLE, ROLE_HAS_MEMBERS: Role is a system role (`ROLE_SYSTEM_IMMUTABLE`) or still has members (`ROLE_HAS_MEMBERS`).
1367
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1368
+ * @see DELETE /v1/workspaces/{workspace_slug}/roles/{role_id}
1369
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-workspaces-workspace-slug-roles-role-id
1370
+ * @example
1371
+ * ```ts
1372
+ * await platform.workspaces.roles.delete("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6");
1373
+ * ```
1374
+ */
1375
+ delete(workspaceSlug, roleId, options) {
1376
+ return this._client.request({ method: "DELETE", path: "/v1/workspaces/{workspace_slug}/roles/{role_id}", pathParams: { workspace_slug: workspaceSlug, role_id: roleId } }, options);
1377
+ }
1378
+ /**
1379
+ * List roles in a workspace. System roles first, then alphabetical. 20/page (max 100), cursor-paginated.
1380
+ *
1381
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1382
+ * @param params - `PlatformAuth.WorkspaceRoleListParams`.
1383
+ * @param options - Per-request options.
1384
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`.
1385
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
1386
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1387
+ * @see GET /v1/workspaces/{workspace_slug}/roles
1388
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-roles
1389
+ * @example
1390
+ * ```ts
1391
+ * for await (const role of platform.workspaces.roles.list("workspace")) {
1392
+ * console.log(role);
1393
+ * }
1394
+ * const page = await platform.workspaces.roles.list("workspace", {}, { timeout: 5_000 });
1395
+ * ```
1396
+ */
1397
+ list(workspaceSlug, params, options) {
1398
+ return this._client.list({ method: "GET", path: "/v1/workspaces/{workspace_slug}/roles", pathParams: { workspace_slug: workspaceSlug }, query: params }, options);
1399
+ }
1400
+ /**
1401
+ * Get a role + its permissions
1402
+ *
1403
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1404
+ * @param roleId - Id of the role.
1405
+ * @param options - Per-request options.
1406
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: `roleId` is not a UUID.
1407
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only).
1408
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.role.read`.
1409
+ * @throws {NotFoundError} 404 NOT_FOUND, ROLE_NOT_FOUND: Workspace not found, or role not found in this workspace (`ROLE_NOT_FOUND`).
1410
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1411
+ * @see GET /v1/workspaces/{workspace_slug}/roles/{role_id}
1412
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-roles-role-id
1413
+ * @example
1414
+ * ```ts
1415
+ * const workspaceRole = await platform.workspaces.roles.retrieve("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6");
1416
+ * ```
1417
+ */
1418
+ retrieve(workspaceSlug, roleId, options) {
1419
+ return this._client.request({ method: "GET", path: "/v1/workspaces/{workspace_slug}/roles/{role_id}", pathParams: { workspace_slug: workspaceSlug, role_id: roleId } }, options);
1420
+ }
1421
+ /**
1422
+ * Update a role or replace its permission set. Cookie/JWT only — role authoring is a human-admin surface.
1423
+ *
1424
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1425
+ * @param roleId - Id of the role.
1426
+ * @param params - `PlatformAuth.WorkspaceRoleUpdateParams`.
1427
+ * @param options - Per-request options.
1428
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: `roleId` is not a UUID, body failed validation, malformed policy, both `policy_id` and `policy` sent, or an action pattern matches no known permission.
1429
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only). Also a session that has been signed out (`SESSION_REVOKED`).
1430
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER, ACTIONS_NOT_GRANTABLE: Caller is not a member of this workspace (`NOT_A_MEMBER`), lacks `workspace.role.update`, or the policy grants actions the caller does not hold (`ACTIONS_NOT_GRANTABLE`).
1431
+ * @throws {NotFoundError} 404 NOT_FOUND, ROLE_NOT_FOUND, POLICY_NOT_FOUND: Workspace, role (`ROLE_NOT_FOUND`) or bound policy (`POLICY_NOT_FOUND`) not found in this workspace.
1432
+ * @throws {ConflictError} 409 CONFLICT, ROLE_SYSTEM_IMMUTABLE, ROLE_NAME_TAKEN: System roles cannot be renamed, edited or bound (`ROLE_SYSTEM_IMMUTABLE`), or the new name is taken (`ROLE_NAME_TAKEN`).
1433
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1434
+ * @see PATCH /v1/workspaces/{workspace_slug}/roles/{role_id}
1435
+ * @see https://productcraft.co/docs/platform/api-reference#patch-v1-workspaces-workspace-slug-roles-role-id
1436
+ * @example
1437
+ * ```ts
1438
+ * const workspaceRole = await platform.workspaces.roles.update("workspace", "5d1e2f3a-4b5c-4d6e-8f70-8192a3b4c5d6", { description: "string" });
1439
+ * ```
1440
+ */
1441
+ update(workspaceSlug, roleId, params, options) {
1442
+ return this._client.request({ method: "PATCH", path: "/v1/workspaces/{workspace_slug}/roles/{role_id}", pathParams: { workspace_slug: workspaceSlug, role_id: roleId }, body: params }, options);
1443
+ }
1444
+ };
1445
+ var WorkspacesServicesResource = class extends APIResource {
1446
+ /**
1447
+ * Disable a service (settings are retained)
1448
+ *
1449
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1450
+ * @param service - The product: `auth`, `mail`, `waitlist`, `social` or `trawl`.
1451
+ * @param options - Per-request options.
1452
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR, SERVICE_UNKNOWN: Unknown service name (`SERVICE_UNKNOWN`).
1453
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only).
1454
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.service.disable`.
1455
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id).
1456
+ * @throws {ConflictError} 409 CONFLICT, SERVICE_NOT_ENABLED: Service is not currently enabled (`SERVICE_NOT_ENABLED`).
1457
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1458
+ * @see DELETE /v1/workspaces/{workspace_slug}/services/{service}
1459
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-workspaces-workspace-slug-services-service
1460
+ * @example
1461
+ * ```ts
1462
+ * await platform.workspaces.services.disable("workspace", "service");
1463
+ * ```
1464
+ */
1465
+ disable(workspaceSlug, service, options) {
1466
+ return this._client.request({ method: "DELETE", path: "/v1/workspaces/{workspace_slug}/services/{service}", pathParams: { workspace_slug: workspaceSlug, service } }, options);
1467
+ }
1468
+ /**
1469
+ * Enable (or re-enable) a service for this workspace
1470
+ *
1471
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1472
+ * @param service - The product: `auth`, `mail`, `waitlist`, `social` or `trawl`.
1473
+ * @param params - `PlatformAuth.WorkspaceServiceEnableParams`.
1474
+ * @param options - Per-request options.
1475
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR, SERVICE_UNKNOWN: Unknown service name (`SERVICE_UNKNOWN`) or body failed validation.
1476
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only).
1477
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.service.enable`.
1478
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id).
1479
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1480
+ * @see POST /v1/workspaces/{workspace_slug}/services/{service}
1481
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces-workspace-slug-services-service
1482
+ * @example
1483
+ * ```ts
1484
+ * const workspaceServiceState = await platform.workspaces.services.enable("workspace", "service", { settings: {} });
1485
+ * ```
1486
+ */
1487
+ enable(workspaceSlug, service, params, options) {
1488
+ return this._client.request({ method: "POST", path: "/v1/workspaces/{workspace_slug}/services/{service}", pathParams: { workspace_slug: workspaceSlug, service }, body: params }, options);
1489
+ }
1490
+ /**
1491
+ * List services activated on this workspace. Complete — one row per product, not paginated.
1492
+ *
1493
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1494
+ * @param options - Per-request options.
1495
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only).
1496
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.service.read`.
1497
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id).
1498
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1499
+ * @see GET /v1/workspaces/{workspace_slug}/services
1500
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug-services
1501
+ * @example
1502
+ * ```ts
1503
+ * const listWorkspaceServices = await platform.workspaces.services.list("workspace");
1504
+ * ```
1505
+ */
1506
+ list(workspaceSlug, options) {
1507
+ return this._client.request({ method: "GET", path: "/v1/workspaces/{workspace_slug}/services", pathParams: { workspace_slug: workspaceSlug } }, options);
1508
+ }
1509
+ /**
1510
+ * Replace the settings jsonb for an active service
1511
+ *
1512
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1513
+ * @param service - The product: `auth`, `mail`, `waitlist`, `social` or `trawl`.
1514
+ * @param params - `PlatformAuth.WorkspaceServiceUpdateSettingsParams`.
1515
+ * @param options - Per-request options.
1516
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR, SERVICE_UNKNOWN: Unknown service name (`SERVICE_UNKNOWN`).
1517
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, malformed or invalid session, or a PAK bearer (this route accepts cookie/JWT sessions only).
1518
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`), or lacks `workspace.service.enable`.
1519
+ * @throws {NotFoundError} 404 NOT_FOUND, SERVICE_NOT_ACTIVATED: Workspace not found, or the service was never activated on it (`SERVICE_NOT_ACTIVATED`).
1520
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1521
+ * @see PATCH /v1/workspaces/{workspace_slug}/services/{service}/settings
1522
+ * @see https://productcraft.co/docs/platform/api-reference#patch-v1-workspaces-workspace-slug-services-service-settings
1523
+ * @example
1524
+ * ```ts
1525
+ * const workspaceServiceState = await platform.workspaces.services.updateSettings("workspace", "service", { default_sender: "noreply@acme.com" });
1526
+ * ```
1527
+ */
1528
+ updateSettings(workspaceSlug, service, params, options) {
1529
+ return this._client.request({ method: "PATCH", path: "/v1/workspaces/{workspace_slug}/services/{service}/settings", pathParams: { workspace_slug: workspaceSlug, service }, body: params }, options);
1530
+ }
1531
+ };
1532
+ var WorkspacesResource = class extends APIResource {
1533
+ #apiKeys;
1534
+ #auditFeed;
1535
+ #auditLogs;
1536
+ #avatar;
1537
+ #invites;
1538
+ #members;
1539
+ #policies;
1540
+ #roles;
1541
+ #services;
1542
+ get apiKeys() {
1543
+ return this.#apiKeys ??= new WorkspacesApiKeysResource(this._client, this._b);
1544
+ }
1545
+ get auditFeed() {
1546
+ return this.#auditFeed ??= new WorkspacesAuditFeedResource(this._client, this._b);
1547
+ }
1548
+ get auditLogs() {
1549
+ return this.#auditLogs ??= new WorkspacesAuditLogsResource(this._client, this._b);
1550
+ }
1551
+ get avatar() {
1552
+ return this.#avatar ??= new WorkspacesAvatarResource(this._client, this._b);
1553
+ }
1554
+ get invites() {
1555
+ return this.#invites ??= new WorkspacesInvitesResource(this._client, this._b);
1556
+ }
1557
+ get members() {
1558
+ return this.#members ??= new WorkspacesMembersResource(this._client, this._b);
1559
+ }
1560
+ get policies() {
1561
+ return this.#policies ??= new WorkspacesPoliciesResource(this._client, this._b);
1562
+ }
1563
+ get roles() {
1564
+ return this.#roles ??= new WorkspacesRolesResource(this._client, this._b);
1565
+ }
1566
+ get services() {
1567
+ return this.#services ??= new WorkspacesServicesResource(this._client, this._b);
1568
+ }
1569
+ /**
1570
+ * Create a new workspace. Cookie/JWT only — PAKs are workspace-scoped credentials and cannot create new workspaces.
1571
+ *
1572
+ * @param params - `PlatformAuth.WorkspaceCreateParams`.
1573
+ * @param options - Per-request options (an Idempotency-Key is sent automatically; override with `idempotencyKey`).
1574
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
1575
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Caller is a PAK (`pcft_live_*`). Workspace creation requires a human-issued session.
1576
+ * @throws {ConflictError} 409 CONFLICT, IDEMPOTENCY_KEY_REUSE, IDEMPOTENCY_IN_PROGRESS: Idempotency: `IDEMPOTENCY_KEY_REUSE` when this `Idempotency-Key` was already used with a different body or route; `IDEMPOTENCY_IN_PROGRESS` while another request with the same key is still running (retry after `Retry-After` seconds, with the same key).
1577
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1578
+ * @see POST /v1/workspaces
1579
+ * @see https://productcraft.co/docs/platform/api-reference#post-v1-workspaces
1580
+ * @example
1581
+ * ```ts
1582
+ * const workspace = await platform.workspaces.create({ display_name: "Acme Corp", slug: "acme-corp" });
1583
+ * ```
1584
+ */
1585
+ create(params, options) {
1586
+ return this._client.request({ method: "POST", path: "/v1/workspaces", body: params, idempotent: true }, options);
1587
+ }
1588
+ /**
1589
+ * Delete a workspace (requires workspace.delete). Cookie/JWT only — irreversible workspace destruction needs a human-attributed audit row.
1590
+ *
1591
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1592
+ * @param options - Per-request options.
1593
+ * @throws {AuthenticationError} 401 UNAUTHORIZED, SESSION_REVOKED: Missing or invalid session, or a session that has been signed out (`SESSION_REVOKED`).
1594
+ * @throws {PermissionDeniedError} 403 FORBIDDEN: Caller is a PAK (`pcft_live_*`). Workspace deletion requires a human-issued session.
1595
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1596
+ * @see DELETE /v1/workspaces/{workspace_slug}
1597
+ * @see https://productcraft.co/docs/platform/api-reference#delete-v1-workspaces-workspace-slug
1598
+ * @example
1599
+ * ```ts
1600
+ * await platform.workspaces.delete("workspace");
1601
+ * ```
1602
+ */
1603
+ delete(workspaceSlug, options) {
1604
+ return this._client.request({ method: "DELETE", path: "/v1/workspaces/{workspace_slug}", pathParams: { workspace_slug: workspaceSlug } }, options);
1605
+ }
1606
+ /**
1607
+ * List workspaces the current user belongs to
1608
+ *
1609
+ * @param params - `PlatformAuth.WorkspaceListParams`.
1610
+ * @param options - Per-request options.
1611
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Malformed `cursor`.
1612
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing or invalid session.
1613
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1614
+ * @see GET /v1/workspaces
1615
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces
1616
+ * @example
1617
+ * ```ts
1618
+ * for await (const workspace of platform.workspaces.list()) {
1619
+ * console.log(workspace);
1620
+ * }
1621
+ * const page = await platform.workspaces.list({}, { timeout: 5_000 });
1622
+ * ```
1623
+ */
1624
+ list(params, options) {
1625
+ return this._client.list({ method: "GET", path: "/v1/workspaces", query: params }, options);
1626
+ }
1627
+ /**
1628
+ * Get workspace details
1629
+ *
1630
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1631
+ * @param options - Per-request options.
1632
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing or invalid session.
1633
+ * @throws {PermissionDeniedError} 403 FORBIDDEN, NOT_A_MEMBER: Caller is not a member of this workspace (`NOT_A_MEMBER`).
1634
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found (unknown slug or id).
1635
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1636
+ * @see GET /v1/workspaces/{workspace_slug}
1637
+ * @see https://productcraft.co/docs/platform/api-reference#get-v1-workspaces-workspace-slug
1638
+ * @example
1639
+ * ```ts
1640
+ * const workspace = await platform.workspaces.retrieve("workspace");
1641
+ * ```
1642
+ */
1643
+ retrieve(workspaceSlug, options) {
1644
+ return this._client.request({ method: "GET", path: "/v1/workspaces/{workspace_slug}", pathParams: { workspace_slug: workspaceSlug } }, options);
1645
+ }
1646
+ /**
1647
+ * Update workspace display name, slug, or settings. Slug renames broadcast a `workspace.renamed` event so denormalised consumers (waitlist-api) sync.
1648
+ *
1649
+ * @param workspaceSlug - Slug of the workspace. Platform routes name the workspace by slug, positionally in the SDK (`platform.workspaces.retrieve("acme")`); the product APIs bind `workspace_id` instead.
1650
+ * @param params - `PlatformAuth.WorkspaceUpdateParams`.
1651
+ * @param options - Per-request options.
1652
+ * @throws {BadRequestError} 400 BAD_REQUEST, VALIDATION_ERROR: Invalid slug or display name.
1653
+ * @throws {AuthenticationError} 401 UNAUTHORIZED: Missing, invalid or expired bearer token.
1654
+ * @throws {NotFoundError} 404 NOT_FOUND: Workspace not found.
1655
+ * @throws {ConflictError} 409 CONFLICT: Slug already taken by another workspace.
1656
+ * @throws {RateLimitError} 429 RATE_LIMITED: Rate limited: too many requests from this client IP in the last 60 seconds (`RATE_LIMITED`); wait `Retry-After` seconds.
1657
+ * @see PATCH /v1/workspaces/{workspace_slug}
1658
+ * @see https://productcraft.co/docs/platform/api-reference#patch-v1-workspaces-workspace-slug
1659
+ * @example
1660
+ * ```ts
1661
+ * const workspace = await platform.workspaces.update("workspace", { display_name: "string" });
1662
+ * ```
1663
+ */
1664
+ update(workspaceSlug, params, options) {
1665
+ return this._client.request({ method: "PATCH", path: "/v1/workspaces/{workspace_slug}", pathParams: { workspace_slug: workspaceSlug }, body: params }, options);
1666
+ }
1667
+ };
1668
+ var PlatformAuthResources = class extends APIResource {
1669
+ #account;
1670
+ #apiKeys;
1671
+ #auth;
1672
+ #introspect;
1673
+ #me;
1674
+ #oauth;
1675
+ #sessions;
1676
+ #stats;
1677
+ #verification;
1678
+ #wellKnown;
1679
+ #workspaces;
1680
+ get account() {
1681
+ return this.#account ??= new AccountResource(this._client, this._b);
1682
+ }
1683
+ get apiKeys() {
1684
+ return this.#apiKeys ??= new ApiKeysResource(this._client, this._b);
1685
+ }
1686
+ get auth() {
1687
+ return this.#auth ??= new AuthResource(this._client, this._b);
1688
+ }
1689
+ get introspect() {
1690
+ return this.#introspect ??= new IntrospectResource(this._client, this._b);
1691
+ }
1692
+ get me() {
1693
+ return this.#me ??= new MeResource(this._client, this._b);
1694
+ }
1695
+ get oauth() {
1696
+ return this.#oauth ??= new OauthResource(this._client, this._b);
1697
+ }
1698
+ get sessions() {
1699
+ return this.#sessions ??= new SessionsResource(this._client, this._b);
1700
+ }
1701
+ get stats() {
1702
+ return this.#stats ??= new StatsResource(this._client, this._b);
1703
+ }
1704
+ get verification() {
1705
+ return this.#verification ??= new VerificationResource(this._client, this._b);
1706
+ }
1707
+ get wellKnown() {
1708
+ return this.#wellKnown ??= new WellKnownResource(this._client, this._b);
1709
+ }
1710
+ get workspaces() {
1711
+ return this.#workspaces ??= new WorkspacesResource(this._client, this._b);
1712
+ }
1713
+ };
1714
+
1715
+ // src/_generated/types.ts
1716
+ var ApiKeyPresetKey = { values: ["mail-send", "waitlist-write", "trawl-jobs", "readonly", "full"] };
1717
+ var ApiKeyStatus = { values: ["active", "expired", "revoked"] };
1718
+ var AuditActorType = { values: ["platform_user", "system", "pat"] };
1719
+ var AuditFeedSource = { values: ["workspace_audit", "heimdall_audit", "agora_moderation"] };
1720
+ var McpProduct = { values: ["auth", "mail", "waitlist", "social", "trawl"] };
1721
+ var PolicyEffect = { values: ["allow", "deny"] };
1722
+ var StatsGranularity = { values: ["day"] };
1723
+ var StatsMetric = { values: ["audit_events"] };
1724
+ var StatsWindow = { values: ["1d", "7d", "30d"] };
1725
+
1726
+ // src/_generated/client.ts
1727
+ var VERSION = "1.0.0" ;
1728
+ exports.default = class PlatformAuth extends PlatformAuthResources {
1729
+ #openapi;
1730
+ constructor(options = {}) {
1731
+ super(new core.APIClient(options, core.PC_BASE_URL.platformAuth, { name: "platform-auth", version: VERSION }));
1732
+ }
1733
+ /** The typed `openapi-fetch` escape hatch over the same credential and base URL. It does not retry. */
1734
+ get client() {
1735
+ return this.#openapi ??= core.createOpenAPIClient(this._client);
11
1736
  }
12
1737
  };
1738
+ ((PlatformAuth2) => {
1739
+ PlatformAuth2.ApiKeyPresetKey = ApiKeyPresetKey;
1740
+ PlatformAuth2.ApiKeyStatus = ApiKeyStatus;
1741
+ PlatformAuth2.AuditActorType = AuditActorType;
1742
+ PlatformAuth2.AuditFeedSource = AuditFeedSource;
1743
+ PlatformAuth2.McpProduct = McpProduct;
1744
+ PlatformAuth2.PolicyEffect = PolicyEffect;
1745
+ PlatformAuth2.StatsGranularity = StatsGranularity;
1746
+ PlatformAuth2.StatsMetric = StatsMetric;
1747
+ PlatformAuth2.StatsWindow = StatsWindow;
1748
+ })(exports.default || (exports.default = {}));
1749
+ var PlatformAuthErrorCode = { values: ["BAD_REQUEST", "VALIDATION_ERROR", "UNAUTHORIZED", "PAYMENT_REQUIRED", "FORBIDDEN", "NOT_FOUND", "METHOD_NOT_ALLOWED", "NOT_ACCEPTABLE", "REQUEST_TIMEOUT", "CONFLICT", "GONE", "PRECONDITION_FAILED", "PAYLOAD_TOO_LARGE", "UNSUPPORTED_MEDIA_TYPE", "UNPROCESSABLE_ENTITY", "PRECONDITION_REQUIRED", "RATE_LIMITED", "INTERNAL_SERVER_ERROR", "NOT_IMPLEMENTED", "BAD_GATEWAY", "SERVICE_UNAVAILABLE", "GATEWAY_TIMEOUT", "SERVICE_NOT_ENABLED", "INVALID_CREDENTIALS", "SESSION_REVOKED", "MCP_NOT_PERMITTED", "MCP_WORKSPACE_MISMATCH", "PAK_NOT_PERMITTED", "ACTIONS_NOT_GRANTABLE", "IDEMPOTENCY_KEY_REUSE", "IDEMPOTENCY_KEY_REQUIRED", "IDEMPOTENCY_IN_PROGRESS", "WEBHOOK_ENDPOINT_LIMIT", "WEBHOOK_ENDPOINT_NOT_FOUND", "WEBHOOK_ENDPOINT_NOT_SUBSCRIBED", "WEBHOOK_EVENT_NOT_FOUND", "WEBHOOK_EVENT_TYPE_UNKNOWN", "ACCOUNT_DEACTIVATED", "ACCOUNT_SUSPENDED", "ALREADY_A_MEMBER", "CROSS_ORIGIN_REJECTED", "EMAIL_NOT_VERIFIED", "INVITE_EMAIL_MISMATCH", "INVITE_EXHAUSTED", "INVITE_EXPIRED", "INVITE_INVALID", "INVITE_NOT_FOUND", "INVITE_REVOKED", "LAST_MEMBER", "MEMBER_RANK_EXCEEDED", "NOT_A_MEMBER", "OAUTH_GRANT_ADMIN_REVOKED", "OWNER_ROLE_REQUIRED", "PAK_ALREADY_MINTED", "PAK_EXPIRED", "PAK_NAME_REQUIRED", "PAK_NAME_TOO_LONG", "PAK_NOT_FOUND", "PAK_REVOKED", "PASSWORD_RESET_INVALID", "POLICY_INVALID", "POLICY_NAME_TAKEN", "POLICY_NOT_FOUND", "ROLE_HAS_MEMBERS", "ROLE_NAME_TAKEN", "ROLE_NOT_FOUND", "ROLE_SYSTEM_IMMUTABLE", "SERVICE_NOT_ACTIVATED", "SERVICE_UNKNOWN", "SOLE_OWNER", "TOO_MANY_ATTEMPTS", "WORKSPACE_KEY_REQUIRED"] };
13
1750
 
14
- exports.PlatformAuth = PlatformAuth;
1751
+ Object.defineProperty(exports, "APIConnectionError", {
1752
+ enumerable: true,
1753
+ get: function () { return core.APIConnectionError; }
1754
+ });
1755
+ Object.defineProperty(exports, "APIError", {
1756
+ enumerable: true,
1757
+ get: function () { return core.APIError; }
1758
+ });
1759
+ Object.defineProperty(exports, "APITimeoutError", {
1760
+ enumerable: true,
1761
+ get: function () { return core.APITimeoutError; }
1762
+ });
1763
+ Object.defineProperty(exports, "APIUserAbortError", {
1764
+ enumerable: true,
1765
+ get: function () { return core.APIUserAbortError; }
1766
+ });
1767
+ Object.defineProperty(exports, "AuthenticationError", {
1768
+ enumerable: true,
1769
+ get: function () { return core.AuthenticationError; }
1770
+ });
1771
+ Object.defineProperty(exports, "BadRequestError", {
1772
+ enumerable: true,
1773
+ get: function () { return core.BadRequestError; }
1774
+ });
1775
+ Object.defineProperty(exports, "ConfigurationError", {
1776
+ enumerable: true,
1777
+ get: function () { return core.ConfigurationError; }
1778
+ });
1779
+ Object.defineProperty(exports, "ConflictError", {
1780
+ enumerable: true,
1781
+ get: function () { return core.ConflictError; }
1782
+ });
1783
+ Object.defineProperty(exports, "IdempotencyKeyReuseError", {
1784
+ enumerable: true,
1785
+ get: function () { return core.IdempotencyKeyReuseError; }
1786
+ });
1787
+ Object.defineProperty(exports, "InternalServerError", {
1788
+ enumerable: true,
1789
+ get: function () { return core.InternalServerError; }
1790
+ });
1791
+ Object.defineProperty(exports, "NotFoundError", {
1792
+ enumerable: true,
1793
+ get: function () { return core.NotFoundError; }
1794
+ });
1795
+ Object.defineProperty(exports, "PermissionDeniedError", {
1796
+ enumerable: true,
1797
+ get: function () { return core.PermissionDeniedError; }
1798
+ });
1799
+ Object.defineProperty(exports, "ProductCraftError", {
1800
+ enumerable: true,
1801
+ get: function () { return core.ProductCraftError; }
1802
+ });
1803
+ Object.defineProperty(exports, "RateLimitError", {
1804
+ enumerable: true,
1805
+ get: function () { return core.RateLimitError; }
1806
+ });
1807
+ Object.defineProperty(exports, "UnprocessableEntityError", {
1808
+ enumerable: true,
1809
+ get: function () { return core.UnprocessableEntityError; }
1810
+ });
1811
+ Object.defineProperty(exports, "WebhookVerificationError", {
1812
+ enumerable: true,
1813
+ get: function () { return core.WebhookVerificationError; }
1814
+ });
1815
+ exports.PlatformAuth = exports.default;
1816
+ exports.PlatformAuthErrorCode = PlatformAuthErrorCode;
15
1817
  //# sourceMappingURL=index.cjs.map
16
1818
  //# sourceMappingURL=index.cjs.map