-
Notifications
You must be signed in to change notification settings - Fork 396
/
lineModuleAttachClient.ts
155 lines (144 loc) · 6.38 KB
/
lineModuleAttachClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* LINE Messaging API
* This document describes LINE Messaging API.
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/* tslint:disable:no-unused-locals */
import { AttachModuleResponse } from "../model/attachModuleResponse.js";
import * as Types from "../../types.js";
import { ensureJSON } from "../../utils.js";
import { Readable } from "node:stream";
import HTTPFetchClient, {
convertResponseToReadable,
} from "../../http-fetch.js";
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
interface httpClientConfig {
baseURL?: string;
channelAccessToken: string;
// TODO support defaultHeaders?
}
export class LineModuleAttachClient {
private httpClient: HTTPFetchClient;
constructor(config: httpClientConfig) {
const baseURL = config.baseURL || "https://manager.line.biz";
this.httpClient = new HTTPFetchClient({
defaultHeaders: {
Authorization: "Bearer " + config.channelAccessToken,
},
baseURL: baseURL,
});
}
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
LINE_REQUEST_ID_HTTP_HEADER_NAME,
);
}
return resBody;
}
/**
* Attach by operation of the module channel provider
* @param grantType authorization_code
* @param code Authorization code received from the LINE Platform.
* @param redirectUri Specify the redirect_uri specified in the URL for authentication and authorization.
* @param codeVerifier Specify when using PKCE (Proof Key for Code Exchange) defined in the OAuth 2.0 extension specification as a countermeasure against authorization code interception attacks.
* @param clientId Instead of using Authorization header, you can use this parameter to specify the channel ID of the module channel. You can find the channel ID of the module channel in the LINE Developers Console.
* @param clientSecret Instead of using Authorization header, you can use this parameter to specify the channel secret of the module channel. You can find the channel secret of the module channel in the LINE Developers Console.
* @param region If you specified a value for region in the URL for authentication and authorization, specify the same value.
* @param basicSearchId If you specified a value for basic_search_id in the URL for authentication and authorization, specify the same value.
* @param scope If you specified a value for scope in the URL for authentication and authorization, specify the same value.
* @param brandType If you specified a value for brand_type in the URL for authentication and authorization, specify the same value.
*
* @see <a href="https://developers.line.biz/en/reference/partner-docs/#link-attach-by-operation-module-channel-provider"> Documentation</a>
*/
public async attachModule(
grantType?: string,
code?: string,
redirectUri?: string,
codeVerifier?: string,
clientId?: string,
clientSecret?: string,
region?: string,
basicSearchId?: string,
scope?: string,
brandType?: string,
): Promise<AttachModuleResponse> {
return (
await this.attachModuleWithHttpInfo(
grantType,
code,
redirectUri,
codeVerifier,
clientId,
clientSecret,
region,
basicSearchId,
scope,
brandType,
)
).body;
}
/**
* Attach by operation of the module channel provider.
* This method includes HttpInfo object to return additional information.
* @param grantType authorization_code
* @param code Authorization code received from the LINE Platform.
* @param redirectUri Specify the redirect_uri specified in the URL for authentication and authorization.
* @param codeVerifier Specify when using PKCE (Proof Key for Code Exchange) defined in the OAuth 2.0 extension specification as a countermeasure against authorization code interception attacks.
* @param clientId Instead of using Authorization header, you can use this parameter to specify the channel ID of the module channel. You can find the channel ID of the module channel in the LINE Developers Console.
* @param clientSecret Instead of using Authorization header, you can use this parameter to specify the channel secret of the module channel. You can find the channel secret of the module channel in the LINE Developers Console.
* @param region If you specified a value for region in the URL for authentication and authorization, specify the same value.
* @param basicSearchId If you specified a value for basic_search_id in the URL for authentication and authorization, specify the same value.
* @param scope If you specified a value for scope in the URL for authentication and authorization, specify the same value.
* @param brandType If you specified a value for brand_type in the URL for authentication and authorization, specify the same value.
*
* @see <a href="https://developers.line.biz/en/reference/partner-docs/#link-attach-by-operation-module-channel-provider"> Documentation</a>
*/
public async attachModuleWithHttpInfo(
grantType?: string,
code?: string,
redirectUri?: string,
codeVerifier?: string,
clientId?: string,
clientSecret?: string,
region?: string,
basicSearchId?: string,
scope?: string,
brandType?: string,
): Promise<Types.ApiResponseType<AttachModuleResponse>> {
const formParams = {
grant_type: grantType,
code: code,
redirect_uri: redirectUri,
code_verifier: codeVerifier,
client_id: clientId,
client_secret: clientSecret,
region: region,
basic_search_id: basicSearchId,
scope: scope,
brand_type: brandType,
};
Object.keys(formParams).forEach((key: keyof typeof formParams) => {
if (formParams[key] === undefined) {
delete formParams[key];
}
});
const res = await this.httpClient.postForm(
"/module/auth/v1/token",
formParams,
);
return { httpResponse: res, body: await res.json() };
}
}