@osdk/maker 0.12.0-beta.8 → 0.12.0-beta.9

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 (40) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +88 -62
  3. package/build/browser/api/defineAction.js +91 -78
  4. package/build/browser/api/defineAction.js.map +1 -1
  5. package/build/browser/api/defineLink.js +2 -2
  6. package/build/browser/api/defineLink.js.map +1 -1
  7. package/build/browser/api/defineObject.js +6 -2
  8. package/build/browser/api/defineObject.js.map +1 -1
  9. package/build/browser/api/defineOntology.js +2 -2
  10. package/build/browser/api/defineOntology.js.map +1 -1
  11. package/build/browser/api/overall.test.js +1123 -452
  12. package/build/browser/api/overall.test.js.map +1 -1
  13. package/build/browser/api/types.js.map +1 -1
  14. package/build/browser/cli/main.js +1 -1
  15. package/build/browser/index.js.map +1 -1
  16. package/build/cjs/index.cjs +100 -84
  17. package/build/cjs/index.cjs.map +1 -1
  18. package/build/cjs/index.d.cts +23 -14
  19. package/build/esm/api/defineAction.js +91 -78
  20. package/build/esm/api/defineAction.js.map +1 -1
  21. package/build/esm/api/defineLink.js +2 -2
  22. package/build/esm/api/defineLink.js.map +1 -1
  23. package/build/esm/api/defineObject.js +6 -2
  24. package/build/esm/api/defineObject.js.map +1 -1
  25. package/build/esm/api/defineOntology.js +2 -2
  26. package/build/esm/api/defineOntology.js.map +1 -1
  27. package/build/esm/api/overall.test.js +1123 -452
  28. package/build/esm/api/overall.test.js.map +1 -1
  29. package/build/esm/api/types.js.map +1 -1
  30. package/build/esm/cli/main.js +1 -1
  31. package/build/esm/index.js.map +1 -1
  32. package/build/types/api/defineAction.d.ts +6 -6
  33. package/build/types/api/defineAction.d.ts.map +1 -1
  34. package/build/types/api/defineObject.d.ts +2 -2
  35. package/build/types/api/defineObject.d.ts.map +1 -1
  36. package/build/types/api/types.d.ts +15 -6
  37. package/build/types/api/types.d.ts.map +1 -1
  38. package/build/types/index.d.ts +1 -1
  39. package/build/types/index.d.ts.map +1 -1
  40. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @osdk/maker
2
2
 
3
+ ## 0.12.0-beta.9
4
+
5
+ ### Minor Changes
6
+
7
+ - ac0029e: Improve CRUD actions customization
8
+
9
+ ### Patch Changes
10
+
11
+ - @osdk/api@2.4.0-beta.7
12
+
3
13
  ## 0.12.0-beta.8
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -567,72 +567,15 @@ const personToAddressLink = defineInterfaceLinkConstraint({
567
567
 
568
568
  Actions define operations that can be performed on objects and interfaces.
569
569
 
570
- ### Custom Action
571
-
572
- ```typescript
573
- import { defineAction } from "@osdk/maker";
574
-
575
- // Define a custom action
576
- const markAsInactiveAction = defineAction({
577
- apiName: "mark-as-inactive",
578
- displayName: "Mark as Inactive",
579
- parameters: [
580
- {
581
- id: "reason",
582
- displayName: "Reason",
583
- type: "string",
584
- validation: {
585
- required: true,
586
- allowedValues: { type: "text" },
587
- },
588
- },
589
- {
590
- id: "effectiveDate",
591
- displayName: "Effective Date",
592
- type: "date",
593
- validation: {
594
- required: true,
595
- allowedValues: { type: "datetime" },
596
- },
597
- },
598
- ],
599
- status: "active",
600
- rules: [
601
- {
602
- type: "addOrModifyObjectRuleV2",
603
- addOrModifyObjectRuleV2: {
604
- objectToModify: "objectToModifyParameter",
605
- propertyValues: {
606
- "isActive": {
607
- type: "staticValue",
608
- staticValue: {
609
- type: "boolean",
610
- boolean: false,
611
- },
612
- },
613
- "inactiveReason": {
614
- type: "parameterId",
615
- parameterId: "reason",
616
- },
617
- "inactiveDate": {
618
- type: "parameterId",
619
- parameterId: "effectiveDate",
620
- },
621
- },
622
- structFieldValues: {},
623
- },
624
- },
625
- ],
626
- });
627
- ```
628
-
629
570
  ### Create Object Action
630
571
 
631
572
  ```typescript
632
573
  import { defineCreateObjectAction } from "@osdk/maker";
633
574
 
634
575
  // Define an action to create an employee
635
- const createEmployeeAction = defineCreateObjectAction(employeeObject);
576
+ const createEmployeeAction = defineCreateObjectAction({
577
+ objectType: employeeObject,
578
+ });
636
579
  ```
637
580
 
638
581
  ### Modify Object Action
@@ -641,7 +584,9 @@ const createEmployeeAction = defineCreateObjectAction(employeeObject);
641
584
  import { defineModifyObjectAction } from "@osdk/maker";
642
585
 
643
586
  // Define an action to modify an employee
644
- const modifyEmployeeAction = defineModifyObjectAction(employeeObject);
587
+ const modifyEmployeeAction = defineModifyObjectAction({
588
+ objectType: employeeObject,
589
+ });
645
590
  ```
646
591
 
647
592
  ### Delete Object Action
@@ -650,7 +595,9 @@ const modifyEmployeeAction = defineModifyObjectAction(employeeObject);
650
595
  import { defineDeleteObjectAction } from "@osdk/maker";
651
596
 
652
597
  // Define an action to delete an employee
653
- const deleteEmployeeAction = defineDeleteObjectAction(employeeObject);
598
+ const deleteEmployeeAction = defineDeleteObjectAction({
599
+ objectType: employeeObject,
600
+ });
654
601
  ```
655
602
 
656
603
  ### Interface Actions
@@ -673,3 +620,82 @@ const createEmployeePersonAction = defineCreateInterfaceObjectAction(
673
620
  // Define an action to modify objects implementing an interface
674
621
  const modifyPersonAction = defineModifyInterfaceObjectAction(personInterface);
675
622
  ```
623
+
624
+ ### Custom Action
625
+
626
+ More customization such as security/submission criteria, constraints on parameter values, parameter overrides, etc.
627
+ can also be added.
628
+
629
+ ```typescript
630
+ import {
631
+ ActionParameterConditionalOverride,
632
+ ConditionDefinition,
633
+ defineModifyObjectAction,
634
+ defineObject,
635
+ } from "@osdk/maker";
636
+
637
+ const employeeObject = defineObject({
638
+ apiName: "employee",
639
+ displayName: "Employee",
640
+ pluralDisplayName: "Employees",
641
+ titlePropertyApiName: "id",
642
+ primaryKeyPropertyApiName: "id",
643
+ properties: {
644
+ "id": { type: "string", displayName: "ID" },
645
+ "team": { type: "string" },
646
+ "numDeals": { type: "integer" },
647
+ "experience": { type: "integer" },
648
+ },
649
+ });
650
+
651
+ const mustBeManagerCondition: ConditionDefinition = {
652
+ type: "group",
653
+ name: "managerGroup", // Actual group assigned during installation
654
+ };
655
+
656
+ const mustBeInTeamCondition: ConditionDefinition = {
657
+ type: "group",
658
+ name: "teamGroup",
659
+ };
660
+
661
+ const teamEqualsSalesParameterCondition: ConditionDefinition = {
662
+ type: "parameter",
663
+ parameterId: "team",
664
+ matches: {
665
+ type: "staticValue",
666
+ staticValue: {
667
+ type: "string",
668
+ string: "sales",
669
+ },
670
+ },
671
+ };
672
+
673
+ const makeDealsVisible: ActionParameterConditionalOverride = {
674
+ type: "visibility",
675
+ condition: {
676
+ type: "and",
677
+ conditions: [
678
+ mustBeInTeamCondition,
679
+ teamEqualsSalesParameterCondition,
680
+ ],
681
+ },
682
+ };
683
+
684
+ const modifyObjectActionType = defineModifyObjectAction(
685
+ {
686
+ objectType: employeeObject,
687
+ actionLevelValidation: {
688
+ condition: mustBeManagerCondition,
689
+ },
690
+ parameterLevelValidations: {
691
+ "numDeals": {
692
+ defaultVisibility: "hidden",
693
+ conditionalOverrides: [
694
+ makeDealsVisible,
695
+ ],
696
+ },
697
+ },
698
+ excludedProperties: ["experience"],
699
+ },
700
+ );
701
+ ```
@@ -16,7 +16,7 @@
16
16
 
17
17
  import { consola } from "consola";
18
18
  import invariant from "tiny-invariant";
19
- import { getAllInterfaceProperties } from "./defineObject.js";
19
+ import { convertToDisplayName, getAllInterfaceProperties } from "./defineObject.js";
20
20
  import { namespace, ontologyDefinition, updateOntology } from "./defineOntology.js";
21
21
  import { convertConditionDefinition } from "./ontologyUtils.js";
22
22
  import { OntologyEntityTypeEnum } from "./types.js";
@@ -90,48 +90,55 @@ export function defineCreateInterfaceObjectAction(interfaceType, objectType, val
90
90
  } : {})
91
91
  });
92
92
  }
93
- export function defineCreateObjectAction(objectType, validation) {
94
- const filteredProperties = objectType.properties?.filter(prop => !isStruct(prop.type)) ?? [];
95
- if (filteredProperties.length !== (objectType.properties?.length ?? 0)) {
96
- consola.info(`Some properties on ${objectType.apiName} were skipped in the create action because they are structs`);
97
- }
93
+ export function defineCreateObjectAction(def) {
94
+ Object.keys(def.parameterLevelValidations ?? {}).forEach(id => {
95
+ !(def.objectType.properties?.[id] !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Property ${id} does not exist on ${def.objectType.apiName}`) : invariant(false) : void 0;
96
+ });
97
+ (def.excludedProperties ?? []).forEach(id => {
98
+ !(def.objectType.properties?.[id] !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Property ${id} does not exist on ${def.objectType.apiName}`) : invariant(false) : void 0;
99
+ });
100
+ const parameterNames = Object.keys(def.objectType.properties ?? {}).filter(id => !def.excludedProperties?.includes(id) && !isStruct(def.objectType.properties?.[id].type));
101
+ const parameters = Array.from(parameterNames).map(id => ({
102
+ id,
103
+ displayName: def.objectType.properties?.[id].displayName ?? convertToDisplayName(id),
104
+ type: extractActionParameterType(def.objectType.properties?.[id]),
105
+ validation: def.parameterLevelValidations?.[id] !== undefined ? {
106
+ ...def.parameterLevelValidations?.[id],
107
+ allowedValues: def.parameterLevelValidations?.[id].allowedValues ?? extractAllowedValuesFromType(def.objectType.properties?.[id].type),
108
+ required: def.parameterLevelValidations?.[id].required ?? true
109
+ } : {
110
+ required: def.objectType.properties?.[id].array ?? false ? {
111
+ listLength: def.objectType.properties?.[id].nullability?.noEmptyCollections ? {
112
+ min: 1
113
+ } : {}
114
+ } : def.objectType.properties?.[id].nullability?.noNulls ?? true,
115
+ allowedValues: extractAllowedValuesFromType(def.objectType.properties?.[id].type)
116
+ }
117
+ }));
98
118
  return defineAction({
99
- apiName: `create-object-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`,
100
- displayName: `Create ${objectType.displayName}`,
101
- parameters: [...filteredProperties.map(prop => ({
102
- id: prop.apiName,
103
- displayName: prop.displayName,
104
- type: extractActionParameterType(prop),
105
- typeClasses: prop.typeClasses ?? [],
106
- validation: {
107
- required: prop.array ?? false ? {
108
- listLength: prop.nullability?.noEmptyCollections ? {
109
- min: 1
110
- } : {}
111
- } : prop.nullability?.noNulls ?? true,
112
- allowedValues: extractAllowedValuesFromType(prop.type)
113
- }
114
- }))],
115
- status: "active",
119
+ apiName: def.apiName ?? `create-object-${kebab(def.objectType.apiName.split(".").pop() ?? def.objectType.apiName)}`,
120
+ displayName: def.displayName ?? `Create ${def.objectType.displayName}`,
121
+ parameters: parameters,
122
+ status: def.status ?? "active",
116
123
  entities: {
117
124
  affectedInterfaceTypes: [],
118
- affectedObjectTypes: [objectType.apiName],
125
+ affectedObjectTypes: [def.objectType.apiName],
119
126
  affectedLinkTypes: [],
120
127
  typeGroups: []
121
128
  },
122
129
  rules: [{
123
130
  type: "addObjectRule",
124
131
  addObjectRule: {
125
- objectTypeId: objectType.apiName,
126
- propertyValues: filteredProperties.length > 0 ? Object.fromEntries(filteredProperties.map(p => [p.apiName, {
132
+ objectTypeId: def.objectType.apiName,
133
+ propertyValues: Object.fromEntries(parameters.map(p => [p.id, {
127
134
  type: "parameterId",
128
- parameterId: p.apiName
129
- }])) : {},
135
+ parameterId: p.id
136
+ }])),
130
137
  structFieldValues: {}
131
138
  }
132
139
  }],
133
- ...(validation ? {
134
- validation: [convertValidationRule(validation)]
140
+ ...(def.actionLevelValidation ? {
141
+ validation: [convertValidationRule(def.actionLevelValidation)]
135
142
  } : {})
136
143
  });
137
144
  }
@@ -203,22 +210,41 @@ export function defineModifyInterfaceObjectAction(interfaceType, objectType, val
203
210
  } : {})
204
211
  });
205
212
  }
206
- export function defineModifyObjectAction(objectType, validation) {
207
- const properties = objectType.properties ?? [];
208
- const filteredProperties = properties.filter(prop => !isStruct(prop.type) && prop.apiName !== objectType.primaryKeyPropertyApiName);
209
- if (filteredProperties.length < properties.length) {
210
- consola.warn(`Some properties on ${objectType.apiName} were skipped in the modify action because they were structs, or were the object's primary key which cannot be edited.`);
211
- }
213
+ export function defineModifyObjectAction(def) {
214
+ Object.keys(def.parameterLevelValidations ?? {}).forEach(id => {
215
+ !(def.objectType.properties?.[id] !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Property ${id} does not exist on ${def.objectType.apiName}`) : invariant(false) : void 0;
216
+ });
217
+ (def.excludedProperties ?? []).forEach(id => {
218
+ !(def.objectType.properties?.[id] !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Property ${id} does not exist on ${def.objectType.apiName}`) : invariant(false) : void 0;
219
+ });
220
+ const parameterNames = Object.keys(def.objectType.properties ?? {}).filter(id => !def.excludedProperties?.includes(id) && !isStruct(def.objectType.properties?.[id].type) && id !== def.objectType.primaryKeyPropertyApiName);
221
+ const parameters = Array.from(parameterNames).map(id => ({
222
+ id,
223
+ displayName: def.objectType.properties?.[id].displayName ?? convertToDisplayName(id),
224
+ type: extractActionParameterType(def.objectType.properties?.[id]),
225
+ validation: def.parameterLevelValidations?.[id] !== undefined ? {
226
+ ...def.parameterLevelValidations?.[id],
227
+ allowedValues: def.parameterLevelValidations?.[id].allowedValues ?? extractAllowedValuesFromType(def.objectType.properties?.[id].type),
228
+ required: def.parameterLevelValidations?.[id].required ?? false
229
+ } : {
230
+ required: def.objectType.properties?.[id].array ?? false ? {
231
+ listLength: def.objectType.properties?.[id].nullability?.noEmptyCollections ? {
232
+ min: 1
233
+ } : {}
234
+ } : def.objectType.properties?.[id].nullability?.noNulls ?? false,
235
+ allowedValues: extractAllowedValuesFromType(def.objectType.properties?.[id].type)
236
+ }
237
+ }));
212
238
  return defineAction({
213
- apiName: `modify-object-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`,
214
- displayName: `Modify ${objectType.displayName}`,
239
+ apiName: def.apiName ?? `modify-object-${kebab(def.objectType.apiName.split(".").pop() ?? def.objectType.apiName)}`,
240
+ displayName: def.displayName ?? `Modify ${def.objectType.displayName}`,
215
241
  parameters: [{
216
242
  id: "objectToModifyParameter",
217
243
  displayName: "Modify object",
218
244
  type: {
219
245
  type: "objectReference",
220
246
  objectReference: {
221
- objectTypeId: objectType.apiName
247
+ objectTypeId: def.objectType.apiName
222
248
  }
223
249
  },
224
250
  validation: {
@@ -227,54 +253,41 @@ export function defineModifyObjectAction(objectType, validation) {
227
253
  },
228
254
  required: true
229
255
  }
230
- }, ...filteredProperties.map(prop => ({
231
- id: prop.apiName,
232
- displayName: prop.displayName,
233
- type: extractActionParameterType(prop),
234
- typeClasses: prop.typeClasses ?? [],
235
- validation: {
236
- required: prop.array ?? false ? {
237
- listLength: prop.nullability?.noEmptyCollections ? {
238
- min: 1
239
- } : {}
240
- } : prop.nullability?.noNulls ?? false,
241
- allowedValues: extractAllowedValuesFromType(prop.type)
242
- }
243
- }))],
244
- status: "active",
245
- entities: {
246
- affectedInterfaceTypes: [],
247
- affectedObjectTypes: [objectType.apiName],
248
- affectedLinkTypes: [],
249
- typeGroups: []
250
- },
256
+ }, ...parameters],
257
+ status: def.status ?? "active",
251
258
  rules: [{
252
259
  type: "modifyObjectRule",
253
260
  modifyObjectRule: {
254
261
  objectToModify: "objectToModifyParameter",
255
- propertyValues: filteredProperties.length > 0 ? Object.fromEntries(filteredProperties.map(p => [p.apiName, {
262
+ propertyValues: Object.fromEntries(parameters.map(p => [p.id, {
256
263
  type: "parameterId",
257
- parameterId: p.apiName
258
- }])) : {},
264
+ parameterId: p.id
265
+ }])),
259
266
  structFieldValues: {}
260
267
  }
261
268
  }],
262
- ...(validation ? {
263
- validation: [convertValidationRule(validation)]
269
+ entities: {
270
+ affectedInterfaceTypes: [],
271
+ affectedObjectTypes: [def.objectType.apiName],
272
+ affectedLinkTypes: [],
273
+ typeGroups: []
274
+ },
275
+ ...(def.actionLevelValidation ? {
276
+ validation: [convertValidationRule(def.actionLevelValidation)]
264
277
  } : {})
265
278
  });
266
279
  }
267
- export function defineDeleteObjectAction(objectType, validation) {
280
+ export function defineDeleteObjectAction(def) {
268
281
  return defineAction({
269
- apiName: `delete-object-${kebab(objectType.apiName.split(".").pop() ?? objectType.apiName)}`,
270
- displayName: `Delete ${objectType.displayName}`,
282
+ apiName: def.apiName ?? `delete-object-${kebab(def.objectType.apiName.split(".").pop() ?? def.objectType.apiName)}`,
283
+ displayName: def.displayName ?? `Delete ${def.objectType.displayName}`,
271
284
  parameters: [{
272
285
  id: "objectToDeleteParameter",
273
286
  displayName: "Delete object",
274
287
  type: {
275
288
  type: "objectReference",
276
289
  objectReference: {
277
- objectTypeId: objectType.apiName
290
+ objectTypeId: def.objectType.apiName
278
291
  }
279
292
  },
280
293
  validation: {
@@ -284,21 +297,21 @@ export function defineDeleteObjectAction(objectType, validation) {
284
297
  }
285
298
  }
286
299
  }],
287
- status: "active",
288
- entities: {
289
- affectedInterfaceTypes: [],
290
- affectedObjectTypes: [objectType.apiName],
291
- affectedLinkTypes: [],
292
- typeGroups: []
293
- },
300
+ status: def.status ?? "active",
294
301
  rules: [{
295
302
  type: "deleteObjectRule",
296
303
  deleteObjectRule: {
297
304
  objectToDelete: "objectToDeleteParameter"
298
305
  }
299
306
  }],
300
- ...(validation ? {
301
- validation: [convertValidationRule(validation)]
307
+ entities: {
308
+ affectedInterfaceTypes: [],
309
+ affectedObjectTypes: [def.objectType.apiName],
310
+ affectedLinkTypes: [],
311
+ typeGroups: []
312
+ },
313
+ ...(def.actionLevelValidation ? {
314
+ validation: [convertValidationRule(def.actionLevelValidation)]
302
315
  } : {})
303
316
  });
304
317
  }