@digipair/skill-http 0.17.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.
package/index.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.cjs.js ADDED
@@ -0,0 +1,70 @@
1
+ 'use strict';
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
+ }
15
+
16
+ let HttpService = class HttpService {
17
+ async call(url, method, data = null, headers = {}) {
18
+ const response = await fetch(url, {
19
+ method,
20
+ headers: _extends({
21
+ Accept: 'application/json',
22
+ 'Content-Type': 'application/json'
23
+ }, headers),
24
+ body: data ? this.IS_JSON ? JSON.stringify(data) : data : undefined
25
+ });
26
+ if (!response.ok) throw new Error('[SKILL-HTTP] REQUEST FAILED: ' + response.status);
27
+ return await this.IS_JSON ? response.json() : response.text();
28
+ }
29
+ async create(params, _pinsSettingsList, _context) {
30
+ const { path, body = {}, headers = {} } = params;
31
+ return await this.call(path, 'POST', body, headers);
32
+ }
33
+ async read(params, _pinsSettingsList, _context) {
34
+ const { path, headers = {} } = params;
35
+ return await this.call(path, 'GET', null, headers);
36
+ }
37
+ async update(params, _pinsSettingsList, _context) {
38
+ const { path, body = {}, headers = {} } = params;
39
+ return await this.call(path, 'PUT', body, headers);
40
+ }
41
+ async partialUpdate(params, _pinsSettingsList, _context) {
42
+ const { path, body = {}, headers = {} } = params;
43
+ return await this.call(path, 'PATCH', body, headers);
44
+ }
45
+ async remove(params, _pinsSettingsList, _context) {
46
+ const { path, headers = {} } = params;
47
+ return await this.call(path, 'DELETE', null, headers);
48
+ }
49
+ async request(params, _pinsSettingsList, _context) {
50
+ const { path, method = 'GET', body = null, headers = {} } = params;
51
+ return await this.call(path, method, body, headers);
52
+ }
53
+ constructor(_context, params){
54
+ const { IS_JSON = true } = params;
55
+ this.IS_JSON = IS_JSON;
56
+ }
57
+ };
58
+ const create = (params, pinsSettingsList, context)=>new HttpService(context, params).create(params, pinsSettingsList, context);
59
+ const read = (params, pinsSettingsList, context)=>new HttpService(context, params).read(params, pinsSettingsList, context);
60
+ const update = (params, pinsSettingsList, context)=>new HttpService(context, params).update(params, pinsSettingsList, context);
61
+ const partialUpdate = (params, pinsSettingsList, context)=>new HttpService(context, params).update(params, pinsSettingsList, context);
62
+ const remove = (params, pinsSettingsList, context)=>new HttpService(context, params).remove(params, pinsSettingsList, context);
63
+ const request = (params, pinsSettingsList, context)=>new HttpService(context, params).request(params, pinsSettingsList, context);
64
+
65
+ exports.create = create;
66
+ exports.partialUpdate = partialUpdate;
67
+ exports.read = read;
68
+ exports.remove = remove;
69
+ exports.request = request;
70
+ exports.update = update;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './libs/skill-http/src/index';
package/index.esm.js ADDED
@@ -0,0 +1,61 @@
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
+ }
11
+
12
+ let HttpService = class HttpService {
13
+ async call(url, method, data = null, headers = {}) {
14
+ const response = await fetch(url, {
15
+ method,
16
+ headers: _extends({
17
+ Accept: 'application/json',
18
+ 'Content-Type': 'application/json'
19
+ }, headers),
20
+ body: data ? this.IS_JSON ? JSON.stringify(data) : data : undefined
21
+ });
22
+ if (!response.ok) throw new Error('[SKILL-HTTP] REQUEST FAILED: ' + response.status);
23
+ return await this.IS_JSON ? response.json() : response.text();
24
+ }
25
+ async create(params, _pinsSettingsList, _context) {
26
+ const { path, body = {}, headers = {} } = params;
27
+ return await this.call(path, 'POST', body, headers);
28
+ }
29
+ async read(params, _pinsSettingsList, _context) {
30
+ const { path, headers = {} } = params;
31
+ return await this.call(path, 'GET', null, headers);
32
+ }
33
+ async update(params, _pinsSettingsList, _context) {
34
+ const { path, body = {}, headers = {} } = params;
35
+ return await this.call(path, 'PUT', body, headers);
36
+ }
37
+ async partialUpdate(params, _pinsSettingsList, _context) {
38
+ const { path, body = {}, headers = {} } = params;
39
+ return await this.call(path, 'PATCH', body, headers);
40
+ }
41
+ async remove(params, _pinsSettingsList, _context) {
42
+ const { path, headers = {} } = params;
43
+ return await this.call(path, 'DELETE', null, headers);
44
+ }
45
+ async request(params, _pinsSettingsList, _context) {
46
+ const { path, method = 'GET', body = null, headers = {} } = params;
47
+ return await this.call(path, method, body, headers);
48
+ }
49
+ constructor(_context, params){
50
+ const { IS_JSON = true } = params;
51
+ this.IS_JSON = IS_JSON;
52
+ }
53
+ };
54
+ const create = (params, pinsSettingsList, context)=>new HttpService(context, params).create(params, pinsSettingsList, context);
55
+ const read = (params, pinsSettingsList, context)=>new HttpService(context, params).read(params, pinsSettingsList, context);
56
+ const update = (params, pinsSettingsList, context)=>new HttpService(context, params).update(params, pinsSettingsList, context);
57
+ const partialUpdate = (params, pinsSettingsList, context)=>new HttpService(context, params).update(params, pinsSettingsList, context);
58
+ const remove = (params, pinsSettingsList, context)=>new HttpService(context, params).remove(params, pinsSettingsList, context);
59
+ const request = (params, pinsSettingsList, context)=>new HttpService(context, params).request(params, pinsSettingsList, context);
60
+
61
+ export { create, partialUpdate, read, remove, request, update };
@@ -0,0 +1 @@
1
+ export * from './lib/skill-http';
@@ -0,0 +1,7 @@
1
+ import { PinsSettings } from '@digipair/engine';
2
+ export declare const create: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
3
+ export declare const read: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
4
+ export declare const update: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
5
+ export declare const partialUpdate: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
6
+ export declare const remove: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
7
+ export declare const request: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
package/package.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@digipair/skill-http",
3
+ "version": "0.17.0",
4
+ "dependencies": {},
5
+ "main": "./index.cjs.js",
6
+ "module": "./index.esm.js"
7
+ }
package/schema.json ADDED
@@ -0,0 +1,277 @@
1
+ {
2
+ "openapi": "3.0.0",
3
+ "info": {
4
+ "title": "@digipair/skill-http",
5
+ "summary": "Communication avec les services HTTP",
6
+ "description": "Cette compétence permet d'utiliser les services HTTP",
7
+ "version": "0.1.0",
8
+ "x-icon": ""
9
+ },
10
+ "paths": {
11
+ "/request": {
12
+ "post": {
13
+ "tags": ["service"],
14
+ "summary": "Exécute un service HTTP",
15
+ "parameters": [
16
+ {
17
+ "name": "url",
18
+ "summary": "Adresse du service",
19
+ "required": true,
20
+ "description": "Adresse du service à exécuter",
21
+ "schema": {
22
+ "type": "string"
23
+ }
24
+ },
25
+ {
26
+ "name": "method",
27
+ "summary": "Méthode HTTP",
28
+ "required": false,
29
+ "description": "Méthode HTTP à utiliser",
30
+ "schema": {
31
+ "type": "string"
32
+ }
33
+ },
34
+ {
35
+ "name": "body",
36
+ "summary": "Valeur",
37
+ "required": false,
38
+ "description": "Valeur à envoyer",
39
+ "schema": {
40
+ "type": "object"
41
+ }
42
+ },
43
+ {
44
+ "name": "headers",
45
+ "summary": "En-têtes",
46
+ "required": false,
47
+ "description": "En-têtes à envoyer",
48
+ "schema": {
49
+ "type": "object"
50
+ }
51
+ },
52
+ {
53
+ "name": "IS_JSON",
54
+ "summary": "API JSON",
55
+ "required": false,
56
+ "description": "Indique si l'API est en JSON",
57
+ "schema": {
58
+ "type": "boolean"
59
+ }
60
+ }
61
+ ],
62
+ "x-events": []
63
+ }
64
+ },
65
+ "/create": {
66
+ "post": {
67
+ "tags": ["service"],
68
+ "summary": "Ajoute une ressource HTTP",
69
+ "parameters": [
70
+ {
71
+ "name": "url",
72
+ "summary": "Adresse du service",
73
+ "required": true,
74
+ "description": "Adresse du service à exécuter",
75
+ "schema": {
76
+ "type": "string"
77
+ }
78
+ },
79
+ {
80
+ "name": "body",
81
+ "summary": "Valeur",
82
+ "required": false,
83
+ "description": "Valeur à envoyer",
84
+ "schema": {
85
+ "type": "object"
86
+ }
87
+ },
88
+ {
89
+ "name": "headers",
90
+ "summary": "En-têtes",
91
+ "required": false,
92
+ "description": "En-têtes à envoyer",
93
+ "schema": {
94
+ "type": "object"
95
+ }
96
+ },
97
+ {
98
+ "name": "IS_JSON",
99
+ "summary": "API JSON",
100
+ "required": false,
101
+ "description": "Indique si l'API est en JSON",
102
+ "schema": {
103
+ "type": "boolean"
104
+ }
105
+ }
106
+ ],
107
+ "x-events": []
108
+ }
109
+ },
110
+ "/read": {
111
+ "post": {
112
+ "tags": ["service"],
113
+ "summary": "Lit une ressource HTTP",
114
+ "parameters": [
115
+ {
116
+ "name": "url",
117
+ "summary": "Adresse du service",
118
+ "required": true,
119
+ "description": "Adresse du service à exécuter",
120
+ "schema": {
121
+ "type": "string"
122
+ }
123
+ },
124
+ {
125
+ "name": "headers",
126
+ "summary": "En-têtes",
127
+ "required": false,
128
+ "description": "En-têtes à envoyer",
129
+ "schema": {
130
+ "type": "object"
131
+ }
132
+ },
133
+ {
134
+ "name": "IS_JSON",
135
+ "summary": "API JSON",
136
+ "required": false,
137
+ "description": "Indique si l'API est en JSON",
138
+ "schema": {
139
+ "type": "boolean"
140
+ }
141
+ }
142
+ ],
143
+ "x-events": []
144
+ }
145
+ },
146
+ "/update": {
147
+ "post": {
148
+ "tags": ["service"],
149
+ "summary": "Modifie une ressource HTTP",
150
+ "parameters": [
151
+ {
152
+ "name": "url",
153
+ "summary": "Adresse du service",
154
+ "required": true,
155
+ "description": "Adresse du service à exécuter",
156
+ "schema": {
157
+ "type": "string"
158
+ }
159
+ },
160
+ {
161
+ "name": "body",
162
+ "summary": "Valeur",
163
+ "required": false,
164
+ "description": "Valeur à envoyer",
165
+ "schema": {
166
+ "type": "object"
167
+ }
168
+ },
169
+ {
170
+ "name": "headers",
171
+ "summary": "En-têtes",
172
+ "required": false,
173
+ "description": "En-têtes à envoyer",
174
+ "schema": {
175
+ "type": "object"
176
+ }
177
+ },
178
+ {
179
+ "name": "IS_JSON",
180
+ "summary": "API JSON",
181
+ "required": false,
182
+ "description": "Indique si l'API est en JSON",
183
+ "schema": {
184
+ "type": "boolean"
185
+ }
186
+ }
187
+ ],
188
+ "x-events": []
189
+ }
190
+ },
191
+ "/partialUpdate": {
192
+ "post": {
193
+ "tags": ["service"],
194
+ "summary": "Modifie une partie d'une ressource HTTP",
195
+ "parameters": [
196
+ {
197
+ "name": "url",
198
+ "summary": "Adresse du service",
199
+ "required": true,
200
+ "description": "Adresse du service à exécuter",
201
+ "schema": {
202
+ "type": "string"
203
+ }
204
+ },
205
+ {
206
+ "name": "body",
207
+ "summary": "Valeur",
208
+ "required": false,
209
+ "description": "Valeur à envoyer",
210
+ "schema": {
211
+ "type": "object"
212
+ }
213
+ },
214
+ {
215
+ "name": "headers",
216
+ "summary": "En-têtes",
217
+ "required": false,
218
+ "description": "En-têtes à envoyer",
219
+ "schema": {
220
+ "type": "object"
221
+ }
222
+ },
223
+ {
224
+ "name": "IS_JSON",
225
+ "summary": "API JSON",
226
+ "required": false,
227
+ "description": "Indique si l'API est en JSON",
228
+ "schema": {
229
+ "type": "boolean"
230
+ }
231
+ }
232
+ ],
233
+ "x-events": []
234
+ }
235
+ },
236
+ "/remove": {
237
+ "post": {
238
+ "tags": ["service"],
239
+ "summary": "Supprime une ressource HTTP",
240
+ "parameters": [
241
+ {
242
+ "name": "URL",
243
+ "summary": "Adresse du service",
244
+ "required": true,
245
+ "description": "Adresse du service à exécuter",
246
+ "schema": {
247
+ "type": "string"
248
+ }
249
+ },
250
+ {
251
+ "name": "headers",
252
+ "summary": "En-têtes",
253
+ "required": false,
254
+ "description": "En-têtes à envoyer",
255
+ "schema": {
256
+ "type": "object"
257
+ }
258
+ },
259
+ {
260
+ "name": "IS_JSON",
261
+ "summary": "API JSON",
262
+ "required": false,
263
+ "description": "Indique si l'API est en JSON",
264
+ "schema": {
265
+ "type": "boolean"
266
+ }
267
+ }
268
+ ],
269
+ "x-events": []
270
+ }
271
+ }
272
+ },
273
+ "components": {
274
+ "schemas": {}
275
+ },
276
+ "x-scene-blocks": {}
277
+ }