@agnocon/piece-buffer 0.0.5

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.
Files changed (47) hide show
  1. package/LICENSE.MIT-AP +24 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +40 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/actions/create-idea.d.ts +8 -0
  7. package/dist/lib/actions/create-idea.d.ts.map +1 -0
  8. package/dist/lib/actions/create-idea.js +102 -0
  9. package/dist/lib/actions/create-idea.js.map +1 -0
  10. package/dist/lib/actions/create-post.d.ts +12 -0
  11. package/dist/lib/actions/create-post.d.ts.map +1 -0
  12. package/dist/lib/actions/create-post.js +141 -0
  13. package/dist/lib/actions/create-post.js.map +1 -0
  14. package/dist/lib/common/auth.d.ts +2 -0
  15. package/dist/lib/common/auth.d.ts.map +1 -0
  16. package/dist/lib/common/auth.js +37 -0
  17. package/dist/lib/common/auth.js.map +1 -0
  18. package/dist/lib/common/client.d.ts +11 -0
  19. package/dist/lib/common/client.d.ts.map +1 -0
  20. package/dist/lib/common/client.js +34 -0
  21. package/dist/lib/common/client.js.map +1 -0
  22. package/dist/lib/common/props.d.ts +52 -0
  23. package/dist/lib/common/props.d.ts.map +1 -0
  24. package/dist/lib/common/props.js +181 -0
  25. package/dist/lib/common/props.js.map +1 -0
  26. package/dist/lib/triggers/new-channel.d.ts +11 -0
  27. package/dist/lib/triggers/new-channel.d.ts.map +1 -0
  28. package/dist/lib/triggers/new-channel.js +73 -0
  29. package/dist/lib/triggers/new-channel.js.map +1 -0
  30. package/dist/lib/triggers/new-queue-item.d.ts +15 -0
  31. package/dist/lib/triggers/new-queue-item.d.ts.map +1 -0
  32. package/dist/lib/triggers/new-queue-item.js +118 -0
  33. package/dist/lib/triggers/new-queue-item.js.map +1 -0
  34. package/dist/lib/triggers/new-sent-item.d.ts +15 -0
  35. package/dist/lib/triggers/new-sent-item.d.ts.map +1 -0
  36. package/dist/lib/triggers/new-sent-item.js +117 -0
  37. package/dist/lib/triggers/new-sent-item.js.map +1 -0
  38. package/package.json +46 -0
  39. package/src/index.ts +33 -0
  40. package/src/lib/actions/create-idea.ts +123 -0
  41. package/src/lib/actions/create-post.ts +173 -0
  42. package/src/lib/common/auth.ts +31 -0
  43. package/src/lib/common/client.ts +44 -0
  44. package/src/lib/common/props.ts +224 -0
  45. package/src/lib/triggers/new-channel.ts +73 -0
  46. package/src/lib/triggers/new-queue-item.ts +122 -0
  47. package/src/lib/triggers/new-sent-item.ts +121 -0
@@ -0,0 +1,122 @@
1
+ import {
2
+ createTrigger,
3
+ Property,
4
+ TriggerStrategy,
5
+ AppConnectionValueForAuthProperty,
6
+ } from '@agnocon/pieces-framework';
7
+ import {
8
+ DedupeStrategy,
9
+ Polling,
10
+ pollingHelper,
11
+ } from '@agnocon/pieces-common';
12
+ import { bufferAuth } from '../common/auth';
13
+ import {
14
+ bufferProps,
15
+ bufferQueries,
16
+ BufferPost,
17
+ } from '../common/props';
18
+
19
+ const polling: Polling<
20
+ AppConnectionValueForAuthProperty<typeof bufferAuth>,
21
+ { organizationId: string; channelIds?: string[] }
22
+ > = {
23
+ strategy: DedupeStrategy.TIMEBASED,
24
+ async items({ auth, propsValue }) {
25
+ const posts = await bufferQueries.fetchPosts({
26
+ accessToken: auth.secret_text,
27
+ organizationId: propsValue.organizationId,
28
+ channelIds: propsValue.channelIds,
29
+ statusFilter: (status) => {
30
+ const normalized = status?.toLowerCase();
31
+ return normalized !== 'sent' && normalized !== 'error';
32
+ },
33
+ });
34
+ return posts.map((post) => ({
35
+ epochMilliSeconds: post.createdAt
36
+ ? new Date(post.createdAt).getTime()
37
+ : 0,
38
+ data: post,
39
+ }));
40
+ },
41
+ };
42
+
43
+ export const newQueueItem = createTrigger({
44
+ auth: bufferAuth,
45
+ name: 'new_queue_item',
46
+ displayName: 'New Queue Item',
47
+ description: 'Triggers when a new post is queued in Buffer.',
48
+ aiMetadata: {
49
+ description:
50
+ 'Fires when a new not-yet-published post (any status except sent or error, e.g. pending, scheduled, or draft) appears in the selected Buffer organization, optionally limited to specific channels. Represents the queued post.',
51
+ },
52
+ type: TriggerStrategy.POLLING,
53
+ props: {
54
+ organizationId: bufferProps.organizationId(),
55
+ channelIds: Property.MultiSelectDropdown<string, false, typeof bufferAuth>({
56
+ auth: bufferAuth,
57
+ displayName: 'Channels',
58
+ description: 'Limit results to specific channels (optional).',
59
+ required: false,
60
+ refreshers: ['organizationId'],
61
+ options: async ({ auth, organizationId }) => {
62
+ if (!auth || !organizationId) {
63
+ return {
64
+ disabled: true,
65
+ placeholder: 'Select an organization first.',
66
+ options: [],
67
+ };
68
+ }
69
+ try {
70
+ const channels = await bufferQueries.fetchChannels(
71
+ auth.secret_text,
72
+ organizationId as string,
73
+ );
74
+ return {
75
+ disabled: false,
76
+ options: channels.map((channel) => ({
77
+ label: `${channel.name} (${channel.service})`,
78
+ value: channel.id,
79
+ })),
80
+ };
81
+ } catch {
82
+ return {
83
+ disabled: true,
84
+ placeholder: 'Failed to load channels.',
85
+ options: [],
86
+ };
87
+ }
88
+ },
89
+ }),
90
+ },
91
+ sampleData: {
92
+ id: 'post_id_example',
93
+ text: 'Hello from Buffer!',
94
+ status: 'pending',
95
+ createdAt: '2026-05-25T10:00:00.000Z',
96
+ dueAt: '2026-05-25T18:00:00.000Z',
97
+ channelId: 'channel_id',
98
+ channelService: 'facebook',
99
+ channel: { id: 'channel_id', name: 'My Page', service: 'facebook' },
100
+ tags: [],
101
+ } satisfies BufferPost,
102
+ async onEnable(context) {
103
+ await pollingHelper.onEnable(polling, {
104
+ auth: context.auth,
105
+ store: context.store,
106
+ propsValue: context.propsValue,
107
+ });
108
+ },
109
+ async onDisable(context) {
110
+ await pollingHelper.onDisable(polling, {
111
+ auth: context.auth,
112
+ store: context.store,
113
+ propsValue: context.propsValue,
114
+ });
115
+ },
116
+ async test(context) {
117
+ return await pollingHelper.test(polling, context);
118
+ },
119
+ async run(context) {
120
+ return await pollingHelper.poll(polling, context);
121
+ },
122
+ });
@@ -0,0 +1,121 @@
1
+ import {
2
+ createTrigger,
3
+ Property,
4
+ TriggerStrategy,
5
+ AppConnectionValueForAuthProperty,
6
+ } from '@agnocon/pieces-framework';
7
+ import {
8
+ DedupeStrategy,
9
+ Polling,
10
+ pollingHelper,
11
+ } from '@agnocon/pieces-common';
12
+ import { bufferAuth } from '../common/auth';
13
+ import {
14
+ bufferProps,
15
+ bufferQueries,
16
+ BufferPost,
17
+ } from '../common/props';
18
+
19
+ const polling: Polling<
20
+ AppConnectionValueForAuthProperty<typeof bufferAuth>,
21
+ { organizationId: string; channelIds?: string[] }
22
+ > = {
23
+ strategy: DedupeStrategy.TIMEBASED,
24
+ async items({ auth, propsValue }) {
25
+ const posts = await bufferQueries.fetchPosts({
26
+ accessToken: auth.secret_text,
27
+ organizationId: propsValue.organizationId,
28
+ channelIds: propsValue.channelIds,
29
+ statusFilter: (status) => status?.toLowerCase() === 'sent',
30
+ });
31
+ return posts.map((post) => ({
32
+ epochMilliSeconds: post.sentAt
33
+ ? new Date(post.sentAt).getTime()
34
+ : post.createdAt
35
+ ? new Date(post.createdAt).getTime()
36
+ : 0,
37
+ data: post,
38
+ }));
39
+ },
40
+ };
41
+
42
+ export const newSentItem = createTrigger({
43
+ auth: bufferAuth,
44
+ name: 'new_sent_item',
45
+ displayName: 'New Sent Post',
46
+ description: 'Triggers when a Buffer post is successfully published.',
47
+ aiMetadata: {
48
+ description:
49
+ 'Fires when a Buffer post is successfully published (status sent) to a connected channel in the selected organization, optionally limited to specific channels. Represents the sent post.',
50
+ },
51
+ type: TriggerStrategy.POLLING,
52
+ props: {
53
+ organizationId: bufferProps.organizationId(),
54
+ channelIds: Property.MultiSelectDropdown<string, false, typeof bufferAuth>({
55
+ auth: bufferAuth,
56
+ displayName: 'Channels',
57
+ description: 'Limit results to specific channels (optional).',
58
+ required: false,
59
+ refreshers: ['organizationId'],
60
+ options: async ({ auth, organizationId }) => {
61
+ if (!auth || !organizationId) {
62
+ return {
63
+ disabled: true,
64
+ placeholder: 'Select an organization first.',
65
+ options: [],
66
+ };
67
+ }
68
+ try {
69
+ const channels = await bufferQueries.fetchChannels(
70
+ auth.secret_text,
71
+ organizationId as string,
72
+ );
73
+ return {
74
+ disabled: false,
75
+ options: channels.map((channel) => ({
76
+ label: `${channel.name} (${channel.service})`,
77
+ value: channel.id,
78
+ })),
79
+ };
80
+ } catch {
81
+ return {
82
+ disabled: true,
83
+ placeholder: 'Failed to load channels.',
84
+ options: [],
85
+ };
86
+ }
87
+ },
88
+ }),
89
+ },
90
+ sampleData: {
91
+ id: 'post_id_example',
92
+ text: 'Hello from Buffer!',
93
+ status: 'sent',
94
+ createdAt: '2026-05-25T10:00:00.000Z',
95
+ sentAt: '2026-05-25T18:00:00.000Z',
96
+ channelId: 'channel_id',
97
+ channelService: 'facebook',
98
+ channel: { id: 'channel_id', name: 'My Page', service: 'facebook' },
99
+ tags: [],
100
+ } satisfies BufferPost,
101
+ async onEnable(context) {
102
+ await pollingHelper.onEnable(polling, {
103
+ auth: context.auth,
104
+ store: context.store,
105
+ propsValue: context.propsValue,
106
+ });
107
+ },
108
+ async onDisable(context) {
109
+ await pollingHelper.onDisable(polling, {
110
+ auth: context.auth,
111
+ store: context.store,
112
+ propsValue: context.propsValue,
113
+ });
114
+ },
115
+ async test(context) {
116
+ return await pollingHelper.test(polling, context);
117
+ },
118
+ async run(context) {
119
+ return await pollingHelper.poll(polling, context);
120
+ },
121
+ });