NSF command implementation (list, get, ln and rm)#169
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
| }, | ||
| "dependencies": { | ||
| "@keeper-security/keeperapi": "17.2.6", | ||
| "protobufjs": "^7.6.1", |
There was a problem hiding this comment.
probably not needed as we are getting proto from keeperapi project
| return { | ||
| userPermissions: entries | ||
| .filter(isFolderUserPermission) | ||
| .map((entry) => buildFolderAccessRow(storage, folder, entry)), | ||
| shareAdmins: entries | ||
| .filter(isFolderShareAdministrator) | ||
| .map((entry) => buildFolderAccessRow(storage, folder, entry)), | ||
| teamPermissions: entries | ||
| .filter((entry) => entry.accessType === Folder.AccessType.AT_TEAM) | ||
| .map(mapFolderPermission), | ||
| } |
There was a problem hiding this comment.
| return { | |
| userPermissions: entries | |
| .filter(isFolderUserPermission) | |
| .map((entry) => buildFolderAccessRow(storage, folder, entry)), | |
| shareAdmins: entries | |
| .filter(isFolderShareAdministrator) | |
| .map((entry) => buildFolderAccessRow(storage, folder, entry)), | |
| teamPermissions: entries | |
| .filter((entry) => entry.accessType === Folder.AccessType.AT_TEAM) | |
| .map(mapFolderPermission), | |
| } | |
| const userPermissions: NsfFolderAccessRow[] = []; | |
| const shareAdmins: NsfFolderAccessRow[] = []; | |
| const teamPermissions: NsfFolderPermission[] = []; | |
| for (const entry of entries) { | |
| if (isFolderUserPermission(entry)) { | |
| userPermissions.push(buildFolderAccessRow(storage, folder, entry)); | |
| } | |
| if (isFolderShareAdministrator(entry)) { | |
| shareAdmins.push(buildFolderAccessRow(storage, folder, entry)); | |
| } | |
| if (entry.accessType === Folder.AccessType.AT_TEAM) { | |
| teamPermissions.push(mapFolderPermission(entry)); | |
| } | |
| } | |
| return { userPermissions, shareAdmins, teamPermissions }; |
There is no necessity for multiple loops -> 3x iterations to 1x
| function buildRecordFields(record: DRecord, unmask: boolean): NsfRecordView['fields'] { | ||
| return getRecordFields(record).flatMap((field) => { | ||
| if (NSF_TOP_LEVEL_FIELD_TYPES.has(field.type)) return [] | ||
| const rawValue = Array.isArray(field.value) ? field.value[0] : field.value | ||
| if (rawValue == null || rawValue === '') return [] | ||
| const value = !unmask && isSensitiveFieldType(field.type) ? NSF_MASKED_VALUE : String(rawValue) | ||
| return [{ type: field.type, label: field.label, value }] | ||
| }) | ||
| } |
There was a problem hiding this comment.
| function buildRecordFields(record: DRecord, unmask: boolean): NsfRecordView['fields'] { | |
| return getRecordFields(record).flatMap((field) => { | |
| if (NSF_TOP_LEVEL_FIELD_TYPES.has(field.type)) return [] | |
| const rawValue = Array.isArray(field.value) ? field.value[0] : field.value | |
| if (rawValue == null || rawValue === '') return [] | |
| const value = !unmask && isSensitiveFieldType(field.type) ? NSF_MASKED_VALUE : String(rawValue) | |
| return [{ type: field.type, label: field.label, value }] | |
| }) | |
| } | |
| ffunction buildRecordFields(record: DRecord, unmask: boolean): NsfRecordView['fields'] { | |
| return getRecordFields(record) | |
| // Step 1: Remove top-level types up front | |
| .filter(field => !NSF_TOP_LEVEL_FIELD_TYPES.has(field.type)) | |
| // Step 2: Map to items with unwrapped/validated values | |
| .map(field => { | |
| const rawValue = Array.isArray(field.value) ? field.value[0] : field.value; | |
| return { field, rawValue }; | |
| }) | |
| // Step 3: Filter out fields with empty values | |
| .filter(({ rawValue }) => rawValue != null && rawValue !== '') | |
| // Step 4: Construct final object with masked value | |
| .map(({ field, rawValue }) => { | |
| const isSensitive = isSensitiveFieldType(field.type); | |
| const finalValue = !unmask && isSensitive ? NSF_MASKED_VALUE : String(rawValue); | |
| return { | |
| type: field.type, | |
| label: field.label, | |
| value: finalValue | |
| }; | |
| }); | |
| } |
will something like this fit your usecase ?
There was a problem hiding this comment.
Replaced the single flatMap with empty-array returns by an explicit pipeline
| .map((ext) => ext.email || '') | ||
| .filter((email) => email.length > 0) |
There was a problem hiding this comment.
| .map((ext) => ext.email || '') | |
| .filter((email) => email.length > 0) | |
| .flatMap((ext) => ext?.email ? [ext.email] : []) |
| message: string | ||
| } | ||
|
|
||
| async function resolveRecordKeyType( |
There was a problem hiding this comment.
should probably be a utility function and to be moved to utils
| return response | ||
| } | ||
|
|
||
| export function removeRecordMessage( |
There was a problem hiding this comment.
Should probably be moved to keeper api
dbb5f0d to
e3b921e
Compare
| .map((value) => formatNsfFieldValue(value)) | ||
| .filter((value) => value.length > 0) |
There was a problem hiding this comment.
probably these have to be interchanged ? I am unsure here but that reduces complexity maybe.
| return lines | ||
| } | ||
|
|
||
| async function fetchRecordPermissions(auth: Auth, recordUid: string): Promise<NsfRecordPermission[]> { |
There was a problem hiding this comment.
do we need promise as a return type here ? at end we are just returning a nullable array right ?
There was a problem hiding this comment.
The async / Promise is required, the function calls await auth.executeRest(), so it cannot be synchronous.
…d-p1-dev Sync feature-kd-part1 updates (rest messages, proto, package) into feature-kd-p1-dev. Co-authored-by: Cursor <cursoragent@cursor.com>
No description provided.