0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-24 22:41:28 -05:00

refactor: fix type issues

This commit is contained in:
Gao Sun 2024-03-20 11:00:11 +08:00
parent beff82ae2c
commit 1bc40faf98
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
19 changed files with 194 additions and 162 deletions

View file

@ -19,9 +19,11 @@ export const mockUser: User = {
logtoConfig: {},
mfaVerifications: [],
customData: {},
profile: {},
applicationId: 'bar',
lastSignInAt: 1_650_969_465_789,
createdAt: 1_650_969_000_000,
updatedAt: 1_650_969_000_000,
isSuspended: false,
};
@ -73,9 +75,11 @@ export const mockUserWithPassword: User = {
customData: {},
logtoConfig: {},
mfaVerifications: [],
profile: {},
applicationId: 'bar',
lastSignInAt: 1_650_969_465_789,
createdAt: 1_650_969_000_000,
updatedAt: 1_650_969_000_000,
isSuspended: false,
};
@ -94,9 +98,11 @@ export const mockUserList: User[] = [
customData: {},
logtoConfig: {},
mfaVerifications: [],
profile: {},
applicationId: 'bar',
lastSignInAt: 1_650_969_465_000,
createdAt: 1_650_969_000_000,
updatedAt: 1_650_969_000_000,
isSuspended: false,
},
{
@ -113,9 +119,11 @@ export const mockUserList: User[] = [
customData: {},
logtoConfig: {},
mfaVerifications: [],
profile: {},
applicationId: 'bar',
lastSignInAt: 1_650_969_465_000,
createdAt: 1_650_969_000_000,
updatedAt: 1_650_969_000_000,
isSuspended: false,
},
{
@ -132,9 +140,11 @@ export const mockUserList: User[] = [
customData: {},
logtoConfig: {},
mfaVerifications: [],
profile: {},
applicationId: 'bar',
lastSignInAt: 1_650_969_465_000,
createdAt: 1_650_969_000_000,
updatedAt: 1_650_969_000_000,
isSuspended: false,
},
{
@ -151,9 +161,11 @@ export const mockUserList: User[] = [
customData: {},
logtoConfig: {},
mfaVerifications: [],
profile: {},
applicationId: 'bar',
lastSignInAt: 1_650_969_465_000,
createdAt: 1_650_969_000_000,
updatedAt: 1_650_969_000_000,
isSuspended: false,
},
{
@ -170,9 +182,11 @@ export const mockUserList: User[] = [
customData: {},
logtoConfig: {},
mfaVerifications: [],
profile: {},
applicationId: 'bar',
lastSignInAt: 1_650_969_465_000,
createdAt: 1_650_969_000_000,
updatedAt: 1_650_969_000_000,
isSuspended: false,
},
];

View file

@ -65,10 +65,12 @@ export const generateHookTestPayload = (hookId: string, event: HookEvent): HookE
userId: 'fake-google-user-id',
},
},
profile: {},
applicationId: 'fake-application-id',
isSuspended: false,
lastSignInAt: now.getTime(),
createdAt: now.getTime(),
updatedAt: now.getTime(),
},
application: {
id: 'fake-spa-application-id',

View file

@ -5,18 +5,33 @@ const use = {
userinfo: 'userinfo',
} as const;
const profileExpectation = Object.freeze([
'name',
'family_name',
'given_name',
'middle_name',
'nickname',
'preferred_username',
'profile',
'picture',
'website',
'gender',
'birthdate',
'zoneinfo',
'locale',
'updated_at',
'username',
'created_at',
]);
describe('OIDC getUserClaims()', () => {
it('should return proper ID Token claims', () => {
expect(getAcceptedUserClaims(use.idToken, 'openid profile', {}, [])).toEqual([
'name',
'picture',
'username',
]);
expect(getAcceptedUserClaims(use.idToken, 'openid profile', {}, [])).toEqual(
profileExpectation
);
expect(getAcceptedUserClaims(use.idToken, 'openid profile email phone', {}, [])).toEqual([
'name',
'picture',
'username',
...profileExpectation,
'email',
'email_verified',
'phone_number',
@ -25,23 +40,23 @@ describe('OIDC getUserClaims()', () => {
expect(
getAcceptedUserClaims(use.idToken, 'openid profile custom_data identities', {}, [])
).toEqual(['name', 'picture', 'username']);
).toEqual(profileExpectation);
expect(
getAcceptedUserClaims(use.idToken, 'openid profile email', {}, ['email_verified'])
).toEqual(['name', 'picture', 'username', 'email']);
).toEqual([...profileExpectation, 'email']);
});
it('should return proper Userinfo claims', () => {
expect(
getAcceptedUserClaims(use.userinfo, 'openid profile custom_data identities', {}, [])
).toEqual(['name', 'picture', 'username', 'custom_data', 'identities']);
).toEqual([...profileExpectation, 'custom_data', 'identities']);
});
// Ignore `_claims` since [Claims Parameter](https://github.com/panva/node-oidc-provider/tree/main/docs#featuresclaimsparameter) is not enabled
it('should ignore claims parameter', () => {
expect(
getAcceptedUserClaims(use.idToken, 'openid profile custom_data', { email: null }, [])
).toEqual(['name', 'picture', 'username']);
).toEqual(profileExpectation);
});
});

View file

@ -49,6 +49,7 @@ describe('user query', () => {
const { table, fields } = convertToIdentifiers(Users);
const databaseValue = {
...mockUser,
profile: JSON.stringify({}),
identities: JSON.stringify(mockUser.identities),
customData: JSON.stringify(mockUser.customData),
logtoConfig: JSON.stringify(mockUser.logtoConfig),
@ -321,6 +322,7 @@ describe('user query', () => {
const { connector1, ...restIdentities } = mockUser.identities;
const finalDbvalue = {
...mockUser,
profile: JSON.stringify({}),
identities: JSON.stringify(restIdentities),
customData: JSON.stringify(mockUser.customData),
logtoConfig: JSON.stringify(mockUser.logtoConfig),

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,15 +1,14 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
[UserScope.CustomData]: 'Your custom data',
[UserScope.Email]: 'Your email address',
[UserScope.Phone]: 'Your phone number',
[UserScope.Profile]: 'Your name, username and avatar',
[UserScope.Roles]: 'Your roles',
[UserScope.Identities]: 'Your linked social identities',
[UserScope.Organizations]: 'Your organizations info',
[UserScope.OrganizationRoles]: 'Your organization roles',
custom_data: 'Your custom data',
email: 'Your email address',
phone: 'Your phone number',
profile: 'Your name, username, avatar, and other profile info',
roles: 'Your roles',
identities: 'Your linked social identities',
'urn:logto:scope:organizations': 'Your organizations info',
'urn:logto:scope:organization_roles': 'Your organization roles',
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};

View file

@ -1,23 +1,23 @@
import { UserScope } from '@logto/core-kit';
const user_scopes = {
descriptions: {
/** UNTRANSLATED */
[UserScope.CustomData]: 'Your custom data',
custom_data: 'Your custom data',
/** UNTRANSLATED */
[UserScope.Email]: 'Your email address',
email: 'Your email address',
/** UNTRANSLATED */
[UserScope.Phone]: 'Your phone number',
phone: 'Your phone number',
/** UNTRANSLATED */
[UserScope.Profile]: 'Your name, username and avatar',
profile: 'Your name, username, avatar, and other profile info',
/** UNTRANSLATED */
[UserScope.Roles]: 'Your roles',
roles: 'Your roles',
/** UNTRANSLATED */
[UserScope.Identities]: 'Your linked social identities',
identities: 'Your linked social identities',
/** UNTRANSLATED */
[UserScope.Organizations]: 'Your organizations info',
'urn:logto:scope:organizations': 'Your organizations info',
/** UNTRANSLATED */
[UserScope.OrganizationRoles]: 'Your organization roles',
'urn:logto:scope:organization_roles': 'Your organization roles',
/** UNTRANSLATED */
address: 'Your address',
},
};