@superdurable/connector-hootsuite 0.0.0-stage → 0.1.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/dist/index.js ADDED
@@ -0,0 +1,485 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ ListScheduledPostsBranch,
6
+ ListScheduledPostsBranchDefect,
7
+ ListScheduledPostsBranchInvalidResponse,
8
+ ListScheduledPostsBranchListed,
9
+ ListScheduledPostsBranchProviderRejected,
10
+ ListScheduledPostsDefinition,
11
+ ListScheduledPostsInputSchema,
12
+ ListScheduledPostsMetadata,
13
+ ListSocialProfilesBranch,
14
+ ListSocialProfilesBranchDefect,
15
+ ListSocialProfilesBranchInvalidResponse,
16
+ ListSocialProfilesBranchListed,
17
+ ListSocialProfilesBranchProviderRejected,
18
+ ListSocialProfilesDefinition,
19
+ ListSocialProfilesInputSchema,
20
+ ListSocialProfilesMetadata,
21
+ ProviderID,
22
+ SchedulePostBranch,
23
+ SchedulePostBranchDefect,
24
+ SchedulePostBranchProviderRejected,
25
+ SchedulePostBranchScheduled,
26
+ SchedulePostBranchUncertain,
27
+ SchedulePostDefinition,
28
+ SchedulePostInputSchema,
29
+ SchedulePostMetadata,
30
+ ScheduledPostReceiptSchema,
31
+ ScheduledPostSchema,
32
+ ScheduledPostsPageSchema,
33
+ SocialProfileSchema,
34
+ SocialProfilesPageSchema,
35
+ decodeCredentials,
36
+ decodeSharedCredentials,
37
+ newConnection,
38
+ newConnectionWithOperations,
39
+ newProjectCredentialProvider
40
+ } from "./chunk-LBB5UANL.js";
41
+
42
+ // src/generated/steps.ts
43
+ import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
44
+ function newListSocialProfilesStep(configuration) {
45
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
46
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
47
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listSocialProfiles(), connection: connection.reference, branches: [
48
+ goToBranch("listed", listed),
49
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
50
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
51
+ ...defect ? [goToBranch("defect", defect)] : []
52
+ ] });
53
+ }
54
+ function newListScheduledPostsStep(configuration) {
55
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
56
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
57
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listScheduledPosts(), connection: connection.reference, branches: [
58
+ goToBranch("listed", listed),
59
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
60
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
61
+ ...defect ? [goToBranch("defect", defect)] : []
62
+ ] });
63
+ }
64
+ function newSchedulePostStep(configuration) {
65
+ const { connection, connectionName, scheduled, providerRejected, uncertain, defect, ...stepConfiguration } = configuration;
66
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
67
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.schedulePost(), connection: connection.reference, branches: [
68
+ goToBranch("scheduled", scheduled),
69
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
70
+ ...uncertain ? [goToBranch("uncertain", uncertain)] : [],
71
+ ...defect ? [goToBranch("defect", defect)] : []
72
+ ] });
73
+ }
74
+
75
+ // src/client.ts
76
+ import { SecretString, ReauthorizationRequiredError, resolveCredential, newQueryBranch, newQueryRetry, newMutationBranch, newMutationRetry, newMutationUncertain } from "@superdurable/connectors-sdk";
77
+ import { ManifestCredentialRefreshDriver } from "@superdurable/connectors-sdk/oauthtoken";
78
+ import { BodyTooLargeError, ProviderTransportError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
79
+ import { CheckpointError, InsufficientTimeError, newFence } from "@superdurable/connectors-sdk/singledispatch";
80
+
81
+ // src/generated/refresh.ts
82
+ var Authorization = {
83
+ "fields": [
84
+ {
85
+ "name": "oauth_client_id",
86
+ "required": true,
87
+ "type": "string"
88
+ },
89
+ {
90
+ "name": "oauth_client_secret",
91
+ "required": true,
92
+ "type": "secretString"
93
+ },
94
+ {
95
+ "name": "access_token",
96
+ "required": true,
97
+ "type": "secretString"
98
+ },
99
+ {
100
+ "name": "refresh_token",
101
+ "required": true,
102
+ "type": "secretString"
103
+ }
104
+ ],
105
+ "oauth2": {
106
+ "clientIDCredential": "oauth_client_id",
107
+ "clientSecretCredential": "oauth_client_secret",
108
+ "credentialMappings": [
109
+ {
110
+ "credential": "access_token",
111
+ "source": "access_token"
112
+ },
113
+ {
114
+ "credential": "refresh_token",
115
+ "source": "refresh_token"
116
+ }
117
+ ],
118
+ "refresh": {
119
+ "missingExpiry": "reject",
120
+ "storedMissingExpiry": "refresh",
121
+ "terminalErrorCodes": [
122
+ "invalid_grant",
123
+ "invalid_client",
124
+ "unauthorized_client"
125
+ ],
126
+ "tokenExchangeTimeout": "15s"
127
+ },
128
+ "scopes": [
129
+ "offline"
130
+ ],
131
+ "tokenEndpoint": "https://platform.hootsuite.com/oauth2/token",
132
+ "tokenEndpointAuthMethod": "client_secret_basic"
133
+ },
134
+ "refreshable": true,
135
+ "type": "oauth2"
136
+ };
137
+ var CredentialFields = {
138
+ "access_token": "accessToken",
139
+ "oauth_client_id": "oauthClientId",
140
+ "oauth_client_secret": "oauthClientSecret",
141
+ "refresh_token": "refreshToken"
142
+ };
143
+
144
+ // src/client.ts
145
+ var emptyProfiles = () => ({ profiles: [] });
146
+ var emptyScheduledPosts = () => ({ posts: [], nextCursor: "" });
147
+ var emptyReceipt = () => ({ id: "", state: "", socialProfileId: "" });
148
+ var numericID = /^[0-9]{1,40}$/;
149
+ var utcInstant = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
150
+ var HootsuiteClient = class {
151
+ /** Validate configuration without contacting Hootsuite. */
152
+ constructor(config, credentials, options = {}) {
153
+ this.credentials = credentials;
154
+ if (!config || !credentials) throw new TypeError("Hootsuite configuration and credentials are required");
155
+ this.baseURL = validateBaseURL(config.baseUrl || "https://platform.hootsuite.com");
156
+ this.timeoutMs = config.timeoutMs || 15e3;
157
+ this.maxResponseBytes = config.maxResponseBytes || 1048576;
158
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0) throw new TypeError("Hootsuite request limits are invalid");
159
+ this.refreshDriver = options.refreshDriver ?? new ManifestCredentialRefreshDriver({
160
+ providerName: "Hootsuite",
161
+ auth: Authorization,
162
+ credentialFields: CredentialFields
163
+ });
164
+ this.sendRequest = options.send ?? sendProviderRequest;
165
+ this.now = options.now ?? (() => /* @__PURE__ */ new Date());
166
+ }
167
+ credentials;
168
+ baseURL;
169
+ timeoutMs;
170
+ maxResponseBytes;
171
+ refreshDriver;
172
+ sendRequest;
173
+ now;
174
+ /** Bind the social profile Query. */
175
+ listSocialProfiles() {
176
+ return new ListSocialProfilesOperation(this);
177
+ }
178
+ /** Bind the scheduled message Query. */
179
+ listScheduledPosts() {
180
+ return new ListScheduledPostsOperation(this);
181
+ }
182
+ /** Bind the scheduled message Mutation. */
183
+ schedulePost() {
184
+ return new SchedulePostOperation(this);
185
+ }
186
+ /** Resolve a header-safe access token for the current call. */
187
+ async resolveToken(call) {
188
+ try {
189
+ const resolved = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
190
+ const token = resolved.accessToken instanceof SecretString ? resolved.accessToken.reveal() : "";
191
+ return token && isHeaderSafeCredential(token) ? token : failedExchange("credential");
192
+ } catch (error) {
193
+ return failedExchange(error instanceof ReauthorizationRequiredError ? "credential" : "refresh");
194
+ }
195
+ }
196
+ /** Read one bounded provider response for a Query. */
197
+ async get(call, path) {
198
+ const token = await this.resolveToken(call);
199
+ if (typeof token !== "string") return token;
200
+ return this.send("GET", path, token, call.context.cancellationSignal);
201
+ }
202
+ /** Send one authenticated request; the caller owns dispatch fencing for writes. */
203
+ async send(method, path, token, signal, body) {
204
+ const request = {
205
+ url: this.baseURL + path,
206
+ method,
207
+ headers: {
208
+ Accept: "application/json",
209
+ Authorization: `Bearer ${token}`,
210
+ "User-Agent": "Dex Connector (https://superdurable.io)",
211
+ ...body === void 0 ? {} : { "Content-Type": "application/json;charset=utf-8" }
212
+ },
213
+ ...body === void 0 ? {} : { body },
214
+ maxResponseBytes: this.maxResponseBytes,
215
+ timeoutMs: this.timeoutMs,
216
+ addressPolicy: this.baseURL.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP",
217
+ signal
218
+ };
219
+ let response;
220
+ try {
221
+ response = await this.sendRequest(request);
222
+ } catch (error) {
223
+ if (error instanceof BodyTooLargeError && error.status !== void 0) return {
224
+ ...failedExchange("tooLarge"),
225
+ status: error.status,
226
+ requestSent: true,
227
+ retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"), this.now())
228
+ };
229
+ if (error instanceof ProviderTransportError) return { ...failedExchange("request"), requestSent: !error.isProvablyNotSent };
230
+ return failedExchange("request");
231
+ }
232
+ const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"), this.now());
233
+ if (Buffer.from(response.body).includes(token)) return { ...failedExchange("credential"), status: response.status, requestSent: true, retryAfterMs };
234
+ if (response.body.length > this.maxResponseBytes) return { ...failedExchange("tooLarge"), status: response.status, requestSent: true, retryAfterMs };
235
+ return { status: response.status, body: response.body, retryAfterMs, requestSent: true };
236
+ }
237
+ };
238
+ var ListSocialProfilesOperation = class {
239
+ /** Bind the provider client. */
240
+ constructor(client) {
241
+ this.client = client;
242
+ }
243
+ client;
244
+ /** Return the generated Query definition. */
245
+ definition() {
246
+ return ListSocialProfilesDefinition;
247
+ }
248
+ /** Project one bounded provider response. */
249
+ async invoke(call, input) {
250
+ if (!input || typeof input !== "object") return queryBranch("listSocialProfiles", "defect", "VALIDATION", "social profile input is invalid", emptyProfiles());
251
+ const exchange = await this.client.get(call, "/v1/socialProfiles");
252
+ const decision = queryFailure("listSocialProfiles", exchange, emptyProfiles());
253
+ if (decision) return decision;
254
+ const document = parseJSON(exchange.body);
255
+ if (!isObject(document) || !Array.isArray(document.data) || document.data.length > 1e3) return queryBranch("listSocialProfiles", "invalidResponse", "PROTOCOL", "Hootsuite returned invalid social profile JSON", emptyProfiles());
256
+ const profiles = [];
257
+ for (const item of document.data) {
258
+ if (!isObject(item) || typeof item.id !== "string" || !item.id || typeof item.type !== "string" || !item.type || typeof item.socialNetworkUsername !== "string" || !item.socialNetworkUsername) return queryBranch("listSocialProfiles", "invalidResponse", "PROTOCOL", "Hootsuite returned incomplete social profile metadata", emptyProfiles());
259
+ profiles.push({ id: item.id, type: item.type, username: item.socialNetworkUsername });
260
+ }
261
+ return newQueryBranch("listed", { profiles });
262
+ }
263
+ };
264
+ var ListScheduledPostsOperation = class {
265
+ /** Bind the provider client. */
266
+ constructor(client) {
267
+ this.client = client;
268
+ }
269
+ client;
270
+ /** Return the generated Query definition. */
271
+ definition() {
272
+ return ListScheduledPostsDefinition;
273
+ }
274
+ /** Read one UTC interval of at most four weeks. */
275
+ async invoke(call, input) {
276
+ const start = utcTime(input?.startTime);
277
+ const end = utcTime(input?.endTime);
278
+ if (start === void 0 || end === void 0 || end <= start || end - start > 28 * 24 * 60 * 60 * 1e3 || typeof input.socialProfileId !== "string" && input.socialProfileId !== void 0 || typeof input.cursor !== "string" && input.cursor !== void 0 || (input.socialProfileId?.length ?? 0) > 40 || (input.cursor?.length ?? 0) > 4096 || !safeQueryValue(input.socialProfileId ?? "") || !safeQueryValue(input.cursor ?? "")) return queryBranch("listScheduledPosts", "defect", "VALIDATION", "scheduled post interval or filter is invalid", emptyScheduledPosts());
279
+ const query = new URLSearchParams({ startTime: input.startTime, endTime: input.endTime, state: "SCHEDULED", limit: "100" });
280
+ if (input.socialProfileId) query.set("socialProfileIds", input.socialProfileId);
281
+ if (input.cursor) query.set("cursor", input.cursor);
282
+ const exchange = await this.client.get(call, `/v1/messages?${query}`);
283
+ const decision = queryFailure("listScheduledPosts", exchange, emptyScheduledPosts());
284
+ if (decision) return decision;
285
+ const document = parseJSON(exchange.body);
286
+ if (!isObject(document) || !Array.isArray(document.data) || document.data.length > 100) return queryBranch("listScheduledPosts", "invalidResponse", "PROTOCOL", "Hootsuite returned invalid scheduled message JSON", emptyScheduledPosts());
287
+ const posts = [];
288
+ for (const item of document.data) {
289
+ if (!isObject(item) || typeof item.id !== "string" || !item.id || item.state !== "SCHEDULED" || typeof item.scheduledSendTime !== "string" || !item.scheduledSendTime || !isObject(item.socialProfile) || typeof item.socialProfile.id !== "string" || !item.socialProfile.id) return queryBranch("listScheduledPosts", "invalidResponse", "PROTOCOL", "Hootsuite returned incomplete scheduled message metadata", emptyScheduledPosts());
290
+ posts.push({ id: item.id, state: item.state, socialProfileId: item.socialProfile.id, scheduledSendTime: item.scheduledSendTime });
291
+ }
292
+ const metadata = document.metadata ?? {};
293
+ if (!isObject(metadata)) return queryBranch("listScheduledPosts", "invalidResponse", "PROTOCOL", "Hootsuite returned an invalid page cursor", emptyScheduledPosts());
294
+ const cursor = metadata.cursor ?? {};
295
+ if (!isObject(cursor)) return queryBranch("listScheduledPosts", "invalidResponse", "PROTOCOL", "Hootsuite returned an invalid page cursor", emptyScheduledPosts());
296
+ const nextCursor = cursor.next ?? "";
297
+ if (typeof nextCursor !== "string" || nextCursor.length > 4096 || !safeQueryValue(nextCursor)) return queryBranch("listScheduledPosts", "invalidResponse", "PROTOCOL", "Hootsuite returned an invalid page cursor", emptyScheduledPosts());
298
+ return newQueryBranch("listed", { posts, nextCursor });
299
+ }
300
+ };
301
+ var SchedulePostOperation = class {
302
+ /** Bind the provider client. */
303
+ constructor(client) {
304
+ this.client = client;
305
+ }
306
+ client;
307
+ /** Return the generated Mutation definition. */
308
+ definition() {
309
+ return SchedulePostDefinition;
310
+ }
311
+ /** Record the Call ID; Hootsuite does not deduplicate this key. */
312
+ idempotencyKey(callID) {
313
+ return callID;
314
+ }
315
+ /** Send once, returning uncertainty when the provider may have accepted the post. */
316
+ async invoke(call, input) {
317
+ const operation = "schedulePost";
318
+ const empty = emptyReceipt();
319
+ let fence;
320
+ try {
321
+ fence = newFence(call, SchedulePostDefinition.stepDefaults.executeMethodTimeoutMs ?? 3e4);
322
+ } catch {
323
+ return newMutationBranch("defect", empty, {}, failure(operation, "LOCAL_DEFECT", "Hootsuite dispatch fence is unavailable"));
324
+ }
325
+ if (fence.decide().kind !== "sendAllowed") return newMutationUncertain(empty, failure(operation, "TRANSPORT", "Hootsuite schedule outcome cannot be confirmed; inspect Planner before resending"));
326
+ if (!input || typeof input.text !== "string" || !input.text.trim() || Buffer.from(input.text, "utf8").toString("utf8") !== input.text || Buffer.byteLength(input.text, "utf8") > 1e4 || typeof input.socialProfileId !== "string" || !numericID.test(input.socialProfileId) || utcTime(input.scheduledSendTime) === void 0) return newMutationBranch("defect", empty, {}, failure(operation, "VALIDATION", "scheduled message text, profile ID, or UTC time is invalid"));
327
+ const token = await this.client.resolveToken(call);
328
+ if (typeof token !== "string") {
329
+ if (token.error === "credential") return newMutationBranch("defect", empty, {}, failure(operation, "AUTHENTICATION", "connection credentials require reauthorization"));
330
+ return newMutationRetry(failure(operation, "TRANSPORT", "connection refresh failed"));
331
+ }
332
+ const body = Buffer.from(JSON.stringify({ text: input.text, socialProfileIds: [input.socialProfileId], scheduledSendTime: input.scheduledSendTime }));
333
+ let exchange;
334
+ try {
335
+ exchange = await fence.dispatch((signal) => this.client.send("POST", "/v1/messages", token, signal, body));
336
+ } catch (error) {
337
+ if (error instanceof CheckpointError || error instanceof InsufficientTimeError) return newMutationRetry(failure(operation, "TRANSPORT", "Hootsuite dispatch did not start"));
338
+ return newMutationUncertain(empty, failure(operation, "TRANSPORT", "Hootsuite schedule outcome is unknown"));
339
+ }
340
+ if (exchange.error === "request") {
341
+ if (!exchange.requestSent) {
342
+ try {
343
+ await fence.recordCanResend();
344
+ return newMutationRetry(failure(operation, "TRANSPORT", "Hootsuite could not be reached before sending"));
345
+ } catch {
346
+ }
347
+ }
348
+ return newMutationUncertain(empty, failure(operation, "TRANSPORT", "Hootsuite schedule outcome is unknown"));
349
+ }
350
+ if (exchange.status === 429 || exchange.status === 503) {
351
+ try {
352
+ await fence.recordCanResend();
353
+ } catch {
354
+ return newMutationRetry(failure(operation, "AVAILABILITY", "Hootsuite retry checkpoint is unavailable"));
355
+ }
356
+ const kind = exchange.status === 429 ? "RATE_LIMIT" : "AVAILABILITY";
357
+ return newMutationRetry(failure(operation, kind, "Hootsuite did not schedule the message"), exchange.retryAfterMs);
358
+ }
359
+ if (exchange.status === 408 || exchange.status >= 500) return newMutationUncertain(empty, failure(operation, "AVAILABILITY", "Hootsuite schedule outcome is unknown"));
360
+ if (exchange.status >= 400 && exchange.status < 500) return newMutationBranch("providerRejected", empty, {}, failure(operation, "PROVIDER_REJECTION", `Hootsuite rejected HTTP ${exchange.status}`));
361
+ if (exchange.status !== 200) return newMutationUncertain(empty, failure(operation, "PROTOCOL", "Hootsuite returned an unexpected schedule response"));
362
+ if (exchange.error) return newMutationUncertain(empty, failure(operation, "TRANSPORT", "Hootsuite accepted the request but its response could not be read"));
363
+ const document = parseJSON(exchange.body);
364
+ const data = isObject(document) ? document.data : void 0;
365
+ if (!Array.isArray(data) || data.length !== 1 || !isObject(data[0]) || typeof data[0].id !== "string" || !data[0].id || typeof data[0].state !== "string" || !data[0].state) return newMutationUncertain(empty, failure(operation, "PROTOCOL", "Hootsuite accepted the request but returned no usable message ID"));
366
+ const socialProfile = data[0].socialProfile ?? {};
367
+ if (!isObject(socialProfile) || socialProfile.id && socialProfile.id !== input.socialProfileId) return newMutationUncertain(empty, failure(operation, "PROTOCOL", "Hootsuite returned an unexpected social profile"));
368
+ try {
369
+ await fence.recordProviderId(data[0].id);
370
+ } catch {
371
+ }
372
+ return newMutationBranch("scheduled", { id: data[0].id, state: data[0].state, socialProfileId: input.socialProfileId });
373
+ }
374
+ };
375
+ function failure(operation, kind, message) {
376
+ return { provider: "hootsuite", operation, kind, message };
377
+ }
378
+ function queryBranch(operation, branch, kind, message, empty) {
379
+ return newQueryBranch(branch, empty, {}, failure(operation, kind, message));
380
+ }
381
+ function queryRetry(operation, kind, message, delay = 0) {
382
+ return newQueryRetry(failure(operation, kind, message), delay);
383
+ }
384
+ function queryFailure(operation, exchange, empty) {
385
+ if (exchange.error === "credential") return queryBranch(operation, "defect", "AUTHENTICATION", "connection credentials are unavailable or invalid", empty);
386
+ if (exchange.error === "request" || exchange.error === "refresh") return queryRetry(operation, "TRANSPORT", "Hootsuite request failed");
387
+ if (exchange.status === 429) return queryRetry(operation, "RATE_LIMIT", "Hootsuite rate limited the request", exchange.retryAfterMs);
388
+ if (exchange.status === 408 || exchange.status >= 500) return queryRetry(operation, "AVAILABILITY", "Hootsuite is temporarily unavailable", exchange.retryAfterMs);
389
+ if (exchange.status !== 200) return queryBranch(operation, "providerRejected", "PROVIDER_REJECTION", `Hootsuite rejected HTTP ${exchange.status}`, empty);
390
+ if (exchange.error === "tooLarge") return queryBranch(operation, "invalidResponse", "RESPONSE_TOO_LARGE", "Hootsuite response exceeded the configured limit", empty);
391
+ return void 0;
392
+ }
393
+ function failedExchange(error) {
394
+ return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error, requestSent: false };
395
+ }
396
+ function isObject(value) {
397
+ return typeof value === "object" && value !== null && !Array.isArray(value);
398
+ }
399
+ function parseJSON(body) {
400
+ try {
401
+ return JSON.parse(Buffer.from(body).toString("utf8"));
402
+ } catch {
403
+ return void 0;
404
+ }
405
+ }
406
+ function safeQueryValue(value) {
407
+ return ![...value].some((character) => {
408
+ const code = character.charCodeAt(0);
409
+ return code < 32 || code === 127;
410
+ });
411
+ }
412
+ function utcTime(value) {
413
+ if (typeof value !== "string" || !utcInstant.test(value)) return void 0;
414
+ const parsed = Date.parse(value);
415
+ return Number.isNaN(parsed) ? void 0 : parsed;
416
+ }
417
+ function header(headers, name) {
418
+ const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
419
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
420
+ }
421
+
422
+ // src/project.ts
423
+ function encodeCredentials(credentials) {
424
+ return {
425
+ oauth_client_id: credentials.oauthClientId,
426
+ oauth_client_secret: credentials.oauthClientSecret.reveal(),
427
+ access_token: credentials.accessToken.reveal(),
428
+ refresh_token: credentials.refreshToken.reveal()
429
+ };
430
+ }
431
+ function newProjectConnection(project, connectionName, options = {}) {
432
+ if (!project) throw new TypeError("Hootsuite project is required");
433
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === "hootsuite" && entry.connectionName === connectionName);
434
+ if (!selected || selected.provider !== "hootsuite") throw new TypeError("Hootsuite project connection is not configured");
435
+ const config = ConfigSchema.parse(selected.configuration);
436
+ const provider = newProjectCredentialProvider(project, connectionName, decodeCredentials, encodeCredentials, decodeSharedCredentials);
437
+ return newConnection(new HootsuiteClient(config, provider, options), { provider: "hootsuite", name: connectionName });
438
+ }
439
+ export {
440
+ ConfigSchema,
441
+ Connection,
442
+ ConnectorID,
443
+ HootsuiteClient,
444
+ ListScheduledPostsBranch,
445
+ ListScheduledPostsBranchDefect,
446
+ ListScheduledPostsBranchInvalidResponse,
447
+ ListScheduledPostsBranchListed,
448
+ ListScheduledPostsBranchProviderRejected,
449
+ ListScheduledPostsDefinition,
450
+ ListScheduledPostsInputSchema,
451
+ ListScheduledPostsMetadata,
452
+ ListScheduledPostsOperation,
453
+ ListSocialProfilesBranch,
454
+ ListSocialProfilesBranchDefect,
455
+ ListSocialProfilesBranchInvalidResponse,
456
+ ListSocialProfilesBranchListed,
457
+ ListSocialProfilesBranchProviderRejected,
458
+ ListSocialProfilesDefinition,
459
+ ListSocialProfilesInputSchema,
460
+ ListSocialProfilesMetadata,
461
+ ListSocialProfilesOperation,
462
+ ProviderID,
463
+ SchedulePostBranch,
464
+ SchedulePostBranchDefect,
465
+ SchedulePostBranchProviderRejected,
466
+ SchedulePostBranchScheduled,
467
+ SchedulePostBranchUncertain,
468
+ SchedulePostDefinition,
469
+ SchedulePostInputSchema,
470
+ SchedulePostMetadata,
471
+ SchedulePostOperation,
472
+ ScheduledPostReceiptSchema,
473
+ ScheduledPostSchema,
474
+ ScheduledPostsPageSchema,
475
+ SocialProfileSchema,
476
+ SocialProfilesPageSchema,
477
+ decodeCredentials,
478
+ decodeSharedCredentials,
479
+ newConnection,
480
+ newConnectionWithOperations,
481
+ newListScheduledPostsStep,
482
+ newListSocialProfilesStep,
483
+ newProjectConnection,
484
+ newSchedulePostStep
485
+ };
package/dist/mock.d.ts ADDED
@@ -0,0 +1,75 @@
1
+ import { MockQuery, MockMutation, Case } from '@superdurable/connectors-sdk/connectormock';
2
+ import { Failure } from '@superdurable/connectors-sdk';
3
+ import { O as Operations, C as Connection, a as ListSocialProfilesInput, b as SocialProfilesPage, L as ListScheduledPostsInput, S as ScheduledPostsPage, c as SchedulePostInput, d as ScheduledPostReceipt, l as ScheduledPost, p as SocialProfile } from './connection-CArKfYhH.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for ListSocialProfilesInput in scripted cases. */
7
+ declare const emptyListSocialProfilesInput: ListSocialProfilesInput;
8
+ /** Go zero value for SocialProfile in scripted cases. */
9
+ declare const emptySocialProfile: SocialProfile;
10
+ /** Go zero value for SocialProfilesPage in scripted cases. */
11
+ declare const emptySocialProfilesPage: SocialProfilesPage;
12
+ /** Go zero value for ListScheduledPostsInput in scripted cases. */
13
+ declare const emptyListScheduledPostsInput: ListScheduledPostsInput;
14
+ /** Go zero value for ScheduledPost in scripted cases. */
15
+ declare const emptyScheduledPost: ScheduledPost;
16
+ /** Go zero value for ScheduledPostsPage in scripted cases. */
17
+ declare const emptyScheduledPostsPage: ScheduledPostsPage;
18
+ /** Go zero value for SchedulePostInput in scripted cases. */
19
+ declare const emptySchedulePostInput: SchedulePostInput;
20
+ /** Go zero value for ScheduledPostReceipt in scripted cases. */
21
+ declare const emptyScheduledPostReceipt: ScheduledPostReceipt;
22
+ /** Script the listed branch. */
23
+ declare function listSocialProfilesListed(value: SocialProfilesPage, failure?: Failure): Case<SocialProfilesPage>;
24
+ /** Script the providerRejected branch. */
25
+ declare function listSocialProfilesProviderRejected(value: SocialProfilesPage, failure?: Failure): Case<SocialProfilesPage>;
26
+ /** Script the invalidResponse branch. */
27
+ declare function listSocialProfilesInvalidResponse(value: SocialProfilesPage, failure?: Failure): Case<SocialProfilesPage>;
28
+ /** Script the defect branch. */
29
+ declare function listSocialProfilesDefect(value: SocialProfilesPage, failure?: Failure): Case<SocialProfilesPage>;
30
+ /** Script a safe retry of listSocialProfiles. */
31
+ declare function listSocialProfilesRetry(failure: Failure, retryAfterMs?: number): Case<SocialProfilesPage>;
32
+ /** Manifest scenario listedDefault for listSocialProfiles. */
33
+ declare function listSocialProfilesListedDefault(): Case<SocialProfilesPage>;
34
+ /** Default listSocialProfiles scenario. */
35
+ declare function listSocialProfilesDefault(): Case<SocialProfilesPage>;
36
+ /** Script the listed branch. */
37
+ declare function listScheduledPostsListed(value: ScheduledPostsPage, failure?: Failure): Case<ScheduledPostsPage>;
38
+ /** Script the providerRejected branch. */
39
+ declare function listScheduledPostsProviderRejected(value: ScheduledPostsPage, failure?: Failure): Case<ScheduledPostsPage>;
40
+ /** Script the invalidResponse branch. */
41
+ declare function listScheduledPostsInvalidResponse(value: ScheduledPostsPage, failure?: Failure): Case<ScheduledPostsPage>;
42
+ /** Script the defect branch. */
43
+ declare function listScheduledPostsDefect(value: ScheduledPostsPage, failure?: Failure): Case<ScheduledPostsPage>;
44
+ /** Script a safe retry of listScheduledPosts. */
45
+ declare function listScheduledPostsRetry(failure: Failure, retryAfterMs?: number): Case<ScheduledPostsPage>;
46
+ /** Manifest scenario listedDefault for listScheduledPosts. */
47
+ declare function listScheduledPostsListedDefault(): Case<ScheduledPostsPage>;
48
+ /** Default listScheduledPosts scenario. */
49
+ declare function listScheduledPostsDefault(): Case<ScheduledPostsPage>;
50
+ /** Script the scheduled branch. */
51
+ declare function schedulePostScheduled(value: ScheduledPostReceipt, failure?: Failure): Case<ScheduledPostReceipt>;
52
+ /** Script the providerRejected branch. */
53
+ declare function schedulePostProviderRejected(value: ScheduledPostReceipt, failure?: Failure): Case<ScheduledPostReceipt>;
54
+ /** Script the defect branch. */
55
+ declare function schedulePostDefect(value: ScheduledPostReceipt, failure?: Failure): Case<ScheduledPostReceipt>;
56
+ /** Script a safe retry of schedulePost. */
57
+ declare function schedulePostRetry(failure: Failure, retryAfterMs?: number): Case<ScheduledPostReceipt>;
58
+ /** Script an uncertain schedulePost attempt. */
59
+ declare function schedulePostUncertain(value: ScheduledPostReceipt, failure: Failure): Case<ScheduledPostReceipt>;
60
+ /** Manifest scenario scheduledDefault for schedulePost. */
61
+ declare function schedulePostScheduledDefault(): Case<ScheduledPostReceipt>;
62
+ /** Default schedulePost scenario. */
63
+ declare function schedulePostDefault(): Case<ScheduledPostReceipt>;
64
+ /** Scripted operations and manifest defaults for this connector. */
65
+ declare class GeneratedMock implements Operations {
66
+ #private;
67
+ constructor(connectionName: string);
68
+ connection(): Connection;
69
+ listSocialProfiles(): MockQuery<ListSocialProfilesInput, SocialProfilesPage>;
70
+ listScheduledPosts(): MockQuery<ListScheduledPostsInput, ScheduledPostsPage>;
71
+ schedulePost(): MockMutation<SchedulePostInput, ScheduledPostReceipt>;
72
+ assertNoFailures(): void;
73
+ }
74
+
75
+ export { GeneratedMock, GeneratedMock as Mock, emptyListScheduledPostsInput, emptyListSocialProfilesInput, emptySchedulePostInput, emptyScheduledPost, emptyScheduledPostReceipt, emptyScheduledPostsPage, emptySocialProfile, emptySocialProfilesPage, listScheduledPostsDefault, listScheduledPostsDefect, listScheduledPostsInvalidResponse, listScheduledPostsListed, listScheduledPostsListedDefault, listScheduledPostsProviderRejected, listScheduledPostsRetry, listSocialProfilesDefault, listSocialProfilesDefect, listSocialProfilesInvalidResponse, listSocialProfilesListed, listSocialProfilesListedDefault, listSocialProfilesProviderRejected, listSocialProfilesRetry, schedulePostDefault, schedulePostDefect, schedulePostProviderRejected, schedulePostRetry, schedulePostScheduled, schedulePostScheduledDefault, schedulePostUncertain };