Skip to content

Commit cdd7fc0

Browse files
New Components - ikas (#12815)
* ikas init * [Components] ikas #12409 Sources - New Customer (Instant) - New Product (Instant) - New Order (Instant) * pnpm update * Update components/ikas/sources/common/base.mjs Co-authored-by: michelle0927 <[email protected]> * some adjusts * fix descriptions * add response data parse * fix test-events * fix test-events.mjs --------- Co-authored-by: michelle0927 <[email protected]> Co-authored-by: michelle0927 <[email protected]>
1 parent 5f95b69 commit cdd7fc0

File tree

10 files changed

+400
-7
lines changed

10 files changed

+400
-7
lines changed

components/ikas/ikas.app.mjs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "ikas",
4-
propDefinitions: {},
56
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
7+
_baseUrl() {
8+
return "https://api.myikas.com/api/v1/admin/graphql";
9+
},
10+
_headers() {
11+
return {
12+
"Content-Type": "application/json",
13+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
14+
};
15+
},
16+
makeRequest({
17+
$ = this, ...opts
18+
}) {
19+
return axios($, {
20+
method: "POST",
21+
url: this._baseUrl(),
22+
headers: this._headers(),
23+
...opts,
24+
});
925
},
1026
},
1127
};

components/ikas/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/ikas",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Ikas Components",
55
"main": "ikas.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.0"
1417
}
15-
}
18+
}
19+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import ikas from "../../ikas.app.mjs";
2+
3+
export default {
4+
props: {
5+
ikas,
6+
http: {
7+
type: "$.interface.http",
8+
customResponse: false,
9+
},
10+
db: "$.service.db",
11+
alert: {
12+
type: "alert",
13+
alertType: "warning",
14+
content: "Please note that you can have only one webhook of each type at the same time, any change will overwrite the current webhook configuration.",
15+
},
16+
},
17+
methods: {
18+
_getWebhookId() {
19+
return this.db.get("webhookId");
20+
},
21+
_setWebhookId(webhookId) {
22+
return this.db.set("webhookId", webhookId);
23+
},
24+
},
25+
hooks: {
26+
async activate() {
27+
const { data } = await this.ikas.makeRequest({
28+
data: {
29+
"query": `mutation {
30+
saveWebhook(
31+
input: {
32+
scopes: "${this.getScope()}"
33+
endpoint: "${this.http.endpoint}"
34+
}
35+
) {
36+
createdAt
37+
deleted
38+
endpoint
39+
id
40+
scope
41+
updatedAt
42+
}
43+
}`,
44+
},
45+
});
46+
this._setWebhookId(data.saveWebhook[0].id);
47+
},
48+
async deactivate() {
49+
const webhookId = this._getWebhookId();
50+
if (webhookId) {
51+
await this.ikas.makeRequest({
52+
data: {
53+
"query": `mutation {
54+
deleteWebhook(scopes: ["${this.getScope()}"])
55+
}`,
56+
},
57+
});
58+
}
59+
},
60+
},
61+
async run({ body }) {
62+
const data = JSON.parse(body.data);
63+
body.data = data;
64+
65+
this.$emit(body, {
66+
id: body.id,
67+
summary: this.getSummary(data),
68+
ts: Date.parse(body.createdAt),
69+
});
70+
},
71+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "ikas-new-customer-instant",
7+
name: "New Customer (Instant)",
8+
description: "Emit new event when a customer account is created on ikas. **You can only have one webhook of each type at the same time.**",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getScope() {
15+
return "store/customer/created";
16+
},
17+
getSummary(data) {
18+
return `New customer created with Id: ${data.id}.`;
19+
},
20+
},
21+
sampleEmit,
22+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
export default {
2+
"authorizedAppId": "12345678-1234-1234-1234-123456789012",
3+
"createdAt": "2024-07-11T19:06:04.736Z",
4+
"data": {
5+
"createdAt": "2024-07-11T19:04:19.158Z",
6+
"updatedAt": "2024-07-11T19:04:19.158Z",
7+
"merchantId": "12345678-1234-1234-1234-123456789012",
8+
"deleted": false,
9+
"firstName": "Customer ",
10+
"lastName": "Test",
11+
"fullName": "Customer Test",
12+
"email": "[email protected]",
13+
"isEmailVerified": false,
14+
"attributes": null,
15+
"phone": null,
16+
"isPhoneVerified": false,
17+
"addresses": [],
18+
"note": null,
19+
"accountStatus": null,
20+
"subscriptionStatus": "NOT_SUBSCRIBED",
21+
"smsSubscriptionStatus": null,
22+
"phoneSubscriptionStatus": null,
23+
"tagIds": null,
24+
"customerGroupIds": null,
25+
"preferredLanguage": null,
26+
"b2bStatus": null,
27+
"priceListRules": null,
28+
"priceListId": null,
29+
"isEmailBounced": false,
30+
"customerSegmentIds": [],
31+
"gender": null,
32+
"birthDate": null,
33+
"customerSequence": 1,
34+
"id": "12345678-1234-1234-1234-123456789012",
35+
},
36+
"id": "12345678-1234-1234-1234-123456789012-12345678-1234-1234-1234-123456789012",
37+
"merchantId": "12345678-1234-1234-1234-123456789012",
38+
"scope": "store/customer/created",
39+
"signature": "373045525decbad86b3a09f4bac07cd2a6611801c8a2c9ec9be4973be269a522",
40+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "ikas-new-order-instant",
7+
name: "New Order Created (Instant)",
8+
description: "Emit new event when a new order is created on ikas. **You can only have one webhook of each type at the same time.**",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getScope() {
15+
return "store/order/created";
16+
},
17+
getSummary(data) {
18+
return `New order created with Id: ${data.id}.`;
19+
},
20+
},
21+
sampleEmit,
22+
};
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
export default {
2+
"authorizedAppId": "12345678-1234-1234-1234-123456789012",
3+
"createdAt": "2024-07-11T19:06:04.736Z",
4+
"data": {
5+
"createdAt": "2024-07-11T21:22:48.992Z",
6+
"updatedAt": "2024-07-11T21:23:16.543Z",
7+
"merchantId": "12345678-1234-1234-1234-123456789012",
8+
"deleted": false,
9+
"billingAddress": null,
10+
"cartId": "12345678-1234-1234-1234-123456789012",
11+
"cartStatus": 2,
12+
"checkoutId": "12345678-1234-1234-1234-123456789012",
13+
"availableShippingMethods": [],
14+
"createdBy": 2,
15+
"campaignOffers": [],
16+
"clientIp": "123.123.12.12",
17+
"currencyCode": "USD",
18+
"currencyRates": [],
19+
"customer": {
20+
"id": "12345678-1234-1234-1234-123456789012",
21+
"firstName": "Customer",
22+
"lastName": "Test",
23+
"fullName": "Customer Test",
24+
"email": "[email protected]",
25+
"notificationsAccepted": false,
26+
"isGuestCheckout": true,
27+
"lastOrderDate": null,
28+
},
29+
"dueDate": "2024-07-11T21:23:16.377Z",
30+
"itemCount": 1,
31+
"note": null,
32+
"giftPackageLines": [],
33+
"orderLineItems": [
34+
{
35+
"createdAt": "2024-07-11T21:23:16.543Z",
36+
"updatedAt": "2024-07-11T21:23:16.543Z",
37+
"deleted": false,
38+
"price": 123,
39+
"discountPrice": null,
40+
"finalPrice": 123,
41+
"taxValue": null,
42+
"quantity": 1,
43+
"currencyCode": "USD",
44+
"discount": null,
45+
"variant": {
46+
"id": "12345678-1234-1234-1234-123456789012",
47+
"productId": "12345678-1234-1234-1234-123456789012",
48+
"name": "product test",
49+
"barcodeList": [],
50+
"variantValues": [],
51+
"slug": "product-test",
52+
"tagIds": [],
53+
"tags": [],
54+
"prices": [
55+
{
56+
"sellPrice": 123,
57+
},
58+
],
59+
"type": 1,
60+
"categories": [],
61+
},
62+
"status": "UNFULFILLED",
63+
"sourceId": null,
64+
"id": "12345678-1234-1234-1234-123456789012",
65+
},
66+
],
67+
"orderNumber": "1001",
68+
"orderedAt": "2024-07-11T21:22:48.993Z",
69+
"priceListId": null,
70+
"salesChannelId": "ADMIN",
71+
"shippingAddress": null,
72+
"shippingMethod": "SHIPMENT",
73+
"storefrontRouting": null,
74+
"totalFinalPrice": 123,
75+
"netTotalFinalPrice": 123,
76+
"totalPrice": 123,
77+
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
78+
"taxLines": [],
79+
"attributes": [],
80+
"branchSession": null,
81+
"branchSessionId": null,
82+
"invoices": [],
83+
"orderPackages": [],
84+
"orderPaymentStatus": "WAITING",
85+
"orderTagIds": null,
86+
"paymentMethods": [],
87+
"priceList": null,
88+
"salesChannel": {
89+
"id": "ADMIN",
90+
"name": "ADMIN",
91+
"type": 6,
92+
},
93+
"status": "DRAFT",
94+
"storefront": null,
95+
"storefrontTheme": null,
96+
"terminalId": null,
97+
"sourceId": null,
98+
"archived": false,
99+
"orderSequence": 1,
100+
"id": "12345678-1234-1234-1234-123456789012",
101+
},
102+
"id": "12345678-1234-1234-1234-123456789012-12345678-1234-1234-1234-123456789012",
103+
"merchantId": "12345678-1234-1234-1234-123456789012",
104+
"scope": "store/order/created",
105+
"signature": "373045525decbad86b3a09f4bac07cd2a6611801c8a2c9ec9be4973be269a522",
106+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "ikas-new-product-instant",
7+
name: "New Product Created (Instant)",
8+
description: "Emit new event when a product is created on ikas. **You can only have one webhook of each type at the same time.**",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getScope() {
15+
return "store/product/created";
16+
},
17+
getSummary(data) {
18+
return `New product created with Id: ${data.id}.`;
19+
},
20+
},
21+
sampleEmit,
22+
};

0 commit comments

Comments
 (0)