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