Skip to content

Commit e86de43

Browse files
committed
Update Walletap component to version 0.1.0, add new actions for creating, retrieving, updating passes, and sending notifications. Introduce utility function for parsing objects.
1 parent 17e5267 commit e86de43

File tree

7 files changed

+299
-5
lines changed

7 files changed

+299
-5
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import walletap from "../../walletap.app.mjs";
3+
4+
export default {
5+
key: "walletap-create-pass",
6+
name: "Create Pass",
7+
description: "Creates a mobile Wallet pass. [See the documentation](https://walletap.io/docs/api#tag/Pass/operation/createPass)",
8+
version: "0.0.1",
9+
type: "action",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: false,
14+
},
15+
props: {
16+
walletap,
17+
passes: {
18+
type: "string[]",
19+
label: "Passes",
20+
description: "A list of objects with the pass data. Example: `[{ \"templateId\": \"daltQAV1vidnfj6C6Vws\", \"templateFields\": { \"validUntil\": \"2025-01-15T21:38:37+01:00\" }, \"customFields\": { \"memberName\": \"John Doe\" } }]`",
21+
optional: true,
22+
},
23+
email: {
24+
type: "string",
25+
label: "Email",
26+
description: "The email of the user",
27+
optional: true,
28+
},
29+
phone: {
30+
type: "string",
31+
label: "Phone",
32+
description: "The phone of the user",
33+
optional: true,
34+
},
35+
sendToEmail: {
36+
type: "boolean",
37+
label: "Send to Email",
38+
description: "Whether to send pass link via email",
39+
optional: true,
40+
},
41+
sendToPhone: {
42+
type: "boolean",
43+
label: "Send to Phone",
44+
description: "Whether to send pass link via phone messaging",
45+
optional: true,
46+
},
47+
locale: {
48+
type: "string",
49+
label: "Locale",
50+
description: "[ISO 639 language code](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) to display localized \"Add to Wallet\" badges, SMS and WhatsApp messages",
51+
optional: true,
52+
},
53+
},
54+
async run({ $ }) {
55+
const response = await this.walletap.createPass({
56+
$,
57+
data: {
58+
passes: parseObject(this.passes),
59+
email: this.email,
60+
phone: this.phone,
61+
sendToEmail: this.sendToEmail,
62+
sendToPhone: this.sendToPhone,
63+
locale: this.locale,
64+
},
65+
});
66+
67+
$.export("$summary", `Successfully created pass with id: ${response.id}`);
68+
return response;
69+
},
70+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import walletap from "../../walletap.app.mjs";
2+
3+
export default {
4+
key: "walletap-get-pass",
5+
name: "Get Pass",
6+
description: "Gets a Walletap pass by ID. [See the documentation](https://walletap.io/docs/api#tag/Pass/operation/getPass)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
walletap,
16+
passId: {
17+
type: "string",
18+
label: "Pass ID",
19+
description: "Internal pass ID or External pass ID",
20+
},
21+
},
22+
async run({ $ }) {
23+
const response = await this.walletap.getPass({
24+
$,
25+
params: {
26+
id: this.passId,
27+
},
28+
});
29+
30+
$.export("$summary", `Successfully updated pass with id: ${response.id}`);
31+
return response;
32+
},
33+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import walletap from "../../walletap.app.mjs";
2+
3+
export default {
4+
key: "walletap-send-notification",
5+
name: "Send Notification",
6+
description: "Sends a notification to all pass users. [See the documentation](https://walletap.io/docs/api#tag/Template/operation/sendNotification)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
walletap,
16+
title: {
17+
type: "string",
18+
label: "Title",
19+
description: "The title of the notification",
20+
},
21+
content: {
22+
type: "string",
23+
label: "Content",
24+
description: "The content of the notification",
25+
},
26+
},
27+
async run({ $ }) {
28+
const response = await this.walletap.sendNotification({
29+
$,
30+
data: {
31+
title: this.title,
32+
content: this.content,
33+
},
34+
});
35+
36+
$.export("$summary", "Successfully sent notification");
37+
return response;
38+
},
39+
};
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import walletap from "../../walletap.app.mjs";
3+
4+
export default {
5+
key: "walletap-update-pass",
6+
name: "Update Pass",
7+
description: "Updates an existing Walletap pass and pushes the updated pass to the user. [See the documentation](https://walletap.io/docs/api#tag/Pass/operation/updatePass)",
8+
version: "0.0.1",
9+
type: "action",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: false,
14+
},
15+
props: {
16+
walletap,
17+
passId: {
18+
type: "string",
19+
label: "Pass ID",
20+
description: "Walletap generated pass ID",
21+
},
22+
templateFields: {
23+
type: "object",
24+
label: "Template Fields",
25+
description: "The template fields to update. Generic (object) or Loyalty (object) or Gift Card (object) or Event Ticket (object) or Offer/Coupon (object)",
26+
optional: true,
27+
},
28+
memberId: {
29+
type: "string",
30+
label: "Member ID",
31+
description: "The ID connecting this pass to a member in your system",
32+
optional: true,
33+
},
34+
customFields: {
35+
type: "object",
36+
label: "Custom Fields",
37+
description: "Custom fields defined in pass design, using field IDs as object keys",
38+
optional: true,
39+
},
40+
redemptionValue: {
41+
type: "string",
42+
label: "Redemption Value",
43+
description: "Value to be encoded in barcode and/or NFC payload. If not provided, it is set to `externalId`. If also not provided, it is set to Walletap generated `id`",
44+
optional: true,
45+
},
46+
isValid: {
47+
type: "boolean",
48+
label: "Valid",
49+
description: "If set to `false` it invalidates the pass and moves it to the \"Expired passes\" section in user Wallet",
50+
optional: true,
51+
},
52+
email: {
53+
type: "string",
54+
label: "Email",
55+
description: "The email of the user",
56+
optional: true,
57+
},
58+
phone: {
59+
type: "string",
60+
label: "Phone",
61+
description: "The phone of the user",
62+
optional: true,
63+
},
64+
},
65+
async run({ $ }) {
66+
const response = await this.walletap.updatePass({
67+
$,
68+
data: {
69+
id: this.passId,
70+
templateFields: parseObject(this.templateFields),
71+
memberId: this.memberId,
72+
customFields: parseObject(this.customFields),
73+
redemptionValue: this.redemptionValue,
74+
isValid: this.isValid,
75+
email: this.email,
76+
phone: this.phone,
77+
},
78+
});
79+
80+
$.export("$summary", `Successfully updated pass with id: ${response.id}`);
81+
return response;
82+
},
83+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

components/walletap/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/walletap",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream WalleTap Components",
55
"main": "walletap.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}
Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,53 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "walletap",
46
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_apiUrl() {
9+
return "https://api.walletap.io";
10+
},
11+
_getHeaders() {
12+
return {
13+
"x-api-key": this.$auth.api_key,
14+
};
15+
},
16+
_makeRequest({
17+
$ = this, path, ...opts
18+
}) {
19+
return axios($, {
20+
url: `${this._apiUrl()}${path}`,
21+
headers: this._getHeaders(),
22+
...opts,
23+
});
24+
},
25+
createPass(args = {}) {
26+
return this._makeRequest({
27+
method: "POST",
28+
path: "/pass",
29+
...args,
30+
});
31+
},
32+
getPass(args = {}) {
33+
return this._makeRequest({
34+
path: "/pass",
35+
...args,
36+
});
37+
},
38+
updatePass(args = {}) {
39+
return this._makeRequest({
40+
method: "PATCH",
41+
path: "/pass",
42+
...args,
43+
});
44+
},
45+
sendNotification(args = {}) {
46+
return this._makeRequest({
47+
method: "POST",
48+
path: `/template/${this.$auth.template_id}/notification`,
49+
...args,
50+
});
951
},
1052
},
1153
};

0 commit comments

Comments
 (0)