webflow-api 1.1.2 → 1.2.1
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/README.md +41 -17
- package/dist/api/collection.d.ts +86 -25
- package/dist/api/collection.js +88 -29
- package/dist/api/index.d.ts +7 -7
- package/dist/api/index.js +9 -19
- package/dist/api/item.d.ts +141 -107
- package/dist/api/item.js +145 -125
- package/dist/api/meta.d.ts +16 -14
- package/dist/api/meta.js +20 -19
- package/dist/api/oauth.d.ts +38 -36
- package/dist/api/oauth.js +59 -59
- package/dist/api/site.d.ts +118 -43
- package/dist/api/site.js +131 -53
- package/dist/api/user.d.ts +143 -0
- package/dist/api/user.js +119 -0
- package/dist/api/webhook.d.ts +77 -55
- package/dist/api/webhook.js +74 -61
- package/dist/core/error.d.ts +2 -0
- package/dist/core/error.js +8 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/response.d.ts +32 -0
- package/dist/core/response.js +26 -0
- package/dist/{webflow.d.ts → core/webflow.d.ts} +66 -54
- package/dist/{webflow.js → core/webflow.js} +114 -65
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +12 -8
- package/src/api/collection.ts +103 -36
- package/src/api/index.ts +7 -7
- package/src/api/item.ts +217 -176
- package/src/api/meta.ts +19 -18
- package/src/api/oauth.ts +71 -74
- package/src/api/site.ts +161 -55
- package/src/api/user.ts +192 -0
- package/src/api/webhook.ts +103 -80
- package/src/core/error.ts +8 -0
- package/src/core/index.ts +2 -2
- package/src/core/response.ts +50 -0
- package/src/{webflow.ts → core/webflow.ts} +153 -125
- package/src/index.ts +1 -1
- package/yarn.lock +4 -9
- package/dist/api/membership.d.ts +0 -114
- package/dist/api/membership.js +0 -96
- package/dist/core/client.d.ts +0 -27
- package/dist/core/client.js +0 -60
- package/dist/core/options.d.ts +0 -8
- package/dist/core/options.js +0 -5
- package/dist/wrapper/collection.d.ts +0 -85
- package/dist/wrapper/collection.js +0 -94
- package/dist/wrapper/index.d.ts +0 -6
- package/dist/wrapper/index.js +0 -22
- package/dist/wrapper/item.d.ts +0 -140
- package/dist/wrapper/item.js +0 -153
- package/dist/wrapper/membership.d.ts +0 -105
- package/dist/wrapper/membership.js +0 -123
- package/dist/wrapper/response.d.ts +0 -16
- package/dist/wrapper/response.js +0 -17
- package/dist/wrapper/site.d.ts +0 -168
- package/dist/wrapper/site.js +0 -191
- package/dist/wrapper/webhook.d.ts +0 -78
- package/dist/wrapper/webhook.js +0 -82
- package/src/api/membership.ts +0 -155
- package/src/core/client.ts +0 -82
- package/src/core/options.ts +0 -9
- package/src/wrapper/collection.ts +0 -115
- package/src/wrapper/index.ts +0 -6
- package/src/wrapper/item.ts +0 -218
- package/src/wrapper/membership.ts +0 -163
- package/src/wrapper/response.ts +0 -25
- package/src/wrapper/site.ts +0 -228
- package/src/wrapper/webhook.ts +0 -116
package/src/api/item.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { PaginatedData, requireArgs, WebflowRecord } from "../core";
|
|
2
3
|
|
|
3
4
|
/**************************************************************
|
|
4
5
|
* Interfaces
|
|
@@ -40,192 +41,232 @@ export type PageinatedItems = PaginatedData & {
|
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
/**************************************************************
|
|
43
|
-
*
|
|
44
|
+
* Class
|
|
44
45
|
**************************************************************/
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
60
|
-
// The API returns a paginated list with one record :(
|
|
61
|
-
return client.get<PageinatedItems>(path);
|
|
62
|
-
}
|
|
47
|
+
export class Item extends WebflowRecord<IItem> implements IItem {
|
|
48
|
+
"published-on"?: string | null;
|
|
49
|
+
"published-by"?: string | null;
|
|
50
|
+
"updated-on": string;
|
|
51
|
+
"created-on": string;
|
|
52
|
+
"updated-by": string;
|
|
53
|
+
"created-by": string;
|
|
54
|
+
_archived: boolean;
|
|
55
|
+
_draft: boolean;
|
|
56
|
+
_cid: string;
|
|
57
|
+
name: string;
|
|
58
|
+
slug: string;
|
|
59
|
+
_id: string;
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* @param params The params for the request
|
|
68
|
-
* @param params.collectionId The Collection ID
|
|
69
|
-
* @param params.limit The number of items to return (optional)
|
|
70
|
-
* @param params.offset The number of items to skip (optional)
|
|
71
|
-
* @returns A list of Items
|
|
72
|
-
*/
|
|
73
|
-
export function list(
|
|
74
|
-
client: Client,
|
|
75
|
-
{
|
|
76
|
-
collectionId,
|
|
77
|
-
limit,
|
|
78
|
-
offset,
|
|
79
|
-
}: { collectionId: string; limit?: number; offset?: number }
|
|
80
|
-
) {
|
|
81
|
-
requireArgs({ collectionId });
|
|
82
|
-
const params = { limit, offset };
|
|
83
|
-
const path = `/collections/${collectionId}/items`;
|
|
84
|
-
return client.get<PageinatedItems>(path, { params });
|
|
85
|
-
}
|
|
61
|
+
/**************************************************************
|
|
62
|
+
* Static Methods
|
|
63
|
+
**************************************************************/
|
|
86
64
|
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Get a single Item
|
|
67
|
+
* @param params The params for the request
|
|
68
|
+
* @param params.collectionId The Collection ID
|
|
69
|
+
* @param params.itemId The Item ID
|
|
70
|
+
* @param client The Axios client instance
|
|
71
|
+
* @returns A single Item
|
|
72
|
+
*/
|
|
73
|
+
static getOne(
|
|
74
|
+
{ collectionId, itemId }: { collectionId: string; itemId: string },
|
|
75
|
+
client: AxiosInstance,
|
|
76
|
+
) {
|
|
77
|
+
requireArgs({ collectionId, itemId });
|
|
78
|
+
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
79
|
+
// The API returns a paginated list with one record :(
|
|
80
|
+
return client.get<PageinatedItems>(path);
|
|
81
|
+
}
|
|
103
82
|
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
itemId: string;
|
|
122
|
-
collectionId: string;
|
|
83
|
+
/**
|
|
84
|
+
* Get a list of Items
|
|
85
|
+
* @param params The params for the request
|
|
86
|
+
* @param params.collectionId The Collection ID
|
|
87
|
+
* @param params.limit The number of items to return (optional)
|
|
88
|
+
* @param params.offset The number of items to skip (optional)
|
|
89
|
+
* @param client The Axios client instance
|
|
90
|
+
* @returns A list of Items
|
|
91
|
+
*/
|
|
92
|
+
static list(
|
|
93
|
+
{ collectionId, limit, offset }: { collectionId: string; limit?: number; offset?: number },
|
|
94
|
+
client: AxiosInstance,
|
|
95
|
+
) {
|
|
96
|
+
requireArgs({ collectionId });
|
|
97
|
+
const params = { limit, offset };
|
|
98
|
+
const path = `/collections/${collectionId}/items`;
|
|
99
|
+
return client.get<PageinatedItems>(path, { params });
|
|
123
100
|
}
|
|
124
|
-
) {
|
|
125
|
-
requireArgs({ collectionId, itemId });
|
|
126
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
127
|
-
return client.put<IItem>(path, { fields });
|
|
128
|
-
}
|
|
129
101
|
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
{
|
|
142
|
-
collectionId
|
|
143
|
-
|
|
144
|
-
fields
|
|
145
|
-
}: {
|
|
146
|
-
fields: any;
|
|
147
|
-
itemId: string;
|
|
148
|
-
collectionId: string;
|
|
102
|
+
/**
|
|
103
|
+
* Create a new Item
|
|
104
|
+
* @param params The params for the request
|
|
105
|
+
* @param params.collectionId The Collection ID
|
|
106
|
+
* @param params.fields The Item fields to create
|
|
107
|
+
* @param client The Axios client instance
|
|
108
|
+
* @returns The created Item
|
|
109
|
+
*/
|
|
110
|
+
static create(
|
|
111
|
+
{ collectionId, fields }: { fields: any; collectionId: string },
|
|
112
|
+
client: AxiosInstance,
|
|
113
|
+
) {
|
|
114
|
+
requireArgs({ collectionId });
|
|
115
|
+
const path = `/collections/${collectionId}/items`;
|
|
116
|
+
return client.post<IItem>(path, { fields });
|
|
149
117
|
}
|
|
150
|
-
) {
|
|
151
|
-
requireArgs({ collectionId, itemId });
|
|
152
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
153
|
-
return client.patch<IItem>(path, { fields });
|
|
154
|
-
}
|
|
155
118
|
|
|
156
|
-
/**
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Update a single Item
|
|
121
|
+
* @param params The params for the request
|
|
122
|
+
* @param params.collectionId The Collection ID
|
|
123
|
+
* @param params.itemId The Item ID
|
|
124
|
+
* @param params.fields The fields to update
|
|
125
|
+
* @param client The Axios client instance
|
|
126
|
+
* @returns The updated Item
|
|
127
|
+
*/
|
|
128
|
+
static update(
|
|
129
|
+
{
|
|
130
|
+
collectionId,
|
|
131
|
+
itemId,
|
|
132
|
+
fields,
|
|
133
|
+
}: {
|
|
134
|
+
fields: any;
|
|
135
|
+
itemId: string;
|
|
136
|
+
collectionId: string;
|
|
137
|
+
},
|
|
138
|
+
client: AxiosInstance,
|
|
139
|
+
) {
|
|
140
|
+
requireArgs({ collectionId, itemId });
|
|
141
|
+
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
142
|
+
return client.put<IItem>(path, { fields });
|
|
172
143
|
}
|
|
173
|
-
) {
|
|
174
|
-
requireArgs({ collectionId, itemId });
|
|
175
|
-
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
176
|
-
return client.delete<IItemDelete>(path);
|
|
177
|
-
}
|
|
178
144
|
|
|
179
|
-
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Patch a single Item
|
|
147
|
+
* @param params The params for the request
|
|
148
|
+
* @param params.collectionId The Collection ID
|
|
149
|
+
* @param params.itemId The Item ID
|
|
150
|
+
* @param params.fields The fields to patch
|
|
151
|
+
* @param client The Axios client instance
|
|
152
|
+
* @returns The patched Item
|
|
153
|
+
*/
|
|
154
|
+
static patch(
|
|
155
|
+
{
|
|
156
|
+
collectionId,
|
|
157
|
+
itemId,
|
|
158
|
+
fields,
|
|
159
|
+
}: {
|
|
160
|
+
fields: any;
|
|
161
|
+
itemId: string;
|
|
162
|
+
collectionId: string;
|
|
163
|
+
},
|
|
164
|
+
client: AxiosInstance,
|
|
165
|
+
) {
|
|
166
|
+
requireArgs({ collectionId, itemId });
|
|
167
|
+
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
168
|
+
return client.patch<IItem>(path, { fields });
|
|
197
169
|
}
|
|
198
|
-
) {
|
|
199
|
-
requireArgs({ collectionId, itemIds });
|
|
200
|
-
const params = { live };
|
|
201
|
-
const data = { itemIds };
|
|
202
|
-
const url = `/collections/${collectionId}/items`;
|
|
203
|
-
const _params = { method: "DELETE", url, data, params };
|
|
204
|
-
|
|
205
|
-
// DELETE spec doesn't support body in delete
|
|
206
|
-
// RFC-9110 https://tools.ietf.org/html/rfc9110
|
|
207
|
-
return client.request<IDeletedItems>(_params);
|
|
208
|
-
}
|
|
209
170
|
|
|
210
|
-
/**
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Remove a single Item
|
|
173
|
+
* @param params The params for the request
|
|
174
|
+
* @param params.collectionId The Collection ID
|
|
175
|
+
* @param params.itemId The Item ID
|
|
176
|
+
* @param client The Axios client instance
|
|
177
|
+
* @returns The result from the removal
|
|
178
|
+
*/
|
|
179
|
+
static remove(
|
|
180
|
+
{
|
|
181
|
+
collectionId,
|
|
182
|
+
itemId,
|
|
183
|
+
}: {
|
|
184
|
+
itemId: string;
|
|
185
|
+
collectionId: string;
|
|
186
|
+
},
|
|
187
|
+
client: AxiosInstance,
|
|
188
|
+
) {
|
|
189
|
+
requireArgs({ collectionId, itemId });
|
|
190
|
+
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
191
|
+
return client.delete<IItemDelete>(path);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Unpublishes a list of Items
|
|
196
|
+
* @param params The params for the request
|
|
197
|
+
* @param params.collectionId The Collection ID
|
|
198
|
+
* @param params.live Unpublish from the live site
|
|
199
|
+
* @param client The Axios client instance
|
|
200
|
+
* @returns The result of the unpublish
|
|
201
|
+
*/
|
|
202
|
+
static unpublish(
|
|
203
|
+
{
|
|
204
|
+
collectionId,
|
|
205
|
+
itemIds,
|
|
206
|
+
live = false,
|
|
207
|
+
}: {
|
|
208
|
+
live?: boolean;
|
|
209
|
+
itemIds: string[];
|
|
210
|
+
collectionId: string;
|
|
211
|
+
},
|
|
212
|
+
client: AxiosInstance,
|
|
213
|
+
) {
|
|
214
|
+
requireArgs({ collectionId, itemIds });
|
|
215
|
+
const params = { live };
|
|
216
|
+
const data = { itemIds };
|
|
217
|
+
const url = `/collections/${collectionId}/items`;
|
|
218
|
+
const _params = { method: "DELETE", url, data, params };
|
|
219
|
+
|
|
220
|
+
// DELETE spec doesn't support body in delete
|
|
221
|
+
// RFC-9110 https://tools.ietf.org/html/rfc9110
|
|
222
|
+
return client.request<IDeletedItems>(_params);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Publishes a list of Items
|
|
227
|
+
* @param params The request parameters
|
|
228
|
+
* @param params.collectionId The Collection ID
|
|
229
|
+
* @param params.itemIds The list of Item IDs to publish
|
|
230
|
+
* @param params.live Publish to live site
|
|
231
|
+
* @param client The Axios client instance
|
|
232
|
+
* @returns The result of the publish
|
|
233
|
+
*/
|
|
234
|
+
static publish(
|
|
235
|
+
{
|
|
236
|
+
itemIds,
|
|
237
|
+
live = false,
|
|
238
|
+
collectionId,
|
|
239
|
+
}: { live?: boolean; itemIds: string[]; collectionId: string },
|
|
240
|
+
client: AxiosInstance,
|
|
241
|
+
) {
|
|
242
|
+
requireArgs({ collectionId, itemIds });
|
|
243
|
+
const params = { live };
|
|
244
|
+
const path = `/collections/${collectionId}/items/publish`;
|
|
245
|
+
return client.put<IPublishItems>(path, { itemIds }, { params });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**************************************************************
|
|
249
|
+
* Instance Methods
|
|
250
|
+
**************************************************************/
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Update a single Item
|
|
254
|
+
* @param fields The fields to update
|
|
255
|
+
* @returns The updated Item
|
|
256
|
+
*/
|
|
257
|
+
async update({ ...fields }) {
|
|
258
|
+
const params = { collectionId: this._cid, itemId: this._id, fields };
|
|
259
|
+
const res = await Item.update(params, this.client);
|
|
260
|
+
return new Item(this.client, res);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Remove a single Item
|
|
265
|
+
* @returns The result from the removal
|
|
266
|
+
*/
|
|
267
|
+
async remove() {
|
|
268
|
+
const params = { collectionId: this._cid, itemId: this._id };
|
|
269
|
+
const res = await Item.remove(params, this.client);
|
|
270
|
+
return res.data;
|
|
271
|
+
}
|
|
231
272
|
}
|
package/src/api/meta.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
2
|
|
|
3
3
|
/**************************************************************
|
|
4
4
|
* Types
|
|
@@ -39,23 +39,24 @@ export interface IAuthentiationInfo {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**************************************************************
|
|
42
|
-
*
|
|
42
|
+
* Class
|
|
43
43
|
**************************************************************/
|
|
44
|
+
export class Meta {
|
|
45
|
+
/**
|
|
46
|
+
* Get the authentication info for the current token
|
|
47
|
+
* @param client The Axios client instance
|
|
48
|
+
* @returns The authentication info
|
|
49
|
+
*/
|
|
50
|
+
static info(client: AxiosInstance) {
|
|
51
|
+
return client.get<IAuthentiationInfo>("/info");
|
|
52
|
+
}
|
|
44
53
|
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get the authenticated user
|
|
56
|
-
* @param client The Webflow client
|
|
57
|
-
* @returns The authenticated user
|
|
58
|
-
*/
|
|
59
|
-
export function user(client: Client) {
|
|
60
|
-
return client.get<IAuthenticatedUser>("/user");
|
|
54
|
+
/**
|
|
55
|
+
* Get the authenticated user
|
|
56
|
+
* @param client The Axios client instance
|
|
57
|
+
* @returns The authenticated user
|
|
58
|
+
*/
|
|
59
|
+
static user(client: AxiosInstance) {
|
|
60
|
+
return client.get<IAuthenticatedUser>("/user");
|
|
61
|
+
}
|
|
61
62
|
}
|
package/src/api/oauth.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { requireArgs } from "../core";
|
|
2
3
|
|
|
3
4
|
/**************************************************************
|
|
4
5
|
* Interfaces
|
|
@@ -35,85 +36,81 @@ export interface IRevokeToken {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/**************************************************************
|
|
38
|
-
*
|
|
39
|
+
* Class
|
|
39
40
|
**************************************************************/
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
client_id
|
|
58
|
-
state,
|
|
59
|
-
scope,
|
|
60
|
-
}: IAuthorizeUrlParams
|
|
61
|
-
) {
|
|
62
|
-
requireArgs({ client_id });
|
|
42
|
+
export class OAuth {
|
|
43
|
+
/**
|
|
44
|
+
* Get the URL to authorize a user
|
|
45
|
+
* @param params The params for the request
|
|
46
|
+
* @param params.client_id The OAuth client ID
|
|
47
|
+
* @param params.scope The scope (optional)
|
|
48
|
+
* @param params.state The state (optional)
|
|
49
|
+
* @param params.redirect_uri The redirect URI (optional)
|
|
50
|
+
* @param params.response_type The response type (default: code)
|
|
51
|
+
* @param client The Axios client instance
|
|
52
|
+
* @returns The URL to authorize a user
|
|
53
|
+
*/
|
|
54
|
+
static authorizeUrl(
|
|
55
|
+
{ response_type = "code", redirect_uri, client_id, state, scope }: IAuthorizeUrlParams,
|
|
56
|
+
client: AxiosInstance,
|
|
57
|
+
) {
|
|
58
|
+
requireArgs({ client_id });
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
const params = { response_type, client_id };
|
|
61
|
+
if (redirect_uri) params["redirect_uri"] = redirect_uri;
|
|
62
|
+
if (state) params["state"] = state;
|
|
63
|
+
if (scope) params["scope"] = scope;
|
|
68
64
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
65
|
+
const url = "/oauth/authorize";
|
|
66
|
+
return client.getUri({ url, method: "GET", params });
|
|
67
|
+
}
|
|
72
68
|
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
) {
|
|
94
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Get an access token
|
|
71
|
+
* @param params The params for the request
|
|
72
|
+
* @param params.code The OAuth code
|
|
73
|
+
* @param params.client_id The OAuth client ID
|
|
74
|
+
* @param params.client_secret The OAuth client secret
|
|
75
|
+
* @param params.redirect_uri The redirect URI (optional)
|
|
76
|
+
* @param params.grant_type The grant type (default: "authorization_code")
|
|
77
|
+
* @param client The Axios client instance
|
|
78
|
+
* @returns An access token
|
|
79
|
+
*/
|
|
80
|
+
static accessToken(
|
|
81
|
+
{
|
|
82
|
+
grant_type = "authorization_code",
|
|
83
|
+
client_secret,
|
|
84
|
+
redirect_uri,
|
|
85
|
+
client_id,
|
|
86
|
+
code,
|
|
87
|
+
}: IAccessTokenParams,
|
|
88
|
+
client: AxiosInstance,
|
|
89
|
+
) {
|
|
90
|
+
requireArgs({ client_id, client_secret, code });
|
|
95
91
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
92
|
+
const path = "/oauth/access_token";
|
|
93
|
+
const data = { client_secret, redirect_uri, grant_type, client_id, code };
|
|
94
|
+
return client.post<IAccessToken>(path, data);
|
|
95
|
+
}
|
|
100
96
|
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
) {
|
|
114
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Revoke an access token
|
|
99
|
+
* @param params The params for the request
|
|
100
|
+
* @param params.client_id The OAuth client ID
|
|
101
|
+
* @param params.client_secret The OAuth client secret
|
|
102
|
+
* @param params.access_token The OAuth access token
|
|
103
|
+
* @param client The Axios client instance
|
|
104
|
+
* @returns The result of the revoke
|
|
105
|
+
*/
|
|
106
|
+
static revokeToken(
|
|
107
|
+
{ client_secret, access_token, client_id }: IRevokeTokenParams,
|
|
108
|
+
client: AxiosInstance,
|
|
109
|
+
) {
|
|
110
|
+
requireArgs({ client_id, client_secret, access_token });
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
const path = "/oauth/revoke_authorization";
|
|
113
|
+
const data = { client_secret, access_token, client_id };
|
|
114
|
+
return client.post<IRevokeToken>(path, data);
|
|
115
|
+
}
|
|
119
116
|
}
|