@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
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "target": "es2021",
6
+ "moduleResolution": "node",
7
+ "forceConsistentCasingInFileNames": true,
8
+ "strict": true,
9
+ "strictNullChecks": true,
10
+ "noImplicitAny": true,
11
+ "noImplicitOverride": true,
12
+ "noImplicitReturns": true,
13
+ "noFallthroughCasesInSwitch": true,
14
+ "importHelpers": true,
15
+ "lib": ["es2021", "dom"]
16
+ },
17
+ "files": [],
18
+ "include": [],
19
+ "references": [
20
+ {
21
+ "path": "./tsconfig.lib.json"
22
+ },
23
+ {
24
+ "path": "./tsconfig.spec.json"
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "../../dist/out-tsc",
6
+ "declaration": true,
7
+ "types": ["node"]
8
+ },
9
+ "include": ["src/**/*.ts"],
10
+ "exclude": [
11
+ "jest.config.ts",
12
+ "jest.config.cts",
13
+ "src/**/*.spec.ts",
14
+ "src/**/*.test.ts"
15
+ ]
16
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "moduleResolution": "node10",
7
+ "types": ["jest", "node"]
8
+ },
9
+ "include": [
10
+ "jest.config.ts",
11
+ "jest.config.cts",
12
+ "src/**/*.test.ts",
13
+ "src/**/*.spec.ts",
14
+ "src/**/*.d.ts"
15
+ ]
16
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Rytass
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/src/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/api-auth-client"), exports);
5
- tslib_1.__exportStar(require("./lib/graphql-client"), exports);
6
- tslib_1.__exportStar(require("./lib/member-api"), exports);
7
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/bpm-core-client/src/index.ts"],"names":[],"mappings":";;;AAAA,gEAAsC;AACtC,+DAAqC;AACrC,2DAAiC"}
@@ -1,73 +0,0 @@
1
- /**
2
- * Authenticated BPM member returned by {@link loginApi} and
3
- * {@link readApiCurrentMember}.
4
- *
5
- * Mirrors the shape that BPM-compatible wrapper hosts emit from their
6
- * `POST /auth/login` and `GET /auth/me` endpoints. Roles and permissions
7
- * are used by BPM's `BPMAdminGuard` / `BPMDesignerGuard`.
8
- */
9
- export interface ApiMember {
10
- readonly email: string;
11
- readonly expiresAt: string;
12
- readonly memberId: string;
13
- readonly name: string;
14
- readonly permissions: readonly string[];
15
- readonly roles: readonly string[];
16
- }
17
- /**
18
- * Reduced member shape returned by {@link listApiTestMembers}. Excludes
19
- * `permissions` and `expiresAt` because the test-members endpoint is meant
20
- * for picker UIs in dev / demo, not for session establishment.
21
- */
22
- export interface ApiPublicMember {
23
- readonly email: string;
24
- readonly memberId: string;
25
- readonly name: string;
26
- readonly roles: readonly string[];
27
- }
28
- /**
29
- * Lists seeded test members exposed by the host's `/auth/test-members`
30
- * endpoint. Hosts targeting production typically disable this endpoint or
31
- * gate it behind a feature flag.
32
- */
33
- export declare function listApiTestMembers(): Promise<readonly ApiPublicMember[]>;
34
- /**
35
- * Performs a login against the host's `POST /auth/login` endpoint. On
36
- * success the host issues an HTTP-only session cookie that subsequent
37
- * {@link requestGraphQl} calls automatically carry, because
38
- * {@link requestApi} uses `credentials: 'include'`.
39
- *
40
- * Throws on HTTP errors with a message extracted from the response body
41
- * when available.
42
- *
43
- * @param input.identifier - Member id, email, or any other identifier the
44
- * host understands.
45
- * @param input.password - Cleartext credential — TLS is the consumer's
46
- * responsibility.
47
- */
48
- export declare function loginApi(input: {
49
- readonly identifier: string;
50
- readonly password: string;
51
- }): Promise<ApiMember>;
52
- /**
53
- * Calls `POST /auth/logout` on the host. The host clears the session
54
- * cookie. Safe to call when not logged in (host should return 200).
55
- */
56
- export declare function logoutApi(): Promise<void>;
57
- /**
58
- * Reads the currently authenticated member from `GET /auth/me`.
59
- *
60
- * Returns `null` when the host replies `401`, which is the conventional
61
- * way to signal "no active session". Any other HTTP failure throws.
62
- */
63
- export declare function readApiCurrentMember(): Promise<ApiMember | null>;
64
- /**
65
- * Resolves the base URL used by the REST `/auth/*` calls.
66
- *
67
- * Resolution order:
68
- * 1. `process.env.NEXT_PUBLIC_API_AUTH_URL` if non-empty.
69
- * 2. Derived from {@link readGraphQlEndpoint}'s origin — the host is
70
- * assumed to expose both `/graphql` and `/auth/*` at the same origin.
71
- */
72
- export declare function readApiBaseUrl(): string;
73
- export declare function resolveApiBaseUrlFromGraphQlEndpoint(graphQlEndpoint: string): string;
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listApiTestMembers = listApiTestMembers;
4
- exports.loginApi = loginApi;
5
- exports.logoutApi = logoutApi;
6
- exports.readApiCurrentMember = readApiCurrentMember;
7
- exports.readApiBaseUrl = readApiBaseUrl;
8
- exports.resolveApiBaseUrlFromGraphQlEndpoint = resolveApiBaseUrlFromGraphQlEndpoint;
9
- const graphql_client_1 = require("./graphql-client");
10
- /**
11
- * Lists seeded test members exposed by the host's `/auth/test-members`
12
- * endpoint. Hosts targeting production typically disable this endpoint or
13
- * gate it behind a feature flag.
14
- */
15
- async function listApiTestMembers() {
16
- return requestApi('/auth/test-members');
17
- }
18
- /**
19
- * Performs a login against the host's `POST /auth/login` endpoint. On
20
- * success the host issues an HTTP-only session cookie that subsequent
21
- * {@link requestGraphQl} calls automatically carry, because
22
- * {@link requestApi} uses `credentials: 'include'`.
23
- *
24
- * Throws on HTTP errors with a message extracted from the response body
25
- * when available.
26
- *
27
- * @param input.identifier - Member id, email, or any other identifier the
28
- * host understands.
29
- * @param input.password - Cleartext credential — TLS is the consumer's
30
- * responsibility.
31
- */
32
- async function loginApi(input) {
33
- return requestApi('/auth/login', {
34
- body: JSON.stringify(input),
35
- headers: { 'Content-Type': 'application/json' },
36
- method: 'POST',
37
- });
38
- }
39
- /**
40
- * Calls `POST /auth/logout` on the host. The host clears the session
41
- * cookie. Safe to call when not logged in (host should return 200).
42
- */
43
- async function logoutApi() {
44
- await requestApi('/auth/logout', {
45
- method: 'POST',
46
- });
47
- }
48
- /**
49
- * Reads the currently authenticated member from `GET /auth/me`.
50
- *
51
- * Returns `null` when the host replies `401`, which is the conventional
52
- * way to signal "no active session". Any other HTTP failure throws.
53
- */
54
- async function readApiCurrentMember() {
55
- try {
56
- return await requestApi('/auth/me');
57
- }
58
- catch (error) {
59
- if (error instanceof ApiRequestError && error.status === 401) {
60
- return null;
61
- }
62
- throw error;
63
- }
64
- }
65
- /**
66
- * Resolves the base URL used by the REST `/auth/*` calls.
67
- *
68
- * Resolution order:
69
- * 1. `process.env.NEXT_PUBLIC_API_AUTH_URL` if non-empty.
70
- * 2. Derived from {@link readGraphQlEndpoint}'s origin — the host is
71
- * assumed to expose both `/graphql` and `/auth/*` at the same origin.
72
- */
73
- function readApiBaseUrl() {
74
- const explicitApiBaseUrl = process.env.NEXT_PUBLIC_API_AUTH_URL?.trim();
75
- if (explicitApiBaseUrl) {
76
- return explicitApiBaseUrl.replace(/\/$/, '');
77
- }
78
- const graphQlEndpoint = (0, graphql_client_1.readGraphQlEndpoint)();
79
- return resolveApiBaseUrlFromGraphQlEndpoint(graphQlEndpoint);
80
- }
81
- function resolveApiBaseUrlFromGraphQlEndpoint(graphQlEndpoint) {
82
- if (!isAbsoluteUrl(graphQlEndpoint)) {
83
- return '';
84
- }
85
- const endpoint = new URL(graphQlEndpoint);
86
- endpoint.pathname = '/';
87
- endpoint.search = '';
88
- endpoint.hash = '';
89
- return endpoint.toString().replace(/\/$/, '');
90
- }
91
- async function requestApi(path, init) {
92
- const response = await fetch(`${readApiBaseUrl()}${path}`, {
93
- credentials: 'include',
94
- ...init,
95
- });
96
- if (!response.ok) {
97
- throw new ApiRequestError(response.status, await readError(response));
98
- }
99
- return (await response.json());
100
- }
101
- async function readError(response) {
102
- try {
103
- const payload = (await response.json());
104
- return typeof payload.message === 'string'
105
- ? payload.message
106
- : `BPM API request failed with HTTP ${response.status}`;
107
- }
108
- catch {
109
- return `BPM API request failed with HTTP ${response.status}`;
110
- }
111
- }
112
- class ApiRequestError extends Error {
113
- constructor(status, message) {
114
- super(message);
115
- this.status = status;
116
- }
117
- }
118
- function isAbsoluteUrl(value) {
119
- return value.startsWith('http://') || value.startsWith('https://');
120
- }
121
- //# sourceMappingURL=api-auth-client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api-auth-client.js","sourceRoot":"","sources":["../../../../../libs/bpm-core-client/src/lib/api-auth-client.ts"],"names":[],"mappings":";;AAoCA,gDAIC;AAgBD,4BASC;AAMD,8BAIC;AAQD,oDAUC;AAUD,wCAUC;AAED,oFAYC;AA/HD,qDAAuD;AA+BvD;;;;GAIG;AACI,KAAK,UAAU,kBAAkB;IAGtC,OAAO,UAAU,CAA6B,oBAAoB,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,QAAQ,CAAC,KAG9B;IACC,OAAO,UAAU,CAAY,aAAa,EAAE;QAC1C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;QAC3B,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,MAAM,EAAE,MAAM;KACf,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,SAAS;IAC7B,MAAM,UAAU,CAA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AAc,EAAE,GAAG,IAAI,EAAE,EAAE;QACzD,WAAW,EAAE,SAAS;QACtB,GAAG,IAAI;KACR,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,eAAe,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAU,CAAC;AAC1C,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,QAAkB;IACzC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAmC,CAAC;QAE1E,OAAO,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;YACxC,CAAC,CAAC,OAAO,CAAC,OAAO;YACjB,CAAC,CAAC,oCAAoC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,oCAAoC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,MAAM,eAAgB,SAAQ,KAAK;IACjC,YACW,MAAc,EACvB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,WAAM,GAAN,MAAM,CAAQ;IAIzB,CAAC;CACF;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AACrE,CAAC"}
@@ -1,48 +0,0 @@
1
- import { FormDefinitionSchema, FormFieldDefinition, FormUiSchema } from '@rytass/bpm-core-shared/form';
2
- export interface FormDefinitionRecord {
3
- readonly currentVersionId: string | null;
4
- readonly currentVersionCreatedAt: string | null;
5
- readonly currentVersionNumber: number | null;
6
- readonly currentVersionPublishedAt: string | null;
7
- readonly description: string | null;
8
- readonly id: string;
9
- readonly name: string;
10
- readonly updatedAt: string;
11
- }
12
- export type FormDefinitionListStatus = 'DRAFT' | 'PUBLISHED';
13
- export interface FormDefinitionVersionRecord {
14
- readonly id: string;
15
- readonly publishedAt: string | null;
16
- readonly schema: FormDefinitionSchema;
17
- readonly schemaJson: string;
18
- readonly status: 'ARCHIVED' | 'DRAFT' | 'PUBLISHED';
19
- readonly uiSchema: FormUiSchema;
20
- readonly uiSchemaJson: string;
21
- readonly updatedAt: string;
22
- readonly version: number;
23
- }
24
- export interface FormBuilderRecord {
25
- readonly definition: FormDefinitionRecord;
26
- readonly versions: readonly FormDefinitionVersionRecord[];
27
- }
28
- export interface FormSchemaLintResult {
29
- readonly errors: readonly string[];
30
- readonly valid: boolean;
31
- }
32
- export declare function listFormDefinitions(): Promise<readonly FormDefinitionRecord[]>;
33
- export declare function listFormDefinitionsPage({ page, pageSize, status, }: {
34
- readonly page: number;
35
- readonly pageSize: number;
36
- readonly status?: FormDefinitionListStatus | null;
37
- }): Promise<{
38
- readonly forms: readonly FormDefinitionRecord[];
39
- readonly totalCount: number;
40
- }>;
41
- export declare function createFormDefinition(name: string): Promise<string>;
42
- export declare function updateFormDefinition(id: string, name: string): Promise<FormDefinitionRecord>;
43
- export declare function readFormBuilder(formDefinitionId: string): Promise<FormBuilderRecord>;
44
- export declare function updateFormDefinitionDraft(versionId: string, schema: FormDefinitionSchema, uiSchema: FormUiSchema): Promise<FormDefinitionVersionRecord>;
45
- export declare function publishFormDefinitionVersion(versionId: string): Promise<FormDefinitionVersionRecord>;
46
- export declare function forkFormDefinition(formDefinitionId: string): Promise<FormDefinitionVersionRecord>;
47
- export declare function lintFormSchema(schema: FormDefinitionSchema, uiSchema: FormUiSchema): Promise<FormSchemaLintResult>;
48
- export declare function createFieldDefinition(type: FormFieldDefinition['type'], index: number): FormFieldDefinition;
@@ -1,228 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listFormDefinitions = listFormDefinitions;
4
- exports.listFormDefinitionsPage = listFormDefinitionsPage;
5
- exports.createFormDefinition = createFormDefinition;
6
- exports.updateFormDefinition = updateFormDefinition;
7
- exports.readFormBuilder = readFormBuilder;
8
- exports.updateFormDefinitionDraft = updateFormDefinitionDraft;
9
- exports.publishFormDefinitionVersion = publishFormDefinitionVersion;
10
- exports.forkFormDefinition = forkFormDefinition;
11
- exports.lintFormSchema = lintFormSchema;
12
- exports.createFieldDefinition = createFieldDefinition;
13
- const graphql_client_1 = require("../graphql-client");
14
- async function listFormDefinitions() {
15
- const data = await (0, graphql_client_1.requestGraphQl)(`query FormDefinitions {
16
- formDefinitions {
17
- currentVersionCreatedAt
18
- currentVersionId
19
- currentVersionNumber
20
- currentVersionPublishedAt
21
- description
22
- id
23
- name
24
- updatedAt
25
- }
26
- }`);
27
- return data.formDefinitions;
28
- }
29
- async function listFormDefinitionsPage({ page, pageSize, status, }) {
30
- const data = await (0, graphql_client_1.requestGraphQl)(`query FormDefinitionsPage(
31
- $page: Int!
32
- $pageSize: Int!
33
- $status: FormDefinitionListStatus
34
- ) {
35
- formDefinitions(page: $page, pageSize: $pageSize, status: $status) {
36
- currentVersionCreatedAt
37
- currentVersionId
38
- currentVersionNumber
39
- currentVersionPublishedAt
40
- description
41
- id
42
- name
43
- updatedAt
44
- }
45
- formDefinitionCount(status: $status)
46
- }`, { page, pageSize, status: status ?? null });
47
- return {
48
- forms: data.formDefinitions,
49
- totalCount: data.formDefinitionCount,
50
- };
51
- }
52
- async function createFormDefinition(name) {
53
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation CreateFormDefinition($input: CreateFormDefinitionInput!) {
54
- createFormDefinition(input: $input) {
55
- id
56
- }
57
- }`, {
58
- input: {
59
- createdByMemberId: null,
60
- description: null,
61
- name,
62
- schemaJson: null,
63
- uiSchemaJson: null,
64
- },
65
- });
66
- return data.createFormDefinition.id;
67
- }
68
- async function updateFormDefinition(id, name) {
69
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation UpdateFormDefinition($input: UpdateFormDefinitionInput!) {
70
- updateFormDefinition(input: $input) {
71
- currentVersionCreatedAt
72
- currentVersionId
73
- currentVersionNumber
74
- currentVersionPublishedAt
75
- description
76
- id
77
- name
78
- updatedAt
79
- }
80
- }`, {
81
- input: {
82
- description: null,
83
- id,
84
- name,
85
- },
86
- });
87
- return data.updateFormDefinition;
88
- }
89
- async function readFormBuilder(formDefinitionId) {
90
- const data = await (0, graphql_client_1.requestGraphQl)(`query FormBuilder($id: String!) {
91
- formDefinition(id: $id) {
92
- currentVersionCreatedAt
93
- currentVersionId
94
- currentVersionNumber
95
- currentVersionPublishedAt
96
- description
97
- id
98
- name
99
- updatedAt
100
- }
101
- formDefinitionVersions(formDefinitionId: $id) {
102
- id
103
- publishedAt
104
- schemaJson
105
- status
106
- uiSchemaJson
107
- updatedAt
108
- version
109
- }
110
- }`, { id: formDefinitionId });
111
- return {
112
- definition: data.formDefinition,
113
- versions: data.formDefinitionVersions.map(parseVersionJson),
114
- };
115
- }
116
- async function updateFormDefinitionDraft(versionId, schema, uiSchema) {
117
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation UpdateFormDefinitionDraft($input: UpdateFormDefinitionDraftInput!) {
118
- updateFormDefinitionDraft(input: $input) {
119
- id
120
- publishedAt
121
- schemaJson
122
- status
123
- uiSchemaJson
124
- updatedAt
125
- version
126
- }
127
- }`, {
128
- input: {
129
- schemaJson: JSON.stringify(schema),
130
- uiSchemaJson: JSON.stringify(uiSchema),
131
- versionId,
132
- },
133
- });
134
- return parseVersionJson(data.updateFormDefinitionDraft);
135
- }
136
- async function publishFormDefinitionVersion(versionId) {
137
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation PublishFormDefinitionVersion($versionId: String!) {
138
- publishFormDefinitionVersion(versionId: $versionId) {
139
- id
140
- publishedAt
141
- schemaJson
142
- status
143
- uiSchemaJson
144
- updatedAt
145
- version
146
- }
147
- }`, { versionId });
148
- return parseVersionJson(data.publishFormDefinitionVersion);
149
- }
150
- async function forkFormDefinition(formDefinitionId) {
151
- const data = await (0, graphql_client_1.requestGraphQl)(`mutation ForkFormDefinition($formDefinitionId: String!) {
152
- forkFormDefinition(formDefinitionId: $formDefinitionId) {
153
- id
154
- publishedAt
155
- schemaJson
156
- status
157
- uiSchemaJson
158
- updatedAt
159
- version
160
- }
161
- }`, { formDefinitionId });
162
- return parseVersionJson(data.forkFormDefinition);
163
- }
164
- async function lintFormSchema(schema, uiSchema) {
165
- const data = await (0, graphql_client_1.requestGraphQl)(`query LintFormSchema($input: LintFormSchemaInput!) {
166
- lintFormSchema(input: $input) {
167
- errors
168
- valid
169
- }
170
- }`, {
171
- input: {
172
- schemaJson: JSON.stringify(schema),
173
- uiSchemaJson: JSON.stringify(uiSchema),
174
- },
175
- });
176
- return data.lintFormSchema;
177
- }
178
- function createFieldDefinition(type, index) {
179
- const fieldKey = `${type}_${index}`;
180
- const base = {
181
- fieldKey,
182
- label: readDefaultFieldLabel(type, index),
183
- required: false,
184
- type,
185
- };
186
- if (type === 'select' || type === 'radio' || type === 'checkbox') {
187
- return {
188
- ...base,
189
- options: [
190
- { label: '選項 A', value: 'option_a' },
191
- { label: '選項 B', value: 'option_b' },
192
- ],
193
- type,
194
- };
195
- }
196
- if (type === 'file_upload') {
197
- return {
198
- ...base,
199
- maxFiles: 1,
200
- type,
201
- };
202
- }
203
- return base;
204
- }
205
- function parseVersionJson(version) {
206
- return {
207
- ...version,
208
- schema: JSON.parse(version.schemaJson),
209
- uiSchema: JSON.parse(version.uiSchemaJson),
210
- };
211
- }
212
- function readDefaultFieldLabel(type, index) {
213
- const labels = {
214
- boolean: '開關',
215
- checkbox: '複選',
216
- date: '日期',
217
- datetime: '日期時間',
218
- file_upload: '附件',
219
- money: '金額',
220
- number: '數字',
221
- radio: '單選',
222
- select: '下拉選單',
223
- text: '文字',
224
- textarea: '長文字',
225
- };
226
- return `${labels[type]} ${index}`;
227
- }
228
- //# sourceMappingURL=form-api.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file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,IAAiC,EACjC,KAAa;IAEb,MAAM,MAAM,GAA0D;QACpE,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;QACd,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,MAAM;QAChB,WAAW,EAAE,IAAI;QACjB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,KAAK;KAChB,CAAC;IAEF,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;AACpC,CAAC"}
@@ -1,52 +0,0 @@
1
- import { DateFieldDefinition, FormDefinitionSchema, FormFieldDefinition, FormFieldOption, FormFieldValue, FormUiSchema, NumberFieldDefinition, SelectFieldDefinition } from '@rytass/bpm-core-shared/form';
2
- export type ConditionOperator = 'equals' | 'greaterThan' | 'greaterThanOrEqual' | 'lessThan' | 'lessThanOrEqual' | 'notEquals';
3
- export type ParsedConditionRule = Readonly<{
4
- fieldKey: string;
5
- operator: ConditionOperator;
6
- value: string;
7
- }>;
8
- export type FormRendererValues = Readonly<Record<string, FormFieldValue | undefined>>;
9
- export interface FormRendererValidationResult {
10
- readonly errors: Readonly<Record<string, string>>;
11
- readonly firstInvalidFieldKey: string | null;
12
- readonly valid: boolean;
13
- }
14
- export declare function buildFormRendererValues(fields: readonly FormFieldDefinition[], currentValues: FormRendererValues): FormRendererValues;
15
- export declare function readVisibleFormRendererFields(schema: FormDefinitionSchema, uiSchema: FormUiSchema, values: FormRendererValues): readonly FormFieldDefinition[];
16
- export declare function validateFormRendererValues({ schema, uiSchema, values, }: {
17
- readonly schema: FormDefinitionSchema;
18
- readonly uiSchema: FormUiSchema;
19
- readonly values: FormRendererValues;
20
- }): FormRendererValidationResult;
21
- export declare function focusFormRendererField(fieldKey: string): void;
22
- export declare function isFormRendererFieldVisible(field: FormFieldDefinition, fields: readonly FormFieldDefinition[], values: FormRendererValues): boolean;
23
- export declare function isFormRendererFieldRequired(field: FormFieldDefinition, fields: readonly FormFieldDefinition[], values: FormRendererValues): boolean;
24
- export declare function isFormRendererFieldReadonly(field: FormFieldDefinition, fields: readonly FormFieldDefinition[], values: FormRendererValues): boolean;
25
- export declare function evaluateConditionExpression(expression: string, fields: readonly FormFieldDefinition[], values: FormRendererValues, fallback: boolean): boolean;
26
- export declare function parseConditionRule(expression: string): ParsedConditionRule | null;
27
- export declare function buildConditionExpression(field: FormFieldDefinition, operator: ConditionOperator, value: string): string;
28
- export declare function readDefaultConditionOperator(field: FormFieldDefinition): ConditionOperator;
29
- export declare function readDefaultConditionValue(field: FormFieldDefinition): string;
30
- export declare function readConditionOperatorOptions(field: FormFieldDefinition): readonly {
31
- readonly id: ConditionOperator;
32
- readonly name: string;
33
- }[];
34
- export declare function readConditionOperatorOption(value: string | undefined): ConditionOperator | null;
35
- export declare function readDatePickerValue(value: FormFieldValue | string | undefined): string | undefined;
36
- export declare function formatDatePickerValue(value: string | undefined): string | undefined;
37
- export declare function formatDateTimePickerValue(value: string | undefined): string | undefined;
38
- export declare function isNumberFieldDefinition(field: FormFieldDefinition): field is NumberFieldDefinition;
39
- export declare function isDateFieldDefinition(field: FormFieldDefinition): field is DateFieldDefinition;
40
- export declare function isSelectFieldDefinition(field: FormFieldDefinition): field is SelectFieldDefinition;
41
- export declare function readSelectOption<TOption extends {
42
- readonly id: string;
43
- }>(options: readonly TOption[], id: string): TOption | null;
44
- export declare function readFieldOptionAsSelectOption(option: FormFieldOption): {
45
- readonly id: string;
46
- readonly name: string;
47
- };
48
- export declare function parseOptionalNumberInput(value: string): number | undefined;
49
- export declare function clampOptionalNumber(value: number | undefined, range: {
50
- readonly max?: number;
51
- readonly min?: number;
52
- }): number | undefined;