@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
@@ -0,0 +1,88 @@
1
+ import {
2
+ createApprovalTemplate,
3
+ listApprovalTemplates,
4
+ } from './template-api';
5
+
6
+ interface CapturedRequest {
7
+ readonly query: string;
8
+ readonly variables?: Readonly<Record<string, unknown>>;
9
+ }
10
+
11
+ function installFetchMock<TData>(payload: TData): {
12
+ readonly capture: () => CapturedRequest;
13
+ readonly restore: () => void;
14
+ } {
15
+ const originalFetch = global.fetch;
16
+ const fetchMock = jest.fn<
17
+ Promise<Response>,
18
+ [RequestInfo | URL, RequestInit?]
19
+ >();
20
+ fetchMock.mockImplementation(
21
+ async () =>
22
+ new Response(JSON.stringify({ data: payload }), {
23
+ headers: { 'Content-Type': 'application/json' },
24
+ status: 200,
25
+ }),
26
+ );
27
+ (global as { fetch: typeof fetch }).fetch =
28
+ fetchMock as unknown as typeof fetch;
29
+
30
+ return {
31
+ capture: (): CapturedRequest => {
32
+ expect(fetchMock).toHaveBeenCalledTimes(1);
33
+ const init = fetchMock.mock.calls[0]?.[1];
34
+ return JSON.parse(String(init?.body ?? '{}')) as CapturedRequest;
35
+ },
36
+ restore: (): void => {
37
+ (global as { fetch: typeof fetch }).fetch = originalFetch;
38
+ },
39
+ };
40
+ }
41
+
42
+ describe('@rytass/bpm-core-client/template', () => {
43
+ describe('listApprovalTemplates', () => {
44
+ it('issues the ApprovalTemplates query and returns the records', async (): Promise<void> => {
45
+ const harness = installFetchMock({ approvalTemplates: [] });
46
+ try {
47
+ const records = await listApprovalTemplates();
48
+ const request = harness.capture();
49
+
50
+ expect(request.query).toContain('query ApprovalTemplates');
51
+ expect(request.variables).toBeUndefined();
52
+ expect(records).toEqual([]);
53
+ } finally {
54
+ harness.restore();
55
+ }
56
+ });
57
+ });
58
+
59
+ describe('createApprovalTemplate', () => {
60
+ it('wraps the name and category into CreateApprovalTemplateInput', async (): Promise<void> => {
61
+ const harness = installFetchMock({
62
+ createApprovalTemplate: { id: 'template-1' },
63
+ });
64
+ try {
65
+ const id = await createApprovalTemplate({
66
+ categoryId: 'cat-1',
67
+ name: 'Expense reimbursement',
68
+ });
69
+ const request = harness.capture();
70
+
71
+ expect(request.query).toContain('mutation CreateApprovalTemplate');
72
+ expect(request.variables).toEqual({
73
+ input: {
74
+ category: null,
75
+ categoryId: 'cat-1',
76
+ createdByMemberId: null,
77
+ description: null,
78
+ formDefinitionVersionId: null,
79
+ name: 'Expense reimbursement',
80
+ },
81
+ });
82
+ expect(id).toBe('template-1');
83
+ } finally {
84
+ harness.restore();
85
+ }
86
+ });
87
+ });
88
+ });