@rippling/rippling-sdk 0.2.0-alpha.82 → 0.2.0-alpha.84
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 +4 -4
- package/client.d.mts.map +1 -1
- package/client.d.ts +4 -4
- package/client.d.ts.map +1 -1
- package/client.js.map +1 -1
- package/client.mjs.map +1 -1
- package/core/platform/custom-objects/category.d.mts +125 -0
- package/core/platform/custom-objects/category.d.mts.map +1 -0
- package/core/platform/custom-objects/category.d.ts +125 -0
- package/core/platform/custom-objects/category.d.ts.map +1 -0
- package/core/platform/custom-objects/category.js +188 -0
- package/core/platform/custom-objects/category.js.map +1 -0
- package/core/platform/custom-objects/category.mjs +178 -0
- package/core/platform/custom-objects/category.mjs.map +1 -0
- package/core/platform/custom-objects/definition.d.mts +147 -0
- package/core/platform/custom-objects/definition.d.mts.map +1 -0
- package/core/platform/custom-objects/definition.d.ts +147 -0
- package/core/platform/custom-objects/definition.d.ts.map +1 -0
- package/core/platform/custom-objects/definition.js +200 -0
- package/core/platform/custom-objects/definition.js.map +1 -0
- package/core/platform/custom-objects/definition.mjs +190 -0
- package/core/platform/custom-objects/definition.mjs.map +1 -0
- package/core/platform/custom-objects/fields.d.mts +302 -0
- package/core/platform/custom-objects/fields.d.mts.map +1 -0
- package/core/platform/custom-objects/fields.d.ts +302 -0
- package/core/platform/custom-objects/fields.d.ts.map +1 -0
- package/core/platform/custom-objects/fields.js +369 -0
- package/core/platform/custom-objects/fields.js.map +1 -0
- package/core/platform/custom-objects/fields.mjs +347 -0
- package/core/platform/custom-objects/fields.mjs.map +1 -0
- package/core/platform/custom-objects/function-runtime.d.mts +42 -0
- package/core/platform/custom-objects/function-runtime.d.mts.map +1 -0
- package/core/platform/custom-objects/function-runtime.d.ts +42 -0
- package/core/platform/custom-objects/function-runtime.d.ts.map +1 -0
- package/core/platform/custom-objects/function-runtime.js +38 -0
- package/core/platform/custom-objects/function-runtime.js.map +1 -0
- package/core/platform/custom-objects/function-runtime.mjs +35 -0
- package/core/platform/custom-objects/function-runtime.mjs.map +1 -0
- package/core/platform/custom-objects/lifecycle.d.mts +83 -0
- package/core/platform/custom-objects/lifecycle.d.mts.map +1 -0
- package/core/platform/custom-objects/lifecycle.d.ts +83 -0
- package/core/platform/custom-objects/lifecycle.d.ts.map +1 -0
- package/core/platform/custom-objects/lifecycle.js +372 -0
- package/core/platform/custom-objects/lifecycle.js.map +1 -0
- package/core/platform/custom-objects/lifecycle.mjs +367 -0
- package/core/platform/custom-objects/lifecycle.mjs.map +1 -0
- package/core/platform/custom-objects/manager.d.mts +354 -0
- package/core/platform/custom-objects/manager.d.mts.map +1 -0
- package/core/platform/custom-objects/manager.d.ts +354 -0
- package/core/platform/custom-objects/manager.d.ts.map +1 -0
- package/core/platform/custom-objects/manager.js +646 -0
- package/core/platform/custom-objects/manager.js.map +1 -0
- package/core/platform/custom-objects/manager.mjs +637 -0
- package/core/platform/custom-objects/manager.mjs.map +1 -0
- package/core/platform/custom-objects/provisioning.d.mts +138 -0
- package/core/platform/custom-objects/provisioning.d.mts.map +1 -0
- package/core/platform/custom-objects/provisioning.d.ts +138 -0
- package/core/platform/custom-objects/provisioning.d.ts.map +1 -0
- package/core/platform/custom-objects/provisioning.js +455 -0
- package/core/platform/custom-objects/provisioning.js.map +1 -0
- package/core/platform/custom-objects/provisioning.mjs +447 -0
- package/core/platform/custom-objects/provisioning.mjs.map +1 -0
- package/core/platform/custom-objects/rql.d.mts +122 -0
- package/core/platform/custom-objects/rql.d.mts.map +1 -0
- package/core/platform/custom-objects/rql.d.ts +122 -0
- package/core/platform/custom-objects/rql.d.ts.map +1 -0
- package/core/platform/custom-objects/rql.js +225 -0
- package/core/platform/custom-objects/rql.js.map +1 -0
- package/core/platform/custom-objects/rql.mjs +222 -0
- package/core/platform/custom-objects/rql.mjs.map +1 -0
- package/core/platform/custom-objects/schema-manager.d.mts +203 -0
- package/core/platform/custom-objects/schema-manager.d.mts.map +1 -0
- package/core/platform/custom-objects/schema-manager.d.ts +203 -0
- package/core/platform/custom-objects/schema-manager.d.ts.map +1 -0
- package/core/platform/custom-objects/schema-manager.js +256 -0
- package/core/platform/custom-objects/schema-manager.js.map +1 -0
- package/core/platform/custom-objects/schema-manager.mjs +249 -0
- package/core/platform/custom-objects/schema-manager.mjs.map +1 -0
- package/core/platform/custom-objects/typed-rql.d.mts +157 -0
- package/core/platform/custom-objects/typed-rql.d.mts.map +1 -0
- package/core/platform/custom-objects/typed-rql.d.ts +157 -0
- package/core/platform/custom-objects/typed-rql.d.ts.map +1 -0
- package/core/platform/custom-objects/typed-rql.js +583 -0
- package/core/platform/custom-objects/typed-rql.js.map +1 -0
- package/core/platform/custom-objects/typed-rql.mjs +580 -0
- package/core/platform/custom-objects/typed-rql.mjs.map +1 -0
- package/core/platform/custom-objects/types.d.mts +549 -0
- package/core/platform/custom-objects/types.d.mts.map +1 -0
- package/core/platform/custom-objects/types.d.ts +549 -0
- package/core/platform/custom-objects/types.d.ts.map +1 -0
- package/core/platform/custom-objects/types.js +20 -0
- package/core/platform/custom-objects/types.js.map +1 -0
- package/core/platform/custom-objects/types.mjs +17 -0
- package/core/platform/custom-objects/types.mjs.map +1 -0
- package/core/platform/custom-objects/validation.d.mts +97 -0
- package/core/platform/custom-objects/validation.d.mts.map +1 -0
- package/core/platform/custom-objects/validation.d.ts +97 -0
- package/core/platform/custom-objects/validation.d.ts.map +1 -0
- package/core/platform/custom-objects/validation.js +477 -0
- package/core/platform/custom-objects/validation.js.map +1 -0
- package/core/platform/custom-objects/validation.mjs +465 -0
- package/core/platform/custom-objects/validation.mjs.map +1 -0
- package/core/platform/custom-objects.d.mts +67 -0
- package/core/platform/custom-objects.d.mts.map +1 -0
- package/core/platform/custom-objects.d.ts +67 -0
- package/core/platform/custom-objects.d.ts.map +1 -0
- package/core/platform/custom-objects.js +118 -0
- package/core/platform/custom-objects.js.map +1 -0
- package/core/platform/custom-objects.mjs +45 -0
- package/core/platform/custom-objects.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/action.d.mts +58 -0
- package/core/platform/manifest/custom-objects/action.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/action.d.ts +58 -0
- package/core/platform/manifest/custom-objects/action.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/action.js +44 -0
- package/core/platform/manifest/custom-objects/action.js.map +1 -0
- package/core/platform/manifest/custom-objects/action.mjs +40 -0
- package/core/platform/manifest/custom-objects/action.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/conditions.d.mts +240 -0
- package/core/platform/manifest/custom-objects/conditions.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/conditions.d.ts +240 -0
- package/core/platform/manifest/custom-objects/conditions.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/conditions.js +326 -0
- package/core/platform/manifest/custom-objects/conditions.js.map +1 -0
- package/core/platform/manifest/custom-objects/conditions.mjs +321 -0
- package/core/platform/manifest/custom-objects/conditions.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/existing.d.mts +87 -0
- package/core/platform/manifest/custom-objects/existing.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/existing.d.ts +87 -0
- package/core/platform/manifest/custom-objects/existing.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/existing.js +113 -0
- package/core/platform/manifest/custom-objects/existing.js.map +1 -0
- package/core/platform/manifest/custom-objects/existing.mjs +109 -0
- package/core/platform/manifest/custom-objects/existing.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/field-resolution.d.mts +48 -0
- package/core/platform/manifest/custom-objects/field-resolution.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/field-resolution.d.ts +48 -0
- package/core/platform/manifest/custom-objects/field-resolution.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/field-resolution.js +61 -0
- package/core/platform/manifest/custom-objects/field-resolution.js.map +1 -0
- package/core/platform/manifest/custom-objects/field-resolution.mjs +58 -0
- package/core/platform/manifest/custom-objects/field-resolution.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/function-file.d.mts +87 -0
- package/core/platform/manifest/custom-objects/function-file.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/function-file.d.ts +87 -0
- package/core/platform/manifest/custom-objects/function-file.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/function-file.js +76 -0
- package/core/platform/manifest/custom-objects/function-file.js.map +1 -0
- package/core/platform/manifest/custom-objects/function-file.mjs +69 -0
- package/core/platform/manifest/custom-objects/function-file.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/list-view.d.mts +65 -0
- package/core/platform/manifest/custom-objects/list-view.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/list-view.d.ts +65 -0
- package/core/platform/manifest/custom-objects/list-view.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/list-view.js +33 -0
- package/core/platform/manifest/custom-objects/list-view.js.map +1 -0
- package/core/platform/manifest/custom-objects/list-view.mjs +30 -0
- package/core/platform/manifest/custom-objects/list-view.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/object-list-page.d.mts +43 -0
- package/core/platform/manifest/custom-objects/object-list-page.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/object-list-page.d.ts +43 -0
- package/core/platform/manifest/custom-objects/object-list-page.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/object-list-page.js +54 -0
- package/core/platform/manifest/custom-objects/object-list-page.js.map +1 -0
- package/core/platform/manifest/custom-objects/object-list-page.mjs +50 -0
- package/core/platform/manifest/custom-objects/object-list-page.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/page-layout.d.mts +142 -0
- package/core/platform/manifest/custom-objects/page-layout.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/page-layout.d.ts +142 -0
- package/core/platform/manifest/custom-objects/page-layout.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/page-layout.js +184 -0
- package/core/platform/manifest/custom-objects/page-layout.js.map +1 -0
- package/core/platform/manifest/custom-objects/page-layout.mjs +180 -0
- package/core/platform/manifest/custom-objects/page-layout.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/register.d.mts +87 -0
- package/core/platform/manifest/custom-objects/register.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/register.d.ts +87 -0
- package/core/platform/manifest/custom-objects/register.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/register.js +395 -0
- package/core/platform/manifest/custom-objects/register.js.map +1 -0
- package/core/platform/manifest/custom-objects/register.mjs +391 -0
- package/core/platform/manifest/custom-objects/register.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/rule.d.mts +113 -0
- package/core/platform/manifest/custom-objects/rule.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/rule.d.ts +113 -0
- package/core/platform/manifest/custom-objects/rule.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/rule.js +49 -0
- package/core/platform/manifest/custom-objects/rule.js.map +1 -0
- package/core/platform/manifest/custom-objects/rule.mjs +45 -0
- package/core/platform/manifest/custom-objects/rule.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/sdui-page.d.mts +214 -0
- package/core/platform/manifest/custom-objects/sdui-page.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/sdui-page.d.ts +214 -0
- package/core/platform/manifest/custom-objects/sdui-page.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/sdui-page.js +194 -0
- package/core/platform/manifest/custom-objects/sdui-page.js.map +1 -0
- package/core/platform/manifest/custom-objects/sdui-page.mjs +182 -0
- package/core/platform/manifest/custom-objects/sdui-page.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/typed-condition.d.mts +28 -0
- package/core/platform/manifest/custom-objects/typed-condition.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/typed-condition.d.ts +28 -0
- package/core/platform/manifest/custom-objects/typed-condition.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/typed-condition.js +434 -0
- package/core/platform/manifest/custom-objects/typed-condition.js.map +1 -0
- package/core/platform/manifest/custom-objects/typed-condition.mjs +431 -0
- package/core/platform/manifest/custom-objects/typed-condition.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/types.d.mts +29 -0
- package/core/platform/manifest/custom-objects/types.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/types.d.ts +29 -0
- package/core/platform/manifest/custom-objects/types.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/types.js +3 -0
- package/core/platform/manifest/custom-objects/types.js.map +1 -0
- package/core/platform/manifest/custom-objects/types.mjs +2 -0
- package/core/platform/manifest/custom-objects/types.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/validation.d.mts +44 -0
- package/core/platform/manifest/custom-objects/validation.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/validation.d.ts +44 -0
- package/core/platform/manifest/custom-objects/validation.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/validation.js +30 -0
- package/core/platform/manifest/custom-objects/validation.js.map +1 -0
- package/core/platform/manifest/custom-objects/validation.mjs +27 -0
- package/core/platform/manifest/custom-objects/validation.mjs.map +1 -0
- package/core/platform/manifest/custom-objects/workflow.d.mts +47 -0
- package/core/platform/manifest/custom-objects/workflow.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects/workflow.d.ts +47 -0
- package/core/platform/manifest/custom-objects/workflow.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects/workflow.js +38 -0
- package/core/platform/manifest/custom-objects/workflow.js.map +1 -0
- package/core/platform/manifest/custom-objects/workflow.mjs +34 -0
- package/core/platform/manifest/custom-objects/workflow.mjs.map +1 -0
- package/core/platform/manifest/custom-objects.d.mts +85 -0
- package/core/platform/manifest/custom-objects.d.mts.map +1 -0
- package/core/platform/manifest/custom-objects.d.ts +85 -0
- package/core/platform/manifest/custom-objects.d.ts.map +1 -0
- package/core/platform/manifest/custom-objects.js +84 -0
- package/core/platform/manifest/custom-objects.js.map +1 -0
- package/core/platform/manifest/custom-objects.mjs +55 -0
- package/core/platform/manifest/custom-objects.mjs.map +1 -0
- package/examples/manifest/custom-object-creation-workflow/custom-object-creation-workflow.ts +26 -44
- package/examples/manifest/custom-object-creation-workflow/functions/intake-request-created.ts +20 -0
- package/examples/manifest/custom-object-creation-workflow/schema.ts +29 -0
- package/examples/manifest/dental-practice-management/dental-practice-management.ts +142 -470
- package/examples/manifest/dental-practice-management/functions/chair-schedule.ts +13 -23
- package/examples/manifest/dental-practice-management/functions/complete-visit.ts +32 -55
- package/examples/manifest/dental-practice-management/functions/operatory-list.ts +13 -23
- package/examples/manifest/dental-practice-management/functions/patient-list.ts +13 -23
- package/examples/manifest/dental-practice-management/functions/treatment-plan-list.ts +13 -23
- package/examples/manifest/dental-practice-management/schema.ts +298 -0
- package/examples/manifest/existing-manifest-mutations/existing-manifest-mutations.ts +68 -23
- package/examples/manifest/field-service-dispatch/field-service-dispatch.ts +102 -375
- package/examples/manifest/field-service-dispatch/schema.ts +248 -0
- package/examples/manifest/grant-program-management/grant-program-management.ts +125 -419
- package/examples/manifest/grant-program-management/schema.ts +269 -0
- package/examples/manifest/gym-membership-management/functions/check-in-desk.ts +13 -23
- package/examples/manifest/gym-membership-management/functions/member-list.ts +13 -23
- package/examples/manifest/gym-membership-management/functions/today-schedule.ts +13 -23
- package/examples/manifest/gym-membership-management/functions/trainer-list.ts +13 -23
- package/examples/manifest/gym-membership-management/gym-membership-management.ts +92 -442
- package/examples/manifest/gym-membership-management/schema.ts +266 -0
- package/examples/manifest/procurement-approval-hub/functions/route-purchase-request.ts +20 -0
- package/examples/manifest/procurement-approval-hub/procurement-approval-hub.ts +122 -408
- package/examples/manifest/procurement-approval-hub/schema.ts +256 -0
- package/examples/manifest/simple-todo-app/functions/mark-done.ts +16 -12
- package/examples/manifest/simple-todo-app/functions/todo-list.ts +13 -23
- package/examples/manifest/simple-todo-app/schema.ts +60 -0
- package/examples/manifest/simple-todo-app/simple-todo-app.ts +40 -109
- package/examples/manifest/todo-app-without-object-list-view/functions/todo-page.ts +166 -193
- package/examples/manifest/todo-app-without-object-list-view/schema.ts +28 -0
- package/examples/manifest/todo-app-without-object-list-view/todo-app-without-object-list-view.ts +24 -47
- package/package.json +7 -13
- package/resources/custom-objects/custom-objects.d.mts +7 -0
- package/resources/custom-objects/custom-objects.d.mts.map +1 -1
- package/resources/custom-objects/custom-objects.d.ts +7 -0
- package/resources/custom-objects/custom-objects.d.ts.map +1 -1
- package/resources/custom-objects/custom-objects.js.map +1 -1
- package/resources/custom-objects/custom-objects.mjs.map +1 -1
- package/resources/custom-objects/fields.d.mts +170 -15
- package/resources/custom-objects/fields.d.mts.map +1 -1
- package/resources/custom-objects/fields.d.ts +170 -15
- package/resources/custom-objects/fields.d.ts.map +1 -1
- package/resources/index.d.mts +2 -2
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +2 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/leave-program-evaluations.d.mts +510 -3
- package/resources/leave-program-evaluations.d.mts.map +1 -1
- package/resources/leave-program-evaluations.d.ts +510 -3
- package/resources/leave-program-evaluations.d.ts.map +1 -1
- package/resources/levels.d.mts +64 -2
- package/resources/levels.d.mts.map +1 -1
- package/resources/levels.d.ts +64 -2
- package/resources/levels.d.ts.map +1 -1
- package/resources/levels.js +22 -0
- package/resources/levels.js.map +1 -1
- package/resources/levels.mjs +22 -0
- package/resources/levels.mjs.map +1 -1
- package/resources/tracks.d.mts +45 -1
- package/resources/tracks.d.mts.map +1 -1
- package/resources/tracks.d.ts +45 -1
- package/resources/tracks.d.ts.map +1 -1
- package/resources/tracks.js +22 -0
- package/resources/tracks.js.map +1 -1
- package/resources/tracks.mjs +22 -0
- package/resources/tracks.mjs.map +1 -1
- package/src/client.ts +8 -0
- package/src/core/platform/README.md +20 -0
- package/src/core/platform/custom-objects/category.ts +294 -0
- package/src/core/platform/custom-objects/definition.ts +373 -0
- package/src/core/platform/custom-objects/fields.ts +653 -0
- package/src/core/platform/custom-objects/function-runtime.ts +76 -0
- package/src/core/platform/custom-objects/lifecycle.ts +557 -0
- package/src/core/platform/custom-objects/manager.ts +959 -0
- package/src/core/platform/custom-objects/provisioning.ts +672 -0
- package/src/core/platform/custom-objects/rql.ts +375 -0
- package/src/core/platform/custom-objects/schema-manager.ts +351 -0
- package/src/core/platform/custom-objects/typed-rql.ts +1273 -0
- package/src/core/platform/custom-objects/types.ts +753 -0
- package/src/core/platform/custom-objects/validation.ts +573 -0
- package/src/core/platform/custom-objects.ts +269 -0
- package/src/core/platform/manifest/README.md +26 -0
- package/src/core/platform/manifest/custom-objects/action.ts +87 -0
- package/src/core/platform/manifest/custom-objects/conditions.ts +762 -0
- package/src/core/platform/manifest/custom-objects/existing.ts +221 -0
- package/src/core/platform/manifest/custom-objects/field-resolution.ts +116 -0
- package/src/core/platform/manifest/custom-objects/function-file.ts +149 -0
- package/src/core/platform/manifest/custom-objects/list-view.ts +95 -0
- package/src/core/platform/manifest/custom-objects/object-list-page.ts +87 -0
- package/src/core/platform/manifest/custom-objects/page-layout.ts +380 -0
- package/src/core/platform/manifest/custom-objects/register.ts +555 -0
- package/src/core/platform/manifest/custom-objects/rule.ts +192 -0
- package/src/core/platform/manifest/custom-objects/sdui-page.ts +515 -0
- package/src/core/platform/manifest/custom-objects/typed-condition.ts +617 -0
- package/src/core/platform/manifest/custom-objects/types.ts +92 -0
- package/src/core/platform/manifest/custom-objects/validation.ts +70 -0
- package/src/core/platform/manifest/custom-objects/workflow.ts +71 -0
- package/src/core/platform/manifest/custom-objects.ts +203 -0
- package/src/pebble-sdui-web-custom-apps-shim.d.ts +3 -0
- package/src/resources/custom-objects/custom-objects.ts +8 -0
- package/src/resources/custom-objects/fields.ts +239 -14
- package/src/resources/index.ts +4 -0
- package/src/resources/leave-program-evaluations.ts +610 -3
- package/src/resources/levels.ts +93 -1
- package/src/resources/tracks.ts +70 -0
- package/src/tsconfig.json +1 -1
- 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
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
import { buildAction, type ActionBinding, type ActionOptions } from '@rippling/pebble-sdui-web';
|
|
2
|
+
import { setState } from '@rippling/pebble-sdui-web/catalogs/custom-apps';
|
|
3
|
+
import {
|
|
4
|
+
FunctionResponse,
|
|
5
|
+
type FunctionContext,
|
|
6
|
+
type FunctionResponseOptions,
|
|
7
|
+
type SduiPageFunctionEvent,
|
|
8
|
+
} from '../../../../functions';
|
|
9
|
+
|
|
10
|
+
type TypedSduiStatePathPrefix<TPrefix extends string, TKey extends string> = `${TPrefix}/${TKey}`;
|
|
11
|
+
type TypedSduiPathKeys<TValue> = Extract<keyof TValue, string>;
|
|
12
|
+
|
|
13
|
+
type TypedSduiStatePathInner<TValue, TPrefix extends string> = {
|
|
14
|
+
readonly [TKey in TypedSduiPathKeys<TValue>]: TValue[TKey] extends readonly unknown[] ?
|
|
15
|
+
TypedSduiStatePathPrefix<TPrefix, TKey>
|
|
16
|
+
: TValue[TKey] extends Record<string, unknown> ?
|
|
17
|
+
| TypedSduiStatePathPrefix<TPrefix, TKey>
|
|
18
|
+
| TypedSduiStatePathInner<TValue[TKey], TypedSduiStatePathPrefix<TPrefix, TKey>>
|
|
19
|
+
: TypedSduiStatePathPrefix<TPrefix, TKey>;
|
|
20
|
+
}[TypedSduiPathKeys<TValue>];
|
|
21
|
+
|
|
22
|
+
type TypedSduiStatePathValueInner<TValue, TSegments extends string> = TSegments extends (
|
|
23
|
+
`${infer THead}/${infer TRest}`
|
|
24
|
+
) ?
|
|
25
|
+
THead extends TypedSduiPathKeys<TValue> ?
|
|
26
|
+
TypedSduiStatePathValueInner<TValue[THead], TRest>
|
|
27
|
+
: never
|
|
28
|
+
: TSegments extends TypedSduiPathKeys<TValue> ? TValue[TSegments]
|
|
29
|
+
: never;
|
|
30
|
+
|
|
31
|
+
/** JSON-pointer-like state path derived from one SDUI page-state shape. */
|
|
32
|
+
export type TypedSduiStatePath<TState> = TypedSduiStatePathInner<TState, ''>;
|
|
33
|
+
|
|
34
|
+
/** Value type stored at one typed SDUI page-state path. */
|
|
35
|
+
export type TypedSduiStatePathValue<TState, TPath extends TypedSduiStatePath<TState>> = TPath extends (
|
|
36
|
+
`/${infer TSegments}`
|
|
37
|
+
) ?
|
|
38
|
+
TypedSduiStatePathValueInner<TState, TSegments>
|
|
39
|
+
: never;
|
|
40
|
+
|
|
41
|
+
/** Typed SDUI page-state paths whose values accept `TValue`. */
|
|
42
|
+
export type TypedSduiStatePathForValue<TState, TValue> = {
|
|
43
|
+
readonly [TPath in TypedSduiStatePath<TState>]: TValue extends TypedSduiStatePathValue<TState, TPath> ?
|
|
44
|
+
TPath
|
|
45
|
+
: never;
|
|
46
|
+
}[TypedSduiStatePath<TState>];
|
|
47
|
+
|
|
48
|
+
/** State assignments applied by common SDUI helper actions. */
|
|
49
|
+
export type TypedSduiStateAssignments<TState> = Partial<{
|
|
50
|
+
readonly [TPath in TypedSduiStatePath<TState>]: TypedSduiStatePathValue<TState, TPath>;
|
|
51
|
+
}>;
|
|
52
|
+
|
|
53
|
+
/** Returns a typed SDUI page-state path resolver that preserves literal path inference. */
|
|
54
|
+
export function resolveTypedSduiStatePath<TState>() {
|
|
55
|
+
return <TPath extends TypedSduiStatePath<TState>>(path: TPath): TPath => path;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Returns one typed SDUI page-state assignment map as-is while preserving compile-time validation. */
|
|
59
|
+
export function defineTypedSduiStateAssignments<TState>(
|
|
60
|
+
assignments: TypedSduiStateAssignments<TState>,
|
|
61
|
+
): TypedSduiStateAssignments<TState> {
|
|
62
|
+
return assignments;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Standard output body returned when a function renders one SDUI page spec. */
|
|
66
|
+
export interface TypedSduiPageSpecOutput {
|
|
67
|
+
/** JSON-serialized SDUI spec payload returned to the platform. */
|
|
68
|
+
readonly spec: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Standard error output body for SDUI page functions. */
|
|
72
|
+
export interface TypedSduiPageErrorOutput {
|
|
73
|
+
/** Human-readable error message surfaced back to the caller. */
|
|
74
|
+
readonly error: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Common output union for stateful SDUI page functions.
|
|
79
|
+
*
|
|
80
|
+
* @typeParam TStateUpdate - State payload returned for follow-up actions such as
|
|
81
|
+
* partial updates written into a `responsePath`.
|
|
82
|
+
*/
|
|
83
|
+
export type TypedSduiPageOutput<TStateUpdate> =
|
|
84
|
+
| TypedSduiPageSpecOutput
|
|
85
|
+
| TStateUpdate
|
|
86
|
+
| TypedSduiPageErrorOutput;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Serializes one rendered SDUI spec into the standard function output shape.
|
|
90
|
+
*
|
|
91
|
+
* @param spec - Rendered SDUI spec object that should be JSON-serialized.
|
|
92
|
+
* @returns Standard SDUI spec output payload.
|
|
93
|
+
*/
|
|
94
|
+
export function createTypedSduiPageSpecOutput<TSpec extends TypedSduiPageSpec>(
|
|
95
|
+
spec: TSpec,
|
|
96
|
+
): TypedSduiPageSpecOutput {
|
|
97
|
+
return { spec: JSON.stringify(spec) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Builds one successful SDUI page-function response.
|
|
102
|
+
*
|
|
103
|
+
* @param body - Response body to return to the platform.
|
|
104
|
+
* @param options - Optional response metadata such as status code, headers, or message.
|
|
105
|
+
* @returns Typed function response.
|
|
106
|
+
* @typeParam TBody - Body shape returned by the function.
|
|
107
|
+
*/
|
|
108
|
+
export function createTypedSduiPageResponse<TBody>(
|
|
109
|
+
body: TBody,
|
|
110
|
+
options: Omit<FunctionResponseOptions<TBody>, 'body'> = {},
|
|
111
|
+
): FunctionResponse<TBody> {
|
|
112
|
+
return new FunctionResponse<TBody>({
|
|
113
|
+
body,
|
|
114
|
+
statusCode: options.statusCode ?? 200,
|
|
115
|
+
headers: options.headers ?? {},
|
|
116
|
+
message: options.message ?? '',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Builds the standard SDUI page-function response for one rendered page spec.
|
|
122
|
+
*
|
|
123
|
+
* @param spec - Rendered SDUI spec object that should be JSON-serialized.
|
|
124
|
+
* @returns Typed function response containing `body.spec`.
|
|
125
|
+
* @typeParam TOutput - Output union that includes the standard spec payload.
|
|
126
|
+
*/
|
|
127
|
+
export function createTypedSduiPageSpecResponse<
|
|
128
|
+
TOutput = TypedSduiPageSpecOutput,
|
|
129
|
+
TSpec extends TypedSduiPageSpec = TypedSduiPageSpec,
|
|
130
|
+
>(spec: TSpec): FunctionResponse<TOutput> {
|
|
131
|
+
return createTypedSduiPageResponse(createTypedSduiPageSpecOutput(spec) as TOutput);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Builds a 400 SDUI page-function error response.
|
|
136
|
+
*
|
|
137
|
+
* @param message - Human-readable error message.
|
|
138
|
+
* @returns Typed function response containing the standard error payload.
|
|
139
|
+
* @typeParam TOutput - Output union that includes the standard error payload.
|
|
140
|
+
*/
|
|
141
|
+
export function createTypedSduiPageBadRequestResponse<TOutput = TypedSduiPageErrorOutput>(
|
|
142
|
+
message: string,
|
|
143
|
+
): FunctionResponse<TOutput> {
|
|
144
|
+
return createTypedSduiPageResponse({ error: message } as TOutput, {
|
|
145
|
+
statusCode: 400,
|
|
146
|
+
message,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Builds a 500 SDUI page-function error response from one thrown value.
|
|
152
|
+
*
|
|
153
|
+
* @param error - Unknown thrown value that should be normalized to a message.
|
|
154
|
+
* @returns Typed function response containing the standard error payload.
|
|
155
|
+
* @typeParam TOutput - Output union that includes the standard error payload.
|
|
156
|
+
*/
|
|
157
|
+
export function createTypedSduiPageServerErrorResponse<TOutput = TypedSduiPageErrorOutput>(
|
|
158
|
+
error: unknown,
|
|
159
|
+
): FunctionResponse<TOutput> {
|
|
160
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
161
|
+
return createTypedSduiPageResponse({ error: message } as TOutput, {
|
|
162
|
+
statusCode: 500,
|
|
163
|
+
message,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
type TypedSduiPageEvent<TParameters extends { action: string }> = Omit<
|
|
168
|
+
SduiPageFunctionEvent,
|
|
169
|
+
'parameters'
|
|
170
|
+
> & {
|
|
171
|
+
readonly parameters: TParameters;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export type TypedSduiPageActionName<TParameters extends { action: string }> = TParameters['action'];
|
|
175
|
+
|
|
176
|
+
export type TypedSduiPageActionParams<
|
|
177
|
+
TParameters extends { action: string },
|
|
178
|
+
TAction extends TypedSduiPageActionName<TParameters>,
|
|
179
|
+
> = Extract<TParameters, { action: TAction }>;
|
|
180
|
+
|
|
181
|
+
type TypedSduiPageRoleId<TRequireRoleId extends boolean | undefined> =
|
|
182
|
+
TRequireRoleId extends true ? string : string | undefined;
|
|
183
|
+
|
|
184
|
+
type TypedSduiPageSpec = object;
|
|
185
|
+
|
|
186
|
+
type DefaultInitAction<TParameters extends { action: string }> =
|
|
187
|
+
Extract<TypedSduiPageActionName<TParameters>, 'init'> extends never ? TypedSduiPageActionName<TParameters>
|
|
188
|
+
: Extract<TypedSduiPageActionName<TParameters>, 'init'>;
|
|
189
|
+
|
|
190
|
+
type TypedSduiNonInitActionName<
|
|
191
|
+
TParameters extends { action: string },
|
|
192
|
+
TInitAction extends TypedSduiPageActionName<TParameters>,
|
|
193
|
+
> = Exclude<TypedSduiPageActionName<TParameters>, TInitAction>;
|
|
194
|
+
|
|
195
|
+
type TypedSduiActionHandlerMap<
|
|
196
|
+
TParameters extends { action: string },
|
|
197
|
+
TRuntime,
|
|
198
|
+
TStateUpdate,
|
|
199
|
+
TInitAction extends TypedSduiPageActionName<TParameters>,
|
|
200
|
+
TRequireRoleId extends boolean | undefined,
|
|
201
|
+
> = {
|
|
202
|
+
readonly [TAction in TypedSduiNonInitActionName<TParameters, TInitAction>]: (
|
|
203
|
+
args: TypedSduiPageHandlerArgs<TParameters, TRuntime, TAction, TRequireRoleId>,
|
|
204
|
+
) => TStateUpdate | Promise<TStateUpdate>;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/** Shared arguments passed to typed SDUI page handler callbacks. */
|
|
208
|
+
export interface TypedSduiPageHandlerArgs<
|
|
209
|
+
TParameters extends { action: string },
|
|
210
|
+
TRuntime,
|
|
211
|
+
TAction extends TypedSduiPageActionName<TParameters>,
|
|
212
|
+
TRequireRoleId extends boolean | undefined = false,
|
|
213
|
+
> {
|
|
214
|
+
/** Raw SDUI page event supplied by the platform. */
|
|
215
|
+
readonly event: TypedSduiPageEvent<TParameters>;
|
|
216
|
+
/** Function context supplied by the platform. */
|
|
217
|
+
readonly context: FunctionContext;
|
|
218
|
+
/** Action-specific parameter payload narrowed by the selected action string. */
|
|
219
|
+
readonly params: TypedSduiPageActionParams<TParameters, TAction>;
|
|
220
|
+
/** Per-request runtime created once for this handler invocation. */
|
|
221
|
+
readonly runtime: TRuntime;
|
|
222
|
+
/** Current function role id when present. */
|
|
223
|
+
readonly roleId: TypedSduiPageRoleId<TRequireRoleId>;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Initialization properties for {@link defineTypedSduiPageHandler}.
|
|
228
|
+
*
|
|
229
|
+
* @typeParam TParameters - SDUI page parameter union discriminated by `action`.
|
|
230
|
+
* @typeParam TRuntime - Shared runtime created once per invocation.
|
|
231
|
+
* @typeParam TStateUpdate - State payload returned for follow-up actions.
|
|
232
|
+
* @typeParam TInitAction - Action string that renders the initial SDUI spec.
|
|
233
|
+
* @typeParam TRequireRoleId - Whether callback args should require `roleId`.
|
|
234
|
+
*/
|
|
235
|
+
type TypedSduiPageHandlerOptionsBase<
|
|
236
|
+
TParameters extends { action: string },
|
|
237
|
+
TRuntime,
|
|
238
|
+
TStateUpdate,
|
|
239
|
+
TInitAction extends TypedSduiPageActionName<TParameters>,
|
|
240
|
+
TRequireRoleId extends boolean | undefined,
|
|
241
|
+
> = {
|
|
242
|
+
/** Whether the handler should reject requests without `context.function.role_id`. */
|
|
243
|
+
readonly requireRoleId?: TRequireRoleId;
|
|
244
|
+
/** Error message used when `requireRoleId` is true but no role id is present. */
|
|
245
|
+
readonly missingRoleIdMessage?: string;
|
|
246
|
+
/** Creates one shared runtime object for this invocation. */
|
|
247
|
+
readonly createRuntime: (context: FunctionContext) => TRuntime | Promise<TRuntime>;
|
|
248
|
+
/** Renders the initial SDUI page spec for the selected init action. */
|
|
249
|
+
readonly init: (
|
|
250
|
+
args: TypedSduiPageHandlerArgs<TParameters, TRuntime, TInitAction, TRequireRoleId>,
|
|
251
|
+
) => TypedSduiPageSpec | Promise<TypedSduiPageSpec>;
|
|
252
|
+
/** Returns one state update payload for each non-init action. */
|
|
253
|
+
readonly actions: TypedSduiActionHandlerMap<
|
|
254
|
+
TParameters,
|
|
255
|
+
TRuntime,
|
|
256
|
+
TStateUpdate,
|
|
257
|
+
TInitAction,
|
|
258
|
+
TRequireRoleId
|
|
259
|
+
>;
|
|
260
|
+
/** Optional formatter for the unknown-action bad-request message. */
|
|
261
|
+
readonly unknownActionMessage?: (action: string) => string;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export type TypedSduiPageHandlerOptions<
|
|
265
|
+
TParameters extends { action: string },
|
|
266
|
+
TRuntime,
|
|
267
|
+
TStateUpdate = never,
|
|
268
|
+
TInitAction extends TypedSduiPageActionName<TParameters> = DefaultInitAction<TParameters>,
|
|
269
|
+
TRequireRoleId extends boolean | undefined = false,
|
|
270
|
+
> = TypedSduiPageHandlerOptionsBase<TParameters, TRuntime, TStateUpdate, TInitAction, TRequireRoleId> &
|
|
271
|
+
(Extract<TypedSduiPageActionName<TParameters>, 'init'> extends never ?
|
|
272
|
+
/** Action string treated as the initial SDUI render request when no literal `init` action exists. */
|
|
273
|
+
{ readonly initAction: TInitAction }
|
|
274
|
+
: /** Optional action string treated as the initial SDUI render request. Defaults to `'init'` when present. */
|
|
275
|
+
{ readonly initAction?: TInitAction });
|
|
276
|
+
|
|
277
|
+
function hasOwnActionHandler<
|
|
278
|
+
TParameters extends { action: string },
|
|
279
|
+
TRuntime,
|
|
280
|
+
TStateUpdate,
|
|
281
|
+
TInitAction extends TypedSduiPageActionName<TParameters>,
|
|
282
|
+
TRequireRoleId extends boolean | undefined,
|
|
283
|
+
>(
|
|
284
|
+
actions: TypedSduiActionHandlerMap<TParameters, TRuntime, TStateUpdate, TInitAction, TRequireRoleId>,
|
|
285
|
+
action: string,
|
|
286
|
+
): action is TypedSduiNonInitActionName<TParameters, TInitAction> {
|
|
287
|
+
return Object.prototype.hasOwnProperty.call(actions, action);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
type TypedSduiPageHandler<TParameters extends { action: string }, TStateUpdate> = (
|
|
291
|
+
event: TypedSduiPageEvent<TParameters>,
|
|
292
|
+
context: FunctionContext,
|
|
293
|
+
) => Promise<FunctionResponse<TypedSduiPageOutput<TStateUpdate>>>;
|
|
294
|
+
|
|
295
|
+
function buildTypedSduiPageHandler<
|
|
296
|
+
TParameters extends { action: string },
|
|
297
|
+
TRuntime,
|
|
298
|
+
TStateUpdate = never,
|
|
299
|
+
TInitAction extends TypedSduiPageActionName<TParameters> = DefaultInitAction<TParameters>,
|
|
300
|
+
TRequireRoleId extends boolean | undefined = false,
|
|
301
|
+
>(
|
|
302
|
+
options: TypedSduiPageHandlerOptions<TParameters, TRuntime, TStateUpdate, TInitAction, TRequireRoleId>,
|
|
303
|
+
): TypedSduiPageHandler<TParameters, TStateUpdate> {
|
|
304
|
+
const initAction = (options.initAction ?? 'init') as TInitAction;
|
|
305
|
+
|
|
306
|
+
return async (
|
|
307
|
+
event: TypedSduiPageEvent<TParameters>,
|
|
308
|
+
context: FunctionContext,
|
|
309
|
+
): Promise<FunctionResponse<TypedSduiPageOutput<TStateUpdate>>> => {
|
|
310
|
+
const roleId = context.function.role_id;
|
|
311
|
+
if (options.requireRoleId === true && !roleId) {
|
|
312
|
+
return createTypedSduiPageBadRequestResponse<TypedSduiPageOutput<TStateUpdate>>(
|
|
313
|
+
options.missingRoleIdMessage ?? 'Role ID is required',
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
try {
|
|
318
|
+
const runtime = await options.createRuntime(context);
|
|
319
|
+
const action = String(event.parameters.action);
|
|
320
|
+
|
|
321
|
+
if (action === initAction) {
|
|
322
|
+
const spec = await options.init({
|
|
323
|
+
event,
|
|
324
|
+
context,
|
|
325
|
+
params: event.parameters as TypedSduiPageActionParams<TParameters, TInitAction>,
|
|
326
|
+
runtime,
|
|
327
|
+
roleId: roleId as TypedSduiPageRoleId<TRequireRoleId>,
|
|
328
|
+
});
|
|
329
|
+
return createTypedSduiPageSpecResponse<TypedSduiPageOutput<TStateUpdate>>(spec);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (!hasOwnActionHandler(options.actions, action)) {
|
|
333
|
+
return createTypedSduiPageBadRequestResponse<TypedSduiPageOutput<TStateUpdate>>(
|
|
334
|
+
options.unknownActionMessage?.(action) ?? `Unknown action: ${action}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const stateUpdate = await options.actions[action]({
|
|
339
|
+
event,
|
|
340
|
+
context,
|
|
341
|
+
params: event.parameters as TypedSduiPageActionParams<TParameters, typeof action>,
|
|
342
|
+
runtime,
|
|
343
|
+
roleId: roleId as TypedSduiPageRoleId<TRequireRoleId>,
|
|
344
|
+
});
|
|
345
|
+
return createTypedSduiPageResponse<TypedSduiPageOutput<TStateUpdate>>(stateUpdate);
|
|
346
|
+
} catch (error) {
|
|
347
|
+
return createTypedSduiPageServerErrorResponse<TypedSduiPageOutput<TStateUpdate>>(error);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function defineTypedSduiPageHandler<
|
|
353
|
+
TParameters extends { action: string },
|
|
354
|
+
TRuntime,
|
|
355
|
+
TStateUpdate = never,
|
|
356
|
+
TInitAction extends TypedSduiPageActionName<TParameters> = DefaultInitAction<TParameters>,
|
|
357
|
+
>(
|
|
358
|
+
options: TypedSduiPageHandlerOptions<TParameters, TRuntime, TStateUpdate, TInitAction, true>,
|
|
359
|
+
): TypedSduiPageHandler<TParameters, TStateUpdate>;
|
|
360
|
+
|
|
361
|
+
export function defineTypedSduiPageHandler<
|
|
362
|
+
TParameters extends { action: string },
|
|
363
|
+
TRuntime,
|
|
364
|
+
TStateUpdate = never,
|
|
365
|
+
TInitAction extends TypedSduiPageActionName<TParameters> = DefaultInitAction<TParameters>,
|
|
366
|
+
TRequireRoleId extends boolean | undefined = false,
|
|
367
|
+
>(
|
|
368
|
+
options: TypedSduiPageHandlerOptions<TParameters, TRuntime, TStateUpdate, TInitAction, TRequireRoleId>,
|
|
369
|
+
): TypedSduiPageHandler<TParameters, TStateUpdate>;
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Defines one typed SDUI page handler with a shared runtime, one init action,
|
|
373
|
+
* and a typed action-dispatch table for follow-up state updates.
|
|
374
|
+
*
|
|
375
|
+
* The returned handler still accepts the normal `(event, context)` signature, so
|
|
376
|
+
* callers can keep an exported `onRipplingEvent(...)` function declaration that
|
|
377
|
+
* backend IO-contract derivation understands while removing the repetitive
|
|
378
|
+
* action-routing / response-wrapping boilerplate from the function body.
|
|
379
|
+
*
|
|
380
|
+
* @param options - Handler configuration including init renderer, runtime factory, and action dispatch table.
|
|
381
|
+
* @returns Handler function that returns typed SDUI spec / state / error responses.
|
|
382
|
+
* @typeParam TParameters - SDUI page parameter union discriminated by `action`.
|
|
383
|
+
* @typeParam TRuntime - Shared runtime created once per invocation.
|
|
384
|
+
* @typeParam TStateUpdate - State payload returned for follow-up actions.
|
|
385
|
+
* @typeParam TInitAction - Action string that renders the initial SDUI spec.
|
|
386
|
+
* @typeParam TRequireRoleId - Whether callback args should require `roleId`.
|
|
387
|
+
*/
|
|
388
|
+
export function defineTypedSduiPageHandler<
|
|
389
|
+
TParameters extends { action: string },
|
|
390
|
+
TRuntime,
|
|
391
|
+
TStateUpdate = never,
|
|
392
|
+
TInitAction extends TypedSduiPageActionName<TParameters> = DefaultInitAction<TParameters>,
|
|
393
|
+
TRequireRoleId extends boolean | undefined = false,
|
|
394
|
+
>(
|
|
395
|
+
options: TypedSduiPageHandlerOptions<TParameters, TRuntime, TStateUpdate, TInitAction, TRequireRoleId>,
|
|
396
|
+
): TypedSduiPageHandler<TParameters, TStateUpdate> {
|
|
397
|
+
return buildTypedSduiPageHandler(options);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Creates one parameter-first SDUI page-handler builder that fixes the action
|
|
402
|
+
* union and state-update payload up front, then infers the shared runtime type
|
|
403
|
+
* from `createRuntime(...)` when the returned builder is called.
|
|
404
|
+
*
|
|
405
|
+
* This is the intended golden path for normal page-function authoring: specify
|
|
406
|
+
* the discriminated input union and returned state payload once, then let the
|
|
407
|
+
* runtime object and `requireRoleId` behavior infer from the provided options.
|
|
408
|
+
*
|
|
409
|
+
* @returns Builder that accepts typed SDUI page-handler options.
|
|
410
|
+
* @typeParam TParameters - SDUI page parameter union discriminated by `action`.
|
|
411
|
+
* @typeParam TStateUpdate - State payload returned for follow-up actions.
|
|
412
|
+
*/
|
|
413
|
+
export function defineTypedSduiPageHandlerFor<
|
|
414
|
+
TParameters extends { action: string },
|
|
415
|
+
TStateUpdate = never,
|
|
416
|
+
>(): <
|
|
417
|
+
TRuntime,
|
|
418
|
+
TInitAction extends TypedSduiPageActionName<TParameters> = DefaultInitAction<TParameters>,
|
|
419
|
+
TRequireRoleId extends boolean | undefined = false,
|
|
420
|
+
>(
|
|
421
|
+
options: TypedSduiPageHandlerOptions<TParameters, TRuntime, TStateUpdate, TInitAction, TRequireRoleId>,
|
|
422
|
+
) => TypedSduiPageHandler<TParameters, TStateUpdate> {
|
|
423
|
+
return <
|
|
424
|
+
TRuntime,
|
|
425
|
+
TInitAction extends TypedSduiPageActionName<TParameters> = DefaultInitAction<TParameters>,
|
|
426
|
+
TRequireRoleId extends boolean | undefined = false,
|
|
427
|
+
>(
|
|
428
|
+
options: TypedSduiPageHandlerOptions<TParameters, TRuntime, TStateUpdate, TInitAction, TRequireRoleId>,
|
|
429
|
+
): TypedSduiPageHandler<TParameters, TStateUpdate> => buildTypedSduiPageHandler(options);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Configuration for the standard "set loading state, trigger function, write
|
|
434
|
+
* responsePath, then clear loading / error state" SDUI interaction pattern.
|
|
435
|
+
*
|
|
436
|
+
* @typeParam TState - SDUI page-state shape that owns the referenced state paths.
|
|
437
|
+
* @typeParam TResponse - Response payload written into `responsePath`.
|
|
438
|
+
* @typeParam TInputs - Server-bound function input payload sent through `triggerFunction(...)`.
|
|
439
|
+
*/
|
|
440
|
+
export interface TypedSduiMutationTriggerOptions<TState, TResponse, TInputs extends { action: string }> {
|
|
441
|
+
/** Target function id that should handle the mutation. */
|
|
442
|
+
readonly functionId: string;
|
|
443
|
+
/** Server-bound input payload forwarded to the function. */
|
|
444
|
+
readonly inputs: TInputs;
|
|
445
|
+
/** State path that should receive the function response body. */
|
|
446
|
+
readonly responsePath: TypedSduiStatePathForValue<TState, TResponse>;
|
|
447
|
+
/** Human-readable error message shown when the function call fails. */
|
|
448
|
+
readonly errorMessage: string;
|
|
449
|
+
/** Optional state assignments applied after a successful mutation. */
|
|
450
|
+
readonly onSuccessState?: TypedSduiStateAssignments<TState>;
|
|
451
|
+
/** Optional state assignments applied after a failed mutation. */
|
|
452
|
+
readonly onErrorState?: TypedSduiStateAssignments<TState>;
|
|
453
|
+
/** State path that stores the shared in-flight mutation flag. Defaults to `/isMutating`. */
|
|
454
|
+
readonly mutationStatePath?: TypedSduiStatePathForValue<TState, boolean>;
|
|
455
|
+
/** State path that stores the visible error message. Defaults to `/errorMessage`. */
|
|
456
|
+
readonly errorStatePath?: TypedSduiStatePathForValue<TState, string>;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Builds the common SDUI mutation action sequence used by stateful page
|
|
461
|
+
* functions: set a shared mutation flag, call the function, write the response
|
|
462
|
+
* into one `responsePath`, then clear the mutation/error state.
|
|
463
|
+
*
|
|
464
|
+
* Pebble's generated `triggerFunction(...)` params are currently too weakly
|
|
465
|
+
* typed for nested `inputs` expression objects, so this helper builds the same
|
|
466
|
+
* action binding through the lower-level action factory while keeping a fully
|
|
467
|
+
* typed public surface here.
|
|
468
|
+
*
|
|
469
|
+
* @param options - Trigger configuration for one mutation action.
|
|
470
|
+
* @returns Two-action sequence: optimistic mutation-state update plus function trigger.
|
|
471
|
+
* @typeParam TState - SDUI page-state shape that owns the referenced state paths.
|
|
472
|
+
* @typeParam TResponse - Response payload written into `responsePath`.
|
|
473
|
+
* @typeParam TInputs - Server-bound function input payload sent through the trigger action.
|
|
474
|
+
*/
|
|
475
|
+
type TypedSduiTriggerFunctionParams<TInputs extends { action: string }> = {
|
|
476
|
+
readonly functionId: string;
|
|
477
|
+
readonly inputs: TInputs;
|
|
478
|
+
readonly responsePath: string;
|
|
479
|
+
} & Record<string, string | TInputs>;
|
|
480
|
+
|
|
481
|
+
export function createTypedSduiMutationTrigger<TState, TResponse, TInputs extends { action: string }>(
|
|
482
|
+
options: TypedSduiMutationTriggerOptions<TState, TResponse, TInputs>,
|
|
483
|
+
): ActionBinding[] {
|
|
484
|
+
const mutationStatePath = options.mutationStatePath ?? '/isMutating';
|
|
485
|
+
const errorStatePath = options.errorStatePath ?? '/errorMessage';
|
|
486
|
+
const triggerParams: TypedSduiTriggerFunctionParams<TInputs> = {
|
|
487
|
+
functionId: options.functionId,
|
|
488
|
+
inputs: options.inputs,
|
|
489
|
+
responsePath: options.responsePath,
|
|
490
|
+
};
|
|
491
|
+
const triggerOptions: ActionOptions = {
|
|
492
|
+
onSuccess: {
|
|
493
|
+
set: {
|
|
494
|
+
[errorStatePath]: '',
|
|
495
|
+
[mutationStatePath]: false,
|
|
496
|
+
...(options.onSuccessState ?? {}),
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
onError: {
|
|
500
|
+
set: {
|
|
501
|
+
[errorStatePath]: options.errorMessage,
|
|
502
|
+
[mutationStatePath]: false,
|
|
503
|
+
...(options.onErrorState ?? {}),
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
return [
|
|
509
|
+
setState({
|
|
510
|
+
statePath: mutationStatePath,
|
|
511
|
+
value: true,
|
|
512
|
+
}),
|
|
513
|
+
buildAction('triggerFunction', triggerParams, triggerOptions),
|
|
514
|
+
];
|
|
515
|
+
}
|