@pipedream/salesforce_rest_api 2.0.0 → 2.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/salesforce_rest_api",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Pipedream Salesforce (REST API) Components",
5
5
  "main": "salesforce_rest_api.app.mjs",
6
6
  "keywords": [
@@ -26,7 +26,7 @@ export default {
26
26
  parentObjectType: {
27
27
  type: "string",
28
28
  label: "Parent Object Type",
29
- description: "Optional. The Salesforce SObject API name of the parent record to filter by, e.g. `Case` or `Opportunity`. When set, appends `AND Parent.Type = '<value>'` to the SOQL WHERE clause (traversal of the polymorphic `ParentId`). Leave blank to emit events on any parent object.",
29
+ description: "Optional. Only emit events whose parent record is of this Salesforce SObject API name, e.g. `Case` or `Opportunity`. Enforced on both delivery paths: `AND Parent.Type = '<value>'` in the polling SOQL, and the parent's Salesforce ID key prefix on instant (webhook) deliveries. Leave blank to emit events on any parent object.",
30
30
  optional: true,
31
31
  },
32
32
  excludeSelf: {
@@ -89,6 +89,62 @@ export default {
89
89
  }
90
90
  return userId;
91
91
  },
92
+ _getParentKeyPrefix() {
93
+ return this.db.get("parentKeyPrefix");
94
+ },
95
+ _setParentKeyPrefix(parentKeyPrefix) {
96
+ this.db.set("parentKeyPrefix", parentKeyPrefix);
97
+ },
98
+ async _resolveParentKeyPrefix() {
99
+ const objectType = this.parentObjectType;
100
+
101
+ // The cache records which object type it was resolved for, so editing the
102
+ // prop on a deployed source re-resolves instead of reusing a stale prefix.
103
+ const cached = this._getParentKeyPrefix();
104
+ if (cached?.objectType === objectType) {
105
+ return cached.keyPrefix;
106
+ }
107
+
108
+ let keyPrefix;
109
+ try {
110
+ ({ keyPrefix } = await this.getObjectTypeDescription(objectType));
111
+ } catch (err) {
112
+ console.log(`Error describing ${objectType} to resolve its ID key prefix:`, err);
113
+ }
114
+
115
+ if (!keyPrefix) {
116
+ // Not cached, so a transient describe failure is retried on the next event.
117
+ console.log(`No ID key prefix available for ${objectType}, falling back to a per-event Parent.Type lookup.`);
118
+ return null;
119
+ }
120
+
121
+ this._setParentKeyPrefix({
122
+ objectType,
123
+ keyPrefix,
124
+ });
125
+ return keyPrefix;
126
+ },
127
+ async _parentTypeMatches(record) {
128
+ const parentId = record?.ParentId;
129
+ if (!parentId) {
130
+ return false;
131
+ }
132
+
133
+ // Salesforce ID key prefixes are stable per SObject (Case = `500`,
134
+ // Account = `001`, ...), so the parent's type is read straight off the
135
+ // pushed ParentId with no extra API call per event.
136
+ const keyPrefix = await this._resolveParentKeyPrefix();
137
+ if (keyPrefix) {
138
+ return parentId.startsWith(keyPrefix);
139
+ }
140
+
141
+ // Fallback for an object with no key prefix: one SOQL lookup per event,
142
+ // reusing the same polymorphic traversal as the polling query.
143
+ const { records } = await this.query({
144
+ query: `SELECT Id FROM ${this.getObjectType()} WHERE Id = '${record.Id}' AND Parent.Type = '${this.parentObjectType}'`,
145
+ });
146
+ return !!records?.length;
147
+ },
92
148
  async _buildExtraConditions() {
93
149
  const conditions = [];
94
150
  if (this.parentObjectType) {
@@ -101,13 +157,16 @@ export default {
101
157
  return conditions.join(" ");
102
158
  },
103
159
  async processWebhookEvent(event) {
104
- // Instant/webhook deliveries can't filter on Parent.Type (the pushed
105
- // payload has ParentId but not the parent's object type), so
106
- // parentObjectType is only enforced on the polling/deploy SOQL queries.
107
- // excludeSelf is enforced here to prevent self-trigger loops.
160
+ // Instant/webhook deliveries can't filter on Parent.Type in SOQL (the
161
+ // pushed payload carries ParentId but not the parent's object type), so
162
+ // both props are enforced here to match the polling/deploy queries.
163
+ const record = event.body?.New;
164
+ if (this.parentObjectType && !(await this._parentTypeMatches(record))) {
165
+ return;
166
+ }
108
167
  if (this.excludeSelf) {
109
168
  const userId = await this._resolveAuthenticatedUserId();
110
- if (event.body?.New?.CreatedById === userId) {
169
+ if (record?.CreatedById === userId) {
111
170
  return;
112
171
  }
113
172
  }
@@ -11,13 +11,13 @@ export default {
11
11
  type: "source",
12
12
  name: "New Chatter Feed Comment (Instant or Polling)",
13
13
  key: "salesforce_rest_api-new-feed-comment",
14
- description: "Emit new events for each Chatter FeedComment (reply) created in Salesforce, polling `FeedComment` via SOQL on `CreatedDate`. Use this to react to comments on Chatter posts, since Chatter activity does not update the parent record's `LastModifiedDate`. The payload includes both `ParentId` (a polymorphic reference to the feed's parent - either a record feed, e.g. a Case ID starting with `500`, or a User feed) and `FeedItemId` (the ID of the FeedItem the comment belongs to) - these are distinct fields; do not confuse them. Set `parentObjectType` to a parent object API name (e.g. `Case`) to append `AND Parent.Type = '<value>'` to the SOQL WHERE clause. Set `excludeSelf` to `true` to drop comments authored by the connected integration user. Note: querying FeedComment without a parent filter requires the `View All Data` permission on the connected user. Attempts instant delivery via webhook and falls back to timer polling automatically. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_feedcomment.htm)",
15
- version: "0.0.4",
14
+ description: "Emit new events for each Chatter FeedComment (reply) created in Salesforce, polling `FeedComment` via SOQL on `CreatedDate`. Use this to react to comments on Chatter posts, since Chatter activity does not update the parent record's `LastModifiedDate`. The payload includes both `ParentId` (a polymorphic reference to the feed's parent - either a record feed, e.g. a Case ID starting with `500`, or a User feed) and `FeedItemId` (the ID of the FeedItem the comment belongs to) - these are distinct fields; do not confuse them. Set `parentObjectType` to a parent object API name (e.g. `Case`) to only emit comments whose parent record is of that type. Set `excludeSelf` to `true` to drop comments authored by the connected integration user. Note: querying FeedComment without a parent filter requires the `View All Data` permission on the connected user. Attempts instant delivery via webhook and falls back to timer polling automatically. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_feedcomment.htm)",
15
+ version: "0.0.5",
16
16
  props: {
17
17
  ...common.props,
18
18
  parentObjectType: {
19
19
  ...common.props.parentObjectType,
20
- description: "Optional. The Salesforce SObject API name of the parent business record to filter by, e.g. `Case`. When set, appends `AND Parent.Type = '<value>'` to the SOQL WHERE clause (traversal of the polymorphic `FeedComment.ParentId`). Leave blank to emit comments on any parent object (requires `View All Data` permission).",
20
+ description: "Optional. Only emit comments whose parent record is of this Salesforce SObject API name, e.g. `Case` (traversal of the polymorphic `FeedComment.ParentId`). Enforced on both delivery paths: `AND Parent.Type = '<value>'` in the polling SOQL, and the parent's Salesforce ID key prefix on instant (webhook) deliveries. Leave blank to emit comments on any parent object (requires `View All Data` permission).",
21
21
  },
22
22
  excludeSelf: {
23
23
  ...common.props.excludeSelf,
@@ -12,12 +12,12 @@ export default {
12
12
  name: "New Chatter Feed Item (Instant or Polling)",
13
13
  key: "salesforce_rest_api-new-feed-item",
14
14
  description: "Emit new events for each Chatter FeedItem (post) created in Salesforce, polling `FeedItem` via SOQL on `CreatedDate`. Use this to react to Chatter posts on Cases and other records, since Chatter activity does not update the parent record's `LastModifiedDate` (so **New Record (Instant, of Selectable Type)** and **New Case (Instant, of Selectable Type)** never emit for it). Set `parentObjectType` to the parent object's API name (e.g. `Case`, `Opportunity`) to only emit posts whose parent record is of that type. Set `excludeSelf` to `true` to drop posts authored by the connected integration user. Note: `Body` is null for system-generated post types (e.g. `TrackedChange`). Attempts instant delivery via webhook and falls back to timer polling automatically when the Streaming API does not support this object. [See the documentation](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_feeditem.htm)",
15
- version: "0.0.4",
15
+ version: "0.0.5",
16
16
  props: {
17
17
  ...common.props,
18
18
  parentObjectType: {
19
19
  ...common.props.parentObjectType,
20
- description: "Optional. The Salesforce SObject API name of the parent record to filter by, e.g. `Case` or `Opportunity`. When set, appends `AND Parent.Type = '<value>'` to the SOQL WHERE clause (traversal of the polymorphic `FeedItem.ParentId`). Leave blank to emit posts on any parent object.",
20
+ description: "Optional. Only emit posts whose parent record is of this Salesforce SObject API name, e.g. `Case` or `Opportunity` (traversal of the polymorphic `FeedItem.ParentId`). Enforced on both delivery paths: `AND Parent.Type = '<value>'` in the polling SOQL, and the parent's Salesforce ID key prefix on instant (webhook) deliveries. Leave blank to emit posts on any parent object.",
21
21
  },
22
22
  excludeSelf: {
23
23
  ...common.props.excludeSelf,