@lagent_titi/kick.js-ts 1.0.1 → 1.0.2
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/client.js +270 -84
- package/dist/errors.js +48 -16
- package/dist/index.js +17 -1
- package/dist/package.json +5 -5
- package/dist/services/categories.js +101 -25
- package/dist/services/channels.js +105 -41
- package/dist/services/chat.js +93 -39
- package/dist/services/events.js +169 -84
- package/dist/services/publicKey.js +64 -13
- package/dist/services/users.js +97 -34
- package/dist/types/webhooks.js +15 -11
- package/dist/utils/signature.js +20 -12
- package/dist/webhooks/handler.js +103 -57
- package/dist/webhooks/server.js +89 -31
- package/package.json +5 -5
package/dist/client.js
CHANGED
@@ -1,86 +1,272 @@
|
|
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
|
-
|
1
|
+
"use strict";
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
3
|
+
var extendStatics = function (d, b) {
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7
|
+
return extendStatics(d, b);
|
8
|
+
};
|
9
|
+
return function (d, b) {
|
10
|
+
if (typeof b !== "function" && b !== null)
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12
|
+
extendStatics(d, b);
|
13
|
+
function __() { this.constructor = d; }
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
|
+
};
|
16
|
+
})();
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
18
|
+
__assign = Object.assign || function(t) {
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
20
|
+
s = arguments[i];
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
22
|
+
t[p] = s[p];
|
23
|
+
}
|
24
|
+
return t;
|
25
|
+
};
|
26
|
+
return __assign.apply(this, arguments);
|
27
|
+
};
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
35
|
+
});
|
36
|
+
};
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
39
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
41
|
+
function step(op) {
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
43
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
44
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
46
|
+
switch (op[0]) {
|
47
|
+
case 0: case 1: t = op; break;
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
51
|
+
default:
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
56
|
+
if (t[2]) _.ops.pop();
|
57
|
+
_.trys.pop(); continue;
|
58
|
+
}
|
59
|
+
op = body.call(thisArg, _);
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
54
62
|
}
|
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
|
-
|
63
|
+
};
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
65
|
+
exports.KickClient = void 0;
|
66
|
+
var events_1 = require("events");
|
67
|
+
var categories_1 = require("./services/categories");
|
68
|
+
var users_1 = require("./services/users");
|
69
|
+
var channels_1 = require("./services/channels");
|
70
|
+
var chat_1 = require("./services/chat");
|
71
|
+
var publicKey_1 = require("./services/publicKey");
|
72
|
+
var events_2 = require("./services/events"); // ✅ Ajout
|
73
|
+
var handler_1 = require("./webhooks/handler");
|
74
|
+
var server_1 = require("./webhooks/server");
|
75
|
+
var KickClient = /** @class */ (function (_super) {
|
76
|
+
__extends(KickClient, _super);
|
77
|
+
function KickClient(options) {
|
78
|
+
if (options === void 0) { options = {}; }
|
79
|
+
var _a;
|
80
|
+
var _this = _super.call(this) || this;
|
81
|
+
_this.options = __assign({ webhookPort: options.webhookPort || 3000, webhookPath: options.webhookPath || '/webhook', webhookBaseUrl: options.webhookBaseUrl || 'http://localhost', token: (_a = options.token) !== null && _a !== void 0 ? _a : '' }, options);
|
82
|
+
_this.categories = new categories_1.CategoriesService(_this);
|
83
|
+
_this.users = new users_1.UsersService(_this);
|
84
|
+
_this.channels = new channels_1.ChannelsService(_this);
|
85
|
+
_this.chat = new chat_1.ChatService(_this);
|
86
|
+
_this.publicKey = new publicKey_1.PublicKeyService(_this);
|
87
|
+
_this.events = new events_2.EventsService(_this);
|
88
|
+
_this.webhookHandler = new handler_1.WebhookHandler(_this);
|
89
|
+
_this.webhookServer = new server_1.WebhookServer(_this, {
|
90
|
+
port: _this.options.webhookPort,
|
91
|
+
path: _this.options.webhookPath
|
92
|
+
});
|
93
|
+
_this.token = options.token || '';
|
94
|
+
return _this;
|
85
95
|
}
|
86
|
-
|
96
|
+
KickClient.prototype.searchCategories = function () {
|
97
|
+
return __awaiter(this, arguments, void 0, function (query) {
|
98
|
+
if (query === void 0) { query = ''; }
|
99
|
+
return __generator(this, function (_a) {
|
100
|
+
switch (_a.label) {
|
101
|
+
case 0: return [4 /*yield*/, this.categories.getCategories(query, this.token)];
|
102
|
+
case 1: return [2 /*return*/, _a.sent()];
|
103
|
+
}
|
104
|
+
});
|
105
|
+
});
|
106
|
+
};
|
107
|
+
KickClient.prototype.getCategory = function (categoryId) {
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
109
|
+
return __generator(this, function (_a) {
|
110
|
+
switch (_a.label) {
|
111
|
+
case 0: return [4 /*yield*/, this.categories.getCategory(categoryId, this.token)];
|
112
|
+
case 1: return [2 /*return*/, _a.sent()];
|
113
|
+
}
|
114
|
+
});
|
115
|
+
});
|
116
|
+
};
|
117
|
+
KickClient.prototype.introspectToken = function () {
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
119
|
+
return __generator(this, function (_a) {
|
120
|
+
switch (_a.label) {
|
121
|
+
case 0:
|
122
|
+
if (!this.token)
|
123
|
+
throw new Error('No token provided');
|
124
|
+
return [4 /*yield*/, this.users.introspectToken(this.token)];
|
125
|
+
case 1: return [2 /*return*/, _a.sent()];
|
126
|
+
}
|
127
|
+
});
|
128
|
+
});
|
129
|
+
};
|
130
|
+
KickClient.prototype.getUsers = function () {
|
131
|
+
return __awaiter(this, arguments, void 0, function (userIds) {
|
132
|
+
if (userIds === void 0) { userIds = []; }
|
133
|
+
return __generator(this, function (_a) {
|
134
|
+
switch (_a.label) {
|
135
|
+
case 0: return [4 /*yield*/, this.users.getUsers(userIds.map(String), this.token)];
|
136
|
+
case 1: return [2 /*return*/, _a.sent()];
|
137
|
+
}
|
138
|
+
});
|
139
|
+
});
|
140
|
+
};
|
141
|
+
KickClient.prototype.getChannels = function () {
|
142
|
+
return __awaiter(this, arguments, void 0, function (broadcasterIds) {
|
143
|
+
if (broadcasterIds === void 0) { broadcasterIds = []; }
|
144
|
+
return __generator(this, function (_a) {
|
145
|
+
switch (_a.label) {
|
146
|
+
case 0: return [4 /*yield*/, this.channels.getChannels(broadcasterIds.map(String), this.token)];
|
147
|
+
case 1: return [2 /*return*/, _a.sent()];
|
148
|
+
}
|
149
|
+
});
|
150
|
+
});
|
151
|
+
};
|
152
|
+
KickClient.prototype.updateChannel = function (options) {
|
153
|
+
return __awaiter(this, void 0, void 0, function () {
|
154
|
+
var typedOptions;
|
155
|
+
return __generator(this, function (_a) {
|
156
|
+
switch (_a.label) {
|
157
|
+
case 0:
|
158
|
+
if (!this.token)
|
159
|
+
throw new Error('No token provided');
|
160
|
+
typedOptions = options;
|
161
|
+
return [4 /*yield*/, this.channels.updateChannel(typedOptions, this.token)];
|
162
|
+
case 1: return [2 /*return*/, _a.sent()];
|
163
|
+
}
|
164
|
+
});
|
165
|
+
});
|
166
|
+
};
|
167
|
+
KickClient.prototype.sendChatMessage = function (options) {
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
169
|
+
return __generator(this, function (_a) {
|
170
|
+
switch (_a.label) {
|
171
|
+
case 0: return [4 /*yield*/, this.chat.sendMessage(__assign(__assign({}, options), { token: this.token, content: options.content // Assure-toi que content existe
|
172
|
+
}))];
|
173
|
+
case 1: return [2 /*return*/, _a.sent()];
|
174
|
+
}
|
175
|
+
});
|
176
|
+
});
|
177
|
+
};
|
178
|
+
KickClient.prototype.getPublicKey = function () {
|
179
|
+
return __awaiter(this, void 0, void 0, function () {
|
180
|
+
return __generator(this, function (_a) {
|
181
|
+
switch (_a.label) {
|
182
|
+
case 0: return [4 /*yield*/, this.publicKey.getPublicKey()];
|
183
|
+
case 1: return [2 /*return*/, _a.sent()];
|
184
|
+
}
|
185
|
+
});
|
186
|
+
});
|
187
|
+
};
|
188
|
+
KickClient.prototype.validateWebhook = function (headers, body) {
|
189
|
+
return __awaiter(this, void 0, void 0, function () {
|
190
|
+
return __generator(this, function (_a) {
|
191
|
+
switch (_a.label) {
|
192
|
+
case 0: return [4 /*yield*/, this.events.initializeVerifier()];
|
193
|
+
case 1:
|
194
|
+
_a.sent();
|
195
|
+
return [2 /*return*/, this.events.validateWebhook(headers, body)];
|
196
|
+
}
|
197
|
+
});
|
198
|
+
});
|
199
|
+
};
|
200
|
+
KickClient.prototype.getEventSubscriptions = function () {
|
201
|
+
return __awaiter(this, void 0, void 0, function () {
|
202
|
+
return __generator(this, function (_a) {
|
203
|
+
switch (_a.label) {
|
204
|
+
case 0:
|
205
|
+
if (!this.token)
|
206
|
+
throw new Error('No token provided');
|
207
|
+
return [4 /*yield*/, this.events.getSubscriptions(this.token)];
|
208
|
+
case 1: return [2 /*return*/, _a.sent()];
|
209
|
+
}
|
210
|
+
});
|
211
|
+
});
|
212
|
+
};
|
213
|
+
KickClient.prototype.subscribeToEvents = function (events_3) {
|
214
|
+
return __awaiter(this, arguments, void 0, function (events, method) {
|
215
|
+
if (method === void 0) { method = 'webhook'; }
|
216
|
+
return __generator(this, function (_a) {
|
217
|
+
switch (_a.label) {
|
218
|
+
case 0:
|
219
|
+
if (!this.token)
|
220
|
+
throw new Error('No token provided');
|
221
|
+
return [4 /*yield*/, this.events.subscribe(events, method, this.token)];
|
222
|
+
case 1: return [2 /*return*/, _a.sent()];
|
223
|
+
}
|
224
|
+
});
|
225
|
+
});
|
226
|
+
};
|
227
|
+
KickClient.prototype.unsubscribeFromEvents = function (subscriptionIds) {
|
228
|
+
return __awaiter(this, void 0, void 0, function () {
|
229
|
+
return __generator(this, function (_a) {
|
230
|
+
switch (_a.label) {
|
231
|
+
case 0:
|
232
|
+
if (!this.token)
|
233
|
+
throw new Error('No token provided');
|
234
|
+
return [4 /*yield*/, this.events.unsubscribe(subscriptionIds, this.token)];
|
235
|
+
case 1: return [2 /*return*/, _a.sent()];
|
236
|
+
}
|
237
|
+
});
|
238
|
+
});
|
239
|
+
};
|
240
|
+
KickClient.prototype.startWebhookServer = function () {
|
241
|
+
return __awaiter(this, void 0, void 0, function () {
|
242
|
+
return __generator(this, function (_a) {
|
243
|
+
switch (_a.label) {
|
244
|
+
case 0: return [4 /*yield*/, this.webhookServer.start()];
|
245
|
+
case 1: return [2 /*return*/, _a.sent()];
|
246
|
+
}
|
247
|
+
});
|
248
|
+
});
|
249
|
+
};
|
250
|
+
KickClient.prototype.stopWebhookServer = function () {
|
251
|
+
return __awaiter(this, void 0, void 0, function () {
|
252
|
+
return __generator(this, function (_a) {
|
253
|
+
switch (_a.label) {
|
254
|
+
case 0: return [4 /*yield*/, this.webhookServer.stop()];
|
255
|
+
case 1: return [2 /*return*/, _a.sent()];
|
256
|
+
}
|
257
|
+
});
|
258
|
+
});
|
259
|
+
};
|
260
|
+
KickClient.prototype.handleWebhookRequest = function (headers, rawBody) {
|
261
|
+
return __awaiter(this, void 0, void 0, function () {
|
262
|
+
return __generator(this, function (_a) {
|
263
|
+
switch (_a.label) {
|
264
|
+
case 0: return [4 /*yield*/, this.webhookHandler.handleWebhook(headers, rawBody)];
|
265
|
+
case 1: return [2 /*return*/, _a.sent()];
|
266
|
+
}
|
267
|
+
});
|
268
|
+
});
|
269
|
+
};
|
270
|
+
return KickClient;
|
271
|
+
}(events_1.EventEmitter));
|
272
|
+
exports.KickClient = KickClient;
|
package/dist/errors.js
CHANGED
@@ -1,19 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
"use strict";
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
3
|
+
var extendStatics = function (d, b) {
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7
|
+
return extendStatics(d, b);
|
8
|
+
};
|
9
|
+
return function (d, b) {
|
10
|
+
if (typeof b !== "function" && b !== null)
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12
|
+
extendStatics(d, b);
|
13
|
+
function __() { this.constructor = d; }
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
|
+
};
|
16
|
+
})();
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
+
exports.ForbiddenError = exports.UnauthorizedError = exports.KickApiError = void 0;
|
19
|
+
var KickApiError = /** @class */ (function (_super) {
|
20
|
+
__extends(KickApiError, _super);
|
21
|
+
function KickApiError(message, status) {
|
22
|
+
var _this = _super.call(this, message) || this;
|
23
|
+
_this.name = 'KickApiError';
|
24
|
+
_this.status = status;
|
25
|
+
return _this;
|
6
26
|
}
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
27
|
+
return KickApiError;
|
28
|
+
}(Error));
|
29
|
+
exports.KickApiError = KickApiError;
|
30
|
+
var UnauthorizedError = /** @class */ (function (_super) {
|
31
|
+
__extends(UnauthorizedError, _super);
|
32
|
+
function UnauthorizedError(message) {
|
33
|
+
if (message === void 0) { message = 'Unauthorized'; }
|
34
|
+
var _this = _super.call(this, message, 401) || this;
|
35
|
+
_this.name = 'UnauthorizedError';
|
36
|
+
return _this;
|
12
37
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
38
|
+
return UnauthorizedError;
|
39
|
+
}(KickApiError));
|
40
|
+
exports.UnauthorizedError = UnauthorizedError;
|
41
|
+
var ForbiddenError = /** @class */ (function (_super) {
|
42
|
+
__extends(ForbiddenError, _super);
|
43
|
+
function ForbiddenError(message) {
|
44
|
+
if (message === void 0) { message = 'Forbidden'; }
|
45
|
+
var _this = _super.call(this, message, 403) || this;
|
46
|
+
_this.name = 'ForbiddenError';
|
47
|
+
return _this;
|
18
48
|
}
|
19
|
-
|
49
|
+
return ForbiddenError;
|
50
|
+
}(KickApiError));
|
51
|
+
exports.ForbiddenError = ForbiddenError;
|
package/dist/index.js
CHANGED
@@ -1 +1,17 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./client"), exports);
|
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lagent_titi/kick.js-ts",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
4
4
|
"description": "Node.js TypeScript client for Kick.com API",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -20,9 +20,9 @@
|
|
20
20
|
"author": "botk4cp3r",
|
21
21
|
"license": "MIT",
|
22
22
|
"bugs": {
|
23
|
-
"url": "https://github.com/
|
23
|
+
"url": "https://github.com/lagentiti/kick.api-ts/issues"
|
24
24
|
},
|
25
|
-
"homepage": "https://github.com/
|
25
|
+
"homepage": "https://github.com/lagentiti/kick.api-ts#readme",
|
26
26
|
"dependencies": {
|
27
27
|
"express": "^4.21.2"
|
28
28
|
},
|
@@ -33,8 +33,8 @@
|
|
33
33
|
"typescript": "^5.8.3"
|
34
34
|
},
|
35
35
|
"scripts": {
|
36
|
-
|
37
|
-
|
36
|
+
"build": "tsc && cpx \"package.json\" dist && cpx \"README.md\" dist",
|
37
|
+
"start": "node dist/index.js",
|
38
38
|
"dev": "ts-node src/index.ts"
|
39
39
|
},
|
40
40
|
"publishConfig": {
|
@@ -1,30 +1,106 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
20
|
+
});
|
21
|
+
};
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
26
|
+
function step(op) {
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
31
|
+
switch (op[0]) {
|
32
|
+
case 0: case 1: t = op; break;
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
36
|
+
default:
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
41
|
+
if (t[2]) _.ops.pop();
|
42
|
+
_.trys.pop(); continue;
|
43
|
+
}
|
44
|
+
op = body.call(thisArg, _);
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
47
|
+
}
|
48
|
+
};
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
50
|
+
exports.CategoriesService = void 0;
|
51
|
+
var CategoriesService = /** @class */ (function () {
|
52
|
+
function CategoriesService(apiClient) {
|
3
53
|
this.apiClient = apiClient;
|
4
54
|
this.baseUrl = 'https://api.kick.com/public/v1/categories';
|
5
55
|
}
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
56
|
+
CategoriesService.prototype.getCategories = function () {
|
57
|
+
return __awaiter(this, arguments, void 0, function (searchQuery, token) {
|
58
|
+
var url, response;
|
59
|
+
if (searchQuery === void 0) { searchQuery = ''; }
|
60
|
+
if (token === void 0) { token = ''; }
|
61
|
+
return __generator(this, function (_a) {
|
62
|
+
switch (_a.label) {
|
63
|
+
case 0:
|
64
|
+
url = new URL(this.baseUrl);
|
65
|
+
if (searchQuery) {
|
66
|
+
url.searchParams.append('q', searchQuery);
|
67
|
+
}
|
68
|
+
return [4 /*yield*/, fetch(url.toString(), {
|
69
|
+
method: 'GET',
|
70
|
+
headers: __assign({}, (token && { Authorization: "Bearer ".concat(token) }))
|
71
|
+
})];
|
72
|
+
case 1:
|
73
|
+
response = _a.sent();
|
74
|
+
if (!response.ok) {
|
75
|
+
throw new Error("HTTP error! status: ".concat(response.status));
|
76
|
+
}
|
77
|
+
return [4 /*yield*/, response.json()];
|
78
|
+
case 2: return [2 /*return*/, _a.sent()];
|
79
|
+
}
|
80
|
+
});
|
14
81
|
});
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
82
|
+
};
|
83
|
+
CategoriesService.prototype.getCategory = function (categoryId_1) {
|
84
|
+
return __awaiter(this, arguments, void 0, function (categoryId, token) {
|
85
|
+
var response;
|
86
|
+
if (token === void 0) { token = ''; }
|
87
|
+
return __generator(this, function (_a) {
|
88
|
+
switch (_a.label) {
|
89
|
+
case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/").concat(categoryId), {
|
90
|
+
method: 'GET',
|
91
|
+
headers: __assign({}, (token && { Authorization: "Bearer ".concat(token) }))
|
92
|
+
})];
|
93
|
+
case 1:
|
94
|
+
response = _a.sent();
|
95
|
+
if (!response.ok) {
|
96
|
+
throw new Error("HTTP error! status: ".concat(response.status));
|
97
|
+
}
|
98
|
+
return [4 /*yield*/, response.json()];
|
99
|
+
case 2: return [2 /*return*/, _a.sent()];
|
100
|
+
}
|
101
|
+
});
|
24
102
|
});
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
}
|
30
|
-
}
|
103
|
+
};
|
104
|
+
return CategoriesService;
|
105
|
+
}());
|
106
|
+
exports.CategoriesService = CategoriesService;
|