@activeboxes/pieces-common 0.4.0
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/README.md +7 -0
- package/package.json +35 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +10 -0
- package/src/index.js.map +1 -0
- package/src/lib/ai/index.d.ts +94 -0
- package/src/lib/ai/index.js +44 -0
- package/src/lib/ai/index.js.map +1 -0
- package/src/lib/ai/providers/anthropic/index.d.ts +2 -0
- package/src/lib/ai/providers/anthropic/index.js +148 -0
- package/src/lib/ai/providers/anthropic/index.js.map +1 -0
- package/src/lib/ai/providers/index.d.ts +79 -0
- package/src/lib/ai/providers/index.js +170 -0
- package/src/lib/ai/providers/index.js.map +1 -0
- package/src/lib/ai/providers/openai/index.d.ts +22 -0
- package/src/lib/ai/providers/openai/index.js +224 -0
- package/src/lib/ai/providers/openai/index.js.map +1 -0
- package/src/lib/ai/providers/replicate/index.d.ts +10 -0
- package/src/lib/ai/providers/replicate/index.js +185 -0
- package/src/lib/ai/providers/replicate/index.js.map +1 -0
- package/src/lib/ai/providers/utils.d.ts +58 -0
- package/src/lib/ai/providers/utils.js +48 -0
- package/src/lib/ai/providers/utils.js.map +1 -0
- package/src/lib/authentication/index.d.ts +15 -0
- package/src/lib/authentication/index.js +9 -0
- package/src/lib/authentication/index.js.map +1 -0
- package/src/lib/helpers/index.d.ts +29 -0
- package/src/lib/helpers/index.js +101 -0
- package/src/lib/helpers/index.js.map +1 -0
- package/src/lib/http/axios/axios-http-client.d.ts +11 -0
- package/src/lib/http/axios/axios-http-client.js +74 -0
- package/src/lib/http/axios/axios-http-client.js.map +1 -0
- package/src/lib/http/core/base-http-client.d.ts +19 -0
- package/src/lib/http/core/base-http-client.js +52 -0
- package/src/lib/http/core/base-http-client.js.map +1 -0
- package/src/lib/http/core/delegating-authentication-converter.d.ts +17 -0
- package/src/lib/http/core/delegating-authentication-converter.js +33 -0
- package/src/lib/http/core/delegating-authentication-converter.js.map +1 -0
- package/src/lib/http/core/http-client.d.ts +9 -0
- package/src/lib/http/core/http-client.js +6 -0
- package/src/lib/http/core/http-client.js.map +1 -0
- package/src/lib/http/core/http-error.d.ts +33 -0
- package/src/lib/http/core/http-error.js +56 -0
- package/src/lib/http/core/http-error.js.map +1 -0
- package/src/lib/http/core/http-header.d.ts +6 -0
- package/src/lib/http/core/http-header.js +11 -0
- package/src/lib/http/core/http-header.js.map +1 -0
- package/src/lib/http/core/http-headers.d.ts +1 -0
- package/src/lib/http/core/http-headers.js +3 -0
- package/src/lib/http/core/http-headers.js.map +1 -0
- package/src/lib/http/core/http-message-body.d.ts +1 -0
- package/src/lib/http/core/http-message-body.js +3 -0
- package/src/lib/http/core/http-message-body.js.map +1 -0
- package/src/lib/http/core/http-method.d.ts +8 -0
- package/src/lib/http/core/http-method.js +13 -0
- package/src/lib/http/core/http-method.js.map +1 -0
- package/src/lib/http/core/http-request-body.d.ts +2 -0
- package/src/lib/http/core/http-request-body.js +3 -0
- package/src/lib/http/core/http-request-body.js.map +1 -0
- package/src/lib/http/core/http-request.d.ts +17 -0
- package/src/lib/http/core/http-request.js +3 -0
- package/src/lib/http/core/http-request.js.map +1 -0
- package/src/lib/http/core/http-response.d.ts +7 -0
- package/src/lib/http/core/http-response.js +3 -0
- package/src/lib/http/core/http-response.js.map +1 -0
- package/src/lib/http/core/media-type.d.ts +4 -0
- package/src/lib/http/core/media-type.js +9 -0
- package/src/lib/http/core/media-type.js.map +1 -0
- package/src/lib/http/core/query-params.d.ts +1 -0
- package/src/lib/http/core/query-params.js +3 -0
- package/src/lib/http/core/query-params.js.map +1 -0
- package/src/lib/http/index.d.ts +13 -0
- package/src/lib/http/index.js +17 -0
- package/src/lib/http/index.js.map +1 -0
- package/src/lib/polling/index.d.ts +57 -0
- package/src/lib/polling/index.js +136 -0
- package/src/lib/polling/index.js.map +1 -0
- package/src/lib/validation/index.d.ts +4 -0
- package/src/lib/validation/index.js +26 -0
- package/src/lib/validation/index.js.map +1 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"query-params.js","sourceRoot":"","sources":["../../../../../../../../../packages/pieces/community/common/src/lib/http/core/query-params.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export * from './axios/axios-http-client';
|
2
|
+
export * from './core/base-http-client';
|
3
|
+
export * from './core/delegating-authentication-converter';
|
4
|
+
export * from './core/http-client';
|
5
|
+
export * from './core/http-error';
|
6
|
+
export * from './core/http-header';
|
7
|
+
export * from './core/http-headers';
|
8
|
+
export * from './core/http-message-body';
|
9
|
+
export * from './core/http-method';
|
10
|
+
export * from './core/http-request';
|
11
|
+
export * from './core/http-response';
|
12
|
+
export * from './core/media-type';
|
13
|
+
export * from './core/query-params';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const tslib_1 = require("tslib");
|
4
|
+
tslib_1.__exportStar(require("./axios/axios-http-client"), exports);
|
5
|
+
tslib_1.__exportStar(require("./core/base-http-client"), exports);
|
6
|
+
tslib_1.__exportStar(require("./core/delegating-authentication-converter"), exports);
|
7
|
+
tslib_1.__exportStar(require("./core/http-client"), exports);
|
8
|
+
tslib_1.__exportStar(require("./core/http-error"), exports);
|
9
|
+
tslib_1.__exportStar(require("./core/http-header"), exports);
|
10
|
+
tslib_1.__exportStar(require("./core/http-headers"), exports);
|
11
|
+
tslib_1.__exportStar(require("./core/http-message-body"), exports);
|
12
|
+
tslib_1.__exportStar(require("./core/http-method"), exports);
|
13
|
+
tslib_1.__exportStar(require("./core/http-request"), exports);
|
14
|
+
tslib_1.__exportStar(require("./core/http-response"), exports);
|
15
|
+
tslib_1.__exportStar(require("./core/media-type"), exports);
|
16
|
+
tslib_1.__exportStar(require("./core/query-params"), exports);
|
17
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/common/src/lib/http/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,kEAAwC;AACxC,qFAA2D;AAC3D,6DAAmC;AACnC,4DAAkC;AAClC,6DAAmC;AACnC,8DAAoC;AACpC,mEAAyC;AACzC,6DAAmC;AACnC,8DAAoC;AACpC,+DAAqC;AACrC,4DAAkC;AAClC,8DAAoC"}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { FilesService, Store } from '@activeboxes/pieces-framework';
|
2
|
+
interface TimebasedPolling<AuthValue, PropsValue> {
|
3
|
+
strategy: DedupeStrategy.TIMEBASED;
|
4
|
+
items: (params: {
|
5
|
+
auth: AuthValue;
|
6
|
+
store: Store;
|
7
|
+
propsValue: PropsValue;
|
8
|
+
lastFetchEpochMS: number;
|
9
|
+
}) => Promise<{
|
10
|
+
epochMilliSeconds: number;
|
11
|
+
data: unknown;
|
12
|
+
}[]>;
|
13
|
+
}
|
14
|
+
interface LastItemPolling<AuthValue, PropsValue> {
|
15
|
+
strategy: DedupeStrategy.LAST_ITEM;
|
16
|
+
items: (params: {
|
17
|
+
auth: AuthValue;
|
18
|
+
store: Store;
|
19
|
+
files?: FilesService;
|
20
|
+
propsValue: PropsValue;
|
21
|
+
lastItemId: unknown;
|
22
|
+
}) => Promise<{
|
23
|
+
id: unknown;
|
24
|
+
data: unknown;
|
25
|
+
}[]>;
|
26
|
+
}
|
27
|
+
export declare enum DedupeStrategy {
|
28
|
+
TIMEBASED = 0,
|
29
|
+
LAST_ITEM = 1
|
30
|
+
}
|
31
|
+
export type Polling<AuthValue, PropsValue> = TimebasedPolling<AuthValue, PropsValue> | LastItemPolling<AuthValue, PropsValue>;
|
32
|
+
export declare const pollingHelper: {
|
33
|
+
poll<AuthValue, PropsValue>(polling: Polling<AuthValue, PropsValue>, { store, auth, propsValue, maxItemsToPoll, files, }: {
|
34
|
+
store: Store;
|
35
|
+
auth: AuthValue;
|
36
|
+
propsValue: PropsValue;
|
37
|
+
files: FilesService;
|
38
|
+
maxItemsToPoll?: number;
|
39
|
+
}): Promise<unknown[]>;
|
40
|
+
onEnable<AuthValue, PropsValue>(polling: Polling<AuthValue, PropsValue>, { store, auth, propsValue, }: {
|
41
|
+
store: Store;
|
42
|
+
auth: AuthValue;
|
43
|
+
propsValue: PropsValue;
|
44
|
+
}): Promise<void>;
|
45
|
+
onDisable<AuthValue, PropsValue>(polling: Polling<AuthValue, PropsValue>, params: {
|
46
|
+
store: Store;
|
47
|
+
auth: AuthValue;
|
48
|
+
propsValue: PropsValue;
|
49
|
+
}): Promise<void>;
|
50
|
+
test<AuthValue, PropsValue>(polling: Polling<AuthValue, PropsValue>, { auth, propsValue, store, files, }: {
|
51
|
+
store: Store;
|
52
|
+
auth: AuthValue;
|
53
|
+
propsValue: PropsValue;
|
54
|
+
files: FilesService;
|
55
|
+
}): Promise<unknown[]>;
|
56
|
+
};
|
57
|
+
export {};
|
@@ -0,0 +1,136 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.pollingHelper = exports.DedupeStrategy = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const shared_1 = require("@activeboxes/shared");
|
6
|
+
var DedupeStrategy;
|
7
|
+
(function (DedupeStrategy) {
|
8
|
+
DedupeStrategy[DedupeStrategy["TIMEBASED"] = 0] = "TIMEBASED";
|
9
|
+
DedupeStrategy[DedupeStrategy["LAST_ITEM"] = 1] = "LAST_ITEM";
|
10
|
+
})(DedupeStrategy || (exports.DedupeStrategy = DedupeStrategy = {}));
|
11
|
+
exports.pollingHelper = {
|
12
|
+
poll(polling_1, _a) {
|
13
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (polling, { store, auth, propsValue, maxItemsToPoll, files, }) {
|
14
|
+
var _b, _c;
|
15
|
+
switch (polling.strategy) {
|
16
|
+
case DedupeStrategy.TIMEBASED: {
|
17
|
+
const lastEpochMilliSeconds = (yield store.get('lastPoll'));
|
18
|
+
if ((0, shared_1.isNil)(lastEpochMilliSeconds)) {
|
19
|
+
throw new Error("lastPoll doesn't exist in the store.");
|
20
|
+
}
|
21
|
+
const items = yield polling.items({
|
22
|
+
store,
|
23
|
+
auth,
|
24
|
+
propsValue,
|
25
|
+
lastFetchEpochMS: lastEpochMilliSeconds,
|
26
|
+
});
|
27
|
+
const newLastEpochMilliSeconds = items.reduce((acc, item) => Math.max(acc, item.epochMilliSeconds), lastEpochMilliSeconds);
|
28
|
+
yield store.put('lastPoll', newLastEpochMilliSeconds);
|
29
|
+
return items
|
30
|
+
.filter((f) => f.epochMilliSeconds > lastEpochMilliSeconds)
|
31
|
+
.map((item) => item.data);
|
32
|
+
}
|
33
|
+
case DedupeStrategy.LAST_ITEM: {
|
34
|
+
const lastItemId = yield store.get('lastItem');
|
35
|
+
const items = yield polling.items({
|
36
|
+
store,
|
37
|
+
auth,
|
38
|
+
propsValue,
|
39
|
+
lastItemId,
|
40
|
+
files,
|
41
|
+
});
|
42
|
+
const lastItemIndex = items.findIndex((f) => f.id === lastItemId);
|
43
|
+
let newItems = [];
|
44
|
+
if ((0, shared_1.isNil)(lastItemId) || lastItemIndex == -1) {
|
45
|
+
newItems = items !== null && items !== void 0 ? items : [];
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
newItems = (_b = items === null || items === void 0 ? void 0 : items.slice(0, lastItemIndex)) !== null && _b !== void 0 ? _b : [];
|
49
|
+
}
|
50
|
+
// Sorted from newest to oldest
|
51
|
+
if (!(0, shared_1.isNil)(maxItemsToPoll)) {
|
52
|
+
// Get the last polling.maxItemsToPoll items
|
53
|
+
newItems = newItems.slice(-maxItemsToPoll);
|
54
|
+
}
|
55
|
+
const newLastItem = (_c = newItems === null || newItems === void 0 ? void 0 : newItems[0]) === null || _c === void 0 ? void 0 : _c.id;
|
56
|
+
if (!(0, shared_1.isNil)(newLastItem)) {
|
57
|
+
yield store.put('lastItem', newLastItem);
|
58
|
+
}
|
59
|
+
return newItems.map((item) => item.data);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
});
|
63
|
+
},
|
64
|
+
onEnable(polling_1, _a) {
|
65
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (polling, { store, auth, propsValue, }) {
|
66
|
+
var _b;
|
67
|
+
switch (polling.strategy) {
|
68
|
+
case DedupeStrategy.TIMEBASED: {
|
69
|
+
yield store.put('lastPoll', Date.now());
|
70
|
+
break;
|
71
|
+
}
|
72
|
+
case DedupeStrategy.LAST_ITEM: {
|
73
|
+
const items = yield polling.items({
|
74
|
+
store,
|
75
|
+
auth,
|
76
|
+
propsValue,
|
77
|
+
lastItemId: null,
|
78
|
+
});
|
79
|
+
const lastItemId = (_b = items === null || items === void 0 ? void 0 : items[0]) === null || _b === void 0 ? void 0 : _b.id;
|
80
|
+
if (!(0, shared_1.isNil)(lastItemId)) {
|
81
|
+
yield store.put('lastItem', lastItemId);
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
yield store.delete('lastItem');
|
85
|
+
}
|
86
|
+
break;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
});
|
90
|
+
},
|
91
|
+
onDisable(polling, params) {
|
92
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
93
|
+
switch (polling.strategy) {
|
94
|
+
case DedupeStrategy.TIMEBASED:
|
95
|
+
case DedupeStrategy.LAST_ITEM:
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
});
|
99
|
+
},
|
100
|
+
test(polling_1, _a) {
|
101
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (polling, { auth, propsValue, store, files, }) {
|
102
|
+
let items = [];
|
103
|
+
switch (polling.strategy) {
|
104
|
+
case DedupeStrategy.TIMEBASED: {
|
105
|
+
items = yield polling.items({
|
106
|
+
store,
|
107
|
+
auth,
|
108
|
+
propsValue,
|
109
|
+
lastFetchEpochMS: 0,
|
110
|
+
});
|
111
|
+
break;
|
112
|
+
}
|
113
|
+
case DedupeStrategy.LAST_ITEM: {
|
114
|
+
items = yield polling.items({
|
115
|
+
store,
|
116
|
+
auth,
|
117
|
+
propsValue,
|
118
|
+
lastItemId: null,
|
119
|
+
files,
|
120
|
+
});
|
121
|
+
break;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
return getFirstFiveOrAll(items.map((item) => item.data));
|
125
|
+
});
|
126
|
+
},
|
127
|
+
};
|
128
|
+
function getFirstFiveOrAll(array) {
|
129
|
+
if (array.length <= 5) {
|
130
|
+
return array;
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
return array.slice(0, 5);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/common/src/lib/polling/index.ts"],"names":[],"mappings":";;;;AACA,gDAA4C;AAkC5C,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,6DAAS,CAAA;IACT,6DAAS,CAAA;AACX,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AAMY,QAAA,aAAa,GAAG;IACrB,IAAI;qEACR,OAAuC,EACvC,EACE,KAAK,EACL,IAAI,EACJ,UAAU,EACV,cAAc,EACd,KAAK,GAON;;YAED,QAAQ,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACzB,KAAK,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;oBAC9B,MAAM,qBAAqB,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,CAAS,UAAU,CAAC,CAAC,CAAC;oBACpE,IAAI,IAAA,cAAK,EAAC,qBAAqB,CAAC,EAAE,CAAC;wBACjC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;oBAC1D,CAAC;oBACD,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC;wBAChC,KAAK;wBACL,IAAI;wBACJ,UAAU;wBACV,gBAAgB,EAAE,qBAAqB;qBACxC,CAAC,CAAC;oBACH,MAAM,wBAAwB,GAAG,KAAK,CAAC,MAAM,CAC3C,C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,CAAC"}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.propsValidation = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const zod_1 = require("zod");
|
6
|
+
exports.propsValidation = {
|
7
|
+
validateZod(props, schema) {
|
8
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
9
|
+
const schemaObj = zod_1.z.object(Object.entries(schema).reduce((acc, [key, value]) => (Object.assign(Object.assign({}, acc), { [key]: value })), {}));
|
10
|
+
try {
|
11
|
+
yield schemaObj.parseAsync(props);
|
12
|
+
}
|
13
|
+
catch (error) {
|
14
|
+
if (error instanceof zod_1.z.ZodError) {
|
15
|
+
const errors = error.errors.reduce((acc, err) => {
|
16
|
+
const path = err.path.join('.');
|
17
|
+
return Object.assign(Object.assign({}, acc), { [path]: err.message });
|
18
|
+
}, {});
|
19
|
+
throw new Error(JSON.stringify({ errors }, null, 2));
|
20
|
+
}
|
21
|
+
throw error;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
}
|
25
|
+
};
|
26
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/common/src/lib/validation/index.ts"],"names":[],"mappings":";;;;AAAA,6BAAuB;AAEV,QAAA,eAAe,GAAG;IACrB,WAAW,CAAoC,KAAQ,EAAE,MAA2C;;YACtG,MAAM,SAAS,GAAG,OAAC,CAAC,MAAM,CACtB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,iCAC9C,GAAG,KACN,CAAC,GAAG,CAAC,EAAE,KAAK,IACd,EAAE,EAAE,CAAC,CACV,CAAA;YAED,IAAI,CAAC;gBACD,MAAM,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YACrC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,IAAI,KAAK,YAAY,OAAC,CAAC,QAAQ,EAAE,CAAC;oBAC9B,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;wBAC5C,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;wBAC/B,uCACO,GAAG,KACN,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,IACtB;oBACL,CAAC,EAAE,EAAE,CAAC,CAAA;oBACN,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;gBACxD,CAAC;gBACD,MAAM,KAAK,CAAA;YACf,CAAC;QACL,CAAC;KAAA;CACJ,CAAA"}
|