diff --git a/keyserver/src/responders/activity-responders.js b/keyserver/src/responders/activity-responders.js --- a/keyserver/src/responders/activity-responders.js +++ b/keyserver/src/responders/activity-responders.js @@ -1,13 +1,14 @@ // @flow import t from 'tcomb'; -import type { TList, TInterface } from 'tcomb'; +import type { TList } from 'tcomb'; import type { UpdateActivityResult, UpdateActivityRequest, SetThreadUnreadStatusRequest, SetThreadUnreadStatusResult, + ActivityUpdate, } from 'lib/types/activity-types.js'; import { tShape } from 'lib/utils/validation-utils.js'; @@ -18,7 +19,7 @@ } from '../updaters/activity-updaters.js'; import { validateInput } from '../utils/validation-utils.js'; -const activityUpdatesInputValidator: TList = t.list( +const activityUpdatesInputValidator: TList> = t.list( tShape({ focus: t.Bool, threadID: t.String, diff --git a/keyserver/src/responders/device-responders.js b/keyserver/src/responders/device-responders.js --- a/keyserver/src/responders/device-responders.js +++ b/keyserver/src/responders/device-responders.js @@ -10,11 +10,12 @@ import { deviceTokenUpdater } from '../updaters/device-token-updaters.js'; import { validateInput } from '../utils/validation-utils.js'; -const deviceTokenUpdateRequestInputValidator: TInterface = tShape({ - deviceToken: t.maybe(t.String), - deviceType: t.maybe(t.enums.of(['ios', 'android'])), - platformDetails: t.maybe(tPlatformDetails), -}); +const deviceTokenUpdateRequestInputValidator: TInterface = + tShape({ + deviceToken: t.maybe(t.String), + deviceType: t.maybe(t.enums.of(['ios', 'android'])), + platformDetails: t.maybe(tPlatformDetails), + }); async function deviceTokenUpdateResponder( viewer: Viewer, diff --git a/keyserver/src/responders/entry-responders.js b/keyserver/src/responders/entry-responders.js --- a/keyserver/src/responders/entry-responders.js +++ b/keyserver/src/responders/entry-responders.js @@ -16,7 +16,10 @@ DeltaEntryInfosResult, SaveEntryResponse, } from 'lib/types/entry-types.js'; -import { calendarThreadFilterTypes } from 'lib/types/filter-types.js'; +import { + type CalendarFilter, + calendarThreadFilterTypes, +} from 'lib/types/filter-types.js'; import type { FetchEntryRevisionInfosResult, FetchEntryRevisionInfosRequest, @@ -40,7 +43,14 @@ import { commitSessionUpdate } from '../updaters/session-updaters.js'; import { validateInput } from '../utils/validation-utils.js'; -const entryQueryInputValidator: TInterface = tShape({ +type EntryQueryInput = { + +startDate: string, + +endDate: string, + +navID?: ?string, + +includeDeleted?: ?boolean, + +filters?: ?$ReadOnlyArray, +}; +const entryQueryInputValidator: TInterface = tShape({ navID: t.maybe(t.String), startDate: tDate, endDate: tDate, @@ -59,7 +69,8 @@ ), ), }); -const newEntryQueryInputValidator: TInterface = tShape({ + +const newEntryQueryInputValidator: TInterface = tShape({ startDate: tDate, endDate: tDate, filters: t.list( diff --git a/keyserver/src/responders/report-responders.js b/keyserver/src/responders/report-responders.js --- a/keyserver/src/responders/report-responders.js +++ b/keyserver/src/responders/report-responders.js @@ -9,6 +9,8 @@ type ReportCreationRequest, type FetchErrorReportInfosResponse, type FetchErrorReportInfosRequest, + type ThreadInconsistencyReportShape, + type EntryInconsistencyReportShape, reportTypes, } from 'lib/types/report-types.js'; import { ServerError } from 'lib/utils/errors.js'; @@ -32,27 +34,29 @@ time: t.Number, summary: t.String, }); -const threadInconsistencyReportValidatorShape: TStructProps = { - platformDetails: tPlatformDetails, - beforeAction: t.Object, - action: t.Object, - pollResult: t.maybe(t.Object), - pushResult: t.Object, - lastActionTypes: t.maybe(t.list(t.String)), - lastActions: t.maybe(t.list(tActionSummary)), - time: t.maybe(t.Number), -}; -const entryInconsistencyReportValidatorShape: TStructProps = { - platformDetails: tPlatformDetails, - beforeAction: t.Object, - action: t.Object, - calendarQuery: newEntryQueryInputValidator, - pollResult: t.maybe(t.Object), - pushResult: t.Object, - lastActionTypes: t.maybe(t.list(t.String)), - lastActions: t.maybe(t.list(tActionSummary)), - time: t.Number, -}; +const threadInconsistencyReportValidatorShape: TStructProps = + { + platformDetails: tPlatformDetails, + beforeAction: t.Object, + action: t.Object, + pollResult: t.maybe(t.Object), + pushResult: t.Object, + lastActionTypes: t.maybe(t.list(t.String)), + lastActions: t.maybe(t.list(tActionSummary)), + time: t.maybe(t.Number), + }; +const entryInconsistencyReportValidatorShape: TStructProps = + { + platformDetails: tPlatformDetails, + beforeAction: t.Object, + action: t.Object, + calendarQuery: newEntryQueryInputValidator, + pollResult: t.maybe(t.Object), + pushResult: t.Object, + lastActionTypes: t.maybe(t.list(t.String)), + lastActions: t.maybe(t.list(tActionSummary)), + time: t.Number, + }; const userInconsistencyReportValidatorShape = { platformDetails: tPlatformDetails, action: t.Object, diff --git a/keyserver/src/responders/thread-responders.js b/keyserver/src/responders/thread-responders.js --- a/keyserver/src/responders/thread-responders.js +++ b/keyserver/src/responders/thread-responders.js @@ -1,7 +1,7 @@ // @flow import t from 'tcomb'; -import type { TUnion, TInterface } from 'tcomb'; +import type { TUnion } from 'tcomb'; import { type ThreadDeletionRequest, @@ -138,7 +138,7 @@ initialMemberIDs: t.maybe(t.list(t.String)), calendarQuery: t.maybe(entryQueryInputValidator), }; -const newThreadRequestInputValidator: TUnion = t.union([ +const newThreadRequestInputValidator: TUnion = t.union([ tShape({ type: tNumEnum([threadTypes.SIDEBAR]), sourceMessageID: t.String, diff --git a/keyserver/src/socket/session-utils.js b/keyserver/src/socket/session-utils.js --- a/keyserver/src/socket/session-utils.js +++ b/keyserver/src/socket/session-utils.js @@ -2,7 +2,7 @@ import invariant from 'invariant'; import t from 'tcomb'; -import type { TUnion, TInterface } from 'tcomb'; +import type { TUnion } from 'tcomb'; import { usersInRawEntryInfos, @@ -74,7 +74,7 @@ import type { SessionUpdate } from '../updaters/session-updaters.js'; import { getOlmUtility } from '../utils/olm-utils.js'; -const clientResponseInputValidator: TUnion = t.union([ +const clientResponseInputValidator: TUnion = t.union([ tShape({ type: t.irreducible( 'serverRequestTypes.PLATFORM', diff --git a/lib/flow-typed/npm/tcomb_v3.x.x.js b/lib/flow-typed/npm/tcomb_v3.x.x.js --- a/lib/flow-typed/npm/tcomb_v3.x.x.js +++ b/lib/flow-typed/npm/tcomb_v3.x.x.js @@ -2,532 +2,135 @@ // flow-typed version: <>/tcomb_v3.2.29/flow_v0.137.0 declare module 'tcomb' { - declare type TBaseMeta = { - +kind: string, - +name: string, - +identity: boolean, - ... - }; - - declare export class TType { + declare class TBaseType<+T> { (val: T): this; is(val: mixed): boolean; displayName: string; - meta: M; - t: T; + +t: T; } - declare export class TIrreducible extends TType boolean, - |}> { } - - declare export class TMaybe extends TType, - |}> { } - - declare export class TList extends TType, {| - +kind: string, - +name: string, - +identity: boolean, - +type: TType, - |}> { } - - declare export class TDict extends TType<{ [key: string]: T }, {| - +kind: string, - +name: string, - +identity: boolean, - +domain: TType, - +codomain: T, - |}> { } + declare export type TType<+T> = + | TIrreducible + | TMaybe + | TList + | TDict + | TUnion + | TEnums + | TRefinement + | TInterface; + + declare export class TIrreducible<+T> extends TBaseType { + meta: { + +kind: 'irreducible', + +name: string, + +identity: boolean, + +predicate: mixed => boolean, + } + } + + declare export class TMaybe<+T> extends TBaseType { + meta: { + +kind: 'maybe', + +name: string, + +identity: boolean, + +type: TType, + } + } + + declare export class TList<+T> extends TBaseType { + meta: { + +kind: 'list', + +name: string, + +identity: boolean, + +type: TType, + } + } + + declare export class TDict<+T> extends TBaseType { + meta: { + +kind: 'dict', + +name: string, + +identity: boolean, + +domain: TType, + +codomain: TType, + } + } + + declare export class TUnion<+T> extends TBaseType { + meta: { + +kind: 'union', + +name: string, + +identity: boolean, + +types: Array>, + } + } - declare export class TUnion extends TType>, - |}> { } + declare export class TEnums extends TBaseType { + meta: { + +kind: 'enums', + +name: string, + +identity: boolean, + +map: Object, + } + } - declare export class TEnums extends TType { } + declare export class TRefinement<+T> extends TBaseType { + meta: { + +kind: 'subtype', + +name: string, + +identity: boolean, + +type: TType, + +predicate: mixed => boolean, + } + } - declare export class TRefinement extends TType, - +predicate: mixed => boolean, - |}> { } + declare type TypeToValidator = (v: V) => TType; - declare export type TStructProps = { [key: string]: TType }; + declare export type TStructProps<+T> = $ObjMap; declare type TStructOptions = {| name?: string, strict?: boolean, defaultProps?: Object, |}; - declare export class TInterface extends TType { } + + declare export class TInterface<+T> extends TBaseType { + meta: {| + +kind: 'interface', + +name: string, + +identity: boolean, + +props: TStructProps, + +strict: boolean, + |} + } declare export default { + +Nil: TIrreducible, +Bool: TIrreducible, +Boolean: TIrreducible, +String: TIrreducible, +Number: TIrreducible, +Object: TIrreducible, - maybe(type: TType, name?: string): TMaybe, - list(type: TType, name?: string): TList, - dict( - domain: TType, - codomain: TType, + maybe(type: TType, name?: string): TMaybe, + list(type: TType, name?: string): TList>, + dict( + domain: TType, + codomain: TType, name?: string, - ): TDict, - union(types: Array>, name?: string): TUnion, + ): TDict<{ [key: string]: T }>, + union<+T>(types: $ReadOnlyArray>, name?: string): TUnion, +enums: {| of(enums: $ReadOnlyArray, name?: string): TEnums, |}, irreducible(name: string, predicate: mixed => boolean): TIrreducible, - refinement( - type: TType, + refinement( + type: TType, predicate: T => boolean, name?: string, ): TRefinement, - interface( - props: TStructProps, + interface( + props: TStructProps, options?: string | TStructOptions, - ): TInterface, + ): TInterface, ... }; } - -/** - * We include stubs for each file inside this npm package in case you need to - * require those files directly. Feel free to delete any files that aren't - * needed. - */ -declare module 'tcomb/lib/Any' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Array' { - declare module.exports: any; -} - -declare module 'tcomb/lib/assert' { - declare module.exports: any; -} - -declare module 'tcomb/lib/assign' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Boolean' { - declare module.exports: any; -} - -declare module 'tcomb/lib/create' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Date' { - declare module.exports: any; -} - -declare module 'tcomb/lib/declare' { - declare module.exports: any; -} - -declare module 'tcomb/lib/decompose' { - declare module.exports: any; -} - -declare module 'tcomb/lib/dict' { - declare module.exports: any; -} - -declare module 'tcomb/lib/enums' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Error' { - declare module.exports: any; -} - -declare module 'tcomb/lib/extend' { - declare module.exports: any; -} - -declare module 'tcomb/lib/fail' { - declare module.exports: any; -} - -declare module 'tcomb/lib/forbidNewOperator' { - declare module.exports: any; -} - -declare module 'tcomb/lib/fromJSON' { - declare module.exports: any; -} - -declare module 'tcomb/lib/func' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Function' { - declare module.exports: any; -} - -declare module 'tcomb/lib/getDefaultInterfaceName' { - declare module.exports: any; -} - -declare module 'tcomb/lib/getFunctionName' { - declare module.exports: any; -} - -declare module 'tcomb/lib/getTypeName' { - declare module.exports: any; -} - -declare module 'tcomb/lib/installTypeFormatter' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Integer' { - declare module.exports: any; -} - -declare module 'tcomb/lib/interface' { - declare module.exports: any; -} - -declare module 'tcomb/lib/intersection' { - declare module.exports: any; -} - -declare module 'tcomb/lib/irreducible' { - declare module.exports: any; -} - -declare module 'tcomb/lib/is' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isArray' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isBoolean' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isFunction' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isIdentity' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isInterface' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isMaybe' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isNil' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isNumber' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isObject' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isString' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isStruct' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isSubsetOf' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isType' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isTypeName' { - declare module.exports: any; -} - -declare module 'tcomb/lib/isUnion' { - declare module.exports: any; -} - -declare module 'tcomb/lib/list' { - declare module.exports: any; -} - -declare module 'tcomb/lib/match' { - declare module.exports: any; -} - -declare module 'tcomb/lib/maybe' { - declare module.exports: any; -} - -declare module 'tcomb/lib/mixin' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Nil' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Number' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Object' { - declare module.exports: any; -} - -declare module 'tcomb/lib/refinement' { - declare module.exports: any; -} - -declare module 'tcomb/lib/RegExp' { - declare module.exports: any; -} - -declare module 'tcomb/lib/String' { - declare module.exports: any; -} - -declare module 'tcomb/lib/stringify' { - declare module.exports: any; -} - -declare module 'tcomb/lib/struct' { - declare module.exports: any; -} - -declare module 'tcomb/lib/tuple' { - declare module.exports: any; -} - -declare module 'tcomb/lib/Type' { - declare module.exports: any; -} - -declare module 'tcomb/lib/union' { - declare module.exports: any; -} - -declare module 'tcomb/lib/update' { - declare module.exports: any; -} - -// Filename aliases -declare module 'tcomb/index' { - declare module.exports: $Exports<'tcomb'>; -} -declare module 'tcomb/index.js' { - declare module.exports: $Exports<'tcomb'>; -} -declare module 'tcomb/lib/Any.js' { - declare module.exports: $Exports<'tcomb/lib/Any'>; -} -declare module 'tcomb/lib/Array.js' { - declare module.exports: $Exports<'tcomb/lib/Array'>; -} -declare module 'tcomb/lib/assert.js' { - declare module.exports: $Exports<'tcomb/lib/assert'>; -} -declare module 'tcomb/lib/assign.js' { - declare module.exports: $Exports<'tcomb/lib/assign'>; -} -declare module 'tcomb/lib/Boolean.js' { - declare module.exports: $Exports<'tcomb/lib/Boolean'>; -} -declare module 'tcomb/lib/create.js' { - declare module.exports: $Exports<'tcomb/lib/create'>; -} -declare module 'tcomb/lib/Date.js' { - declare module.exports: $Exports<'tcomb/lib/Date'>; -} -declare module 'tcomb/lib/declare.js' { - declare module.exports: $Exports<'tcomb/lib/declare'>; -} -declare module 'tcomb/lib/decompose.js' { - declare module.exports: $Exports<'tcomb/lib/decompose'>; -} -declare module 'tcomb/lib/dict.js' { - declare module.exports: $Exports<'tcomb/lib/dict'>; -} -declare module 'tcomb/lib/enums.js' { - declare module.exports: $Exports<'tcomb/lib/enums'>; -} -declare module 'tcomb/lib/Error.js' { - declare module.exports: $Exports<'tcomb/lib/Error'>; -} -declare module 'tcomb/lib/extend.js' { - declare module.exports: $Exports<'tcomb/lib/extend'>; -} -declare module 'tcomb/lib/fail.js' { - declare module.exports: $Exports<'tcomb/lib/fail'>; -} -declare module 'tcomb/lib/forbidNewOperator.js' { - declare module.exports: $Exports<'tcomb/lib/forbidNewOperator'>; -} -declare module 'tcomb/lib/fromJSON.js' { - declare module.exports: $Exports<'tcomb/lib/fromJSON'>; -} -declare module 'tcomb/lib/func.js' { - declare module.exports: $Exports<'tcomb/lib/func'>; -} -declare module 'tcomb/lib/Function.js' { - declare module.exports: $Exports<'tcomb/lib/Function'>; -} -declare module 'tcomb/lib/getDefaultInterfaceName.js' { - declare module.exports: $Exports<'tcomb/lib/getDefaultInterfaceName'>; -} -declare module 'tcomb/lib/getFunctionName.js' { - declare module.exports: $Exports<'tcomb/lib/getFunctionName'>; -} -declare module 'tcomb/lib/getTypeName.js' { - declare module.exports: $Exports<'tcomb/lib/getTypeName'>; -} -declare module 'tcomb/lib/installTypeFormatter.js' { - declare module.exports: $Exports<'tcomb/lib/installTypeFormatter'>; -} -declare module 'tcomb/lib/Integer.js' { - declare module.exports: $Exports<'tcomb/lib/Integer'>; -} -declare module 'tcomb/lib/interface.js' { - declare module.exports: $Exports<'tcomb/lib/interface'>; -} -declare module 'tcomb/lib/intersection.js' { - declare module.exports: $Exports<'tcomb/lib/intersection'>; -} -declare module 'tcomb/lib/irreducible.js' { - declare module.exports: $Exports<'tcomb/lib/irreducible'>; -} -declare module 'tcomb/lib/is.js' { - declare module.exports: $Exports<'tcomb/lib/is'>; -} -declare module 'tcomb/lib/isArray.js' { - declare module.exports: $Exports<'tcomb/lib/isArray'>; -} -declare module 'tcomb/lib/isBoolean.js' { - declare module.exports: $Exports<'tcomb/lib/isBoolean'>; -} -declare module 'tcomb/lib/isFunction.js' { - declare module.exports: $Exports<'tcomb/lib/isFunction'>; -} -declare module 'tcomb/lib/isIdentity.js' { - declare module.exports: $Exports<'tcomb/lib/isIdentity'>; -} -declare module 'tcomb/lib/isInterface.js' { - declare module.exports: $Exports<'tcomb/lib/isInterface'>; -} -declare module 'tcomb/lib/isMaybe.js' { - declare module.exports: $Exports<'tcomb/lib/isMaybe'>; -} -declare module 'tcomb/lib/isNil.js' { - declare module.exports: $Exports<'tcomb/lib/isNil'>; -} -declare module 'tcomb/lib/isNumber.js' { - declare module.exports: $Exports<'tcomb/lib/isNumber'>; -} -declare module 'tcomb/lib/isObject.js' { - declare module.exports: $Exports<'tcomb/lib/isObject'>; -} -declare module 'tcomb/lib/isString.js' { - declare module.exports: $Exports<'tcomb/lib/isString'>; -} -declare module 'tcomb/lib/isStruct.js' { - declare module.exports: $Exports<'tcomb/lib/isStruct'>; -} -declare module 'tcomb/lib/isSubsetOf.js' { - declare module.exports: $Exports<'tcomb/lib/isSubsetOf'>; -} -declare module 'tcomb/lib/isType.js' { - declare module.exports: $Exports<'tcomb/lib/isType'>; -} -declare module 'tcomb/lib/isTypeName.js' { - declare module.exports: $Exports<'tcomb/lib/isTypeName'>; -} -declare module 'tcomb/lib/isUnion.js' { - declare module.exports: $Exports<'tcomb/lib/isUnion'>; -} -declare module 'tcomb/lib/list.js' { - declare module.exports: $Exports<'tcomb/lib/list'>; -} -declare module 'tcomb/lib/match.js' { - declare module.exports: $Exports<'tcomb/lib/match'>; -} -declare module 'tcomb/lib/maybe.js' { - declare module.exports: $Exports<'tcomb/lib/maybe'>; -} -declare module 'tcomb/lib/mixin.js' { - declare module.exports: $Exports<'tcomb/lib/mixin'>; -} -declare module 'tcomb/lib/Nil.js' { - declare module.exports: $Exports<'tcomb/lib/Nil'>; -} -declare module 'tcomb/lib/Number.js' { - declare module.exports: $Exports<'tcomb/lib/Number'>; -} -declare module 'tcomb/lib/Object.js' { - declare module.exports: $Exports<'tcomb/lib/Object'>; -} -declare module 'tcomb/lib/refinement.js' { - declare module.exports: $Exports<'tcomb/lib/refinement'>; -} -declare module 'tcomb/lib/RegExp.js' { - declare module.exports: $Exports<'tcomb/lib/RegExp'>; -} -declare module 'tcomb/lib/String.js' { - declare module.exports: $Exports<'tcomb/lib/String'>; -} -declare module 'tcomb/lib/stringify.js' { - declare module.exports: $Exports<'tcomb/lib/stringify'>; -} -declare module 'tcomb/lib/struct.js' { - declare module.exports: $Exports<'tcomb/lib/struct'>; -} -declare module 'tcomb/lib/tuple.js' { - declare module.exports: $Exports<'tcomb/lib/tuple'>; -} -declare module 'tcomb/lib/Type.js' { - declare module.exports: $Exports<'tcomb/lib/Type'>; -} -declare module 'tcomb/lib/union.js' { - declare module.exports: $Exports<'tcomb/lib/union'>; -} -declare module 'tcomb/lib/update.js' { - declare module.exports: $Exports<'tcomb/lib/update'>; -} diff --git a/lib/types/messages/media.js b/lib/types/messages/media.js --- a/lib/types/messages/media.js +++ b/lib/types/messages/media.js @@ -32,16 +32,18 @@ +media: $ReadOnlyArray, }; +export type PhotoMessageServerDBContent = { + +type: 'photo', + +uploadID: string, +}; +export type VideoMessageServerDBContent = { + +type: 'video', + +uploadID: string, + +thumbnailUploadID: string, +}; export type MediaMessageServerDBContent = - | { - +type: 'photo', - +uploadID: string, - } - | { - +type: 'video', - +uploadID: string, - +thumbnailUploadID: string, - }; + | PhotoMessageServerDBContent + | VideoMessageServerDBContent; function getUploadIDsFromMediaMessageServerDBContents( mediaMessageContents: $ReadOnlyArray, diff --git a/lib/utils/avatar-utils.js b/lib/utils/avatar-utils.js --- a/lib/utils/avatar-utils.js +++ b/lib/utils/avatar-utils.js @@ -6,32 +6,41 @@ import { tRegex, tShape, tString } from './validation-utils.js'; import { validHexColorRegex } from '../shared/account-utils.js'; import { onlyOneEmojiRegex } from '../shared/emojis.js'; - -const emojiAvatarDBContentValidator: TInterface = tShape({ +import type { + ENSAvatarDBContent, + EmojiAvatarDBContent, + ImageAvatarDBContent, + UpdateUserAvatarRemoveRequest, + UpdateUserAvatarRequest, +} from '../types/avatar-types'; + +const emojiAvatarDBContentValidator: TInterface = tShape({ type: tString('emoji'), emoji: tRegex(onlyOneEmojiRegex), color: tRegex(validHexColorRegex), }); -const imageAvatarDBContentValidator: TInterface = tShape({ +const imageAvatarDBContentValidator: TInterface = tShape({ type: tString('image'), uploadID: t.String, }); -const ensAvatarDBContentValidator: TInterface = tShape({ +const ensAvatarDBContentValidator: TInterface = tShape({ type: tString('ens'), }); -const updateUserAvatarRemoveRequestValidator: TInterface = tShape({ - type: tString('remove'), -}); - -const updateUserAvatarRequestValidator: TUnion = t.union([ - emojiAvatarDBContentValidator, - imageAvatarDBContentValidator, - ensAvatarDBContentValidator, - updateUserAvatarRemoveRequestValidator, -]); +const updateUserAvatarRemoveRequestValidator: TInterface = + tShape({ + type: tString('remove'), + }); + +const updateUserAvatarRequestValidator: TUnion = + t.union([ + emojiAvatarDBContentValidator, + imageAvatarDBContentValidator, + ensAvatarDBContentValidator, + updateUserAvatarRemoveRequestValidator, + ]); export { emojiAvatarDBContentValidator, diff --git a/lib/utils/crypto-utils.js b/lib/utils/crypto-utils.js --- a/lib/utils/crypto-utils.js +++ b/lib/utils/crypto-utils.js @@ -5,20 +5,26 @@ import { primaryIdentityPublicKeyRegex } from './siwe-utils.js'; import { tRegex, tShape } from './validation-utils.js'; +import type { + IdentityKeysBlob, + OLMIdentityKeys, + SignedIdentityKeysBlob, +} from '../types/crypto-types'; const minimumOneTimeKeysRequired = 10; -const signedIdentityKeysBlobValidator: TInterface = tShape({ - payload: t.String, - signature: t.String, -}); +const signedIdentityKeysBlobValidator: TInterface = + tShape({ + payload: t.String, + signature: t.String, + }); -const olmIdentityKeysValidator: TInterface = tShape({ +const olmIdentityKeysValidator: TInterface = tShape({ ed25519: tRegex(primaryIdentityPublicKeyRegex), curve25519: tRegex(primaryIdentityPublicKeyRegex), }); -const identityKeysBlobValidator: TInterface = tShape({ +const identityKeysBlobValidator: TInterface = tShape({ primaryIdentityPublicKeys: olmIdentityKeysValidator, notificationIdentityPublicKeys: olmIdentityKeysValidator, }); diff --git a/lib/utils/validation-utils.js b/lib/utils/validation-utils.js --- a/lib/utils/validation-utils.js +++ b/lib/utils/validation-utils.js @@ -15,6 +15,12 @@ oldValidUsernameRegex, validHexColorRegex, } from '../shared/account-utils.js'; +import type { PlatformDetails } from '../types/device-types'; +import type { + MediaMessageServerDBContent, + PhotoMessageServerDBContent, + VideoMessageServerDBContent, +} from '../types/messages/media'; function tBool(value: boolean): TIrreducible { return t.irreducible('literal bool', x => x === value); @@ -28,7 +34,7 @@ return t.irreducible('literal number', x => x === value); } -function tShape(spec: TStructProps): TInterface { +function tShape(spec: TStructProps): TInterface { return t.interface(spec, { strict: true }); } @@ -58,7 +64,7 @@ 'macos', ]); const tDeviceType: TEnums = t.enums.of(['ios', 'android']); -const tPlatformDetails: TInterface = tShape({ +const tPlatformDetails: TInterface = tShape({ platform: tPlatform, codeVersion: t.maybe(t.Number), stateVersion: t.maybe(t.Number), @@ -72,18 +78,18 @@ const tOldValidUsername: TRegex = tRegex(oldValidUsernameRegex); const tID: TRefinement = t.refinement(t.String, (id: string) => !!id); -const tMediaMessagePhoto: TInterface = tShape({ +const tMediaMessagePhoto: TInterface = tShape({ type: tString('photo'), uploadID: t.String, }); -const tMediaMessageVideo: TInterface = tShape({ +const tMediaMessageVideo: TInterface = tShape({ type: tString('video'), uploadID: t.String, thumbnailUploadID: t.String, }); -const tMediaMessageMedia: TUnion = t.union([ +const tMediaMessageMedia: TUnion = t.union([ tMediaMessagePhoto, tMediaMessageVideo, ]);