@usesocial/cli 0.19.5 → 0.19.6

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.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#147](https://github.com/usesocial/monorepo/pull/147) [`df61320`](https://github.com/usesocial/monorepo/commit/df61320ec0e5d4eacc9eae02c843710be388d532) Thanks [@CyrusNuevoDia](https://github.com/CyrusNuevoDia)! - Advertise normalized X and LinkedIn result envelopes, simplify LinkedIn mirror views, and keep LinkedIn usage logs at zero cost.
8
+
3
9
  ## 0.19.5
4
10
 
5
11
  ### Patch Changes
package/dist/index.mjs CHANGED
@@ -1246,16 +1246,123 @@ const helpDescriptionFor = (adapter, op, context) => {
1246
1246
  };
1247
1247
  const buildRuntimeContract = (adapter, op, context) => {
1248
1248
  const hazard = adapter.hazardFor(op);
1249
+ const upstreamPagination = op.endpoint.pagination;
1250
+ const listOutput = upstreamPagination.style !== "none";
1251
+ const pagination = upstreamPagination.style === "none" ? upstreamPagination : upstreamPagination.style === "cursor" ? {
1252
+ style: "cursor",
1253
+ ...upstreamPagination.limitParam ? { limitParam: upstreamPagination.limitParam } : {},
1254
+ ...upstreamPagination.cursorParam ? { cursorParam: upstreamPagination.cursorParam } : {},
1255
+ cursorPath: "meta.cursor",
1256
+ itemsPath: "items",
1257
+ ..."totalCountPath" in upstreamPagination && upstreamPagination.totalCountPath ? { totalCountPath: "meta.totalCount" } : {}
1258
+ } : {
1259
+ style: "offset",
1260
+ ...upstreamPagination.limitParam ? { limitParam: upstreamPagination.limitParam } : {},
1261
+ offsetParam: upstreamPagination.offsetParam,
1262
+ itemsPath: "items",
1263
+ ...upstreamPagination.totalCountPath ? { totalCountPath: "meta.totalCount" } : {}
1264
+ };
1265
+ const outputSchema = {
1266
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1267
+ type: "object",
1268
+ properties: {
1269
+ account: {
1270
+ type: "object",
1271
+ properties: {
1272
+ platform: { type: "string" },
1273
+ username: { type: ["string", "null"] }
1274
+ },
1275
+ required: ["platform"],
1276
+ additionalProperties: false
1277
+ },
1278
+ ...listOutput ? { items: {
1279
+ type: "array",
1280
+ items: {}
1281
+ } } : { data: {
1282
+ type: "object",
1283
+ additionalProperties: true
1284
+ } },
1285
+ meta: {
1286
+ type: "object",
1287
+ properties: {
1288
+ resolved: {
1289
+ type: "array",
1290
+ items: {
1291
+ type: "object",
1292
+ properties: {
1293
+ input: { type: "string" },
1294
+ id: { type: "string" },
1295
+ url: { type: "string" },
1296
+ source: { type: "string" }
1297
+ },
1298
+ required: [
1299
+ "input",
1300
+ "id",
1301
+ "source"
1302
+ ],
1303
+ additionalProperties: true
1304
+ }
1305
+ },
1306
+ cost: {
1307
+ type: "number",
1308
+ minimum: 0
1309
+ },
1310
+ cache: {
1311
+ type: "object",
1312
+ properties: {
1313
+ hit: { type: "boolean" },
1314
+ status: { type: "string" },
1315
+ age_s: { type: ["number", "null"] },
1316
+ source: { type: "string" },
1317
+ tables: {
1318
+ type: "array",
1319
+ items: {
1320
+ type: "object",
1321
+ additionalProperties: true
1322
+ }
1323
+ },
1324
+ migration: {
1325
+ type: "object",
1326
+ additionalProperties: true
1327
+ }
1328
+ },
1329
+ required: ["hit"],
1330
+ additionalProperties: true
1331
+ },
1332
+ cursor: { type: "string" },
1333
+ totalCount: { type: "number" },
1334
+ errors: {
1335
+ type: "array",
1336
+ items: {}
1337
+ },
1338
+ includes: {
1339
+ type: "object",
1340
+ additionalProperties: true
1341
+ }
1342
+ },
1343
+ required: ["resolved", "cache"],
1344
+ additionalProperties: true
1345
+ }
1346
+ },
1347
+ required: [
1348
+ "account",
1349
+ listOutput ? "items" : "data",
1350
+ "meta"
1351
+ ],
1352
+ additionalProperties: false
1353
+ };
1249
1354
  return {
1250
1355
  inputSchema: adapter.schema(adapter.contractInputSchemaName(op)),
1251
- outputSchema: adapter.schema(`${op.schemaBaseName}Output`),
1356
+ outputSchema,
1357
+ upstreamOutputSchema: adapter.schema(`${op.schemaBaseName}Output`),
1252
1358
  auth: adapter.authFor(op),
1253
1359
  capability: op.endpoint.capability,
1254
1360
  mutates: op.endpoint.mutates,
1255
1361
  method: op.endpoint.method,
1256
1362
  idempotency: adapter.idempotencyFor(op),
1257
1363
  ...hazard ? { hazard } : {},
1258
- pagination: op.endpoint.pagination,
1364
+ pagination,
1365
+ upstreamPagination,
1259
1366
  responseShaping: adapter.responseShapingFor(op),
1260
1367
  ...adapter.includeIdField === true && op.config.idField ? { idField: op.config.idField } : {},
1261
1368
  ...op.config.itemUrlTemplate ? { itemUrlTemplate: op.config.itemUrlTemplate } : {},
@@ -1793,7 +1900,7 @@ const userTypeValues = ["individual", "organization"];
1793
1900
  const LINKEDIN_CACHE_METADATA = {
1794
1901
  joins: [
1795
1902
  "li_*.user_id = li_profiles.provider_id",
1796
- "li_messages.conversation_id = li_conversations.id",
1903
+ "li_messages.chat_id = li_conversations.chat_id",
1797
1904
  "li_messages.sender_id = li_profiles.provider_id",
1798
1905
  "li_posts.author_id = li_profiles.provider_id"
1799
1906
  ],
@@ -1803,8 +1910,7 @@ const LINKEDIN_CACHE_METADATA = {
1803
1910
  "li_conversations.user_type": userTypeValues,
1804
1911
  "li_messages.sender_type": userTypeValues,
1805
1912
  "li_posts.author_type": userTypeValues,
1806
- "li_requests.type": ["received", "sent"],
1807
- "li_requests.user_type": userTypeValues
1913
+ "li_requests.type": ["received", "sent"]
1808
1914
  },
1809
1915
  indexed: {
1810
1916
  li_connections: [
@@ -1823,7 +1929,7 @@ const LINKEDIN_CACHE_METADATA = {
1823
1929
  ],
1824
1930
  li_messages: [
1825
1931
  "created_at",
1826
- "conversation_id",
1932
+ "chat_id",
1827
1933
  "sender_id"
1828
1934
  ],
1829
1935
  li_posts: [
@@ -2430,6 +2536,10 @@ const MIGRATIONS = [
2430
2536
  {
2431
2537
  "tag": "0010_x_timeline",
2432
2538
  "sql": "CREATE TABLE \"x_timeline_raw\" (\n \"id\" text PRIMARY KEY NOT NULL,\n \"created_at\" integer,\n \"author_id\" text,\n \"conversation_id\" text,\n \"in_reply_to_user_id\" text,\n \"lang\" text,\n \"reply_settings\" text,\n \"text\" text,\n \"url\" text,\n \"paid_partnership\" integer,\n \"possibly_sensitive\" integer,\n \"like_count\" integer,\n \"retweet_count\" integer,\n \"reply_count\" integer,\n \"quote_count\" integer,\n \"bookmark_count\" integer,\n \"impression_count\" integer,\n \"raw\" text NOT NULL,\n \"synced_at\" integer NOT NULL\n);\n--> statement-breakpoint\nCREATE INDEX \"x_timeline_created_at_idx\" ON \"x_timeline_raw\" (\"created_at\");--> statement-breakpoint\nCREATE INDEX \"x_timeline_author_id_created_at_idx\" ON \"x_timeline_raw\" (\"author_id\",\"created_at\");--> statement-breakpoint\nCREATE INDEX \"x_timeline_conversation_id_created_at_idx\" ON \"x_timeline_raw\" (\"conversation_id\",\"created_at\");--> statement-breakpoint\nCREATE VIEW \"x_timeline\" AS\nSELECT \"id\", \"created_at\", \"author_id\", \"conversation_id\", \"in_reply_to_user_id\", \"lang\",\n \"reply_settings\", \"text\", \"url\", \"paid_partnership\", \"possibly_sensitive\",\n \"like_count\", \"retweet_count\", \"reply_count\", \"quote_count\", \"bookmark_count\",\n \"impression_count\"\nFROM \"x_timeline_raw\";\n"
2539
+ },
2540
+ {
2541
+ "tag": "0011_linkedin_public_views",
2542
+ "sql": "DROP VIEW IF EXISTS \"li_requests\";\nDROP VIEW IF EXISTS \"li_conversations\";\nDROP VIEW IF EXISTS \"li_messages\";\nCREATE VIEW \"li_requests\" AS\nSELECT \"id\", \"created_at\", \"type\", json_extract(\"raw\", '$.message') AS \"message\",\n \"user_id\", \"user_public_identifier\" AS \"user_username\",\n \"user_display_name\" AS \"user_name\",\n COALESCE(\"user_headline\", \"user_description\") AS \"user_headline\",\n \"user_profile_url\", \"user_public_picture_url\" AS \"user_avatar_url\"\nFROM \"li_requests_raw\";\nCREATE VIEW \"li_conversations\" AS\nSELECT \"id\" AS \"chat_id\", \"created_at\", \"last_message_timestamp\" AS \"last_message_at\", \"name\",\n CASE\n WHEN \"is_1to1\" = 1 THEN '1to1'\n WHEN \"is_group\" = 1 THEN 'group'\n ELSE \"type\"\n END AS \"type\",\n \"unread_count\", \"is_archived\", \"is_pinned\", \"is_readonly\", \"is_channel\",\n \"muted_until\", \"image_url\", \"creator_id\", \"user_id\",\n \"user_public_identifier\" AS \"user_username\", \"user_display_name\" AS \"user_name\",\n COALESCE(\"user_headline\", \"user_description\") AS \"user_headline\", \"user_description\",\n \"user_profile_url\", \"user_public_picture_url\" AS \"user_avatar_url\", \"user_type\",\n \"user_specifics_network_distance\" AS \"user_distance\"\nFROM \"li_conversations_raw\";\nCREATE VIEW \"li_messages\" AS\nSELECT \"id\", \"timestamp\" AS \"created_at\", \"chat_id\", \"text\",\n \"sender_id\", \"is_deleted\", \"is_delivered\", \"is_edited\", \"is_event\", \"is_hidden\",\n \"is_mentionned\" AS \"is_mentioned\", \"is_pinned\", \"is_seen\", \"is_sender\",\n \"sender_public_identifier\" AS \"sender_username\",\n \"sender_display_name\" AS \"sender_name\", \"sender_description\" AS \"sender_headline\",\n \"sender_public_picture_url\" AS \"sender_avatar_url\", \"sender_profile_url\",\n \"sender_type\", \"sender_specifics_network_distance\" AS \"sender_distance\"\nFROM \"li_messages_raw\";\n"
2433
2543
  }
2434
2544
  ];
2435
2545
  //#endregion
@@ -11056,14 +11166,6 @@ const CONNECTED_ACCOUNT_STATUSES = [
11056
11166
  "failed",
11057
11167
  "expired"
11058
11168
  ];
11059
- const ACCOUNT_CONNECT_ATTEMPT_LANES = ["provider", "legacy"];
11060
- const ACCOUNT_CONNECT_ATTEMPT_STATUSES = [
11061
- "pending_billing",
11062
- "pending_approval",
11063
- "connected",
11064
- "expired",
11065
- "failed"
11066
- ];
11067
11169
  const PROXY_SURFACES = [
11068
11170
  "cli",
11069
11171
  "mcp",
@@ -11126,8 +11228,6 @@ const WEBHOOK_OPERATION_STATES = [
11126
11228
  _enum(PLATFORMS);
11127
11229
  _enum(CONNECTED_ACCOUNT_STATUSES);
11128
11230
  _enum(MATERIALIZED_CONNECTED_ACCOUNT_STATUSES);
11129
- _enum(ACCOUNT_CONNECT_ATTEMPT_LANES);
11130
- _enum(ACCOUNT_CONNECT_ATTEMPT_STATUSES);
11131
11231
  _enum(PROXY_SURFACES);
11132
11232
  _enum(PROXY_CACHE_STATUSES);
11133
11233
  _enum(PROXY_CAPABILITIES);
@@ -11333,35 +11433,6 @@ const connectedAccounts = pgTable("connected_accounts", {
11333
11433
  check("connected_accounts_status_check", sqlCheckIn(table.status, CONNECTED_ACCOUNT_STATUSES)),
11334
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)`)
11335
11435
  ]);
11336
- pgTable("account_connect_attempts", {
11337
- id: text$1("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
11338
- userId: text$1("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
11339
- platform: text$1("platform", { enum: PLATFORMS }).notNull(),
11340
- lane: text$1("lane", { enum: ACCOUNT_CONNECT_ATTEMPT_LANES }).notNull(),
11341
- targetPaidSeats: integer("target_paid_seats").notNull(),
11342
- status: text$1("status", { enum: ACCOUNT_CONNECT_ATTEMPT_STATUSES }).notNull().default("pending_billing"),
11343
- connectedAccountId: text$1("connected_account_id").references(() => connectedAccounts.id, { onDelete: "set null" }),
11344
- operationKey: text$1("operation_key").notNull(),
11345
- billingPaymentURL: text$1("billing_payment_url"),
11346
- billingRequiredAction: jsonb("billing_required_action").$type(),
11347
- failureCode: text$1("failure_code"),
11348
- failureStage: text$1("failure_stage"),
11349
- hostedAuthBindingId: text$1("hosted_auth_binding_id"),
11350
- hostedAuthAccountId: text$1("hosted_auth_account_id"),
11351
- hostedAuthBoundAt: timestamptz("hosted_auth_bound_at"),
11352
- expiresAt: timestamptz("expires_at").notNull(),
11353
- createdAt: timestamptz("created_at").notNull().defaultNow(),
11354
- updatedAt: timestamptz("updated_at").notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
11355
- }, (table) => [
11356
- uniqueIndex("account_connect_attempts_operation_key_key").on(table.operationKey),
11357
- uniqueIndex("account_connect_attempts_hosted_auth_binding_id_key").on(table.hostedAuthBindingId),
11358
- uniqueIndex("account_connect_attempts_active_user_platform_key").on(table.userId, table.platform).where(sql`${table.status} in ('pending_billing', 'pending_approval')`),
11359
- index("account_connect_attempts_expiry_idx").on(table.expiresAt).where(sql`${table.status} in ('pending_billing', 'pending_approval')`),
11360
- check("account_connect_attempts_platform_check", sqlCheckIn(table.platform, PLATFORMS)),
11361
- check("account_connect_attempts_lane_check", sqlCheckIn(table.lane, ACCOUNT_CONNECT_ATTEMPT_LANES)),
11362
- check("account_connect_attempts_status_check", sqlCheckIn(table.status, ACCOUNT_CONNECT_ATTEMPT_STATUSES)),
11363
- check("account_connect_attempts_target_paid_seats_check", sql`${table.targetPaidSeats} >= 0`)
11364
- ]);
11365
11436
  pgTable("account_defaults", {
11366
11437
  userId: text$1("user_id").notNull(),
11367
11438
  platform: text$1("platform", { enum: PLATFORMS }).notNull(),
@@ -24510,7 +24581,7 @@ function createEnv(opts) {
24510
24581
  }
24511
24582
  //#endregion
24512
24583
  //#region package.json
24513
- var version$1 = "0.19.5";
24584
+ var version$1 = "0.19.6";
24514
24585
  //#endregion
24515
24586
  //#region src/lib/env.ts
24516
24587
  const URLWithTrailingSlash = url().transform(ensureTrailingSlash);
@@ -25179,14 +25250,14 @@ const cacheFromLocal = (local, now) => ({
25179
25250
  });
25180
25251
  const nextCursorFrom = (contract, data) => {
25181
25252
  if (!isRecord$7(contract)) return;
25182
- const pagination = contract.pagination;
25253
+ const pagination = contract.upstreamPagination ?? contract.pagination;
25183
25254
  if (!isRecord$7(pagination)) return;
25184
25255
  const response = pagination.response;
25185
25256
  return stringAtPath(data, isRecord$7(response) ? response.nextCursorPath : null) ?? stringAtPath(data, pagination.cursorPath);
25186
25257
  };
25187
25258
  const totalCountFrom = (contract, data) => {
25188
25259
  if (!isRecord$7(contract)) return;
25189
- const pagination = contract.pagination;
25260
+ const pagination = contract.upstreamPagination ?? contract.pagination;
25190
25261
  if (!isRecord$7(pagination)) return;
25191
25262
  return numberAtPath(data, pagination.totalCountPath);
25192
25263
  };
@@ -33504,22 +33575,26 @@ const USAGE_LOG_PAGE_LIMIT = 100;
33504
33575
  const USAGE_LOG_MAX_AUTO_PAGES = 50;
33505
33576
  const cursorFrom = (usage) => usage.nextCursor ?? null;
33506
33577
  const normalizeUsageLogForOutput = (item) => {
33578
+ const withLinkedinSeatPricing = (log) => log.platform === "linkedin" ? {
33579
+ ...log,
33580
+ usageUSD: 0
33581
+ } : log;
33507
33582
  if (typeof item === "object" && item !== null && "createdAt" in item && item.createdAt instanceof Date) {
33508
33583
  const { credits, ...rest } = item;
33509
- return {
33584
+ return withLinkedinSeatPricing({
33510
33585
  ...rest,
33511
33586
  createdAt: item.createdAt.toISOString(),
33512
33587
  ...typeof credits === "number" ? { usageUSD: creditsToUsageUSD(credits) } : {}
33513
- };
33588
+ });
33514
33589
  }
33515
33590
  if (typeof item === "object" && item !== null && "credits" in item) {
33516
33591
  const { credits, ...rest } = item;
33517
- return {
33592
+ return withLinkedinSeatPricing({
33518
33593
  ...rest,
33519
33594
  ...typeof credits === "number" ? { usageUSD: creditsToUsageUSD(credits) } : {}
33520
- };
33595
+ });
33521
33596
  }
33522
- return item;
33597
+ return typeof item === "object" && item !== null ? withLinkedinSeatPricing(item) : item;
33523
33598
  };
33524
33599
  const sumByFrom = (value) => {
33525
33600
  if (value === void 0) return;
@@ -39561,7 +39636,9 @@ const CLIContractMetadata = object({
39561
39636
  outputSchema: unknown().optional(),
39562
39637
  pagination: JSONMetadata.optional(),
39563
39638
  params: record(string(), JSONMetadata).optional(),
39564
- responseShaping: JSONMetadata.optional()
39639
+ responseShaping: JSONMetadata.optional(),
39640
+ upstreamOutputSchema: unknown().optional(),
39641
+ upstreamPagination: JSONMetadata.optional()
39565
39642
  }).strict();
39566
39643
  const issueSummary = (error) => error.issues.map((issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`).join("; ");
39567
39644
  const invalidMetadataError = (label, error) => /* @__PURE__ */ new Error(`Invalid CLI contract metadata for ${label}: ${issueSummary(error)}`);