diff --git a/.github/workflows/aws-service-sanity-check.yml b/.github/workflows/aws-service-sanity-check.yml index 8b0bf20f..2634929b 100644 --- a/.github/workflows/aws-service-sanity-check.yml +++ b/.github/workflows/aws-service-sanity-check.yml @@ -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 diff --git a/samples/node/mqtt/mqtt5_aws_websocket/README.md b/samples/node/mqtt/mqtt5_aws_websocket/README.md index ff4ec6eb..5bf3e72c 100644 --- a/samples/node/mqtt/mqtt5_aws_websocket/README.md +++ b/samples/node/mqtt/mqtt5_aws_websocket/README.md @@ -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 \ --signing_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: diff --git a/samples/node/mqtt/mqtt5_aws_websocket/index.js b/samples/node/mqtt/mqtt5_aws_websocket/index.ts similarity index 85% rename from samples/node/mqtt/mqtt5_aws_websocket/index.js rename to samples/node/mqtt/mqtt5_aws_websocket/index.ts index 9aca983e..f8a142c7 100644 --- a/samples/node/mqtt/mqtt5_aws_websocket/index.js +++ b/samples/node/mqtt/mqtt5_aws_websocket/index.ts @@ -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; @@ -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`); @@ -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}`); }); @@ -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((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT)) ]); console.log(`==== Subscribing to topic '${args.topic}' ====`); @@ -149,9 +149,9 @@ 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(resolve => setTimeout(resolve, 1500)); publishCount++; } @@ -159,7 +159,7 @@ async function runSample() { const receivedAll = once(client, "receivedAll"); await Promise.race([ receivedAll, - new Promise(resolve => setTimeout(resolve, 5000)) + new Promise(resolve => setTimeout(resolve, 5000)) ]); } console.log(`${receivedCount} message(s) received.\n`); @@ -177,7 +177,7 @@ async function runSample() { await Promise.race([ stopped, - new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) + new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) ]); console.log("==== Client Stopped! ===="); @@ -186,7 +186,7 @@ async function runSample() { runSample().then(() => { process.exit(0); -}).catch((error) => { +}).catch((error: Error) => { console.error(error); process.exit(1); }); \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_aws_websocket/package.json b/samples/node/mqtt/mqtt5_aws_websocket/package.json index 8f5f00a7..cdece484 100644 --- a/samples/node/mqtt/mqtt5_aws_websocket/package.json +++ b/samples/node/mqtt/mqtt5_aws_websocket/package.json @@ -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 " + ], + "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" } } \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_aws_websocket/tsconfig.json b/samples/node/mqtt/mqtt5_aws_websocket/tsconfig.json new file mode 100644 index 00000000..358dbd0e --- /dev/null +++ b/samples/node/mqtt/mqtt5_aws_websocket/tsconfig.json @@ -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" + ] +} \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_custom_auth_signed/README.md b/samples/node/mqtt/mqtt5_custom_auth_signed/README.md index 37121630..9af9e367 100644 --- a/samples/node/mqtt/mqtt5_custom_auth_signed/README.md +++ b/samples/node/mqtt/mqtt5_custom_auth_signed/README.md @@ -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 \ --authorizer_name \ --auth_signature \ @@ -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: diff --git a/samples/node/mqtt/mqtt5_custom_auth_signed/index.js b/samples/node/mqtt/mqtt5_custom_auth_signed/index.ts similarity index 87% rename from samples/node/mqtt/mqtt5_custom_auth_signed/index.js rename to samples/node/mqtt/mqtt5_custom_auth_signed/index.ts index 1e8efd4c..6f59aaeb 100644 --- a/samples/node/mqtt/mqtt5_custom_auth_signed/index.js +++ b/samples/node/mqtt/mqtt5_custom_auth_signed/index.ts @@ -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; @@ -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, @@ -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`); @@ -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}`); }); @@ -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((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT)) ]); console.log(`==== Subscribing to topic '${args.topic}' ====`); @@ -193,9 +193,9 @@ 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(resolve => setTimeout(resolve, 1500)); publishCount++; } @@ -203,7 +203,7 @@ async function runSample() { const receivedAll = once(client, "receivedAll"); await Promise.race([ receivedAll, - new Promise(resolve => setTimeout(resolve, 5000)) + new Promise(resolve => setTimeout(resolve, 5000)) ]); } console.log(`${receivedCount} message(s) received.\n`); @@ -221,7 +221,7 @@ async function runSample() { await Promise.race([ stopped, - new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) + new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) ]); console.log("==== Client Stopped! ===="); @@ -230,7 +230,7 @@ async function runSample() { runSample().then(() => { process.exit(0); -}).catch((error) => { +}).catch((error: Error) => { console.error(error); process.exit(1); }); \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_custom_auth_signed/package.json b/samples/node/mqtt/mqtt5_custom_auth_signed/package.json index 00b5969f..bbf83fb0 100644 --- a/samples/node/mqtt/mqtt5_custom_auth_signed/package.json +++ b/samples/node/mqtt/mqtt5_custom_auth_signed/package.json @@ -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 " + ], + "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" } } \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_custom_auth_signed/tsconfig.json b/samples/node/mqtt/mqtt5_custom_auth_signed/tsconfig.json new file mode 100644 index 00000000..358dbd0e --- /dev/null +++ b/samples/node/mqtt/mqtt5_custom_auth_signed/tsconfig.json @@ -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" + ] +} \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_custom_auth_unsigned/README.md b/samples/node/mqtt/mqtt5_custom_auth_unsigned/README.md index 84a1f36f..83ef3525 100644 --- a/samples/node/mqtt/mqtt5_custom_auth_unsigned/README.md +++ b/samples/node/mqtt/mqtt5_custom_auth_unsigned/README.md @@ -75,7 +75,7 @@ To Run this sample from the `samples/node/mqtt/mqtt5_custom_auth_unsigned` folde ```sh npm install -node index.js \ +node dist/index.js \ --endpoint \ --authorizer_name \ --auth_username \ @@ -83,7 +83,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: diff --git a/samples/node/mqtt/mqtt5_custom_auth_unsigned/index.js b/samples/node/mqtt/mqtt5_custom_auth_unsigned/index.ts similarity index 86% rename from samples/node/mqtt/mqtt5_custom_auth_unsigned/index.js rename to samples/node/mqtt/mqtt5_custom_auth_unsigned/index.ts index 10859e51..e0d59199 100644 --- a/samples/node/mqtt/mqtt5_custom_auth_unsigned/index.js +++ b/samples/node/mqtt/mqtt5_custom_auth_unsigned/index.ts @@ -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; @@ -77,7 +77,7 @@ async function runSample() { { authorizerName: args.authorizer_name, username: args.auth_username, - password: args.auth_password + password: Buffer.from(args.auth_password, 'utf-8') } ); @@ -90,7 +90,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`); @@ -112,17 +112,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}`); }); @@ -136,7 +136,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((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT)) ]); console.log(`==== Subscribing to topic '${args.topic}' ====`); @@ -165,9 +165,9 @@ 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(resolve => setTimeout(resolve, 1500)); publishCount++; } @@ -175,7 +175,7 @@ async function runSample() { const receivedAll = once(client, "receivedAll"); await Promise.race([ receivedAll, - new Promise(resolve => setTimeout(resolve, 5000)) + new Promise(resolve => setTimeout(resolve, 5000)) ]); } console.log(`${receivedCount} message(s) received.\n`); @@ -193,7 +193,7 @@ async function runSample() { await Promise.race([ stopped, - new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) + new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) ]); console.log("==== Client Stopped! ===="); @@ -202,7 +202,7 @@ async function runSample() { runSample().then(() => { process.exit(0); -}).catch((error) => { +}).catch((error: Error) => { console.error(error); process.exit(1); }); \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_custom_auth_unsigned/package.json b/samples/node/mqtt/mqtt5_custom_auth_unsigned/package.json index 69f37051..29875a11 100644 --- a/samples/node/mqtt/mqtt5_custom_auth_unsigned/package.json +++ b/samples/node/mqtt/mqtt5_custom_auth_unsigned/package.json @@ -2,13 +2,27 @@ "name": "mqtt5-custom-auth-unsigned-sample", "version": "1.0.0", "description": "MQTT5 Unsigned 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 " + ], + "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" } } \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_custom_auth_unsigned/tsconfig.json b/samples/node/mqtt/mqtt5_custom_auth_unsigned/tsconfig.json new file mode 100644 index 00000000..358dbd0e --- /dev/null +++ b/samples/node/mqtt/mqtt5_custom_auth_unsigned/tsconfig.json @@ -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" + ] +} \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_pkcs11/README.md b/samples/node/mqtt/mqtt5_pkcs11/README.md index 9fdef3be..50972df3 100644 --- a/samples/node/mqtt/mqtt5_pkcs11/README.md +++ b/samples/node/mqtt/mqtt5_pkcs11/README.md @@ -75,7 +75,7 @@ To Run this sample from the `samples/node/mqtt/mqtt5_pkcs11` folder, use the fol ```sh npm install -node index.js \ +node dist/index.js \ --endpoint \ --cert \ --pkcs11_lib \ @@ -83,7 +83,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: diff --git a/samples/node/mqtt/mqtt5_pkcs11/index.js b/samples/node/mqtt/mqtt5_pkcs11/index.ts similarity index 85% rename from samples/node/mqtt/mqtt5_pkcs11/index.js rename to samples/node/mqtt/mqtt5_pkcs11/index.ts index 43b08fa4..e2b65591 100644 --- a/samples/node/mqtt/mqtt5_pkcs11/index.js +++ b/samples/node/mqtt/mqtt5_pkcs11/index.ts @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0. */ -const { mqtt5, iot, io } = require("aws-iot-device-sdk-v2"); -const { once } = require("events"); -const yargs = require('yargs'); -const { v4: uuidv4 } = require('uuid'); +import { mqtt5, iot, io } from "aws-iot-device-sdk-v2"; +import { once } from "events"; +import yargs from "yargs"; +import { v4 as uuidv4 } from "uuid"; const TIMEOUT = 100000; @@ -95,11 +95,11 @@ async function runSample() { // Create MQTT5 client using PKCS#11 console.log("==== Creating MQTT5 Client ====\n"); const pkcs11Options = { - pkcs11Lib: pkcs11Lib, - userPin: args.pin, - slotId: args.slot_id, - tokenLabel: args.token_label, - privateKeyObjectLabel: args.key_label + pkcs11_lib: pkcs11Lib, + user_pin: args.pin, + slot_id: args.slot_id, + token_label: args.token_label, + private_key_object_label: args.key_label }; const builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithMtlsFromPkcs11( @@ -116,7 +116,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`); @@ -138,17 +138,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}`); }); @@ -162,7 +162,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((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT)) ]); console.log(`==== Subscribing to topic '${args.topic}' ====`); @@ -191,9 +191,9 @@ 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(resolve => setTimeout(resolve, 1500)); publishCount++; } @@ -201,7 +201,7 @@ async function runSample() { const receivedAll = once(client, "receivedAll"); await Promise.race([ receivedAll, - new Promise(resolve => setTimeout(resolve, 5000)) + new Promise(resolve => setTimeout(resolve, 5000)) ]); } console.log(`${receivedCount} message(s) received.\n`); @@ -219,7 +219,7 @@ async function runSample() { await Promise.race([ stopped, - new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) + new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) ]); console.log("==== Client Stopped! ===="); @@ -228,7 +228,7 @@ async function runSample() { runSample().then(() => { process.exit(0); -}).catch((error) => { +}).catch((error: Error) => { console.error(error); process.exit(1); }); \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_pkcs11/package.json b/samples/node/mqtt/mqtt5_pkcs11/package.json index 2765b3eb..ab185eaa 100644 --- a/samples/node/mqtt/mqtt5_pkcs11/package.json +++ b/samples/node/mqtt/mqtt5_pkcs11/package.json @@ -2,13 +2,27 @@ "name": "mqtt5-pkcs11-sample", "version": "1.0.0", "description": "MQTT5 PKCS11 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 " + ], + "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" } } \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_pkcs11/tsconfig.json b/samples/node/mqtt/mqtt5_pkcs11/tsconfig.json new file mode 100644 index 00000000..358dbd0e --- /dev/null +++ b/samples/node/mqtt/mqtt5_pkcs11/tsconfig.json @@ -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" + ] +} \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_x509/README.md b/samples/node/mqtt/mqtt5_x509/README.md index 962ca121..27953506 100644 --- a/samples/node/mqtt/mqtt5_x509/README.md +++ b/samples/node/mqtt/mqtt5_x509/README.md @@ -73,14 +73,14 @@ To Run this sample from the `samples/node/mqtt/mqtt5_x509` folder, use the follo ```sh npm install -node index.js \ +node dist/index.js \ --endpoint \ --cert \ --key ``` 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: diff --git a/samples/node/mqtt/mqtt5_x509/index.js b/samples/node/mqtt/mqtt5_x509/index.ts similarity index 86% rename from samples/node/mqtt/mqtt5_x509/index.js rename to samples/node/mqtt/mqtt5_x509/index.ts index f4f26cd2..10b35e82 100644 --- a/samples/node/mqtt/mqtt5_x509/index.js +++ b/samples/node/mqtt/mqtt5_x509/index.ts @@ -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; @@ -81,7 +81,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`); @@ -103,17 +103,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}`); }); @@ -127,7 +127,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((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), TIMEOUT)) ]); console.log(`==== Subscribing to topic '${args.topic}' ====`); @@ -156,9 +156,9 @@ 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(resolve => setTimeout(resolve, 1500)); publishCount++; } @@ -166,7 +166,7 @@ async function runSample() { const receivedAll = once(client, "receivedAll"); await Promise.race([ receivedAll, - new Promise(resolve => setTimeout(resolve, 5000)) + new Promise(resolve => setTimeout(resolve, 5000)) ]); } console.log(`${receivedCount} message(s) received.\n`); @@ -184,7 +184,7 @@ async function runSample() { await Promise.race([ stopped, - new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) + new Promise((_, reject) => setTimeout(() => reject(new Error("Stop timeout")), TIMEOUT)) ]); console.log("==== Client Stopped! ===="); @@ -193,7 +193,7 @@ async function runSample() { runSample().then(() => { process.exit(0); -}).catch((error) => { +}).catch((error: Error) => { console.error(error); process.exit(1); }); \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_x509/package.json b/samples/node/mqtt/mqtt5_x509/package.json index 778bef9b..20397fac 100644 --- a/samples/node/mqtt/mqtt5_x509/package.json +++ b/samples/node/mqtt/mqtt5_x509/package.json @@ -2,13 +2,27 @@ "name": "mqtt5-x509-sample", "version": "1.0.0", "description": "MQTT5 X509 Sample (mTLS)", - "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 " + ], + "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" } } \ No newline at end of file diff --git a/samples/node/mqtt/mqtt5_x509/tsconfig.json b/samples/node/mqtt/mqtt5_x509/tsconfig.json new file mode 100644 index 00000000..358dbd0e --- /dev/null +++ b/samples/node/mqtt/mqtt5_x509/tsconfig.json @@ -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" + ] +} \ No newline at end of file diff --git a/utils/ci-aws-doc-links.txt b/utils/ci-aws-doc-links.txt index 11167c38..75a8bd13 100644 --- a/utils/ci-aws-doc-links.txt +++ b/utils/ci-aws-doc-links.txt @@ -1,2 +1,2 @@ -samples/node/mqtt/mqtt5_x509/index.js +samples/node/mqtt/mqtt5_x509/index.ts samples/node/greengrass/basic_discovery/index.ts \ No newline at end of file