@superdurable/connector-hootsuite 0.1.0 → 0.1.1
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/README.md +1 -1
- package/dex-connector.json +3 -3
- package/dist/{chunk-LBB5UANL.js → chunk-IDMDRTUF.js} +39 -21
- package/dist/{connection-CArKfYhH.d.ts → connection-DZkHHYyF.d.ts} +7 -1
- package/dist/index.d.ts +19 -9
- package/dist/index.js +106 -28
- package/dist/mock.d.ts +1 -1
- package/dist/mock.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
This package implements `listSocialProfiles`, `listScheduledPosts`, and `schedulePost` with generated typed Steps, a renewable OAuth connection, and bounded provider requests. See the [connector guide](../README.md) for Hootsuite app setup.
|
|
4
4
|
|
|
5
|
-
`schedulePost` can create a real scheduled message. If the outcome is `uncertain`, inspect Hootsuite Planner before asking for another post. Go-recorded provider scenarios are replayed in `test/conformance.test.ts`; live Hootsuite authorization remains unverified.
|
|
5
|
+
`schedulePost` can create a real scheduled message. An unknown outcome resends while possible sends stay below the send cap, and a definite refusal is never resent. If the outcome is `uncertain`, inspect Hootsuite Planner before asking for another post. Go-recorded provider scenarios are replayed in `test/conformance.test.ts`; live Hootsuite authorization remains unverified.
|
|
6
6
|
|
|
7
7
|
The runnable [social profiles Flow](examples/social-profiles/README.md) uses the static `hootsuite` Dex Web connection. Run `npm ci` and `npm run check` from this package. The Flow's real Dex integration test uses a local Hootsuite fixture and does not need provider credentials.
|
package/dex-connector.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"connectorId": "hootsuite",
|
|
3
|
-
"releaseTag": "connectors/hootsuite/go/v0.1.
|
|
3
|
+
"releaseTag": "connectors/hootsuite/go/v0.1.1",
|
|
4
4
|
"package": {
|
|
5
5
|
"ecosystem": "npm",
|
|
6
6
|
"name": "@superdurable/connector-hootsuite",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.1"
|
|
8
8
|
},
|
|
9
9
|
"factories": [
|
|
10
10
|
{
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"kind": "mutation",
|
|
116
116
|
"operationId": "schedulePost",
|
|
117
117
|
"inputType": "SchedulePostInput",
|
|
118
|
-
"description": "Schedule a text message on one social profile; inspect
|
|
118
|
+
"description": "Schedule a text message on one social profile. An unknown outcome resends up to the send cap, so Planner may show a duplicate; inspect Planner if the outcome is uncertain.",
|
|
119
119
|
"fields": {
|
|
120
120
|
"stepType": "stepType",
|
|
121
121
|
"annotations": "annotations",
|
|
@@ -6,40 +6,54 @@ var ConfigSchema = z.object({
|
|
|
6
6
|
"timeoutMs": z.number().int().optional(),
|
|
7
7
|
"maxResponseBytes": z.number().int().optional()
|
|
8
8
|
});
|
|
9
|
+
var CredentialMaterialError = class extends TypeError {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "CredentialMaterialError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
|
|
16
|
+
"project credential decoding failed",
|
|
17
|
+
"shared project credential decoding failed",
|
|
18
|
+
"project credential decoding failed: this connector version does not support shared credentials"
|
|
19
|
+
]);
|
|
20
|
+
function isCredentialMaterialError(error) {
|
|
21
|
+
return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
|
|
22
|
+
}
|
|
9
23
|
function decodeCredentials(value) {
|
|
10
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw new
|
|
24
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
|
|
11
25
|
const fields = value;
|
|
12
26
|
const allowed = /* @__PURE__ */ new Set(["access_token", "oauth_client_id", "oauth_client_secret", "refresh_token"]);
|
|
13
|
-
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new
|
|
14
|
-
if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new
|
|
15
|
-
if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new
|
|
16
|
-
if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new
|
|
17
|
-
if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new
|
|
27
|
+
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
|
|
28
|
+
if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new CredentialMaterialError("credential access_token has an invalid type");
|
|
29
|
+
if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new CredentialMaterialError("credential oauth_client_id has an invalid type");
|
|
30
|
+
if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new CredentialMaterialError("credential oauth_client_secret has an invalid type");
|
|
31
|
+
if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new CredentialMaterialError("credential refresh_token has an invalid type");
|
|
18
32
|
const credentials = {};
|
|
19
|
-
if (!fields["oauth_client_id"]) throw new
|
|
33
|
+
if (!fields["oauth_client_id"]) throw new CredentialMaterialError("credential oauth_client_id is required");
|
|
20
34
|
credentials.oauthClientId = fields["oauth_client_id"] ?? "";
|
|
21
|
-
if (!fields["oauth_client_secret"]) throw new
|
|
35
|
+
if (!fields["oauth_client_secret"]) throw new CredentialMaterialError("credential oauth_client_secret is required");
|
|
22
36
|
credentials.oauthClientSecret = new SecretString(fields["oauth_client_secret"] ?? "");
|
|
23
|
-
if (!fields["access_token"]) throw new
|
|
37
|
+
if (!fields["access_token"]) throw new CredentialMaterialError("credential access_token is required");
|
|
24
38
|
credentials.accessToken = new SecretString(fields["access_token"] ?? "");
|
|
25
|
-
if (!fields["refresh_token"]) throw new
|
|
39
|
+
if (!fields["refresh_token"]) throw new CredentialMaterialError("credential refresh_token is required");
|
|
26
40
|
credentials.refreshToken = new SecretString(fields["refresh_token"] ?? "");
|
|
27
41
|
return credentials;
|
|
28
42
|
}
|
|
29
43
|
function decodeSharedCredentials(value) {
|
|
30
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw new
|
|
44
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
|
|
31
45
|
const fields = value;
|
|
32
46
|
const allowed = /* @__PURE__ */ new Set(["access_token", "oauth_client_id", "oauth_client_secret", "refresh_token"]);
|
|
33
|
-
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new
|
|
34
|
-
if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new
|
|
35
|
-
if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new
|
|
36
|
-
if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new
|
|
37
|
-
if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new
|
|
47
|
+
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
|
|
48
|
+
if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new CredentialMaterialError("credential access_token has an invalid type");
|
|
49
|
+
if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new CredentialMaterialError("credential oauth_client_id has an invalid type");
|
|
50
|
+
if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new CredentialMaterialError("credential oauth_client_secret has an invalid type");
|
|
51
|
+
if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new CredentialMaterialError("credential refresh_token has an invalid type");
|
|
38
52
|
const credentials = {};
|
|
39
|
-
if (!fields["oauth_client_id"]) throw new
|
|
53
|
+
if (!fields["oauth_client_id"]) throw new CredentialMaterialError("credential oauth_client_id is required");
|
|
40
54
|
credentials.oauthClientId = fields["oauth_client_id"] ?? "";
|
|
41
55
|
credentials.oauthClientSecret = new SecretString(fields["oauth_client_secret"] ?? "");
|
|
42
|
-
if (!fields["access_token"]) throw new
|
|
56
|
+
if (!fields["access_token"]) throw new CredentialMaterialError("credential access_token is required");
|
|
43
57
|
credentials.accessToken = new SecretString(fields["access_token"] ?? "");
|
|
44
58
|
credentials.refreshToken = new SecretString(fields["refresh_token"] ?? "");
|
|
45
59
|
return credentials;
|
|
@@ -140,10 +154,12 @@ var SchedulePostDefinition = {
|
|
|
140
154
|
branches: [
|
|
141
155
|
{ id: "scheduled", description: "Hootsuite accepted the scheduled message and returned its ID." },
|
|
142
156
|
{ id: "providerRejected", description: "Hootsuite definitively rejected the schedule request.", optional: true },
|
|
143
|
-
{ id: "uncertain", description: "
|
|
144
|
-
{ id: "defect", description: "Local post input, credentials, or dispatch
|
|
157
|
+
{ id: "uncertain", description: "Hootsuite may have scheduled the message, but the send cap was reached or Hootsuite returned a message ID without a complete confirmation; inspect Planner before resending.", optional: true },
|
|
158
|
+
{ id: "defect", description: "Local post input, credentials, or dispatch fence is invalid before any send.", optional: true }
|
|
145
159
|
],
|
|
146
|
-
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync" }
|
|
160
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "sync" },
|
|
161
|
+
repeatOnUnknown: "limited",
|
|
162
|
+
maxSends: 3
|
|
147
163
|
};
|
|
148
164
|
var SchedulePostMetadata = { kind: "mutation", idempotency: "required", authorization: "required" };
|
|
149
165
|
|
|
@@ -176,6 +192,8 @@ function newProjectCredentialProvider(project, connectionName, decode, encode, d
|
|
|
176
192
|
|
|
177
193
|
export {
|
|
178
194
|
ConfigSchema,
|
|
195
|
+
CredentialMaterialError,
|
|
196
|
+
isCredentialMaterialError,
|
|
179
197
|
decodeCredentials,
|
|
180
198
|
decodeSharedCredentials,
|
|
181
199
|
ListSocialProfilesInputSchema,
|
|
@@ -27,6 +27,12 @@ interface Credentials {
|
|
|
27
27
|
/** Secret refresh token returned with offline consent. Dex rotates it on refresh; blank requires reauthorization. */
|
|
28
28
|
refreshToken: SecretString;
|
|
29
29
|
}
|
|
30
|
+
/** Stored credential material that fails the connector credential checks, so no retry can succeed. */
|
|
31
|
+
declare class CredentialMaterialError extends TypeError {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
/** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
|
|
35
|
+
declare function isCredentialMaterialError(error: unknown): boolean;
|
|
30
36
|
/** Decode private credential fields for the connector. */
|
|
31
37
|
declare function decodeCredentials(value: unknown): Credentials;
|
|
32
38
|
/** Decode shared credential fields for the connector. */
|
|
@@ -173,4 +179,4 @@ declare function newConnection(client: Operations, reference: ConnectionRef): Co
|
|
|
173
179
|
/** Bind scripted operations to a named connection. */
|
|
174
180
|
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
175
181
|
|
|
176
|
-
export { Connection as C, type ListScheduledPostsInput as L, type Operations as O, type ScheduledPostsPage as S, type ListSocialProfilesInput as a, type SocialProfilesPage as b, type SchedulePostInput as c, type ScheduledPostReceipt as d, type Config as e, type Credentials as f, ConfigSchema as g, type CredentialSource as
|
|
182
|
+
export { Connection as C, type ListScheduledPostsInput as L, type Operations as O, type ScheduledPostsPage as S, type ListSocialProfilesInput as a, type SocialProfilesPage as b, type SchedulePostInput as c, type ScheduledPostReceipt as d, type Config as e, type Credentials as f, ConfigSchema as g, CredentialMaterialError as h, type CredentialSource as i, ListScheduledPostsInputSchema as j, ListSocialProfilesInputSchema as k, SchedulePostInputSchema as l, type ScheduledPost as m, ScheduledPostReceiptSchema as n, ScheduledPostSchema as o, ScheduledPostsPageSchema as p, type SocialProfile as q, SocialProfileSchema as r, SocialProfilesPageSchema as s, decodeCredentials as t, decodeSharedCredentials as u, isCredentialMaterialError as v, newConnection as w, newConnectionWithOperations as x };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as ListScheduledPostsInput, S as ScheduledPostsPage, C as Connection, a as ListSocialProfilesInput, b as SocialProfilesPage, c as SchedulePostInput, d as ScheduledPostReceipt, e as Config, f as Credentials, O as Operations } from './connection-
|
|
2
|
-
export { g as ConfigSchema, h as
|
|
1
|
+
import { L as ListScheduledPostsInput, S as ScheduledPostsPage, C as Connection, a as ListSocialProfilesInput, b as SocialProfilesPage, c as SchedulePostInput, d as ScheduledPostReceipt, e as Config, f as Credentials, O as Operations } from './connection-DZkHHYyF.js';
|
|
2
|
+
export { g as ConfigSchema, h as CredentialMaterialError, i as CredentialSource, j as ListScheduledPostsInputSchema, k as ListSocialProfilesInputSchema, l as SchedulePostInputSchema, m as ScheduledPost, n as ScheduledPostReceiptSchema, o as ScheduledPostSchema, p as ScheduledPostsPageSchema, q as SocialProfile, r as SocialProfileSchema, s as SocialProfilesPageSchema, t as decodeCredentials, u as decodeSharedCredentials, v as isCredentialMaterialError, w as newConnection, x as newConnectionWithOperations } from './connection-DZkHHYyF.js';
|
|
3
3
|
import { QueryDefinition, MutationDefinition, QueryStepConfig, Query, QueryResult, MutationStepConfig, Mutation, MutationResult, QueryStep, MutationStep, CredentialProvider, CredentialRefreshDriver, Call, QueryAttempt, CallID, MutationAttempt } from '@superdurable/connectors-sdk';
|
|
4
4
|
import { StepTarget } from '@superdurable/dex';
|
|
5
5
|
import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
|
|
@@ -67,9 +67,9 @@ declare const SchedulePostBranch: {
|
|
|
67
67
|
declare const SchedulePostBranchScheduled: "scheduled";
|
|
68
68
|
/** Hootsuite definitively rejected the schedule request. */
|
|
69
69
|
declare const SchedulePostBranchProviderRejected: "providerRejected";
|
|
70
|
-
/**
|
|
70
|
+
/** Hootsuite may have scheduled the message, but the send cap was reached or Hootsuite returned a message ID without a complete confirmation; inspect Planner before resending. */
|
|
71
71
|
declare const SchedulePostBranchUncertain: "uncertain";
|
|
72
|
-
/** Local post input, credentials, or dispatch
|
|
72
|
+
/** Local post input, credentials, or dispatch fence is invalid before any send. */
|
|
73
73
|
declare const SchedulePostBranchDefect: "defect";
|
|
74
74
|
/** Manifest definition for schedulePost. */
|
|
75
75
|
declare const SchedulePostDefinition: MutationDefinition;
|
|
@@ -130,9 +130,9 @@ interface SchedulePostStepConfig<StepInput, OperationInput = SchedulePostInput,
|
|
|
130
130
|
scheduled: StepTarget<MutationResult<OperationOutput>>;
|
|
131
131
|
/** Hootsuite definitively rejected the schedule request. */
|
|
132
132
|
providerRejected?: StepTarget<MutationResult<OperationOutput>>;
|
|
133
|
-
/**
|
|
133
|
+
/** Hootsuite may have scheduled the message, but the send cap was reached or Hootsuite returned a message ID without a complete confirmation; inspect Planner before resending. */
|
|
134
134
|
uncertain?: StepTarget<MutationResult<OperationOutput>>;
|
|
135
|
-
/** Local post input, credentials, or dispatch
|
|
135
|
+
/** Local post input, credentials, or dispatch fence is invalid before any send. */
|
|
136
136
|
defect?: StepTarget<MutationResult<OperationOutput>>;
|
|
137
137
|
}
|
|
138
138
|
/** Build the schedulePost Step from a named connection. */
|
|
@@ -149,7 +149,7 @@ interface HootsuiteExchange {
|
|
|
149
149
|
/** Provider HTTP status, or zero before response headers. */ status: number;
|
|
150
150
|
/** Bounded response body retained only in process memory. */ body: Uint8Array;
|
|
151
151
|
/** Provider Retry-After delay in milliseconds. */ retryAfterMs: number;
|
|
152
|
-
/** Safe local error class. */ error?: 'credential' | 'refresh' | 'request' | 'tooLarge';
|
|
152
|
+
/** Safe local error class; read means the body failed after its status arrived. */ error?: 'credential' | 'refresh' | 'request' | 'read' | 'tooLarge';
|
|
153
153
|
/** Whether request bytes may have reached Hootsuite. */ requestSent: boolean;
|
|
154
154
|
}
|
|
155
155
|
/** Hootsuite client with call-time OAuth resolution and bounded responses. */
|
|
@@ -166,8 +166,14 @@ declare class HootsuiteClient {
|
|
|
166
166
|
/** Bind the social profile Query. */ listSocialProfiles(): ListSocialProfilesOperation;
|
|
167
167
|
/** Bind the scheduled message Query. */ listScheduledPosts(): ListScheduledPostsOperation;
|
|
168
168
|
/** Bind the scheduled message Mutation. */ schedulePost(): SchedulePostOperation;
|
|
169
|
-
/** Resolve a header-safe access token for the current call. */
|
|
169
|
+
/** Resolve a header-safe access token for the current call, classified as for a write. */
|
|
170
170
|
resolveToken(call: Call): Promise<string | HootsuiteExchange>;
|
|
171
|
+
/**
|
|
172
|
+
* Resolve a header-safe access token for a write. A revoked, missing, unselected, or broker-refused
|
|
173
|
+
* connection is `credential`; any other read failure is `refresh` and may succeed on a later attempt.
|
|
174
|
+
*/
|
|
175
|
+
resolveWriteToken(call: Call): Promise<string | HootsuiteExchange>;
|
|
176
|
+
private resolveTokenClassifying;
|
|
171
177
|
/** Read one bounded provider response for a Query. */
|
|
172
178
|
get(call: Call, path: string): Promise<HootsuiteExchange>;
|
|
173
179
|
/** Send one authenticated request; the caller owns dispatch fencing for writes. */
|
|
@@ -195,7 +201,11 @@ declare class SchedulePostOperation implements Mutation<SchedulePostInput, Sched
|
|
|
195
201
|
/** Bind the provider client. */ constructor(client: HootsuiteClient);
|
|
196
202
|
/** Return the generated Mutation definition. */ definition(): MutationDefinition;
|
|
197
203
|
/** Record the Call ID; Hootsuite does not deduplicate this key. */ idempotencyKey(callID: CallID): string;
|
|
198
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* Schedule under a single-dispatch fence. Hootsuite has no message idempotency key, so an unknown
|
|
206
|
+
* outcome retries while possible sends stay below the send cap and selects uncertain at the cap.
|
|
207
|
+
* A definite refusal is never resent.
|
|
208
|
+
*/
|
|
199
209
|
invoke(call: Call, input: SchedulePostInput): Promise<MutationAttempt<ScheduledPostReceipt>>;
|
|
200
210
|
}
|
|
201
211
|
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
ConfigSchema,
|
|
3
3
|
Connection,
|
|
4
4
|
ConnectorID,
|
|
5
|
+
CredentialMaterialError,
|
|
5
6
|
ListScheduledPostsBranch,
|
|
6
7
|
ListScheduledPostsBranchDefect,
|
|
7
8
|
ListScheduledPostsBranchInvalidResponse,
|
|
@@ -34,10 +35,11 @@ import {
|
|
|
34
35
|
SocialProfilesPageSchema,
|
|
35
36
|
decodeCredentials,
|
|
36
37
|
decodeSharedCredentials,
|
|
38
|
+
isCredentialMaterialError,
|
|
37
39
|
newConnection,
|
|
38
40
|
newConnectionWithOperations,
|
|
39
41
|
newProjectCredentialProvider
|
|
40
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-IDMDRTUF.js";
|
|
41
43
|
|
|
42
44
|
// src/generated/steps.ts
|
|
43
45
|
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
@@ -73,10 +75,11 @@ function newSchedulePostStep(configuration) {
|
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
// src/client.ts
|
|
76
|
-
import { SecretString, ReauthorizationRequiredError, resolveCredential, newQueryBranch, newQueryRetry, newMutationBranch, newMutationRetry, newMutationUncertain } from "@superdurable/connectors-sdk";
|
|
78
|
+
import { definitionMaxSends, SecretString, ReauthorizationRequiredError, resolveCredential, newQueryBranch, newQueryRetry, newMutationBranch, newMutationRetry, newMutationUncertain } from "@superdurable/connectors-sdk";
|
|
77
79
|
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
|
+
import { BodyTooLargeError, ProviderStalledError, ProviderTransportError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
81
|
+
import { CheckpointError, DispatchNotAllowedError, InsufficientTimeError, newFence } from "@superdurable/connectors-sdk/singledispatch";
|
|
82
|
+
import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
|
|
80
83
|
|
|
81
84
|
// src/generated/refresh.ts
|
|
82
85
|
var Authorization = {
|
|
@@ -183,14 +186,24 @@ var HootsuiteClient = class {
|
|
|
183
186
|
schedulePost() {
|
|
184
187
|
return new SchedulePostOperation(this);
|
|
185
188
|
}
|
|
186
|
-
/** Resolve a header-safe access token for the current call. */
|
|
189
|
+
/** Resolve a header-safe access token for the current call, classified as for a write. */
|
|
187
190
|
async resolveToken(call) {
|
|
191
|
+
return this.resolveTokenClassifying(call, isTerminalCredentialError);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Resolve a header-safe access token for a write. A revoked, missing, unselected, or broker-refused
|
|
195
|
+
* connection is `credential`; any other read failure is `refresh` and may succeed on a later attempt.
|
|
196
|
+
*/
|
|
197
|
+
async resolveWriteToken(call) {
|
|
198
|
+
return this.resolveTokenClassifying(call, isTerminalCredentialError);
|
|
199
|
+
}
|
|
200
|
+
async resolveTokenClassifying(call, isTerminal) {
|
|
188
201
|
try {
|
|
189
202
|
const resolved = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
|
|
190
203
|
const token = resolved.accessToken instanceof SecretString ? resolved.accessToken.reveal() : "";
|
|
191
204
|
return token && isHeaderSafeCredential(token) ? token : failedExchange("credential");
|
|
192
205
|
} catch (error) {
|
|
193
|
-
return failedExchange(error
|
|
206
|
+
return failedExchange(isTerminal(error) ? "credential" : "refresh");
|
|
194
207
|
}
|
|
195
208
|
}
|
|
196
209
|
/** Read one bounded provider response for a Query. */
|
|
@@ -226,8 +239,14 @@ var HootsuiteClient = class {
|
|
|
226
239
|
requestSent: true,
|
|
227
240
|
retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"), this.now())
|
|
228
241
|
};
|
|
242
|
+
if ((error instanceof ProviderTransportError && !error.isProvablyNotSent || error instanceof ProviderStalledError) && error.status !== void 0 && error.status >= 100) return {
|
|
243
|
+
...failedExchange("read"),
|
|
244
|
+
status: error.status,
|
|
245
|
+
requestSent: true,
|
|
246
|
+
retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"), this.now())
|
|
247
|
+
};
|
|
229
248
|
if (error instanceof ProviderTransportError) return { ...failedExchange("request"), requestSent: !error.isProvablyNotSent };
|
|
230
|
-
return failedExchange("request");
|
|
249
|
+
return { ...failedExchange("request"), requestSent: true };
|
|
231
250
|
}
|
|
232
251
|
const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"), this.now());
|
|
233
252
|
if (Buffer.from(response.body).includes(token)) return { ...failedExchange("credential"), status: response.status, requestSent: true, retryAfterMs };
|
|
@@ -312,21 +331,38 @@ var SchedulePostOperation = class {
|
|
|
312
331
|
idempotencyKey(callID) {
|
|
313
332
|
return callID;
|
|
314
333
|
}
|
|
315
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* Schedule under a single-dispatch fence. Hootsuite has no message idempotency key, so an unknown
|
|
336
|
+
* outcome retries while possible sends stay below the send cap and selects uncertain at the cap.
|
|
337
|
+
* A definite refusal is never resent.
|
|
338
|
+
*/
|
|
316
339
|
async invoke(call, input) {
|
|
317
340
|
const operation = "schedulePost";
|
|
318
341
|
const empty = emptyReceipt();
|
|
342
|
+
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"));
|
|
343
|
+
const operationMaxSends = definitionMaxSends(SchedulePostDefinition);
|
|
319
344
|
let fence;
|
|
320
345
|
try {
|
|
321
|
-
fence = newFence(call, SchedulePostDefinition.stepDefaults.executeMethodTimeoutMs ?? 3e4);
|
|
346
|
+
fence = newFence(call, SchedulePostDefinition.stepDefaults.executeMethodTimeoutMs ?? 3e4, { maxSends: operationMaxSends });
|
|
322
347
|
} catch {
|
|
323
348
|
return newMutationBranch("defect", empty, {}, failure(operation, "LOCAL_DEFECT", "Hootsuite dispatch fence is unavailable"));
|
|
324
349
|
}
|
|
325
|
-
|
|
326
|
-
if (
|
|
327
|
-
|
|
350
|
+
const decision = fence.decide();
|
|
351
|
+
if (decision.kind === "failClosed") return newMutationRetry(failure(operation, "AVAILABILITY", "Hootsuite dispatch checkpoint is unreadable; no message was scheduled in this attempt"));
|
|
352
|
+
if (decision.kind === "readBackRequired") return newMutationUncertain(empty, failure(operation, "TRANSPORT", "an earlier attempt may have scheduled the Hootsuite message, and the send cap is reached; inspect Planner before resending"));
|
|
353
|
+
if (decision.kind === "readBackThenResendAllowed" && decision.marker?.providerId) return newMutationUncertain(empty, failure(operation, "TRANSPORT", "an earlier attempt scheduled the Hootsuite message, but its confirmation was lost"));
|
|
354
|
+
const priorSendUpperBound = decision.priorSendUpperBound ?? 0;
|
|
355
|
+
const canResendUnknownOutcome = priorSendUpperBound + 1 < effectiveMaxSends(call, operationMaxSends);
|
|
356
|
+
const hasPossibleEarlierSend = priorSendUpperBound > 0;
|
|
357
|
+
const token = await this.client.resolveWriteToken(call);
|
|
328
358
|
if (typeof token !== "string") {
|
|
329
|
-
if (token.error === "credential") return
|
|
359
|
+
if (token.error === "credential") return localScheduleFailure(fence, hasPossibleEarlierSend, failure(operation, "AUTHENTICATION", "connection credentials are unavailable or require reauthorization"));
|
|
360
|
+
if (!hasPossibleEarlierSend) {
|
|
361
|
+
try {
|
|
362
|
+
await fence.recordNotSent();
|
|
363
|
+
} catch {
|
|
364
|
+
}
|
|
365
|
+
}
|
|
330
366
|
return newMutationRetry(failure(operation, "TRANSPORT", "connection refresh failed"));
|
|
331
367
|
}
|
|
332
368
|
const body = Buffer.from(JSON.stringify({ text: input.text, socialProfileIds: [input.socialProfileId], scheduledSendTime: input.scheduledSendTime }));
|
|
@@ -334,18 +370,18 @@ var SchedulePostOperation = class {
|
|
|
334
370
|
try {
|
|
335
371
|
exchange = await fence.dispatch((signal) => this.client.send("POST", "/v1/messages", token, signal, body));
|
|
336
372
|
} catch (error) {
|
|
337
|
-
if (error instanceof CheckpointError || error instanceof InsufficientTimeError) return newMutationRetry(failure(operation, "TRANSPORT", "Hootsuite dispatch did not start"));
|
|
338
|
-
return
|
|
373
|
+
if (error instanceof CheckpointError || error instanceof InsufficientTimeError || error instanceof DispatchNotAllowedError || isFenceInsufficientTimeAggregateError(error)) return newMutationRetry(failure(operation, "TRANSPORT", "Hootsuite dispatch did not start"));
|
|
374
|
+
return resendOrSelectUncertain(canResendUnknownOutcome, failure(operation, "TRANSPORT", "Hootsuite schedule outcome is unknown"));
|
|
339
375
|
}
|
|
340
376
|
if (exchange.error === "request") {
|
|
341
377
|
if (!exchange.requestSent) {
|
|
342
378
|
try {
|
|
343
379
|
await fence.recordCanResend();
|
|
344
|
-
return newMutationRetry(failure(operation, "TRANSPORT", "Hootsuite could not be reached before sending"));
|
|
345
380
|
} catch {
|
|
346
381
|
}
|
|
382
|
+
return newMutationRetry(failure(operation, "TRANSPORT", "Hootsuite could not be reached before sending"));
|
|
347
383
|
}
|
|
348
|
-
return
|
|
384
|
+
return resendOrSelectUncertain(canResendUnknownOutcome, failure(operation, "TRANSPORT", "Hootsuite schedule outcome is unknown"));
|
|
349
385
|
}
|
|
350
386
|
if (exchange.status === 429 || exchange.status === 503) {
|
|
351
387
|
try {
|
|
@@ -356,22 +392,59 @@ var SchedulePostOperation = class {
|
|
|
356
392
|
const kind = exchange.status === 429 ? "RATE_LIMIT" : "AVAILABILITY";
|
|
357
393
|
return newMutationRetry(failure(operation, kind, "Hootsuite did not schedule the message"), exchange.retryAfterMs);
|
|
358
394
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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);
|
|
395
|
+
const isSuccessStatus = exchange.status >= 200 && exchange.status < 300;
|
|
396
|
+
const isBodyReadable = !exchange.error;
|
|
397
|
+
const document = isBodyReadable ? parseJSON(exchange.body) : void 0;
|
|
364
398
|
const data = isObject(document) ? document.data : void 0;
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
399
|
+
const first = Array.isArray(data) && isObject(data[0]) ? data[0] : void 0;
|
|
400
|
+
const messageID = first && typeof first.id === "string" ? first.id : "";
|
|
401
|
+
if (isSuccessStatus && !isBodyReadable) return newMutationUncertain(empty, failure(operation, "TRANSPORT", "Hootsuite accepted the request, but its response could not be read"));
|
|
402
|
+
if (isSuccessStatus && !messageID) return newMutationUncertain(empty, failure(operation, "PROTOCOL", "Hootsuite accepted the request, but its response is malformed"));
|
|
403
|
+
if (!isSuccessStatus && messageID) return newMutationUncertain(empty, failure(operation, "PROTOCOL", "Hootsuite returned a contradictory schedule response"));
|
|
404
|
+
if (!isSuccessStatus) {
|
|
405
|
+
if (isBodyReadable && definiteRefusalStatuses.has(exchange.status)) return rejectOrSelectUncertain(fence, hasPossibleEarlierSend, failure(operation, rejectionKind(exchange.status), `Hootsuite rejected HTTP ${exchange.status}`));
|
|
406
|
+
return resendOrSelectUncertain(canResendUnknownOutcome, failure(operation, "AVAILABILITY", `Hootsuite schedule outcome is unknown after HTTP ${exchange.status}`), exchange.retryAfterMs);
|
|
407
|
+
}
|
|
408
|
+
if (!first || !Array.isArray(data)) return newMutationUncertain(empty, failure(operation, "PROTOCOL", "Hootsuite accepted the request, but its response is malformed"));
|
|
368
409
|
try {
|
|
369
|
-
await fence.recordProviderId(
|
|
410
|
+
await fence.recordProviderId(messageID);
|
|
370
411
|
} catch {
|
|
371
412
|
}
|
|
372
|
-
|
|
413
|
+
if (exchange.status !== 200 || data.length !== 1 || typeof first.state !== "string" || !first.state) return newMutationUncertain(empty, failure(operation, "PROTOCOL", "Hootsuite accepted the request but returned an unexpected schedule response"));
|
|
414
|
+
const socialProfile = first.socialProfile ?? {};
|
|
415
|
+
if (!isObject(socialProfile) || socialProfile.id && socialProfile.id !== input.socialProfileId) return newMutationUncertain(empty, failure(operation, "PROTOCOL", "Hootsuite returned an unexpected social profile"));
|
|
416
|
+
return newMutationBranch("scheduled", { id: messageID, state: first.state, socialProfileId: input.socialProfileId });
|
|
373
417
|
}
|
|
374
418
|
};
|
|
419
|
+
var definiteRefusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
|
|
420
|
+
function effectiveMaxSends(call, operationMaxSends) {
|
|
421
|
+
return operationMaxSends >= 2 ? call.maxSendsOverride ?? operationMaxSends : 1;
|
|
422
|
+
}
|
|
423
|
+
function resendOrSelectUncertain(canResendUnknownOutcome, unknownFailure, delay = 0) {
|
|
424
|
+
return canResendUnknownOutcome ? newMutationRetry(unknownFailure, delay) : newMutationUncertain(emptyReceipt(), unknownFailure);
|
|
425
|
+
}
|
|
426
|
+
async function rejectOrSelectUncertain(fence, hasPossibleEarlierSend, rejection) {
|
|
427
|
+
if (hasPossibleEarlierSend) return newMutationUncertain(emptyReceipt(), rejection);
|
|
428
|
+
try {
|
|
429
|
+
await fence.recordCanResend();
|
|
430
|
+
} catch {
|
|
431
|
+
}
|
|
432
|
+
return newMutationBranch("providerRejected", emptyReceipt(), {}, rejection);
|
|
433
|
+
}
|
|
434
|
+
async function localScheduleFailure(fence, hasPossibleEarlierSend, localFailure) {
|
|
435
|
+
if (hasPossibleEarlierSend) return newMutationUncertain(emptyReceipt(), { ...localFailure, message: `${localFailure.message}; an earlier attempt may have scheduled the message` });
|
|
436
|
+
try {
|
|
437
|
+
await fence.recordNotSent();
|
|
438
|
+
} catch {
|
|
439
|
+
}
|
|
440
|
+
return newMutationBranch("defect", emptyReceipt(), {}, localFailure);
|
|
441
|
+
}
|
|
442
|
+
function isTerminalCredentialError(error) {
|
|
443
|
+
return error instanceof ReauthorizationRequiredError || error instanceof ObjectNotFoundError || error instanceof ConnectionNotSelectedError || error instanceof CredentialBrokerRejectedError || isCredentialMaterialError(error);
|
|
444
|
+
}
|
|
445
|
+
function rejectionKind(status) {
|
|
446
|
+
return status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : "PROVIDER_REJECTION";
|
|
447
|
+
}
|
|
375
448
|
function failure(operation, kind, message) {
|
|
376
449
|
return { provider: "hootsuite", operation, kind, message };
|
|
377
450
|
}
|
|
@@ -383,7 +456,7 @@ function queryRetry(operation, kind, message, delay = 0) {
|
|
|
383
456
|
}
|
|
384
457
|
function queryFailure(operation, exchange, empty) {
|
|
385
458
|
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");
|
|
459
|
+
if (exchange.error === "request" || exchange.error === "refresh" || exchange.error === "read") return queryRetry(operation, "TRANSPORT", "Hootsuite request failed");
|
|
387
460
|
if (exchange.status === 429) return queryRetry(operation, "RATE_LIMIT", "Hootsuite rate limited the request", exchange.retryAfterMs);
|
|
388
461
|
if (exchange.status === 408 || exchange.status >= 500) return queryRetry(operation, "AVAILABILITY", "Hootsuite is temporarily unavailable", exchange.retryAfterMs);
|
|
389
462
|
if (exchange.status !== 200) return queryBranch(operation, "providerRejected", "PROVIDER_REJECTION", `Hootsuite rejected HTTP ${exchange.status}`, empty);
|
|
@@ -418,6 +491,9 @@ function header(headers, name) {
|
|
|
418
491
|
const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
|
|
419
492
|
return Array.isArray(value) ? value[0] ?? "" : value ?? "";
|
|
420
493
|
}
|
|
494
|
+
function isFenceInsufficientTimeAggregateError(error) {
|
|
495
|
+
return error instanceof AggregateError && error.errors.some((cause) => cause instanceof InsufficientTimeError);
|
|
496
|
+
}
|
|
421
497
|
|
|
422
498
|
// src/project.ts
|
|
423
499
|
function encodeCredentials(credentials) {
|
|
@@ -440,6 +516,7 @@ export {
|
|
|
440
516
|
ConfigSchema,
|
|
441
517
|
Connection,
|
|
442
518
|
ConnectorID,
|
|
519
|
+
CredentialMaterialError,
|
|
443
520
|
HootsuiteClient,
|
|
444
521
|
ListScheduledPostsBranch,
|
|
445
522
|
ListScheduledPostsBranchDefect,
|
|
@@ -476,6 +553,7 @@ export {
|
|
|
476
553
|
SocialProfilesPageSchema,
|
|
477
554
|
decodeCredentials,
|
|
478
555
|
decodeSharedCredentials,
|
|
556
|
+
isCredentialMaterialError,
|
|
479
557
|
newConnection,
|
|
480
558
|
newConnectionWithOperations,
|
|
481
559
|
newListScheduledPostsStep,
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MockQuery, MockMutation, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
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,
|
|
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, m as ScheduledPost, q as SocialProfile } from './connection-DZkHHYyF.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/** Go zero value for ListSocialProfilesInput in scripted cases. */
|
package/dist/mock.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
SocialProfileSchema,
|
|
13
13
|
SocialProfilesPageSchema,
|
|
14
14
|
newConnectionWithOperations
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-IDMDRTUF.js";
|
|
16
16
|
|
|
17
17
|
// src/generated/mock.ts
|
|
18
18
|
import { branchCase, retryCase, uncertainCase, newMutation, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-hootsuite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Hootsuite connector for Dex TypeScript applications",
|
|
6
6
|
"repository": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"check": "npm run typecheck && npm run lint && npm test && npm run build"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@superdurable/connectors-sdk": "0.
|
|
46
|
+
"@superdurable/connectors-sdk": "0.12.0",
|
|
47
47
|
"@superdurable/dex": ">=1.28.0",
|
|
48
48
|
"zod": "^4.1.0"
|
|
49
49
|
},
|