@usesocial/cli 0.19.4 → 0.19.5

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.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#145](https://github.com/usesocial/monorepo/pull/145) [`53da7fa`](https://github.com/usesocial/monorepo/commit/53da7fae95987f30845666f836cb82f5f7c8a309) Thanks [@CyrusNuevoDia](https://github.com/CyrusNuevoDia)! - Replace `--attempt` with `--account-id` for resumable LinkedIn and X connections.
8
+
3
9
  ## 0.19.4
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -159,8 +159,8 @@ profile lookup is needed.
159
159
  | `(bare)` | Show who is signed in and list connected accounts. | |
160
160
  | `login` | Device sign-in and scope selection. | |
161
161
  | `logout` | Revoke the session and clear the saved token. | |
162
- | `connect linkedin [--attempt <id>]` | Start a LinkedIn billing-and-connect attempt, or resume the exact returned attempt. | write |
163
- | `connect x [--attempt <id>]` | Start an X billing-and-connect attempt, or resume the exact returned attempt. | write |
162
+ | `connect linkedin [--account-id <id>]` | Start a LinkedIn connection, or resume the exact returned account. | write |
163
+ | `connect x [--account-id <id>]` | Start an X connection, or resume the exact returned account. | write |
164
164
  | `reconnect linkedin <account>` | Re-auth an existing LinkedIn account. | write |
165
165
  | `reconnect x <account>` | Re-auth an existing X account. | write |
166
166
  | `disconnect linkedin <account>` | Disconnect a LinkedIn account. | write |
@@ -282,15 +282,15 @@ session and removes the stored token. Non-interactive callers should surface the
282
282
  returned approval or checkout URL, then rerun `social account setup` until it is
283
283
  `ready`.
284
284
 
285
- `social account connect <platform>` starts or resumes a server-owned attempt
286
- that purchases only that provider's plan or next seat, or the applicable legacy
287
- Social Pro seat during transition. It normally charges the stored card directly
288
- before returning hosted provider approval. In a non-TTY
289
- shell, omit `--attempt` on the first call, capture the returned `attemptId`, and
290
- pass it back as `--attempt <attemptId>` on every poll. Surface `paymentURL` only
291
- when `pending_billing` says customer action is required, then surface
292
- `connectURL` for provider approval. Replaying a completed attempt is stable;
293
- omit `--attempt` after completion only to connect another account.
285
+ `social account connect <platform>` starts or resumes a server-owned partial
286
+ account that purchases only that provider's plan or next seat, or the applicable
287
+ legacy Social Pro seat during transition. It normally charges the stored card
288
+ directly before returning hosted provider approval. In a non-TTY shell, omit
289
+ `--account-id` on the first call, capture the returned `accountId`, and pass it
290
+ back as `--account-id <accountId>` on every poll. Surface `paymentURL` only when
291
+ `pending_billing` says customer action is required, then surface `connectURL`
292
+ for provider approval. Replaying a connected account ID is stable; omit
293
+ `--account-id` after completion only to connect another account.
294
294
 
295
295
  `social account billing` prints Social LinkedIn and Social X independently.
296
296
  Social LinkedIn costs $20 per connected account with flat proxy usage. Social X
package/dist/index.mjs CHANGED
@@ -11042,13 +11042,20 @@ function uniqueIndex(name) {
11042
11042
  //#endregion
11043
11043
  //#region ../../packages/db/src/domain.ts
11044
11044
  const PLATFORMS = ["linkedin", "x"];
11045
- const CONNECTED_ACCOUNT_STATUSES = [
11045
+ const MATERIALIZED_CONNECTED_ACCOUNT_STATUSES = [
11046
11046
  "connected",
11047
11047
  "credentials",
11048
11048
  "connecting",
11049
11049
  "disconnected",
11050
11050
  "error"
11051
11051
  ];
11052
+ const CONNECTED_ACCOUNT_STATUSES = [
11053
+ ...MATERIALIZED_CONNECTED_ACCOUNT_STATUSES,
11054
+ "pending_billing",
11055
+ "pending_approval",
11056
+ "failed",
11057
+ "expired"
11058
+ ];
11052
11059
  const ACCOUNT_CONNECT_ATTEMPT_LANES = ["provider", "legacy"];
11053
11060
  const ACCOUNT_CONNECT_ATTEMPT_STATUSES = [
11054
11061
  "pending_billing",
@@ -11118,6 +11125,7 @@ const WEBHOOK_OPERATION_STATES = [
11118
11125
  ];
11119
11126
  _enum(PLATFORMS);
11120
11127
  _enum(CONNECTED_ACCOUNT_STATUSES);
11128
+ _enum(MATERIALIZED_CONNECTED_ACCOUNT_STATUSES);
11121
11129
  _enum(ACCOUNT_CONNECT_ATTEMPT_LANES);
11122
11130
  _enum(ACCOUNT_CONNECT_ATTEMPT_STATUSES);
11123
11131
  _enum(PROXY_SURFACES);
@@ -11294,23 +11302,36 @@ const connectedAccounts = pgTable("connected_accounts", {
11294
11302
  id: text$1("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
11295
11303
  userId: text$1("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
11296
11304
  platform: text$1("platform", { enum: PLATFORMS }).notNull(),
11297
- platformAccountId: text$1("platform_account_id").notNull(),
11298
- platformProfileId: text$1("platform_profile_id").notNull(),
11299
- username: text$1("username").notNull(),
11300
- displayName: text$1("display_name").notNull(),
11305
+ platformAccountId: text$1("platform_account_id"),
11306
+ platformProfileId: text$1("platform_profile_id"),
11307
+ username: text$1("username"),
11308
+ displayName: text$1("display_name"),
11301
11309
  profileImageURL: text$1("profile_image_url"),
11302
11310
  status: text$1("status", { enum: CONNECTED_ACCOUNT_STATUSES }).notNull().default("connected"),
11303
11311
  platformData: jsonb("platform_data").$type().notNull().default(sql`'{}'::jsonb`),
11304
- connectedAt: timestamptz("connected_at").notNull().defaultNow(),
11305
- lastSeenAt: timestamptz("last_seen_at").notNull().defaultNow()
11312
+ connectExpiresAt: timestamptz("connect_expires_at"),
11313
+ connectURL: text$1("connect_url"),
11314
+ billingPaymentURL: text$1("billing_payment_url"),
11315
+ billingRequiredAction: jsonb("billing_required_action").$type(),
11316
+ failureCode: text$1("failure_code"),
11317
+ failureStage: text$1("failure_stage"),
11318
+ connectedAt: timestamptz("connected_at"),
11319
+ lastSeenAt: timestamptz("last_seen_at"),
11320
+ createdAt: timestamptz("created_at").notNull().defaultNow(),
11321
+ updatedAt: timestamptz("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
11306
11322
  }, (table) => [
11307
11323
  uniqueIndex("connected_accounts_platform_account_pkey").on(table.platform, table.platformAccountId),
11324
+ uniqueIndex("connected_accounts_platform_profile_pkey").on(table.platform, table.platformProfileId).where(sql`${table.platformProfileId} is not null`),
11308
11325
  uniqueIndex("connected_accounts_user_platform_pkey").on(table.userId, table.platform, table.platformAccountId),
11309
11326
  uniqueIndex("connected_accounts_user_platform_id_key").on(table.userId, table.platform, table.id),
11310
11327
  index("connected_accounts_user_platform_idx").on(table.userId, table.platform).where(sql`${table.status} = 'connected'`),
11311
11328
  index("connected_accounts_user_username_idx").on(table.userId, table.platform, table.username),
11329
+ uniqueIndex("connected_accounts_active_partial_user_platform_key").on(table.userId, table.platform).where(sql`${table.status} in ('pending_billing', 'pending_approval')`),
11330
+ index("connected_accounts_partial_expiry_idx").on(table.connectExpiresAt).where(sql`${table.status} in ('pending_billing', 'pending_approval')`),
11331
+ index("connected_accounts_terminal_updated_idx").on(table.updatedAt).where(sql`${table.status} in ('failed', 'expired')`),
11312
11332
  check("connected_accounts_platform_check", sqlCheckIn(table.platform, PLATFORMS)),
11313
- check("connected_accounts_status_check", sqlCheckIn(table.status, CONNECTED_ACCOUNT_STATUSES))
11333
+ check("connected_accounts_status_check", sqlCheckIn(table.status, CONNECTED_ACCOUNT_STATUSES)),
11334
+ 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)`)
11314
11335
  ]);
11315
11336
  pgTable("account_connect_attempts", {
11316
11337
  id: text$1("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
@@ -22836,18 +22857,18 @@ const resolveDisconnectTarget = async (deps, identifier) => {
22836
22857
  if (ae.isError(account)) throw account.error;
22837
22858
  return account.value;
22838
22859
  };
22839
- const connectLinkedinAccount = async (deps, attemptId) => {
22860
+ const connectLinkedinAccount = async (deps, accountId) => {
22840
22861
  const intervalMs = deps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
22841
22862
  const sleep = deps.sleep ?? setTimeout$1;
22842
22863
  const startedAt = Date.now();
22843
- let currentAttemptId = attemptId;
22864
+ let currentAccountId = accountId;
22844
22865
  const surfacedURLs = /* @__PURE__ */ new Set();
22845
22866
  while (Date.now() - startedAt < CONNECT_POLL_TIMEOUT_MS) {
22846
22867
  const state = await deps.client.connectStep({
22847
22868
  platform: LINKEDIN_PLATFORM,
22848
- ...currentAttemptId ? { attemptId: currentAttemptId } : {}
22869
+ ...currentAccountId ? { accountId: currentAccountId } : {}
22849
22870
  });
22850
- currentAttemptId = state.attemptId;
22871
+ currentAccountId = state.accountId;
22851
22872
  if (state.status === "connected") return {
22852
22873
  platform: LINKEDIN_PLATFORM,
22853
22874
  status: "connected",
@@ -23013,18 +23034,18 @@ const listXLifecycleAccounts = async (deps, includeDisconnected) => ae.ok(await
23013
23034
  platform: "x",
23014
23035
  includeDisconnected
23015
23036
  }));
23016
- const connectXAccount = async (deps, attemptId) => {
23037
+ const connectXAccount = async (deps, accountId) => {
23017
23038
  const sleep = deps.sleep ?? defaultSleep;
23018
23039
  const now = deps.now ?? Date.now;
23019
23040
  const startedAt = now();
23020
- let currentAttemptId = attemptId;
23041
+ let currentAccountId = accountId;
23021
23042
  const surfacedURLs = /* @__PURE__ */ new Set();
23022
23043
  while (now() - startedAt < CONNECT_TIMEOUT_MS) {
23023
23044
  const state = await deps.client.connectStep({
23024
23045
  platform: "x",
23025
- ...currentAttemptId ? { attemptId: currentAttemptId } : {}
23046
+ ...currentAccountId ? { accountId: currentAccountId } : {}
23026
23047
  });
23027
- currentAttemptId = state.attemptId;
23048
+ currentAccountId = state.accountId;
23028
23049
  if (state.status === "connected") return ae.ok({
23029
23050
  platform: "x",
23030
23051
  status: "connected",
@@ -24489,7 +24510,7 @@ function createEnv(opts) {
24489
24510
  }
24490
24511
  //#endregion
24491
24512
  //#region package.json
24492
- var version$1 = "0.19.4";
24513
+ var version$1 = "0.19.5";
24493
24514
  //#endregion
24494
24515
  //#region src/lib/env.ts
24495
24516
  const URLWithTrailingSlash = url().transform(ensureTrailingSlash);
@@ -33661,13 +33682,13 @@ const AccountDefaultSetInput = AccountDefaultGetInput.extend({ account: string()
33661
33682
  const AccountConnectStateOutput = discriminatedUnion("status", [
33662
33683
  object({
33663
33684
  status: literal("connected"),
33664
- attemptId: uuid$1(),
33685
+ accountId: uuid$1(),
33665
33686
  platform: _enum(["linkedin", "x"]),
33666
33687
  account: LifecycleAccountOutput
33667
33688
  }),
33668
33689
  object({
33669
33690
  status: literal("pending_billing"),
33670
- attemptId: uuid$1(),
33691
+ accountId: uuid$1(),
33671
33692
  platform: _enum(["linkedin", "x"]),
33672
33693
  plan: object({
33673
33694
  id: string(),
@@ -33686,14 +33707,14 @@ const AccountConnectStateOutput = discriminatedUnion("status", [
33686
33707
  }),
33687
33708
  object({
33688
33709
  status: literal("pending_approval"),
33689
- attemptId: uuid$1(),
33710
+ accountId: uuid$1(),
33690
33711
  platform: _enum(["linkedin", "x"]),
33691
33712
  connectURL: string().nullable(),
33692
33713
  expiresAt: string()
33693
33714
  }),
33694
33715
  object({
33695
33716
  status: _enum(["expired", "failed"]),
33696
- attemptId: uuid$1(),
33717
+ accountId: uuid$1(),
33697
33718
  platform: _enum(["linkedin", "x"]),
33698
33719
  code: string(),
33699
33720
  retryable: boolean$1()
@@ -33788,12 +33809,12 @@ const lifecycleConnectContract = writeCLIContract({
33788
33809
  responseShaping: { supported: false },
33789
33810
  idempotency: {
33790
33811
  idempotent: false,
33791
- retrySafeWith: "attemptId"
33812
+ retrySafeWith: "accountId"
33792
33813
  },
33793
- idField: "attemptId",
33814
+ idField: "accountId",
33794
33815
  hazards: [{
33795
33816
  code: "account_connect_billing",
33796
- message: "The first call can start provider billing; pass the returned attemptId when polling so retries cannot start another charge."
33817
+ message: "The first call can start provider billing; pass the returned accountId when polling so retries cannot start another charge."
33797
33818
  }]
33798
33819
  });
33799
33820
  const usernameLabelFor = (account) => account.username.startsWith("@") ? account.username : `@${account.username}`;
@@ -33825,11 +33846,11 @@ const runConnectOutput = async (deps, connect) => {
33825
33846
  writeText(deps, `${usernameLabelFor(result.account)} connected!`);
33826
33847
  };
33827
33848
  const isInteractiveConnect = (deps) => deps.isInteractiveTerminal?.() === true;
33828
- /** One retry-safe connect step for a non-TTY caller; the JSON carries its next attempt ID. */
33829
- const runConnectStep = async (deps, platform, attemptId) => {
33849
+ /** One retry-safe connect step for a non-TTY caller; the JSON carries its account ID. */
33850
+ const runConnectStep = async (deps, platform, accountId) => {
33830
33851
  const state = await deps.client.connectStep({
33831
33852
  platform,
33832
- ...attemptId ? { attemptId } : {}
33853
+ ...accountId ? { accountId } : {}
33833
33854
  });
33834
33855
  await writeOutput(deps, state);
33835
33856
  };
@@ -33841,12 +33862,13 @@ const createConnectPlatformCommand = (platform, run) => defineCommand({
33841
33862
  contract: lifecycleConnectContract,
33842
33863
  mutates: true
33843
33864
  }),
33844
- args: { attempt: {
33865
+ args: { "account-id": {
33845
33866
  type: "string",
33846
- description: "Resume the exact connect attempt returned by a previous call."
33867
+ description: "Resume the exact connection returned by a previous call."
33847
33868
  } },
33848
- run: async ({ args }) => {
33849
- await run({ attempt: typeof args.attempt === "string" ? args.attempt : void 0 });
33869
+ run: async ({ args, rawArgs }) => {
33870
+ if (rawArgs?.includes("--attempt") || rawArgs?.some((arg) => arg.startsWith("--attempt="))) throw new UsageError("--attempt was removed; use --account-id.");
33871
+ await run({ accountId: typeof args["account-id"] === "string" ? args["account-id"] : void 0 });
33850
33872
  }
33851
33873
  });
33852
33874
  const createAccountPlatformCommand = (platform, description, run, options = {}) => defineCommand({
@@ -33932,23 +33954,23 @@ const createAccountCommand = (deps, accountSetupCommand = setupCommand) => {
33932
33954
  description: "Connect a LinkedIn or X account."
33933
33955
  },
33934
33956
  subCommands: {
33935
- linkedin: createConnectPlatformCommand("linkedin", async ({ attempt }) => {
33957
+ linkedin: createConnectPlatformCommand("linkedin", async ({ accountId }) => {
33936
33958
  if (isInteractiveConnect(deps)) {
33937
- await runConnectOutput(deps, (connectDeps) => connectLinkedinAccount(connectDeps, attempt));
33959
+ await runConnectOutput(deps, (connectDeps) => connectLinkedinAccount(connectDeps, accountId));
33938
33960
  return;
33939
33961
  }
33940
- await runConnectStep(deps, "linkedin", attempt);
33962
+ await runConnectStep(deps, "linkedin", accountId);
33941
33963
  }),
33942
- x: createConnectPlatformCommand("x", async ({ attempt }) => {
33964
+ x: createConnectPlatformCommand("x", async ({ accountId }) => {
33943
33965
  if (isInteractiveConnect(deps)) {
33944
33966
  await runConnectOutput(deps, async (connectDeps) => {
33945
- const result = await connectXAccount(connectDeps, attempt);
33967
+ const result = await connectXAccount(connectDeps, accountId);
33946
33968
  if (ae.isError(result)) throwXLifecycleError(result.error);
33947
33969
  return result.value;
33948
33970
  });
33949
33971
  return;
33950
33972
  }
33951
- await runConnectStep(deps, "x", attempt);
33973
+ await runConnectStep(deps, "x", accountId);
33952
33974
  })
33953
33975
  }
33954
33976
  });