@digipair/skill-http 0.43.5 → 0.44.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.js CHANGED
@@ -51,6 +51,46 @@ let HttpService = class HttpService {
51
51
  const { path, method = 'GET', body = null, headers = {} } = params;
52
52
  return await this.call(path, method, body, headers);
53
53
  }
54
+ async upload(params, _pinsSettingsList, _context) {
55
+ const { path, parameters, method = 'POST', headers = {} } = params;
56
+ const formData = new FormData();
57
+ // Ajout des paramètres au FormData
58
+ parameters.forEach((param)=>{
59
+ if (!Array.isArray(param.value)) {
60
+ this.appendParam(formData, param);
61
+ } else {
62
+ param.value.forEach((item)=>{
63
+ this.appendParam(formData, _extends({}, param, {
64
+ value: item
65
+ }));
66
+ });
67
+ }
68
+ });
69
+ const response = await fetch(path, {
70
+ method,
71
+ headers: _extends({
72
+ Accept: this.IS_JSON ? 'application/json' : '*/*',
73
+ 'Content-Type': 'multipart/form-data'
74
+ }, headers),
75
+ body: formData
76
+ });
77
+ if (!response.ok) throw new Error('[SKILL-HTTP] REQUEST FAILED: ' + response.status);
78
+ return this.IS_JSON ? response.json() : response.text();
79
+ }
80
+ appendParam(formData, param) {
81
+ if (param.value.type == 'text') {
82
+ formData.append(param.name, param.value);
83
+ } else if (param.type === 'file') {
84
+ // Gestion des fichiers encodés en base64
85
+ const matches = param.value.match(/^data:(.+);base64,(.+)$/);
86
+ if (!matches || matches.length !== 3) {
87
+ throw new Error(`Bad base64 format for ${param.name}`);
88
+ }
89
+ const base64Data = matches[2];
90
+ const buffer = Buffer.from(base64Data, 'base64');
91
+ formData.append(param.name, buffer);
92
+ }
93
+ }
54
94
  constructor(_context, params){
55
95
  const { IS_JSON = true } = params;
56
96
  this.IS_JSON = IS_JSON;
@@ -62,6 +102,7 @@ const update = (params, pinsSettingsList, context)=>new HttpService(context, par
62
102
  const partialUpdate = (params, pinsSettingsList, context)=>new HttpService(context, params).update(params, pinsSettingsList, context);
63
103
  const remove = (params, pinsSettingsList, context)=>new HttpService(context, params).remove(params, pinsSettingsList, context);
64
104
  const request = (params, pinsSettingsList, context)=>new HttpService(context, params).request(params, pinsSettingsList, context);
105
+ const upload = (params, pinsSettingsList, context)=>new HttpService(context, params).upload(params, pinsSettingsList, context);
65
106
 
66
107
  exports.create = create;
67
108
  exports.partialUpdate = partialUpdate;
@@ -69,3 +110,4 @@ exports.read = read;
69
110
  exports.remove = remove;
70
111
  exports.request = request;
71
112
  exports.update = update;
113
+ exports.upload = upload;
package/index.esm.js CHANGED
@@ -47,6 +47,46 @@ let HttpService = class HttpService {
47
47
  const { path, method = 'GET', body = null, headers = {} } = params;
48
48
  return await this.call(path, method, body, headers);
49
49
  }
50
+ async upload(params, _pinsSettingsList, _context) {
51
+ const { path, parameters, method = 'POST', headers = {} } = params;
52
+ const formData = new FormData();
53
+ // Ajout des paramètres au FormData
54
+ parameters.forEach((param)=>{
55
+ if (!Array.isArray(param.value)) {
56
+ this.appendParam(formData, param);
57
+ } else {
58
+ param.value.forEach((item)=>{
59
+ this.appendParam(formData, _extends({}, param, {
60
+ value: item
61
+ }));
62
+ });
63
+ }
64
+ });
65
+ const response = await fetch(path, {
66
+ method,
67
+ headers: _extends({
68
+ Accept: this.IS_JSON ? 'application/json' : '*/*',
69
+ 'Content-Type': 'multipart/form-data'
70
+ }, headers),
71
+ body: formData
72
+ });
73
+ if (!response.ok) throw new Error('[SKILL-HTTP] REQUEST FAILED: ' + response.status);
74
+ return this.IS_JSON ? response.json() : response.text();
75
+ }
76
+ appendParam(formData, param) {
77
+ if (param.value.type == 'text') {
78
+ formData.append(param.name, param.value);
79
+ } else if (param.type === 'file') {
80
+ // Gestion des fichiers encodés en base64
81
+ const matches = param.value.match(/^data:(.+);base64,(.+)$/);
82
+ if (!matches || matches.length !== 3) {
83
+ throw new Error(`Bad base64 format for ${param.name}`);
84
+ }
85
+ const base64Data = matches[2];
86
+ const buffer = Buffer.from(base64Data, 'base64');
87
+ formData.append(param.name, buffer);
88
+ }
89
+ }
50
90
  constructor(_context, params){
51
91
  const { IS_JSON = true } = params;
52
92
  this.IS_JSON = IS_JSON;
@@ -58,5 +98,6 @@ const update = (params, pinsSettingsList, context)=>new HttpService(context, par
58
98
  const partialUpdate = (params, pinsSettingsList, context)=>new HttpService(context, params).update(params, pinsSettingsList, context);
59
99
  const remove = (params, pinsSettingsList, context)=>new HttpService(context, params).remove(params, pinsSettingsList, context);
60
100
  const request = (params, pinsSettingsList, context)=>new HttpService(context, params).request(params, pinsSettingsList, context);
101
+ const upload = (params, pinsSettingsList, context)=>new HttpService(context, params).upload(params, pinsSettingsList, context);
61
102
 
62
- export { create, partialUpdate, read, remove, request, update };
103
+ export { create, partialUpdate, read, remove, request, update, upload };
@@ -5,3 +5,4 @@ export declare const update: (params: any, pinsSettingsList: PinsSettings[], con
5
5
  export declare const partialUpdate: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
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
+ export declare const upload: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-http",
3
- "version": "0.43.5",
3
+ "version": "0.44.0",
4
4
  "dependencies": {},
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js"
package/schema.fr.json CHANGED
@@ -268,10 +268,85 @@
268
268
  ],
269
269
  "x-events": []
270
270
  }
271
+ },
272
+
273
+ "/upload": {
274
+ "post": {
275
+ "tags": ["service", "web", "spatial"],
276
+ "summary": "Upload une ressource HTTP",
277
+ "parameters": [
278
+ {
279
+ "name": "path",
280
+ "summary": "Adresse du service",
281
+ "required": true,
282
+ "description": "Adresse du service à exécuter",
283
+ "schema": {
284
+ "type": "string"
285
+ }
286
+ },
287
+ {
288
+ "name": "method",
289
+ "summary": "Méthode HTTP",
290
+ "required": false,
291
+ "description": "Méthode HTTP à utiliser",
292
+ "schema": {
293
+ "type": "string"
294
+ }
295
+ },
296
+ {
297
+ "name": "parameters",
298
+ "summary": "Parametres",
299
+ "required": true,
300
+ "description": "Liste des paramètres à envoyer",
301
+ "schema": {
302
+ "type": "array",
303
+ "items": {
304
+ "$ref": "#/components/schemas/UploadParameters"
305
+ }
306
+ }
307
+ },
308
+ {
309
+ "name": "headers",
310
+ "summary": "En-têtes",
311
+ "required": false,
312
+ "description": "En-têtes à envoyer",
313
+ "schema": {
314
+ "type": "object"
315
+ }
316
+ },
317
+ {
318
+ "name": "IS_JSON",
319
+ "summary": "API JSON",
320
+ "required": false,
321
+ "description": "Indique si l'API est en JSON",
322
+ "schema": {
323
+ "type": "boolean"
324
+ }
325
+ }
326
+ ],
327
+ "x-events": []
328
+ }
271
329
  }
272
330
  },
273
331
  "components": {
274
- "schemas": {}
332
+ "schemas": {
333
+ "UploadParameters": {
334
+ "symmary": "Parametres d'upload",
335
+ "tags": ["service", "web", "spatial"],
336
+ "type": "object",
337
+ "properties": {
338
+ "name": {
339
+ "type": "string"
340
+ },
341
+ "type": {
342
+ "type": "string"
343
+ },
344
+ "value": {
345
+ "type": "object"
346
+ }
347
+ }
348
+ }
349
+ }
275
350
  },
276
351
  "x-scene-blocks": {}
277
352
  }
package/schema.json CHANGED
@@ -268,10 +268,84 @@
268
268
  ],
269
269
  "x-events": []
270
270
  }
271
+ },
272
+ "/upload": {
273
+ "post": {
274
+ "tags": ["service", "web", "spatial"],
275
+ "summary": "Uploads a HTTP resource",
276
+ "parameters": [
277
+ {
278
+ "name": "path",
279
+ "summary": "Service address",
280
+ "required": true,
281
+ "description": "Address of the service to execute",
282
+ "schema": {
283
+ "type": "string"
284
+ }
285
+ },
286
+ {
287
+ "name": "method",
288
+ "summary": "HTTP method",
289
+ "required": false,
290
+ "description": "HTTP method to use",
291
+ "schema": {
292
+ "type": "string"
293
+ }
294
+ },
295
+ {
296
+ "name": "parameters",
297
+ "summary": "Parameters",
298
+ "required": true,
299
+ "description": "Parameters to send",
300
+ "schema": {
301
+ "type": "array",
302
+ "items": {
303
+ "$ref": "#/components/schemas/UploadParameters"
304
+ }
305
+ }
306
+ },
307
+ {
308
+ "name": "headers",
309
+ "summary": "Headers",
310
+ "required": false,
311
+ "description": "Headers to send",
312
+ "schema": {
313
+ "type": "object"
314
+ }
315
+ },
316
+ {
317
+ "name": "IS_JSON",
318
+ "summary": "JSON API",
319
+ "required": false,
320
+ "description": "Indicates if the API is in JSON",
321
+ "schema": {
322
+ "type": "boolean"
323
+ }
324
+ }
325
+ ],
326
+ "x-events": []
327
+ }
271
328
  }
272
329
  },
273
330
  "components": {
274
- "schemas": {}
331
+ "schemas": {
332
+ "UploadParameters": {
333
+ "symmary": "Parametres d'upload",
334
+ "tags": ["service", "web", "spatial"],
335
+ "type": "object",
336
+ "properties": {
337
+ "name": {
338
+ "type": "string"
339
+ },
340
+ "type": {
341
+ "type": "string"
342
+ },
343
+ "value": {
344
+ "type": "object"
345
+ }
346
+ }
347
+ }
348
+ }
275
349
  },
276
350
  "x-scene-blocks": {}
277
351
  }