@foxtware/mineral 1.0.5 → 1.0.7

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.
Files changed (87) hide show
  1. package/.creds.yml.sample +1 -0
  2. package/_build_scripts/createNewFunction.js +23 -41
  3. package/api/UTILS.md +1 -1
  4. package/api/bleckmann/bleckmannPickticketGet.js +4 -2
  5. package/api/github/githubActionsSecretCreateOrUpdate.js +139 -0
  6. package/api/github/githubActionsSecretPublicKeyGet.js +59 -0
  7. package/api/google/googlecalendarEventCreate.js +2 -0
  8. package/api/linear/linearTeamGet.js +6 -3
  9. package/api/shopify/shopify.constants.js +25 -0
  10. package/api/shopify/shopify.utils.js +41 -6
  11. package/api/shopify/shopifyInventoryQuantitiesSet.js +164 -0
  12. package/api/shopify/shopifyMutationDo.js +12 -6
  13. package/api/shopify/shopifyShopGet.js +68 -0
  14. package/api/shopify/shopifyStorefrontArticleGet.js +86 -0
  15. package/api/shopify/shopifyStorefrontArticlesGet.js +67 -0
  16. package/api/shopify/shopifyStorefrontBlogGet.js +110 -0
  17. package/api/shopify/shopifyStorefrontBlogsGet.js +66 -0
  18. package/api/shopify/shopifyStorefrontCartAttributesUpdate.js +87 -0
  19. package/api/shopify/shopifyStorefrontCartBuyerIdentityUpdate.js +87 -0
  20. package/api/shopify/shopifyStorefrontCartCreate.js +83 -0
  21. package/api/shopify/shopifyStorefrontCartDeliveryAddressesAdd.js +87 -0
  22. package/api/shopify/shopifyStorefrontCartDeliveryAddressesRemove.js +87 -0
  23. package/api/shopify/shopifyStorefrontCartDeliveryAddressesReplace.js +87 -0
  24. package/api/shopify/shopifyStorefrontCartDeliveryAddressesUpdate.js +87 -0
  25. package/api/shopify/shopifyStorefrontCartDiscountCodesUpdate.js +87 -0
  26. package/api/shopify/shopifyStorefrontCartGet.js +100 -0
  27. package/api/shopify/shopifyStorefrontCartGiftCardCodesAdd.js +87 -0
  28. package/api/shopify/shopifyStorefrontCartGiftCardCodesRemove.js +87 -0
  29. package/api/shopify/shopifyStorefrontCartGiftCardCodesUpdate.js +87 -0
  30. package/api/shopify/shopifyStorefrontCartLinesAdd.js +87 -0
  31. package/api/shopify/shopifyStorefrontCartLinesRemove.js +87 -0
  32. package/api/shopify/shopifyStorefrontCartLinesUpdate.js +87 -0
  33. package/api/shopify/shopifyStorefrontCartMetafieldDelete.js +69 -0
  34. package/api/shopify/shopifyStorefrontCartMetafieldsSet.js +80 -0
  35. package/api/shopify/shopifyStorefrontCartNoteUpdate.js +87 -0
  36. package/api/shopify/shopifyStorefrontCartSelectedDeliveryOptionsUpdate.js +87 -0
  37. package/api/shopify/shopifyStorefrontCollectionGet.js +92 -0
  38. package/api/shopify/shopifyStorefrontCollectionsGet.js +66 -0
  39. package/api/shopify/shopifyStorefrontCustomerAccessTokenCreate.js +75 -0
  40. package/api/shopify/shopifyStorefrontCustomerAccessTokenCreateWithMultipass.js +72 -0
  41. package/api/shopify/shopifyStorefrontCustomerAccessTokenDelete.js +67 -0
  42. package/api/shopify/shopifyStorefrontCustomerAccessTokenRenew.js +72 -0
  43. package/api/shopify/shopifyStorefrontCustomerActivate.js +98 -0
  44. package/api/shopify/shopifyStorefrontCustomerActivateByUrl.js +91 -0
  45. package/api/shopify/shopifyStorefrontCustomerAddressCreate.js +94 -0
  46. package/api/shopify/shopifyStorefrontCustomerAddressDelete.js +78 -0
  47. package/api/shopify/shopifyStorefrontCustomerAddressUpdate.js +101 -0
  48. package/api/shopify/shopifyStorefrontCustomerCreate.js +79 -0
  49. package/api/shopify/shopifyStorefrontCustomerDefaultAddressUpdate.js +89 -0
  50. package/api/shopify/shopifyStorefrontCustomerGet.js +92 -0
  51. package/api/shopify/shopifyStorefrontCustomerRecover.js +64 -0
  52. package/api/shopify/shopifyStorefrontCustomerReset.js +98 -0
  53. package/api/shopify/shopifyStorefrontCustomerResetByUrl.js +91 -0
  54. package/api/shopify/shopifyStorefrontCustomerUpdate.js +93 -0
  55. package/api/shopify/shopifyStorefrontGet.js +233 -0
  56. package/api/shopify/shopifyStorefrontLocalizationGet.js +98 -0
  57. package/api/shopify/shopifyStorefrontLocationsGet.js +70 -0
  58. package/api/shopify/shopifyStorefrontMenuGet.js +93 -0
  59. package/api/shopify/shopifyStorefrontMetaobjectGet.js +126 -0
  60. package/api/shopify/shopifyStorefrontMetaobjectsGet.js +73 -0
  61. package/api/shopify/shopifyStorefrontMutationDo.js +103 -0
  62. package/api/shopify/shopifyStorefrontNodeGet.js +90 -0
  63. package/api/shopify/shopifyStorefrontNodesGet.js +86 -0
  64. package/api/shopify/shopifyStorefrontPageGet.js +93 -0
  65. package/api/shopify/shopifyStorefrontPagesGet.js +66 -0
  66. package/api/shopify/shopifyStorefrontPaymentSettingsGet.js +79 -0
  67. package/api/shopify/shopifyStorefrontPredictiveSearch.js +138 -0
  68. package/api/shopify/shopifyStorefrontProductGet.js +94 -0
  69. package/api/shopify/shopifyStorefrontProductRecommendationsGet.js +112 -0
  70. package/api/shopify/shopifyStorefrontProductTagsGet.js +80 -0
  71. package/api/shopify/shopifyStorefrontProductTypesGet.js +80 -0
  72. package/api/shopify/shopifyStorefrontProductsGet.js +76 -0
  73. package/api/shopify/shopifyStorefrontPublicApiVersionsGet.js +75 -0
  74. package/api/shopify/shopifyStorefrontSearch.js +8 -2
  75. package/api/shopify/shopifyStorefrontShopGet.js +81 -0
  76. package/api/shopify/shopifyStorefrontShopPayPaymentRequestSessionCreate.js +91 -0
  77. package/api/shopify/shopifyStorefrontShopPayPaymentRequestSessionSubmit.js +95 -0
  78. package/api/shopify/shopifyStorefrontSitemapGet.js +98 -0
  79. package/api/shopify/shopifyStorefrontUrlRedirectsGet.js +67 -0
  80. package/api/slack/docs.md +4 -0
  81. package/api/slack/slack.utils.js +36 -2
  82. package/api/slack/slackMessagePost.js +11 -3
  83. package/api/slack/slackMessagesSearch.js +81 -0
  84. package/api/utils.js +44 -8
  85. package/hosting/deployFromHostingYml.js +9 -21
  86. package/package.json +3 -1
  87. package/server.utils.js +24 -15
package/api/utils.js CHANGED
@@ -185,7 +185,13 @@ const xmlResponseParser = (parserOptions = {}) => {
185
185
  };
186
186
 
187
187
  const getResponseParser = (contentType) => {
188
- if (contentType?.includes('jsonl') || contentType?.includes('ndjson')) return (res) => res.text();
188
+ if (!contentType) {
189
+ return async (res) => {
190
+ const text = await res.text();
191
+ return text || null;
192
+ };
193
+ }
194
+ if (contentType.includes('jsonl') || contentType.includes('ndjson')) return (res) => res.text();
189
195
  if (contentType.includes('application/json')) return (res) => res.json();
190
196
  if (contentType.includes('text/xml')) return xmlResponseParser();
191
197
  if (contentType.includes('application/soap+xml')) return (res) => res.text();
@@ -1393,10 +1399,11 @@ const objectMatchesPartial = (object, partial) => {
1393
1399
  ));
1394
1400
  };
1395
1401
 
1396
- const oneFromManyInResponse = (
1402
+ const oneFromManyResponse = (
1397
1403
  response,
1398
- idProp,
1399
- idValue,
1404
+ {
1405
+ validator,
1406
+ } = {},
1400
1407
  ) => {
1401
1408
  const {
1402
1409
  ok,
@@ -1406,15 +1413,19 @@ const oneFromManyInResponse = (
1406
1413
  if (!ok || !data) {
1407
1414
  return response;
1408
1415
  }
1416
+
1417
+ let candidates = data;
1409
1418
 
1410
- const candidates = data.filter(item => item[idProp] === idValue);
1419
+ if (validator) {
1420
+ candidates = candidates.filter(validator);
1421
+ }
1411
1422
 
1412
1423
  if (candidates.length === 0) {
1413
1424
  return {
1414
1425
  ok: true,
1415
1426
  data: null,
1416
1427
  meta: {
1417
- message: `No item found with ${ idProp } ${ idValue }`,
1428
+ message: `No ${ validator ? 'matching ' : '' }item found`,
1418
1429
  },
1419
1430
  };
1420
1431
  }
@@ -1425,7 +1436,7 @@ const oneFromManyInResponse = (
1425
1436
  ok: true,
1426
1437
  data: null,
1427
1438
  meta: {
1428
- message: `Multiple items found with ${ idProp } ${ idValue }`,
1439
+ message: `Multiple ${ validator ? 'matching ' : '' }items found`,
1429
1440
  },
1430
1441
  };
1431
1442
  }
@@ -1572,6 +1583,30 @@ const arrayPartition = (array, partitioner) => {
1572
1583
  return { passed, rejected };
1573
1584
  };
1574
1585
 
1586
+ const truncateMiddle = (
1587
+ value,
1588
+ maxLength,
1589
+ {
1590
+ marker = '...',
1591
+ includeMarkerInLength = false,
1592
+ } = {},
1593
+ ) => {
1594
+ const string = String(value ?? '');
1595
+ if (string.length <= maxLength) {
1596
+ return string;
1597
+ }
1598
+
1599
+ if (includeMarkerInLength && maxLength <= marker.length) {
1600
+ return marker.slice(0, maxLength);
1601
+ }
1602
+
1603
+ const available = includeMarkerInLength ? maxLength - marker.length : maxLength;
1604
+ const frontLength = Math.ceil(available / 2);
1605
+ const backLength = Math.floor(available / 2);
1606
+
1607
+ return `${ string.slice(0, frontLength) }${ marker }${ string.slice(string.length - backLength) }`;
1608
+ };
1609
+
1575
1610
  module.exports = {
1576
1611
  wait,
1577
1612
  timeMs,
@@ -1613,7 +1648,7 @@ module.exports = {
1613
1648
  valueProvided,
1614
1649
  objectToArray,
1615
1650
  objectMatchesPartial,
1616
- oneFromManyInResponse,
1651
+ oneFromManyResponse,
1617
1652
  surveyObject,
1618
1653
  diffObjects,
1619
1654
  objectPropsTranslate,
@@ -1621,4 +1656,5 @@ module.exports = {
1621
1656
  deterministicArrayItem,
1622
1657
  oneTrickProcessor,
1623
1658
  arrayPartition,
1659
+ truncateMiddle,
1624
1660
  };
@@ -1,5 +1,5 @@
1
- const readline = require('readline');
2
1
  const { toAbsolutePath, setWorkspace, loadWorkspaceEnv } = require('../api/workspace');
2
+ const choicy = require('choicy');
3
3
  const { getApiDirs, readCliFlag } = require('../cli');
4
4
  const { loadHandlers } = require('../server');
5
5
  const {
@@ -31,24 +31,6 @@ const getHostConfig = (options = {}) => ({
31
31
  api_dirs: getApiDirs(options),
32
32
  });
33
33
 
34
- const chooseOption = async (prompt, options) => new Promise((resolve) => {
35
- const rl = readline.createInterface({
36
- input: process.stdin,
37
- output: process.stdout,
38
- });
39
-
40
- console.log(prompt);
41
- options.forEach((option, index) => {
42
- console.log(` ${ index + 1 }. ${ option }`);
43
- });
44
-
45
- rl.question('> ', (answer) => {
46
- rl.close();
47
- const choice = Number(answer) - 1;
48
- resolve(options[choice] ?? options[0]);
49
- });
50
- });
51
-
52
34
  const getDeployArgs = () => {
53
35
  const args = process.argv.slice(2);
54
36
  const deployArgs = [];
@@ -257,7 +239,10 @@ const deployFromHostingYml = async (options = {}) => {
257
239
  return;
258
240
  }
259
241
 
260
- const selectedGroup = await chooseOption('Which group would you like to deploy?', groupNames);
242
+ const selectedGroup = await choicy(groupNames, {
243
+ question: 'Which group would you like to deploy?',
244
+ oneChoice: true,
245
+ });
261
246
  for (const functionName of groups[selectedGroup] || []) {
262
247
  await deployOne(functionName);
263
248
  }
@@ -271,7 +256,10 @@ const deployFromHostingYml = async (options = {}) => {
271
256
  return;
272
257
  }
273
258
 
274
- const selectedFunction = await chooseOption('Which function would you like to deploy?', functionNames);
259
+ const selectedFunction = await choicy(functionNames, {
260
+ question: 'Which function would you like to deploy?',
261
+ oneChoice: true,
262
+ });
275
263
  await deployOne(selectedFunction);
276
264
  return;
277
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxtware/mineral",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "bin": {
5
5
  "mineral": "bin/mineral.js"
6
6
  },
@@ -23,10 +23,12 @@
23
23
  "dependencies": {
24
24
  "@supabase/supabase-js": "^2.55.0",
25
25
  "@upstash/redis": "^1.28.4",
26
+ "choicy": "^1.1.1",
26
27
  "csvtojson": "^2.0.14",
27
28
  "dotenv": "^17.2.0",
28
29
  "googleapis": "^165.0.0",
29
30
  "json-2-csv": "^5.5.9",
31
+ "libsodium-wrappers": "^0.8.4",
30
32
  "xml2js": "^0.6.2",
31
33
  "yaml": "^2.9.0"
32
34
  },
package/server.utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const { execFileSync } = require('child_process');
2
- const { logDeep, askQuestion } = require('./api/utils');
2
+ const { logDeep } = require('./api/utils');
3
+ const choicy = require('choicy');
3
4
  const { HOSTED } = require('./api/constants');
4
5
  const { StringDecoder } = require('string_decoder');
5
6
 
@@ -368,17 +369,21 @@ const listenOrOfferKillPort = (server, port, onListening) => {
368
369
  };
369
370
 
370
371
  const askRecoveryQuestions = async () => {
371
- const shouldFind = await askQuestion('Look up the process using it? ');
372
+ const shouldFind = await choicy(
373
+ [
374
+ { title: 'Yes', value: true },
375
+ { title: 'No', value: false },
376
+ ],
377
+ {
378
+ question: 'Look up the process using it?',
379
+ oneChoice: true,
380
+ },
381
+ );
372
382
 
373
- if (shouldFind === 'n') {
383
+ if (!shouldFind) {
374
384
  return false;
375
385
  }
376
386
 
377
- if (shouldFind !== '') {
378
- console.error('not a valid input');
379
- exitServer(1);
380
- }
381
-
382
387
  const listeners = findPortListeners(port);
383
388
 
384
389
  if (!listeners.length) {
@@ -388,17 +393,21 @@ const listenOrOfferKillPort = (server, port, onListening) => {
388
393
 
389
394
  console.log('Port in use by:', formatPortListeners(listeners));
390
395
 
391
- const shouldKill = await askQuestion('Kill it and retry? ');
396
+ const shouldKill = await choicy(
397
+ [
398
+ { title: 'Yes', value: true },
399
+ { title: 'No', value: false },
400
+ ],
401
+ {
402
+ question: 'Kill it and retry?',
403
+ oneChoice: true,
404
+ },
405
+ );
392
406
 
393
- if (shouldKill === 'n') {
407
+ if (!shouldKill) {
394
408
  return false;
395
409
  }
396
410
 
397
- if (shouldKill !== '') {
398
- console.error('not a valid input');
399
- exitServer(1);
400
- }
401
-
402
411
  await killPortListeners(listeners);
403
412
  return true;
404
413
  };