@productcraft/auth 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,2197 @@
1
+ import { PC_BASE_URL } from '@productcraft/core';
2
+ import { createRemoteJWKSet, errors, jwtVerify, customFetch } from 'jose';
3
+
4
+ // src/index.ts
5
+
6
+ // src/_http.ts
7
+ var AuthHttpError = class extends Error {
8
+ status;
9
+ statusText;
10
+ data;
11
+ constructor(response) {
12
+ super(
13
+ `Auth request failed: ${response.status} ${response.statusText}`
14
+ );
15
+ this.name = "AuthHttpError";
16
+ this.status = response.status;
17
+ this.statusText = response.statusText;
18
+ this.data = response.data;
19
+ }
20
+ };
21
+ function applyAuthHeader(headers, auth) {
22
+ if (!auth) return;
23
+ switch (auth.type) {
24
+ case "apiKey":
25
+ headers.set("Authorization", `Bearer ${auth.key}`);
26
+ break;
27
+ case "bearer":
28
+ headers.set("Authorization", `Bearer ${auth.token}`);
29
+ break;
30
+ case "cookie":
31
+ headers.set("Cookie", `auth_token=${auth.value}`);
32
+ break;
33
+ }
34
+ }
35
+ function buildUrl(baseUrl, path, params) {
36
+ const url = new URL(path, baseUrl);
37
+ if (params && typeof params === "object") {
38
+ for (const [k, v] of Object.entries(params)) {
39
+ if (v === void 0 || v === null) continue;
40
+ if (Array.isArray(v)) {
41
+ for (const item of v) url.searchParams.append(k, String(item));
42
+ } else {
43
+ url.searchParams.set(k, String(v));
44
+ }
45
+ }
46
+ }
47
+ return url;
48
+ }
49
+ function makeAuthHttpClient(options) {
50
+ const fetchImpl = options.fetch ?? globalThis.fetch;
51
+ if (!fetchImpl) {
52
+ throw new Error(
53
+ "@productcraft/auth: no `fetch` available \u2014 pass `fetch` in the config or run on Node 18+"
54
+ );
55
+ }
56
+ return async function client2(req) {
57
+ const url = buildUrl(req.baseURL ?? options.baseUrl, req.url ?? "", req.params);
58
+ const headers = new Headers(req.headers);
59
+ applyAuthHeader(headers, options.auth);
60
+ const hasBody = req.data !== void 0 && req.method !== "GET" && req.method !== "HEAD";
61
+ const isFormData = typeof FormData !== "undefined" && req.data instanceof FormData;
62
+ if (hasBody && !isFormData && !headers.has("Content-Type")) {
63
+ headers.set("Content-Type", "application/json");
64
+ }
65
+ const body = hasBody ? isFormData ? req.data : JSON.stringify(req.data) : void 0;
66
+ const res = await fetchImpl(url, {
67
+ method: req.method,
68
+ headers,
69
+ body,
70
+ credentials: req.credentials,
71
+ signal: req.signal
72
+ });
73
+ let data = void 0;
74
+ const ctype = res.headers.get("content-type") ?? "";
75
+ if (req.responseType === "text") {
76
+ data = await res.text();
77
+ } else if (req.responseType === "blob") {
78
+ data = await res.blob();
79
+ } else if (req.responseType === "arraybuffer") {
80
+ data = await res.arrayBuffer();
81
+ } else if (ctype.includes("application/json") || ctype.includes("application/problem+json")) {
82
+ data = await res.json().catch(() => void 0);
83
+ } else if (res.status !== 204) {
84
+ const text = await res.text().catch(() => "");
85
+ data = text || void 0;
86
+ }
87
+ const response = {
88
+ data,
89
+ status: res.status,
90
+ statusText: res.statusText,
91
+ headers: res.headers
92
+ };
93
+ if (!res.ok) throw new AuthHttpError(response);
94
+ return response;
95
+ };
96
+ }
97
+
98
+ // ../../node_modules/.pnpm/@kubb+plugin-client@4.37.8_@kubb+fabric-core@0.14.0_@kubb+react-fabric@0.14.0/node_modules/@kubb/plugin-client/dist/clients/fetch.js
99
+ var _config = {};
100
+ var getConfig = () => _config;
101
+ var setConfig = (config) => {
102
+ _config = config;
103
+ return getConfig();
104
+ };
105
+ var mergeConfig = (...configs) => {
106
+ return configs.reduce((merged, config) => {
107
+ return {
108
+ ...merged,
109
+ ...config,
110
+ headers: {
111
+ ...Array.isArray(merged.headers) ? Object.fromEntries(merged.headers) : merged.headers,
112
+ ...Array.isArray(config.headers) ? Object.fromEntries(config.headers) : config.headers
113
+ }
114
+ };
115
+ }, {});
116
+ };
117
+ var client = async (paramsConfig) => {
118
+ const normalizedParams = new URLSearchParams();
119
+ const config = mergeConfig(getConfig(), paramsConfig);
120
+ Object.entries(config.params || {}).forEach(([key, value]) => {
121
+ if (value !== void 0) normalizedParams.append(key, value === null ? "null" : value.toString());
122
+ });
123
+ let targetUrl = [config.baseURL, config.url].filter(Boolean).join("");
124
+ if (config.params) targetUrl += `?${normalizedParams}`;
125
+ const response = await fetch(targetUrl, {
126
+ credentials: config.credentials || "same-origin",
127
+ method: config.method?.toUpperCase(),
128
+ body: config.data instanceof FormData ? config.data : JSON.stringify(config.data),
129
+ signal: config.signal,
130
+ headers: config.headers
131
+ });
132
+ return {
133
+ data: [
134
+ 204,
135
+ 205,
136
+ 304
137
+ ].includes(response.status) || !response.body ? {} : await response.json(),
138
+ status: response.status,
139
+ statusText: response.statusText,
140
+ headers: response.headers
141
+ };
142
+ };
143
+ client.getConfig = getConfig;
144
+ client.setConfig = setConfig;
145
+
146
+ // src/_generated/clients/apps/appControllerGetApp.ts
147
+ function getAppControllerGetAppUrl({
148
+ appId
149
+ }) {
150
+ const app_id = appId;
151
+ const res = { method: "GET", url: `/v1/apps/${app_id}` };
152
+ return res;
153
+ }
154
+ async function appControllerGetApp({ appId }, config = {}) {
155
+ const { client: request = client, ...requestConfig } = config;
156
+ const res = await request({
157
+ method: "GET",
158
+ url: getAppControllerGetAppUrl({ appId }).url.toString(),
159
+ ...requestConfig
160
+ });
161
+ return res.data;
162
+ }
163
+
164
+ // src/_generated/clients/apps/appControllerUpdateApp.ts
165
+ function getAppControllerUpdateAppUrl({
166
+ appId
167
+ }) {
168
+ const app_id = appId;
169
+ const res = { method: "PATCH", url: `/v1/apps/${app_id}` };
170
+ return res;
171
+ }
172
+ async function appControllerUpdateApp({
173
+ appId,
174
+ data
175
+ }, config = {}) {
176
+ const { client: request = client, ...requestConfig } = config;
177
+ const requestData = data;
178
+ const res = await request({
179
+ method: "PATCH",
180
+ url: getAppControllerUpdateAppUrl({ appId }).url.toString(),
181
+ data: requestData,
182
+ ...requestConfig
183
+ });
184
+ return res.data;
185
+ }
186
+
187
+ // src/_generated/clients/apps/appControllerDeleteApp.ts
188
+ function getAppControllerDeleteAppUrl({
189
+ appId
190
+ }) {
191
+ const app_id = appId;
192
+ const res = { method: "DELETE", url: `/v1/apps/${app_id}` };
193
+ return res;
194
+ }
195
+ async function appControllerDeleteApp({ appId }, config = {}) {
196
+ const { client: request = client, ...requestConfig } = config;
197
+ const res = await request({
198
+ method: "DELETE",
199
+ url: getAppControllerDeleteAppUrl({ appId }).url.toString(),
200
+ ...requestConfig
201
+ });
202
+ return res.data;
203
+ }
204
+
205
+ // src/_generated/clients/apps/appControllerUpdateAppStatus.ts
206
+ function getAppControllerUpdateAppStatusUrl({
207
+ appId
208
+ }) {
209
+ const app_id = appId;
210
+ const res = { method: "PATCH", url: `/v1/apps/${app_id}/status` };
211
+ return res;
212
+ }
213
+ async function appControllerUpdateAppStatus({
214
+ appId,
215
+ data
216
+ }, config = {}) {
217
+ const { client: request = client, ...requestConfig } = config;
218
+ const requestData = data;
219
+ const res = await request({
220
+ method: "PATCH",
221
+ url: getAppControllerUpdateAppStatusUrl({ appId }).url.toString(),
222
+ data: requestData,
223
+ ...requestConfig
224
+ });
225
+ return res.data;
226
+ }
227
+
228
+ // src/_generated/clients/apps/authConfigControllerGetConfig.ts
229
+ function getAuthConfigControllerGetConfigUrl({
230
+ appId
231
+ }) {
232
+ const app_id = appId;
233
+ const res = { method: "GET", url: `/v1/apps/${app_id}/auth-config` };
234
+ return res;
235
+ }
236
+ async function authConfigControllerGetConfig({ appId }, config = {}) {
237
+ const { client: request = client, ...requestConfig } = config;
238
+ const res = await request({
239
+ method: "GET",
240
+ url: getAuthConfigControllerGetConfigUrl({ appId }).url.toString(),
241
+ ...requestConfig
242
+ });
243
+ return res.data;
244
+ }
245
+
246
+ // src/_generated/clients/apps/authConfigControllerUpdateConfig.ts
247
+ function getAuthConfigControllerUpdateConfigUrl({
248
+ appId
249
+ }) {
250
+ const app_id = appId;
251
+ const res = {
252
+ method: "PATCH",
253
+ url: `/v1/apps/${app_id}/auth-config`
254
+ };
255
+ return res;
256
+ }
257
+ async function authConfigControllerUpdateConfig({
258
+ appId,
259
+ data
260
+ }, config = {}) {
261
+ const { client: request = client, ...requestConfig } = config;
262
+ const requestData = data;
263
+ const res = await request({
264
+ method: "PATCH",
265
+ url: getAuthConfigControllerUpdateConfigUrl({ appId }).url.toString(),
266
+ data: requestData,
267
+ ...requestConfig
268
+ });
269
+ return res.data;
270
+ }
271
+
272
+ // src/_generated/clients/endUserInvites/endUserInviteControllerList.ts
273
+ function getEndUserInviteControllerListUrl({
274
+ appId
275
+ }) {
276
+ const app_id = appId;
277
+ const res = {
278
+ method: "GET",
279
+ url: `/v1/apps/${app_id}/end-users/invites`
280
+ };
281
+ return res;
282
+ }
283
+ async function endUserInviteControllerList({
284
+ appId,
285
+ params
286
+ }, config = {}) {
287
+ const { client: request = client, ...requestConfig } = config;
288
+ const res = await request({
289
+ method: "GET",
290
+ url: getEndUserInviteControllerListUrl({ appId }).url.toString(),
291
+ params,
292
+ ...requestConfig
293
+ });
294
+ return res.data;
295
+ }
296
+
297
+ // src/_generated/clients/endUserInvites/endUserInviteControllerCreate.ts
298
+ function getEndUserInviteControllerCreateUrl({
299
+ appId
300
+ }) {
301
+ const app_id = appId;
302
+ const res = {
303
+ method: "POST",
304
+ url: `/v1/apps/${app_id}/end-users/invites`
305
+ };
306
+ return res;
307
+ }
308
+ async function endUserInviteControllerCreate({
309
+ appId,
310
+ data,
311
+ headers
312
+ }, config = {}) {
313
+ const { client: request = client, ...requestConfig } = config;
314
+ const mappedHeaders = headers ? { "Idempotency-Key": headers.idempotencyKey } : void 0;
315
+ const requestData = data;
316
+ const res = await request({
317
+ method: "POST",
318
+ url: getEndUserInviteControllerCreateUrl({ appId }).url.toString(),
319
+ data: requestData,
320
+ ...requestConfig,
321
+ headers: { ...mappedHeaders, ...requestConfig.headers }
322
+ });
323
+ return res.data;
324
+ }
325
+
326
+ // src/_generated/clients/endUserInvites/endUserInviteControllerRevoke.ts
327
+ function getEndUserInviteControllerRevokeUrl({
328
+ appId,
329
+ inviteId
330
+ }) {
331
+ const app_id = appId;
332
+ const invite_id = inviteId;
333
+ const res = {
334
+ method: "DELETE",
335
+ url: `/v1/apps/${app_id}/end-users/invites/${invite_id}`
336
+ };
337
+ return res;
338
+ }
339
+ async function endUserInviteControllerRevoke({
340
+ appId,
341
+ inviteId
342
+ }, config = {}) {
343
+ const { client: request = client, ...requestConfig } = config;
344
+ const res = await request({
345
+ method: "DELETE",
346
+ url: getEndUserInviteControllerRevokeUrl({
347
+ appId,
348
+ inviteId
349
+ }).url.toString(),
350
+ ...requestConfig
351
+ });
352
+ return res.data;
353
+ }
354
+
355
+ // src/_generated/clients/apps/appControllerListMembers.ts
356
+ function getAppControllerListMembersUrl({
357
+ appId
358
+ }) {
359
+ const app_id = appId;
360
+ const res = { method: "GET", url: `/v1/apps/${app_id}/members` };
361
+ return res;
362
+ }
363
+ async function appControllerListMembers({
364
+ appId,
365
+ params
366
+ }, config = {}) {
367
+ const { client: request = client, ...requestConfig } = config;
368
+ const res = await request({
369
+ method: "GET",
370
+ url: getAppControllerListMembersUrl({ appId }).url.toString(),
371
+ params,
372
+ ...requestConfig
373
+ });
374
+ return res.data;
375
+ }
376
+
377
+ // src/_generated/clients/apps/appControllerRemoveMember.ts
378
+ function getAppControllerRemoveMemberUrl({
379
+ appId,
380
+ accountId
381
+ }) {
382
+ const app_id = appId;
383
+ const account_id = accountId;
384
+ const res = {
385
+ method: "DELETE",
386
+ url: `/v1/apps/${app_id}/members/${account_id}`
387
+ };
388
+ return res;
389
+ }
390
+ async function appControllerRemoveMember({
391
+ appId,
392
+ accountId
393
+ }, config = {}) {
394
+ const { client: request = client, ...requestConfig } = config;
395
+ const res = await request({
396
+ method: "DELETE",
397
+ url: getAppControllerRemoveMemberUrl({ appId, accountId }).url.toString(),
398
+ ...requestConfig
399
+ });
400
+ return res.data;
401
+ }
402
+
403
+ // src/_generated/clients/endUsers/endUserControllerListEndUsers.ts
404
+ function getEndUserControllerListEndUsersUrl({
405
+ appId
406
+ }) {
407
+ const app_id = appId;
408
+ const res = { method: "GET", url: `/v1/apps/${app_id}/end-users` };
409
+ return res;
410
+ }
411
+ async function endUserControllerListEndUsers({
412
+ appId,
413
+ params
414
+ }, config = {}) {
415
+ const { client: request = client, ...requestConfig } = config;
416
+ const res = await request({
417
+ method: "GET",
418
+ url: getEndUserControllerListEndUsersUrl({ appId }).url.toString(),
419
+ params,
420
+ ...requestConfig
421
+ });
422
+ return res.data;
423
+ }
424
+
425
+ // src/_generated/clients/endUsers/endUserControllerGetEndUser.ts
426
+ function getEndUserControllerGetEndUserUrl({
427
+ appId,
428
+ userId
429
+ }) {
430
+ const app_id = appId;
431
+ const user_id = userId;
432
+ const res = {
433
+ method: "GET",
434
+ url: `/v1/apps/${app_id}/end-users/${user_id}`
435
+ };
436
+ return res;
437
+ }
438
+ async function endUserControllerGetEndUser({
439
+ appId,
440
+ userId
441
+ }, config = {}) {
442
+ const { client: request = client, ...requestConfig } = config;
443
+ const res = await request({
444
+ method: "GET",
445
+ url: getEndUserControllerGetEndUserUrl({ appId, userId }).url.toString(),
446
+ ...requestConfig
447
+ });
448
+ return res.data;
449
+ }
450
+
451
+ // src/_generated/clients/endUsers/endUserControllerUpdateEndUser.ts
452
+ function getEndUserControllerUpdateEndUserUrl({
453
+ appId,
454
+ userId
455
+ }) {
456
+ const app_id = appId;
457
+ const user_id = userId;
458
+ const res = {
459
+ method: "PATCH",
460
+ url: `/v1/apps/${app_id}/end-users/${user_id}`
461
+ };
462
+ return res;
463
+ }
464
+ async function endUserControllerUpdateEndUser({
465
+ appId,
466
+ userId,
467
+ data
468
+ }, config = {}) {
469
+ const { client: request = client, ...requestConfig } = config;
470
+ const requestData = data;
471
+ const res = await request({
472
+ method: "PATCH",
473
+ url: getEndUserControllerUpdateEndUserUrl({ appId, userId }).url.toString(),
474
+ data: requestData,
475
+ ...requestConfig
476
+ });
477
+ return res.data;
478
+ }
479
+
480
+ // src/_generated/clients/endUsers/endUserControllerDeleteEndUser.ts
481
+ function getEndUserControllerDeleteEndUserUrl({
482
+ appId,
483
+ userId
484
+ }) {
485
+ const app_id = appId;
486
+ const user_id = userId;
487
+ const res = {
488
+ method: "DELETE",
489
+ url: `/v1/apps/${app_id}/end-users/${user_id}`
490
+ };
491
+ return res;
492
+ }
493
+ async function endUserControllerDeleteEndUser({
494
+ appId,
495
+ userId
496
+ }, config = {}) {
497
+ const { client: request = client, ...requestConfig } = config;
498
+ const res = await request({
499
+ method: "DELETE",
500
+ url: getEndUserControllerDeleteEndUserUrl({ appId, userId }).url.toString(),
501
+ ...requestConfig
502
+ });
503
+ return res.data;
504
+ }
505
+
506
+ // src/_generated/clients/endUsers/endUserControllerUpdateRole.ts
507
+ function getEndUserControllerUpdateRoleUrl({
508
+ appId,
509
+ userId
510
+ }) {
511
+ const app_id = appId;
512
+ const user_id = userId;
513
+ const res = {
514
+ method: "PATCH",
515
+ url: `/v1/apps/${app_id}/end-users/${user_id}/role`
516
+ };
517
+ return res;
518
+ }
519
+ async function endUserControllerUpdateRole({
520
+ appId,
521
+ userId,
522
+ data
523
+ }, config = {}) {
524
+ const { client: request = client, ...requestConfig } = config;
525
+ const requestData = data;
526
+ const res = await request({
527
+ method: "PATCH",
528
+ url: getEndUserControllerUpdateRoleUrl({ appId, userId }).url.toString(),
529
+ data: requestData,
530
+ ...requestConfig
531
+ });
532
+ return res.data;
533
+ }
534
+
535
+ // src/_generated/clients/endUsers/endUserControllerUpdateStatus.ts
536
+ function getEndUserControllerUpdateStatusUrl({
537
+ appId,
538
+ userId
539
+ }) {
540
+ const app_id = appId;
541
+ const user_id = userId;
542
+ const res = {
543
+ method: "PATCH",
544
+ url: `/v1/apps/${app_id}/end-users/${user_id}/status`
545
+ };
546
+ return res;
547
+ }
548
+ async function endUserControllerUpdateStatus({
549
+ appId,
550
+ userId,
551
+ data
552
+ }, config = {}) {
553
+ const { client: request = client, ...requestConfig } = config;
554
+ const requestData = data;
555
+ const res = await request({
556
+ method: "PATCH",
557
+ url: getEndUserControllerUpdateStatusUrl({ appId, userId }).url.toString(),
558
+ data: requestData,
559
+ ...requestConfig
560
+ });
561
+ return res.data;
562
+ }
563
+
564
+ // src/_generated/clients/roles/roleControllerListRoles.ts
565
+ function getRoleControllerListRolesUrl({
566
+ appId
567
+ }) {
568
+ const app_id = appId;
569
+ const res = { method: "GET", url: `/v1/apps/${app_id}/roles` };
570
+ return res;
571
+ }
572
+ async function roleControllerListRoles({
573
+ appId,
574
+ params
575
+ }, config = {}) {
576
+ const { client: request = client, ...requestConfig } = config;
577
+ const res = await request({
578
+ method: "GET",
579
+ url: getRoleControllerListRolesUrl({ appId }).url.toString(),
580
+ params,
581
+ ...requestConfig
582
+ });
583
+ return res.data;
584
+ }
585
+
586
+ // src/_generated/clients/roles/roleControllerCreateRole.ts
587
+ function getRoleControllerCreateRoleUrl({
588
+ appId
589
+ }) {
590
+ const app_id = appId;
591
+ const res = { method: "POST", url: `/v1/apps/${app_id}/roles` };
592
+ return res;
593
+ }
594
+ async function roleControllerCreateRole({
595
+ appId,
596
+ data
597
+ }, config = {}) {
598
+ const { client: request = client, ...requestConfig } = config;
599
+ const requestData = data;
600
+ const res = await request({
601
+ method: "POST",
602
+ url: getRoleControllerCreateRoleUrl({ appId }).url.toString(),
603
+ data: requestData,
604
+ ...requestConfig
605
+ });
606
+ return res.data;
607
+ }
608
+
609
+ // src/_generated/clients/roles/roleControllerAssignRole.ts
610
+ function getRoleControllerAssignRoleUrl({
611
+ appId
612
+ }) {
613
+ const app_id = appId;
614
+ const res = {
615
+ method: "POST",
616
+ url: `/v1/apps/${app_id}/roles/assign`
617
+ };
618
+ return res;
619
+ }
620
+ async function roleControllerAssignRole({
621
+ appId,
622
+ data
623
+ }, config = {}) {
624
+ const { client: request = client, ...requestConfig } = config;
625
+ const requestData = data;
626
+ const res = await request({
627
+ method: "POST",
628
+ url: getRoleControllerAssignRoleUrl({ appId }).url.toString(),
629
+ data: requestData,
630
+ ...requestConfig
631
+ });
632
+ return res.data;
633
+ }
634
+
635
+ // src/_generated/clients/roles/roleControllerSetPermissions.ts
636
+ function getRoleControllerSetPermissionsUrl({
637
+ appId,
638
+ roleName
639
+ }) {
640
+ const app_id = appId;
641
+ const role_name = roleName;
642
+ const res = {
643
+ method: "PUT",
644
+ url: `/v1/apps/${app_id}/roles/${role_name}/permissions`
645
+ };
646
+ return res;
647
+ }
648
+ async function roleControllerSetPermissions({
649
+ appId,
650
+ roleName,
651
+ data
652
+ }, config = {}) {
653
+ const { client: request = client, ...requestConfig } = config;
654
+ const requestData = data;
655
+ const res = await request({
656
+ method: "PUT",
657
+ url: getRoleControllerSetPermissionsUrl({ appId, roleName }).url.toString(),
658
+ data: requestData,
659
+ ...requestConfig
660
+ });
661
+ return res.data;
662
+ }
663
+
664
+ // src/_generated/clients/roles/roleControllerListPermissions.ts
665
+ function getRoleControllerListPermissionsUrl({
666
+ appId
667
+ }) {
668
+ const app_id = appId;
669
+ const res = {
670
+ method: "GET",
671
+ url: `/v1/apps/${app_id}/roles/permissions`
672
+ };
673
+ return res;
674
+ }
675
+ async function roleControllerListPermissions({ appId }, config = {}) {
676
+ const { client: request = client, ...requestConfig } = config;
677
+ const res = await request({
678
+ method: "GET",
679
+ url: getRoleControllerListPermissionsUrl({ appId }).url.toString(),
680
+ ...requestConfig
681
+ });
682
+ return res.data;
683
+ }
684
+
685
+ // src/_generated/clients/permissions/permissionControllerListPermissions.ts
686
+ function getPermissionControllerListPermissionsUrl({
687
+ appId
688
+ }) {
689
+ const app_id = appId;
690
+ const res = { method: "GET", url: `/v1/apps/${app_id}/permissions` };
691
+ return res;
692
+ }
693
+ async function permissionControllerListPermissions({ appId }, config = {}) {
694
+ const { client: request = client, ...requestConfig } = config;
695
+ const res = await request({
696
+ method: "GET",
697
+ url: getPermissionControllerListPermissionsUrl({ appId }).url.toString(),
698
+ ...requestConfig
699
+ });
700
+ return res.data;
701
+ }
702
+
703
+ // src/_generated/clients/permissions/permissionControllerCreatePermission.ts
704
+ function getPermissionControllerCreatePermissionUrl({
705
+ appId
706
+ }) {
707
+ const app_id = appId;
708
+ const res = {
709
+ method: "POST",
710
+ url: `/v1/apps/${app_id}/permissions`
711
+ };
712
+ return res;
713
+ }
714
+ async function permissionControllerCreatePermission({
715
+ appId,
716
+ data
717
+ }, config = {}) {
718
+ const { client: request = client, ...requestConfig } = config;
719
+ const requestData = data;
720
+ const res = await request({
721
+ method: "POST",
722
+ url: getPermissionControllerCreatePermissionUrl({ appId }).url.toString(),
723
+ data: requestData,
724
+ ...requestConfig
725
+ });
726
+ return res.data;
727
+ }
728
+
729
+ // src/_generated/clients/permissions/permissionControllerDeletePermission.ts
730
+ function getPermissionControllerDeletePermissionUrl({
731
+ appId,
732
+ permissionKey
733
+ }) {
734
+ const app_id = appId;
735
+ const permission_key = permissionKey;
736
+ const res = {
737
+ method: "DELETE",
738
+ url: `/v1/apps/${app_id}/permissions/${permission_key}`
739
+ };
740
+ return res;
741
+ }
742
+ async function permissionControllerDeletePermission({
743
+ appId,
744
+ permissionKey
745
+ }, config = {}) {
746
+ const { client: request = client, ...requestConfig } = config;
747
+ const res = await request({
748
+ method: "DELETE",
749
+ url: getPermissionControllerDeletePermissionUrl({
750
+ appId,
751
+ permissionKey
752
+ }).url.toString(),
753
+ ...requestConfig
754
+ });
755
+ return res.data;
756
+ }
757
+
758
+ // src/_generated/clients/apiKeys/apiKeyControllerListApiKeys.ts
759
+ function getApiKeyControllerListApiKeysUrl({
760
+ appId
761
+ }) {
762
+ const app_id = appId;
763
+ const res = { method: "GET", url: `/v1/apps/${app_id}/api-keys` };
764
+ return res;
765
+ }
766
+ async function apiKeyControllerListApiKeys({ appId }, config = {}) {
767
+ const { client: request = client, ...requestConfig } = config;
768
+ const res = await request({
769
+ method: "GET",
770
+ url: getApiKeyControllerListApiKeysUrl({ appId }).url.toString(),
771
+ ...requestConfig
772
+ });
773
+ return res.data;
774
+ }
775
+
776
+ // src/_generated/clients/apiKeys/apiKeyControllerCreateApiKey.ts
777
+ function getApiKeyControllerCreateApiKeyUrl({
778
+ appId
779
+ }) {
780
+ const app_id = appId;
781
+ const res = { method: "POST", url: `/v1/apps/${app_id}/api-keys` };
782
+ return res;
783
+ }
784
+ async function apiKeyControllerCreateApiKey({
785
+ appId,
786
+ data,
787
+ headers
788
+ }, config = {}) {
789
+ const { client: request = client, ...requestConfig } = config;
790
+ const mappedHeaders = headers ? { "Idempotency-Key": headers.idempotencyKey } : void 0;
791
+ const requestData = data;
792
+ const res = await request({
793
+ method: "POST",
794
+ url: getApiKeyControllerCreateApiKeyUrl({ appId }).url.toString(),
795
+ data: requestData,
796
+ ...requestConfig,
797
+ headers: { ...mappedHeaders, ...requestConfig.headers }
798
+ });
799
+ return res.data;
800
+ }
801
+
802
+ // src/_generated/clients/apiKeys/apiKeyControllerDeleteApiKey.ts
803
+ function getApiKeyControllerDeleteApiKeyUrl({
804
+ appId,
805
+ keyId
806
+ }) {
807
+ const app_id = appId;
808
+ const key_id = keyId;
809
+ const res = {
810
+ method: "DELETE",
811
+ url: `/v1/apps/${app_id}/api-keys/${key_id}`
812
+ };
813
+ return res;
814
+ }
815
+ async function apiKeyControllerDeleteApiKey({
816
+ appId,
817
+ keyId
818
+ }, config = {}) {
819
+ const { client: request = client, ...requestConfig } = config;
820
+ const res = await request({
821
+ method: "DELETE",
822
+ url: getApiKeyControllerDeleteApiKeyUrl({ appId, keyId }).url.toString(),
823
+ ...requestConfig
824
+ });
825
+ return res.data;
826
+ }
827
+
828
+ // src/_generated/clients/credentials/M2MControllerListClients.ts
829
+ function getM2MControllerListClientsUrl({
830
+ appId
831
+ }) {
832
+ const app_id = appId;
833
+ const res = { method: "GET", url: `/v1/apps/${app_id}/credentials` };
834
+ return res;
835
+ }
836
+ async function M2MControllerListClients({
837
+ appId,
838
+ params
839
+ }, config = {}) {
840
+ const { client: request = client, ...requestConfig } = config;
841
+ const res = await request({
842
+ method: "GET",
843
+ url: getM2MControllerListClientsUrl({ appId }).url.toString(),
844
+ params,
845
+ ...requestConfig
846
+ });
847
+ return res.data;
848
+ }
849
+
850
+ // src/_generated/clients/credentials/M2MControllerCreateClient.ts
851
+ function getM2MControllerCreateClientUrl({
852
+ appId
853
+ }) {
854
+ const app_id = appId;
855
+ const res = {
856
+ method: "POST",
857
+ url: `/v1/apps/${app_id}/credentials`
858
+ };
859
+ return res;
860
+ }
861
+ async function M2MControllerCreateClient({
862
+ appId,
863
+ data,
864
+ headers
865
+ }, config = {}) {
866
+ const { client: request = client, ...requestConfig } = config;
867
+ const mappedHeaders = headers ? { "Idempotency-Key": headers.idempotencyKey } : void 0;
868
+ const requestData = data;
869
+ const res = await request({
870
+ method: "POST",
871
+ url: getM2MControllerCreateClientUrl({ appId }).url.toString(),
872
+ data: requestData,
873
+ ...requestConfig,
874
+ headers: { ...mappedHeaders, ...requestConfig.headers }
875
+ });
876
+ return res.data;
877
+ }
878
+
879
+ // src/_generated/clients/credentials/M2MControllerGetClient.ts
880
+ function getM2MControllerGetClientUrl({
881
+ appId,
882
+ clientId
883
+ }) {
884
+ const app_id = appId;
885
+ const client_id = clientId;
886
+ const res = {
887
+ method: "GET",
888
+ url: `/v1/apps/${app_id}/credentials/${client_id}`
889
+ };
890
+ return res;
891
+ }
892
+ async function M2MControllerGetClient({
893
+ appId,
894
+ clientId
895
+ }, config = {}) {
896
+ const { client: request = client, ...requestConfig } = config;
897
+ const res = await request({
898
+ method: "GET",
899
+ url: getM2MControllerGetClientUrl({ appId, clientId }).url.toString(),
900
+ ...requestConfig
901
+ });
902
+ return res.data;
903
+ }
904
+
905
+ // src/_generated/clients/credentials/M2MControllerUpdateClient.ts
906
+ function getM2MControllerUpdateClientUrl({
907
+ appId,
908
+ clientId
909
+ }) {
910
+ const app_id = appId;
911
+ const client_id = clientId;
912
+ const res = {
913
+ method: "PATCH",
914
+ url: `/v1/apps/${app_id}/credentials/${client_id}`
915
+ };
916
+ return res;
917
+ }
918
+ async function M2MControllerUpdateClient({
919
+ appId,
920
+ clientId,
921
+ data
922
+ }, config = {}) {
923
+ const { client: request = client, ...requestConfig } = config;
924
+ const requestData = data;
925
+ const res = await request({
926
+ method: "PATCH",
927
+ url: getM2MControllerUpdateClientUrl({ appId, clientId }).url.toString(),
928
+ data: requestData,
929
+ ...requestConfig
930
+ });
931
+ return res.data;
932
+ }
933
+
934
+ // src/_generated/clients/credentials/M2MControllerDeleteClient.ts
935
+ function getM2MControllerDeleteClientUrl({
936
+ appId,
937
+ clientId
938
+ }) {
939
+ const app_id = appId;
940
+ const client_id = clientId;
941
+ const res = {
942
+ method: "DELETE",
943
+ url: `/v1/apps/${app_id}/credentials/${client_id}`
944
+ };
945
+ return res;
946
+ }
947
+ async function M2MControllerDeleteClient({
948
+ appId,
949
+ clientId
950
+ }, config = {}) {
951
+ const { client: request = client, ...requestConfig } = config;
952
+ const res = await request({
953
+ method: "DELETE",
954
+ url: getM2MControllerDeleteClientUrl({ appId, clientId }).url.toString(),
955
+ ...requestConfig
956
+ });
957
+ return res.data;
958
+ }
959
+
960
+ // src/_generated/clients/credentials/M2MControllerRotateSecret.ts
961
+ function getM2MControllerRotateSecretUrl({
962
+ appId,
963
+ clientId
964
+ }) {
965
+ const app_id = appId;
966
+ const client_id = clientId;
967
+ const res = {
968
+ method: "POST",
969
+ url: `/v1/apps/${app_id}/credentials/${client_id}/rotate`
970
+ };
971
+ return res;
972
+ }
973
+ async function M2MControllerRotateSecret({
974
+ appId,
975
+ clientId
976
+ }, config = {}) {
977
+ const { client: request = client, ...requestConfig } = config;
978
+ const res = await request({
979
+ method: "POST",
980
+ url: getM2MControllerRotateSecretUrl({ appId, clientId }).url.toString(),
981
+ ...requestConfig
982
+ });
983
+ return res.data;
984
+ }
985
+
986
+ // src/_generated/clients/credentials/M2MControllerSetScopes.ts
987
+ function getM2MControllerSetScopesUrl({
988
+ appId,
989
+ clientId
990
+ }) {
991
+ const app_id = appId;
992
+ const client_id = clientId;
993
+ const res = {
994
+ method: "PUT",
995
+ url: `/v1/apps/${app_id}/credentials/${client_id}/scopes`
996
+ };
997
+ return res;
998
+ }
999
+ async function M2MControllerSetScopes({
1000
+ appId,
1001
+ clientId,
1002
+ data
1003
+ }, config = {}) {
1004
+ const { client: request = client, ...requestConfig } = config;
1005
+ const requestData = data;
1006
+ const res = await request({
1007
+ method: "PUT",
1008
+ url: getM2MControllerSetScopesUrl({ appId, clientId }).url.toString(),
1009
+ data: requestData,
1010
+ ...requestConfig
1011
+ });
1012
+ return res.data;
1013
+ }
1014
+
1015
+ // src/_generated/clients/appAudit/appAuditControllerGetAuditLogs.ts
1016
+ function getAppAuditControllerGetAuditLogsUrl({
1017
+ appId
1018
+ }) {
1019
+ const app_id = appId;
1020
+ const res = { method: "GET", url: `/v1/apps/${app_id}/audit-logs` };
1021
+ return res;
1022
+ }
1023
+ async function appAuditControllerGetAuditLogs({
1024
+ appId,
1025
+ params
1026
+ }, config = {}) {
1027
+ const { client: request = client, ...requestConfig } = config;
1028
+ const mappedParams = params ? {
1029
+ limit: params.limit,
1030
+ cursor: params.cursor,
1031
+ action: params.action,
1032
+ actor_id: params.actorId
1033
+ } : void 0;
1034
+ const res = await request({
1035
+ method: "GET",
1036
+ url: getAppAuditControllerGetAuditLogsUrl({ appId }).url.toString(),
1037
+ params: mappedParams,
1038
+ ...requestConfig
1039
+ });
1040
+ return res.data;
1041
+ }
1042
+
1043
+ // src/scopes/app.ts
1044
+ var AppScope = class {
1045
+ /** The appId bound to this scope. */
1046
+ appId;
1047
+ client;
1048
+ constructor(appId, client2) {
1049
+ this.appId = appId;
1050
+ this.client = client2;
1051
+ }
1052
+ /**
1053
+ * Direct HTTP escape hatch used to call endpoints whose spec is buggy
1054
+ * — currently those whose path declares `{appId}` but whose
1055
+ * `parameters[]` omits it, so the kubb-generated code leaves the
1056
+ * URL template unfilled. Tracked upstream; remove once the spec is
1057
+ * fixed and the per-call wrappers can move back to kubb's output.
1058
+ */
1059
+ async callDirect(method, url, body) {
1060
+ const res = await this.client({ method, url, data: body });
1061
+ return res.data;
1062
+ }
1063
+ // ─────────────────────────────────────────────────────────────
1064
+ // App meta — operations on the app record itself
1065
+ // ─────────────────────────────────────────────────────────────
1066
+ get = () => appControllerGetApp({ appId: this.appId }, { client: this.client });
1067
+ update = (data) => appControllerUpdateApp({ appId: this.appId, data }, { client: this.client });
1068
+ delete = () => appControllerDeleteApp({ appId: this.appId }, { client: this.client });
1069
+ updateStatus = (data) => appControllerUpdateAppStatus(
1070
+ { appId: this.appId, data },
1071
+ { client: this.client }
1072
+ );
1073
+ // ─────────────────────────────────────────────────────────────
1074
+ // Auth config (workspace-side config for the app's auth surface)
1075
+ // ─────────────────────────────────────────────────────────────
1076
+ authConfig = {
1077
+ get: () => authConfigControllerGetConfig(
1078
+ { appId: this.appId },
1079
+ { client: this.client }
1080
+ ),
1081
+ update: (data) => authConfigControllerUpdateConfig(
1082
+ { appId: this.appId, data },
1083
+ { client: this.client }
1084
+ )
1085
+ };
1086
+ // ─────────────────────────────────────────────────────────────
1087
+ // End-user invites (invite EndUsers into this app)
1088
+ // ─────────────────────────────────────────────────────────────
1089
+ invites = {
1090
+ list: (params = {}) => endUserInviteControllerList(
1091
+ { appId: this.appId, params },
1092
+ { client: this.client }
1093
+ ),
1094
+ create: (data) => endUserInviteControllerCreate(
1095
+ { appId: this.appId, data },
1096
+ { client: this.client }
1097
+ ),
1098
+ revoke: (inviteId) => endUserInviteControllerRevoke(
1099
+ { appId: this.appId, inviteId },
1100
+ { client: this.client }
1101
+ )
1102
+ };
1103
+ // ─────────────────────────────────────────────────────────────
1104
+ // Members (workspace seats on this app)
1105
+ // ─────────────────────────────────────────────────────────────
1106
+ members = {
1107
+ list: (params = {}) => appControllerListMembers(
1108
+ { appId: this.appId, params },
1109
+ { client: this.client }
1110
+ ),
1111
+ remove: (accountId) => appControllerRemoveMember(
1112
+ { appId: this.appId, accountId },
1113
+ { client: this.client }
1114
+ )
1115
+ };
1116
+ // ─────────────────────────────────────────────────────────────
1117
+ // EndUsers (the app's authenticated users — Auth's bread + butter)
1118
+ // ─────────────────────────────────────────────────────────────
1119
+ endUsers = {
1120
+ list: (params = {}) => endUserControllerListEndUsers(
1121
+ { appId: this.appId, params },
1122
+ { client: this.client }
1123
+ ),
1124
+ get: (userId) => endUserControllerGetEndUser(
1125
+ { appId: this.appId, userId },
1126
+ { client: this.client }
1127
+ ),
1128
+ update: (userId, data) => endUserControllerUpdateEndUser(
1129
+ { appId: this.appId, userId, data },
1130
+ { client: this.client }
1131
+ ),
1132
+ delete: (userId) => endUserControllerDeleteEndUser(
1133
+ { appId: this.appId, userId },
1134
+ { client: this.client }
1135
+ ),
1136
+ updateRole: (userId, data) => endUserControllerUpdateRole(
1137
+ { appId: this.appId, userId, data },
1138
+ { client: this.client }
1139
+ ),
1140
+ updateStatus: (userId, data) => endUserControllerUpdateStatus(
1141
+ { appId: this.appId, userId, data },
1142
+ { client: this.client }
1143
+ ),
1144
+ /** Spec bug: appId missing in spec params (see callDirect). */
1145
+ revokeAllSessions: (userId) => this.callDirect(
1146
+ "POST",
1147
+ `/v1/apps/${this.appId}/end-users/${userId}/sessions/revoke-all`
1148
+ )
1149
+ };
1150
+ // ─────────────────────────────────────────────────────────────
1151
+ // Roles
1152
+ // ─────────────────────────────────────────────────────────────
1153
+ roles = {
1154
+ list: (params = {}) => roleControllerListRoles(
1155
+ { appId: this.appId, params },
1156
+ { client: this.client }
1157
+ ),
1158
+ /** Spec bug: appId missing in spec params (see callDirect). */
1159
+ get: (roleName) => this.callDirect("GET", `/v1/apps/${this.appId}/roles/${roleName}`),
1160
+ create: (data) => roleControllerCreateRole(
1161
+ { appId: this.appId, data },
1162
+ { client: this.client }
1163
+ ),
1164
+ /** Spec bug: appId missing in spec params (see callDirect). */
1165
+ update: (roleName, data) => this.callDirect(
1166
+ "PATCH",
1167
+ `/v1/apps/${this.appId}/roles/${roleName}`,
1168
+ data
1169
+ ),
1170
+ /** Spec bug: appId missing in spec params (see callDirect). */
1171
+ delete: (roleName) => this.callDirect("DELETE", `/v1/apps/${this.appId}/roles/${roleName}`),
1172
+ assign: (data) => roleControllerAssignRole(
1173
+ { appId: this.appId, data },
1174
+ { client: this.client }
1175
+ ),
1176
+ setPermissions: (roleName, data) => roleControllerSetPermissions(
1177
+ { appId: this.appId, roleName, data },
1178
+ { client: this.client }
1179
+ ),
1180
+ listPermissions: () => roleControllerListPermissions(
1181
+ { appId: this.appId },
1182
+ { client: this.client }
1183
+ )
1184
+ };
1185
+ // ─────────────────────────────────────────────────────────────
1186
+ // Permissions catalog
1187
+ // ─────────────────────────────────────────────────────────────
1188
+ permissions = {
1189
+ list: () => permissionControllerListPermissions(
1190
+ { appId: this.appId },
1191
+ { client: this.client }
1192
+ ),
1193
+ create: (data) => permissionControllerCreatePermission(
1194
+ { appId: this.appId, data },
1195
+ { client: this.client }
1196
+ ),
1197
+ delete: (permissionKey) => permissionControllerDeletePermission(
1198
+ { appId: this.appId, permissionKey },
1199
+ { client: this.client }
1200
+ )
1201
+ };
1202
+ // ─────────────────────────────────────────────────────────────
1203
+ // API keys (server-to-server platform keys for this app)
1204
+ // ─────────────────────────────────────────────────────────────
1205
+ apiKeys = {
1206
+ list: () => apiKeyControllerListApiKeys(
1207
+ { appId: this.appId },
1208
+ { client: this.client }
1209
+ ),
1210
+ create: (data) => apiKeyControllerCreateApiKey(
1211
+ { appId: this.appId, data },
1212
+ { client: this.client }
1213
+ ),
1214
+ delete: (keyId) => apiKeyControllerDeleteApiKey(
1215
+ { appId: this.appId, keyId },
1216
+ { client: this.client }
1217
+ )
1218
+ };
1219
+ // ─────────────────────────────────────────────────────────────
1220
+ // M2M credentials (client_id + client_secret for service-to-service)
1221
+ // ─────────────────────────────────────────────────────────────
1222
+ credentials = {
1223
+ list: (params = {}) => M2MControllerListClients(
1224
+ { appId: this.appId, params },
1225
+ { client: this.client }
1226
+ ),
1227
+ create: (data) => M2MControllerCreateClient(
1228
+ { appId: this.appId, data },
1229
+ { client: this.client }
1230
+ ),
1231
+ get: (clientId) => M2MControllerGetClient(
1232
+ { appId: this.appId, clientId },
1233
+ { client: this.client }
1234
+ ),
1235
+ update: (clientId, data) => M2MControllerUpdateClient(
1236
+ { appId: this.appId, clientId, data },
1237
+ { client: this.client }
1238
+ ),
1239
+ delete: (clientId) => M2MControllerDeleteClient(
1240
+ { appId: this.appId, clientId },
1241
+ { client: this.client }
1242
+ ),
1243
+ rotateSecret: (clientId) => M2MControllerRotateSecret(
1244
+ { appId: this.appId, clientId },
1245
+ { client: this.client }
1246
+ ),
1247
+ setScopes: (clientId, data) => M2MControllerSetScopes(
1248
+ { appId: this.appId, clientId, data },
1249
+ { client: this.client }
1250
+ )
1251
+ };
1252
+ // ─────────────────────────────────────────────────────────────
1253
+ // Audit logs
1254
+ // ─────────────────────────────────────────────────────────────
1255
+ auditLogs = {
1256
+ list: (params = {}) => appAuditControllerGetAuditLogs(
1257
+ { appId: this.appId, params },
1258
+ { client: this.client }
1259
+ )
1260
+ };
1261
+ };
1262
+
1263
+ // src/_generated/clients/consumerAuth/consumerAuthControllerSignin.ts
1264
+ function getConsumerAuthControllerSigninUrl({
1265
+ appSlug
1266
+ }) {
1267
+ const app_slug = appSlug;
1268
+ const res = { method: "POST", url: `/${app_slug}/v1/auth/signin` };
1269
+ return res;
1270
+ }
1271
+ async function consumerAuthControllerSignin({
1272
+ appSlug,
1273
+ data
1274
+ }, config = {}) {
1275
+ const { client: request = client, ...requestConfig } = config;
1276
+ const requestData = data;
1277
+ const res = await request({
1278
+ method: "POST",
1279
+ url: getConsumerAuthControllerSigninUrl({ appSlug }).url.toString(),
1280
+ data: requestData,
1281
+ ...requestConfig
1282
+ });
1283
+ return res.data;
1284
+ }
1285
+
1286
+ // src/_generated/clients/consumerAuth/consumerAuthControllerRefresh.ts
1287
+ function getConsumerAuthControllerRefreshUrl({
1288
+ appSlug
1289
+ }) {
1290
+ const app_slug = appSlug;
1291
+ const res = { method: "POST", url: `/${app_slug}/v1/auth/refresh` };
1292
+ return res;
1293
+ }
1294
+ async function consumerAuthControllerRefresh({
1295
+ appSlug,
1296
+ data
1297
+ }, config = {}) {
1298
+ const { client: request = client, ...requestConfig } = config;
1299
+ const requestData = data;
1300
+ const res = await request({
1301
+ method: "POST",
1302
+ url: getConsumerAuthControllerRefreshUrl({ appSlug }).url.toString(),
1303
+ data: requestData,
1304
+ ...requestConfig
1305
+ });
1306
+ return res.data;
1307
+ }
1308
+
1309
+ // src/_generated/clients/consumerAuth/consumerAuthControllerLogout.ts
1310
+ function getConsumerAuthControllerLogoutUrl({
1311
+ appSlug
1312
+ }) {
1313
+ const app_slug = appSlug;
1314
+ const res = { method: "POST", url: `/${app_slug}/v1/auth/logout` };
1315
+ return res;
1316
+ }
1317
+ async function consumerAuthControllerLogout({
1318
+ appSlug,
1319
+ data
1320
+ }, config = {}) {
1321
+ const { client: request = client, ...requestConfig } = config;
1322
+ const requestData = data;
1323
+ const res = await request({
1324
+ method: "POST",
1325
+ url: getConsumerAuthControllerLogoutUrl({ appSlug }).url.toString(),
1326
+ data: requestData,
1327
+ ...requestConfig
1328
+ });
1329
+ return res.data;
1330
+ }
1331
+
1332
+ // src/_generated/clients/consumerAuth/consumerAuthControllerRequestPasswordReset.ts
1333
+ function getConsumerAuthControllerRequestPasswordResetUrl({
1334
+ appSlug
1335
+ }) {
1336
+ const app_slug = appSlug;
1337
+ const res = {
1338
+ method: "POST",
1339
+ url: `/${app_slug}/v1/auth/request-password-reset`
1340
+ };
1341
+ return res;
1342
+ }
1343
+ async function consumerAuthControllerRequestPasswordReset({
1344
+ appSlug,
1345
+ data,
1346
+ headers
1347
+ }, config = {}) {
1348
+ const { client: request = client, ...requestConfig } = config;
1349
+ const requestData = data;
1350
+ const res = await request({
1351
+ method: "POST",
1352
+ url: getConsumerAuthControllerRequestPasswordResetUrl({
1353
+ appSlug
1354
+ }).url.toString(),
1355
+ data: requestData,
1356
+ ...requestConfig,
1357
+ headers: { ...headers, ...requestConfig.headers }
1358
+ });
1359
+ return res.data;
1360
+ }
1361
+
1362
+ // src/_generated/clients/consumerAuth/consumerAuthControllerResetPassword.ts
1363
+ function getConsumerAuthControllerResetPasswordUrl({
1364
+ appSlug
1365
+ }) {
1366
+ const app_slug = appSlug;
1367
+ const res = {
1368
+ method: "POST",
1369
+ url: `/${app_slug}/v1/auth/reset-password`
1370
+ };
1371
+ return res;
1372
+ }
1373
+ async function consumerAuthControllerResetPassword({
1374
+ appSlug,
1375
+ data
1376
+ }, config = {}) {
1377
+ const { client: request = client, ...requestConfig } = config;
1378
+ const requestData = data;
1379
+ const res = await request({
1380
+ method: "POST",
1381
+ url: getConsumerAuthControllerResetPasswordUrl({ appSlug }).url.toString(),
1382
+ data: requestData,
1383
+ ...requestConfig
1384
+ });
1385
+ return res.data;
1386
+ }
1387
+
1388
+ // src/_generated/clients/consumerAuth/consumerAuthControllerRequestVerification.ts
1389
+ function getConsumerAuthControllerRequestVerificationUrl({
1390
+ appSlug
1391
+ }) {
1392
+ const app_slug = appSlug;
1393
+ const res = {
1394
+ method: "POST",
1395
+ url: `/${app_slug}/v1/auth/request-verification`
1396
+ };
1397
+ return res;
1398
+ }
1399
+ async function consumerAuthControllerRequestVerification({
1400
+ appSlug,
1401
+ data,
1402
+ headers
1403
+ }, config = {}) {
1404
+ const { client: request = client, ...requestConfig } = config;
1405
+ const requestData = data;
1406
+ const res = await request({
1407
+ method: "POST",
1408
+ url: getConsumerAuthControllerRequestVerificationUrl({
1409
+ appSlug
1410
+ }).url.toString(),
1411
+ data: requestData,
1412
+ ...requestConfig,
1413
+ headers: { ...headers, ...requestConfig.headers }
1414
+ });
1415
+ return res.data;
1416
+ }
1417
+
1418
+ // src/_generated/clients/consumerAuth/consumerAuthControllerSendVerificationEmail.ts
1419
+ function getConsumerAuthControllerSendVerificationEmailUrl({
1420
+ appSlug
1421
+ }) {
1422
+ const app_slug = appSlug;
1423
+ const res = {
1424
+ method: "POST",
1425
+ url: `/${app_slug}/v1/auth/send-verification-email`
1426
+ };
1427
+ return res;
1428
+ }
1429
+ async function consumerAuthControllerSendVerificationEmail({
1430
+ appSlug,
1431
+ data,
1432
+ headers
1433
+ }, config = {}) {
1434
+ const { client: request = client, ...requestConfig } = config;
1435
+ const requestData = data;
1436
+ const res = await request({
1437
+ method: "POST",
1438
+ url: getConsumerAuthControllerSendVerificationEmailUrl({
1439
+ appSlug
1440
+ }).url.toString(),
1441
+ data: requestData,
1442
+ ...requestConfig,
1443
+ headers: { ...headers, ...requestConfig.headers }
1444
+ });
1445
+ return res.data;
1446
+ }
1447
+
1448
+ // src/_generated/clients/consumerAuth/consumerAuthControllerVerify.ts
1449
+ function getConsumerAuthControllerVerifyUrl({
1450
+ appSlug
1451
+ }) {
1452
+ const app_slug = appSlug;
1453
+ const res = { method: "POST", url: `/${app_slug}/v1/auth/verify` };
1454
+ return res;
1455
+ }
1456
+ async function consumerAuthControllerVerify({
1457
+ appSlug,
1458
+ data
1459
+ }, config = {}) {
1460
+ const { client: request = client, ...requestConfig } = config;
1461
+ const requestData = data;
1462
+ const res = await request({
1463
+ method: "POST",
1464
+ url: getConsumerAuthControllerVerifyUrl({ appSlug }).url.toString(),
1465
+ data: requestData,
1466
+ ...requestConfig
1467
+ });
1468
+ return res.data;
1469
+ }
1470
+
1471
+ // src/_generated/clients/consumerAuth/consumerAuthControllerAcceptInvite.ts
1472
+ function getConsumerAuthControllerAcceptInviteUrl({
1473
+ appSlug
1474
+ }) {
1475
+ const app_slug = appSlug;
1476
+ const res = {
1477
+ method: "POST",
1478
+ url: `/${app_slug}/v1/auth/accept-invite`
1479
+ };
1480
+ return res;
1481
+ }
1482
+ async function consumerAuthControllerAcceptInvite({
1483
+ appSlug,
1484
+ data
1485
+ }, config = {}) {
1486
+ const { client: request = client, ...requestConfig } = config;
1487
+ const requestData = data;
1488
+ const res = await request({
1489
+ method: "POST",
1490
+ url: getConsumerAuthControllerAcceptInviteUrl({ appSlug }).url.toString(),
1491
+ data: requestData,
1492
+ ...requestConfig
1493
+ });
1494
+ return res.data;
1495
+ }
1496
+
1497
+ // src/_generated/clients/consumerOauthSignIn/consumerIdpControllerNativeSignIn.ts
1498
+ function getConsumerIdpControllerNativeSignInUrl({
1499
+ appSlug,
1500
+ provider
1501
+ }) {
1502
+ const app_slug = appSlug;
1503
+ const res = {
1504
+ method: "POST",
1505
+ url: `/${app_slug}/v1/auth/oauth/${provider}`
1506
+ };
1507
+ return res;
1508
+ }
1509
+ async function consumerIdpControllerNativeSignIn({
1510
+ appSlug,
1511
+ provider,
1512
+ data
1513
+ }, config = {}) {
1514
+ const { client: request = client, ...requestConfig } = config;
1515
+ const requestData = data;
1516
+ const res = await request({
1517
+ method: "POST",
1518
+ url: getConsumerIdpControllerNativeSignInUrl({
1519
+ appSlug,
1520
+ provider
1521
+ }).url.toString(),
1522
+ data: requestData,
1523
+ ...requestConfig
1524
+ });
1525
+ return res.data;
1526
+ }
1527
+
1528
+ // src/_generated/clients/consumerVerify/consumerVerifyControllerVerify.ts
1529
+ function getConsumerVerifyControllerVerifyUrl({
1530
+ appSlug
1531
+ }) {
1532
+ const app_slug = appSlug;
1533
+ const res = { method: "POST", url: `/${app_slug}/v1/verify` };
1534
+ return res;
1535
+ }
1536
+ async function consumerVerifyControllerVerify({
1537
+ appSlug,
1538
+ data,
1539
+ headers
1540
+ }, config = {}) {
1541
+ const { client: request = client, ...requestConfig } = config;
1542
+ const requestData = data;
1543
+ const res = await request({
1544
+ method: "POST",
1545
+ url: getConsumerVerifyControllerVerifyUrl({ appSlug }).url.toString(),
1546
+ data: requestData,
1547
+ ...requestConfig,
1548
+ headers: { ...headers, ...requestConfig.headers }
1549
+ });
1550
+ return res.data;
1551
+ }
1552
+
1553
+ // src/_generated/clients/consumerVerify/consumerVerifyControllerAuthorize.ts
1554
+ function getConsumerVerifyControllerAuthorizeUrl({
1555
+ appSlug
1556
+ }) {
1557
+ const app_slug = appSlug;
1558
+ const res = { method: "POST", url: `/${app_slug}/v1/authorize` };
1559
+ return res;
1560
+ }
1561
+ async function consumerVerifyControllerAuthorize({
1562
+ appSlug,
1563
+ data,
1564
+ headers
1565
+ }, config = {}) {
1566
+ const { client: request = client, ...requestConfig } = config;
1567
+ const requestData = data;
1568
+ const res = await request({
1569
+ method: "POST",
1570
+ url: getConsumerVerifyControllerAuthorizeUrl({ appSlug }).url.toString(),
1571
+ data: requestData,
1572
+ ...requestConfig,
1573
+ headers: { ...headers, ...requestConfig.headers }
1574
+ });
1575
+ return res.data;
1576
+ }
1577
+
1578
+ // src/_generated/clients/consumerVerify/consumerVerifyControllerAuthorizeBatch.ts
1579
+ function getConsumerVerifyControllerAuthorizeBatchUrl({
1580
+ appSlug
1581
+ }) {
1582
+ const app_slug = appSlug;
1583
+ const res = {
1584
+ method: "POST",
1585
+ url: `/${app_slug}/v1/authorize/batch`
1586
+ };
1587
+ return res;
1588
+ }
1589
+ async function consumerVerifyControllerAuthorizeBatch({
1590
+ appSlug,
1591
+ data,
1592
+ headers
1593
+ }, config = {}) {
1594
+ const { client: request = client, ...requestConfig } = config;
1595
+ const requestData = data;
1596
+ const res = await request({
1597
+ method: "POST",
1598
+ url: getConsumerVerifyControllerAuthorizeBatchUrl({
1599
+ appSlug
1600
+ }).url.toString(),
1601
+ data: requestData,
1602
+ ...requestConfig,
1603
+ headers: { ...headers, ...requestConfig.headers }
1604
+ });
1605
+ return res.data;
1606
+ }
1607
+
1608
+ // src/_generated/clients/consumerOauthM2m/consumerOAuthControllerClientCredentials.ts
1609
+ function getConsumerOAuthControllerClientCredentialsUrl({
1610
+ appSlug
1611
+ }) {
1612
+ const app_slug = appSlug;
1613
+ const res = { method: "POST", url: `/${app_slug}/v1/oauth/token` };
1614
+ return res;
1615
+ }
1616
+ async function consumerOAuthControllerClientCredentials({
1617
+ appSlug,
1618
+ data
1619
+ }, config = {}) {
1620
+ const { client: request = client, ...requestConfig } = config;
1621
+ const requestData = data;
1622
+ const res = await request({
1623
+ method: "POST",
1624
+ url: getConsumerOAuthControllerClientCredentialsUrl({
1625
+ appSlug
1626
+ }).url.toString(),
1627
+ data: requestData,
1628
+ ...requestConfig
1629
+ });
1630
+ return res.data;
1631
+ }
1632
+
1633
+ // src/jwt/errors.ts
1634
+ var JwtVerifyError = class extends Error {
1635
+ code;
1636
+ constructor(code, message, options) {
1637
+ super(message, options);
1638
+ this.name = "JwtVerifyError";
1639
+ this.code = code;
1640
+ }
1641
+ };
1642
+ var JwtInvalidError = class extends JwtVerifyError {
1643
+ constructor(message, options) {
1644
+ super("ERR_JWT_INVALID", message, options);
1645
+ this.name = "JwtInvalidError";
1646
+ }
1647
+ };
1648
+ var JwtExpiredError = class extends JwtVerifyError {
1649
+ expiredAt;
1650
+ constructor(message, expiredAt, options) {
1651
+ super("ERR_JWT_EXPIRED", message, options);
1652
+ this.name = "JwtExpiredError";
1653
+ this.expiredAt = expiredAt;
1654
+ }
1655
+ };
1656
+ var JwtNotYetValidError = class extends JwtVerifyError {
1657
+ constructor(message, options) {
1658
+ super("ERR_JWT_NOT_YET_VALID", message, options);
1659
+ this.name = "JwtNotYetValidError";
1660
+ }
1661
+ };
1662
+ var JwtIssuerMismatchError = class extends JwtVerifyError {
1663
+ constructor(message, options) {
1664
+ super("ERR_JWT_ISS_MISMATCH", message, options);
1665
+ this.name = "JwtIssuerMismatchError";
1666
+ }
1667
+ };
1668
+ var JwtAudienceMismatchError = class extends JwtVerifyError {
1669
+ constructor(message, options) {
1670
+ super("ERR_JWT_AUD_MISMATCH", message, options);
1671
+ this.name = "JwtAudienceMismatchError";
1672
+ }
1673
+ };
1674
+ var JwksKeyNotFoundError = class extends JwtVerifyError {
1675
+ kid;
1676
+ constructor(kid, options) {
1677
+ super(
1678
+ "ERR_JWKS_KID_NOT_FOUND",
1679
+ `JWKS has no key matching kid=${kid ?? "(missing)"}`,
1680
+ options
1681
+ );
1682
+ this.name = "JwksKeyNotFoundError";
1683
+ this.kid = kid;
1684
+ }
1685
+ };
1686
+ var JwksFetchError = class extends JwtVerifyError {
1687
+ constructor(message, options) {
1688
+ super("ERR_JWKS_FETCH", message, options);
1689
+ this.name = "JwksFetchError";
1690
+ }
1691
+ };
1692
+
1693
+ // src/jwt/jwks-cache.ts
1694
+ var JwksCache = class {
1695
+ url;
1696
+ _jose;
1697
+ constructor(options) {
1698
+ this.url = options.url;
1699
+ const joseOpts = {
1700
+ cacheMaxAge: options.ttlMs ?? 10 * 60 * 1e3,
1701
+ cooldownDuration: options.cooldownMs ?? 3e4,
1702
+ timeoutDuration: options.timeoutMs ?? 5e3
1703
+ };
1704
+ if (options.fetch) {
1705
+ joseOpts[customFetch] = options.fetch;
1706
+ }
1707
+ this._jose = createRemoteJWKSet(
1708
+ options.url,
1709
+ joseOpts
1710
+ );
1711
+ }
1712
+ /**
1713
+ * Resolve a signing key for a given JWT header.
1714
+ * Bound as an arrow-function field so it can be passed around
1715
+ * (`jose.jwtVerify(token, cache.getKey, ...)`, passport-jwt, etc.)
1716
+ * without losing `this`.
1717
+ */
1718
+ getKey = async (header, input) => {
1719
+ try {
1720
+ return await this._jose(header, input);
1721
+ } catch (err) {
1722
+ if (err instanceof errors.JWKSNoMatchingKey) {
1723
+ throw new JwksKeyNotFoundError(header?.kid, { cause: err });
1724
+ }
1725
+ if (err instanceof errors.JWKSTimeout || err instanceof errors.JWKSInvalid || err instanceof errors.JOSEError) {
1726
+ throw new JwksFetchError(
1727
+ `Failed to load JWKS from ${this.url.href}: ${err.message}`,
1728
+ { cause: err }
1729
+ );
1730
+ }
1731
+ throw err;
1732
+ }
1733
+ };
1734
+ /**
1735
+ * Force a refetch on the next verify. Useful in tests and for
1736
+ * external rotation drills — the normal flow self-heals because
1737
+ * jose auto-refetches on kid miss.
1738
+ */
1739
+ refresh() {
1740
+ }
1741
+ };
1742
+ async function verifyAuthToken(token, getKey, opts = {}) {
1743
+ try {
1744
+ const { payload } = await jwtVerify(token, getKey, {
1745
+ algorithms: opts.algorithms ?? ["ES256", "RS256", "EdDSA"],
1746
+ issuer: opts.issuer,
1747
+ audience: opts.audience,
1748
+ clockTolerance: opts.clockTolerance ?? 5,
1749
+ requiredClaims: opts.requiredClaims,
1750
+ currentDate: opts.currentDate,
1751
+ maxTokenAge: opts.maxTokenAge
1752
+ });
1753
+ return payload;
1754
+ } catch (err) {
1755
+ throw translateJoseError(err);
1756
+ }
1757
+ }
1758
+ function translateJoseError(err) {
1759
+ if (err instanceof JwksKeyNotFoundError || err instanceof JwksFetchError || err instanceof JwtVerifyError) {
1760
+ return err;
1761
+ }
1762
+ const code = err?.code ?? "";
1763
+ const message = err?.message ?? "JWT verification failed";
1764
+ switch (code) {
1765
+ case "ERR_JWT_EXPIRED":
1766
+ return new JwtExpiredError(message, void 0, { cause: err });
1767
+ case "ERR_JWT_CLAIM_VALIDATION_FAILED": {
1768
+ const claim = err?.claim;
1769
+ if (claim === "iss") return new JwtIssuerMismatchError(message, { cause: err });
1770
+ if (claim === "aud") return new JwtAudienceMismatchError(message, { cause: err });
1771
+ if (claim === "nbf") return new JwtNotYetValidError(message, { cause: err });
1772
+ return new JwtInvalidError(message, { cause: err });
1773
+ }
1774
+ case "ERR_JWS_SIGNATURE_VERIFICATION_FAILED":
1775
+ case "ERR_JWS_INVALID":
1776
+ case "ERR_JWT_INVALID":
1777
+ return new JwtInvalidError(message, { cause: err });
1778
+ default:
1779
+ return new JwtInvalidError(message, { cause: err });
1780
+ }
1781
+ }
1782
+
1783
+ // src/scopes/consumer.ts
1784
+ var AUTH_LEGACY_ISSUER = "heimdall";
1785
+ var ConsumerScope = class {
1786
+ /** The appSlug bound to this scope. */
1787
+ appSlug;
1788
+ /**
1789
+ * Issuer the Auth Consumer API stamps on every token for this
1790
+ * app — the public Auth API base joined with the app slug
1791
+ * (e.g. `https://api.auth.productcraft.co/acme`). Pin it in
1792
+ * your local verifier so a token minted for another app on the
1793
+ * platform cannot pass.
1794
+ *
1795
+ * `scope.verifyToken` already enforces this for you. Pass it as a
1796
+ * second-position issuer if you're wiring `jose.jwtVerify`,
1797
+ * `passport-jwt`, or PyJWT yourself.
1798
+ */
1799
+ expectedIssuer;
1800
+ /**
1801
+ * Audience the Consumer API stamps on every token for this app —
1802
+ * literally the app slug (e.g. `"acme"`). Pin it in your verifier
1803
+ * the same way as `expectedIssuer`. `scope.verifyToken` enforces
1804
+ * it by default.
1805
+ */
1806
+ expectedAudience;
1807
+ /**
1808
+ * Both accepted issuer strings (`expectedIssuer` + the legacy
1809
+ * `'auth'` literal). `verifyToken` passes this to jose so tokens
1810
+ * minted before the 2026-05-24 per-app-issuer migration keep
1811
+ * verifying alongside fresh ones — useful for the ~1-hour transition
1812
+ * window per access-token TTL, and the longer session TTL on
1813
+ * refresh tokens.
1814
+ */
1815
+ acceptedIssuers;
1816
+ /** jose-compatible JWKS resolver. Drop into `jose.jwtVerify`, passport-jwt, etc. */
1817
+ jwks;
1818
+ client;
1819
+ constructor(appSlug, internals, opts = {}) {
1820
+ this.appSlug = appSlug;
1821
+ this.client = internals.client;
1822
+ const apiOrigin = new URL(internals.baseUrl);
1823
+ apiOrigin.pathname = `/${appSlug}`;
1824
+ this.expectedIssuer = apiOrigin.toString().replace(/\/$/, "");
1825
+ this.expectedAudience = appSlug;
1826
+ this.acceptedIssuers = [this.expectedIssuer, AUTH_LEGACY_ISSUER];
1827
+ this.jwks = new JwksCache({
1828
+ url: new URL(`/${appSlug}/v1/.well-known/jwks.json`, internals.baseUrl),
1829
+ ttlMs: opts.jwksTtlMs,
1830
+ fetch: internals.fetch
1831
+ });
1832
+ }
1833
+ /**
1834
+ * Direct HTTP escape hatch for endpoints whose spec is buggy
1835
+ * (path declares `{appSlug}` but parameters[] omits it). Tracked
1836
+ * upstream; remove once the spec is fixed.
1837
+ */
1838
+ async callDirect(method, url, body, params) {
1839
+ const res = await this.client({ method, url, data: body, params });
1840
+ return res.data;
1841
+ }
1842
+ /**
1843
+ * Verify an Auth-issued JWT against this app's JWKS.
1844
+ *
1845
+ * Checks the signature, expiry, `iss`, and `aud`. Accepts both the
1846
+ * per-app issuer URL (`expectedIssuer`) and the legacy `'heimdall'`
1847
+ * literal during the issuer-migration transition window — callers
1848
+ * who want to refuse legacy tokens can override with
1849
+ * `{ issuer: scope.expectedIssuer }`. Audience defaults to the app
1850
+ * slug (`expectedAudience`); pass `{ audience: false }` (in an
1851
+ * options override) to skip the audience check entirely.
1852
+ */
1853
+ verifyToken(token, opts = {}) {
1854
+ return verifyAuthToken(token, this.jwks.getKey, {
1855
+ issuer: this.acceptedIssuers,
1856
+ audience: this.expectedAudience,
1857
+ ...opts
1858
+ });
1859
+ }
1860
+ // ─────────────────────────────────────────────────────────────
1861
+ // Auth — sign-in/up flows, refresh, password reset
1862
+ // ─────────────────────────────────────────────────────────────
1863
+ auth = {
1864
+ signin: (data) => consumerAuthControllerSignin(
1865
+ { appSlug: this.appSlug, data },
1866
+ { client: this.client }
1867
+ ),
1868
+ /**
1869
+ * Signup may require a Platform API Key when the app has
1870
+ * `signup_requires_pak: true`. Configure that on the Auth
1871
+ * instance (`new Auth({ auth: { type: "apiKey", key: "..." } })`)
1872
+ * — our HTTP client attaches the Authorization header automatically.
1873
+ */
1874
+ signup: (data) => this.callDirect(
1875
+ "POST",
1876
+ `/${this.appSlug}/v1/auth/signup`,
1877
+ data
1878
+ ),
1879
+ refresh: (data) => consumerAuthControllerRefresh(
1880
+ { appSlug: this.appSlug, data },
1881
+ { client: this.client }
1882
+ ),
1883
+ logout: (data) => consumerAuthControllerLogout(
1884
+ { appSlug: this.appSlug, data },
1885
+ { client: this.client }
1886
+ ),
1887
+ /**
1888
+ * PAK-required: caller must instantiate `Auth` with
1889
+ * `auth: { type: "apiKey", key: "pcft_live_..." }`. The
1890
+ * kubb-generated `headers.authorization` slot is a stub — the
1891
+ * HTTP client's auth middleware overrides whatever's passed.
1892
+ */
1893
+ requestReset: (data) => consumerAuthControllerRequestPasswordReset(
1894
+ { appSlug: this.appSlug, data, headers: { authorization: "" } },
1895
+ { client: this.client }
1896
+ ),
1897
+ resetPassword: (data) => consumerAuthControllerResetPassword(
1898
+ { appSlug: this.appSlug, data },
1899
+ { client: this.client }
1900
+ ),
1901
+ /**
1902
+ * Mint a 6-digit contact-verification code bound to the email or
1903
+ * phone in the body. Returns `{ code, expires_at }` for delivery
1904
+ * via the customer's own channel — or `{}` if no match / already
1905
+ * verified (uniform shape — no account enumeration).
1906
+ *
1907
+ * PAK-required: caller must instantiate `Auth` with
1908
+ * `auth: { type: "apiKey", key: "pcft_live_..." }` carrying
1909
+ * `auth.user.verify.create` narrowed to this app's URN. The
1910
+ * kubb-generated `headers.authorization` slot is a stub — the
1911
+ * HTTP client's auth middleware overrides whatever's passed.
1912
+ */
1913
+ requestVerification: (data) => consumerAuthControllerRequestVerification(
1914
+ {
1915
+ appSlug: this.appSlug,
1916
+ data,
1917
+ headers: { authorization: "" }
1918
+ },
1919
+ { client: this.client }
1920
+ ),
1921
+ /**
1922
+ * Mint + dispatch a verification email via Mail in one call.
1923
+ * Returns `{ expires_at }` on success; the plaintext code is NOT
1924
+ * returned. Returns `{}` when the contact is missing or already
1925
+ * verified (same enumeration defence as `requestVerification`).
1926
+ *
1927
+ * PAK-required with `auth.user.verify.send-email` — distinct
1928
+ * permission from the bare mint so customers can enable mint
1929
+ * without enabling outbound Mail traffic. Surfaces typed 412
1930
+ * precondition errors (e.g. `ENVOI_NOT_ENABLED`) rather than the
1931
+ * silent fail-closed of a fire-and-forget mailer.
1932
+ */
1933
+ sendVerificationEmail: (data) => consumerAuthControllerSendVerificationEmail(
1934
+ {
1935
+ appSlug: this.appSlug,
1936
+ data,
1937
+ headers: { authorization: "" }
1938
+ },
1939
+ { client: this.client }
1940
+ ),
1941
+ /**
1942
+ * Consume a 6-digit verification code, flipping the bound
1943
+ * contact's `verified_at`. Public — anyone holding the code can
1944
+ * submit it; that is the whole point of the flow. Server resolves
1945
+ * the contact + account from the code value itself. Returns
1946
+ * `{ account_id, email_verified_at }` on success; 410 on invalid /
1947
+ * expired / consumed code.
1948
+ */
1949
+ verify: (data) => consumerAuthControllerVerify(
1950
+ { appSlug: this.appSlug, data },
1951
+ { client: this.client }
1952
+ ),
1953
+ /**
1954
+ * Accept an end-user invite into this app. The invite is minted by
1955
+ * an app admin (`auth.app(appId).invites.create`) and delivered
1956
+ * to the invitee out-of-band; this consumes the invite token and
1957
+ * provisions the EndUser. Public — the caller is unauthenticated
1958
+ * until the invite is accepted.
1959
+ */
1960
+ acceptInvite: (data) => consumerAuthControllerAcceptInvite(
1961
+ { appSlug: this.appSlug, data },
1962
+ { client: this.client }
1963
+ ),
1964
+ /**
1965
+ * Sign in / sign up with a provider ID token (native flow).
1966
+ *
1967
+ * Submit the identity token Apple (or Google, once enabled) issued
1968
+ * to a native client (iOS `ASAuthorizationController`, Google
1969
+ * Sign-In for iOS / Android). Auth verifies the signature
1970
+ * against the provider's JWKS, pins the issuer, checks the
1971
+ * audience against the app's configured native client ids,
1972
+ * recomputes `sha256(nonce)` and compares to the token's `nonce`
1973
+ * claim, then resolves or creates the EndUser. Same response
1974
+ * shape as `auth.signin`.
1975
+ *
1976
+ * Account linking: when an EndUser already exists with a verified
1977
+ * primary email matching the token's `email` claim, the app's
1978
+ * `oauth_link_policy` decides the outcome:
1979
+ * - `confirm` (default): refuse with 409 `link_required`. UI
1980
+ * should sign the user in via their original method to bind.
1981
+ * - `auto`: silently link the identity to the existing account
1982
+ * (provider claims `email_verified: true` AND the email is
1983
+ * not an Apple private relay).
1984
+ * - `reject`: refuse with 409 `account_exists_with_different_provider`.
1985
+ *
1986
+ * Apple's private-relay emails (`*@privaterelay.appleid.com`) are
1987
+ * persisted as-is on the EndUser's primary email contact and
1988
+ * never participate in auto-link.
1989
+ *
1990
+ * Apple sends the user's display name only on the FIRST sign-in.
1991
+ * Pass it through `user.name` on that call — Auth persists it
1992
+ * to the EndUser row. Subsequent sign-ins should omit `user`.
1993
+ */
1994
+ signinWithProvider: (args) => consumerIdpControllerNativeSignIn(
1995
+ {
1996
+ appSlug: this.appSlug,
1997
+ provider: args.provider,
1998
+ data: { id_token: args.id_token, nonce: args.nonce, user: args.user }
1999
+ },
2000
+ { client: this.client }
2001
+ )
2002
+ };
2003
+ // ─────────────────────────────────────────────────────────────
2004
+ // Me — the currently-signed-in EndUser's own resources
2005
+ // All six endpoints currently use callDirect to work around spec
2006
+ // bugs in auth.json (appSlug missing from parameters[]).
2007
+ // ─────────────────────────────────────────────────────────────
2008
+ me = {
2009
+ getProfile: () => this.callDirect("GET", `/${this.appSlug}/v1/me`),
2010
+ updateProfile: (data) => this.callDirect("PATCH", `/${this.appSlug}/v1/me`, data),
2011
+ listSessions: (params = {}) => this.callDirect(
2012
+ "GET",
2013
+ `/${this.appSlug}/v1/me/sessions`,
2014
+ void 0,
2015
+ params
2016
+ ),
2017
+ revokeSession: (id) => this.callDirect("DELETE", `/${this.appSlug}/v1/me/sessions/${id}`),
2018
+ getActivity: (params = {}) => this.callDirect(
2019
+ "GET",
2020
+ `/${this.appSlug}/v1/me/activity`,
2021
+ void 0,
2022
+ params
2023
+ ),
2024
+ deleteAccount: () => this.callDirect("DELETE", `/${this.appSlug}/v1/me`)
2025
+ };
2026
+ // ─────────────────────────────────────────────────────────────
2027
+ // Verify — server-to-server token verification + authorization
2028
+ // (typically called by the customer's backend, not the user agent)
2029
+ // ─────────────────────────────────────────────────────────────
2030
+ verify = {
2031
+ /**
2032
+ * The kubb-generated client makes `headers.authorization` a required
2033
+ * arg because the server controllers accept the bearer as a fallback
2034
+ * to `body.token`. We stub an empty string here — the HTTP client's
2035
+ * auth middleware overrides whatever's passed with the configured
2036
+ * credential (`PCAuth.apiKey` / `bearer` / `cookie`).
2037
+ */
2038
+ verify: (data) => consumerVerifyControllerVerify(
2039
+ { appSlug: this.appSlug, data, headers: { authorization: "" } },
2040
+ { client: this.client }
2041
+ ),
2042
+ authorize: (data) => consumerVerifyControllerAuthorize(
2043
+ { appSlug: this.appSlug, data, headers: { authorization: "" } },
2044
+ { client: this.client }
2045
+ ),
2046
+ authorizeBatch: (data) => consumerVerifyControllerAuthorizeBatch(
2047
+ { appSlug: this.appSlug, data, headers: { authorization: "" } },
2048
+ { client: this.client }
2049
+ )
2050
+ };
2051
+ // ─────────────────────────────────────────────────────────────
2052
+ // OAuth M2M — client_credentials grant for service-to-service tokens
2053
+ // ─────────────────────────────────────────────────────────────
2054
+ oauth = {
2055
+ clientCredentials: (data) => consumerOAuthControllerClientCredentials(
2056
+ { appSlug: this.appSlug, data },
2057
+ { client: this.client }
2058
+ )
2059
+ };
2060
+ };
2061
+
2062
+ // src/_generated/clients/apps/appControllerListMyApps.ts
2063
+ function getAppControllerListMyAppsUrl() {
2064
+ const res = { method: "GET", url: `/v1/apps` };
2065
+ return res;
2066
+ }
2067
+ async function appControllerListMyApps({ params } = {}, config = {}) {
2068
+ const { client: request = client, ...requestConfig } = config;
2069
+ const mappedParams = params ? {
2070
+ limit: params.limit,
2071
+ cursor: params.cursor,
2072
+ workspace_id: params.workspaceId
2073
+ } : void 0;
2074
+ const res = await request({
2075
+ method: "GET",
2076
+ url: getAppControllerListMyAppsUrl().url.toString(),
2077
+ params: mappedParams,
2078
+ ...requestConfig
2079
+ });
2080
+ return res.data;
2081
+ }
2082
+
2083
+ // src/_generated/clients/apps/appControllerCreateApp.ts
2084
+ function getAppControllerCreateAppUrl() {
2085
+ const res = { method: "POST", url: `/v1/apps` };
2086
+ return res;
2087
+ }
2088
+ async function appControllerCreateApp({
2089
+ data,
2090
+ headers
2091
+ }, config = {}) {
2092
+ const { client: request = client, ...requestConfig } = config;
2093
+ const mappedHeaders = headers ? { "Idempotency-Key": headers.idempotencyKey } : void 0;
2094
+ const requestData = data;
2095
+ const res = await request({
2096
+ method: "POST",
2097
+ url: getAppControllerCreateAppUrl().url.toString(),
2098
+ data: requestData,
2099
+ ...requestConfig,
2100
+ headers: { ...mappedHeaders, ...requestConfig.headers }
2101
+ });
2102
+ return res.data;
2103
+ }
2104
+
2105
+ // src/_generated/clients/platformStats/statsControllerGetMyStats.ts
2106
+ function getStatsControllerGetMyStatsUrl() {
2107
+ const res = { method: "GET", url: `/v1/stats/me` };
2108
+ return res;
2109
+ }
2110
+ async function statsControllerGetMyStats({ params } = {}, config = {}) {
2111
+ const { client: request = client, ...requestConfig } = config;
2112
+ const mappedParams = params ? { workspace_id: params.workspaceId } : void 0;
2113
+ const res = await request({
2114
+ method: "GET",
2115
+ url: getStatsControllerGetMyStatsUrl().url.toString(),
2116
+ params: mappedParams,
2117
+ ...requestConfig
2118
+ });
2119
+ return res.data;
2120
+ }
2121
+
2122
+ // src/index.ts
2123
+ var Auth = class {
2124
+ client;
2125
+ baseUrl;
2126
+ fetch;
2127
+ jwtConfig;
2128
+ constructor(config = {}) {
2129
+ this.baseUrl = config.baseUrl ?? PC_BASE_URL.auth;
2130
+ this.fetch = config.fetch;
2131
+ this.client = makeAuthHttpClient({
2132
+ baseUrl: this.baseUrl,
2133
+ auth: config.auth,
2134
+ fetch: this.fetch
2135
+ });
2136
+ this.jwtConfig = {
2137
+ jwksTtlMs: config.jwksTtlMs
2138
+ };
2139
+ }
2140
+ /**
2141
+ * Returns an `AppScope` bound to the given appId. All operations under
2142
+ * `/v1/apps/{appId}/...` are exposed as resource namespaces on the
2143
+ * returned object.
2144
+ */
2145
+ app(appId) {
2146
+ return new AppScope(appId, this.client);
2147
+ }
2148
+ /**
2149
+ * Returns a `ConsumerScope` bound to the given appSlug. Exposes the
2150
+ * `/{appSlug}/v1/...` surface (sign-in, sign-up, me, verify, oauth)
2151
+ * and the JWT-verify helper for tokens issued by this app.
2152
+ */
2153
+ consumer(appSlug) {
2154
+ return new ConsumerScope(
2155
+ appSlug,
2156
+ { client: this.client, baseUrl: this.baseUrl, fetch: this.fetch },
2157
+ this.jwtConfig
2158
+ );
2159
+ }
2160
+ // ─────────────────────────────────────────────────────────────
2161
+ // Workspace-wide apps surface
2162
+ // (other admin operations are under `app(appId).*` once an app exists)
2163
+ // ─────────────────────────────────────────────────────────────
2164
+ apps = {
2165
+ /** List apps the caller's workspace can see. */
2166
+ list: (params = {}) => appControllerListMyApps(
2167
+ { params },
2168
+ { client: this.client }
2169
+ ),
2170
+ /** Create a new app under the caller's workspace. */
2171
+ create: (data) => appControllerCreateApp({ data }, { client: this.client })
2172
+ };
2173
+ // ─────────────────────────────────────────────────────────────
2174
+ // Platform stats
2175
+ //
2176
+ // Workspace-level IdP admin (`/v1/idp/*`) was removed from the API
2177
+ // when consumer-side OAuth moved to per-app `auth_config_provider`
2178
+ // rows. Configure providers via the per-app auth-config endpoints
2179
+ // (`app(appId).authConfig.*`) and consume them client-side through
2180
+ // `consumer(slug).auth.signinWithProvider({ ... })`.
2181
+ // ─────────────────────────────────────────────────────────────
2182
+ stats = {
2183
+ /**
2184
+ * Get the signed-in PlatformUser's aggregate counts. Pass
2185
+ * `workspaceId` to scope to a single workspace; omit to total
2186
+ * across every workspace the caller belongs to.
2187
+ */
2188
+ get: (params = {}) => statsControllerGetMyStats(
2189
+ { params },
2190
+ { client: this.client }
2191
+ )
2192
+ };
2193
+ };
2194
+
2195
+ export { AUTH_LEGACY_ISSUER, AppScope, Auth, AuthHttpError, ConsumerScope, JwksCache, JwksFetchError, JwksKeyNotFoundError, JwtAudienceMismatchError, JwtExpiredError, JwtInvalidError, JwtIssuerMismatchError, JwtNotYetValidError, JwtVerifyError, verifyAuthToken };
2196
+ //# sourceMappingURL=index.js.map
2197
+ //# sourceMappingURL=index.js.map