@pipedream/salesforce_rest_api 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ import {
2
+ convertFieldsToProps, getAdditionalFields,
3
+ } from "../../common/props-utils.mjs";
4
+ import salesforce from "../../salesforce_rest_api.app.mjs";
5
+ import { additionalFields } from "../common/base-create-update.mjs";
6
+
7
+ export default {
8
+ key: "salesforce_rest_api-upsert-record",
9
+ name: "Upsert Record",
10
+ description: "Create or update a record of a given object. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm)",
11
+ version: "0.0.1",
12
+ type: "action",
13
+ props: {
14
+ salesforce,
15
+ objectType: {
16
+ propDefinition: [
17
+ salesforce,
18
+ "objectType",
19
+ ],
20
+ description: "The type of object to create a record of",
21
+ reloadProps: true,
22
+ },
23
+ },
24
+ methods: {
25
+ getAdditionalFields,
26
+ convertFieldsToProps,
27
+ async upsertRecord(sobjectName, {
28
+ externalIdFieldName, externalIdValue, ...args
29
+ }) {
30
+ const url = `${this.salesforce._sObjectTypeApiUrl(sobjectName)}/${externalIdFieldName}/${externalIdValue}`;
31
+ return this.salesforce._makeRequest({
32
+ url,
33
+ method: "PATCH",
34
+ ...args,
35
+ });
36
+ },
37
+ },
38
+ async additionalProps() {
39
+ const { objectType } = this;
40
+ const fields = await this.salesforce.getFieldsForObjectType(objectType);
41
+
42
+ const requiredFields = fields.filter((field) => {
43
+ return field.createable && field.updateable && !field.nillable && !field.defaultedOnCreate;
44
+ });
45
+
46
+ const externalIdFieldOptions = fields.filter((field) => field.externalId).map(({
47
+ label, name,
48
+ }) => ({
49
+ label,
50
+ value: name,
51
+ }));
52
+
53
+ const requiredFieldProps = this.convertFieldsToProps(requiredFields);
54
+
55
+ return {
56
+ docsInfo: {
57
+ type: "alert",
58
+ alertType: "info",
59
+ content: `[See the documentation](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_${objectType.toLowerCase()}.htm) for information on all available fields.`,
60
+ },
61
+ externalIdFieldName: {
62
+ type: "string",
63
+ label: "External ID Field",
64
+ description: "The field to use as the external ID to identify the record.",
65
+ options: externalIdFieldOptions,
66
+ },
67
+ docsInfoExtId: {
68
+ type: "alert",
69
+ alertType: "info",
70
+ content: "If you don't see any fields in the above list, you probably need to create one in Salesforce's Object Manager. Only a field marked as an external id field can be used to identify a record.",
71
+ },
72
+ externalIdValue: {
73
+ type: "string",
74
+ label: "External ID Value",
75
+ description: "The value of the external ID field selected above. If a record with this value exists, it will be updated, otherwise a new one will be created.",
76
+ },
77
+ updateOnly: {
78
+ type: "boolean",
79
+ label: "Update Only",
80
+ description: "If enabled, the action will only update an existing record, but not create one.",
81
+ optional: true,
82
+ },
83
+ ...requiredFieldProps,
84
+ additionalFields,
85
+ };
86
+ },
87
+ async run({ $ }) {
88
+ /* eslint-disable no-unused-vars */
89
+ const {
90
+ salesforce,
91
+ objectType,
92
+ getAdditionalFields: getData,
93
+ convertFieldsToProps,
94
+ docsInfo,
95
+ docsInfoExtId,
96
+ additionalFields,
97
+ externalIdFieldName,
98
+ externalIdValue,
99
+ updateOnly,
100
+ ...data
101
+ } = this;
102
+ /* eslint-enable no-unused-vars */
103
+ const response = await this.upsertRecord(objectType, {
104
+ $,
105
+ externalIdFieldName,
106
+ externalIdValue,
107
+ params: {
108
+ updateOnly,
109
+ },
110
+ data: {
111
+ ...data,
112
+ ...getData(),
113
+ },
114
+ });
115
+ $.export("$summary", `Successfully ${response.created
116
+ ? "created"
117
+ : "updated"} ${objectType} record (ID: ${response.id})`);
118
+ return response;
119
+ },
120
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/salesforce_rest_api",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Pipedream Salesforce (REST API) Components",
5
5
  "main": "salesforce_rest_api.app.mjs",
6
6
  "keywords": [
@@ -7,7 +7,21 @@ export default {
7
7
  name: "New Record (Instant, of Selectable Type)",
8
8
  key: "salesforce_rest_api-new-record-instant",
9
9
  description: "Emit new event when a record of the selected object type is created. [See the documentation](https://sforce.co/3yPSJZy)",
10
- version: "0.1.0",
10
+ version: "0.2.0",
11
+ props: {
12
+ ...common.props,
13
+ fieldsToObtain: {
14
+ propDefinition: [
15
+ common.props.salesforce,
16
+ "fieldsToObtain",
17
+ (c) => ({
18
+ objType: c.objectType,
19
+ }),
20
+ ],
21
+ optional: true,
22
+ description: "Select the field(s) to be retrieved for the records. Only applicable if the source is running on a timer. If running on a webhook, or if not specified, all fields will be retrieved.",
23
+ },
24
+ },
11
25
  hooks: {
12
26
  ...common.hooks,
13
27
  async deploy() {
@@ -40,7 +54,7 @@ export default {
40
54
  Id: id,
41
55
  } = item;
42
56
  const entityType = startCase(objectType);
43
- const summary = `New ${entityType} created: ${name}`;
57
+ const summary = `New ${entityType} created: ${name ?? id}`;
44
58
  const ts = Date.parse(createdDate);
45
59
  return {
46
60
  id,
@@ -57,7 +71,7 @@ export default {
57
71
  [nameField]: name,
58
72
  } = newObject;
59
73
  const entityType = startCase(this.objectType).toLowerCase();
60
- const summary = `New ${entityType} created: ${name}`;
74
+ const summary = `New ${entityType} created: ${name ?? id}`;
61
75
  const ts = Date.parse(createdDate);
62
76
  return {
63
77
  id,
@@ -118,8 +132,11 @@ export default {
118
132
  setObjectTypeColumns,
119
133
  } = this;
120
134
 
121
- const { fields } = await getObjectTypeDescription(objectType);
122
- const columns = fields.map(({ name }) => name);
135
+ let columns = this.fieldsToObtain;
136
+ if (!columns?.length) {
137
+ const { fields } = await getObjectTypeDescription(objectType);
138
+ columns = fields.map(({ name }) => name);
139
+ }
123
140
 
124
141
  setObjectTypeColumns(columns);
125
142
  },