@pipedream/salesforce_rest_api 1.1.0 → 1.2.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,215 @@
|
|
|
1
|
+
import common from "../common/base.mjs";
|
|
2
|
+
import utils from "../../common/props-utils.mjs";
|
|
3
|
+
import { toSingleLineString } from "../../common/utils.mjs";
|
|
4
|
+
|
|
5
|
+
const { salesforce } = common.props;
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
...common,
|
|
9
|
+
key: "salesforce_rest_api-create-user",
|
|
10
|
+
name: "Create User",
|
|
11
|
+
description: toSingleLineString(`
|
|
12
|
+
Creates a Salesforce user.
|
|
13
|
+
See [User SObject](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_user.htm)
|
|
14
|
+
and [Create Record](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm)
|
|
15
|
+
`),
|
|
16
|
+
version: "0.0.1",
|
|
17
|
+
type: "action",
|
|
18
|
+
props: {
|
|
19
|
+
salesforce,
|
|
20
|
+
alias: {
|
|
21
|
+
type: "string",
|
|
22
|
+
label: "Alias",
|
|
23
|
+
description: "Alias of the user. The alias can contain only underscores and alphanumeric characters. It must be unique in your org, not include spaces, not end with a hyphen, and not contain two consecutive hyphens.",
|
|
24
|
+
},
|
|
25
|
+
email: {
|
|
26
|
+
type: "string",
|
|
27
|
+
label: "Email",
|
|
28
|
+
description: "The email address of the user.",
|
|
29
|
+
},
|
|
30
|
+
emailEncodingKey: {
|
|
31
|
+
type: "string",
|
|
32
|
+
label: "Email Encoding Key",
|
|
33
|
+
description: "The key used to encode the user's email.",
|
|
34
|
+
options: [
|
|
35
|
+
"ISO-8859-1",
|
|
36
|
+
"UTF-8",
|
|
37
|
+
"Shift_JIS",
|
|
38
|
+
"EUC-JP",
|
|
39
|
+
"ISO-2022-JP",
|
|
40
|
+
],
|
|
41
|
+
default: "UTF-8",
|
|
42
|
+
},
|
|
43
|
+
languageLocaleKey: {
|
|
44
|
+
type: "string",
|
|
45
|
+
label: "Language Locale Key",
|
|
46
|
+
description: "The user's language locale key.",
|
|
47
|
+
async options() {
|
|
48
|
+
const fields = await this.salesforce.getFieldsForObjectType("User");
|
|
49
|
+
const { picklistValues } = fields.find(({ name }) => name === "LanguageLocaleKey");
|
|
50
|
+
return picklistValues.map(({
|
|
51
|
+
value, label,
|
|
52
|
+
}) => ({
|
|
53
|
+
label,
|
|
54
|
+
value,
|
|
55
|
+
}));
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
firstName: {
|
|
59
|
+
type: "string",
|
|
60
|
+
label: "First Name",
|
|
61
|
+
description: "The user's first name.",
|
|
62
|
+
optional: true,
|
|
63
|
+
},
|
|
64
|
+
lastName: {
|
|
65
|
+
type: "string",
|
|
66
|
+
label: "Last Name",
|
|
67
|
+
description: "The user's last name.",
|
|
68
|
+
},
|
|
69
|
+
localeSidKey: {
|
|
70
|
+
type: "string",
|
|
71
|
+
label: "Locale Sid Key",
|
|
72
|
+
description: "The user's locale sid key.",
|
|
73
|
+
async options() {
|
|
74
|
+
const fields = await this.salesforce.getFieldsForObjectType("User");
|
|
75
|
+
const { picklistValues } = fields.find(({ name }) => name === "LocaleSidKey");
|
|
76
|
+
return picklistValues.map(({
|
|
77
|
+
value, label,
|
|
78
|
+
}) => ({
|
|
79
|
+
label,
|
|
80
|
+
value,
|
|
81
|
+
}));
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
profileId: {
|
|
85
|
+
type: "string",
|
|
86
|
+
label: "Profile ID",
|
|
87
|
+
description: "The ID of the user's profile.",
|
|
88
|
+
async options() {
|
|
89
|
+
const { records } = await this.salesforce.query({
|
|
90
|
+
query: "SELECT Id, Name FROM Profile",
|
|
91
|
+
});
|
|
92
|
+
return records.map(({
|
|
93
|
+
Id: value, Name: label,
|
|
94
|
+
}) => ({
|
|
95
|
+
label,
|
|
96
|
+
value,
|
|
97
|
+
}));
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
timeZoneSidKey: {
|
|
101
|
+
type: "string",
|
|
102
|
+
label: "Time Zone Sid Key",
|
|
103
|
+
description: "The user's time zone sid key.",
|
|
104
|
+
async options() {
|
|
105
|
+
const fields = await this.salesforce.getFieldsForObjectType("User");
|
|
106
|
+
const { picklistValues } = fields.find(({ name }) => name === "TimeZoneSidKey");
|
|
107
|
+
return picklistValues.map(({
|
|
108
|
+
value, label,
|
|
109
|
+
}) => ({
|
|
110
|
+
label,
|
|
111
|
+
value,
|
|
112
|
+
}));
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
userName: {
|
|
116
|
+
type: "string",
|
|
117
|
+
label: "User Name",
|
|
118
|
+
description: "The user's username. It should be in email format. Eg. `john@acme.com`.",
|
|
119
|
+
},
|
|
120
|
+
title: {
|
|
121
|
+
type: "string",
|
|
122
|
+
label: "Title",
|
|
123
|
+
description: "The user's title.",
|
|
124
|
+
optional: true,
|
|
125
|
+
},
|
|
126
|
+
department: {
|
|
127
|
+
type: "string",
|
|
128
|
+
label: "Department",
|
|
129
|
+
description: "The department the user belongs to.",
|
|
130
|
+
optional: true,
|
|
131
|
+
},
|
|
132
|
+
division: {
|
|
133
|
+
type: "string",
|
|
134
|
+
label: "Division",
|
|
135
|
+
description: "The division the user belongs to.",
|
|
136
|
+
optional: true,
|
|
137
|
+
},
|
|
138
|
+
phone: {
|
|
139
|
+
type: "string",
|
|
140
|
+
label: "Phone",
|
|
141
|
+
description: "The user's phone number.",
|
|
142
|
+
optional: true,
|
|
143
|
+
},
|
|
144
|
+
mobilePhone: {
|
|
145
|
+
type: "string",
|
|
146
|
+
label: "Mobile Phone",
|
|
147
|
+
description: "The user's mobile phone number.",
|
|
148
|
+
optional: true,
|
|
149
|
+
},
|
|
150
|
+
street: {
|
|
151
|
+
type: "string",
|
|
152
|
+
label: "Street",
|
|
153
|
+
description: "The user's street address.",
|
|
154
|
+
optional: true,
|
|
155
|
+
},
|
|
156
|
+
city: {
|
|
157
|
+
type: "string",
|
|
158
|
+
label: "City",
|
|
159
|
+
description: "The user's city.",
|
|
160
|
+
optional: true,
|
|
161
|
+
},
|
|
162
|
+
state: {
|
|
163
|
+
type: "string",
|
|
164
|
+
label: "State",
|
|
165
|
+
description: "The user's state.",
|
|
166
|
+
optional: true,
|
|
167
|
+
},
|
|
168
|
+
postalCode: {
|
|
169
|
+
type: "string",
|
|
170
|
+
label: "Postal Code",
|
|
171
|
+
description: "The user's postal code.",
|
|
172
|
+
optional: true,
|
|
173
|
+
},
|
|
174
|
+
country: {
|
|
175
|
+
type: "string",
|
|
176
|
+
label: "Country",
|
|
177
|
+
description: "The user's country.",
|
|
178
|
+
optional: true,
|
|
179
|
+
},
|
|
180
|
+
userRoleId: {
|
|
181
|
+
type: "string",
|
|
182
|
+
label: "User Role ID",
|
|
183
|
+
description: "The ID of the user's role.",
|
|
184
|
+
optional: true,
|
|
185
|
+
},
|
|
186
|
+
isActive: {
|
|
187
|
+
type: "boolean",
|
|
188
|
+
label: "Is Active",
|
|
189
|
+
description: "Whether the user is active.",
|
|
190
|
+
optional: true,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
methods: {
|
|
194
|
+
createUser(args = {}) {
|
|
195
|
+
return this.salesforce._makeRequest({
|
|
196
|
+
method: "POST",
|
|
197
|
+
url: this.salesforce._sObjectTypeApiUrl("User"),
|
|
198
|
+
...args,
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
async run({ $ }) {
|
|
203
|
+
const {
|
|
204
|
+
createUser,
|
|
205
|
+
...data
|
|
206
|
+
} = this;
|
|
207
|
+
|
|
208
|
+
const response = await createUser({
|
|
209
|
+
$,
|
|
210
|
+
data: utils.keysToCapitalCase(data),
|
|
211
|
+
});
|
|
212
|
+
$.export("$summary", `Successfully created user with ID \`${response.id}\``);
|
|
213
|
+
return response;
|
|
214
|
+
},
|
|
215
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function toCapitalCase(str) {
|
|
2
|
+
return str
|
|
3
|
+
.split(" ")
|
|
4
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
5
|
+
.join("");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function filterProps(props) {
|
|
9
|
+
if (!props) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
return Object.fromEntries(
|
|
13
|
+
Object.entries(props)
|
|
14
|
+
.filter(([
|
|
15
|
+
key,
|
|
16
|
+
value,
|
|
17
|
+
]) => typeof (value) !== "function"
|
|
18
|
+
&& ![
|
|
19
|
+
"app",
|
|
20
|
+
"salesforce",
|
|
21
|
+
].includes(key)),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function keysToCapitalCase(data = {}) {
|
|
26
|
+
return Object.entries(filterProps(data))
|
|
27
|
+
.reduce((acc, [
|
|
28
|
+
key,
|
|
29
|
+
value,
|
|
30
|
+
]) => ({
|
|
31
|
+
...acc,
|
|
32
|
+
[toCapitalCase(key)]: value,
|
|
33
|
+
}), {});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default {
|
|
37
|
+
keysToCapitalCase,
|
|
38
|
+
};
|