@layerhq/idk
Advanced tools
Comparing version 1.0.0-pre.4 to 1.0.0-pre1.0
415
API.md
## API | ||
Access common [Layer Server API](https://docs.layer.com/reference/server_api/introduction) operations via `.api` namespace. | ||
Access common [Layer Server API](https://docs.layer.com/reference/server_api/introduction) operations via `.api` namespace. All the operations are asynchronous and return a Promise that needs to be handled. | ||
> All of these operation are asynchronous and return a Promise that needs to be handled. | ||
The response schema contains the following information: | ||
### .api.identities.create(userId, identity) | ||
```js | ||
{ | ||
// `data` is the response that was provided by the server | ||
data: {}, | ||
Create a new Layer identity by passing `userId` and `identity` object. | ||
// `status` is the HTTP status code from the server response | ||
status: 200 | ||
} | ||
``` | ||
#### Arguments | ||
### conversations.create(participants, metadata, distinct) | ||
- `userId` - Layer user identity ID | ||
- `identity` - Layer user identity object | ||
Create a new conversation. | ||
- `participants` - Array of user IDs | ||
- `metadata` - *Optional* Metadata object | ||
- `distinct` - *Optional* Distinct boolean | ||
#### Example | ||
```javascript | ||
const senderId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const identity = { | ||
display_name: 'Foo Bar' | ||
} | ||
layerIDK.api.identities.create(senderId, identity) | ||
```js | ||
const participants = ['user1'] | ||
layerIDK.api.conversations.create(participants) | ||
.then(() => { | ||
// identity created | ||
// conversation created | ||
}) | ||
.catch(console.error) | ||
``` | ||
### conversations.get(conversationId) | ||
Fetch a conversation. | ||
- `conversationId` - Conversation ID | ||
#### Example | ||
```js | ||
const conversationId = 'layer:///conversations/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
layerIDK.api.conversations.get(conversationId) | ||
.then(({ data }) => { | ||
console.log('conversation', data) | ||
}) | ||
``` | ||
### .api.identities.get(userId) | ||
### conversations.delete(conversationId) | ||
Fetch a full Layer identity object by passing the `userId`. | ||
Delete a conversation. | ||
#### Arguments | ||
- `conversationId` - Conversation ID | ||
- `userId` - Layer user identity ID | ||
#### Example | ||
```js | ||
const conversationId = 'layer:///conversations/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
layerIDK.api.conversations.delete(conversationId) | ||
.then(() => { | ||
// conversation deleted | ||
}) | ||
``` | ||
### conversations.addParticipants(conversationId, participants) | ||
Add one or more participants to a conversation. | ||
- `conversationId` - Conversation ID | ||
- `participants` - Array or participant user IDs | ||
#### Example | ||
```javascript | ||
const senderId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
layerIDK.api.identities.get(senderId) | ||
.then((identity) => { | ||
// identity payload | ||
```js | ||
const participants = ['user2', 'user3'] | ||
layerIDK.api.conversations.addParticipants(conversationId, participants) | ||
.then(() => { | ||
// participants added | ||
}) | ||
.catch(console.error) | ||
``` | ||
### conversations.removeParticipants(conversationId, participants) | ||
Remove one or more participants to a conversation. | ||
- `conversationId` - Conversation ID | ||
- `participants` - Array or participant user IDs | ||
#### Example | ||
```js | ||
const participants = ['user3'] | ||
layerIDK.api.conversations.removeParticipants(conversationId, participants) | ||
.then(() => { | ||
// participants added | ||
}) | ||
``` | ||
### .api.identities.update(userId, identity) | ||
### conversations.updateMetadata(conversationId, operations) | ||
Update Layer identity by passing `userId` and `identity` object. | ||
Update conversation metadata. | ||
#### Arguments | ||
- `conversationId` - Conversation ID | ||
- `operations` - Array of [Layer Patch](https://github.com/layerhq/layer-patch) operations | ||
- `userId` - Layer user identity ID | ||
- `identity` - Layer user identity object | ||
#### Example | ||
```js | ||
const operations = [{ | ||
'operation': 'set', | ||
'property': 'metadata.foo', | ||
'value': 'bar' | ||
}] | ||
layerIDK.api.conversations.updateMetadata(conversationId, operations) | ||
.then(() => { | ||
// metadata updated | ||
}) | ||
``` | ||
### conversations.markAsRead(conversationId, userId, position) | ||
Mark all messages as read in a conversation. | ||
- `conversationId` - Conversation ID | ||
- `userId` - User ID | ||
- `position` - *Optional* Message position | ||
#### Example | ||
```javascript | ||
const senderId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const identity = { | ||
display_name: 'Foo Baz' | ||
} | ||
layerIDK.api.identities.update(senderId, identity) | ||
```js | ||
const userId = 'user1' | ||
layerIDK.api.conversations.markAsRead(conversationId, userId) | ||
.then(() => { | ||
// identity updated | ||
// marked as read | ||
}) | ||
.catch(console.error) | ||
``` | ||
### messages.send(conversationId, userId, parts) | ||
Send a message in a conversation. | ||
- `conversationId` - Conversation ID | ||
- `userId` - User ID | ||
- `parts` - Array of message parts | ||
#### Example | ||
```js | ||
const userId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const parts = [{ | ||
mime_type: 'plain/text', | ||
body: 'Hello world' | ||
}] | ||
layerIDK.api.messages.send(conversationId, userId, parts) | ||
.then(({ data }) => { | ||
console.log('message', data) | ||
}) | ||
``` | ||
### .api.messages.send(conversationId, senderId, parts) | ||
### messages.get(conversationId, messageId) | ||
Send a message with message parts to a conversation. | ||
Fetch a message in a conversation. | ||
#### Arguments | ||
- `conversationId` - Conversation ID | ||
- `messageId` - Message ID | ||
- `conversationId` - Layer conversation ID | ||
- `senderId` - Layer user identity ID | ||
- `parts` - Layer message parts array | ||
#### Example | ||
```js | ||
const messageId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
layerIDK.api.messages.get(conversationId, messageId) | ||
.then(({ data }) => { | ||
console.log('message', data) | ||
}) | ||
``` | ||
### messages.getAll(conversationId) | ||
Fetch all messages in a conversation. | ||
- `conversationId` - Conversation ID | ||
#### Example | ||
```javascript | ||
const conversationId = 'layer:///conversations/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const senderId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const parts = [ | ||
{ | ||
mime_type: 'plain/text', | ||
body: 'Hello world' | ||
} | ||
] | ||
layerIDK.api.messages.send(conversationId, senderId, parts) | ||
.then(() => { | ||
// message sent | ||
```js | ||
layerIDK.api.messages.getAll(conversationId) | ||
.then(({ data }) => { | ||
console.log('messages', data) | ||
}) | ||
.catch(console.error) | ||
``` | ||
### .api.messages.getPart(conversationId, messageId, partId) | ||
### messages.getParts(conversationId, messageId) | ||
Get a message part in a conversation. | ||
Fetch all message parts in a conversation. | ||
#### Arguments | ||
- `conversationId` - Conversation ID | ||
- `messageId` - Message ID | ||
- `conversationId` - Layer conversation ID | ||
- `messageId` - Layer message ID | ||
- `partId` - Layer message part ID | ||
#### Example | ||
```js | ||
const messageId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
layerIDK.api.messages.getParts(conversationId, messageId) | ||
.then(({ data }) => { | ||
console.log('message parts', data) | ||
}) | ||
``` | ||
### messages.getPart(conversationId, messageId, partId) | ||
Fetch a single message part in a conversation. | ||
- `conversationId` - Conversation ID | ||
- `messageId` - Message ID | ||
- `partId` - Message part ID | ||
#### Example | ||
```javascript | ||
const conversationId = 'layer:///conversations/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
```js | ||
const messageId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
@@ -121,21 +226,17 @@ const partId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff/parts/0' | ||
.then((part) => { | ||
// message part | ||
console.log('message part', data) | ||
}) | ||
.catch(console.error) | ||
``` | ||
### .api.messages.addPart(conversationId, messageId, part) | ||
### messages.addPart(conversationId, messageId, part) | ||
Add a new part to a message in a conversation. | ||
#### Arguments | ||
- `conversationId` - Conversation ID | ||
- `messageId` - Message ID | ||
- `part` - Message part object | ||
- `conversationId` - Layer conversation ID | ||
- `messageId` - Layer message ID | ||
- `part` - Layer message part object | ||
#### Example | ||
```javascript | ||
const conversationId = 'layer:///conversations/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
```js | ||
const messageId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
@@ -150,20 +251,16 @@ const part = { | ||
}) | ||
.catch(console.error) | ||
``` | ||
### .api.messages.updatePart(conversationId, messageId, partId, part) | ||
### messages.updatePart(conversationId, messageId, partId, part) | ||
Add a new part to a message in a conversation. | ||
Update existing message part in a conversation. | ||
#### Arguments | ||
- `conversationId` - Conversation ID | ||
- `messageId` - Message ID | ||
- `partId` - Message part ID | ||
- `part` - Message part object | ||
- `conversationId` - Layer conversation ID | ||
- `messageId` - Layer message ID | ||
- `partId` - Layer message part ID | ||
- `part` - Layer message part object | ||
#### Example | ||
```javascript | ||
const conversationId = 'layer:///conversations/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
```js | ||
const messageId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
@@ -179,19 +276,56 @@ const partId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff/parts/0' | ||
}) | ||
.catch(console.error) | ||
``` | ||
### .api.messages.delete(conversationId, messageId) | ||
### messages.replaceParts(conversationId, messageId, part) | ||
Delete a message in a conversation. | ||
Replace all message parts. | ||
#### Arguments | ||
- `conversationId` - Conversation ID | ||
- `messageId` - Message ID | ||
- `parts` - Array of message parts | ||
- `conversationId` - Layer conversation ID | ||
- `messageId` - Layer message ID | ||
#### Example | ||
```js | ||
const messageId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const parts = [{ | ||
mime_type: 'plain/text', | ||
body: 'Hello world' | ||
}] | ||
layerIDK.api.messages.replaceParts(conversationId, messageId, parts) | ||
.then(() => { | ||
// message parts replaced | ||
}) | ||
``` | ||
### messages.deletePart(conversationId, messageId, partId) | ||
Delete a single message part in a conversation. | ||
- `conversationId` - Conversation ID | ||
- `messageId` - Message ID | ||
- `partId` - Message part ID | ||
#### Example | ||
```javascript | ||
const conversationId = 'layer:///conversations/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
```js | ||
const messageId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const partId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff/parts/0' | ||
layerIDK.api.messages.deletePart(conversationId, messageId, partId) | ||
.then(() => { | ||
// message part deleted | ||
}) | ||
``` | ||
### messages.delete(conversationId, messageId) | ||
Delete a message in a conversation. | ||
- `conversationId` - Conversation ID | ||
- `messageId` - Message ID | ||
#### Example | ||
```js | ||
const messageId = 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
layerIDK.api.messages.delete(conversationId, messageId) | ||
@@ -201,3 +335,94 @@ .then(() => { | ||
}) | ||
.catch(console.error) | ||
``` | ||
### identities.create(userId, identity) | ||
Create a new identity. | ||
- `userId` - User ID | ||
- `identity` - User identity object | ||
#### Example | ||
```js | ||
const userId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const identity = { | ||
display_name: 'Foo Bar' | ||
} | ||
layerIDK.api.identities.create(userId, identity) | ||
.then(() => { | ||
// identity created | ||
}) | ||
``` | ||
### identities.get(userId) | ||
Fetch an identity. | ||
- `userId` - User ID | ||
#### Example | ||
```js | ||
const userId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
layerIDK.api.identities.get(userId) | ||
.then(({ data }) => { | ||
console.log('identity', data) | ||
}) | ||
``` | ||
### identities.update(userId, identity) | ||
Update identity object. | ||
- `userId` - User ID | ||
- `identity` - Identity object | ||
#### Example | ||
```js | ||
const userId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const identity = { | ||
email: 'foo@bar.com' | ||
} | ||
layerIDK.api.identities.update(userId, identity) | ||
.then(() => { | ||
// identity updated | ||
}) | ||
``` | ||
### identities.replace(userId, identity) | ||
Replace entire identity object. | ||
- `userId` - User ID | ||
- `identity` - Identity object | ||
#### Example | ||
```js | ||
const userId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
const identity = { | ||
display_name: 'Foo Bar New' | ||
} | ||
layerIDK.api.identities.replace(userId, identity) | ||
.then(() => { | ||
// identity replaced | ||
}) | ||
``` | ||
### identities.delete(userId) | ||
Delete an identity. | ||
- `userId` - User ID | ||
#### Example | ||
```js | ||
const userId = 'layer:///identities/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
layerIDK.api.identities.delete(userId) | ||
.then(() => { | ||
// identity deleted | ||
}) | ||
``` |
## Monitoring | ||
Logger has a built in monitoring capabilities using [PagerDuty](https://www.pagerduty.com/) API. It is enabled **only** if PagerDuty credentials are present in config as part of [initialization](../README.md#initialization). | ||
Logger has a built in monitoring capabilities using [PagerDuty](https://www.pagerduty.com/) API. It is enabled **only** if PagerDuty credentials are present in config as part of [initialization](/README.md#initialization). | ||
@@ -34,2 +34,2 @@ ```json | ||
All this information should help identify which integration triggered an alert. | ||
All this information should help identify which integration triggered an alert. |
{ | ||
"name": "@layerhq/idk", | ||
"version": "1.0.0-pre.4", | ||
"version": "1.0.0-pre1.0", | ||
"description": "Layer Integration Development Kit common library", | ||
"author": "Layer Developers <support@layer.com>", | ||
"license": "Apache-2.0", | ||
"repository": "layerhq/idk", | ||
"scripts": { | ||
@@ -11,3 +14,2 @@ "test": "LOG_LEVEL=none mocha --require should --bail tests/*spec.js tests/api/*spec.js", | ||
}, | ||
"author": "Layer Developers <support@layer.com>", | ||
"dependencies": { | ||
@@ -14,0 +16,0 @@ "axios": "^0.16.2", |
# Layer IDK | ||
[![Build Status](https://circleci.com/gh/layerhq/idk.png?circle-token=6240fae3391dc4c5e37b06ef8494c9dd47350d07)](https://circleci.com/gh/layerhq/idk) | ||
This is a Node.js library that is designed to be used with Layer Integration Development Kit (IDK). | ||
This is a Node.js library that is designed to be used with Layer [Integration Development Kit](https://preview-docs.layer.com/reference/integrations/framework) (IDK). | ||
It provides common functionality for validating & processing [Layer Webhooks](https://docs.layer.com/reference/webhooks/introduction) and provides access to common [Layer Server API](https://docs.layer.com/reference/server_api/introduction) operations. | ||
It provides common functionality for validating & processing Layer [Webhooks](https://docs.layer.com/reference/webhooks/introduction) and access to common Layer [Server API](https://docs.layer.com/reference/server_api/introduction) operations. | ||
@@ -28,4 +28,3 @@ ## Initialization | ||
"api": { | ||
"token": "8vztSuZt9qaYmSpCjoPQma4uDwGDNxGrFVcsfpojoPQma4uDwGTb1P4Eu5U", | ||
"permissions": [] | ||
"token": "abcdefg" | ||
} | ||
@@ -32,0 +31,0 @@ } |
@@ -10,3 +10,3 @@ { | ||
"api": { | ||
"token": "X7APpoZNdYdWnG5lCKaLXREwQTOqAzEwMy9pqGwWegetruEV", | ||
"token": "secretoken", | ||
"permissions": [] | ||
@@ -13,0 +13,0 @@ }, |
24
UTILS.md
@@ -9,4 +9,2 @@ ## Utils | ||
#### Arguments | ||
- `id` - Layer ID | ||
@@ -21,2 +19,16 @@ | ||
### .toLayerPrefix(id) | ||
Add Layer prefix to any plain ID. | ||
- `type` - Layer prefix type e.g. `conversations`, `messages`, etc. | ||
- `uuid` - Plain UUID | ||
#### Example | ||
```javascript | ||
const messageUUID = LayerIDK.toLayerPrefix('messages', 'ffffffff-ffff-ffff-ffff-ffffffffffff') | ||
// 'layer:///messages/ffffffff-ffff-ffff-ffff-ffffffffffff' | ||
``` | ||
### .promiseSerial(operations) | ||
@@ -26,4 +38,2 @@ | ||
#### Arguments | ||
- `operations` - An array of functions that returns a Promise | ||
@@ -51,4 +61,2 @@ | ||
#### Arguments | ||
- `array` - An array | ||
@@ -69,4 +77,2 @@ - `chunks` - Number of chunks | ||
#### Arguments | ||
- `parts` - An array of message parts | ||
@@ -104,4 +110,2 @@ - `media` - Mime type media hash | ||
#### Arguments | ||
- `message` - Layer Message object | ||
@@ -108,0 +112,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
142734
55
0
120