@usesocial/cli 0.19.6 → 0.19.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @usesocial/cli
2
2
 
3
+ ## 0.19.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#149](https://github.com/usesocial/monorepo/pull/149) [`23797dd`](https://github.com/usesocial/monorepo/commit/23797dd3f65fd1b0012fb3f92bf997696231b148) Thanks [@CyrusNuevoDia](https://github.com/CyrusNuevoDia)! - Add privacy-safe sync failure correlation fields to CLI exception telemetry.
8
+
3
9
  ## 0.19.6
4
10
 
5
11
  ### Patch Changes
package/dist/index.mjs CHANGED
@@ -648,6 +648,12 @@ var CancelledError = class extends Error {
648
648
  };
649
649
  /** True for any of the typed errors above (single-instance instanceof is safe within this package graph). */
650
650
  const isTypedCLIError = (error) => error instanceof UsageError || error instanceof AuthError || error instanceof NotFoundError || error instanceof CancelledError;
651
+ //#endregion
652
+ //#region ../../packages/billing/src/constants.ts
653
+ const partnerUserPlanId = (partnerSlug) => `social_linkedin_${partnerSlug}`;
654
+ const partnerBillingPlanId = (partnerSlug) => `partner_${partnerSlug}`;
655
+ partnerUserPlanId("slashy");
656
+ partnerBillingPlanId("slashy");
651
657
  const MARKUP_BPS = 5e3;
652
658
  //#endregion
653
659
  //#region ../../packages/billing/src/markup.ts
@@ -11188,9 +11194,11 @@ const CLI_CAPABILITIES = [
11188
11194
  "social:read",
11189
11195
  "x:read",
11190
11196
  "linkedin:read",
11197
+ "partner:read",
11191
11198
  "social:write",
11192
11199
  "x:write",
11193
- "linkedin:write"
11200
+ "linkedin:write",
11201
+ "partner:write"
11194
11202
  ];
11195
11203
  const FEEDBACK_TYPES = ["bug", "feature"];
11196
11204
  const WRAPPED_STATUSES = [
@@ -11398,9 +11406,53 @@ const timestamptz = (name) => timestamp(name, {
11398
11406
  withTimezone: true,
11399
11407
  mode: "date"
11400
11408
  });
11409
+ const partners = pgTable("partners", {
11410
+ id: text$1("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
11411
+ slug: text$1("slug").notNull(),
11412
+ displayName: text$1("display_name").notNull(),
11413
+ callbackURL: text$1("callback_url").notNull(),
11414
+ authDomain: text$1("auth_domain").notNull(),
11415
+ apiKeyPrefix: text$1("api_key_prefix").notNull(),
11416
+ apiKeyHash: text$1("api_key_hash").notNull(),
11417
+ disabledAt: timestamptz("disabled_at"),
11418
+ createdAt: timestamptz("created_at").notNull().defaultNow(),
11419
+ updatedAt: timestamptz("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
11420
+ }, (table) => [
11421
+ uniqueIndex("partners_slug_key").on(table.slug),
11422
+ uniqueIndex("partners_api_key_prefix_key").on(table.apiKeyPrefix),
11423
+ check("partners_slug_check", sql`${table.slug} ~ '^[a-z0-9]+(?:-[a-z0-9]+)*$'`),
11424
+ check("partners_display_name_nonempty_check", sql`length(${table.displayName}) > 0`),
11425
+ check("partners_callback_url_https_check", sql`${table.callbackURL} ~ '^https://[^[:space:]]+$'`),
11426
+ check("partners_auth_domain_hostname_check", sql`${table.authDomain} ~ '^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$'`),
11427
+ check("partners_api_key_prefix_nonempty_check", sql`length(${table.apiKeyPrefix}) > 0`),
11428
+ check("partners_api_key_hash_check", sql`${table.apiKeyHash} ~ '^[0-9a-f]{64}$'`)
11429
+ ]);
11430
+ const partnerUsers = pgTable("partner_users", {
11431
+ partnerId: text$1("partner_id").notNull().references(() => partners.id),
11432
+ externalUserId: text$1("external_user_id").notNull(),
11433
+ userId: text$1("user_id").notNull().references(() => user.id),
11434
+ activeSessionId: text$1("active_session_id").references(() => session.id, { onDelete: "set null" }),
11435
+ canceledAt: timestamptz("canceled_at"),
11436
+ upstreamDeletedAt: timestamptz("upstream_deleted_at"),
11437
+ entitlementCanceledAt: timestamptz("entitlement_canceled_at"),
11438
+ createdAt: timestamptz("created_at").notNull().defaultNow(),
11439
+ updatedAt: timestamptz("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
11440
+ }, (table) => [
11441
+ primaryKey({
11442
+ name: "partner_users_pkey",
11443
+ columns: [table.partnerId, table.externalUserId]
11444
+ }),
11445
+ uniqueIndex("partner_users_user_id_key").on(table.userId),
11446
+ uniqueIndex("partner_users_partner_user_id_key").on(table.partnerId, table.userId),
11447
+ uniqueIndex("partner_users_active_session_id_key").on(table.activeSessionId).where(sql`${table.activeSessionId} is not null`),
11448
+ check("partner_users_external_user_id_nonempty_check", sql`length(${table.externalUserId}) > 0`),
11449
+ check("partner_users_cleanup_requires_cancellation_check", sql`(${table.upstreamDeletedAt} is null and ${table.entitlementCanceledAt} is null) or ${table.canceledAt} is not null`),
11450
+ check("partner_users_canceled_session_check", sql`${table.canceledAt} is null or ${table.activeSessionId} is null`)
11451
+ ]);
11401
11452
  const connectedAccounts = pgTable("connected_accounts", {
11402
11453
  id: text$1("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
11403
11454
  userId: text$1("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
11455
+ partnerId: text$1("partner_id"),
11404
11456
  platform: text$1("platform", { enum: PLATFORMS }).notNull(),
11405
11457
  platformAccountId: text$1("platform_account_id"),
11406
11458
  platformProfileId: text$1("platform_profile_id"),
@@ -11420,18 +11472,44 @@ const connectedAccounts = pgTable("connected_accounts", {
11420
11472
  createdAt: timestamptz("created_at").notNull().defaultNow(),
11421
11473
  updatedAt: timestamptz("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
11422
11474
  }, (table) => [
11423
- uniqueIndex("connected_accounts_platform_account_pkey").on(table.platform, table.platformAccountId),
11424
- uniqueIndex("connected_accounts_platform_profile_pkey").on(table.platform, table.platformProfileId).where(sql`${table.platformProfileId} is not null`),
11475
+ uniqueIndex("connected_accounts_direct_platform_account_key").on(table.platform, table.platformAccountId).where(sql`${table.partnerId} is null`),
11476
+ uniqueIndex("connected_accounts_partner_platform_account_key").on(table.partnerId, table.platform, table.platformAccountId).where(sql`${table.partnerId} is not null`),
11477
+ uniqueIndex("connected_accounts_direct_platform_profile_key").on(table.platform, table.platformProfileId).where(sql`${table.partnerId} is null and ${table.platformProfileId} is not null`),
11478
+ uniqueIndex("connected_accounts_partner_platform_profile_key").on(table.partnerId, table.platform, table.platformProfileId).where(sql`${table.partnerId} is not null and ${table.platformProfileId} is not null`),
11425
11479
  uniqueIndex("connected_accounts_user_platform_pkey").on(table.userId, table.platform, table.platformAccountId),
11426
11480
  uniqueIndex("connected_accounts_user_platform_id_key").on(table.userId, table.platform, table.id),
11427
11481
  index("connected_accounts_user_platform_idx").on(table.userId, table.platform).where(sql`${table.status} = 'connected'`),
11428
11482
  index("connected_accounts_user_username_idx").on(table.userId, table.platform, table.username),
11429
- uniqueIndex("connected_accounts_active_partial_user_platform_key").on(table.userId, table.platform).where(sql`${table.status} in ('pending_billing', 'pending_approval')`),
11483
+ uniqueIndex("connected_accounts_direct_active_partial_user_platform_key").on(table.userId, table.platform).where(sql`${table.partnerId} is null and ${table.status} in ('pending_billing', 'pending_approval')`),
11484
+ uniqueIndex("connected_accounts_partner_user_platform_key").on(table.userId, table.platform).where(sql`${table.partnerId} is not null`),
11430
11485
  index("connected_accounts_partial_expiry_idx").on(table.connectExpiresAt).where(sql`${table.status} in ('pending_billing', 'pending_approval')`),
11431
11486
  index("connected_accounts_terminal_updated_idx").on(table.updatedAt).where(sql`${table.status} in ('failed', 'expired')`),
11432
11487
  check("connected_accounts_platform_check", sqlCheckIn(table.platform, PLATFORMS)),
11433
11488
  check("connected_accounts_status_check", sqlCheckIn(table.status, CONNECTED_ACCOUNT_STATUSES)),
11434
- check("connected_accounts_materialized_fields_check", sql`${table.status} in ('pending_billing', 'pending_approval', 'failed', 'expired') or (${table.platformAccountId} is not null and ${table.platformProfileId} is not null and ${table.username} is not null and ${table.displayName} is not null and ${table.connectedAt} is not null and ${table.lastSeenAt} is not null)`)
11489
+ check("connected_accounts_partner_platform_check", sql`${table.partnerId} is null or ${table.platform} = 'linkedin'`),
11490
+ check("connected_accounts_materialized_fields_check", sql`${table.status} in ('pending_billing', 'pending_approval', 'failed', 'expired') or (${table.platformAccountId} is not null and ${table.platformProfileId} is not null and ${table.username} is not null and ${table.displayName} is not null and ${table.connectedAt} is not null and ${table.lastSeenAt} is not null)`),
11491
+ foreignKey({
11492
+ name: "connected_accounts_partner_user_fk",
11493
+ columns: [table.partnerId, table.userId],
11494
+ foreignColumns: [partnerUsers.partnerId, partnerUsers.userId]
11495
+ })
11496
+ ]);
11497
+ pgTable("partner_billable_account_periods", {
11498
+ id: text$1("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
11499
+ partnerId: text$1("partner_id").notNull(),
11500
+ userId: text$1("user_id").notNull(),
11501
+ platformAccountId: text$1("platform_account_id").notNull(),
11502
+ periodStart: timestamptz("period_start").notNull(),
11503
+ firstObservedAt: timestamptz("first_observed_at").notNull(),
11504
+ autumnTrackedAt: timestamptz("autumn_tracked_at")
11505
+ }, (table) => [
11506
+ uniqueIndex("partner_billable_account_periods_account_period_key").on(table.partnerId, table.platformAccountId, table.periodStart),
11507
+ index("partner_billable_account_periods_untracked_idx").on(table.firstObservedAt, table.id).where(sql`${table.autumnTrackedAt} is null`),
11508
+ foreignKey({
11509
+ name: "partner_billable_account_periods_partner_user_fk",
11510
+ columns: [table.partnerId, table.userId],
11511
+ foreignColumns: [partnerUsers.partnerId, partnerUsers.userId]
11512
+ })
11435
11513
  ]);
11436
11514
  pgTable("account_defaults", {
11437
11515
  userId: text$1("user_id").notNull(),
@@ -14988,6 +15066,50 @@ const schemas$1 = {
14988
15066
  var UnexpectedLinkedinResponseError = class extends Error {
14989
15067
  name = "UnexpectedLinkedinResponseError";
14990
15068
  };
15069
+ const linkedinInboxRecordsFrom = (data) => {
15070
+ if (Array.isArray(data)) return data.filter((item) => typeof item === "object" && item !== null && !Array.isArray(item));
15071
+ if (typeof data !== "object" || data === null || Array.isArray(data)) return [];
15072
+ const record = data;
15073
+ for (const key of [
15074
+ "data",
15075
+ "items",
15076
+ "inboxes"
15077
+ ]) {
15078
+ const value = record[key];
15079
+ if (Array.isArray(value)) return value.filter((item) => typeof item === "object" && item !== null && !Array.isArray(item));
15080
+ }
15081
+ return [];
15082
+ };
15083
+ const linkedinInboxString = (inbox, keys) => {
15084
+ for (const key of keys) {
15085
+ const value = inbox[key];
15086
+ if (typeof value === "string" && value.length > 0) return value;
15087
+ }
15088
+ };
15089
+ const linkedinInboxText = (inbox) => [linkedinInboxString(inbox, ["id", "inbox_id"]), linkedinInboxString(inbox, [
15090
+ "provider",
15091
+ "provider_id",
15092
+ "type",
15093
+ "inbox_type",
15094
+ "name",
15095
+ "label"
15096
+ ])].filter(Boolean).join(" ").toLowerCase();
15097
+ const classicLinkedinInboxIdFrom = (data) => {
15098
+ const withIds = linkedinInboxRecordsFrom(data).map((inbox) => ({
15099
+ id: linkedinInboxString(inbox, ["id", "inbox_id"]),
15100
+ inbox
15101
+ })).filter((item) => Boolean(item.id));
15102
+ const exact = withIds.find(({ id }) => id === "CLASSIC_PRIMARY");
15103
+ if (exact) return exact.id;
15104
+ const classic = withIds.find(({ inbox }) => {
15105
+ const text = linkedinInboxText(inbox);
15106
+ return text.includes("linkedin_classic") || text.includes("classic");
15107
+ });
15108
+ if (classic) return classic.id;
15109
+ const primary = withIds.find(({ inbox }) => linkedinInboxText(inbox).includes("primary"));
15110
+ if (primary) return primary.id;
15111
+ return withIds.length === 1 ? withIds[0]?.id : void 0;
15112
+ };
14991
15113
  const commandMeta$2 = (meta) => commandMeta$3(meta);
14992
15114
  const schema$1 = (name) => {
14993
15115
  const resolved = schemas$1[name];
@@ -15510,57 +15632,12 @@ const requireAccountSelector$1 = (selector) => {
15510
15632
  return selector;
15511
15633
  };
15512
15634
  const linkedinClassicInboxIdCache = /* @__PURE__ */ new WeakMap();
15513
- const inboxRecordsFrom = (data) => {
15514
- if (Array.isArray(data)) return data.filter((item) => Boolean(item && typeof item === "object" && !Array.isArray(item)));
15515
- const record = dataRecordFrom$1(data);
15516
- if (!record) return [];
15517
- for (const key of [
15518
- "data",
15519
- "items",
15520
- "inboxes"
15521
- ]) {
15522
- const value = record[key];
15523
- if (Array.isArray(value)) return value.filter((item) => Boolean(item && typeof item === "object" && !Array.isArray(item)));
15524
- }
15525
- return [];
15526
- };
15527
- const inboxString = (inbox, keys) => {
15528
- for (const key of keys) {
15529
- const value = inbox[key];
15530
- if (typeof value === "string" && value.length > 0) return value;
15531
- }
15532
- };
15533
- const inboxText = (inbox) => [inboxString(inbox, ["id", "inbox_id"]), inboxString(inbox, [
15534
- "provider",
15535
- "provider_id",
15536
- "type",
15537
- "inbox_type",
15538
- "name",
15539
- "label"
15540
- ])].filter(Boolean).join(" ").toLowerCase();
15541
- const classicInboxIdFrom = (data) => {
15542
- const withIds = inboxRecordsFrom(data).map((inbox) => ({
15543
- id: inboxString(inbox, ["id", "inbox_id"]),
15544
- inbox
15545
- })).filter((item) => Boolean(item.id));
15546
- const exact = withIds.find(({ id }) => id === "CLASSIC_PRIMARY");
15547
- if (exact) return exact.id;
15548
- const classic = withIds.find(({ inbox }) => {
15549
- const text = inboxText(inbox);
15550
- return text.includes("linkedin_classic") || text.includes("classic");
15551
- });
15552
- if (classic) return classic.id;
15553
- const primary = withIds.find(({ inbox }) => inboxText(inbox).includes("primary"));
15554
- if (primary) return primary.id;
15555
- return withIds.length === 1 ? withIds[0]?.id : void 0;
15556
- };
15557
15635
  const linkedinClassicInboxId = async (args) => {
15558
15636
  const cache = linkedinClassicInboxIdCache.get(args.api) ?? /* @__PURE__ */ new Map();
15559
15637
  linkedinClassicInboxIdCache.set(args.api, cache);
15560
15638
  const cached = cache.get(args.cacheKey);
15561
15639
  if (cached) return cached;
15562
- const response = await args.api.get("linkedin/inboxes", { headers: args.headers });
15563
- const inboxId = classicInboxIdFrom(await response.json());
15640
+ const inboxId = classicLinkedinInboxIdFrom(await (await args.api.get("linkedin/inboxes", { headers: args.headers })).json());
15564
15641
  if (!inboxId) throw new UsageError("Could not find a LinkedIn classic inbox for this account.");
15565
15642
  cache.set(args.cacheKey, inboxId);
15566
15643
  return inboxId;
@@ -24581,7 +24658,7 @@ function createEnv(opts) {
24581
24658
  }
24582
24659
  //#endregion
24583
24660
  //#region package.json
24584
- var version$1 = "0.19.6";
24661
+ var version$1 = "0.19.7";
24585
24662
  //#endregion
24586
24663
  //#region src/lib/env.ts
24587
24664
  const URLWithTrailingSlash = url().transform(ensureTrailingSlash);
@@ -31275,6 +31352,45 @@ const recordValue = (value) => value && typeof value === "object" ? value : void
31275
31352
  const stringProperty = (value) => typeof value === "string" ? value : void 0;
31276
31353
  const numberProperty = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
31277
31354
  const causeOf = (value) => recordValue(value)?.cause;
31355
+ const SYNC_REQUEST_PATHS = {
31356
+ li_connections: /* @__PURE__ */ new Set(["/users/connections"]),
31357
+ li_conversations: /* @__PURE__ */ new Set(["/chats"]),
31358
+ li_messages: /* @__PURE__ */ new Set(["/chats/:chat_id/messages"]),
31359
+ li_posts: /* @__PURE__ */ new Set(["/users/:identifier/posts"]),
31360
+ li_requests: /* @__PURE__ */ new Set(["/users/me/relation-requests/received", "/users/me/relation-requests/sent"]),
31361
+ x_bookmarks: /* @__PURE__ */ new Set(["/users/:id/bookmarks"]),
31362
+ x_followers: /* @__PURE__ */ new Set(["/users/:id/followers"]),
31363
+ x_following: /* @__PURE__ */ new Set(["/users/:id/following"]),
31364
+ x_liked: /* @__PURE__ */ new Set(["/users/:id/liked_tweets"]),
31365
+ x_mentions: /* @__PURE__ */ new Set(["/users/:id/mentions"]),
31366
+ x_messages: /* @__PURE__ */ new Set(["/dm_events"]),
31367
+ x_timeline: /* @__PURE__ */ new Set(["/users/:id/timelines/reverse_chronological"]),
31368
+ x_tweets: /* @__PURE__ */ new Set(["/users/:id/tweets"])
31369
+ };
31370
+ const syncPlatformForCommand = (command) => {
31371
+ if (command === "linkedin" || command?.startsWith("linkedin ")) return "linkedin";
31372
+ if (command === "x" || command?.startsWith("x ")) return "x";
31373
+ };
31374
+ const syncCollection = (value, platform) => {
31375
+ if (!(platform && typeof value === "string" && value in SYNC_REQUEST_PATHS)) return;
31376
+ if (platform === "linkedin" ? value.startsWith("li_") : value.startsWith("x_")) return value;
31377
+ };
31378
+ const syncFailureProperties = (error, command) => {
31379
+ const errorRecord = recordValue(error);
31380
+ if (!(errorRecord?.name === "SyncPageError" && errorRecord._tag === "SyncPageError")) return {};
31381
+ const platform = syncPlatformForCommand(command);
31382
+ const collection = syncCollection(errorRecord.collectionKey, platform);
31383
+ const requestPath = collection && typeof errorRecord.requestPath === "string" && errorRecord.requestPath.startsWith("/") && !errorRecord.requestPath.includes("?") && !errorRecord.requestPath.includes("#") && SYNC_REQUEST_PATHS[collection].has(errorRecord.requestPath) ? errorRecord.requestPath : void 0;
31384
+ const pagesCompleted = Number.isSafeInteger(errorRecord.pagesCompleted) && errorRecord.pagesCompleted >= 0 ? errorRecord.pagesCompleted : void 0;
31385
+ const cursorPersisted = typeof errorRecord.cursorPersisted === "boolean" ? errorRecord.cursorPersisted : void 0;
31386
+ return withoutUndefined({
31387
+ sync_platform: platform,
31388
+ sync_collection: collection,
31389
+ sync_request_path: requestPath,
31390
+ sync_pages_completed: pagesCompleted,
31391
+ sync_cursor_persisted: cursorPersisted
31392
+ });
31393
+ };
31278
31394
  const causeProperties = (error) => {
31279
31395
  const causeNames = [];
31280
31396
  const causeCodes = [];
@@ -31317,6 +31433,7 @@ const buildFailureProperties = (error, ctx) => {
31317
31433
  retry_after_seconds: error instanceof CLIAPIError ? error.retryAfterSeconds : void 0,
31318
31434
  retry_count: error instanceof CLIAPIError ? error.retryCount : void 0,
31319
31435
  retry_budget_exhausted: error instanceof CLIAPIError ? error.retryBudgetExhausted : void 0,
31436
+ ...syncFailureProperties(error, ctx.command),
31320
31437
  ...causeProperties(error),
31321
31438
  top_frame: topFrame
31322
31439
  });