The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/packages/apps/deno-runtime/lib/secureFields.ts

26 lines
784 B

import { kSecureFields, WithSecureFields } from '@rocket.chat/apps/dist/lib/SecureFields';
import type { App } from '@rocket.chat/apps-engine/definition/App';
import { AppObjectRegistry } from '../AppObjectRegistry.ts';
export type { WithSecureFields } from '@rocket.chat/apps/dist/lib/SecureFields';
export function applySecureFields(object: WithSecureFields<Record<string, unknown>>) {
const { [kSecureFields]: secureFields, ...rest } = object;
const app = AppObjectRegistry.get<App>('app');
if (!app) {
throw new Error("App unavailable, can't parse object with secure fields");
}
secureFields.forEach(({ permission, name, value }) => {
if (!app.getInfo().permissions?.find((p) => p.name === permission)) {
return;
}
rest[name] = value;
});
return rest;
}