sharetribe-cli 1.15.1 → 1.15.2
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 +9 -8
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
- package/src/commands/assets/index.ts +81 -30
- package/test/assets.test.ts +141 -0
- package/test/strict-comparison.test.ts +13 -2
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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 jt}from"commander";import{readFileSync as Ft}from"node:fs";import{fileURLToPath as Kt}from"node:url";import{dirname as Ut,join as Vt}from"node:path";import{readFileSync as Ae}from"node:fs";import{fileURLToPath as we}from"node:url";import{dirname as H,join as Ce}from"node:path";function Pe(){let r=we(import.meta.url),t=H(r);for(;t!=="/";)try{let e=Ce(t,"package.json");return Ae(e,"utf-8")}catch{t=H(t)}throw new Error("Could not find package.json")}function J(){let r=JSON.parse(Pe());console.log(r.version)}import Ie from"inquirer";import{writeAuth as Oe}from"sharetribe-flex-build-sdk";async function B(){let r=await Ie.prompt([{type:"password",name:"apiKey",message:"Enter API key:",mask:"*",validate:t=>!t||t.trim().length===0?"API key cannot be empty":!0}]);Oe({apiKey:r.apiKey}),console.log("Successfully logged in.")}import{clearAuth as be}from"sharetribe-flex-build-sdk";async function W(){await be(),console.log("Successfully logged out.")}import{listProcesses as xe,listProcessVersions as Re}from"sharetribe-flex-build-sdk";import x from"chalk";function w(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,p=n.padEnd(a+1);return i===r.length-1?p:p+" "}).join("");console.log(x.bold.black(o));for(let n of t){let a=r.map((p,l)=>{let m=n[p]||"",f=e[p]||0,h=m.padEnd(f+1);return l===r.length-1?h:h+" "}).join("");console.log(a)}console.log("")}function c(r){console.error(x.red(`Error: ${r}`))}function y(r){console.log(x.green(r))}function qe(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 R(r,t){try{if(t){let e=await Re(void 0,r,t);if(e.length===0){console.log(`No versions found for process: ${t}`);return}let s=e.map(o=>({Created:qe(o.createdAt),Version:o.version.toString(),Aliases:o.aliases?.join(", ")||"",Transactions:o.transactionCount?.toString()||"0"}));w(["Created","Version","Aliases","Transactions"],s)}else{let e=await xe(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()||""}));w(["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 Te}from"sharetribe-flex-build-sdk";import{readFileSync as Me}from"node:fs";import{join as De}from"node:path";async function q(r,t,e){try{let s=De(e,"process.edn"),o=Me(s,"utf-8"),n=await Te(void 0,r,t,o);y(`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 _e}from"sharetribe-flex-build-sdk";import{readFileSync as T,readdirSync as Le}from"node:fs";import{join as I}from"node:path";function Ne(r){let t=I(r,"templates"),e=[];try{let s=Le(t);for(let o of s){let n=I(t,o),i=I(n,`${o}-html.html`),a=I(n,`${o}-subject.txt`);try{let p=T(i,"utf-8"),l=T(a,"utf-8");e.push({name:o,html:p,subject:l})}catch{}}}catch{}return e}async function M(r,t,e){try{let s=I(e,"process.edn"),o=T(s,"utf-8"),n=Ne(e),i=await _e(void 0,r,t,o,n);i.noChanges?console.log("No changes"):y(`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 D,mkdirSync as _}from"node:fs";import{join as O}from"node:path";async function L(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);_(e,{recursive:!0}),a||console.error(`Creating a new directory: ${e}`);let p=O(e,"process.edn");D(p,n.definition,"utf-8");let l=n.emailTemplates||[];if(l&&Array.isArray(l)&&l.length>0){let m=O(e,"templates");_(m,{recursive:!0});for(let f of l){let h=f.name,v=f.html,A=f.subject;if(h){let d=O(m,h);if(_(d,{recursive:!0}),v){let g=O(d,`${h}-html.html`);D(g,v,"utf-8")}if(A){let g=O(d,`${h}-subject.txt`);D(g,A,"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 je,updateAlias as Fe,deleteAlias as Ke}from"sharetribe-flex-build-sdk";async function N(r,t,e,s){try{let o=await je(void 0,r,t,e,s);y(`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 $(r,t,e,s){try{let o=await Fe(void 0,r,t,e,s);y(`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(r,t,e){try{let s=await Ke(void 0,r,t,e);y(`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 Ue,parseProcessFile as Ve}from"sharetribe-flex-build-sdk";import{readFileSync as He}from"node:fs";import{join as Je}from"node:path";async function F(r,t,e,s){try{let o=Je(e,"process.edn"),n=He(o,"utf-8"),i=Ve(n),a=await Ue(void 0,r,{process:t,alias:s,path:o,processDefinition:i});a.processCreated&&y(`Process ${t} successfully created.`),y(`Version ${a.version} successfully saved for process ${t}.`),a.aliasCreated?y(`Alias ${a.alias} successfully created to point to version ${a.version}.`):y(`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 G(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 R(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 q(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 M(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 L(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 N(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 $(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 j(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 F(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 R(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 q(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 M(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 L(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 N(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 $(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 j(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 F(s,e.process,e.path,e.alias)})}import{listSearchSchemas as Be,setSearchSchema as We,unsetSearchSchema as Ge}from"sharetribe-flex-build-sdk";var Q={metadata:"Metadata",private:"Private data",protected:"Protected data",public:"Public data"};async function Qe(r,t){try{await We(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=Q[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 Ye(r,t){try{await Ge(void 0,r,{key:t.key,scope:t.scope,schemaFor:t.schemaFor});let e=t.schemaFor||"listing",s=Q[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 Xe(r){return r==null?"":Array.isArray(r)?r.join(", "):String(r)}async function ze(r){try{let t=await Be(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":Xe(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 p=i[a]||"";o[a]=Math.max(o[a],p.length)}console.log("");let n=s.map((i,a)=>{let p=o[i]||0,l=i.padEnd(p);return a===s.length-1?l+" ":l+" "});console.log(n.join(""));for(let i of e){let a=s.map((p,l)=>{let m=i[p]||"",f=o[p]||0,h=m.padEnd(f);return l===s.length-1?h+" ":h+" "});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 Y(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 ze(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 Qe(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 Ye(s,{key:e.key,scope:e.scope,schemaFor:e.schemaFor})})}import{pullAssets as Ze,pushAssets as et,stageAsset as tt}from"sharetribe-flex-build-sdk";import{readFileSync as z,writeFileSync as Z,existsSync as C,mkdirSync as K,readdirSync as st,statSync as U,unlinkSync as rt}from"node:fs";import{join as k,dirname as ot}from"node:path";import{createHash as nt}from"node:crypto";import X from"chalk";import E from"jsedn";function ee(r){let t=k(r,".flex-cli","asset-meta.edn");if(!C(t))return null;try{let e=z(t,"utf-8"),s=E.parse(e),o=s.at(E.kw(":version")),n=s.at(E.kw(":assets")),i=[];if(n&&n.val)for(let a of n.val)i.push({path:a.at(E.kw(":path")),"content-hash":a.at(E.kw(":content-hash"))});return{version:o,assets:i}}catch{return null}}function te(r,t){let e=k(r,".flex-cli");C(e)||K(e,{recursive:!0});let s=t.assets.map(i=>new E.Map([E.kw(":path"),i.path,E.kw(":content-hash"),i["content-hash"]])),o=new E.Map([E.kw(":version"),t.version,E.kw(":assets"),new E.Vector(s)]),n=k(r,".flex-cli","asset-meta.edn");Z(n,E.encode(o),"utf-8")}function se(r){let t=Buffer.from(`${r.length}|`,"utf-8");return nt("sha1").update(t).update(r).digest("hex")}function it(r){let t=[];function e(s,o=""){let n=st(s);for(let i of n){if(i===".flex-cli"||i===".DS_Store")continue;let a=k(s,i),p=o?k(o,i):i,l=U(a);if(l.isDirectory())e(a,p);else if(l.isFile()){let m=z(a),f=se(m);t.push({path:p,data:m,hash:f})}}}return e(r),t}function at(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 ct(r,t,e,s){try{if(C(t)||K(t,{recursive:!0}),!U(t).isDirectory())throw new Error(`${t} is not a directory`);let n=await Ze(void 0,r,e?{version:e}:void 0),i=n.version,a=ee(t);if(a&&a.version===i&&n.assets.length===a.assets.length){console.log("Assets are up to date.");return}let p=[];for(let l of n.assets){let m=k(t,l.path),f=ot(m);C(f)||K(f,{recursive:!0});let h=Buffer.from(l.dataRaw,"base64");Z(m,h);let v=se(h);p.push({path:l.path,"content-hash":l.contentHash||v})}if(s&&a){let l=new Set(n.assets.map(m=>m.path));for(let m of a.assets)if(!l.has(m.path)){let f=k(t,m.path);C(f)&&rt(f)}}te(t,{version:i,assets:p}),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)}}function lt(r,t){let e=new Map(r.map(s=>[s.path,s["content-hash"]]));return t.filter(s=>{let o=e.get(s.path);return!o||o!==s.hash})}async function pt(r,t,e){try{if(!C(t)||!U(t).isDirectory())throw new Error(`${t} is not a valid directory`);let s=ee(t),o=s?.version||"nil",n=it(t);at(n);let i=lt(s?.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&&s)for(let d of s.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(X.green(`Uploading changed assets: ${d}`))}let h=new Map;if(p.length>0){let d=p.map(g=>g.path).join(", ");console.log(X.green(`Staging assets: ${d}`));for(let g of p)try{let S=await tt(void 0,r,g.data,g.path);h.set(g.path,S.stagingId)}catch(S){if(S&&typeof S=="object"&&"code"in S&&S.code==="asset-invalid-content"){let ve="message"in S?S.message:"The file is missing or uses an unsupported format.";throw new Error(`Failed to stage image ${g.path}: ${ve}
|
|
4
|
+
Fix the file and rerun assets push to retry staging.`)}throw S}}let v=i.map(d=>{let g=h.get(d.path);return{path:d.path,op:"upsert",...g?{stagingId:g}:{data:d.data,filename:d.path}}}),A=await et(void 0,r,o,[...v,...m]);te(t,{version:A.version,assets:A.assets.map(d=>({path:d.path,"content-hash":d.contentHash}))}),console.log(`New version ${A.version} successfully created.`)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to push assets"),process.exit(1)}}function re(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 ct(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 pt(s,e.path,e.prune)})}import{sendNotification as mt,previewNotification as dt}from"sharetribe-flex-build-sdk";import{readFileSync as V,existsSync as b,statSync as ft}from"node:fs";import{join as oe}from"node:path";import{createServer as ut}from"node:http";function ne(r){if(!b(r)||!ft(r).isDirectory())throw new Error(`Template directory not found: ${r}`);let t=oe(r,"template.html"),e=oe(r,"template-subject.txt");if(!b(t))throw new Error(`template.html not found in ${r}`);if(!b(e))throw new Error(`template-subject.txt not found in ${r}`);let s=V(t,"utf-8"),o=V(e,"utf-8").trim();return{html:s,subject:o}}function ie(r){if(!r)return;if(!b(r))throw new Error(`Context file not found: ${r}`);let t=V(r,"utf-8");try{return JSON.parse(t)}catch(e){throw new Error(`Invalid JSON in context file: ${e}`)}}async function ht(r,t,e){try{let s=ne(t),o=ie(e),n=await mt(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 gt(r,t,e){try{let s=ne(t),o=ie(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 m=(await dt(void 0,r,{template:s,context:o})).html,f=`<title>${s.subject}</title>`;m.includes("<head>")?n=m.replace("<head>",`<head>
|
|
5
|
+
${f}`):m.includes("<html>")?n=m.replace("<html>",`<html>
|
|
6
|
+
<head>${f}</head>`):n=`<html><head>${f}</head><body>${m}</body></html>`}catch(l){n=`
|
|
6
7
|
<html>
|
|
7
8
|
<head><title>Error</title></head>
|
|
8
9
|
<body style="font-family: sans-serif; padding: 20px;">
|
|
@@ -10,10 +11,10 @@ ${p}`):d.includes("<html>")?n=d.replace("<html>",`<html>
|
|
|
10
11
|
<pre style="background: #f5f5f5; padding: 15px; border-radius: 4px;">${l&&typeof l=="object"&&"message"in l?l.message:"Failed to preview notification"}</pre>
|
|
11
12
|
</body>
|
|
12
13
|
</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",s),process.on("SIGTERM",s)}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to tail events"),process.exit(1)}}function
|
|
16
|
-
`)}function
|
|
14
|
+
`}};await i();let a=ut(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(`
|
|
15
|
+
Shutting down preview server...`),a.close(()=>{process.exit(0)})};process.on("SIGINT",p),process.on("SIGTERM",p)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to preview notification"),process.exit(1)}}function ae(r){let t=r.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 s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await gt(s,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 s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await ht(s,e.template,e.context)})}import{getListingApprovalStatus as yt,enableListingApproval as Et,disableListingApproval as St}from"sharetribe-flex-build-sdk";async function kt(r){try{(await yt(void 0,r)).enabled?console.log(`Listing approvals are enabled in ${r}`):console.log(`Listing approvals are disabled in ${r}`)}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(r){try{await Et(void 0,r),console.log(`Successfully enabled listing approvals in ${r}`)}catch(t){t&&typeof t=="object"&&"message"in t?c(t.message):c("Failed to enable listing approvals"),process.exit(1)}}async function At(r){try{await St(void 0,r),console.log(`Successfully disabled listing approvals in ${r}`)}catch(t){t&&typeof t=="object"&&"message"in t?c(t.message):c("Failed to disable listing approvals"),process.exit(1)}}function ce(r){let t=r.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 s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await kt(s)}),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 s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await vt(s)}),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 s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await At(s)})}import{queryEvents as wt,pollEvents as Ct}from"sharetribe-flex-build-sdk";function le(r){if([r.sequenceId!==void 0,r.afterSeqId!==void 0,r.beforeSeqId!==void 0,r.afterTs!==void 0,r.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(r.resourceId&&r.relatedResourceId)throw new Error("Only one of --resource or --related-resource can be specified")}function pe(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 Pt(r,t){try{le(t);let e=await wt(void 0,r,{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 s of e){let{auditEmails:o,...n}=s;console.log(JSON.stringify(n))}else if(t.jsonPretty)for(let s of e){let{auditEmails:o,...n}=s;console.log(JSON.stringify(n,null,2))}else w(["Seq ID","Resource ID","Event type","Created at local time","Source","Actor"],e.map(s=>{let o=s.auditEmails?.userEmail||s.auditEmails?.adminEmail||"",n=s.source?.replace("source/","")||"";return{"Seq ID":s.sequenceId.toString(),"Resource ID":s.resourceId,"Event type":s.eventType,"Created at local time":pe(s.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 It(r,t){try{le(t),console.log("Tailing events... Press Ctrl+C to stop"),console.log("");let e=Ct(void 0,r,{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 w(["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":pe(n.createdAt),Source:a,Actor:i}}))},5e3),s=()=>{console.log(`
|
|
16
|
+
Stopping tail...`),e(),process.exit(0)};process.on("SIGINT",s),process.on("SIGTERM",s)}catch(e){e&&typeof e=="object"&&"message"in e?c(e.message):c("Failed to tail events"),process.exit(1)}}function me(r){let t=r.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 s=e.marketplace||r.opts().marketplace;s||(console.error("Could not parse arguments:"),console.error("--marketplace is required"),process.exit(1)),await Pt(s,{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 s=e.marketplace||r.opts().marketplace;s||(console.error("Could not parse arguments:"),console.error("--marketplace is required"),process.exit(1)),await It(s,{resourceId:e.resource,relatedResourceId:e.relatedResource,eventTypes:e.filter,limit:e.limit||10,json:e.json,jsonPretty:e.jsonPretty})})}import{updateStripeVersion as Ot,SUPPORTED_STRIPE_VERSIONS as bt}from"sharetribe-flex-build-sdk";import de from"inquirer";async function xt(){return(await de.prompt([{type:"list",name:"version",message:"Select Stripe API version:",choices:[...bt]}])).version}async function Rt(){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 de.prompt([{type:"confirm",name:"confirmed",message:"Do you want to continue?",default:!1}])).confirmed}async function qt(r,t,e){try{let s=t;s||(s=await xt()),e||await Rt()||(console.log("Cancelled."),process.exit(0)),await Ot(void 0,r,s),console.log(`Stripe API version successfully changed to ${s}`)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to update Stripe API version"),process.exit(1)}}function fe(r){r.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 s=e.marketplace||r.opts().marketplace;s||(console.error("Error: --marketplace is required"),process.exit(1)),await qt(s,e.version,e.force)})}import P from"jsedn";import{getConfigMap as Tt,readAuth as Mt}from"sharetribe-flex-build-sdk";function Dt(r){return r.length<=4?`...${r}`:`...${r.slice(-4)}`}function _t(r){let t=[];for(let[e,s]of Object.entries(r))t.push(P.kw(`:${e}`),s);return new P.Map(t)}function ue(){let r=Mt(),t=r?.apiKey?Dt(r.apiKey):"No API key set",e=Tt(),s=new P.Map([P.kw(":api-key"),t,P.kw(":conf-map"),_t(e)]);console.log(P.encode(s))}function Lt(r){let t=[],e=!r.parent,s=r.description();if(s&&(t.push(s),t.push("")),e){let a=r.version();a&&(t.push("VERSION"),t.push(` ${a}`),t.push(""))}t.push("USAGE");let o=Nt(r);t.push(` $ ${o}`),t.push("");let n=ge(r),i=r.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=r.options;if(a.length>0){t.push("OPTIONS");let p=Math.max(...a.map(l=>he(l).length));for(let l of a){let f=he(l).padEnd(p+2),h=l.description||"";t.push(` ${f}${h}`)}t.push("")}}if(n.length>0&&!i){t.push("Subcommand help:");let a=ye(r);t.push(` $ ${a} help [COMMAND]`)}return t.push(""),t.join(`
|
|
17
|
+
`)}function ge(r){let t=[],e=r.commands.filter(s=>!s._hidden&&s.name()!=="help");for(let s of e){let o=$t(s),n=s.commands.filter(i=>!i._hidden);if(s.description()&&t.push({name:o,description:s.description()||""}),n.length>0){let i=ge(s);for(let a of i)t.push(a)}}return r.parent||t.unshift({name:"help",description:"display help for Flex CLI"}),t.sort((s,o)=>s.name.localeCompare(o.name)),t}function ye(r){let t=[],e=r;for(;e;)e.name()&&t.unshift(e.name()),e=e.parent;return t.length>0&&(t[0]="sharetribe-cli"),t.join(" ")}function Nt(r){let t=ye(r),e=r.commands.filter(n=>!n._hidden),s=r.options.length>0;return!r.parent&&e.length>0?`${t} [COMMAND]`:e.length>0&&!s?`${t} [COMMAND]`:t}function $t(r){let t=[],e=r;for(;e&&e.parent;)e.name()&&t.unshift(e.name()),e=e.parent;return t.join(" ")}function he(r){let e=(r.flags||"").split(/,\s*/),s=[];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];s.push(`${a}=${p}`)}else s.push(n)}return s.join(", ")}function Ee(r){r.configureHelp({formatHelp:(t,e)=>Lt(t)})}function Se(r){let t=r.findIndex(o=>o==="process");if(t===-1)return r;let e=r[t+1];return e&&["list","create","push","pull","create-alias","update-alias","delete-alias","deploy"].includes(e)?[...r.slice(0,t),`process-${e}`,...r.slice(t+2)]:r}var Ht=Kt(import.meta.url),Jt=Ut(Ht),Bt=JSON.parse(Ft(Vt(Jt,"../package.json"),"utf-8")),ke=Se(process.argv),u=new jt;Ee(u);u.configureOutput({writeOut:r=>process.stdout.write(r+`
|
|
17
18
|
`),writeErr:r=>process.stderr.write(r+`
|
|
18
|
-
`)});
|
|
19
|
+
`)});u.name("sharetribe-cli").description("CLI to interact with Sharetribe Flex").version(Bt.version,"-V","output the version number").option("-m, --marketplace <MARKETPLACE_ID>","marketplace identifier");u.command("version").description("show version").action(()=>{J()});u.command("login").description("log in with API key").action(async()=>{await B()});u.command("logout").description("logout").action(async()=>{await W()});u.command("debug").description("display debug info").action(()=>{ue()});G(u);Y(u);re(u);ae(u);ce(u);me(u);fe(u);u.command("help [command...]").description("display help for Flex CLI").action(r=>{if(!r||r.length===0){u.outputHelp();return}let t=u;for(let e of r){let s=t.commands.find(o=>o.name()===e);s||(console.error(`Unknown command: ${r.join(" ")}`),process.exit(1)),t=s}t.outputHelp()});ke.slice(2).length?u.parse(ke):u.outputHelp();
|
|
19
20
|
//# sourceMappingURL=index.js.map
|