@unito/integration-sdk 2.3.5 → 2.3.6

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.
@@ -1440,13 +1440,18 @@ class Provider {
1440
1440
  * @param options RequestOptions used to adjust the call made to the provider (use to override default headers).
1441
1441
  * @returns The {@link Response} extracted from the provider.
1442
1442
  */
1443
- async delete(endpoint, options) {
1444
- return this.fetchWrapper(endpoint, null, {
1443
+ async delete(endpoint, options, body = null) {
1444
+ const defaultHeaders = {
1445
+ Accept: 'application/json',
1446
+ };
1447
+ // Only add Content-Type header when body is provided
1448
+ if (body !== null) {
1449
+ defaultHeaders['Content-Type'] = 'application/json';
1450
+ }
1451
+ return this.fetchWrapper(endpoint, body, {
1445
1452
  ...options,
1446
1453
  method: 'DELETE',
1447
- defaultHeaders: {
1448
- Accept: 'application/json',
1449
- },
1454
+ defaultHeaders,
1450
1455
  });
1451
1456
  }
1452
1457
  generateAbsoluteUrl(providerUrl, endpoint, queryParams) {
@@ -207,7 +207,7 @@ export declare class Provider {
207
207
  * @param options RequestOptions used to adjust the call made to the provider (use to override default headers).
208
208
  * @returns The {@link Response} extracted from the provider.
209
209
  */
210
- delete<T = undefined>(endpoint: string, options: RequestOptions): Promise<Response<T>>;
210
+ delete<T = undefined>(endpoint: string, options: RequestOptions, body?: RequestBody | null): Promise<Response<T>>;
211
211
  private generateAbsoluteUrl;
212
212
  private fetchWrapper;
213
213
  private handleError;
@@ -241,13 +241,18 @@ export class Provider {
241
241
  * @param options RequestOptions used to adjust the call made to the provider (use to override default headers).
242
242
  * @returns The {@link Response} extracted from the provider.
243
243
  */
244
- async delete(endpoint, options) {
245
- return this.fetchWrapper(endpoint, null, {
244
+ async delete(endpoint, options, body = null) {
245
+ const defaultHeaders = {
246
+ Accept: 'application/json',
247
+ };
248
+ // Only add Content-Type header when body is provided
249
+ if (body !== null) {
250
+ defaultHeaders['Content-Type'] = 'application/json';
251
+ }
252
+ return this.fetchWrapper(endpoint, body, {
246
253
  ...options,
247
254
  method: 'DELETE',
248
- defaultHeaders: {
249
- Accept: 'application/json',
250
- },
255
+ defaultHeaders,
251
256
  });
252
257
  }
253
258
  generateAbsoluteUrl(providerUrl, endpoint, queryParams) {
@@ -404,6 +404,37 @@ describe('Provider', () => {
404
404
  ]);
405
405
  assert.deepEqual(actualResponse, { status: 204, headers: response.headers, body: undefined });
406
406
  });
407
+ it('deleteWithBody', async (context) => {
408
+ const response = new Response('{"success": true}', {
409
+ status: 200,
410
+ headers: { 'Content-Type': 'application/json' },
411
+ });
412
+ const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
413
+ const requestBody = { webhookIds: [1, 2, 3] };
414
+ const actualResponse = await provider.delete('/webhook', {
415
+ credentials: { apiKey: 'apikey#1111', unitoCredentialId: '123' },
416
+ logger: logger,
417
+ signal: new AbortController().signal,
418
+ additionnalheaders: { 'X-Additional-Header': 'value1' },
419
+ }, requestBody);
420
+ assert.equal(fetchMock.mock.calls.length, 1);
421
+ assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
422
+ 'www.myApi.com/webhook',
423
+ {
424
+ method: 'DELETE',
425
+ body: JSON.stringify(requestBody),
426
+ signal: new AbortController().signal,
427
+ headers: {
428
+ 'Content-Type': 'application/json',
429
+ Accept: 'application/json',
430
+ 'X-Custom-Provider-Header': 'value',
431
+ 'X-Provider-Credential-Header': 'apikey#1111',
432
+ 'X-Additional-Header': 'value1',
433
+ },
434
+ },
435
+ ]);
436
+ assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { success: true } });
437
+ });
407
438
  it('uses rate limiter if provided', async (context) => {
408
439
  const mockRateLimiter = context.mock.fn((_context, request) => Promise.resolve(request()));
409
440
  const rateLimitedProvider = new Provider({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -336,13 +336,24 @@ export class Provider {
336
336
  * @param options RequestOptions used to adjust the call made to the provider (use to override default headers).
337
337
  * @returns The {@link Response} extracted from the provider.
338
338
  */
339
- public async delete<T = undefined>(endpoint: string, options: RequestOptions): Promise<Response<T>> {
340
- return this.fetchWrapper<T>(endpoint, null, {
339
+ public async delete<T = undefined>(
340
+ endpoint: string,
341
+ options: RequestOptions,
342
+ body: RequestBody | null = null,
343
+ ): Promise<Response<T>> {
344
+ const defaultHeaders: { Accept: string; 'Content-Type'?: string } = {
345
+ Accept: 'application/json',
346
+ };
347
+
348
+ // Only add Content-Type header when body is provided
349
+ if (body !== null) {
350
+ defaultHeaders['Content-Type'] = 'application/json';
351
+ }
352
+
353
+ return this.fetchWrapper<T>(endpoint, body, {
341
354
  ...options,
342
355
  method: 'DELETE',
343
- defaultHeaders: {
344
- Accept: 'application/json',
345
- },
356
+ defaultHeaders,
346
357
  });
347
358
  }
348
359
 
@@ -486,6 +486,45 @@ describe('Provider', () => {
486
486
  assert.deepEqual(actualResponse, { status: 204, headers: response.headers, body: undefined });
487
487
  });
488
488
 
489
+ it('deleteWithBody', async context => {
490
+ const response = new Response('{"success": true}', {
491
+ status: 200,
492
+ headers: { 'Content-Type': 'application/json' },
493
+ });
494
+
495
+ const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
496
+
497
+ const requestBody = { webhookIds: [1, 2, 3] };
498
+ const actualResponse = await provider.delete(
499
+ '/webhook',
500
+ {
501
+ credentials: { apiKey: 'apikey#1111', unitoCredentialId: '123' },
502
+ logger: logger,
503
+ signal: new AbortController().signal,
504
+ additionnalheaders: { 'X-Additional-Header': 'value1' },
505
+ },
506
+ requestBody,
507
+ );
508
+
509
+ assert.equal(fetchMock.mock.calls.length, 1);
510
+ assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
511
+ 'www.myApi.com/webhook',
512
+ {
513
+ method: 'DELETE',
514
+ body: JSON.stringify(requestBody),
515
+ signal: new AbortController().signal,
516
+ headers: {
517
+ 'Content-Type': 'application/json',
518
+ Accept: 'application/json',
519
+ 'X-Custom-Provider-Header': 'value',
520
+ 'X-Provider-Credential-Header': 'apikey#1111',
521
+ 'X-Additional-Header': 'value1',
522
+ },
523
+ },
524
+ ]);
525
+ assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { success: true } });
526
+ });
527
+
489
528
  it('uses rate limiter if provided', async context => {
490
529
  const mockRateLimiter = context.mock.fn((_context, request) => Promise.resolve(request()));
491
530