@simpleplatform/sdk 2.4.2 → 3.0.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.
package/dist/tasks.js ADDED
@@ -0,0 +1,34 @@
1
+ import { execute as hostExecute } from './host';
2
+ /**
3
+ * Creates a task through the platform task service.
4
+ *
5
+ * The task is assigned to the user the action is running as. The platform
6
+ * creates both the task and its first message ids.
7
+ */
8
+ export async function create(options, context) {
9
+ if (typeof options.taskTypeId !== 'string' || options.taskTypeId.trim() === '') {
10
+ throw new Error('taskTypeId is required for task creation');
11
+ }
12
+ if (typeof options.title !== 'string' || options.title.trim() === '') {
13
+ throw new Error('title is required for task creation');
14
+ }
15
+ if (options.input === null || typeof options.input !== 'object' || Array.isArray(options.input)) {
16
+ throw new Error('input must be an object for task creation');
17
+ }
18
+ const response = await hostExecute('action:tasks/create', {
19
+ input: options.input,
20
+ task_type_id: options.taskTypeId,
21
+ title: options.title,
22
+ }, context);
23
+ if (!response.ok) {
24
+ throw new Error(response.error?.message ?? 'Task creation failed');
25
+ }
26
+ const data = response.data;
27
+ if (data === null || typeof data !== 'object' || Array.isArray(data)
28
+ || data.task === null || typeof data.task !== 'object' || Array.isArray(data.task)
29
+ || typeof data.task.id !== 'string' || typeof data.task.revision !== 'number'
30
+ || typeof data.task.status !== 'string') {
31
+ throw new Error('Task creation response was not understood');
32
+ }
33
+ return { task: { id: data.task.id, revision: data.task.revision, status: data.task.status } };
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleplatform/sdk",
3
- "version": "2.4.2",
3
+ "version": "3.0.0",
4
4
  "description": "Simple Platform Typescript SDK",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://docs.simple.dev",
@@ -41,6 +41,10 @@
41
41
  "types": "./dist/settings.d.ts",
42
42
  "default": "./dist/settings.js"
43
43
  },
44
+ "./tasks": {
45
+ "types": "./dist/tasks.d.ts",
46
+ "default": "./dist/tasks.js"
47
+ },
44
48
  "./security": {
45
49
  "types": "./dist/security.d.ts",
46
50
  "default": "./dist/security.js"