@rooted-software/piece-sitestacker-http-request 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ export declare const siteStackerAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
+ secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
4
+ }>;
5
+ export declare const siteStackerHttpRequest: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
6
+ accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
7
+ secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
8
+ }>>;
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.siteStackerHttpRequest = exports.siteStackerAuth = void 0;
4
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
5
+ const send_request_1 = require("./lib/actions/send-request");
6
+ exports.siteStackerAuth = pieces_framework_1.PieceAuth.CustomAuth({
7
+ description: 'SiteStacker HMAC API authentication credentials',
8
+ required: true,
9
+ props: {
10
+ accessKeyId: pieces_framework_1.Property.ShortText({
11
+ displayName: 'Access Key ID',
12
+ description: 'Found in Users component > right-click user > API Access',
13
+ required: true,
14
+ }),
15
+ secretAccessKey: pieces_framework_1.PieceAuth.SecretText({
16
+ displayName: 'Secret Access Key',
17
+ description: 'The secret key generated alongside the Access Key ID',
18
+ required: true,
19
+ }),
20
+ },
21
+ });
22
+ exports.siteStackerHttpRequest = (0, pieces_framework_1.createPiece)({
23
+ displayName: 'SiteStacker HTTP Request',
24
+ description: 'Send HTTP requests with automatic SiteStacker HMAC authentication',
25
+ auth: exports.siteStackerAuth,
26
+ minimumSupportedRelease: '0.20.3',
27
+ logoUrl: 'https://cdn.activepieces.com/pieces/http.png',
28
+ authors: [],
29
+ actions: [send_request_1.sendRequest],
30
+ triggers: [],
31
+ });
@@ -0,0 +1,13 @@
1
+ import { HttpMethod } from '@activepieces/pieces-common';
2
+ export declare const sendRequest: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
3
+ accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
4
+ secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
5
+ }>, {
6
+ method: import("@activepieces/pieces-framework").StaticDropdownProperty<HttpMethod, true>;
7
+ url: import("@activepieces/pieces-framework").ShortTextProperty<true>;
8
+ headers: import("@activepieces/pieces-framework").ObjectProperty<false>;
9
+ body_type: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
10
+ body: import("@activepieces/pieces-framework").JsonProperty<false>;
11
+ body_raw: import("@activepieces/pieces-framework").LongTextProperty<false>;
12
+ timeout: import("@activepieces/pieces-framework").NumberProperty<false>;
13
+ }>;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.sendRequest = void 0;
37
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
38
+ const pieces_common_1 = require("@activepieces/pieces-common");
39
+ const crypto = __importStar(require("crypto"));
40
+ const index_1 = require("../../index");
41
+ function formatDateRFC2616(date) {
42
+ return date.toUTCString().replace('GMT', '+0000');
43
+ }
44
+ function computeHmacSignature(secretKey, method, contentType, dateStr) {
45
+ const stringToSign = `${method}\n${contentType}\n${dateStr}`;
46
+ return crypto.createHmac('sha256', secretKey).update(stringToSign).digest('hex');
47
+ }
48
+ exports.sendRequest = (0, pieces_framework_1.createAction)({
49
+ auth: index_1.siteStackerAuth,
50
+ name: 'send_sitestacker_request',
51
+ displayName: 'Send Request',
52
+ description: 'Send an HTTP request with automatic SiteStacker HMAC authentication',
53
+ props: {
54
+ method: pieces_framework_1.Property.StaticDropdown({
55
+ displayName: 'Method',
56
+ required: true,
57
+ defaultValue: pieces_common_1.HttpMethod.GET,
58
+ options: {
59
+ disabled: false,
60
+ options: [
61
+ { label: 'GET', value: pieces_common_1.HttpMethod.GET },
62
+ { label: 'POST', value: pieces_common_1.HttpMethod.POST },
63
+ { label: 'PUT', value: pieces_common_1.HttpMethod.PUT },
64
+ { label: 'PATCH', value: pieces_common_1.HttpMethod.PATCH },
65
+ { label: 'DELETE', value: pieces_common_1.HttpMethod.DELETE },
66
+ ],
67
+ },
68
+ }),
69
+ url: pieces_framework_1.Property.ShortText({
70
+ displayName: 'URL',
71
+ description: 'The full URL to send the request to',
72
+ required: true,
73
+ }),
74
+ headers: pieces_framework_1.Property.Object({
75
+ displayName: 'Headers',
76
+ description: 'Additional headers to include. Authorization, Date/ss-date are set automatically.',
77
+ required: false,
78
+ }),
79
+ body_type: pieces_framework_1.Property.StaticDropdown({
80
+ displayName: 'Body Type',
81
+ required: true,
82
+ defaultValue: 'none',
83
+ options: {
84
+ disabled: false,
85
+ options: [
86
+ { label: 'None', value: 'none' },
87
+ { label: 'JSON', value: 'json' },
88
+ { label: 'Form Data', value: 'form_data' },
89
+ { label: 'Raw', value: 'raw' },
90
+ ],
91
+ },
92
+ }),
93
+ body: pieces_framework_1.Property.Json({
94
+ displayName: 'Body (JSON)',
95
+ description: 'Request body when Body Type is JSON',
96
+ required: false,
97
+ }),
98
+ body_raw: pieces_framework_1.Property.LongText({
99
+ displayName: 'Body (Raw)',
100
+ description: 'Request body when Body Type is Raw',
101
+ required: false,
102
+ }),
103
+ timeout: pieces_framework_1.Property.Number({
104
+ displayName: 'Timeout (seconds)',
105
+ required: false,
106
+ defaultValue: 30,
107
+ }),
108
+ },
109
+ async run(context) {
110
+ const { method, url, headers, body_type, body, body_raw, timeout } = context.propsValue;
111
+ const accessKeyId = context.auth.props['accessKeyId'];
112
+ const secretAccessKey = context.auth.props['secretAccessKey'];
113
+ const now = new Date();
114
+ const dateStr = formatDateRFC2616(now);
115
+ // Determine content type from body type
116
+ let contentType = '';
117
+ let requestBody = undefined;
118
+ switch (body_type) {
119
+ case 'json':
120
+ contentType = 'application/json';
121
+ requestBody = body;
122
+ break;
123
+ case 'form_data':
124
+ contentType = 'application/x-www-form-urlencoded';
125
+ requestBody = body;
126
+ break;
127
+ case 'raw':
128
+ contentType = 'text/plain';
129
+ requestBody = body_raw;
130
+ break;
131
+ default:
132
+ contentType = '';
133
+ requestBody = undefined;
134
+ }
135
+ // Compute HMAC signature
136
+ const signature = computeHmacSignature(secretAccessKey, method, contentType, dateStr);
137
+ const authorization = `HMAC ${accessKeyId}:${signature}`;
138
+ // Build final headers
139
+ const userHeaders = headers ?? {};
140
+ const hasUserDateHeader = Object.keys(userHeaders).some((k) => k.toLowerCase() === 'date');
141
+ const finalHeaders = {
142
+ ...userHeaders,
143
+ Authorization: authorization,
144
+ };
145
+ if (contentType) {
146
+ finalHeaders['Content-Type'] = contentType;
147
+ }
148
+ // Use ss-date if user already set a Date header, otherwise set Date
149
+ if (hasUserDateHeader) {
150
+ finalHeaders['ss-date'] = dateStr;
151
+ }
152
+ else {
153
+ finalHeaders['Date'] = dateStr;
154
+ }
155
+ const request = {
156
+ method,
157
+ url,
158
+ headers: finalHeaders,
159
+ body: requestBody,
160
+ timeout: timeout ? timeout * 1000 : 30000,
161
+ };
162
+ const response = await pieces_common_1.httpClient.sendRequest(request);
163
+ return {
164
+ status: response.status,
165
+ headers: response.headers,
166
+ body: response.body,
167
+ };
168
+ },
169
+ });
package/package.json CHANGED
@@ -1,8 +1,17 @@
1
1
  {
2
2
  "name": "@rooted-software/piece-sitestacker-http-request",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "HTTP request piece with SiteStacker HMAC authentication",
5
- "main": "src/index.ts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "commonjs",
8
+ "scripts": {
9
+ "build": "tsc"
10
+ },
11
+ "devDependencies": {
12
+ "@types/node": "^25.2.3",
13
+ "typescript": "^5.0.0"
14
+ },
6
15
  "keywords": [
7
16
  "activepieces",
8
17
  "piece",
@@ -21,8 +30,8 @@
21
30
  "url": "https://github.com/Rooted-Software/piece-sitestacker/issues"
22
31
  },
23
32
  "homepage": "https://github.com/Rooted-Software/piece-sitestacker#readme",
24
- "peerDependencies": {
25
- "@activepieces/pieces-framework": ">=0.18.0",
26
- "@activepieces/pieces-common": ">=0.6.0"
33
+ "dependencies": {
34
+ "@activepieces/pieces-common": "0.11.5",
35
+ "@activepieces/pieces-framework": "0.25.3"
27
36
  }
28
37
  }
@@ -4,7 +4,7 @@ import {
4
4
  HttpMethod,
5
5
  HttpRequest,
6
6
  } from '@activepieces/pieces-common';
7
- import { createHmac } from 'crypto';
7
+ import * as crypto from 'crypto';
8
8
  import { siteStackerAuth } from '../../index';
9
9
 
10
10
  function formatDateRFC2616(date: Date): string {
@@ -18,7 +18,7 @@ function computeHmacSignature(
18
18
  dateStr: string
19
19
  ): string {
20
20
  const stringToSign = `${method}\n${contentType}\n${dateStr}`;
21
- return createHmac('sha256', secretKey).update(stringToSign).digest('hex');
21
+ return crypto.createHmac('sha256', secretKey).update(stringToSign).digest('hex');
22
22
  }
23
23
 
24
24
  export const sendRequest = createAction({
@@ -87,7 +87,8 @@ export const sendRequest = createAction({
87
87
  async run(context) {
88
88
  const { method, url, headers, body_type, body, body_raw, timeout } =
89
89
  context.propsValue;
90
- const { accessKeyId, secretAccessKey } = context.auth;
90
+ const accessKeyId = context.auth.props['accessKeyId'] as string;
91
+ const secretAccessKey = context.auth.props['secretAccessKey'] as string;
91
92
 
92
93
  const now = new Date();
93
94
  const dateStr = formatDateRFC2616(now);