ede566eed9
* prep for new resources algo * typescriptifying stuff * minor types fix * migrate to resources col * repo & creation updated, WIP processing/retrieval * WIP invite processing * finished finalization refactor * project invite management * transformed all invites services * fixed up projects & core serverinvites resolvers * test fixes * WIP workspace create GQL & test * basic invite creation test works * a buncha working tests * more tests * cancelation tests * minor invite use refactor * invite retrieval tasks * invite use() works as expected * filtering out broken invites * enabled invite retrieval by token irregardless of who is it for * minor adjustments * tests fix * test config improvements * test env adjustment * extra test case * making resource access limits harder to ignore * linter fixes * eventBus type cleanup * better generic names * refactored serverinvites resource migration * fix(server): better error message in project invite edge case
68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
import { AuthContext } from '@/modules/shared/authz'
|
|
import { base64Decode, base64Encode } from '@/modules/shared/helpers/cryptoHelper'
|
|
import DataLoader from 'dataloader'
|
|
import dayjs, { Dayjs } from 'dayjs'
|
|
|
|
/**
|
|
* Encode cursor to turn it into an opaque & obfuscated value
|
|
*/
|
|
export function encodeCursor(value: string): string {
|
|
return base64Encode(value)
|
|
}
|
|
|
|
/**
|
|
* Decode obfuscated cursor value
|
|
*/
|
|
export function decodeCursor(value: string): string {
|
|
return base64Decode(value)
|
|
}
|
|
|
|
export function decodeIsoDateCursor(value: string): string | null {
|
|
const decoded = decodeCursor(value)
|
|
if (!decoded) return null
|
|
|
|
const date = dayjs(decoded)
|
|
if (!date.isValid()) return null
|
|
|
|
return date.toISOString()
|
|
}
|
|
|
|
export function encodeIsoDateCursor(date: Date | Dayjs): string {
|
|
const str = date.toISOString()
|
|
return encodeCursor(str)
|
|
}
|
|
|
|
export type RequestDataLoadersBuilder<
|
|
T extends {
|
|
[group: string]: {
|
|
[loader: string]: unknown
|
|
}
|
|
}
|
|
> = (params: {
|
|
ctx: AuthContext
|
|
createLoader: <K, V, C = K>(
|
|
batchLoadFn: DataLoader.BatchLoadFn<K, V>,
|
|
options?: DataLoader.Options<K, V, C>
|
|
) => DataLoader<K, V, C>
|
|
}) => T
|
|
|
|
export type RequestDataLoaders<
|
|
T extends {
|
|
[group: string]: {
|
|
[loader: string]: unknown
|
|
}
|
|
}
|
|
> = ReturnType<RequestDataLoadersBuilder<T>>
|
|
|
|
export const defineRequestDataloaders = <
|
|
T extends {
|
|
[group: string]: {
|
|
[loader: string]: unknown
|
|
}
|
|
}
|
|
>(
|
|
builder: RequestDataLoadersBuilder<T>
|
|
): RequestDataLoadersBuilder<T> => {
|
|
return builder
|
|
}
|