@rytass/bpm-core-client 0.1.1 → 0.1.3

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 (62) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +113 -3
  3. package/eslint.config.mjs +19 -0
  4. package/jest.config.cts +10 -0
  5. package/package.json +4 -5
  6. package/project.json +66 -0
  7. package/src/lib/api-auth-client.ts +169 -0
  8. package/src/lib/form/form-api.spec.ts +81 -0
  9. package/src/lib/form/form-api.ts +388 -0
  10. package/src/lib/form/form-rendering.ts +580 -0
  11. package/src/lib/graphql-client.spec.ts +65 -0
  12. package/src/lib/graphql-client.ts +114 -0
  13. package/src/lib/member-api.ts +129 -0
  14. package/src/lib/organization/organization-api.spec.ts +90 -0
  15. package/src/lib/organization/organization-api.ts +710 -0
  16. package/src/lib/template/template-api.spec.ts +88 -0
  17. package/src/lib/template/template-api.ts +772 -0
  18. package/src/lib/workflow/workflow-api.spec.ts +132 -0
  19. package/src/lib/workflow/workflow-api.ts +1749 -0
  20. package/tsconfig.json +27 -0
  21. package/tsconfig.lib.json +16 -0
  22. package/tsconfig.spec.json +16 -0
  23. package/LICENSE +0 -21
  24. package/src/index.js +0 -7
  25. package/src/index.js.map +0 -1
  26. package/src/lib/api-auth-client.d.ts +0 -73
  27. package/src/lib/api-auth-client.js +0 -121
  28. package/src/lib/api-auth-client.js.map +0 -1
  29. package/src/lib/form/form-api.d.ts +0 -48
  30. package/src/lib/form/form-api.js +0 -228
  31. package/src/lib/form/form-api.js.map +0 -1
  32. package/src/lib/form/form-rendering.d.ts +0 -52
  33. package/src/lib/form/form-rendering.js +0 -341
  34. package/src/lib/form/form-rendering.js.map +0 -1
  35. package/src/lib/form/index.js +0 -6
  36. package/src/lib/form/index.js.map +0 -1
  37. package/src/lib/graphql-client.d.ts +0 -45
  38. package/src/lib/graphql-client.js +0 -92
  39. package/src/lib/graphql-client.js.map +0 -1
  40. package/src/lib/member-api.d.ts +0 -49
  41. package/src/lib/member-api.js +0 -72
  42. package/src/lib/member-api.js.map +0 -1
  43. package/src/lib/organization/index.js +0 -5
  44. package/src/lib/organization/index.js.map +0 -1
  45. package/src/lib/organization/organization-api.d.ts +0 -168
  46. package/src/lib/organization/organization-api.js +0 -394
  47. package/src/lib/organization/organization-api.js.map +0 -1
  48. package/src/lib/template/index.js +0 -5
  49. package/src/lib/template/index.js.map +0 -1
  50. package/src/lib/template/template-api.d.ts +0 -150
  51. package/src/lib/template/template-api.js +0 -407
  52. package/src/lib/template/template-api.js.map +0 -1
  53. package/src/lib/workflow/index.js +0 -5
  54. package/src/lib/workflow/index.js.map +0 -1
  55. package/src/lib/workflow/workflow-api.d.ts +0 -376
  56. package/src/lib/workflow/workflow-api.js +0 -867
  57. package/src/lib/workflow/workflow-api.js.map +0 -1
  58. /package/src/{index.d.ts → index.ts} +0 -0
  59. /package/src/lib/form/{index.d.ts → index.ts} +0 -0
  60. /package/src/lib/organization/{index.d.ts → index.ts} +0 -0
  61. /package/src/lib/template/{index.d.ts → index.ts} +0 -0
  62. /package/src/lib/workflow/{index.d.ts → index.ts} +0 -0
@@ -1,867 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listApprovalInstances = listApprovalInstances;
4
- exports.listApprovalInstancesPage = listApprovalInstancesPage;
5
- exports.readLaunchContext = readLaunchContext;
6
- exports.listLaunchableTemplates = listLaunchableTemplates;
7
- exports.readApprovalInstance = readApprovalInstance;
8
- exports.listInboxTasks = listInboxTasks;
9
- exports.listApprovalHistoryTasks = listApprovalHistoryTasks;
10
- exports.readWorkflowDashboardSummary = readWorkflowDashboardSummary;
11
- exports.listTaskDecisions = listTaskDecisions;
12
- exports.listAttachments = listAttachments;
13
- exports.uploadAttachment = uploadAttachment;
14
- exports.readAttachmentDownloadUrl = readAttachmentDownloadUrl;
15
- exports.readAttachmentPreviewUrl = readAttachmentPreviewUrl;
16
- exports.readInstanceSignatures = readInstanceSignatures;
17
- exports.resolveMemberProfiles = resolveMemberProfiles;
18
- exports.searchMembers = searchMembers;
19
- exports.listMemberDirectoryPage = listMemberDirectoryPage;
20
- exports.listDelegationRules = listDelegationRules;
21
- exports.listDelegationRulesPage = listDelegationRulesPage;
22
- exports.createDelegationRule = createDelegationRule;
23
- exports.revokeDelegationRule = revokeDelegationRule;
24
- exports.listNotifications = listNotifications;
25
- exports.readUnreadNotificationCount = readUnreadNotificationCount;
26
- exports.markNotificationRead = markNotificationRead;
27
- exports.markAllNotificationsRead = markAllNotificationsRead;
28
- exports.readNotificationPreference = readNotificationPreference;
29
- exports.updateNotificationPreference = updateNotificationPreference;
30
- exports.submitApprovalInstance = submitApprovalInstance;
31
- exports.decideTask = decideTask;
32
- exports.cancelApprovalInstance = cancelApprovalInstance;
33
- exports.resubmitApprovalInstance = resubmitApprovalInstance;
34
- exports.readApprovalInstanceCaseTitle = readApprovalInstanceCaseTitle;
35
- exports.readFormDataCaseTitle = readFormDataCaseTitle;
36
- const graphql_client_1 = require("../graphql-client");
37
- async function listApprovalInstances() {
38
- const data = await (0, graphql_client_1.requestGraphQl)(`query ApprovalInstances {
39
- approvalInstances {
40
- completedAt
41
- formDataJson
42
- formDefinitionSnapshotJson
43
- id
44
- initiatorMemberId
45
- startedAt
46
- state
47
- templateId
48
- templateVersionId
49
- title
50
- workflowSnapshotJson
51
- }
52
- }`);
53
- return data.approvalInstances.map(parseInstanceJson);
54
- }
55
- async function listApprovalInstancesPage({ page, pageSize, searchText, state, templateId, view, }) {
56
- const variables = {
57
- page,
58
- pageSize,
59
- searchText: searchText?.trim() || null,
60
- state: state ? [state] : null,
61
- templateId: templateId?.trim() || null,
62
- view,
63
- };
64
- const [pageData, pageInfoData] = await Promise.all([
65
- (0, graphql_client_1.requestGraphQl)(`query ApprovalInstancesPage(
66
- $view: ApprovalInstanceListView
67
- $searchText: String
68
- $state: [ApprovalInstanceState!]
69
- $templateId: String
70
- $page: Int
71
- $pageSize: Int
72
- ) {
73
- approvalInstances(
74
- view: $view
75
- searchText: $searchText
76
- state: $state
77
- templateId: $templateId
78
- page: $page
79
- pageSize: $pageSize
80
- ) {
81
- completedAt
82
- formDataJson
83
- formDefinitionSnapshotJson
84
- id
85
- initiatorMemberId
86
- startedAt
87
- state
88
- templateId
89
- templateVersionId
90
- title
91
- workflowSnapshotJson
92
- }
93
- }`, variables),
94
- (0, graphql_client_1.requestGraphQl)(`query ApprovalInstancePageInfo(
95
- $view: ApprovalInstanceListView
96
- $searchText: String
97
- $state: [ApprovalInstanceState!]
98
- $templateId: String
99
- $page: Int
100
- $pageSize: Int
101
- ) {
102
- approvalInstancePageInfo(
103
- view: $view
104
- searchText: $searchText
105
- state: $state
106
- templateId: $templateId
107
- page: $page
108
- pageSize: $pageSize
109
- ) {
110
- hasNextPage
111
- hasPreviousPage
112
- page
113
- pageSize
114
- totalCount
115
- totalPages
116
- }
117
- }`, variables),
118
- ]);
119
- const pageInfo = pageInfoData.approvalInstancePageInfo;
120
- return {
121
- instances: pageData.approvalInstances.map(parseInstanceJson),
122
- pageInfo,
123
- totalCount: pageInfo.totalCount,
124
- };
125
- }
126
- async function readLaunchContext(templateId) {
127
- const templateData = await (0, graphql_client_1.requestGraphQl)(`query LaunchTemplate($id: String!) {
128
- approvalTemplate(id: $id) {
129
- currentVersionId
130
- id
131
- name
132
- }
133
- approvalTemplateVersions(templateId: $id) {
134
- formDefinitionVersionId
135
- id
136
- status
137
- version
138
- }
139
- launchableApprovalTemplates {
140
- currentVersionId
141
- id
142
- name
143
- updatedAt
144
- }
145
- }`, { id: templateId });
146
- const templateVersion = templateData.approvalTemplateVersions.find((version) => version.id === templateData.approvalTemplate.currentVersionId);
147
- if (!templateVersion || templateVersion.status !== 'PUBLISHED') {
148
- throw new Error('模板尚未發布,無法發起簽核。');
149
- }
150
- if (!templateVersion.formDefinitionVersionId) {
151
- throw new Error('模板尚未綁定表單版本,無法發起簽核。');
152
- }
153
- const launchableApprovalTemplates = templateData.launchableApprovalTemplates ?? [templateData.approvalTemplate];
154
- if (!launchableApprovalTemplates.some((template) => template.id === templateId)) {
155
- throw new Error('目前登入者沒有此模板的發起權限。');
156
- }
157
- const formData = await (0, graphql_client_1.requestGraphQl)(`query LaunchFormVersion($id: String!) {
158
- formDefinitionVersion(id: $id) {
159
- id
160
- schemaJson
161
- uiSchemaJson
162
- version
163
- }
164
- }`, { id: templateVersion.formDefinitionVersionId });
165
- return {
166
- formVersion: {
167
- id: formData.formDefinitionVersion.id,
168
- schema: JSON.parse(formData.formDefinitionVersion.schemaJson),
169
- uiSchema: JSON.parse(formData.formDefinitionVersion.uiSchemaJson),
170
- version: formData.formDefinitionVersion.version,
171
- },
172
- template: templateData.approvalTemplate,
173
- templateVersion,
174
- };
175
- }
176
- async function listLaunchableTemplates() {
177
- const templateData = await (0, graphql_client_1.requestGraphQl)(`query ApprovalTemplates {
178
- launchableApprovalTemplates {
179
- currentVersionId
180
- id
181
- name
182
- updatedAt
183
- }
184
- }`);
185
- const launchableApprovalTemplates = templateData.launchableApprovalTemplates ??
186
- templateData.approvalTemplates ??
187
- [];
188
- const versionLists = await Promise.all(launchableApprovalTemplates.map((template) => (0, graphql_client_1.requestGraphQl)(`query LaunchTemplateVersions($templateId: String!) {
189
- approvalTemplateVersions(templateId: $templateId) {
190
- formDefinitionVersionId
191
- id
192
- status
193
- version
194
- }
195
- }`, { templateId: template.id })));
196
- return launchableApprovalTemplates.flatMap((template, index) => {
197
- const currentVersion = versionLists[index]?.approvalTemplateVersions.find((version) => version.id === template.currentVersionId);
198
- return currentVersion?.status === 'PUBLISHED' &&
199
- currentVersion.formDefinitionVersionId
200
- ? [
201
- {
202
- currentVersionId: currentVersion.id,
203
- formDefinitionVersionId: currentVersion.formDefinitionVersionId,
204
- id: template.id,
205
- name: template.name,
206
- updatedAt: template.updatedAt,
207
- version: currentVersion.version,
208
- },
209
- ]
210
- : [];
211
- });
212
- }
213
- async function readApprovalInstance(instanceId) {
214
- const data = await (0, graphql_client_1.requestGraphQl)(`query ApprovalInstance($id: String!) {
215
- approvalInstance(id: $id) {
216
- completedAt
217
- formDataJson
218
- formDefinitionSnapshotJson
219
- id
220
- initiatorMemberId
221
- startedAt
222
- state
223
- templateId
224
- templateVersionId
225
- title
226
- workflowSnapshotJson
227
- }
228
- tasks(instanceId: $id) {
229
- assigneeMemberId
230
- assignmentType
231
- candidateMemberIds
232
- completedAt
233
- createdAt
234
- decisionPolicySnapshotJson
235
- delegationChainJson
236
- id
237
- instanceId
238
- nodeId
239
- openedAt
240
- originalAssigneeMemberId
241
- slaDueAt
242
- status
243
- tokenId
244
- }
245
- workflowTokens(instanceId: $id) {
246
- consumedAt
247
- createdAt
248
- currentNodeId
249
- id
250
- instanceId
251
- parentTokenId
252
- status
253
- }
254
- activityLogs(instanceId: $id) {
255
- actorMemberId
256
- createdAt
257
- eventType
258
- id
259
- nodeId
260
- payloadJson
261
- taskId
262
- }
263
- }`, { id: instanceId });
264
- return {
265
- activityLogs: data.activityLogs,
266
- instance: parseInstanceJson(data.approvalInstance),
267
- tasks: normalizeTaskRecords(data.tasks),
268
- workflowTokens: data.workflowTokens,
269
- };
270
- }
271
- async function listInboxTasks(assigneeMemberId) {
272
- const data = await (0, graphql_client_1.requestGraphQl)(`query InboxTasks($assigneeMemberId: String!) {
273
- inboxTasks(assigneeMemberId: $assigneeMemberId) {
274
- assigneeMemberId
275
- assignmentType
276
- candidateMemberIds
277
- completedAt
278
- createdAt
279
- decisionPolicySnapshotJson
280
- delegationChainJson
281
- id
282
- instanceId
283
- nodeId
284
- openedAt
285
- originalAssigneeMemberId
286
- slaDueAt
287
- status
288
- tokenId
289
- }
290
- }`, { assigneeMemberId });
291
- return normalizeTaskRecords(data.inboxTasks);
292
- }
293
- async function listApprovalHistoryTasks(assigneeMemberId) {
294
- const data = await (0, graphql_client_1.requestGraphQl)(`query ApprovalHistoryTasks($assigneeMemberId: String!) {
295
- approvalHistoryTasks(assigneeMemberId: $assigneeMemberId) {
296
- assigneeMemberId
297
- assignmentType
298
- candidateMemberIds
299
- completedAt
300
- createdAt
301
- decisionPolicySnapshotJson
302
- delegationChainJson
303
- id
304
- instanceId
305
- nodeId
306
- openedAt
307
- originalAssigneeMemberId
308
- slaDueAt
309
- status
310
- tokenId
311
- }
312
- }`, { assigneeMemberId });
313
- return normalizeTaskRecords(data.approvalHistoryTasks);
314
- }
315
- async function readWorkflowDashboardSummary({ currentMemberId, from, to, }) {
316
- const [summaryData, notificationResult] = await Promise.all([
317
- (0, graphql_client_1.requestGraphQl)(`query WorkflowDashboardSummary($from: DateTime, $to: DateTime) {
318
- workflowDashboardSummary(from: $from, to: $to) {
319
- activeInstanceCount
320
- completedInstanceCount
321
- overdueTaskCount
322
- pendingTaskCount
323
- rejectedInstanceCount
324
- totalInstanceCount
325
- }
326
- }`, { from, to }),
327
- listNotifications({
328
- includeRead: true,
329
- page: 1,
330
- pageSize: 1,
331
- recipientMemberId: currentMemberId,
332
- }),
333
- ]);
334
- return {
335
- ...summaryData.workflowDashboardSummary,
336
- unreadNotificationCount: notificationResult.unreadCount,
337
- };
338
- }
339
- function normalizeTaskRecords(tasks) {
340
- return tasks.map((task) => ({
341
- ...task,
342
- assignmentType: task.assignmentType ?? 'DIRECT_MEMBER',
343
- candidateMemberIds: task.candidateMemberIds ?? [],
344
- decisionPolicySnapshotJson: task.decisionPolicySnapshotJson ?? JSON.stringify({ type: 'SINGLE' }),
345
- }));
346
- }
347
- async function listTaskDecisions(taskId) {
348
- const data = await (0, graphql_client_1.requestGraphQl)(`query TaskDecisions($taskId: String!) {
349
- taskDecisions(taskId: $taskId) {
350
- action
351
- comment
352
- decidedAt
353
- decidedByMemberId
354
- id
355
- returnToNodeId
356
- signatureId
357
- taskId
358
- transferToMemberId
359
- }
360
- }`, { taskId });
361
- return data.taskDecisions;
362
- }
363
- async function listAttachments(instanceId) {
364
- const data = await (0, graphql_client_1.requestGraphQl)(`query InstanceAttachments($instanceId: String!) {
365
- attachments(instanceId: $instanceId) {
366
- checksumSha256
367
- createdAt
368
- filename
369
- formFieldPath
370
- id
371
- instanceId
372
- mimeType
373
- sizeBytes
374
- storageKey
375
- storageProvider
376
- taskId
377
- uploaderMemberId
378
- }
379
- }`, { instanceId });
380
- return data.attachments ?? [];
381
- }
382
- async function uploadAttachment({ file, formFieldPath, }) {
383
- const contentBase64 = await readFileBase64(file);
384
- const checksumSha256 = await hashFileSha256(file);
385
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation UploadAttachment($input: UploadAttachmentInput!) {
386
- uploadAttachment(input: $input) {
387
- checksumSha256
388
- createdAt
389
- filename
390
- formFieldPath
391
- id
392
- instanceId
393
- mimeType
394
- sizeBytes
395
- storageKey
396
- storageProvider
397
- taskId
398
- uploaderMemberId
399
- }
400
- }`, {
401
- input: {
402
- checksumSha256,
403
- contentBase64,
404
- filename: file.name,
405
- formFieldPath,
406
- instanceId: null,
407
- mimeType: file.type || 'application/octet-stream',
408
- sizeBytes: file.size,
409
- taskId: null,
410
- },
411
- });
412
- return data.uploadAttachment;
413
- }
414
- async function readAttachmentDownloadUrl({ id, }) {
415
- const data = await (0, graphql_client_1.requestGraphQl)(`query AttachmentDownloadUrl($id: String!) {
416
- attachmentDownloadUrl(id: $id)
417
- }`, { id });
418
- return data.attachmentDownloadUrl;
419
- }
420
- async function readAttachmentPreviewUrl({ id, }) {
421
- const data = await (0, graphql_client_1.requestGraphQl)(`query AttachmentPreviewUrl($id: String!) {
422
- attachmentPreviewUrl(id: $id)
423
- }`, { id });
424
- return data.attachmentPreviewUrl;
425
- }
426
- async function readInstanceSignatures(instanceId) {
427
- const data = await (0, graphql_client_1.requestGraphQl)(`query InstanceSignatures($instanceId: String!) {
428
- signatures(instanceId: $instanceId) {
429
- algorithm
430
- id
431
- instanceId
432
- keyVersion
433
- previousSignatureHash
434
- signature
435
- signedAt
436
- signedPayloadHash
437
- signedPayloadJson
438
- signerMemberId
439
- taskId
440
- timestampTokenBase64
441
- }
442
- verifySignatureChain(instanceId: $instanceId) {
443
- checkedCount
444
- errors
445
- instanceId
446
- valid
447
- }
448
- }`, { instanceId });
449
- return {
450
- signatures: data.signatures ?? [],
451
- verification: data.verifySignatureChain ?? {
452
- checkedCount: 0,
453
- errors: [],
454
- instanceId,
455
- valid: true,
456
- },
457
- };
458
- }
459
- async function resolveMemberProfiles(memberIds) {
460
- if (memberIds.length === 0) {
461
- return [];
462
- }
463
- const data = await (0, graphql_client_1.requestGraphQl)(`query InstanceMembers($memberIds: [String!]!) {
464
- members(memberIds: $memberIds) {
465
- email
466
- memberId
467
- name
468
- }
469
- }`, { memberIds });
470
- return data.members;
471
- }
472
- async function searchMembers(searchText) {
473
- const data = await (0, graphql_client_1.requestGraphQl)(`query SearchMembers($searchText: String!) {
474
- searchMembers(searchText: $searchText) {
475
- email
476
- memberId
477
- name
478
- }
479
- }`, { searchText });
480
- return data.searchMembers;
481
- }
482
- async function listMemberDirectoryPage({ page, pageSize, searchText = '', }) {
483
- const data = await (0, graphql_client_1.requestGraphQl)(`query MemberDirectoryPage($page: Int, $pageSize: Int, $searchText: String!) {
484
- searchMembers(page: $page, pageSize: $pageSize, searchText: $searchText) {
485
- email
486
- memberId
487
- name
488
- }
489
- memberCount(searchText: $searchText)
490
- }`, { page, pageSize, searchText });
491
- return {
492
- members: data.searchMembers,
493
- totalCount: data.memberCount,
494
- };
495
- }
496
- async function listDelegationRules({ includeInactive = true, principalMemberId = null, } = {}) {
497
- const data = await (0, graphql_client_1.requestGraphQl)(`query DelegationRules($includeInactive: Boolean, $principalMemberId: String) {
498
- delegationRules(
499
- includeInactive: $includeInactive
500
- principalMemberId: $principalMemberId
501
- ) {
502
- agentMemberId
503
- createdAt
504
- createdByMemberId
505
- endAt
506
- id
507
- principalMemberId
508
- priority
509
- requiresConfirmation
510
- revokedAt
511
- revokedByMemberId
512
- scopeConditionCel
513
- scopeTemplateIds
514
- scopeType
515
- startAt
516
- status
517
- updatedAt
518
- }
519
- }`, { includeInactive, principalMemberId });
520
- return data.delegationRules;
521
- }
522
- async function listDelegationRulesPage({ agentMemberId = null, includeInactive = true, page = 1, pageSize = 10, principalMemberId = null, scopeType = null, status = null, } = {}) {
523
- const data = await (0, graphql_client_1.requestGraphQl)(`query DelegationRulesPage(
524
- $includeInactive: Boolean
525
- $page: Int
526
- $pageSize: Int
527
- $principalMemberId: String
528
- $agentMemberId: String
529
- $scopeType: DelegationScopeType
530
- $status: DelegationRuleStatus
531
- ) {
532
- delegationRules(
533
- agentMemberId: $agentMemberId
534
- includeInactive: $includeInactive
535
- page: $page
536
- pageSize: $pageSize
537
- principalMemberId: $principalMemberId
538
- scopeType: $scopeType
539
- status: $status
540
- ) {
541
- agentMemberId
542
- createdAt
543
- createdByMemberId
544
- endAt
545
- id
546
- principalMemberId
547
- priority
548
- requiresConfirmation
549
- revokedAt
550
- revokedByMemberId
551
- scopeConditionCel
552
- scopeTemplateIds
553
- scopeType
554
- startAt
555
- status
556
- updatedAt
557
- }
558
- delegationRuleCount(
559
- agentMemberId: $agentMemberId
560
- includeInactive: $includeInactive
561
- principalMemberId: $principalMemberId
562
- scopeType: $scopeType
563
- status: $status
564
- )
565
- }`, {
566
- agentMemberId,
567
- includeInactive,
568
- page,
569
- pageSize,
570
- principalMemberId,
571
- scopeType,
572
- status,
573
- });
574
- return {
575
- rules: data.delegationRules,
576
- totalCount: data.delegationRuleCount,
577
- };
578
- }
579
- async function createDelegationRule(input) {
580
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation CreateDelegationRule($input: CreateDelegationRuleInput!) {
581
- createDelegationRule(input: $input) {
582
- agentMemberId
583
- createdAt
584
- createdByMemberId
585
- endAt
586
- id
587
- principalMemberId
588
- priority
589
- requiresConfirmation
590
- revokedAt
591
- revokedByMemberId
592
- scopeConditionCel
593
- scopeTemplateIds
594
- scopeType
595
- startAt
596
- status
597
- updatedAt
598
- }
599
- }`, { input });
600
- return data.createDelegationRule;
601
- }
602
- async function revokeDelegationRule({ id, revokedByMemberId, }) {
603
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation RevokeDelegationRule($id: String!, $revokedByMemberId: String) {
604
- revokeDelegationRule(id: $id, revokedByMemberId: $revokedByMemberId) {
605
- agentMemberId
606
- createdAt
607
- createdByMemberId
608
- endAt
609
- id
610
- principalMemberId
611
- priority
612
- requiresConfirmation
613
- revokedAt
614
- revokedByMemberId
615
- scopeConditionCel
616
- scopeTemplateIds
617
- scopeType
618
- startAt
619
- status
620
- updatedAt
621
- }
622
- }`, { id, revokedByMemberId });
623
- return data.revokeDelegationRule;
624
- }
625
- async function listNotifications({ includeRead = true, page = 1, pageSize = 10, recipientMemberId, }) {
626
- const data = await (0, graphql_client_1.requestGraphQl)(`query Notifications(
627
- $recipientMemberId: String!
628
- $includeRead: Boolean
629
- $page: Int
630
- $pageSize: Int
631
- ) {
632
- notifications(
633
- includeRead: $includeRead
634
- page: $page
635
- pageSize: $pageSize
636
- recipientMemberId: $recipientMemberId
637
- ) {
638
- attemptCount
639
- body
640
- channel
641
- createdAt
642
- deliveredAt
643
- deliveryError
644
- deliveryTarget
645
- id
646
- instanceId
647
- lastAttemptAt
648
- nextRetryAt
649
- payloadJson
650
- readAt
651
- recipientMemberId
652
- sentAt
653
- status
654
- taskId
655
- title
656
- type
657
- }
658
- notificationCount(
659
- includeRead: $includeRead
660
- recipientMemberId: $recipientMemberId
661
- )
662
- unreadNotificationCount(recipientMemberId: $recipientMemberId)
663
- }`, { includeRead, page, pageSize, recipientMemberId });
664
- return {
665
- notifications: data.notifications,
666
- totalCount: data.notificationCount,
667
- unreadCount: data.unreadNotificationCount,
668
- };
669
- }
670
- async function readUnreadNotificationCount(recipientMemberId) {
671
- const data = await (0, graphql_client_1.requestGraphQl)(`query UnreadNotificationCount($recipientMemberId: String!) {
672
- unreadNotificationCount(recipientMemberId: $recipientMemberId)
673
- }`, { recipientMemberId });
674
- return data.unreadNotificationCount;
675
- }
676
- async function markNotificationRead({ id, readerMemberId, }) {
677
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation MarkNotificationRead($id: String!, $readerMemberId: String) {
678
- markNotificationRead(id: $id, readerMemberId: $readerMemberId) {
679
- id
680
- readAt
681
- status
682
- }
683
- }`, { id, readerMemberId });
684
- return data.markNotificationRead;
685
- }
686
- async function markAllNotificationsRead({ recipientMemberId, }) {
687
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation MarkAllNotificationsRead($recipientMemberId: String) {
688
- markAllNotificationsRead(recipientMemberId: $recipientMemberId)
689
- }`, { recipientMemberId });
690
- return data.markAllNotificationsRead;
691
- }
692
- async function readNotificationPreference(memberId) {
693
- const data = await (0, graphql_client_1.requestGraphQl)(`query NotificationPreference($memberId: String!) {
694
- notificationPreference(memberId: $memberId) {
695
- emailDigestMode
696
- emailEnabled
697
- inAppEnabled
698
- memberId
699
- quietHoursEnd
700
- quietHoursStart
701
- updatedAt
702
- }
703
- }`, { memberId });
704
- return data.notificationPreference;
705
- }
706
- async function updateNotificationPreference(input) {
707
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation UpdateNotificationPreference($input: UpdateNotificationPreferenceInput!) {
708
- updateNotificationPreference(input: $input) {
709
- emailDigestMode
710
- emailEnabled
711
- inAppEnabled
712
- memberId
713
- quietHoursEnd
714
- quietHoursStart
715
- updatedAt
716
- }
717
- }`, { input });
718
- return data.updateNotificationPreference;
719
- }
720
- async function submitApprovalInstance({ formData, initiatorMemberId, templateId, title, }) {
721
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation SubmitApprovalInstance($input: SubmitApprovalInstanceInput!) {
722
- submitApprovalInstance(input: $input) {
723
- id
724
- }
725
- }`, {
726
- input: {
727
- formDataJson: JSON.stringify(formData),
728
- initiatorMemberId,
729
- initiatorMetadataSnapshotJson: null,
730
- templateId,
731
- title,
732
- },
733
- });
734
- return data.submitApprovalInstance.id;
735
- }
736
- async function decideTask({ action, comment, decidedByMemberId, returnToNodeId = null, taskId, transferToMemberId = null, }) {
737
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation DecideTask($input: DecideTaskInput!) {
738
- decideTask(input: $input) {
739
- action
740
- comment
741
- decidedAt
742
- decidedByMemberId
743
- id
744
- returnToNodeId
745
- signatureId
746
- taskId
747
- transferToMemberId
748
- }
749
- }`, {
750
- input: {
751
- action,
752
- comment,
753
- decidedByMemberId,
754
- returnToNodeId,
755
- taskId,
756
- transferToMemberId,
757
- },
758
- });
759
- return data.decideTask;
760
- }
761
- async function cancelApprovalInstance({ cancelledByMemberId, comment, instanceId, }) {
762
- await (0, graphql_client_1.requestGraphQl)(`mutation CancelApprovalInstance($input: CancelApprovalInstanceInput!) {
763
- cancelApprovalInstance(input: $input) {
764
- id
765
- state
766
- }
767
- }`, {
768
- input: {
769
- cancelledByMemberId,
770
- comment,
771
- instanceId,
772
- },
773
- });
774
- }
775
- async function resubmitApprovalInstance({ formData, initiatorMemberId, instanceId, title, }) {
776
- await (0, graphql_client_1.requestGraphQl)(`mutation ResubmitApprovalInstance($input: ResubmitApprovalInstanceInput!) {
777
- resubmitApprovalInstance(input: $input) {
778
- id
779
- state
780
- }
781
- }`, {
782
- input: {
783
- formDataJson: JSON.stringify(formData),
784
- initiatorMemberId,
785
- instanceId,
786
- title,
787
- },
788
- });
789
- }
790
- function readApprovalInstanceCaseTitle(instance) {
791
- return readFormDataCaseTitle({
792
- fallbackTitle: instance.title || instance.id,
793
- formData: instance.formData,
794
- schema: instance.formDefinitionSnapshot.schema ?? null,
795
- uiSchema: instance.formDefinitionSnapshot.uiSchema ?? null,
796
- });
797
- }
798
- function readFormDataCaseTitle({ fallbackTitle, formData, schema, uiSchema, }) {
799
- const firstField = readFirstCaseTitleField(schema, uiSchema);
800
- if (!firstField) {
801
- return fallbackTitle;
802
- }
803
- const valueLabel = readFieldValueLabel(firstField, formData[firstField.fieldKey]);
804
- return valueLabel ? `${firstField.label}:${valueLabel}` : fallbackTitle;
805
- }
806
- function parseInstanceJson(record) {
807
- return {
808
- ...record,
809
- formData: JSON.parse(record.formDataJson),
810
- formDefinitionSnapshot: JSON.parse(record.formDefinitionSnapshotJson),
811
- workflowSnapshot: JSON.parse(record.workflowSnapshotJson),
812
- };
813
- }
814
- async function readFileBase64(file) {
815
- const buffer = await file.arrayBuffer();
816
- const bytes = new Uint8Array(buffer);
817
- const chunkSize = 0x8000;
818
- const chunks = Array.from({ length: Math.ceil(bytes.length / chunkSize) }, (_, index) => String.fromCharCode(...bytes.slice(index * chunkSize, (index + 1) * chunkSize)));
819
- return btoa(chunks.join(''));
820
- }
821
- async function hashFileSha256(file) {
822
- const digest = await crypto.subtle.digest('SHA-256', await file.arrayBuffer());
823
- const bytes = Array.from(new Uint8Array(digest));
824
- return bytes.map((byte) => byte.toString(16).padStart(2, '0')).join('');
825
- }
826
- function readFirstCaseTitleField(schema, uiSchema) {
827
- if (!schema?.fields.length) {
828
- return null;
829
- }
830
- const fieldsByKey = new Map(schema.fields.map((field) => [field.fieldKey, field]));
831
- const firstLayoutField = uiSchema?.layout
832
- .map((layoutItem) => fieldsByKey.get(layoutItem.fieldKey) ?? null)
833
- .find((field) => Boolean(field));
834
- return firstLayoutField ?? schema.fields[0] ?? null;
835
- }
836
- function readFieldValueLabel(field, value) {
837
- if (typeof value === 'undefined' || value === null) {
838
- return null;
839
- }
840
- if (Array.isArray(value)) {
841
- return readArrayFieldValueLabel(field, value);
842
- }
843
- if (field.type === 'boolean') {
844
- return value === true ? '是' : '否';
845
- }
846
- if (isSelectFieldDefinition(field) && typeof value === 'string') {
847
- return readSelectOptionLabel(field, value);
848
- }
849
- const valueLabel = String(value).trim();
850
- return valueLabel || null;
851
- }
852
- function readArrayFieldValueLabel(field, value) {
853
- const labels = isSelectFieldDefinition(field)
854
- ? value.map((item) => readSelectOptionLabel(field, item))
855
- : value;
856
- const label = labels.filter((item) => item.trim()).join('、');
857
- return label || null;
858
- }
859
- function readSelectOptionLabel(field, value) {
860
- return (field.options.find((option) => option.value === value)?.label ?? value).trim();
861
- }
862
- function isSelectFieldDefinition(field) {
863
- return (field.type === 'select' ||
864
- field.type === 'radio' ||
865
- field.type === 'checkbox');
866
- }
867
- //# sourceMappingURL=workflow-api.js.map