File tree Expand file tree Collapse file tree 9 files changed +229
-20
lines changed
Expand file tree Collapse file tree 9 files changed +229
-20
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11{
22 "name" : " @pipedream/scalr" ,
3- "version" : " 0.0.2 " ,
3+ "version" : " 0.1.0 " ,
44 "description" : " Pipedream Scalr Components" ,
5- "main" : " dist/app/ scalr.app.mjs" ,
5+ "main" : " scalr.app.mjs" ,
66 "keywords" : [
77 " pipedream" ,
88 " scalr"
99 ],
10- "files" : [" dist" ],
1110 "homepage" : " https://pipedream.com/apps/scalr" ,
1211 "author" : " Pipedream <support@pipedream.com> (https://pipedream.com/)" ,
1312 "publishConfig" : {
1413 "access" : " public"
14+ },
15+ "dependencies" : {
16+ "@pipedream/platform" : " ^3.0.3"
1517 }
1618}
Original file line number Diff line number Diff line change 1+ import { axios } from "@pipedream/platform" ;
2+
3+ export default {
4+ type : "app" ,
5+ app : "scalr" ,
6+ propDefinitions : {
7+ accountId : {
8+ type : "string" ,
9+ label : "Account ID" ,
10+ description : "The ID of the account you wish to use." ,
11+ async options ( { page } ) {
12+ const { data : accounts } = await this . getAccounts ( {
13+ params : {
14+ "page[number]" : page + 1 ,
15+ } ,
16+ } ) ;
17+ return accounts . map ( ( account ) => ( {
18+ label : account . attributes . name ,
19+ value : account . id ,
20+ } ) ) ;
21+ } ,
22+ } ,
23+ } ,
24+ methods : {
25+ _baseUrl ( ) {
26+ return `https://${ this . $auth . domain } .scalr.io/api/iacp/v3` ;
27+ } ,
28+ async _makeRequest ( opts = { } ) {
29+ const {
30+ $ = this ,
31+ path,
32+ headers,
33+ ...otherOpts
34+ } = opts ;
35+ return axios ( $ , {
36+ ...otherOpts ,
37+ url : this . _baseUrl ( ) + path ,
38+ headers : {
39+ "Authorization" : `Bearer ${ this . $auth . api_token } ` ,
40+ "Content-type" : "application/vnd.api+json" ,
41+ ...headers ,
42+ } ,
43+ } ) ;
44+ } ,
45+ async createWebhook ( { ...args } ) {
46+ return this . _makeRequest ( {
47+ path : "/integrations/webhooks" ,
48+ method : "post" ,
49+ ...args ,
50+ } ) ;
51+ } ,
52+ async removeWebhook ( webhookId ) {
53+ return this . _makeRequest ( {
54+ path : `/integrations/webhooks/${ webhookId } ` ,
55+ method : "delete" ,
56+ } ) ;
57+ } ,
58+ async getAccounts ( args = { } ) {
59+ return this . _makeRequest ( {
60+ path : "/accounts" ,
61+ ...args ,
62+ } ) ;
63+ } ,
64+ } ,
65+ } ;
Original file line number Diff line number Diff line change 1+ import scalr from "../../scalr.app.mjs" ;
2+
3+ export default {
4+ props : {
5+ scalr,
6+ db : "$.service.db" ,
7+ http : "$.interface.http" ,
8+ accountId : {
9+ propDefinition : [
10+ scalr ,
11+ "accountId" ,
12+ ] ,
13+ } ,
14+ } ,
15+ methods : {
16+ _getWebhookId ( ) {
17+ return this . db . get ( "webhookId" ) ;
18+ } ,
19+ _setWebhookId ( webhookId ) {
20+ this . db . set ( "webhookId" , webhookId ) ;
21+ } ,
22+ getWebhookEventType ( ) {
23+ throw new Error ( "getWebhookEventType is not implemented" ) ;
24+ } ,
25+ emitEvent ( event ) {
26+ throw new Error ( "emitEvent is not implemented" , event ) ;
27+ } ,
28+ } ,
29+ hooks : {
30+ async activate ( ) {
31+ const { data } = await this . scalr . createWebhook ( {
32+ data : {
33+ "data" : {
34+ "attributes" : {
35+ "max-attempts" : 3 ,
36+ "timeout" : 15 ,
37+ "name" : "Webhook Pipedream - " + new Date ( ) . toISOString ( ) ,
38+ "url" : this . http . endpoint ,
39+ } ,
40+ "relationships" : {
41+ "account" : {
42+ "data" : {
43+ "type" : "accounts" ,
44+ "id" : this . accountId ,
45+ } ,
46+ } ,
47+ "events" : {
48+ "data" : [
49+ {
50+ "type" : "event-definitions" ,
51+ "id" : this . getWebhookEventType ( ) ,
52+ } ,
53+ ] ,
54+ } ,
55+ } ,
56+ "type" : "webhook-integrations" ,
57+ } ,
58+ } ,
59+ } ) ;
60+ this . _setWebhookId ( data . id ) ;
61+ } ,
62+ async deactivate ( ) {
63+ const webhookId = this . _getWebhookId ( ) ;
64+ await this . scalr . removeWebhook ( webhookId ) ;
65+ } ,
66+ } ,
67+ async run ( event ) {
68+ await this . emitEvent ( event . body ) ;
69+ } ,
70+ } ;
Original file line number Diff line number Diff line change 1+ import common from "../common/common.mjs" ;
2+
3+ export default {
4+ ...common ,
5+ name : "New Run Completed (Instant)" ,
6+ version : "0.0.1" ,
7+ key : "scalr-new-run-completed" ,
8+ description : "Emit new event on each new completed run. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)" ,
9+ type : "source" ,
10+ dedupe : "unique" ,
11+ hooks : {
12+ ...common . hooks ,
13+ } ,
14+ methods : {
15+ ...common . methods ,
16+ getWebhookEventType ( ) {
17+ return "run:completed" ;
18+ } ,
19+ async emitEvent ( data ) {
20+
21+ this . $emit ( data , {
22+ id : data . run . id ,
23+ summary : `New run completed with ID ${ data . run . id } ` ,
24+ ts : Date . parse ( data . run [ "created-at" ] ) ,
25+ } ) ;
26+ } ,
27+ } ,
28+ } ;
Original file line number Diff line number Diff line change 1+ import common from "../common/common.mjs" ;
2+
3+ export default {
4+ ...common ,
5+ name : "New Run Errored (Instant)" ,
6+ version : "0.0.1" ,
7+ key : "scalr-new-run-errored" ,
8+ description : "Emit new event when a new run encountered an error. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)" ,
9+ type : "source" ,
10+ dedupe : "unique" ,
11+ hooks : {
12+ ...common . hooks ,
13+ } ,
14+ methods : {
15+ ...common . methods ,
16+ getWebhookEventType ( ) {
17+ return "run:errored" ;
18+ } ,
19+ async emitEvent ( data ) {
20+
21+ this . $emit ( data , {
22+ id : data . run . id ,
23+ summary : `New run completed with ID ${ data . run . id } ` ,
24+ ts : Date . parse ( data . run [ "created-at" ] ) ,
25+ } ) ;
26+ } ,
27+ } ,
28+ } ;
Original file line number Diff line number Diff line change 1+ import common from "../common/common.mjs" ;
2+
3+ export default {
4+ ...common ,
5+ name : "New Run Needs Attention (Instant)" ,
6+ version : "0.0.1" ,
7+ key : "scalr-new-run-needs-attention" ,
8+ description : "Emit new event when a new run needs attention. [See the documentation](https://docs.scalr.io/reference/create_webhook_integration)" ,
9+ type : "source" ,
10+ dedupe : "unique" ,
11+ hooks : {
12+ ...common . hooks ,
13+ } ,
14+ methods : {
15+ ...common . methods ,
16+ getWebhookEventType ( ) {
17+ return "run:needs_attention" ;
18+ } ,
19+ async emitEvent ( data ) {
20+
21+ this . $emit ( data , {
22+ id : data . run . id ,
23+ summary : `New run with ID ${ data . run . id } needs attention` ,
24+ ts : Date . parse ( data . run [ "created-at" ] ) ,
25+ } ) ;
26+ } ,
27+ } ,
28+ } ;
You can’t perform that action at this time.
0 commit comments