@weave-apps/sdk 0.9.0 → 0.11.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.
Files changed (37) hide show
  1. package/dist/WeaveAPIClient.d.ts +49 -0
  2. package/dist/WeaveAPIClient.d.ts.map +1 -1
  3. package/dist/WeaveDOMAPI.d.ts +66 -0
  4. package/dist/WeaveDOMAPI.d.ts.map +1 -1
  5. package/dist/WeaveDOMAPI.js +51 -0
  6. package/dist/apis/api-mono/services/interfaces/WorkflowsTriggersWorkflowCompanyIdPostPost.d.ts +224 -0
  7. package/dist/apis/api-mono/services/interfaces/WorkflowsTriggersWorkflowCompanyIdPostPost.d.ts.map +1 -0
  8. package/dist/apis/api-mono/services/interfaces/WorkflowsTriggersWorkflowCompanyIdPostPost.js +66 -0
  9. package/dist/app-sdk/src/WeaveAPIClient.d.ts +370 -0
  10. package/dist/app-sdk/src/WeaveAPIClient.d.ts.map +1 -0
  11. package/dist/app-sdk/src/WeaveAPIClient.js +361 -0
  12. package/dist/app-sdk/src/WeaveAppInstanceAPI.d.ts +237 -0
  13. package/dist/app-sdk/src/WeaveAppInstanceAPI.d.ts.map +1 -0
  14. package/dist/app-sdk/src/WeaveAppInstanceAPI.js +395 -0
  15. package/dist/app-sdk/src/WeaveBackgroundAPI.d.ts +81 -0
  16. package/dist/app-sdk/src/WeaveBackgroundAPI.d.ts.map +1 -0
  17. package/dist/app-sdk/src/WeaveBackgroundAPI.js +165 -0
  18. package/dist/app-sdk/src/WeaveBaseApp.d.ts +318 -0
  19. package/dist/app-sdk/src/WeaveBaseApp.d.ts.map +1 -0
  20. package/dist/app-sdk/src/WeaveBaseApp.js +434 -0
  21. package/dist/app-sdk/src/WeaveCronAPI.d.ts +68 -0
  22. package/dist/app-sdk/src/WeaveCronAPI.d.ts.map +1 -0
  23. package/dist/app-sdk/src/WeaveCronAPI.js +172 -0
  24. package/dist/app-sdk/src/WeaveDOMAPI.d.ts +593 -0
  25. package/dist/app-sdk/src/WeaveDOMAPI.d.ts.map +1 -0
  26. package/dist/app-sdk/src/WeaveDOMAPI.js +774 -0
  27. package/dist/app-sdk/src/global.d.ts +25 -0
  28. package/dist/app-sdk/src/global.d.ts.map +1 -0
  29. package/dist/app-sdk/src/global.js +23 -0
  30. package/dist/app-sdk/src/index.d.ts +14 -0
  31. package/dist/app-sdk/src/index.d.ts.map +1 -0
  32. package/dist/app-sdk/src/index.js +14 -0
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1 -1
  36. package/package.json +3 -3
  37. package/templates/WEAVE_SPEC.md +417 -1
@@ -0,0 +1,318 @@
1
+ /**
2
+ * Weave Base App
3
+ *
4
+ * Base class for all Weave apps. Provides common functionality and lifecycle methods.
5
+ * Third-party developers should extend this class instead of HTMLElement directly.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Define your settings and state types
10
+ * interface MyAppSettings {
11
+ * apiKey: string;
12
+ * endpoint: string;
13
+ * }
14
+ *
15
+ * interface MyAppState {
16
+ * count: number;
17
+ * isLoading: boolean;
18
+ * data: any[];
19
+ * }
20
+ *
21
+ * class MyApp extends WeaveBaseApp<MyAppSettings, MyAppState> {
22
+ * constructor() {
23
+ * super({
24
+ * id: 'my-app',
25
+ * name: 'My App',
26
+ * version: '1.0.0',
27
+ * category: 'utility',
28
+ * description: 'My custom app',
29
+ * author: 'Your Name',
30
+ * tags: ['custom'],
31
+ * // Enable auto-persist to survive page reloads
32
+ * persistState: true,
33
+ * });
34
+ *
35
+ * // Settings are now type-safe!
36
+ * const apiKey = this.appSettings?.apiKey; // ✅ TypeScript knows this exists
37
+ *
38
+ * // Initialize state with proper typing
39
+ * this.state = {
40
+ * count: 0,
41
+ * isLoading: false,
42
+ * data: []
43
+ * };
44
+ * }
45
+ *
46
+ * render() {
47
+ * return `<div>My App Content</div>`;
48
+ * }
49
+ *
50
+ * setupEventListeners() {
51
+ * // setState is also type-safe and auto-persists if enabled
52
+ * this.setState({ count: this.state.count + 1 }); // ✅ Type-safe
53
+ * }
54
+ * }
55
+ *
56
+ * customElements.define('my-app', MyApp);
57
+ * ```
58
+ */
59
+ /**
60
+ * Pending operation for multi-page flows
61
+ */
62
+ export interface PendingOperation {
63
+ type: string;
64
+ data: any;
65
+ targetUrl?: string;
66
+ }
67
+ /**
68
+ * App metadata configuration
69
+ */
70
+ export interface WeaveAppInfo {
71
+ /** Unique identifier for the app (kebab-case recommended) */
72
+ id: string;
73
+ /** Display name of the app */
74
+ name: string;
75
+ /** Semantic version (x.y.z) */
76
+ version: string;
77
+ /** Primary category for the app */
78
+ category: string;
79
+ /** Detailed description of the app */
80
+ description: string;
81
+ /** Author or organization name */
82
+ author: string;
83
+ /** Additional tags for search and categorization */
84
+ tags?: string[];
85
+ /**
86
+ * Enable automatic state persistence across page reloads.
87
+ * When true, state is automatically saved to background service on each setState() call.
88
+ * State is restored when the app initializes after a page reload.
89
+ * @default false
90
+ */
91
+ persistState?: boolean;
92
+ /**
93
+ * Debounce delay for state persistence in milliseconds.
94
+ * Prevents excessive saves when state changes rapidly.
95
+ * @default 100
96
+ */
97
+ persistDebounce?: number;
98
+ }
99
+ /**
100
+ * Base class for Weave apps
101
+ * @template TSettings - Type for app settings, defaults to an empty object
102
+ * @template TState - Type for app state, defaults to an empty object
103
+ */
104
+ export declare abstract class WeaveBaseApp<TSettings = Record<string, any>, TState = Record<string, any>> extends HTMLElement {
105
+ /** App metadata */
106
+ protected appInfo: WeaveAppInfo;
107
+ /** App settings (override in subclass) **/
108
+ protected appSettings?: TSettings;
109
+ /** App-specific state (override in subclass) */
110
+ protected state: TState;
111
+ /** Shadow root for style isolation */
112
+ private _shadowRoot;
113
+ /** App-specific API client instance (prevents app ID conflicts) */
114
+ protected weaveAPI: any;
115
+ /** Background API for state persistence */
116
+ private _backgroundAPI;
117
+ /** Cron API for scheduled tasks */
118
+ private _cronAPI;
119
+ /** App Instance API for cross-tab communication */
120
+ private _instancesAPI;
121
+ /** Debounced persist function */
122
+ private _debouncedPersist;
123
+ /** Flag to track if state has been restored */
124
+ private _stateRestored;
125
+ /** App UUID from registry */
126
+ private _appUuid;
127
+ /** User's company role (e.g., 'admin', 'member') */
128
+ protected companyRole: string | null;
129
+ /** Current user object */
130
+ protected currentUser: any;
131
+ /** Current company object */
132
+ protected currentCompany: any;
133
+ /**
134
+ * Creates a new Weave app
135
+ * @param appInfo - App metadata configuration
136
+ */
137
+ constructor(appInfo: WeaveAppInfo);
138
+ /**
139
+ * Get the background API for state persistence and pending operations
140
+ * Use this for manual state management or multi-page flows
141
+ */
142
+ protected get background(): any;
143
+ /**
144
+ * Get the cron API for scheduled tasks
145
+ */
146
+ protected get cron(): any;
147
+ /**
148
+ * Get the app instance API for cross-tab communication
149
+ *
150
+ * Use this to:
151
+ * - Discover other instances of your app across browser tabs
152
+ * - Claim/release controller status (for automation coordination)
153
+ * - Send messages between instances
154
+ * - Listen for instance changes
155
+ *
156
+ * @example
157
+ * // Register this instance and check for others
158
+ * const instances = await this.instances.register();
159
+ * if (instances.length > 1) {
160
+ * // Other instances exist
161
+ * }
162
+ *
163
+ * // Claim controller status
164
+ * const claimed = await this.instances.claimController();
165
+ *
166
+ * // Listen for messages from other instances
167
+ * this.instances.onMessage((msg) => {
168
+ * if (msg.type === 'YIELD_CONTROL') {
169
+ * // Another tab wants control
170
+ * }
171
+ * });
172
+ */
173
+ protected get instances(): any;
174
+ /**
175
+ * Register a cron job with a callback
176
+ *
177
+ * @param cronExpression - Standard cron expression (5 or 6 fields)
178
+ * - 5 fields: minute hour dayOfMonth month dayOfWeek
179
+ * - 6 fields: second minute hour dayOfMonth month dayOfWeek
180
+ * @param callback - Function to call when cron triggers
181
+ * @param jobName - Optional unique name for the job
182
+ * @returns Job ID if successful, null otherwise
183
+ *
184
+ * @example
185
+ * // Every second
186
+ * this.cronTab('* * * * * *', this.handleEverySecond);
187
+ *
188
+ * // Every minute
189
+ * this.cronTab('* * * * *', this.handleEveryMinute);
190
+ *
191
+ * // Every 5 seconds
192
+ * this.cronTab('0/5 * * * * *', this.handleEvery5Seconds);
193
+ *
194
+ * // Every hour at minute 0
195
+ * this.cronTab('0 * * * *', this.handleEveryHour);
196
+ */
197
+ protected cronTab(cronExpression: string, callback: () => void | Promise<void>, jobName?: string): Promise<string | null>;
198
+ /**
199
+ * Unregister a cron job by name
200
+ */
201
+ protected cronUnregister(jobName: string): Promise<boolean>;
202
+ /**
203
+ * Unregister all cron jobs for this app
204
+ */
205
+ protected cronUnregisterAll(): Promise<number>;
206
+ /**
207
+ * Get shadow root (override native property)
208
+ */
209
+ get shadowRoot(): ShadowRoot;
210
+ /**
211
+ * Background service - optional override in subclass
212
+ * Called immediately after app instantiation, before DOM attachment
213
+ * Use this for background tasks like URL monitoring, event listening, etc.
214
+ */
215
+ protected onBackgroundService?(): void;
216
+ /**
217
+ * URL change handler - optional override in subclass
218
+ * Called when the page URL changes (SPA navigation)
219
+ * @param url - The new URL
220
+ */
221
+ protected onUrlChange?(url: string): void;
222
+ /**
223
+ * Server event handler - optional override in subclass
224
+ * Called when the server sends an event to this app via WebSocket
225
+ * Works whether the app is in background or foreground mode
226
+ *
227
+ * @param event - The event name (e.g., 'form_completed')
228
+ * @param data - Optional event data from the server
229
+ *
230
+ * @example
231
+ * protected onServerEvent(event: string, data?: Record<string, any>): void {
232
+ * if (event === 'form_completed') {
233
+ * console.log('Form completed:', data);
234
+ * this.refreshData();
235
+ * }
236
+ * }
237
+ */
238
+ protected onServerEvent?(event: string, data?: Record<string, any>): void;
239
+ /**
240
+ * Render method - must be implemented by subclass
241
+ * Should return HTML string or directly manipulate shadowRoot
242
+ */
243
+ protected render(): void;
244
+ /**
245
+ * Setup event listeners - optional override in subclass
246
+ */
247
+ protected setupEventListeners(): void;
248
+ /**
249
+ * Initialize background service
250
+ * Called by BackgroundAppManager after instantiation
251
+ */
252
+ initializeBackgroundService(): void;
253
+ /**
254
+ * Handle URL change
255
+ * Called by BackgroundAppManager when URL changes
256
+ */
257
+ handleUrlChange(url: string): void;
258
+ /**
259
+ * Handle server event
260
+ * Called by BackgroundAppManager when a WebSocket event is received for this app
261
+ */
262
+ handleServerEvent(event: string, data?: Record<string, any>): void;
263
+ /**
264
+ * Lifecycle: Called when element is added to DOM
265
+ * This happens when user opens the app in the drawer
266
+ */
267
+ connectedCallback(): void;
268
+ /**
269
+ * Lifecycle: Called when element is removed from DOM
270
+ */
271
+ disconnectedCallback(): void;
272
+ /**
273
+ * Cleanup method - optional override in subclass
274
+ * Called when app is disconnected from DOM
275
+ */
276
+ protected cleanup(): void;
277
+ /**
278
+ * Get app configuration (for Weave Platform)
279
+ */
280
+ getAppInfo(): WeaveAppInfo;
281
+ /**
282
+ * Get current app state (for Weave Platform)
283
+ */
284
+ getAppState(): Record<string, any>;
285
+ /**
286
+ * Set app configuration (for Weave Platform)
287
+ * Override this method to handle configuration updates
288
+ */
289
+ setAppConfig(_config: Record<string, any>): void;
290
+ /**
291
+ * Helper: Update app state
292
+ * If persistState is enabled, state is automatically saved to background service
293
+ */
294
+ protected setState(updates: Partial<TState>): void;
295
+ /**
296
+ * Persist current state to background service
297
+ * Called automatically when persistState is enabled
298
+ */
299
+ private _persistState;
300
+ /**
301
+ * Restore state from background service
302
+ * Called by BackgroundAppManager during initialization
303
+ */
304
+ restoreState(): Promise<boolean>;
305
+ /**
306
+ * Helper: Render HTML into shadow root
307
+ */
308
+ protected renderHTML(html: string): void;
309
+ /**
310
+ * Helper: Query element in shadow root
311
+ */
312
+ protected query<T extends Element = Element>(selector: string): T | null;
313
+ /**
314
+ * Helper: Query all elements in shadow root
315
+ */
316
+ protected queryAll<T extends Element = Element>(selector: string): NodeListOf<T>;
317
+ }
318
+ //# sourceMappingURL=WeaveBaseApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WeaveBaseApp.d.ts","sourceRoot":"","sources":["../../../src/WeaveBaseApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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