1- import { User } from '@sofie-automation/meteor-lib/dist/collections/Users'
21import { PeripheralDevice } from '@sofie-automation/corelib/dist/dataModel/PeripheralDevice'
32import { cacheResult } from '../../lib/cacheResult'
43import { LIMIT_CACHE_TIME } from './security'
@@ -12,12 +11,6 @@ export interface Credentials {
1211 token ?: string
1312}
1413
15- /**
16- * A minimal set of properties about the user.
17- * We keep it small so that we don't cache too much in memory or have to invalidate the credentials when something insignificant changes
18- */
19- export type ResolvedUser = Pick < User , '_id' | 'organizationId' | 'superAdmin' >
20-
2114/**
2215 * A minimal set of properties about the OeripheralDevice.
2316 * We keep it small so that we don't cache too much in memory or have to invalidate the credentials when something insignificant changes
@@ -26,54 +19,9 @@ export type ResolvedPeripheralDevice = Pick<PeripheralDevice, '_id' | 'organizat
2619
2720export interface ResolvedCredentials {
2821 organizationId : OrganizationId | null
29- user ?: ResolvedUser
22+ user ?: any
3023 device ?: ResolvedPeripheralDevice
3124}
32- export interface ResolvedUserCredentials {
33- organizationId : OrganizationId
34- user : ResolvedUser
35- }
36- export interface ResolvedPeripheralDeviceCredentials {
37- organizationId : OrganizationId
38- device : ResolvedPeripheralDevice
39- }
40-
41- /**
42- * Resolve the provided credentials, and retrieve the PeripheralDevice and Organization for the provided credentials.
43- * @returns null if the PeripheralDevice was not found
44- */
45- export async function resolveAuthenticatedPeripheralDevice (
46- cred : Credentials
47- ) : Promise < ResolvedPeripheralDeviceCredentials | null > {
48- const resolved = await resolveCredentials ( { userId : null , token : cred . token } )
49-
50- if ( resolved . device && resolved . organizationId ) {
51- return {
52- organizationId : resolved . organizationId ,
53- device : resolved . device ,
54- }
55- } else {
56- return null
57- }
58- }
59-
60- /**
61- * Resolve the provided credentials, and retrieve the User and Organization for the provided credentials.
62- * Note: this requies that the UserId came from a trusted source,it must not be from user input
63- * @returns null if the user was not found
64- */
65- export async function resolveAuthenticatedUser ( cred : Credentials ) : Promise < ResolvedUserCredentials | null > {
66- const resolved = await resolveCredentials ( { userId : cred . userId } )
67-
68- if ( resolved . user && resolved . organizationId ) {
69- return {
70- organizationId : resolved . organizationId ,
71- user : resolved . user ,
72- }
73- } else {
74- return null
75- }
76- }
7725
7826/**
7927 * Resolve the provided credentials/identifier, and fetch the authenticating document from the database.
@@ -152,7 +100,7 @@ export async function resolveCredentials(cred: Credentials | ResolvedCredentials
152100function credCacheName ( cred : Credentials ) {
153101 return `resolveCredentials_${ cred . userId } _${ cred . token } `
154102}
155- export function isResolvedCredentials ( cred : Credentials | ResolvedCredentials ) : cred is ResolvedCredentials {
103+ function isResolvedCredentials ( cred : Credentials | ResolvedCredentials ) : cred is ResolvedCredentials {
156104 const c = cred as ResolvedCredentials
157105 return ! ! ( c . user || c . organizationId || c . device )
158106}
0 commit comments