@ofocus/sdk 0.1.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 (200) hide show
  1. package/README.md +80 -0
  2. package/api-report/ofocus-sdk.api.md +564 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/applescript.d.ts +30 -0
  5. package/dist/applescript.d.ts.map +1 -0
  6. package/dist/applescript.js +142 -0
  7. package/dist/applescript.js.map +1 -0
  8. package/dist/commands/batch.d.ts +23 -0
  9. package/dist/commands/batch.d.ts.map +1 -0
  10. package/dist/commands/batch.js +324 -0
  11. package/dist/commands/batch.js.map +1 -0
  12. package/dist/commands/complete.d.ts +14 -0
  13. package/dist/commands/complete.d.ts.map +1 -0
  14. package/dist/commands/complete.js +37 -0
  15. package/dist/commands/complete.js.map +1 -0
  16. package/dist/commands/create-project.d.ts +6 -0
  17. package/dist/commands/create-project.d.ts.map +1 -0
  18. package/dist/commands/create-project.js +124 -0
  19. package/dist/commands/create-project.js.map +1 -0
  20. package/dist/commands/drop.d.ts +26 -0
  21. package/dist/commands/drop.d.ts.map +1 -0
  22. package/dist/commands/drop.js +62 -0
  23. package/dist/commands/drop.js.map +1 -0
  24. package/dist/commands/folders.d.ts +10 -0
  25. package/dist/commands/folders.d.ts.map +1 -0
  26. package/dist/commands/folders.js +150 -0
  27. package/dist/commands/folders.js.map +1 -0
  28. package/dist/commands/inbox.d.ts +6 -0
  29. package/dist/commands/inbox.d.ts.map +1 -0
  30. package/dist/commands/inbox.js +124 -0
  31. package/dist/commands/inbox.js.map +1 -0
  32. package/dist/commands/perspectives.d.ts +20 -0
  33. package/dist/commands/perspectives.d.ts.map +1 -0
  34. package/dist/commands/perspectives.js +166 -0
  35. package/dist/commands/perspectives.js.map +1 -0
  36. package/dist/commands/projects.d.ts +6 -0
  37. package/dist/commands/projects.d.ts.map +1 -0
  38. package/dist/commands/projects.js +113 -0
  39. package/dist/commands/projects.js.map +1 -0
  40. package/dist/commands/repetition.d.ts +17 -0
  41. package/dist/commands/repetition.d.ts.map +1 -0
  42. package/dist/commands/repetition.js +59 -0
  43. package/dist/commands/repetition.js.map +1 -0
  44. package/dist/commands/review.d.ts +10 -0
  45. package/dist/commands/review.d.ts.map +1 -0
  46. package/dist/commands/review.js +132 -0
  47. package/dist/commands/review.js.map +1 -0
  48. package/dist/commands/search.d.ts +6 -0
  49. package/dist/commands/search.d.ts.map +1 -0
  50. package/dist/commands/search.js +150 -0
  51. package/dist/commands/search.js.map +1 -0
  52. package/dist/commands/subtasks.d.ts +14 -0
  53. package/dist/commands/subtasks.d.ts.map +1 -0
  54. package/dist/commands/subtasks.js +370 -0
  55. package/dist/commands/subtasks.js.map +1 -0
  56. package/dist/commands/tags-crud.d.ts +22 -0
  57. package/dist/commands/tags-crud.d.ts.map +1 -0
  58. package/dist/commands/tags-crud.js +187 -0
  59. package/dist/commands/tags-crud.js.map +1 -0
  60. package/dist/commands/tags.d.ts +6 -0
  61. package/dist/commands/tags.d.ts.map +1 -0
  62. package/dist/commands/tags.js +61 -0
  63. package/dist/commands/tags.js.map +1 -0
  64. package/dist/commands/tasks.d.ts +6 -0
  65. package/dist/commands/tasks.d.ts.map +1 -0
  66. package/dist/commands/tasks.js +160 -0
  67. package/dist/commands/tasks.js.map +1 -0
  68. package/dist/commands/update.d.ts +6 -0
  69. package/dist/commands/update.d.ts.map +1 -0
  70. package/dist/commands/update.js +179 -0
  71. package/dist/commands/update.js.map +1 -0
  72. package/dist/errors.d.ts +38 -0
  73. package/dist/errors.d.ts.map +1 -0
  74. package/dist/errors.js +77 -0
  75. package/dist/errors.js.map +1 -0
  76. package/dist/escape.d.ts +6 -0
  77. package/dist/escape.d.ts.map +1 -0
  78. package/dist/escape.js +8 -0
  79. package/dist/escape.js.map +1 -0
  80. package/dist/index.d.ts +30 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +36 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/ofocus-sdk.d.ts +608 -0
  85. package/dist/result.d.ts +15 -0
  86. package/dist/result.d.ts.map +1 -0
  87. package/dist/result.js +29 -0
  88. package/dist/result.js.map +1 -0
  89. package/dist/types.d.ts +228 -0
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/types.js +2 -0
  92. package/dist/types.js.map +1 -0
  93. package/dist/validation.d.ts +57 -0
  94. package/dist/validation.d.ts.map +1 -0
  95. package/dist/validation.js +172 -0
  96. package/dist/validation.js.map +1 -0
  97. package/docs/index.md +30 -0
  98. package/docs/sdk.addtoinbox.md +68 -0
  99. package/docs/sdk.applescriptresult.data.md +11 -0
  100. package/docs/sdk.applescriptresult.error.md +11 -0
  101. package/docs/sdk.applescriptresult.md +92 -0
  102. package/docs/sdk.applescriptresult.success.md +11 -0
  103. package/docs/sdk.clierror.code.md +11 -0
  104. package/docs/sdk.clierror.details.md +11 -0
  105. package/docs/sdk.clierror.md +92 -0
  106. package/docs/sdk.clierror.message.md +11 -0
  107. package/docs/sdk.clioutput.data.md +11 -0
  108. package/docs/sdk.clioutput.error.md +11 -0
  109. package/docs/sdk.clioutput.md +90 -0
  110. package/docs/sdk.clioutput.success.md +11 -0
  111. package/docs/sdk.commandinfo.description.md +11 -0
  112. package/docs/sdk.commandinfo.md +90 -0
  113. package/docs/sdk.commandinfo.name.md +11 -0
  114. package/docs/sdk.commandinfo.usage.md +11 -0
  115. package/docs/sdk.completeresult.completed.md +11 -0
  116. package/docs/sdk.completeresult.md +90 -0
  117. package/docs/sdk.completeresult.taskid.md +11 -0
  118. package/docs/sdk.completeresult.taskname.md +11 -0
  119. package/docs/sdk.completetask.md +52 -0
  120. package/docs/sdk.createerror.md +82 -0
  121. package/docs/sdk.errorcode.md +24 -0
  122. package/docs/sdk.escapeapplescript.md +52 -0
  123. package/docs/sdk.failure.md +52 -0
  124. package/docs/sdk.failuremessage.md +52 -0
  125. package/docs/sdk.inboxoptions.defer.md +11 -0
  126. package/docs/sdk.inboxoptions.due.md +11 -0
  127. package/docs/sdk.inboxoptions.flag.md +11 -0
  128. package/docs/sdk.inboxoptions.md +134 -0
  129. package/docs/sdk.inboxoptions.note.md +11 -0
  130. package/docs/sdk.inboxoptions.tags.md +11 -0
  131. package/docs/sdk.jsonhelpers.md +13 -0
  132. package/docs/sdk.md +471 -0
  133. package/docs/sdk.ofperspective.id.md +11 -0
  134. package/docs/sdk.ofperspective.md +73 -0
  135. package/docs/sdk.ofperspective.name.md +11 -0
  136. package/docs/sdk.ofproject.folderid.md +11 -0
  137. package/docs/sdk.ofproject.foldername.md +11 -0
  138. package/docs/sdk.ofproject.id.md +11 -0
  139. package/docs/sdk.ofproject.md +192 -0
  140. package/docs/sdk.ofproject.name.md +11 -0
  141. package/docs/sdk.ofproject.note.md +11 -0
  142. package/docs/sdk.ofproject.remainingtaskcount.md +11 -0
  143. package/docs/sdk.ofproject.sequential.md +11 -0
  144. package/docs/sdk.ofproject.status.md +11 -0
  145. package/docs/sdk.ofproject.taskcount.md +11 -0
  146. package/docs/sdk.oftag.availabletaskcount.md +11 -0
  147. package/docs/sdk.oftag.id.md +11 -0
  148. package/docs/sdk.oftag.md +124 -0
  149. package/docs/sdk.oftag.name.md +11 -0
  150. package/docs/sdk.oftag.parentid.md +11 -0
  151. package/docs/sdk.oftag.parentname.md +11 -0
  152. package/docs/sdk.oftask.completed.md +11 -0
  153. package/docs/sdk.oftask.completiondate.md +11 -0
  154. package/docs/sdk.oftask.deferdate.md +11 -0
  155. package/docs/sdk.oftask.duedate.md +11 -0
  156. package/docs/sdk.oftask.flagged.md +11 -0
  157. package/docs/sdk.oftask.id.md +11 -0
  158. package/docs/sdk.oftask.md +226 -0
  159. package/docs/sdk.oftask.name.md +11 -0
  160. package/docs/sdk.oftask.note.md +11 -0
  161. package/docs/sdk.oftask.projectid.md +11 -0
  162. package/docs/sdk.oftask.projectname.md +11 -0
  163. package/docs/sdk.oftask.tags.md +11 -0
  164. package/docs/sdk.omnifocusscript.md +52 -0
  165. package/docs/sdk.omnifocusscriptwithhelpers.md +52 -0
  166. package/docs/sdk.parseapplescripterror.md +52 -0
  167. package/docs/sdk.projectqueryoptions.folder.md +11 -0
  168. package/docs/sdk.projectqueryoptions.md +96 -0
  169. package/docs/sdk.projectqueryoptions.sequential.md +11 -0
  170. package/docs/sdk.projectqueryoptions.status.md +11 -0
  171. package/docs/sdk.queryprojects.md +54 -0
  172. package/docs/sdk.querytags.md +54 -0
  173. package/docs/sdk.querytasks.md +54 -0
  174. package/docs/sdk.runapplescript.md +52 -0
  175. package/docs/sdk.runapplescriptfile.md +68 -0
  176. package/docs/sdk.success.md +52 -0
  177. package/docs/sdk.tagqueryoptions.md +58 -0
  178. package/docs/sdk.tagqueryoptions.parent.md +11 -0
  179. package/docs/sdk.taskqueryoptions.available.md +11 -0
  180. package/docs/sdk.taskqueryoptions.completed.md +11 -0
  181. package/docs/sdk.taskqueryoptions.dueafter.md +11 -0
  182. package/docs/sdk.taskqueryoptions.duebefore.md +11 -0
  183. package/docs/sdk.taskqueryoptions.flagged.md +11 -0
  184. package/docs/sdk.taskqueryoptions.md +172 -0
  185. package/docs/sdk.taskqueryoptions.project.md +11 -0
  186. package/docs/sdk.taskqueryoptions.tag.md +11 -0
  187. package/docs/sdk.taskupdateoptions.defer.md +11 -0
  188. package/docs/sdk.taskupdateoptions.due.md +11 -0
  189. package/docs/sdk.taskupdateoptions.flag.md +11 -0
  190. package/docs/sdk.taskupdateoptions.md +172 -0
  191. package/docs/sdk.taskupdateoptions.note.md +11 -0
  192. package/docs/sdk.taskupdateoptions.project.md +11 -0
  193. package/docs/sdk.taskupdateoptions.tags.md +11 -0
  194. package/docs/sdk.taskupdateoptions.title.md +11 -0
  195. package/docs/sdk.updatetask.md +66 -0
  196. package/docs/sdk.validatedatestring.md +54 -0
  197. package/docs/sdk.validateid.md +66 -0
  198. package/docs/sdk.validateprojectname.md +52 -0
  199. package/docs/sdk.validatetags.md +52 -0
  200. package/package.json +51 -0
@@ -0,0 +1,370 @@
1
+ import { success, failure } from "../result.js";
2
+ import { ErrorCode, createError } from "../errors.js";
3
+ import { validateId, validateDateString, validateTags, validateEstimatedMinutes, validateRepetitionRule, } from "../validation.js";
4
+ import { escapeAppleScript } from "../escape.js";
5
+ import { runAppleScript, omniFocusScriptWithHelpers, } from "../applescript.js";
6
+ import { buildRepetitionRuleScript } from "./repetition.js";
7
+ /**
8
+ * Create a subtask under a parent task in OmniFocus.
9
+ */
10
+ export async function createSubtask(title, parentTaskId, options = {}) {
11
+ // Validate inputs
12
+ const idError = validateId(parentTaskId, "task");
13
+ if (idError)
14
+ return failure(idError);
15
+ if (!title || title.trim() === "") {
16
+ return failure(createError(ErrorCode.VALIDATION_ERROR, "Task title cannot be empty"));
17
+ }
18
+ if (options.due !== undefined) {
19
+ const dueError = validateDateString(options.due);
20
+ if (dueError)
21
+ return failure(dueError);
22
+ }
23
+ if (options.defer !== undefined) {
24
+ const deferError = validateDateString(options.defer);
25
+ if (deferError)
26
+ return failure(deferError);
27
+ }
28
+ const tagsError = validateTags(options.tags);
29
+ if (tagsError)
30
+ return failure(tagsError);
31
+ const estimateError = validateEstimatedMinutes(options.estimatedMinutes);
32
+ if (estimateError)
33
+ return failure(estimateError);
34
+ const repeatError = validateRepetitionRule(options.repeat);
35
+ if (repeatError)
36
+ return failure(repeatError);
37
+ // Build properties for the new subtask
38
+ const properties = [`name:"${escapeAppleScript(title)}"`];
39
+ if (options.note !== undefined) {
40
+ properties.push(`note:"${escapeAppleScript(options.note)}"`);
41
+ }
42
+ if (options.flag === true) {
43
+ properties.push("flagged:true");
44
+ }
45
+ if (options.due !== undefined) {
46
+ properties.push(`due date:date "${options.due}"`);
47
+ }
48
+ if (options.defer !== undefined) {
49
+ properties.push(`defer date:date "${options.defer}"`);
50
+ }
51
+ if (options.estimatedMinutes !== undefined) {
52
+ properties.push(`estimated minutes:${String(options.estimatedMinutes)}`);
53
+ }
54
+ // Build repetition rule script if provided
55
+ const repetitionScript = options.repeat
56
+ ? buildRepetitionRuleScript("newTask", options.repeat)
57
+ : "";
58
+ let tagScript = "";
59
+ if (options.tags && options.tags.length > 0) {
60
+ for (const tagName of options.tags) {
61
+ tagScript += `
62
+ try
63
+ set theTag to first flattened tag whose name is "${escapeAppleScript(tagName)}"
64
+ add theTag to tags of newTask
65
+ end try
66
+ `;
67
+ }
68
+ }
69
+ const script = `
70
+ set parentTask to first flattened task whose id is "${escapeAppleScript(parentTaskId)}"
71
+ set newTask to make new task at end of tasks of parentTask with properties {${properties.join(", ")}}
72
+
73
+ ${tagScript}
74
+ ${repetitionScript}
75
+
76
+ -- Return the created task info
77
+ set taskId to id of newTask
78
+ set taskName to name of newTask
79
+ set taskNote to note of newTask
80
+ set taskFlagged to flagged of newTask
81
+ set taskCompleted to completed of newTask
82
+
83
+ set dueStr to ""
84
+ try
85
+ set dueStr to (due date of newTask) as string
86
+ end try
87
+
88
+ set deferStr to ""
89
+ try
90
+ set deferStr to (defer date of newTask) as string
91
+ end try
92
+
93
+ set projId to ""
94
+ set projName to ""
95
+ try
96
+ set proj to containing project of newTask
97
+ set projId to id of proj
98
+ set projName to name of proj
99
+ end try
100
+
101
+ set tagNames to {}
102
+ repeat with t in tags of newTask
103
+ set end of tagNames to name of t
104
+ end repeat
105
+
106
+ set estMinutes to 0
107
+ try
108
+ set estMinutes to estimated minutes of newTask
109
+ if estMinutes is missing value then set estMinutes to 0
110
+ end try
111
+
112
+ set parentId to ""
113
+ set parentName to ""
114
+ try
115
+ set pTask to container of newTask
116
+ if class of pTask is task then
117
+ set parentId to id of pTask
118
+ set parentName to name of pTask
119
+ end if
120
+ end try
121
+
122
+ set childCount to count of tasks of newTask
123
+ set isGroup to childCount > 0
124
+
125
+ return "{" & ¬
126
+ "\\"id\\": \\"" & taskId & "\\"," & ¬
127
+ "\\"name\\": \\"" & (my escapeJson(taskName)) & "\\"," & ¬
128
+ "\\"note\\": " & (my jsonString(taskNote)) & "," & ¬
129
+ "\\"flagged\\": " & taskFlagged & "," & ¬
130
+ "\\"completed\\": " & taskCompleted & "," & ¬
131
+ "\\"dueDate\\": " & (my jsonString(dueStr)) & "," & ¬
132
+ "\\"deferDate\\": " & (my jsonString(deferStr)) & "," & ¬
133
+ "\\"completionDate\\": null," & ¬
134
+ "\\"projectId\\": " & (my jsonString(projId)) & "," & ¬
135
+ "\\"projectName\\": " & (my jsonString(projName)) & "," & ¬
136
+ "\\"tags\\": " & (my jsonArray(tagNames)) & "," & ¬
137
+ "\\"estimatedMinutes\\": " & estMinutes & "," & ¬
138
+ "\\"parentTaskId\\": " & (my jsonString(parentId)) & "," & ¬
139
+ "\\"parentTaskName\\": " & (my jsonString(parentName)) & "," & ¬
140
+ "\\"childTaskCount\\": " & childCount & "," & ¬
141
+ "\\"isActionGroup\\": " & isGroup & ¬
142
+ "}"
143
+ `;
144
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
145
+ if (!result.success) {
146
+ return failure(result.error ??
147
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to create subtask"));
148
+ }
149
+ if (result.data === undefined) {
150
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No task data returned"));
151
+ }
152
+ return success(result.data);
153
+ }
154
+ /**
155
+ * Query subtasks of a parent task in OmniFocus.
156
+ */
157
+ export async function querySubtasks(parentTaskId, options = {}) {
158
+ // Validate parent task ID
159
+ const idError = validateId(parentTaskId, "task");
160
+ if (idError)
161
+ return failure(idError);
162
+ // Build filter conditions
163
+ const conditions = [];
164
+ if (options.completed === true) {
165
+ conditions.push("completed is true");
166
+ }
167
+ else if (options.completed === false) {
168
+ conditions.push("completed is false");
169
+ }
170
+ if (options.flagged === true) {
171
+ conditions.push("flagged is true");
172
+ }
173
+ else if (options.flagged === false) {
174
+ conditions.push("flagged is false");
175
+ }
176
+ const whereClause = conditions.length > 0 ? ` where ${conditions.join(" and ")}` : "";
177
+ const script = `
178
+ set parentTask to first flattened task whose id is "${escapeAppleScript(parentTaskId)}"
179
+ set output to "["
180
+ set isFirst to true
181
+
182
+ set childTasks to tasks of parentTask${whereClause}
183
+
184
+ repeat with t in childTasks
185
+ if not isFirst then set output to output & ","
186
+ set isFirst to false
187
+
188
+ set taskId to id of t
189
+ set taskName to name of t
190
+ set taskNote to note of t
191
+ set taskFlagged to flagged of t
192
+ set taskCompleted to completed of t
193
+
194
+ set dueStr to ""
195
+ try
196
+ set dueStr to (due date of t) as string
197
+ end try
198
+
199
+ set deferStr to ""
200
+ try
201
+ set deferStr to (defer date of t) as string
202
+ end try
203
+
204
+ set completionStr to ""
205
+ try
206
+ set completionStr to (completion date of t) as string
207
+ end try
208
+
209
+ set projId to ""
210
+ set projName to ""
211
+ try
212
+ set proj to containing project of t
213
+ set projId to id of proj
214
+ set projName to name of proj
215
+ end try
216
+
217
+ set tagNames to {}
218
+ repeat with tg in tags of t
219
+ set end of tagNames to name of tg
220
+ end repeat
221
+
222
+ set estMinutes to 0
223
+ try
224
+ set estMinutes to estimated minutes of t
225
+ if estMinutes is missing value then set estMinutes to 0
226
+ end try
227
+
228
+ set pTaskId to ""
229
+ set pTaskName to ""
230
+ try
231
+ set pTask to container of t
232
+ if class of pTask is task then
233
+ set pTaskId to id of pTask
234
+ set pTaskName to name of pTask
235
+ end if
236
+ end try
237
+
238
+ set childCount to count of tasks of t
239
+ set isGroup to childCount > 0
240
+
241
+ set output to output & "{" & ¬
242
+ "\\"id\\": \\"" & taskId & "\\"," & ¬
243
+ "\\"name\\": \\"" & (my escapeJson(taskName)) & "\\"," & ¬
244
+ "\\"note\\": " & (my jsonString(taskNote)) & "," & ¬
245
+ "\\"flagged\\": " & taskFlagged & "," & ¬
246
+ "\\"completed\\": " & taskCompleted & "," & ¬
247
+ "\\"dueDate\\": " & (my jsonString(dueStr)) & "," & ¬
248
+ "\\"deferDate\\": " & (my jsonString(deferStr)) & "," & ¬
249
+ "\\"completionDate\\": " & (my jsonString(completionStr)) & "," & ¬
250
+ "\\"projectId\\": " & (my jsonString(projId)) & "," & ¬
251
+ "\\"projectName\\": " & (my jsonString(projName)) & "," & ¬
252
+ "\\"tags\\": " & (my jsonArray(tagNames)) & "," & ¬
253
+ "\\"estimatedMinutes\\": " & estMinutes & "," & ¬
254
+ "\\"parentTaskId\\": " & (my jsonString(pTaskId)) & "," & ¬
255
+ "\\"parentTaskName\\": " & (my jsonString(pTaskName)) & "," & ¬
256
+ "\\"childTaskCount\\": " & childCount & "," & ¬
257
+ "\\"isActionGroup\\": " & isGroup & ¬
258
+ "}"
259
+ end repeat
260
+
261
+ return output & "]"
262
+ `;
263
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
264
+ if (!result.success) {
265
+ return failure(result.error ??
266
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to query subtasks"));
267
+ }
268
+ return success(result.data ?? []);
269
+ }
270
+ /**
271
+ * Move a task to become a subtask of another task.
272
+ */
273
+ export async function moveTaskToParent(taskId, parentTaskId) {
274
+ // Validate task IDs
275
+ const taskIdError = validateId(taskId, "task");
276
+ if (taskIdError)
277
+ return failure(taskIdError);
278
+ const parentIdError = validateId(parentTaskId, "task");
279
+ if (parentIdError)
280
+ return failure(parentIdError);
281
+ const script = `
282
+ set theTask to first flattened task whose id is "${escapeAppleScript(taskId)}"
283
+ set parentTask to first flattened task whose id is "${escapeAppleScript(parentTaskId)}"
284
+
285
+ move theTask to end of tasks of parentTask
286
+
287
+ -- Return updated task info
288
+ set taskId to id of theTask
289
+ set taskName to name of theTask
290
+ set taskNote to note of theTask
291
+ set taskFlagged to flagged of theTask
292
+ set taskCompleted to completed of theTask
293
+
294
+ set dueStr to ""
295
+ try
296
+ set dueStr to (due date of theTask) as string
297
+ end try
298
+
299
+ set deferStr to ""
300
+ try
301
+ set deferStr to (defer date of theTask) as string
302
+ end try
303
+
304
+ set completionStr to ""
305
+ try
306
+ set completionStr to (completion date of theTask) as string
307
+ end try
308
+
309
+ set projId to ""
310
+ set projName to ""
311
+ try
312
+ set proj to containing project of theTask
313
+ set projId to id of proj
314
+ set projName to name of proj
315
+ end try
316
+
317
+ set tagNames to {}
318
+ repeat with t in tags of theTask
319
+ set end of tagNames to name of t
320
+ end repeat
321
+
322
+ set estMinutes to 0
323
+ try
324
+ set estMinutes to estimated minutes of theTask
325
+ if estMinutes is missing value then set estMinutes to 0
326
+ end try
327
+
328
+ set pTaskId to ""
329
+ set pTaskName to ""
330
+ try
331
+ set pTask to container of theTask
332
+ if class of pTask is task then
333
+ set pTaskId to id of pTask
334
+ set pTaskName to name of pTask
335
+ end if
336
+ end try
337
+
338
+ set childCount to count of tasks of theTask
339
+ set isGroup to childCount > 0
340
+
341
+ return "{" & ¬
342
+ "\\"id\\": \\"" & taskId & "\\"," & ¬
343
+ "\\"name\\": \\"" & (my escapeJson(taskName)) & "\\"," & ¬
344
+ "\\"note\\": " & (my jsonString(taskNote)) & "," & ¬
345
+ "\\"flagged\\": " & taskFlagged & "," & ¬
346
+ "\\"completed\\": " & taskCompleted & "," & ¬
347
+ "\\"dueDate\\": " & (my jsonString(dueStr)) & "," & ¬
348
+ "\\"deferDate\\": " & (my jsonString(deferStr)) & "," & ¬
349
+ "\\"completionDate\\": " & (my jsonString(completionStr)) & "," & ¬
350
+ "\\"projectId\\": " & (my jsonString(projId)) & "," & ¬
351
+ "\\"projectName\\": " & (my jsonString(projName)) & "," & ¬
352
+ "\\"tags\\": " & (my jsonArray(tagNames)) & "," & ¬
353
+ "\\"estimatedMinutes\\": " & estMinutes & "," & ¬
354
+ "\\"parentTaskId\\": " & (my jsonString(pTaskId)) & "," & ¬
355
+ "\\"parentTaskName\\": " & (my jsonString(pTaskName)) & "," & ¬
356
+ "\\"childTaskCount\\": " & childCount & "," & ¬
357
+ "\\"isActionGroup\\": " & isGroup & ¬
358
+ "}"
359
+ `;
360
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
361
+ if (!result.success) {
362
+ return failure(result.error ??
363
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to move task"));
364
+ }
365
+ if (result.data === undefined) {
366
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No task data returned"));
367
+ }
368
+ return success(result.data);
369
+ }
370
+ //# sourceMappingURL=subtasks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subtasks.js","sourceRoot":"","sources":["../../src/commands/subtasks.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,cAAc,EACd,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAAa,EACb,YAAoB,EACpB,UAAwB,EAAE;IAE1B,kBAAkB;IAClB,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IAErC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAClC,OAAO,OAAO,CACZ,WAAW,CAAC,SAAS,CAAC,gBAAgB,EAAE,4BAA4B,CAAC,CACtE,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjD,IAAI,QAAQ;YAAE,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,UAAU,GAAG,kBAAkB,CAAC,O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../types.js";
2
+ /**
3
+ * Result from deleting a tag.
4
+ */
5
+ export interface DeleteTagResult {
6
+ tagId: string;
7
+ deleted: true;
8
+ }
9
+ /**
10
+ * Create a new tag in OmniFocus.
11
+ */
12
+ export declare function createTag(name: string, options?: CreateTagOptions): Promise<CliOutput<OFTag>>;
13
+ /**
14
+ * Update an existing tag in OmniFocus.
15
+ */
16
+ export declare function updateTag(tagId: string, options: UpdateTagOptions): Promise<CliOutput<OFTag>>;
17
+ /**
18
+ * Delete a tag from OmniFocus.
19
+ * Note: This cannot be undone.
20
+ */
21
+ export declare function deleteTag(tagId: string): Promise<CliOutput<DeleteTagResult>>;
22
+ //# sourceMappingURL=tags-crud.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags-crud.d.ts","sourceRoot":"","sources":["../../src/commands/tags-crud.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,EACN,MAAM,aAAa,CAAC;AAUrB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,IAAI,CAAC;CACf;AAED;;GAEG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CA8E3B;AAED;;GAEG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CA6F3B;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CA4BrC"}
@@ -0,0 +1,187 @@
1
+ import { success, failure } from "../result.js";
2
+ import { ErrorCode, createError } from "../errors.js";
3
+ import { validateId, validateTagName } from "../validation.js";
4
+ import { escapeAppleScript } from "../escape.js";
5
+ import { runAppleScript, omniFocusScriptWithHelpers, } from "../applescript.js";
6
+ /**
7
+ * Create a new tag in OmniFocus.
8
+ */
9
+ export async function createTag(name, options = {}) {
10
+ // Validate tag name (required for create)
11
+ const nameError = validateTagName(name);
12
+ if (nameError)
13
+ return failure(nameError);
14
+ // Validate optional inputs
15
+ if (options.parentTagId !== undefined) {
16
+ const parentIdError = validateId(options.parentTagId, "tag");
17
+ if (parentIdError)
18
+ return failure(parentIdError);
19
+ }
20
+ if (options.parentTagName !== undefined) {
21
+ const parentNameError = validateTagName(options.parentTagName);
22
+ if (parentNameError)
23
+ return failure(parentNameError);
24
+ }
25
+ // Build script based on whether we're placing under a parent tag
26
+ let findParent = "";
27
+ let makeTag = "";
28
+ if (options.parentTagId) {
29
+ findParent = `set parentTag to first flattened tag whose id is "${escapeAppleScript(options.parentTagId)}"`;
30
+ makeTag = `set newTag to make new tag at end of tags of parentTag with properties {name:"${escapeAppleScript(name)}"}`;
31
+ }
32
+ else if (options.parentTagName) {
33
+ findParent = `set parentTag to first flattened tag whose name is "${escapeAppleScript(options.parentTagName)}"`;
34
+ makeTag = `set newTag to make new tag at end of tags of parentTag with properties {name:"${escapeAppleScript(name)}"}`;
35
+ }
36
+ else {
37
+ findParent = "";
38
+ makeTag = `set newTag to make new tag with properties {name:"${escapeAppleScript(name)}"}`;
39
+ }
40
+ const script = `
41
+ ${findParent}
42
+ ${makeTag}
43
+
44
+ -- Return the created tag info
45
+ set tagId to id of newTag
46
+ set tagName to name of newTag
47
+
48
+ set parentId to ""
49
+ set parentName to ""
50
+ try
51
+ set p to container of newTag
52
+ if class of p is tag then
53
+ set parentId to id of p
54
+ set parentName to name of p
55
+ end if
56
+ end try
57
+
58
+ set availCount to count of (flattened tasks whose primary tag is newTag and completed is false)
59
+
60
+ return "{" & ¬
61
+ "\\"id\\": \\"" & tagId & "\\"," & ¬
62
+ "\\"name\\": \\"" & (my escapeJson(tagName)) & "\\"," & ¬
63
+ "\\"parentId\\": " & (my jsonString(parentId)) & "," & ¬
64
+ "\\"parentName\\": " & (my jsonString(parentName)) & "," & ¬
65
+ "\\"availableTaskCount\\": " & availCount & ¬
66
+ "}"
67
+ `;
68
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
69
+ if (!result.success) {
70
+ return failure(result.error ??
71
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to create tag"));
72
+ }
73
+ if (result.data === undefined) {
74
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No tag data returned"));
75
+ }
76
+ return success(result.data);
77
+ }
78
+ /**
79
+ * Update an existing tag in OmniFocus.
80
+ */
81
+ export async function updateTag(tagId, options) {
82
+ // Validate tag ID
83
+ const idError = validateId(tagId, "tag");
84
+ if (idError)
85
+ return failure(idError);
86
+ // Validate optional inputs
87
+ if (options.name !== undefined) {
88
+ const nameError = validateTagName(options.name);
89
+ if (nameError)
90
+ return failure(nameError);
91
+ }
92
+ if (options.parentTagId !== undefined) {
93
+ const parentIdError = validateId(options.parentTagId, "tag");
94
+ if (parentIdError)
95
+ return failure(parentIdError);
96
+ }
97
+ if (options.parentTagName !== undefined) {
98
+ const parentNameError = validateTagName(options.parentTagName);
99
+ if (parentNameError)
100
+ return failure(parentNameError);
101
+ }
102
+ // Build the update statements
103
+ const updates = [];
104
+ if (options.name !== undefined) {
105
+ updates.push(`set name of theTag to "${escapeAppleScript(options.name)}"`);
106
+ }
107
+ // Handle reparenting
108
+ let reparentScript = "";
109
+ if (options.parentTagId !== undefined) {
110
+ reparentScript = `
111
+ set newParent to first flattened tag whose id is "${escapeAppleScript(options.parentTagId)}"
112
+ move theTag to end of tags of newParent
113
+ `;
114
+ }
115
+ else if (options.parentTagName !== undefined) {
116
+ reparentScript = `
117
+ set newParent to first flattened tag whose name is "${escapeAppleScript(options.parentTagName)}"
118
+ move theTag to end of tags of newParent
119
+ `;
120
+ }
121
+ const updateScript = updates.join("\n ");
122
+ const script = `
123
+ set theTag to first flattened tag whose id is "${escapeAppleScript(tagId)}"
124
+
125
+ ${updateScript}
126
+ ${reparentScript}
127
+
128
+ -- Return updated tag info
129
+ set tagId to id of theTag
130
+ set tagName to name of theTag
131
+
132
+ set parentId to ""
133
+ set parentName to ""
134
+ try
135
+ set p to container of theTag
136
+ if class of p is tag then
137
+ set parentId to id of p
138
+ set parentName to name of p
139
+ end if
140
+ end try
141
+
142
+ set availCount to count of (flattened tasks whose primary tag is theTag and completed is false)
143
+
144
+ return "{" & ¬
145
+ "\\"id\\": \\"" & tagId & "\\"," & ¬
146
+ "\\"name\\": \\"" & (my escapeJson(tagName)) & "\\"," & ¬
147
+ "\\"parentId\\": " & (my jsonString(parentId)) & "," & ¬
148
+ "\\"parentName\\": " & (my jsonString(parentName)) & "," & ¬
149
+ "\\"availableTaskCount\\": " & availCount & ¬
150
+ "}"
151
+ `;
152
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
153
+ if (!result.success) {
154
+ return failure(result.error ??
155
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to update tag"));
156
+ }
157
+ if (result.data === undefined) {
158
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No tag data returned"));
159
+ }
160
+ return success(result.data);
161
+ }
162
+ /**
163
+ * Delete a tag from OmniFocus.
164
+ * Note: This cannot be undone.
165
+ */
166
+ export async function deleteTag(tagId) {
167
+ // Validate tag ID
168
+ const idError = validateId(tagId, "tag");
169
+ if (idError)
170
+ return failure(idError);
171
+ const script = `
172
+ set theTag to first flattened tag whose id is "${escapeAppleScript(tagId)}"
173
+ delete theTag
174
+
175
+ return "{\\"tagId\\": \\"${escapeAppleScript(tagId)}\\", \\"deleted\\": true}"
176
+ `;
177
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
178
+ if (!result.success) {
179
+ return failure(result.error ??
180
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to delete tag"));
181
+ }
182
+ if (result.data === undefined) {
183
+ return failure(createError(ErrorCode.UNKNOWN_ERROR, "No result returned"));
184
+ }
185
+ return success(result.data);
186
+ }
187
+ //# sourceMappingURL=tags-crud.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags-crud.js","sourceRoot":"","sources":["../../src/commands/tags-crud.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,cAAc,EACd,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAU3B;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAY,EACZ,UAA4B,EAAE;IAE9B,0CAA0C;IAC1C,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,SAAS;QAAE,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;IAEzC,2BAA2B;IAC3B,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACtC,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QAC7D,IAAI,aAAa;YAAE,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACxC,MAAM,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC/D,IAAI,eAAe;YAAE,OAAO,OAAO,CAAC,eAAe,CAAC,CAAC;IACvD,CAAC;IAED,iEAAiE;IACjE,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,OAAO,GAAG,EAAE,CAAC;IAEjB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,UAAU,GAAG,qDAAqD,i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AAS,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { CliOutput, TagQueryOptions, OFTag } from "../types.js";
2
+ /**
3
+ * Query tags from OmniFocus with optional filters.
4
+ */
5
+ export declare function queryTags(options?: TagQueryOptions): Promise<CliOutput<OFTag[]>>;
6
+ //# sourceMappingURL=tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../src/commands/tags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AASrE;;GAEG;AACH,wBAAsB,SAAS,CAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC,CA2D7B"}
@@ -0,0 +1,61 @@
1
+ import { success, failure } from "../result.js";
2
+ import { ErrorCode, createError } from "../errors.js";
3
+ import { escapeAppleScript } from "../escape.js";
4
+ import { runAppleScript, omniFocusScriptWithHelpers, } from "../applescript.js";
5
+ /**
6
+ * Query tags from OmniFocus with optional filters.
7
+ */
8
+ export async function queryTags(options = {}) {
9
+ const script = `
10
+ set output to "["
11
+ set isFirst to true
12
+
13
+ set allTags to flattened tags
14
+
15
+ repeat with theTag in allTags
16
+ ${options.parent ? `set parentMatch to false` : ""}
17
+ ${options.parent ? `try` : ""}
18
+ ${options.parent ? ` set theContainer to container of theTag` : ""}
19
+ ${options.parent ? ` if name of theContainer is "${escapeAppleScript(options.parent)}" then set parentMatch to true` : ""}
20
+ ${options.parent ? `end try` : ""}
21
+ ${options.parent ? `if parentMatch then` : ""}
22
+
23
+ if not isFirst then set output to output & ","
24
+ set isFirst to false
25
+
26
+ set tagId to id of theTag
27
+ set tagName to name of theTag
28
+
29
+ set parentId to ""
30
+ set parentName to ""
31
+ try
32
+ set theContainer to container of theTag
33
+ set parentId to id of theContainer
34
+ set parentName to name of theContainer
35
+ on error
36
+ -- No parent or container is not a tag
37
+ end try
38
+
39
+ set availCount to count of (available tasks of theTag)
40
+
41
+ set output to output & "{" & ¬
42
+ "\\"id\\": \\"" & tagId & "\\"," & ¬
43
+ "\\"name\\": \\"" & (my escapeJson(tagName)) & "\\"," & ¬
44
+ "\\"parentId\\": " & (my jsonString(parentId)) & "," & ¬
45
+ "\\"parentName\\": " & (my jsonString(parentName)) & "," & ¬
46
+ "\\"availableTaskCount\\": " & availCount & ¬
47
+ "}"
48
+
49
+ ${options.parent ? "end if" : ""}
50
+ end repeat
51
+
52
+ return output & "]"
53
+ `;
54
+ const result = await runAppleScript(omniFocusScriptWithHelpers(script));
55
+ if (!result.success) {
56
+ return failure(result.error ??
57
+ createError(ErrorCode.UNKNOWN_ERROR, "Failed to query tags"));
58
+ }
59
+ return success(result.data ?? []);
60
+ }
61
+ //# sourceMappingURL=tags.js.map