Skip to content

Commit

Permalink
feat(cli-next): look in the env for the credentials if they are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Sep 11, 2024
1 parent ba16f99 commit 5bd7ef2
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 41 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crystallize/cli-next",
"version": "4.18.0",
"version": "4.19.0",
"description": "Crystallize CLI",
"main": "./build/index.js",
"repository": "https://github.com/CrystallizeAPI/crystallize-cli-next",
Expand Down Expand Up @@ -46,8 +46,8 @@
"bump": "yarn tsc && yarn version --no-git-tag-version --new-version"
},
"dependencies": {
"@crystallize/import-utilities": "^1.28",
"@crystallize/js-api-client": "^1.12.2",
"@crystallize/import-utilities": "^1.33",
"@crystallize/js-api-client": "^3.2.0",
"chalk": "^5.2",
"cli-spinners": "^2.7.0",
"dotenv": "^16.0.3",
Expand Down
9 changes: 9 additions & 0 deletions src/core/utils/crystallize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { isFileExists, loadJSON, makeDirectory, removeFile, saveFile } from './f
const PIM_CREDENTIALS_PATH = `${os.homedir()}/.crystallize/credentials.json`;

export async function hasCredentials(): Promise<boolean> {
if (process.env.CRYSTALLIZE_ACCESS_TOKEN_ID && process.env.CRYSTALLIZE_ACCESS_TOKEN_SECRET) {
return true;
}
const home = os.homedir();
makeDirectory(`${home}/.crystallize`);
if (!isFileExists(PIM_CREDENTIALS_PATH)) {
Expand All @@ -20,6 +23,12 @@ export async function hasCredentials(): Promise<boolean> {
}

export async function getCredentials(): Promise<PimCredentials> {
if (process.env.CRYSTALLIZE_ACCESS_TOKEN_ID && process.env.CRYSTALLIZE_ACCESS_TOKEN_SECRET) {
return {
ACCESS_TOKEN_ID: process.env.CRYSTALLIZE_ACCESS_TOKEN_ID,
ACCESS_TOKEN_SECRET: process.env.CRYSTALLIZE_ACCESS_TOKEN_SECRET,
};
}
return await loadJSON(PIM_CREDENTIALS_PATH);
}

Expand Down
125 changes: 87 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,24 @@
integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==

"@commitlint/config-conventional@^17.1.0":
version "17.6.6"
resolved "https://registry.yarnpkg.com/@commitlint/config-conventional/-/config-conventional-17.6.6.tgz#5452aa601d34503b88530ba38432116bcffdd005"
integrity sha512-phqPz3BDhfj49FUYuuZIuDiw+7T6gNAEy7Yew1IBHqSohVUCWOK2FXMSAExzS2/9X+ET93g0Uz83KjiHDOOFag==
version "17.8.1"
resolved "https://registry.yarnpkg.com/@commitlint/config-conventional/-/config-conventional-17.8.1.tgz#e5bcf0cfec8da7ac50bc04dc92e0a4ea74964ce0"
integrity sha512-NxCOHx1kgneig3VLauWJcDWS40DVjg7nKOpBEEK9E5fjJpQqLCilcnKkIIjdBH98kEO1q3NpE5NSrZ2kl/QGJg==
dependencies:
conventional-changelog-conventionalcommits "^5.0.0"
conventional-changelog-conventionalcommits "^6.1.0"

"@commitlint/format@^17.0.0":
version "17.4.4"
resolved "https://registry.yarnpkg.com/@commitlint/format/-/format-17.4.4.tgz#0f6e1b4d7a301c7b1dfd4b6334edd97fc050b9f5"
integrity sha512-+IS7vpC4Gd/x+uyQPTAt3hXs5NxnkqAZ3aqrHd5Bx/R9skyCAWusNlNbw3InDbAK6j166D9asQM8fnmYIa+CXQ==
version "17.8.1"
resolved "https://registry.yarnpkg.com/@commitlint/format/-/format-17.8.1.tgz#6108bb6b4408e711006680649927e1b559bdc5f8"
integrity sha512-f3oMTyZ84M9ht7fb93wbCKmWxO5/kKSbwuYvS867duVomoOsgrgljkGGIztmT/srZnaiGbaK8+Wf8Ik2tSr5eg==
dependencies:
"@commitlint/types" "^17.4.4"
"@commitlint/types" "^17.8.1"
chalk "^4.1.0"

"@commitlint/types@^17.0.0", "@commitlint/types@^17.4.4":
version "17.4.4"
resolved "https://registry.yarnpkg.com/@commitlint/types/-/types-17.4.4.tgz#1416df936e9aad0d6a7bbc979ecc31e55dade662"
integrity sha512-amRN8tRLYOsxRr6mTnGGGvB5EmW/4DDjLMgiwK3CCVEmN6Sr/6xePGEpWaspKkckILuUORCwe6VfDBw6uj4axQ==
"@commitlint/types@^17.0.0", "@commitlint/types@^17.8.1":
version "17.8.1"
resolved "https://registry.yarnpkg.com/@commitlint/types/-/types-17.8.1.tgz#883a0ad35c5206d5fef7bc6ce1bbe648118af44e"
integrity sha512-PXDQXkAmiMEG162Bqdh9ChML/GJZo6vU+7F03ALKDK8zYc6SuAr47LjG7hGYRqUOz+WK0dU7bQ0xzuqFMdxzeQ==
dependencies:
chalk "^4.1.0"

Expand All @@ -336,23 +336,23 @@
ow "^0.4.0"
parse5 "^6.0.1"

"@crystallize/import-export-sdk@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@crystallize/import-export-sdk/-/import-export-sdk-0.1.4.tgz#fbd9e679ba11423cd99f66d122fd00a11435589a"
integrity sha512-2UM1TwcSePzEZd9acBydmKOrXdRV66GFBCINKv/u8jHmepMIsu8Pzg0yz442waumpcTPhzCz/zQCqBOIwOTNEw==
"@crystallize/import-export-sdk@^0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@crystallize/import-export-sdk/-/import-export-sdk-0.1.5.tgz#dc4dc4e53843d59ab2c0ece6c4787c96c5428437"
integrity sha512-5/EoC1JMTIUcZQraYbxqoOHPzkMEeQcvpmHG/tim2f/wEcY1+lTxmI/VHlxYpgI9RRsZ4cxoBD9UejTkPKgpzw==
dependencies:
"@crystallize/js-api-client" "*"
"@crystallize/schema" "*"

"@crystallize/import-utilities@^1.28.5":
version "1.28.5"
resolved "https://registry.yarnpkg.com/@crystallize/import-utilities/-/import-utilities-1.28.5.tgz#cf60da97276c0bac73d11ab5eaaca58afbc827fd"
integrity sha512-u++AsfV3vSvSg1YEMHs2VPqOKFPCQhBFnvJGkfqM9mguO+SKrm18I9AVu6UobmZHyn8Mpmk29J+RJY0k9HNzYQ==
"@crystallize/import-utilities@^1.33":
version "1.33.0"
resolved "https://registry.yarnpkg.com/@crystallize/import-utilities/-/import-utilities-1.33.0.tgz#d6debe2ddfd359d44e152cc915b78f4253416d7f"
integrity sha512-a2LlgDcR4W8LOLC4HhkryHvvZgtZyn6Ln6LuNeg6wiPMn8sGDpU/HKVK3JBjqf0FBQY2nWUwJN6Hl3klNrv80w==
dependencies:
"@crystallize/content-transformer" "^9.2.0"
"@crystallize/import-export-sdk" "^0.1.4"
"@crystallize/js-api-client" "^1.12.2"
"@crystallize/schema" "^0.2.0"
"@crystallize/import-export-sdk" "^0.1.5"
"@crystallize/js-api-client" "^2.5.0"
"@crystallize/schema" "^0.3.0"
dotenv "^10.0.0"
download "^8.0.0"
duration "^0.2.2"
Expand All @@ -371,7 +371,7 @@
uuid "^8.3.2"
xml-js "^1.6.11"

"@crystallize/js-api-client@*", "@crystallize/js-api-client@^1.12.2":
"@crystallize/js-api-client@*":
version "1.12.2"
resolved "https://registry.yarnpkg.com/@crystallize/js-api-client/-/js-api-client-1.12.2.tgz#5606025a042b9fc323b53f841cf59eec00b9c205"
integrity sha512-6PfW0yn5RnawE3u59nogyVEHb157+vut81m8G6+LSfuRapQelRj8h0Ycm8LgDzxq/vA0IAG0nYtt4ngfEGDfwA==
Expand All @@ -383,13 +383,44 @@
typescript "^4.6.3"
zod "^3.14.3"

"@crystallize/schema@*", "@crystallize/schema@^0.2.0":
"@crystallize/js-api-client@^2.5.0":
version "2.6.1"
resolved "https://registry.yarnpkg.com/@crystallize/js-api-client/-/js-api-client-2.6.1.tgz#30c9300b078af974c48a6f725580c653fc40fb14"
integrity sha512-jKIW2kHux7DuxSyhTL6Pl6P/OCFV/9lN5QlloEQ5yqZsoTrrOPl0U5DjR4ojQuQFJKbM4Qn2/+N8/eg6/+Z5xQ==
dependencies:
dotenv "^16.4.1"
json-to-graphql-query "^2.2.5"
mime-lite "^1.0.3"
node-fetch "^2"
tiny-invariant "^1.3.1"
typescript "^5.3.3"
zod "^3.22.4"

"@crystallize/js-api-client@^3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@crystallize/js-api-client/-/js-api-client-3.2.0.tgz#7c8b7494d28c09aaa91d0cefcbeea66f1b64df6e"
integrity sha512-UdWoYNJ53mvzb0dM41e16xUmfb3ndbxBTm6CJdrxCYXsIoEHrnXVOa/ccL4JCuVHKyFyg0Ks6k+b16NKXOIwKA==
dependencies:
dotenv "^16.4.5"
json-to-graphql-query "^2.2.5"
mime-lite "^1.0.3"
tiny-invariant "^1.3.3"
zod "^3.23.8"

"@crystallize/schema@*":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@crystallize/schema/-/schema-0.2.0.tgz#70c289d0c3598fc3ceeb3cb6b20d937163ab0c48"
integrity sha512-ABpyH2D4tK7iB4N0jFeOMuK6KawZnr7P7fsQGa3tcZQ5clc6e+b1kJ1LHkFxrCl+gjFZYkJH5UmqXqVOoehpxA==
dependencies:
zod "^3.21.4"

"@crystallize/schema@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@crystallize/schema/-/schema-0.3.0.tgz#36b76ffd9ef4eb0c322ada7704a8c8e372062c74"
integrity sha512-At7bW6LQM9zFE6FuIs0O2yIB7h3xQNH6UL96pOzNzH3G28HVGKDR84LU2PXaMraUKD9K+nxNNa/ATdVrh1zB8A==
dependencies:
zod "^3.21.4"

"@istanbuljs/load-nyc-config@^1.0.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"
Expand Down Expand Up @@ -1299,14 +1330,12 @@ content-disposition@^0.5.2:
dependencies:
safe-buffer "5.2.1"

conventional-changelog-conventionalcommits@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-5.0.0.tgz#41bdce54eb65a848a4a3ffdca93e92fa22b64a86"
integrity sha512-lCDbA+ZqVFQGUj7h9QBKoIpLhl8iihkO0nCTyRNzuXtcd7ubODpYB04IFy31JloiJgG0Uovu8ot8oxRzn7Nwtw==
conventional-changelog-conventionalcommits@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-6.1.0.tgz#3bad05f4eea64e423d3d90fc50c17d2c8cf17652"
integrity sha512-3cS3GEtR78zTfMzk0AizXKKIdN4OvSh7ibNz6/DPbhWWQu7LqE/8+/GqSodV+sywUR2gpJAdP/1JFf4XtN7Zpw==
dependencies:
compare-func "^2.0.0"
lodash "^4.17.15"
q "^1.5.1"

convert-source-map@^1.6.0, convert-source-map@^1.7.0:
version "1.9.0"
Expand Down Expand Up @@ -1489,6 +1518,11 @@ dotenv@^16.0.0, dotenv@^16.0.3:
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==

dotenv@^16.4.1, dotenv@^16.4.5:
version "16.4.5"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

download@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/download/-/download-8.0.0.tgz#afc0b309730811731aae9f5371c9f46be73e51b1"
Expand Down Expand Up @@ -2642,7 +2676,7 @@ json-parse-even-better-errors@^2.3.0:
resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d"
integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==

json-to-graphql-query@^2.0.0, json-to-graphql-query@^2.2.4:
json-to-graphql-query@^2.0.0, json-to-graphql-query@^2.2.4, json-to-graphql-query@^2.2.5:
version "2.2.5"
resolved "https://registry.yarnpkg.com/json-to-graphql-query/-/json-to-graphql-query-2.2.5.tgz#56b072a693b50fd4dc981367b60d52e3dc78f426"
integrity sha512-5Nom9inkIMrtY992LMBBG1Zaekrc10JaRhyZgprwHBVMDtRgllTvzl0oBbg13wJsVZoSoFNNMaeIVQs0P04vsA==
Expand Down Expand Up @@ -2708,7 +2742,7 @@ lodash.merge@^4.6.2:
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.21:
lodash@^4.17.20, lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -2854,6 +2888,11 @@ mime-db@1.52.0, mime-db@^1.28.0:
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==

mime-lite@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/mime-lite/-/mime-lite-1.0.3.tgz#778e1880842545f71b223898cdff1c9ddbc995fe"
integrity sha512-V85l97zJSTG8FEvmdTlmNYb0UMrVBwvRjw7bWTf/aT6KjFwtz3iTz8D2tuFIp7lwiaO2C5ecnrEmSkkMRCrqVw==

mime-types@^2.1.12:
version "2.1.35"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
Expand Down Expand Up @@ -3250,11 +3289,6 @@ pure-rand@^6.0.0:
resolved "https://registry.yarnpkg.com/pure-rand/-/pure-rand-6.0.2.tgz#a9c2ddcae9b68d736a8163036f088a2781c8b306"
integrity sha512-6Yg0ekpKICSjPswYOuC5sku/TSWaRYlA0qsXqJgM/d/4pLPHPuTxK7Nbf7jFKzAeedUhR8C7K9Uv63FBsSo8xQ==

q@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==

query-string@^5.0.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-5.1.1.tgz#a78c012b71c17e05f2e3fa2319dd330682efb3cb"
Expand Down Expand Up @@ -3757,6 +3791,11 @@ tiny-invariant@^1.2.0:
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.1.tgz#8560808c916ef02ecfd55e66090df23a4b7aa642"
integrity sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==

tiny-invariant@^1.3.1, tiny-invariant@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.3.tgz#46680b7a873a0d5d10005995eb90a70d74d60127"
integrity sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==

tmpl@1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc"
Expand Down Expand Up @@ -3868,6 +3907,11 @@ typescript@^4.6.3, typescript@^4.9.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

typescript@^5.3.3:
version "5.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0"
integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==

unbzip2-stream@^1.0.9:
version "1.4.3"
resolved "https://registry.yarnpkg.com/unbzip2-stream/-/unbzip2-stream-1.4.3.tgz#b0da04c4371311df771cdc215e87f2130991ace7"
Expand Down Expand Up @@ -4079,3 +4123,8 @@ zod@^3.14.3, zod@^3.21.4:
version "3.21.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db"
integrity sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==

zod@^3.22.4, zod@^3.23.8:
version "3.23.8"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.23.8.tgz#e37b957b5d52079769fb8097099b592f0ef4067d"
integrity sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==

0 comments on commit 5bd7ef2

Please sign in to comment.