1 | import { Signer } from '@aws-amplify/core/internals/utils';
|
2 | import { fetchAuthSession } from '@aws-amplify/core';
|
3 | import { MqttOverWS } from './MqttOverWS.mjs';
|
4 |
|
5 |
|
6 |
|
7 | const SERVICE_NAME = 'iotdevicegateway';
|
8 | class 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 |
|
33 | export { AWSIoT };
|
34 |
|