hume 0.8.1-beta4 → 0.8.1-beta5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wrapper/fetchAccessToken.d.ts +23 -0
- package/dist/wrapper/fetchAccessToken.js +51 -0
- package/dist/wrapper/index.d.ts +1 -0
- package/dist/wrapper/index.js +3 -1
- package/package.json +1 -1
- package/wrapper/fetchAccessToken.d.ts +23 -0
- package/wrapper/fetchAccessToken.js +51 -0
- package/wrapper/index.d.ts +1 -0
- package/wrapper/index.js +3 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches a new access token from the Hume API using the provided API key and Secret key.
|
|
3
|
+
*
|
|
4
|
+
* @param args - The arguments for the request.
|
|
5
|
+
* @returns Promise that resolves to the new access token.
|
|
6
|
+
* @throws If the base64 encoding fails.
|
|
7
|
+
* @throws If the network request fails.
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* async function getToken() {
|
|
11
|
+
* const accessToken = await fetchAccessToken({
|
|
12
|
+
* apiKey: 'test',
|
|
13
|
+
* secretKey: 'test',
|
|
14
|
+
* });
|
|
15
|
+
* console.log(accessToken); // Outputs the access token
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const fetchAccessToken: (args: {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
secretKey: string;
|
|
22
|
+
host?: string;
|
|
23
|
+
}) => Promise<string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fetchAccessToken = void 0;
|
|
13
|
+
const base64Encode_1 = require("./base64Encode");
|
|
14
|
+
/**
|
|
15
|
+
* Fetches a new access token from the Hume API using the provided API key and Secret key.
|
|
16
|
+
*
|
|
17
|
+
* @param args - The arguments for the request.
|
|
18
|
+
* @returns Promise that resolves to the new access token.
|
|
19
|
+
* @throws If the base64 encoding fails.
|
|
20
|
+
* @throws If the network request fails.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* async function getToken() {
|
|
24
|
+
* const accessToken = await fetchAccessToken({
|
|
25
|
+
* apiKey: 'test',
|
|
26
|
+
* secretKey: 'test',
|
|
27
|
+
* });
|
|
28
|
+
* console.log(accessToken); // Outputs the access token
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const fetchAccessToken = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const { apiKey, secretKey, host = 'api.hume.ai' } = args;
|
|
34
|
+
const authString = `${apiKey}:${secretKey}`;
|
|
35
|
+
const encoded = (0, base64Encode_1.base64Encode)(authString);
|
|
36
|
+
const res = yield fetch(`https://${host}/oauth2-cc/token`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers: {
|
|
39
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
40
|
+
Authorization: `Basic ${encoded}`,
|
|
41
|
+
},
|
|
42
|
+
body: new URLSearchParams({
|
|
43
|
+
grant_type: 'client_credentials',
|
|
44
|
+
}).toString(),
|
|
45
|
+
cache: 'no-cache',
|
|
46
|
+
});
|
|
47
|
+
const data = (yield res.json());
|
|
48
|
+
const accessToken = String(data['access_token']);
|
|
49
|
+
return accessToken;
|
|
50
|
+
});
|
|
51
|
+
exports.fetchAccessToken = fetchAccessToken;
|
package/dist/wrapper/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { convertBase64ToBlob } from "./convertBase64ToBlob";
|
|
|
4
4
|
export { convertBlobToBase64 } from "./convertBlobToBase64";
|
|
5
5
|
export { ensureSingleValidAudioTrack } from "./ensureSingleValidAudioTrack";
|
|
6
6
|
export { checkForAudioTracks } from "./checkForAudioTracks";
|
|
7
|
+
export { fetchAccessToken } from "./fetchAccessToken";
|
|
7
8
|
export { getAudioStream } from "./getAudioStream";
|
|
8
9
|
export { MimeType, getBrowserSupportedMimeType } from "./getBrowserSupportedMimeType";
|
|
9
10
|
export { HumeClient } from "./HumeClient";
|
package/dist/wrapper/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
|
|
3
|
+
exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.fetchAccessToken = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
|
|
4
4
|
var base64Decode_1 = require("./base64Decode");
|
|
5
5
|
Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64Decode_1.base64Decode; } });
|
|
6
6
|
var base64Encode_1 = require("./base64Encode");
|
|
@@ -13,6 +13,8 @@ var ensureSingleValidAudioTrack_1 = require("./ensureSingleValidAudioTrack");
|
|
|
13
13
|
Object.defineProperty(exports, "ensureSingleValidAudioTrack", { enumerable: true, get: function () { return ensureSingleValidAudioTrack_1.ensureSingleValidAudioTrack; } });
|
|
14
14
|
var checkForAudioTracks_1 = require("./checkForAudioTracks");
|
|
15
15
|
Object.defineProperty(exports, "checkForAudioTracks", { enumerable: true, get: function () { return checkForAudioTracks_1.checkForAudioTracks; } });
|
|
16
|
+
var fetchAccessToken_1 = require("./fetchAccessToken");
|
|
17
|
+
Object.defineProperty(exports, "fetchAccessToken", { enumerable: true, get: function () { return fetchAccessToken_1.fetchAccessToken; } });
|
|
16
18
|
var getAudioStream_1 = require("./getAudioStream");
|
|
17
19
|
Object.defineProperty(exports, "getAudioStream", { enumerable: true, get: function () { return getAudioStream_1.getAudioStream; } });
|
|
18
20
|
var getBrowserSupportedMimeType_1 = require("./getBrowserSupportedMimeType");
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches a new access token from the Hume API using the provided API key and Secret key.
|
|
3
|
+
*
|
|
4
|
+
* @param args - The arguments for the request.
|
|
5
|
+
* @returns Promise that resolves to the new access token.
|
|
6
|
+
* @throws If the base64 encoding fails.
|
|
7
|
+
* @throws If the network request fails.
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* async function getToken() {
|
|
11
|
+
* const accessToken = await fetchAccessToken({
|
|
12
|
+
* apiKey: 'test',
|
|
13
|
+
* secretKey: 'test',
|
|
14
|
+
* });
|
|
15
|
+
* console.log(accessToken); // Outputs the access token
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const fetchAccessToken: (args: {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
secretKey: string;
|
|
22
|
+
host?: string;
|
|
23
|
+
}) => Promise<string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fetchAccessToken = void 0;
|
|
13
|
+
const base64Encode_1 = require("./base64Encode");
|
|
14
|
+
/**
|
|
15
|
+
* Fetches a new access token from the Hume API using the provided API key and Secret key.
|
|
16
|
+
*
|
|
17
|
+
* @param args - The arguments for the request.
|
|
18
|
+
* @returns Promise that resolves to the new access token.
|
|
19
|
+
* @throws If the base64 encoding fails.
|
|
20
|
+
* @throws If the network request fails.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* async function getToken() {
|
|
24
|
+
* const accessToken = await fetchAccessToken({
|
|
25
|
+
* apiKey: 'test',
|
|
26
|
+
* secretKey: 'test',
|
|
27
|
+
* });
|
|
28
|
+
* console.log(accessToken); // Outputs the access token
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const fetchAccessToken = (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const { apiKey, secretKey, host = 'api.hume.ai' } = args;
|
|
34
|
+
const authString = `${apiKey}:${secretKey}`;
|
|
35
|
+
const encoded = (0, base64Encode_1.base64Encode)(authString);
|
|
36
|
+
const res = yield fetch(`https://${host}/oauth2-cc/token`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers: {
|
|
39
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
40
|
+
Authorization: `Basic ${encoded}`,
|
|
41
|
+
},
|
|
42
|
+
body: new URLSearchParams({
|
|
43
|
+
grant_type: 'client_credentials',
|
|
44
|
+
}).toString(),
|
|
45
|
+
cache: 'no-cache',
|
|
46
|
+
});
|
|
47
|
+
const data = (yield res.json());
|
|
48
|
+
const accessToken = String(data['access_token']);
|
|
49
|
+
return accessToken;
|
|
50
|
+
});
|
|
51
|
+
exports.fetchAccessToken = fetchAccessToken;
|
package/wrapper/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { convertBase64ToBlob } from "./convertBase64ToBlob";
|
|
|
4
4
|
export { convertBlobToBase64 } from "./convertBlobToBase64";
|
|
5
5
|
export { ensureSingleValidAudioTrack } from "./ensureSingleValidAudioTrack";
|
|
6
6
|
export { checkForAudioTracks } from "./checkForAudioTracks";
|
|
7
|
+
export { fetchAccessToken } from "./fetchAccessToken";
|
|
7
8
|
export { getAudioStream } from "./getAudioStream";
|
|
8
9
|
export { MimeType, getBrowserSupportedMimeType } from "./getBrowserSupportedMimeType";
|
|
9
10
|
export { HumeClient } from "./HumeClient";
|
package/wrapper/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
|
|
3
|
+
exports.HumeClient = exports.getBrowserSupportedMimeType = exports.MimeType = exports.getAudioStream = exports.fetchAccessToken = exports.checkForAudioTracks = exports.ensureSingleValidAudioTrack = exports.convertBlobToBase64 = exports.convertBase64ToBlob = exports.base64Encode = exports.base64Decode = void 0;
|
|
4
4
|
var base64Decode_1 = require("./base64Decode");
|
|
5
5
|
Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64Decode_1.base64Decode; } });
|
|
6
6
|
var base64Encode_1 = require("./base64Encode");
|
|
@@ -13,6 +13,8 @@ var ensureSingleValidAudioTrack_1 = require("./ensureSingleValidAudioTrack");
|
|
|
13
13
|
Object.defineProperty(exports, "ensureSingleValidAudioTrack", { enumerable: true, get: function () { return ensureSingleValidAudioTrack_1.ensureSingleValidAudioTrack; } });
|
|
14
14
|
var checkForAudioTracks_1 = require("./checkForAudioTracks");
|
|
15
15
|
Object.defineProperty(exports, "checkForAudioTracks", { enumerable: true, get: function () { return checkForAudioTracks_1.checkForAudioTracks; } });
|
|
16
|
+
var fetchAccessToken_1 = require("./fetchAccessToken");
|
|
17
|
+
Object.defineProperty(exports, "fetchAccessToken", { enumerable: true, get: function () { return fetchAccessToken_1.fetchAccessToken; } });
|
|
16
18
|
var getAudioStream_1 = require("./getAudioStream");
|
|
17
19
|
Object.defineProperty(exports, "getAudioStream", { enumerable: true, get: function () { return getAudioStream_1.getAudioStream; } });
|
|
18
20
|
var getBrowserSupportedMimeType_1 = require("./getBrowserSupportedMimeType");
|