sharetribe-cli 1.15.1 → 1.16.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 +12 -9
- package/dist/index.js.map +3 -3
- package/package.json +5 -3
- package/src/commands/assets/index.ts +372 -85
- package/src/commands/debug.ts +6 -16
- package/src/commands/search/index.ts +19 -7
- package/test/assets.test.ts +156 -0
- package/test/help-comparison.test.ts +29 -0
- package/test/strict-comparison.test.ts +13 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import{Command as _t}from"commander";import{readFileSync as Lt}from"node:fs";import{fileURLToPath as Nt}from"node:url";import{dirname as $t,join as jt}from"node:path";import{readFileSync as Se}from"node:fs";import{fileURLToPath as ke}from"node:url";import{dirname as V,join as ve}from"node:path";function Ae(){let r=ke(import.meta.url),t=V(r);for(;t!=="/";)try{let e=ve(t,"package.json");return Se(e,"utf-8")}catch{t=V(t)}throw new Error("Could not find package.json")}function H(){let r=JSON.parse(Ae());console.log(r.version)}import we from"inquirer";import{writeAuth as Ce}from"sharetribe-flex-build-sdk";async function J(){let r=await we.prompt([{type:"password",name:"apiKey",message:"Enter API key:",mask:"*",validate:t=>!t||t.trim().length===0?"API key cannot be empty":!0}]);Ce({apiKey:r.apiKey}),console.log("Successfully logged in.")}import{clearAuth as Pe}from"sharetribe-flex-build-sdk";async function B(){await Pe(),console.log("Successfully logged out.")}import{listProcesses as Ie,listProcessVersions as Oe}from"sharetribe-flex-build-sdk";import O from"chalk";function S(r,t){if(t.length===0)return;let e={};for(let n of r)e[n]=n.length+1;for(let n of t)for(let i of r){let a=n[i]||"";e[i]=Math.max(e[i]||0,a.length)}console.log("");let o=r.map((n,i)=>{let a=e[n]||0,m=n.padEnd(a+1);return i===r.length-1?m:m+" "}).join("");console.log(O.bold.black(o));for(let n of t){let a=r.map((m,l)=>{let d=n[m]||"",p=e[m]||0,u=d.padEnd(p+1);return l===r.length-1?u:u+" "}).join("");console.log(a)}console.log("")}function c(r){console.error(O.red(`Error: ${r}`))}function h(r){console.log(O.green(r))}function be(r){try{let t=new Date(r),e=t.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0"),n=t.toLocaleTimeString("en-US");return`${e}-${s}-${o} ${n}`}catch{return r}}async function b(r,t){try{if(t){let e=await Oe(void 0,r,t);if(e.length===0){console.log(`No versions found for process: ${t}`);return}let s=e.map(o=>({Created:be(o.createdAt),Version:o.version.toString(),Aliases:o.aliases?.join(", ")||"",Transactions:o.transactionCount?.toString()||"0"}));S(["Created","Version","Aliases","Transactions"],s)}else{let e=await Ie(void 0,r);if(e.length===0){console.log("No processes found.");return}let s=e.map(o=>({Name:o.name,"Latest version":o.version?.toString()||""}));S(["Name","Latest version"],s)}}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to list processes"),process.exit(1)}}import{createProcess as xe}from"sharetribe-flex-build-sdk";import{readFileSync as Re}from"node:fs";import{join as qe}from"node:path";async function x(r,t,e){try{let s=qe(e,"process.edn"),o=Re(s,"utf-8"),n=await xe(void 0,r,t,o);h(`Process ${n.name} successfully created with version ${n.version}.`)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to create process"),process.exit(1)}}import{pushProcess as Te}from"sharetribe-flex-build-sdk";import{readFileSync as R,readdirSync as Me}from"node:fs";import{join as A}from"node:path";function De(r){let t=A(r,"templates"),e=[];try{let s=Me(t);for(let o of s){let n=A(t,o),i=A(n,`${o}-html.html`),a=A(n,`${o}-subject.txt`);try{let m=R(i,"utf-8"),l=R(a,"utf-8");e.push({name:o,html:m,subject:l})}catch{}}}catch{}return e}async function q(r,t,e){try{let s=A(e,"process.edn"),o=R(s,"utf-8"),n=De(e),i=await Te(void 0,r,t,o,n);i.noChanges?console.log("No changes"):h(`Version ${i.version} successfully saved for process ${t}.`)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to push process"),process.exit(1)}}import{getProcess as _e}from"sharetribe-flex-build-sdk";import{writeFileSync as T,mkdirSync as M}from"node:fs";import{join as w}from"node:path";async function D(r,t,e,s,o){try{let n=await _e(void 0,r,t,{version:s,alias:o});if(!n.definition)throw new Error("No process definition in response");let{existsSync:i}=await import("node:fs"),a=i(e);M(e,{recursive:!0}),a||console.error(`Creating a new directory: ${e}`);let m=w(e,"process.edn");T(m,n.definition,"utf-8");let l=n.emailTemplates||[];if(l&&Array.isArray(l)&&l.length>0){let d=w(e,"templates");M(d,{recursive:!0});for(let p of l){let u=p.name,y=p.html,U=p.subject;if(u){let P=w(d,u);if(M(P,{recursive:!0}),y){let I=w(P,`${u}-html.html`);T(I,y,"utf-8")}if(U){let I=w(P,`${u}-subject.txt`);T(I,U,"utf-8")}}}}console.error(`Saved process to ${e}`)}catch(n){n&&typeof n=="object"&&"message"in n?c(n.message):c("Failed to pull process"),process.exit(1)}}import{createAlias as Le,updateAlias as Ne,deleteAlias as $e}from"sharetribe-flex-build-sdk";async function _(r,t,e,s){try{let o=await Le(void 0,r,t,e,s);h(`Alias ${o.alias} successfully created to point to version ${o.version}.`)}catch(o){o&&typeof o=="object"&&"message"in o?c(o.message):c("Failed to create alias"),process.exit(1)}}async function L(r,t,e,s){try{let o=await Ne(void 0,r,t,e,s);h(`Alias ${o.alias} successfully updated to point to version ${o.version}.`)}catch(o){o&&typeof o=="object"&&"message"in o?c(o.message):c("Failed to update alias"),process.exit(1)}}async function N(r,t,e){try{let s=await $e(void 0,r,t,e);h(`Alias ${s.alias} successfully deleted.`)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to delete alias"),process.exit(1)}}import{deployProcess as je,parseProcessFile as Fe}from"sharetribe-flex-build-sdk";import{readFileSync as Ke}from"node:fs";import{join as Ue}from"node:path";async function $(r,t,e,s){try{let o=Ue(e,"process.edn"),n=Ke(o,"utf-8"),i=Fe(n),a=await je(void 0,r,{process:t,alias:s,path:o,processDefinition:i});a.processCreated&&h(`Process ${t} successfully created.`),h(`Version ${a.version} successfully saved for process ${t}.`),a.aliasCreated?h(`Alias ${a.alias} successfully created to point to version ${a.version}.`):h(`Alias ${a.alias} successfully updated to point to version ${a.version}.`)}catch(o){o&&typeof o=="object"&&"message"in o?c(o.message):c("Failed to create/push process and alias"),process.exit(1)}}function W(r){let t=r.command("process").description("describe a process file").option("--path <PROCESS_DIR>","path to the directory where the process.edn file is").option("--transition <TRANSITION_NAME>","transition name, e.g. transition/request to get more details of it").action(async e=>{e.path?(console.log(`Describing process at: ${e.path}`),e.transition&&console.log(`Transition: ${e.transition}`),console.log("Process description not yet implemented")):t.outputHelp()});t.command("list").description("list all transaction processes").option("--process <PROCESS_NAME>","print version and alias info of a specific process").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await b(s,e.process)}),t.command("create").description("create a new transaction process").requiredOption("--process <PROCESS_NAME>","name for the new process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory where the process.edn file is").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await x(s,e.process,e.path)}),t.command("push").description("push a process file to the remote").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory where the process.edn file is").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await q(s,e.process,e.path)}),t.command("pull").description("fetch a process file").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path where to save the process").option("--version <VERSION_NUM>","version number").option("--alias <PROCESS_ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await D(s,e.process,e.path,e.version,e.alias)}),t.command("create-alias").description("create a new alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--version <VERSION_NUM>","version number").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").allowUnknownOption(!1).action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await _(s,e.process,parseInt(e.version),e.alias)}),t.command("update-alias").description("update an existing alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--version <VERSION_NUM>","version number").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await L(s,e.process,parseInt(e.version),e.alias)}),t.command("delete-alias").description("delete an existing alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await N(s,e.process,e.alias)}),t.command("deploy").description("deploy a process file with alias (create/push + alias create/update)").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory with the process files").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await $(s,e.process,e.path,e.alias)}),r.command("process-list",{hidden:!0}).description("list all transaction processes").option("--process <PROCESS_NAME>","print version and alias info of a specific process").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await b(s,e.process)}),r.command("process-create",{hidden:!0}).description("create a new transaction process").requiredOption("--process <PROCESS_NAME>","name for the new process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory where the process.edn file is").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await x(s,e.process,e.path)}),r.command("process-push",{hidden:!0}).description("push a process file to the remote").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory where the process.edn file is").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await q(s,e.process,e.path)}),r.command("process-pull",{hidden:!0}).description("fetch a process file").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path where to save the process").option("--version <VERSION_NUM>","version number").option("--alias <PROCESS_ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await D(s,e.process,e.path,e.version,e.alias)}),r.command("process-create-alias",{hidden:!0}).description("create a new alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--version <VERSION_NUM>","version number").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await _(s,e.process,parseInt(e.version),e.alias)}),r.command("process-update-alias",{hidden:!0}).description("update an existing alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--version <VERSION_NUM>","version number").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await L(s,e.process,parseInt(e.version),e.alias)}),r.command("process-delete-alias",{hidden:!0}).description("delete an existing alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await N(s,e.process,e.alias)}),r.command("process-deploy",{hidden:!0}).description("deploy a process file with alias (create/push + alias create/update)").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory with the process files").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await $(s,e.process,e.path,e.alias)})}import{listSearchSchemas as Ve,setSearchSchema as He,unsetSearchSchema as Je}from"sharetribe-flex-build-sdk";var G={metadata:"Metadata",private:"Private data",protected:"Protected data",public:"Public data"};async function Be(r,t){try{await He(void 0,r,{key:t.key,scope:t.scope,type:t.type,doc:t.doc,defaultValue:t.default,schemaFor:t.schemaFor});let e=t.schemaFor||"listing",s=G[t.scope]||t.scope;console.log(`${s} schema, ${t.key} is successfully set for ${e}.`)}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to set search schema"),process.exit(1)}}async function We(r,t){try{await Je(void 0,r,{key:t.key,scope:t.scope,schemaFor:t.schemaFor});let e=t.schemaFor||"listing",s=G[t.scope]||t.scope;console.log(`${s} schema, ${t.key} is successfully unset for ${e}.`)}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to unset search schema"),process.exit(1)}}function Ge(r){return r==null?"":Array.isArray(r)?r.join(", "):String(r)}async function Qe(r){try{let t=await Ve(void 0,r);if(t.length===0){console.log("No search schemas found.");return}let e=t.map(i=>({"Schema for":i.schemaFor,Scope:i.scope,Key:i.key,Type:i.type,"Default value":Ge(i.defaultValue),Doc:i.doc||""})).sort((i,a)=>i["Schema for"]!==a["Schema for"]?i["Schema for"].localeCompare(a["Schema for"]):i.Scope!==a.Scope?i.Scope.localeCompare(a.Scope):i.Key.localeCompare(a.Key)),s=["Schema for","Scope","Key","Type","Default value","Doc"],o={};for(let i of s)o[i]=i.length+1;for(let i of e)for(let a of s){let m=i[a]||"";o[a]=Math.max(o[a],m.length)}console.log("");let n=s.map((i,a)=>{let m=o[i]||0,l=i.padEnd(m);return a===s.length-1?l+" ":l+" "});console.log(n.join(""));for(let i of e){let a=s.map((m,l)=>{let d=i[m]||"",p=o[m]||0,u=d.padEnd(p);return l===s.length-1?u+" ":u+" "});console.log(a.join(""))}console.log("")}catch(t){t&&typeof t=="object"&&"message"in t?c(t.message):c("Failed to list search schemas"),process.exit(1)}}function Q(r){let t=r.command("search").description("list all search schemas").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await Qe(s)});t.command("set").description("set search schema").requiredOption("--key <KEY>","schema key").requiredOption("--scope <SCOPE>","schema scope").requiredOption("--type <TYPE>","value type (enum, multi-enum, boolean, long, or text)").option("--doc <DOC>","description of the schema").option("--default <DEFAULT>","default value for search if value is not set").option("--schema-for <SCHEMA_FOR>","subject of the schema (listing, userProfile, or transaction)").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await Be(s,{key:e.key,scope:e.scope,type:e.type,doc:e.doc,default:e.default,schemaFor:e.schemaFor})}),t.command("unset").description("unset search schema").requiredOption("--key <KEY>","schema key").requiredOption("--scope <SCOPE>","schema scope").option("--schema-for <SCHEMA_FOR>","subject of the schema (listing, userProfile, or transaction)").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await We(s,{key:e.key,scope:e.scope,schemaFor:e.schemaFor})})}import{pullAssets as Ye,pushAssets as Xe}from"sharetribe-flex-build-sdk";import{readFileSync as Y,writeFileSync as X,existsSync as k,mkdirSync as j,readdirSync as ze,statSync as F,unlinkSync as Ze}from"node:fs";import{join as E,dirname as et}from"node:path";import{createHash as tt}from"node:crypto";import st from"chalk";import g from"jsedn";function z(r){let t=E(r,".flex-cli","asset-meta.edn");if(!k(t))return null;try{let e=Y(t,"utf-8"),s=g.parse(e),o=s.at(g.kw(":version")),n=s.at(g.kw(":assets")),i=[];if(n&&n.val)for(let a of n.val)i.push({path:a.at(g.kw(":path")),"content-hash":a.at(g.kw(":content-hash"))});return{version:o,assets:i}}catch{return null}}function Z(r,t){let e=E(r,".flex-cli");k(e)||j(e,{recursive:!0});let s=t.assets.map(i=>new g.Map([g.kw(":path"),i.path,g.kw(":content-hash"),i["content-hash"]])),o=new g.Map([g.kw(":version"),t.version,g.kw(":assets"),new g.Vector(s)]),n=E(r,".flex-cli","asset-meta.edn");X(n,g.encode(o),"utf-8")}function ee(r){let t=Buffer.from(`${r.length}|`,"utf-8");return tt("sha1").update(t).update(r).digest("hex")}function rt(r){let t=[];function e(s,o=""){let n=ze(s);for(let i of n){if(i===".flex-cli")continue;let a=E(s,i),m=o?E(o,i):i,l=F(a);if(l.isDirectory())e(a,m);else if(l.isFile()){let d=Y(a),p=ee(d);t.push({path:m,data:d,hash:p})}}}return e(r),t}function ot(r){for(let t of r)if(t.path.endsWith(".json"))try{JSON.parse(t.data.toString("utf-8"))}catch(e){throw new Error(`Invalid JSON in ${t.path}: ${e}`)}}async function nt(r,t,e,s){try{if(k(t)||j(t,{recursive:!0}),!F(t).isDirectory())throw new Error(`${t} is not a directory`);let n=await Ye(void 0,r,e?{version:e}:void 0),i=n.version,a=z(t);if(a&&a.version===i&&n.assets.length===a.assets.length){console.log("Assets are up to date.");return}let m=[];for(let l of n.assets){let d=E(t,l.path),p=et(d);k(p)||j(p,{recursive:!0});let u=Buffer.from(l.dataRaw,"base64");X(d,u);let y=ee(u);m.push({path:l.path,"content-hash":l.contentHash||y})}if(s&&a){let l=new Set(n.assets.map(d=>d.path));for(let d of a.assets)if(!l.has(d.path)){let p=E(t,d.path);k(p)&&Ze(p)}}Z(t,{version:i,assets:m}),console.log(`Version ${i} successfully pulled.`)}catch(o){o&&typeof o=="object"&&"message"in o?c(o.message):c("Failed to pull assets"),process.exit(1)}}async function it(r,t,e){try{if(!k(t)||!F(t).isDirectory())throw new Error(`${t} is not a valid directory`);let s=z(t),o=s?.version||"nil",n=rt(t);ot(n);let i=[],a=new Map(n.map(p=>[p.path,p])),m=new Map((s?.assets||[]).map(p=>[p.path,p["content-hash"]]));for(let[p,u]of a){let y=m.get(p);(!y||y!==u.hash)&&i.push({path:p,op:"upsert",data:u.data})}if(e&&s)for(let p of s.assets)a.has(p.path)||i.push({path:p.path,op:"delete"});if(i.length===0){console.log("Assets are up to date.");return}let l=i.filter(p=>p.op==="upsert").map(p=>p.path);l.length>0&&console.log(st.green(`Uploading changed assets: ${l.join(", ")}`));let d=await Xe(void 0,r,o,i);Z(t,{version:d.version,assets:d.assets.map(p=>({path:p.path,"content-hash":p.contentHash}))}),console.log(`New version ${d.version} successfully created.`)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to push assets"),process.exit(1)}}function te(r){let t=r.command("assets").description("manage marketplace assets");t.command("pull").description("pull assets from remote").requiredOption("--path <PATH>","path to directory where assets will be stored").option("--version <VERSION>","version of assets to pull").option("--prune","delete local files no longer present as remote assets").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await nt(s,e.path,e.version,e.prune)}),t.command("push").description("push assets to remote").requiredOption("--path <PATH>","path to directory with assets").option("--prune","delete remote assets no longer present locally").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await it(s,e.path,e.prune)})}import{sendNotification as at,previewNotification as ct}from"sharetribe-flex-build-sdk";import{readFileSync as K,existsSync as C,statSync as lt}from"node:fs";import{join as se}from"node:path";import{createServer as pt}from"node:http";function re(r){if(!C(r)||!lt(r).isDirectory())throw new Error(`Template directory not found: ${r}`);let t=se(r,"template.html"),e=se(r,"template-subject.txt");if(!C(t))throw new Error(`template.html not found in ${r}`);if(!C(e))throw new Error(`template-subject.txt not found in ${r}`);let s=K(t,"utf-8"),o=K(e,"utf-8").trim();return{html:s,subject:o}}function oe(r){if(!r)return;if(!C(r))throw new Error(`Context file not found: ${r}`);let t=K(r,"utf-8");try{return JSON.parse(t)}catch(e){throw new Error(`Invalid JSON in context file: ${e}`)}}async function mt(r,t,e){try{let s=re(t),o=oe(e),n=await at(void 0,r,{template:s,context:o});console.log(`Preview successfully sent to ${n.adminEmail}`)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to send notification"),process.exit(1)}}async function dt(r,t,e){try{let s=re(t),o=oe(e);console.log(`Template: ${t}`),console.log(`Subject: ${s.subject}`),console.log(""),console.log("Starting preview server at http://localhost:3535"),console.log("Press Ctrl+C to stop"),console.log("");let n=null,i=async()=>{try{let d=(await ct(void 0,r,{template:s,context:o})).html,p=`<title>${s.subject}</title>`;d.includes("<head>")?n=d.replace("<head>",`<head>
|
|
4
|
-
|
|
5
|
-
<
|
|
3
|
+
import{Command as ir}from"commander";import{readFileSync as ar}from"node:fs";import{fileURLToPath as cr}from"node:url";import{dirname as lr,join as pr}from"node:path";import{readFileSync as Ce}from"node:fs";import{fileURLToPath as Ie}from"node:url";import{dirname as V,join as be}from"node:path";function Oe(){let s=Ie(import.meta.url),t=V(s);for(;t!=="/";)try{let e=be(t,"package.json");return Ce(e,"utf-8")}catch{t=V(t)}throw new Error("Could not find package.json")}function H(){let s=JSON.parse(Oe());console.log(s.version)}import Re from"inquirer";import{writeAuth as xe}from"sharetribe-flex-build-sdk";async function J(){let s=await Re.prompt([{type:"password",name:"apiKey",message:"Enter API key:",mask:"*",validate:t=>!t||t.trim().length===0?"API key cannot be empty":!0}]);xe({apiKey:s.apiKey}),console.log("Successfully logged in.")}import{clearAuth as Te}from"sharetribe-flex-build-sdk";async function B(){await Te(),console.log("Successfully logged out.")}import{listProcesses as qe,listProcessVersions as Me}from"sharetribe-flex-build-sdk";import R from"chalk";function P(s,t){if(t.length===0)return;let e={};for(let n of s)e[n]=n.length+1;for(let n of t)for(let i of s){let a=n[i]||"";e[i]=Math.max(e[i]||0,a.length)}console.log("");let o=s.map((n,i)=>{let a=e[n]||0,p=n.padEnd(a+1);return i===s.length-1?p:p+" "}).join("");console.log(R.bold.black(o));for(let n of t){let a=s.map((p,l)=>{let m=n[p]||"",u=e[p]||0,f=m.padEnd(u+1);return l===s.length-1?f:f+" "}).join("");console.log(a)}console.log("")}function c(s){console.error(R.red(`Error: ${s}`))}function E(s){console.log(R.green(s))}function De(s){try{let t=new Date(s),e=t.getFullYear(),r=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0"),n=t.toLocaleTimeString("en-US");return`${e}-${r}-${o} ${n}`}catch{return s}}async function x(s,t){try{if(t){let e=await Me(void 0,s,t);if(e.length===0){console.log(`No versions found for process: ${t}`);return}let r=e.map(o=>({Created:De(o.createdAt),Version:o.version.toString(),Aliases:o.aliases?.join(", ")||"",Transactions:o.transactionCount?.toString()||"0"}));P(["Created","Version","Aliases","Transactions"],r)}else{let e=await qe(void 0,s);if(e.length===0){console.log("No processes found.");return}let r=e.map(o=>({Name:o.name,"Latest version":o.version?.toString()||""}));P(["Name","Latest version"],r)}}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to list processes"),process.exit(1)}}import{createProcess as _e}from"sharetribe-flex-build-sdk";import{readFileSync as Le}from"node:fs";import{join as Ne}from"node:path";async function T(s,t,e){try{let r=Ne(e,"process.edn"),o=Le(r,"utf-8"),n=await _e(void 0,s,t,o);E(`Process ${n.name} successfully created with version ${n.version}.`)}catch(r){r&&typeof r=="object"&&"message"in r?c(r.message):c("Failed to create process"),process.exit(1)}}import{pushProcess as $e}from"sharetribe-flex-build-sdk";import{readFileSync as q,readdirSync as je}from"node:fs";import{join as C}from"node:path";function Fe(s){let t=C(s,"templates"),e=[];try{let r=je(t);for(let o of r){let n=C(t,o),i=C(n,`${o}-html.html`),a=C(n,`${o}-subject.txt`);try{let p=q(i,"utf-8"),l=q(a,"utf-8");e.push({name:o,html:p,subject:l})}catch{}}}catch{}return e}async function M(s,t,e){try{let r=C(e,"process.edn"),o=q(r,"utf-8"),n=Fe(e),i=await $e(void 0,s,t,o,n);i.noChanges?console.log("No changes"):E(`Version ${i.version} successfully saved for process ${t}.`)}catch(r){r&&typeof r=="object"&&"message"in r?c(r.message):c("Failed to push process"),process.exit(1)}}import{getProcess as Ke}from"sharetribe-flex-build-sdk";import{writeFileSync as D,mkdirSync as _}from"node:fs";import{join as I}from"node:path";async function L(s,t,e,r,o){try{let n=await Ke(void 0,s,t,{version:r,alias:o});if(!n.definition)throw new Error("No process definition in response");let{existsSync:i}=await import("node:fs"),a=i(e);_(e,{recursive:!0}),a||console.error(`Creating a new directory: ${e}`);let p=I(e,"process.edn");D(p,n.definition,"utf-8");let l=n.emailTemplates||[];if(l&&Array.isArray(l)&&l.length>0){let m=I(e,"templates");_(m,{recursive:!0});for(let u of l){let f=u.name,w=u.html,S=u.subject;if(f){let d=I(m,f);if(_(d,{recursive:!0}),w){let g=I(d,`${f}-html.html`);D(g,w,"utf-8")}if(S){let g=I(d,`${f}-subject.txt`);D(g,S,"utf-8")}}}}console.error(`Saved process to ${e}`)}catch(n){n&&typeof n=="object"&&"message"in n?c(n.message):c("Failed to pull process"),process.exit(1)}}import{createAlias as Ue,updateAlias as Ve,deleteAlias as He}from"sharetribe-flex-build-sdk";async function N(s,t,e,r){try{let o=await Ue(void 0,s,t,e,r);E(`Alias ${o.alias} successfully created to point to version ${o.version}.`)}catch(o){o&&typeof o=="object"&&"message"in o?c(o.message):c("Failed to create alias"),process.exit(1)}}async function $(s,t,e,r){try{let o=await Ve(void 0,s,t,e,r);E(`Alias ${o.alias} successfully updated to point to version ${o.version}.`)}catch(o){o&&typeof o=="object"&&"message"in o?c(o.message):c("Failed to update alias"),process.exit(1)}}async function j(s,t,e){try{let r=await He(void 0,s,t,e);E(`Alias ${r.alias} successfully deleted.`)}catch(r){r&&typeof r=="object"&&"message"in r?c(r.message):c("Failed to delete alias"),process.exit(1)}}import{deployProcess as Je,parseProcessFile as Be}from"sharetribe-flex-build-sdk";import{readFileSync as We}from"node:fs";import{join as Ge}from"node:path";async function F(s,t,e,r){try{let o=Ge(e,"process.edn"),n=We(o,"utf-8"),i=Be(n),a=await Je(void 0,s,{process:t,alias:r,path:o,processDefinition:i});a.processCreated&&E(`Process ${t} successfully created.`),E(`Version ${a.version} successfully saved for process ${t}.`),a.aliasCreated?E(`Alias ${a.alias} successfully created to point to version ${a.version}.`):E(`Alias ${a.alias} successfully updated to point to version ${a.version}.`)}catch(o){o&&typeof o=="object"&&"message"in o?c(o.message):c("Failed to create/push process and alias"),process.exit(1)}}function W(s){let t=s.command("process").description("describe a process file").option("--path <PROCESS_DIR>","path to the directory where the process.edn file is").option("--transition <TRANSITION_NAME>","transition name, e.g. transition/request to get more details of it").action(async e=>{e.path?(console.log(`Describing process at: ${e.path}`),e.transition&&console.log(`Transition: ${e.transition}`),console.log("Process description not yet implemented")):t.outputHelp()});t.command("list").description("list all transaction processes").option("--process <PROCESS_NAME>","print version and alias info of a specific process").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await x(r,e.process)}),t.command("create").description("create a new transaction process").requiredOption("--process <PROCESS_NAME>","name for the new process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory where the process.edn file is").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await T(r,e.process,e.path)}),t.command("push").description("push a process file to the remote").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory where the process.edn file is").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await M(r,e.process,e.path)}),t.command("pull").description("fetch a process file").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path where to save the process").option("--version <VERSION_NUM>","version number").option("--alias <PROCESS_ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await L(r,e.process,e.path,e.version,e.alias)}),t.command("create-alias").description("create a new alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--version <VERSION_NUM>","version number").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").allowUnknownOption(!1).action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await N(r,e.process,parseInt(e.version),e.alias)}),t.command("update-alias").description("update an existing alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--version <VERSION_NUM>","version number").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await $(r,e.process,parseInt(e.version),e.alias)}),t.command("delete-alias").description("delete an existing alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await j(r,e.process,e.alias)}),t.command("deploy").description("deploy a process file with alias (create/push + alias create/update)").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory with the process files").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await F(r,e.process,e.path,e.alias)}),s.command("process-list",{hidden:!0}).description("list all transaction processes").option("--process <PROCESS_NAME>","print version and alias info of a specific process").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await x(r,e.process)}),s.command("process-create",{hidden:!0}).description("create a new transaction process").requiredOption("--process <PROCESS_NAME>","name for the new process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory where the process.edn file is").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await T(r,e.process,e.path)}),s.command("process-push",{hidden:!0}).description("push a process file to the remote").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory where the process.edn file is").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await M(r,e.process,e.path)}),s.command("process-pull",{hidden:!0}).description("fetch a process file").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path where to save the process").option("--version <VERSION_NUM>","version number").option("--alias <PROCESS_ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await L(r,e.process,e.path,e.version,e.alias)}),s.command("process-create-alias",{hidden:!0}).description("create a new alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--version <VERSION_NUM>","version number").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await N(r,e.process,parseInt(e.version),e.alias)}),s.command("process-update-alias",{hidden:!0}).description("update an existing alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--version <VERSION_NUM>","version number").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await $(r,e.process,parseInt(e.version),e.alias)}),s.command("process-delete-alias",{hidden:!0}).description("delete an existing alias").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await j(r,e.process,e.alias)}),s.command("process-deploy",{hidden:!0}).description("deploy a process file with alias (create/push + alias create/update)").requiredOption("--process <PROCESS_NAME>","name of the process").requiredOption("--path <LOCAL_PROCESS_DIR>","path to the directory with the process files").requiredOption("--alias <ALIAS>","alias name").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await F(r,e.process,e.path,e.alias)})}import{listSearchSchemas as Qe,setSearchSchema as Ye,unsetSearchSchema as ze}from"sharetribe-flex-build-sdk";var G={metadata:"Metadata",private:"Private data",protected:"Protected data",public:"Public data"};async function Ze(s,t){try{await Ye(void 0,s,{key:t.key,scope:t.scope,type:t.type,doc:t.doc,defaultValue:t.default,schemaFor:t.schemaFor});let e=t.schemaFor||"listing",r=G[t.scope]||t.scope;console.log(`${r} schema, ${t.key} is successfully set for ${e}.`)}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to set search schema"),process.exit(1)}}async function Xe(s,t){try{await ze(void 0,s,{key:t.key,scope:t.scope,schemaFor:t.schemaFor});let e=t.schemaFor||"listing",r=G[t.scope]||t.scope;console.log(`${r} schema, ${t.key} is successfully unset for ${e}.`)}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to unset search schema"),process.exit(1)}}function et(s){return s==null?"":Array.isArray(s)?s.join(", "):String(s)}async function tt(s){try{let t=await Qe(void 0,s);if(t.length===0){console.log("No search schemas found.");return}let e=t.map(i=>({"Schema for":i.schemaFor,Scope:i.scope,Key:i.key,Type:i.type,"Default value":et(i.defaultValue),Doc:i.doc||""})).sort((i,a)=>i["Schema for"]!==a["Schema for"]?i["Schema for"].localeCompare(a["Schema for"]):i.Scope!==a.Scope?i.Scope.localeCompare(a.Scope):i.Key.localeCompare(a.Key)),r=["Schema for","Scope","Key","Type","Default value","Doc"],o={};for(let i of r)o[i]=i.length+1;for(let i of e)for(let a of r){let p=i[a]||"";o[a]=Math.max(o[a],p.length)}console.log("");let n=r.map((i,a)=>{let p=o[i]||0,l=i.padEnd(p);return a===r.length-1?l+" ":l+" "});console.log(n.join(""));for(let i of e){let a=r.map((p,l)=>{let m=i[p]||"",u=o[p]||0,f=m.padEnd(u);return l===r.length-1?f+" ":f+" "});console.log(a.join(""))}console.log("")}catch(t){t&&typeof t=="object"&&"message"in t?c(t.message):c("Failed to list search schemas"),process.exit(1)}}function Q(s){let t=s.command("search").description("list all search schemas").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await tt(r)});t.command("set").description("set search schema").requiredOption("--key <KEY>","key name").requiredOption("--scope <SCOPE>","extended data scope (either metadata or public for listing schema, metadata, private, protected or public for userProfile schema, metadata or protected for transaction schema)").requiredOption("--type <TYPE>","value type (either enum, multi-enum, boolean, long or text)").option("--doc <DOC>","description of the schema").option("--default <DEFAULT>","default value for search if value is not set").option("--schema-for <SCHEMA_FOR>","Subject of the schema (either listing, userProfile or transaction, defaults to listing)").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await Ze(r,{key:e.key,scope:e.scope,type:e.type,doc:e.doc,default:e.default,schemaFor:e.schemaFor})}),t.command("unset").description("unset search schema").requiredOption("--key <KEY>","key name").requiredOption("--scope <SCOPE>","extended data scope (either metadata or public for listing schema, metadata, private, protected or public for userProfile schema, metadata or protected for transaction schema)").option("--schema-for <SCHEMA_FOR>","Subject of the schema (either listing, userProfile or transaction, defaults to listing)").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await Xe(r,{key:e.key,scope:e.scope,schemaFor:e.schemaFor})})}import{pushAssets as rt,stageAsset as st,getApiBaseUrl as ot,readAuth as nt}from"sharetribe-flex-build-sdk";import{readFileSync as X,writeFileSync as it,existsSync as v,mkdirSync as K,readdirSync as ee,statSync as b,unlinkSync as Y,createWriteStream as te}from"node:fs";import{join as k,dirname as at}from"node:path";import{createHash as ct}from"node:crypto";import*as lt from"node:http";import*as pt from"node:https";import{tmpdir as mt}from"node:os";import{pipeline as re}from"node:stream/promises";import z from"chalk";import y from"jsedn";import dt from"yauzl";var ut="meta/asset-meta.edn",Z="assets/",ft="\x1B[K",ht="\r";function se(s){try{let t=y.parse(s),e=t.at(y.kw(":version"))||t.at(y.kw(":aliased-version")),r=t.at(y.kw(":assets")),o=[];if(r&&r.val)for(let n of r.val)o.push({path:n.at(y.kw(":path")),"content-hash":n.at(y.kw(":content-hash"))});return e?{version:e,assets:o}:null}catch{return null}}function oe(s){let t=k(s,".flex-cli","asset-meta.edn");if(!v(t))return null;try{let e=X(t,"utf-8");return se(e)}catch{return null}}function ne(s,t){let e=k(s,".flex-cli");v(e)||K(e,{recursive:!0});let r=t.assets.map(i=>new y.Map([y.kw(":path"),i.path,y.kw(":content-hash"),i["content-hash"]])),o=new y.Map([y.kw(":version"),t.version,y.kw(":assets"),new y.Vector(r)]),n=k(s,".flex-cli","asset-meta.edn");it(n,y.encode(o),"utf-8")}function gt(s){let t=Buffer.from(`${s.length}|`,"utf-8");return ct("sha1").update(t).update(s).digest("hex")}function yt(s){let t=[];function e(r,o=""){let n=ee(r);for(let i of n){if(i===".flex-cli"||i===".DS_Store")continue;let a=k(r,i),p=o?k(o,i):i,l=b(a);if(l.isDirectory())e(a,p);else if(l.isFile()){let m=X(a),u=gt(m);t.push({path:p,data:m,hash:u})}}}return e(s),t}function Et(s){let t=[];function e(r,o=""){let n=ee(r);for(let i of n){if(i===".flex-cli"||i===".DS_Store")continue;let a=k(r,i),p=o?k(o,i):i,l=b(a);l.isDirectory()?e(a,p):l.isFile()&&t.push(p)}}return e(s),t}function St(s){for(let t of s)if(t.path.endsWith(".json"))try{JSON.parse(t.data.toString("utf-8"))}catch(e){throw new Error(`Invalid JSON in ${t.path}: ${e}`)}}function kt(s){let t=s/1024/1024;return`${ht}${ft}Downloaded ${t.toFixed(2)}MB`}function At(s){let t=0,e=()=>{process.stderr.write(kt(t))},r=setInterval(e,100);s.on("data",o=>{t+=o.length}),s.on("end",()=>{clearInterval(r),e(),process.stderr.write(`
|
|
4
|
+
Finished downloading assets
|
|
5
|
+
`)})}function vt(){let s=nt();if(!s?.apiKey)throw new Error("Not logged in. Please provide apiKey or run: sharetribe-cli login");return s.apiKey}function wt(s,t){let e=new URL(ot()+"/assets/pull");return e.searchParams.set("marketplace",s),t?e.searchParams.set("version",t):e.searchParams.set("version-alias","latest"),e}function Pt(s,t){try{let r=JSON.parse(s).errors?.[0]?.message;if(r)return r}catch{}return s||`HTTP ${t}`}async function Ct(s,t){let e=wt(s,t),r=vt(),o=e.protocol==="https:",n=o?pt:lt;return new Promise((i,a)=>{let p=n.request({method:"GET",hostname:e.hostname,port:e.port||(o?443:80),path:e.pathname+e.search,headers:{Authorization:`Apikey ${r}`,Accept:"application/zip"}},l=>{let m=l.statusCode||0;if(m<200||m>=300){let u=[];l.on("data",f=>u.push(f)),l.on("end",()=>{let f=Buffer.concat(u).toString("utf-8");a(new Error(Pt(f,m)))});return}i(l)});p.setTimeout(12e4,()=>{p.destroy(new Error("Request timeout"))}),p.on("error",a),p.end()})}function It(){return k(mt(),`assets-${Date.now()}.zip`)}function bt(s){return s.startsWith(Z)?s.slice(Z.length):s}function Ot(s){return new Promise((t,e)=>{let r=[];s.on("data",o=>r.push(o)),s.on("end",()=>t(Buffer.concat(r).toString("utf-8"))),s.on("error",e)})}async function Rt(s,t){return new Promise((e,r)=>{dt.open(s,{lazyEntries:!0},(o,n)=>{if(o||!n){r(o||new Error("Failed to open zip file"));return}let i=null;n.on("error",r),n.on("end",()=>{if(!i){r(new Error("Asset metadata not found in zip"));return}e(i)}),n.readEntry(),n.on("entry",a=>{if(a.fileName.endsWith("/")){n.readEntry();return}n.openReadStream(a,(p,l)=>{if(p||!l){r(p||new Error("Failed to read zip entry"));return}if(a.fileName===ut){Ot(l).then(f=>{if(i=se(f),!i){r(new Error("Invalid asset metadata"));return}n.readEntry()}).catch(r);return}let m=k(t,bt(a.fileName)),u=at(m);v(u)||K(u,{recursive:!0}),re(l,te(m)).then(()=>n.readEntry()).catch(r)})})})})}async function xt(s,t,e,r){try{if(v(t)||K(t,{recursive:!0}),!b(t).isDirectory())throw new Error(`${t} is not a directory`);let n=r?Et(t):[],i=oe(t),a=It();try{let p=await Ct(s,e);At(p),await re(p,te(a));let l=await Rt(a,t),m=l.version,u=r?new Set(n.filter(S=>!l.assets.some(d=>d.path===S))):new Set,w=i?.version!==m||u.size>0;if(u.size>0)for(let S of u){let d=k(t,S);v(d)&&Y(d)}w?(ne(t,{version:m,assets:l.assets}),console.log(`Version ${m} successfully pulled.`)):console.log("Assets are up to date.")}finally{v(a)&&Y(a)}}catch(o){o&&typeof o=="object"&&"message"in o?c(o.message):c("Failed to pull assets"),process.exit(1)}}function Tt(s,t){let e=new Map(s.map(r=>[r.path,r["content-hash"]]));return t.filter(r=>{let o=e.get(r.path);return!o||o!==r.hash})}async function qt(s,t,e){try{if(!v(t)||!b(t).isDirectory())throw new Error(`${t} is not a valid directory`);let r=oe(t),o=r?.version||"nil",n=yt(t);St(n);let i=Tt(r?.assets||[],n),a=d=>d.toLowerCase().endsWith(".json"),p=i.filter(d=>!a(d.path)),l=new Map(n.map(d=>[d.path,d])),m=[];if(e&&r)for(let d of r.assets)l.has(d.path)||m.push({path:d.path,op:"delete"});if(i.length===0&&m.length===0){console.log("Assets are up to date.");return}if(i.length>0){let d=i.map(g=>g.path).join(", ");console.log(z.green(`Uploading changed assets: ${d}`))}let f=new Map;if(p.length>0){let d=p.map(g=>g.path).join(", ");console.log(z.green(`Staging assets: ${d}`));for(let g of p)try{let A=await st(void 0,s,g.data,g.path);f.set(g.path,A.stagingId)}catch(A){if(A&&typeof A=="object"&&"code"in A&&A.code==="asset-invalid-content"){let Pe="message"in A?A.message:"The file is missing or uses an unsupported format.";throw new Error(`Failed to stage image ${g.path}: ${Pe}
|
|
6
|
+
Fix the file and rerun assets push to retry staging.`)}throw A}}let w=i.map(d=>{let g=f.get(d.path);return{path:d.path,op:"upsert",...g?{stagingId:g}:{data:d.data,filename:d.path}}}),S=await rt(void 0,s,o,[...w,...m]);ne(t,{version:S.version,assets:S.assets.map(d=>({path:d.path,"content-hash":d.contentHash}))}),console.log(`New version ${S.version} successfully created.`)}catch(r){r&&typeof r=="object"&&"message"in r?c(r.message):c("Failed to push assets"),process.exit(1)}}function ie(s){let t=s.command("assets").description("manage marketplace assets");t.command("pull").description("pull assets from remote").requiredOption("--path <PATH>","path to directory where assets will be stored").option("--version <VERSION>","version of assets to pull").option("--prune","delete local files no longer present as remote assets").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await xt(r,e.path,e.version,e.prune)}),t.command("push").description("push assets to remote").requiredOption("--path <PATH>","path to directory with assets").option("--prune","delete remote assets no longer present locally").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await qt(r,e.path,e.prune)})}import{sendNotification as Mt,previewNotification as Dt}from"sharetribe-flex-build-sdk";import{readFileSync as U,existsSync as O,statSync as _t}from"node:fs";import{join as ae}from"node:path";import{createServer as Lt}from"node:http";function ce(s){if(!O(s)||!_t(s).isDirectory())throw new Error(`Template directory not found: ${s}`);let t=ae(s,"template.html"),e=ae(s,"template-subject.txt");if(!O(t))throw new Error(`template.html not found in ${s}`);if(!O(e))throw new Error(`template-subject.txt not found in ${s}`);let r=U(t,"utf-8"),o=U(e,"utf-8").trim();return{html:r,subject:o}}function le(s){if(!s)return;if(!O(s))throw new Error(`Context file not found: ${s}`);let t=U(s,"utf-8");try{return JSON.parse(t)}catch(e){throw new Error(`Invalid JSON in context file: ${e}`)}}async function Nt(s,t,e){try{let r=ce(t),o=le(e),n=await Mt(void 0,s,{template:r,context:o});console.log(`Preview successfully sent to ${n.adminEmail}`)}catch(r){r&&typeof r=="object"&&"message"in r?c(r.message):c("Failed to send notification"),process.exit(1)}}async function $t(s,t,e){try{let r=ce(t),o=le(e);console.log(`Template: ${t}`),console.log(`Subject: ${r.subject}`),console.log(""),console.log("Starting preview server at http://localhost:3535"),console.log("Press Ctrl+C to stop"),console.log("");let n=null,i=async()=>{try{let m=(await Dt(void 0,s,{template:r,context:o})).html,u=`<title>${r.subject}</title>`;m.includes("<head>")?n=m.replace("<head>",`<head>
|
|
7
|
+
${u}`):m.includes("<html>")?n=m.replace("<html>",`<html>
|
|
8
|
+
<head>${u}</head>`):n=`<html><head>${u}</head><body>${m}</body></html>`}catch(l){n=`
|
|
6
9
|
<html>
|
|
7
10
|
<head><title>Error</title></head>
|
|
8
11
|
<body style="font-family: sans-serif; padding: 20px;">
|
|
@@ -10,10 +13,10 @@ ${p}`):d.includes("<html>")?n=d.replace("<html>",`<html>
|
|
|
10
13
|
<pre style="background: #f5f5f5; padding: 15px; border-radius: 4px;">${l&&typeof l=="object"&&"message"in l?l.message:"Failed to preview notification"}</pre>
|
|
11
14
|
</body>
|
|
12
15
|
</html>
|
|
13
|
-
`}};await i();let a=
|
|
14
|
-
Shutting down preview server...`),a.close(()=>{process.exit(0)})};process.on("SIGINT",
|
|
15
|
-
Stopping tail...`),e(),process.exit(0)};process.on("SIGINT",
|
|
16
|
-
`)}function
|
|
17
|
-
`),writeErr:
|
|
18
|
-
`)});
|
|
16
|
+
`}};await i();let a=Lt(async(l,m)=>{l.url==="/"||l.url===""?(await i(),m.writeHead(200,{"Content-Type":"text/html"}),m.end(n)):(m.writeHead(404,{"Content-Type":"text/plain"}),m.end("Not Found"))});a.listen(3535,()=>{console.log("Preview server started. Open http://localhost:3535 in your browser.")});let p=()=>{console.log(`
|
|
17
|
+
Shutting down preview server...`),a.close(()=>{process.exit(0)})};process.on("SIGINT",p),process.on("SIGTERM",p)}catch(r){r&&typeof r=="object"&&"message"in r?c(r.message):c("Failed to preview notification"),process.exit(1)}}function pe(s){let t=s.command("notifications").description("manage email notifications");t.command("preview").description("render a preview of an email template").requiredOption("--template <TEMPLATE_DIR>","path to template directory").option("--context <CONTEXT_FILE>","path to email rendering context JSON file").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await $t(r,e.template,e.context)}),t.command("send").description("send a preview of an email template to the logged in admin").requiredOption("--template <TEMPLATE_DIR>","path to template directory").option("--context <CONTEXT_FILE>","path to email rendering context JSON file").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await Nt(r,e.template,e.context)})}import{getListingApprovalStatus as jt,enableListingApproval as Ft,disableListingApproval as Kt}from"sharetribe-flex-build-sdk";async function Ut(s){try{(await jt(void 0,s)).enabled?console.log(`Listing approvals are enabled in ${s}`):console.log(`Listing approvals are disabled in ${s}`)}catch(t){t&&typeof t=="object"&&"message"in t?c(t.message):c("Failed to get listing approval status"),process.exit(1)}}async function Vt(s){try{await Ft(void 0,s),console.log(`Successfully enabled listing approvals in ${s}`)}catch(t){t&&typeof t=="object"&&"message"in t?c(t.message):c("Failed to enable listing approvals"),process.exit(1)}}async function Ht(s){try{await Kt(void 0,s),console.log(`Successfully disabled listing approvals in ${s}`)}catch(t){t&&typeof t=="object"&&"message"in t?c(t.message):c("Failed to disable listing approvals"),process.exit(1)}}function me(s){let t=s.command("listing-approval").description("manage listing approvals (DEPRECATED - use Console instead)").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier");t.action(async e=>{console.warn("Warning: CLI command `listing-approval` is deprecated. Use Console instead.");let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await Ut(r)}),t.command("enable").description("enable listing approvals").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{console.warn("Warning: CLI command `listing-approval` is deprecated. Use Console instead.");let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await Vt(r)}),t.command("disable").description("disable listing approvals").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{console.warn("Warning: CLI command `listing-approval` is deprecated. Use Console instead.");let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await Ht(r)})}import{queryEvents as Jt,pollEvents as Bt}from"sharetribe-flex-build-sdk";function de(s){if([s.sequenceId!==void 0,s.afterSeqId!==void 0,s.beforeSeqId!==void 0,s.afterTs!==void 0,s.beforeTs!==void 0].filter(Boolean).length>1)throw new Error("Only one of --seqid, --after-seqid, --before-seqid, --after-ts, or --before-ts can be specified");if(s.resourceId&&s.relatedResourceId)throw new Error("Only one of --resource or --related-resource can be specified")}function ue(s){try{let t=new Date(s),e=t.getFullYear(),r=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0"),n=t.toLocaleTimeString("en-US");return`${e}-${r}-${o} ${n}`}catch{return s}}async function Wt(s,t){try{de(t);let e=await Jt(void 0,s,{resourceId:t.resourceId,relatedResourceId:t.relatedResourceId,eventTypes:t.eventTypes,sequenceId:t.sequenceId,afterSeqId:t.afterSeqId,beforeSeqId:t.beforeSeqId,afterTs:t.afterTs,beforeTs:t.beforeTs,limit:t.limit});if(e.length===0){console.log("No events found.");return}if(t.json)for(let r of e){let{auditEmails:o,...n}=r;console.log(JSON.stringify(n))}else if(t.jsonPretty)for(let r of e){let{auditEmails:o,...n}=r;console.log(JSON.stringify(n,null,2))}else P(["Seq ID","Resource ID","Event type","Created at local time","Source","Actor"],e.map(r=>{let o=r.auditEmails?.userEmail||r.auditEmails?.adminEmail||"",n=r.source?.replace("source/","")||"";return{"Seq ID":r.sequenceId.toString(),"Resource ID":r.resourceId,"Event type":r.eventType,"Created at local time":ue(r.createdAt),Source:n,Actor:o}}))}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to query events"),process.exit(1)}}async function Gt(s,t){try{de(t),console.log("Tailing events... Press Ctrl+C to stop"),console.log("");let e=Bt(void 0,s,{resourceId:t.resourceId,relatedResourceId:t.relatedResourceId,eventTypes:t.eventTypes,limit:t.limit||10},o=>{if(t.json)for(let n of o){let{auditEmails:i,...a}=n;console.log(JSON.stringify(a))}else if(t.jsonPretty)for(let n of o){let{auditEmails:i,...a}=n;console.log(JSON.stringify(a,null,2))}else P(["Seq ID","Resource ID","Event type","Created at local time","Source","Actor"],o.map(n=>{let i=n.auditEmails?.userEmail||n.auditEmails?.adminEmail||"",a=n.source?.replace("source/","")||"";return{"Seq ID":n.sequenceId.toString(),"Resource ID":n.resourceId,"Event type":n.eventType,"Created at local time":ue(n.createdAt),Source:a,Actor:i}}))},5e3),r=()=>{console.log(`
|
|
18
|
+
Stopping tail...`),e(),process.exit(0)};process.on("SIGINT",r),process.on("SIGTERM",r)}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to tail events"),process.exit(1)}}function fe(s){let t=s.command("events").description("Get a list of events.").option("--resource <RESOURCE_ID>","show events for specific resource ID").option("--related-resource <RELATED_RESOURCE_ID>","show events related to specific resource ID").option("--filter <EVENT_TYPES>","filter by event types (comma-separated)").option("--seqid <SEQUENCE_ID>","get event with specific sequence ID",parseInt).option("--after-seqid <SEQUENCE_ID>","show events after sequence ID (exclusive)",parseInt).option("--before-seqid <SEQUENCE_ID>","show events before sequence ID (exclusive)",parseInt).option("--after-ts <TIMESTAMP>","show events after timestamp").option("--before-ts <TIMESTAMP>","show events before timestamp").option("-l, --limit <NUMBER>","limit results (default: 100, max: 100)",parseInt).option("--json","output as single-line JSON strings").option("--json-pretty","output as indented multi-line JSON").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier");t.action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Could not parse arguments:"),console.error("--marketplace is required"),process.exit(1)),await Wt(r,{resourceId:e.resource,relatedResourceId:e.relatedResource,eventTypes:e.filter,sequenceId:e.seqid,afterSeqId:e.afterSeqid,beforeSeqId:e.beforeSeqid,afterTs:e.afterTs,beforeTs:e.beforeTs,limit:e.limit||100,json:e.json,jsonPretty:e.jsonPretty})}),t.command("tail").description("Tail events live as they happen").option("--resource <RESOURCE_ID>","show events for specific resource ID").option("--related-resource <RELATED_RESOURCE_ID>","show events related to specific resource ID").option("--filter <EVENT_TYPES>","filter by event types (comma-separated)").option("-l, --limit <NUMBER>","limit results per poll (default: 10, max: 100)",parseInt).option("--json","output as single-line JSON strings").option("--json-pretty","output as indented multi-line JSON").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Could not parse arguments:"),console.error("--marketplace is required"),process.exit(1)),await Gt(r,{resourceId:e.resource,relatedResourceId:e.relatedResource,eventTypes:e.filter,limit:e.limit||10,json:e.json,jsonPretty:e.jsonPretty})})}import{updateStripeVersion as Qt,SUPPORTED_STRIPE_VERSIONS as Yt}from"sharetribe-flex-build-sdk";import he from"inquirer";async function zt(){return(await he.prompt([{type:"list",name:"version",message:"Select Stripe API version:",choices:[...Yt]}])).version}async function Zt(){return console.log(""),console.log("WARNING: Changing Stripe API version may affect your integration."),console.log(""),console.log("After updating the Stripe API version, you may need to:"),console.log("- Handle new Capabilities requirements"),console.log("- Update identity verification settings"),console.log(""),console.log("See Stripe documentation for details:"),console.log("https://stripe.com/docs/connect/capabilities-overview"),console.log("https://stripe.com/docs/connect/identity-verification"),console.log(""),(await he.prompt([{type:"confirm",name:"confirmed",message:"Do you want to continue?",default:!1}])).confirmed}async function Xt(s,t,e){try{let r=t;r||(r=await zt()),e||await Zt()||(console.log("Cancelled."),process.exit(0)),await Qt(void 0,s,r),console.log(`Stripe API version successfully changed to ${r}`)}catch(r){r&&typeof r=="object"&&"message"in r?c(r.message):c("Failed to update Stripe API version"),process.exit(1)}}function ge(s){s.command("stripe").description("manage Stripe integration").command("update-version").description("update Stripe API version in use").option("--version <VERSION>","Stripe API version to update to").option("-f, --force","skip confirmation prompt and force update").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier").action(async e=>{let r=e.marketplace||s.opts().marketplace;r||(console.error("Error: --marketplace is required"),process.exit(1)),await Xt(r,e.version,e.force)})}import{getConfigMap as er,readAuth as tr}from"sharetribe-flex-build-sdk";function rr(s){return s.length<=4?`...${s}`:`...${s.slice(-4)}`}function ye(){let s=tr(),t=s?.apiKey?rr(s.apiKey):"No API key set",e=er(),r=Object.keys(e).sort().map(n=>`:${n} ${e[n]}`).join(" "),o=r?`{${r}}`:"{}";console.log(`{:api-key ${t}, :conf-map ${o}}`)}function sr(s){let t=[],e=!s.parent,r=s.description();if(r&&(t.push(r),t.push("")),e){let a=s.version();a&&(t.push("VERSION"),t.push(` ${a}`),t.push(""))}t.push("USAGE");let o=or(s);t.push(` $ ${o}`),t.push("");let n=Se(s),i=s.options.length>0&&!e;if(n.length>0&&!i){t.push("COMMANDS");let a=Math.max(...n.map(p=>p.name.length));for(let p of n){let l=p.name.padEnd(a+2);t.push(` ${l}${p.description}`)}t.push("")}if(!e){let a=s.options;if(a.length>0){t.push("OPTIONS");let p=Math.max(...a.map(l=>Ee(l).length));for(let l of a){let u=Ee(l).padEnd(p+2),f=l.description||"";t.push(` ${u}${f}`)}t.push("")}}if(n.length>0&&!i){t.push("Subcommand help:");let a=ke(s);t.push(` $ ${a} help [COMMAND]`)}return t.push(""),t.join(`
|
|
19
|
+
`)}function Se(s){let t=[],e=s.commands.filter(r=>!r._hidden&&r.name()!=="help");for(let r of e){let o=nr(r),n=r.commands.filter(i=>!i._hidden);if(r.description()&&t.push({name:o,description:r.description()||""}),n.length>0){let i=Se(r);for(let a of i)t.push(a)}}return s.parent||t.unshift({name:"help",description:"display help for Flex CLI"}),t.sort((r,o)=>r.name.localeCompare(o.name)),t}function ke(s){let t=[],e=s;for(;e;)e.name()&&t.unshift(e.name()),e=e.parent;return t.length>0&&(t[0]="sharetribe-cli"),t.join(" ")}function or(s){let t=ke(s),e=s.commands.filter(n=>!n._hidden),r=s.options.length>0;return!s.parent&&e.length>0?`${t} [COMMAND]`:e.length>0&&!r?`${t} [COMMAND]`:t}function nr(s){let t=[],e=s;for(;e&&e.parent;)e.name()&&t.unshift(e.name()),e=e.parent;return t.join(" ")}function Ee(s){let e=(s.flags||"").split(/,\s*/),r=[];for(let o of e){let n=o.trim(),i=n.match(/^((?:-{1,2}[\w-]+))\s*[<\[]([^\]>]+)[\]>]/);if(i){let a=i[1],p=i[2];r.push(`${a}=${p}`)}else r.push(n)}return r.join(", ")}function Ae(s){s.configureHelp({formatHelp:(t,e)=>sr(t)})}function ve(s){let t=s.findIndex(o=>o==="process");if(t===-1)return s;let e=s[t+1];return e&&["list","create","push","pull","create-alias","update-alias","delete-alias","deploy"].includes(e)?[...s.slice(0,t),`process-${e}`,...s.slice(t+2)]:s}var mr=cr(import.meta.url),dr=lr(mr),ur=JSON.parse(ar(pr(dr,"../package.json"),"utf-8")),we=ve(process.argv),h=new ir;Ae(h);h.configureOutput({writeOut:s=>process.stdout.write(s+`
|
|
20
|
+
`),writeErr:s=>process.stderr.write(s+`
|
|
21
|
+
`)});h.name("sharetribe-cli").description("CLI to interact with Sharetribe Flex").version(ur.version,"-V","output the version number").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier");h.command("version").description("show version").action(()=>{H()});h.command("login").description("log in with API key").action(async()=>{await J()});h.command("logout").description("logout").action(async()=>{await B()});h.command("debug").description("display debug info").action(()=>{ye()});W(h);Q(h);ie(h);pe(h);me(h);fe(h);ge(h);h.command("help [command...]").description("display help for Flex CLI").action(s=>{if(!s||s.length===0){h.outputHelp();return}let t=h;for(let e of s){let r=t.commands.find(o=>o.name()===e);r||(console.error(`Unknown command: ${s.join(" ")}`),process.exit(1)),t=r}t.outputHelp()});we.slice(2).length?h.parse(we):h.outputHelp();
|
|
19
22
|
//# sourceMappingURL=index.js.map
|