Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/aws-service-sanity-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Verify documentation files and links
# check if the files exists in the repository. The file list is in utils/doc-links.txt.
# check if the files exists in the repository. The file list is in utils/ci-aws-doc-links.txt.
run: |
missing=0
while read -r file || [ -n "$file" ]; do
Expand Down
4 changes: 2 additions & 2 deletions samples/node/mqtt/mqtt5_aws_websocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ To Run this sample from the `samples/node/mqtt/aws_websocket` folder, use the fo

```sh
npm install
node index.js \
node dist/index.js \
--endpoint <AWS IoT endpoint> \
--signing_region <AWS region>
```
If you would like to see what optional arguments are available, use the `--help` argument:
``` sh
node index.js --help
node dist/index.js --help
```

will result in the following output:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* SPDX-License-Identifier: Apache-2.0.
*/

const { mqtt5, iot } = require("aws-iot-device-sdk-v2");
const { once } = require("events");
const yargs = require('yargs');
const { v4: uuidv4 } = require('uuid');
import { mqtt5, iot } from "aws-iot-device-sdk-v2";
import { once } from "events";
import yargs from "yargs";
import { v4 as uuidv4 } from "uuid";

const TIMEOUT = 100000;

Expand Down Expand Up @@ -74,7 +74,7 @@ async function runSample() {
const client = new mqtt5.Mqtt5Client(config);

// Event handler for when any message is received
client.on('messageReceived', (eventData) => {
client.on('messageReceived', (eventData: mqtt5.MessageReceivedEvent) => {
const message = eventData.message;
const payload = message.payload ? Buffer.from(message.payload).toString('utf-8') : '';
console.log(`==== Received message from topic '${message.topicName}': ${payload} ====\n`);
Expand All @@ -96,17 +96,17 @@ async function runSample() {
});

// Event handler for lifecycle event Connection Success
client.on('connectionSuccess', (eventData) => {
client.on('connectionSuccess', (eventData: mqtt5.ConnectionSuccessEvent) => {
console.log(`Lifecycle Connection Success with reason code: ${eventData.connack.reasonCode}\n`);
});

// Event handler for lifecycle event Connection Failure
client.on('connectionFailure', (eventData) => {
client.on('connectionFailure', (eventData: mqtt5.ConnectionFailureEvent) => {
console.log(`Lifecycle Connection Failure with exception: ${eventData.error}`);
});

// Event handler for lifecycle event Disconnection
client.on('disconnection', (eventData) => {
client.on('disconnection', (eventData: mqtt5.DisconnectionEvent) => {
const reasonCode = eventData.disconnect ? eventData.disconnect.reasonCode : 'None';
console.log(`Lifecycle Disconnected with reason code: ${reasonCode}`);
});
Expand All @@ -120,7 +120,7 @@ async function runSample() {
const connectionSuccess = once(client, "connectionSuccess");
await Promise.race([
connectionSuccess,
new Promise((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT))
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT))
]);

console.log(`==== Subscribing to topic '${args.topic}' ====`);
Expand Down Expand Up @@ -149,17 +149,17 @@ async function runSample() {
payload: message,
qos: mqtt5.QoS.AtLeastOnce
});
console.log(`PubAck received with ${publishResult.reasonCode}\n`);
console.log(`PubAck received with ${publishResult?.reasonCode}\n`);

await new Promise(resolve => setTimeout(resolve, 1500));
await new Promise<void>(resolve => setTimeout(resolve, 1500));
publishCount++;
}

if (receivedCount < args.count) {
const receivedAll = once(client, "receivedAll");
await Promise.race([
receivedAll,
new Promise(resolve => setTimeout(resolve, 5000))
new Promise<void>(resolve => setTimeout(resolve, 5000))
]);
}
console.log(`${receivedCount} message(s) received.\n`);
Expand All @@ -177,7 +177,7 @@ async function runSample() {

await Promise.race([
stopped,
new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT))
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT))
]);

console.log("==== Client Stopped! ====");
Expand All @@ -186,7 +186,7 @@ async function runSample() {

runSample().then(() => {
process.exit(0);
}).catch((error) => {
}).catch((error: Error) => {
console.error(error);
process.exit(1);
});
20 changes: 17 additions & 3 deletions samples/node/mqtt/mqtt5_aws_websocket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@
"name": "mqtt5-aws-websocket-sample",
"version": "1.0.0",
"description": "MQTT5 AWS Websocket Sample",
"main": "index.js",
"homepage": "https://github.com/aws/aws-iot-device-sdk-js-v2",
"repository": {
"type": "git",
"url": "git+https://github.com/aws/aws-iot-device-sdk-js-v2.git"
},
"contributors": [
"AWS SDK Common Runtime Team <aws-sdk-common-runtime@amazon.com>"
],
"license": "Apache-2.0",
"main": "dist/index.js",
"scripts": {
"start": "node index.js"
"tsc": "tsc",
"prepare": "npm run tsc"
},
"dependencies": {
"aws-iot-device-sdk-v2": "file:../../../..",
"yargs": "^17.0.0",
"yargs": "^16.2.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/node": "10.17.50",
"typescript": "^4.7.4"
}
}
67 changes: 67 additions & 0 deletions samples/node/mqtt/mqtt5_aws_websocket/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
"outDir": "./dist", /* Redirect output structure to the directory. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "composite": true, /* Enable project compilation */
// "removeComments": false, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": [
"*.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
4 changes: 2 additions & 2 deletions samples/node/mqtt/mqtt5_custom_auth_signed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ To Run this sample from the `samples/node/mqtt/mqtt5_custom_auth_signed` folder,

```sh
npm install
node index.js \
node dist/index.js \
--endpoint <AWS IoT endpoint> \
--authorizer_name <custom authorizer name> \
--auth_signature <signature> \
Expand All @@ -79,7 +79,7 @@ node index.js \
```
If you would like to see what optional arguments are available, use the `--help` argument:
``` sh
node index.js --help
node dist/index.js --help
```

will result in the following output:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* SPDX-License-Identifier: Apache-2.0.
*/

const { mqtt5, iot } = require("aws-iot-device-sdk-v2");
const { once } = require("events");
const yargs = require('yargs');
const { v4: uuidv4 } = require('uuid');
import { mqtt5, iot } from "aws-iot-device-sdk-v2";
import { once } from "events";
import yargs from "yargs";
import { v4 as uuidv4 } from "uuid";

const TIMEOUT = 100000;

Expand Down Expand Up @@ -90,7 +90,7 @@ async function runSample() {

// Create MQTT5 Client with a custom authorizer
console.log("==== Creating MQTT5 Client ====\n");
const customAuthConfig = {
const customAuthConfig: any = {
authorizerName: args.authorizer_name,
tokenSignature: args.auth_signature,
tokenKeyName: args.auth_token_key_name,
Expand Down Expand Up @@ -118,7 +118,7 @@ async function runSample() {
const client = new mqtt5.Mqtt5Client(config);

// Event handler for when any message is received
client.on('messageReceived', (eventData) => {
client.on('messageReceived', (eventData: mqtt5.MessageReceivedEvent) => {
const message = eventData.message;
const payload = message.payload ? Buffer.from(message.payload).toString('utf-8') : '';
console.log(`==== Received message from topic '${message.topicName}': ${payload} ====\n`);
Expand All @@ -140,17 +140,17 @@ async function runSample() {
});

// Event handler for lifecycle event Connection Success
client.on('connectionSuccess', (eventData) => {
client.on('connectionSuccess', (eventData: mqtt5.ConnectionSuccessEvent) => {
console.log(`Lifecycle Connection Success with reason code: ${eventData.connack.reasonCode}\n`);
});

// Event handler for lifecycle event Connection Failure
client.on('connectionFailure', (eventData) => {
client.on('connectionFailure', (eventData: mqtt5.ConnectionFailureEvent) => {
console.log(`Lifecycle Connection Failure with exception: ${eventData.error}`);
});

// Event handler for lifecycle event Disconnection
client.on('disconnection', (eventData) => {
client.on('disconnection', (eventData: mqtt5.DisconnectionEvent) => {
const reasonCode = eventData.disconnect ? eventData.disconnect.reasonCode : 'None';
console.log(`Lifecycle Disconnected with reason code: ${reasonCode}`);
});
Expand All @@ -164,7 +164,7 @@ async function runSample() {
const connectionSuccess = once(client, "connectionSuccess");
await Promise.race([
connectionSuccess,
new Promise((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT))
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT))
]);

console.log(`==== Subscribing to topic '${args.topic}' ====`);
Expand Down Expand Up @@ -193,17 +193,17 @@ async function runSample() {
payload: message,
qos: mqtt5.QoS.AtLeastOnce
});
console.log(`PubAck received with ${publishResult.reasonCode}\n`);
console.log(`PubAck received with ${publishResult?.reasonCode}\n`);

await new Promise(resolve => setTimeout(resolve, 1500));
await new Promise<void>(resolve => setTimeout(resolve, 1500));
publishCount++;
}

if (receivedCount < args.count) {
const receivedAll = once(client, "receivedAll");
await Promise.race([
receivedAll,
new Promise(resolve => setTimeout(resolve, 5000))
new Promise<void>(resolve => setTimeout(resolve, 5000))
]);
}
console.log(`${receivedCount} message(s) received.\n`);
Expand All @@ -221,7 +221,7 @@ async function runSample() {

await Promise.race([
stopped,
new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT))
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT))
]);

console.log("==== Client Stopped! ====");
Expand All @@ -230,7 +230,7 @@ async function runSample() {

runSample().then(() => {
process.exit(0);
}).catch((error) => {
}).catch((error: Error) => {
console.error(error);
process.exit(1);
});
20 changes: 17 additions & 3 deletions samples/node/mqtt/mqtt5_custom_auth_signed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@
"name": "mqtt5-custom-auth-signed-sample",
"version": "1.0.0",
"description": "MQTT5 Signed Custom Authorizer Sample",
"main": "index.js",
"homepage": "https://github.com/aws/aws-iot-device-sdk-js-v2",
"repository": {
"type": "git",
"url": "git+https://github.com/aws/aws-iot-device-sdk-js-v2.git"
},
"contributors": [
"AWS SDK Common Runtime Team <aws-sdk-common-runtime@amazon.com>"
],
"license": "Apache-2.0",
"main": "dist/index.js",
"scripts": {
"start": "node index.js"
"tsc": "tsc",
"prepare": "npm run tsc"
},
"dependencies": {
"aws-iot-device-sdk-v2": "file:../../../..",
"yargs": "^17.0.0",
"yargs": "^16.2.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/node": "10.17.50",
"typescript": "^4.7.4"
}
}
Loading
Loading