1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.encode = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const querystring_1 = tslib_1.__importDefault(require("querystring"));
|
6 | const helpers_1 = require("./helpers");
|
7 | const signature_1 = tslib_1.__importDefault(require("./modules/signature"));
|
8 | function encode(data) {
|
9 | return querystring_1.default.stringify(data, "&", "=", {
|
10 | encodeURIComponent: helpers_1.percentEncode,
|
11 | });
|
12 | }
|
13 | exports.encode = encode;
|
14 | function oAuth1a(requestOptions, oAuthOptions) {
|
15 | const oAuthParams = {
|
16 | oauth_consumer_key: oAuthOptions.api_key,
|
17 | oauth_nonce: (0, helpers_1.randomString)(32),
|
18 | oauth_signature: "",
|
19 | oauth_signature_method: "HMAC-SHA1",
|
20 | oauth_timestamp: (0, helpers_1.timestamp)(),
|
21 | oauth_token: oAuthOptions.access_token,
|
22 | oauth_version: "1.0",
|
23 | };
|
24 | oAuthParams.oauth_signature = (0, signature_1.default)({
|
25 | ...requestOptions,
|
26 | oAuthOptions: { ...oAuthOptions, ...oAuthParams },
|
27 | });
|
28 | return `OAuth ${Object.entries(oAuthParams)
|
29 | .map(([key, value]) => `${(0, helpers_1.percentEncode)(key)}="${(0, helpers_1.percentEncode)(String(value))}"`)
|
30 | .join(", ")}`;
|
31 | }
|
32 | exports.default = oAuth1a;
|