@pipedream/snipe_it 0.0.1 → 0.1.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.
- package/actions/create-hardware/create-hardware.mjs +228 -0
- package/actions/create-user/create-user.mjs +211 -0
- package/actions/get-hardware/get-hardware.mjs +27 -0
- package/actions/get-license/get-license.mjs +32 -0
- package/actions/get-user-assets/get-user-assets.mjs +32 -0
- package/actions/update-hardware/update-hardware.mjs +284 -0
- package/common/utils.mjs +44 -0
- package/package.json +4 -1
- package/snipe_it.app.mjs +566 -5
- package/LICENSE +0 -41
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import app from "../../snipe_it.app.mjs";
|
|
2
|
+
import utils from "../../common/utils.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "snipe_it-update-hardware",
|
|
6
|
+
name: "Update Hardware Asset",
|
|
7
|
+
description: "Partially updates information about an existing hardware asset. [See the documentation](https://snipe-it.readme.io/reference/hardware-partial-update)",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
props: {
|
|
11
|
+
app,
|
|
12
|
+
hardwareId: {
|
|
13
|
+
propDefinition: [
|
|
14
|
+
app,
|
|
15
|
+
"hardwareId",
|
|
16
|
+
],
|
|
17
|
+
description: "Select the hardware asset to update",
|
|
18
|
+
},
|
|
19
|
+
assetTag: {
|
|
20
|
+
propDefinition: [
|
|
21
|
+
app,
|
|
22
|
+
"assetTag",
|
|
23
|
+
],
|
|
24
|
+
description: "Update the asset tag",
|
|
25
|
+
},
|
|
26
|
+
notes: {
|
|
27
|
+
propDefinition: [
|
|
28
|
+
app,
|
|
29
|
+
"notes",
|
|
30
|
+
],
|
|
31
|
+
description: "Update notes about the asset",
|
|
32
|
+
},
|
|
33
|
+
statusId: {
|
|
34
|
+
optional: true,
|
|
35
|
+
propDefinition: [
|
|
36
|
+
app,
|
|
37
|
+
"statusId",
|
|
38
|
+
],
|
|
39
|
+
description: "Update the status of the asset",
|
|
40
|
+
},
|
|
41
|
+
modelId: {
|
|
42
|
+
optional: true,
|
|
43
|
+
propDefinition: [
|
|
44
|
+
app,
|
|
45
|
+
"modelId",
|
|
46
|
+
],
|
|
47
|
+
description: "Update the model of the asset",
|
|
48
|
+
},
|
|
49
|
+
lastCheckout: {
|
|
50
|
+
propDefinition: [
|
|
51
|
+
app,
|
|
52
|
+
"lastCheckout",
|
|
53
|
+
],
|
|
54
|
+
description: "Update the last checkout date",
|
|
55
|
+
},
|
|
56
|
+
assignedUser: {
|
|
57
|
+
optional: true,
|
|
58
|
+
propDefinition: [
|
|
59
|
+
app,
|
|
60
|
+
"userId",
|
|
61
|
+
],
|
|
62
|
+
label: "Assigned User",
|
|
63
|
+
description: "The ID of the user the asset should be checked out to",
|
|
64
|
+
},
|
|
65
|
+
assignedLocation: {
|
|
66
|
+
optional: true,
|
|
67
|
+
propDefinition: [
|
|
68
|
+
app,
|
|
69
|
+
"userId",
|
|
70
|
+
],
|
|
71
|
+
label: "Assigned Location",
|
|
72
|
+
description: "The ID of the user the location should be checked out to",
|
|
73
|
+
},
|
|
74
|
+
assignedAsset: {
|
|
75
|
+
optional: true,
|
|
76
|
+
propDefinition: [
|
|
77
|
+
app,
|
|
78
|
+
"hardwareId",
|
|
79
|
+
],
|
|
80
|
+
label: "Assigned Asset",
|
|
81
|
+
description: "The ID of the asset the asset should be checked out to",
|
|
82
|
+
},
|
|
83
|
+
companyId: {
|
|
84
|
+
propDefinition: [
|
|
85
|
+
app,
|
|
86
|
+
"companyId",
|
|
87
|
+
],
|
|
88
|
+
description: "The ID of an associated company id",
|
|
89
|
+
},
|
|
90
|
+
serial: {
|
|
91
|
+
propDefinition: [
|
|
92
|
+
app,
|
|
93
|
+
"serial",
|
|
94
|
+
],
|
|
95
|
+
description: "Serial number of the asset",
|
|
96
|
+
},
|
|
97
|
+
orderNumber: {
|
|
98
|
+
propDefinition: [
|
|
99
|
+
app,
|
|
100
|
+
"orderNumber",
|
|
101
|
+
],
|
|
102
|
+
description: "Update the order number",
|
|
103
|
+
},
|
|
104
|
+
warrantyMonths: {
|
|
105
|
+
propDefinition: [
|
|
106
|
+
app,
|
|
107
|
+
"warrantyMonths",
|
|
108
|
+
],
|
|
109
|
+
description: "Update the warranty period",
|
|
110
|
+
},
|
|
111
|
+
purchaseCost: {
|
|
112
|
+
propDefinition: [
|
|
113
|
+
app,
|
|
114
|
+
"purchaseCost",
|
|
115
|
+
],
|
|
116
|
+
description: "Update the purchase cost",
|
|
117
|
+
},
|
|
118
|
+
purchaseDate: {
|
|
119
|
+
propDefinition: [
|
|
120
|
+
app,
|
|
121
|
+
"purchaseDate",
|
|
122
|
+
],
|
|
123
|
+
description: "Update the purchase date",
|
|
124
|
+
},
|
|
125
|
+
requestable: {
|
|
126
|
+
propDefinition: [
|
|
127
|
+
app,
|
|
128
|
+
"requestable",
|
|
129
|
+
],
|
|
130
|
+
description: "Update whether the asset can be requested",
|
|
131
|
+
},
|
|
132
|
+
archived: {
|
|
133
|
+
propDefinition: [
|
|
134
|
+
app,
|
|
135
|
+
"archived",
|
|
136
|
+
],
|
|
137
|
+
description: "Update the archived status",
|
|
138
|
+
},
|
|
139
|
+
rtdLocationId: {
|
|
140
|
+
propDefinition: [
|
|
141
|
+
app,
|
|
142
|
+
"locationId",
|
|
143
|
+
],
|
|
144
|
+
description: "Update the RTD location",
|
|
145
|
+
},
|
|
146
|
+
name: {
|
|
147
|
+
propDefinition: [
|
|
148
|
+
app,
|
|
149
|
+
"name",
|
|
150
|
+
],
|
|
151
|
+
description: "Update the name of the asset",
|
|
152
|
+
},
|
|
153
|
+
locationId: {
|
|
154
|
+
propDefinition: [
|
|
155
|
+
app,
|
|
156
|
+
"locationId",
|
|
157
|
+
],
|
|
158
|
+
description: "Update the location of the asset",
|
|
159
|
+
},
|
|
160
|
+
byod: {
|
|
161
|
+
propDefinition: [
|
|
162
|
+
app,
|
|
163
|
+
"byod",
|
|
164
|
+
],
|
|
165
|
+
description: "Update the BYOD",
|
|
166
|
+
},
|
|
167
|
+
customFields: {
|
|
168
|
+
propDefinition: [
|
|
169
|
+
app,
|
|
170
|
+
"customFields",
|
|
171
|
+
],
|
|
172
|
+
description: "Update custom fields using DB field names from Settings > Custom Fields",
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
async run({ $ }) {
|
|
176
|
+
const {
|
|
177
|
+
app,
|
|
178
|
+
hardwareId,
|
|
179
|
+
assetTag,
|
|
180
|
+
notes,
|
|
181
|
+
statusId,
|
|
182
|
+
modelId,
|
|
183
|
+
lastCheckout,
|
|
184
|
+
assignedUser,
|
|
185
|
+
assignedLocation,
|
|
186
|
+
assignedAsset,
|
|
187
|
+
companyId,
|
|
188
|
+
serial,
|
|
189
|
+
orderNumber,
|
|
190
|
+
warrantyMonths,
|
|
191
|
+
purchaseCost,
|
|
192
|
+
purchaseDate,
|
|
193
|
+
requestable,
|
|
194
|
+
archived,
|
|
195
|
+
rtdLocationId,
|
|
196
|
+
name,
|
|
197
|
+
locationId,
|
|
198
|
+
byod,
|
|
199
|
+
customFields,
|
|
200
|
+
} = this;
|
|
201
|
+
|
|
202
|
+
const parsedCustomFields = utils.parseJson(customFields);
|
|
203
|
+
|
|
204
|
+
const data = {
|
|
205
|
+
...(assetTag && {
|
|
206
|
+
asset_tag: assetTag,
|
|
207
|
+
}),
|
|
208
|
+
...(notes && {
|
|
209
|
+
notes,
|
|
210
|
+
}),
|
|
211
|
+
...(statusId && {
|
|
212
|
+
status_id: statusId,
|
|
213
|
+
}),
|
|
214
|
+
...(modelId && {
|
|
215
|
+
model_id: modelId,
|
|
216
|
+
}),
|
|
217
|
+
...(lastCheckout && {
|
|
218
|
+
last_checkout: lastCheckout,
|
|
219
|
+
}),
|
|
220
|
+
...(assignedUser && {
|
|
221
|
+
assigned_user_id: assignedUser,
|
|
222
|
+
}),
|
|
223
|
+
...(assignedLocation && {
|
|
224
|
+
assigned_location_id: assignedLocation,
|
|
225
|
+
}),
|
|
226
|
+
...(assignedAsset && {
|
|
227
|
+
assigned_asset_id: assignedAsset,
|
|
228
|
+
}),
|
|
229
|
+
...(companyId && {
|
|
230
|
+
company_id: companyId,
|
|
231
|
+
}),
|
|
232
|
+
...(serial && {
|
|
233
|
+
serial,
|
|
234
|
+
}),
|
|
235
|
+
...(orderNumber && {
|
|
236
|
+
order_number: orderNumber,
|
|
237
|
+
}),
|
|
238
|
+
...(warrantyMonths && {
|
|
239
|
+
warranty_months: warrantyMonths,
|
|
240
|
+
}),
|
|
241
|
+
...(purchaseCost && {
|
|
242
|
+
purchase_cost: purchaseCost,
|
|
243
|
+
}),
|
|
244
|
+
...(purchaseDate && {
|
|
245
|
+
purchase_date: purchaseDate,
|
|
246
|
+
}),
|
|
247
|
+
...(requestable && {
|
|
248
|
+
requestable,
|
|
249
|
+
}),
|
|
250
|
+
...(archived && {
|
|
251
|
+
archived,
|
|
252
|
+
}),
|
|
253
|
+
...(rtdLocationId && {
|
|
254
|
+
rtd_location_id: rtdLocationId,
|
|
255
|
+
}),
|
|
256
|
+
...(name && {
|
|
257
|
+
name,
|
|
258
|
+
}),
|
|
259
|
+
...(locationId && {
|
|
260
|
+
location_id: locationId,
|
|
261
|
+
}),
|
|
262
|
+
...(byod && {
|
|
263
|
+
byod,
|
|
264
|
+
}),
|
|
265
|
+
...(typeof(parsedCustomFields) === "object"
|
|
266
|
+
? parsedCustomFields
|
|
267
|
+
: {}
|
|
268
|
+
),
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
if (Object.keys(data).length === 0) {
|
|
272
|
+
throw new Error("At least one field must be provided to update");
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const response = await app.updateHardware({
|
|
276
|
+
$,
|
|
277
|
+
hardwareId,
|
|
278
|
+
data,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
$.export("$summary", `Successfully updated hardware asset with ID \`${response.payload.id}\``);
|
|
282
|
+
return response;
|
|
283
|
+
},
|
|
284
|
+
};
|
package/common/utils.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const parseJson = (input, maxDepth = 100) => {
|
|
2
|
+
const seen = new WeakSet();
|
|
3
|
+
const parse = (value) => {
|
|
4
|
+
if (maxDepth <= 0) {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
if (typeof(value) === "string") {
|
|
8
|
+
// Only parse if the string looks like a JSON object or array
|
|
9
|
+
const trimmed = value.trim();
|
|
10
|
+
if (
|
|
11
|
+
(trimmed.startsWith("{") && trimmed.endsWith("}")) ||
|
|
12
|
+
(trimmed.startsWith("[") && trimmed.endsWith("]"))
|
|
13
|
+
) {
|
|
14
|
+
try {
|
|
15
|
+
return parseJson(JSON.parse(value), maxDepth - 1);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
} else if (typeof(value) === "object" && value !== null && !Array.isArray(value)) {
|
|
22
|
+
if (seen.has(value)) {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
seen.add(value);
|
|
26
|
+
return Object.entries(value)
|
|
27
|
+
.reduce((acc, [
|
|
28
|
+
key,
|
|
29
|
+
val,
|
|
30
|
+
]) => Object.assign(acc, {
|
|
31
|
+
[key]: parse(val),
|
|
32
|
+
}), {});
|
|
33
|
+
} else if (Array.isArray(value)) {
|
|
34
|
+
return value.map((item) => parse(item));
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return parse(input);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default {
|
|
43
|
+
parseJson,
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/snipe_it",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Pipedream Snipe-IT Components",
|
|
5
5
|
"main": "snipe_it.app.mjs",
|
|
6
6
|
"keywords": [
|
|
@@ -11,5 +11,8 @@
|
|
|
11
11
|
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@pipedream/platform": "^3.1.0"
|
|
14
17
|
}
|
|
15
18
|
}
|