@frogbotai/piece-hubspot 0.0.0-stage → 0.41.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/LICENSE +21 -0
- package/README.md +146 -2
- package/dist/actions/associations.d.ts +161 -0
- package/dist/actions/associations.d.ts.map +1 -0
- package/dist/actions/associations.js +192 -0
- package/dist/actions/associations.js.map +1 -0
- package/dist/actions/createOrUpdateContact.d.ts +36 -0
- package/dist/actions/createOrUpdateContact.d.ts.map +1 -0
- package/dist/actions/createOrUpdateContact.js +65 -0
- package/dist/actions/createOrUpdateContact.js.map +1 -0
- package/dist/actions/crm.d.ts +1042 -0
- package/dist/actions/crm.d.ts.map +1 -0
- package/dist/actions/crm.js +266 -0
- package/dist/actions/crm.js.map +1 -0
- package/dist/actions/crud.d.ts +180 -0
- package/dist/actions/crud.d.ts.map +1 -0
- package/dist/actions/crud.js +203 -0
- package/dist/actions/crud.js.map +1 -0
- package/dist/actions/customApiCall.d.ts +6 -0
- package/dist/actions/customApiCall.d.ts.map +1 -0
- package/dist/actions/customApiCall.js +10 -0
- package/dist/actions/customApiCall.js.map +1 -0
- package/dist/actions/lists.d.ts +42 -0
- package/dist/actions/lists.d.ts.map +1 -0
- package/dist/actions/lists.js +108 -0
- package/dist/actions/lists.js.map +1 -0
- package/dist/actions/lookups.d.ts +110 -0
- package/dist/actions/lookups.d.ts.map +1 -0
- package/dist/actions/lookups.js +71 -0
- package/dist/actions/lookups.js.map +1 -0
- package/dist/actions/marketing.d.ts +45 -0
- package/dist/actions/marketing.d.ts.map +1 -0
- package/dist/actions/marketing.js +75 -0
- package/dist/actions/marketing.js.map +1 -0
- package/dist/actions/options.d.ts +38 -0
- package/dist/actions/options.d.ts.map +1 -0
- package/dist/actions/options.js +229 -0
- package/dist/actions/options.js.map +1 -0
- package/dist/actions/reads.d.ts +351 -0
- package/dist/actions/reads.d.ts.map +1 -0
- package/dist/actions/reads.js +253 -0
- package/dist/actions/reads.js.map +1 -0
- package/dist/actions/uploadFile.d.ts +47 -0
- package/dist/actions/uploadFile.d.ts.map +1 -0
- package/dist/actions/uploadFile.js +66 -0
- package/dist/actions/uploadFile.js.map +1 -0
- package/dist/client.d.ts +31 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +115 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +35 -0
- package/dist/config.js.map +1 -0
- package/dist/define.d.ts +76 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +4 -0
- package/dist/define.js.map +1 -0
- package/dist/files.d.ts +13 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +55 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +3463 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +173 -0
- package/dist/index.js.map +1 -0
- package/dist/objects.d.ts +57 -0
- package/dist/objects.d.ts.map +1 -0
- package/dist/objects.js +194 -0
- package/dist/objects.js.map +1 -0
- package/dist/pagination.d.ts +41 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +29 -0
- package/dist/pagination.js.map +1 -0
- package/dist/records.d.ts +99 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +106 -0
- package/dist/records.js.map +1 -0
- package/dist/triggers/marketing.d.ts +167 -0
- package/dist/triggers/marketing.d.ts.map +1 -0
- package/dist/triggers/marketing.js +227 -0
- package/dist/triggers/marketing.js.map +1 -0
- package/dist/triggers/newContactInList.d.ts +75 -0
- package/dist/triggers/newContactInList.d.ts.map +1 -0
- package/dist/triggers/newContactInList.js +78 -0
- package/dist/triggers/newContactInList.js.map +1 -0
- package/dist/triggers/newEngagement.d.ts +91 -0
- package/dist/triggers/newEngagement.d.ts.map +1 -0
- package/dist/triggers/newEngagement.js +125 -0
- package/dist/triggers/newEngagement.js.map +1 -0
- package/dist/triggers/poll.d.ts +94 -0
- package/dist/triggers/poll.d.ts.map +1 -0
- package/dist/triggers/poll.js +141 -0
- package/dist/triggers/poll.js.map +1 -0
- package/dist/triggers/records.d.ts +1234 -0
- package/dist/triggers/records.d.ts.map +1 -0
- package/dist/triggers/records.js +249 -0
- package/dist/triggers/records.js.map +1 -0
- package/package.json +41 -3
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { signal } from '../client.js';
|
|
3
|
+
import { objectType, recordId } from '../config.js';
|
|
4
|
+
import { defineAction } from '../define.js';
|
|
5
|
+
import { cursorPage, pageInput, pageOutput } from '../pagination.js';
|
|
6
|
+
import { associationLabel, crmRecord, list, listMember, owner, pipeline, property } from '../records.js';
|
|
7
|
+
const names = (label, description)=>z.array(z.string().regex(/^[\w-]+$/, `${label} must be HubSpot internal names.`)).optional().meta({
|
|
8
|
+
label,
|
|
9
|
+
description
|
|
10
|
+
});
|
|
11
|
+
export const listRecords = defineAction({
|
|
12
|
+
slug: 'listRecords',
|
|
13
|
+
description: 'List one page of a CRM object’s records: contacts, companies, deals, tickets, activities (notes, emails, calls, meetings, tasks), line items, products or a custom object. Unlike search, this has no 10,000-result limit.',
|
|
14
|
+
input: z.object({
|
|
15
|
+
objectType,
|
|
16
|
+
properties: names('Properties', 'Property names to return. HubSpot returns a few defaults when this is empty.'),
|
|
17
|
+
associations: names('Associations', 'Object types whose associated IDs to include, such as companies. Only the first page of each comes back; use listAssociations for the rest.'),
|
|
18
|
+
...pageInput
|
|
19
|
+
}),
|
|
20
|
+
output: pageOutput(crmRecord),
|
|
21
|
+
idempotent: true,
|
|
22
|
+
run ({ client, input, req }) {
|
|
23
|
+
return client.request(cursorPage(crmRecord), {
|
|
24
|
+
path: `/crm/v3/objects/${input.objectType}`,
|
|
25
|
+
query: {
|
|
26
|
+
limit: input.limit,
|
|
27
|
+
after: input.cursor,
|
|
28
|
+
properties: input.properties,
|
|
29
|
+
associations: input.associations
|
|
30
|
+
},
|
|
31
|
+
signal: signal(req)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const associationsPage = z.object({
|
|
36
|
+
results: z.array(z.object({
|
|
37
|
+
from: z.object({
|
|
38
|
+
id: z.coerce.string()
|
|
39
|
+
}),
|
|
40
|
+
to: z.array(z.object({
|
|
41
|
+
toObjectId: z.coerce.string(),
|
|
42
|
+
associationTypes: z.array(associationLabel)
|
|
43
|
+
})),
|
|
44
|
+
paging: z.object({
|
|
45
|
+
next: z.object({
|
|
46
|
+
after: z.string()
|
|
47
|
+
}).optional()
|
|
48
|
+
}).optional()
|
|
49
|
+
})),
|
|
50
|
+
errors: z.array(z.object({
|
|
51
|
+
message: z.string(),
|
|
52
|
+
category: z.string().optional()
|
|
53
|
+
})).optional().default([])
|
|
54
|
+
});
|
|
55
|
+
export const listAssociations = defineAction({
|
|
56
|
+
slug: 'listAssociations',
|
|
57
|
+
description: 'Read the associations from up to 1,000 records to one object type, with their labels. Each record’s result has its own nextCursor; pass it back in cursors to read that record’s next page.',
|
|
58
|
+
input: z.object({
|
|
59
|
+
fromType: objectType.meta({
|
|
60
|
+
label: 'From object type'
|
|
61
|
+
}),
|
|
62
|
+
toType: objectType.meta({
|
|
63
|
+
label: 'To object type'
|
|
64
|
+
}),
|
|
65
|
+
ids: z.array(recordId('Record ID')).min(1).max(1000).meta({
|
|
66
|
+
label: 'Record IDs'
|
|
67
|
+
}),
|
|
68
|
+
cursors: z.record(z.string(), z.string().min(1)).optional().meta({
|
|
69
|
+
description: 'A record’s nextCursor from a previous call, keyed by record ID.'
|
|
70
|
+
})
|
|
71
|
+
}),
|
|
72
|
+
output: z.object({
|
|
73
|
+
results: z.array(z.object({
|
|
74
|
+
id: z.string(),
|
|
75
|
+
associations: z.array(z.object({
|
|
76
|
+
id: z.string(),
|
|
77
|
+
labels: z.array(associationLabel)
|
|
78
|
+
})),
|
|
79
|
+
nextCursor: z.string().nullable()
|
|
80
|
+
})),
|
|
81
|
+
errors: z.array(z.object({
|
|
82
|
+
message: z.string(),
|
|
83
|
+
category: z.string().optional()
|
|
84
|
+
}))
|
|
85
|
+
}),
|
|
86
|
+
idempotent: true,
|
|
87
|
+
async run ({ client, input, req }) {
|
|
88
|
+
const page = await client.request(associationsPage, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
path: `/crm/v4/associations/${input.fromType}/${input.toType}/batch/read`,
|
|
91
|
+
body: {
|
|
92
|
+
inputs: input.ids.map((id)=>{
|
|
93
|
+
const after = input.cursors?.[id];
|
|
94
|
+
return after === undefined ? {
|
|
95
|
+
id
|
|
96
|
+
} : {
|
|
97
|
+
id,
|
|
98
|
+
after
|
|
99
|
+
};
|
|
100
|
+
})
|
|
101
|
+
},
|
|
102
|
+
signal: signal(req)
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
results: page.results.map((result)=>({
|
|
106
|
+
id: result.from.id,
|
|
107
|
+
associations: result.to.map((to)=>({
|
|
108
|
+
id: to.toObjectId,
|
|
109
|
+
labels: to.associationTypes
|
|
110
|
+
})),
|
|
111
|
+
nextCursor: result.paging?.next?.after ?? null
|
|
112
|
+
})),
|
|
113
|
+
errors: page.errors
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const listsPage = z.object({
|
|
118
|
+
lists: z.array(list),
|
|
119
|
+
hasMore: z.boolean(),
|
|
120
|
+
offset: z.number()
|
|
121
|
+
});
|
|
122
|
+
export const listLists = defineAction({
|
|
123
|
+
slug: 'listLists',
|
|
124
|
+
description: 'List one page of lists (segments), optionally filtered by name or object type.',
|
|
125
|
+
input: z.object({
|
|
126
|
+
query: z.string().optional().meta({
|
|
127
|
+
description: 'Only lists whose name contains this.'
|
|
128
|
+
}),
|
|
129
|
+
objectTypeId: z.string().regex(/^\d+-\d+$/).optional().meta({
|
|
130
|
+
description: 'Only lists of this object type, such as 0-1 for contacts.'
|
|
131
|
+
}),
|
|
132
|
+
limit: pageInput.limit,
|
|
133
|
+
cursor: z.string().regex(/^\d+$/, "cursor must be a previous page's nextCursor.").optional().meta({
|
|
134
|
+
description: "The previous page's nextCursor. Keep the other inputs the same."
|
|
135
|
+
})
|
|
136
|
+
}),
|
|
137
|
+
output: pageOutput(list),
|
|
138
|
+
idempotent: true,
|
|
139
|
+
async run ({ client, input, req }) {
|
|
140
|
+
const page = await client.request(listsPage, {
|
|
141
|
+
method: 'POST',
|
|
142
|
+
path: '/crm/v3/lists/search',
|
|
143
|
+
body: {
|
|
144
|
+
query: input.query ?? '',
|
|
145
|
+
count: input.limit,
|
|
146
|
+
offset: input.cursor === undefined ? 0 : Number(input.cursor),
|
|
147
|
+
additionalProperties: [],
|
|
148
|
+
...input.objectTypeId ? {
|
|
149
|
+
objectTypeId: input.objectTypeId
|
|
150
|
+
} : {}
|
|
151
|
+
},
|
|
152
|
+
signal: signal(req)
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
results: page.lists,
|
|
156
|
+
nextCursor: page.hasMore ? String(page.offset) : null
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
export const listListMembers = defineAction({
|
|
161
|
+
slug: 'listListMembers',
|
|
162
|
+
description: 'List one page of the record IDs in a list, ordered by record ID.',
|
|
163
|
+
input: z.object({
|
|
164
|
+
listId: recordId('List ID'),
|
|
165
|
+
...pageInput
|
|
166
|
+
}),
|
|
167
|
+
output: pageOutput(listMember),
|
|
168
|
+
idempotent: true,
|
|
169
|
+
run ({ client, input, req }) {
|
|
170
|
+
return client.request(cursorPage(listMember), {
|
|
171
|
+
path: `/crm/v3/lists/${input.listId}/memberships`,
|
|
172
|
+
query: {
|
|
173
|
+
limit: input.limit,
|
|
174
|
+
after: input.cursor
|
|
175
|
+
},
|
|
176
|
+
signal: signal(req)
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
export const listOwners = defineAction({
|
|
181
|
+
slug: 'listOwners',
|
|
182
|
+
description: 'List one page of the account’s owners: the users records can be assigned to.',
|
|
183
|
+
input: z.object({
|
|
184
|
+
archived: z.boolean().optional().meta({
|
|
185
|
+
description: 'List deactivated owners instead of active ones.'
|
|
186
|
+
}),
|
|
187
|
+
...pageInput
|
|
188
|
+
}),
|
|
189
|
+
output: pageOutput(owner),
|
|
190
|
+
idempotent: true,
|
|
191
|
+
run ({ client, input, req }) {
|
|
192
|
+
return client.request(cursorPage(owner), {
|
|
193
|
+
path: '/crm/v3/owners',
|
|
194
|
+
query: {
|
|
195
|
+
limit: input.limit,
|
|
196
|
+
after: input.cursor,
|
|
197
|
+
archived: input.archived
|
|
198
|
+
},
|
|
199
|
+
signal: signal(req)
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
export const listPipelines = defineAction({
|
|
204
|
+
slug: 'listPipelines',
|
|
205
|
+
description: 'List every deal or ticket pipeline, with its stages.',
|
|
206
|
+
input: z.object({
|
|
207
|
+
objectType: z.enum([
|
|
208
|
+
'deals',
|
|
209
|
+
'tickets'
|
|
210
|
+
]).meta({
|
|
211
|
+
label: 'Object type'
|
|
212
|
+
})
|
|
213
|
+
}),
|
|
214
|
+
output: z.object({
|
|
215
|
+
results: z.array(pipeline)
|
|
216
|
+
}),
|
|
217
|
+
idempotent: true,
|
|
218
|
+
run ({ client, input, req }) {
|
|
219
|
+
return client.request(z.object({
|
|
220
|
+
results: z.array(pipeline)
|
|
221
|
+
}), {
|
|
222
|
+
path: `/crm/v3/pipelines/${input.objectType}`,
|
|
223
|
+
signal: signal(req)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
export const listProperties = defineAction({
|
|
228
|
+
slug: 'listProperties',
|
|
229
|
+
description: 'List every property of a CRM object, with its type and options. Use it to choose properties for listRecords.',
|
|
230
|
+
input: z.object({
|
|
231
|
+
objectType,
|
|
232
|
+
archived: z.boolean().optional().meta({
|
|
233
|
+
description: 'List archived properties instead.'
|
|
234
|
+
})
|
|
235
|
+
}),
|
|
236
|
+
output: z.object({
|
|
237
|
+
results: z.array(property)
|
|
238
|
+
}),
|
|
239
|
+
idempotent: true,
|
|
240
|
+
run ({ client, input, req }) {
|
|
241
|
+
return client.request(z.object({
|
|
242
|
+
results: z.array(property)
|
|
243
|
+
}), {
|
|
244
|
+
path: `/crm/v3/properties/${input.objectType}`,
|
|
245
|
+
query: {
|
|
246
|
+
archived: input.archived
|
|
247
|
+
},
|
|
248
|
+
signal: signal(req)
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
//# sourceMappingURL=reads.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/actions/reads.ts"],"names":["z","signal","objectType","recordId","defineAction","cursorPage","pageInput","pageOutput","associationLabel","crmRecord","list","listMember","owner","pipeline","property","names","label","description","array","string","regex","optional","meta","listRecords","slug","input","object","properties","associations","output","idempotent","run","client","req","request","path","query","limit","after","cursor","associationsPage","results","from","id","coerce","to","toObjectId","associationTypes","paging","next","errors","message","category","default","listAssociations","fromType","toType","ids","min","max","cursors","record","labels","nextCursor","nullable","page","method","body","inputs","map","undefined","result","listsPage","lists","hasMore","boolean","offset","number","listLists","objectTypeId","count","Number","additionalProperties","String","listListMembers","listId","listOwners","archived","listPipelines","enum","listProperties"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AAExB,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,UAAU,EAAEC,QAAQ,QAAQ,eAAe;AACpD,SAASC,YAAY,QAAQ,eAAe;AAC5C,SAASC,UAAU,EAAEC,SAAS,EAAEC,UAAU,QAAQ,mBAAmB;AACrE,SACEC,gBAAgB,EAChBC,SAAS,EACTC,IAAI,EACJC,UAAU,EACVC,KAAK,EACLC,QAAQ,EACRC,QAAQ,QACH,gBAAgB;AAEvB,MAAMC,QAAQ,CAACC,OAAeC,cAC5BjB,EACGkB,KAAK,CAAClB,EAAEmB,MAAM,GAAGC,KAAK,CAAC,YAAY,GAAGJ,MAAM,gCAAgC,CAAC,GAC7EK,QAAQ,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IACZC,KAAI,EAAEC,MAAM,EAAEP,KAAK,EAAEQ,GAAG,EAAE;QACxB,OAAOD,OAAOE,OAAO,CAAClC,EAAE0B,MAAM,CAAC;YAAEe,SAASzC,EAAEkB,KAAK,CAACJ;QAAU,IAAI;YAC9DqB,MAAM,CAAC,mBAAmB,EAAEV,MAAMvB,UAAU,EAAE;YAC9CkC,OAAO;gBAAEmD,UAAU9D,MAAM8D,QAAQ;YAAC;YAClCtF,QAAQA,OAAOgC;QACjB;IACF;AACF,GAAG","file":"reads.js"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const uploadFile: import("frogbot/pieces").PieceActionDefinition<z.ZodObject<{
|
|
3
|
+
folderId: z.ZodString;
|
|
4
|
+
fileName: z.ZodString;
|
|
5
|
+
accessLevel: z.ZodEnum<{
|
|
6
|
+
PUBLIC_INDEXABLE: "PUBLIC_INDEXABLE";
|
|
7
|
+
PUBLIC_NOT_INDEXABLE: "PUBLIC_NOT_INDEXABLE";
|
|
8
|
+
PRIVATE: "PRIVATE";
|
|
9
|
+
}>;
|
|
10
|
+
file: z.ZodObject<{
|
|
11
|
+
fileId: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
12
|
+
name: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
name: z.ZodOptional<z.ZodString>;
|
|
17
|
+
path: z.ZodOptional<z.ZodString>;
|
|
18
|
+
url: z.ZodOptional<z.ZodString>;
|
|
19
|
+
defaultHostingUrl: z.ZodOptional<z.ZodString>;
|
|
20
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
type: z.ZodOptional<z.ZodString>;
|
|
22
|
+
extension: z.ZodOptional<z.ZodString>;
|
|
23
|
+
access: z.ZodOptional<z.ZodString>;
|
|
24
|
+
parentFolderId: z.ZodOptional<z.ZodString>;
|
|
25
|
+
createdAt: z.ZodOptional<z.ZodString>;
|
|
26
|
+
updatedAt: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>, Record<string, never>, {
|
|
28
|
+
json: (request: import("../client.js").HubSpotRequest) => Promise<unknown>;
|
|
29
|
+
request: <T>(schema: z.ZodType<T>, options: import("../client.js").HubSpotRequest) => Promise<T>;
|
|
30
|
+
authorize(headers: Headers): void;
|
|
31
|
+
}, {
|
|
32
|
+
id: string;
|
|
33
|
+
name?: string | undefined;
|
|
34
|
+
path?: string | undefined;
|
|
35
|
+
url?: string | undefined;
|
|
36
|
+
defaultHostingUrl?: string | undefined;
|
|
37
|
+
size?: number | undefined;
|
|
38
|
+
type?: string | undefined;
|
|
39
|
+
extension?: string | undefined;
|
|
40
|
+
access?: string | undefined;
|
|
41
|
+
parentFolderId?: string | undefined;
|
|
42
|
+
createdAt?: string | undefined;
|
|
43
|
+
updatedAt?: string | undefined;
|
|
44
|
+
}> & {
|
|
45
|
+
slug: "uploadFile";
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=uploadFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../../src/actions/uploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAsBxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BrB,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { signal } from '../client.js';
|
|
3
|
+
import { defineAction } from '../define.js';
|
|
4
|
+
import { fileInput, loadFile } from '../files.js';
|
|
5
|
+
import { folderOptions } from './options.js';
|
|
6
|
+
const uploaded = z.object({
|
|
7
|
+
id: z.string(),
|
|
8
|
+
name: z.string().optional(),
|
|
9
|
+
path: z.string().optional(),
|
|
10
|
+
url: z.string().optional(),
|
|
11
|
+
defaultHostingUrl: z.string().optional(),
|
|
12
|
+
size: z.number().optional(),
|
|
13
|
+
type: z.string().optional(),
|
|
14
|
+
extension: z.string().optional(),
|
|
15
|
+
access: z.string().optional(),
|
|
16
|
+
parentFolderId: z.string().optional(),
|
|
17
|
+
createdAt: z.string().optional(),
|
|
18
|
+
updatedAt: z.string().optional()
|
|
19
|
+
});
|
|
20
|
+
export const uploadFile = defineAction({
|
|
21
|
+
slug: 'uploadFile',
|
|
22
|
+
description: "Upload a FrogBot file to a folder in HubSpot's file manager.",
|
|
23
|
+
input: z.object({
|
|
24
|
+
folderId: z.string().regex(/^\d+$/).meta({
|
|
25
|
+
label: 'Folder'
|
|
26
|
+
}),
|
|
27
|
+
fileName: z.string().min(1).meta({
|
|
28
|
+
label: 'File name'
|
|
29
|
+
}),
|
|
30
|
+
accessLevel: z.enum([
|
|
31
|
+
'PUBLIC_INDEXABLE',
|
|
32
|
+
'PUBLIC_NOT_INDEXABLE',
|
|
33
|
+
'PRIVATE'
|
|
34
|
+
]).meta({
|
|
35
|
+
label: 'Access level'
|
|
36
|
+
}),
|
|
37
|
+
file: fileInput
|
|
38
|
+
}),
|
|
39
|
+
output: uploaded,
|
|
40
|
+
idempotent: false,
|
|
41
|
+
options: {
|
|
42
|
+
folderId: folderOptions
|
|
43
|
+
},
|
|
44
|
+
async run ({ client, input, req, overrideAccess }) {
|
|
45
|
+
const file = await loadFile(req, input.file, overrideAccess);
|
|
46
|
+
const form = new FormData();
|
|
47
|
+
form.append('file', new Blob([
|
|
48
|
+
file.data
|
|
49
|
+
], {
|
|
50
|
+
type: file.mimeType
|
|
51
|
+
}), input.fileName);
|
|
52
|
+
form.append('folderId', input.folderId);
|
|
53
|
+
form.append('fileName', input.fileName);
|
|
54
|
+
form.append('options', JSON.stringify({
|
|
55
|
+
access: input.accessLevel
|
|
56
|
+
}));
|
|
57
|
+
return client.request(uploaded, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
path: '/files/v3/files',
|
|
60
|
+
body: form,
|
|
61
|
+
signal: signal(req)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=uploadFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/actions/uploadFile.ts"],"names":["z","signal","defineAction","fileInput","loadFile","folderOptions","uploaded","object","id","string","name","optional","path","url","defaultHostingUrl","size","number","type","extension","access","parentFolderId","createdAt","updatedAt","uploadFile","slug","description","input","folderId","regex","meta","label","fileName","min","accessLevel","enum","file","output","idempotent","options","run","client","req","overrideAccess","form","FormData","append","Blob","data","mimeType","JSON","stringify","request","method","body"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AAExB,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,YAAY,QAAQ,eAAe;AAC5C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,cAAc;AAClD,SAASC,aAAa,QAAQ,eAAe;AAE7C,MAAMC,WAAWN,EAAEO,MAAM,CAAC;IACxBC,IAAIR,EAAES,MAAM;IACZC,MAAMV,EAAES,MAAM,GAAGE,QAAQ;IACzBC,MAAMZ,EAAES,MAAM,GAAGE,QAAQ;IACzBE,KAAKb,EAAES,MAAM,GAAGE,QAAQ;IACxBG,mBAAmBd,EAAES,MAAM,GAAGE,QAAQ;IACtCI,MAAMf,EAAEgB,MAAM,GAAGL,QAAQ;IACzBM,MAAMjB,EAAES,MAAM,GAAGE,QAAQ;IACzBO,WAAWlB,EAAES,MAAM,GAAGE,QAAQ;IAC9BQ,QAAQnB,EAAES,MAAM,GAAGE,QAAQ;IAC3BS,gBAAgBpB,EAAES,MAAM,GAAGE,QAAQ;IACnCU,WAAWrB,EAAES,MAAM,GAAGE,QAAQ;IAC9BW,WAAWtB,EAAES,MAAM,GAAGE,QAAQ;AAChC;AAEA,OAAO,MAAMY,aAAarB,aAAa;IACrCsB,MAAM;IACNC,aAAa;IACbC,OAAO1B,EAAEO,MAAM,CAAC;QACdoB,UAAU3B,EAAES,MAAM,GAAGmB,KAAK,CAAC,SAASC,IAAI,CAAC;YAAEC,OAAO;QAAS;QAC3DC,UAAU/B,EAAES,MAAM,GAAGuB,GAAG,CAAC,GAAGH,IAAI,CAAC;YAAEC,OAAO;QAAY;QACtDG,aAAajC,EACVkC,IAAI,CAAC;YAAC;YAAoB;YAAwB;SAAU,EAC5DL,IAAI,CAAC;YAAEC,OAAO;QAAe;QAChCK,MAAMhC;IACR;IACAiC,QAAQ9B;IACR+B,YAAY;IACZC,SAAS;QAAEX,UAAUtB;IAAc;IACnC,MAAMkC,KAAI,EAAEC,MAAM,EAAEd,KAAK,EAAEe,GAAG,EAAEC,cAAc,EAAE;QAC9C,MAAMP,OAAO,MAAM/B,SAASqC,KAAKf,MAAMS,IAAI,EAAEO;QAC7C,MAAMC,OAAO,IAAIC;QAEjBD,KAAKE,MAAM,CAAC,QAAQ,IAAIC,KAAK;YAACX,KAAKY,IAAI;SAAC,EAAE;YAAE9B,MAAMkB,KAAKa,QAAQ;QAAC,IAAItB,MAAMK,QAAQ;QAClFY,KAAKE,MAAM,CAAC,YAAYnB,MAAMC,QAAQ;QACtCgB,KAAKE,MAAM,CAAC,YAAYnB,MAAMK,QAAQ;QACtCY,KAAKE,MAAM,CAAC,WAAWI,KAAKC,SAAS,CAAC;YAAE/B,QAAQO,MAAMO,WAAW;QAAC;QAElE,OAAOO,OAAOW,OAAO,CAAC7C,UAAU;YAC9B8C,QAAQ;YACRxC,MAAM;YACNyC,MAAMV;YACN1C,QAAQA,OAAOwC;QACjB;IACF;AACF,GAAG","file":"uploadFile.js"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FrogBotRequest } from 'frogbot/pieces';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
type Query = Record<string, string | number | boolean | readonly string[] | undefined>;
|
|
4
|
+
export type HubSpotRequest = {
|
|
5
|
+
method?: string;
|
|
6
|
+
/** A path under the API root, such as `/crm/v3/owners`. */
|
|
7
|
+
path: string;
|
|
8
|
+
query?: Query;
|
|
9
|
+
/** JSON, or `FormData` sent as multipart. */
|
|
10
|
+
body?: unknown;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
};
|
|
13
|
+
export type HubSpotClient = ReturnType<typeof createHubSpotClient>;
|
|
14
|
+
export declare const hubspotApi = "https://api.hubapi.com";
|
|
15
|
+
export declare class HubSpotError extends Error {
|
|
16
|
+
readonly status: number;
|
|
17
|
+
/** HubSpot's error category, such as `VALIDATION_ERROR` or `RATE_LIMITS`. */
|
|
18
|
+
readonly category: string | undefined;
|
|
19
|
+
readonly body: unknown;
|
|
20
|
+
constructor(status: number, message: string, category: string | undefined, body: unknown);
|
|
21
|
+
}
|
|
22
|
+
export declare function createHubSpotClient({ auth }: {
|
|
23
|
+
auth: unknown;
|
|
24
|
+
}): {
|
|
25
|
+
json: (request: HubSpotRequest) => Promise<unknown>;
|
|
26
|
+
request: <T>(schema: z.ZodType<T>, options: HubSpotRequest) => Promise<T>;
|
|
27
|
+
authorize(headers: Headers): void;
|
|
28
|
+
};
|
|
29
|
+
export declare function signal(req: FrogBotRequest): AbortSignal | undefined;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;AAEvF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,6CAA6C;IAC7C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEnE,eAAO,MAAM,UAAU,2BAA2B,CAAC;AAUnD,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAEX,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,OAAO;CAOzF;AAoDD,wBAAgB,mBAAmB,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE;oBAgBhC,cAAc,KAAG,OAAO,CAAC,OAAO,CAAC;cAsCvC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,cAAc,KAAG,OAAO,CAAC,CAAC,CAAC;uBAO/D,OAAO;EAI7B;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,cAAc,2BAIzC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { hubspotAuth } from './config.js';
|
|
3
|
+
export const hubspotApi = 'https://api.hubapi.com';
|
|
4
|
+
const maxRetries = 3;
|
|
5
|
+
const defaultRetrySeconds = 10;
|
|
6
|
+
const hubspotErrorBody = z.object({
|
|
7
|
+
message: z.string().optional(),
|
|
8
|
+
category: z.string().optional()
|
|
9
|
+
});
|
|
10
|
+
export class HubSpotError extends Error {
|
|
11
|
+
status;
|
|
12
|
+
/** HubSpot's error category, such as `VALIDATION_ERROR` or `RATE_LIMITS`. */ category;
|
|
13
|
+
body;
|
|
14
|
+
constructor(status, message, category, body){
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'HubSpotError';
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.category = category;
|
|
19
|
+
this.body = body;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function parseJson(text) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(text);
|
|
25
|
+
} catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function failure(response) {
|
|
30
|
+
const text = await response.text().catch(()=>'');
|
|
31
|
+
const body = parseJson(text);
|
|
32
|
+
const parsed = hubspotErrorBody.safeParse(body);
|
|
33
|
+
const category = parsed.success ? parsed.data.category : undefined;
|
|
34
|
+
const detail = parsed.success && parsed.data.message ? parsed.data.message : text.slice(0, 500);
|
|
35
|
+
const status = category ? `${response.status} ${category}` : String(response.status);
|
|
36
|
+
return new HubSpotError(response.status, `HubSpot request failed (${status})${detail ? `: ${detail}` : ''}`, category, body);
|
|
37
|
+
}
|
|
38
|
+
function retryDelay(header) {
|
|
39
|
+
const seconds = header === null ? defaultRetrySeconds : Number(header);
|
|
40
|
+
return Number.isFinite(seconds) ? Math.min(Math.max(seconds, 0), 120) * 1000 : defaultRetrySeconds * 1000;
|
|
41
|
+
}
|
|
42
|
+
function wait(ms, signal) {
|
|
43
|
+
return new Promise((resolve, reject)=>{
|
|
44
|
+
signal?.throwIfAborted();
|
|
45
|
+
const abort = ()=>{
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
reject(signal?.reason instanceof Error ? signal.reason : new Error('Aborted.'));
|
|
48
|
+
};
|
|
49
|
+
const timer = setTimeout(()=>{
|
|
50
|
+
signal?.removeEventListener('abort', abort);
|
|
51
|
+
resolve();
|
|
52
|
+
}, ms);
|
|
53
|
+
signal?.addEventListener('abort', abort, {
|
|
54
|
+
once: true
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export function createHubSpotClient({ auth }) {
|
|
59
|
+
const authorization = `Bearer ${hubspotAuth.parse(auth).accessToken}`;
|
|
60
|
+
function url(request) {
|
|
61
|
+
const path = request.path.startsWith('/') ? request.path : `/${request.path}`;
|
|
62
|
+
const target = new URL(`${hubspotApi}${path}`);
|
|
63
|
+
for (const [name, value] of Object.entries(request.query ?? {})){
|
|
64
|
+
if (value === undefined || Array.isArray(value) && value.length === 0) continue;
|
|
65
|
+
target.searchParams.set(name, Array.isArray(value) ? value.join(',') : String(value));
|
|
66
|
+
}
|
|
67
|
+
return target;
|
|
68
|
+
}
|
|
69
|
+
async function json(request) {
|
|
70
|
+
const target = url(request);
|
|
71
|
+
const multipart = request.body instanceof FormData;
|
|
72
|
+
const isJson = request.body !== undefined && !multipart;
|
|
73
|
+
for(let attempt = 0;; attempt++){
|
|
74
|
+
const result = await fetch(target, {
|
|
75
|
+
method: request.method ?? 'GET',
|
|
76
|
+
headers: {
|
|
77
|
+
authorization,
|
|
78
|
+
accept: 'application/json',
|
|
79
|
+
...isJson ? {
|
|
80
|
+
'content-type': 'application/json'
|
|
81
|
+
} : {}
|
|
82
|
+
},
|
|
83
|
+
body: multipart ? request.body : isJson ? JSON.stringify(request.body) : undefined,
|
|
84
|
+
redirect: 'error',
|
|
85
|
+
signal: request.signal
|
|
86
|
+
});
|
|
87
|
+
if (result.ok) {
|
|
88
|
+
const text = result.status === 204 ? '' : await result.text();
|
|
89
|
+
return text ? JSON.parse(text) : undefined;
|
|
90
|
+
}
|
|
91
|
+
if (result.status === 429 && attempt < maxRetries) {
|
|
92
|
+
await result.body?.cancel();
|
|
93
|
+
await wait(retryDelay(result.headers.get('retry-after')), request.signal);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
throw await failure(result);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function request(schema, options) {
|
|
100
|
+
return schema.parse(await json(options));
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
json,
|
|
104
|
+
request,
|
|
105
|
+
authorize (headers) {
|
|
106
|
+
headers.set('authorization', authorization);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export function signal(req) {
|
|
111
|
+
req.signal?.throwIfAborted();
|
|
112
|
+
return req.signal ?? undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":["z","hubspotAuth","hubspotApi","maxRetries","defaultRetrySeconds","hubspotErrorBody","object","message","string","optional","category","HubSpotError","Error","status","body","name","parseJson","text","JSON","parse","undefined","failure","response","catch","parsed","safeParse","success","data","detail","slice","String","retryDelay","header","seconds","Number","isFinite","Math","min","max","wait","ms","signal","Promise","resolve","reject","throwIfAborted","abort","clearTimeout","timer","reason","setTimeout","removeEventListener","addEventListener","once","createHubSpotClient","auth","authorization","accessToken","url","request","path","startsWith","target","URL","value","Object","entries","query","Array","isArray","length","searchParams","set","join","json","multipart","FormData","isJson","attempt","result","fetch","method","headers","accept","stringify","redirect","ok","cancel","get","schema","options","authorize","req"],"mappings":"AACA,SAASA,CAAC,QAAQ,MAAM;AAExB,SAASC,WAAW,QAAQ,cAAc;AAgB1C,OAAO,MAAMC,aAAa,yBAAyB;AAEnD,MAAMC,aAAa;AACnB,MAAMC,sBAAsB;AAE5B,MAAMC,mBAAmBL,EAAEM,MAAM,CAAC;IAChCC,SAASP,EAAEQ,MAAM,GAAGC,QAAQ;IAC5BC,UAAUV,EAAEQ,MAAM,GAAGC,QAAQ;AAC/B;AAEA,OAAO,MAAME,qBAAqBC;IACvBC,OAAe;IACxB,2EAA2E,GAC3E,AAASH,SAA6B;IAC7BI,KAAc;IAEvB,YAAYD,MAAc,EAAEN,OAAe,EAAEG,QAA4B,EAAEI,IAAa,CAAE;QACxF,KAAK,CAACP;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D,MAAM6D,YACDhB,QAAQ7C,IAAI,GACb+D,SACE3D,KAAKkE,SAAS,CAACzB,QAAQ7C,IAAI,IAC3BM;gBACNiE,UAAU;gBACV5C,QAAQkB,QAAQlB,MAAM;YACxB;YAEA,IAAIsC,OAAOO,EAAE,EAAE;gBACb,MAAMrE,OAAO8D,OAAOlE,MAAM,KAAK,MAAM,KAAK,MAAMkE,OAAO9D,IAAI;gBAE3D,OAAOA,OAAOC,KAAKC,KAAK,CAACF,QAAQG;YACnC;YAEA,IAAI2D,OAAOlE,MAAM,KAAK,OAAOiE,UAAU3E,YAAY;gBACjD,MAAM4E,OAAOjE,IAAI,EAAEyE;gBACnB,MAAMhD,KAAKR,WAAWgD,OAAOG,OAAO,CAACM,GAAG,CAAC,iBAAiB7B,QAAQlB,MAAM;gBACxE;YACF;YAEA,MAAM,MAAMpB,QAAQ0D;QACtB;IACF;IAEA,eAAepB,QAAW8B,MAAoB,EAAEC,OAAuB;QACrE,OAAOD,OAAOtE,KAAK,CAAC,MAAMuD,KAAKgB;IACjC;IAEA,OAAO;QACLhB;QACAf;QACAgC,WAAUT,OAAgB;YACxBA,QAAQV,GAAG,CAAC,iBAAiBhB;QAC/B;IACF;AACF;AAEA,OAAO,SAASf,OAAOmD,GAAmB;IACxCA,IAAInD,MAAM,EAAEI;IAEZ,OAAO+C,IAAInD,MAAM,IAAIrB;AACvB","file":"client.js"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** A service key, an existing private-app token, or the access token from a HubSpot sign-in. All are bearer tokens. */
|
|
3
|
+
export declare const hubspotAuth: z.ZodObject<{
|
|
4
|
+
accessToken: z.ZodString;
|
|
5
|
+
}, z.core.$strip>;
|
|
6
|
+
export type HubSpotAuth = z.output<typeof hubspotAuth>;
|
|
7
|
+
export declare const standardObjectTypes: readonly ["contacts", "companies", "deals", "tickets", "notes", "emails", "calls", "meetings", "tasks", "line_items", "products"];
|
|
8
|
+
/** A standard CRM object, or a custom object's type ID such as `2-3456789`. */
|
|
9
|
+
export declare const objectType: z.ZodUnion<readonly [z.ZodEnum<{
|
|
10
|
+
contacts: "contacts";
|
|
11
|
+
companies: "companies";
|
|
12
|
+
deals: "deals";
|
|
13
|
+
tickets: "tickets";
|
|
14
|
+
notes: "notes";
|
|
15
|
+
emails: "emails";
|
|
16
|
+
calls: "calls";
|
|
17
|
+
meetings: "meetings";
|
|
18
|
+
tasks: "tasks";
|
|
19
|
+
line_items: "line_items";
|
|
20
|
+
products: "products";
|
|
21
|
+
}>, z.ZodTemplateLiteral<`2-${number}`>]>;
|
|
22
|
+
export type ObjectType = z.output<typeof objectType>;
|
|
23
|
+
export declare const recordId: (label: string) => z.ZodString;
|
|
24
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,uHAAuH;AACvH,eAAO,MAAM,WAAW;;iBAEtB,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAEvD,eAAO,MAAM,mBAAmB,mIAYtB,CAAC;AAEX,+EAA+E;AAC/E,eAAO,MAAM,UAAU;;;;;;;;;;;;yCAKnB,CAAC;AAEL,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAErD,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,gBAC0D,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** A service key, an existing private-app token, or the access token from a HubSpot sign-in. All are bearer tokens. */ export const hubspotAuth = z.object({
|
|
3
|
+
accessToken: z.string().min(1).meta({
|
|
4
|
+
label: 'Access token',
|
|
5
|
+
secret: true
|
|
6
|
+
})
|
|
7
|
+
});
|
|
8
|
+
export const standardObjectTypes = [
|
|
9
|
+
'contacts',
|
|
10
|
+
'companies',
|
|
11
|
+
'deals',
|
|
12
|
+
'tickets',
|
|
13
|
+
'notes',
|
|
14
|
+
'emails',
|
|
15
|
+
'calls',
|
|
16
|
+
'meetings',
|
|
17
|
+
'tasks',
|
|
18
|
+
'line_items',
|
|
19
|
+
'products'
|
|
20
|
+
];
|
|
21
|
+
/** A standard CRM object, or a custom object's type ID such as `2-3456789`. */ export const objectType = z.union([
|
|
22
|
+
z.enum(standardObjectTypes),
|
|
23
|
+
z.templateLiteral([
|
|
24
|
+
'2-',
|
|
25
|
+
z.number().int().nonnegative()
|
|
26
|
+
])
|
|
27
|
+
]).meta({
|
|
28
|
+
label: 'Object type',
|
|
29
|
+
description: `One of ${standardObjectTypes.join(', ')}, or a custom object type ID such as 2-3456789.`
|
|
30
|
+
});
|
|
31
|
+
export const recordId = (label)=>z.string().trim().regex(/^\d+$/, `${label} must be a HubSpot ID, such as 51.`).meta({
|
|
32
|
+
label
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"names":["z","hubspotAuth","object","accessToken","string","min","meta","label","secret","standardObjectTypes","objectType","union","enum","templateLiteral","number","int","nonnegative","description","join","recordId","trim","regex"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AAExB,qHAAqH,GACrH,OAAO,MAAMC,cAAcD,EAAEE,MAAM,CAAC;IAClCC,aAAaH,EAAEI,MAAM,GAAGC,GAAG,CAAC,GAAGC,IAAI,CAAC;QAAEC,OAAO;QAAgBC,QAAQ;IAAK;AAC5E,GAAG;AAIH,OAAO,MAAMC,sBAAsB;IACjC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAU;AAEX,6EAA6E,GAC7E,OAAO,MAAMC,aAAaV,EACvBW,KAAK,CAAC;IAACX,EAAEY,IAAI,CAACH;IAAsBT,EAAEa,eAAe,CAAC;QAAC;QAAMb,EAAEc,MAAM,GAAGC,GAAG,GAAGC,WAAW;KAAG;CAAE,EAC9FV,IAAI,CAAC;IACJC,OAAO;IACPU,aAAa,CAAC,OAAO,EAAER,oBAAoBS,IAAI,CAAC,MAAM,+CAA+C,CAAC;AACxG,GAAG;AAIL,OAAO,MAAMC,WAAW,CAACZ,QACvBP,EAAEI,MAAM,GAAGgB,IAAI,GAAGC,KAAK,CAAC,SAAS,GAAGd,MAAM,kCAAkC,CAAC,EAAED,IAAI,CAAC;QAAEC;IAAM,GAAG","file":"config.js"}
|