@baasix/sdk 0.1.5 → 0.1.7

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 CHANGED
@@ -807,24 +807,198 @@ const categories = await baasix.reports.distinct('products', 'category');
807
807
 
808
808
  ## Workflows
809
809
 
810
+ ### Basic Operations
811
+
812
+ ```typescript
813
+ // List workflows
814
+ const { data: workflows } = await baasix.workflows.find();
815
+
816
+ // Get workflow by ID
817
+ const workflow = await baasix.workflows.findOne('workflow-uuid');
818
+
819
+ // Create workflow
820
+ const newWorkflow = await baasix.workflows.create({
821
+ name: 'Order Processing',
822
+ trigger: { type: 'hook', config: { collection: 'orders', event: 'items.create.after' } },
823
+ nodes: [...],
824
+ edges: [...],
825
+ isActive: true
826
+ });
827
+
828
+ // Update workflow
829
+ await baasix.workflows.update('workflow-uuid', { name: 'Updated Name' });
830
+
831
+ // Delete workflow
832
+ await baasix.workflows.delete('workflow-uuid');
833
+
834
+ // Enable/Disable workflow
835
+ await baasix.workflows.enable('workflow-uuid');
836
+ await baasix.workflows.disable('workflow-uuid');
837
+
838
+ // Duplicate workflow
839
+ const copy = await baasix.workflows.duplicate('workflow-uuid', { name: 'Copy' });
840
+ ```
841
+
842
+ ### Execution
843
+
810
844
  ```typescript
811
845
  // Execute workflow
812
846
  const result = await baasix.workflows.execute('workflow-uuid', {
813
847
  orderId: 'order-123',
814
848
  });
815
849
 
850
+ // Execute a specific node
851
+ const nodeResult = await baasix.workflows.executeNode('workflow-uuid', 'node-id', {
852
+ inputData: 'value'
853
+ });
854
+
855
+ // Test workflow (without persisting)
856
+ const testResult = await baasix.workflows.test('workflow-uuid', { testData: {} });
857
+
816
858
  // Get execution history
817
- const { data: executions } = await baasix.workflows.getExecutions('workflow-uuid');
859
+ const { data: executions } = await baasix.workflows.getExecutions('workflow-uuid', {
860
+ limit: 50,
861
+ status: 'completed'
862
+ });
863
+
864
+ // Get specific execution
865
+ const execution = await baasix.workflows.getExecution('workflow-uuid', 'execution-uuid');
866
+
867
+ // Get execution logs
868
+ const logs = await baasix.workflows.getExecutionLogs('workflow-uuid', 'execution-uuid');
869
+
870
+ // Cancel running execution
871
+ await baasix.workflows.cancelExecution('workflow-uuid', 'execution-uuid');
818
872
 
819
873
  // Subscribe to execution updates (requires realtime)
820
874
  const unsubscribe = baasix.realtime.subscribeToExecution(executionId, (update) => {
821
- console.log('Execution progress:', update.progress, '%');
875
+ console.log('Progress:', update.progress, '%');
822
876
  if (update.status === 'complete') {
823
877
  console.log('Workflow finished!', update.result);
824
878
  }
825
879
  });
826
880
  ```
827
881
 
882
+ ### Statistics & Validation
883
+
884
+ ```typescript
885
+ // Get workflow statistics
886
+ const stats = await baasix.workflows.getStats('workflow-uuid');
887
+ console.log(`Total: ${stats.totalExecutions}, Success Rate: ${stats.successRate}%`);
888
+
889
+ // Validate workflow definition
890
+ const validation = await baasix.workflows.validate({
891
+ name: 'My Workflow',
892
+ nodes: [...],
893
+ edges: [...]
894
+ });
895
+ if (!validation.valid) {
896
+ console.log('Errors:', validation.errors);
897
+ }
898
+ ```
899
+
900
+ ### Export/Import
901
+
902
+ ```typescript
903
+ // Export single workflow
904
+ const exported = await baasix.workflows.export('workflow-uuid');
905
+
906
+ // Export all workflows
907
+ const allExported = await baasix.workflows.exportAll({
908
+ ids: ['wf-1', 'wf-2'], // Optional: specific workflows
909
+ includeInactive: true
910
+ });
911
+
912
+ // Preview import
913
+ const preview = await baasix.workflows.importPreview(file);
914
+ console.log('Will import:', preview.workflows.length);
915
+ console.log('Conflicts:', preview.conflicts);
916
+
917
+ // Import workflows
918
+ const result = await baasix.workflows.import(file, { overwrite: true });
919
+ console.log(`Imported: ${result.imported}, Skipped: ${result.skipped}`);
920
+ ```
921
+
922
+ ## Settings
923
+
924
+ ```typescript
925
+ // Get all settings
926
+ const settings = await baasix.settings.get();
927
+
928
+ // Get a specific setting
929
+ const appName = await baasix.settings.getKey('appName');
930
+
931
+ // Update settings
932
+ await baasix.settings.update({
933
+ appName: 'My Application',
934
+ theme: 'dark'
935
+ });
936
+
937
+ // Set a specific setting
938
+ await baasix.settings.set('appName', 'New App Name');
939
+
940
+ // Get settings by app URL (multi-tenant)
941
+ const tenantSettings = await baasix.settings.getByAppUrl('https://myapp.example.com');
942
+
943
+ // Get email branding
944
+ const branding = await baasix.settings.getBranding();
945
+
946
+ // Test email configuration (admin only)
947
+ await baasix.settings.testEmail('admin@example.com');
948
+
949
+ // Reload settings cache (admin only)
950
+ await baasix.settings.reload();
951
+
952
+ // Delete tenant settings (admin only)
953
+ await baasix.settings.deleteTenant();
954
+ ```
955
+
956
+ ## Permissions
957
+
958
+ ```typescript
959
+ // List all permissions
960
+ const { data: permissions } = await baasix.permissions.find();
961
+
962
+ // Get permissions for a role
963
+ const { data: rolePerms } = await baasix.permissions.findByRole('role-uuid');
964
+
965
+ // Get permissions for a collection
966
+ const { data: collectionPerms } = await baasix.permissions.findByCollection('products');
967
+
968
+ // Create permission
969
+ const permission = await baasix.permissions.create({
970
+ role_Id: 'editor-role-uuid',
971
+ collection: 'posts',
972
+ action: 'update',
973
+ fields: ['title', 'content'],
974
+ conditions: { author_Id: { eq: '$CURRENT_USER' } }
975
+ });
976
+
977
+ // Create CRUD permissions for a collection
978
+ await baasix.permissions.createCrudPermissions('role-uuid', 'products', {
979
+ create: { fields: ['name', 'price'] },
980
+ read: { fields: ['*'] },
981
+ update: { fields: ['name', 'price'] },
982
+ delete: false
983
+ });
984
+
985
+ // Update permission
986
+ await baasix.permissions.update('permission-uuid', { fields: ['*'] });
987
+
988
+ // Delete permission
989
+ await baasix.permissions.delete('permission-uuid');
990
+
991
+ // Reload permissions cache (admin only)
992
+ await baasix.permissions.reloadCache();
993
+
994
+ // Export all permissions
995
+ const exported = await baasix.permissions.export();
996
+
997
+ // Import permissions
998
+ const result = await baasix.permissions.import(exportedData, { overwrite: true });
999
+ console.log(`Imported: ${result.imported}`);
1000
+ ```
1001
+
828
1002
  ## Realtime Subscriptions
829
1003
 
830
1004
  The SDK supports real-time data updates via WebSocket connections.
package/dist/index.cjs CHANGED
@@ -120,7 +120,9 @@ var HttpClient = class {
120
120
  "Content-Type": "application/json",
121
121
  ...this.config.headers
122
122
  },
123
- body: this.config.authMode === "jwt" ? JSON.stringify({ refreshToken }) : void 0,
123
+ body: JSON.stringify(
124
+ this.config.authMode === "jwt" ? { refreshToken, authMode: "jwt" } : { authMode: "cookie" }
125
+ ),
124
126
  credentials: this.config.credentials
125
127
  }
126
128
  );
@@ -721,7 +723,7 @@ var AuthModule = class {
721
723
  const refreshToken = await this.storage.get(STORAGE_KEYS.REFRESH_TOKEN);
722
724
  const response = await this.client.post(
723
725
  "/auth/refresh",
724
- this.authMode === "jwt" ? { refreshToken } : void 0
726
+ this.authMode === "jwt" ? { refreshToken, authMode: "jwt" } : { authMode: "cookie" }
725
727
  );
726
728
  await this.storeTokens(response);
727
729
  const tokens = {
@@ -2582,6 +2584,37 @@ var PermissionsModule = class {
2582
2584
  async reloadCache() {
2583
2585
  await this.client.post("/permissions/reload");
2584
2586
  }
2587
+ /**
2588
+ * Export all permissions (admin only)
2589
+ *
2590
+ * @example
2591
+ * ```typescript
2592
+ * const exported = await baasix.permissions.export();
2593
+ * // Save to file or transfer
2594
+ * ```
2595
+ */
2596
+ async export() {
2597
+ const response = await this.client.post("/permissions-export", {});
2598
+ return response.data;
2599
+ }
2600
+ /**
2601
+ * Import permissions from exported data (admin only)
2602
+ *
2603
+ * @example
2604
+ * ```typescript
2605
+ * const result = await baasix.permissions.import(exportedData, {
2606
+ * overwrite: true
2607
+ * });
2608
+ * console.log('Imported:', result.imported, 'permissions');
2609
+ * ```
2610
+ */
2611
+ async import(data, options) {
2612
+ const response = await this.client.post("/permissions-import", {
2613
+ ...data,
2614
+ ...options
2615
+ });
2616
+ return response.data;
2617
+ }
2585
2618
  };
2586
2619
 
2587
2620
  // src/modules/settings.ts
@@ -2648,6 +2681,73 @@ var SettingsModule = class {
2648
2681
  async set(key, value) {
2649
2682
  return this.update({ [key]: value });
2650
2683
  }
2684
+ /**
2685
+ * Get settings by application URL (useful for multi-tenant apps)
2686
+ *
2687
+ * @example
2688
+ * ```typescript
2689
+ * const settings = await baasix.settings.getByAppUrl('https://myapp.example.com');
2690
+ * ```
2691
+ */
2692
+ async getByAppUrl(appUrl) {
2693
+ const response = await this.client.get(
2694
+ "/settings/by-app-url",
2695
+ { params: { appUrl } }
2696
+ );
2697
+ return response.data;
2698
+ }
2699
+ /**
2700
+ * Get email branding settings for the current tenant
2701
+ *
2702
+ * @example
2703
+ * ```typescript
2704
+ * const branding = await baasix.settings.getBranding();
2705
+ * console.log(branding.logo, branding.primaryColor);
2706
+ * ```
2707
+ */
2708
+ async getBranding() {
2709
+ const response = await this.client.get(
2710
+ "/settings/branding"
2711
+ );
2712
+ return response.data;
2713
+ }
2714
+ /**
2715
+ * Test email configuration by sending a test email
2716
+ *
2717
+ * @example
2718
+ * ```typescript
2719
+ * await baasix.settings.testEmail('admin@example.com');
2720
+ * ```
2721
+ */
2722
+ async testEmail(to) {
2723
+ const response = await this.client.post(
2724
+ "/settings/test-email",
2725
+ { to }
2726
+ );
2727
+ return response;
2728
+ }
2729
+ /**
2730
+ * Reload settings cache (admin only)
2731
+ *
2732
+ * @example
2733
+ * ```typescript
2734
+ * await baasix.settings.reload();
2735
+ * ```
2736
+ */
2737
+ async reload() {
2738
+ await this.client.post("/settings/reload");
2739
+ }
2740
+ /**
2741
+ * Delete tenant settings (admin only, multi-tenant)
2742
+ *
2743
+ * @example
2744
+ * ```typescript
2745
+ * await baasix.settings.deleteTenant();
2746
+ * ```
2747
+ */
2748
+ async deleteTenant() {
2749
+ await this.client.delete("/settings/tenant");
2750
+ }
2651
2751
  };
2652
2752
 
2653
2753
  // src/modules/reports.ts
@@ -3025,6 +3125,159 @@ var WorkflowsModule = class {
3025
3125
  ...overrides
3026
3126
  });
3027
3127
  }
3128
+ /**
3129
+ * Execute a specific node in a workflow
3130
+ *
3131
+ * @example
3132
+ * ```typescript
3133
+ * const result = await baasix.workflows.executeNode(
3134
+ * 'workflow-uuid',
3135
+ * 'node-id',
3136
+ * { inputData: 'value' }
3137
+ * );
3138
+ * ```
3139
+ */
3140
+ async executeNode(workflowId, nodeId, triggerData) {
3141
+ const response = await this.client.post(
3142
+ `/workflows/${workflowId}/nodes/${nodeId}/execute`,
3143
+ { triggerData }
3144
+ );
3145
+ return response.data;
3146
+ }
3147
+ /**
3148
+ * Get execution logs for a specific execution
3149
+ *
3150
+ * @example
3151
+ * ```typescript
3152
+ * const logs = await baasix.workflows.getExecutionLogs(
3153
+ * 'workflow-uuid',
3154
+ * 'execution-uuid'
3155
+ * );
3156
+ * ```
3157
+ */
3158
+ async getExecutionLogs(workflowId, executionId) {
3159
+ const response = await this.client.get(
3160
+ `/workflows/${workflowId}/executions/${executionId}/logs`
3161
+ );
3162
+ return response.data;
3163
+ }
3164
+ /**
3165
+ * Get workflow statistics
3166
+ *
3167
+ * @example
3168
+ * ```typescript
3169
+ * const stats = await baasix.workflows.getStats('workflow-uuid');
3170
+ * console.log(stats.totalExecutions, stats.successRate);
3171
+ * ```
3172
+ */
3173
+ async getStats(id) {
3174
+ const response = await this.client.get(`/workflows/${id}/stats`);
3175
+ return response.data;
3176
+ }
3177
+ /**
3178
+ * Validate a workflow definition
3179
+ *
3180
+ * @example
3181
+ * ```typescript
3182
+ * const result = await baasix.workflows.validate({
3183
+ * name: 'My Workflow',
3184
+ * nodes: [...],
3185
+ * edges: [...]
3186
+ * });
3187
+ * if (result.valid) {
3188
+ * console.log('Workflow is valid');
3189
+ * } else {
3190
+ * console.log('Errors:', result.errors);
3191
+ * }
3192
+ * ```
3193
+ */
3194
+ async validate(workflow) {
3195
+ const response = await this.client.post(
3196
+ "/workflows/validate",
3197
+ workflow
3198
+ );
3199
+ return response;
3200
+ }
3201
+ /**
3202
+ * Export a single workflow
3203
+ *
3204
+ * @example
3205
+ * ```typescript
3206
+ * const exported = await baasix.workflows.export('workflow-uuid');
3207
+ * // Save to file or transfer
3208
+ * ```
3209
+ */
3210
+ async export(id) {
3211
+ const response = await this.client.get(
3212
+ `/workflows/${id}/export`
3213
+ );
3214
+ return response.data;
3215
+ }
3216
+ /**
3217
+ * Export multiple workflows
3218
+ *
3219
+ * @example
3220
+ * ```typescript
3221
+ * // Export all workflows
3222
+ * const exported = await baasix.workflows.exportAll();
3223
+ *
3224
+ * // Export specific workflows
3225
+ * const exported = await baasix.workflows.exportAll({
3226
+ * ids: ['workflow-1', 'workflow-2']
3227
+ * });
3228
+ * ```
3229
+ */
3230
+ async exportAll(options) {
3231
+ const response = await this.client.post(
3232
+ "/workflows/export",
3233
+ options || {}
3234
+ );
3235
+ return response.data;
3236
+ }
3237
+ /**
3238
+ * Preview workflow import without applying changes
3239
+ *
3240
+ * @example
3241
+ * ```typescript
3242
+ * const preview = await baasix.workflows.importPreview(file);
3243
+ * console.log('Will import:', preview.workflows.length, 'workflows');
3244
+ * console.log('Conflicts:', preview.conflicts);
3245
+ * ```
3246
+ */
3247
+ async importPreview(file) {
3248
+ const formData = new FormData();
3249
+ if (file instanceof File) {
3250
+ formData.append("file", file);
3251
+ } else {
3252
+ formData.append("file", file);
3253
+ }
3254
+ const response = await this.client.post("/workflows/import/preview", formData);
3255
+ return response.data;
3256
+ }
3257
+ /**
3258
+ * Import workflows from a file
3259
+ *
3260
+ * @example
3261
+ * ```typescript
3262
+ * const result = await baasix.workflows.import(file, {
3263
+ * overwrite: true
3264
+ * });
3265
+ * console.log('Imported:', result.imported, 'workflows');
3266
+ * ```
3267
+ */
3268
+ async import(file, options) {
3269
+ const formData = new FormData();
3270
+ if (file instanceof File) {
3271
+ formData.append("file", file);
3272
+ } else {
3273
+ formData.append("file", file);
3274
+ }
3275
+ if (options?.overwrite !== void 0) {
3276
+ formData.append("overwrite", String(options.overwrite));
3277
+ }
3278
+ const response = await this.client.post("/workflows/import", formData);
3279
+ return response.data;
3280
+ }
3028
3281
  };
3029
3282
 
3030
3283
  // src/modules/realtime.ts