UNPKG

1.26 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.encode = void 0;
4const tslib_1 = require("tslib");
5const querystring_1 = tslib_1.__importDefault(require("querystring"));
6const helpers_1 = require("./helpers");
7const signature_1 = tslib_1.__importDefault(require("./modules/signature"));
8function encode(data) {
9 return querystring_1.default.stringify(data, "&", "=", {
10 encodeURIComponent: helpers_1.percentEncode,
11 });
12}
13exports.encode = encode;
14function 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}
32exports.default = oAuth1a;