sharetribe-cli 1.15.0 → 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 +10 -9
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
- package/src/commands/assets/index.ts +86 -26
- package/src/commands/debug.ts +36 -0
- package/src/index.ts +9 -0
- package/test/assets.test.ts +141 -0
- package/test/strict-comparison.test.ts +45 -5
package/dist/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import{Command as bt}from"commander";import{readFileSync as Rt}from"node:fs";import{fileURLToPath as xt}from"node:url";import{dirname as qt,join as Tt}from"node:path";import{readFileSync as ye}from"node:fs";import{fileURLToPath as Ee}from"node:url";import{dirname as U,join as Se}from"node:path";function ke(){let r=Ee(import.meta.url),t=U(r);for(;t!=="/";)try{let e=Se(t,"package.json");return ye(e,"utf-8")}catch{t=U(t)}throw new Error("Could not find package.json")}function V(){let r=JSON.parse(ke());console.log(r.version)}import ve from"inquirer";import{writeAuth as Ae}from"sharetribe-flex-build-sdk";async function H(){let r=await ve.prompt([{type:"password",name:"apiKey",message:"Enter API key:",mask:"*",validate:t=>!t||t.trim().length===0?"API key cannot be empty":!0}]);Ae({apiKey:r.apiKey}),console.log("Successfully logged in.")}import{clearAuth as we}from"sharetribe-flex-build-sdk";async function J(){await we(),console.log("Successfully logged out.")}import{listProcesses as Ce,listProcessVersions as Pe}from"sharetribe-flex-build-sdk";import I from"chalk";function E(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(I.bold.black(o));for(let n of t){let a=r.map((m,p)=>{let l=n[m]||"",d=e[m]||0,f=l.padEnd(d+1);return p===r.length-1?f:f+" "}).join("");console.log(a)}console.log("")}function c(r){console.error(I.red(`Error: ${r}`))}function h(r){console.log(I.green(r))}function Ie(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 O(r,t){try{if(t){let e=await Pe(void 0,r,t);if(e.length===0){console.log(`No versions found for process: ${t}`);return}let s=e.map(o=>({Created:Ie(o.createdAt),Version:o.version.toString(),Aliases:o.aliases?.join(", ")||"",Transactions:o.transactionCount?.toString()||"0"}));E(["Created","Version","Aliases","Transactions"],s)}else{let e=await Ce(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()||""}));E(["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 Oe}from"sharetribe-flex-build-sdk";import{readFileSync as be}from"node:fs";import{join as Re}from"node:path";async function b(r,t,e){try{let s=Re(e,"process.edn"),o=be(s,"utf-8"),n=await Oe(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 xe}from"sharetribe-flex-build-sdk";import{readFileSync as R,readdirSync as qe}from"node:fs";import{join as k}from"node:path";function Te(r){let t=k(r,"templates"),e=[];try{let s=qe(t);for(let o of s){let n=k(t,o),i=k(n,`${o}-html.html`),a=k(n,`${o}-subject.txt`);try{let m=R(i,"utf-8"),p=R(a,"utf-8");e.push({name:o,html:m,subject:p})}catch{}}}catch{}return e}async function x(r,t,e){try{let s=k(e,"process.edn"),o=R(s,"utf-8"),n=Te(e),i=await xe(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 De}from"sharetribe-flex-build-sdk";import{writeFileSync as q,mkdirSync as T}from"node:fs";import{join as v}from"node:path";async function D(r,t,e,s,o){try{let n=await De(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);T(e,{recursive:!0}),a||console.error(`Creating a new directory: ${e}`);let m=v(e,"process.edn");q(m,n.definition,"utf-8");let p=n.emailTemplates||[];if(p&&Array.isArray(p)&&p.length>0){let l=v(e,"templates");T(l,{recursive:!0});for(let d of p){let f=d.name,A=d.html,K=d.subject;if(f){let C=v(l,f);if(T(C,{recursive:!0}),A){let P=v(C,`${f}-html.html`);q(P,A,"utf-8")}if(K){let P=v(C,`${f}-subject.txt`);q(P,K,"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 _e,updateAlias as Me,deleteAlias as Le}from"sharetribe-flex-build-sdk";async function _(r,t,e,s){try{let o=await _e(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 M(r,t,e,s){try{let o=await Me(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 L(r,t,e){try{let s=await Le(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 Ne,parseProcessFile as je}from"sharetribe-flex-build-sdk";import{readFileSync as $e}from"node:fs";import{join as Fe}from"node:path";async function N(r,t,e,s){try{let o=Fe(e,"process.edn"),n=$e(o,"utf-8"),i=je(n),a=await Ne(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 O(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 b(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 x(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 M(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 L(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 N(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 O(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 b(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 x(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 M(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 L(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 N(s,e.process,e.path,e.alias)})}import{listSearchSchemas as Ke,setSearchSchema as Ue,unsetSearchSchema as Ve}from"sharetribe-flex-build-sdk";var B={metadata:"Metadata",private:"Private data",protected:"Protected data",public:"Public data"};async function He(r,t){try{await Ue(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=B[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 Je(r,t){try{await Ve(void 0,r,{key:t.key,scope:t.scope,schemaFor:t.schemaFor});let e=t.schemaFor||"listing",s=B[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 We(r){return r==null?"":Array.isArray(r)?r.join(", "):String(r)}async function Be(r){try{let t=await Ke(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":We(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,p=i.padEnd(m);return a===s.length-1?p+" ":p+" "});console.log(n.join(""));for(let i of e){let a=s.map((m,p)=>{let l=i[m]||"",d=o[m]||0,f=l.padEnd(d);return p===s.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 G(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 Be(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 He(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 Je(s,{key:e.key,scope:e.scope,schemaFor:e.schemaFor})})}import{pullAssets as Ge,pushAssets as Qe}from"sharetribe-flex-build-sdk";import{readFileSync as Q,writeFileSync as Y,existsSync as S,mkdirSync as j,readdirSync as Ye,statSync as $,unlinkSync as Xe}from"node:fs";import{join as y,dirname as ze}from"node:path";import{createHash as Ze}from"node:crypto";import g from"jsedn";function X(r){let t=y(r,".flex-cli","asset-meta.edn");if(!S(t))return null;try{let e=Q(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=y(r,".flex-cli");S(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=y(r,".flex-cli","asset-meta.edn");Y(n,g.encode(o),"utf-8")}function Z(r){return Ze("sha1").update(r).digest("hex")}function et(r){let t=[];function e(s,o=""){let n=Ye(s);for(let i of n){if(i===".flex-cli")continue;let a=y(s,i),m=o?y(o,i):i,p=$(a);if(p.isDirectory())e(a,m);else if(p.isFile()){let l=Q(a),d=Z(l);t.push({path:m,data:l,hash:d})}}}return e(r),t}function tt(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 st(r,t,e,s){try{if(S(t)||j(t,{recursive:!0}),!$(t).isDirectory())throw new Error(`${t} is not a directory`);let n=await Ge(void 0,r,e?{version:e}:void 0),i=n.version,a=X(t);if(a&&a.version===i&&n.assets.length===a.assets.length){console.log("Assets are up to date.");return}let m=[];for(let p of n.assets){let l=y(t,p.path),d=ze(l);S(d)||j(d,{recursive:!0});let f=Buffer.from(p.dataRaw,"base64");Y(l,f);let A=Z(f);m.push({path:p.path,"content-hash":p.contentHash||A})}if(s&&a){let p=new Set(n.assets.map(l=>l.path));for(let l of a.assets)if(!p.has(l.path)){let d=y(t,l.path);S(d)&&Xe(d)}}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 rt(r,t,e){try{if(!S(t)||!$(t).isDirectory())throw new Error(`${t} is not a valid directory`);let s=X(t),o=s?.version||"nil",n=et(t);tt(n);let i=[],a=new Map(n.map(l=>[l.path,l])),m=new Map((s?.assets||[]).map(l=>[l.path,l["content-hash"]]));for(let[l,d]of a){let f=m.get(l);(!f||f!==d.hash)&&i.push({path:l,op:"upsert",data:d.data})}if(e&&s)for(let l of s.assets)a.has(l.path)||i.push({path:l.path,op:"delete"});if(i.length===0){console.log("Assets are up to date.");return}let p=await Qe(void 0,r,o,i);z(t,{version:p.version,assets:p.assets.map(l=>({path:l.path,"content-hash":l.contentHash}))}),console.log(`New version ${p.version} successfully created.`)}catch(s){s&&typeof s=="object"&&"message"in s?c(s.message):c("Failed to push assets"),process.exit(1)}}function ee(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 st(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 rt(s,e.path,e.prune)})}import{sendNotification as ot,previewNotification as nt}from"sharetribe-flex-build-sdk";import{readFileSync as F,existsSync as w,statSync as it}from"node:fs";import{join as te}from"node:path";import{createServer as at}from"node:http";function se(r){if(!w(r)||!it(r).isDirectory())throw new Error(`Template directory not found: ${r}`);let t=te(r,"template.html"),e=te(r,"template-subject.txt");if(!w(t))throw new Error(`template.html not found in ${r}`);if(!w(e))throw new Error(`template-subject.txt not found in ${r}`);let s=F(t,"utf-8"),o=F(e,"utf-8").trim();return{html:s,subject:o}}function re(r){if(!r)return;if(!w(r))throw new Error(`Context file not found: ${r}`);let t=F(r,"utf-8");try{return JSON.parse(t)}catch(e){throw new Error(`Invalid JSON in context file: ${e}`)}}async function ct(r,t,e){try{let s=se(t),o=re(e),n=await ot(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 lt(r,t,e){try{let s=se(t),o=re(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 l=(await nt(void 0,r,{template:s,context:o})).html,d=`<title>${s.subject}</title>`;l.includes("<head>")?n=l.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;">
|
|
9
10
|
<h1 style="color: #d32f2f;">Error</h1>
|
|
10
|
-
<pre style="background: #f5f5f5; padding: 15px; border-radius: 4px;">${
|
|
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
|
-
`)});u.name("sharetribe-cli").description("CLI to interact with Sharetribe Flex").version(
|
|
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
|