# @krimzen-ninja/mongo-crud

> A collection of types and code to make crud work easier and standardized

Latest version **0.4.8** (published 2024-05-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @krimzen-ninja/mongo-crud
pnpm add @krimzen-ninja/mongo-crud
yarn add @krimzen-ninja/mongo-crud
bun add @krimzen-ninja/mongo-crud
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.8 |
| Published | 2024-05-20 |
| First published | 2022-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 16 |
| Unpacked size | 107.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ryan Kotzen |
| Maintainers | exigentcoder |
| Keywords | krimzen-ninja, mongodb, crud |

## Links

- npm: https://www.npmjs.com/package/@krimzen-ninja/mongo-crud
- npm.io page: https://npm.io/package/@krimzen-ninja/mongo-crud

## Dependencies (16)

- [ajv](https://npm.io/package/ajv.md) ^8.11.2
- [path](https://npm.io/package/path.md) 0.12.7
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [moment](https://npm.io/package/moment.md) ^2.29.3
- [mongodb](https://npm.io/package/mongodb.md) ^6.3.0
- [json-diff](https://npm.io/package/json-diff.md) ^1.0.6
- [check-types](https://npm.io/package/check-types.md) ^11.2.3
- [json-schema](https://npm.io/package/json-schema.md) ^0.4.0
- [@casl/ability](https://npm.io/package/@casl/ability.md) ^6.5.0
- [http-status-codes](https://npm.io/package/http-status-codes.md) ^2.3.0
- [json-schema-to-ts](https://npm.io/package/json-schema-to-ts.md) ^2.9.2
- [@krimzen-ninja/mongo](https://npm.io/package/@krimzen-ninja/mongo.md) 0.4.8
- [@krimzen-ninja/validation](https://npm.io/package/@krimzen-ninja/validation.md) 0.4.9
- [@krimzen-ninja/common-errors](https://npm.io/package/@krimzen-ninja/common-errors.md) 0.7.10
- [@krimzen-ninja/json-schema-to-ts](https://npm.io/package/@krimzen-ninja/json-schema-to-ts.md) 0.4.8
- [@krimzen-ninja/validation-mongodb](https://npm.io/package/@krimzen-ninja/validation-mongodb.md) 0.3.9

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.4.8 (latest) — 2024-05-20
- 0.4.9-beta.0 (next) — 2024-10-11
- 0.4.4-beta.19 — 2024-02-15
- 0.4.4-beta.18 — 2024-02-15
- 0.4.4-beta.17 — 2024-01-25
- 0.4.4-beta.16 — 2024-01-24
- 0.4.4-beta.15 — 2024-01-22
- 0.4.7 — 2024-01-22
- 0.4.4-beta.14 — 2024-01-14
- 0.4.6 — 2023-12-27
- 0.4.4-beta.13 — 2023-12-27
- 0.4.4-beta.12 — 2023-12-27
- 0.4.4-beta.11 — 2023-12-27
- 0.4.4-beta.10 — 2023-12-27
- 0.4.4-beta.9 — 2023-12-27
- … 38 more at https://npm.io/package/@krimzen-ninja/mongo-crud/versions

## README

# mongo-crud

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test mongo-crud` to execute the unit tests via [Jest](https://jestjs.io).

## Running lint

Run `nx lint mongo-crud` to execute the lint via [ESLint](https://eslint.org/).

## About

The purpose of this library is not just to CRUD objects, this is already provided for in a simple way by the mongodb package. Instead what I intend is to provide a mechanism of middleware when performing CRUD operations that can alter the data or the nature of the operation prior and post the actual operation. Some of the objectives would be:

1. Prevent CRUD operations if there is a logged in user who doesn't have access to this particular resource. e.g. Customer cannot see orders from other customers
2. Prevent entities in one organisation from performing CRUD operations on entities in other organisations.
   1. While still allowing me to write cross-organisation reports or perform cross-org data migrations
3. Enforce schema of objects prior to being saved - Probably best to do this using a JSON schema on the actual collection, need to test as this will alleviate workload on the api and also ensure any other apps or manual access from storing invalid data.
4. When returning a document from an api, there are certain fields (cost price, passwordHash, etc) that should not be exposed, this should provide a framework for stripping those out, while still allowing these values to be used internally by the code.
5. Set date created
6. Set last updated
7. Add audit information
8. Ownership of entities by logged in user
9. Status (Active/inactive)

## Authorisation/Permissions

### Objectives

1. Prevent access across orgs if not a super user (e.g. allow super users to pull a report that reads data across orgs)
2. Prevent certain actions on objects based on ownership (e.g. if you don't own a voucher, you can't CRUD it)
3. Prevent certain actions on objects based on status of object (E.g. soft deleted objects can't be updated)
4. limit certain actions on objects to certain roles (e.g. only admins can read reports)
5. Prevent certain fields from being CRUDed by certain types of users (e.g. don't allow user to see or change passwordHash directly)
6. Limit result sets returned to only ones you are allowed (e.g. my orders)

https://dev.to/rschwabco/building-rbac-in-node-3hcb

### Casl

https://www.npmjs.com/package/@casl/ability
https://casl.js.org/v6/en/package/casl-react
https://www.npmjs.com/package/@casl/mongoose (Provides a filtered query)

### Cerbos

https://cerbos.dev/video/implement-cerbos-in-less-than-4-minutes

Data stores - https://docs.cerbos.dev/cerbos/latest/configuration/storage.html

### Aserto

https://www.aserto.com/
.

---
_Source: https://npm.io/package/@krimzen-ninja/mongo-crud · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
