@digipair/skill-http 0.113.1 → 0.114.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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # skill-test
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build skill-http` to build the library.
@@ -1,25 +1,20 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _extends() {
6
- _extends = Object.assign || function assign(target) {
7
- for(var i = 1; i < arguments.length; i++){
8
- var source = arguments[i];
9
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
3
+ var FormDataNode = require('form-data');
15
4
 
16
5
  let HttpService = class HttpService {
6
+ constructor(_context, params){
7
+ const { type = 'json' } = params;
8
+ this.type = type;
9
+ }
17
10
  async call(url, method, data, headers, signal) {
18
- const requestHeaders = _extends({
19
- Accept: this.type === 'json' ? 'application/json' : '*/*'
20
- }, data ? {
21
- 'Content-Type': 'application/json'
22
- } : {}, headers);
11
+ const requestHeaders = {
12
+ Accept: this.type === 'json' ? 'application/json' : '*/*',
13
+ ...data ? {
14
+ 'Content-Type': 'application/json'
15
+ } : {},
16
+ ...headers
17
+ };
23
18
  let result;
24
19
  let body = undefined;
25
20
  if (requestHeaders['Content-Type'] === 'application/json') {
@@ -49,39 +44,32 @@ let HttpService = class HttpService {
49
44
  return result;
50
45
  }
51
46
  async create(params, _pinsSettingsList, context) {
52
- var _context_protected;
53
47
  const { path, body = {}, headers = {} } = params;
54
- return await this.call(path, 'POST', body, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
48
+ return await this.call(path, 'POST', body, headers, context.protected?.signal);
55
49
  }
56
50
  async read(params, _pinsSettingsList, context) {
57
- var _context_protected;
58
51
  const { path, headers = {} } = params;
59
- return await this.call(path, 'GET', null, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
52
+ return await this.call(path, 'GET', null, headers, context.protected?.signal);
60
53
  }
61
54
  async update(params, _pinsSettingsList, context) {
62
- var _context_protected;
63
55
  const { path, body = {}, headers = {} } = params;
64
- return await this.call(path, 'PUT', body, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
56
+ return await this.call(path, 'PUT', body, headers, context.protected?.signal);
65
57
  }
66
58
  async partialUpdate(params, _pinsSettingsList, context) {
67
- var _context_protected;
68
59
  const { path, body = {}, headers = {} } = params;
69
- return await this.call(path, 'PATCH', body, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
60
+ return await this.call(path, 'PATCH', body, headers, context.protected?.signal);
70
61
  }
71
62
  async remove(params, _pinsSettingsList, context) {
72
- var _context_protected;
73
63
  const { path, headers = {} } = params;
74
- return await this.call(path, 'DELETE', null, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
64
+ return await this.call(path, 'DELETE', null, headers, context.protected?.signal);
75
65
  }
76
66
  async request(params, _pinsSettingsList, context) {
77
- var _context_protected;
78
67
  const { path, method = 'GET', body = null, headers = {} } = params;
79
- return await this.call(path, method, body, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
68
+ return await this.call(path, method, body, headers, context.protected?.signal);
80
69
  }
81
70
  async upload(params, _pinsSettingsList, context) {
82
- var _context_protected;
83
71
  const { path, parameters, method = 'POST', headers = {} } = params;
84
- const formData = typeof window !== 'undefined' ? new FormData() : new (require('form-data'))();
72
+ const formData = typeof window !== 'undefined' ? new FormData() : new FormDataNode();
85
73
  let result;
86
74
  // Ajout des paramètres au FormData
87
75
  parameters.forEach((param)=>{
@@ -89,18 +77,21 @@ let HttpService = class HttpService {
89
77
  this.appendParam(formData, param);
90
78
  } else {
91
79
  param.value.forEach((item)=>{
92
- this.appendParam(formData, _extends({}, param, {
80
+ this.appendParam(formData, {
81
+ ...param,
93
82
  value: item
94
- }));
83
+ });
95
84
  });
96
85
  }
97
86
  });
98
87
  const response = await fetch(path, {
99
- signal: (_context_protected = context.protected) == null ? void 0 : _context_protected.signal,
88
+ signal: context.protected?.signal,
100
89
  method,
101
- headers: _extends({}, formData.getHeaders(), {
102
- Accept: this.type === 'json' ? 'application/json' : '*/*'
103
- }, headers),
90
+ headers: {
91
+ ...formData.getHeaders(),
92
+ Accept: this.type === 'json' ? 'application/json' : '*/*',
93
+ ...headers
94
+ },
104
95
  body: formData.getBuffer()
105
96
  });
106
97
  if (!response.ok) throw new Error('[SKILL-HTTP] REQUEST FAILED: ' + response.status);
@@ -132,10 +123,6 @@ let HttpService = class HttpService {
132
123
  });
133
124
  }
134
125
  }
135
- constructor(_context, params){
136
- const { type = 'json' } = params;
137
- this.type = type;
138
- }
139
126
  };
140
127
  const create = (params, pinsSettingsList, context)=>new HttpService(context, params).create(params, pinsSettingsList, context);
141
128
  const read = (params, pinsSettingsList, context)=>new HttpService(context, params).read(params, pinsSettingsList, context);
@@ -1,21 +1,18 @@
1
- function _extends() {
2
- _extends = Object.assign || function assign(target) {
3
- for(var i = 1; i < arguments.length; i++){
4
- var source = arguments[i];
5
- for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
6
- }
7
- return target;
8
- };
9
- return _extends.apply(this, arguments);
10
- }
1
+ import FormDataNode from 'form-data';
11
2
 
12
3
  let HttpService = class HttpService {
4
+ constructor(_context, params){
5
+ const { type = 'json' } = params;
6
+ this.type = type;
7
+ }
13
8
  async call(url, method, data, headers, signal) {
14
- const requestHeaders = _extends({
15
- Accept: this.type === 'json' ? 'application/json' : '*/*'
16
- }, data ? {
17
- 'Content-Type': 'application/json'
18
- } : {}, headers);
9
+ const requestHeaders = {
10
+ Accept: this.type === 'json' ? 'application/json' : '*/*',
11
+ ...data ? {
12
+ 'Content-Type': 'application/json'
13
+ } : {},
14
+ ...headers
15
+ };
19
16
  let result;
20
17
  let body = undefined;
21
18
  if (requestHeaders['Content-Type'] === 'application/json') {
@@ -45,39 +42,32 @@ let HttpService = class HttpService {
45
42
  return result;
46
43
  }
47
44
  async create(params, _pinsSettingsList, context) {
48
- var _context_protected;
49
45
  const { path, body = {}, headers = {} } = params;
50
- return await this.call(path, 'POST', body, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
46
+ return await this.call(path, 'POST', body, headers, context.protected?.signal);
51
47
  }
52
48
  async read(params, _pinsSettingsList, context) {
53
- var _context_protected;
54
49
  const { path, headers = {} } = params;
55
- return await this.call(path, 'GET', null, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
50
+ return await this.call(path, 'GET', null, headers, context.protected?.signal);
56
51
  }
57
52
  async update(params, _pinsSettingsList, context) {
58
- var _context_protected;
59
53
  const { path, body = {}, headers = {} } = params;
60
- return await this.call(path, 'PUT', body, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
54
+ return await this.call(path, 'PUT', body, headers, context.protected?.signal);
61
55
  }
62
56
  async partialUpdate(params, _pinsSettingsList, context) {
63
- var _context_protected;
64
57
  const { path, body = {}, headers = {} } = params;
65
- return await this.call(path, 'PATCH', body, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
58
+ return await this.call(path, 'PATCH', body, headers, context.protected?.signal);
66
59
  }
67
60
  async remove(params, _pinsSettingsList, context) {
68
- var _context_protected;
69
61
  const { path, headers = {} } = params;
70
- return await this.call(path, 'DELETE', null, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
62
+ return await this.call(path, 'DELETE', null, headers, context.protected?.signal);
71
63
  }
72
64
  async request(params, _pinsSettingsList, context) {
73
- var _context_protected;
74
65
  const { path, method = 'GET', body = null, headers = {} } = params;
75
- return await this.call(path, method, body, headers, (_context_protected = context.protected) == null ? void 0 : _context_protected.signal);
66
+ return await this.call(path, method, body, headers, context.protected?.signal);
76
67
  }
77
68
  async upload(params, _pinsSettingsList, context) {
78
- var _context_protected;
79
69
  const { path, parameters, method = 'POST', headers = {} } = params;
80
- const formData = typeof window !== 'undefined' ? new FormData() : new (require('form-data'))();
70
+ const formData = typeof window !== 'undefined' ? new FormData() : new FormDataNode();
81
71
  let result;
82
72
  // Ajout des paramètres au FormData
83
73
  parameters.forEach((param)=>{
@@ -85,18 +75,21 @@ let HttpService = class HttpService {
85
75
  this.appendParam(formData, param);
86
76
  } else {
87
77
  param.value.forEach((item)=>{
88
- this.appendParam(formData, _extends({}, param, {
78
+ this.appendParam(formData, {
79
+ ...param,
89
80
  value: item
90
- }));
81
+ });
91
82
  });
92
83
  }
93
84
  });
94
85
  const response = await fetch(path, {
95
- signal: (_context_protected = context.protected) == null ? void 0 : _context_protected.signal,
86
+ signal: context.protected?.signal,
96
87
  method,
97
- headers: _extends({}, formData.getHeaders(), {
98
- Accept: this.type === 'json' ? 'application/json' : '*/*'
99
- }, headers),
88
+ headers: {
89
+ ...formData.getHeaders(),
90
+ Accept: this.type === 'json' ? 'application/json' : '*/*',
91
+ ...headers
92
+ },
100
93
  body: formData.getBuffer()
101
94
  });
102
95
  if (!response.ok) throw new Error('[SKILL-HTTP] REQUEST FAILED: ' + response.status);
@@ -128,10 +121,6 @@ let HttpService = class HttpService {
128
121
  });
129
122
  }
130
123
  }
131
- constructor(_context, params){
132
- const { type = 'json' } = params;
133
- this.type = type;
134
- }
135
124
  };
136
125
  const create = (params, pinsSettingsList, context)=>new HttpService(context, params).create(params, pinsSettingsList, context);
137
126
  const read = (params, pinsSettingsList, context)=>new HttpService(context, params).read(params, pinsSettingsList, context);
@@ -0,0 +1,2 @@
1
+ export * from './lib/skill-http';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -6,3 +6,4 @@ export declare const partialUpdate: (params: any, pinsSettingsList: PinsSettings
6
6
  export declare const remove: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
7
7
  export declare const request: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
8
8
  export declare const upload: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
9
+ //# sourceMappingURL=skill-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-http.d.ts","sourceRoot":"","sources":["../../../src/lib/skill-http.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAuJhD,eAAO,MAAM,MAAM,GAAI,QAAQ,GAAG,EAAE,kBAAkB,YAAY,EAAE,EAAE,SAAS,GAAG,iBACN,CAAC;AAE7E,eAAO,MAAM,IAAI,GAAI,QAAQ,GAAG,EAAE,kBAAkB,YAAY,EAAE,EAAE,SAAS,GAAG,iBACN,CAAC;AAE3E,eAAO,MAAM,MAAM,GAAI,QAAQ,GAAG,EAAE,kBAAkB,YAAY,EAAE,EAAE,SAAS,GAAG,iBACN,CAAC;AAE7E,eAAO,MAAM,aAAa,GAAI,QAAQ,GAAG,EAAE,kBAAkB,YAAY,EAAE,EAAE,SAAS,GAAG,iBACb,CAAC;AAE7E,eAAO,MAAM,MAAM,GAAI,QAAQ,GAAG,EAAE,kBAAkB,YAAY,EAAE,EAAE,SAAS,GAAG,iBACN,CAAC;AAE7E,eAAO,MAAM,OAAO,GAAI,QAAQ,GAAG,EAAE,kBAAkB,YAAY,EAAE,EAAE,SAAS,GAAG,iBACN,CAAC;AAE9E,eAAO,MAAM,MAAM,GAAI,QAAQ,GAAG,EAAE,kBAAkB,YAAY,EAAE,EAAE,SAAS,GAAG,iBACN,CAAC"}
package/package.json CHANGED
@@ -1,15 +1,36 @@
1
1
  {
2
2
  "name": "@digipair/skill-http",
3
- "version": "0.113.1",
3
+ "version": "0.114.2",
4
+ "main": "./dist/index.cjs.js",
5
+ "module": "./dist/index.esm.js",
6
+ "types": "./dist/index.d.ts",
4
7
  "keywords": [
5
8
  "digipair",
6
9
  "web",
7
10
  "service",
8
11
  "tool"
9
12
  ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.esm.js",
17
+ "default": "./dist/index.cjs.js"
18
+ },
19
+ "./index.esm.js": "./dist/index.esm.js",
20
+ "./index.cjs.js": "./dist/index.cjs.js",
21
+ "./package.json": "./package.json",
22
+ "./schema.json": "./dist/schema.json",
23
+ "./schema.fr.json": "./dist/schema.fr.json"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "package.json"
29
+ ],
30
+ "nx": {
31
+ "name": "skill-http"
32
+ },
10
33
  "dependencies": {
11
34
  "form-data": "4.0.1"
12
- },
13
- "main": "./index.cjs.js",
14
- "module": "./index.esm.js"
15
- }
35
+ }
36
+ }
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './libs/skill-http/src/index';
@@ -1 +0,0 @@
1
- export * from './lib/skill-http';
File without changes
File without changes
File without changes