diff --git a/components/ikas/ikas.app.mjs b/components/ikas/ikas.app.mjs index 1f4ecadd57a42..80efc0a056b37 100644 --- a/components/ikas/ikas.app.mjs +++ b/components/ikas/ikas.app.mjs @@ -1,11 +1,27 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "ikas", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.myikas.com/api/v1/admin/graphql"; + }, + _headers() { + return { + "Content-Type": "application/json", + "Authorization": `Bearer ${this.$auth.oauth_access_token}`, + }; + }, + makeRequest({ + $ = this, ...opts + }) { + return axios($, { + method: "POST", + url: this._baseUrl(), + headers: this._headers(), + ...opts, + }); }, }, }; diff --git a/components/ikas/package.json b/components/ikas/package.json index dd8e408c9baed..067e330b4bbc6 100644 --- a/components/ikas/package.json +++ b/components/ikas/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/ikas", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Ikas Components", "main": "ikas.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.0" } -} \ No newline at end of file +} + diff --git a/components/ikas/sources/common/base.mjs b/components/ikas/sources/common/base.mjs new file mode 100644 index 0000000000000..568ef6c72766b --- /dev/null +++ b/components/ikas/sources/common/base.mjs @@ -0,0 +1,71 @@ +import ikas from "../../ikas.app.mjs"; + +export default { + props: { + ikas, + http: { + type: "$.interface.http", + customResponse: false, + }, + db: "$.service.db", + alert: { + type: "alert", + alertType: "warning", + 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.", + }, + }, + methods: { + _getWebhookId() { + return this.db.get("webhookId"); + }, + _setWebhookId(webhookId) { + return this.db.set("webhookId", webhookId); + }, + }, + hooks: { + async activate() { + const { data } = await this.ikas.makeRequest({ + data: { + "query": `mutation { + saveWebhook( + input: { + scopes: "${this.getScope()}" + endpoint: "${this.http.endpoint}" + } + ) { + createdAt + deleted + endpoint + id + scope + updatedAt + } + }`, + }, + }); + this._setWebhookId(data.saveWebhook[0].id); + }, + async deactivate() { + const webhookId = this._getWebhookId(); + if (webhookId) { + await this.ikas.makeRequest({ + data: { + "query": `mutation { + deleteWebhook(scopes: ["${this.getScope()}"]) + }`, + }, + }); + } + }, + }, + async run({ body }) { + const data = JSON.parse(body.data); + body.data = data; + + this.$emit(body, { + id: body.id, + summary: this.getSummary(data), + ts: Date.parse(body.createdAt), + }); + }, +}; diff --git a/components/ikas/sources/new-customer-instant/new-customer-instant.mjs b/components/ikas/sources/new-customer-instant/new-customer-instant.mjs new file mode 100644 index 0000000000000..6ba59639614e9 --- /dev/null +++ b/components/ikas/sources/new-customer-instant/new-customer-instant.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "ikas-new-customer-instant", + name: "New Customer (Instant)", + 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.**", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getScope() { + return "store/customer/created"; + }, + getSummary(data) { + return `New customer created with Id: ${data.id}.`; + }, + }, + sampleEmit, +}; diff --git a/components/ikas/sources/new-customer-instant/test-event.mjs b/components/ikas/sources/new-customer-instant/test-event.mjs new file mode 100644 index 0000000000000..2fc4ba0521e1e --- /dev/null +++ b/components/ikas/sources/new-customer-instant/test-event.mjs @@ -0,0 +1,40 @@ +export default { + "authorizedAppId": "12345678-1234-1234-1234-123456789012", + "createdAt": "2024-07-11T19:06:04.736Z", + "data": { + "createdAt": "2024-07-11T19:04:19.158Z", + "updatedAt": "2024-07-11T19:04:19.158Z", + "merchantId": "12345678-1234-1234-1234-123456789012", + "deleted": false, + "firstName": "Customer ", + "lastName": "Test", + "fullName": "Customer Test", + "email": "customer@test.com", + "isEmailVerified": false, + "attributes": null, + "phone": null, + "isPhoneVerified": false, + "addresses": [], + "note": null, + "accountStatus": null, + "subscriptionStatus": "NOT_SUBSCRIBED", + "smsSubscriptionStatus": null, + "phoneSubscriptionStatus": null, + "tagIds": null, + "customerGroupIds": null, + "preferredLanguage": null, + "b2bStatus": null, + "priceListRules": null, + "priceListId": null, + "isEmailBounced": false, + "customerSegmentIds": [], + "gender": null, + "birthDate": null, + "customerSequence": 1, + "id": "12345678-1234-1234-1234-123456789012", + }, + "id": "12345678-1234-1234-1234-123456789012-12345678-1234-1234-1234-123456789012", + "merchantId": "12345678-1234-1234-1234-123456789012", + "scope": "store/customer/created", + "signature": "373045525decbad86b3a09f4bac07cd2a6611801c8a2c9ec9be4973be269a522", +}; diff --git a/components/ikas/sources/new-order-instant/new-order-instant.mjs b/components/ikas/sources/new-order-instant/new-order-instant.mjs new file mode 100644 index 0000000000000..23f920cd3f754 --- /dev/null +++ b/components/ikas/sources/new-order-instant/new-order-instant.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "ikas-new-order-instant", + name: "New Order Created (Instant)", + 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.**", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getScope() { + return "store/order/created"; + }, + getSummary(data) { + return `New order created with Id: ${data.id}.`; + }, + }, + sampleEmit, +}; diff --git a/components/ikas/sources/new-order-instant/test-event.mjs b/components/ikas/sources/new-order-instant/test-event.mjs new file mode 100644 index 0000000000000..d79edf2d4ef1a --- /dev/null +++ b/components/ikas/sources/new-order-instant/test-event.mjs @@ -0,0 +1,106 @@ +export default { + "authorizedAppId": "12345678-1234-1234-1234-123456789012", + "createdAt": "2024-07-11T19:06:04.736Z", + "data": { + "createdAt": "2024-07-11T21:22:48.992Z", + "updatedAt": "2024-07-11T21:23:16.543Z", + "merchantId": "12345678-1234-1234-1234-123456789012", + "deleted": false, + "billingAddress": null, + "cartId": "12345678-1234-1234-1234-123456789012", + "cartStatus": 2, + "checkoutId": "12345678-1234-1234-1234-123456789012", + "availableShippingMethods": [], + "createdBy": 2, + "campaignOffers": [], + "clientIp": "123.123.12.12", + "currencyCode": "USD", + "currencyRates": [], + "customer": { + "id": "12345678-1234-1234-1234-123456789012", + "firstName": "Customer", + "lastName": "Test", + "fullName": "Customer Test", + "email": "customer@test.com", + "notificationsAccepted": false, + "isGuestCheckout": true, + "lastOrderDate": null, + }, + "dueDate": "2024-07-11T21:23:16.377Z", + "itemCount": 1, + "note": null, + "giftPackageLines": [], + "orderLineItems": [ + { + "createdAt": "2024-07-11T21:23:16.543Z", + "updatedAt": "2024-07-11T21:23:16.543Z", + "deleted": false, + "price": 123, + "discountPrice": null, + "finalPrice": 123, + "taxValue": null, + "quantity": 1, + "currencyCode": "USD", + "discount": null, + "variant": { + "id": "12345678-1234-1234-1234-123456789012", + "productId": "12345678-1234-1234-1234-123456789012", + "name": "product test", + "barcodeList": [], + "variantValues": [], + "slug": "product-test", + "tagIds": [], + "tags": [], + "prices": [ + { + "sellPrice": 123, + }, + ], + "type": 1, + "categories": [], + }, + "status": "UNFULFILLED", + "sourceId": null, + "id": "12345678-1234-1234-1234-123456789012", + }, + ], + "orderNumber": "1001", + "orderedAt": "2024-07-11T21:22:48.993Z", + "priceListId": null, + "salesChannelId": "ADMIN", + "shippingAddress": null, + "shippingMethod": "SHIPMENT", + "storefrontRouting": null, + "totalFinalPrice": 123, + "netTotalFinalPrice": 123, + "totalPrice": 123, + "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36", + "taxLines": [], + "attributes": [], + "branchSession": null, + "branchSessionId": null, + "invoices": [], + "orderPackages": [], + "orderPaymentStatus": "WAITING", + "orderTagIds": null, + "paymentMethods": [], + "priceList": null, + "salesChannel": { + "id": "ADMIN", + "name": "ADMIN", + "type": 6, + }, + "status": "DRAFT", + "storefront": null, + "storefrontTheme": null, + "terminalId": null, + "sourceId": null, + "archived": false, + "orderSequence": 1, + "id": "12345678-1234-1234-1234-123456789012", + }, + "id": "12345678-1234-1234-1234-123456789012-12345678-1234-1234-1234-123456789012", + "merchantId": "12345678-1234-1234-1234-123456789012", + "scope": "store/order/created", + "signature": "373045525decbad86b3a09f4bac07cd2a6611801c8a2c9ec9be4973be269a522", +}; diff --git a/components/ikas/sources/new-product-instant/new-product-instant.mjs b/components/ikas/sources/new-product-instant/new-product-instant.mjs new file mode 100644 index 0000000000000..d352592a74739 --- /dev/null +++ b/components/ikas/sources/new-product-instant/new-product-instant.mjs @@ -0,0 +1,22 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "ikas-new-product-instant", + name: "New Product Created (Instant)", + description: "Emit new event when a product is created on ikas. **You can only have one webhook of each type at the same time.**", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getScope() { + return "store/product/created"; + }, + getSummary(data) { + return `New product created with Id: ${data.id}.`; + }, + }, + sampleEmit, +}; diff --git a/components/ikas/sources/new-product-instant/test-event.mjs b/components/ikas/sources/new-product-instant/test-event.mjs new file mode 100644 index 0000000000000..55b02a0b17053 --- /dev/null +++ b/components/ikas/sources/new-product-instant/test-event.mjs @@ -0,0 +1,87 @@ +export default { + "authorizedAppId": "12345678-1234-1234-1234-123456789012", + "createdAt": "2024-07-11T19:06:04.736Z", + "data": { + "deleted": false, + "name": "product test", + "shortDescription": null, + "weight": null, + "maxQuantityPerCart": null, + "groupVariantsByVariantTypeId": null, + "type": "PHYSICAL", + "productVariantTypes": [], + "categoryIds": null, + "variants": [ + { + "deleted": false, + "sku": null, + "barcodeList": null, + "weight": null, + "isActive": true, + "sellIfOutOfStock": null, + "images": null, + "prices": [ + { + "sellPrice": 123, + "discountPrice": null, + "buyPrice": null, + "currency": null, + "priceListId": null, + }, + ], + "hsCode": null, + "unit": null, + "bundleSettings": null, + "fileId": null, + "id": "12345678-1234-1234-1234-123456789012", + }, + ], + "attributes": [], + "tagIds": null, + "brandId": null, + "vendorId": null, + "metaData": { + "deleted": false, + "slug": "product-test", + "pageTitle": "product test", + "canonicals": null, + "disableIndex": null, + "targetType": 1, + "targetId": "12345678-1234-1234-1234-123456789012", + "metadataOverrides": null, + "id": "12345678-1234-1234-1234-123456789012", + }, + "salesChannels": [ + { + "id": "12345678-1234-1234-1234-123456789012", + "status": 1, + "maxQuantityPerCart": null, + "minQuantityPerCart": null, + "quantitySettings": null, + "productVolumeDiscountId": null, + }, + { + "id": "12345678-1234-1234-1234-123456789012", + "status": 1, + "maxQuantityPerCart": null, + "minQuantityPerCart": null, + "quantitySettings": null, + "productVolumeDiscountId": null, + }, + ], + "productOptionSetId": null, + "baseUnit": null, + "googleTaxonomyId": null, + "dynamicPriceListIds": null, + "productVolumeDiscountId": null, + "brand": null, + "id": "12345678-1234-1234-1234-123456789012", + "createdAt": "2024-07-11T21:20:50.506Z", + "updatedAt": "2024-07-11T21:20:50.506Z", + "merchantId": "12345678-1234-1234-1234-123456789012", + }, + "id": "12345678-1234-1234-1234-123456789012-12345678-1234-1234-1234-123456789012", + "merchantId": "12345678-1234-1234-1234-123456789012", + "scope": "store/product/created", + "signature": "373045525decbad86b3a09f4bac07cd2a6611801c8a2c9ec9be4973be269a522", +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 342337b599d8c..61266f6a7e994 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4355,7 +4355,10 @@ importers: '@pipedream/platform': 0.10.0 components/ikas: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.0 + dependencies: + '@pipedream/platform': 3.0.0 components/ikigai: specifiers: {}