Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
850c666
feat(docs): email usage tutorial
sdimitris Nov 28, 2022
32f0d3c
fix(docs): email boolean values
sdimitris Nov 28, 2022
fcbc4b1
fix(docs): delete irrelevant text
sdimitris Nov 28, 2022
9e83aa3
fix(docs): delete irrelevant text
sdimitris Nov 28, 2022
8a0bbde
feat(docs): additional docs in email usage
sdimitris Nov 28, 2022
f57b81a
feat(docs): grpc sdk usage
sdimitris Nov 29, 2022
454464e
refactor(docs): email usage
sdimitris Nov 29, 2022
e40da31
fix(docs): email broken link
sdimitris Nov 29, 2022
ece1a26
feat(docs): authentication and email sdk usage
sdimitris Nov 29, 2022
8f266ee
chore(docs): typo
sdimitris Nov 29, 2022
5f2eb5b
feat(docs): sms,authentication
sdimitris Nov 29, 2022
f9edfbc
chore(docs): typos
sdimitris Nov 29, 2022
cac6e13
feat(docs,authentication,sms,push-notifications): docs updated
sdimitris Nov 30, 2022
fbdd63c
feat(docs,chat): docs updated wth sdk usage
sdimitris Nov 30, 2022
bd88b8f
chore(docs,chat,email,sms,push-notifications): typos syntax etc
sdimitris Nov 30, 2022
62fc30a
feat(docs,database): database sdk usage
sdimitris Nov 30, 2022
c6d0087
chore(docs): grammar and syntax fixes
sdimitris Dec 5, 2022
93b81ab
feat(docs): database sdk additions
sdimitris Dec 5, 2022
d6e056f
chore(docs): database sdk type fixes
sdimitris Dec 5, 2022
a5a929a
feat(docs): storage
sdimitris Dec 5, 2022
5ffbcab
fix(docs): email fixes
sdimitris Dec 5, 2022
fa0f6c2
fix(docs): database fixes
sdimitris Dec 5, 2022
fe1bba7
fix(docs): database fixes
sdimitris Dec 5, 2022
3d699a4
Merge branch 'main' into sdk_sage
kon14 Dec 16, 2022
f523dee
fix(docs): authentication sdk usage fixes
kon14 Dec 16, 2022
191c38b
fix(docs): chat sdk usage fixes
kon14 Dec 16, 2022
a7589f2
fix(docs): initial wip database sdk usage fixes
kon14 Dec 16, 2022
811dae8
fix(docs): remaining sdk usage page sidebar metadata
kon14 Dec 16, 2022
b2d71f2
fix(docs): chat sdk usage room response
kon14 Dec 16, 2022
a7bfc0a
fix(docs): requested changes
sdimitris Dec 22, 2022
65e9975
Merge branch 'main' of github.com:ConduitPlatform/Conduit-Website int…
sdimitris Dec 22, 2022
1bc62ec
Merge branch 'sdk_sage' of github.com:ConduitPlatform/Conduit-Website…
sdimitris Dec 22, 2022
73a3a6c
fix(docs): requested changes
sdimitris Dec 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
sidebar_label: 'SDK Usage'
sidebar_position: 100
---

# SDK Usage

## User Creation

You may easily create users (utilizing the [Local Authentication](./strategies#local) strategy) through the SDK.<br />
The `verify` boolean field specifies whether the newly created user **should verify themselves**.

:::caution
User authentication requires that the Email module is available and [configured](../email/config).<br />
The Authentication module's Local Authentication strategy should also enable email verification.
:::

[//]: # (TODO: Update verify naming)

```ts
await grpcSdk.authentication.userCreate({
email: "[email protected]",
password : "P@$$w0rd",
verify: true,
});
```

## User Login

You may retrieve an access/refresh token pair for your users through the SDK.<br />
Specifying a [security client](../router/security.mdx) id for your login request is required.

[//]: # (TODO: Update this once security clients are optional in gRPC)

```ts title="Request"
await grpcSdk.authentication.userLogin({
userId: "someuserid",
clientId: "someclientid"
});
```

```ts title="Response"
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYyNDJmMWJiMTBhMDk5MDE4Mjc3MzhmZSIsImlhdCI6MTY0ODU1NDUyNywiZXhwIjoxNzM0OTU0NTI3fQ.Fjqa7ORBBF2giwG7OgiWr2HMgHDL7R6ddFq2E730Djc",
"refreshToken": "BsKhe3ARhL/FfDfK1REphKkkqQaxRCj/LvvRHOg5wCXCBaUSOwafRHyFYIttaORY/NmHS7NAuT6+knBQegVOwQ=="
}
```

## User Deletion

```ts title="Request"
await grpcSdk.authentication.userDelete({
userId: "someuserid"
});
```

## Changing Passwords

You may update the passwords for any users utilizing [Local Authentication](./strategies#local).

```ts title="Request"
await grpcSdk.authentication.changePass({
email: "[email protected]",
password: "newP@$$w0rd"
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
sidebar_label: 'SDK Usage'
sidebar_position: 100
---

# SDK Usage

## Room Creation

Let's begin by creating a room. All you need is:
- A participant array which include the participants user ids.
- A room name.

```ts title="Request"
await grpcSdk.chat.createRoom({
name: "roomName",
participants: ["userId1", "userId2"],
});
```
```ts title="Response"
{
room: {
Id: "roomId",
name: "roomName",
participants: ["userId1", "userId2"]
}
}
```

## Room Deletion

```ts title="Request"
await grpcSdk.chat.deleteRoom({
id: "roomId",
});
```
```ts title="Response"
{
room: {
Id: "roomId",
name: "roomName",
participants: ["userId1", "userId2"]
}
}
```

## Sending Messages

Before sending a message to a group, make sure the user you're sending it as is already a member of the group.

```ts title="Request"
await grpcSdk.chat.sendMessage({
userId: "userId",
roomId: "roomId",
message: "Hello Conduit users!"
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
---
sidebar_label: 'SDK Usage'
sidebar_position: 100
---

# SDK Usage

Since the database is up, its SDK comes up with a bunch of operations you could use.
In order to explain the functionality of the database SDK, we're going to extend
the [movie tutorial](./tutorials/cinema_ticket_booking).<br />
To start operating on schemas, you need to create one first. Let's create a movie schema using the SDK.

## Schema Creation

Create schema from adapter accepts a JSON schema as an argument, and it stores into the database.
Additional arguments are required such as:
- Schema name
- [Schema fields](./sdk_usage#schema-fields)
- [Schema model options](./sdk_usage#model-options)
- Owner module name // module that owns the module
- Collection name ( name of the collection)

### Schema fields
Schema fields represent the whole schema. Each field may have:

Name | Type | Description |
| ---- | ---- | ----------- |
| `type` | TYPE | Could be TYPE.(String,Number,Boolean etc.)|
| `required` | boolean | Indicates whether a field is required. |
| `unique` | boolean | Indicates whether a field is unique. |
| `select` | boolean | Indicates whether a field could be retreived from a query. |
| `description` | string | Description of the field, |
| `default` | any | Default value of the field. |
| `enum` | enum values | When a field has enum values. |

Assume that we want to create a movie schema. A movie may have **title** , **genre**, **duration**, **director** , **description** and surely an **_id** field.
So a possible schema could be this:

```jsx title="Movie schema"
enum MoviesGenreEnum {
THRILLER = "THRILLER",
COMEDY = "COMEDY",
ADVENTURE ="ADVENTURE",
SCIENCE_FICTION = "SCIFI"
};

const schema = {
_id: TYPE.ObjectId,
name: {
type: TYPE.String,
unique: true,
required: true,
},
director: {
type: TYPE.String,
required: true,
},
duration: {
type: TYPE.Number
},
genre: {
type: TYPE.String,
enum: Object.values(MoviesGenreEnum),
required: true,
},
description: {
type: TYPE.String,
required: false,
unique: false,
},
releaseDate: TYPE.Date,
createdAt: TYPE.Date,
updatedAt: TYPE.Date,
}
```
### Model Options

There is another argument that createSchemaFromAdapter() needs, and it is called modelOptions.
Model options are objects that are stored in the database and contain some information about our schema.

Name | Type | Description |
| ---- | ---- | ----------- |
| `type` | TYPE | Could be TYPE.(String,Number,Boolean etc.)|
| `conduit.permissions` | object | Schema permissions |
| `conduit.persmissions.extendable` | boolean | Indicates if a schema could be extend after its creation. |
| `conduit.permissions.canCreate` | boolean | Indicates if a module can create documents of that schema. |
| `conduit.permissions.canModify` | boolean | Indicates if a module can modify documents of that schema. |
| `conduit.permissions.canDelete` | boolean | Indicates if a module can delete of that schema. |

A modelOptions object could be this:

```jsx title="Model options object"
const modelOptions = {
timestamps: true,
conduit: {
permissions: {
extendable: true,
canCreate: false,
canModify: 'ExtensionOnly',
canDelete: false,
},
},
} as const;
```

## Schema Creation

```ts title="Request"
await grpcSdk.database.createSchemaFromAdapter({
name: "Movies",
fields: schema,
modelOptions: modelOptions,
collectionName: "", // could be 'Movies' also
});
```

## Schema Retrieval

```ts title="Request"
await grpcSdk.database.getSchemas({});
```

## Schema Deletion

Deleting schemas could also be done by calling the SDK's deleteSchema() function. All you need is Schema's name.
Remember that conduit allows you to delete the schema's created documents as well.

```ts title="Request"
await grpcSdk.database.deleteSchema({
name: "Movies",
deleteData: true // could be also false
});
```


## Extending Schemas

Most Conduit modules need to register schemas and perform database queries for their data.<br />
These schemas are usually limited to the functionality that's required for their owner's internal operations.

The Authentication module, for instance, registers a plain `User` schema, containing just enough descriptor fields for its authentication strategies.<br />
The `User` schema doesn't make any assumptions in regard to how user-facing apps would account for additional user-related information.

Suppose your use case requires that you keep track of a user's first and last names.<br />
Traditionally, you would register your own `UserInfo` schema, including these fields as well as a relation field to the `User` entry they reference.<br />
Instead, Conduit lets you extend the main `User` schema, appending the fields you deem necessary,
as long as they are not part of the schema's base fields or otherwise already provided through another modules' extension on the same schema.

```ts title="Request"
await grpcSdk.database.setSchemaExtension({
schemaName: "Movies",
extOwner: "yourModule",
extFields: {
firstName: {
type: "String",
required: "true",
},
lastName: {
type: "String",
required: "true",
},
},
});
```

Now the User schema includes this new field called **recoverEmail**.

## Database Operations

Conduit models provide several static helper functions for CRUD operations.<br/>
Queries are structured Mongoose-like. To see Conduit's query language click [here](./operators).

### Document Retrieval

Suppose we wish to find a record with a specific id.

```ts title="Request"
await grpcSdk.database
.findOne("Movies",{ _id: "someMovieId" });
```

### Multi-Document Retrieval

Suppose we want to fetch all Movies that have a duration greater than 1 hour.

```ts title="Request"
await grpcSdk.database
.findMany("Movies", { duration: { $gt: 60 } });
```

### Document Creation

Create operation is very simple. Just invoke the **create()** function through database sdk and fill the
necessary fields for document creation.

```ts title="Request"
await grpcSdk.database
.create("Movies",{
title: "The Hobbit",
duration: 165,
genre: "scifi",
description: "Tolkien rocks",
director: "Peter Jackson",
releaseDate: "13/12/2012"
});
```

### Multi-Document Creation

```ts title="Request"
await grpcSdk.database.createMany("User",
[
{
title: "The Hobbit",
duration: 165,
genre: "scifi",
description: "Tolkien rocks",
director: "Peter Jackson",
releaseDate: "13/12/2012"
},
{
title: "The Spiderman",
duration: 200,
genre: "scifi",
description: "Marvel rocks",
director: "Sam Raimi",
releaseDate: "29/04/2002"
},
]
);
```


### Multi-Document Updates

We can use `updateMany()`to update multiple documents given some optional constraints.<br />
Suppose we wish to discontinue some movies from an online streaming service.

```ts title="Request"
const discontinuedMovies = [movieId2, movieId2,movieId3];
await grpcSdk.database
.updaeteMany("Movies",{ _id: { $in: discontinuedMovies } }, { discontinued: true });
```

### Document Deletion

The only thing we need is the document ID we want to delete.

```ts title="Request"
await grpcSdk.database
.deleteOne("Movies",{ _id : id });
```

### Multi-Document Deletion

Like updateMany we can use `deleteMany` to delete documents given some constraints.

```ts title="Request"
const idArray = [movieid2, movieid2, movieid3];
await grpcSdk.database
.deleteMany("Movies",{ _id :{ $in: idArray } });
```

### Document Count

Sometimes we only need to count how many documents exist with specific features.
For example, if we want to count how many movies are suitable only for.
**countDocuments()** should be used.<br />
An alternative but more complicated way of doing it is to use **findMany()** and calculate the length of the returned array.

```ts title="Request"
await grpcSdk.database
.countDocuments("Movies",{ genre: "SCIFI" });
```
Loading