Socket
Socket
Sign inDemoInstall

aws-crt

Package Overview
Dependencies
Maintainers
4
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-crt - npm Package Compare versions

Comparing version 1.14.8 to 1.15.1

canary/mqtt5/canary.ts

7

dist.browser/browser.d.ts

@@ -5,7 +5,8 @@ import * as platform from './common/platform';

import * as mqtt from './browser/mqtt';
import * as mqtt5 from './browser/mqtt5';
import * as http from './browser/http';
import * as crypto from './browser/crypto';
import * as iot from './browser/aws_iot';
import * as iot from './browser/iot';
import * as auth from './browser/auth';
import { CrtError } from './browser/error';
export { io, mqtt, http, crypto, auth, iot, platform, resource_safety, CrtError };
import { ICrtError, CrtError } from './browser/error';
export { auth, crypto, http, io, iot, mqtt, mqtt5, platform, resource_safety, ICrtError, CrtError };

@@ -30,3 +30,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.CrtError = exports.resource_safety = exports.platform = exports.iot = exports.auth = exports.crypto = exports.http = exports.mqtt = exports.io = void 0;
exports.CrtError = exports.resource_safety = exports.platform = exports.mqtt5 = exports.mqtt = exports.iot = exports.io = exports.http = exports.crypto = exports.auth = void 0;
// This is the entry point for the browser AWS CRT shim library

@@ -43,2 +43,4 @@ /* common libs */

exports.mqtt = mqtt;
var mqtt5 = __importStar(require("./browser/mqtt5"));
exports.mqtt5 = mqtt5;
var http = __importStar(require("./browser/http"));

@@ -48,3 +50,3 @@ exports.http = http;

exports.crypto = crypto;
var iot = __importStar(require("./browser/aws_iot"));
var iot = __importStar(require("./browser/iot"));
exports.iot = iot;

@@ -51,0 +53,0 @@ var auth = __importStar(require("./browser/auth"));

@@ -9,2 +9,3 @@ /**

import { AwsSigningConfigBase } from '../common/auth';
export { AwsSigningConfigBase } from '../common/auth';
/**

@@ -11,0 +12,0 @@ * Standard AWS Credentials

@@ -5,4 +5,2 @@ /**

* @packageDocumentation
* @module aws_iot
* @mergeTarget
*/

@@ -9,0 +7,0 @@ import { CredentialsProvider } from "./auth";

@@ -35,4 +35,2 @@ "use strict";

* @packageDocumentation
* @module aws_iot
* @mergeTarget
*/

@@ -39,0 +37,0 @@ var auth_1 = require("./auth");

import { Hashable } from "../common/crypto";
export { Hashable } from "../common/crypto";
/**

@@ -3,0 +4,0 @@ * Object that allows for continuous MD5 hashing of data.

@@ -8,2 +8,4 @@ /**

*/
import { ICrtError } from "../common/error";
export { ICrtError } from "../common/error";
/**

@@ -14,4 +16,5 @@ * Represents an error thrown by the CRT browser shim

*/
export declare class CrtError extends Error {
export declare class CrtError extends Error implements ICrtError {
readonly error: any;
readonly error_name?: string;
/**

@@ -18,0 +21,0 @@ * @param error - The original error, provided for context. Could be any type, often from underlying libraries

@@ -24,9 +24,2 @@ "use strict";

/**
* Library-specific error extension type
*
* @packageDocumentation
* @module error
* @mergeTarget
*/
/**
* Represents an error thrown by the CRT browser shim

@@ -44,2 +37,3 @@ *

_this.error = error;
_this.error_name = error.toString();
return _this;

@@ -46,0 +40,0 @@ }

@@ -7,3 +7,3 @@ import * as WebsocketUtils from "./ws";

import { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill, OnMessageCallback, MqttConnectionConnected, MqttConnectionDisconnected, MqttConnectionResumed } from "../common/mqtt";
export { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill } from "../common/mqtt";
export { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill, OnMessageCallback, MqttConnectionConnected, MqttConnectionDisconnected, MqttConnectionResumed } from "../common/mqtt";
/**

@@ -10,0 +10,0 @@ * Listener signature for event emitted from an {@link MqttClientConnection} when an error occurs

@@ -108,2 +108,3 @@ "use strict";

var mqtt_1 = require("../common/mqtt");
var mqtt_shared_1 = require("../common/mqtt_shared");
var mqtt_2 = require("../common/mqtt");

@@ -189,31 +190,2 @@ Object.defineProperty(exports, "QoS", { enumerable: true, get: function () { return mqtt_2.QoS; } });

/**
* Converts payload to Buffer or string regardless of the supplied type
* @param payload The payload to convert
* @internal
*/
function normalize_payload(payload) {
if (payload instanceof Buffer) {
// pass Buffer through
return payload;
}
if (typeof payload === 'string') {
// pass string through
return payload;
}
if (ArrayBuffer.isView(payload)) {
// return Buffer with view upon the same bytes (no copy)
var view = payload;
return Buffer.from(view.buffer, view.byteOffset, view.byteLength);
}
if (payload instanceof ArrayBuffer) {
// return Buffer with view upon the same bytes (no copy)
return Buffer.from(payload);
}
if (typeof payload === 'object') {
// Convert Object to JSON string
return JSON.stringify(payload);
}
throw new TypeError("payload parameter must be a string, object, or DataView.");
}
/**
* MQTT client connection

@@ -294,3 +266,3 @@ *

topic: _this.config.will.topic,
payload: normalize_payload(_this.config.will.payload),
payload: (0, mqtt_shared_1.normalize_payload)(_this.config.will.payload),
qos: _this.config.will.qos,

@@ -402,3 +374,3 @@ retain: _this.config.will.retain,

return __generator(this, function (_a) {
payload_data = normalize_payload(payload);
payload_data = (0, mqtt_shared_1.normalize_payload)(payload);
return [2 /*return*/, new Promise(function (resolve, reject) {

@@ -405,0 +377,0 @@ _this.connection.publish(topic, payload_data, { qos: qos, retain: retain }, function (error, packet) {

@@ -9,2 +9,3 @@ /**

import { MqttConnectionConfig } from "./mqtt";
import * as mqtt5 from "./mqtt5";
import { WebsocketOptionsBase } from "../common/auth";

@@ -28,1 +29,5 @@ /**

export declare function create_websocket_stream(config: MqttConnectionConfig): any;
/** @internal */
export declare function create_mqtt5_websocket_url(config: mqtt5.Mqtt5ClientConfig): string;
/** @internal */
export declare function create_mqtt5_websocket_stream(config: mqtt5.Mqtt5ClientConfig): any;

@@ -30,5 +30,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.create_websocket_stream = exports.create_websocket_url = void 0;
exports.create_mqtt5_websocket_stream = exports.create_mqtt5_websocket_url = exports.create_websocket_stream = exports.create_websocket_url = void 0;
var mqtt5 = __importStar(require("./mqtt5"));
var error_1 = require("./error");
var websocket = require('@httptoolkit/websocket-stream');
var Crypto = __importStar(require("crypto-js"));
var iot_shared = __importStar(require("../common/aws_iot_shared"));
/** @internal */

@@ -113,2 +116,48 @@ function zero_pad(n) {

exports.create_websocket_stream = create_websocket_stream;
/** @internal */
function create_mqtt5_websocket_url(config) {
var _a, _b;
var path = '/mqtt';
var websocketConfig = (_a = config.websocketOptions) !== null && _a !== void 0 ? _a : { urlFactoryOptions: { urlFactory: mqtt5.Mqtt5WebsocketUrlFactoryType.Ws } };
var urlFactory = websocketConfig.urlFactoryOptions.urlFactory;
switch (urlFactory) {
case mqtt5.Mqtt5WebsocketUrlFactoryType.Ws:
return "ws://".concat(config.hostName, ":").concat(config.port).concat(path);
break;
case mqtt5.Mqtt5WebsocketUrlFactoryType.Wss:
return "wss://".concat(config.hostName, ":").concat(config.port).concat(path);
break;
case mqtt5.Mqtt5WebsocketUrlFactoryType.Sigv4:
var sigv4Options = websocketConfig.urlFactoryOptions;
var credentials = sigv4Options.credentialsProvider.getCredentials();
if (credentials === undefined) {
throw new error_1.CrtError("Websockets with sigv4 requires valid AWS credentials");
}
var signingConfig = {
service: "iotdevicegateway",
region: (_b = sigv4Options.region) !== null && _b !== void 0 ? _b : iot_shared.extractRegionFromEndpoint(config.hostName),
credentials: credentials,
date: new Date()
};
var time = canonical_time(signingConfig.date);
var day = canonical_day(time);
var query_params = "X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=".concat(signingConfig.credentials.aws_access_id) +
"%2F".concat(day, "%2F").concat(signingConfig.credentials.aws_region, "%2F").concat(signingConfig.service, "%2Faws4_request&X-Amz-Date=").concat(time, "&X-Amz-SignedHeaders=host");
var url = new URL("wss://".concat(config.hostName).concat(path, "?").concat(query_params));
return sign_url('GET', url, signingConfig, time, day);
case mqtt5.Mqtt5WebsocketUrlFactoryType.Custom:
var customOptions = websocketConfig.urlFactoryOptions;
return customOptions.customUrlFactory();
}
throw new URIError("Invalid url factory requested: ".concat(urlFactory));
}
exports.create_mqtt5_websocket_url = create_mqtt5_websocket_url;
/** @internal */
function create_mqtt5_websocket_stream(config) {
var _a;
var url = create_mqtt5_websocket_url(config);
var ws = websocket(url, ['mqtt'], (_a = config.websocketOptions) === null || _a === void 0 ? void 0 : _a.wsOptions);
return ws;
}
exports.create_mqtt5_websocket_stream = create_mqtt5_websocket_stream;
//# sourceMappingURL=ws.js.map

@@ -0,9 +1,3 @@

import * as mqtt5_packet from "./mqtt5_packet";
/**
*
* A module containing miscellaneous functionality that is shared across both native and browser for aws_iot
*
* @packageDocumentation
* @module aws_iot
*/
/**
* A helper function to add parameters to the username in with_custom_authorizer function

@@ -32,1 +26,73 @@ *

export declare function populate_username_string_with_custom_authorizer(current_username?: string, input_username?: string, input_authorizer?: string, input_signature?: string, input_builder_username?: string): string;
/**
* Configuration options specific to
* [AWS IoT Core custom authentication](https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html)
* features. For clients constructed by an {@link AwsIotMqtt5ClientConfigBuilder}, all parameters associated
* with AWS IoT custom authentication are passed via the username and password properties in the CONNECT packet.
*/
export interface MqttConnectCustomAuthConfig {
/**
* Name of the custom authorizer to use.
*
* Required if the endpoint does not have a default custom authorizer associated with it. It is strongly suggested
* to URL-encode this value; the SDK will not do so for you.
*/
authorizerName?: string;
/**
* The username to use with the custom authorizer. Query-string elements of this property value will be unioned
* with the query-string elements implied by other properties in this object.
*
* For example, if you set this to:
*
* 'MyUsername?someKey=someValue'
*
* and use {@link authorizerName} to specify the authorizer, the final username would look like:
*
* `MyUsername?someKey=someValue&x-amz-customauthorizer-name=<your authorizer's name>&...`
*/
username?: string;
/**
* The password to use with the custom authorizer. Becomes the MQTT5 CONNECT packet's password property.
* AWS IoT Core will base64 encode this binary data before passing it to the authorizer's lambda function.
*/
password?: mqtt5_packet.BinaryData;
/**
* Key used to extract the custom authorizer token from MQTT username query-string properties.
*
* Required if the custom authorizer has signing enabled. It is strongly suggested to URL-encode this value; the
* SDK will not do so for you.
*/
tokenKeyName?: string;
/**
* An opaque token value. This value must be signed by the private key associated with the custom authorizer and
* the result placed in the {@link tokenSignature} property.
*
* Required if the custom authorizer has signing enabled.
*/
tokenValue?: string;
/**
* The digital signature of the token value in the {@link tokenValue} property. The signature must be based on
* the private key associated with the custom authorizer. The signature must be base64 encoded.
*
* Required if the custom authorizer has signing enabled. It is strongly suggested to URL-encode this value; the
* SDK will not do so for you.
*/
tokenSignature?: string;
}
/**
* Builds the final value for the CONNECT packet's username property based on AWS IoT custom auth configuration
* and SDK metrics properties.
*
* @param customAuthConfig intended AWS IoT custom auth client configuration
*
* @internal
*/
export declare function buildMqtt5FinalUsername(customAuthConfig?: MqttConnectCustomAuthConfig): string;
/**
* Attempts to determine the AWS region associated with an endpoint.
*
* @param endpoint endpoint to compute the region for
*
* @internal
*/
export declare function extractRegionFromEndpoint(endpoint: string): string;

@@ -6,4 +6,27 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.populate_username_string_with_custom_authorizer = exports.is_string_and_not_empty = exports.add_to_username_parameter = void 0;
exports.extractRegionFromEndpoint = exports.buildMqtt5FinalUsername = exports.populate_username_string_with_custom_authorizer = exports.is_string_and_not_empty = exports.add_to_username_parameter = void 0;
/**

@@ -16,2 +39,3 @@ *

*/
var platform = __importStar(require("./platform"));
/**

@@ -80,2 +104,71 @@ * A helper function to add parameters to the username in with_custom_authorizer function

exports.populate_username_string_with_custom_authorizer = populate_username_string_with_custom_authorizer;
;
/** @internal */
function addParam(paramName, paramValue, paramSet) {
if (paramValue) {
paramSet.push([paramName, paramValue]);
}
}
/**
* Builds the final value for the CONNECT packet's username property based on AWS IoT custom auth configuration
* and SDK metrics properties.
*
* @param customAuthConfig intended AWS IoT custom auth client configuration
*
* @internal
*/
function buildMqtt5FinalUsername(customAuthConfig) {
var path = "";
var paramList = [];
if (customAuthConfig) {
/* If we're using token-signing authentication, then all token properties must be set */
var usingSigning = false;
if (customAuthConfig.tokenValue || customAuthConfig.tokenKeyName || customAuthConfig.tokenSignature) {
usingSigning = true;
if (!customAuthConfig.tokenValue || !customAuthConfig.tokenKeyName || !customAuthConfig.tokenSignature) {
throw new Error("Token-based custom authentication requires all token-related properties to be set");
}
}
var username = customAuthConfig.username;
var pathSplit = (username !== null && username !== void 0 ? username : "").split("?");
var params = pathSplit.slice(1);
path = pathSplit[0];
if (params.length > 1) {
throw new Error("Custom auth username property value is invalid");
}
else if (params.length == 1) {
params[0].split("&").forEach(function (keyValue, index, array) {
var _a;
var kvPair = keyValue.split("=");
paramList.push([kvPair[0], (_a = kvPair[1]) !== null && _a !== void 0 ? _a : ""]);
});
}
addParam("x-amz-customauthorizer-name", customAuthConfig.authorizerName, paramList);
if (usingSigning) {
// @ts-ignore verified earlier
addParam(customAuthConfig.tokenKeyName, customAuthConfig.tokenValue, paramList);
addParam("x-amz-customauthorizer-signature", customAuthConfig.tokenSignature, paramList);
}
}
paramList.push(["SDK", "NodeJSv2"]);
paramList.push(["Version", platform.crt_version()]);
return (path !== null && path !== void 0 ? path : "") + "?" + paramList.map(function (value) { return "".concat(value[0], "=").concat(value[1]); }).join("&");
}
exports.buildMqtt5FinalUsername = buildMqtt5FinalUsername;
/**
* Attempts to determine the AWS region associated with an endpoint.
*
* @param endpoint endpoint to compute the region for
*
* @internal
*/
function extractRegionFromEndpoint(endpoint) {
var regexpRegion = /^[\w\-]+\.[\w\-]+\.([\w+\-]+)\./;
var match = endpoint.match(regexpRegion);
if (match) {
return match[1];
}
throw new Error("AWS region could not be extracted from endpoint. Use 'region' property on WebsocketConfig to set manually.");
}
exports.extractRegionFromEndpoint = extractRegionFromEndpoint;
//# sourceMappingURL=aws_iot_shared.js.map

@@ -0,9 +1,3 @@

import * as mqtt5_packet from "./mqtt5_packet";
/**
*
* A module containing miscellaneous functionality that is shared across both native and browser for aws_iot
*
* @packageDocumentation
* @module aws_iot
*/
/**
* A helper function to add parameters to the username in with_custom_authorizer function

@@ -32,1 +26,73 @@ *

export declare function populate_username_string_with_custom_authorizer(current_username?: string, input_username?: string, input_authorizer?: string, input_signature?: string, input_builder_username?: string): string;
/**
* Configuration options specific to
* [AWS IoT Core custom authentication](https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html)
* features. For clients constructed by an {@link AwsIotMqtt5ClientConfigBuilder}, all parameters associated
* with AWS IoT custom authentication are passed via the username and password properties in the CONNECT packet.
*/
export interface MqttConnectCustomAuthConfig {
/**
* Name of the custom authorizer to use.
*
* Required if the endpoint does not have a default custom authorizer associated with it. It is strongly suggested
* to URL-encode this value; the SDK will not do so for you.
*/
authorizerName?: string;
/**
* The username to use with the custom authorizer. Query-string elements of this property value will be unioned
* with the query-string elements implied by other properties in this object.
*
* For example, if you set this to:
*
* 'MyUsername?someKey=someValue'
*
* and use {@link authorizerName} to specify the authorizer, the final username would look like:
*
* `MyUsername?someKey=someValue&x-amz-customauthorizer-name=<your authorizer's name>&...`
*/
username?: string;
/**
* The password to use with the custom authorizer. Becomes the MQTT5 CONNECT packet's password property.
* AWS IoT Core will base64 encode this binary data before passing it to the authorizer's lambda function.
*/
password?: mqtt5_packet.BinaryData;
/**
* Key used to extract the custom authorizer token from MQTT username query-string properties.
*
* Required if the custom authorizer has signing enabled. It is strongly suggested to URL-encode this value; the
* SDK will not do so for you.
*/
tokenKeyName?: string;
/**
* An opaque token value. This value must be signed by the private key associated with the custom authorizer and
* the result placed in the {@link tokenSignature} property.
*
* Required if the custom authorizer has signing enabled.
*/
tokenValue?: string;
/**
* The digital signature of the token value in the {@link tokenValue} property. The signature must be based on
* the private key associated with the custom authorizer. The signature must be base64 encoded.
*
* Required if the custom authorizer has signing enabled. It is strongly suggested to URL-encode this value; the
* SDK will not do so for you.
*/
tokenSignature?: string;
}
/**
* Builds the final value for the CONNECT packet's username property based on AWS IoT custom auth configuration
* and SDK metrics properties.
*
* @param customAuthConfig intended AWS IoT custom auth client configuration
*
* @internal
*/
export declare function buildMqtt5FinalUsername(customAuthConfig?: MqttConnectCustomAuthConfig): string;
/**
* Attempts to determine the AWS region associated with an endpoint.
*
* @param endpoint endpoint to compute the region for
*
* @internal
*/
export declare function extractRegionFromEndpoint(endpoint: string): string;

@@ -6,4 +6,27 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.populate_username_string_with_custom_authorizer = exports.is_string_and_not_empty = exports.add_to_username_parameter = void 0;
exports.extractRegionFromEndpoint = exports.buildMqtt5FinalUsername = exports.populate_username_string_with_custom_authorizer = exports.is_string_and_not_empty = exports.add_to_username_parameter = void 0;
/**

@@ -16,2 +39,3 @@ *

*/
const platform = __importStar(require("./platform"));
/**

@@ -80,2 +104,71 @@ * A helper function to add parameters to the username in with_custom_authorizer function

exports.populate_username_string_with_custom_authorizer = populate_username_string_with_custom_authorizer;
;
/** @internal */
function addParam(paramName, paramValue, paramSet) {
if (paramValue) {
paramSet.push([paramName, paramValue]);
}
}
/**
* Builds the final value for the CONNECT packet's username property based on AWS IoT custom auth configuration
* and SDK metrics properties.
*
* @param customAuthConfig intended AWS IoT custom auth client configuration
*
* @internal
*/
function buildMqtt5FinalUsername(customAuthConfig) {
let path = "";
let paramList = [];
if (customAuthConfig) {
/* If we're using token-signing authentication, then all token properties must be set */
let usingSigning = false;
if (customAuthConfig.tokenValue || customAuthConfig.tokenKeyName || customAuthConfig.tokenSignature) {
usingSigning = true;
if (!customAuthConfig.tokenValue || !customAuthConfig.tokenKeyName || !customAuthConfig.tokenSignature) {
throw new Error("Token-based custom authentication requires all token-related properties to be set");
}
}
let username = customAuthConfig.username;
let pathSplit = (username !== null && username !== void 0 ? username : "").split("?");
let params = pathSplit.slice(1);
path = pathSplit[0];
if (params.length > 1) {
throw new Error("Custom auth username property value is invalid");
}
else if (params.length == 1) {
params[0].split("&").forEach((keyValue, index, array) => {
var _a;
let kvPair = keyValue.split("=");
paramList.push([kvPair[0], (_a = kvPair[1]) !== null && _a !== void 0 ? _a : ""]);
});
}
addParam("x-amz-customauthorizer-name", customAuthConfig.authorizerName, paramList);
if (usingSigning) {
// @ts-ignore verified earlier
addParam(customAuthConfig.tokenKeyName, customAuthConfig.tokenValue, paramList);
addParam("x-amz-customauthorizer-signature", customAuthConfig.tokenSignature, paramList);
}
}
paramList.push(["SDK", "NodeJSv2"]);
paramList.push(["Version", platform.crt_version()]);
return (path !== null && path !== void 0 ? path : "") + "?" + paramList.map((value) => `${value[0]}=${value[1]}`).join("&");
}
exports.buildMqtt5FinalUsername = buildMqtt5FinalUsername;
/**
* Attempts to determine the AWS region associated with an endpoint.
*
* @param endpoint endpoint to compute the region for
*
* @internal
*/
function extractRegionFromEndpoint(endpoint) {
const regexpRegion = /^[\w\-]+\.[\w\-]+\.([\w+\-]+)\./;
const match = endpoint.match(regexpRegion);
if (match) {
return match[1];
}
throw new Error("AWS region could not be extracted from endpoint. Use 'region' property on WebsocketConfig to set manually.");
}
exports.extractRegionFromEndpoint = extractRegionFromEndpoint;
//# sourceMappingURL=aws_iot_shared.js.map
import * as platform from './common/platform';
import * as resource_safety from './common/resource_safety';
import * as auth from './native/auth';
import * as checksums from './native/checksums';
import * as crt from './native/crt';
import * as crypto from './native/crypto';
import * as http from './native/http';
import * as io from './native/io';
import * as iot from './native/iot';
import * as mqtt from './native/mqtt';
import * as http from './native/http';
import * as crypto from './native/crypto';
import * as auth from './native/auth';
import * as iot from './native/aws_iot';
import * as checksums from './native/checksums';
import { CrtError } from './native/error';
export { crt, io, mqtt, http, crypto, auth, iot, platform, resource_safety, checksums, CrtError };
import * as mqtt5 from './native/mqtt5';
import { ICrtError, CrtError } from './native/error';
export { auth, checksums, crypto, crt, http, io, iot, mqtt, mqtt5, platform, resource_safety, ICrtError, CrtError };

@@ -30,3 +30,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.CrtError = exports.checksums = exports.resource_safety = exports.platform = exports.iot = exports.auth = exports.crypto = exports.http = exports.mqtt = exports.io = exports.crt = void 0;
exports.CrtError = exports.resource_safety = exports.platform = exports.mqtt5 = exports.mqtt = exports.iot = exports.io = exports.http = exports.crt = exports.crypto = exports.checksums = exports.auth = void 0;
// This is the entry point for the AWS CRT nodejs native libraries

@@ -39,20 +39,22 @@ /* common libs */

/* node specific libs */
const auth = __importStar(require("./native/auth"));
exports.auth = auth;
const checksums = __importStar(require("./native/checksums"));
exports.checksums = checksums;
const crt = __importStar(require("./native/crt"));
exports.crt = crt;
const crypto = __importStar(require("./native/crypto"));
exports.crypto = crypto;
const http = __importStar(require("./native/http"));
exports.http = http;
const io = __importStar(require("./native/io"));
exports.io = io;
const iot = __importStar(require("./native/iot"));
exports.iot = iot;
const mqtt = __importStar(require("./native/mqtt"));
exports.mqtt = mqtt;
const http = __importStar(require("./native/http"));
exports.http = http;
const crypto = __importStar(require("./native/crypto"));
exports.crypto = crypto;
const auth = __importStar(require("./native/auth"));
exports.auth = auth;
const iot = __importStar(require("./native/aws_iot"));
exports.iot = iot;
const checksums = __importStar(require("./native/checksums"));
exports.checksums = checksums;
const mqtt5 = __importStar(require("./native/mqtt5"));
exports.mqtt5 = mqtt5;
const error_1 = require("./native/error");
Object.defineProperty(exports, "CrtError", { enumerable: true, get: function () { return error_1.CrtError; } });
//# sourceMappingURL=index.js.map

@@ -12,2 +12,3 @@ /**

import { ClientBootstrap, ClientTlsContext } from './io';
export { AwsSigningConfigBase } from "../common/auth";
/**

@@ -14,0 +15,0 @@ * A pair defining an identity provider and a valid login token sourced from it.

@@ -5,4 +5,2 @@ /**

* @packageDocumentation
* @module aws_iot
* @mergeTarget
*/

@@ -9,0 +7,0 @@ import { MqttConnectionConfig, MqttWill } from "./mqtt";

@@ -17,3 +17,7 @@ /*

import { OnMessageCallback, QoS } from "../common/mqtt";
import { Mqtt5ClientConfig, Mqtt5Client, ClientStatistics, NegotiatedSettings } from "./mqtt5";
import * as mqtt5_packet from "../common/mqtt5_packet";
import { PublishCompletionResult } from "../common/mqtt5";
/**

@@ -139,2 +143,41 @@ * Type used to store pointers to CRT native resources

/* MQTT5 Client */
/** @internal */
export function mqtt5_client_new(
client: Mqtt5Client,
config: Mqtt5ClientConfig,
on_stopped_event_handler: (client: Mqtt5Client) => void,
on_attempt_connect_handler: (client: Mqtt5Client) => void,
on_connection_success_handler: (client: Mqtt5Client, connack: mqtt5_packet.ConnackPacket, settings: NegotiatedSettings) => void,
on_connection_failure_handler: (client: Mqtt5Client, errorCode: number, connack?: mqtt5_packet.ConnackPacket) => void,
on_disconnection_handler: (client: Mqtt5Client, errorCode: number, disconnect?: mqtt5_packet.DisconnectPacket) => void,
on_message_received_handler: (client: Mqtt5Client, message: mqtt5_packet.PublishPacket) => void,
client_bootstrap?: NativeHandle,
socket_options?: NativeHandle,
tls_ctx?: NativeHandle,
proxy_options?: NativeHandle,
): NativeHandle;
/** @internal */
export function mqtt5_client_start(client: NativeHandle) : void;
/** @internal */
export function mqtt5_client_stop(client: NativeHandle, disconnect_packet?: mqtt5_packet.DisconnectPacket) : void;
/** @internal */
export function mqtt5_client_subscribe(client: NativeHandle, subscribe_packet: mqtt5_packet.SubscribePacket, on_resolution: (client: Mqtt5Client, errorCode: number, suback?: mqtt5_packet.SubackPacket) => void) : void;
/** @internal */
export function mqtt5_client_unsubscribe(client: NativeHandle, unsubscribe_packet: mqtt5_packet.UnsubscribePacket, on_resolution: (client: Mqtt5Client, errorCode: number, unsuback?: mqtt5_packet.UnsubackPacket) => void) : void;
/** @internal */
export function mqtt5_client_publish(client: NativeHandle, publish_packet: mqtt5_packet.PublishPacket, on_resolution: (client: Mqtt5Client, errorCode: number, result: PublishCompletionResult) => void) : void;
/** @internal */
export function mqtt5_client_get_queue_statistics(client: NativeHandle) : ClientStatistics;
/** @internal */
export function mqtt5_client_close(client: NativeHandle) : void;
/* MQTT Client */

@@ -141,0 +184,0 @@ /** @internal */

import { NativeResource } from "./native_resource";
import { Hashable } from "../common/crypto";
export { Hashable } from "../common/crypto";
/**

@@ -115,2 +116,1 @@ * Object that allows for continuous hashing of data.

export declare function hmac_sha256(secret: Hashable, data: Hashable, truncate_to?: number): DataView;
export {};

@@ -0,1 +1,3 @@

import { ICrtError } from "../common/error";
export { ICrtError } from "../common/error";
/**

@@ -7,3 +9,3 @@ * Represents an error encountered in native code. Can also be used to convert a numeric error code into

*/
export declare class CrtError extends Error {
export declare class CrtError extends Error implements ICrtError {
readonly error: any;

@@ -10,0 +12,0 @@ /** The original integer error code from the CRT */

@@ -8,3 +8,3 @@ import { NativeResource } from "./native_resource";

import { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill, OnMessageCallback, MqttConnectionConnected, MqttConnectionDisconnected, MqttConnectionResumed } from "../common/mqtt";
export { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill, OnMessageCallback } from "../common/mqtt";
export { QoS, Payload, MqttRequest, MqttSubscribeRequest, MqttWill, OnMessageCallback, MqttConnectionConnected, MqttConnectionDisconnected, MqttConnectionResumed } from "../common/mqtt";
/**

@@ -11,0 +11,0 @@ * Listener signature for event emitted from an {@link MqttClientConnection} when an error occurs

@@ -54,2 +54,3 @@ "use strict";

const event_1 = require("../common/event");
const crt = __importStar(require("../common/mqtt_shared"));
const error_1 = require("./error");

@@ -87,22 +88,2 @@ const io = __importStar(require("./io"));

exports.MqttClient = MqttClient;
/** @internal */
function normalize_payload(payload) {
if (ArrayBuffer.isView(payload)) {
// native can use ArrayBufferView bytes directly
return payload;
}
if (payload instanceof ArrayBuffer) {
// native can use ArrayBuffer bytes directly
return payload;
}
if (typeof payload === 'string') {
// native will convert string to utf-8
return payload;
}
if (typeof payload === 'object') {
// convert object to JSON string (which will be converted to utf-8 in native)
return JSON.stringify(payload);
}
throw new TypeError("payload parameter must be a string, object, or DataView.");
}
/**

@@ -127,3 +108,3 @@ * MQTT client connection

qos: config.will.qos,
payload: normalize_payload(config.will.payload),
payload: crt.normalize_payload(config.will.payload),
retain: config.will.retain

@@ -135,3 +116,3 @@ }

var max_sec = mqtt_1.DEFAULT_RECONNECT_MAX_SEC;
if (config.reconnect_min_sec !== undefined) {
if (config.reconnect_min_sec) {
min_sec = config.reconnect_min_sec;

@@ -141,3 +122,3 @@ // clamp max, in case they only passed in min

}
if (config.reconnect_max_sec !== undefined) {
if (config.reconnect_max_sec) {
max_sec = config.reconnect_max_sec;

@@ -230,3 +211,3 @@ // clamp min, in case they only passed in max (or passed in min > max)

try {
binding_1.default.mqtt_client_connection_publish(this.native_handle(), topic, normalize_payload(payload), qos, retain, this._on_puback_callback.bind(this, resolve, reject));
binding_1.default.mqtt_client_connection_publish(this.native_handle(), topic, crt.normalize_payload(payload), qos, retain, this._on_puback_callback.bind(this, resolve, reject));
}

@@ -233,0 +214,0 @@ catch (e) {

{
"name": "aws-crt",
"version": "1.14.8",
"version": "1.15.1",
"description": "NodeJS/browser bindings to the aws-c-* libraries",

@@ -37,2 +37,3 @@ "homepage": "https://github.com/awslabs/aws-crt-nodejs",

"aws-sdk": "^2.848.0",
"https-proxy-agent": "^5.0.1",
"jest": "^27.2.1",

@@ -47,3 +48,5 @@ "jest-puppeteer": "^5.0.4",

"uuid": "^8.3.2",
"yargs": "^17.2.1"
"yargs": "^17.2.1",
"cmake-js": "^6.3.2",
"tar": "^6.1.11"
},

@@ -50,0 +53,0 @@ "dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc