@onlineapps/conn-orch-api-mapper 1.0.10 → 1.0.11

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ApiMapper.js +44 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/conn-orch-api-mapper",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "API mapping connector for OA Drive - maps cookbook operations to HTTP endpoints",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/ApiMapper.js CHANGED
@@ -260,11 +260,50 @@ class ApiMapper {
260
260
  /**
261
261
  * Convert handler output to Descriptor
262
262
  * @private
263
+ *
264
+ * Supported formats from handler/HTTP response:
265
+ * 1. { data: base64_string, encoding: 'base64', filename, content_type } - HTTP transport format
266
+ * 2. { temp_path, filename, content_type } - Local file (only for same-process calls)
267
+ * 3. Buffer - Raw binary data
268
+ * 4. string - Text content
263
269
  */
264
270
  async _convertToDescriptor(output, schema, getContentResolver, logPrefix, context, fieldName = null) {
265
271
  const fieldLabel = fieldName ? `field '${fieldName}'` : 'output';
266
272
 
267
- // Handler should return object with temp_path for file operations
273
+ // Format 1: Base64-encoded data from HTTP response (primary format for distributed services)
274
+ if (output && typeof output === 'object' && output.data && output.encoding === 'base64') {
275
+ console.log(`${logPrefix}:PROCESS] ${JSON.stringify({
276
+ action: 'convert_base64',
277
+ field: fieldName,
278
+ filename: output.filename,
279
+ size: output.size
280
+ })}`);
281
+
282
+ // Decode base64 to Buffer
283
+ const buffer = Buffer.from(output.data, 'base64');
284
+
285
+ const resolver = getContentResolver();
286
+ const descriptor = await resolver.createDescriptor(buffer, {
287
+ filename: output.filename || schema.filename || 'output.bin',
288
+ content_type: output.content_type || schema.content_type,
289
+ context: {
290
+ workflow_id: context.workflow_id || 'standalone',
291
+ step_id: context.step_id || 'api-mapper'
292
+ },
293
+ forceFile: true // Binary data → always store as file
294
+ });
295
+
296
+ console.log(`${logPrefix}:PROCESS] ${JSON.stringify({
297
+ action: 'descriptor_created',
298
+ field: fieldName,
299
+ storage_ref: descriptor.storage_ref,
300
+ size: descriptor.size
301
+ })}`);
302
+
303
+ return descriptor;
304
+ }
305
+
306
+ // Format 2: Temp file path (for same-process calls, e.g. tests)
268
307
  if (output && typeof output === 'object' && output.temp_path) {
269
308
  console.log(`${logPrefix}:PROCESS] ${JSON.stringify({
270
309
  action: 'convert_temp_file',
@@ -294,7 +333,7 @@ class ApiMapper {
294
333
  return descriptor;
295
334
  }
296
335
 
297
- // Handler returned Buffer - store it
336
+ // Format 3: Raw Buffer
298
337
  if (Buffer.isBuffer(output)) {
299
338
  console.log(`${logPrefix}:PROCESS] ${JSON.stringify({
300
339
  action: 'convert_buffer',
@@ -314,7 +353,7 @@ class ApiMapper {
314
353
  });
315
354
  }
316
355
 
317
- // Handler returned string (for content type) - may be inline or stored
356
+ // Format 4: Plain string (text content)
318
357
  if (typeof output === 'string') {
319
358
  console.log(`${logPrefix}:PROCESS] ${JSON.stringify({
320
359
  action: 'convert_string',
@@ -338,11 +377,11 @@ class ApiMapper {
338
377
  console.error(`${logPrefix}:FAIL] ${JSON.stringify({
339
378
  error: 'UNEXPECTED_OUTPUT_FORMAT',
340
379
  field: fieldName,
341
- expected: 'object with temp_path, Buffer, or string',
380
+ expected: '{ data, encoding: "base64" } or { temp_path } or Buffer or string',
342
381
  received: typeof output,
343
382
  receivedKeys: output && typeof output === 'object' ? Object.keys(output) : null
344
383
  })}`);
345
- throw new Error(`[ApiMapper] FAIL-FAST: ${errorMsg}. Expected temp_path/Buffer/string, got ${typeof output}`);
384
+ throw new Error(`[ApiMapper] FAIL-FAST: ${errorMsg}. Expected base64/temp_path/Buffer/string, got ${typeof output}`);
346
385
  }
347
386
 
348
387
  /**