@docbrasil/api-systemmanager 1.2.3 → 1.2.5

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/docs/Process.html CHANGED
@@ -538,6 +538,280 @@ const result = await api.user.process.downloadDocs(params, session);</code></pre
538
538
 
539
539
 
540
540
 
541
+ </div>
542
+
543
+ <div class="member">
544
+
545
+
546
+
547
+ <h4 class="name" id="end">
548
+ <a class="href-link" href="#end">#</a>
549
+
550
+
551
+ <span class='tag'>async</span>
552
+
553
+
554
+ <span class="code-name">
555
+
556
+ end<span class="signature">(params, session)</span><span class="type-signature"> &rarr; {Promise.&lt;object>}</span>
557
+
558
+ </span>
559
+ </h4>
560
+
561
+
562
+
563
+
564
+ <div class="description">
565
+ End a running process task from a specific flow step.
566
+ </div>
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+ <h5>Parameters:</h5>
578
+
579
+ <div class="table-container">
580
+ <table class="params table">
581
+ <thead>
582
+ <tr>
583
+
584
+ <th>Name</th>
585
+
586
+
587
+ <th>Type</th>
588
+
589
+
590
+
591
+
592
+
593
+ <th class="last">Description</th>
594
+ </tr>
595
+ </thead>
596
+
597
+ <tbody>
598
+
599
+
600
+
601
+ <tr class="deep-level-0">
602
+
603
+ <td class="name"><code>params</code></td>
604
+
605
+
606
+ <td class="type">
607
+
608
+
609
+ <code class="param-type">object</code>
610
+
611
+
612
+
613
+ </td>
614
+
615
+
616
+
617
+
618
+
619
+ <td class="description last">Params to end the process task</td>
620
+ </tr>
621
+
622
+
623
+
624
+
625
+ <tr class="deep-level-1">
626
+
627
+ <td class="name"><code>processId</code></td>
628
+
629
+
630
+ <td class="type">
631
+
632
+
633
+ <code class="param-type">string</code>
634
+
635
+
636
+
637
+ </td>
638
+
639
+
640
+
641
+
642
+
643
+ <td class="description last">Process id (_id database);</td>
644
+ </tr>
645
+
646
+
647
+
648
+ <tr class="deep-level-1">
649
+
650
+ <td class="name"><code>orgId</code></td>
651
+
652
+
653
+ <td class="type">
654
+
655
+
656
+ <code class="param-type">string</code>
657
+
658
+
659
+
660
+ </td>
661
+
662
+
663
+
664
+
665
+
666
+ <td class="description last">Organization id (_id database);</td>
667
+ </tr>
668
+
669
+
670
+
671
+ <tr class="deep-level-1">
672
+
673
+ <td class="name"><code>flowName</code></td>
674
+
675
+
676
+ <td class="type">
677
+
678
+
679
+ <code class="param-type">string</code>
680
+
681
+
682
+
683
+ </td>
684
+
685
+
686
+
687
+
688
+
689
+ <td class="description last">The flow name of the step to end;</td>
690
+ </tr>
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+ <tr class="deep-level-0">
699
+
700
+ <td class="name"><code>session</code></td>
701
+
702
+
703
+ <td class="type">
704
+
705
+
706
+ <code class="param-type">string</code>
707
+
708
+
709
+
710
+ </td>
711
+
712
+
713
+
714
+
715
+
716
+ <td class="description last">Session, token JWT</td>
717
+ </tr>
718
+
719
+
720
+
721
+ </tbody>
722
+ </table>
723
+ </div>
724
+
725
+
726
+
727
+
728
+
729
+ <dl class="details">
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+ <p class="tag-source">
762
+ <a href="user_process.js.html" class="button">View Source</a>
763
+ <span>
764
+ <a href="user_process.js.html">user/process.js</a>, <a href="user_process.js.html#line717">line 717</a>
765
+ </span>
766
+ </p>
767
+
768
+ </dl>
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+ <div class='columns method-parameter'>
788
+ <div class="column is-2"><label>Returns:</label></div>
789
+ <div class="column is-10">
790
+
791
+
792
+
793
+ <div class="columns">
794
+
795
+ <div class='param-desc column is-7'>{ response: 'OK' } on success</div>
796
+
797
+
798
+ <div class='column is-5 has-text-left'>
799
+ <label>Type: </label>
800
+
801
+ <code class="param-type">Promise.&lt;object></code>
802
+
803
+
804
+ </div>
805
+
806
+ </div>
807
+
808
+
809
+ </div>
810
+ </div>
811
+
812
+
813
+
814
+
541
815
  </div>
542
816
 
543
817
  <div class="member">
@@ -385,6 +385,90 @@ class AdminUser {
385
385
  }
386
386
  }
387
387
 
388
+ /**
389
+ * @author Myndware &lt;augusto.pissarra@myndware.com>
390
+ * @description Batch-create users from an uploaded Excel (.xlsx) or CSV file.
391
+ *
392
+ * Uploads the file as multipart/form-data. The server parses it, validates
393
+ * headers, de-duplicates emails, admits rows FIFO against the organization's
394
+ * user cap, and delegates the actual creation to the existing registration
395
+ * chain. Response is a per-row result array (created / existing / skipped).
396
+ *
397
+ * Status codes:
398
+ * - 200 when at least one row was created or matched an existing user.
399
+ * - 422 (same JSON body shape) when EVERY row was skipped — callers
400
+ * should promote the 422 response body to a completed result, not an
401
+ * error. Axios throws on 422 by default, so catch and inspect
402
+ * `ex.response.data.results`.
403
+ * - 400 for structural failures (invalid_file, missing_columns, empty_file,
404
+ * too_many_rows) — `response.data.code` carries the machine-readable code.
405
+ * - 403 when the caller does not belong to the target organization or lacks
406
+ * user-admin role (code: 'forbidden').
407
+ * - 413 when the uploaded file exceeds 2 MB.
408
+ *
409
+ * @param {FormData} formData A browser FormData instance with a single field
410
+ * named `file` whose value is the .xlsx or .csv File/Blob. Must be
411
+ * FormData so the browser/axios can set the multipart boundary.
412
+ * @param {string} session JWT session token
413
+ * @return {Promise&lt;object>} Batch result:
414
+ * {
415
+ * total: number,
416
+ * created: number,
417
+ * existing: number,
418
+ * skipped: number,
419
+ * results: Array&lt;{
420
+ * row: number, // spreadsheet row (1-based, header = 1)
421
+ * email: string,
422
+ * status: 'created' | 'existing' | 'skipped',
423
+ * userId: string | null,
424
+ * message: string | null // snake_case code, optionally `code:detail`
425
+ * }>
426
+ * }
427
+ * @public
428
+ * @async
429
+ * @example
430
+ *
431
+ * const API = require('@docbrasil/api-systemmanager');
432
+ * const api = new API();
433
+ * const fd = new FormData();
434
+ * fd.append('file', fileInput.files[0]); // .xlsx or .csv
435
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
436
+ * // Ensure the client is scoped to the caller's org:
437
+ * api.admin.user.setOrgId(myOrgId);
438
+ * try {
439
+ * const result = await api.admin.user.batchCreate(fd, session);
440
+ * console.log(`${result.created} created, ${result.skipped} skipped`);
441
+ * } catch (ex) {
442
+ * if (ex?.response?.status === 422 &amp;&amp; ex.response.data?.results) {
443
+ * // All-skipped batch — still a valid result to render.
444
+ * console.warn('All rows skipped:', ex.response.data.results);
445
+ * } else {
446
+ * throw ex;
447
+ * }
448
+ * }
449
+ */
450
+ async batchCreate(formData, session) {
451
+ const self = this;
452
+
453
+ try {
454
+ Joi.assert(formData, Joi.any().required(), 'Multipart FormData with a `file` field');
455
+ Joi.assert(session, Joi.string().required(), 'Session token');
456
+
457
+ // Do NOT force Content-Type — let the browser/axios set it with the
458
+ // correct multipart boundary. Raise the axios body-size caps to 5 MB
459
+ // (server enforces its own 2 MB cap via Hapi `maxBytes`).
460
+ const cfg = {
461
+ ...self._setHeader(session),
462
+ maxContentLength: 5 * 1024 * 1024,
463
+ maxBodyLength: 5 * 1024 * 1024
464
+ };
465
+ const apiCall = self.client.put(`${self._basePath()}/batch`, formData, cfg);
466
+ return self._returnData(await apiCall);
467
+ } catch (ex) {
468
+ throw ex;
469
+ }
470
+ }
471
+
388
472
  /**
389
473
  * @author Myndware &lt;augusto.pissarra@myndware.com>
390
474
  * @description Remove a user
@@ -792,6 +792,33 @@ class Process {
792
792
  }
793
793
  }
794
794
 
795
+ /**
796
+ * @description End a running process task from a specific flow step.
797
+ * @param {object} params Params to end the process task
798
+ * @param {string} params.processId Process id (_id database);
799
+ * @param {string} params.orgId Organization id (_id database);
800
+ * @param {string} params.flowName The flow name of the step to end;
801
+ * @param {string} session Session, token JWT
802
+ * @return {Promise&lt;object>} { response: 'OK' } on success
803
+ */
804
+ async end(params, session) {
805
+ const self = this;
806
+
807
+ try {
808
+ Joi.assert(params, Joi.object().required(), 'Params to end the process task');
809
+ Joi.assert(params.processId, Joi.string().required(), 'Process id (_id database)');
810
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
811
+ Joi.assert(params.flowName, Joi.string().required(), 'Flow name of the step');
812
+ Joi.assert(session, Joi.string().required(), 'Session token JWT');
813
+
814
+ const {processId, orgId, flowName} = params;
815
+ const apiCall = self._client.post(`/organizations/${orgId}/process/${processId}/task/${flowName}/end`, {}, self._setHeader(session));
816
+ return self._returnData(await apiCall);
817
+ } catch (ex) {
818
+ throw ex;
819
+ }
820
+ }
821
+
795
822
  async getStepHistory(params, session) {
796
823
  const self = this;
797
824
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docbrasil/api-systemmanager",
3
3
  "description": "Module API System Manager",
4
- "version": "1.2.3",
4
+ "version": "1.2.5",
5
5
  "scripts": {
6
6
  "htmldoc": "rm -rf docs && jsdoc api/** -d docs -t ./node_modules/better-docs",
7
7
  "doc": "rm -rf doc && mkdir doc && jsdoc2md api/**/* api/* > doc/api.md",