+15
-2
| #!/usr/bin/env node | ||
| "use strict";var M=Object.create;var E=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var J=(i,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of Q(e))!H.call(i,t)&&t!==n&&E(i,t,{get:()=>e[t],enumerable:!(o=N(e,t))||o.enumerable});return i};var d=(i,e,n)=>(n=i!=null?M(V(i)):{},J(e||!i||!i.__esModule?E(n,"default",{value:i,enumerable:!0}):n,i));var K=require("commander");var u=d(require("path")),F=d(require("fs")),p=d(require("@clack/prompts"));var l=d(require("fs")),h=d(require("path"));function x(i){let{configPath:e,outputPath:n,typesPackages:o=["@blimu/types","@blimu/backend"]}=i,t=[],s=o.join(" and ");t.push("/**"),t.push(` * Type Augmentation for ${s}`),t.push(" *"),t.push(` * This file augments the ${s} packages with union types`),t.push(" * specific to your environment configuration."),t.push(" *"),t.push(" * Types are automatically inferred from your blimu.config.ts file."),t.push(" * No regeneration needed when you update your config!"),t.push(" *"),t.push(" * Make sure to include this file in your tsconfig.json:"),t.push(" * {"),t.push(' * "include": ["blimu-types.d.ts"]'),t.push(" * }"),t.push(" */"),t.push("");let a=h.dirname(n),f=h.isAbsolute(e)?h.resolve(e):h.resolve(a,e),D=h.relative(a,f).replace(/\.(ts|mjs|js)$/,""),W=D.startsWith(".")?D:`./${D}`;t.push(`import type config from '${W}';`),t.push("import type {"),t.push(" InferResourceTypes,"),t.push(" InferEntitlementTypes,"),t.push(" InferPlanTypes,"),t.push(" InferLimitTypes,"),t.push(" InferUsageLimitTypes,"),t.push("} from 'blimu';"),t.push("");for(let z of o)t.push(`declare module '${z}' {`),t.push(" /**"),t.push(" * Resource types inferred from your Blimu configuration."),t.push(" */"),t.push(" type ResourceType = InferResourceTypes<typeof config>;"),t.push(""),t.push(" /**"),t.push(" * Entitlement types inferred from your Blimu configuration."),t.push(" */"),t.push(" type EntitlementType = InferEntitlementTypes<typeof config>;"),t.push(""),t.push(" /**"),t.push(" * Plan types inferred from your Blimu configuration."),t.push(" */"),t.push(" type PlanType = InferPlanTypes<typeof config>;"),t.push(""),t.push(" /**"),t.push(" * Limit types inferred from your Blimu configuration."),t.push(" */"),t.push(" type LimitType = InferLimitTypes<typeof config>;"),t.push(""),t.push(" /**"),t.push(" * Usage limit types inferred from your Blimu configuration."),t.push(" */"),t.push(" type UsageLimitType = InferUsageLimitTypes<typeof config>;"),t.push("}"),t.push("");l.existsSync(a)||l.mkdirSync(a,{recursive:!0}),l.writeFileSync(n,t.join(` | ||
| `),"utf-8")}var m=d(require("path")),g=d(require("fs"));function y(){let i=[m.join(process.cwd(),"blimu.config.ts"),m.join(process.cwd(),"blimu.config.mjs"),m.join(process.cwd(),"blimu.config.js"),m.join(process.cwd(),"blimu.config.json")];for(let e of i)if(g.existsSync(e))return e;return null}async function _(i){let e=m.isAbsolute(i)?i:m.resolve(process.cwd(),i);if(!g.existsSync(e))throw new Error(`Config file not found: ${e}`);if(m.extname(e).toLowerCase()===".json"){let t=g.readFileSync(e,"utf-8");return JSON.parse(t)}let o=await import(e);return o.default||o}function A(i,e){let o=m.relative(i,e).replace(/\.(ts|mjs|js)$/,"");return o.startsWith(".")?o:`./${o}`}function L(i){i.command("codegen").description("Generate type augmentation file from Blimu config").option("--config <path>","Path to Blimu config file (defaults to blimu.config.ts in project root)").option("--output <path>","Output path for generated type augmentation file (defaults to blimu-types.d.ts in project root)").action(async e=>{let n=p.spinner();try{let o=e.config||y();o||(p.cancel("No config file found. Please provide --config or ensure blimu.config.ts exists in project root."),process.exit(1));let t=u.isAbsolute(o)?o:u.resolve(process.cwd(),o);F.existsSync(t)||(p.cancel(`Config file not found: ${t}`),process.exit(1)),p.log.step(`Using config file: ${t}`);let s=e.output?u.isAbsolute(e.output)?e.output:u.resolve(process.cwd(),e.output):u.join(process.cwd(),"blimu-types.d.ts");p.log.step(`Output: ${s}`);let a=u.dirname(s),f=A(a,t);n.start("Generating type augmentation file with type inference..."),x({configPath:f,outputPath:s}),n.stop("\u26A1\uFE0F Successfully generated type augmentation file"),p.log.success(`Generated at: ${s}`),p.log.info("\u{1F4A1} Tip: Types are automatically inferred from your config."),p.log.info(" No regeneration needed when you update blimu.config.ts!")}catch(o){n.stop("\u274C Failed to generate type augmentation"),p.log.error(`Failed to generate type augmentation: ${o instanceof Error?o.message:String(o)}`),o instanceof Error&&o.stack&&p.log.error(o.stack),process.exit(1)}})}var c=d(require("@clack/prompts"));var T=require("@blimu/fetch");function j(i){let e=[...i?.authStrategies??[]];return i.bearer&&e.push({type:"bearer",token:i.bearer}),i.apiKey&&e.push({type:"apiKey",key:i.apiKey,location:"header",name:"X-API-KEY"}),e}var R=class{constructor(e){this.core=e}list(e,n){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/api-keys`,...n??{}})}create(e,n,o){return this.core.request({method:"POST",path:`/v1/workspace/${encodeURIComponent(e)}/api-keys`,body:n,...o??{}})}delete(e,n,o){return this.core.request({method:"DELETE",path:`/v1/workspace/${encodeURIComponent(e)}/api-keys/${encodeURIComponent(n)}`,...o??{}})}get(e,n,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/api-keys/${encodeURIComponent(n)}`,...o??{}})}reveal(e,n,o){return this.core.request({method:"POST",path:`/v1/workspace/${encodeURIComponent(e)}/api-keys/${encodeURIComponent(n)}/reveal`,...o??{}})}};var C=class{constructor(e){this.core=e}get(e,n,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/definitions`,...o??{}})}update(e,n,o,t){return this.core.request({method:"PUT",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/definitions`,body:o,...t??{}})}validate(e,n,o,t){return this.core.request({method:"POST",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/definitions/validate`,body:o,...t??{}})}};var v=class{constructor(e){this.core=e}getRecords(e,n,o){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/dns/records`,...o??{}})}validate(e,n,o){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/dns/validate`,...o??{}})}};var I=class{constructor(e){this.core=e}list(e,n,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments`,query:n,...o??{}})}create(e,n,o){return this.core.request({method:"POST",path:`/v1/workspace/${encodeURIComponent(e)}/environments`,body:n,...o??{}})}delete(e,n,o){return this.core.request({method:"DELETE",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}`,...o??{}})}read(e,n,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}`,...o??{}})}update(e,n,o,t){return this.core.request({method:"PUT",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}`,body:o,...t??{}})}getAuthConfig(e,n,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/auth-config`,...o??{}})}updateAuthConfig(e,n,o,t){return this.core.request({method:"PUT",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/auth-config`,body:o,...t??{}})}};var S=class{constructor(e){this.core=e}getAccess(e){return this.core.request({method:"GET",path:"/v1/me/access",...e??{}})}};var k=class{constructor(e){this.core=e}list(e,n,o,t){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/resources`,query:o,...t??{}})}create(e,n,o,t){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/resources`,body:o,...t??{}})}delete(e,n,o,t,s){return this.core.request({method:"DELETE",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(t)}`,...s??{}})}get(e,n,o,t,s){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(t)}`,...s??{}})}update(e,n,o,t,s,a){return this.core.request({method:"PUT",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(t)}`,body:s,...a??{}})}listChildren(e,n,o,t,s,a){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(t)}/children`,query:s,...a??{}})}getResourceUsers(e,n,o,t,s,a){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(t)}/users`,query:s,...a??{}})}};var b=class{constructor(e){this.core=e}provision(e,n,o){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/ssl/provision`,...o??{}})}getStatus(e,n,o){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/ssl/status`,...o??{}})}};var U=class{constructor(e){this.core=e}list(e,n,o,t){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/users`,query:o,...t??{}})}get(e,n,o,t){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/users/${encodeURIComponent(o)}`,...t??{}})}getUserResources(e,n,o,t){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(n)}/users/${encodeURIComponent(o)}/resources`,...t??{}})}};var P=class{constructor(e){this.core=e}list(e,n,o){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/members`,query:n,...o??{}})}remove(e,n,o){return this.core.request({method:"DELETE",path:`/v1/workspaces/${encodeURIComponent(e)}/members/${encodeURIComponent(n)}`,...o??{}})}updateRole(e,n,o,t){return this.core.request({method:"PUT",path:`/v1/workspaces/${encodeURIComponent(e)}/members/${encodeURIComponent(n)}/role`,body:o,...t??{}})}invite(e,n,o){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/members/invite`,body:n,...o??{}})}};var $=class{constructor(e){this.core=e}list(e){return this.core.request({method:"GET",path:"/v1/workspaces",...e??{}})}create(e,n){return this.core.request({method:"POST",path:"/v1/workspaces",body:e,...n??{}})}getCurrent(e,n){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}`,...n??{}})}update(e,n,o){return this.core.request({method:"PUT",path:`/v1/workspaces/${encodeURIComponent(e)}`,body:n,...o??{}})}};var w=class{apiKeys;definitions;dns;environments;me;resources;ssl;users;workspaceMembers;workspaces;constructor(e){let n={...e??{}};delete n.apiKey,delete n.bearer;let o=j(e??{}),t=new T.FetchClient({...n,baseURL:e?.baseURL??"https://runtime.blimu.dev",...o.length>0?{authStrategies:o}:{}});this.apiKeys=new R(t),this.definitions=new C(t),this.dns=new v(t),this.environments=new I(t),this.me=new S(t),this.resources=new k(t),this.ssl=new b(t),this.users=new U(t),this.workspaceMembers=new P(t),this.workspaces=new $(t)}};var r=require("zod"),X=r.z.object({is_tenant:r.z.boolean().optional(),roles:r.z.array(r.z.string()).min(1,"At least one role must be defined"),parents:r.z.record(r.z.string(),r.z.object({required:r.z.boolean()})).optional(),roles_inheritance:r.z.record(r.z.string().min(1),r.z.array(r.z.string().regex(/^([a-z0-9_-]+->)*[a-z0-9_-]+$/i)).min(1)).optional()}),Y=r.z.object({roles:r.z.array(r.z.string()).min(1).optional(),plans:r.z.array(r.z.string()).optional(),limit:r.z.string().optional()}),Z=r.z.object({name:r.z.string(),summary:r.z.string().optional(),entitlements:r.z.array(r.z.string()).optional(),plans:r.z.array(r.z.string()).optional(),default_enabled:r.z.boolean().optional()}),ee=r.z.object({name:r.z.string().min(1,"Plan name is required"),summary:r.z.string().optional(),description:r.z.string().min(1,"Plan description is required").optional(),resource_limits:r.z.record(r.z.string(),r.z.number().int().min(0)).optional(),usage_based_limits:r.z.record(r.z.string(),r.z.object({value:r.z.number().int().min(0),period:r.z.enum(["monthly","yearly","lifetime"])})).optional()}),G=r.z.object({resources:r.z.record(r.z.string().min(1),X),entitlements:r.z.record(r.z.string().min(1),Y).optional(),features:r.z.record(r.z.string().min(1),Z).optional(),plans:r.z.record(r.z.string().min(1),ee).optional()});function B(i){i.command("push").description("Push definitions to Blimu API").option("--config <path>","Path to Blimu config file (defaults to blimu.config.ts in project root)").option("--workspace-id <id>","Workspace ID (required)").option("--environment-id <id>","Environment ID (required)").option("--api-key <key>","API key for authentication").option("--bearer <token>","Bearer token for authentication").option("--base-url <url>","Base URL for the API","https://runtime.blimu.dev").action(async e=>{let n=c.spinner();try{e.workspaceId||(c.cancel("Workspace ID is required. Use --workspace-id <id>"),process.exit(1)),e.environmentId||(c.cancel("Environment ID is required. Use --environment-id <id>"),process.exit(1)),!e.apiKey&&!e.bearer&&(c.cancel("Authentication required. Provide either --api-key <key> or --bearer <token>"),process.exit(1));let o=e.config||y();o||(c.cancel("No config file found. Please provide --config or ensure blimu.config.ts exists in project root."),process.exit(1)),c.log.step(`Loading config from: ${o}`),n.start("Loading and validating config file...");let t=await _(o);n.stop("\u2713 Config loaded"),n.start("Validating config structure...");let s=G.safeParse(t);s.success||(n.stop("\u274C Config validation failed"),c.log.error("Config validation errors:"),s.error.issues.forEach(q=>{c.log.error(` - ${q.path.join(".")}: ${q.message}`)}),process.exit(1));let a=s.data;n.stop("\u2713 Config validated"),n.start("Connecting to Blimu API...");let f=new w({baseURL:e.baseUrl,...e.apiKey?{apiKey:e.apiKey}:{},...e.bearer?{bearer:e.bearer}:{}});n.stop("\u2713 Connected"),n.start("Pushing definitions to Blimu..."),await f.definitions.update(e.workspaceId,e.environmentId,{resources:a.resources,...a.entitlements?{entitlements:a.entitlements}:{},...a.features?{features:a.features}:{},...a.plans?{plans:a.plans}:{}}),n.stop("\u2713 Definitions pushed successfully"),c.log.success(`Successfully pushed definitions to workspace ${e.workspaceId}, environment ${e.environmentId}`)}catch(o){n.stop("\u274C Failed to push definitions"),c.log.error(`Failed to push definitions: ${o instanceof Error?o.message:String(o)}`),o instanceof Error&&o.stack&&c.log.error(o.stack),process.exit(1)}})}var O=new K.Command;O.name("blimu").description("Blimu - Authorization as a Service CLI").version(process.env.npm_package_version??"0.0.0");L(O);B(O);O.parse(); | ||
| "use strict";var Qe=Object.create;var D=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Xe=Object.getPrototypeOf,Ze=Object.prototype.hasOwnProperty;var et=(r,e)=>()=>(r&&(e=r(r=0)),e);var tt=(r,e)=>{for(var t in e)D(r,t,{get:e[t],enumerable:!0})},pe=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ye(e))!Ze.call(r,n)&&n!==t&&D(r,n,{get:()=>e[n],enumerable:!(o=He(e,n))||o.enumerable});return r};var f=(r,e,t)=>(t=r!=null?Qe(Xe(r)):{},pe(e||!r||!r.__esModule?D(t,"default",{value:r,enumerable:!0}):t,r)),nt=r=>pe(D({},"__esModule",{value:!0}),r);var Re={};tt(Re,{CLIENT_IDS:()=>Ce,DEFAULT_ENVIRONMENT:()=>at,getClientId:()=>T});function T(r){let e=Ce[r];if(!e||e.startsWith("client_id_for_"))throw new Error(`Client ID not configured for environment: ${r}. Please update CLIENT_IDS in client-ids.ts`);return e}var Ce,at,Y=et(()=>{"use strict";Ce={"local-dev":"9MhKB71lI9jF5p5OSfykG4juDo5hiGYm","local-prod":"client_id_for_local_prod","cloud-dev":"client_id_for_cloud_dev","cloud-prod":"client_id_for_cloud_prod"};at="cloud-prod"});var Je=require("commander");var C=f(require("path")),he=f(require("fs")),O=f(require("@clack/prompts"));var P=f(require("fs")),R=f(require("path"));function ue(r){let{configPath:e,outputPath:t,typesPackages:o=["@blimu/types","@blimu/backend"]}=r,n=[],i=o.join(" and ");n.push("/**"),n.push(` * Type Augmentation for ${i}`),n.push(" *"),n.push(` * This file augments the ${i} packages with union types`),n.push(" * specific to your environment configuration."),n.push(" *"),n.push(" * Types are automatically inferred from your blimu.config.ts file."),n.push(" * No regeneration needed when you update your config!"),n.push(" *"),n.push(" * Make sure to include this file in your tsconfig.json:"),n.push(" * {"),n.push(' * "include": ["blimu-types.d.ts"]'),n.push(" * }"),n.push(" */"),n.push("");let c=R.dirname(t),m=R.isAbsolute(e)?R.resolve(e):R.resolve(c,e),d=R.relative(c,m).replace(/\.(ts|mjs|js)$/,""),p=d.startsWith(".")?d:`./${d}`;n.push(`import type config from '${p}';`),n.push("import type {"),n.push(" InferResourceTypes,"),n.push(" InferEntitlementTypes,"),n.push(" InferPlanTypes,"),n.push(" InferLimitTypes,"),n.push(" InferUsageLimitTypes,"),n.push("} from 'blimu';"),n.push("");for(let v of o)n.push(`declare module '${v}' {`),n.push(" /**"),n.push(" * Resource types inferred from your Blimu configuration."),n.push(" */"),n.push(" type ResourceType = InferResourceTypes<typeof config>;"),n.push(""),n.push(" /**"),n.push(" * Entitlement types inferred from your Blimu configuration."),n.push(" */"),n.push(" type EntitlementType = InferEntitlementTypes<typeof config>;"),n.push(""),n.push(" /**"),n.push(" * Plan types inferred from your Blimu configuration."),n.push(" */"),n.push(" type PlanType = InferPlanTypes<typeof config>;"),n.push(""),n.push(" /**"),n.push(" * Limit types inferred from your Blimu configuration."),n.push(" */"),n.push(" type LimitType = InferLimitTypes<typeof config>;"),n.push(""),n.push(" /**"),n.push(" * Usage limit types inferred from your Blimu configuration."),n.push(" */"),n.push(" type UsageLimitType = InferUsageLimitTypes<typeof config>;"),n.push("}"),n.push("");P.existsSync(c)||P.mkdirSync(c,{recursive:!0}),P.writeFileSync(t,n.join(` | ||
| `),"utf-8")}var U=f(require("@clack/prompts")),$=f(require("chalk")),a={info:r=>{U.log.info(r)},step:r=>{U.log.step($.default.cyan(r))},success:r=>{U.log.success($.default.green(r))},warn:r=>{U.log.warn($.default.yellow(r))},error:r=>{U.log.error($.default.red(r))}};var g=f(require("path")),x=f(require("fs"));function B(){let r=[g.join(process.cwd(),"blimu.config.ts"),g.join(process.cwd(),"blimu.config.mjs"),g.join(process.cwd(),"blimu.config.js"),g.join(process.cwd(),"blimu.config.json")];for(let e of r)if(x.existsSync(e))return e;return null}async function le(r){let e=g.isAbsolute(r)?r:g.resolve(process.cwd(),r);if(!x.existsSync(e))throw new Error(`Config file not found: ${e}`);if(g.extname(e).toLowerCase()===".json"){let n=x.readFileSync(e,"utf-8");return JSON.parse(n)}let o=await import(e);return o.default||o}function de(r,e){let o=g.relative(r,e).replace(/\.(ts|mjs|js)$/,"");return o.startsWith(".")?o:`./${o}`}function fe(r){r.command("codegen").description("Generate type augmentation file from Blimu config").option("--config <path>","Path to Blimu config file (defaults to blimu.config.ts in project root)").option("--output <path>","Output path for generated type augmentation file (defaults to blimu-types.d.ts in project root)").action(e=>{let t=O.spinner();try{let o=e.config||B();o||(O.cancel("No config file found. Please provide --config or ensure blimu.config.ts exists in project root."),process.exit(1));let n=C.isAbsolute(o)?o:C.resolve(process.cwd(),o);he.existsSync(n)||(O.cancel(`Config file not found: ${n}`),process.exit(1)),a.step(`Using config file: ${n}`);let i=e.output?C.isAbsolute(e.output)?e.output:C.resolve(process.cwd(),e.output):C.join(process.cwd(),"blimu-types.d.ts");a.step(`Output: ${i}`);let c=C.dirname(i),m=de(c,n);t.start("Generating type augmentation file with type inference..."),ue({configPath:m,outputPath:i}),t.stop("\u26A1\uFE0F Successfully generated type augmentation file"),a.success(`Generated at: ${i}`),a.info("\u{1F4A1} Tip: Types are automatically inferred from your config."),a.info(" No regeneration needed when you update blimu.config.ts!")}catch(o){t.stop("\u274C Failed to generate type augmentation"),a.error(`Failed to generate type augmentation: ${o instanceof Error?o.message:String(o)}`),o instanceof Error&&o.stack&&a.error(o.stack),process.exit(1)}})}var w=f(require("@clack/prompts"));var s=require("zod"),ot=s.z.object({is_tenant:s.z.boolean().optional(),roles:s.z.array(s.z.string()).min(1,"At least one role must be defined"),parents:s.z.record(s.z.string(),s.z.object({required:s.z.boolean()})).optional(),roles_inheritance:s.z.record(s.z.string().min(1),s.z.array(s.z.string().regex(/^([a-z0-9_-]+->)*[a-z0-9_-]+$/i)).min(1)).optional()}),rt=s.z.object({roles:s.z.array(s.z.string()).min(1).optional(),plans:s.z.array(s.z.string()).optional(),limit:s.z.string().optional()}),it=s.z.object({name:s.z.string(),summary:s.z.string().optional(),entitlements:s.z.array(s.z.string()).optional(),plans:s.z.array(s.z.string()).optional(),default_enabled:s.z.boolean().optional()}),st=s.z.object({name:s.z.string().min(1,"Plan name is required"),summary:s.z.string().optional(),description:s.z.string().min(1,"Plan description is required").optional(),resource_limits:s.z.record(s.z.string(),s.z.number().int().min(0)).optional(),usage_based_limits:s.z.record(s.z.string(),s.z.object({value:s.z.number().int().min(0),period:s.z.enum(["monthly","yearly","lifetime"])})).optional()}),ge=s.z.object({resources:s.z.record(s.z.string().min(1),ot),entitlements:s.z.record(s.z.string().min(1),rt).optional(),features:s.z.record(s.z.string().min(1),it).optional(),plans:s.z.record(s.z.string().min(1),st).optional()});var ae=require("@blimu/fetch");function ye(r){let e=[...r?.authStrategies??[]];return r.bearer&&e.push({type:"bearer",token:r.bearer}),r.apiKey&&e.push({type:"apiKey",key:r.apiKey,location:"header",name:"X-API-KEY"}),e}var L=class{constructor(e){this.core=e}list(e,t,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/api-keys`,...o??{}})}create(e,t,o,n){return this.core.request({method:"POST",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/api-keys`,body:o,...n??{}})}delete(e,t,o,n){return this.core.request({method:"DELETE",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/api-keys/${encodeURIComponent(o)}`,...n??{}})}get(e,t,o,n){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/api-keys/${encodeURIComponent(o)}`,...n??{}})}reveal(e,t,o,n){return this.core.request({method:"POST",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/api-keys/${encodeURIComponent(o)}/reveal`,...n??{}})}};var F=class{constructor(e){this.core=e}get(e,t,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/definitions`,...o??{}})}update(e,t,o,n){return this.core.request({method:"PUT",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/definitions`,body:o,...n??{}})}validate(e,t,o,n){return this.core.request({method:"POST",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/definitions/validate`,body:o,...n??{}})}};var j=class{constructor(e){this.core=e}getRecords(e,t,o){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/dns/records`,...o??{}})}validate(e,t,o){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/dns/validate`,...o??{}})}};var K=class{constructor(e){this.core=e}list(e,t,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments`,query:t,...o??{}})}create(e,t,o){return this.core.request({method:"POST",path:`/v1/workspace/${encodeURIComponent(e)}/environments`,body:t,...o??{}})}delete(e,t,o){return this.core.request({method:"DELETE",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}`,...o??{}})}read(e,t,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}`,...o??{}})}update(e,t,o,n){return this.core.request({method:"PUT",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}`,body:o,...n??{}})}getAuthConfig(e,t,o){return this.core.request({method:"GET",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/auth-config`,...o??{}})}updateAuthConfig(e,t,o,n){return this.core.request({method:"PUT",path:`/v1/workspace/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/auth-config`,body:o,...n??{}})}};var N=class{constructor(e){this.core=e}getAccess(e){return this.core.request({method:"GET",path:"/v1/me/access",...e??{}})}};var G=class{constructor(e){this.core=e}list(e,t,o,n){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/oauth-apps`,query:o,...n??{}})}create(e,t,o,n){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/oauth-apps`,body:o,...n??{}})}delete(e,t,o,n){return this.core.request({method:"DELETE",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/oauth-apps/${encodeURIComponent(o)}`,...n??{}})}getById(e,t,o,n){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/oauth-apps/${encodeURIComponent(o)}`,...n??{}})}update(e,t,o,n,i){return this.core.request({method:"PUT",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/oauth-apps/${encodeURIComponent(o)}`,body:n,...i??{}})}revokeAllTokens(e,t,o,n){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/oauth-apps/${encodeURIComponent(o)}/revoke-all`,...n??{}})}rotateSecret(e,t,o,n){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/oauth-apps/${encodeURIComponent(o)}/rotate-secret`,...n??{}})}listTokens(e,t,o,n,i){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/oauth-apps/${encodeURIComponent(o)}/tokens`,query:n,...i??{}})}};var M=class{constructor(e){this.core=e}list(e,t,o,n){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/resources`,query:o,...n??{}})}create(e,t,o,n){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/resources`,body:o,...n??{}})}delete(e,t,o,n,i){return this.core.request({method:"DELETE",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(n)}`,...i??{}})}get(e,t,o,n,i){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(n)}`,...i??{}})}update(e,t,o,n,i,c){return this.core.request({method:"PUT",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(n)}`,body:i,...c??{}})}listChildren(e,t,o,n,i,c){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(n)}/children`,query:i,...c??{}})}getResourceUsers(e,t,o,n,i,c){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/resources/${encodeURIComponent(o)}/${encodeURIComponent(n)}/users`,query:i,...c??{}})}};var W=class{constructor(e){this.core=e}provision(e,t,o){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/ssl/provision`,...o??{}})}getStatus(e,t,o){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/ssl/status`,...o??{}})}};var V=class{constructor(e){this.core=e}list(e,t,o,n){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/users`,query:o,...n??{}})}get(e,t,o,n){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/users/${encodeURIComponent(o)}`,...n??{}})}getUserResources(e,t,o,n){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/environments/${encodeURIComponent(t)}/users/${encodeURIComponent(o)}/resources`,...n??{}})}};var z=class{constructor(e){this.core=e}list(e,t,o){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}/members`,query:t,...o??{}})}remove(e,t,o){return this.core.request({method:"DELETE",path:`/v1/workspaces/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,...o??{}})}updateRole(e,t,o,n){return this.core.request({method:"PUT",path:`/v1/workspaces/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}/role`,body:o,...n??{}})}invite(e,t,o){return this.core.request({method:"POST",path:`/v1/workspaces/${encodeURIComponent(e)}/members/invite`,body:t,...o??{}})}};var J=class{constructor(e){this.core=e}list(e){return this.core.request({method:"GET",path:"/v1/workspaces",...e??{}})}create(e,t){return this.core.request({method:"POST",path:"/v1/workspaces",body:e,...t??{}})}getCurrent(e,t){return this.core.request({method:"GET",path:`/v1/workspaces/${encodeURIComponent(e)}`,...t??{}})}update(e,t,o){return this.core.request({method:"PUT",path:`/v1/workspaces/${encodeURIComponent(e)}`,body:t,...o??{}})}};var E=class{apiKeys;definitions;dns;environments;me;oauthApps;resources;ssl;users;workspaceMembers;workspaces;constructor(e){let t={...e??{}};delete t.apiKey,delete t.bearer;let o=ye(e??{}),n=new ae.FetchClient({...t,baseURL:e?.baseURL??"https://runtime.blimu.dev",...o.length>0?{authStrategies:o}:{}});this.apiKeys=new L(n),this.definitions=new F(n),this.dns=new j(n),this.environments=new K(n),this.me=new N(n),this.oauthApps=new G(n),this.resources=new M(n),this.ssl=new W(n),this.users=new V(n),this.workspaceMembers=new z(n),this.workspaces=new J(n)}};var we=require("fs");var Q=require("os"),H=require("path"),ce=require("fs"),h={credentials:(0,H.join)((0,Q.homedir)(),".blimu","credentials.json"),config:{primary:(0,H.join)((0,Q.homedir)(),".blimurc.json"),xdg:(0,H.join)((0,Q.homedir)(),".config","blimu","config.json")}};function ve(){return(0,ce.existsSync)(h.config.primary)?h.config.primary:(0,ce.existsSync)(h.config.xdg)?h.config.xdg:null}function X(){let r=ve();if(!r)return null;try{let e=(0,we.readFileSync)(r,"utf-8");return JSON.parse(e)}catch{return null}}function be(r,e){return r||(e?.blimuInternalEnvironment?e.blimuInternalEnvironment:(Y(),nt(Re)).DEFAULT_ENVIRONMENT)}var Ie={"local-dev":"https://runtime-api.dev-blimu.dev","local-prod":"https://runtime-api.dev-blimu.dev","cloud-dev":"https://api.blimu.dev","cloud-prod":"https://api.blimu.dev"},ke={"local-dev":"https://platform-api.dev-blimu.dev","local-prod":"https://platform.blimu.dev","cloud-dev":"https://platform.blimu.dev","cloud-prod":"https://platform.blimu.dev"};function Z(r,e,t){return r||(e?.runtimeApiBaseUrl?e.runtimeApiBaseUrl:t&&Ie[t]?Ie[t]:"https://runtime.blimu.dev")}function Se(r,e,t){return r||(e?.platformApiBaseUrl?e.platformApiBaseUrl:t&&ke[t]?ke[t]:"https://platform.blimu.dev")}var l=require("fs"),Ue=require("path");var A="blimu-cli",ee=null,Pe=null;async function q(){return ee||(Pe??=import("@napi-rs/keyring"),ee=await Pe),ee.Entry}async function Ee(){try{let r=await q(),e=new r(A,"test-availability");return e.setPassword("test"),e.deletePassword(),!0}catch{return!1}}async function _e(r){let e=`refresh-token-${r}`;try{let t=await q(),n=new t(A,e).getPassword();if(n)return n}catch{}if((0,l.existsSync)(h.credentials))try{let t=(0,l.readFileSync)(h.credentials,"utf-8"),o=JSON.parse(t);if(o._keychain_unavailable&&o.refresh_token)return o.refresh_token}catch{}return null}async function te(r,e){let t=`refresh-token-${r}`;try{let i=await q();return new i(A,t).setPassword(e),{usedKeychain:!0}}catch{}let n={...y(),refresh_token:e,_keychain_unavailable:!0,environment:r};return _(n),{usedKeychain:!1}}async function $e(r){let e=`refresh-token-${r}`;try{let t=await q();new t(A,e).deletePassword()}catch{}if((0,l.existsSync)(h.credentials))try{let t=(0,l.readFileSync)(h.credentials,"utf-8"),o=JSON.parse(t);if(o._keychain_unavailable){let{refresh_token:n,_keychain_unavailable:i,...c}=o;_(c)}}catch{}}async function xe(r,e){let t=`code-verifier-${r}`;try{let o=await q();return new o(A,t).setPassword(e),{usedKeychain:!0}}catch{return{usedKeychain:!1}}}function y(){if(!(0,l.existsSync)(h.credentials))throw new Error("No credentials found. Please run `blimu login` first.");try{let r=(0,l.readFileSync)(h.credentials,"utf-8");return JSON.parse(r)}catch(r){throw new Error(`Failed to read credentials: ${r instanceof Error?r.message:String(r)}`)}}function _(r){let e=(0,Ue.dirname)(h.credentials);(0,l.existsSync)(e)||(0,l.mkdirSync)(e,{recursive:!0,mode:448}),(0,l.writeFileSync)(h.credentials,JSON.stringify(r,null,2),"utf-8"),(0,l.chmodSync)(h.credentials,384)}function Oe(){(0,l.existsSync)(h.credentials)&&(0,l.unlinkSync)(h.credentials)}function me(){return(0,l.existsSync)(h.credentials)}async function ct(r,e,t){let o=await _e(t);if(!o)throw new Error("No refresh token found. Please run `blimu login` again.");let n=await fetch(`${r}/v1/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",client_id:e,refresh_token:o})});if(!n.ok){let u=await n.json().catch(()=>({}));throw new Error(u.error_description??u.error??`HTTP ${n.status}: ${n.statusText}`)}let i=await n.json(),c=Math.floor(Date.now()/1e3)+i.expires_in,m=y();return _({...m,access_token:i.access_token,expires_at:c,environment:t}),i.refresh_token!==o&&await te(t,i.refresh_token),{access_token:i.access_token,expires_at:c,refresh_token:i.refresh_token}}function mt(r=60){try{let e=y(),t=Math.floor(Date.now()/1e3);return e.expires_at-t<r}catch{return!0}}async function Te(r,e,t){return mt()?(await ct(r,e,t)).access_token:y().access_token}Y();async function Ae(r={}){let{apiKey:e,bearer:t,platformApiUrl:o,requireAuth:n=!0,spinner:i}=r,c=X(),m;if(me())try{m=y().environment??c?.blimuInternalEnvironment}catch{m=c?.blimuInternalEnvironment}else m=c?.blimuInternalEnvironment;let u=o??Se(void 0,c,m)??"https://platform.blimu.dev",d=e,p=t;if(d||p)return new E({baseURL:u,...d?{apiKey:d}:{},...p?{bearer:p}:{}});if(!n)return new E({baseURL:u});if(!me())throw new Error("Authentication required. Please run `blimu login` first or provide --api-key <key> or --bearer <token>");try{let I=y().environment??c?.blimuInternalEnvironment??"cloud-prod",ie=Z(void 0,c,I),se=T(I);i&&i.start("Refreshing authentication token..."),p=await Te(ie,se,I),i&&i.stop("\u2713 Token refreshed")}catch(v){throw i&&i.stop("\u274C Failed to refresh token"),new Error(`Failed to authenticate: ${v instanceof Error?v.message:String(v)} | ||
| Please run \`blimu login\` again.`)}return new E({baseURL:u,bearer:p})}function qe(r){r.command("push").description("Push definitions to Blimu API").option("--config <path>","Path to Blimu config file (defaults to blimu.config.ts in project root)").option("--workspace-id <id>","Workspace ID (required)").option("--environment-id <id>","Environment ID (required)").option("--platform-api-url <url>","Override Platform API base URL").action(async e=>{let t=w.spinner();try{e.workspaceId||(w.cancel("Workspace ID is required. Use --workspace-id <id>"),process.exit(1)),e.environmentId||(w.cancel("Environment ID is required. Use --environment-id <id>"),process.exit(1));let o;try{t.start("Connecting to Blimu API..."),o=await Ae({...e.apiKey?{apiKey:e.apiKey}:{},...e.bearer?{bearer:e.bearer}:{},...e.platformApiUrl?{platformApiUrl:e.platformApiUrl}:{},requireAuth:!0,spinner:t}),t.stop("\u2713 Connected")}catch(u){t.stop("\u274C Failed to connect"),w.cancel(u instanceof Error?u.message:String(u)),process.exit(1)}let n=e.config??B();n||(w.cancel("No config file found. Please provide --config or ensure blimu.config.ts exists in project root."),process.exit(1)),a.step(`Loading config from: ${n}`),t.start("Loading and validating config file...");let i=await le(n);t.stop("\u2713 Config loaded"),t.start("Validating config structure...");let c=ge.safeParse(i);c.success||(t.stop("\u274C Config validation failed"),a.error("Config validation errors:"),c.error.issues.forEach(u=>{a.error(` - ${u.path.join(".")}: ${u.message}`)}),process.exit(1));let m=c.data;t.stop("\u2713 Config validated"),t.start("Pushing definitions to Blimu..."),await o.definitions.update(e.workspaceId,e.environmentId,{resources:m.resources,...m.entitlements?{entitlements:m.entitlements}:{},...m.features?{features:m.features}:{},...m.plans?{plans:m.plans}:{}}),t.stop("\u2713 Definitions pushed successfully"),a.success(`Successfully pushed definitions to workspace ${e.workspaceId}, environment ${e.environmentId}`)}catch(o){t.stop("\u274C Failed to push definitions"),a.error(`Failed to push definitions: ${o instanceof Error?o.message:String(o)}`),o instanceof Error&&o.stack&&a.error(o.stack),process.exit(1)}})}var je=require("@clack/prompts"),Ke=f(require("open"));var b=require("@blimu/backend");var ne=require("crypto");function De(){let r=(0,ne.randomBytes)(96);return Le(r)}function Be(r){let e=(0,ne.createHash)("sha256").update(r).digest();return Le(e)}function Le(r){return r.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}async function Fe(r,e={}){let{initialInterval:t=5,maxInterval:o=60,maxAttempts:n=120,timeout:i=6e5}=e,c=Date.now(),m=t,u=0;for(;u<n;){if(Date.now()-c>i)throw new Error("Login timed out");u>0&&await pt(m*1e3),u++;try{let d=await r();if(d.success)return d.data;let p=d.error;if(p.error==="authorization_pending")continue;if(p.error==="slow_down"){m=Math.min(m+5,o);continue}throw p.error==="access_denied"?new Error("Authorization was denied"):p.error==="expired_token"?new Error("Login session has expired"):new Error(p.error_description??p.error??"Authorization failed")}catch(d){throw d instanceof Error?d:new Error(`Polling error: ${String(d)}`)}}throw new Error("Login timed out")}function pt(r){return new Promise(e=>setTimeout(e,r))}var re=require("undici");function ut(){let r=new re.Agent({connect:{rejectUnauthorized:!1}});return async(e,t)=>(0,re.fetch)(e,{...t,dispatcher:r})}var oe=class{constructor(e,t,o){this.runtimeApiBaseUrl=e;this.clientId=t;this.environment=o;let n=this.environment==="local-dev"||this.environment==="local-prod"?ut():void 0;this.client=new b.Blimu({baseURL:e,...n?{fetch:n}:{}})}client;async requestDeviceCode(){let e=De(),t=Be(e);try{return{deviceCodeResponse:await this.client.oauth.requestDeviceCode({client_id:this.clientId,code_challenge:t,code_challenge_method:"S256"}),codeVerifier:e,codeChallenge:t}}catch(o){if(o instanceof b.FetchError){let n=o.data||{};if(o.status===0){let i=o.message||"Unknown network error";throw new Error(`Failed to connect to ${this.runtimeApiBaseUrl}. ${i} | ||
| This usually means: | ||
| - The server is not running or not reachable | ||
| - DNS resolution failed | ||
| - SSL/TLS certificate issues | ||
| - Network connectivity problems | ||
| Please verify that the Runtime API is accessible at: ${this.runtimeApiBaseUrl}`)}throw new Error(n.error_description??n.error??o.message??"Request failed")}throw o}}async pollForTokens(e,t,o){return Fe(async()=>{try{return{success:!0,data:await this.client.oauth.exchangeDeviceCode({grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:e,client_id:this.clientId,code_verifier:t})}}catch(n){if(n instanceof b.BadRequestError)return{success:!1,error:{error:n.message,error_description:n.message}};if(n instanceof b.FetchError){if(n.status===0)throw new Error(`Network error while polling for tokens: ${n.message||"Connection failed"} | ||
| Please verify that the Runtime API is accessible at: ${this.runtimeApiBaseUrl}`);return{success:!1,error:{error:`http_${n.status}`,error_description:n.message||`HTTP ${n.status} error`}}}let i=n instanceof Error?n.message:String(n);throw new Error(`Unexpected error while polling for tokens: ${i}`)}},{initialInterval:o,maxInterval:60,maxAttempts:120,timeout:6e5})}};Y();function Ne(r){r.command("login").description("Authenticate with Blimu using OAuth2 device flow").option("--exec-env <env>","Blimu internal environment (local-dev, local-prod, cloud-dev, cloud-prod)").option("--runtime-api-url <url>","Override Runtime API base URL").option("--verbose","Show detailed output",!1).action(async e=>{let t=(0,je.spinner)(),o=e.verbose;try{let n=X(),i=be(e.execEnv,n),c=Z(e.runtimeApiUrl,n,i);o&&a.info(`Runtime API: ${c}`);let m=T(i);a.step(`Authenticating to ${i} environment...`),await Ee()||a.warn("System keychain not available. Refresh token will be stored in plaintext at ~/.blimu/credentials.json");let d=new oe(c,m,i);o&&t.start("Requesting device code...");let{deviceCodeResponse:p,codeVerifier:v}=await d.requestDeviceCode();o&&t.stop("Device code received"),a.info("To complete authentication, please visit:"),a.info(` ${p.verification_uri_complete}`),a.info(`Or enter this code: ${p.user_code}`);try{await(0,Ke.default)(p.verification_uri_complete)}catch{}await xe(i,v),t.start("Waiting for authorization...");let I=await d.pollForTokens(p.device_code,v,p.interval);t.stop();let ie=Math.floor(Date.now()/1e3)+I.expires_in;_({access_token:I.access_token,token_type:I.token_type,expires_at:ie,environment:i});let{usedKeychain:se}=await te(i,I.refresh_token);a.success("Successfully authenticated!"),o&&(se?a.info("Refresh token stored in system keychain"):a.info("Refresh token stored in credentials file"))}catch(n){let i=n instanceof Error?n.message:String(n);a.error(`Authentication failed: ${lt(i)}`),o&&n instanceof Error&&n.stack&&a.info(n.stack),process.exit(1)}})}function lt(r){let e=r.replace(/^HTTP \d+:\s*/i,"");return{"Invalid request":"The authorization request was invalid. Please try again.","User denied authorization":"Authorization was denied.","Device code has expired":"The login session has expired. Please try again.","Polling timeout exceeded":"Login timed out. Please try again.","Maximum polling attempts exceeded":"Login timed out. Please try again."}[e]??e}var Ge=f(require("@clack/prompts"));function Me(r){r.command("logout").description("Log out and remove stored credentials").action(async()=>{let e=Ge.spinner();try{let t;try{t=y().environment}catch{a.info("No credentials found. Already logged out.");return}e.start("Removing credentials..."),t&&await $e(t),Oe(),e.stop("\u2713 Credentials removed"),a.success("Successfully logged out!")}catch(t){e.stop("\u274C Logout failed"),a.error(`Failed to logout: ${t instanceof Error?t.message:String(t)}`),process.exit(1)}})}function We(r){return Object.entries(r).map(([e,t])=>{let o;return t==null?o="":typeof t=="object"?o=JSON.stringify(t):o=String(t),`${e}: ${o}`.trimEnd()}).join(` | ||
| `)}function Ve(r){try{let e=r.split(".");if(e.length!==3)return null;let t=e[1];if(!t)return null;let o=Buffer.from(t,"base64url").toString("utf-8");return JSON.parse(o)}catch{return null}}var k=f(require("chalk"));function dt(r){return new Date(r*1e3).toLocaleString()}function ze(r){r.command("whoami").description("Display current authentication information").action(()=>{try{let e=y(),t=Ve(e.access_token),o=Math.floor(Date.now()/1e3),n=e.expires_at-o,i={...t?.sub?{[`${k.default.cyan("@userid")}`]:t.sub}:{},...t?.email?{[`${k.default.cyan("@email")}`]:t.email}:{},...t?.name?{[`${k.default.cyan("@name")}`]:t.name}:{},[`${k.default.cyan("@environment")}`]:e.environment??"unknown",[`${k.default.cyan("@expires")}`]:dt(e.expires_at),...n>0?{[`${k.default.cyan("@expires_in")}`]:`${Math.floor(n/60)} minutes`}:{[`${k.default.red("@expired")}`]:!0}};a.info(`Current authentication: | ||
| `+We(i)+` | ||
| `)}catch(e){e instanceof Error&&e.message.includes("No credentials found")?a.error("Not authenticated. Please run `blimu login` first."):a.error(`Failed to get user info: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}})}var S=new Je.Command;S.name("blimu").description("Blimu - Authorization as a Service CLI").version(process.env.npm_package_version??"0.0.0");fe(S);qe(S);Ne(S);Me(S);ze(S);S.parse(); | ||
| //# sourceMappingURL=main.cjs.map |
+13
-6
| { | ||
| "name": "blimu", | ||
| "version": "1.2.0", | ||
| "version": "1.2.1", | ||
| "description": "Blimu - Authorization as a Service CLI", | ||
@@ -28,2 +28,3 @@ "main": "dist/index.cjs", | ||
| "dev": "tsx watch src/main.ts", | ||
| "cli": "tsx src/main.ts", | ||
| "typecheck": "tsc --noEmit", | ||
@@ -35,13 +36,19 @@ "test": "vitest run", | ||
| "dependencies": { | ||
| "@blimu/fetch": "^0.4.0", | ||
| "@clack/prompts": "^0.11.0", | ||
| "@blimu/backend": "1.2.1", | ||
| "@blimu/fetch": "^0.4.2", | ||
| "@clack/prompts": "^1.0.0", | ||
| "@napi-rs/keyring": "^1.2.0", | ||
| "chalk": "^5.6.2", | ||
| "commander": "^14.0.2", | ||
| "zod": "^4.3.5" | ||
| "open": "^11.0.0", | ||
| "undici": "^7.19.2", | ||
| "zod": ">=4.3.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^25.0.9", | ||
| "@types/node": "^25.1.0", | ||
| "msw": "^2.12.7", | ||
| "tsup": "^8.5.1", | ||
| "tsx": "^4.21.0", | ||
| "typescript": "^5.9.3", | ||
| "vitest": "^4.0.17" | ||
| "vitest": "^4.0.18" | ||
| }, | ||
@@ -48,0 +55,0 @@ "repository": { |
Sorry, the diff of this file is too big to display
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
188909
75.33%376
20.13%9
125%6
20%8
60%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated
Updated