@alva-ai/toolkit 0.34.0 → 0.36.0-beta.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.cjs CHANGED
@@ -27,6 +27,7 @@ __export(src_exports, {
27
27
  AutomationResource: () => AutomationResource,
28
28
  CliUsageError: () => CliUsageError,
29
29
  CompanyNewsResource: () => CompanyNewsResource,
30
+ FollowsResource: () => FollowsResource,
30
31
  ForYouResource: () => ForYouResource,
31
32
  MarketsResource: () => MarketsResource,
32
33
  PBSV_UPDATE_MESSAGE: () => PBSV_UPDATE_MESSAGE,
@@ -2888,6 +2889,458 @@ var SubscriptionsResource = class {
2888
2889
  }
2889
2890
  };
2890
2891
 
2892
+ // src/resources/follows.ts
2893
+ var MAX_TICKERS = 50;
2894
+ var MAX_TICKER_LENGTH = 40;
2895
+ var MAX_WATCHLIST_FIRST = 100;
2896
+ var MAX_PROFILE_FIRST = 50;
2897
+ var MAX_PROFILE_QUERY_LENGTH = 200;
2898
+ var LOOKUP_CONCURRENCY = 5;
2899
+ var TICKER_KINDS = ["STOCK", "ETF", "CRYPTO"];
2900
+ var PROFILE_KINDS = ["USER", "PERSON"];
2901
+ var UNRESOLVED_LOOKUP_CODES = /* @__PURE__ */ new Set(["NOT_FOUND", "FAILED_PRECONDITION"]);
2902
+ var GRAPHQL_STATUS_BY_CODE2 = {
2903
+ INVALID_ARGUMENT: 400,
2904
+ UNAUTHENTICATED: 401,
2905
+ PERMISSION_DENIED: 403,
2906
+ NOT_FOUND: 404,
2907
+ ALREADY_EXISTS: 409,
2908
+ ABORTED: 409,
2909
+ FAILED_PRECONDITION: 412,
2910
+ RESOURCE_EXHAUSTED: 429,
2911
+ INTERNAL: 500,
2912
+ UNKNOWN: 500,
2913
+ DATA_LOSS: 500,
2914
+ UNAVAILABLE: 503,
2915
+ DEADLINE_EXCEEDED: 504
2916
+ };
2917
+ var TICKER_FIELDS = "id ticker name kind";
2918
+ var PROFILE_FIELDS = "__typename id displayName followersCount viewerState { following } ... on PublicUser { username } ... on Person { slug xHandle }";
2919
+ function record3(value) {
2920
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2921
+ }
2922
+ function invalidResponse3(field) {
2923
+ throw new AlvaError(
2924
+ "GRAPHQL_INVALID_RESPONSE",
2925
+ `GraphQL returned an invalid ${field} response`,
2926
+ 502
2927
+ );
2928
+ }
2929
+ function graphQLFailure(response) {
2930
+ if (!record3(response) || response.errors === void 0) return void 0;
2931
+ if (!Array.isArray(response.errors)) return invalidResponse3("GraphQL");
2932
+ if (response.errors.length === 0) return void 0;
2933
+ const errors = response.errors;
2934
+ const messages = errors.flatMap(
2935
+ (error) => record3(error) && typeof error.message === "string" ? [error.message] : []
2936
+ );
2937
+ const codes = errors.map(
2938
+ (error) => record3(error) && record3(error.extensions) ? error.extensions.code : void 0
2939
+ );
2940
+ const code = typeof codes[0] === "string" && Object.hasOwn(GRAPHQL_STATUS_BY_CODE2, codes[0]) && codes.every((value) => value === codes[0]) ? codes[0] : "GRAPHQL_ERROR";
2941
+ return { code, message: messages.join("; ") || "Request failed", errors };
2942
+ }
2943
+ function throwFailure(failure) {
2944
+ throw new AlvaError(
2945
+ failure.code,
2946
+ failure.message,
2947
+ GRAPHQL_STATUS_BY_CODE2[failure.code] ?? 502,
2948
+ { errors: failure.errors }
2949
+ );
2950
+ }
2951
+ function responseData(response, field) {
2952
+ const failure = graphQLFailure(response);
2953
+ if (failure) throwFailure(failure);
2954
+ if (!record3(response) || !record3(response.data))
2955
+ return invalidResponse3(field);
2956
+ return response.data;
2957
+ }
2958
+ function viewerField2(response, field) {
2959
+ const data = responseData(response, field);
2960
+ if (!record3(data.viewer)) return invalidResponse3(field);
2961
+ return data.viewer[field];
2962
+ }
2963
+ function requireString(value, field) {
2964
+ if (typeof value !== "string" || !value) return invalidResponse3(field);
2965
+ return value;
2966
+ }
2967
+ function pageInfo(value, field) {
2968
+ if (!record3(value) || typeof value.hasNextPage !== "boolean" || value.endCursor !== null && value.endCursor !== void 0 && typeof value.endCursor !== "string" || value.hasNextPage && !value.endCursor) {
2969
+ return invalidResponse3(field);
2970
+ }
2971
+ return {
2972
+ endCursor: typeof value.endCursor === "string" ? value.endCursor : "",
2973
+ hasNextPage: value.hasNextPage
2974
+ };
2975
+ }
2976
+ function normalizeProfile(value, field) {
2977
+ if (!record3(value) || !record3(value.viewerState))
2978
+ return invalidResponse3(field);
2979
+ const following = value.viewerState.following;
2980
+ if (typeof value.followersCount !== "number" || typeof value.displayName !== "string" || following !== null && typeof following !== "boolean") {
2981
+ return invalidResponse3(field);
2982
+ }
2983
+ const base = {
2984
+ id: requireString(value.id, field),
2985
+ displayName: value.displayName,
2986
+ followersCount: value.followersCount,
2987
+ following: following ?? null
2988
+ };
2989
+ if (value.__typename === "PublicUser") {
2990
+ return {
2991
+ kind: "USER",
2992
+ ...base,
2993
+ username: requireString(value.username, field)
2994
+ };
2995
+ }
2996
+ if (value.__typename === "Person") {
2997
+ if (value.xHandle !== null && value.xHandle !== void 0 && typeof value.xHandle !== "string") {
2998
+ return invalidResponse3(field);
2999
+ }
3000
+ return {
3001
+ kind: "PERSON",
3002
+ ...base,
3003
+ slug: requireString(value.slug, field),
3004
+ xHandle: value.xHandle ?? null
3005
+ };
3006
+ }
3007
+ return invalidResponse3(field);
3008
+ }
3009
+ function boundedFirst(value, max, name = "first") {
3010
+ if (value === void 0) return void 0;
3011
+ if (!Number.isInteger(value) || value < 1 || value > max) {
3012
+ throw new Error(`${name} must be an integer between 1 and ${max}`);
3013
+ }
3014
+ return value;
3015
+ }
3016
+ function optionalCursor(value) {
3017
+ if (value === void 0) return void 0;
3018
+ if (typeof value !== "string" || !value.trim() || value.length > 4096) {
3019
+ throw new Error(
3020
+ "after must be a non-empty cursor of at most 4096 characters"
3021
+ );
3022
+ }
3023
+ return value;
3024
+ }
3025
+ function profileKind(value, required) {
3026
+ if (value === void 0 && !required) return void 0;
3027
+ if (typeof value !== "string" || !PROFILE_KINDS.includes(value)) {
3028
+ throw new Error("kind must be USER or PERSON");
3029
+ }
3030
+ return value;
3031
+ }
3032
+ function tickerKind(value) {
3033
+ if (value === void 0) return void 0;
3034
+ if (typeof value !== "string" || !TICKER_KINDS.includes(value)) {
3035
+ throw new Error("kind must be STOCK, ETF, or CRYPTO");
3036
+ }
3037
+ return value;
3038
+ }
3039
+ function normalizeWatchlistTickersParams(params) {
3040
+ if (!record3(params) || !Array.isArray(params.tickers)) {
3041
+ throw new Error("tickers must be a list of ticker symbols");
3042
+ }
3043
+ const defaultKind = tickerKind(params.kind);
3044
+ const tickers = [];
3045
+ for (const raw of params.tickers) {
3046
+ const spec = typeof raw === "string" ? { ticker: raw } : raw;
3047
+ if (!record3(spec) || typeof spec.ticker !== "string") {
3048
+ throw new Error("tickers must be symbols or {ticker, kind} specs");
3049
+ }
3050
+ const ticker = spec.ticker.trim().toUpperCase();
3051
+ if (!ticker || /\s/.test(ticker) || ticker.length > MAX_TICKER_LENGTH) {
3052
+ throw new Error(
3053
+ `ticker '${spec.ticker}' must be a non-empty symbol of at most ${MAX_TICKER_LENGTH} characters`
3054
+ );
3055
+ }
3056
+ const kind = tickerKind(spec.kind) ?? defaultKind;
3057
+ if (!tickers.some((t) => t.ticker === ticker && t.kind === kind)) {
3058
+ tickers.push(kind === void 0 ? { ticker } : { ticker, kind });
3059
+ }
3060
+ }
3061
+ if (tickers.length === 0 || tickers.length > MAX_TICKERS) {
3062
+ throw new Error(
3063
+ `tickers must contain between 1 and ${MAX_TICKERS} symbols`
3064
+ );
3065
+ }
3066
+ return { tickers };
3067
+ }
3068
+ function validateProfileRef(params) {
3069
+ if (!record3(params)) throw new Error("profile reference must be an object");
3070
+ const kind = profileKind(params.kind, true);
3071
+ if (typeof params.id !== "string" || !/^[1-9]\d{0,18}$/.test(params.id)) {
3072
+ throw new Error("id must be a positive decimal profile id");
3073
+ }
3074
+ return { kind, id: params.id };
3075
+ }
3076
+ function validateSearchProfilesParams(params) {
3077
+ if (!record3(params) || typeof params.query !== "string") {
3078
+ throw new Error("query is required");
3079
+ }
3080
+ const query = params.query.trim();
3081
+ if (!query || query.length > MAX_PROFILE_QUERY_LENGTH) {
3082
+ throw new Error(
3083
+ `query must be non-empty and at most ${MAX_PROFILE_QUERY_LENGTH} characters`
3084
+ );
3085
+ }
3086
+ return {
3087
+ query,
3088
+ kind: profileKind(params.kind, false),
3089
+ first: boundedFirst(params.first, MAX_PROFILE_FIRST)
3090
+ };
3091
+ }
3092
+ function unresolvedTicker(input, kind, code, message) {
3093
+ if (kind === void 0) {
3094
+ return { ok: false, unresolved: { input, code, message } };
3095
+ }
3096
+ return {
3097
+ ok: false,
3098
+ unresolved: {
3099
+ input,
3100
+ kind,
3101
+ code,
3102
+ message: code === "NOT_FOUND" ? `no ${kind} entity found for ticker ${input}; it may exist as another kind (retry with a different :kind suffix or none)` : message
3103
+ }
3104
+ };
3105
+ }
3106
+ var FollowsResource = class {
3107
+ constructor(client) {
3108
+ this.client = client;
3109
+ }
3110
+ client;
3111
+ /** Add tickers to the watchlist by exact symbol in one atomic batch. */
3112
+ async addToWatchlist(params) {
3113
+ const { changed, unchanged, unresolved } = await this.changeWatchlist(
3114
+ params,
3115
+ "add"
3116
+ );
3117
+ return { added: changed, unchanged, unresolved };
3118
+ }
3119
+ /** Remove tickers from the watchlist by exact symbol in one atomic batch. */
3120
+ async removeFromWatchlist(params) {
3121
+ const { changed, unchanged, unresolved } = await this.changeWatchlist(
3122
+ params,
3123
+ "remove"
3124
+ );
3125
+ return { removed: changed, unchanged, unresolved };
3126
+ }
3127
+ /** One page of the watchlist, most recently added first. */
3128
+ async watchlist(params = {}) {
3129
+ const first = boundedFirst(params.first, MAX_WATCHLIST_FIRST);
3130
+ const after = optionalCursor(params.after);
3131
+ this.client._requireAuth();
3132
+ const response = await this.client._request("POST", "/query", {
3133
+ body: {
3134
+ query: `query ToolkitWatchlist($input: MarketWatchlistConnectionInput) { viewer { marketWatchlist(input: $input) { totalCount edges { cursor followedAtMs node { ${TICKER_FIELDS} } } pageInfo { endCursor hasNextPage } } } }`,
3135
+ variables: { input: { first: first ?? 20, after } }
3136
+ }
3137
+ });
3138
+ const field = "viewer.marketWatchlist";
3139
+ const value = viewerField2(response, "marketWatchlist");
3140
+ if (!record3(value) || typeof value.totalCount !== "number" || !Array.isArray(value.edges)) {
3141
+ return invalidResponse3(field);
3142
+ }
3143
+ const tickers = value.edges.map((edge) => {
3144
+ if (!record3(edge) || !record3(edge.node) || typeof edge.followedAtMs !== "number") {
3145
+ return invalidResponse3(field);
3146
+ }
3147
+ return {
3148
+ entityId: requireString(edge.node.id, field),
3149
+ ticker: requireString(edge.node.ticker, field),
3150
+ name: typeof edge.node.name === "string" ? edge.node.name : "",
3151
+ kind: requireString(edge.node.kind, field),
3152
+ addedAtMs: edge.followedAtMs
3153
+ };
3154
+ });
3155
+ return {
3156
+ totalCount: value.totalCount,
3157
+ tickers,
3158
+ pageInfo: pageInfo(value.pageInfo, field)
3159
+ };
3160
+ }
3161
+ /** Search public profiles (Alva users and curated people). */
3162
+ async searchProfiles(params) {
3163
+ const { query, kind, first } = validateSearchProfilesParams(params);
3164
+ this.client._requireAuth();
3165
+ const response = await this.client._request("POST", "/query", {
3166
+ body: {
3167
+ query: `query ToolkitSearchProfiles($input: PublicProfileConnectionInput) { profiles(input: $input) { edges { node { ${PROFILE_FIELDS} } } pageInfo { endCursor hasNextPage } } }`,
3168
+ variables: { input: { query, kind, first: first ?? 10 } }
3169
+ }
3170
+ });
3171
+ return this.profilesPage(
3172
+ responseData(response, "profiles").profiles,
3173
+ "profiles"
3174
+ );
3175
+ }
3176
+ /** One page of profiles the caller follows. */
3177
+ async profiles(params = {}) {
3178
+ const kind = profileKind(params.kind, false);
3179
+ const first = boundedFirst(params.first, MAX_PROFILE_FIRST);
3180
+ const after = optionalCursor(params.after);
3181
+ this.client._requireAuth();
3182
+ const response = await this.client._request("POST", "/query", {
3183
+ body: {
3184
+ query: `query ToolkitFollowedProfiles($input: FollowingProfileConnectionInput) { viewer { followingProfiles(input: $input) { edges { node { ${PROFILE_FIELDS} } } pageInfo { endCursor hasNextPage } } } }`,
3185
+ variables: { input: { kind, first: first ?? 20, after } }
3186
+ }
3187
+ });
3188
+ return this.profilesPage(
3189
+ viewerField2(response, "followingProfiles"),
3190
+ "viewer.followingProfiles"
3191
+ );
3192
+ }
3193
+ /** Follow one profile. Idempotent. */
3194
+ async followProfile(params) {
3195
+ return this.changeProfile(params, "followProfile");
3196
+ }
3197
+ /** Unfollow one profile. Idempotent. */
3198
+ async unfollowProfile(params) {
3199
+ return this.changeProfile(params, "unfollowProfile");
3200
+ }
3201
+ profilesPage(value, field) {
3202
+ if (!record3(value) || !Array.isArray(value.edges)) {
3203
+ return invalidResponse3(field);
3204
+ }
3205
+ return {
3206
+ profiles: value.edges.map(
3207
+ (edge) => record3(edge) ? normalizeProfile(edge.node, field) : invalidResponse3(field)
3208
+ ),
3209
+ pageInfo: pageInfo(value.pageInfo, field)
3210
+ };
3211
+ }
3212
+ async changeProfile(params, mutation) {
3213
+ const input = validateProfileRef(params);
3214
+ this.client._requireAuth();
3215
+ const response = await this.client._request("POST", "/query", {
3216
+ body: {
3217
+ query: `mutation ToolkitChangeProfileFollow($input: PublicProfileRefInput!) { ${mutation}(input: $input) { following target { ${PROFILE_FIELDS} } } }`,
3218
+ variables: { input }
3219
+ }
3220
+ });
3221
+ const value = responseData(response, mutation)[mutation];
3222
+ if (!record3(value) || typeof value.following !== "boolean") {
3223
+ return invalidResponse3(mutation);
3224
+ }
3225
+ return {
3226
+ following: value.following,
3227
+ profile: value.target === null || value.target === void 0 ? null : normalizeProfile(value.target, mutation)
3228
+ };
3229
+ }
3230
+ async changeWatchlist(params, direction) {
3231
+ const { tickers } = normalizeWatchlistTickersParams(params);
3232
+ this.client._requireAuth();
3233
+ const lookups = await this.lookupTickers(tickers);
3234
+ const changed = [];
3235
+ const unchanged = [];
3236
+ const unresolved = [];
3237
+ const groupByEntity = /* @__PURE__ */ new Map();
3238
+ const writeIds = [];
3239
+ for (const lookup of lookups) {
3240
+ if (!lookup.ok) {
3241
+ unresolved.push(lookup.unresolved);
3242
+ continue;
3243
+ }
3244
+ const seenGroup = groupByEntity.get(lookup.ticker.entityId);
3245
+ if (seenGroup) {
3246
+ seenGroup.push(lookup.ticker);
3247
+ continue;
3248
+ }
3249
+ const needsChange = direction === "add" ? !lookup.inWatchlist : lookup.inWatchlist;
3250
+ const group = needsChange ? changed : unchanged;
3251
+ group.push(lookup.ticker);
3252
+ groupByEntity.set(lookup.ticker.entityId, group);
3253
+ if (needsChange || direction === "remove") {
3254
+ writeIds.push(lookup.ticker.entityId);
3255
+ }
3256
+ }
3257
+ if (writeIds.length > 0) {
3258
+ const mutation = direction === "add" ? "followTickers" : "unfollowTickers";
3259
+ const input = direction === "add" ? "FollowTickersInput" : "UnfollowTickersInput";
3260
+ const response = await this.client._request("POST", "/query", {
3261
+ body: {
3262
+ query: `mutation ToolkitChangeWatchlist($input: ${input}!) { ${mutation}(input: $input) { entities { id } } }`,
3263
+ variables: { input: { entityIds: writeIds } }
3264
+ }
3265
+ });
3266
+ const value = responseData(response, mutation)[mutation];
3267
+ if (!record3(value) || !Array.isArray(value.entities)) {
3268
+ return invalidResponse3(mutation);
3269
+ }
3270
+ }
3271
+ return { changed, unchanged, unresolved };
3272
+ }
3273
+ async lookupTickers(tickers) {
3274
+ const results = new Array(tickers.length);
3275
+ let next = 0;
3276
+ const worker = async () => {
3277
+ while (next < tickers.length) {
3278
+ const index = next++;
3279
+ const { ticker, kind } = tickers[index];
3280
+ results[index] = await this.lookupTicker(ticker, kind);
3281
+ }
3282
+ };
3283
+ await Promise.all(
3284
+ Array.from(
3285
+ { length: Math.min(LOOKUP_CONCURRENCY, tickers.length) },
3286
+ worker
3287
+ )
3288
+ );
3289
+ return results;
3290
+ }
3291
+ async lookupTicker(input, kind) {
3292
+ const response = await this.client._request("POST", "/query", {
3293
+ body: {
3294
+ query: `query ToolkitTickerLookup($input: MarketEntityLookupInput!) { market { entity(input: $input) { ${TICKER_FIELDS} viewerState { isFollowed } } } }`,
3295
+ variables: { input: { ticker: input, kind } }
3296
+ }
3297
+ });
3298
+ const failure = graphQLFailure(response);
3299
+ if (failure) {
3300
+ if (UNRESOLVED_LOOKUP_CODES.has(failure.code)) {
3301
+ return unresolvedTicker(input, kind, failure.code, failure.message);
3302
+ }
3303
+ throwFailure(failure);
3304
+ }
3305
+ const field = "market.entity";
3306
+ if (!record3(response) || !record3(response.data) || !record3(response.data.market)) {
3307
+ return invalidResponse3(field);
3308
+ }
3309
+ const entity = response.data.market.entity;
3310
+ if (entity === null || entity === void 0) {
3311
+ return unresolvedTicker(
3312
+ input,
3313
+ kind,
3314
+ "NOT_FOUND",
3315
+ `no entity found for ticker: ${input}`
3316
+ );
3317
+ }
3318
+ if (!record3(entity)) return invalidResponse3(field);
3319
+ const viewerState = entity.viewerState;
3320
+ if (viewerState === null || viewerState === void 0) {
3321
+ throw new AlvaError(
3322
+ "PERMISSION_DENIED",
3323
+ "This credential cannot read the user's watchlist",
3324
+ 403
3325
+ );
3326
+ }
3327
+ if (!record3(viewerState) || typeof viewerState.isFollowed !== "boolean") {
3328
+ return invalidResponse3(field);
3329
+ }
3330
+ return {
3331
+ ok: true,
3332
+ inWatchlist: viewerState.isFollowed,
3333
+ ticker: {
3334
+ input,
3335
+ entityId: requireString(entity.id, field),
3336
+ ticker: requireString(entity.ticker, field),
3337
+ name: typeof entity.name === "string" ? entity.name : "",
3338
+ kind: requireString(entity.kind, field)
3339
+ }
3340
+ };
3341
+ }
3342
+ };
3343
+
2891
3344
  // src/resources/alerts.ts
2892
3345
  var AlertsResource = class {
2893
3346
  constructor(client) {
@@ -3559,7 +4012,8 @@ var MarketsResource = class {
3559
4012
  }
3560
4013
  selectPeriod(catalog, event, ticker) {
3561
4014
  if (event === "latest-completed") {
3562
- if (catalog.defaultPeriod) return catalog.defaultPeriod;
4015
+ const completed = catalog.periods.filter((period) => period.status === "COMPLETED").sort((a, b) => b.earningsDate.localeCompare(a.earningsDate));
4016
+ if (completed.length > 0) return completed[0];
3563
4017
  } else {
3564
4018
  const upcoming = catalog.periods.filter((period) => period.status === "UPCOMING").sort((a, b) => a.earningsDate.localeCompare(b.earningsDate));
3565
4019
  if (upcoming.length > 0) return upcoming[0];
@@ -3655,7 +4109,7 @@ var SCHEDULE_NAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
3655
4109
  var RFC3339 = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[+-](\d{2}):(\d{2}))$/i;
3656
4110
  var RFC3339_FRACTIONAL = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(Z|[+-](\d{2}):(\d{2}))$/i;
3657
4111
  var ISO_DURATION = /^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/;
3658
- var GRAPHQL_STATUS_BY_CODE2 = {
4112
+ var GRAPHQL_STATUS_BY_CODE3 = {
3659
4113
  INVALID_ARGUMENT: 400,
3660
4114
  UNAUTHENTICATED: 401,
3661
4115
  PERMISSION_DENIED: 403,
@@ -3757,7 +4211,7 @@ var SchedulesResource = class {
3757
4211
  const codes = response.errors.map((error) => error.extensions?.code);
3758
4212
  const distinctCodes = new Set(codes);
3759
4213
  const canonicalCode = distinctCodes.size === 1 && typeof codes[0] === "string" ? codes[0] : void 0;
3760
- const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE2[canonicalCode] : void 0;
4214
+ const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE3[canonicalCode] : void 0;
3761
4215
  const errorCode = canonicalCode !== void 0 && canonicalStatus !== void 0 ? canonicalCode : "GRAPHQL_ERROR";
3762
4216
  throw new AlvaError(
3763
4217
  errorCode,
@@ -4006,7 +4460,7 @@ function scheduleEmptyResponse() {
4006
4460
  }
4007
4461
 
4008
4462
  // src/resources/steward.ts
4009
- var GRAPHQL_STATUS_BY_CODE3 = {
4463
+ var GRAPHQL_STATUS_BY_CODE4 = {
4010
4464
  INVALID_ARGUMENT: 400,
4011
4465
  UNAUTHENTICATED: 401,
4012
4466
  PERMISSION_DENIED: 403,
@@ -4051,12 +4505,47 @@ var BRIEFED = `
4051
4505
  mutation ToolkitStewardBriefed($input: CompleteStewardBriefInput!) {
4052
4506
  completeStewardBrief(input: $input) { ok }
4053
4507
  }`.trim();
4508
+ var DIGEST_RUN_FIELDS = `
4509
+ digestRunId state scheduleId scheduleVersion occurrenceIndex
4510
+ windowSinceMs windowUntilMs scanCompletedAtMs bodySha256 coverageSha256
4511
+ channelMessageId attempts lastError startedAtMs completedAtMs sendUncertainAtMs
4512
+ `.trim();
4513
+ var DIGEST_RUN = `
4514
+ query ToolkitStewardDigestRun($inboxPath: String!, $digestRunId: String!) {
4515
+ viewer { stewardDigestRun(inboxPath: $inboxPath, digestRunId: $digestRunId) { ${DIGEST_RUN_FIELDS} } }
4516
+ }`.trim();
4517
+ var DIGEST_RUN_PENDING = `
4518
+ query ToolkitStewardDigestRunPending($inboxPath: String!, $digestRunId: String!, $input: StewardDigestRunPendingInput) {
4519
+ viewer {
4520
+ stewardDigestRunPending(inboxPath: $inboxPath, digestRunId: $digestRunId, input: $input) {
4521
+ edges {
4522
+ node { deliveryId feedEntryId source { kind id } decisionReason consumedAtMs alertSnapshot }
4523
+ }
4524
+ pageInfo { hasNextPage endCursor }
4525
+ }
4526
+ }
4527
+ }`.trim();
4528
+ var PUBLISH_DAILY_BRIEF = `
4529
+ mutation ToolkitStewardPublishDailyBrief($input: PublishStewardDailyBriefInput!) {
4530
+ publishStewardDailyBrief(input: $input) { run { ${DIGEST_RUN_FIELDS} } }
4531
+ }`.trim();
4054
4532
  var DECISIONS = /* @__PURE__ */ new Set([
4055
4533
  "immediate",
4056
4534
  "digest",
4057
4535
  "suppress"
4058
4536
  ]);
4059
4537
  var DELIVERY_ID = /^[1-9][0-9]{0,18}$/;
4538
+ var MAX_LEGACY_BRIEFED_IDS = 100;
4539
+ var MAX_DIGEST_RUN_COVERAGE = 1e4;
4540
+ var DIGEST_RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
4541
+ var PENDING_ATTEMPTS = 3;
4542
+ var TRANSIENT_PENDING_CODES = /* @__PURE__ */ new Set([
4543
+ "NETWORK_ERROR",
4544
+ "NETWORK_TIMEOUT",
4545
+ "UNAVAILABLE",
4546
+ "DEADLINE_EXCEEDED"
4547
+ ]);
4548
+ var TRANSIENT_HTTP_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
4060
4549
  function invalid2(message) {
4061
4550
  return new AlvaError("INVALID_ARGUMENT", message, 400);
4062
4551
  }
@@ -4115,6 +4604,13 @@ function requireRequestId(value) {
4115
4604
  throw invalid2("request id must be a UUID");
4116
4605
  return value;
4117
4606
  }
4607
+ function requireDigestRunId(value) {
4608
+ if (!DIGEST_RUN_ID.test(value)) throw invalid2("digest run id must be a UUID");
4609
+ return value.toLowerCase();
4610
+ }
4611
+ function isTransientStewardError(error) {
4612
+ return error instanceof AlvaError && (TRANSIENT_PENDING_CODES.has(error.code) || TRANSIENT_HTTP_STATUSES.has(error.status));
4613
+ }
4118
4614
  function emptyResponse() {
4119
4615
  return new AlvaError("EMPTY_RESPONSE", "steward response was empty", 502);
4120
4616
  }
@@ -4177,6 +4673,56 @@ var StewardResource = class {
4177
4673
  return message;
4178
4674
  }
4179
4675
  async pending(params) {
4676
+ if (params.after !== void 0) return this.pendingPage(params);
4677
+ const items = [];
4678
+ const deliveryIds = /* @__PURE__ */ new Set();
4679
+ const cursors = /* @__PURE__ */ new Set();
4680
+ let after;
4681
+ let windowSinceMs;
4682
+ let windowUntilMs;
4683
+ do {
4684
+ const page = await this.pendingPageWithRetry({
4685
+ ...params,
4686
+ after,
4687
+ sinceMs: after === void 0 ? params.sinceMs : void 0,
4688
+ untilMs: after === void 0 ? params.untilMs : void 0
4689
+ });
4690
+ if (windowSinceMs === void 0) {
4691
+ windowSinceMs = page.windowSinceMs;
4692
+ windowUntilMs = page.windowUntilMs;
4693
+ } else if (page.windowSinceMs !== windowSinceMs || page.windowUntilMs !== windowUntilMs) {
4694
+ throw new AlvaError(
4695
+ "ABORTED",
4696
+ "steward pending window changed during pagination",
4697
+ 409
4698
+ );
4699
+ }
4700
+ for (const item of page.items) {
4701
+ if (deliveryIds.has(item.deliveryId)) continue;
4702
+ deliveryIds.add(item.deliveryId);
4703
+ items.push(item);
4704
+ }
4705
+ after = page.nextCursor ?? void 0;
4706
+ if (after !== void 0) {
4707
+ if (cursors.has(after)) {
4708
+ throw new AlvaError(
4709
+ "INTERNAL",
4710
+ "steward pending pagination loop detected",
4711
+ 500
4712
+ );
4713
+ }
4714
+ cursors.add(after);
4715
+ }
4716
+ } while (after !== void 0);
4717
+ if (windowSinceMs === void 0 || windowUntilMs === void 0)
4718
+ throw emptyResponse();
4719
+ return {
4720
+ items,
4721
+ windowSinceMs,
4722
+ windowUntilMs
4723
+ };
4724
+ }
4725
+ async pendingPage(params) {
4180
4726
  this.client._requireAuth();
4181
4727
  const first = params.first ?? 50;
4182
4728
  if (!Number.isInteger(first) || first < 1 || first > 100)
@@ -4205,7 +4751,14 @@ var StewardResource = class {
4205
4751
  if (!Number.isSafeInteger(windowSinceMs) || !Number.isSafeInteger(windowUntilMs) || windowSinceMs <= 0 || windowUntilMs <= windowSinceMs)
4206
4752
  throw emptyResponse();
4207
4753
  const items = page.edges.map((edge) => edge.node);
4208
- const nextCursor2 = page.pageInfo?.hasNextPage === true && page.pageInfo.endCursor ? page.pageInfo.endCursor : null;
4754
+ const pageInfo2 = page.pageInfo;
4755
+ if (!pageInfo2 || typeof pageInfo2.hasNextPage !== "boolean")
4756
+ throw emptyResponse();
4757
+ const endCursor = pageInfo2.endCursor;
4758
+ if (endCursor !== void 0 && endCursor !== null && typeof endCursor !== "string")
4759
+ throw emptyResponse();
4760
+ if (pageInfo2.hasNextPage && !endCursor) throw emptyResponse();
4761
+ const nextCursor2 = pageInfo2.hasNextPage ? endCursor : null;
4209
4762
  return {
4210
4763
  items,
4211
4764
  nextCursor: nextCursor2,
@@ -4213,20 +4766,95 @@ var StewardResource = class {
4213
4766
  windowUntilMs
4214
4767
  };
4215
4768
  }
4769
+ async pendingPageWithRetry(params) {
4770
+ for (let attempt = 1; attempt < PENDING_ATTEMPTS; attempt += 1) {
4771
+ try {
4772
+ return await this.pendingPage(params);
4773
+ } catch (error) {
4774
+ if (!isTransientStewardError(error)) throw error;
4775
+ }
4776
+ }
4777
+ return this.pendingPage(params);
4778
+ }
4216
4779
  async briefed(params) {
4217
4780
  this.client._requireAuth();
4218
4781
  const digestRunId = params.digestRunId?.trim();
4219
4782
  if (!digestRunId) throw invalid2("a digest run id is required");
4783
+ const inboxPath = requireInboxPath(params);
4784
+ const deliveryIds = requireDeliveryIds(params.deliveryIds);
4785
+ if (deliveryIds.length > MAX_LEGACY_BRIEFED_IDS)
4786
+ throw invalid2("legacy briefed accepts at most 100 delivery ids");
4220
4787
  const data = await this.graphql(BRIEFED, {
4221
4788
  input: {
4222
- inboxPath: requireInboxPath(params),
4223
- deliveryIds: requireDeliveryIds(params.deliveryIds),
4789
+ inboxPath,
4790
+ deliveryIds,
4224
4791
  digestRunId
4225
4792
  }
4226
4793
  });
4227
4794
  if (data.completeStewardBrief?.ok !== true) throw emptyResponse();
4228
4795
  return { ok: true };
4229
4796
  }
4797
+ async digestRun(params) {
4798
+ this.client._requireAuth();
4799
+ const data = await this.graphql(DIGEST_RUN, {
4800
+ inboxPath: requireInboxPath(params),
4801
+ digestRunId: requireDigestRunId(params.digestRunId)
4802
+ });
4803
+ const run = data.viewer?.stewardDigestRun;
4804
+ if (!run) throw emptyResponse();
4805
+ return run;
4806
+ }
4807
+ async digestRunPending(params) {
4808
+ this.client._requireAuth();
4809
+ const inboxPath = requireInboxPath(params);
4810
+ const digestRunId = requireDigestRunId(params.digestRunId);
4811
+ const items = [];
4812
+ const seenCursors = /* @__PURE__ */ new Set();
4813
+ let after;
4814
+ for (; ; ) {
4815
+ const data = await this.graphql(DIGEST_RUN_PENDING, {
4816
+ inboxPath,
4817
+ digestRunId,
4818
+ input: { first: 100, ...after === void 0 ? {} : { after } }
4819
+ });
4820
+ const connection2 = data.viewer?.stewardDigestRunPending;
4821
+ if (!connection2 || !Array.isArray(connection2.edges))
4822
+ throw emptyResponse();
4823
+ const pageInfo2 = connection2.pageInfo;
4824
+ if (!pageInfo2 || typeof pageInfo2.hasNextPage !== "boolean")
4825
+ throw emptyResponse();
4826
+ for (const edge of connection2.edges) {
4827
+ if (!edge?.node) throw emptyResponse();
4828
+ items.push(edge.node);
4829
+ }
4830
+ if (!pageInfo2.hasNextPage) break;
4831
+ const next = pageInfo2.endCursor;
4832
+ if (typeof next !== "string" || next === "" || seenCursors.has(next))
4833
+ throw emptyResponse();
4834
+ seenCursors.add(next);
4835
+ after = next;
4836
+ }
4837
+ return items;
4838
+ }
4839
+ async sendDigestRun(params) {
4840
+ this.client._requireAuth();
4841
+ const deliveryIds = normalizeDeliveryIds(params.deliveryIds ?? []);
4842
+ if (deliveryIds.length > MAX_DIGEST_RUN_COVERAGE)
4843
+ throw invalid2("durable Daily Brief accepts at most 10000 delivery ids");
4844
+ if (params.body !== void 0 && params.body.trim() === "")
4845
+ throw invalid2("a message body must be non-blank when provided");
4846
+ const data = await this.graphql(PUBLISH_DAILY_BRIEF, {
4847
+ input: {
4848
+ inboxPath: requireInboxPath(params),
4849
+ digestRunId: requireDigestRunId(params.digestRunId),
4850
+ deliveryIds,
4851
+ ...params.body === void 0 ? {} : { body: params.body }
4852
+ }
4853
+ });
4854
+ const run = data.publishStewardDailyBrief?.run;
4855
+ if (!run) throw emptyResponse();
4856
+ return run;
4857
+ }
4230
4858
  async graphql(query, variables) {
4231
4859
  const response = await this.client._request("POST", "/query", {
4232
4860
  body: { query, variables }
@@ -4235,7 +4863,7 @@ var StewardResource = class {
4235
4863
  if (response.errors?.length) {
4236
4864
  const codes = response.errors.map((error) => error.extensions?.code);
4237
4865
  const canonicalCode = new Set(codes).size === 1 && typeof codes[0] === "string" ? codes[0] : void 0;
4238
- const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE3[canonicalCode] : void 0;
4866
+ const canonicalStatus = canonicalCode ? GRAPHQL_STATUS_BY_CODE4[canonicalCode] : void 0;
4239
4867
  throw new AlvaError(
4240
4868
  canonicalCode !== void 0 && canonicalStatus !== void 0 ? canonicalCode : "GRAPHQL_ERROR",
4241
4869
  response.errors.map((error) => error.message).filter((message) => typeof message === "string").join("; ") || "GraphQL request failed",
@@ -4351,12 +4979,12 @@ function dedupe(candidates) {
4351
4979
  });
4352
4980
  }
4353
4981
  function resolveFilters(params) {
4354
- const record3 = isRecord(params) ? params : {};
4982
+ const record4 = isRecord(params) ? params : {};
4355
4983
  return {
4356
- market: typeof record3.market === "string" ? record3.market : void 0,
4357
- instrumentType: typeof record3.instrumentType === "string" ? record3.instrumentType : void 0,
4358
- underlyingType: typeof record3.underlyingType === "string" ? record3.underlyingType : void 0,
4359
- quote: typeof record3.quote === "string" ? record3.quote : void 0
4984
+ market: typeof record4.market === "string" ? record4.market : void 0,
4985
+ instrumentType: typeof record4.instrumentType === "string" ? record4.instrumentType : void 0,
4986
+ underlyingType: typeof record4.underlyingType === "string" ? record4.underlyingType : void 0,
4987
+ quote: typeof record4.quote === "string" ? record4.quote : void 0
4360
4988
  };
4361
4989
  }
4362
4990
  function pairSearchParams(pair, params) {
@@ -4404,11 +5032,11 @@ var TradingPairsResource = class {
4404
5032
  return { query, candidates };
4405
5033
  }
4406
5034
  async resolve(params) {
4407
- const record3 = isRecord(params) ? params : {};
4408
- const pair = typeof record3.pair === "string" ? record3.pair.trim() : void 0;
5035
+ const record4 = isRecord(params) ? params : {};
5036
+ const pair = typeof record4.pair === "string" ? record4.pair.trim() : void 0;
4409
5037
  const filters = resolveFilters(params);
4410
5038
  const searchParams = pair === void 0 ? {
4411
- symbol: typeof record3.symbol === "string" ? record3.symbol : "",
5039
+ symbol: typeof record4.symbol === "string" ? record4.symbol : "",
4412
5040
  ...filters
4413
5041
  } : pairSearchParams(pair, filters);
4414
5042
  const result = await this.search(searchParams);
@@ -4621,6 +5249,58 @@ function nextCursor(page) {
4621
5249
  throw invalid3();
4622
5250
  return info.hasNextPage ? info.endCursor : null;
4623
5251
  }
5252
+ var RETURN_QUERY = `query ToolkitThesisReturn($id: ID!, $detail: Boolean!) {
5253
+ node(id: $id) { ... on Playbook { latestRelease { thesisPublication {
5254
+ returnTracking
5255
+ thesisReturn(detail: $detail) {
5256
+ live value firstFillAtMs pricedAtMs stale computedAtMs
5257
+ updates { authorVersionId publishedAtMs startValue updateReturn
5258
+ positions { entityId symbol direction startPrice startAtMs endPrice endAtMs end positionReturn currency } }
5259
+ }
5260
+ } } } }
5261
+ }`;
5262
+ async function thesisReturn(client, id, params = {}) {
5263
+ if (!isPositiveInt64(id))
5264
+ throw argument("id must be an internal positive int64 Playbook ID");
5265
+ if (params.detail !== void 0 && typeof params.detail !== "boolean")
5266
+ throw argument("detail must be a boolean");
5267
+ client._requireAuth();
5268
+ const data = await graphql(client, RETURN_QUERY, {
5269
+ id: `Playbook:${id}`,
5270
+ detail: params.detail ?? false
5271
+ });
5272
+ if (data.node === null) throw notFound();
5273
+ if (!record2(data.node)) throw invalid3();
5274
+ const release = data.node.latestRelease;
5275
+ if (release === null || release === void 0)
5276
+ return { playbookId: id, returnTracking: null, thesisReturn: null };
5277
+ if (!record2(release)) throw invalid3();
5278
+ const publication = release.thesisPublication;
5279
+ if (publication === null)
5280
+ return { playbookId: id, returnTracking: null, thesisReturn: null };
5281
+ if (!record2(publication)) throw invalid3();
5282
+ const tracking = publication.returnTracking;
5283
+ if (tracking !== null && !["UNSET", "ON", "OFF"].includes(tracking))
5284
+ throw invalid3();
5285
+ const value = publication.thesisReturn;
5286
+ if (value !== null && !validThesisReturn(value)) throw invalid3();
5287
+ return {
5288
+ playbookId: id,
5289
+ returnTracking: tracking,
5290
+ thesisReturn: value
5291
+ };
5292
+ }
5293
+ function validThesisReturn(value) {
5294
+ if (!record2(value) || typeof value.live !== "boolean" || typeof value.value !== "number" || typeof value.stale !== "boolean" || typeof value.computedAtMs !== "number" || !Array.isArray(value.updates))
5295
+ return false;
5296
+ return value.updates.every(
5297
+ (update) => record2(update) && nonempty(update.authorVersionId) && typeof update.publishedAtMs === "number" && typeof update.startValue === "number" && Array.isArray(update.positions) && update.positions.every(
5298
+ (position) => record2(position) && nonempty(position.symbol) && ["BULLISH", "BEARISH"].includes(position.direction) && ["PENDING", "NEXT_UPDATE", "LATEST"].includes(
5299
+ position.end
5300
+ ) && typeof position.positionReturn === "number"
5301
+ )
5302
+ );
5303
+ }
4624
5304
  async function graphql(client, document, variables) {
4625
5305
  const response = await client._request("POST", "/query", {
4626
5306
  body: { query: document, variables }
@@ -4706,17 +5386,29 @@ var ThesesResource = class {
4706
5386
  related(id, params = {}) {
4707
5387
  return relatedTheses(this.client, id, params);
4708
5388
  }
4709
- async assetCandidates(text) {
5389
+ async assetCandidates(text, params = {}) {
4710
5390
  this.client._requireAuth();
4711
5391
  const source = requireBody(text);
5392
+ const input = {
5393
+ text: source,
5394
+ selectedEntityIds: requireIDs(params.entityIds ?? [], "entityIds")
5395
+ };
5396
+ if (params.thesisId !== void 0)
5397
+ input.thesisId = requireID(params.thesisId, "thesisId");
5398
+ if (params.discover !== void 0) {
5399
+ if (typeof params.discover !== "boolean")
5400
+ throw invalidArgument("discover must be a boolean");
5401
+ input.discover = params.discover;
5402
+ }
4712
5403
  const response = await this.client._request("POST", "/query", {
4713
5404
  body: {
4714
5405
  query: `query ThesisAssetCandidates($input: ThesisAssetCandidatesInput!) {
4715
5406
  viewer { thesisAssetCandidates(input: $input) {
4716
5407
  mentions { quote ticker resolution stance candidates { entityId ticker name kind } }
5408
+ returnPreview { tracking askSwitch directions { entityId direction } keptEntityIds lastLegRemoved }
4717
5409
  } }
4718
5410
  }`,
4719
- variables: { input: { text: source } }
5411
+ variables: { input }
4720
5412
  }
4721
5413
  });
4722
5414
  if (Array.isArray(response?.errors) && response.errors.length > 0) {
@@ -4728,19 +5420,19 @@ var ThesesResource = class {
4728
5420
  const viewer = isRecord2(data) ? data.viewer : void 0;
4729
5421
  const result = isRecord2(viewer) ? viewer.thesisAssetCandidates : void 0;
4730
5422
  if (!isRecord2(result) || !Array.isArray(result.mentions)) {
4731
- throw invalidResponse3("asset candidates response must contain mentions");
5423
+ throw invalidResponse4("asset candidates response must contain mentions");
4732
5424
  }
4733
5425
  const mentions = result.mentions.map((item, index) => {
4734
5426
  if (!isRecord2(item) || typeof item.quote !== "string" || typeof item.ticker !== "string" || !["RESOLVED", "AMBIGUOUS", "UNRESOLVED"].includes(
4735
5427
  item.resolution
4736
5428
  ) || !["UNKNOWN", "BULLISH", "BEARISH"].includes(item.stance) || !Array.isArray(item.candidates)) {
4737
- throw invalidResponse3(`asset mention ${index} is invalid`);
5429
+ throw invalidResponse4(`asset mention ${index} is invalid`);
4738
5430
  }
4739
5431
  const candidates = item.candidates.map((candidate) => {
4740
5432
  if (!isRecord2(candidate) || typeof candidate.ticker !== "string" || typeof candidate.name !== "string" || !["STOCK", "ETF", "CRYPTO", "INDEX"].includes(
4741
5433
  candidate.kind
4742
5434
  )) {
4743
- throw invalidResponse3(`asset mention ${index} has invalid candidate`);
5435
+ throw invalidResponse4(`asset mention ${index} has invalid candidate`);
4744
5436
  }
4745
5437
  return {
4746
5438
  entityId: responseID(
@@ -4754,7 +5446,11 @@ var ThesesResource = class {
4754
5446
  });
4755
5447
  return { ...item, candidates };
4756
5448
  });
4757
- return { mentions };
5449
+ return { mentions, returnPreview: returnPreview(result.returnPreview) };
5450
+ }
5451
+ /** The Thesis return of a Playbook's current publication; detail revalues it. */
5452
+ thesisReturn(id, params = {}) {
5453
+ return thesisReturn(this.client, id, params);
4758
5454
  }
4759
5455
  async create(params) {
4760
5456
  this.client._requireAuth();
@@ -4770,7 +5466,7 @@ var ThesesResource = class {
4770
5466
  await this.client._request("GET", `/api/v1/theses/${thesisID}`)
4771
5467
  );
4772
5468
  if (response.thesis.id !== thesisID) {
4773
- throw invalidResponse3("get response must match the requested thesis");
5469
+ throw invalidResponse4("get response must match the requested thesis");
4774
5470
  }
4775
5471
  return response;
4776
5472
  }
@@ -4785,7 +5481,7 @@ var ThesesResource = class {
4785
5481
  )
4786
5482
  );
4787
5483
  if (response.thesis.id !== thesisID || response.thesis.author_version_id !== versionID) {
4788
- throw invalidResponse3(
5484
+ throw invalidResponse4(
4789
5485
  "version response must match the requested thesis and author version"
4790
5486
  );
4791
5487
  }
@@ -4808,38 +5504,14 @@ var ThesesResource = class {
4808
5504
  }
4809
5505
  );
4810
5506
  if (!isRecord2(response) || !Array.isArray(response.versions) || typeof response.next_cursor !== "string")
4811
- throw invalidResponse3("invalid Update list");
5507
+ throw invalidResponse4("invalid Update list");
4812
5508
  const versions = response.versions.map(
4813
5509
  (value) => thesisResponse({ thesis: value }).thesis
4814
5510
  );
4815
5511
  if (versions.some((version) => version.id !== thesisID))
4816
- throw invalidResponse3("Update list must match requested Thesis");
5512
+ throw invalidResponse4("Update list must match requested Thesis");
4817
5513
  return { versions, next_cursor: response.next_cursor };
4818
5514
  }
4819
- /** Deletes only the selected Update; never falls back to whole-Thesis deletion. */
4820
- async deleteUpdate(id, authorVersionID, expectedAuthorVersionID) {
4821
- this.client._requireAuth();
4822
- const thesisID = requireID(id, "id");
4823
- const versionID = requireID(authorVersionID, "author_version_id");
4824
- const expected = requireID(
4825
- expectedAuthorVersionID,
4826
- "expected_author_version_id"
4827
- );
4828
- const response = thesisResponse(
4829
- await this.client._request(
4830
- "DELETE",
4831
- `/api/v1/theses/${thesisID}/versions/${versionID}`,
4832
- {
4833
- query: { expected_author_version_id: expected }
4834
- }
4835
- )
4836
- );
4837
- if (response.thesis.id !== thesisID)
4838
- throw invalidResponse3(
4839
- "delete Update response must match requested Thesis"
4840
- );
4841
- return response;
4842
- }
4843
5515
  async signals(id, params = {}) {
4844
5516
  this.client._requireAuth();
4845
5517
  const first = params.first ?? 20;
@@ -4874,7 +5546,7 @@ var ThesesResource = class {
4874
5546
  })
4875
5547
  );
4876
5548
  if (response.thesis.id !== thesisID) {
4877
- throw invalidResponse3("update response must match the requested thesis");
5549
+ throw invalidResponse4("update response must match the requested thesis");
4878
5550
  }
4879
5551
  return response;
4880
5552
  }
@@ -4896,7 +5568,7 @@ var ThesesResource = class {
4896
5568
  current.thesis.entity_ids,
4897
5569
  current.thesis.entity_stances
4898
5570
  )) {
4899
- throw invalidResponse3(
5571
+ throw invalidResponse4(
4900
5572
  "archive requires one entity_stance for every Thesis entity"
4901
5573
  );
4902
5574
  }
@@ -4913,7 +5585,7 @@ var ThesesResource = class {
4913
5585
  note: params.note
4914
5586
  });
4915
5587
  if (response.thesis.id !== thesisID || response.thesis.archived !== params.archived) {
4916
- throw invalidResponse3("archive response must match the requested state");
5588
+ throw invalidResponse4("archive response must match the requested state");
4917
5589
  }
4918
5590
  return response;
4919
5591
  }
@@ -4928,15 +5600,15 @@ var ThesesResource = class {
4928
5600
  });
4929
5601
  const result = data.setThesisStarred;
4930
5602
  if (!isRecord2(result) || !isRecord2(result.stats) || !isRecord2(result.viewerState)) {
4931
- throw invalidResponse3("star response must contain stats and viewerState");
5603
+ throw invalidResponse4("star response must contain stats and viewerState");
4932
5604
  }
4933
5605
  const returnedID = responseID(result.thesisId, "thesisId");
4934
5606
  if (returnedID !== thesisID) {
4935
- throw invalidResponse3("star response must match the requested thesis");
5607
+ throw invalidResponse4("star response must match the requested thesis");
4936
5608
  }
4937
5609
  const starCount = result.stats.starCount;
4938
5610
  if (typeof starCount !== "number" || !Number.isInteger(starCount) || starCount < 0) {
4939
- throw invalidResponse3(
5611
+ throw invalidResponse4(
4940
5612
  "star response must contain a nonnegative star count"
4941
5613
  );
4942
5614
  }
@@ -4945,7 +5617,7 @@ var ThesesResource = class {
4945
5617
  "viewerState.isStarred"
4946
5618
  );
4947
5619
  if (returnedStarred !== isStarred) {
4948
- throw invalidResponse3("star response did not apply the requested state");
5620
+ throw invalidResponse4("star response did not apply the requested state");
4949
5621
  }
4950
5622
  return {
4951
5623
  thesis_id: returnedID,
@@ -4964,7 +5636,7 @@ var ThesesResource = class {
4964
5636
  });
4965
5637
  const result = data.setThesisSignalEnabled;
4966
5638
  if (!isRecord2(result) || !isRecord2(result.publication)) {
4967
- throw invalidResponse3("Signal response must contain publication");
5639
+ throw invalidResponse4("Signal response must contain publication");
4968
5640
  }
4969
5641
  const publication = result.publication;
4970
5642
  const returnedID = responseID(
@@ -4972,14 +5644,14 @@ var ThesesResource = class {
4972
5644
  "publication.playbookId"
4973
5645
  );
4974
5646
  if (returnedID !== thesisID) {
4975
- throw invalidResponse3("Signal response must match the requested thesis");
5647
+ throw invalidResponse4("Signal response must match the requested thesis");
4976
5648
  }
4977
5649
  const researchPaused = responseBoolean(
4978
5650
  publication.researchPaused,
4979
5651
  "publication.researchPaused"
4980
5652
  );
4981
5653
  if (researchPaused === enabled) {
4982
- throw invalidResponse3(
5654
+ throw invalidResponse4(
4983
5655
  "Signal response did not apply the requested state"
4984
5656
  );
4985
5657
  }
@@ -5009,41 +5681,12 @@ var ThesesResource = class {
5009
5681
  )
5010
5682
  );
5011
5683
  if (response.thesis.id !== thesisID || response.thesis.visibility !== visibility) {
5012
- throw invalidResponse3(
5684
+ throw invalidResponse4(
5013
5685
  "visibility response must match the requested thesis and visibility"
5014
5686
  );
5015
5687
  }
5016
5688
  return response;
5017
5689
  }
5018
- async close(id, params) {
5019
- this.client._requireAuth();
5020
- const body = {
5021
- expected_author_version_id: requireID(
5022
- params.expected_author_version_id,
5023
- "expected_author_version_id"
5024
- )
5025
- };
5026
- if (params.note !== void 0) body.note = requireText2(params.note, "note");
5027
- return thesisResponse(
5028
- await this.client._request(
5029
- "POST",
5030
- `/api/v1/theses/${requireID(id, "id")}/close`,
5031
- { body }
5032
- )
5033
- );
5034
- }
5035
- async delete(id) {
5036
- this.client._requireAuth();
5037
- const response = await this.client._request(
5038
- "DELETE",
5039
- `/api/v1/theses/${requireID(id, "id")}`
5040
- );
5041
- if (response === void 0) return {};
5042
- if (!isRecord2(response) || Object.keys(response).length !== 0) {
5043
- throw invalidResponse3("delete response must be {}");
5044
- }
5045
- return {};
5046
- }
5047
5690
  async rewrite(params) {
5048
5691
  this.client._requireAuth();
5049
5692
  const body = requireBody(params.body);
@@ -5056,7 +5699,7 @@ var ThesesResource = class {
5056
5699
  }
5057
5700
  );
5058
5701
  if (!isRecord2(response) || typeof response.body !== "string") {
5059
- throw invalidResponse3("rewrite response must contain a string body");
5702
+ throw invalidResponse4("rewrite response must contain a string body");
5060
5703
  }
5061
5704
  return { body: responseBody(response.body) };
5062
5705
  }
@@ -5086,6 +5729,8 @@ function createBody(params) {
5086
5729
  }
5087
5730
  if (params.tickers !== void 0)
5088
5731
  body.tickers = requireTickers(params.tickers);
5732
+ if (params.track_return !== void 0)
5733
+ body.track_return = requireTrackReturn(params.track_return);
5089
5734
  if (params.entity_stances !== void 0) {
5090
5735
  body.entity_stances = requireEntityStances(
5091
5736
  params.entity_stances,
@@ -5094,6 +5739,52 @@ function createBody(params) {
5094
5739
  }
5095
5740
  return body;
5096
5741
  }
5742
+ var ENTITY_STANCES = [
5743
+ "unknown",
5744
+ "bullish",
5745
+ "bearish",
5746
+ "none"
5747
+ ];
5748
+ var THESIS_DIRECTIONS = [
5749
+ "UNKNOWN",
5750
+ "BULLISH",
5751
+ "BEARISH",
5752
+ "NONE"
5753
+ ];
5754
+ var RETURN_TRACKING = ["UNSET", "ON", "OFF"];
5755
+ function requireTrackReturn(value) {
5756
+ if (typeof value !== "boolean")
5757
+ throw invalidArgument("track_return must be a boolean");
5758
+ return value;
5759
+ }
5760
+ function selectedDirections(value, field) {
5761
+ if (!Array.isArray(value)) throw invalidResponse4(`${field} must be an array`);
5762
+ return value.map((item, index) => {
5763
+ if (!isRecord2(item) || !THESIS_DIRECTIONS.includes(item.direction))
5764
+ throw invalidResponse4(`${field}[${index}] is invalid`);
5765
+ return {
5766
+ entityId: responseID(item.entityId, `${field}[${index}].entityId`),
5767
+ direction: item.direction
5768
+ };
5769
+ });
5770
+ }
5771
+ function returnPreview(value) {
5772
+ if (value === null || value === void 0) return null;
5773
+ if (!isRecord2(value) || !RETURN_TRACKING.includes(value.tracking) || typeof value.askSwitch !== "boolean" || typeof value.lastLegRemoved !== "boolean" || !Array.isArray(value.keptEntityIds))
5774
+ throw invalidResponse4("returnPreview is invalid");
5775
+ return {
5776
+ tracking: value.tracking,
5777
+ askSwitch: value.askSwitch,
5778
+ directions: selectedDirections(
5779
+ value.directions,
5780
+ "returnPreview.directions"
5781
+ ),
5782
+ keptEntityIds: value.keptEntityIds.map(
5783
+ (id, index) => responseID(id, `returnPreview.keptEntityIds[${index}]`)
5784
+ ),
5785
+ lastLegRemoved: value.lastLegRemoved
5786
+ };
5787
+ }
5097
5788
  function requireEntityStances(value, entityIDs) {
5098
5789
  if (!Array.isArray(value) || value.length > MAX_ENTITY_IDS)
5099
5790
  throw invalidArgument("entity_stances must contain at most 100 values");
@@ -5111,7 +5802,7 @@ function requireEntityStances(value, entityIDs) {
5111
5802
  "entity stance must reference one unique entity_id"
5112
5803
  );
5113
5804
  seen.add(entityID);
5114
- if (!["unknown", "bullish", "bearish"].includes(item.stance))
5805
+ if (!ENTITY_STANCES.includes(item.stance))
5115
5806
  throw invalidArgument(`entity_stances[${index}].stance is invalid`);
5116
5807
  return { entity_id: entityID, stance: item.stance };
5117
5808
  });
@@ -5126,8 +5817,7 @@ function updateBody(params) {
5126
5817
  body: requireBody(params.body),
5127
5818
  title: requireTitle(params.title ?? ""),
5128
5819
  entity_ids: requireIDs(params.entity_ids ?? [], "entity_ids"),
5129
- visibility: requireVisibility(params.visibility),
5130
- editorial: params.editorial ?? false
5820
+ visibility: requireVisibility(params.visibility)
5131
5821
  };
5132
5822
  if (params.medias !== void 0) {
5133
5823
  if (!Array.isArray(params.medias) || params.medias.length > 20)
@@ -5142,6 +5832,8 @@ function updateBody(params) {
5142
5832
  body.archived = params.archived;
5143
5833
  }
5144
5834
  if (params.note !== void 0) body.note = requireText2(params.note, "note");
5835
+ if (params.track_return !== void 0)
5836
+ body.track_return = requireTrackReturn(params.track_return);
5145
5837
  if (params.entity_stances !== void 0) {
5146
5838
  body.entity_stances = requireEntityStances(
5147
5839
  params.entity_stances,
@@ -5152,7 +5844,7 @@ function updateBody(params) {
5152
5844
  }
5153
5845
  function thesisResponse(response) {
5154
5846
  if (!isRecord2(response) || !isRecord2(response.thesis)) {
5155
- throw invalidResponse3("response must contain thesis");
5847
+ throw invalidResponse4("response must contain thesis");
5156
5848
  }
5157
5849
  const thesis = response.thesis;
5158
5850
  const value = {
@@ -5177,10 +5869,10 @@ function thesisResponse(response) {
5177
5869
  };
5178
5870
  if (thesis.medias !== void 0) {
5179
5871
  if (!Array.isArray(thesis.medias) || thesis.medias.length > 20)
5180
- throw invalidResponse3("thesis.medias must contain at most 20 items");
5872
+ throw invalidResponse4("thesis.medias must contain at most 20 items");
5181
5873
  value.medias = thesis.medias.map((item) => {
5182
5874
  if (!validMedia(item))
5183
- throw invalidResponse3("thesis.medias contains invalid media");
5875
+ throw invalidResponse4("thesis.medias contains invalid media");
5184
5876
  return {
5185
5877
  type: item.type,
5186
5878
  cover_url: item.cover_url,
@@ -5197,16 +5889,27 @@ function thesisResponse(response) {
5197
5889
  value.note = responseText(thesis.note, "thesis.note");
5198
5890
  if (thesis.entity_stances !== void 0) {
5199
5891
  if (!Array.isArray(thesis.entity_stances))
5200
- throw invalidResponse3("thesis.entity_stances must be an array");
5892
+ throw invalidResponse4("thesis.entity_stances must be an array");
5201
5893
  value.entity_stances = thesis.entity_stances.map((item) => {
5202
5894
  if (!isRecord2(item))
5203
- throw invalidResponse3("thesis.entity_stances contains invalid entry");
5895
+ throw invalidResponse4("thesis.entity_stances contains invalid entry");
5204
5896
  const entityID = responseID(item.entity_id, "entity_stances.entity_id");
5205
5897
  if (!value.entity_ids.includes(entityID))
5206
- throw invalidResponse3("entity stance must reference a thesis entity");
5207
- if (!["unknown", "bullish", "bearish"].includes(item.stance))
5208
- throw invalidResponse3("thesis.entity_stances contains invalid stance");
5209
- return { entity_id: entityID, stance: item.stance };
5898
+ throw invalidResponse4("entity stance must reference a thesis entity");
5899
+ if (!ENTITY_STANCES.includes(item.stance))
5900
+ throw invalidResponse4("thesis.entity_stances contains invalid stance");
5901
+ const stance = {
5902
+ entity_id: entityID,
5903
+ stance: item.stance
5904
+ };
5905
+ if (item.direction !== void 0) {
5906
+ if (!ENTITY_STANCES.includes(item.direction))
5907
+ throw invalidResponse4(
5908
+ "thesis.entity_stances contains invalid direction"
5909
+ );
5910
+ stance.direction = item.direction;
5911
+ }
5912
+ return stance;
5210
5913
  });
5211
5914
  }
5212
5915
  return { thesis: value };
@@ -5214,7 +5917,7 @@ function thesisResponse(response) {
5214
5917
  function thesisGetResponse(response) {
5215
5918
  const base = thesisResponse(response);
5216
5919
  if (!isRecord2(response) || !isRecord2(response.author)) {
5217
- throw invalidResponse3("response must contain author");
5920
+ throw invalidResponse4("response must contain author");
5218
5921
  }
5219
5922
  const authorRecord = response.author;
5220
5923
  const author = {
@@ -5228,14 +5931,14 @@ function thesisGetResponse(response) {
5228
5931
  username: responseText(authorRecord.username, "author.username")
5229
5932
  };
5230
5933
  if (!Array.isArray(response.entities)) {
5231
- throw invalidResponse3("response must contain entities");
5934
+ throw invalidResponse4("response must contain entities");
5232
5935
  }
5233
5936
  if (response.entities.length !== base.thesis.entity_ids.length) {
5234
- throw invalidResponse3("entities must match thesis.entity_ids");
5937
+ throw invalidResponse4("entities must match thesis.entity_ids");
5235
5938
  }
5236
5939
  const entities = response.entities.map((item, index) => {
5237
5940
  if (!isRecord2(item))
5238
- throw invalidResponse3(`entities[${index}] must be an object`);
5941
+ throw invalidResponse4(`entities[${index}] must be an object`);
5239
5942
  const entity = {
5240
5943
  id: responseID(item.id, `entities[${index}].id`),
5241
5944
  ticker: responseText(item.ticker, `entities[${index}].ticker`),
@@ -5244,7 +5947,7 @@ function thesisGetResponse(response) {
5244
5947
  kind: responseText(item.kind, `entities[${index}].kind`)
5245
5948
  };
5246
5949
  if (entity.id !== base.thesis.entity_ids[index]) {
5247
- throw invalidResponse3("entities must preserve thesis.entity_ids order");
5950
+ throw invalidResponse4("entities must preserve thesis.entity_ids order");
5248
5951
  }
5249
5952
  return entity;
5250
5953
  });
@@ -5252,7 +5955,7 @@ function thesisGetResponse(response) {
5252
5955
  }
5253
5956
  function thesisSignalsResponse(response, thesisID, first) {
5254
5957
  if (!isRecord2(response) || !isRecord2(response.research) || !Array.isArray(response.entries) || response.entries.length > first) {
5255
- throw invalidResponse3("invalid Signal history response");
5958
+ throw invalidResponse4("invalid Signal history response");
5256
5959
  }
5257
5960
  const research = response.research;
5258
5961
  const status = {
@@ -5278,13 +5981,13 @@ function thesisSignalsResponse(response, thesisID, first) {
5278
5981
  );
5279
5982
  const entries = response.entries.map((raw) => {
5280
5983
  if (!isRecord2(raw) || !isRecord2(raw.signal) || !isRecord2(raw.signal.source)) {
5281
- throw invalidResponse3("entry must include a Signal and source");
5984
+ throw invalidResponse4("entry must include a Signal and source");
5282
5985
  }
5283
5986
  const signal = raw.signal;
5284
5987
  const source = signal.source;
5285
5988
  const signalID = responseID(signal.thesis_id, "signal.thesis_id");
5286
5989
  if (signalID !== thesisID)
5287
- throw invalidResponse3("Signal belongs to another Thesis");
5990
+ throw invalidResponse4("Signal belongs to another Thesis");
5288
5991
  const cursor = responseNonemptyText(raw.cursor, "entry.cursor");
5289
5992
  const mappedSource = {
5290
5993
  title: responseText(source.title, "source.title")
@@ -5317,7 +6020,7 @@ function thesisSignalsResponse(response, thesisID, first) {
5317
6020
  };
5318
6021
  if (signal.evidence_excerpt !== void 0) {
5319
6022
  if (!isRecord2(signal.evidence_excerpt))
5320
- throw invalidResponse3("invalid evidence excerpt");
6023
+ throw invalidResponse4("invalid evidence excerpt");
5321
6024
  mappedSignal.evidence_excerpt = {
5322
6025
  text: responseNonemptyText(
5323
6026
  signal.evidence_excerpt.text,
@@ -5341,19 +6044,19 @@ function thesisSignalsResponse(response, thesisID, first) {
5341
6044
  });
5342
6045
  const nextCursor2 = responseText(response.next_cursor, "next_cursor");
5343
6046
  if (nextCursor2 && nextCursor2 !== entries[entries.length - 1]?.cursor) {
5344
- throw invalidResponse3("next_cursor must match the final entry");
6047
+ throw invalidResponse4("next_cursor must match the final entry");
5345
6048
  }
5346
6049
  return { research: status, entries, next_cursor: nextCursor2 };
5347
6050
  }
5348
6051
  function responseNonnegativeInteger(value, field) {
5349
6052
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
5350
- throw invalidResponse3(field + " must be a nonnegative safe integer");
6053
+ throw invalidResponse4(field + " must be a nonnegative safe integer");
5351
6054
  }
5352
6055
  return value;
5353
6056
  }
5354
6057
  function responseNonemptyText(value, field) {
5355
6058
  const valueText = responseText(value, field);
5356
- if (!valueText.trim()) throw invalidResponse3(field + " must be nonempty");
6059
+ if (!valueText.trim()) throw invalidResponse4(field + " must be nonempty");
5357
6060
  return valueText;
5358
6061
  }
5359
6062
  function requireRequestID(value) {
@@ -5444,20 +6147,20 @@ function requireText2(value, field) {
5444
6147
  }
5445
6148
  function responseID(value, field) {
5446
6149
  if (typeof value === "number") {
5447
- throw invalidResponse3(
6150
+ throw invalidResponse4(
5448
6151
  `${field} must be a decimal string; numeric IDs are unsafe`
5449
6152
  );
5450
6153
  }
5451
6154
  try {
5452
6155
  return requireID(value, field);
5453
6156
  } catch {
5454
- throw invalidResponse3(`${field} must be a positive int64 decimal string`);
6157
+ throw invalidResponse4(`${field} must be a positive int64 decimal string`);
5455
6158
  }
5456
6159
  }
5457
6160
  function responseIDs(value, field) {
5458
- if (!Array.isArray(value)) throw invalidResponse3(`${field} must be an array`);
6161
+ if (!Array.isArray(value)) throw invalidResponse4(`${field} must be an array`);
5459
6162
  if (value.length > MAX_ENTITY_IDS) {
5460
- throw invalidResponse3(
6163
+ throw invalidResponse4(
5461
6164
  `${field} must contain at most ${MAX_ENTITY_IDS} IDs`
5462
6165
  );
5463
6166
  }
@@ -5467,33 +6170,33 @@ function responseText(value, field) {
5467
6170
  try {
5468
6171
  return requireText2(value, field);
5469
6172
  } catch {
5470
- throw invalidResponse3(`${field} must be valid text`);
6173
+ throw invalidResponse4(`${field} must be valid text`);
5471
6174
  }
5472
6175
  }
5473
6176
  function responseClosingNote(value) {
5474
6177
  try {
5475
6178
  return requireText2(value, "note");
5476
6179
  } catch {
5477
- throw invalidResponse3("thesis.closing_note must be valid text");
6180
+ throw invalidResponse4("thesis.closing_note must be valid text");
5478
6181
  }
5479
6182
  }
5480
6183
  function responseBoolean(value, field) {
5481
6184
  if (typeof value !== "boolean")
5482
- throw invalidResponse3(`${field} must be boolean`);
6185
+ throw invalidResponse4(`${field} must be boolean`);
5483
6186
  return value;
5484
6187
  }
5485
6188
  function responseVisibility(value) {
5486
6189
  try {
5487
6190
  return requireVisibility(value);
5488
6191
  } catch {
5489
- throw invalidResponse3("thesis.visibility must be public, private or paid");
6192
+ throw invalidResponse4("thesis.visibility must be public, private or paid");
5490
6193
  }
5491
6194
  }
5492
6195
  function responseBody(value) {
5493
6196
  try {
5494
6197
  return requireBody(value);
5495
6198
  } catch {
5496
- throw invalidResponse3(
6199
+ throw invalidResponse4(
5497
6200
  "response body must be nonblank valid text at most 65536 UTF-8 bytes"
5498
6201
  );
5499
6202
  }
@@ -5502,7 +6205,7 @@ function responseTitle(value) {
5502
6205
  try {
5503
6206
  return requireTitle(value);
5504
6207
  } catch {
5505
- throw invalidResponse3(
6208
+ throw invalidResponse4(
5506
6209
  "response title must be valid text at most 500 UTF-8 bytes"
5507
6210
  );
5508
6211
  }
@@ -5522,7 +6225,7 @@ function completeEntityStances(entityIDs, stances) {
5522
6225
  function invalidArgument(message) {
5523
6226
  return new AlvaError("INVALID_ARGUMENT", message, 400);
5524
6227
  }
5525
- function invalidResponse3(message) {
6228
+ function invalidResponse4(message) {
5526
6229
  return new AlvaError("INVALID_RESPONSE", message, 502);
5527
6230
  }
5528
6231
  function validMedia(item) {
@@ -5543,10 +6246,10 @@ async function thesisGraphql(client, query, variables) {
5543
6246
  body: { query, variables }
5544
6247
  });
5545
6248
  if (!isRecord2(response))
5546
- throw invalidResponse3("GraphQL response must be an object");
6249
+ throw invalidResponse4("GraphQL response must be an object");
5547
6250
  if (response.errors !== void 0) {
5548
6251
  if (!Array.isArray(response.errors))
5549
- throw invalidResponse3("GraphQL errors must be an array");
6252
+ throw invalidResponse4("GraphQL errors must be an array");
5550
6253
  if (response.errors.length > 0) {
5551
6254
  const messages = response.errors.flatMap(
5552
6255
  (error) => isRecord2(error) && typeof error.message === "string" ? [error.message] : []
@@ -5568,7 +6271,7 @@ async function thesisGraphql(client, query, variables) {
5568
6271
  }
5569
6272
  }
5570
6273
  if (!isRecord2(response.data))
5571
- throw invalidResponse3("GraphQL response must contain data");
6274
+ throw invalidResponse4("GraphQL response must contain data");
5572
6275
  return response.data;
5573
6276
  }
5574
6277
 
@@ -5578,7 +6281,7 @@ var CREATE_COMPANY_NEWS = `mutation CreateCompanyNews($input: CompanyNewsFeedInp
5578
6281
  createFeed(input: $input) { id producer { id } }
5579
6282
  }
5580
6283
  }`;
5581
- var GRAPHQL_STATUS_BY_CODE4 = {
6284
+ var GRAPHQL_STATUS_BY_CODE5 = {
5582
6285
  INVALID_ARGUMENT: 400,
5583
6286
  UNAUTHENTICATED: 401,
5584
6287
  PERMISSION_DENIED: 403,
@@ -5647,7 +6350,7 @@ var CompanyNewsResource = class {
5647
6350
  throw new AlvaError(
5648
6351
  code,
5649
6352
  graph.errors.map((error) => error?.message).filter(Boolean).join("; ") || "Company News creation failed",
5650
- GRAPHQL_STATUS_BY_CODE4[code] ?? 502,
6353
+ GRAPHQL_STATUS_BY_CODE5[code] ?? 502,
5651
6354
  { errors: graph.errors }
5652
6355
  );
5653
6356
  }
@@ -5773,6 +6476,7 @@ var AlvaClient = class {
5773
6476
  _notifications;
5774
6477
  _notificationPreferences;
5775
6478
  _subscriptions;
6479
+ _follows;
5776
6480
  _alerts;
5777
6481
  _channelGroupSubscriptions;
5778
6482
  _feedback;
@@ -5864,6 +6568,9 @@ var AlvaClient = class {
5864
6568
  get subscriptions() {
5865
6569
  return this._subscriptions ??= new SubscriptionsResource(this);
5866
6570
  }
6571
+ get follows() {
6572
+ return this._follows ??= new FollowsResource(this);
6573
+ }
5867
6574
  get alerts() {
5868
6575
  return this._alerts ??= new AlertsResource(this);
5869
6576
  }
@@ -6053,7 +6760,8 @@ var AlvaClient = class {
6053
6760
  throw new AlvaError(
6054
6761
  data.error.code ?? "UNKNOWN",
6055
6762
  data.error.message ?? `HTTP ${response.status}`,
6056
- response.status
6763
+ response.status,
6764
+ data.details
6057
6765
  );
6058
6766
  }
6059
6767
  } catch (e) {
@@ -6183,14 +6891,16 @@ var stripPbsvFromUrl = (targetWindow) => {
6183
6891
  };
6184
6892
  var parseBootParams = (targetWindow) => {
6185
6893
  const params = new URLSearchParams(targetWindow.location.search);
6186
- cachedToken = params.get("_pbsv");
6894
+ const boot = targetWindow;
6895
+ cachedToken = boot.__ALVA_PBSV_BOOTSTRAP__ || null;
6896
+ delete boot.__ALVA_PBSV_BOOTSTRAP__;
6897
+ if (params.has("_pbsv")) stripPbsvFromUrl(targetWindow);
6187
6898
  expectedParentOrigin = params.get("parent_origin");
6188
6899
  apiOrigin = (params.get("api_origin") || DEFAULT_API_ORIGIN).replace(
6189
6900
  /\/$/,
6190
6901
  ""
6191
6902
  );
6192
6903
  playbookIdFromBoot = playbookIdFromToken(cachedToken);
6193
- if (cachedToken) stripPbsvFromUrl(targetWindow);
6194
6904
  };
6195
6905
  var safeJson = async (response) => {
6196
6906
  try {
@@ -6516,7 +7226,7 @@ var installPlaybookRuntime = (targetWindow) => {
6516
7226
  };
6517
7227
 
6518
7228
  // src/index.ts
6519
- var VERSION = true ? "0.34.0" : "dev";
7229
+ var VERSION = true ? "0.36.0-beta.0" : "dev";
6520
7230
  // Annotate the CommonJS export names for ESM import in node:
6521
7231
  0 && (module.exports = {
6522
7232
  AlertsResource,
@@ -6526,6 +7236,7 @@ var VERSION = true ? "0.34.0" : "dev";
6526
7236
  AutomationResource,
6527
7237
  CliUsageError,
6528
7238
  CompanyNewsResource,
7239
+ FollowsResource,
6529
7240
  ForYouResource,
6530
7241
  MarketsResource,
6531
7242
  PBSV_UPDATE_MESSAGE,