# marjory

> marjory sdk

Latest version **3.4.1** (published 2025-01-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install marjory
pnpm add marjory
yarn add marjory
bun add marjory
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.4.1 |
| Published | 2025-01-23 |
| First published | 2021-03-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 3 |
| Unpacked size | 53.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Marjory |
| Maintainers | partners-marjory |

## Links

- npm: https://www.npmjs.com/package/marjory
- npm.io page: https://npm.io/package/marjory

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^1.6.7
- [mongodb](https://npm.io/package/mongodb.md) ^6.3.0
- [date-fns](https://npm.io/package/date-fns.md) ^4.1.0

## Recent versions

- 3.4.1 (latest) — 2025-01-23
- 3.3.5-beta.2 (beta) — 2024-10-24
- 3.4.0 — 2024-12-05
- 3.3.6 — 2024-10-25
- 3.3.5-beta.1 — 2024-10-24
- 3.3.5 — 2024-10-22
- 3.3.4-beta.1 — 2024-10-07
- 3.3.4 — 2024-10-02
- 3.3.3 — 2024-09-26
- 3.3.2 — 2024-09-19
- 3.3.1 — 2024-09-19
- 3.3.0 — 2024-09-11
- 3.2.1 — 2024-05-29
- 3.2.0 — 2024-05-24
- 3.1.1 — 2024-05-23
- … 116 more at https://npm.io/package/marjory/versions

## README

# Marjory SDK

This SDK can be used to write Marjory application and use advanced feature of the Marjory platform.

## Installation

You can add the SDK to your project using npm:

```bash
npm install marjory
```

Then you can import the SDK in your application:

```javascript
import Marjory from "marjory";
```

The SDK will be automatically initialized with the default configuration when your application will run on Marjory platform.

## Usage

### App Database (with MongoDB)

Each application have a dedicated database. To manipulate it, you have access to several functions.

#### Collection access

```javascript
import Marjory from "marjory";

const myCollection = await Marjory.Db.collection("<collection_name>");
```

#### Get functions

```javascript
import Marjory from 'marjory';

const myCollection = await Marjory.Db.collection("<collection_name>");

const resultFind = await myCollection.find(...);
const resultFindOne = await myCollection.findOne(...);
const resultCount = await myCollection.countDocuments(...);
```

#### Insert functions

```javascript
import Marjory from 'marjory';

const myCollection = await Marjory.Db.collection("<collection_name>");

const resultInsertOne = await myCollection.insertOne(...);
const resultInsertMany = await myCollection.insertMany(...);
```

If you want to insert multiple documents at the same time, you can use the `bulkWrite` function:

```javascript
import Marjory from "marjory";

const myCollection = await Marjory.Db.collection("<collection_name>");

const resultBulkWrite = await myCollection.bulkWrite([
  { insertOne: { document: { a: 1 } } },
  { insertOne: { document: { a: 2 } } },
  { insertOne: { document: { a: 3 } } },
  { updateOne: { filter: { a: 2 }, update: { $set: { a: 5 } } } },
  { deleteOne: { filter: { c: 1 } } },
  { replaceOne: { filter: { c: 3 }, replacement: { c: 4 } } },
]);
```

#### Update functions

```javascript
import Marjory from 'marjory';

const myCollection = await Marjory.Db.collection("<collection_name>");

const resultUpdateOne = await myCollection.updateOne(...)
const resultUpdateMany = await myCollection.updateMany(...)
const resultFindOneAndUpdate = await myCollection.findOneAndUpdate(...)
const resultFindOneAndReplace = await myCollection.findOneAndReplace(...)
const resultReplaceOne = await myCollection.replaceOne(...)
```

#### Delete functions

```javascript
import Marjory from 'marjory';

const myCollection = await Marjory.Db.collection("<collection_name>");

const resultDeletetOne = await myCollection.deleteOne(...);
const resultDeleteMany = await myCollection.deleteMany(...);
```

#### Aggregation functions

```javascript
import Marjory from 'marjory';

const myCollection = await Marjory.Db.collection("<collection_name>");

const resultAggregate = await myCollection.aggregate(...);
```

### Access variables

You can retrieve variables declared inside your `deployment.yml` file and configured using `marjory configure` command.

```javascript
import Marjory from "marjory";

const variableValue = Marjory.variables["<variable_name>"];
```

### Logger

```javascript
import Marjory from "marjory";

const detailsObject = {}; // For example stack trace object

await Marjory.Logger.trace("message", detailsObject); // equivalent to debug in javascript
await Marjory.Logger.info("message", detailsObject);
await Marjory.Logger.warn("message", detailsObject);
await Marjory.Logger.error("message", detailsObject);
```

### Events

In mostly cases during the webservice and scheduled functions, you will generate events. This method can throw event.

```javascript
import Marjory from "marjory";

const eventPayload = {};
await Marjory.Events.send("<event_name>", eventPayload);
```

### Access context information
You can retrieve context information of the execution of you function.

```javascript
import Marjory from "marjory";

const contextValue = Marjory.context["<context_property>"];
```

### Files

You can use the SDK to upload and download files.

#### Upload Files
```javascript
import Marjory from "marjory";

const buffer = Buffer.from("<file_content>", "utf-8");
await Marjory.sdk.Files.upload("<file_name>", buffer);
```

#### Download Files
```javascript
import Marjory from "marjory";

const buffer = Buffer.from("<file_content>", "utf-8");
const myFile = await Marjory.sdk.Files.upload("<file_name>", buffer);

const myBuffer = await Marjory.sdk.Files.download(myFile);
```

## Issues

If you have any issue, please contact us at [support@marjory.io](mailto:support@marjory.io)

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