@rippling/rippling-sdk 0.2.0-alpha.34 → 0.2.0-alpha.36
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/client.d.mts +6 -0
- package/client.d.mts.map +1 -1
- package/client.d.ts +6 -0
- package/client.d.ts.map +1 -1
- package/client.js +6 -0
- package/client.js.map +1 -1
- package/client.mjs +6 -0
- package/client.mjs.map +1 -1
- package/examples/.keep +4 -0
- package/examples/manifest/dental-practice-management/dental-practice-management.ts +651 -0
- package/examples/manifest/dental-practice-management/manifest.json +1870 -0
- package/examples/manifest/gym-membership-management/gym-membership-management.ts +757 -0
- package/examples/manifest/gym-membership-management/manifest.json +1975 -0
- package/examples/sdui/sdui-crud-todo/rippling-function.ts +367 -0
- package/examples/sdui/sdui-crud-todo/sdui-crud-todo.ts +282 -0
- package/examples/sdui/sdui-showcase/rippling-function.ts +381 -0
- package/examples/sdui/sdui-showcase/sdui-showcase.ts +351 -0
- package/examples/sdui/sdui-tab-multi-view/rippling-function.ts +1061 -0
- package/examples/sdui/sdui-tab-multi-view/sdui-tab-multi-view.ts +924 -0
- package/examples/sdui/vote/rippling-function.ts +330 -0
- package/examples/sdui/vote/vote.ts +298 -0
- package/lib/manifest/app.d.mts +81 -13
- package/lib/manifest/app.d.mts.map +1 -1
- package/lib/manifest/app.d.ts +81 -13
- package/lib/manifest/app.d.ts.map +1 -1
- package/lib/manifest/app.js +37 -16
- package/lib/manifest/app.js.map +1 -1
- package/lib/manifest/app.mjs +37 -16
- package/lib/manifest/app.mjs.map +1 -1
- package/lib/manifest/category.d.mts +63 -7
- package/lib/manifest/category.d.mts.map +1 -1
- package/lib/manifest/category.d.ts +63 -7
- package/lib/manifest/category.d.ts.map +1 -1
- package/lib/manifest/category.js +45 -10
- package/lib/manifest/category.js.map +1 -1
- package/lib/manifest/category.mjs +43 -8
- package/lib/manifest/category.mjs.map +1 -1
- package/lib/manifest/custom-object-field-section.d.mts +56 -6
- package/lib/manifest/custom-object-field-section.d.mts.map +1 -1
- package/lib/manifest/custom-object-field-section.d.ts +56 -6
- package/lib/manifest/custom-object-field-section.d.ts.map +1 -1
- package/lib/manifest/custom-object-field-section.js +41 -14
- package/lib/manifest/custom-object-field-section.js.map +1 -1
- package/lib/manifest/custom-object-field-section.mjs +39 -12
- package/lib/manifest/custom-object-field-section.mjs.map +1 -1
- package/lib/manifest/custom-object-page-layout.d.mts +201 -41
- package/lib/manifest/custom-object-page-layout.d.mts.map +1 -1
- package/lib/manifest/custom-object-page-layout.d.ts +201 -41
- package/lib/manifest/custom-object-page-layout.d.ts.map +1 -1
- package/lib/manifest/custom-object-page-layout.js +76 -30
- package/lib/manifest/custom-object-page-layout.js.map +1 -1
- package/lib/manifest/custom-object-page-layout.mjs +74 -28
- package/lib/manifest/custom-object-page-layout.mjs.map +1 -1
- package/lib/manifest/custom-object.d.mts +128 -15
- package/lib/manifest/custom-object.d.mts.map +1 -1
- package/lib/manifest/custom-object.d.ts +128 -15
- package/lib/manifest/custom-object.d.ts.map +1 -1
- package/lib/manifest/custom-object.js +61 -26
- package/lib/manifest/custom-object.js.map +1 -1
- package/lib/manifest/custom-object.mjs +61 -26
- package/lib/manifest/custom-object.mjs.map +1 -1
- package/lib/manifest/field.d.mts +265 -54
- package/lib/manifest/field.d.mts.map +1 -1
- package/lib/manifest/field.d.ts +265 -54
- package/lib/manifest/field.d.ts.map +1 -1
- package/lib/manifest/field.js +100 -57
- package/lib/manifest/field.js.map +1 -1
- package/lib/manifest/field.mjs +100 -57
- package/lib/manifest/field.mjs.map +1 -1
- package/lib/manifest/list-view.d.mts +105 -14
- package/lib/manifest/list-view.d.mts.map +1 -1
- package/lib/manifest/list-view.d.ts +105 -14
- package/lib/manifest/list-view.d.ts.map +1 -1
- package/lib/manifest/list-view.js +50 -14
- package/lib/manifest/list-view.js.map +1 -1
- package/lib/manifest/list-view.mjs +48 -12
- package/lib/manifest/list-view.mjs.map +1 -1
- package/lib/manifest/manifest-builder.d.mts +77 -11
- package/lib/manifest/manifest-builder.d.mts.map +1 -1
- package/lib/manifest/manifest-builder.d.ts +77 -11
- package/lib/manifest/manifest-builder.d.ts.map +1 -1
- package/lib/manifest/manifest-builder.js +46 -24
- package/lib/manifest/manifest-builder.js.map +1 -1
- package/lib/manifest/manifest-builder.mjs +44 -22
- package/lib/manifest/manifest-builder.mjs.map +1 -1
- package/lib/manifest/manifest-function.d.mts +92 -12
- package/lib/manifest/manifest-function.d.mts.map +1 -1
- package/lib/manifest/manifest-function.d.ts +92 -12
- package/lib/manifest/manifest-function.d.ts.map +1 -1
- package/lib/manifest/manifest-function.js +40 -11
- package/lib/manifest/manifest-function.js.map +1 -1
- package/lib/manifest/manifest-function.mjs +38 -9
- package/lib/manifest/manifest-function.mjs.map +1 -1
- package/lib/manifest/rule.d.mts +94 -16
- package/lib/manifest/rule.d.mts.map +1 -1
- package/lib/manifest/rule.d.ts +94 -16
- package/lib/manifest/rule.d.ts.map +1 -1
- package/lib/manifest/rule.js +36 -15
- package/lib/manifest/rule.js.map +1 -1
- package/lib/manifest/rule.mjs +36 -15
- package/lib/manifest/rule.mjs.map +1 -1
- package/lib/manifest/sdui-page.d.mts +67 -11
- package/lib/manifest/sdui-page.d.mts.map +1 -1
- package/lib/manifest/sdui-page.d.ts +67 -11
- package/lib/manifest/sdui-page.d.ts.map +1 -1
- package/lib/manifest/sdui-page.js +44 -13
- package/lib/manifest/sdui-page.js.map +1 -1
- package/lib/manifest/sdui-page.mjs +42 -11
- package/lib/manifest/sdui-page.mjs.map +1 -1
- package/lib/manifest/validation.d.mts +87 -12
- package/lib/manifest/validation.d.mts.map +1 -1
- package/lib/manifest/validation.d.ts +87 -12
- package/lib/manifest/validation.d.ts.map +1 -1
- package/lib/manifest/validation.js +41 -15
- package/lib/manifest/validation.js.map +1 -1
- package/lib/manifest/validation.mjs +39 -13
- package/lib/manifest/validation.mjs.map +1 -1
- package/lib/sdui/actions.d.mts +25 -0
- package/lib/sdui/actions.d.mts.map +1 -0
- package/lib/sdui/actions.d.ts +25 -0
- package/lib/sdui/actions.d.ts.map +1 -0
- package/lib/sdui/actions.js +53 -0
- package/lib/sdui/actions.js.map +1 -0
- package/lib/sdui/actions.mjs +42 -0
- package/lib/sdui/actions.mjs.map +1 -0
- package/lib/sdui/component.d.mts +41 -0
- package/lib/sdui/component.d.mts.map +1 -0
- package/lib/sdui/component.d.ts +41 -0
- package/lib/sdui/component.d.ts.map +1 -0
- package/lib/sdui/component.js +95 -0
- package/lib/sdui/component.js.map +1 -0
- package/lib/sdui/component.mjs +91 -0
- package/lib/sdui/component.mjs.map +1 -0
- package/lib/sdui/components.d.mts +149 -0
- package/lib/sdui/components.d.mts.map +1 -0
- package/lib/sdui/components.d.ts +149 -0
- package/lib/sdui/components.d.ts.map +1 -0
- package/lib/sdui/components.js +303 -0
- package/lib/sdui/components.js.map +1 -0
- package/lib/sdui/components.mjs +298 -0
- package/lib/sdui/components.mjs.map +1 -0
- package/lib/sdui/conditions.d.mts +25 -0
- package/lib/sdui/conditions.d.mts.map +1 -0
- package/lib/sdui/conditions.d.ts +25 -0
- package/lib/sdui/conditions.d.ts.map +1 -0
- package/lib/sdui/conditions.js +47 -0
- package/lib/sdui/conditions.js.map +1 -0
- package/lib/sdui/conditions.mjs +35 -0
- package/lib/sdui/conditions.mjs.map +1 -0
- package/lib/sdui/directives.d.mts +18 -0
- package/lib/sdui/directives.d.mts.map +1 -0
- package/lib/sdui/directives.d.ts +18 -0
- package/lib/sdui/directives.d.ts.map +1 -0
- package/lib/sdui/directives.js +28 -0
- package/lib/sdui/directives.js.map +1 -0
- package/lib/sdui/directives.mjs +21 -0
- package/lib/sdui/directives.mjs.map +1 -0
- package/lib/sdui/index.d.mts +362 -0
- package/lib/sdui/index.d.mts.map +1 -0
- package/lib/sdui/index.d.ts +362 -0
- package/lib/sdui/index.d.ts.map +1 -0
- package/lib/sdui/index.js +375 -0
- package/lib/sdui/index.js.map +1 -0
- package/lib/sdui/index.mjs +199 -0
- package/lib/sdui/index.mjs.map +1 -0
- package/lib/sdui/props.d.mts +12 -0
- package/lib/sdui/props.d.mts.map +1 -0
- package/lib/sdui/props.d.ts +12 -0
- package/lib/sdui/props.d.ts.map +1 -0
- package/lib/sdui/props.js +25 -0
- package/lib/sdui/props.js.map +1 -0
- package/lib/sdui/props.mjs +21 -0
- package/lib/sdui/props.mjs.map +1 -0
- package/lib/sdui/render.d.mts +23 -0
- package/lib/sdui/render.d.mts.map +1 -0
- package/lib/sdui/render.d.ts +23 -0
- package/lib/sdui/render.d.ts.map +1 -0
- package/lib/sdui/render.js +40 -0
- package/lib/sdui/render.js.map +1 -0
- package/lib/sdui/render.mjs +37 -0
- package/lib/sdui/render.mjs.map +1 -0
- package/lib/sdui/state.d.mts +22 -0
- package/lib/sdui/state.d.mts.map +1 -0
- package/lib/sdui/state.d.ts +22 -0
- package/lib/sdui/state.d.ts.map +1 -0
- package/lib/sdui/state.js +57 -0
- package/lib/sdui/state.js.map +1 -0
- package/lib/sdui/state.mjs +53 -0
- package/lib/sdui/state.mjs.map +1 -0
- package/package.json +11 -1
- package/resources/company-legal-entity-workers.d.mts +79 -0
- package/resources/company-legal-entity-workers.d.mts.map +1 -0
- package/resources/company-legal-entity-workers.d.ts +79 -0
- package/resources/company-legal-entity-workers.d.ts.map +1 -0
- package/resources/company-legal-entity-workers.js +30 -0
- package/resources/company-legal-entity-workers.js.map +1 -0
- package/resources/company-legal-entity-workers.mjs +26 -0
- package/resources/company-legal-entity-workers.mjs.map +1 -0
- package/resources/draft-hires.d.mts +4 -0
- package/resources/draft-hires.d.mts.map +1 -1
- package/resources/draft-hires.d.ts +4 -0
- package/resources/draft-hires.d.ts.map +1 -1
- package/resources/files.d.mts +16 -1
- package/resources/files.d.mts.map +1 -1
- package/resources/files.d.ts +16 -1
- package/resources/files.d.ts.map +1 -1
- package/resources/headcount-positions.d.mts +2 -2
- package/resources/headcount-positions.d.mts.map +1 -1
- package/resources/headcount-positions.d.ts +2 -2
- package/resources/headcount-positions.d.ts.map +1 -1
- package/resources/index.d.mts +1 -0
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -0
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +4 -2
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -0
- package/resources/index.mjs.map +1 -1
- package/resources/legal-entities.d.mts +1 -1
- package/resources/legal-entities.d.mts.map +1 -1
- package/resources/legal-entities.d.ts +1 -1
- package/resources/legal-entities.d.ts.map +1 -1
- package/resources/location-factors.d.mts +2 -2
- package/resources/location-factors.d.mts.map +1 -1
- package/resources/location-factors.d.ts +2 -2
- package/resources/location-factors.d.ts.map +1 -1
- package/resources/shared.d.mts +1 -1
- package/resources/shared.d.mts.map +1 -1
- package/resources/shared.d.ts +1 -1
- package/resources/shared.d.ts.map +1 -1
- package/resources/workers.d.mts +2 -2
- package/resources/workers.d.mts.map +1 -1
- package/resources/workers.d.ts +2 -2
- package/resources/workers.d.ts.map +1 -1
- package/src/client.ts +20 -0
- package/src/lib/manifest/app.ts +81 -26
- package/src/lib/manifest/category.ts +63 -14
- package/src/lib/manifest/custom-object-field-section.ts +56 -17
- package/src/lib/manifest/custom-object-page-layout.ts +201 -66
- package/src/lib/manifest/custom-object.ts +128 -37
- package/src/lib/manifest/field.ts +265 -75
- package/src/lib/manifest/list-view.ts +105 -25
- package/src/lib/manifest/manifest-builder.ts +75 -32
- package/src/lib/manifest/manifest-function.ts +92 -22
- package/src/lib/manifest/rule.ts +95 -29
- package/src/lib/manifest/sdui-page.ts +67 -21
- package/src/lib/manifest/validation.ts +87 -24
- package/src/lib/sdui/actions.ts +58 -0
- package/src/lib/sdui/component.ts +122 -0
- package/src/lib/sdui/components.ts +308 -0
- package/src/lib/sdui/conditions.ts +59 -0
- package/src/lib/sdui/directives.ts +42 -0
- package/src/lib/sdui/index.ts +365 -0
- package/src/lib/sdui/props.ts +32 -0
- package/src/lib/sdui/render.ts +58 -0
- package/src/lib/sdui/state.ts +60 -0
- package/src/resources/company-legal-entity-workers.ts +115 -0
- package/src/resources/draft-hires.ts +5 -0
- package/src/resources/files.ts +18 -1
- package/src/resources/headcount-positions.ts +2 -0
- package/src/resources/index.ts +7 -0
- package/src/resources/legal-entities.ts +1 -0
- package/src/resources/location-factors.ts +2 -0
- package/src/resources/shared.ts +1 -0
- package/src/resources/workers.ts +2 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -1,38 +1,74 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The contents of this file were inserted manually and are not generated by Stainless.
|
|
3
|
-
*
|
|
4
|
-
* SDUI page definitions for Unity packages.
|
|
5
|
-
* Backend schema: SDUI_PAGE (v2) — `SDUIPageConfig` in
|
|
6
|
-
* `app/hub_platform/sdui/unity_package/sdui_page_interface.py`.
|
|
7
|
-
*
|
|
8
|
-
* Dependency order: FUNCTION → SDUI_PAGE → CUSTOM_APP.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
1
|
import type { ManifestFunction } from './manifest-function';
|
|
12
2
|
import type { ManifestScope } from './manifest-builder';
|
|
13
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Initialization properties for {@link SduiPage}.
|
|
6
|
+
*/
|
|
14
7
|
export interface SduiPageProps {
|
|
15
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Unique identifier for this page within the package (e.g. `'gym_today_schedule'`).
|
|
10
|
+
*
|
|
11
|
+
* Required.
|
|
12
|
+
*/
|
|
16
13
|
sduiPageId: string;
|
|
17
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Display name shown as the tab label in the app (e.g. `'Today\'s schedule'`).
|
|
16
|
+
*
|
|
17
|
+
* Required.
|
|
18
|
+
*/
|
|
18
19
|
name: string;
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* The function that renders this page. Pass a live {@link ManifestFunction} reference,
|
|
22
|
+
* or a raw api_name string for functions defined outside this manifest.
|
|
23
|
+
*
|
|
24
|
+
* Required.
|
|
23
25
|
*/
|
|
24
26
|
function: ManifestFunction | string;
|
|
25
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Human-readable description of what this page shows.
|
|
29
|
+
*
|
|
30
|
+
* Optional. @default `''`
|
|
31
|
+
*/
|
|
26
32
|
description?: string;
|
|
27
33
|
}
|
|
28
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Defines an SDUI page and registers it with the manifest.
|
|
37
|
+
*
|
|
38
|
+
* An SDUI page is a custom UI surface backed by a {@link ManifestFunction}. It appears
|
|
39
|
+
* as a tab in a Rippling {@link App}. You would normally define SDUI pages after the
|
|
40
|
+
* functions they reference, then pass them to an `App` via `pages`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const todaySchedulePage = new SduiPage(manifest, {
|
|
45
|
+
* sduiPageId: 'gym_today_schedule',
|
|
46
|
+
* name: 'Today\'s schedule',
|
|
47
|
+
* function: todayScheduleFn,
|
|
48
|
+
* description: 'SDUI list of class sessions for front desk',
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* new App(manifest, {
|
|
52
|
+
* apiName: 'gym_membership_management_app',
|
|
53
|
+
* name: 'Gym Membership Management',
|
|
54
|
+
* pages: [memberObj, trainerObj, todaySchedulePage],
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @see {@link ManifestFunction} — provides the handler that renders this page.
|
|
59
|
+
* @see {@link App} — hosts this page as a tab via `pages`.
|
|
60
|
+
*/
|
|
29
61
|
export class SduiPage {
|
|
30
62
|
private readonly _sduiPageId: string;
|
|
31
63
|
private readonly _name: string;
|
|
32
64
|
private readonly _functionApiName: string;
|
|
33
65
|
private readonly _description: string;
|
|
34
66
|
|
|
35
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* @param scope - The manifest to register this page with.
|
|
69
|
+
* @param props - Initialization properties.
|
|
70
|
+
* @throws {Error} If `sduiPageId`, `name`, or `function` is missing.
|
|
71
|
+
*/
|
|
36
72
|
constructor(scope: ManifestScope, props: SduiPageProps) {
|
|
37
73
|
if (!props.sduiPageId) throw new Error('sduiPageId is required');
|
|
38
74
|
if (!props.name) throw new Error('name is required');
|
|
@@ -44,22 +80,32 @@ export class SduiPage {
|
|
|
44
80
|
scope._register(this);
|
|
45
81
|
}
|
|
46
82
|
|
|
47
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Returns the unique page identifier (e.g. `'gym_today_schedule'`).
|
|
85
|
+
*/
|
|
48
86
|
getSduiPageId(): string {
|
|
49
87
|
return this._sduiPageId;
|
|
50
88
|
}
|
|
51
89
|
|
|
52
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Returns the display name (tab label) of this page.
|
|
92
|
+
*/
|
|
53
93
|
getName(): string {
|
|
54
94
|
return this._name;
|
|
55
95
|
}
|
|
56
96
|
|
|
57
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Returns the api_name of the function backing this page.
|
|
99
|
+
*/
|
|
58
100
|
getFunctionApiName(): string {
|
|
59
101
|
return this._functionApiName;
|
|
60
102
|
}
|
|
61
103
|
|
|
62
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Serializes this SDUI page to the wire format consumed by the manifest install endpoint.
|
|
106
|
+
*
|
|
107
|
+
* @returns A plain object with `type: 'SDUI_PAGE'`.
|
|
108
|
+
*/
|
|
63
109
|
toDict(): Record<string, any> {
|
|
64
110
|
return {
|
|
65
111
|
type: 'SDUI_PAGE',
|
|
@@ -1,38 +1,89 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The contents of this file were inserted manually and are not generated by Stainless.
|
|
3
|
-
*
|
|
4
|
-
* Validation rules for custom objects (RQL formulas with violation semantics).
|
|
5
|
-
* Backend schema: CUSTOM_OBJECT_VALIDATION_RULE (v2)
|
|
6
|
-
*
|
|
7
|
-
* VIOLATION SEMANTICS: `rqlFormula` returns true when the record is INVALID.
|
|
8
|
-
* Construction is CDK-style: `new Validation(customObject, props)` — the CO
|
|
9
|
-
* is the first positional arg, and the validation auto-registers with the
|
|
10
|
-
* manifest via the CO's scope chain.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
1
|
import { generateId, type ValidationLevel, type ValidationState } from './_helpers';
|
|
14
2
|
import type { CustomObject } from './custom-object';
|
|
15
3
|
import type { Field } from './field';
|
|
16
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Initialization properties for {@link Validation}.
|
|
7
|
+
*/
|
|
17
8
|
export interface ValidationProps {
|
|
18
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Display name of this validation rule shown in the UI.
|
|
11
|
+
*
|
|
12
|
+
* Required.
|
|
13
|
+
*/
|
|
19
14
|
displayName: string;
|
|
20
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* RQL formula that returns `true` when the record is **invalid**.
|
|
17
|
+
*
|
|
18
|
+
* Required. Note the violation semantics: a truthy result triggers the error,
|
|
19
|
+
* not a passing check. Example: `'(end_time__c <= start_time__c)'` fires when
|
|
20
|
+
* end is not after start.
|
|
21
|
+
*/
|
|
21
22
|
rqlFormula: string;
|
|
22
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* User-facing error message shown when the validation fires.
|
|
25
|
+
*
|
|
26
|
+
* Required. Pass an empty string for no message.
|
|
27
|
+
*/
|
|
23
28
|
errorMessage: string;
|
|
24
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Whether this rule is active or inactive.
|
|
31
|
+
*
|
|
32
|
+
* Required. One of `'ACTIVE'` | `'INACTIVE'`.
|
|
33
|
+
*/
|
|
25
34
|
state: ValidationState;
|
|
26
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Whether the error is shown at the record level or on a specific field.
|
|
37
|
+
*
|
|
38
|
+
* Required. One of `'RECORD'` | `'FIELD'`. When `'FIELD'`, also set `fieldRef`.
|
|
39
|
+
*/
|
|
27
40
|
level: ValidationLevel;
|
|
28
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Internal description of this rule (for developer reference only).
|
|
43
|
+
*
|
|
44
|
+
* Required. Pass an empty string if unused.
|
|
45
|
+
*/
|
|
29
46
|
ruleDescription: string;
|
|
30
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Stable identifier for this rule. Pass a human-readable slug
|
|
49
|
+
* (e.g. `'gym_session_end_after_start'`) to keep it stable across regenerations.
|
|
50
|
+
*
|
|
51
|
+
* Optional. Auto-generated when omitted. @default generateId('rule')
|
|
52
|
+
*/
|
|
31
53
|
ruleId?: string;
|
|
32
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* The field the error is pinned to. Typically paired with `level: 'FIELD'`.
|
|
56
|
+
*
|
|
57
|
+
* Optional.
|
|
58
|
+
*/
|
|
33
59
|
fieldRef?: Field;
|
|
34
60
|
}
|
|
35
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Defines a validation rule and registers it with the manifest.
|
|
64
|
+
*
|
|
65
|
+
* A validation rule evaluates an RQL formula on save and blocks the operation
|
|
66
|
+
* when the formula returns `true`. You would normally define validations after
|
|
67
|
+
* the fields they reference.
|
|
68
|
+
*
|
|
69
|
+
* **Violation semantics:** the formula encodes the *invalid* condition, not the
|
|
70
|
+
* valid one. `'(end_time__c <= start_time__c)'` fires when end is before or equal
|
|
71
|
+
* to start — i.e., it is truthy when the record is wrong.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* new Validation(sessionObj, {
|
|
76
|
+
* ruleId: 'gym_session_end_after_start',
|
|
77
|
+
* displayName: 'End time must be after start',
|
|
78
|
+
* rqlFormula: '(end_time__c <= start_time__c)',
|
|
79
|
+
* errorMessage: 'End time must be after the start time.',
|
|
80
|
+
* ruleDescription: 'Prevents zero-length or inverted intervals',
|
|
81
|
+
* state: 'ACTIVE',
|
|
82
|
+
* level: 'FIELD',
|
|
83
|
+
* fieldRef: sessionEndField,
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
36
87
|
export class Validation {
|
|
37
88
|
private readonly _ruleId: string;
|
|
38
89
|
private readonly _customObjectApiName: string;
|
|
@@ -44,7 +95,10 @@ export class Validation {
|
|
|
44
95
|
private readonly _ruleDescription: string;
|
|
45
96
|
private readonly _fieldRef: Field | undefined;
|
|
46
97
|
|
|
47
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* @param customObject - The custom object this rule applies to.
|
|
100
|
+
* @param props - Initialization properties.
|
|
101
|
+
*/
|
|
48
102
|
constructor(customObject: CustomObject, props: ValidationProps) {
|
|
49
103
|
this._ruleId = props.ruleId ?? generateId('rule');
|
|
50
104
|
this._customObjectApiName = customObject.getApiName();
|
|
@@ -58,17 +112,26 @@ export class Validation {
|
|
|
58
112
|
customObject._register(this);
|
|
59
113
|
}
|
|
60
114
|
|
|
61
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Returns the stable identifier for this validation rule (e.g. `'gym_session_end_after_start'`).
|
|
117
|
+
*/
|
|
62
118
|
getRuleId(): string {
|
|
63
119
|
return this._ruleId;
|
|
64
120
|
}
|
|
65
121
|
|
|
66
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* Returns the api_name of the custom object this validation rule applies to.
|
|
124
|
+
*/
|
|
67
125
|
getCustomObjectApiName(): string {
|
|
68
126
|
return this._customObjectApiName;
|
|
69
127
|
}
|
|
70
128
|
|
|
71
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* Serializes this validation rule to the wire format consumed by the manifest install endpoint.
|
|
131
|
+
*
|
|
132
|
+
* @returns A plain object with `type: 'CUSTOM_OBJECT_VALIDATION_RULE'`.
|
|
133
|
+
* `field_rql_name` is omitted when `fieldRef` was not provided.
|
|
134
|
+
*/
|
|
72
135
|
toDict(): Record<string, any> {
|
|
73
136
|
const component: Record<string, any> = {
|
|
74
137
|
type: 'CUSTOM_OBJECT_VALIDATION_RULE',
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { extractPath } from './state';
|
|
2
|
+
|
|
3
|
+
export interface ActionBinding {
|
|
4
|
+
action: string;
|
|
5
|
+
params?: Record<string, unknown>;
|
|
6
|
+
onSuccess?: ActionBinding | { set: Record<string, unknown> };
|
|
7
|
+
onError?: ActionBinding | { set: Record<string, unknown> };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function set(ref: unknown, value: unknown): ActionBinding {
|
|
11
|
+
return { action: 'setState', params: { statePath: extractPath(ref), value } };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function push(ref: unknown, value: unknown, opts?: { clear?: unknown }): ActionBinding {
|
|
15
|
+
const params: Record<string, unknown> = { statePath: extractPath(ref), value };
|
|
16
|
+
if (opts?.clear) {
|
|
17
|
+
params['clearStatePath'] = extractPath(opts.clear);
|
|
18
|
+
}
|
|
19
|
+
return { action: 'pushState', params };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function remove(ref: unknown, index: unknown): ActionBinding {
|
|
23
|
+
return { action: 'removeState', params: { statePath: extractPath(ref), index } };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function callFunction(
|
|
27
|
+
functionId: string,
|
|
28
|
+
action: string,
|
|
29
|
+
opts?: Record<string, unknown>,
|
|
30
|
+
): ActionBinding {
|
|
31
|
+
const { responsePath, onSuccess, onError, ...rest } = opts || {};
|
|
32
|
+
const params: Record<string, unknown> = { functionId, action, ...rest };
|
|
33
|
+
if (responsePath !== undefined) params['responsePath'] = responsePath;
|
|
34
|
+
const binding: ActionBinding = { action: 'triggerFunction', params };
|
|
35
|
+
if (onSuccess) binding.onSuccess = onSuccess as ActionBinding;
|
|
36
|
+
if (onError) binding.onError = onError as ActionBinding;
|
|
37
|
+
return binding;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function nav(config: { path: string; openInNewTab?: boolean }): ActionBinding {
|
|
41
|
+
return { action: 'navigate', params: config };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function notify(message: string, variant: string): ActionBinding {
|
|
45
|
+
return { action: 'showNotification', params: { message, variant } };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function validate(statePath = '/formValidation'): ActionBinding {
|
|
49
|
+
return { action: 'validateForm', params: { statePath } };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function openModal(modalId: string): ActionBinding {
|
|
53
|
+
return { action: 'openModal', params: { modalId } };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function closeModal(): ActionBinding {
|
|
57
|
+
return { action: 'closeModal' };
|
|
58
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* component() — creates a stateful component boundary.
|
|
3
|
+
*
|
|
4
|
+
* Provides ctx.useState (scoped local state) and ctx.useEffect (onMount actions).
|
|
5
|
+
* The returned element is automatically wrapped with _LocalStateProvider in the rendered spec.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* function MembersGrid(props) {
|
|
9
|
+
* return component((ctx) => {
|
|
10
|
+
* const local = ctx.useState({ data: [], loading: true })
|
|
11
|
+
* ctx.useEffect(fetchAction)
|
|
12
|
+
* return { element: DataGrid({ ... }), refresh: fetchAction }
|
|
13
|
+
* })
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { SpecNode } from './components';
|
|
18
|
+
import type { ActionBinding } from './actions';
|
|
19
|
+
|
|
20
|
+
let _idCounter = 0;
|
|
21
|
+
function generateId(): string {
|
|
22
|
+
return `auto_${(++_idCounter).toString(36)}_${Date.now().toString(36)}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Reset counter (for testing)
|
|
26
|
+
export function _resetIdCounter(): void {
|
|
27
|
+
_idCounter = 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface StateScope {
|
|
31
|
+
/** Read state value: { $state: "/auto_xxx/field" } */
|
|
32
|
+
readonly [key: string]: any;
|
|
33
|
+
/** Two-way bind: { $bindState: "/auto_xxx/field" } */
|
|
34
|
+
readonly $bind: { $bindState: string };
|
|
35
|
+
/** Raw path string */
|
|
36
|
+
readonly $path: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface ComponentContext {
|
|
40
|
+
/** Declare scoped local state. Returns a proxy for reading/binding. */
|
|
41
|
+
useState<T extends Record<string, unknown>>(initial: T): StateScope;
|
|
42
|
+
/** Register an action to fire on mount (when element becomes visible). */
|
|
43
|
+
useEffect(action: ActionBinding | ActionBinding[]): void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface ComponentResult {
|
|
47
|
+
element: SpecNode;
|
|
48
|
+
[key: string]: any; // exposed actions like refresh, reset, etc.
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createScopeProxy(basePath: string): StateScope {
|
|
52
|
+
const handler: ProxyHandler<object> = {
|
|
53
|
+
get(_target, prop) {
|
|
54
|
+
if (prop === '$bind') return { $bindState: basePath };
|
|
55
|
+
if (prop === '$path') return basePath;
|
|
56
|
+
if (prop === '$state') return basePath;
|
|
57
|
+
if (prop === 'toJSON') return () => ({ $state: basePath });
|
|
58
|
+
if (prop === Symbol.toPrimitive) return () => `$state:${basePath}`;
|
|
59
|
+
|
|
60
|
+
const childPath = `${basePath}/${String(prop)}`;
|
|
61
|
+
return createScopeProxy(childPath);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
return new Proxy({} as any, handler);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function component(factory: (ctx: ComponentContext) => ComponentResult): ComponentResult {
|
|
68
|
+
let localState: { path: string; initial: unknown } | null = null;
|
|
69
|
+
let mountAction: ActionBinding | ActionBinding[] | null = null;
|
|
70
|
+
|
|
71
|
+
const ctx: ComponentContext = {
|
|
72
|
+
useState<T extends Record<string, unknown>>(initial: T): StateScope {
|
|
73
|
+
const path = `/${generateId()}`;
|
|
74
|
+
localState = { path, initial };
|
|
75
|
+
return createScopeProxy(path);
|
|
76
|
+
},
|
|
77
|
+
useEffect(action: ActionBinding | ActionBinding[]) {
|
|
78
|
+
mountAction = action;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const result = factory(ctx);
|
|
83
|
+
|
|
84
|
+
// Capture state after factory execution (TS can't track closure mutations)
|
|
85
|
+
const capturedState = localState as { path: string; initial: unknown } | null;
|
|
86
|
+
const capturedMount = mountAction;
|
|
87
|
+
|
|
88
|
+
// If no local state and no effects, return as-is
|
|
89
|
+
if (!capturedState && !capturedMount) {
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Wrap element with _LocalStateProvider
|
|
94
|
+
const providerProps: Record<string, unknown> = {};
|
|
95
|
+
if (capturedState) {
|
|
96
|
+
providerProps['statePath'] = capturedState.path;
|
|
97
|
+
providerProps['initialValue'] = capturedState.initial;
|
|
98
|
+
}
|
|
99
|
+
if (capturedMount) {
|
|
100
|
+
providerProps['onMountAction'] = capturedMount;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const wrapper: SpecNode = {
|
|
104
|
+
type: '_LocalStateProvider',
|
|
105
|
+
props: providerProps,
|
|
106
|
+
children: [result.element],
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Attach the local state to the spec's state tree
|
|
110
|
+
// The render() function will collect this via a special marker
|
|
111
|
+
if (capturedState) {
|
|
112
|
+
(wrapper as any)._localStateRegistration = {
|
|
113
|
+
path: capturedState.path,
|
|
114
|
+
initial: capturedState.initial,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
...result,
|
|
120
|
+
element: wrapper,
|
|
121
|
+
};
|
|
122
|
+
}
|