@activepieces/pieces-common 0.2.5 → 0.2.6

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.
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@activepieces/pieces-common",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "type": "commonjs",
5
5
  "dependencies": {
6
6
  "@sinclair/typebox": "0.26.8",
7
- "axios": "^1.6.0",
7
+ "axios": "^1.6.3",
8
8
  "dayjs": "1.11.9",
9
9
  "is-base64": "1.1.0",
10
10
  "lodash": "4.17.21",
11
11
  "nanoid": "3.3.6",
12
12
  "semver": "7.5.4",
13
- "@activepieces/pieces-framework": "0.7.1",
14
- "@activepieces/shared": "0.10.13",
15
- "tslib": "2.6.1"
13
+ "@activepieces/pieces-framework": "0.7.10",
14
+ "@activepieces/shared": "0.10.59",
15
+ "tslib": "2.6.2"
16
16
  },
17
17
  "main": "./src/index.js"
18
18
  }
@@ -1,2 +1,16 @@
1
- import { OAuth2PropertyValue } from "@activepieces/pieces-framework";
1
+ import { OAuth2PropertyValue, PieceAuthProperty } from "@activepieces/pieces-framework";
2
+ import { HttpHeaders, HttpMethod } from "../http";
2
3
  export declare const getAccessTokenOrThrow: (auth: OAuth2PropertyValue | undefined) => string;
4
+ export declare function createCustomApiCallAction({ auth, baseUrl, authMapping }: {
5
+ auth?: PieceAuthProperty;
6
+ baseUrl: string;
7
+ authMapping?: (auth: PieceAuthProperty) => HttpHeaders;
8
+ }): import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").BasicAuthProperty<boolean> | import("@activepieces/pieces-framework").CustomAuthProperty<boolean, any> | import("@activepieces/pieces-framework").OAuth2Property<boolean, import("@activepieces/pieces-framework").OAuth2Props> | import("@activepieces/pieces-framework").SecretTextProperty<boolean>, {
9
+ url: import("@activepieces/pieces-framework").ShortTextProperty<true>;
10
+ method: import("@activepieces/pieces-framework").StaticDropdownProperty<HttpMethod, true>;
11
+ headers: import("@activepieces/pieces-framework").ObjectProperty<true>;
12
+ queryParams: import("@activepieces/pieces-framework").ObjectProperty<true>;
13
+ body: import("@activepieces/pieces-framework").JsonProperty<false>;
14
+ failsafe: import("@activepieces/pieces-framework").CheckboxProperty<false>;
15
+ timeout: import("@activepieces/pieces-framework").NumberProperty<false>;
16
+ }>;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAccessTokenOrThrow = void 0;
3
+ exports.createCustomApiCallAction = exports.getAccessTokenOrThrow = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const http_1 = require("../http");
7
+ const shared_1 = require("@activepieces/shared");
4
8
  const getAccessTokenOrThrow = (auth) => {
5
9
  const accessToken = auth === null || auth === void 0 ? void 0 : auth.access_token;
6
10
  if (accessToken === undefined) {
@@ -9,4 +13,81 @@ const getAccessTokenOrThrow = (auth) => {
9
13
  return accessToken;
10
14
  };
11
15
  exports.getAccessTokenOrThrow = getAccessTokenOrThrow;
16
+ function createCustomApiCallAction({ auth, baseUrl, authMapping }) {
17
+ return (0, pieces_framework_1.createAction)({
18
+ name: 'custom_api_call',
19
+ displayName: 'Custom API Call',
20
+ description: 'Send a custom API call to a specific endpoint',
21
+ auth: auth ? auth : undefined,
22
+ props: {
23
+ url: pieces_framework_1.Property.ShortText({
24
+ displayName: 'URL',
25
+ description: 'The endpoint to use. For example, `/models`',
26
+ required: true,
27
+ }),
28
+ method: pieces_framework_1.Property.StaticDropdown({
29
+ displayName: 'Method',
30
+ required: true,
31
+ options: {
32
+ options: Object.values(http_1.HttpMethod).map(v => {
33
+ return {
34
+ label: v,
35
+ value: v,
36
+ };
37
+ })
38
+ }
39
+ }),
40
+ headers: pieces_framework_1.Property.Object({
41
+ displayName: 'Headers',
42
+ description: 'Authorization headers are injected automatically from your connection.',
43
+ required: true,
44
+ }),
45
+ queryParams: pieces_framework_1.Property.Object({
46
+ displayName: 'Query Parameters',
47
+ required: true,
48
+ }),
49
+ body: pieces_framework_1.Property.Json({
50
+ displayName: 'Body',
51
+ required: false,
52
+ }),
53
+ failsafe: pieces_framework_1.Property.Checkbox({
54
+ displayName: 'No Error on Failure',
55
+ required: false,
56
+ }),
57
+ timeout: pieces_framework_1.Property.Number({
58
+ displayName: 'Timeout (in seconds)',
59
+ required: false,
60
+ }),
61
+ },
62
+ run: (context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
63
+ const { method, url, headers, queryParams, body, failsafe, timeout } = context.propsValue;
64
+ (0, shared_1.assertNotNullOrUndefined)(method, 'Method');
65
+ (0, shared_1.assertNotNullOrUndefined)(url, 'URL');
66
+ let headersValue = headers;
67
+ if (authMapping) {
68
+ headersValue = Object.assign(Object.assign({}, headersValue), authMapping(context.auth));
69
+ }
70
+ const request = {
71
+ method,
72
+ url: `${baseUrl}${url}`,
73
+ headers: headersValue,
74
+ queryParams: queryParams,
75
+ timeout: timeout ? timeout * 1000 : 0,
76
+ };
77
+ if (body) {
78
+ request.body = body;
79
+ }
80
+ try {
81
+ return yield http_1.httpClient.sendRequest(request);
82
+ }
83
+ catch (error) {
84
+ if (failsafe) {
85
+ return error.errorMessage();
86
+ }
87
+ throw error;
88
+ }
89
+ })
90
+ });
91
+ }
92
+ exports.createCustomApiCallAction = createCustomApiCallAction;
12
93
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/common/src/lib/helpers/index.ts"],"names":[],"mappings":";;;AAEO,MAAM,qBAAqB,GAAG,CAAC,IAAqC,EAAU,EAAE;IACrF,MAAM,WAAW,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,CAAC;IAEvC,IAAI,WAAW,KAAK,SAAS,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACzC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AARW,QAAA,qBAAqB,yBAQhC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/common/src/lib/helpers/index.ts"],"names":[],"mappings":";;;;AAAA,qEAAgH;AAChH,kCAAmG;AACnG,iDAAgE;AAEzD,MAAM,qBAAqB,GAAG,CAAC,IAAqC,EAAU,EAAE;IACrF,MAAM,WAAW,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,CAAC;IAEvC,IAAI,WAAW,KAAK,SAAS,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACzC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AARW,QAAA,qBAAqB,yBAQhC;AAEF,SAAgB,yBAAyB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAIrE;IACC,OAAO,IAAA,+BAAY,EAAC;QAClB,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,iBAAiB;QAC9B,WAAW,EAAE,+CAA+C;QAC5D,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QAC7B,KAAK,EAAE;YACL,GAAG,EAAE,2BAAQ,CAAC,SAAS,CAAC;gBACtB,WAAW,EAAE,KAAK;gBAClB,WAAW,EAAE,6CAA6C;gBAC1D,QAAQ,EAAE,IAAI;aACf,CAAC;YACF,MAAM,EAAE,2BAAQ,CAAC,cAAc,CAAC;gBAC9B,WAAW,EAAE,QAAQ;gBACrB,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE;oBACP,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,iBAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;wBACzC,OAAO;4BACL,KAAK,EAAE,CAAC;4BACR,KAAK,EAAE,CAAC;yBACT,CAAA;oBACH,CAAC,CAAC;iBACH;aACF,CAAC;YACF,OAAO,EAAE,2BAAQ,CAAC,MAAM,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