@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
@@ -1,46 +1,110 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
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);
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
+
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;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
+
exports.ChannelsService = void 0;
|
40
|
+
var errors_1 = require("../errors");
|
41
|
+
var ChannelsService = /** @class */ (function () {
|
42
|
+
function ChannelsService(apiClient) {
|
4
43
|
this.apiClient = apiClient;
|
5
44
|
this.baseUrl = 'https://api.kick.com/public/v1/channels';
|
6
45
|
}
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
broadcasterIds
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
46
|
+
ChannelsService.prototype.getChannels = function () {
|
47
|
+
return __awaiter(this, arguments, void 0, function (broadcasterIds, token) {
|
48
|
+
var url, response;
|
49
|
+
if (broadcasterIds === void 0) { broadcasterIds = []; }
|
50
|
+
return __generator(this, function (_a) {
|
51
|
+
switch (_a.label) {
|
52
|
+
case 0:
|
53
|
+
url = new URL(this.baseUrl);
|
54
|
+
if (broadcasterIds.length > 0) {
|
55
|
+
broadcasterIds.forEach(function (id) {
|
56
|
+
return url.searchParams.append('broadcaster_user_id[]', id.toString());
|
57
|
+
});
|
58
|
+
}
|
59
|
+
return [4 /*yield*/, fetch(url.toString(), {
|
60
|
+
method: 'GET',
|
61
|
+
headers: {
|
62
|
+
Authorization: "Bearer ".concat(token)
|
63
|
+
}
|
64
|
+
})];
|
65
|
+
case 1:
|
66
|
+
response = _a.sent();
|
67
|
+
if (response.status === 401)
|
68
|
+
throw new errors_1.UnauthorizedError();
|
69
|
+
if (response.status === 403)
|
70
|
+
throw new errors_1.ForbiddenError();
|
71
|
+
if (!response.ok)
|
72
|
+
throw new Error("HTTP error! status: ".concat(response.status));
|
73
|
+
return [4 /*yield*/, response.json()];
|
74
|
+
case 2: return [2 /*return*/, _a.sent()];
|
75
|
+
}
|
76
|
+
});
|
17
77
|
});
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
78
|
+
};
|
79
|
+
ChannelsService.prototype.updateChannel = function (options, token) {
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
81
|
+
var response;
|
82
|
+
return __generator(this, function (_a) {
|
83
|
+
switch (_a.label) {
|
84
|
+
case 0: return [4 /*yield*/, fetch(this.baseUrl, {
|
85
|
+
method: 'PATCH',
|
86
|
+
headers: {
|
87
|
+
Authorization: "Bearer ".concat(token),
|
88
|
+
'Content-Type': 'application/json'
|
89
|
+
},
|
90
|
+
body: JSON.stringify({
|
91
|
+
category_id: options.categoryId,
|
92
|
+
stream_title: options.streamTitle
|
93
|
+
})
|
94
|
+
})];
|
95
|
+
case 1:
|
96
|
+
response = _a.sent();
|
97
|
+
if (response.status === 401)
|
98
|
+
throw new errors_1.UnauthorizedError();
|
99
|
+
if (response.status === 403)
|
100
|
+
throw new errors_1.ForbiddenError();
|
101
|
+
if (!response.ok)
|
102
|
+
throw new Error("HTTP error! status: ".concat(response.status));
|
103
|
+
return [2 /*return*/, response.status === 204];
|
104
|
+
}
|
105
|
+
});
|
37
106
|
});
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
if (!response.ok)
|
43
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
44
|
-
return response.status === 204;
|
45
|
-
}
|
46
|
-
}
|
107
|
+
};
|
108
|
+
return ChannelsService;
|
109
|
+
}());
|
110
|
+
exports.ChannelsService = ChannelsService;
|
package/dist/services/chat.js
CHANGED
@@ -1,43 +1,97 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
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);
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
+
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;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
+
exports.ChatService = void 0;
|
40
|
+
var errors_1 = require("../errors");
|
41
|
+
var ChatService = /** @class */ (function () {
|
42
|
+
function ChatService(apiClient) {
|
4
43
|
this.apiClient = apiClient;
|
5
44
|
this.baseUrl = 'https://api.kick.com/public/v1/chat';
|
6
45
|
}
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
46
|
+
ChatService.prototype.sendMessage = function (options) {
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
48
|
+
var payload, response, error, result;
|
49
|
+
return __generator(this, function (_a) {
|
50
|
+
switch (_a.label) {
|
51
|
+
case 0:
|
52
|
+
payload = {
|
53
|
+
content: options.content,
|
54
|
+
type: options.type || 'bot'
|
55
|
+
};
|
56
|
+
if (payload.type === 'user') {
|
57
|
+
if (!options.broadcasterUserId) {
|
58
|
+
throw new Error('broadcaster_user_id is required for user type messages');
|
59
|
+
}
|
60
|
+
payload.broadcaster_user_id = options.broadcasterUserId;
|
61
|
+
}
|
62
|
+
if (payload.content.length > 500) {
|
63
|
+
throw new Error('Message content cannot exceed 500 characters');
|
64
|
+
}
|
65
|
+
if (!['user', 'bot'].includes(payload.type)) {
|
66
|
+
throw new Error('Message type must be either "user" or "bot"');
|
67
|
+
}
|
68
|
+
return [4 /*yield*/, fetch(this.baseUrl, {
|
69
|
+
method: 'POST',
|
70
|
+
headers: {
|
71
|
+
Authorization: "Bearer ".concat(options.token),
|
72
|
+
'Content-Type': 'application/json'
|
73
|
+
},
|
74
|
+
body: JSON.stringify(payload)
|
75
|
+
})];
|
76
|
+
case 1:
|
77
|
+
response = _a.sent();
|
78
|
+
if (response.status === 401)
|
79
|
+
throw new errors_1.UnauthorizedError();
|
80
|
+
if (response.status === 403)
|
81
|
+
throw new errors_1.ForbiddenError();
|
82
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
83
|
+
return [4 /*yield*/, response.json().catch(function () { return ({}); })];
|
84
|
+
case 2:
|
85
|
+
error = _a.sent();
|
86
|
+
throw new Error("HTTP error! status: ".concat(response.status, ", message: ").concat(error.message || 'Unknown error'));
|
87
|
+
case 3: return [4 /*yield*/, response.json()];
|
88
|
+
case 4:
|
89
|
+
result = _a.sent();
|
90
|
+
return [2 /*return*/, result.data || result];
|
91
|
+
}
|
92
|
+
});
|
31
93
|
});
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
if (!response.ok) {
|
37
|
-
const error = await response.json().catch(() => ({}));
|
38
|
-
throw new Error(`HTTP error! status: ${response.status}, message: ${error.message || 'Unknown error'}`);
|
39
|
-
}
|
40
|
-
const result = await response.json();
|
41
|
-
return result.data || result;
|
42
|
-
}
|
43
|
-
}
|
94
|
+
};
|
95
|
+
return ChatService;
|
96
|
+
}());
|
97
|
+
exports.ChatService = ChatService;
|
package/dist/services/events.js
CHANGED
@@ -1,100 +1,185 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
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);
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
+
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;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
+
exports.EventsService = void 0;
|
40
|
+
var signature_1 = require("../utils/signature");
|
41
|
+
var errors_1 = require("../errors");
|
42
|
+
var webhooks_1 = require("../types/webhooks");
|
43
|
+
var EventsService = /** @class */ (function () {
|
44
|
+
function EventsService(apiClient) {
|
6
45
|
this.verifier = null;
|
7
46
|
this.baseUrl = 'https://api.kick.com/public/v1/events';
|
8
47
|
this.apiClient = apiClient;
|
9
48
|
}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
this
|
14
|
-
|
15
|
-
|
16
|
-
|
49
|
+
EventsService.prototype.initializeVerifier = function () {
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
51
|
+
var publicKeyResponse;
|
52
|
+
return __generator(this, function (_a) {
|
53
|
+
switch (_a.label) {
|
54
|
+
case 0:
|
55
|
+
if (!!this.verifier) return [3 /*break*/, 2];
|
56
|
+
return [4 /*yield*/, this.apiClient.getPublicKey()];
|
57
|
+
case 1:
|
58
|
+
publicKeyResponse = _a.sent();
|
59
|
+
this.verifier = new signature_1.SignatureVerifier(publicKeyResponse.data.public_key);
|
60
|
+
_a.label = 2;
|
61
|
+
case 2: return [2 /*return*/];
|
62
|
+
}
|
63
|
+
});
|
64
|
+
});
|
65
|
+
};
|
66
|
+
EventsService.prototype.validateWebhook = function (headers, body) {
|
17
67
|
if (!this.verifier) {
|
18
68
|
throw new Error('Signature verifier not initialized');
|
19
69
|
}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
70
|
+
var messageId = headers['kick-event-message-id'];
|
71
|
+
var timestamp = headers['kick-event-message-timestamp'];
|
72
|
+
var signature = headers['kick-event-signature'];
|
73
|
+
var eventType = headers['kick-event-type'];
|
74
|
+
var version = headers['kick-event-version'];
|
25
75
|
if (!messageId || !timestamp || !signature) {
|
26
76
|
throw new Error('Missing required webhook headers');
|
27
77
|
}
|
28
|
-
|
29
|
-
|
78
|
+
var isValid = this.verifier.verify(messageId, timestamp, body, signature);
|
79
|
+
var parsedPayload = (0, webhooks_1.parseWebhookPayload)(eventType, JSON.parse(body));
|
30
80
|
return {
|
31
|
-
isValid,
|
32
|
-
eventType,
|
33
|
-
version,
|
34
|
-
messageId,
|
35
|
-
timestamp,
|
81
|
+
isValid: isValid,
|
82
|
+
eventType: eventType,
|
83
|
+
version: version,
|
84
|
+
messageId: messageId,
|
85
|
+
timestamp: timestamp,
|
36
86
|
payload: parsedPayload
|
37
87
|
};
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
88
|
+
};
|
89
|
+
EventsService.prototype.getSubscriptions = function (token) {
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
91
|
+
var response;
|
92
|
+
return __generator(this, function (_a) {
|
93
|
+
switch (_a.label) {
|
94
|
+
case 0: return [4 /*yield*/, fetch("".concat(this.baseUrl, "/subscriptions"), {
|
95
|
+
method: 'GET',
|
96
|
+
headers: {
|
97
|
+
Authorization: "Bearer ".concat(token)
|
98
|
+
}
|
99
|
+
})];
|
100
|
+
case 1:
|
101
|
+
response = _a.sent();
|
102
|
+
if (response.status === 401)
|
103
|
+
throw new errors_1.UnauthorizedError();
|
104
|
+
if (response.status === 403)
|
105
|
+
throw new errors_1.ForbiddenError();
|
106
|
+
if (!response.ok)
|
107
|
+
throw new Error("HTTP error! status: ".concat(response.status));
|
108
|
+
return [4 /*yield*/, response.json()];
|
109
|
+
case 2: return [2 /*return*/, _a.sent()];
|
110
|
+
}
|
111
|
+
});
|
45
112
|
});
|
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
|
-
|
113
|
+
};
|
114
|
+
EventsService.prototype.subscribe = function (events_1) {
|
115
|
+
return __awaiter(this, arguments, void 0, function (events, method, token) {
|
116
|
+
var webhookUrl, payload, response, error;
|
117
|
+
if (method === void 0) { method = 'webhook'; }
|
118
|
+
return __generator(this, function (_a) {
|
119
|
+
switch (_a.label) {
|
120
|
+
case 0:
|
121
|
+
webhookUrl = "".concat(this.apiClient.options.webhookBaseUrl, ":").concat(this.apiClient.options.webhookPort).concat(this.apiClient.options.webhookPath);
|
122
|
+
payload = {
|
123
|
+
method: method,
|
124
|
+
url: webhookUrl,
|
125
|
+
types: events.map(function (eventName) { return ({
|
126
|
+
name: eventName,
|
127
|
+
version: 1
|
128
|
+
}); })
|
129
|
+
};
|
130
|
+
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/subscriptions"), {
|
131
|
+
method: 'POST',
|
132
|
+
headers: {
|
133
|
+
Authorization: "Bearer ".concat(token),
|
134
|
+
'Content-Type': 'application/json'
|
135
|
+
},
|
136
|
+
body: JSON.stringify(payload)
|
137
|
+
})];
|
138
|
+
case 1:
|
139
|
+
response = _a.sent();
|
140
|
+
if (response.status === 401)
|
141
|
+
throw new errors_1.UnauthorizedError();
|
142
|
+
if (response.status === 403)
|
143
|
+
throw new errors_1.ForbiddenError();
|
144
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
145
|
+
return [4 /*yield*/, response.json().catch(function () { return ({}); })];
|
146
|
+
case 2:
|
147
|
+
error = _a.sent();
|
148
|
+
throw new Error("HTTP error! status: ".concat(response.status, ", message: ").concat(JSON.stringify(error)));
|
149
|
+
case 3: return [4 /*yield*/, response.json()];
|
150
|
+
case 4: return [2 /*return*/, _a.sent()];
|
151
|
+
}
|
152
|
+
});
|
71
153
|
});
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
154
|
+
};
|
155
|
+
EventsService.prototype.unsubscribe = function (subscriptionIds, token) {
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
157
|
+
var url, response;
|
158
|
+
return __generator(this, function (_a) {
|
159
|
+
switch (_a.label) {
|
160
|
+
case 0:
|
161
|
+
url = new URL("".concat(this.baseUrl, "/subscriptions"));
|
162
|
+
subscriptionIds.forEach(function (id) { return url.searchParams.append('id[]', id); });
|
163
|
+
return [4 /*yield*/, fetch(url.toString(), {
|
164
|
+
method: 'DELETE',
|
165
|
+
headers: {
|
166
|
+
Authorization: "Bearer ".concat(token)
|
167
|
+
}
|
168
|
+
})];
|
169
|
+
case 1:
|
170
|
+
response = _a.sent();
|
171
|
+
if (response.status === 401)
|
172
|
+
throw new errors_1.UnauthorizedError();
|
173
|
+
if (response.status === 403)
|
174
|
+
throw new errors_1.ForbiddenError();
|
175
|
+
if (!response.ok && response.status !== 204) {
|
176
|
+
throw new Error("HTTP error! status: ".concat(response.status));
|
177
|
+
}
|
178
|
+
return [2 /*return*/, response.status === 204];
|
179
|
+
}
|
180
|
+
});
|
90
181
|
});
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
if (!response.ok && response.status !== 204) {
|
96
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
97
|
-
}
|
98
|
-
return response.status === 204;
|
99
|
-
}
|
100
|
-
}
|
182
|
+
};
|
183
|
+
return EventsService;
|
184
|
+
}());
|
185
|
+
exports.EventsService = EventsService;
|