@phis/ui 0.7.4 → 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/components/controls/phi-form-control.d.ts +3 -1
  2. package/components/controls/phi-form-control.js +5 -4
  3. package/components/controls/phi-options-provider.d.ts +14 -1
  4. package/components/controls/phi-options-provider.js +73 -2
  5. package/components/forms/auth-admin-settings-labels.d.ts +1 -1
  6. package/components/forms/auth-admin-settings-labels.js +2 -2
  7. package/components/forms/form-descriptor-contract.d.ts +1 -1
  8. package/components/forms/form-descriptor-contract.js +1 -1
  9. package/components/forms/form-descriptor-runtime-client.d.ts +4 -1
  10. package/components/forms/form-descriptor-runtime-client.js +33 -11
  11. package/components/forms/form-media-limits.d.ts +12 -0
  12. package/components/forms/form-media-limits.js +14 -0
  13. package/components/forms/form-provider-registry.d.ts +8 -0
  14. package/components/forms/form-record-title.d.ts +14 -0
  15. package/components/forms/form-record-title.js +38 -0
  16. package/components/forms/form-widget-config.d.ts +3 -0
  17. package/components/forms/form-widget-config.js +2 -0
  18. package/components/forms/phi-form-widget.d.ts +1 -1
  19. package/components/forms/phi-form-widget.js +4 -0
  20. package/components/overlays/phi-overlay-container-client.js +8 -8
  21. package/components/overlays/phi-overlay-title.d.ts +7 -0
  22. package/components/overlays/phi-overlay-title.js +21 -0
  23. package/components/tables/client/phi-table-binding.d.ts +3 -1
  24. package/components/tables/client/phi-table-binding.js +90 -49
  25. package/components/tables/client/phi-table-filter-options.d.ts +27 -0
  26. package/components/tables/client/phi-table-filter-options.js +35 -0
  27. package/components/widgets/accessible-areas.d.ts +1 -1
  28. package/components/widgets/accessible-areas.js +1 -1
  29. package/components/widgets/client/shared/phi-choice-controller.js +22 -15
  30. package/components/widgets/client/shared/phi-rendered-value.d.ts +10 -0
  31. package/components/widgets/client/shared/phi-rendered-value.js +49 -1
  32. package/components/widgets/client/shared/phi-table-provider.d.ts +10 -1
  33. package/components/widgets/client/shared/phi-table-provider.js +22 -0
  34. package/components/widgets/label-sets/admin-users.d.ts +15 -0
  35. package/components/widgets/label-sets/admin-users.js +31 -0
  36. package/constants/core-data-provider-keys.d.ts +7 -0
  37. package/constants/core-data-provider-keys.js +7 -0
  38. package/constants/phi-base-role-metadata.d.ts +2 -2
  39. package/constants/phi-base-role-metadata.js +1 -1
  40. package/constants/runtime-module-ownership.js +3 -0
  41. package/forms.d.ts +1 -1
  42. package/forms.js +1 -1
  43. package/gateway/capability-media-limits.d.ts +10 -0
  44. package/gateway/capability-media-limits.js +40 -0
  45. package/gateway/server-capabilities.js +4 -0
  46. package/helpers/preset-tree-contract-check.d.ts +3 -2
  47. package/helpers/preset-tree-contract-check.js +60 -0
  48. package/helpers/record-title.d.ts +7 -0
  49. package/helpers/record-title.js +25 -0
  50. package/helpers/record-widget.d.ts +15 -0
  51. package/helpers/record-widget.js +57 -0
  52. package/package.json +2 -2
  53. package/plugins/runtime-modules/accounting/client-data-providers.d.ts +7 -0
  54. package/plugins/runtime-modules/accounting/client-data-providers.js +9 -0
  55. package/plugins/runtime-modules/accounting/data-providers.d.ts +63 -0
  56. package/plugins/runtime-modules/accounting/data-providers.js +127 -0
  57. package/plugins/runtime-modules/accounting/definition.d.ts +54 -2
  58. package/plugins/runtime-modules/accounting/definition.js +5 -3
  59. package/plugins/runtime-modules/accounting/ids.d.ts +20 -0
  60. package/plugins/runtime-modules/accounting/ids.js +27 -0
  61. package/plugins/runtime-modules/accounting/module.d.ts +52 -0
  62. package/plugins/runtime-modules/accounting/presets.js +23 -4
  63. package/plugins/runtime-modules/accounting/services/products-table.d.ts +93 -0
  64. package/plugins/runtime-modules/accounting/services/products-table.js +158 -0
  65. package/plugins/runtime-modules/accounting/trees/accounting-products-label-set.d.ts +86 -0
  66. package/plugins/runtime-modules/accounting/trees/accounting-products-label-set.js +123 -0
  67. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-products-page-tree.d.ts +21 -0
  68. package/plugins/runtime-modules/accounting/trees/phi-default-accounting-products-page-tree.js +435 -0
  69. package/plugins/runtime-modules/area-definitions.js +2 -2
  70. package/plugins/runtime-modules/asset/media-asset-field.d.ts +15 -0
  71. package/plugins/runtime-modules/asset/media-asset-field.js +21 -0
  72. package/plugins/runtime-modules/asset/media-asset-form-control.d.ts +4 -0
  73. package/plugins/runtime-modules/asset/media-asset-form-control.js +10 -5
  74. package/plugins/runtime-modules/asset/media-assets-field.d.ts +8 -0
  75. package/plugins/runtime-modules/asset/media-assets-field.js +10 -0
  76. package/plugins/runtime-modules/asset/media-assets-form-control.d.ts +5 -0
  77. package/plugins/runtime-modules/asset/media-assets-form-control.js +15 -6
  78. package/plugins/runtime-modules/auth/admin-settings-forms.js +1 -1
  79. package/plugins/runtime-modules/builder/clients/inspector-config-field.js +11 -6
  80. package/plugins/runtime-modules/client-manifests/accounting.js +5 -1
  81. package/plugins/runtime-modules/core/cards.js +2 -2
  82. package/plugins/runtime-modules/core/client-data-providers.js +5 -0
  83. package/plugins/runtime-modules/core/data-providers.js +14 -0
  84. package/plugins/runtime-modules/core/services/site-members-options.d.ts +27 -0
  85. package/plugins/runtime-modules/core/services/site-members-options.js +55 -0
  86. package/plugins/runtime-modules/core/widgets/cascader/client.js +13 -12
  87. package/plugins/runtime-modules/core/widgets/checkbox-group/client.js +5 -4
  88. package/plugins/runtime-modules/core/widgets/form/config.d.ts +5 -0
  89. package/plugins/runtime-modules/core/widgets/form/config.js +3 -0
  90. package/plugins/runtime-modules/core/widgets/multi-select/client.js +6 -4
  91. package/plugins/runtime-modules/core/widgets/record/actions.d.ts +20 -0
  92. package/plugins/runtime-modules/core/widgets/record/actions.js +77 -0
  93. package/plugins/runtime-modules/core/widgets/record/client.js +71 -8
  94. package/plugins/runtime-modules/core/widgets/record/config.d.ts +66 -1
  95. package/plugins/runtime-modules/core/widgets/record/config.js +71 -2
  96. package/plugins/runtime-modules/core/widgets/table/client.js +33 -29
  97. package/plugins/runtime-modules/core/widgets/table/config.js +5 -1
  98. package/plugins/runtime-modules/groups/data-providers.js +1 -1
  99. package/plugins/runtime-modules/groups/definition.js +1 -1
  100. package/plugins/runtime-modules/groups/page-visibility.d.ts +1 -1
  101. package/plugins/runtime-modules/groups/page-visibility.js +1 -1
  102. package/plugins/runtime-modules/groups/presets.js +1 -1
  103. package/plugins/runtime-modules/groups/services/options.js +1 -1
  104. package/plugins/runtime-modules/groups/services/table.js +1 -1
  105. package/plugins/runtime-modules/groups/trees/phi-default-app-groups-page-tree.js +2 -2
  106. package/plugins/runtime-modules/user-management/addon-roles.d.ts +60 -4
  107. package/plugins/runtime-modules/user-management/addon-roles.js +92 -8
  108. package/plugins/runtime-modules/user-management/addresses.d.ts +1 -1
  109. package/plugins/runtime-modules/user-management/controller/client.js +1 -1
  110. package/plugins/runtime-modules/user-management/data-providers.js +1 -0
  111. package/plugins/runtime-modules/user-management/forms.js +22 -0
  112. package/plugins/runtime-modules/user-management/presets.js +2 -2
  113. package/plugins/runtime-modules/user-management/services/options.d.ts +4 -0
  114. package/plugins/runtime-modules/user-management/services/options.js +14 -6
  115. package/plugins/runtime-modules/user-management/services/table.js +12 -3
  116. package/plugins/runtime-modules/user-management/trees/phi-default-admin-users-page-tree.js +9 -4
  117. package/types/access.d.ts +1 -1
  118. package/types/access.js +7 -7
  119. package/types/core-widget-placements.d.ts +7 -0
  120. package/types/form-descriptor.d.ts +1 -1
  121. package/types/record-widget.d.ts +35 -0
  122. package/types/server-capabilities.d.ts +1 -1
  123. package/types/table-widget.d.ts +20 -0
  124. package/types/table-widget.js +44 -0
@@ -0,0 +1,127 @@
1
+ import { PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY, PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY, PHI_ACCOUNTING_RUNTIME_MODULE_ID, } from "./ids";
2
+ const SALE_OPTIONS = [
3
+ { value: "own", label: "Own" },
4
+ { value: "referral", label: "Referral" },
5
+ { value: "payout", label: "Payout" },
6
+ ];
7
+ /**
8
+ * The terms the operator releases (`PhisProductReleasedTerms`), once as they are in force and once as
9
+ * they wait for the release, so a record can set the two side by side. A publisher's product never
10
+ * released has nothing in force yet; the Site's own has nothing waiting.
11
+ */
12
+ function termFields(prefix, title) {
13
+ return [
14
+ { key: `${prefix}Sale`, title: `Sale (${title})`, type: "enum", options: SALE_OPTIONS },
15
+ { key: `${prefix}ReferralUrl`, title: `Referral address (${title})`, type: "string" },
16
+ { key: `${prefix}Free`, title: `Free (${title})`, type: "boolean" },
17
+ { key: `${prefix}AccountRequired`, title: `Account required (${title})`, type: "boolean" },
18
+ { key: `${prefix}Parts`, title: `Bundle parts (${title})`, type: "json" },
19
+ ];
20
+ }
21
+ /**
22
+ * The Site's product directory (phis-server SERVER_ADDONS.md, `products:v1`), as the operator
23
+ * administers it: every product of every supplier Add-on, in every state.
24
+ *
25
+ * `live` and `authoringMode: "none"`: the Builder has no business reading a Site's products while somebody
26
+ * composes a Page. The rows come from `GET /api/site/products` and the three acts go to
27
+ * `POST /api/site/products/{id}/release|lock|unlock`, behind Core's Accounting guard; Core refuses them to
28
+ * anybody else whatever a Table offers. Nothing a supplier says of its product -- title, summary, picture
29
+ * -- is edited here: that stays the supplier's.
30
+ */
31
+ export const PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS = [
32
+ {
33
+ key: PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY,
34
+ ownerModuleId: PHI_ACCOUNTING_RUNTIME_MODULE_ID,
35
+ kind: "table",
36
+ executionMode: "live",
37
+ authoringMode: "none",
38
+ title: "Products",
39
+ description: "The Site's product directory: every supplier's products, their terms and their state.",
40
+ resources: [
41
+ {
42
+ resourceKey: PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY,
43
+ title: "Products",
44
+ rowIdentityPath: "id",
45
+ fields: [
46
+ { key: "id", title: "ID", type: "string", required: true },
47
+ { key: "title", title: "Title", type: "string" },
48
+ { key: "summary", title: "Summary", type: "string" },
49
+ { key: "supplier", title: "Supplier", type: "string" },
50
+ { key: "publisher", title: "Publisher", type: "string" },
51
+ { key: "type", title: "Kind", type: "string" },
52
+ {
53
+ key: "state",
54
+ title: "State",
55
+ type: "enum",
56
+ options: [
57
+ { value: "draft", label: "Draft" },
58
+ { value: "active", label: "Active" },
59
+ { value: "withdrawn", label: "Withdrawn" },
60
+ { value: "locked", label: "Locked" },
61
+ ],
62
+ },
63
+ // The state as a mark, for the two acts that each apply to one side of it.
64
+ { key: "locked", title: "Locked", type: "boolean" },
65
+ { key: "sale", title: "Sale", type: "enum", options: SALE_OPTIONS },
66
+ { key: "referralUrl", title: "Referral address", type: "string" },
67
+ { key: "free", title: "Free", type: "boolean" },
68
+ { key: "accountRequired", title: "Account required", type: "boolean" },
69
+ { key: "counted", title: "Counted", type: "boolean" },
70
+ { key: "parts", title: "Bundle parts", type: "json" },
71
+ { key: "partCount", title: "Bundle parts", type: "number" },
72
+ { key: "released", title: "Released", type: "boolean" },
73
+ // Never released, or released with terms pending: what the release acts on.
74
+ { key: "awaitingRelease", title: "Terms waiting for release", type: "boolean" },
75
+ ...termFields("inForce", "in force"),
76
+ ...termFields("pending", "waiting for release"),
77
+ { key: "imagePath", title: "Picture", type: "string" },
78
+ { key: "iconPath", title: "Icon", type: "string" },
79
+ // The same two as the server's small `icon` variant, ready for a line of the list.
80
+ { key: "imageListPath", title: "Picture (list)", type: "string" },
81
+ { key: "iconListPath", title: "Icon (list)", type: "string" },
82
+ { key: "version", title: "Version", type: "number" },
83
+ ],
84
+ query: {
85
+ search: true,
86
+ filterFields: ["supplier", "state", "pendingTerms"],
87
+ sorting: "none",
88
+ pagination: "offset",
89
+ total: true,
90
+ },
91
+ recordRead: true,
92
+ actions: [
93
+ {
94
+ key: "release",
95
+ title: "Release terms",
96
+ scope: "row",
97
+ intent: "write",
98
+ confirmation: "required",
99
+ disabledWhen: { match: "any", conditions: [
100
+ { source: "row", valuePath: "awaitingRelease", operator: "falsy" },
101
+ ] },
102
+ },
103
+ {
104
+ key: "lock",
105
+ title: "Lock",
106
+ scope: "row",
107
+ intent: "destructive",
108
+ confirmation: "required",
109
+ disabledWhen: { match: "any", conditions: [
110
+ { source: "row", valuePath: "locked", operator: "truthy" },
111
+ ] },
112
+ },
113
+ {
114
+ key: "unlock",
115
+ title: "Unlock",
116
+ scope: "row",
117
+ intent: "write",
118
+ confirmation: "required",
119
+ disabledWhen: { match: "any", conditions: [
120
+ { source: "row", valuePath: "locked", operator: "falsy" },
121
+ ] },
122
+ },
123
+ ],
124
+ },
125
+ ],
126
+ },
127
+ ];
@@ -1,10 +1,62 @@
1
1
  export declare const PHI_ACCOUNTING_RUNTIME_MODULE_DEFINITION: Omit<{
2
- area: "accounting";
3
- moduleId: "@phis/ui/modules/accounting";
4
2
  serverBinding: import("../../../types").PhiRuntimeModuleServerBinding;
5
3
  description: string;
6
4
  category: "foundation";
7
5
  icon: string;
6
+ dataProviders: {
7
+ key: `${string}/${string}`;
8
+ ownerModuleId: "@phis/ui/modules/accounting";
9
+ kind: "table";
10
+ executionMode: "live";
11
+ authoringMode: "none";
12
+ title: string;
13
+ description: string;
14
+ resources: {
15
+ resourceKey: string;
16
+ title: string;
17
+ rowIdentityPath: string;
18
+ fields: import("../../../types").PhiTableProviderFieldDefinition[];
19
+ query: {
20
+ search: true;
21
+ filterFields: string[];
22
+ sorting: "none";
23
+ pagination: "offset";
24
+ total: true;
25
+ };
26
+ recordRead: true;
27
+ actions: ({
28
+ key: string;
29
+ title: string;
30
+ scope: "row";
31
+ intent: "write";
32
+ confirmation: "required";
33
+ disabledWhen: {
34
+ match: "any";
35
+ conditions: {
36
+ source: "row";
37
+ valuePath: string;
38
+ operator: "falsy";
39
+ }[];
40
+ };
41
+ } | {
42
+ key: string;
43
+ title: string;
44
+ scope: "row";
45
+ intent: "destructive";
46
+ confirmation: "required";
47
+ disabledWhen: {
48
+ match: "any";
49
+ conditions: {
50
+ source: "row";
51
+ valuePath: string;
52
+ operator: "truthy";
53
+ }[];
54
+ };
55
+ })[];
56
+ }[];
57
+ }[];
58
+ moduleId: "@phis/ui/modules/accounting";
59
+ area: "accounting";
8
60
  }, "area"> & {
9
61
  kind: "module";
10
62
  eligibleAreas: readonly ["public" | "app" | "admin" | "builder" | "editor" | "accounting"];
@@ -1,11 +1,13 @@
1
1
  import { definePhiAreaBaseRuntimeModuleDefinition } from "../area-base-definition";
2
- import { PHI_ACCOUNTING_RUNTIME_MODULE_ID } from "./ids";
2
+ import { PHI_ACCOUNTING_RUNTIME_MODULE_IDENTITY } from "./ids";
3
+ import { PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS } from "./data-providers";
3
4
  import { PHI_CORE_SERVER_BINDING, } from "../../../types/server-capabilities";
4
5
  export const PHI_ACCOUNTING_RUNTIME_MODULE_DEFINITION = definePhiAreaBaseRuntimeModuleDefinition({
5
6
  area: "accounting",
6
- moduleId: PHI_ACCOUNTING_RUNTIME_MODULE_ID,
7
+ ...PHI_ACCOUNTING_RUNTIME_MODULE_IDENTITY,
7
8
  serverBinding: PHI_CORE_SERVER_BINDING,
8
- description: "Locked Accounting Area shell, navigation surface, and root route.",
9
+ description: "Locked Accounting Area shell, navigation surface, root route, and the Site's product directory.",
9
10
  category: "foundation",
10
11
  icon: "antd:profile",
12
+ dataProviders: PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS,
11
13
  });
@@ -1 +1,21 @@
1
1
  export declare const PHI_ACCOUNTING_RUNTIME_MODULE_ID: "@phis/ui/modules/accounting";
2
+ /**
3
+ * The Module's identity as its Label Sets inherit it (`definePhiRuntimeModuleLabelSet`): the id and,
4
+ * where a Module declares one, its source locale. Stated here beside the id and spread into the
5
+ * definition, so a Label Set a tree reads does not import the definition that imports the tree.
6
+ */
7
+ export declare const PHI_ACCOUNTING_RUNTIME_MODULE_IDENTITY: {
8
+ readonly moduleId: "@phis/ui/modules/accounting";
9
+ };
10
+ /**
11
+ * The Site's product directory (phis-server SERVER_ADDONS.md, `products:v1`): every product of every
12
+ * supplier Add-on, as the Site operator administers it. A Page of the Accounting Area itself rather than
13
+ * of a shop, because every supplier's products land in it and it has to work with no shop at all.
14
+ */
15
+ export declare const PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY: `${string}/${string}`;
16
+ /** The one resource the directory's Provider answers. */
17
+ export declare const PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY = "products";
18
+ export declare const PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET_KEY = "accounting-products-page";
19
+ export declare const PHI_ACCOUNTING_PRODUCTS_PAGE_LAYOUT_IDS: Readonly<Record<"layoutTerms" | "layoutTermsFooter", import("@phis/contracts/cms").PhiCmsInstanceId>>;
20
+ export declare const PHI_ACCOUNTING_PRODUCTS_PAGE_OVERLAY_IDS: Readonly<Record<"overlayTerms", import("@phis/contracts/cms").PhiCmsInstanceId>>;
21
+ export declare const PHI_ACCOUNTING_PRODUCTS_PAGE_WIDGET_IDS: Readonly<Record<"widgetTable" | "widgetTerms" | "widgetTermsNote" | "widgetTermsCommands", import("@phis/contracts/cms").PhiCmsInstanceId>>;
@@ -1,2 +1,29 @@
1
1
  import { PHI_SHARED_PACKAGE_NAME } from "../../../types/signals";
2
+ import { createPhiSharedRuntimeDataProviderKey } from "../../../constants/runtime-data-provider-key";
3
+ import { createPhiPresetCmsInstanceIdMap } from "../../../types/cms-instance-id";
2
4
  export const PHI_ACCOUNTING_RUNTIME_MODULE_ID = `${PHI_SHARED_PACKAGE_NAME}/modules/accounting`;
5
+ /**
6
+ * The Module's identity as its Label Sets inherit it (`definePhiRuntimeModuleLabelSet`): the id and,
7
+ * where a Module declares one, its source locale. Stated here beside the id and spread into the
8
+ * definition, so a Label Set a tree reads does not import the definition that imports the tree.
9
+ */
10
+ export const PHI_ACCOUNTING_RUNTIME_MODULE_IDENTITY = {
11
+ moduleId: PHI_ACCOUNTING_RUNTIME_MODULE_ID,
12
+ };
13
+ /**
14
+ * The Site's product directory (phis-server SERVER_ADDONS.md, `products:v1`): every product of every
15
+ * supplier Add-on, as the Site operator administers it. A Page of the Accounting Area itself rather than
16
+ * of a shop, because every supplier's products land in it and it has to work with no shop at all.
17
+ */
18
+ export const PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY = createPhiSharedRuntimeDataProviderKey("tables", "accounting-products");
19
+ /** The one resource the directory's Provider answers. */
20
+ export const PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY = "products";
21
+ export const PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET_KEY = "accounting-products-page";
22
+ const PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET = {
23
+ domain: "page",
24
+ ownerModuleId: PHI_ACCOUNTING_RUNTIME_MODULE_ID,
25
+ presetKey: PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET_KEY,
26
+ };
27
+ export const PHI_ACCOUNTING_PRODUCTS_PAGE_LAYOUT_IDS = createPhiPresetCmsInstanceIdMap(PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET, ["layoutTerms", "layoutTermsFooter"]);
28
+ export const PHI_ACCOUNTING_PRODUCTS_PAGE_OVERLAY_IDS = createPhiPresetCmsInstanceIdMap(PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET, ["overlayTerms"]);
29
+ export const PHI_ACCOUNTING_PRODUCTS_PAGE_WIDGET_IDS = createPhiPresetCmsInstanceIdMap(PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET, ["widgetTable", "widgetTerms", "widgetTermsNote", "widgetTermsCommands"]);
@@ -9,6 +9,58 @@ export declare const PHI_ACCOUNTING_RUNTIME_MODULE: {
9
9
  description: string;
10
10
  icon: string;
11
11
  serverBinding: import("../../../types").PhiRuntimeModuleServerBinding;
12
+ dataProviders: {
13
+ key: `${string}/${string}`;
14
+ ownerModuleId: "@phis/ui/modules/accounting";
15
+ kind: "table";
16
+ executionMode: "live";
17
+ authoringMode: "none";
18
+ title: string;
19
+ description: string;
20
+ resources: {
21
+ resourceKey: string;
22
+ title: string;
23
+ rowIdentityPath: string;
24
+ fields: import("../../../types").PhiTableProviderFieldDefinition[];
25
+ query: {
26
+ search: true;
27
+ filterFields: string[];
28
+ sorting: "none";
29
+ pagination: "offset";
30
+ total: true;
31
+ };
32
+ recordRead: true;
33
+ actions: ({
34
+ key: string;
35
+ title: string;
36
+ scope: "row";
37
+ intent: "write";
38
+ confirmation: "required";
39
+ disabledWhen: {
40
+ match: "any";
41
+ conditions: {
42
+ source: "row";
43
+ valuePath: string;
44
+ operator: "falsy";
45
+ }[];
46
+ };
47
+ } | {
48
+ key: string;
49
+ title: string;
50
+ scope: "row";
51
+ intent: "destructive";
52
+ confirmation: "required";
53
+ disabledWhen: {
54
+ match: "any";
55
+ conditions: {
56
+ source: "row";
57
+ valuePath: string;
58
+ operator: "truthy";
59
+ }[];
60
+ };
61
+ })[];
62
+ }[];
63
+ }[];
12
64
  kind: "module";
13
65
  eligibleAreas: readonly ["public" | "app" | "admin" | "builder" | "editor" | "accounting"];
14
66
  title: "Public Base" | "App Base" | "Accounting Base" | "Admin Base" | "Builder Base" | "Editor Base";
@@ -1,11 +1,12 @@
1
1
  import { buildPhiAreaRootRoutePresetDescriptor } from "../area-root-route";
2
+ import { buildPhiSidebarRoutePresetDescriptor } from "../sidebar-route";
2
3
  import { PhiCmsRegionType } from "../../../constants/phi-cms";
3
4
  import { PHI_DEFAULT_PUB_AREA_COMPOSITION_NODE_KEYS } from "../preset-contracts/pub-area";
4
- import { PHI_ACCOUNTING_RUNTIME_MODULE_ID } from "./ids";
5
+ import { PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET_KEY, PHI_ACCOUNTING_RUNTIME_MODULE_ID } from "./ids";
5
6
  /*
6
- * What the Accounting base Module brings: the Site shell for its Area and the Area root. No Page of its
7
- * own -- the Dashboard Module's entry stands first in the sidebar, so the root lands there, and every other
8
- * Accounting Page is a Module's.
7
+ * What the Accounting base Module brings: the Site shell for its Area, the Area root, and the Site's
8
+ * product directory. The root lands on the first sidebar entry a viewer can see -- the Dashboard
9
+ * Module's where it is on, the directory where it is not.
9
10
  */
10
11
  export const PHI_ACCOUNTING_RUNTIME_MODULE_AREA_SHELLS = [
11
12
  {
@@ -44,4 +45,22 @@ export const PHI_ACCOUNTING_RUNTIME_MODULE_ROUTES = [
44
45
  area: "accounting",
45
46
  title: "Accounting",
46
47
  }),
48
+ /*
49
+ * The product directory, the Area's own Page: every supplier Add-on's products land in it, so it
50
+ * belongs to none of them, and it works with no shop at all (phis-server SERVER_ADDONS.md,
51
+ * `products:v1`). Whoever the Area lets in holds Core's `accounting` access, which is what Core asks
52
+ * of every request the Page makes.
53
+ */
54
+ buildPhiSidebarRoutePresetDescriptor({
55
+ area: "accounting",
56
+ anchor: "main",
57
+ ownerModuleId: PHI_ACCOUNTING_RUNTIME_MODULE_ID,
58
+ presetKey: PHI_ACCOUNTING_PRODUCTS_PAGE_PRESET_KEY,
59
+ title: "Products",
60
+ path: "/products",
61
+ itemKey: "@phis/ui/modules/accounting/nav/accounting/products",
62
+ icon: "antd:appstore",
63
+ loadTree: ({ page, runtime }) => import("./trees/phi-default-accounting-products-page-tree")
64
+ .then((module) => module.buildPhiDefaultAccountingProductsPageTree({ page, runtime })),
65
+ }),
47
66
  ];
@@ -0,0 +1,93 @@
1
+ import { type PhiTableProviderMutationRequest, type PhiTableProviderQueryRequest, type PhiTableProviderRecordRequest } from "../../../../types/table-widget";
2
+ /**
3
+ * A directory row as the Table speaks it: Core's fields, and what the Page reads off them -- the state as
4
+ * a lock mark, the parts as a count, whether a release waits, and the terms in force beside the terms
5
+ * waiting. A publisher's product never released has nothing in force; its terms are what waits. The
6
+ * Site's own product (no publisher) is always released and never waits.
7
+ */
8
+ export declare function toPhiAccountingProductRow(product: Record<string, unknown>): {
9
+ parts: string[];
10
+ partCount: number;
11
+ locked: boolean;
12
+ awaitingRelease: boolean;
13
+ };
14
+ declare function queryProducts({ resourceKey, query, signal }: PhiTableProviderQueryRequest): Promise<{
15
+ rows: {
16
+ parts: string[];
17
+ partCount: number;
18
+ locked: boolean;
19
+ awaitingRelease: boolean;
20
+ }[];
21
+ total: number;
22
+ }>;
23
+ /**
24
+ * One product, read again for the record that sets its terms side by side. Core lists, it has no read of
25
+ * one product here, so the id is searched for -- it is part of what the search reads -- and the one
26
+ * product with exactly that id is taken from the matches.
27
+ */
28
+ declare function readProductRecord({ resourceKey, rowIdentity, signal }: PhiTableProviderRecordRequest): Promise<{
29
+ parts: string[];
30
+ partCount: number;
31
+ locked: boolean;
32
+ awaitingRelease: boolean;
33
+ }>;
34
+ /** The path of one operator command; the id is one segment, so its `@`, `/` and `:` are encoded. */
35
+ export declare function buildPhiAccountingProductCommandPath(productId: string, command: string): string;
36
+ declare function mutateProducts(request: PhiTableProviderMutationRequest): Promise<{
37
+ status: "accepted";
38
+ invalidation: "view";
39
+ }>;
40
+ /** The registration itself, apart from the component, so the requests it makes can be read in a test. */
41
+ export declare const PHI_ACCOUNTING_PRODUCTS_TABLE_PROVIDER_REGISTRATION: {
42
+ key: `${string}/${string}`;
43
+ resources: {
44
+ resourceKey: string;
45
+ title: string;
46
+ rowIdentityPath: string;
47
+ fields: import("../../../../types").PhiTableProviderFieldDefinition[];
48
+ query: {
49
+ search: true;
50
+ filterFields: string[];
51
+ sorting: "none";
52
+ pagination: "offset";
53
+ total: true;
54
+ };
55
+ recordRead: true;
56
+ actions: ({
57
+ key: string;
58
+ title: string;
59
+ scope: "row";
60
+ intent: "write";
61
+ confirmation: "required";
62
+ disabledWhen: {
63
+ match: "any";
64
+ conditions: {
65
+ source: "row";
66
+ valuePath: string;
67
+ operator: "falsy";
68
+ }[];
69
+ };
70
+ } | {
71
+ key: string;
72
+ title: string;
73
+ scope: "row";
74
+ intent: "destructive";
75
+ confirmation: "required";
76
+ disabledWhen: {
77
+ match: "any";
78
+ conditions: {
79
+ source: "row";
80
+ valuePath: string;
81
+ operator: "truthy";
82
+ }[];
83
+ };
84
+ })[];
85
+ }[];
86
+ query: typeof queryProducts;
87
+ readRecord: typeof readProductRecord;
88
+ mutate: typeof mutateProducts;
89
+ };
90
+ export declare const PhiAccountingProductsTableProviderClient: import("react").ComponentType<{
91
+ children: import("react").ReactNode;
92
+ }>;
93
+ export {};
@@ -0,0 +1,158 @@
1
+ "use client";
2
+ import { isPhiRecord } from "../../../../helpers/is-record";
3
+ import { buildPhiTablePageParams, createPhiTableProviderRequestInit, readPhiTableRows, readPhiTableStringFilter, } from "../../../../components/widgets/client/shared/phi-table-provider-request";
4
+ import { readPhiTableProviderResponse, } from "../../../../components/widgets/client/shared/phi-table-provider-response";
5
+ import { createPhiTableProviderClient, } from "../../../../components/widgets/client/shared/phi-table-provider";
6
+ import { PhiTableProviderError, } from "../../../../types/table-widget";
7
+ import { PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS } from "../data-providers";
8
+ import { PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY, PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY } from "../ids";
9
+ const API_PATH = "/api/site/products";
10
+ const RESPONSE_OPTIONS = { subject: "Products" };
11
+ // What a list shows before the reader picks another size; the Page names the same number.
12
+ const DEFAULT_PAGE_SIZE = 25;
13
+ // The route's largest page, which a record read asks for to find its one product among the matches.
14
+ const RECORD_SEARCH_PAGE_SIZE = 100;
15
+ const COMMANDS = new Set(["release", "lock", "unlock"]);
16
+ /*
17
+ * The version of each product as the terms dialog last read it (`readProductRecord`), which is what a
18
+ * release names: the operator releases the terms they compared, and Core refuses (409) a product that has
19
+ * moved on since -- the publisher changed its terms again while the dialog stood open. The Table's own
20
+ * list does not write it: the dialog's record is the one the release runs from.
21
+ */
22
+ const versionsShown = new Map();
23
+ const readParts = (value) => Array.isArray(value) ? value.filter((part) => typeof part === "string") : [];
24
+ function termValues(prefix, terms) {
25
+ return {
26
+ [`${prefix}Sale`]: terms ? terms.sale ?? null : null,
27
+ [`${prefix}ReferralUrl`]: terms ? terms.referralUrl ?? null : null,
28
+ [`${prefix}Free`]: terms ? terms.free === true : null,
29
+ [`${prefix}AccountRequired`]: terms ? terms.accountRequired === true : null,
30
+ [`${prefix}Parts`]: terms ? readParts(terms.parts) : null,
31
+ };
32
+ }
33
+ /**
34
+ * A directory row as the Table speaks it: Core's fields, and what the Page reads off them -- the state as
35
+ * a lock mark, the parts as a count, whether a release waits, and the terms in force beside the terms
36
+ * waiting. A publisher's product never released has nothing in force; its terms are what waits. The
37
+ * Site's own product (no publisher) is always released and never waits.
38
+ */
39
+ export function toPhiAccountingProductRow(product) {
40
+ const pending = isPhiRecord(product.pendingTerms) ? product.pendingTerms : null;
41
+ const released = product.released === true;
42
+ const parts = readParts(product.parts);
43
+ return {
44
+ ...product,
45
+ parts,
46
+ partCount: parts.length,
47
+ locked: product.state === "locked",
48
+ awaitingRelease: !released || pending !== null,
49
+ ...termValues("inForce", released ? product : null),
50
+ ...termValues("pending", released ? pending : product),
51
+ };
52
+ }
53
+ function readStateFilter(query) {
54
+ const value = query.filters?.state;
55
+ const states = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
56
+ return states.filter((state) => typeof state === "string" && Boolean(state.trim()));
57
+ }
58
+ function readTotal(result) {
59
+ if (typeof result?.total !== "number" || !Number.isFinite(result.total) || result.total < 0) {
60
+ throw new PhiTableProviderError("invalid-response", "Products total is invalid.");
61
+ }
62
+ return result.total;
63
+ }
64
+ async function readDirectory(params, signal) {
65
+ return readPhiTableProviderResponse(await fetch(`${API_PATH}?${params.toString()}`, createPhiTableProviderRequestInit(signal)), RESPONSE_OPTIONS);
66
+ }
67
+ function requireResource(resourceKey) {
68
+ if (resourceKey !== PHI_ACCOUNTING_PRODUCTS_RESOURCE_KEY) {
69
+ throw new PhiTableProviderError("resource-not-found", `Unknown Accounting resource "${resourceKey}".`);
70
+ }
71
+ }
72
+ async function queryProducts({ resourceKey, query, signal }) {
73
+ requireResource(resourceKey);
74
+ const params = buildPhiTablePageParams(query, DEFAULT_PAGE_SIZE);
75
+ const search = query.search?.trim() ?? "";
76
+ if (search)
77
+ params.set("q", search);
78
+ const supplier = readPhiTableStringFilter(query, "supplier");
79
+ if (supplier)
80
+ params.set("supplier", supplier);
81
+ const states = readStateFilter(query);
82
+ if (states.length > 0)
83
+ params.set("state", states.join(","));
84
+ // The switch asks for those waiting; off, it asks for nothing rather than for those not waiting.
85
+ if (query.filters?.pendingTerms === true)
86
+ params.set("pendingTerms", "true");
87
+ const result = await readDirectory(params, signal);
88
+ return { rows: readPhiTableRows(result?.rows).map(toPhiAccountingProductRow), total: readTotal(result) };
89
+ }
90
+ /**
91
+ * One product, read again for the record that sets its terms side by side. Core lists, it has no read of
92
+ * one product here, so the id is searched for -- it is part of what the search reads -- and the one
93
+ * product with exactly that id is taken from the matches.
94
+ */
95
+ async function readProductRecord({ resourceKey, rowIdentity, signal }) {
96
+ requireResource(resourceKey);
97
+ if (typeof rowIdentity !== "string" || !rowIdentity) {
98
+ throw new PhiTableProviderError("record-not-found", "A product id is required.");
99
+ }
100
+ const params = new URLSearchParams({ q: rowIdentity, page: "1", pageSize: String(RECORD_SEARCH_PAGE_SIZE) });
101
+ const result = await readDirectory(params, signal);
102
+ const product = readPhiTableRows(result?.rows).find((row) => row.id === rowIdentity);
103
+ if (!product) {
104
+ versionsShown.delete(rowIdentity);
105
+ throw new PhiTableProviderError("record-not-found", `The Site has no product ${rowIdentity}.`);
106
+ }
107
+ if (typeof product.version !== "number" || !Number.isSafeInteger(product.version) || product.version < 1) {
108
+ throw new PhiTableProviderError("invalid-response", `Product ${rowIdentity} has no version.`);
109
+ }
110
+ versionsShown.set(rowIdentity, product.version);
111
+ return toPhiAccountingProductRow(product);
112
+ }
113
+ /** The path of one operator command; the id is one segment, so its `@`, `/` and `:` are encoded. */
114
+ export function buildPhiAccountingProductCommandPath(productId, command) {
115
+ return `${API_PATH}/${encodeURIComponent(productId)}/${command}`;
116
+ }
117
+ /*
118
+ * The operator's three acts. Each can move the row out of what the filters show -- a lock out of the
119
+ * active ones, a release out of those waiting -- so the view is read again rather than patched. A release
120
+ * sends the version of the record the terms dialog shows (`versionsShown`); with none read there is
121
+ * nothing the operator compared, and it is refused here rather than sent without one.
122
+ */
123
+ async function mutateProducts(request) {
124
+ requireResource(request.resourceKey);
125
+ if (request.kind !== "action" || !COMMANDS.has(request.actionKey)) {
126
+ throw new PhiTableProviderError("mutation-not-supported", "Products are released, locked or unlocked here, never edited.");
127
+ }
128
+ if (typeof request.rowIdentity !== "string" || !request.rowIdentity) {
129
+ throw new PhiTableProviderError("invalid-query", "A product id is required.");
130
+ }
131
+ const init = createPhiTableProviderRequestInit(request.signal);
132
+ let body;
133
+ if (request.actionKey === "release") {
134
+ const expectedVersion = versionsShown.get(request.rowIdentity);
135
+ if (expectedVersion === undefined) {
136
+ throw new PhiTableProviderError("invalid-query", `The terms of ${request.rowIdentity} were not read; open them before releasing.`);
137
+ }
138
+ body = JSON.stringify({ expectedVersion });
139
+ }
140
+ await readPhiTableProviderResponse(await fetch(buildPhiAccountingProductCommandPath(request.rowIdentity, request.actionKey), {
141
+ ...init,
142
+ method: "POST",
143
+ ...(body === undefined ? {} : { body, headers: { ...init.headers, "content-type": "application/json" } }),
144
+ }), RESPONSE_OPTIONS);
145
+ return { status: "accepted", invalidation: "view" };
146
+ }
147
+ // Its own descriptor by key, not by position: a Provider added to the list must not take its place.
148
+ const resources = PHI_ACCOUNTING_RUNTIME_DATA_PROVIDER_DESCRIPTORS
149
+ .find((descriptor) => descriptor.key === PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY)?.resources ?? [];
150
+ /** The registration itself, apart from the component, so the requests it makes can be read in a test. */
151
+ export const PHI_ACCOUNTING_PRODUCTS_TABLE_PROVIDER_REGISTRATION = {
152
+ key: PHI_ACCOUNTING_PRODUCTS_DATA_PROVIDER_KEY,
153
+ resources,
154
+ query: queryProducts,
155
+ readRecord: readProductRecord,
156
+ mutate: mutateProducts,
157
+ };
158
+ export const PhiAccountingProductsTableProviderClient = createPhiTableProviderClient(PHI_ACCOUNTING_PRODUCTS_TABLE_PROVIDER_REGISTRATION);