@chirpier/chirpier-js 0.1.6 → 0.2.0

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.
@@ -39,177 +39,476 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ var fs_1 = __importDefault(require("fs"));
43
+ var os_1 = __importDefault(require("os"));
44
+ var path_1 = __importDefault(require("path"));
45
+ var axios_1 = __importDefault(require("axios"));
46
+ var axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
42
47
  var index_1 = require("../index");
43
48
  var constants_1 = require("../constants");
44
- var axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
45
- var axios_1 = __importDefault(require("axios"));
46
49
  describe("Chirpier SDK", function () {
47
- describe("Initialization", function () {
48
- test("should throw error if monitor is called before initialize", function () {
49
- var event = {
50
- group_id: "bfd9299d-817a-452f-bc53-6e154f2281fc",
51
- stream_name: "test-stream",
52
- value: 1,
53
- };
54
- expect(function () { return (0, index_1.monitor)(event); }).toThrow(index_1.ChirpierError);
55
- expect(function () { return (0, index_1.monitor)(event); }).toThrow("Chirpier SDK is not initialized. Please call initialize() first.");
50
+ afterEach(function () { return __awaiter(void 0, void 0, void 0, function () {
51
+ return __generator(this, function (_a) {
52
+ switch (_a.label) {
53
+ case 0: return [4 /*yield*/, (0, index_1.stop)()];
54
+ case 1:
55
+ _a.sent();
56
+ return [2 /*return*/];
57
+ }
56
58
  });
57
- test("should initialize with default values", function () {
58
- (0, index_1.initialize)({
59
- key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
60
- logLevel: index_1.LogLevel.None,
59
+ }); });
60
+ describe("Initialization", function () {
61
+ test("should throw error if logEvent is called before initialize", function () { return __awaiter(void 0, void 0, void 0, function () {
62
+ var log;
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0:
66
+ log = {
67
+ event: "test-event",
68
+ value: 1,
69
+ };
70
+ return [4 /*yield*/, expect((0, index_1.logEvent)(log)).rejects.toThrow(index_1.ChirpierError)];
71
+ case 1:
72
+ _a.sent();
73
+ return [4 /*yield*/, expect((0, index_1.logEvent)(log)).rejects.toThrow("Chirpier SDK is not initialized. Please call initialize() first.")];
74
+ case 2:
75
+ _a.sent();
76
+ return [2 /*return*/];
77
+ }
61
78
  });
62
- var chirpier = index_1.Chirpier.getInstance({
63
- key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
79
+ }); });
80
+ test("should initialize with default values", function () { return __awaiter(void 0, void 0, void 0, function () {
81
+ var mock;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0:
85
+ mock = new axios_mock_adapter_1.default(axios_1.default);
86
+ mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
87
+ (0, index_1.initialize)({
88
+ key: "chp_test_default_key",
89
+ logLevel: 0 /* LogLevel.None */,
90
+ });
91
+ return [4 /*yield*/, (0, index_1.logEvent)({ event: "sdk.initialized", value: 1 })];
92
+ case 1:
93
+ _a.sent();
94
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
95
+ case 2:
96
+ _a.sent();
97
+ expect(mock.history.post[0].url).toBe(constants_1.DEFAULT_API_ENDPOINT);
98
+ return [2 /*return*/];
99
+ }
64
100
  });
65
- // Setup mock server
66
- var mock = new axios_mock_adapter_1.default(axios_1.default);
67
- mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
68
- expect(chirpier === null || chirpier === void 0 ? void 0 : chirpier["apiEndpoint"]).toBe(constants_1.DEFAULT_API_ENDPOINT);
69
- expect(chirpier === null || chirpier === void 0 ? void 0 : chirpier["retries"]).toBe(constants_1.DEFAULT_RETRIES);
70
- expect(chirpier === null || chirpier === void 0 ? void 0 : chirpier["timeout"]).toBe(constants_1.DEFAULT_TIMEOUT);
71
- expect(chirpier === null || chirpier === void 0 ? void 0 : chirpier["batchSize"]).toBe(constants_1.DEFAULT_BATCH_SIZE);
72
- expect(chirpier === null || chirpier === void 0 ? void 0 : chirpier["flushDelay"]).toBe(constants_1.DEFAULT_FLUSH_DELAY);
73
- index_1.Chirpier.stop();
74
- });
75
- test("should throw error if key is not provided", function () {
101
+ }); });
102
+ test("should initialize with custom apiEndpoint", function () { return __awaiter(void 0, void 0, void 0, function () {
103
+ var customEndpoint, mock;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0:
107
+ customEndpoint = "https://localhost:3001/v1.0/logs";
108
+ mock = new axios_mock_adapter_1.default(axios_1.default);
109
+ mock.onPost(customEndpoint).reply(200, { success: true });
110
+ (0, index_1.initialize)({
111
+ key: "chp_test_custom_endpoint",
112
+ apiEndpoint: customEndpoint,
113
+ logLevel: 0 /* LogLevel.None */,
114
+ });
115
+ return [4 /*yield*/, (0, index_1.logEvent)({ event: "sdk.custom-endpoint", value: 1 })];
116
+ case 1:
117
+ _a.sent();
118
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
119
+ case 2:
120
+ _a.sent();
121
+ expect(mock.history.post[0].url).toBe(customEndpoint);
122
+ return [2 /*return*/];
123
+ }
124
+ });
125
+ }); });
126
+ test("should throw error for invalid apiEndpoint", function () {
76
127
  expect(function () {
77
128
  (0, index_1.initialize)({
78
- key: "api_key",
79
- logLevel: index_1.LogLevel.None,
129
+ key: "chp_test_invalid_endpoint",
130
+ apiEndpoint: "not-a-url",
80
131
  });
81
- }).toThrow(index_1.ChirpierError);
132
+ }).toThrow("apiEndpoint must be a valid absolute URL");
133
+ });
134
+ test("should throw error for invalid key prefix", function () {
82
135
  expect(function () {
83
136
  (0, index_1.initialize)({
84
- key: "api_key",
85
- logLevel: index_1.LogLevel.None,
137
+ key: "invalid_key",
138
+ logLevel: 0 /* LogLevel.None */,
86
139
  });
87
- }).toThrow("Invalid API key: Not a valid JWT");
140
+ }).toThrow("Invalid API key: must start with 'chp_'");
141
+ });
142
+ test("should load key from process environment", function () {
143
+ var previousKey = process.env.CHIRPIER_API_KEY;
144
+ process.env.CHIRPIER_API_KEY = "chp_env_key";
145
+ try {
146
+ (0, index_1.initialize)({ logLevel: 0 /* LogLevel.None */ });
147
+ expect(function () { return (0, index_1.initialize)({ logLevel: 0 /* LogLevel.None */ }); }).not.toThrow();
148
+ }
149
+ finally {
150
+ if (previousKey === undefined) {
151
+ delete process.env.CHIRPIER_API_KEY;
152
+ }
153
+ else {
154
+ process.env.CHIRPIER_API_KEY = previousKey;
155
+ }
156
+ }
157
+ });
158
+ test("should load key from .env fallback", function () {
159
+ var previousKey = process.env.CHIRPIER_API_KEY;
160
+ var previousCwd = process.cwd();
161
+ var tempDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "chirpier-js-"));
162
+ try {
163
+ delete process.env.CHIRPIER_API_KEY;
164
+ fs_1.default.writeFileSync(path_1.default.join(tempDir, ".env"), "CHIRPIER_API_KEY=chp_dotenv_key\n");
165
+ process.chdir(tempDir);
166
+ (0, index_1.initialize)({ logLevel: 0 /* LogLevel.None */ });
167
+ expect(function () { return (0, index_1.initialize)({ logLevel: 0 /* LogLevel.None */ }); }).not.toThrow();
168
+ }
169
+ finally {
170
+ process.chdir(previousCwd);
171
+ if (previousKey === undefined) {
172
+ delete process.env.CHIRPIER_API_KEY;
173
+ }
174
+ else {
175
+ process.env.CHIRPIER_API_KEY = previousKey;
176
+ }
177
+ }
88
178
  });
89
179
  });
90
- describe("monitor", function () {
91
- test("event should be sent", function () { return __awaiter(void 0, void 0, void 0, function () {
92
- var mock, event;
180
+ describe("logEvent", function () {
181
+ test("log should be sent", function () { return __awaiter(void 0, void 0, void 0, function () {
182
+ var mock, log;
93
183
  return __generator(this, function (_a) {
94
184
  switch (_a.label) {
95
185
  case 0:
96
186
  mock = new axios_mock_adapter_1.default(axios_1.default);
97
187
  mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
98
188
  (0, index_1.initialize)({
99
- key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
100
- logLevel: index_1.LogLevel.None,
189
+ key: "chp_log_send_key",
190
+ logLevel: 0 /* LogLevel.None */,
101
191
  });
102
- event = {
103
- group_id: "bfd9299d-817a-452f-bc53-6e154f2281fc",
104
- stream_name: "test-stream",
192
+ log = {
193
+ agent_id: "api.worker",
194
+ event: "request.finished",
105
195
  value: 1,
106
196
  };
107
- (0, index_1.monitor)(event);
108
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
197
+ return [4 /*yield*/, (0, index_1.logEvent)(log)];
109
198
  case 1:
110
- _a.sent(); // Wait for flush
199
+ _a.sent();
200
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
201
+ case 2:
202
+ _a.sent();
111
203
  expect(mock.history.post.length).toBe(1);
112
204
  expect(mock.history.post[0].url).toBe(constants_1.DEFAULT_API_ENDPOINT);
113
205
  expect(JSON.parse(mock.history.post[0].data)).toEqual([
114
206
  {
115
- group_id: "bfd9299d-817a-452f-bc53-6e154f2281fc",
116
- stream_name: "test-stream",
207
+ agent_id: "api.worker",
208
+ event: "request.finished",
117
209
  value: 1,
118
210
  },
119
211
  ]);
120
- // Clean up the mock
121
- mock.reset();
122
- index_1.Chirpier.stop();
123
212
  return [2 /*return*/];
124
213
  }
125
214
  });
126
215
  }); });
127
- test("should silently drop invalid event", function () { return __awaiter(void 0, void 0, void 0, function () {
128
- var mock, invalidEvent, consoleSpy;
216
+ test("agent_id whitespace should be omitted", function () { return __awaiter(void 0, void 0, void 0, function () {
217
+ var mock, payload;
129
218
  return __generator(this, function (_a) {
130
219
  switch (_a.label) {
131
220
  case 0:
132
221
  mock = new axios_mock_adapter_1.default(axios_1.default);
133
222
  mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
134
223
  (0, index_1.initialize)({
135
- key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
136
- logLevel: index_1.LogLevel.Debug,
224
+ key: "chp_log_whitespace_agent",
225
+ logLevel: 0 /* LogLevel.None */,
137
226
  });
138
- invalidEvent = {
139
- group_id: "invalid-uuid",
140
- stream_name: "",
141
- value: 0,
142
- };
143
- consoleSpy = jest.spyOn(console, "debug");
144
- return [4 /*yield*/, (0, index_1.monitor)(invalidEvent)];
227
+ return [4 /*yield*/, (0, index_1.logEvent)({
228
+ agent_id: " ",
229
+ event: "metric.tick",
230
+ value: 42,
231
+ })];
145
232
  case 1:
146
233
  _a.sent();
147
- expect(consoleSpy).toHaveBeenCalledWith("Invalid event format, dropping event:", invalidEvent);
148
- expect(mock.history.post.length).toBe(0); // No request should be made
149
- // Clean up
150
- mock.reset();
151
- consoleSpy.mockRestore();
152
- index_1.Chirpier.stop();
234
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
235
+ case 2:
236
+ _a.sent();
237
+ payload = JSON.parse(mock.history.post[0].data);
238
+ expect(payload[0].agent_id).toBeUndefined();
153
239
  return [2 /*return*/];
154
240
  }
155
241
  });
156
242
  }); });
157
- test("should batch events and flush when batch size is reached", function () { return __awaiter(void 0, void 0, void 0, function () {
158
- var mock, event;
243
+ test("should support meta payload", function () { return __awaiter(void 0, void 0, void 0, function () {
244
+ var mock, payload;
159
245
  return __generator(this, function (_a) {
160
246
  switch (_a.label) {
161
247
  case 0:
162
248
  mock = new axios_mock_adapter_1.default(axios_1.default);
163
249
  mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
164
250
  (0, index_1.initialize)({
165
- key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
166
- logLevel: index_1.LogLevel.None,
251
+ key: "chp_log_meta_key",
252
+ logLevel: 0 /* LogLevel.None */,
167
253
  });
168
- event = {
169
- group_id: "bfd9299d-817a-452f-bc53-6e154f2281fc",
170
- stream_name: "test-stream",
171
- value: 1,
172
- };
173
- (0, index_1.monitor)(event);
174
- (0, index_1.monitor)(event);
254
+ return [4 /*yield*/, (0, index_1.logEvent)({
255
+ agent_id: "api.worker",
256
+ event: "request.finished",
257
+ value: 200,
258
+ meta: {
259
+ path: "/v1.0/logs",
260
+ status: "ok",
261
+ },
262
+ })];
263
+ case 1:
264
+ _a.sent();
175
265
  return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
266
+ case 2:
267
+ _a.sent();
268
+ payload = JSON.parse(mock.history.post[0].data);
269
+ expect(payload[0].meta.path).toBe("/v1.0/logs");
270
+ return [2 /*return*/];
271
+ }
272
+ });
273
+ }); });
274
+ test("should support occurred_at timestamp", function () { return __awaiter(void 0, void 0, void 0, function () {
275
+ var mock, occurredAt, payload;
276
+ return __generator(this, function (_a) {
277
+ switch (_a.label) {
278
+ case 0:
279
+ mock = new axios_mock_adapter_1.default(axios_1.default);
280
+ mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
281
+ (0, index_1.initialize)({
282
+ key: "chp_log_occurred_at_key",
283
+ logLevel: 0 /* LogLevel.None */,
284
+ });
285
+ occurredAt = new Date(Date.now() - 2 * 60 * 60 * 1000);
286
+ return [4 /*yield*/, (0, index_1.logEvent)({
287
+ event: "request.finished",
288
+ value: 1,
289
+ occurred_at: occurredAt,
290
+ })];
176
291
  case 1:
177
- _a.sent(); // Wait for flush
292
+ _a.sent();
293
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
294
+ case 2:
295
+ _a.sent();
296
+ payload = JSON.parse(mock.history.post[0].data);
297
+ expect(payload[0].occurred_at).toBe(occurredAt.toISOString());
298
+ return [2 /*return*/];
299
+ }
300
+ });
301
+ }); });
302
+ test("should throw error for invalid log", function () { return __awaiter(void 0, void 0, void 0, function () {
303
+ var mock;
304
+ return __generator(this, function (_a) {
305
+ switch (_a.label) {
306
+ case 0:
307
+ mock = new axios_mock_adapter_1.default(axios_1.default);
308
+ mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
309
+ (0, index_1.initialize)({
310
+ key: "chp_invalid_log_key",
311
+ logLevel: 3 /* LogLevel.Debug */,
312
+ });
313
+ return [4 /*yield*/, expect((0, index_1.logEvent)({
314
+ event: "",
315
+ value: 0,
316
+ })).rejects.toThrow(index_1.ChirpierError)];
317
+ case 1:
318
+ _a.sent();
319
+ return [4 /*yield*/, expect((0, index_1.logEvent)({
320
+ event: "too-old",
321
+ value: 1,
322
+ occurred_at: new Date(Date.now() - 31 * 24 * 60 * 60 * 1000),
323
+ })).rejects.toThrow(index_1.ChirpierError)];
324
+ case 2:
325
+ _a.sent();
326
+ return [4 /*yield*/, expect((0, index_1.logEvent)({
327
+ event: "too-future",
328
+ value: 1,
329
+ occurred_at: new Date(Date.now() + 25 * 60 * 60 * 1000),
330
+ })).rejects.toThrow(index_1.ChirpierError)];
331
+ case 3:
332
+ _a.sent();
333
+ expect(mock.history.post.length).toBe(0);
334
+ return [2 /*return*/];
335
+ }
336
+ });
337
+ }); });
338
+ test("should batch logs and flush when batch size is reached", function () { return __awaiter(void 0, void 0, void 0, function () {
339
+ var mock;
340
+ return __generator(this, function (_a) {
341
+ switch (_a.label) {
342
+ case 0:
343
+ mock = new axios_mock_adapter_1.default(axios_1.default);
344
+ mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
345
+ (0, index_1.initialize)({
346
+ key: "chp_batch_key",
347
+ logLevel: 0 /* LogLevel.None */,
348
+ });
349
+ return [4 /*yield*/, (0, index_1.logEvent)({ event: "batch.event", value: 1 })];
350
+ case 1:
351
+ _a.sent();
352
+ return [4 /*yield*/, (0, index_1.logEvent)({ event: "batch.event", value: 2 })];
353
+ case 2:
354
+ _a.sent();
355
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
356
+ case 3:
357
+ _a.sent();
178
358
  expect(mock.history.post.length).toBe(1);
179
359
  expect(JSON.parse(mock.history.post[0].data).length).toBe(2);
180
- mock.reset();
181
- index_1.Chirpier.stop();
182
360
  return [2 /*return*/];
183
361
  }
184
362
  });
185
363
  }); });
186
- test("should flush events after interval", function () { return __awaiter(void 0, void 0, void 0, function () {
187
- var mock, event;
364
+ });
365
+ describe("Client API", function () {
366
+ test("createClient supports direct logging", function () { return __awaiter(void 0, void 0, void 0, function () {
367
+ var mock, client;
368
+ return __generator(this, function (_a) {
369
+ switch (_a.label) {
370
+ case 0:
371
+ mock = new axios_mock_adapter_1.default(axios_1.default);
372
+ mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
373
+ client = (0, index_1.createClient)({ key: "chp_direct_client_key" });
374
+ return [4 /*yield*/, client.log({
375
+ event: "direct.client.log",
376
+ value: 1,
377
+ })];
378
+ case 1:
379
+ _a.sent();
380
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
381
+ case 2:
382
+ _a.sent();
383
+ expect(mock.history.post.length).toBe(1);
384
+ expect(JSON.parse(mock.history.post[0].data)[0].event).toBe("direct.client.log");
385
+ return [4 /*yield*/, client.shutdown()];
386
+ case 3:
387
+ _a.sent();
388
+ return [2 /*return*/];
389
+ }
390
+ });
391
+ }); });
392
+ test("flush should force delivery of queued logs", function () { return __awaiter(void 0, void 0, void 0, function () {
393
+ var mock;
188
394
  return __generator(this, function (_a) {
189
395
  switch (_a.label) {
190
396
  case 0:
191
397
  mock = new axios_mock_adapter_1.default(axios_1.default);
192
398
  mock.onPost(constants_1.DEFAULT_API_ENDPOINT).reply(200, { success: true });
193
399
  (0, index_1.initialize)({
194
- key: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
195
- logLevel: index_1.LogLevel.None,
400
+ key: "chp_flush_key",
401
+ logLevel: 0 /* LogLevel.None */,
402
+ flushDelay: 10000,
196
403
  });
197
- event = {
198
- group_id: "bfd9299d-817a-452f-bc53-6e154f2281fc",
199
- stream_name: "test-stream",
200
- value: 1,
201
- };
202
- (0, index_1.monitor)(event);
203
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
404
+ return [4 /*yield*/, (0, index_1.logEvent)({ event: "queued.before.flush", value: 1 })];
204
405
  case 1:
205
- _a.sent(); // Wait for flush
406
+ _a.sent();
407
+ expect(mock.history.post.length).toBe(0);
408
+ return [4 /*yield*/, (0, index_1.flush)()];
409
+ case 2:
410
+ _a.sent();
206
411
  expect(mock.history.post.length).toBe(1);
207
- expect(JSON.parse(mock.history.post[0].data).length).toBe(1);
208
- mock.reset();
209
- index_1.Chirpier.stop();
412
+ expect(JSON.parse(mock.history.post[0].data)[0].event).toBe("queued.before.flush");
210
413
  return [2 /*return*/];
211
414
  }
212
415
  });
213
416
  }); });
417
+ test("getEventLogs uses servicer endpoint with period, limit, and offset", function () { return __awaiter(void 0, void 0, void 0, function () {
418
+ var mock, client;
419
+ return __generator(this, function (_a) {
420
+ switch (_a.label) {
421
+ case 0:
422
+ mock = new axios_mock_adapter_1.default(axios_1.default);
423
+ mock.onGet("https://api.chirpier.co/v1.0/events/evt_123/logs?period=hour&limit=25&offset=10").reply(200, []);
424
+ client = (0, index_1.createClient)({ key: "chp_client_logs_key" });
425
+ _a.label = 1;
426
+ case 1:
427
+ _a.trys.push([1, , 3, 5]);
428
+ return [4 /*yield*/, client.getEventLogs("evt_123", { period: "hour", limit: 25, offset: 10 })];
429
+ case 2:
430
+ _a.sent();
431
+ expect(mock.history.get[0].url).toBe("https://api.chirpier.co/v1.0/events/evt_123/logs?period=hour&limit=25&offset=10");
432
+ return [3 /*break*/, 5];
433
+ case 3: return [4 /*yield*/, client.shutdown()];
434
+ case 4:
435
+ _a.sent();
436
+ return [7 /*endfinally*/];
437
+ case 5: return [2 /*return*/];
438
+ }
439
+ });
440
+ }); });
441
+ test("getAlertDeliveries uses pagination params", function () { return __awaiter(void 0, void 0, void 0, function () {
442
+ var mock, client;
443
+ return __generator(this, function (_a) {
444
+ switch (_a.label) {
445
+ case 0:
446
+ mock = new axios_mock_adapter_1.default(axios_1.default);
447
+ mock.onGet("https://api.chirpier.co/v1.0/alerts/alrt_123/deliveries?kind=test&limit=20&offset=5").reply(200, []);
448
+ client = (0, index_1.createClient)({ key: "chp_client_alert_key" });
449
+ _a.label = 1;
450
+ case 1:
451
+ _a.trys.push([1, , 3, 5]);
452
+ return [4 /*yield*/, client.getAlertDeliveries("alrt_123", { kind: "test", limit: 20, offset: 5 })];
453
+ case 2:
454
+ _a.sent();
455
+ expect(mock.history.get[0].url).toBe("https://api.chirpier.co/v1.0/alerts/alrt_123/deliveries?kind=test&limit=20&offset=5");
456
+ return [3 /*break*/, 5];
457
+ case 3: return [4 /*yield*/, client.shutdown()];
458
+ case 4:
459
+ _a.sent();
460
+ return [7 /*endfinally*/];
461
+ case 5: return [2 /*return*/];
462
+ }
463
+ });
464
+ }); });
465
+ test("archiveAlert posts to servicer endpoint", function () { return __awaiter(void 0, void 0, void 0, function () {
466
+ var mock, client;
467
+ return __generator(this, function (_a) {
468
+ switch (_a.label) {
469
+ case 0:
470
+ mock = new axios_mock_adapter_1.default(axios_1.default);
471
+ mock.onPost("https://api.chirpier.co/v1.0/alerts/alrt_123/archive").reply(200, {});
472
+ client = (0, index_1.createClient)({ key: "chp_client_alert_key" });
473
+ _a.label = 1;
474
+ case 1:
475
+ _a.trys.push([1, , 3, 5]);
476
+ return [4 /*yield*/, client.archiveAlert("alrt_123")];
477
+ case 2:
478
+ _a.sent();
479
+ expect(mock.history.post[0].url).toBe("https://api.chirpier.co/v1.0/alerts/alrt_123/archive");
480
+ return [3 /*break*/, 5];
481
+ case 3: return [4 /*yield*/, client.shutdown()];
482
+ case 4:
483
+ _a.sent();
484
+ return [7 /*endfinally*/];
485
+ case 5: return [2 /*return*/];
486
+ }
487
+ });
488
+ }); });
489
+ test("testWebhook posts to servicer endpoint", function () { return __awaiter(void 0, void 0, void 0, function () {
490
+ var mock, client;
491
+ return __generator(this, function (_a) {
492
+ switch (_a.label) {
493
+ case 0:
494
+ mock = new axios_mock_adapter_1.default(axios_1.default);
495
+ mock.onPost("https://api.chirpier.co/v1.0/webhooks/whk_123/test").reply(200);
496
+ client = (0, index_1.createClient)({ key: "chp_client_webhook_key" });
497
+ _a.label = 1;
498
+ case 1:
499
+ _a.trys.push([1, , 3, 5]);
500
+ return [4 /*yield*/, client.testWebhook("whk_123")];
501
+ case 2:
502
+ _a.sent();
503
+ expect(mock.history.post[0].url).toBe("https://api.chirpier.co/v1.0/webhooks/whk_123/test");
504
+ return [3 /*break*/, 5];
505
+ case 3: return [4 /*yield*/, client.shutdown()];
506
+ case 4:
507
+ _a.sent();
508
+ return [7 /*endfinally*/];
509
+ case 5: return [2 /*return*/];
510
+ }
511
+ });
512
+ }); });
214
513
  });
215
514
  });
@@ -1,7 +1,8 @@
1
- export declare const DEFAULT_RETRIES = 15;
2
- export declare const DEFAULT_TIMEOUT = 5000;
3
- export declare const DEFAULT_BATCH_SIZE = 350;
4
- export declare const DEFAULT_FLUSH_DELAY = 500;
5
- export declare const MAX_QUEUE_SIZE = 50000;
6
- export declare const DEFAULT_API_ENDPOINT = "https://eu-west.chirpier.co/v1.0/events";
1
+ export declare const DEFAULT_RETRIES: 15;
2
+ export declare const DEFAULT_TIMEOUT: 5000;
3
+ export declare const DEFAULT_BATCH_SIZE: 500;
4
+ export declare const DEFAULT_FLUSH_DELAY: 500;
5
+ export declare const MAX_QUEUE_SIZE: 5000;
6
+ export declare const DEFAULT_API_ENDPOINT: "https://logs.chirpier.co/v1.0/logs";
7
+ export declare const DEFAULT_SERVICER_ENDPOINT: "https://api.chirpier.co/v1.0";
7
8
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,eAAe,OAAO,CAAA;AACnC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,cAAc,QAAQ,CAAC;AACpC,eAAO,MAAM,oBAAoB,4CAA4C,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,IAAc,CAAC;AAC3C,eAAO,MAAM,eAAe,MAAgB,CAAC;AAC7C,eAAO,MAAM,kBAAkB,KAAe,CAAC;AAC/C,eAAO,MAAM,mBAAmB,KAAe,CAAC;AAChD,eAAO,MAAM,cAAc,MAAgB,CAAC;AAC5C,eAAO,MAAM,oBAAoB,sCAAgD,CAAC;AAClF,eAAO,MAAM,yBAAyB,gCAA0C,CAAC"}
package/dist/constants.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  // constants.ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.DEFAULT_API_ENDPOINT = exports.MAX_QUEUE_SIZE = exports.DEFAULT_FLUSH_DELAY = exports.DEFAULT_BATCH_SIZE = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RETRIES = void 0;
4
+ exports.DEFAULT_SERVICER_ENDPOINT = exports.DEFAULT_API_ENDPOINT = exports.MAX_QUEUE_SIZE = exports.DEFAULT_FLUSH_DELAY = exports.DEFAULT_BATCH_SIZE = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RETRIES = void 0;
5
5
  exports.DEFAULT_RETRIES = 15;
6
6
  exports.DEFAULT_TIMEOUT = 5000;
7
- exports.DEFAULT_BATCH_SIZE = 350;
7
+ exports.DEFAULT_BATCH_SIZE = 500;
8
8
  exports.DEFAULT_FLUSH_DELAY = 500;
9
- exports.MAX_QUEUE_SIZE = 50000;
10
- exports.DEFAULT_API_ENDPOINT = "https://eu-west.chirpier.co/v1.0/events";
9
+ exports.MAX_QUEUE_SIZE = 5000;
10
+ exports.DEFAULT_API_ENDPOINT = "https://logs.chirpier.co/v1.0/logs";
11
+ exports.DEFAULT_SERVICER_ENDPOINT = "https://api.chirpier.co/v1.0";