dunsocial 0.5.0 → 0.6.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.js CHANGED
@@ -191,8 +191,8 @@ Exit codes:
191
191
 
192
192
  Docs: https://dunsocial.com
193
193
  `}import{mkdir as oU,readFile as i0,writeFile as eU,chmod as rU,unlink as lU}from"node:fs/promises";import{dirname as sU,join as XU}from"node:path";import{homedir as tU}from"node:os";var M="0.4.0";function o(){if(process.env.DUN_CONFIG)return process.env.DUN_CONFIG;let U=process.env.XDG_CONFIG_HOME,D=U?U:XU(tU(),".config");return XU(D,"dunsocial","config.json")}function j(){return o()}async function b(U){let D=o();await oU(sU(D),{recursive:!0});let O={...U,updatedAt:new Date().toISOString()};await eU(D,`${JSON.stringify(O,null,2)}
194
- `,"utf8");try{await rU(D,384)}catch{}}async function ZU(){let U=o();try{await lU(U)}catch(D){if(D.code!=="ENOENT")throw new Q(`Failed to clear config: ${D.message}`,z.USAGE)}}function w(U){if(!U.token)throw new Q("Not authenticated. Run `dun auth login` (or `dun auth login --token <token>` / set DUN_TOKEN).",z.AUTH);return U.token}function H(U){if(!U.workspaceId)throw new Q("No workspace selected. Run `dun workspace use <id|slug>` or pass --workspace / DUN_WORKSPACE_ID.",z.VALIDATION);return U.workspaceId}var JU=[" ___ ___ _ _ "," | \\ _ _ _ _ / __| ___ __(_)__ _| |"," | |) | || | ' \\__ \\/ _ \\/ _| / _` | |"," |___/ \\_,_|_||_|___/\\___/\\__|_\\__,_|_|"].join(`
195
- `),RU=[" _ "," __| |_ _ _ _ "," / _` | || | ' \\ "," \\__,_|\\_,_|_||_|",""," DunSocial"].join(`
194
+ `,"utf8");try{await rU(D,384)}catch{}}async function ZU(){let U=o();try{await lU(U)}catch(D){if(D.code!=="ENOENT")throw new Q(`Failed to clear config: ${D.message}`,z.USAGE)}}function w(U){if(!U.token)throw new Q("Not authenticated. Run `dun auth login` (or `dun auth login --token <token>` / set DUN_TOKEN).",z.AUTH);return U.token}function H(U){if(!U.workspaceId)throw new Q("No workspace selected. Run `dun workspace use <id|slug>` or pass --workspace / DUN_WORKSPACE_ID.",z.VALIDATION);return U.workspaceId}var JU=["█▀▀▄ █▀▀▄ █▀▀▀ █▀▀█ █▀▀▀ ▀█▀ █▀▀█ ","█ █ █ █ █ █ ▀▀▀█ █ █ █ █ █▀▀█ █","▀▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀"].join(`
195
+ `),RU=["█▀▀▄ █ █ █▀▀▄"," ","▀▀▀▀ ▀▀▀▀ ▀ ▀",""," DunSocial"].join(`
196
196
  `),aU="DunSocial",U0=YU(JU),O0=YU(RU);function YU(U){return Math.max(...U.split(`
197
197
  `).map((D)=>D.length))}function e(U=process.stderr){if(!U.isTTY)return!1;if(process.env.CI==="true"||process.env.CI==="1")return!1;if(process.env.GITHUB_ACTIONS||process.env.TF_BUILD||process.env.GITLAB_CI)return!1;if(process.env.DUN_JSON==="1")return!1;return!0}function qU(U=process.stdout.columns??80){let D=U>0?U:80;if(D>=U0)return JU;if(D>=O0)return RU;return aU}function D0(U=process.stdout.columns??80){return`${qU(U)}
198
198
 
@@ -210,8 +210,8 @@ ${G}`:G}return Object.entries(O).map(([K,G])=>`${K}: ${r(G)}`).join(`
210
210
  `);return`${V}
211
211
  ${X}`}function r(U){if(U===null||U===void 0)return"";if(typeof U==="string")return U.replace(/\s+/g," ").trim();if(typeof U==="number"||typeof U==="boolean")return String(U);if(U instanceof Date)return U.toISOString();if(typeof U==="object"){let D=U;if(typeof D.id==="string"&&typeof D.name==="string")return`${D.name} (${D.id})`;if(typeof D.status==="string")return D.status;return JSON.stringify(U)}return String(U)}function K0(U,D){if(U.length<=D)return U;return`${U.slice(0,Math.max(0,D-1))}…`}function d(U,D,O){if(!U)return;if(O!==void 0){process.stderr.write(`[debug] ${D} ${JSON.stringify(O)}
212
212
  `);return}process.stderr.write(`[debug] ${D}
213
- `)}class WU{ctx;constructor(U){this.ctx=U}async request(U){let D=U.method??"GET",O=new URL(U.path.startsWith("http")?U.path:`${this.ctx.apiUrl}${U.path}`);if(U.query)for(let[X,Z]of Object.entries(U.query)){if(Z===void 0||Z===null||Z==="")continue;O.searchParams.set(X,String(Z))}let K={Accept:"application/json","User-Agent":`dunsocial-cli/${M}`,...U.headers??{}};if(U.auth!==!1)K.Authorization=`Bearer ${w(this.ctx)}`;if(U.workspace)K["X-Workspace-Id"]=H(this.ctx);let G;if(U.body!==void 0)K["Content-Type"]="application/json",G=JSON.stringify(U.body);d(this.ctx.debug,`${D} ${O.toString()}`);let $;try{$=await fetch(O,{method:D,headers:K,body:G})}catch(X){throw new Q(`Network error: ${X.message}`,z.NETWORK,{cause:String(X)})}let A=await $.text(),V=null;if(A)try{V=JSON.parse(A)}catch{V=null}if(d(this.ctx.debug,`← ${$.status}`,{ok:$.ok,bodyPreview:A.slice(0,300)}),!$.ok){let X=V?.error||V?.message||(A?A.slice(0,300):`HTTP ${$.status}`);throw new Q(X,$U($.status),{status:$.status,body:V??A})}if(V&&typeof V==="object"&&"success"in V){if(V.success===!1)throw new Q(V.error||V.message||"Request failed",z.VALIDATION,V);return V.data}return V??void 0}get(U,D){return this.request({...D,method:"GET",path:U})}post(U,D,O){return this.request({...O,method:"POST",path:U,body:D})}patch(U,D,O){return this.request({...O,method:"PATCH",path:U,body:D})}delete(U,D,O){return this.request({...O,method:"DELETE",path:U,body:D})}}function T(U){return new WU(U)}function Y(U,...D){for(let O of D){let K=U[O];if(typeof K==="string"&&K.length>0)return K}return}function F(U,...D){for(let O of D){let K=U[O];if(K===!0)return!0;if(typeof K==="string"){let G=K.toLowerCase();if(G==="1"||G==="true"||G==="yes")return!0}}return!1}function P(U,...D){let O=Y(U,...D);if(O===void 0)return;let K=Number(O);if(!Number.isFinite(K))throw Error(`Invalid number for --${D[0]}: ${O}`);return K}function u(U,...D){let O=Y(U,...D);if(O===void 0)return;return O.split(",").map((K)=>K.trim()).filter(Boolean)}var V0=[" ___ ___ _ _ "," | \\ _ _ _ _ / __| ___ __(_)__ _| |"," | |) | || | ' \\__ \\/ _ \\/ _| / _` | |"," |___/ \\_,_|_||_|___/\\___/\\__|_\\__,_|_|"].join(`
214
- `),wU=[" _ "," __| |_ _ _ _ "," / _` | || | ' \\ "," \\__,_|\\_,_|_||_|",""," DunSocial"].join(`
213
+ `)}class WU{ctx;constructor(U){this.ctx=U}async request(U){let D=U.method??"GET",O=new URL(U.path.startsWith("http")?U.path:`${this.ctx.apiUrl}${U.path}`);if(U.query)for(let[X,Z]of Object.entries(U.query)){if(Z===void 0||Z===null||Z==="")continue;O.searchParams.set(X,String(Z))}let K={Accept:"application/json","User-Agent":`dunsocial-cli/${M}`,...U.headers??{}};if(U.auth!==!1)K.Authorization=`Bearer ${w(this.ctx)}`;if(U.workspace)K["X-Workspace-Id"]=H(this.ctx);let G;if(U.body!==void 0)K["Content-Type"]="application/json",G=JSON.stringify(U.body);d(this.ctx.debug,`${D} ${O.toString()}`);let $;try{$=await fetch(O,{method:D,headers:K,body:G})}catch(X){throw new Q(`Network error: ${X.message}`,z.NETWORK,{cause:String(X)})}let A=await $.text(),V=null;if(A)try{V=JSON.parse(A)}catch{V=null}if(d(this.ctx.debug,`← ${$.status}`,{ok:$.ok,bodyPreview:A.slice(0,300)}),!$.ok){let X=V?.error||V?.message||(A?A.slice(0,300):`HTTP ${$.status}`);throw new Q(X,$U($.status),{status:$.status,body:V??A})}if(V&&typeof V==="object"&&"success"in V){if(V.success===!1)throw new Q(V.error||V.message||"Request failed",z.VALIDATION,V);return V.data}return V??void 0}get(U,D){return this.request({...D,method:"GET",path:U})}post(U,D,O){return this.request({...O,method:"POST",path:U,body:D})}patch(U,D,O){return this.request({...O,method:"PATCH",path:U,body:D})}delete(U,D,O){return this.request({...O,method:"DELETE",path:U,body:D})}}function T(U){return new WU(U)}function Y(U,...D){for(let O of D){let K=U[O];if(typeof K==="string"&&K.length>0)return K}return}function F(U,...D){for(let O of D){let K=U[O];if(K===!0)return!0;if(typeof K==="string"){let G=K.toLowerCase();if(G==="1"||G==="true"||G==="yes")return!0}}return!1}function P(U,...D){let O=Y(U,...D);if(O===void 0)return;let K=Number(O);if(!Number.isFinite(K))throw Error(`Invalid number for --${D[0]}: ${O}`);return K}function u(U,...D){let O=Y(U,...D);if(O===void 0)return;return O.split(",").map((K)=>K.trim()).filter(Boolean)}var V0=["█▀▀▄ █▀▀▄ █▀▀▀ █▀▀█ █▀▀▀ ▀█▀ █▀▀█ ","█ █ █ █ █ █ ▀▀▀█ █ █ █ █ █▀▀█ █","▀▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀"].join(`
214
+ `),wU=["█▀▀▄ █ █ █▀▀▄"," ","▀▀▀▀ ▀▀▀▀ ▀ ▀",""," DunSocial"].join(`
215
215
  `);var KO=HU(V0),VO=HU(wU);function HU(U){return Math.max(...U.split(`
216
216
  `).map((D)=>D.length))}function S(U=process.stderr){if(!U.isTTY)return!1;if(process.env.CI==="true"||process.env.CI==="1")return!1;if(process.env.GITHUB_ACTIONS||process.env.TF_BUILD||process.env.GITLAB_CI)return!1;if(process.env.DUN_JSON==="1")return!1;return!0}function FU(){return wU}async function PU(U,D,O,K){switch(D){case"login":return A0(U,O);case"logout":return Q0(U);case"whoami":return X0(U);case"status":return Z0(U);default:throw new Q(`Unknown auth command "${D??""}". Try: login, logout, whoami, status`,z.USAGE)}}async function A0(U,D){let O=Y(D,"token")||process.env.DUN_TOKEN;if(O)return G0(U,O);return z0(U,D)}function E(U){if(U)return"Logged in.";return`Logged in.
217
217
  Next: dun workspace list && dun workspace use <id|slug>`}async function G0(U,D){let O={...U,token:D},G=await T(O).get("/api/user/profile");if(await b({...U.config,apiUrl:U.apiUrl,token:D,defaultWorkspaceId:U.config.defaultWorkspaceId,defaultWorkspaceSlug:U.config.defaultWorkspaceSlug,defaultWorkspaceName:U.config.defaultWorkspaceName}),!U.json&&S(process.stdout)){R(E(Boolean(U.config.defaultWorkspaceId)),U);return}R({user:{id:G.id,name:G.name,email:G.email},configPath:j(),method:"token",message:E(Boolean(U.config.defaultWorkspaceId))},U)}async function z0(U,D){let O=T({...U,token:void 0}),K=await O.post("/api/cli/auth/start",{clientName:"dun-cli"},{auth:!1}),G=!F(D,"no-browser");if(!U.json){if(S(process.stderr))process.stderr.write(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dunsocial",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "DunSocial agent-first CLI — schedule and publish social posts from the terminal, CI, and coding agents",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,22 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * Gated install tip — silent in CI / non-TTY / agent installs.
4
- * Keep in sync with apps/cli/src/brand.ts FIGlet Small art.
4
+ * Keep in sync with apps/cli/src/brand.ts OpenCode-style block art.
5
5
  */
6
6
  'use strict';
7
7
 
8
8
  const BANNER_FULL = [
9
- ' ___ ___ _ _ ',
10
- " | \\ _ _ _ _ / __| ___ __(_)__ _| |",
11
- " | |) | || | ' \\__ \\/ _ \\/ _| / _` | |",
12
- ' |___/ \\_,_|_||_|___/\\___/\\__|_\\__,_|_|'
9
+ '█▀▀▄ █ █▀▀▄ █▀▀▀ █▀▀█ █▀▀▀ ▀█▀ █▀▀█ █',
10
+ '█ █ █ █ ▀▀▀█ █ █ █ █ █▀▀█ █',
11
+ '▀▀▀▀ ▀▀▀▀ ▀ ▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀'
13
12
  ].join('\n');
14
13
 
15
14
  const BANNER_MINI = [
16
- ' _ ',
17
- ' __| |_ _ _ _ ',
18
- " / _` | || | ' \\ ",
19
- ' \\__,_|\\_,_|_||_|',
15
+ '█▀▀▄ █ █ █▀▀▄',
16
+ ' ',
17
+ '▀▀▀▀ ▀▀▀▀ ▀ ▀',
20
18
  '',
21
19
  ' DunSocial'
22
20
  ].join('\n');