@managemint-solutions/sdk 0.69.0 → 0.70.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/README.md CHANGED
@@ -401,8 +401,13 @@ await service.staffPermissions.updateForStaff(staffId, patch, byStaffId); // Upd
401
401
  ### User api credentials and emulation
402
402
 
403
403
  A credential is a client id and secret staff issue for one tenant user. Exchanging it mints that
404
- user's own token, which the custom access token hook marks `emulated: true` and gives a one-hour
405
- `exp`; `verifyAccessToken` returns it as `emulated: true` (`false` for a user's own session).
404
+ user's own token, which the custom access token hook marks `api_credential` (the credential) with a
405
+ 15-minute `exp`; `verifyAccessToken` returns it as `api_credential`, and it reads and writes as the
406
+ user. A staff member's Emulate User token is marked `emulated: true` with a one-hour `exp`
407
+ (`verifyAccessToken`'s `emulated`, read-only on the main api). A token Supabase's OAuth server
408
+ issued to an app carries `client_id`, returned as `oauth_client_id`. The caller's side of that
409
+ OAuth server is `supabase.oauth` (`getAuthorization`, `answerAuthorization`, `listGrants`,
410
+ `revokeGrant`), plain calls to GoTrue's endpoints with the caller's bearer.
406
411
 
407
412
  The mint itself lives in the admin api. The SDK calls it is made of:
408
413
 
package/dist/auth.d.ts CHANGED
@@ -40,8 +40,18 @@ export type VerifiedAuth = AuthContext & {
40
40
  name: string | null;
41
41
  surname: string | null;
42
42
  organization: VerifiedOrganization;
43
- /** True when the token was minted through an emulation handshake; false for the user's own session. */
43
+ /** True for a staff member's Emulate User token (read-only); false for every other token. */
44
44
  emulated: boolean;
45
+ /**
46
+ * The user api credential that minted this token, or null. Such a token acts as the user,
47
+ * reads and writes alike, but is not the user at the keyboard.
48
+ */
49
+ api_credential: string | null;
50
+ /**
51
+ * The OAuth app (an MCP client such as Claude) this token was issued to, or null. Like
52
+ * `api_credential`: the user's own access, through an app rather than the user's own login.
53
+ */
54
+ oauth_client_id: string | null;
45
55
  };
46
56
  export type VerifyAccessTokenConfig = {
47
57
  url: string;
package/dist/auth.js CHANGED
@@ -72,9 +72,12 @@ const verifyAccessToken = async ({ url, key, accessToken, client = (0, exports.c
72
72
  access_expires_at: organization.access_expires_at ?? null,
73
73
  modules: organization.modules ?? [],
74
74
  },
75
- // Stamped by the custom access token hook, inside the signature - a user cannot add it to
76
- // their own session.
75
+ // All three are inside the signature - a user cannot add them to their own session.
76
+ // `emulated` and `api_credential` are stamped by the custom access token hook, `client_id`
77
+ // by GoTrue's OAuth server.
77
78
  emulated: claims.emulated === true,
79
+ api_credential: typeof claims.api_credential === 'string' ? claims.api_credential : null,
80
+ oauth_client_id: typeof claims.client_id === 'string' ? claims.client_id : null,
78
81
  };
79
82
  };
80
83
  exports.verifyAccessToken = verifyAccessToken;
package/dist/client.d.ts CHANGED
@@ -7,6 +7,7 @@ import { ConfigsResource } from './configs';
7
7
  import { DocumentsResource, DocumentTemplatesResource } from './documents';
8
8
  import { NotesResource } from './notes';
9
9
  import { NotificationsResource } from './notifications';
10
+ import { OAuthResource } from './oauth';
10
11
  import { BillingReadsResource } from './billing';
11
12
  import { InvoicesReadsResource } from './billing/invoices';
12
13
  import { InventoryItemsResource, InventoryLevelsResource, InventoryLocationsResource, InventoryMovementsResource, InventoryStocktakesResource, InventoryTransfersResource } from './inventory';
@@ -83,6 +84,8 @@ export declare class SupabaseClient {
83
84
  readonly inventoryMovements: InventoryMovementsResource;
84
85
  readonly inventoryTransfers: InventoryTransfersResource;
85
86
  readonly inventoryStocktakes: InventoryStocktakesResource;
87
+ /** The caller's answers to OAuth connection requests and the apps they have connected. */
88
+ readonly oauth: OAuthResource;
86
89
  constructor(config: SupabaseClientConfig);
87
90
  }
88
91
  export declare const createSupabaseClient: (config: SupabaseClientConfig) => SupabaseClient;
package/dist/client.js CHANGED
@@ -9,6 +9,7 @@ const configs_1 = require("./configs");
9
9
  const documents_1 = require("./documents");
10
10
  const notes_1 = require("./notes");
11
11
  const notifications_1 = require("./notifications");
12
+ const oauth_1 = require("./oauth");
12
13
  const billing_1 = require("./billing");
13
14
  const invoices_1 = require("./billing/invoices");
14
15
  const inventory_1 = require("./inventory");
@@ -69,6 +70,8 @@ class SupabaseClient {
69
70
  inventoryMovements;
70
71
  inventoryTransfers;
71
72
  inventoryStocktakes;
73
+ /** The caller's answers to OAuth connection requests and the apps they have connected. */
74
+ oauth;
72
75
  constructor(config) {
73
76
  this.auth = config.auth;
74
77
  this.supabase =
@@ -109,6 +112,7 @@ class SupabaseClient {
109
112
  this.inventoryMovements = new inventory_1.InventoryMovementsResource(this.supabase, this.auth, this.audit);
110
113
  this.inventoryTransfers = new inventory_1.InventoryTransfersResource(this.supabase, this.auth, this.audit);
111
114
  this.inventoryStocktakes = new inventory_1.InventoryStocktakesResource(this.supabase, this.auth, this.audit);
115
+ this.oauth = new oauth_1.OAuthResource(config.url, config.key, config.accessToken);
112
116
  }
113
117
  }
114
118
  exports.SupabaseClient = SupabaseClient;
package/dist/index.d.ts CHANGED
@@ -34,6 +34,7 @@ export { CreateOrganizationDto, GetOrganizationsDto, OrganizationIdDto, UpdateOr
34
34
  export { PermissionsResource } from './permissions';
35
35
  export type { PermissionFlags } from './permissions';
36
36
  export { UpdatePermissionsDto } from './permissions';
37
+ export { OAuthAuthorizationIdDto, OAuthClientIdDto } from './oauth';
37
38
  export { CreateStaffDto, StaffIdDto, UpdateStaffPermissionsDto } from './staff';
38
39
  export type { CreateUserApiCredentialRow, UserApiCredentialRow } from './user-api-credentials';
39
40
  export { CreateUserApiCredentialDto, MintEmulationTokenDto, UserApiCredentialIdDto, } from './user-api-credentials';
package/dist/index.js CHANGED
@@ -8,9 +8,9 @@
8
8
  // to keep. The row and input types they produce and accept are exported for annotations.
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.IsAdditionalDetailsValueByType = exports.GetAllAdditionalDetailsDto = exports.GetAdditionalDetailsDto = exports.AdditionalDetailsIdDto = exports.AddAdditionalDetailsDto = exports.UpdateLabelDto = exports.LabelIdDto = exports.GetLabelsDto = exports.AddLabelDto = exports.UpdateStatusDto = exports.StatusIdDto = exports.ReorderStatusesDto = exports.GetStatusesDto = exports.GetAllStatusesDto = exports.AddStatusDto = exports.CreateSupportRequestDto = exports.GetCronRunsDto = exports.CronIdDto = exports.UpdateConfigDto = exports.CreateConfigDto = exports.ConfigIdDto = exports.CreateFeatureRequestDto = exports.InvoiceIdDto = exports.GetInvoicesQueryDto = exports.ReinstateSubscriptionDto = exports.PurchaseModuleDto = exports.ModuleSetDto = exports.ChangeModulesDto = exports.PaymentIdDto = exports.InitialPaymentDto = exports.GetPaymentsQueryDto = exports.CancelSubscriptionDto = exports.withAuditBatch = exports.GetAuditTrailDto = exports.IsNullable = exports.EmptyToNull = exports.SupabaseClientError = exports.createSupabaseServiceClient = exports.SupabaseServiceClient = exports.SignInDto = exports.SendPasswordResetEmailDto = exports.ResetPasswordDto = exports.ExchangeTokenHashDto = exports.ExchangeRefreshTokenDto = exports.createSupabaseAuthClient = exports.SupabaseAuthClient = exports.createSupabaseStaffClient = exports.SupabaseStaffClient = exports.createSupabaseClient = exports.SupabaseClient = void 0;
11
- exports.GetInventoryItemsDto = exports.GeocodeAddressDto = exports.CreateInventoryTransferLineDto = exports.CreateInventoryTransferDto = exports.CreateInventoryMovementDto = exports.CreateInventoryLocationDto = exports.CreateInventoryItemDto = exports.CountInventoryLineDto = exports.CountInventoryDto = exports.UpdateLeadDto = exports.StaffGetLeadsDto = exports.LeadIdDto = exports.GetLeadsDto = exports.CreateLeadDto = exports.ConvertLeadDto = exports.UpdateClientDto = exports.StaffGetClientsDto = exports.GetClientsDto = exports.CreateClientDto = exports.ClientIdDto = exports.SupportingFileNamesDto = exports.SupportingFileIdDto = exports.GetSupportingFilesDto = exports.GetAllSupportingFilesDto = exports.UserIdDto = exports.UpdateUserDto = exports.UpdateMyProfileDto = exports.StaffGetUsersDto = exports.GetUsersQueryDto = exports.AddUserDto = exports.UserApiCredentialIdDto = exports.MintEmulationTokenDto = exports.CreateUserApiCredentialDto = exports.UpdateStaffPermissionsDto = exports.StaffIdDto = exports.CreateStaffDto = exports.UpdatePermissionsDto = exports.PermissionsResource = exports.UpdateOrganizationDto = exports.OrganizationIdDto = exports.GetOrganizationsDto = exports.CreateOrganizationDto = exports.UpdateOrganizationPayoutsDto = exports.NotificationIdDto = exports.GetNotificationsDto = exports.NoteIdDto = exports.GetNotesDto = exports.GetAllNotesDto = exports.AddNoteDto = exports.UpdateAdditionalDetailsDto = void 0;
12
- exports.GetTasksDto = exports.CreateTaskDto = exports.AddTaskLinkDto = exports.UpdateProjectDto = exports.StaffGetProjectsDto = exports.ProjectIdDto = exports.GetProjectsDto = exports.CreateProjectDto = exports.UpdateVisibilityDto = exports.ReassignPrivateDocumentsDto = exports.ConvertDocumentDto = exports.VoidDocumentDto = exports.UpdateDocumentTemplateDto = exports.UpdateDocumentDto = exports.SendDocumentDto = exports.RecordDocumentPaymentDto = exports.PayDocumentDto = exports.GetDocumentTemplatesDto = exports.GetDocumentsDto = exports.GetCatalogueTemplatesDto = exports.documentProblem = exports.DocumentTemplateIdDto = exports.DocumentPaymentIdDto = exports.DocumentPayTokenDto = exports.DocumentPayQueryDto = exports.DocumentImageUrlsDto = exports.DocumentImageNameDto = exports.DocumentIdDto = exports.CreateDocumentTemplateDto = exports.CreateDocumentDto = exports.CopyCatalogueTemplateDto = exports.CatalogueTemplateSlugDto = exports.UpdateInventoryTransferDto = exports.UpdateInventoryLocationDto = exports.UpdateInventoryLevelDto = exports.UpdateInventoryItemDto = exports.SuggestAddressesDto = exports.StaffGetInventoryItemsDto = exports.ReceiveInventoryTransferDto = exports.InventoryTransferIdDto = exports.InventoryStocktakeIdDto = exports.InventoryLocationIdDto = exports.InventoryLevelKeyDto = exports.InventoryItemIdDto = exports.ImportInventoryItemsDto = exports.ImportInventoryItemDto = exports.GetInventoryTransfersDto = exports.GetInventoryStocktakesDto = exports.GetInventoryMovementsDto = exports.GetInventoryLocationsDto = void 0;
13
- exports.monthlyTotalMinor = exports.weekStartOf = exports.minutesBetween = exports.UpdateTimesheetEntryDto = exports.TimesheetIdDto = exports.TimesheetEntryIdDto = exports.ReviewTimesheetDto = exports.GetTimesheetsDto = exports.GetTimesheetReportDto = exports.CreateTimesheetEntryDto = exports.todayInJohannesburg = exports.shiftDays = exports.proRataDays = exports.isWithinPeriod = exports.initialUntil = exports.cyclePeriodFor = exports.countWorkingDays = exports.completedMonths = exports.addMonths = exports.GetPublicHolidaysDto = exports.UpdateLeaveTypeDto = exports.UpdateLeaveRequestDto = exports.UpdateLeaveEntitlementDto = exports.ReviewLeaveRequestDto = exports.LeaveTypeIdDto = exports.LeaveRequestIdDto = exports.LeaveEntitlementIdDto = exports.GetLeaveTypesDto = exports.GetLeaveRequestsDto = exports.GetLeaveEntitlementsDto = exports.GetLeaveCalendarDto = exports.CreateLeaveTypeDto = exports.CreateLeaveRequestDto = exports.CreateLeaveEntitlementDto = exports.CreateLeaveAdjustmentDto = exports.BulkCreateLeaveEntitlementsDto = exports.UpdateTaskDto = exports.TaskLinkIdDto = exports.TaskIdDto = exports.StaffGetTasksDto = void 0;
11
+ exports.CreateInventoryTransferLineDto = exports.CreateInventoryTransferDto = exports.CreateInventoryMovementDto = exports.CreateInventoryLocationDto = exports.CreateInventoryItemDto = exports.CountInventoryLineDto = exports.CountInventoryDto = exports.UpdateLeadDto = exports.StaffGetLeadsDto = exports.LeadIdDto = exports.GetLeadsDto = exports.CreateLeadDto = exports.ConvertLeadDto = exports.UpdateClientDto = exports.StaffGetClientsDto = exports.GetClientsDto = exports.CreateClientDto = exports.ClientIdDto = exports.SupportingFileNamesDto = exports.SupportingFileIdDto = exports.GetSupportingFilesDto = exports.GetAllSupportingFilesDto = exports.UserIdDto = exports.UpdateUserDto = exports.UpdateMyProfileDto = exports.StaffGetUsersDto = exports.GetUsersQueryDto = exports.AddUserDto = exports.UserApiCredentialIdDto = exports.MintEmulationTokenDto = exports.CreateUserApiCredentialDto = exports.UpdateStaffPermissionsDto = exports.StaffIdDto = exports.CreateStaffDto = exports.OAuthClientIdDto = exports.OAuthAuthorizationIdDto = exports.UpdatePermissionsDto = exports.PermissionsResource = exports.UpdateOrganizationDto = exports.OrganizationIdDto = exports.GetOrganizationsDto = exports.CreateOrganizationDto = exports.UpdateOrganizationPayoutsDto = exports.NotificationIdDto = exports.GetNotificationsDto = exports.NoteIdDto = exports.GetNotesDto = exports.GetAllNotesDto = exports.AddNoteDto = exports.UpdateAdditionalDetailsDto = void 0;
12
+ exports.AddTaskLinkDto = exports.UpdateProjectDto = exports.StaffGetProjectsDto = exports.ProjectIdDto = exports.GetProjectsDto = exports.CreateProjectDto = exports.UpdateVisibilityDto = exports.ReassignPrivateDocumentsDto = exports.ConvertDocumentDto = exports.VoidDocumentDto = exports.UpdateDocumentTemplateDto = exports.UpdateDocumentDto = exports.SendDocumentDto = exports.RecordDocumentPaymentDto = exports.PayDocumentDto = exports.GetDocumentTemplatesDto = exports.GetDocumentsDto = exports.GetCatalogueTemplatesDto = exports.documentProblem = exports.DocumentTemplateIdDto = exports.DocumentPaymentIdDto = exports.DocumentPayTokenDto = exports.DocumentPayQueryDto = exports.DocumentImageUrlsDto = exports.DocumentImageNameDto = exports.DocumentIdDto = exports.CreateDocumentTemplateDto = exports.CreateDocumentDto = exports.CopyCatalogueTemplateDto = exports.CatalogueTemplateSlugDto = exports.UpdateInventoryTransferDto = exports.UpdateInventoryLocationDto = exports.UpdateInventoryLevelDto = exports.UpdateInventoryItemDto = exports.SuggestAddressesDto = exports.StaffGetInventoryItemsDto = exports.ReceiveInventoryTransferDto = exports.InventoryTransferIdDto = exports.InventoryStocktakeIdDto = exports.InventoryLocationIdDto = exports.InventoryLevelKeyDto = exports.InventoryItemIdDto = exports.ImportInventoryItemsDto = exports.ImportInventoryItemDto = exports.GetInventoryTransfersDto = exports.GetInventoryStocktakesDto = exports.GetInventoryMovementsDto = exports.GetInventoryLocationsDto = exports.GetInventoryItemsDto = exports.GeocodeAddressDto = void 0;
13
+ exports.monthlyTotalMinor = exports.weekStartOf = exports.minutesBetween = exports.UpdateTimesheetEntryDto = exports.TimesheetIdDto = exports.TimesheetEntryIdDto = exports.ReviewTimesheetDto = exports.GetTimesheetsDto = exports.GetTimesheetReportDto = exports.CreateTimesheetEntryDto = exports.todayInJohannesburg = exports.shiftDays = exports.proRataDays = exports.isWithinPeriod = exports.initialUntil = exports.cyclePeriodFor = exports.countWorkingDays = exports.completedMonths = exports.addMonths = exports.GetPublicHolidaysDto = exports.UpdateLeaveTypeDto = exports.UpdateLeaveRequestDto = exports.UpdateLeaveEntitlementDto = exports.ReviewLeaveRequestDto = exports.LeaveTypeIdDto = exports.LeaveRequestIdDto = exports.LeaveEntitlementIdDto = exports.GetLeaveTypesDto = exports.GetLeaveRequestsDto = exports.GetLeaveEntitlementsDto = exports.GetLeaveCalendarDto = exports.CreateLeaveTypeDto = exports.CreateLeaveRequestDto = exports.CreateLeaveEntitlementDto = exports.CreateLeaveAdjustmentDto = exports.BulkCreateLeaveEntitlementsDto = exports.UpdateTaskDto = exports.TaskLinkIdDto = exports.TaskIdDto = exports.StaffGetTasksDto = exports.GetTasksDto = exports.CreateTaskDto = void 0;
14
14
  var client_1 = require("./client");
15
15
  Object.defineProperty(exports, "SupabaseClient", { enumerable: true, get: function () { return client_1.SupabaseClient; } });
16
16
  Object.defineProperty(exports, "createSupabaseClient", { enumerable: true, get: function () { return client_1.createSupabaseClient; } });
@@ -100,6 +100,9 @@ var permissions_1 = require("./permissions");
100
100
  Object.defineProperty(exports, "PermissionsResource", { enumerable: true, get: function () { return permissions_1.PermissionsResource; } });
101
101
  var permissions_2 = require("./permissions");
102
102
  Object.defineProperty(exports, "UpdatePermissionsDto", { enumerable: true, get: function () { return permissions_2.UpdatePermissionsDto; } });
103
+ var oauth_1 = require("./oauth");
104
+ Object.defineProperty(exports, "OAuthAuthorizationIdDto", { enumerable: true, get: function () { return oauth_1.OAuthAuthorizationIdDto; } });
105
+ Object.defineProperty(exports, "OAuthClientIdDto", { enumerable: true, get: function () { return oauth_1.OAuthClientIdDto; } });
103
106
  var staff_1 = require("./staff");
104
107
  Object.defineProperty(exports, "CreateStaffDto", { enumerable: true, get: function () { return staff_1.CreateStaffDto; } });
105
108
  Object.defineProperty(exports, "StaffIdDto", { enumerable: true, get: function () { return staff_1.StaffIdDto; } });
@@ -0,0 +1,7 @@
1
+ import type { OAuthAuthorizationIdDto as OAuthAuthorizationIdDtoType, OAuthClientIdDto as OAuthClientIdDtoType } from '@managemint-solutions/entities/oauth/dto';
2
+ export declare class OAuthAuthorizationIdDto implements OAuthAuthorizationIdDtoType {
3
+ readonly authorizationId: string;
4
+ }
5
+ export declare class OAuthClientIdDto implements OAuthClientIdDtoType {
6
+ readonly clientId: string;
7
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OAuthClientIdDto = exports.OAuthAuthorizationIdDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ class OAuthAuthorizationIdDto {
15
+ // GoTrue's own id format, not one of ours, so only its length is checked.
16
+ authorizationId;
17
+ }
18
+ exports.OAuthAuthorizationIdDto = OAuthAuthorizationIdDto;
19
+ __decorate([
20
+ (0, class_validator_1.IsString)({ message: 'Invalid authorization ID' }),
21
+ (0, class_validator_1.MinLength)(1, { message: 'Invalid authorization ID' }),
22
+ (0, class_validator_1.MaxLength)(255, { message: 'Invalid authorization ID' }),
23
+ __metadata("design:type", String)
24
+ ], OAuthAuthorizationIdDto.prototype, "authorizationId", void 0);
25
+ class OAuthClientIdDto {
26
+ clientId;
27
+ }
28
+ exports.OAuthClientIdDto = OAuthClientIdDto;
29
+ __decorate([
30
+ (0, class_validator_1.IsUUID)('all', { message: 'Invalid app ID format' }),
31
+ __metadata("design:type", String)
32
+ ], OAuthClientIdDto.prototype, "clientId", void 0);
@@ -0,0 +1,25 @@
1
+ import type { OAuthAuthorizationResponse, OAuthGrant, OAuthRedirect } from '@managemint-solutions/entities/oauth';
2
+ export * from './dto';
3
+ /**
4
+ * The caller's side of Supabase Auth's OAuth server: answering a connection request on the
5
+ * consent page, and the apps they have connected.
6
+ *
7
+ * GoTrue authenticates these endpoints with the caller's own token, and supabase-js only sends
8
+ * one from a stored session, which a stateless server-side client never has - so these are plain
9
+ * calls to the same endpoints supabase-js uses (`auth.oauth.*`), carrying the caller's bearer.
10
+ */
11
+ export declare class OAuthResource {
12
+ private readonly url;
13
+ private readonly key;
14
+ private readonly accessToken;
15
+ constructor(url: string, key: string, accessToken: string);
16
+ /** A connection request: what the consent page shows, or a redirect if already approved. */
17
+ getAuthorization(authorizationId: string): Promise<OAuthAuthorizationResponse>;
18
+ /** Approves or denies a connection request; either way the answer is a redirect to the app. */
19
+ answerAuthorization(authorizationId: string, action: 'approve' | 'deny'): Promise<OAuthRedirect>;
20
+ /** The apps the caller has connected. */
21
+ listGrants(): Promise<OAuthGrant[]>;
22
+ /** Disconnects an app: GoTrue ends its sessions and refresh tokens at once. */
23
+ revokeGrant(clientId: string): Promise<void>;
24
+ private request;
25
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.OAuthResource = void 0;
18
+ const errors_1 = require("../errors");
19
+ __exportStar(require("./dto"), exports);
20
+ /**
21
+ * The caller's side of Supabase Auth's OAuth server: answering a connection request on the
22
+ * consent page, and the apps they have connected.
23
+ *
24
+ * GoTrue authenticates these endpoints with the caller's own token, and supabase-js only sends
25
+ * one from a stored session, which a stateless server-side client never has - so these are plain
26
+ * calls to the same endpoints supabase-js uses (`auth.oauth.*`), carrying the caller's bearer.
27
+ */
28
+ class OAuthResource {
29
+ url;
30
+ key;
31
+ accessToken;
32
+ constructor(url, key, accessToken) {
33
+ this.url = url;
34
+ this.key = key;
35
+ this.accessToken = accessToken;
36
+ }
37
+ /** A connection request: what the consent page shows, or a redirect if already approved. */
38
+ async getAuthorization(authorizationId) {
39
+ const data = await this.request('GET', `/oauth/authorizations/${encodeURIComponent(authorizationId)}`);
40
+ if ('redirect_url' in data)
41
+ return { redirect_url: data.redirect_url };
42
+ // GoTrue also sends the signed-in user; the caller already knows who they are.
43
+ return {
44
+ authorization_id: data.authorization_id,
45
+ redirect_uri: data.redirect_uri,
46
+ client: data.client,
47
+ scope: data.scope,
48
+ };
49
+ }
50
+ /** Approves or denies a connection request; either way the answer is a redirect to the app. */
51
+ async answerAuthorization(authorizationId, action) {
52
+ const data = await this.request('POST', `/oauth/authorizations/${encodeURIComponent(authorizationId)}/consent`, { action });
53
+ return { redirect_url: data.redirect_url };
54
+ }
55
+ /** The apps the caller has connected. */
56
+ async listGrants() {
57
+ return await this.request('GET', '/user/oauth/grants');
58
+ }
59
+ /** Disconnects an app: GoTrue ends its sessions and refresh tokens at once. */
60
+ async revokeGrant(clientId) {
61
+ await this.request('DELETE', `/user/oauth/grants?client_id=${encodeURIComponent(clientId)}`);
62
+ }
63
+ async request(method, path, body) {
64
+ const response = await fetch(`${this.url}/auth/v1${path}`, {
65
+ method,
66
+ headers: {
67
+ apikey: this.key,
68
+ Authorization: `Bearer ${this.accessToken}`,
69
+ ...(body ? { 'Content-Type': 'application/json' } : {}),
70
+ },
71
+ ...(body ? { body: JSON.stringify(body) } : {}),
72
+ });
73
+ const text = await response.text();
74
+ const data = text ? JSON.parse(text) : null;
75
+ if (!response.ok) {
76
+ const error = (data ?? {});
77
+ throw new errors_1.SupabaseClientError({
78
+ // GoTrue answers an unknown or expired request with 404 and a bad id with 400; anything
79
+ // else is its own failure, not the caller's.
80
+ status: response.status >= 500 ? 502 : response.status,
81
+ error: 'Authentication Error',
82
+ message: error.msg ?? error.message ?? error.error_description ?? 'The connection request failed',
83
+ });
84
+ }
85
+ return data;
86
+ }
87
+ }
88
+ exports.OAuthResource = OAuthResource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managemint-solutions/sdk",
3
- "version": "0.69.0",
3
+ "version": "0.70.0",
4
4
  "description": "Typed Supabase data-access SDK for ManageMint Solutions",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Scott Bebington <scottbebington@gmail.com>",
@@ -55,7 +55,7 @@
55
55
  "testEnvironment": "node"
56
56
  },
57
57
  "dependencies": {
58
- "@managemint-solutions/entities": "^1.51.0"
58
+ "@managemint-solutions/entities": "^1.52.0"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@nestjs/common": "^11.0.0",