@oneblink/apps-react 10.1.2-beta.3 → 10.1.2-beta.4

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.
@@ -7,6 +7,7 @@ export interface TaskAvailability {
7
7
  export interface TaskResponse extends TaskAvailability {
8
8
  actions: ScheduledTasksTypes.TaskAction[];
9
9
  }
10
+ export type AdhocTaskResponse = Pick<TaskResponse, 'task' | 'actions'>;
10
11
  /**
11
12
  * Obtain all of the related Tasks for a specific Forms App
12
13
  *
@@ -29,6 +30,26 @@ export declare function getTasksForFormsApp({ formsAppId, date, abortSignal, }:
29
30
  }): Promise<{
30
31
  taskResponses: TaskResponse[];
31
32
  }>;
33
+ /**
34
+ * Obtain all of the related adhoc Tasks for a specific Forms App
35
+ *
36
+ * #### Example
37
+ *
38
+ * ```js
39
+ * const formsAppId = 1
40
+ * const tasks = await getAdhocTasksForFormsApp({ formsAppId })
41
+ * ```
42
+ *
43
+ * @param formsAppId
44
+ * @param abortSignal
45
+ * @returns
46
+ */
47
+ export declare function getAdhocTasksForFormsApp({ formsAppId, abortSignal, }: {
48
+ formsAppId: number;
49
+ abortSignal?: AbortSignal;
50
+ }): Promise<{
51
+ taskResponses: AdhocTaskResponse[];
52
+ }>;
32
53
  /**
33
54
  * Obtain all of the tasks related to a Task Group Instances in a specific Forms
34
55
  * App
@@ -61,6 +82,34 @@ export declare function getTaskGroupInstanceTasks({ taskGroupInstanceId, date, f
61
82
  taskGroup: ScheduledTasksTypes.TaskGroup;
62
83
  taskGroupInstance: ScheduledTasksTypes.TaskGroupInstance;
63
84
  }>;
85
+ /**
86
+ * Obtain all of the adhoc tasks related to a Task Group Instances in a specific
87
+ * Forms App
88
+ *
89
+ * #### Example
90
+ *
91
+ * ```js
92
+ * const formsAppId = 1
93
+ * const taskGroupInstanceId = 'abc123'
94
+ * const tasks = await getAdhocTaskGroupInstanceTasks({
95
+ * formsAppId,
96
+ * taskGroupInstanceId,
97
+ * })
98
+ * ```
99
+ *
100
+ * @param formsAppId
101
+ * @param taskGroupInstanceId
102
+ * @param abortSignal
103
+ * @returns
104
+ */
105
+ export declare function getAdhocTaskGroupInstanceTasks({ taskGroupInstanceId, formsAppId, abortSignal, }: {
106
+ taskGroupInstanceId: string;
107
+ date: string;
108
+ formsAppId: number;
109
+ abortSignal?: AbortSignal;
110
+ }): Promise<{
111
+ taskResponses: AdhocTaskResponse[];
112
+ }>;
64
113
  /**
65
114
  * Obtain all of the Task Group instances for a specific Forms App
66
115
  *
@@ -53,6 +53,24 @@ export async function getTasksForFormsApp({ formsAppId, date, abortSignal, }) {
53
53
  const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-tasks?date=${date}`;
54
54
  return await getTasks(url, abortSignal);
55
55
  }
56
+ /**
57
+ * Obtain all of the related adhoc Tasks for a specific Forms App
58
+ *
59
+ * #### Example
60
+ *
61
+ * ```js
62
+ * const formsAppId = 1
63
+ * const tasks = await getAdhocTasksForFormsApp({ formsAppId })
64
+ * ```
65
+ *
66
+ * @param formsAppId
67
+ * @param abortSignal
68
+ * @returns
69
+ */
70
+ export async function getAdhocTasksForFormsApp({ formsAppId, abortSignal, }) {
71
+ const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/adhoc-tasks`;
72
+ return (await getTasks(url, abortSignal));
73
+ }
56
74
  /**
57
75
  * Obtain all of the tasks related to a Task Group Instances in a specific Forms
58
76
  * App
@@ -79,6 +97,30 @@ export async function getTaskGroupInstanceTasks({ taskGroupInstanceId, date, for
79
97
  const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-task-group-instances/${taskGroupInstanceId}?date=${date}`;
80
98
  return await getTasks(url, abortSignal);
81
99
  }
100
+ /**
101
+ * Obtain all of the adhoc tasks related to a Task Group Instances in a specific
102
+ * Forms App
103
+ *
104
+ * #### Example
105
+ *
106
+ * ```js
107
+ * const formsAppId = 1
108
+ * const taskGroupInstanceId = 'abc123'
109
+ * const tasks = await getAdhocTaskGroupInstanceTasks({
110
+ * formsAppId,
111
+ * taskGroupInstanceId,
112
+ * })
113
+ * ```
114
+ *
115
+ * @param formsAppId
116
+ * @param taskGroupInstanceId
117
+ * @param abortSignal
118
+ * @returns
119
+ */
120
+ export async function getAdhocTaskGroupInstanceTasks({ taskGroupInstanceId, formsAppId, abortSignal, }) {
121
+ const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-task-group-instances/${taskGroupInstanceId}/adhoc-tasks`;
122
+ return (await getTasks(url, abortSignal));
123
+ }
82
124
  /**
83
125
  * Obtain all of the Task Group instances for a specific Forms App
84
126
  *
@@ -1 +1 @@
1
- {"version":3,"file":"scheduled-tasks-service.js","sourceRoot":"","sources":["../../src/apps/scheduled-tasks-service.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,EAEL,aAAa,EACb,UAAU,EACV,WAAW,GACZ,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AAYnE,KAAK,UAAU,QAAQ,CAIrB,GAAW,EAAE,WAAyB;IACtC,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAI,GAAG,EAAE,WAAW,CAAC,CAAA;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;QAE5B,MAAM,KAAK,GAAG,GAAgB,CAAA;QAC9B,IAAI,SAAS,EAAE,EAAE,CAAC;YAChB,MAAM,IAAI,iBAAiB,CACzB,kIAAkI,EAClI;gBACE,aAAa,EAAE,KAAK;gBACpB,SAAS,EAAE,IAAI;aAChB,CACF,CAAA;QACH,CAAC;QACD,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;YACrB,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAA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,KAAK,GAAG,GAAgB,CAAA;QAC9B,IAAI,SAAS,EAAE,EAAE,CAAC;YAChB,MAAM,IAAI,iBAAiB,CACzB,yEAAyE,EACzE;gBACE,aAAa,EAAE,KAAK;gBACpB,SAAS,EAAE,IAAI;aAChB,CACF,CAAA;QACH,CAAC;QACD,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;YACrB,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CACzB,0HAA0H,EAC1H;oBACE,aAAa,EAAE,KAAK;oBACpB,qBAAqB,EAAE,IAAI;oBAC3B,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;YACD,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE;oBACzC,KAAK,EAAE,iBAAiB;oBACxB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CAAC,CAAA;YACJ,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,IAAI,iBAAiB,CACzB,gFAAgF,EAChF;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { ScheduledTasksTypes } from '@oneblink/types'\nimport tenants from './tenants'\nimport Sentry from './Sentry'\nimport {\n HTTPError,\n deleteRequest,\n getRequest,\n postRequest,\n} from './services/fetch'\nimport { isOffline } from './offline-service'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\n\nexport interface TaskAvailability {\n task: ScheduledTasksTypes.Task\n completedTask?: ScheduledTasksTypes.CompletedTask\n daysAvailable: number\n}\n\nexport interface TaskResponse extends TaskAvailability {\n actions: ScheduledTasksTypes.TaskAction[]\n}\n\nasync function getTasks<\n T extends {\n taskResponses: TaskResponse[]\n },\n>(url: string, abortSignal?: AbortSignal) {\n try {\n return await getRequest<T>(url, abortSignal)\n } catch (err) {\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local version of these scheduled tasks, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the forms app you are looking for. Please contact support if the problem persists.',\n {\n originalError: error,\n title: 'Unknown Forms App',\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Obtain all of the related Tasks for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const date = '2023-12-01'\n * const tasks = await getTasksForFormsApp({ formsAppId, date })\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getTasksForFormsApp({\n formsAppId,\n date,\n abortSignal,\n}: {\n formsAppId: number\n date: string\n abortSignal?: AbortSignal\n}): Promise<{\n taskResponses: TaskResponse[]\n}> {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-tasks?date=${date}`\n return await getTasks(url, abortSignal)\n}\n\n/**\n * Obtain all of the tasks related to a Task Group Instances in a specific Forms\n * App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskGroupInstanceId = 'abc123'\n * const date = '2023-12-01'\n * const tasks = await getTaskGroupInstanceTasks({\n * formsAppId,\n * taskGroupInstanceId,\n * date,\n * })\n * ```\n *\n * @param formsAppId\n * @param taskGroupInstanceId\n * @param abortSignal\n * @returns\n */\nexport async function getTaskGroupInstanceTasks({\n taskGroupInstanceId,\n date,\n formsAppId,\n abortSignal,\n}: {\n taskGroupInstanceId: string\n date: string\n formsAppId: number\n abortSignal?: AbortSignal\n}) {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-task-group-instances/${taskGroupInstanceId}?date=${date}`\n return await getTasks<{\n taskResponses: TaskResponse[]\n taskGroup: ScheduledTasksTypes.TaskGroup\n taskGroupInstance: ScheduledTasksTypes.TaskGroupInstance\n }>(url, abortSignal)\n}\n\n/**\n * Obtain all of the Task Group instances for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskGroupInstances = await getTaskGroupInstances(formsAppId)\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getTaskGroupInstances(\n formsAppId: number,\n abortSignal?: AbortSignal,\n) {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-task-group-instances`\n try {\n return await getRequest<{\n taskGroupInstances: Array<\n ScheduledTasksTypes.TaskGroupInstance & {\n taskAvailabilities: TaskAvailability[]\n taskGroup: ScheduledTasksTypes.TaskGroup\n }\n >\n }>(url, abortSignal)\n } catch (err) {\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local version of these scheduled task groups, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the forms app you are looking for. Please contact support if the problem persists.',\n {\n originalError: error,\n title: 'Unknown Forms App',\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Complete the related Task for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskId = 2\n * const completedTask = await scheduledTasksService.completeTask({\n * formsAppId,\n * taskId,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport async function completeTask({\n formsAppId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n completedAt,\n isAdhoc,\n abortSignal,\n}: {\n formsAppId: number\n taskId: string\n taskActionId: string\n taskGroupInstanceId: string | undefined\n completedAt: string | undefined\n isAdhoc?: boolean\n abortSignal?: AbortSignal\n}): Promise<ScheduledTasksTypes.CompletedTask> {\n const url = `${tenants.current.apiOrigin}/completed-tasks`\n try {\n return await postRequest<ScheduledTasksTypes.CompletedTask>(\n url,\n {\n formsAppId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n completedAt,\n isAdhoc,\n },\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to complete this task. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Delete the completed task record related to a Task for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskId = 2\n * const completedTask = await scheduledTasksService.completeTask({\n * formsAppId,\n * taskId,\n * })\n * await deleteCompletedTask(completedTask.id)\n * ```\n *\n * @param id\n * @param abortSignal\n * @returns\n */\n\nexport async function deleteCompletedTask(\n id: string,\n abortSignal?: AbortSignal,\n): Promise<void> {\n const url = `${tenants.current.apiOrigin}/completed-tasks/${id}`\n try {\n await deleteRequest(url, abortSignal)\n } catch (err) {\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to delete completed tasks. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"scheduled-tasks-service.js","sourceRoot":"","sources":["../../src/apps/scheduled-tasks-service.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,OAAO,EAEL,aAAa,EACb,UAAU,EACV,WAAW,GACZ,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AAcnE,KAAK,UAAU,QAAQ,CAIrB,GAAW,EAAE,WAAyB;IACtC,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAI,GAAG,EAAE,WAAW,CAAC,CAAA;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;QAE5B,MAAM,KAAK,GAAG,GAAgB,CAAA;QAC9B,IAAI,SAAS,EAAE,EAAE,CAAC;YAChB,MAAM,IAAI,iBAAiB,CACzB,kIAAkI,EAClI;gBACE,aAAa,EAAE,KAAK;gBACpB,SAAS,EAAE,IAAI;aAChB,CACF,CAAA;QACH,CAAC;QACD,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;YACrB,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB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AAiB,CACzB,gFAAgF,EAChF;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { ScheduledTasksTypes } from '@oneblink/types'\nimport tenants from './tenants'\nimport Sentry from './Sentry'\nimport {\n HTTPError,\n deleteRequest,\n getRequest,\n postRequest,\n} from './services/fetch'\nimport { isOffline } from './offline-service'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\n\nexport interface TaskAvailability {\n task: ScheduledTasksTypes.Task\n completedTask?: ScheduledTasksTypes.CompletedTask\n daysAvailable: number\n}\n\nexport interface TaskResponse extends TaskAvailability {\n actions: ScheduledTasksTypes.TaskAction[]\n}\n\nexport type AdhocTaskResponse = Pick<TaskResponse, 'task' | 'actions'>\n\nasync function getTasks<\n T extends {\n taskResponses: TaskResponse[]\n },\n>(url: string, abortSignal?: AbortSignal) {\n try {\n return await getRequest<T>(url, abortSignal)\n } catch (err) {\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local version of these scheduled tasks, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the forms app you are looking for. Please contact support if the problem persists.',\n {\n originalError: error,\n title: 'Unknown Forms App',\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Obtain all of the related Tasks for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const date = '2023-12-01'\n * const tasks = await getTasksForFormsApp({ formsAppId, date })\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getTasksForFormsApp({\n formsAppId,\n date,\n abortSignal,\n}: {\n formsAppId: number\n date: string\n abortSignal?: AbortSignal\n}): Promise<{\n taskResponses: TaskResponse[]\n}> {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-tasks?date=${date}`\n return await getTasks(url, abortSignal)\n}\n\n/**\n * Obtain all of the related adhoc Tasks for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const tasks = await getAdhocTasksForFormsApp({ formsAppId })\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getAdhocTasksForFormsApp({\n formsAppId,\n abortSignal,\n}: {\n formsAppId: number\n abortSignal?: AbortSignal\n}) {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/adhoc-tasks`\n return (await getTasks(url, abortSignal)) as {\n taskResponses: AdhocTaskResponse[]\n }\n}\n\n/**\n * Obtain all of the tasks related to a Task Group Instances in a specific Forms\n * App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskGroupInstanceId = 'abc123'\n * const date = '2023-12-01'\n * const tasks = await getTaskGroupInstanceTasks({\n * formsAppId,\n * taskGroupInstanceId,\n * date,\n * })\n * ```\n *\n * @param formsAppId\n * @param taskGroupInstanceId\n * @param abortSignal\n * @returns\n */\nexport async function getTaskGroupInstanceTasks({\n taskGroupInstanceId,\n date,\n formsAppId,\n abortSignal,\n}: {\n taskGroupInstanceId: string\n date: string\n formsAppId: number\n abortSignal?: AbortSignal\n}) {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-task-group-instances/${taskGroupInstanceId}?date=${date}`\n return await getTasks<{\n taskResponses: TaskResponse[]\n taskGroup: ScheduledTasksTypes.TaskGroup\n taskGroupInstance: ScheduledTasksTypes.TaskGroupInstance\n }>(url, abortSignal)\n}\n\n/**\n * Obtain all of the adhoc tasks related to a Task Group Instances in a specific\n * Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskGroupInstanceId = 'abc123'\n * const tasks = await getAdhocTaskGroupInstanceTasks({\n * formsAppId,\n * taskGroupInstanceId,\n * })\n * ```\n *\n * @param formsAppId\n * @param taskGroupInstanceId\n * @param abortSignal\n * @returns\n */\nexport async function getAdhocTaskGroupInstanceTasks({\n taskGroupInstanceId,\n formsAppId,\n abortSignal,\n}: {\n taskGroupInstanceId: string\n date: string\n formsAppId: number\n abortSignal?: AbortSignal\n}) {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-task-group-instances/${taskGroupInstanceId}/adhoc-tasks`\n return (await getTasks(url, abortSignal)) as {\n taskResponses: AdhocTaskResponse[]\n }\n}\n\n/**\n * Obtain all of the Task Group instances for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskGroupInstances = await getTaskGroupInstances(formsAppId)\n * ```\n *\n * @param formsAppId\n * @param abortSignal\n * @returns\n */\nexport async function getTaskGroupInstances(\n formsAppId: number,\n abortSignal?: AbortSignal,\n) {\n const url = `${tenants.current.apiOrigin}/forms-apps/${formsAppId}/scheduled-task-group-instances`\n try {\n return await getRequest<{\n taskGroupInstances: Array<\n ScheduledTasksTypes.TaskGroupInstance & {\n taskAvailabilities: TaskAvailability[]\n taskGroup: ScheduledTasksTypes.TaskGroup\n }\n >\n }>(url, abortSignal)\n } catch (err) {\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline and do not have a local version of these scheduled task groups, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the forms app you are looking for. Please contact support if the problem persists.',\n {\n originalError: error,\n title: 'Unknown Forms App',\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Complete the related Task for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskId = 2\n * const completedTask = await scheduledTasksService.completeTask({\n * formsAppId,\n * taskId,\n * })\n * ```\n *\n * @param options\n * @returns\n */\nexport async function completeTask({\n formsAppId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n completedAt,\n isAdhoc,\n abortSignal,\n}: {\n formsAppId: number\n taskId: string\n taskActionId: string\n taskGroupInstanceId: string | undefined\n completedAt: string | undefined\n isAdhoc?: boolean\n abortSignal?: AbortSignal\n}): Promise<ScheduledTasksTypes.CompletedTask> {\n const url = `${tenants.current.apiOrigin}/completed-tasks`\n try {\n return await postRequest<ScheduledTasksTypes.CompletedTask>(\n url,\n {\n formsAppId,\n taskId,\n taskActionId,\n taskGroupInstanceId,\n completedAt,\n isAdhoc,\n },\n abortSignal,\n )\n } catch (err) {\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to complete this task. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\n/**\n * Delete the completed task record related to a Task for a specific Forms App\n *\n * #### Example\n *\n * ```js\n * const formsAppId = 1\n * const taskId = 2\n * const completedTask = await scheduledTasksService.completeTask({\n * formsAppId,\n * taskId,\n * })\n * await deleteCompletedTask(completedTask.id)\n * ```\n *\n * @param id\n * @param abortSignal\n * @returns\n */\n\nexport async function deleteCompletedTask(\n id: string,\n abortSignal?: AbortSignal,\n): Promise<void> {\n const url = `${tenants.current.apiOrigin}/completed-tasks/${id}`\n try {\n await deleteRequest(url, abortSignal)\n } catch (err) {\n Sentry.captureException(err)\n\n const error = err as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet and try again',\n {\n originalError: error,\n isOffline: true,\n },\n )\n }\n switch (error.status) {\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to delete completed tasks. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n requiresAccessRequest: true,\n httpStatusCode: error.status,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/apps-react",
3
3
  "description": "Helper functions for OneBlink apps in ReactJS.",
4
- "version": "10.1.2-beta.3",
4
+ "version": "10.1.2-beta.4",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/apps-react/issues"