@ever-works/pipedrive-connector-plugin 1.0.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.
@@ -0,0 +1,168 @@
1
+ import { IConnectorPlugin, IEventSourcePlugin, PluginCategory, ConnectorMetadata, JsonSchema, ChannelTargetConfig, ConnectorCallOptions, ChannelVerification, ChannelSendInput, ChannelSendResult, ConnectorRecordInput, ConnectorRecordResult, EventSourcePullInput, EventSourcePullResult, PluginSettings } from '@ever-works/plugin';
2
+
3
+ /**
4
+ * Payload text cap for ingested envelopes. Envelope payloads are
5
+ * size-capped platform-side (32 KB serialized); a CRM field value never
6
+ * needs more than this to be useful in Memory/Activities.
7
+ */
8
+ declare const PIPEDRIVE_EVENT_TEXT_MAX_CHARS = 4000;
9
+ /** Records requested per `/recents` page. */
10
+ declare const PIPEDRIVE_PULL_PAGE_SIZE = 50;
11
+ /**
12
+ * Historical backfill bound: at most this many pages per phase (per
13
+ * entity type) during the opt-in first-pull backfill, so a large
14
+ * account can never turn activation into an unbounded crawl.
15
+ */
16
+ declare const PIPEDRIVE_BACKFILL_MAX_PAGES = 10;
17
+ /** Entity types this connector understands, in sweep order. */
18
+ declare const PIPEDRIVE_ENTITY_TYPES: readonly ["deals", "persons", "organizations"];
19
+ type PipedriveEntityType = (typeof PIPEDRIVE_ENTITY_TYPES)[number];
20
+ /** Per-entity ingest / deep-link / note-association metadata. */
21
+ interface PipedriveEntityMeta {
22
+ /** Envelope `kind` (source-namespaced, singular). */
23
+ readonly kind: string;
24
+ /** Value the `/recents` `items` filter expects. */
25
+ readonly recentsItem: string;
26
+ /** Path segment in a Pipedrive web deep link. */
27
+ readonly urlSegment: string;
28
+ /** Field carrying the human title on the record. */
29
+ readonly titleField: string;
30
+ /** Field the note payload uses to attach to this entity. */
31
+ readonly noteField: string;
32
+ /** Non-custom fields copied into the envelope payload. */
33
+ readonly payloadFields: readonly string[];
34
+ }
35
+ declare const PIPEDRIVE_ENTITY_META: Readonly<Record<PipedriveEntityType, PipedriveEntityMeta>>;
36
+ /** Clamp the opt-in backfill window to the supported 0–90 day range. */
37
+ declare function clampBackfillDays(value: unknown): number;
38
+ /**
39
+ * Which entity types to sweep. Unknown entries are dropped; an empty or
40
+ * absent setting means "all three", matching the manifest default.
41
+ */
42
+ declare function resolveEntityTypes(settings: PluginSettings | undefined): PipedriveEntityType[];
43
+ /**
44
+ * Pipedrive timestamps are `YYYY-MM-DD HH:MM:SS` in UTC without a zone
45
+ * marker, which `Date.parse` would read as LOCAL time. Normalize to a
46
+ * real ISO instant (epoch on garbage, so an envelope never carries NaN).
47
+ */
48
+ declare function pipedriveTimeToIso(value: unknown): string;
49
+ /** ISO instant → the `YYYY-MM-DD HH:MM:SS` UTC form `/recents` expects. */
50
+ declare function isoToPipedriveTime(iso: string): string;
51
+ /** One `/recents` entry: the item type plus the record itself. */
52
+ interface PipedriveRecentItem {
53
+ item?: string;
54
+ id?: number | string;
55
+ data?: Record<string, unknown>;
56
+ }
57
+ interface PipedriveRecentsResponse {
58
+ data?: PipedriveRecentItem[] | null;
59
+ additional_data?: {
60
+ pagination?: {
61
+ start?: number;
62
+ limit?: number;
63
+ more_items_in_collection?: boolean;
64
+ next_start?: number;
65
+ };
66
+ };
67
+ }
68
+ interface PipedriveIdResponse {
69
+ data?: {
70
+ id?: number | string;
71
+ } | null;
72
+ }
73
+ interface PipedriveUserResponse {
74
+ data?: {
75
+ id?: number | string;
76
+ name?: string;
77
+ company_name?: string;
78
+ company_domain?: string;
79
+ } | null;
80
+ }
81
+ /** The subset of the Pipedrive SDK surface this plugin calls. */
82
+ interface PipedriveClientLike {
83
+ getCurrentUser(): Promise<PipedriveUserResponse>;
84
+ getRecents(params: Record<string, unknown>): Promise<PipedriveRecentsResponse>;
85
+ addNote(payload: Record<string, unknown>): Promise<PipedriveIdResponse>;
86
+ addRecord(entityType: PipedriveEntityType, fields: Record<string, unknown>): Promise<PipedriveIdResponse>;
87
+ }
88
+ /** Narrow an arbitrary string to a known entity type. */
89
+ declare function asEntityType(value: unknown): PipedriveEntityType | undefined;
90
+ /**
91
+ * Resolve which record an outbound note attaches to. A per-send
92
+ * `recordId`/`recordType` overrides the connection default; the
93
+ * resolved plugin `settings` `defaultDealId` is the final fallback.
94
+ */
95
+ declare function resolveNoteTarget(config: ChannelTargetConfig, options: ConnectorCallOptions): {
96
+ entityType: PipedriveEntityType;
97
+ recordId: string;
98
+ };
99
+ /**
100
+ * Pipedrive CRM connector — first-party native connector.
101
+ *
102
+ * Outbound: `send` appends a note to a deal / person / organization and
103
+ * `createRecord` writes a new record of any of those types, both through
104
+ * the official `pipedrive` Node SDK (API-token auth; the SDK pins the
105
+ * API host, so there is no SSRF surface).
106
+ *
107
+ * Event source: `pullEvents` sweeps each configured entity type in turn
108
+ * through `/recents` — Pipedrive's own "everything that changed since
109
+ * this timestamp" endpoint — normalized into `IngestedEventEnvelope`s
110
+ * (`pipedrive.deal` / `.person` / `.organization`) for the platform's
111
+ * event-ingest spine. When a `companyDomain` is configured every
112
+ * envelope carries a record deep link as `sourceUrl`. The opt-in
113
+ * historical backfill (`backfillDays`, default 0 = off, max 90) widens
114
+ * the FIRST pull's window only, with a per-phase page bound so
115
+ * activation never becomes an unbounded crawl. Re-delivery across
116
+ * overlapping windows is fine — the ingest pipeline dedupes on
117
+ * `(source, sourceEventId)`.
118
+ *
119
+ * Unconfigured is always LOUD: `verifyConnection` reports the missing
120
+ * token, `send`/`createRecord` throw, and `pullEvents` throws
121
+ * `EventSourceNotConfiguredError`. Nothing silently no-ops.
122
+ */
123
+ declare class PipedriveConnectorPlugin implements IConnectorPlugin, IEventSourcePlugin {
124
+ readonly id = "pipedrive-connector";
125
+ readonly name = "Pipedrive Connector";
126
+ readonly version = "1.0.0";
127
+ readonly category: PluginCategory;
128
+ readonly capabilities: readonly ["connector", "connector-pipedrive", "event-source"];
129
+ readonly providerName = "pipedrive";
130
+ readonly connector: ConnectorMetadata;
131
+ readonly settingsSchema: JsonSchema;
132
+ private readonly idempotencyCache;
133
+ private readonly recordIdempotencyCache;
134
+ onLoad(): Promise<void>;
135
+ onUnload(): Promise<void>;
136
+ /**
137
+ * Testable seam — specs stub this; production adapts the official
138
+ * SDK's per-resource API classes onto the narrow surface above.
139
+ */
140
+ protected createClient(apiToken: string): PipedriveClientLike;
141
+ verifyConnection(config: ChannelTargetConfig, options: ConnectorCallOptions): Promise<ChannelVerification>;
142
+ /** Outbound leg — append a note to a deal / person / organization. */
143
+ send(payload: ChannelSendInput, options: ConnectorCallOptions): Promise<ChannelSendResult>;
144
+ /** Outbound record leg — create a deal / person / organization. */
145
+ createRecord(record: ConnectorRecordInput, options: ConnectorCallOptions): Promise<ConnectorRecordResult>;
146
+ /**
147
+ * Pull one `/recents` page of the current entity-type phase since the
148
+ * effective watermark, normalized to envelopes. The returned cursor
149
+ * resumes the same phase (`next_start` offset) or advances to the
150
+ * next configured entity type; no cursor means the sweep is done.
151
+ *
152
+ * First pull (epoch/absent watermark, no cursor): the window is
153
+ * `now - backfillDays` when the opt-in backfill is on, otherwise
154
+ * `now` — history stays untouched unless the user asked for it.
155
+ */
156
+ pullEvents(input: EventSourcePullInput): Promise<EventSourcePullResult>;
157
+ private normalizeRecent;
158
+ /**
159
+ * Payload fields are limited to the per-entity whitelist and each
160
+ * string value is capped, so a record with a huge free-text field can
161
+ * never blow the envelope byte budget (and custom fields, which can
162
+ * hold anything, never ride along).
163
+ */
164
+ private sanitizeFields;
165
+ }
166
+ declare const pipedriveConnectorPlugin: PipedriveConnectorPlugin;
167
+
168
+ export { PIPEDRIVE_BACKFILL_MAX_PAGES, PIPEDRIVE_ENTITY_META, PIPEDRIVE_ENTITY_TYPES, PIPEDRIVE_EVENT_TEXT_MAX_CHARS, PIPEDRIVE_PULL_PAGE_SIZE, PipedriveConnectorPlugin, type PipedriveEntityType, asEntityType, clampBackfillDays, PipedriveConnectorPlugin as default, isoToPipedriveTime, pipedriveConnectorPlugin, pipedriveTimeToIso, resolveEntityTypes, resolveNoteTarget };
@@ -0,0 +1,168 @@
1
+ import { IConnectorPlugin, IEventSourcePlugin, PluginCategory, ConnectorMetadata, JsonSchema, ChannelTargetConfig, ConnectorCallOptions, ChannelVerification, ChannelSendInput, ChannelSendResult, ConnectorRecordInput, ConnectorRecordResult, EventSourcePullInput, EventSourcePullResult, PluginSettings } from '@ever-works/plugin';
2
+
3
+ /**
4
+ * Payload text cap for ingested envelopes. Envelope payloads are
5
+ * size-capped platform-side (32 KB serialized); a CRM field value never
6
+ * needs more than this to be useful in Memory/Activities.
7
+ */
8
+ declare const PIPEDRIVE_EVENT_TEXT_MAX_CHARS = 4000;
9
+ /** Records requested per `/recents` page. */
10
+ declare const PIPEDRIVE_PULL_PAGE_SIZE = 50;
11
+ /**
12
+ * Historical backfill bound: at most this many pages per phase (per
13
+ * entity type) during the opt-in first-pull backfill, so a large
14
+ * account can never turn activation into an unbounded crawl.
15
+ */
16
+ declare const PIPEDRIVE_BACKFILL_MAX_PAGES = 10;
17
+ /** Entity types this connector understands, in sweep order. */
18
+ declare const PIPEDRIVE_ENTITY_TYPES: readonly ["deals", "persons", "organizations"];
19
+ type PipedriveEntityType = (typeof PIPEDRIVE_ENTITY_TYPES)[number];
20
+ /** Per-entity ingest / deep-link / note-association metadata. */
21
+ interface PipedriveEntityMeta {
22
+ /** Envelope `kind` (source-namespaced, singular). */
23
+ readonly kind: string;
24
+ /** Value the `/recents` `items` filter expects. */
25
+ readonly recentsItem: string;
26
+ /** Path segment in a Pipedrive web deep link. */
27
+ readonly urlSegment: string;
28
+ /** Field carrying the human title on the record. */
29
+ readonly titleField: string;
30
+ /** Field the note payload uses to attach to this entity. */
31
+ readonly noteField: string;
32
+ /** Non-custom fields copied into the envelope payload. */
33
+ readonly payloadFields: readonly string[];
34
+ }
35
+ declare const PIPEDRIVE_ENTITY_META: Readonly<Record<PipedriveEntityType, PipedriveEntityMeta>>;
36
+ /** Clamp the opt-in backfill window to the supported 0–90 day range. */
37
+ declare function clampBackfillDays(value: unknown): number;
38
+ /**
39
+ * Which entity types to sweep. Unknown entries are dropped; an empty or
40
+ * absent setting means "all three", matching the manifest default.
41
+ */
42
+ declare function resolveEntityTypes(settings: PluginSettings | undefined): PipedriveEntityType[];
43
+ /**
44
+ * Pipedrive timestamps are `YYYY-MM-DD HH:MM:SS` in UTC without a zone
45
+ * marker, which `Date.parse` would read as LOCAL time. Normalize to a
46
+ * real ISO instant (epoch on garbage, so an envelope never carries NaN).
47
+ */
48
+ declare function pipedriveTimeToIso(value: unknown): string;
49
+ /** ISO instant → the `YYYY-MM-DD HH:MM:SS` UTC form `/recents` expects. */
50
+ declare function isoToPipedriveTime(iso: string): string;
51
+ /** One `/recents` entry: the item type plus the record itself. */
52
+ interface PipedriveRecentItem {
53
+ item?: string;
54
+ id?: number | string;
55
+ data?: Record<string, unknown>;
56
+ }
57
+ interface PipedriveRecentsResponse {
58
+ data?: PipedriveRecentItem[] | null;
59
+ additional_data?: {
60
+ pagination?: {
61
+ start?: number;
62
+ limit?: number;
63
+ more_items_in_collection?: boolean;
64
+ next_start?: number;
65
+ };
66
+ };
67
+ }
68
+ interface PipedriveIdResponse {
69
+ data?: {
70
+ id?: number | string;
71
+ } | null;
72
+ }
73
+ interface PipedriveUserResponse {
74
+ data?: {
75
+ id?: number | string;
76
+ name?: string;
77
+ company_name?: string;
78
+ company_domain?: string;
79
+ } | null;
80
+ }
81
+ /** The subset of the Pipedrive SDK surface this plugin calls. */
82
+ interface PipedriveClientLike {
83
+ getCurrentUser(): Promise<PipedriveUserResponse>;
84
+ getRecents(params: Record<string, unknown>): Promise<PipedriveRecentsResponse>;
85
+ addNote(payload: Record<string, unknown>): Promise<PipedriveIdResponse>;
86
+ addRecord(entityType: PipedriveEntityType, fields: Record<string, unknown>): Promise<PipedriveIdResponse>;
87
+ }
88
+ /** Narrow an arbitrary string to a known entity type. */
89
+ declare function asEntityType(value: unknown): PipedriveEntityType | undefined;
90
+ /**
91
+ * Resolve which record an outbound note attaches to. A per-send
92
+ * `recordId`/`recordType` overrides the connection default; the
93
+ * resolved plugin `settings` `defaultDealId` is the final fallback.
94
+ */
95
+ declare function resolveNoteTarget(config: ChannelTargetConfig, options: ConnectorCallOptions): {
96
+ entityType: PipedriveEntityType;
97
+ recordId: string;
98
+ };
99
+ /**
100
+ * Pipedrive CRM connector — first-party native connector.
101
+ *
102
+ * Outbound: `send` appends a note to a deal / person / organization and
103
+ * `createRecord` writes a new record of any of those types, both through
104
+ * the official `pipedrive` Node SDK (API-token auth; the SDK pins the
105
+ * API host, so there is no SSRF surface).
106
+ *
107
+ * Event source: `pullEvents` sweeps each configured entity type in turn
108
+ * through `/recents` — Pipedrive's own "everything that changed since
109
+ * this timestamp" endpoint — normalized into `IngestedEventEnvelope`s
110
+ * (`pipedrive.deal` / `.person` / `.organization`) for the platform's
111
+ * event-ingest spine. When a `companyDomain` is configured every
112
+ * envelope carries a record deep link as `sourceUrl`. The opt-in
113
+ * historical backfill (`backfillDays`, default 0 = off, max 90) widens
114
+ * the FIRST pull's window only, with a per-phase page bound so
115
+ * activation never becomes an unbounded crawl. Re-delivery across
116
+ * overlapping windows is fine — the ingest pipeline dedupes on
117
+ * `(source, sourceEventId)`.
118
+ *
119
+ * Unconfigured is always LOUD: `verifyConnection` reports the missing
120
+ * token, `send`/`createRecord` throw, and `pullEvents` throws
121
+ * `EventSourceNotConfiguredError`. Nothing silently no-ops.
122
+ */
123
+ declare class PipedriveConnectorPlugin implements IConnectorPlugin, IEventSourcePlugin {
124
+ readonly id = "pipedrive-connector";
125
+ readonly name = "Pipedrive Connector";
126
+ readonly version = "1.0.0";
127
+ readonly category: PluginCategory;
128
+ readonly capabilities: readonly ["connector", "connector-pipedrive", "event-source"];
129
+ readonly providerName = "pipedrive";
130
+ readonly connector: ConnectorMetadata;
131
+ readonly settingsSchema: JsonSchema;
132
+ private readonly idempotencyCache;
133
+ private readonly recordIdempotencyCache;
134
+ onLoad(): Promise<void>;
135
+ onUnload(): Promise<void>;
136
+ /**
137
+ * Testable seam — specs stub this; production adapts the official
138
+ * SDK's per-resource API classes onto the narrow surface above.
139
+ */
140
+ protected createClient(apiToken: string): PipedriveClientLike;
141
+ verifyConnection(config: ChannelTargetConfig, options: ConnectorCallOptions): Promise<ChannelVerification>;
142
+ /** Outbound leg — append a note to a deal / person / organization. */
143
+ send(payload: ChannelSendInput, options: ConnectorCallOptions): Promise<ChannelSendResult>;
144
+ /** Outbound record leg — create a deal / person / organization. */
145
+ createRecord(record: ConnectorRecordInput, options: ConnectorCallOptions): Promise<ConnectorRecordResult>;
146
+ /**
147
+ * Pull one `/recents` page of the current entity-type phase since the
148
+ * effective watermark, normalized to envelopes. The returned cursor
149
+ * resumes the same phase (`next_start` offset) or advances to the
150
+ * next configured entity type; no cursor means the sweep is done.
151
+ *
152
+ * First pull (epoch/absent watermark, no cursor): the window is
153
+ * `now - backfillDays` when the opt-in backfill is on, otherwise
154
+ * `now` — history stays untouched unless the user asked for it.
155
+ */
156
+ pullEvents(input: EventSourcePullInput): Promise<EventSourcePullResult>;
157
+ private normalizeRecent;
158
+ /**
159
+ * Payload fields are limited to the per-entity whitelist and each
160
+ * string value is capped, so a record with a huge free-text field can
161
+ * never blow the envelope byte budget (and custom fields, which can
162
+ * hold anything, never ride along).
163
+ */
164
+ private sanitizeFields;
165
+ }
166
+ declare const pipedriveConnectorPlugin: PipedriveConnectorPlugin;
167
+
168
+ export { PIPEDRIVE_BACKFILL_MAX_PAGES, PIPEDRIVE_ENTITY_META, PIPEDRIVE_ENTITY_TYPES, PIPEDRIVE_EVENT_TEXT_MAX_CHARS, PIPEDRIVE_PULL_PAGE_SIZE, PipedriveConnectorPlugin, type PipedriveEntityType, asEntityType, clampBackfillDays, PipedriveConnectorPlugin as default, isoToPipedriveTime, pipedriveConnectorPlugin, pipedriveTimeToIso, resolveEntityTypes, resolveNoteTarget };