@finueva/auth 0.28.0 → 0.29.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/server.d.ts +64 -1
- package/dist/server.js +163 -1
- package/package.json +1 -1
package/dist/server.d.ts
CHANGED
|
@@ -258,6 +258,69 @@ interface FinuevaDriveProvisioningAuth {
|
|
|
258
258
|
/** Service authority only. Never pass an incoming User request or session to this client. */
|
|
259
259
|
declare function createDriveProvisioningAuth(options: DriveProvisioningAuthOptions): FinuevaDriveProvisioningAuth;
|
|
260
260
|
//#endregion
|
|
261
|
+
//#region src/user-directory.d.ts
|
|
262
|
+
interface UserDirectoryEntry {
|
|
263
|
+
applicationId: string;
|
|
264
|
+
/** Opaque application-scoped identifier. This is not the canonical Auth User ID. */
|
|
265
|
+
userId: string;
|
|
266
|
+
/** Immutable application-scoped incarnation. A replacement User cannot inherit it. */
|
|
267
|
+
userGeneration: string;
|
|
268
|
+
lifecycle: "active" | "suspended" | "deleted";
|
|
269
|
+
}
|
|
270
|
+
interface UserDirectoryLookupInput {
|
|
271
|
+
applicationId: string;
|
|
272
|
+
userId: string;
|
|
273
|
+
userGeneration: string;
|
|
274
|
+
}
|
|
275
|
+
interface UserDirectoryListInput {
|
|
276
|
+
applicationId: string;
|
|
277
|
+
limit?: number;
|
|
278
|
+
cursor?: string;
|
|
279
|
+
}
|
|
280
|
+
interface UserDirectoryMembersInput extends UserDirectoryListInput {
|
|
281
|
+
organizationId: string;
|
|
282
|
+
organizationGeneration: string;
|
|
283
|
+
}
|
|
284
|
+
interface UserDirectoryResolveInput {
|
|
285
|
+
applicationId: string;
|
|
286
|
+
authUserId: string;
|
|
287
|
+
}
|
|
288
|
+
interface UserDirectoryPage {
|
|
289
|
+
users: UserDirectoryEntry[];
|
|
290
|
+
/** Only null means the collection is exhausted. */ nextCursor: string | null;
|
|
291
|
+
}
|
|
292
|
+
interface UserDirectoryMember {
|
|
293
|
+
user: UserDirectoryEntry;
|
|
294
|
+
role: "owner" | "admin" | "member";
|
|
295
|
+
membershipStatus: "active" | "suspended";
|
|
296
|
+
}
|
|
297
|
+
interface UserDirectoryMembersPage {
|
|
298
|
+
applicationId: string;
|
|
299
|
+
organizationId: string;
|
|
300
|
+
organizationGeneration: string;
|
|
301
|
+
members: UserDirectoryMember[];
|
|
302
|
+
nextCursor: string | null;
|
|
303
|
+
}
|
|
304
|
+
/** Private service authority. Never forward this object to an operator or browser. */
|
|
305
|
+
interface UserDirectoryBinding {
|
|
306
|
+
user: UserDirectoryEntry;
|
|
307
|
+
authUserId: string;
|
|
308
|
+
}
|
|
309
|
+
interface UserDirectoryAuthOptions {
|
|
310
|
+
authOrigin: string;
|
|
311
|
+
fetch?: typeof globalThis.fetch;
|
|
312
|
+
timeoutMs?: number;
|
|
313
|
+
}
|
|
314
|
+
interface FinuevaUserDirectoryAuth {
|
|
315
|
+
listUsers(input: UserDirectoryListInput, assertion: string): Promise<UserDirectoryPage>;
|
|
316
|
+
lookupUser(input: UserDirectoryLookupInput, assertion: string): Promise<UserDirectoryEntry | null>;
|
|
317
|
+
listOrganizationMembers(input: UserDirectoryMembersInput, assertion: string): Promise<UserDirectoryMembersPage>;
|
|
318
|
+
resolveUser(input: UserDirectoryResolveInput, assertion: string): Promise<UserDirectoryEntry | null>;
|
|
319
|
+
resolveUserBinding(input: UserDirectoryLookupInput, assertion: string): Promise<UserDirectoryBinding | null>;
|
|
320
|
+
}
|
|
321
|
+
/** Server-only service assertions. This client has no session authority and performs no automatic retry. */
|
|
322
|
+
declare function createUserDirectoryAuth(options: UserDirectoryAuthOptions): FinuevaUserDirectoryAuth;
|
|
323
|
+
//#endregion
|
|
261
324
|
//#region src/server.d.ts
|
|
262
325
|
interface ServerAuthOptions {
|
|
263
326
|
authOrigin: string;
|
|
@@ -322,4 +385,4 @@ interface FinuevaServerAuth {
|
|
|
322
385
|
}
|
|
323
386
|
declare function createServerAuth(options: ServerAuthOptions): FinuevaServerAuth;
|
|
324
387
|
//#endregion
|
|
325
|
-
export { type AcceptInvitationInput, type AccountProductOperationAuthOptions, type AccountProductOperationConsumer, type AccountProductOperationInput, type AccountProductOperationPhase, type AccountProductOperationProof, type AccountProductOperationReceipt, type AccountProductOperationSnapshot, type AccountProductOperationSnapshotInput, type AddedOrganizationTeamMember, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CanceledOrganizationInvitation, type CompleteGoogleAccountRecoveryInput, type CreateOrganizationMemberInvitationInput, type CreatedOrganization, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type DeclineInvitationInput, type DeletedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type DriveProvisioningAuthOptions, type DriveProvisioningCredential, type DriveRecipient, type DriveRecipientAuthOptions, type FinuevaDriveProvisioningAuth, type FinuevaDriveRecipientAuth, type FinuevaIdentityResolverAuth, type FinuevaMembershipResolverAuth, type FinuevaOrganizationDirectoryAuth, FinuevaServerAuth, type GoogleAccountRecovery, type GoogleAccountRecoveryInput, type IdentityResolverAuthOptions, type InvitationAcceptance, type InvitationDecline, type MembershipResolverAuthOptions, type OrganizationApplicationRegistration, type OrganizationDeparture, type OrganizationDirectoryAuthOptions, type OrganizationDirectoryEntry, type OrganizationDirectoryLookupInput, type OrganizationDirectoryPage, type OrganizationDirectorySearchInput, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberApplicationAccess, type OrganizationMemberApplicationAccessInput, type OrganizationMemberAuthority, type OrganizationMemberPage, type OrganizationMemberPageInput, type OrganizationPage, type OrganizationPageInput, type OrganizationPresenceAuthorization, type OrganizationPresenceInput, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type RegisterOrganizationApplicationInput, type RegisteredOrganizationApplication, type RemovedOrganizationMember, type RemovedOrganizationTeamMember, type ResentOrganizationInvitation, type ResolveDriveRecipientInput, type ResolveIdentityInput, type ResolveMembershipBatchInput, type ResolveMembershipInput, type ResolvedIdentity, type ResolvedMembership, type ResolvedMembershipBatch, type ResolvedMembershipRole, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type UserApiCredential, type UserApiCredentialInput, type UserApiIdentity, type UserApiVerifierOptions, type WorkspaceSelection, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationDirectoryAuth, createServerAuth, createUserApiVerifier };
|
|
388
|
+
export { type AcceptInvitationInput, type AccountProductOperationAuthOptions, type AccountProductOperationConsumer, type AccountProductOperationInput, type AccountProductOperationPhase, type AccountProductOperationProof, type AccountProductOperationReceipt, type AccountProductOperationSnapshot, type AccountProductOperationSnapshotInput, type AddedOrganizationTeamMember, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthSession, type AuthUser, type CanceledOrganizationInvitation, type CompleteGoogleAccountRecoveryInput, type CreateOrganizationMemberInvitationInput, type CreatedOrganization, type CreatedOrganizationMemberInvitation, type CreatedOrganizationTeam, type DeclineInvitationInput, type DeletedOrganizationTeam, type DriveCredential, type DriveCredentialInput, type DriveProvisioningAuthOptions, type DriveProvisioningCredential, type DriveRecipient, type DriveRecipientAuthOptions, type FinuevaDriveProvisioningAuth, type FinuevaDriveRecipientAuth, type FinuevaIdentityResolverAuth, type FinuevaMembershipResolverAuth, type FinuevaOrganizationDirectoryAuth, FinuevaServerAuth, type FinuevaUserDirectoryAuth, type GoogleAccountRecovery, type GoogleAccountRecoveryInput, type IdentityResolverAuthOptions, type InvitationAcceptance, type InvitationDecline, type MembershipResolverAuthOptions, type OrganizationApplicationRegistration, type OrganizationDeparture, type OrganizationDirectoryAuthOptions, type OrganizationDirectoryEntry, type OrganizationDirectoryLookupInput, type OrganizationDirectoryPage, type OrganizationDirectorySearchInput, type OrganizationDisplay, type OrganizationInvitation, type OrganizationInvitationPage, type OrganizationMember, type OrganizationMemberApplicationAccess, type OrganizationMemberApplicationAccessInput, type OrganizationMemberAuthority, type OrganizationMemberPage, type OrganizationMemberPageInput, type OrganizationPage, type OrganizationPageInput, type OrganizationPresenceAuthorization, type OrganizationPresenceInput, type OrganizationTeam, type OrganizationTeamDisplay, type OrganizationTeamMemberPage, type OrganizationTeamPage, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type ReceivedOrganizationInvitation, type ReceivedOrganizationInvitationPage, type RegisterOrganizationApplicationInput, type RegisteredOrganizationApplication, type RemovedOrganizationMember, type RemovedOrganizationTeamMember, type ResentOrganizationInvitation, type ResolveDriveRecipientInput, type ResolveIdentityInput, type ResolveMembershipBatchInput, type ResolveMembershipInput, type ResolvedIdentity, type ResolvedMembership, type ResolvedMembershipBatch, type ResolvedMembershipRole, ServerAuthOptions, ServerInvitationAcceptance, ServerSignOutResult, ServerSocialIdTokenSession, type SocialIdTokenInput, type SocialIdTokenProvider, type UpdateOrganizationDisplayInput, type UpdateOrganizationTeamDisplayInput, type UserApiCredential, type UserApiCredentialInput, type UserApiIdentity, type UserApiVerifierOptions, type UserDirectoryAuthOptions, type UserDirectoryBinding, type UserDirectoryEntry, type UserDirectoryListInput, type UserDirectoryLookupInput, type UserDirectoryMember, type UserDirectoryMembersInput, type UserDirectoryMembersPage, type UserDirectoryPage, type UserDirectoryResolveInput, type WorkspaceSelection, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationDirectoryAuth, createServerAuth, createUserApiVerifier, createUserDirectoryAuth };
|
package/dist/server.js
CHANGED
|
@@ -3475,6 +3475,168 @@ function createDriveProvisioningAuth(options) {
|
|
|
3475
3475
|
} };
|
|
3476
3476
|
}
|
|
3477
3477
|
//#endregion
|
|
3478
|
+
//#region src/user-directory.ts
|
|
3479
|
+
function user(value, applicationId) {
|
|
3480
|
+
if (!exact$6(value, [
|
|
3481
|
+
"applicationId",
|
|
3482
|
+
"userId",
|
|
3483
|
+
"userGeneration",
|
|
3484
|
+
"lifecycle"
|
|
3485
|
+
]) || value.applicationId !== applicationId || !directoryGeneration(value.userId) || !directoryGeneration(value.userGeneration) || ![
|
|
3486
|
+
"active",
|
|
3487
|
+
"suspended",
|
|
3488
|
+
"deleted"
|
|
3489
|
+
].includes(String(value.lifecycle))) throw authorityUnavailable();
|
|
3490
|
+
return {
|
|
3491
|
+
applicationId,
|
|
3492
|
+
userId: value.userId,
|
|
3493
|
+
userGeneration: value.userGeneration,
|
|
3494
|
+
lifecycle: value.lifecycle
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
function exactInput(input) {
|
|
3498
|
+
if (!exact$6(input, [
|
|
3499
|
+
"applicationId",
|
|
3500
|
+
"userId",
|
|
3501
|
+
"userGeneration"
|
|
3502
|
+
]) || !directoryId(input.applicationId) || !directoryGeneration(input.userId) || !directoryGeneration(input.userGeneration)) throw new AuthError("invalid_request", 400);
|
|
3503
|
+
}
|
|
3504
|
+
function pageInput(input, members = false) {
|
|
3505
|
+
if (!record$1(input) || Object.keys(input).some((key) => ![
|
|
3506
|
+
"applicationId",
|
|
3507
|
+
"limit",
|
|
3508
|
+
"cursor",
|
|
3509
|
+
...members ? ["organizationId", "organizationGeneration"] : []
|
|
3510
|
+
].includes(key)) || !directoryId(input.applicationId) || input.limit !== void 0 && (!Number.isInteger(input.limit) || input.limit < 1 || input.limit > 100) || input.cursor !== void 0 && (typeof input.cursor !== "string" || input.cursor.length < 1 || input.cursor.length > 2048) || members && (!directoryId(input.organizationId) || !directoryGeneration(input.organizationGeneration))) throw new AuthError("invalid_request", 400);
|
|
3511
|
+
}
|
|
3512
|
+
function nextCursor(value) {
|
|
3513
|
+
if (value !== null && (typeof value !== "string" || !value.length || value.length > 2048)) throw authorityUnavailable();
|
|
3514
|
+
return value;
|
|
3515
|
+
}
|
|
3516
|
+
function selectedUser(value, input) {
|
|
3517
|
+
const normalized = user(value, input.applicationId);
|
|
3518
|
+
if (normalized.userId !== input.userId || normalized.userGeneration !== input.userGeneration) throw authorityUnavailable();
|
|
3519
|
+
return normalized;
|
|
3520
|
+
}
|
|
3521
|
+
function createUserDirectoryAuth(options) {
|
|
3522
|
+
const origin = normalizeOrigin(options.authOrigin, "authOrigin");
|
|
3523
|
+
const fetchImpl = options.fetch ?? globalThis.fetch?.bind(globalThis);
|
|
3524
|
+
if (typeof fetchImpl !== "function") throw new TypeError("fetch is required");
|
|
3525
|
+
const timeoutMs = normalizeTimeout(options.timeoutMs);
|
|
3526
|
+
let inFlight = 0;
|
|
3527
|
+
async function exchange(operation, body, assertion) {
|
|
3528
|
+
if (typeof assertion !== "string" || assertion.length > 16 * 1024 || !/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$(?![\s\S])/.test(assertion)) throw new AuthError("invalid_request", 400);
|
|
3529
|
+
if (inFlight >= 4) throw new AuthError("state_conflict", 409);
|
|
3530
|
+
inFlight += 1;
|
|
3531
|
+
const controller = new AbortController();
|
|
3532
|
+
let timer;
|
|
3533
|
+
const deadline = new Promise((_, reject) => {
|
|
3534
|
+
timer = setTimeout(() => {
|
|
3535
|
+
reject(authorityUnavailable());
|
|
3536
|
+
controller.abort();
|
|
3537
|
+
}, timeoutMs);
|
|
3538
|
+
});
|
|
3539
|
+
try {
|
|
3540
|
+
return await Promise.race([requestJson(joinURL(origin, "api/v1/auth/user-directory", operation), {
|
|
3541
|
+
fetch: fetchImpl,
|
|
3542
|
+
timeoutMs,
|
|
3543
|
+
method: "POST",
|
|
3544
|
+
credentials: "omit",
|
|
3545
|
+
cache: "no-store",
|
|
3546
|
+
headers: {
|
|
3547
|
+
"x-finueva-service-assertion": assertion,
|
|
3548
|
+
"content-type": "application/json",
|
|
3549
|
+
accept: "application/json"
|
|
3550
|
+
},
|
|
3551
|
+
body,
|
|
3552
|
+
maxResponseBytes: 128 * 1024,
|
|
3553
|
+
signal: controller.signal
|
|
3554
|
+
}).finally(() => {
|
|
3555
|
+
inFlight -= 1;
|
|
3556
|
+
}), deadline]);
|
|
3557
|
+
} catch (cause) {
|
|
3558
|
+
if (cause instanceof AuthError) throw cause;
|
|
3559
|
+
throw authorityUnavailable();
|
|
3560
|
+
} finally {
|
|
3561
|
+
clearTimeout(timer);
|
|
3562
|
+
controller.abort();
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
return {
|
|
3566
|
+
async listUsers(input, assertion) {
|
|
3567
|
+
pageInput(input);
|
|
3568
|
+
const value = await exchange("list", input, assertion);
|
|
3569
|
+
if (!exact$6(value, ["users", "nextCursor"]) || !Array.isArray(value.users) || value.users.length > (input.limit ?? 50)) throw authorityUnavailable();
|
|
3570
|
+
const users = value.users.map((item) => user(item, input.applicationId));
|
|
3571
|
+
if (users.some((item) => item.lifecycle === "deleted") || new Set(users.map((item) => item.userId)).size !== users.length) throw authorityUnavailable();
|
|
3572
|
+
return {
|
|
3573
|
+
users,
|
|
3574
|
+
nextCursor: nextCursor(value.nextCursor)
|
|
3575
|
+
};
|
|
3576
|
+
},
|
|
3577
|
+
async lookupUser(input, assertion) {
|
|
3578
|
+
exactInput(input);
|
|
3579
|
+
const value = await exchange("lookup", input, assertion);
|
|
3580
|
+
if (!exact$6(value, ["user"])) throw authorityUnavailable();
|
|
3581
|
+
return value.user === null ? null : selectedUser(value.user, input);
|
|
3582
|
+
},
|
|
3583
|
+
async listOrganizationMembers(input, assertion) {
|
|
3584
|
+
pageInput(input, true);
|
|
3585
|
+
const value = await exchange("members", input, assertion);
|
|
3586
|
+
if (!exact$6(value, [
|
|
3587
|
+
"applicationId",
|
|
3588
|
+
"organizationId",
|
|
3589
|
+
"organizationGeneration",
|
|
3590
|
+
"members",
|
|
3591
|
+
"nextCursor"
|
|
3592
|
+
]) || value.applicationId !== input.applicationId || value.organizationId !== input.organizationId || value.organizationGeneration !== input.organizationGeneration || !Array.isArray(value.members) || value.members.length > (input.limit ?? 50)) throw authorityUnavailable();
|
|
3593
|
+
const members = value.members.map((item) => {
|
|
3594
|
+
if (!exact$6(item, [
|
|
3595
|
+
"user",
|
|
3596
|
+
"role",
|
|
3597
|
+
"membershipStatus"
|
|
3598
|
+
]) || item.role !== "owner" && item.role !== "admin" && item.role !== "member" || item.membershipStatus !== "active" && item.membershipStatus !== "suspended") throw authorityUnavailable();
|
|
3599
|
+
const normalized = user(item.user, input.applicationId);
|
|
3600
|
+
if (normalized.lifecycle === "deleted") throw authorityUnavailable();
|
|
3601
|
+
return {
|
|
3602
|
+
user: normalized,
|
|
3603
|
+
role: item.role,
|
|
3604
|
+
membershipStatus: item.membershipStatus
|
|
3605
|
+
};
|
|
3606
|
+
});
|
|
3607
|
+
if (new Set(members.map((item) => item.user.userId)).size !== members.length) throw authorityUnavailable();
|
|
3608
|
+
return {
|
|
3609
|
+
applicationId: input.applicationId,
|
|
3610
|
+
organizationId: input.organizationId,
|
|
3611
|
+
organizationGeneration: input.organizationGeneration,
|
|
3612
|
+
members,
|
|
3613
|
+
nextCursor: nextCursor(value.nextCursor)
|
|
3614
|
+
};
|
|
3615
|
+
},
|
|
3616
|
+
async resolveUser(input, assertion) {
|
|
3617
|
+
if (!exact$6(input, ["applicationId", "authUserId"]) || !directoryId(input.applicationId) || !directoryId(input.authUserId)) throw new AuthError("invalid_request", 400);
|
|
3618
|
+
const value = await exchange("resolve", input, assertion);
|
|
3619
|
+
if (!exact$6(value, ["user"])) throw authorityUnavailable();
|
|
3620
|
+
const result = value.user === null ? null : user(value.user, input.applicationId);
|
|
3621
|
+
if (result?.lifecycle === "deleted") throw authorityUnavailable();
|
|
3622
|
+
return result;
|
|
3623
|
+
},
|
|
3624
|
+
async resolveUserBinding(input, assertion) {
|
|
3625
|
+
exactInput(input);
|
|
3626
|
+
const value = await exchange("binding", input, assertion);
|
|
3627
|
+
if (!exact$6(value, ["binding"])) throw authorityUnavailable();
|
|
3628
|
+
if (value.binding === null) return null;
|
|
3629
|
+
if (!exact$6(value.binding, ["user", "authUserId"]) || !directoryId(value.binding.authUserId)) throw authorityUnavailable();
|
|
3630
|
+
const result = selectedUser(value.binding.user, input);
|
|
3631
|
+
if (result.lifecycle === "deleted") throw authorityUnavailable();
|
|
3632
|
+
return {
|
|
3633
|
+
user: result,
|
|
3634
|
+
authUserId: value.binding.authUserId
|
|
3635
|
+
};
|
|
3636
|
+
}
|
|
3637
|
+
};
|
|
3638
|
+
}
|
|
3639
|
+
//#endregion
|
|
3478
3640
|
//#region src/server.ts
|
|
3479
3641
|
const MAX_AUTHORIZATION_BYTES = 16 * 1024;
|
|
3480
3642
|
function createServerAuth(options) {
|
|
@@ -4035,4 +4197,4 @@ function authAuthorizationHeader(value) {
|
|
|
4035
4197
|
return value;
|
|
4036
4198
|
}
|
|
4037
4199
|
//#endregion
|
|
4038
|
-
export { AuthError, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationDirectoryAuth, createServerAuth, createUserApiVerifier };
|
|
4200
|
+
export { AuthError, createAccountProductOperationAuth, createDriveProvisioningAuth, createDriveRecipientAuth, createIdentityResolverAuth, createMembershipResolverAuth, createOrganizationDirectoryAuth, createServerAuth, createUserApiVerifier, createUserDirectoryAuth };
|