Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions bin/pos-cli-constants-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
import { program } from '../lib/program.js';
import Gateway from '../lib/proxy.js';
import { getConstants } from '../lib/graph/queries.js';
import { graphQLErrorMessage } from '../lib/graph/response.js';
import { fetchSettings } from '../lib/settings.js';
import logger from '../lib/logger.js';

const success = (msg) => {
msg.data.constants.results.forEach(x => console.log(x.name.padEnd(50), safe(x.value)));
logger.Print('\n');
};

const safe = (str) => {
if ( process.env.SAFE )
return JSON.stringify(str);
Expand All @@ -26,9 +22,17 @@ program
const gateway = new Gateway(authData);

gateway
.graph({query: getConstants()})
.then(success)
.catch(console.log);
.graph(getConstants())
.then((msg) => {
const errorMessage = graphQLErrorMessage(msg);
if (errorMessage) throw new Error(errorMessage);

msg.data.constants.results.forEach(x => console.log(x.name.padEnd(50), safe(x.value)));
logger.Print('\n');
})
.catch(async (err) => {
await logger.Error(`Listing constants failed: ${err.message || err}`);
});
});

program.parse(process.argv);
22 changes: 11 additions & 11 deletions bin/pos-cli-constants-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { program } from '../lib/program.js';
import Gateway from '../lib/proxy.js';
import { existence as validateExistence } from '../lib/validators/index.js';
import { setConstant } from '../lib/graph/queries.js';
import { graphQLErrorMessage } from '../lib/graph/response.js';
import { fetchSettings } from '../lib/settings.js';
import logger from '../lib/logger.js';

Expand All @@ -17,14 +18,6 @@ const checkParams = ({name, value}) => {
validateExistence({ argumentValue: name, argumentName: 'name', fail: help });
};

const success = (msg) => {
logger.Success(`Constant variable <${msg.data.constant_set.name}> added successfully.`);
};

const error = (msg) => {
logger.Error(`Adding Constant variable <${msg.data.constant_set.name}> failed.`);
};

program
.name('pos-cli constants set')
.option('--name <name>', 'name of constant. Example: TOKEN')
Expand All @@ -36,9 +29,16 @@ program
const gateway = new Gateway(authData);

gateway
.graph({query: setConstant(params.name, params.value)})
.then(success)
.catch(error);
.graph(setConstant(params.name, params.value))
.then((msg) => {
const errorMessage = graphQLErrorMessage(msg);
if (errorMessage) throw new Error(errorMessage);

logger.Success(`Constant variable <${msg.data.constant_set.name}> added successfully.`);
})
.catch(async (err) => {
await logger.Error(`Adding Constant variable <${params.name}> failed: ${err.message || err}`);
});
});

program.parse(process.argv);
28 changes: 14 additions & 14 deletions bin/pos-cli-constants-unset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { program } from '../lib/program.js';
import Gateway from '../lib/proxy.js';
import { existence as validateExistence } from '../lib/validators/index.js';
import { unsetConstant } from '../lib/graph/queries.js';
import { graphQLErrorMessage } from '../lib/graph/response.js';
import { fetchSettings } from '../lib/settings.js';
import logger from '../lib/logger.js';

Expand All @@ -16,17 +17,6 @@ const checkParams = ({name}) => {
validateExistence({ argumentValue: name, argumentName: 'name', fail: help });
};

const success = (msg) => {
if (msg.data.constant_unset)
logger.Success(`Constant variable <${msg.data.constant_unset.name}> deleted successfully.`);
else
logger.Success('Constant variable not found.');
};

const error = (msg) => {
logger.Error(`Deleting Constant variable <${msg.data.constant_unset.name}> failed.`);
};

program
.name('pos-cli constants unset')
.option('--name <name>', 'name of constant. Example: TOKEN')
Expand All @@ -37,9 +27,19 @@ program
const gateway = new Gateway(authData);

gateway
.graph({query: unsetConstant(params.name)})
.then(success)
.catch(error);
.graph(unsetConstant(params.name))
.then((msg) => {
const errorMessage = graphQLErrorMessage(msg);
if (errorMessage) throw new Error(errorMessage);

if (msg.data.constant_unset)
logger.Success(`Constant variable <${msg.data.constant_unset.name}> deleted successfully.`);
else
logger.Success('Constant variable not found.');
})
.catch(async (err) => {
await logger.Error(`Deleting Constant variable <${params.name}> failed: ${err.message || err}`);
});
});

program.parse(process.argv);
8 changes: 6 additions & 2 deletions bin/pos-cli-exec-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { program } from '../lib/program.js';
import logger from '../lib/logger.js';
import { execGraphql } from '../lib/exec/graphql.js';
import { graphQLErrors } from '../lib/graph/response.js';

program
.name('pos-cli exec graphql')
Expand All @@ -25,8 +26,11 @@ program
process.exit(0);
}

if (response.errors) {
await logger.Error(`GraphQL execution error: ${JSON.stringify(response.errors, null, 2)}`);
const errors = graphQLErrors(response);
if (errors) {
// Keep the full array here: this command's whole job is to show the
// instance's raw response, locations and extensions included.
await logger.Error(`GraphQL execution error: ${JSON.stringify(errors, null, 2)}`);
process.exit(1);
}

Expand Down
12 changes: 6 additions & 6 deletions gui/admin/dist/build/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,20 @@ var api = {
return graph({ query }, false);
},
setConstant(name, value) {
const query = `mutation {
constant_set(name: "${name}", value: "${value}") {
const query = `mutation SetConstant($name: String!, $value: String!) {
constant_set(name: $name, value: $value) {
name, value
}
}`;
return graph({ query }, "Constant updated");
return graph({ query, variables: { name, value } }, "Constant updated");
},
unsetConstant(name) {
const query = `mutation {
constant_unset(name: "${name}") {
const query = `mutation UnsetConstant($name: String!) {
constant_unset(name: $name) {
name
}
}`;
return graph({ query }, "Constant unset");
return graph({ query, variables: { name } }, "Constant unset");
}
};

Expand Down
12 changes: 6 additions & 6 deletions gui/admin/dist/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4904,20 +4904,20 @@ var app = (function () {
return graph({ query }, false);
},
setConstant(name, value) {
const query = `mutation {
constant_set(name: "${name}", value: "${value}") {
const query = `mutation SetConstant($name: String!, $value: String!) {
constant_set(name: $name, value: $value) {
name, value
}
}`;
return graph({ query }, "Constant updated");
return graph({ query, variables: { name, value } }, "Constant updated");
},
unsetConstant(name) {
const query = `mutation {
constant_unset(name: "${name}") {
const query = `mutation UnsetConstant($name: String!) {
constant_unset(name: $name) {
name
}
}`;
return graph({ query }, "Constant unset");
return graph({ query, variables: { name } }, "Constant unset");
}
};

Expand Down
26 changes: 17 additions & 9 deletions gui/admin/src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import pageStore from '../pages/Models/Manage/_page-store';

import typeMap from './_typemap';

// Mirrors lib/graph/response.js. Not imported from there: this is a separate
// npm package with its own lockfile, and its build cannot run on current Node
// (routify 1.x), so a cross-package import could not be verified here.
const graphQLErrors = (res) =>
res && Array.isArray(res.errors) && res.errors.length > 0 ? res.errors : null;
const formatGraphQLErrors = (errors) => (errors || []).map((e) => e.message).join(', ');

const getPropsString = (props) => {
return Object.keys(props)
.map((prop) => {
Expand Down Expand Up @@ -36,9 +43,10 @@ const graph = (body, successMessage = 'Success') => {
})
.then((res) => res.json())
.then((res) => {
if (res.errors) {
const err = res.errors[0].message;
return notifier.danger(`Error: ${err}`, 5000);
const errors = graphQLErrors(res);

if (errors) {
return notifier.danger(`Error: ${formatGraphQLErrors(errors)}`, 5000);
} else {
if (successMessage !== false) {
notifier.success(successMessage);
Expand Down Expand Up @@ -204,21 +212,21 @@ export default {
return graph({ query }, false);
},
setConstant(name, value) {
const query = `mutation {
constant_set(name: "${name}", value: "${value}") {
const query = `mutation SetConstant($name: String!, $value: String!) {
constant_set(name: $name, value: $value) {
name, value
}
}`;

return graph({ query }, 'Constant updated');
return graph({ query, variables: { name, value } }, 'Constant updated');
},
unsetConstant(name) {
const query = `mutation {
constant_unset(name: "${name}") {
const query = `mutation UnsetConstant($name: String!) {
constant_unset(name: $name) {
name
}
}`;

return graph({ query }, 'Constant unset');
return graph({ query, variables: { name } }, 'Constant unset');
}
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion gui/next/build/_app/immutable/chunks/49DTrpj7.js

This file was deleted.

1 change: 0 additions & 1 deletion gui/next/build/_app/immutable/chunks/BD1m7lx9.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import{g as o}from"./BD1m7lx9.js";const _={get:async e=>{let t="";e!=null&&e.id&&(t=`id: { value: "${e.id}" }`);let a="";e!=null&&e.type&&(a=`type: ${e.type}`);const r=`
import{g as o}from"./CjsQ2dqX.js";const _={get:async e=>{let t="";e!=null&&e.id&&(t=`id: { value: "${e.id}" }`);let a="";e!=null&&e.type&&(a=`type: ${e.type}`);const r=`
query {
admin_background_jobs(
per_page: 20,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import{g as t}from"./BD1m7lx9.js";const i={get:e=>t({query:`
import{g as t}from"./CjsQ2dqX.js";const i={get:e=>t({query:`
query(
$per_page: Int
$id: ID
Expand Down
1 change: 1 addition & 0 deletions gui/next/build/_app/immutable/chunks/CjsQ2dqX.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gui/next/build/_app/immutable/chunks/oQW2ZZfb.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import{g as n}from"./BD1m7lx9.js";import{b as s}from"./BkeFH9yg.js";const p={get:async(e={})=>{let r="",a="";e.value&&(e.attribute==="email"?r+=`${e.attribute}: { contains: "${e.value}" }`:r+=`${e.attribute}: { value: "${e.value}" }`,(e==null?void 0:e.attribute)==="id"&&(e!=null&&e.value)&&(a=`
import{g as n}from"./CjsQ2dqX.js";import{b as s}from"./BkeFH9yg.js";const p={get:async(e={})=>{let r="",a="";e.value&&(e.attribute==="email"?r+=`${e.attribute}: { contains: "${e.value}" }`:r+=`${e.attribute}: { value: "${e.value}" }`,(e==null?void 0:e.attribute)==="id"&&(e!=null&&e.value)&&(a=`
deleted_at
created_at
external_id
Expand Down
Loading
Loading