@aws-amplify/pubsub
Version:
Pubsub category of aws-amplify
56 lines (54 loc) • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AWSIoT = void 0;
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
const utils_1 = require("@aws-amplify/core/internals/utils");
const core_1 = require("@aws-amplify/core");
const MqttOverWS_1 = require("./MqttOverWS");
const SERVICE_NAME = 'iotdevicegateway';
class AWSIoT extends MqttOverWS_1.MqttOverWS {
constructor(ctxOrOptions, maybeOptions) {
if ((0, core_1.isAmplifyContext)(ctxOrOptions)) {
super(maybeOptions ?? {});
this._resolveCtx = (0, utils_1.createCtxResolver)(ctxOrOptions);
}
else {
// When a second argument is supplied the caller used the
// `(ctx, options)` overload, so the first argument is required to be a
// branded AmplifyContext. Guard against a defined-but-unbranded value
// being silently swallowed as `options`. In the single-argument form
// `ctxOrOptions` is legitimately the options object, so no assertion.
if (maybeOptions !== undefined) {
(0, utils_1.assertOptionalCtxArg)(ctxOrOptions);
}
// `ctxOrOptions` reaching this branch is either the single-argument
// options object or `undefined`. In the `(undefined, options)` form the
// caller omitted the context but still supplied options in the second
// slot, so fall back to `maybeOptions` rather than discarding it.
super(ctxOrOptions ?? maybeOptions ?? {});
this._resolveCtx = (0, utils_1.createCtxResolver)();
}
}
get region() {
return this.options?.region;
}
get endpoint() {
return (async () => {
const { endpoint } = this.options;
const serviceInfo = {
service: SERVICE_NAME,
region: this.region,
};
const session = await this._resolveCtx().fetchAuthSession();
if (!session.credentials) {
throw new Error('No auth session credentials');
}
const { accessKeyId: access_key, secretAccessKey: secret_key, sessionToken: session_token, } = session.credentials;
const result = utils_1.Signer.signUrl(endpoint, { access_key, secret_key, session_token }, serviceInfo);
return result;
})();
}
}
exports.AWSIoT = AWSIoT;
//# sourceMappingURL=AWSIot.js.map