@ductape/sdk 0.0.1 → 0.0.3-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Ductape streamlines software development with **composable** and **portable** co
|
|
|
20
20
|
|
|
21
21
|
### 1️ Install SDK
|
|
22
22
|
```sh
|
|
23
|
-
npm install ductape
|
|
23
|
+
npm install @ductape/sdk
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
### 2️ Define Apps & Actions
|
|
@@ -42,7 +42,7 @@ Group apps, resources, and features into a **product** for seamless interoperabi
|
|
|
42
42
|
|
|
43
43
|
### 6️ Use in Code
|
|
44
44
|
```js
|
|
45
|
-
import Ductape from "ductape
|
|
45
|
+
import Ductape from "@ductape/sdk";
|
|
46
46
|
|
|
47
47
|
const { processor } = new Ductape(credentials);
|
|
48
48
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { IMessageBrokerService } from
|
|
1
|
+
import type { IMessageBrokerService } from "./messagebrokers.type";
|
|
2
2
|
export declare class RedisService implements IMessageBrokerService {
|
|
3
3
|
private config;
|
|
4
4
|
private client;
|
|
5
5
|
private subscriber;
|
|
6
|
+
private isServer;
|
|
6
7
|
constructor(config: {
|
|
7
8
|
host: string;
|
|
8
9
|
port: number;
|
|
9
10
|
password?: string;
|
|
10
11
|
channel: string;
|
|
11
12
|
});
|
|
13
|
+
private loadRedis;
|
|
12
14
|
connect(): Promise<void>;
|
|
13
15
|
publish(topic: string, message: object): Promise<void>;
|
|
14
16
|
subscribe(topic: string, callback: (message: object) => void): Promise<void>;
|
|
@@ -1,13 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.RedisService = void 0;
|
|
4
|
-
const redis_1 = require("redis");
|
|
5
37
|
class RedisService {
|
|
6
38
|
constructor(config) {
|
|
7
39
|
this.config = config;
|
|
40
|
+
this.isServer = typeof window === "undefined";
|
|
41
|
+
}
|
|
42
|
+
async loadRedis() {
|
|
43
|
+
if (!this.isServer)
|
|
44
|
+
throw new Error("RedisService can only be used in a server environment.");
|
|
45
|
+
const redis = await Promise.resolve().then(() => __importStar(require("redis")));
|
|
46
|
+
return redis;
|
|
8
47
|
}
|
|
9
48
|
async connect() {
|
|
10
|
-
|
|
49
|
+
if (!this.isServer)
|
|
50
|
+
return;
|
|
51
|
+
const { createClient } = await this.loadRedis();
|
|
52
|
+
this.client = createClient({
|
|
11
53
|
socket: { host: this.config.host, port: this.config.port },
|
|
12
54
|
password: this.config.password,
|
|
13
55
|
});
|
|
@@ -16,16 +58,22 @@ class RedisService {
|
|
|
16
58
|
await this.subscriber.connect();
|
|
17
59
|
}
|
|
18
60
|
async publish(topic, message) {
|
|
61
|
+
if (!this.isServer)
|
|
62
|
+
return;
|
|
19
63
|
await this.connect();
|
|
20
64
|
await this.client.publish(topic, JSON.stringify(message));
|
|
21
65
|
}
|
|
22
66
|
async subscribe(topic, callback) {
|
|
67
|
+
if (!this.isServer)
|
|
68
|
+
return;
|
|
23
69
|
await this.connect();
|
|
24
70
|
await this.subscriber.subscribe(topic, (message) => {
|
|
25
71
|
callback(JSON.parse(message));
|
|
26
72
|
});
|
|
27
73
|
}
|
|
28
74
|
async disconnect() {
|
|
75
|
+
if (!this.isServer)
|
|
76
|
+
return;
|
|
29
77
|
await this.client.quit();
|
|
30
78
|
await this.subscriber.quit();
|
|
31
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.service.js","sourceRoot":"","sources":["../../../../src/processor/services/messagebrokers/redis.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redis.service.js","sourceRoot":"","sources":["../../../../src/processor/services/messagebrokers/redis.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAa,YAAY;IAKvB,YAAoB,MAA0E;QAA1E,WAAM,GAAN,MAAM,CAAoE;QAC5F,IAAI,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,SAAS;QACrB,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI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AC,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,OAAO;QAE3B,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACzB,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF;AApDD,oCAoDC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ductape/sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "sdk for
|
|
3
|
+
"version": "0.0.3beta1",
|
|
4
|
+
"description": "sdk for building ductaped products",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"@types/amqplib": "^0.10.6",
|
|
54
54
|
"@types/aws-sdk": "^0.0.42",
|
|
55
55
|
"@types/crypto-js": "^4.2.2",
|
|
56
|
+
"@types/mime-types": "^2.1.4",
|
|
56
57
|
"@types/nodemailer": "^6.4.17",
|
|
57
58
|
"@types/pg": "^8.11.11",
|
|
58
59
|
"@types/uuid": "^10.0.0",
|