-
Notifications
You must be signed in to change notification settings - Fork 906
/
new-record.trigger.ts
62 lines (57 loc) · 1.73 KB
/
new-record.trigger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {
DedupeStrategy,
Polling,
pollingHelper,
} from '@activepieces/pieces-common';
import {
StaticPropsValue,
TriggerStrategy,
createTrigger,
} from '@activepieces/pieces-framework';
import { airtableAuth } from '../../';
import { airtableCommon } from '../common';
const props = {
base: airtableCommon.base,
tableId: airtableCommon.tableId,
viewId: airtableCommon.views,
};
const polling: Polling<string, StaticPropsValue<typeof props>> = {
strategy: DedupeStrategy.TIMEBASED,
items: async ({ auth, propsValue }) => {
const records = await airtableCommon.getTableSnapshot({
personalToken: auth,
baseId: propsValue.base,
tableId: propsValue.tableId!,
limitToView: propsValue.viewId,
});
return records.map((record) => ({
epochMilliSeconds: Date.parse(record.createdTime),
data: record,
}));
},
};
export const airtableNewRecordTrigger = createTrigger({
auth: airtableAuth,
name: 'new_record',
displayName: 'New Record',
description: 'Triggers when a new record is added to the selected table.',
props,
sampleData: {},
type: TriggerStrategy.POLLING,
async test(context) {
const { store, auth, propsValue } = context;
return await pollingHelper.test(polling, { store, auth, propsValue });
},
async onEnable(context) {
const { store, auth, propsValue } = context;
await pollingHelper.onEnable(polling, { store, auth, propsValue });
},
async onDisable(context) {
const { store, auth, propsValue } = context;
await pollingHelper.onDisable(polling, { store, auth, propsValue });
},
async run(context) {
const { store, auth, propsValue } = context;
return await pollingHelper.poll(polling, { store, auth, propsValue });
},
});