New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dub-cli

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dub-cli - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

2

dist/index.js
#!/usr/bin/env node
import{OAuth2Client as N}from"@badgateway/oauth2-client";var f=new N({clientId:"dub_app_39527dcc11b452f38bb54a3a1664fd044d7158dfea8abcde",authorizationEndpoint:"https://app.dub.co/oauth/authorize",tokenEndpoint:"https://api.dub.co/oauth/token"});import w from"configstore";async function s(){let o=new w("dub-cli");if(!o.size)throw new Error("Access token not found. Please run `dub login` to authenticate with Dub.");let t=o.all;if(t.expires_at&&Date.now()>=t.expires_at){let n=await f.refreshToken({accessToken:t.access_token,refreshToken:t.refresh_token,expiresAt:t.expires_at}),{accessToken:e,refreshToken:i,expiresAt:p}=n;return await l({access_token:e,refresh_token:i,expires_at:p})}return await o.all}async function l(o){let t=new w("dub-cli"),e={...t.all,...o};if(t.set(e),!t.path)throw new Error("Failed to create or update config file");return e}import d from"chalk";var r={error(...o){console.log(d.red(...o))},warn(...o){console.log(d.yellow(...o))},info(...o){console.log(d.cyan(...o))},success(...o){console.log(d.green(...o))},break(){console.log("")}};import{z}from"zod";function c(o){o instanceof z.ZodError&&(o.issues.forEach(t=>{r.error(t.message)}),process.exit(1)),typeof o=="string"&&(r.error(o),process.exit(1)),o instanceof Error&&(r.error(o.message),process.exit(1)),r.error("Something went wrong. Please try again."),process.exit(1)}import{Command as O}from"commander";import U from"json-colorizer";import G from"ora";var y=new O().name("config").description("See your configured credentials").action(async()=>{let o=G("Getting config").start();try{let t=await s();o.succeed("Configuration file successfully retrieved"),r.info(""),console.log(U(JSON.stringify(t,null,2),{colors:{STRING_KEY:"white",STRING_LITERAL:"#65B741",NUMBER_LITERAL:"#7E30E1"}})),r.info("")}catch(t){o.stop(),c(t)}});async function C(o){if(o.headers.get("content-type")?.includes("application/json")){let e=await o.json();if("error"in e)throw new Error(e.error.message);return e}let n=await o.text();throw new Error(n)}import{Dub as F}from"dub";import J from"node-fetch";async function b(){let o=await s(),t=new F({token:o.access_token}),[{result:n},e]=await Promise.all([t.domains.list(),J("https://api.dub.co/domains/default",{method:"GET",headers:{Authorization:`Bearer ${o.access_token}`,"Content-Type":"application/json"}})]),[i,p]=await Promise.all([n,C(e)]),a=[...i.map(m=>m.slug),...p];return Array.from(new Set(a))}import j from"chalk";import{Command as H}from"commander";import Y from"ora";import B from"prompts";import{z as x}from"zod";var V=x.object({slug:x.string().min(3,{message:"Please provide a valid slug"})}),D=new H().name("domains").description("Configure your workspace domain").action(async()=>{let o=Y("Fetching domains").start();try{let n=await B([{type:"select",name:"domain",message:"Select a domain",choices:await(async()=>{let e=await b();return e&&o.stop(),[...e.map(i=>({title:i,value:i}))]})(),validate:e=>{let i=V.shape.slug.safeParse(e);return i.success||i.error.errors[0].message}}],{onCancel:()=>{r.info(""),r.warn("You cancelled the prompt."),r.info(""),process.exit(0)}});l({domain:n.domain}),o.succeed("Done"),r.info(""),r.info(`${j.green("Success!")} Configuration updated.`),r.info("")}catch(t){o.stop(),c(t)}});import M from"chalk";import*as A from"http";import*as E from"url";function S({oauthClient:o,redirectUri:t,codeVerifier:n,spinner:e}){let i=A.createServer(async(p,a)=>{let m=E.parse(p.url||"",!0);if(m.pathname!=="/callback"||p.method!=="GET"){a.writeHead(404),a.end("Not found");return}let g=m.query.code;if(!g){a.writeHead(400),a.end("Authorization code not found. Please start the login process again.");return}try{e.text="Verifying";let{accessToken:h,refreshToken:L,expiresAt:k}=await o.authorizationCode.getToken({code:g,redirectUri:t,codeVerifier:n});e.text="Configuring";let v={access_token:h.trim(),refresh_token:L,expires_at:k?Date.now()+k*1e3:null,domain:"dub.sh"};await l(v),e.succeed("Configuration completed"),r.info(""),r.info(M.green("Logged in successfully!")),r.info(""),a.writeHead(200,{"Content-Type":"text/html"}),a.end("Authentication successful! You can close this window.")}catch{a.writeHead(500,{"Content-Type":"text/html"}),a.end("An error occurred during authentication. Please try again.")}finally{i.close(),process.exit(0)}});setTimeout(()=>{i.close(),process.exit(0)},3e5),i.listen(4587)}import{customAlphabet as q}from"nanoid";var K="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function u(o=7){return q(K,o)()}import{Command as W}from"commander";import Z from"open";import $ from"ora";var T=new W().name("login").description("Log into the Dub platform").action(async()=>{try{let o=u(64),t="http://localhost:4587/callback",n=await f.authorizationCode.getAuthorizeUri({redirectUri:t,codeVerifier:o,scope:["links.read","links.write","domains.read"]}),e=$("Opening browser for authentication").start();await Z(n),e.text="Waiting for authentication",S({oauthClient:f,redirectUri:t,codeVerifier:o,spinner:e})}catch(o){c(o)}});import{Dub as Q}from"dub";async function P({url:o,key:t}){let n=await s();return await new Q({token:n.access_token}).links.create({domain:n.domain,url:o,key:t})}import X from"chalk";import{Command as oo}from"commander";import to from"ora";import eo from"prompts";var I=new oo().name("shorten").description("Create a short link").argument("[url]","Destination URL").argument("[key]","Short key",u()).action(async(o,t)=>{try{await s();let n={url:o,key:t};o||(n=await eo([{type:"text",name:"url",message:"Enter your Destination URL:"},{type:"text",name:"key",message:"Enter your Short link:",initial:u()}],{onCancel:()=>{r.info(""),r.warn("You cancelled the prompt."),r.info(""),process.exit(0)}}));let e=to("Creating new short link").start();try{let i=await P(n);e.succeed("New short link created!"),r.info(""),r.info(X.green(i.shortLink)),r.info("")}catch(i){throw e.fail("Failed to create link"),e.stop(),r.info(""),i}}catch(n){c(n)}});import ro from"package-json";async function R(){return await ro("dub-cli")}import{Command as so}from"commander";import{Command as no}from"commander";import{Dub as io}from"dub";import ao from"ora";var _=new no().command("links").description("Search for links in your Dub workspace").option("-s, --search [search]","Search term to filter links by").option("-l, --limit [limit]","Number of links to fetch").action(async({search:o,limit:t})=>{try{let n=await s(),e=ao("Fetching links").start(),p=await new io({token:n.access_token}).links.list({search:o,pageSize:t?parseInt(t):10});e.stop();let a=p.result.map(m=>({"Short Link":m.shortLink,"Destination URL":m.url,Clicks:m.clicks,"Created At":new Date(m.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"numeric",hour12:!0})}));console.table(a)}catch(n){c(n)}});process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function co(){let o=await R(),t=new so().name("dub").description("A CLI for shortening links with the Dub.co API.").version(o.version||"1.0.0","-v, --version","display the version number");t.addCommand(T).addCommand(y).addCommand(D).addCommand(I).addCommand(_),t.parse()}co();
import{OAuth2Client as N}from"@badgateway/oauth2-client";var f=new N({clientId:"dub_app_39527dcc11b452f38bb54a3a1664fd044d7158dfea8abcde",authorizationEndpoint:"https://app.dub.co/oauth/authorize",tokenEndpoint:"https://api.dub.co/oauth/token"});import k from"configstore";async function s(){let o=new k("dub-cli");if(!o.size)throw new Error("Access token not found. Please run `dub login` to authenticate with Dub.");let t=o.all;if(t.expires_at&&Date.now()>=t.expires_at){let{accessToken:n,refreshToken:e,expiresAt:i}=await f.refreshToken({accessToken:t.access_token,refreshToken:t.refresh_token,expiresAt:t.expires_at});return await l({access_token:n,refresh_token:e,expires_at:i})}return await o.all}async function l(o){let t=new k("dub-cli"),e={...t.all,...o};if(t.set(e),!t.path)throw new Error("Failed to create or update config file");return e}import d from"chalk";var r={error(...o){console.log(d.red(...o))},warn(...o){console.log(d.yellow(...o))},info(...o){console.log(d.cyan(...o))},success(...o){console.log(d.green(...o))},break(){console.log("")}};import{z}from"zod";function c(o){o instanceof z.ZodError&&(o.issues.forEach(t=>{r.error(t.message)}),process.exit(1)),typeof o=="string"&&(r.error(o),process.exit(1)),o instanceof Error&&(r.error(o.message),process.exit(1)),r.error("Something went wrong. Please try again."),process.exit(1)}import{Command as O}from"commander";import U from"json-colorizer";import G from"ora";var w=new O().name("config").description("See your configured credentials").action(async()=>{let o=G("Getting config").start();try{let t=await s();o.succeed("Configuration file successfully retrieved"),r.info(""),console.log(U(JSON.stringify(t,null,2),{colors:{STRING_KEY:"white",STRING_LITERAL:"#65B741",NUMBER_LITERAL:"#7E30E1"}})),r.info("")}catch(t){o.stop(),c(t)}});async function y(o){if(o.headers.get("content-type")?.includes("application/json")){let e=await o.json();if("error"in e)throw new Error(e.error.message);return e}let n=await o.text();throw new Error(n)}import{Dub as F}from"dub";import J from"node-fetch";async function C(){let o=await s(),t=new F({token:o.access_token}),[{result:n},e]=await Promise.all([t.domains.list(),J("https://api.dub.co/domains/default",{method:"GET",headers:{Authorization:`Bearer ${o.access_token}`,"Content-Type":"application/json"}})]),[i,p]=await Promise.all([n,y(e)]),a=[...i.map(m=>m.slug),...p];return Array.from(new Set(a))}import j from"chalk";import{Command as H}from"commander";import Y from"ora";import B from"prompts";import{z as b}from"zod";var V=b.object({slug:b.string().min(3,{message:"Please provide a valid slug"})}),x=new H().name("domains").description("Configure your workspace domain").action(async()=>{let o=Y("Fetching domains").start();try{let n=await B([{type:"select",name:"domain",message:"Select a domain",choices:await(async()=>{let e=await C();return e&&o.stop(),[...e.map(i=>({title:i,value:i}))]})(),validate:e=>{let i=V.shape.slug.safeParse(e);return i.success||i.error.errors[0].message}}],{onCancel:()=>{r.info(""),r.warn("You cancelled the prompt."),r.info(""),process.exit(0)}});l({domain:n.domain}),o.succeed("Done"),r.info(""),r.info(`${j.green("Success!")} Configuration updated.`),r.info("")}catch(t){o.stop(),c(t)}});import M from"chalk";import*as D from"http";import*as A from"url";function E({oauthClient:o,redirectUri:t,codeVerifier:n,spinner:e}){let i=D.createServer(async(p,a)=>{let m=A.parse(p.url||"",!0);if(m.pathname!=="/callback"||p.method!=="GET"){a.writeHead(404),a.end("Not found");return}let g=m.query.code;if(!g){a.writeHead(400),a.end("Authorization code not found. Please start the login process again.");return}try{e.text="Verifying";let{accessToken:h,refreshToken:_,expiresAt:L}=await o.authorizationCode.getToken({code:g,redirectUri:t,codeVerifier:n});e.text="Configuring";let v={access_token:h.trim(),refresh_token:_,expires_at:L,domain:"dub.sh"};await l(v),e.succeed("Configuration completed"),r.info(""),r.info(M.green("Logged in successfully!")),r.info(""),a.writeHead(200,{"Content-Type":"text/html"}),a.end("Authentication successful! You can close this window.")}catch{a.writeHead(500,{"Content-Type":"text/html"}),a.end("An error occurred during authentication. Please try again.")}finally{i.close(),process.exit(0)}});setTimeout(()=>{i.close(),process.exit(0)},3e5),i.listen(4587)}import{customAlphabet as q}from"nanoid";var K="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";function u(o=7){return q(K,o)()}import{Command as W}from"commander";import Z from"open";import $ from"ora";var S=new W().name("login").description("Log into the Dub platform").action(async()=>{try{let o=u(64),t="http://localhost:4587/callback",n=await f.authorizationCode.getAuthorizeUri({redirectUri:t,codeVerifier:o,scope:["links.read","links.write","domains.read"]}),e=$("Opening browser for authentication").start();await Z(n),e.text="Waiting for authentication",E({oauthClient:f,redirectUri:t,codeVerifier:o,spinner:e})}catch(o){c(o)}});import{Dub as Q}from"dub";async function T({url:o,key:t}){let n=await s();return await new Q({token:n.access_token}).links.create({domain:n.domain,url:o,key:t})}import X from"chalk";import{Command as oo}from"commander";import to from"ora";import eo from"prompts";var P=new oo().name("shorten").description("Create a short link").argument("[url]","Destination URL").argument("[key]","Short key",u()).action(async(o,t)=>{try{await s();let n={url:o,key:t};o||(n=await eo([{type:"text",name:"url",message:"Enter your Destination URL:"},{type:"text",name:"key",message:"Enter your Short link:",initial:u()}],{onCancel:()=>{r.info(""),r.warn("You cancelled the prompt."),r.info(""),process.exit(0)}}));let e=to("Creating new short link").start();try{let i=await T(n);e.succeed("New short link created!"),r.info(""),r.info(X.green(i.shortLink)),r.info("")}catch(i){throw e.fail("Failed to create link"),e.stop(),r.info(""),i}}catch(n){c(n)}});import ro from"package-json";async function I(){return await ro("dub-cli")}import{Command as so}from"commander";import{Command as no}from"commander";import{Dub as io}from"dub";import ao from"ora";var R=new no().command("links").description("Search for links in your Dub workspace").option("-s, --search [search]","Search term to filter links by").option("-l, --limit [limit]","Number of links to fetch").action(async({search:o,limit:t})=>{try{let n=await s(),e=ao("Fetching links").start(),p=await new io({token:n.access_token}).links.list({search:o,pageSize:t?parseInt(t):10});e.stop();let a=p.result.map(m=>({"Short Link":m.shortLink,"Destination URL":m.url,Clicks:m.clicks,"Created At":new Date(m.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"numeric",hour12:!0})}));console.table(a)}catch(n){c(n)}});process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function co(){let o=await I(),t=new so().name("dub").description("A CLI for shortening links with the Dub.co API.").version(o.version||"1.0.0","-v, --version","display the version number");t.addCommand(S).addCommand(w).addCommand(x).addCommand(P).addCommand(R),t.parse()}co();
//# sourceMappingURL=index.js.map
{
"name": "dub-cli",
"version": "0.0.12",
"version": "0.0.13",
"description": "A CLI for easily shortening URLs with the Dub.co API.",

@@ -5,0 +5,0 @@ "publishConfig": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc