@pipedream/vero 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.
@@ -0,0 +1,74 @@
1
+ import { ConfigurationError } from "@pipedream/platform";
2
+ import app from "../../vero.app.mjs";
3
+
4
+ export default {
5
+ type: "action",
6
+ key: "vero-create-or-update-user",
7
+ name: "Create or Update User",
8
+ version: "0.0.1",
9
+ description: "This endpoint creates a new user profile if the user doesn't exist yet. Otherwise, the user profile is updated based on the properties provided. [See the documentation](https://developers.getvero.com/track-api-reference/#/operations/identify)",
10
+ props: {
11
+ app,
12
+ id: {
13
+ propDefinition: [
14
+ app,
15
+ "id",
16
+ ],
17
+ },
18
+ email: {
19
+ propDefinition: [
20
+ app,
21
+ "email",
22
+ ],
23
+ },
24
+ channels: {
25
+ type: "string[]",
26
+ label: "Channels",
27
+ description: "A valid JSON array containing hashes of key/value pairs that represent the user's device token. Each hash should represent a single device token and include the fields type, address, and platform.",
28
+ optional: true,
29
+ },
30
+ data: {
31
+ type: "object",
32
+ label: "Data",
33
+ description: "A valid JSON hash containing key value pairs that represent the custom user properties you want to update. The locale, timezone and userAgent attributes are reserved properties that may be updated automatically by our SDKs. You can use these properties but bear in mind they may be overwritten if using our SDKs or integrations. All other keys are freeform and can be defined by you. Ex: `{\"first_name\":\"Damien\",\"last_name\":\"Brzoska\",\"timezone\":-10}`",
34
+ optional: true,
35
+ },
36
+ },
37
+ methods: {
38
+ parseChannels(data) {
39
+ if (!data) {
40
+ return null;
41
+ }
42
+ const parsed = [];
43
+ for (let i = 0; i < data.length; i++) {
44
+ let item;
45
+ try {
46
+ item = JSON.parse(data[i]);
47
+ } catch (err) {
48
+ throw new ConfigurationError(`Invalid JSON in channels property at index ${i}: ${err.message}`);
49
+ }
50
+
51
+ if (Array.isArray(item)) {
52
+ throw new ConfigurationError(`Invalid JSON in channels property at index ${i}: Expected an object, but received an array. If you want to send multiple items, please create a new child`);
53
+ }
54
+
55
+ parsed.push(item);
56
+ }
57
+
58
+ return parsed;
59
+ },
60
+ },
61
+ async run({ $ }) {
62
+ const {
63
+ app,
64
+ parseChannels,
65
+ ...rest
66
+ } = this;
67
+ const res = await app.createOrUpdateUser({
68
+ ...rest,
69
+ channels: parseChannels(rest.channels),
70
+ });
71
+ $.export("summary", `User with id "${rest.id}" created or updated successfully`);
72
+ return res;
73
+ },
74
+ };
@@ -0,0 +1,63 @@
1
+ import { ConfigurationError } from "@pipedream/platform";
2
+ import app from "../../vero.app.mjs";
3
+
4
+ export default {
5
+ type: "action",
6
+ key: "vero-track-event-for-user",
7
+ name: "Track Event for User",
8
+ version: "0.0.1",
9
+ description: "This endpoint tracks an event for a specific user. If the user profile doesn't exist Vero will create it. [See the documentation](https://developers.getvero.com/track-api-reference/#/operations/track)",
10
+ props: {
11
+ app,
12
+ id: {
13
+ propDefinition: [
14
+ app,
15
+ "id",
16
+ ],
17
+ description: "The unique identifier of the customer. You must provider either `id` or `email`.",
18
+ optional: true,
19
+ },
20
+ email: {
21
+ propDefinition: [
22
+ app,
23
+ "email",
24
+ ],
25
+ description: "The email address of the customer. You must provider either `id` or `email`.",
26
+ optional: true,
27
+ },
28
+ eventName: {
29
+ type: "string",
30
+ label: "Event Name",
31
+ description: "The name of the event tracked.",
32
+ },
33
+ data: {
34
+ type: "object",
35
+ label: "Data",
36
+ description: "A valid JSON hash containing key value pairs that represent the custom user properties you want to track with the event. All keys are freeform and can be defined by you.",
37
+ optional: true,
38
+ },
39
+ extras: {
40
+ type: "object",
41
+ label: "Extras",
42
+ description: "A valid JSON hash containing key/value pairs that represent the reserved, Vero-specific `created_at` and `source` properties.",
43
+ optional: true,
44
+ },
45
+ },
46
+ async run({ $ }) {
47
+ if (!this.id && !this.email) {
48
+ throw new ConfigurationError("You must provide either an `id` or an `email` to create or update a user");
49
+ }
50
+
51
+ const res = await this.app.trackEventForUser({
52
+ identity: {
53
+ id: this.id,
54
+ email: this.email,
55
+ },
56
+ event_name: this.eventName,
57
+ data: this.data,
58
+ extras: this.extras,
59
+ });
60
+ $.export("summary", `Track successfully create for user ${this.id || this.email}`);
61
+ return res;
62
+ },
63
+ };
package/package.json CHANGED
@@ -1,15 +1,12 @@
1
1
  {
2
2
  "name": "@pipedream/vero",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Vero Components",
5
5
  "main": "dist/app/vero.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "vero"
9
9
  ],
10
- "files": [
11
- "dist"
12
- ],
13
10
  "homepage": "https://pipedream.com/apps/vero",
14
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
15
12
  "publishConfig": {
package/vero.app.mjs ADDED
@@ -0,0 +1,51 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "vero",
6
+ propDefinitions: {
7
+ id: {
8
+ type: "string",
9
+ label: "ID",
10
+ description: "The unique identifier of the customer.",
11
+ },
12
+ email: {
13
+ type: "string",
14
+ label: "Email",
15
+ description: "The email address of the customer.",
16
+ },
17
+ },
18
+ methods: {
19
+ _getAuthToken() {
20
+ return this.$auth.auth_token;
21
+ },
22
+ _getBaseUrl() {
23
+ return "https://api.getvero.com/api/v2";
24
+ },
25
+ async _makeHttpRequest(opts = {}, ctx = this) {
26
+ const axiosOpts = {
27
+ ...opts,
28
+ url: this._getBaseUrl() + opts.path,
29
+ params: {
30
+ ...opts.params,
31
+ auth_token: this._getAuthToken(),
32
+ },
33
+ };
34
+ return axios(ctx, axiosOpts);
35
+ },
36
+ async createOrUpdateUser(data) {
37
+ return this._makeHttpRequest({
38
+ method: "POST",
39
+ path: "/users/track",
40
+ data,
41
+ });
42
+ },
43
+ async trackEventForUser(data) {
44
+ return this._makeHttpRequest({
45
+ method: "POST",
46
+ path: "/events/track",
47
+ data,
48
+ });
49
+ },
50
+ },
51
+ };