@roadwork/dapr-js-sdk
Advanced tools
Comparing version 0.1.10 to 0.1.11
"use strict"; | ||
// https://github.com/dapr/docs/blob/master/reference/api/state_api.md | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -61,2 +60,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
server = _a.sent(); | ||
console.log("[Binding] Listening on /" + bindingName); | ||
server.post("/" + bindingName, function (req, res) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -68,3 +68,2 @@ var e_1; | ||
req.setTimeout(60 * 1000); // amount of seconds to wait for the request CB to finalize | ||
console.log(req.body); | ||
_a.label = 1; | ||
@@ -71,0 +70,0 @@ case 1: |
@@ -46,2 +46,3 @@ "use strict"; | ||
var WebServerSingleton_1 = __importDefault(require("../singleton/WebServerSingleton")); | ||
// https://docs.dapr.io/reference/api/service_invocation_api/ | ||
var DaprInvoker = /** @class */ (function () { | ||
@@ -48,0 +49,0 @@ function DaprInvoker(daprUrl) { |
"use strict"; | ||
// https://docs.dapr.io/reference/api/pubsub_api/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -45,2 +44,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var WebServerSingleton_1 = __importDefault(require("../singleton/WebServerSingleton")); | ||
// https://docs.dapr.io/reference/api/pubsub_api/ | ||
var DaprPubSub = /** @class */ (function () { | ||
@@ -47,0 +47,0 @@ function DaprPubSub(daprUrl) { |
@@ -44,2 +44,3 @@ "use strict"; | ||
var Response_util_1 = __importDefault(require("../utils/Response.util")); | ||
// https://docs.dapr.io/reference/api/secrets_api/ | ||
var DaprSecret = /** @class */ (function () { | ||
@@ -46,0 +47,0 @@ function DaprSecret(daprUrl) { |
"use strict"; | ||
// https://github.com/dapr/docs/blob/master/reference/api/state_api.md | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -45,2 +44,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var Response_util_1 = __importDefault(require("../utils/Response.util")); | ||
// https://docs.dapr.io/reference/api/state_api/ | ||
var DaprState = /** @class */ (function () { | ||
@@ -47,0 +47,0 @@ function DaprState(daprUrl) { |
@@ -151,3 +151,3 @@ "use strict"; | ||
this.express = express_1.default(); | ||
// this.express.use(express.json({ type: 'application/*+json' })); // We used this for application/cloudevents+json but empty takes everything as json | ||
this.express.use(express_1.default.json({ type: 'application/*+json' })); // Required for application/cloudevents+json | ||
this.express.use(express_1.default.json()); | ||
@@ -154,0 +154,0 @@ this.expressListener = this.express.listen(appPort, resolve); |
{ | ||
"name": "@roadwork/dapr-js-sdk", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"description": "An unofficial Dapr (https://dapr.io) SDK for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -11,14 +11,18 @@ # Dapr Node.js SDK | ||
Initialize through the following: | ||
1. Set the environment variable `DAPR_APP_PORT` to equal to the app port | ||
e.g. `DAPR_APP_PORT=4000 dapr run --app-id hello-world --app-port 4000 --dapr-http-port 3500 --components-path ./components/ npm run start:dev` | ||
2. Initialize through the following: | ||
```javascript | ||
import Dapr from "@roadwork/dapr-js-sdk"; | ||
import express from "express"; // starts the dapr listener on the app port | ||
import Dapr, { Req, Res } from "@roadwork/dapr-js-sdk"; | ||
const client = new Dapr("<dapr_url>", "<dapr_port>"); | ||
await client.initialize(); | ||
// Pub / Sub | ||
const bindingReceive = (data: any) => { console.log(data); } | ||
client.pubsub.subscribe("pubsub-name", "topic", bindingReceive.bind(this)) | ||
// Note: /dapr/subscribe will be called on the provided DAPR_APP_PORT and --app-port values. | ||
// if you are running an extra HTTP server, make sure to utilize a different port. Dapr will not wait till your app started, which is not required since the library takes care of Dapr related functionality internally. | ||
const pubsubCallback = async (data: any) => { console.log(data); } | ||
client.pubsub.subscribe("pubsub-name", "topic", pubsubCallback.bind(this)) | ||
await client.pubsub.publish("pubsub-name", "topic", { hello: "world" }); | ||
@@ -52,4 +56,4 @@ | ||
const invokerListen = (req: express.Request, res: express.Response) => { console.log(data); } | ||
await client.invoker.listen("method", invokerListen.bind(this), options) | ||
const invokerListen = (req: Req, res: Res) => { console.log(data); } | ||
await client.invoker.listen("method", invokerListen.bind(this), options); | ||
@@ -56,0 +60,0 @@ // Secrets |
122725
2086
109