@rglabs/butterfly 2.0.1

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 (117) hide show
  1. package/CLAUDE.md +201 -0
  2. package/README.md +371 -0
  3. package/dist/commands/add.d.ts +23 -0
  4. package/dist/commands/add.js +303 -0
  5. package/dist/commands/code.d.ts +11 -0
  6. package/dist/commands/code.js +72 -0
  7. package/dist/commands/create-object.d.ts +6 -0
  8. package/dist/commands/create-object.js +293 -0
  9. package/dist/commands/create-report.d.ts +6 -0
  10. package/dist/commands/create-report.js +154 -0
  11. package/dist/commands/diff.d.ts +4 -0
  12. package/dist/commands/diff.js +238 -0
  13. package/dist/commands/download.d.ts +4 -0
  14. package/dist/commands/download.js +374 -0
  15. package/dist/commands/layout.d.ts +12 -0
  16. package/dist/commands/layout.js +83 -0
  17. package/dist/commands/record.d.ts +21 -0
  18. package/dist/commands/record.js +483 -0
  19. package/dist/commands/run-poc.d.ts +3 -0
  20. package/dist/commands/run-poc.js +18 -0
  21. package/dist/commands/setup.d.ts +3 -0
  22. package/dist/commands/setup.js +66 -0
  23. package/dist/commands/start-poc.d.ts +3 -0
  24. package/dist/commands/start-poc.js +55 -0
  25. package/dist/commands/sync-docs.d.ts +3 -0
  26. package/dist/commands/sync-docs.js +27 -0
  27. package/dist/commands/translate.d.ts +13 -0
  28. package/dist/commands/translate.js +401 -0
  29. package/dist/commands/upload.d.ts +3 -0
  30. package/dist/commands/upload.js +150 -0
  31. package/dist/commands/workflow-info.d.ts +13 -0
  32. package/dist/commands/workflow-info.js +161 -0
  33. package/dist/components/ConflictResolver.d.ts +12 -0
  34. package/dist/components/ConflictResolver.js +77 -0
  35. package/dist/components/DiffView.d.ts +11 -0
  36. package/dist/components/DiffView.js +101 -0
  37. package/dist/components/DownloadProgress.d.ts +11 -0
  38. package/dist/components/DownloadProgress.js +29 -0
  39. package/dist/components/RecordPreview.d.ts +11 -0
  40. package/dist/components/RecordPreview.js +91 -0
  41. package/dist/components/SetupForm.d.ts +8 -0
  42. package/dist/components/SetupForm.js +56 -0
  43. package/dist/components/UploadProgress.d.ts +13 -0
  44. package/dist/components/UploadProgress.js +42 -0
  45. package/dist/diff/adapters/index.d.ts +8 -0
  46. package/dist/diff/adapters/index.js +18 -0
  47. package/dist/diff/adapters/objectsAdapter.d.ts +13 -0
  48. package/dist/diff/adapters/objectsAdapter.js +177 -0
  49. package/dist/diff/adapters/reportsAdapter.d.ts +14 -0
  50. package/dist/diff/adapters/reportsAdapter.js +212 -0
  51. package/dist/diff/adapters/types.d.ts +19 -0
  52. package/dist/diff/adapters/types.js +2 -0
  53. package/dist/diff/engine.d.ts +19 -0
  54. package/dist/diff/engine.js +57 -0
  55. package/dist/diff/types.d.ts +34 -0
  56. package/dist/diff/types.js +110 -0
  57. package/dist/index.d.ts +3 -0
  58. package/dist/index.js +117 -0
  59. package/dist/types/index.d.ts +18 -0
  60. package/dist/types/index.js +2 -0
  61. package/dist/utils/api.d.ts +85 -0
  62. package/dist/utils/api.js +1031 -0
  63. package/dist/utils/auth.d.ts +4 -0
  64. package/dist/utils/auth.js +22 -0
  65. package/dist/utils/bfySplitter.d.ts +12 -0
  66. package/dist/utils/bfySplitter.js +151 -0
  67. package/dist/utils/docs.d.ts +16 -0
  68. package/dist/utils/docs.js +186 -0
  69. package/dist/utils/errorLogger.d.ts +6 -0
  70. package/dist/utils/errorLogger.js +29 -0
  71. package/dist/utils/files.d.ts +14 -0
  72. package/dist/utils/files.js +772 -0
  73. package/dist/utils/lockManager.d.ts +15 -0
  74. package/dist/utils/lockManager.js +126 -0
  75. package/dist/utils/resourceHandlers.d.ts +50 -0
  76. package/dist/utils/resourceHandlers.js +684 -0
  77. package/dist/utils/resourceMapping.d.ts +32 -0
  78. package/dist/utils/resourceMapping.js +210 -0
  79. package/dist/utils/singleResourceDownload.d.ts +14 -0
  80. package/dist/utils/singleResourceDownload.js +261 -0
  81. package/dist/utils/summaryGenerator.d.ts +2 -0
  82. package/dist/utils/summaryGenerator.js +183 -0
  83. package/dist/utils/uploadHandler.d.ts +31 -0
  84. package/dist/utils/uploadHandler.js +263 -0
  85. package/docs/AI_API.md +93 -0
  86. package/docs/CLAUDE.md +216 -0
  87. package/docs/PROJECT_SPECIFIC.md +1 -0
  88. package/docs/RECORD_COMMAND.md +262 -0
  89. package/docs/WORKFLOW_API.md +480 -0
  90. package/docs/bfy-splitting.md +126 -0
  91. package/docs/cli-commands.md +333 -0
  92. package/docs/examples/README.md +95 -0
  93. package/docs/examples/order-system.md +147 -0
  94. package/docs/examples/product-catalog.md +195 -0
  95. package/docs/examples/reports.md +187 -0
  96. package/docs/excel-export.md +216 -0
  97. package/docs/field-types/README.md +29 -0
  98. package/docs/field-types/calculated.md +147 -0
  99. package/docs/field-types/code-mappings.md +84 -0
  100. package/docs/field-types/custom.md +340 -0
  101. package/docs/object-specs/README.md +136 -0
  102. package/docs/object-specs/code-parameters.md +151 -0
  103. package/docs/object-specs/creating.md +203 -0
  104. package/docs/object-specs/js-code-examples.md +208 -0
  105. package/docs/object-specs/js-field-updates.md +168 -0
  106. package/docs/objects/README.md +89 -0
  107. package/docs/objects/creating.md +127 -0
  108. package/docs/page-layout.md +361 -0
  109. package/docs/permissions.md +260 -0
  110. package/docs/reports.md +197 -0
  111. package/docs/state-machines.md +544 -0
  112. package/docs/tasks/create-object.md +81 -0
  113. package/docs/translations.md +346 -0
  114. package/docs/twig-helpers.md +283 -0
  115. package/docs/webservices.md +159 -0
  116. package/docs/workspaces.md +176 -0
  117. package/package.json +59 -0
@@ -0,0 +1,15 @@
1
+ export declare class LockManager {
2
+ private static lockFilePath;
3
+ private static maxWaitTime;
4
+ private static checkInterval;
5
+ static acquireLock(operation: 'download' | 'start'): Promise<void>;
6
+ static releaseLock(): Promise<void>;
7
+ static isLocked(): Promise<boolean>;
8
+ static getLockInfo(): Promise<{
9
+ operation: string;
10
+ timestamp: number;
11
+ pid: number;
12
+ } | null>;
13
+ static setupCleanup(): void;
14
+ }
15
+ //# sourceMappingURL=lockManager.d.ts.map
@@ -0,0 +1,126 @@
1
+ import { promises as fs } from 'fs';
2
+ import { dirname } from 'path';
3
+ export class LockManager {
4
+ static lockFilePath = '.butterfly/operation.lock';
5
+ static maxWaitTime = 30000;
6
+ static checkInterval = 100;
7
+ static async acquireLock(operation) {
8
+ const lockFile = this.lockFilePath;
9
+ const lockDir = dirname(lockFile);
10
+ try {
11
+ await fs.mkdir(lockDir, { recursive: true });
12
+ }
13
+ catch (error) {
14
+ }
15
+ const startTime = Date.now();
16
+ while (Date.now() - startTime < this.maxWaitTime) {
17
+ try {
18
+ const existingLock = await fs.readFile(lockFile, 'utf-8');
19
+ const lockData = JSON.parse(existingLock);
20
+ const lockAge = Date.now() - lockData.timestamp;
21
+ const maxLockAge = 5 * 60 * 1000;
22
+ if (lockAge > maxLockAge) {
23
+ await this.releaseLock();
24
+ break;
25
+ }
26
+ if (lockData.operation === 'download' && operation === 'start') {
27
+ throw new Error('Download operation is in progress. Please wait for it to complete before starting the file watcher.');
28
+ }
29
+ if (lockData.operation === 'start' && operation === 'download') {
30
+ throw new Error('File watcher is running. Please stop it (Ctrl+C) before running download operation.');
31
+ }
32
+ if (lockData.operation === operation) {
33
+ throw new Error(`Another ${operation} operation is already running.`);
34
+ }
35
+ await new Promise(resolve => setTimeout(resolve, this.checkInterval));
36
+ }
37
+ catch (error) {
38
+ if (error.code === 'ENOENT') {
39
+ break;
40
+ }
41
+ if (error instanceof Error && error.message.includes('operation is')) {
42
+ throw error;
43
+ }
44
+ break;
45
+ }
46
+ }
47
+ if (Date.now() - startTime >= this.maxWaitTime) {
48
+ throw new Error(`Timeout waiting for existing ${operation} operation to complete. If no operation is running, delete the lock file: ${lockFile}`);
49
+ }
50
+ const lockData = {
51
+ operation,
52
+ timestamp: Date.now(),
53
+ pid: process.pid
54
+ };
55
+ try {
56
+ await fs.writeFile(lockFile, JSON.stringify(lockData, null, 2), { flag: 'wx' });
57
+ }
58
+ catch (error) {
59
+ if (error.code === 'EEXIST') {
60
+ throw new Error(`Another ${operation} operation started at the same time. Please try again.`);
61
+ }
62
+ throw error;
63
+ }
64
+ }
65
+ static async releaseLock() {
66
+ const lockFile = this.lockFilePath;
67
+ try {
68
+ await fs.unlink(lockFile);
69
+ }
70
+ catch (error) {
71
+ if (error.code !== 'ENOENT') {
72
+ console.warn('Warning: Failed to remove lock file:', error);
73
+ }
74
+ }
75
+ }
76
+ static async isLocked() {
77
+ try {
78
+ await fs.access(this.lockFilePath);
79
+ return true;
80
+ }
81
+ catch {
82
+ return false;
83
+ }
84
+ }
85
+ static async getLockInfo() {
86
+ try {
87
+ const lockContent = await fs.readFile(this.lockFilePath, 'utf-8');
88
+ return JSON.parse(lockContent);
89
+ }
90
+ catch {
91
+ return null;
92
+ }
93
+ }
94
+ static setupCleanup() {
95
+ const cleanup = async () => {
96
+ await this.releaseLock();
97
+ };
98
+ process.on('exit', () => {
99
+ try {
100
+ const fs = require('fs');
101
+ fs.unlinkSync(this.lockFilePath);
102
+ }
103
+ catch {
104
+ }
105
+ });
106
+ process.on('SIGINT', async () => {
107
+ await cleanup();
108
+ process.exit(0);
109
+ });
110
+ process.on('SIGTERM', async () => {
111
+ await cleanup();
112
+ process.exit(0);
113
+ });
114
+ process.on('uncaughtException', async (error) => {
115
+ console.error('Uncaught exception:', error);
116
+ await cleanup();
117
+ process.exit(1);
118
+ });
119
+ process.on('unhandledRejection', async (reason) => {
120
+ console.error('Unhandled rejection:', reason);
121
+ await cleanup();
122
+ process.exit(1);
123
+ });
124
+ }
125
+ }
126
+ //# sourceMappingURL=lockManager.js.map
@@ -0,0 +1,50 @@
1
+ import { ButterflyAPI } from './api.js';
2
+ export interface HandlerResult {
3
+ success: boolean;
4
+ message: string;
5
+ resourceId?: number;
6
+ }
7
+ export declare function updateRecord(api: ButterflyAPI, tableName: string, data: Record<string, any>): Promise<HandlerResult>;
8
+ export declare function updateRecordField(api: ButterflyAPI, tableName: string, id: number, fieldName: string, fieldValue: string): Promise<HandlerResult>;
9
+ export declare function updateRecordFields(api: ButterflyAPI, tableName: string, id: number, fields: Record<string, string | undefined>): Promise<HandlerResult>;
10
+ export declare function handleWorkflowJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
11
+ export declare function handleWorkflowVersionJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
12
+ export declare function handleWorkflowNodeJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
13
+ export declare function handleWorkflowNodeCode(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
14
+ export declare function handleWorkflowNodeParams(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
15
+ export declare function handleWorkflowConnections(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
16
+ export declare function handleWebserviceJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
17
+ export declare function handleWebservicePageCode(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
18
+ export declare function handlePdfTemplateJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
19
+ export declare function handlePdfTemplateTwig(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
20
+ export declare function handleCronjobJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
21
+ export declare function handleCronjobCode(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
22
+ export declare function handleEmailTemplateJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
23
+ export declare function handleEmailTemplateBfy(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
24
+ export declare function handleEmailLayoutJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
25
+ export declare function handleEmailLayoutBfy(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
26
+ export declare function handleObjectJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
27
+ export declare function handleObjectSpecJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
28
+ export declare function handleObjectListingQuery(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
29
+ export declare function handleObjectSpecCodeFile(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
30
+ export declare function handlePageJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
31
+ export declare function handleStateMachineJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
32
+ export declare function handleStateMachineStateJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
33
+ export declare function handleStateMachineRoleJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
34
+ export declare function handleStateMachineRoleCode(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
35
+ export declare function handleStateMachineTransitionJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
36
+ export declare function handleStateMachineTransitionCode(api: ButterflyAPI, filePath: string, fieldName: 'action_code' | 'validation_code'): Promise<HandlerResult>;
37
+ export declare function handleStateMachineActionJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
38
+ export declare function handleStateMachineActionCode(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
39
+ export declare function handleTransitionActionJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
40
+ export declare function handleStateMachineSpecJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
41
+ export declare function handleAiTaskJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
42
+ export declare function handleAiTaskCodeFile(api: ButterflyAPI, filePath: string, fieldName: string): Promise<HandlerResult>;
43
+ export declare function handleReportJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
44
+ export declare function handleReportSpecJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
45
+ export declare function handleReportSpecCode(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
46
+ export declare function handleReportQueryJson(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
47
+ export declare function handleReportQueryCode(api: ButterflyAPI, filePath: string, field: 'query' | 'js_code'): Promise<HandlerResult>;
48
+ export declare function handleReportMainQuery(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
49
+ export declare function handleTranslationYaml(api: ButterflyAPI, filePath: string): Promise<HandlerResult>;
50
+ //# sourceMappingURL=resourceHandlers.d.ts.map