
# Service Library - `content`

This document provides a complete reference of the custom code library for the `content` service. It includes all library functions, edge functions with their REST endpoints, templates, and assets.


## Library Functions

Library functions are reusable modules available to all business APIs and other custom code within the service via `require("lib/<moduleName>")`.


### `getPostListVisibilityFilter.js`

```js
module.exports = (ctx) => {
  // Returns an MScript-style object filter for listPosts API
  // Only fetch posts that are:
  // - public (visibility == "public")
  // - or owned by the current user (authorUserId == session.userId)
  // If companyId filter present, only posts from that company.
  // This utility is invoked as MScript in fullWhereClause.
  const userId = ctx.session?.userId;
  const filters = [];
  if (ctx.authorUserId) { filters.push({ authorUserId: ctx.authorUserId }); }
  if (ctx.companyId) { filters.push({ companyId: ctx.companyId }); }
  // Show all public posts
  const publicOrOwned = userId ? { $or: [ { visibility: 'public' }, { authorUserId: userId } ] } : { visibility: 'public' };
  filters.push(publicOrOwned);
  return filters.length > 1 ? { $and: filters } : filters[0];
};
```














---

*This document was generated from the service library configuration and should be kept in sync with design changes.*
