Skip to content

Commit c99ed17

Browse files
committed
Merge remote-tracking branch 'upstream/main' into jriffs/custom-errors
2 parents af421e3 + 0d16244 commit c99ed17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4401
-690
lines changed

.github/workflows/test-e2e.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ jobs:
3434
test-e2e:
3535
runs-on: ubuntu-latest
3636
env:
37-
GOVER: 1.19
38-
DAPR_CLI_VER: 1.10.0
39-
DAPR_RUNTIME_VER: 1.11.0-rc.5
37+
GOVER: 1.20
38+
DAPR_CLI_VER: 1.11.0
39+
DAPR_RUNTIME_VER: 1.11.0
4040
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/master/install/install.sh
4141
DAPR_CLI_REF: ""
4242
DAPR_REF: ""

daprdocs/content/en/js-sdk-docs/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ A client library for building Dapr apps in JavaScript and TypeScript. This clien
1111

1212
## Installation
1313

14-
To get started with the Javascript SDK, install the Dapr JavaScript SDK package from [NPM](https://www.npmjs.com/package/@dapr/dapr):
14+
To get started with the JavaScript SDK, install the Dapr JavaScript SDK package from [NPM](https://www.npmjs.com/package/@dapr/dapr):
1515

1616
```bash
1717
npm install --save @dapr/dapr
1818
```
1919

2020
## Structure
2121

22-
The Dapr Javascript SDK contains two major components:
22+
The Dapr JavaScript SDK contains two major components:
2323

2424
- **DaprServer**: to manage all Dapr sidecar to application communication.
2525
- **DaprClient**: to manage all application to Dapr sidecar communication.

daprdocs/content/en/js-sdk-docs/js-client/_index.md

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The Dapr Client allows you to communicate with the Dapr Sidecar and get access t
1414

1515
- [Dapr CLI]({{< ref install-dapr-cli.md >}}) installed
1616
- Initialized [Dapr environment]({{< ref install-dapr-selfhost.md >}})
17-
- [Latest LTS version of Node or greater](https://nodejs.org/en/)
17+
- [Latest LTS version of Node.js or greater](https://nodejs.org/en/)
1818

1919
## Installing and importing Dapr's JS SDK
2020

@@ -451,6 +451,96 @@ start().catch((e) => {
451451
});
452452
```
453453

454+
### Cryptography API
455+
456+
> Support for the cryptography API is only available on the gRPC client in the JavaScript SDK.
457+
458+
```typescript
459+
import { createReadStream, createWriteStream } from "node:fs";
460+
import { readFile, writeFile } from "node:fs/promises";
461+
import { pipeline } from "node:stream/promises";
462+
463+
import { DaprClient, CommunicationProtocolEnum } from "@dapr/dapr";
464+
465+
const daprHost = "127.0.0.1";
466+
const daprPort = "50050"; // Dapr Sidecar Port of this example server
467+
468+
async function start() {
469+
const client = new DaprClient({
470+
daprHost,
471+
daprPort,
472+
communicationProtocol: CommunicationProtocolEnum.GRPC,
473+
});
474+
475+
// Encrypt and decrypt a message using streams
476+
await encryptDecryptStream(client);
477+
478+
// Encrypt and decrypt a message from a buffer
479+
await encryptDecryptBuffer(client);
480+
}
481+
482+
async function encryptDecryptStream(client: DaprClient) {
483+
// First, encrypt the message
484+
console.log("== Encrypting message using streams");
485+
console.log("Encrypting plaintext.txt to ciphertext.out");
486+
487+
await pipeline(
488+
createReadStream("plaintext.txt"),
489+
await client.crypto.encrypt({
490+
componentName: "crypto-local",
491+
keyName: "symmetric256",
492+
keyWrapAlgorithm: "A256KW",
493+
}),
494+
createWriteStream("ciphertext.out"),
495+
);
496+
497+
// Decrypt the message
498+
console.log("== Decrypting message using streams");
499+
console.log("Encrypting ciphertext.out to plaintext.out");
500+
await pipeline(
501+
createReadStream("ciphertext.out"),
502+
await client.crypto.decrypt({
503+
componentName: "crypto-local",
504+
}),
505+
createWriteStream("plaintext.out"),
506+
);
507+
}
508+
509+
async function encryptDecryptBuffer(client: DaprClient) {
510+
// Read "plaintext.txt" so we have some content
511+
const plaintext = await readFile("plaintext.txt");
512+
513+
// First, encrypt the message
514+
console.log("== Encrypting message using buffers");
515+
516+
const ciphertext = await client.crypto.encrypt(plaintext, {
517+
componentName: "crypto-local",
518+
keyName: "my-rsa-key",
519+
keyWrapAlgorithm: "RSA",
520+
});
521+
522+
await writeFile("test.out", ciphertext);
523+
524+
// Decrypt the message
525+
console.log("== Decrypting message using buffers");
526+
const decrypted = await client.crypto.decrypt(ciphertext, {
527+
componentName: "crypto-local",
528+
});
529+
530+
// The contents should be equal
531+
if (plaintext.compare(decrypted) !== 0) {
532+
throw new Error("Decrypted message does not match original message");
533+
}
534+
}
535+
536+
start().catch((e) => {
537+
console.error(e);
538+
process.exit(1);
539+
});
540+
```
541+
542+
> For a full guide on cryptography visit [How-To: Cryptography]({{< ref howto-cryptography.md >}}).
543+
454544
### Distributed Lock API
455545

456546
#### Try Lock and Unlock APIs
@@ -500,6 +590,56 @@ start().catch((e) => {
500590

501591
> For a full guide on distributed locks visit [How-To: Use Distributed Locks]({{< ref howto-use-distributed-lock.md >}}).
502592
593+
### Workflow API
594+
595+
#### Workflow management
596+
597+
```typescript
598+
import { DaprClient } from "@dapr/dapr";
599+
600+
async function start() {
601+
const client = new DaprClient();
602+
603+
// Start a new workflow instance
604+
const instanceId = await client.workflow.start("OrderProcessingWorkflow", {
605+
Name: "Paperclips",
606+
TotalCost: 99.95,
607+
Quantity: 4,
608+
});
609+
console.log(`Started workflow instance ${instanceId}`);
610+
611+
// Get a workflow instance
612+
const workflow = await client.workflow.get(instanceId);
613+
console.log(
614+
`Workflow ${workflow.workflowName}, created at ${workflow.createdAt.toUTCString()}, has status ${
615+
workflow.runtimeStatus
616+
}`,
617+
);
618+
console.log(`Additional properties: ${JSON.stringify(workflow.properties)}`);
619+
620+
// Pause a workflow instance
621+
await client.workflow.pause(instanceId);
622+
console.log(`Paused workflow instance ${instanceId}`);
623+
624+
// Resume a workflow instance
625+
await client.workflow.resume(instanceId);
626+
console.log(`Resumed workflow instance ${instanceId}`);
627+
628+
// Terminate a workflow instance
629+
await client.workflow.terminate(instanceId);
630+
console.log(`Terminated workflow instance ${instanceId}`);
631+
632+
// Purge a workflow instance
633+
await client.workflow.purge(instanceId);
634+
console.log(`Purged workflow instance ${instanceId}`);
635+
}
636+
637+
start().catch((e) => {
638+
console.error(e);
639+
process.exit(1);
640+
});
641+
```
642+
503643
## Related links
504644

505645
- [JavaScript SDK examples](https://github.com/dapr/js-sdk/tree/master/examples)

examples/grpc/crypto/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.out

examples/grpc/crypto/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Examples - Crypto
2+
3+
## Running
4+
5+
```bash
6+
# Install
7+
npm install
8+
9+
# Run the example
10+
npm run start:dapr
11+
```

0 commit comments

Comments
 (0)