Skip to content

Commit

Permalink
feat: added apitraffic piece
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonfill committed Sep 4, 2024
1 parent 38e8fab commit 9de9ff3
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 42 deletions.
4 changes: 0 additions & 4 deletions packages/pieces/apitraffic/package.json

This file was deleted.

33 changes: 0 additions & 33 deletions packages/pieces/apitraffic/src/lib/triggers/stream-view-match.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/pieces/community/apitraffic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@apitraffic/piece-apitraffic",
"version": "0.0.12"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const apitraffic = createPiece({
description : "",
auth: apiTrafficAuth,
minimumSupportedRelease: '0.20.0',
logoUrl: "https://cdn.prod.website-files.com/642032b99e732884123d5d3f/6448148357d70828c9842ada_apitraffic-logo.svg",
logoUrl: "https://cdn.apitraffic.io/images/icon-color-140x140.svg",
categories: [PieceCategory.DEVELOPER_TOOLS],
authors: ["jasonfill"],
actions: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {
) => {

const { apiToken } = auth;

const baseUrl = 'https://api-apitraffic-io-q90c9rjuvyay.apitraffic.io/v1';

let host = "api.apitraffic.io";

const baseUrl = `https://${host}/v1`;

const request: HttpRequest = {
method: method,
Expand Down Expand Up @@ -50,7 +52,7 @@ import {
};

export async function getUser(auth: ApiTrafficAuthType) {
const api = '/authentication/me';
const api = '/authentication/verify';

const apiReply = await apiTrafficAPI(auth, HttpMethod.GET, api, auth);
const response = {success: false, data: {}};
Expand All @@ -71,7 +73,7 @@ import {

export async function getBuckets(auth: ApiTrafficAuthType): Promise<GetBucketsResponse> {
const api = `/accounts/${auth.accountSid}/buckets`;
const apiReply = await apiTrafficAPI(auth, HttpMethod.GET, api, auth);
const apiReply = await apiTrafficAPI(auth, HttpMethod.GET, api);
const response = {success: false, data: []};

if(apiReply.success){
Expand All @@ -85,4 +87,18 @@ import {
export async function getStreamViews(auth: ApiTrafficAuthType, bucketSid: string) {
const api = `/accounts/${auth.accountSid}/buckets/${bucketSid}`;
return await apiTrafficAPI(auth, HttpMethod.GET, api, auth);
}
export async function updateWebhook(auth: ApiTrafficAuthType, url: string, enabled: boolean) {
const api = `/webhooks`;

const segments = url.split('/');
const externalWorkflowId = segments.pop();

const body = {
externalWorkflowId,
url,
enabled
};

return await apiTrafficAPI(auth, HttpMethod.PUT, api, body);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import { updateWebhook } from '../api';
import { apiTrafficAuth } from '../auth';

export const streamViewMatch = createTrigger({
auth: apiTrafficAuth,
name: 'streamViewMatch',
displayName: 'New Stream View Request',
description: 'Triggers when a request matches a stream view criteria.',
props: {},
sampleData: {},
type: TriggerStrategy.WEBHOOK,
async onEnable(context){
// implement webhook creation logic
const { auth, webhookUrl } = context;
//console.log('Start: ON ENABLE');
//console.log(store);
//console.log(auth);
//console.log(propsValue);
//console.log('End: ON ENABLE');

await updateWebhook(auth, webhookUrl, true);


},
async onDisable(context){
// implement webhook deletion logic
const { auth, webhookUrl } = context;
//console.log('Start: ON DISABLE');
//console.log(store);
//console.log(auth);
//console.log(propsValue);
//console.log('End: ON DISABLE');

await updateWebhook(auth, webhookUrl, false);
},
async run(context){
return [context.payload.body]
}
})
File renamed without changes.
3 changes: 3 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@
"@activepieces/ui/feature-templates": [
"packages/ui/feature-templates/src/index.ts"
],
"@apitraffic/piece-apitraffic": [
"packages/pieces/community/apitraffic/src/index.ts"
],
"@ee/*": ["packages/ee/*"],
"Aminos": ["packages/pieces/community/Aminos/src/index.ts"],
"ee-billing-ui": ["packages/ee/ui/billing/src/index.ts"],
Expand Down

0 comments on commit 9de9ff3

Please sign in to comment.