UNPKG

1.21 kBJavaScriptView Raw
1import { Signer } from '@aws-amplify/core/internals/utils';
2import { fetchAuthSession } from '@aws-amplify/core';
3import { MqttOverWS } from './MqttOverWS.mjs';
4
5// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6// SPDX-License-Identifier: Apache-2.0
7const SERVICE_NAME = 'iotdevicegateway';
8class AWSIoT extends MqttOverWS {
9 constructor(options = {}) {
10 super(options);
11 }
12 get region() {
13 return this.options?.region;
14 }
15 get endpoint() {
16 return (async () => {
17 const { endpoint } = this.options;
18 const serviceInfo = {
19 service: SERVICE_NAME,
20 region: this.region,
21 };
22 const session = await fetchAuthSession();
23 if (!session.credentials) {
24 throw new Error('No auth session credentials');
25 }
26 const { accessKeyId: access_key, secretAccessKey: secret_key, sessionToken: session_token, } = session.credentials;
27 const result = Signer.signUrl(endpoint, { access_key, secret_key, session_token }, serviceInfo);
28 return result;
29 })();
30 }
31}
32
33export { AWSIoT };
34//# sourceMappingURL=AWSIot.mjs.map