processfocus 0.1.0-next.0
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/LICENSE.md +28 -0
- package/README.md +14 -0
- package/dist/auth-FmXptohB.mjs +275 -0
- package/dist/auth-config/src/lib/authentication-config.d.ts +146 -0
- package/dist/auth-config/src/lib/custom-entities-config.d.ts +47 -0
- package/dist/auth-config/src/lib/policies-config.d.ts +52 -0
- package/dist/auth-config/src/lib/provider-types.d.ts +194 -0
- package/dist/auth.d.ts +4 -0
- package/dist/auth.mjs +2 -0
- package/dist/business-calendar/src/index.d.ts +10 -0
- package/dist/business-calendar/src/lib/calendar-config.d.ts +163 -0
- package/dist/business-calendar/src/lib/calendar-period.d.ts +88 -0
- package/dist/business-calendar/src/lib/calendar-service-impl.d.ts +19 -0
- package/dist/business-calendar/src/lib/calendar-service.d.ts +215 -0
- package/dist/business-calendar/src/lib/datetime-utils.d.ts +30 -0
- package/dist/business-calendar/src/lib/duration-calculator.d.ts +49 -0
- package/dist/business-calendar/src/lib/errors.d.ts +69 -0
- package/dist/business-calendar/src/lib/holiday-calculator.d.ts +61 -0
- package/dist/business-calendar/src/lib/holidays.d.ts +141 -0
- package/dist/business-calendar/src/lib/types.d.ts +110 -0
- package/dist/calendar.d.ts +1 -0
- package/dist/calendar.mjs +1204 -0
- package/dist/form-client-representation/src/index.d.ts +6 -0
- package/dist/form-client-representation/src/lib/as-client-representation.d.ts +31 -0
- package/dist/form-client-representation/src/lib/client-form-definition.d.ts +17 -0
- package/dist/form-client-representation/src/lib/extract-annotations.d.ts +20 -0
- package/dist/form-client-representation/src/lib/plugin-registry.d.ts +6 -0
- package/dist/form-client-representation/src/lib/types.d.ts +239 -0
- package/dist/form-client-representation/src/lib/walker.d.ts +68 -0
- package/dist/form-rule/src/index.d.ts +3 -0
- package/dist/form-rule/src/lib/evaluator.d.ts +2 -0
- package/dist/form-rule/src/lib/paths.d.ts +9 -0
- package/dist/form-rule/src/lib/types.d.ts +89 -0
- package/dist/form-schema/src/index.d.ts +8 -0
- package/dist/form-schema/src/lib/annotation-helpers.d.ts +8 -0
- package/dist/form-schema/src/lib/deferred-value.d.ts +10 -0
- package/dist/form-schema/src/lib/email.d.ts +23 -0
- package/dist/form-schema/src/lib/field-count.d.ts +32 -0
- package/dist/form-schema/src/lib/form-annotations.d.ts +25 -0
- package/dist/form-schema/src/lib/form-schema.d.ts +459 -0
- package/dist/form-schema/src/lib/phone.d.ts +4 -0
- package/dist/form-schema/src/lib/property-signature.d.ts +3 -0
- package/dist/form-submission-schema/src/index.d.ts +2 -0
- package/dist/form-submission-schema/src/lib/form-submission-schema.d.ts +49 -0
- package/dist/form-submission-schema/src/lib/schema-defaults.d.ts +16 -0
- package/dist/forms.d.ts +1 -0
- package/dist/forms.mjs +2 -0
- package/dist/frontend-manifest/src/index.d.ts +2 -0
- package/dist/frontend-manifest/src/lib/browser-plugin-artifact.d.ts +25 -0
- package/dist/frontend-manifest/src/lib/frontend-manifest.d.ts +83 -0
- package/dist/frontend-plugin-host/src/index.d.ts +2 -0
- package/dist/frontend-plugin-host/src/lib/frontend-plugin-host.d.ts +124 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.mjs +3780 -0
- package/dist/manifest.d.ts +2 -0
- package/dist/manifest.mjs +5 -0
- package/dist/paths-BkzLn-rG.mjs +282 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.mjs +84 -0
- package/dist/process/src/lib/app-icons.d.ts +52 -0
- package/dist/process/src/lib/brands.d.ts +20 -0
- package/dist/process/src/lib/document-store.d.ts +30 -0
- package/dist/process/src/lib/execution-failure-notifications.d.ts +14 -0
- package/dist/process/src/lib/flow-context.d.ts +181 -0
- package/dist/process/src/lib/flow-path.d.ts +123 -0
- package/dist/process/src/lib/form-authoring.d.ts +19 -0
- package/dist/process/src/lib/form-decoration.d.ts +13 -0
- package/dist/process/src/lib/form-defaults.d.ts +5 -0
- package/dist/process/src/lib/form.d.ts +557 -0
- package/dist/process/src/lib/invitation.d.ts +35 -0
- package/dist/process/src/lib/list.d.ts +447 -0
- package/dist/process/src/lib/lookup-accessor.d.ts +68 -0
- package/dist/process/src/lib/node_step.d.ts +68 -0
- package/dist/process/src/lib/org-unit.d.ts +53 -0
- package/dist/process/src/lib/org-utils.d.ts +56 -0
- package/dist/process/src/lib/organisation-frontend-plugin-manifest.d.ts +33 -0
- package/dist/process/src/lib/organisation.d.ts +166 -0
- package/dist/process/src/lib/phase.d.ts +16 -0
- package/dist/process/src/lib/process.d.ts +196 -0
- package/dist/process/src/lib/public-form-branding.d.ts +27 -0
- package/dist/process/src/lib/role.d.ts +29 -0
- package/dist/process/src/lib/schedule.d.ts +239 -0
- package/dist/process/src/lib/sla.d.ts +84 -0
- package/dist/process/src/lib/stats-view.d.ts +68 -0
- package/dist/process/src/lib/step.d.ts +130 -0
- package/dist/process/src/lib/system-step-executor.d.ts +130 -0
- package/dist/process/src/lib/system-step.d.ts +248 -0
- package/dist/sdk/src/auth.d.ts +4 -0
- package/dist/sdk/src/calendar.d.ts +1 -0
- package/dist/sdk/src/forms.d.ts +1 -0
- package/dist/sdk/src/index.d.ts +26 -0
- package/dist/sdk/src/manifest.d.ts +2 -0
- package/dist/sdk/src/plugin.d.ts +3 -0
- package/dist/sdk/src/testing.d.ts +9 -0
- package/dist/src-C-909PVQ.mjs +498 -0
- package/dist/testing.d.ts +9 -0
- package/dist/testing.mjs +5 -0
- package/package.json +67 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import type { StoredEmailAttachment } from "@processfocus/runtime";
|
|
2
|
+
import { type DateTime, Effect, Schema } from "effect";
|
|
3
|
+
import { type ClientFormDefinition, type WalkError } from "../../../form-client-representation/src/index.js";
|
|
4
|
+
import { type FormRule, type FormRuleEvaluationResult, type FormRuleExpression, type FormRuleLiteral, type FormRulePath, type FormRuleTargetState, type FormRuleValues } from "../../../form-rule/src/index.js";
|
|
5
|
+
import { type CalendarSlotItem, type FlattenMarker, type LookupItem, type ReadOnlyMarker, type StableFormFields, type StructuralOnlyMarker, type TableFieldMarker } from "../../../form-schema/src/index.js";
|
|
6
|
+
import { type DeepWritable } from "../../../form-submission-schema/src/index.js";
|
|
7
|
+
import type { FlowContext, FormStepMeta, StepMeta, SummaryContext } from "./flow-context.js";
|
|
8
|
+
import type { FlowPath } from "./flow-path.js";
|
|
9
|
+
import { type FormAuthoring } from "./form-authoring.js";
|
|
10
|
+
import { LookupAccessor, type LookupOverride, type LookupOverrideStore } from "./lookup-accessor.js";
|
|
11
|
+
import type { InferFormSchemaType, Process } from "./process.js";
|
|
12
|
+
import type { Role } from "./role.js";
|
|
13
|
+
import { type IStepScope, Step, type StepProps } from "./step.js";
|
|
14
|
+
import { type AuthorTaggedError, type ForEachConfig, NotAForEachStepError } from "./system-step.js";
|
|
15
|
+
export type { FormAuthoring } from "./form-authoring.js";
|
|
16
|
+
export { FormDecorationError } from "./form-decoration.js";
|
|
17
|
+
/**
|
|
18
|
+
* Counts leaf fields in a nested structure.
|
|
19
|
+
* A "leaf" is any primitive value or empty array.
|
|
20
|
+
* Objects and non-empty arrays are recursively traversed.
|
|
21
|
+
*
|
|
22
|
+
* @param value - The value to count leaf fields in
|
|
23
|
+
* @returns The number of leaf fields
|
|
24
|
+
*/
|
|
25
|
+
export declare const countLeafFields: (value: unknown) => number;
|
|
26
|
+
/**
|
|
27
|
+
* Typed default values for a form's input fields.
|
|
28
|
+
* Returns properly typed defaults based on TInput schema.
|
|
29
|
+
*/
|
|
30
|
+
type FormDefaults<TInput extends Schema.Struct.Fields> = {
|
|
31
|
+
[K in keyof TInput]: DeepWritable<Schema.Schema.Type<TInput[K]>>;
|
|
32
|
+
};
|
|
33
|
+
export declare const FormRuleSelf: unique symbol;
|
|
34
|
+
type RuleLiteralFor<T> = Extract<T, FormRuleLiteral>;
|
|
35
|
+
type RuleComparable<T> = RuleLiteralFor<Exclude<T, undefined>>;
|
|
36
|
+
type RuleOrderComparable<T> = Extract<RuleComparable<T>, string | number>;
|
|
37
|
+
type Prettify<T> = {
|
|
38
|
+
readonly [K in keyof T]: T[K];
|
|
39
|
+
} & {};
|
|
40
|
+
type UnionToIntersection<T> = (T extends unknown ? (value: T) => void : never) extends (value: infer I) => void ? I : never;
|
|
41
|
+
interface FormRuleValueAccessor<T> {
|
|
42
|
+
readonly equals: (value: RuleComparable<T>) => FormRuleExpression;
|
|
43
|
+
readonly notEquals: (value: RuleComparable<T>) => FormRuleExpression;
|
|
44
|
+
readonly in: (values: readonly RuleComparable<T>[]) => FormRuleExpression;
|
|
45
|
+
readonly notIn: (values: readonly RuleComparable<T>[]) => FormRuleExpression;
|
|
46
|
+
readonly blank: () => FormRuleExpression;
|
|
47
|
+
readonly present: () => FormRuleExpression;
|
|
48
|
+
readonly lt: (value: RuleOrderComparable<T>) => FormRuleExpression;
|
|
49
|
+
readonly lte: (value: RuleOrderComparable<T>) => FormRuleExpression;
|
|
50
|
+
readonly gt: (value: RuleOrderComparable<T>) => FormRuleExpression;
|
|
51
|
+
readonly gte: (value: RuleOrderComparable<T>) => FormRuleExpression;
|
|
52
|
+
}
|
|
53
|
+
type RuleField<Field> = Field extends {
|
|
54
|
+
readonly from: infer From;
|
|
55
|
+
} ? RuleField<From> : Field;
|
|
56
|
+
type FormRuleValueAccessorEntry<TInput extends Schema.Struct.Fields, K extends keyof TInput & string> = RuleField<TInput[K]> extends ReadOnlyMarker | StructuralOnlyMarker ? Record<never, never> : TInput[K] extends FlattenMarker ? TInput[K] extends Schema.Struct<infer NestedFields> ? FormRuleValueAccessors<NestedFields> : Record<never, never> : {
|
|
57
|
+
readonly [P in K]: RuleField<TInput[K]> extends Schema.Struct<infer NestedFields> ? FormRuleValueAccessors<NestedFields> : FormRuleValueAccessor<Schema.Schema.Type<TInput[K]>>;
|
|
58
|
+
};
|
|
59
|
+
type FormRuleValueAccessors<TInput extends Schema.Struct.Fields> = Prettify<UnionToIntersection<{
|
|
60
|
+
readonly [K in keyof TInput & string]: FormRuleValueAccessorEntry<TInput, K>;
|
|
61
|
+
}[keyof TInput & string]>>;
|
|
62
|
+
type LeafFormRuleTargetState = FormRuleTargetState;
|
|
63
|
+
type ContainerFormRuleTargetState = Omit<FormRuleTargetState, "required">;
|
|
64
|
+
type StaticDisplayFormRuleTargetState = Omit<FormRuleTargetState, "required">;
|
|
65
|
+
export type FormRuleTargetTree<TInput extends Schema.Struct.Fields> = {
|
|
66
|
+
readonly [K in keyof TInput & string]?: RuleField<TInput[K]> extends StructuralOnlyMarker | ReadOnlyMarker ? StaticDisplayFormRuleTargetState : RuleField<TInput[K]> extends TableFieldMarker ? StaticDisplayFormRuleTargetState : RuleField<TInput[K]> extends Schema.Struct<infer NestedFields> ? (FormRuleTargetTree<NestedFields> & {
|
|
67
|
+
readonly [FormRuleSelf]?: ContainerFormRuleTargetState;
|
|
68
|
+
}) | (TInput[K] extends Schema.Struct<infer _Fields> ? never : LeafFormRuleTargetState) : LeafFormRuleTargetState;
|
|
69
|
+
};
|
|
70
|
+
interface AuthoredFormRule<TInput extends Schema.Struct.Fields> {
|
|
71
|
+
readonly effects: (effects: FormRuleTargetTree<TInput>, otherwise?: FormRuleTargetTree<TInput>) => FormRule;
|
|
72
|
+
}
|
|
73
|
+
interface FormRuleAuthor<TInput extends Schema.Struct.Fields> {
|
|
74
|
+
readonly when: (condition: FormRuleExpression) => AuthoredFormRule<TInput>;
|
|
75
|
+
readonly and: (...expressions: readonly FormRuleExpression[]) => FormRuleExpression;
|
|
76
|
+
readonly or: (...expressions: readonly FormRuleExpression[]) => FormRuleExpression;
|
|
77
|
+
readonly not: (expression: FormRuleExpression) => FormRuleExpression;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Summary type for todo cards.
|
|
81
|
+
* Record where keys are labels and values are the display strings.
|
|
82
|
+
* Using Record prevents duplicate labels.
|
|
83
|
+
*/
|
|
84
|
+
export type Summary = Record<string, string>;
|
|
85
|
+
export interface FormEmbedConfig {
|
|
86
|
+
readonly sites: readonly string[];
|
|
87
|
+
readonly thankYou: string;
|
|
88
|
+
/**
|
|
89
|
+
* Name of the submitted field that identifies the external participant.
|
|
90
|
+
* The field must exist in the flattened submission schema; runtime validation
|
|
91
|
+
* is still responsible for rejecting non-email values.
|
|
92
|
+
*/
|
|
93
|
+
readonly externalParticipantEmailField: string;
|
|
94
|
+
}
|
|
95
|
+
export interface PublicCompletionRecipient {
|
|
96
|
+
readonly email: string;
|
|
97
|
+
readonly displayName?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface PublicCompletionEmailTemplate {
|
|
100
|
+
readonly id: string;
|
|
101
|
+
readonly variables?: Record<string, string | number>;
|
|
102
|
+
}
|
|
103
|
+
export interface PublicCompletionCorrectionConfig<TState = Record<string, unknown>, TSteps extends Record<string, StepMeta> = Record<string, StepMeta>, TItem = unknown> {
|
|
104
|
+
readonly enabled: true;
|
|
105
|
+
/**
|
|
106
|
+
* Returns the process-state patch for a corrected public recipient email.
|
|
107
|
+
* This can be invoked again after a non-transactional enqueue failure, so it
|
|
108
|
+
* must be idempotent for the current process state and corrected email.
|
|
109
|
+
*/
|
|
110
|
+
readonly applyEmail: (state: TState, correctedEmail: string, ctx: FlowContext<TSteps>, item: TItem) => MaybeEffect<Record<string, unknown>>;
|
|
111
|
+
}
|
|
112
|
+
type MaybeEffect<T> = T | Effect.Effect<T, AuthorTaggedError, unknown>;
|
|
113
|
+
type SummaryResult = Summary | Effect.Effect<Summary, never, never>;
|
|
114
|
+
type AssigneeResult = string | undefined | Effect.Effect<string | undefined, never, unknown>;
|
|
115
|
+
export interface FormPublicCompletionConfig<TState, TSteps extends Record<string, StepMeta>, TItem> {
|
|
116
|
+
/**
|
|
117
|
+
* Resolve who receives the public completion link. This may run while the
|
|
118
|
+
* todo is still waiting, before completed step context is available, so it
|
|
119
|
+
* should depend on process state and the optional forEach item only. If it
|
|
120
|
+
* returns an Effect, that Effect must not require additional context.
|
|
121
|
+
*/
|
|
122
|
+
readonly recipient: (state: TState, ctx: FlowContext<TSteps>, item: TItem) => MaybeEffect<string | PublicCompletionRecipient>;
|
|
123
|
+
readonly expiresAt: (state: TState, ctx: FlowContext<TSteps>, item: TItem) => MaybeEffect<DateTime.DateTime>;
|
|
124
|
+
readonly subject?: (state: TState, ctx: FlowContext<TSteps>, item: TItem, publicUrl: string, expiresAt: DateTime.DateTime) => MaybeEffect<string>;
|
|
125
|
+
readonly body?: (state: TState, ctx: FlowContext<TSteps>, item: TItem, publicUrl: string, expiresAt: DateTime.DateTime) => MaybeEffect<string>;
|
|
126
|
+
readonly template?: (state: TState, ctx: FlowContext<TSteps>, item: TItem, publicUrl: string, expiresAt: DateTime.DateTime) => MaybeEffect<PublicCompletionEmailTemplate>;
|
|
127
|
+
/** Overrides the organisation notification sender for this invitation. */
|
|
128
|
+
readonly from?: string;
|
|
129
|
+
readonly attachments?: (state: TState, ctx: FlowContext<TSteps>, item: TItem) => MaybeEffect<readonly StoredEmailAttachment[]>;
|
|
130
|
+
readonly correction?: PublicCompletionCorrectionConfig<TState, TSteps, TItem>;
|
|
131
|
+
readonly thankYou?: string | ((state: TState, ctx: FlowContext<TSteps>, item: TItem) => MaybeEffect<string>);
|
|
132
|
+
/** Public form heading override for this completion link. */
|
|
133
|
+
readonly formTitle?: string;
|
|
134
|
+
/** Public form supporting copy override for this completion link. */
|
|
135
|
+
readonly formDescription?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Base props shared by all Form steps.
|
|
139
|
+
*/
|
|
140
|
+
interface FormStepPropsBase<TState, TSteps extends Record<string, StepMeta | FormStepMeta> = Record<string, never>, TInput extends Schema.Struct.Fields = Schema.Struct.Fields, TItem = undefined> extends Omit<StepProps<TInput>, "output" | "role"> {
|
|
141
|
+
/**
|
|
142
|
+
* The role responsible for completing this form.
|
|
143
|
+
* Required for Form steps (unlike SystemSteps which have no role).
|
|
144
|
+
*/
|
|
145
|
+
readonly role: Role;
|
|
146
|
+
/**
|
|
147
|
+
* Additional roles that can also complete this form step.
|
|
148
|
+
* Primary role is tried first in authorization; supporting roles provide
|
|
149
|
+
* fallback authorization without needing custom Cedar policies.
|
|
150
|
+
*/
|
|
151
|
+
readonly supportingRoles?: Role[];
|
|
152
|
+
/**
|
|
153
|
+
* Form builder function that defines the form fields.
|
|
154
|
+
*
|
|
155
|
+
* Use `() => ({...})` for static forms. Inline helpers defer expressions
|
|
156
|
+
* that need execution state, completed-step context or a forEach item.
|
|
157
|
+
*
|
|
158
|
+
* Runtime helper callbacks receive `(state, ctx, item)` for each instance.
|
|
159
|
+
*
|
|
160
|
+
* The `state` parameter contains accumulated state from all previous steps.
|
|
161
|
+
* The `ctx` parameter provides access to step metadata like who completed
|
|
162
|
+
* previous steps.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // Static form (no state access needed)
|
|
167
|
+
* const submit = new Form(process, "Submit", {
|
|
168
|
+
* form: () => ({
|
|
169
|
+
* item: ES.String,
|
|
170
|
+
* value: ES.Number,
|
|
171
|
+
* }),
|
|
172
|
+
* role: employeeRole,
|
|
173
|
+
* })
|
|
174
|
+
*
|
|
175
|
+
* // Dynamic form with state access
|
|
176
|
+
* const approve = new Form(flow, "Approve", {
|
|
177
|
+
* form: ({ value }) => ({
|
|
178
|
+
* // state.item is typed from previous step
|
|
179
|
+
* itemDisplay: TextField({
|
|
180
|
+
* label: "Item",
|
|
181
|
+
* readOnly: true,
|
|
182
|
+
* default: value((state) => state.item),
|
|
183
|
+
* }),
|
|
184
|
+
* // ctx.step provides typed access to completed steps
|
|
185
|
+
* requester: TextField({
|
|
186
|
+
* label: "Requester",
|
|
187
|
+
* readOnly: true,
|
|
188
|
+
* default: value((_state, ctx) => ctx.step.submit.providerUser.name),
|
|
189
|
+
* }),
|
|
190
|
+
* approved: ES.Boolean,
|
|
191
|
+
* }),
|
|
192
|
+
* role: managerRole,
|
|
193
|
+
* })
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
readonly form: (helpers: FormAuthoring<TState, TSteps, TItem>) => StaticFormDeclaration<TInput>;
|
|
197
|
+
/**
|
|
198
|
+
* Function to compute summary for todo cards.
|
|
199
|
+
* Returns contextual information displayed on the todo card.
|
|
200
|
+
* Keys are labels, values are display strings (may contain HTML).
|
|
201
|
+
*
|
|
202
|
+
* The second parameter `ctx` provides access to step metadata
|
|
203
|
+
* like who completed previous steps.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const approve = new Form(flow, "Approve", {
|
|
208
|
+
* form: () => ({ approved: ES.Boolean }),
|
|
209
|
+
* summary: (state, ctx) => ({
|
|
210
|
+
* When: formatDate(state.requestedDate),
|
|
211
|
+
* Requester: ctx.step.submitRequest.providerUser.name,
|
|
212
|
+
* }),
|
|
213
|
+
* role: managerRole,
|
|
214
|
+
* })
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
readonly summary?: (state: TState, ctx: SummaryContext<TSteps>, item: TItem) => SummaryResult;
|
|
218
|
+
/**
|
|
219
|
+
* Optional direct provider-user assignee for todos created for this form.
|
|
220
|
+
* The returned value may be a provider-user id or email; runtimes normalize
|
|
221
|
+
* it before persisting `to_do.assigned_to_provider_user`.
|
|
222
|
+
*/
|
|
223
|
+
readonly assignee?: (state: TState, ctx: FlowContext<TSteps>, item: TItem) => AssigneeResult;
|
|
224
|
+
/**
|
|
225
|
+
* Optional struct-level validation that runs after individual field
|
|
226
|
+
* validation during schema decode. Receives the flat decoded struct
|
|
227
|
+
* (wrapper fields are flattened), so it can perform cross-field checks.
|
|
228
|
+
*
|
|
229
|
+
* Return `undefined` to pass, or a `string` error message to fail.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const form = new Form(process, "Deploy", {
|
|
234
|
+
* form: () => ({
|
|
235
|
+
* projectId: LookupField({ label: "Project" }),
|
|
236
|
+
* environmentId: LookupField({ label: "Environment" }),
|
|
237
|
+
* }),
|
|
238
|
+
* validate: (input) =>
|
|
239
|
+
* Effect.gen(function* () {
|
|
240
|
+
* const ops = yield* OrgOperations
|
|
241
|
+
* const belongs = yield* ops.environmentBelongsToProject(
|
|
242
|
+
* input.environmentId,
|
|
243
|
+
* input.projectId,
|
|
244
|
+
* )
|
|
245
|
+
* if (!belongs)
|
|
246
|
+
* return "Environment does not belong to the selected project"
|
|
247
|
+
* return undefined
|
|
248
|
+
* }),
|
|
249
|
+
* role: employeeRole,
|
|
250
|
+
* })
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
readonly validate?: (input: InferFormSchemaType<TInput>) => Effect.Effect<string | undefined, never, any>;
|
|
254
|
+
/**
|
|
255
|
+
* Optional configuration for rendering this start form as an anonymous embed.
|
|
256
|
+
* Allowed sites are exact origins only.
|
|
257
|
+
*/
|
|
258
|
+
readonly embed?: FormEmbedConfig;
|
|
259
|
+
/**
|
|
260
|
+
* Optional external completion email for non-start forms. The regular role
|
|
261
|
+
* todo remains staff-visible; this adds a public completion link email.
|
|
262
|
+
*/
|
|
263
|
+
readonly publicCompletion?: FormPublicCompletionConfig<TState, TSteps, TItem>;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Props specific to Form steps.
|
|
267
|
+
* When `forEach` is present, `TItem` is the type of each forEach item.
|
|
268
|
+
* When absent, `TItem` is `undefined` (no item parameter).
|
|
269
|
+
*
|
|
270
|
+
* @typeParam TState - Accumulated state from previous steps
|
|
271
|
+
* @typeParam TSteps - Record of completed step metadata for ctx.step access
|
|
272
|
+
* @typeParam TInput - Form input schema (inferred from form function return type)
|
|
273
|
+
* @typeParam TItem - Type of forEach item (undefined when no forEach)
|
|
274
|
+
* @typeParam TIsForEach - Whether this step uses forEach semantics
|
|
275
|
+
*/
|
|
276
|
+
export type FormStepProps<TState, TSteps extends Record<string, StepMeta | FormStepMeta> = Record<string, never>, TInput extends Schema.Struct.Fields = Schema.Struct.Fields, TItem = undefined, TIsForEach extends boolean = false> = FormStepPropsBase<TState, TSteps, TInput, TItem> & (TIsForEach extends true ? {
|
|
277
|
+
forEach: ForEachConfig<TState, TSteps, TItem>;
|
|
278
|
+
} : {
|
|
279
|
+
forEach?: never;
|
|
280
|
+
});
|
|
281
|
+
type IsUnion<Value, Whole = Value> = Value extends Whole ? [Whole] extends [Value] ? false : true : never;
|
|
282
|
+
export type StaticFormDeclaration<Fields extends Schema.Struct.Fields> = Fields & (true extends IsUnion<Fields> ? never : StableFormFields<NoInfer<Fields>>);
|
|
283
|
+
export type FormProps<TState, TSteps extends Record<string, StepMeta | FormStepMeta>, TInput extends Schema.Struct.Fields, TItem = undefined> = FormStepPropsBase<TState, TSteps, TInput, TItem> & {
|
|
284
|
+
readonly forEach?: ForEachConfig<TState, TSteps, TItem>;
|
|
285
|
+
};
|
|
286
|
+
declare const LookupFieldNotFoundError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
287
|
+
readonly _tag: "LookupFieldNotFoundError";
|
|
288
|
+
} & Readonly<A>;
|
|
289
|
+
/**
|
|
290
|
+
* Form step class with support for typed state and context access.
|
|
291
|
+
*
|
|
292
|
+
* When using a Step/FlowPath as scope, the state and steps types are
|
|
293
|
+
* automatically inferred from the accumulated state of previous steps.
|
|
294
|
+
*
|
|
295
|
+
* @typeParam TState - Accumulated state type from completed steps
|
|
296
|
+
* @typeParam TSteps - Record of completed step metadata for ctx.step access
|
|
297
|
+
* @typeParam TInput - Form input schema (inferred from form function return type)
|
|
298
|
+
* @typeParam TId - Step identifier literal type
|
|
299
|
+
* @typeParam TItem - Type of forEach item (undefined when no forEach)
|
|
300
|
+
* @typeParam TIsForEach - Whether this step uses forEach semantics
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* // Static form with Process scope
|
|
305
|
+
* const submit = new Form(process, "Submit", {
|
|
306
|
+
* form: () => ({ item: ES.String, value: ES.Number }),
|
|
307
|
+
* role: employeeRole,
|
|
308
|
+
* })
|
|
309
|
+
*
|
|
310
|
+
* // Dynamic form with Step/Flow scope - state is inferred
|
|
311
|
+
* const flow = process.start(submit)
|
|
312
|
+
* const approve = new Form(flow, "Approve", {
|
|
313
|
+
* form: ({ value }) => ({
|
|
314
|
+
* item: TextField({ default: value((state) => state.item), readOnly: true }),
|
|
315
|
+
* approved: ES.Boolean,
|
|
316
|
+
* }),
|
|
317
|
+
* summary: (state, ctx) => ({
|
|
318
|
+
* Item: state.item,
|
|
319
|
+
* Requester: ctx.step.submit.providerUser.name,
|
|
320
|
+
* }),
|
|
321
|
+
* role: managerRole,
|
|
322
|
+
* })
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
/**
|
|
326
|
+
* Error raised when a lookup field is not found or is not annotated
|
|
327
|
+
* as a lookup field in the form schema.
|
|
328
|
+
*/
|
|
329
|
+
export declare class LookupFieldNotFoundError extends LookupFieldNotFoundError_base<{
|
|
330
|
+
readonly fieldName: string;
|
|
331
|
+
readonly formStep: string;
|
|
332
|
+
readonly message: string;
|
|
333
|
+
}> {
|
|
334
|
+
}
|
|
335
|
+
export declare class Form<TState = Record<string, never>, TSteps extends Record<string, StepMeta | FormStepMeta> = Record<string, never>, TInput extends Schema.Struct.Fields = Schema.Struct.Fields, const TId extends string = string, TItem = undefined, TIsForEach extends boolean = [TItem] extends [undefined] ? false : undefined extends TItem ? boolean : true> extends Step<TState, TInput, TId, true, TIsForEach> implements LookupOverrideStore {
|
|
336
|
+
/**
|
|
337
|
+
* The form fields schema extracted from the form function.
|
|
338
|
+
*/
|
|
339
|
+
private _formFields;
|
|
340
|
+
/**
|
|
341
|
+
* Request-local resolution of the static declaration's lazy expressions.
|
|
342
|
+
*/
|
|
343
|
+
private _formFn;
|
|
344
|
+
/**
|
|
345
|
+
* The summary function, stored for computing summary from process state.
|
|
346
|
+
*/
|
|
347
|
+
private _summaryFn;
|
|
348
|
+
private _assigneeFn;
|
|
349
|
+
/**
|
|
350
|
+
* The forEach items function, stored for runtime execution.
|
|
351
|
+
* Undefined when no forEach is configured.
|
|
352
|
+
*/
|
|
353
|
+
private _forEachItemsFn;
|
|
354
|
+
/**
|
|
355
|
+
* The full validation schema: Schema.Struct(fields) optionally refined
|
|
356
|
+
* with a struct-level filterEffect from the validate prop.
|
|
357
|
+
*/
|
|
358
|
+
private _schema;
|
|
359
|
+
/**
|
|
360
|
+
* The flat submission validation schema: submissionSchema(fields) optionally
|
|
361
|
+
* refined with a struct-level filterEffect from the validate prop.
|
|
362
|
+
* Used for server-side validation where wrapper nesting is irrelevant.
|
|
363
|
+
*/
|
|
364
|
+
private _submissionEffectSchema;
|
|
365
|
+
/**
|
|
366
|
+
* Lookup query overrides set via `this.lookups.<field>.setQuery()`.
|
|
367
|
+
*/
|
|
368
|
+
private _lookupOverrides;
|
|
369
|
+
/**
|
|
370
|
+
* Typed accessors for lookup fields.
|
|
371
|
+
* Use `this.lookups.<field>.setQuery()` for independent lookups or
|
|
372
|
+
* `this.lookups.<field>.dependsOn([...]).setQuery()` for dependent lookups.
|
|
373
|
+
*/
|
|
374
|
+
static readonly self: symbol;
|
|
375
|
+
readonly isForm = true;
|
|
376
|
+
readonly lookups: {
|
|
377
|
+
readonly [K in keyof TInput & string]: LookupAccessor<TInput, K>;
|
|
378
|
+
};
|
|
379
|
+
private _rules;
|
|
380
|
+
readonly embed: FormEmbedConfig | undefined;
|
|
381
|
+
readonly supportingRoles: readonly Role[] | undefined;
|
|
382
|
+
readonly publicCompletion: FormPublicCompletionConfig<TState, TSteps, TItem> | undefined;
|
|
383
|
+
/**
|
|
384
|
+
* Create a Form step.
|
|
385
|
+
*
|
|
386
|
+
* @param scope - Parent Process or Step. When a Step is provided, state type is inferred.
|
|
387
|
+
* @param id - Unique identifier for this step
|
|
388
|
+
* @param props - Form properties including form function and optional summary
|
|
389
|
+
*/
|
|
390
|
+
constructor(scope: Process | IStepScope<TState, TSteps> | FlowPath<TState, Schema.Struct.Fields | undefined, TSteps>, id: TId, props: FormProps<TState, TSteps, TInput, TItem>);
|
|
391
|
+
/** @internal Called by LookupAccessor/LookupBuilder to store overrides. */
|
|
392
|
+
_setLookupOverride(fieldName: string, override: LookupOverride): void;
|
|
393
|
+
/**
|
|
394
|
+
* Returns all lookup overrides set via `this.lookups`.
|
|
395
|
+
* Used by the schema generator to emit per-lookup GraphQL queries.
|
|
396
|
+
*/
|
|
397
|
+
lookupOverrides(): ReadonlyMap<string, LookupOverride>;
|
|
398
|
+
/**
|
|
399
|
+
* Append browser-safe form rules authored against typed field accessors and
|
|
400
|
+
* a typed target tree matching this form's schema.
|
|
401
|
+
*/
|
|
402
|
+
rules(build: (values: FormRuleValueAccessors<TInput>, rule: FormRuleAuthor<TInput>) => readonly FormRule[]): this;
|
|
403
|
+
authoritativeFormRules(): readonly FormRule[];
|
|
404
|
+
flattenRuleTargetPath(path: FormRulePath): FormRulePath;
|
|
405
|
+
evaluateFormRules(values: FormRuleValues, baseValues?: FormRuleValues): FormRuleEvaluationResult;
|
|
406
|
+
/**
|
|
407
|
+
* Returns the GraphQL query name for a dependent lookup field.
|
|
408
|
+
* E.g. `lookupDevopsAddEnvironmentInputEnvironmentDetailsStageId`
|
|
409
|
+
*/
|
|
410
|
+
lookupQueryName(fieldName: string): string;
|
|
411
|
+
/**
|
|
412
|
+
* Get the output schema for this form.
|
|
413
|
+
* Returns the fields extracted from the form function.
|
|
414
|
+
*/
|
|
415
|
+
get output(): TInput;
|
|
416
|
+
/**
|
|
417
|
+
* Get the output validation schema for this form.
|
|
418
|
+
* Returns Schema.Struct(fields), optionally refined with a struct-level
|
|
419
|
+
* filterEffect when a `validate` callback was provided.
|
|
420
|
+
*/
|
|
421
|
+
get outputSchema(): Schema.Schema.Any;
|
|
422
|
+
/**
|
|
423
|
+
* Get the flat submission validation schema for this form.
|
|
424
|
+
* Returns submissionSchema(fields) (wrapper fields flattened, read-only/
|
|
425
|
+
* structural-only removed), optionally refined with a struct-level
|
|
426
|
+
* filterEffect when a `validate` callback was provided.
|
|
427
|
+
*
|
|
428
|
+
* Used by start/complete resolvers for server-side validation where
|
|
429
|
+
* wrapper nesting should not affect persisted state shape.
|
|
430
|
+
*/
|
|
431
|
+
get submissionEffectSchema(): Schema.Schema.Any;
|
|
432
|
+
/**
|
|
433
|
+
* Get the forEach items for this form.
|
|
434
|
+
* Returns the array of items, where each item is context data for one form instance.
|
|
435
|
+
* Only available when forEach is configured.
|
|
436
|
+
*/
|
|
437
|
+
forEachItems(state: TState, ctx: FlowContext<TSteps>): Effect.Effect<ReadonlyArray<TItem>, NotAForEachStepError | AuthorTaggedError, unknown>;
|
|
438
|
+
/**
|
|
439
|
+
* Get the form fields with defaults resolved against the given state.
|
|
440
|
+
* Resolves inline lazy expressions against actual execution data.
|
|
441
|
+
*
|
|
442
|
+
* @param state - Process state to resolve defaults against
|
|
443
|
+
* @param ctx - Flow context with step metadata
|
|
444
|
+
* @param item - Optional forEach item data for per-instance context
|
|
445
|
+
* @throws FormDecorationError when a runtime value or presentation is invalid
|
|
446
|
+
* @returns Validated schema fields with defaults properly resolved
|
|
447
|
+
*/
|
|
448
|
+
getFieldsWithState(state: TState, ctx: FlowContext<TSteps>, item?: TItem): TInput;
|
|
449
|
+
/**
|
|
450
|
+
* Check if this form has a summary function defined.
|
|
451
|
+
*/
|
|
452
|
+
get hasSummaryFunction(): boolean;
|
|
453
|
+
get hasAssigneeFunction(): boolean;
|
|
454
|
+
/**
|
|
455
|
+
* Resolve the assignee for this form given the current process state.
|
|
456
|
+
* Returns undefined if no assignee function is defined.
|
|
457
|
+
*
|
|
458
|
+
* Errors in user-provided assignee functions are logged and undefined is
|
|
459
|
+
* returned (same containment as getSummary / dynamic text blocks). Callers
|
|
460
|
+
* must treat `hasAssigneeFunction === true` as “an assignee callback exists”,
|
|
461
|
+
* not as a guarantee that a provider user id will be resolved.
|
|
462
|
+
*/
|
|
463
|
+
getAssignee(state: TState, ctx: FlowContext<TSteps>, item?: TItem): Effect.Effect<string | undefined, never, unknown>;
|
|
464
|
+
/**
|
|
465
|
+
* Compute the summary for this form given the current process state.
|
|
466
|
+
* Returns an empty object if no summary function is defined.
|
|
467
|
+
*
|
|
468
|
+
* Errors in user-provided summary functions are logged and an empty object is returned.
|
|
469
|
+
*
|
|
470
|
+
* @param state - Process state to compute summary from
|
|
471
|
+
* @param ctx - Flow context with step metadata
|
|
472
|
+
* @param item - Optional forEach item data for per-instance context
|
|
473
|
+
* @returns Effect producing summary record (label -> value)
|
|
474
|
+
*/
|
|
475
|
+
getSummary(state: TState, ctx: FlowContext<TSteps> | SummaryContext<TSteps>, item?: TItem): Effect.Effect<Summary, never>;
|
|
476
|
+
/**
|
|
477
|
+
* Resolve default values from schema annotations.
|
|
478
|
+
* Walks through the schema fields and executes any default functions.
|
|
479
|
+
* Errors in user-provided default functions are logged and the field is skipped.
|
|
480
|
+
*/
|
|
481
|
+
private resolveFieldDefaults;
|
|
482
|
+
/**
|
|
483
|
+
* Get the number of leaf fields in this form.
|
|
484
|
+
* Counts primitive fields recursively, not just top-level keys.
|
|
485
|
+
*/
|
|
486
|
+
get totalFields(): number;
|
|
487
|
+
/**
|
|
488
|
+
* Get the schema defaults for this form's input fields.
|
|
489
|
+
* Returns type-compatible placeholder values (empty strings, 0, false, etc.).
|
|
490
|
+
*
|
|
491
|
+
* We need this as input for Tanstack Form in order to display the
|
|
492
|
+
* initial values for a form.
|
|
493
|
+
*
|
|
494
|
+
* @returns Record of field names to their default values
|
|
495
|
+
*/
|
|
496
|
+
defaults(): FormDefaults<TInput>;
|
|
497
|
+
/**
|
|
498
|
+
* Resolve initial metadata defaults without process state.
|
|
499
|
+
* This keeps start-step metadata from leaking symbolic defaults to clients.
|
|
500
|
+
*/
|
|
501
|
+
resolveInitialDefaults(currentProviderUser?: string): Effect.Effect<Record<string, unknown>, never>;
|
|
502
|
+
/**
|
|
503
|
+
* Get the client representation for this form's fields.
|
|
504
|
+
* Used for rendering the form in the UI.
|
|
505
|
+
*
|
|
506
|
+
* Post-processes the representation to add `dependencies` and `queryName`
|
|
507
|
+
* to any lookup components that have dependent overrides.
|
|
508
|
+
*
|
|
509
|
+
* @returns Effect that produces the client representation
|
|
510
|
+
*/
|
|
511
|
+
private buildClientComponents;
|
|
512
|
+
private buildClientFormDefinition;
|
|
513
|
+
private resolveDynamicTextBlockComponent;
|
|
514
|
+
private resolveDynamicTextBlocks;
|
|
515
|
+
private buildRenderableClientFormDefinition;
|
|
516
|
+
clientFormDefinition(): Effect.Effect<ClientFormDefinition, WalkError>;
|
|
517
|
+
renderableClientFormDefinition(): Effect.Effect<ClientFormDefinition, WalkError, unknown>;
|
|
518
|
+
clientFormDefinitionWithState(state: Record<string, unknown>, ctx: FlowContext<TSteps>, item?: unknown): Effect.Effect<ClientFormDefinition, WalkError>;
|
|
519
|
+
renderableClientFormDefinitionWithState(state: Record<string, unknown>, ctx: FlowContext<TSteps>, item?: unknown): Effect.Effect<ClientFormDefinition, WalkError, unknown>;
|
|
520
|
+
/**
|
|
521
|
+
* Get the submission schema for form validation.
|
|
522
|
+
* Excludes read-only fields and removes additionalProperties constraint
|
|
523
|
+
* to allow form values to include read-only fields.
|
|
524
|
+
*
|
|
525
|
+
* @returns JSON schema object
|
|
526
|
+
*/
|
|
527
|
+
submissionSchema(): Record<string, unknown>;
|
|
528
|
+
/**
|
|
529
|
+
* Execute a lookup query for a specific field in this form.
|
|
530
|
+
*
|
|
531
|
+
* Checks for an override (set via `this.lookups`) first, then falls back
|
|
532
|
+
* to the annotation-based query from the LookupField constructor.
|
|
533
|
+
*
|
|
534
|
+
* @param fieldName - The name of the lookup field
|
|
535
|
+
* @param filter - Search filter string
|
|
536
|
+
* @param limit - Maximum number of results
|
|
537
|
+
* @param deps - Dependency values for dependent lookups (field name → value)
|
|
538
|
+
* @returns Effect producing an array of LookupItems
|
|
539
|
+
*/
|
|
540
|
+
executeLookup(fieldName: string, filter: string, limit: number, deps?: Record<string, string | undefined>): Effect.Effect<ReadonlyArray<LookupItem>, unknown, unknown>;
|
|
541
|
+
/** Re-run the form so lookup query closures can see process state. */
|
|
542
|
+
executeLookupWithState(fieldName: string, filter: string, limit: number, state: TState, ctx: FlowContext<TSteps>, item?: TItem, deps?: Record<string, string | undefined>): Effect.Effect<ReadonlyArray<LookupItem>, unknown, unknown>;
|
|
543
|
+
private _runCalendarSlotQuery;
|
|
544
|
+
executeCalendarSlots(fieldName: string): Effect.Effect<ReadonlyArray<CalendarSlotItem>, unknown, unknown>;
|
|
545
|
+
executeCalendarSlotsWithState(fieldName: string, state: TState, ctx: FlowContext<TSteps>, item?: TItem): Effect.Effect<ReadonlyArray<CalendarSlotItem>, unknown, unknown>;
|
|
546
|
+
/**
|
|
547
|
+
* Resolves all default values for this Form given the current process state.
|
|
548
|
+
* Re-executes the form function with state to get fields with state-based defaults.
|
|
549
|
+
* Returns flat defaults (wrapper fields are flattened into parent level).
|
|
550
|
+
*
|
|
551
|
+
* @param processState - Current process state
|
|
552
|
+
* @param ctx - Flow context with step metadata
|
|
553
|
+
* @param item - Optional forEach item data for per-instance context
|
|
554
|
+
* @returns Record of field names to their resolved default values (flat)
|
|
555
|
+
*/
|
|
556
|
+
resolveDefaults(processState: Record<string, unknown>, ctx: FlowContext<TSteps>, item?: unknown, currentProviderUser?: string): Effect.Effect<Record<string, unknown>, never>;
|
|
557
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Construct, type IConstruct } from "constructs";
|
|
2
|
+
import type { Role } from "./role.js";
|
|
3
|
+
export interface InvitationProps {
|
|
4
|
+
/**
|
|
5
|
+
* The email address of the invited user.
|
|
6
|
+
*/
|
|
7
|
+
readonly email: string;
|
|
8
|
+
/**
|
|
9
|
+
* The roles to assign when the user accepts the invitation.
|
|
10
|
+
* Pass Role construct instances to ensure they exist at construction time.
|
|
11
|
+
*/
|
|
12
|
+
readonly roles: readonly Role[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An invitation for a user to join the organisation with pre-assigned roles.
|
|
16
|
+
*
|
|
17
|
+
* When a user signs in for the first time with a matching email address,
|
|
18
|
+
* they will automatically be assigned the specified roles.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const employee = new Role(org, "Employee", { name: "Employee" })
|
|
23
|
+
*
|
|
24
|
+
* new Invitation(org, "admin-invite", {
|
|
25
|
+
* email: "admin@example.com",
|
|
26
|
+
* roles: [employee],
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class Invitation extends Construct {
|
|
31
|
+
readonly isInvitation: true;
|
|
32
|
+
readonly email: string;
|
|
33
|
+
readonly roles: readonly Role[];
|
|
34
|
+
constructor(scope: IConstruct, id: string, props: InvitationProps);
|
|
35
|
+
}
|