@metamask/snaps-utils 0.24.0

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 (78) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +3 -0
  3. package/dist/caveats.d.ts +22 -0
  4. package/dist/caveats.js +27 -0
  5. package/dist/caveats.js.map +1 -0
  6. package/dist/cronjob.d.ts +89 -0
  7. package/dist/cronjob.js +74 -0
  8. package/dist/cronjob.js.map +1 -0
  9. package/dist/deep-clone.d.ts +1 -0
  10. package/dist/deep-clone.js +9 -0
  11. package/dist/deep-clone.js.map +1 -0
  12. package/dist/default-endowments.d.ts +4 -0
  13. package/dist/default-endowments.js +43 -0
  14. package/dist/default-endowments.js.map +1 -0
  15. package/dist/eval-worker.d.ts +1 -0
  16. package/dist/eval-worker.js +32 -0
  17. package/dist/eval-worker.js.map +1 -0
  18. package/dist/eval.d.ts +8 -0
  19. package/dist/eval.js +28 -0
  20. package/dist/eval.js.map +1 -0
  21. package/dist/flatMap.d.ts +22 -0
  22. package/dist/flatMap.js +38 -0
  23. package/dist/flatMap.js.map +1 -0
  24. package/dist/fs.d.ts +69 -0
  25. package/dist/fs.js +144 -0
  26. package/dist/fs.js.map +1 -0
  27. package/dist/index.browser.d.ts +13 -0
  28. package/dist/index.browser.js +30 -0
  29. package/dist/index.browser.js.map +1 -0
  30. package/dist/index.d.ts +19 -0
  31. package/dist/index.js +36 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/json-rpc.d.ts +10 -0
  34. package/dist/json-rpc.js +22 -0
  35. package/dist/json-rpc.js.map +1 -0
  36. package/dist/manifest/index.browser.d.ts +1 -0
  37. package/dist/manifest/index.browser.js +18 -0
  38. package/dist/manifest/index.browser.js.map +1 -0
  39. package/dist/manifest/index.d.ts +2 -0
  40. package/dist/manifest/index.js +19 -0
  41. package/dist/manifest/index.js.map +1 -0
  42. package/dist/manifest/manifest.d.ts +75 -0
  43. package/dist/manifest/manifest.js +237 -0
  44. package/dist/manifest/manifest.js.map +1 -0
  45. package/dist/manifest/validation.d.ts +483 -0
  46. package/dist/manifest/validation.js +142 -0
  47. package/dist/manifest/validation.js.map +1 -0
  48. package/dist/mock.d.ts +14 -0
  49. package/dist/mock.js +107 -0
  50. package/dist/mock.js.map +1 -0
  51. package/dist/namespace.d.ts +275 -0
  52. package/dist/namespace.js +223 -0
  53. package/dist/namespace.js.map +1 -0
  54. package/dist/notification.d.ts +66 -0
  55. package/dist/notification.js +58 -0
  56. package/dist/notification.js.map +1 -0
  57. package/dist/npm.d.ts +20 -0
  58. package/dist/npm.js +73 -0
  59. package/dist/npm.js.map +1 -0
  60. package/dist/object.d.ts +8 -0
  61. package/dist/object.js +15 -0
  62. package/dist/object.js.map +1 -0
  63. package/dist/post-process.d.ts +71 -0
  64. package/dist/post-process.js +321 -0
  65. package/dist/post-process.js.map +1 -0
  66. package/dist/snaps.d.ts +165 -0
  67. package/dist/snaps.js +123 -0
  68. package/dist/snaps.js.map +1 -0
  69. package/dist/types.d.ts +107 -0
  70. package/dist/types.js +82 -0
  71. package/dist/types.js.map +1 -0
  72. package/dist/url.d.ts +7 -0
  73. package/dist/url.js +19 -0
  74. package/dist/url.js.map +1 -0
  75. package/dist/versions.d.ts +44 -0
  76. package/dist/versions.js +77 -0
  77. package/dist/versions.js.map +1 -0
  78. package/package.json +100 -0
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidSnapVersionRange = exports.resolveVersion = exports.getTargetVersion = exports.satisfiesVersionRange = exports.gtVersion = exports.DEFAULT_REQUESTED_SNAP_VERSION = void 0;
4
+ const semver_1 = require("semver");
5
+ exports.DEFAULT_REQUESTED_SNAP_VERSION = '*';
6
+ /**
7
+ * Checks whether a SemVer version is greater than another.
8
+ *
9
+ * @param version1 - The left-hand version.
10
+ * @param version2 - The right-hand version.
11
+ * @returns `version1 > version2`.
12
+ */
13
+ function gtVersion(version1, version2) {
14
+ return (0, semver_1.gt)(version1, version2, { includePrerelease: true });
15
+ }
16
+ exports.gtVersion = gtVersion;
17
+ /**
18
+ * Returns whether a SemVer version satisfies a SemVer range.
19
+ *
20
+ * @param version - The SemVer version to check.
21
+ * @param versionRange - The SemVer version range to check against.
22
+ * @returns Whether the version satisfied the version range.
23
+ */
24
+ function satisfiesVersionRange(version, versionRange) {
25
+ return (0, semver_1.satisfies)(version, versionRange, {
26
+ includePrerelease: true,
27
+ });
28
+ }
29
+ exports.satisfiesVersionRange = satisfiesVersionRange;
30
+ /**
31
+ * Return the highest version in the list that satisfies the range, or `null` if
32
+ * none of them do. For the satisfaction check, pre-release versions will only
33
+ * be checked if no satisfactory non-prerelease version is found first.
34
+ *
35
+ * @param versions - The list of version to check.
36
+ * @param versionRange - The SemVer version range to check against.
37
+ * @returns The highest version in the list that satisfies the range,
38
+ * or `null` if none of them do.
39
+ */
40
+ function getTargetVersion(versions, versionRange) {
41
+ const maxSatisfyingNonPreRelease = (0, semver_1.maxSatisfying)(versions, versionRange);
42
+ // By default don't use pre-release versions
43
+ if (maxSatisfyingNonPreRelease) {
44
+ return maxSatisfyingNonPreRelease;
45
+ }
46
+ // If no satisfying release version is found by default, try pre-release versions
47
+ return (0, semver_1.maxSatisfying)(versions, versionRange, {
48
+ includePrerelease: true,
49
+ });
50
+ }
51
+ exports.getTargetVersion = getTargetVersion;
52
+ /**
53
+ * Parse a version received by some subject attempting to access a snap.
54
+ *
55
+ * @param version - The received version value.
56
+ * @returns `*` if the version is `undefined` or `latest", otherwise returns
57
+ * the specified version.
58
+ */
59
+ function resolveVersion(version) {
60
+ if (version === undefined || version === 'latest') {
61
+ return exports.DEFAULT_REQUESTED_SNAP_VERSION;
62
+ }
63
+ return version;
64
+ }
65
+ exports.resolveVersion = resolveVersion;
66
+ /**
67
+ * Checks whether a SemVer version range is valid.
68
+ *
69
+ * @param versionRange - A potential version range.
70
+ * @returns `true` if the version range is valid, and `false` otherwise.
71
+ */
72
+ function isValidSnapVersionRange(versionRange) {
73
+ return Boolean(typeof versionRange === 'string' &&
74
+ (0, semver_1.validRange)(versionRange, { includePrerelease: true }) !== null);
75
+ }
76
+ exports.isValidSnapVersionRange = isValidSnapVersionRange;
77
+ //# sourceMappingURL=versions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versions.js","sourceRoot":"","sources":["../src/versions.ts"],"names":[],"mappings":";;;AACA,mCAKgB;AAEH,QAAA,8BAA8B,GAAG,GAAG,CAAC;AAElD;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,QAAgB,EAAE,QAAgB;IAC1D,OAAO,IAAA,WAAQ,EAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;AACnE,CAAC;AAFD,8BAEC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,OAAe,EACf,YAAoB;IAEpB,OAAO,IAAA,kBAAe,EAAC,OAAO,EAAE,YAAY,EAAE;QAC5C,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;AACL,CAAC;AAPD,sDAOC;AAED;;;;;;;;;GASG;AACH,SAAgB,gBAAgB,CAC9B,QAAkB,EAClB,YAAoB;IAEpB,MAAM,0BAA0B,GAAG,IAAA,sBAAmB,EACpD,QAAQ,EACR,YAAY,CACb,CAAC;IAEF,4CAA4C;IAC5C,IAAI,0BAA0B,EAAE;QAC9B,OAAO,0BAA0B,CAAC;KACnC;IAED,iFAAiF;IACjF,OAAO,IAAA,sBAAmB,EAAC,QAAQ,EAAE,YAAY,EAAE;QACjD,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC;AACL,CAAC;AAlBD,4CAkBC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,OAAc;IAC3C,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,QAAQ,EAAE;QACjD,OAAO,sCAA8B,CAAC;KACvC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AALD,wCAKC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,YAAqB;IAErB,OAAO,OAAO,CACZ,OAAO,YAAY,KAAK,QAAQ;QAC9B,IAAA,mBAAgB,EAAC,YAAY,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CACvE,CAAC;AACJ,CAAC;AAPD,0DAOC","sourcesContent":["import { Json } from '@metamask/utils';\nimport {\n gt as gtSemver,\n maxSatisfying as maxSatisfyingSemver,\n satisfies as satisfiesSemver,\n validRange as validRangeSemver,\n} from 'semver';\n\nexport const DEFAULT_REQUESTED_SNAP_VERSION = '*';\n\n/**\n * Checks whether a SemVer version is greater than another.\n *\n * @param version1 - The left-hand version.\n * @param version2 - The right-hand version.\n * @returns `version1 > version2`.\n */\nexport function gtVersion(version1: string, version2: string): boolean {\n return gtSemver(version1, version2, { includePrerelease: true });\n}\n\n/**\n * Returns whether a SemVer version satisfies a SemVer range.\n *\n * @param version - The SemVer version to check.\n * @param versionRange - The SemVer version range to check against.\n * @returns Whether the version satisfied the version range.\n */\nexport function satisfiesVersionRange(\n version: string,\n versionRange: string,\n): boolean {\n return satisfiesSemver(version, versionRange, {\n includePrerelease: true,\n });\n}\n\n/**\n * Return the highest version in the list that satisfies the range, or `null` if\n * none of them do. For the satisfaction check, pre-release versions will only\n * be checked if no satisfactory non-prerelease version is found first.\n *\n * @param versions - The list of version to check.\n * @param versionRange - The SemVer version range to check against.\n * @returns The highest version in the list that satisfies the range,\n * or `null` if none of them do.\n */\nexport function getTargetVersion(\n versions: string[],\n versionRange: string,\n): string | null {\n const maxSatisfyingNonPreRelease = maxSatisfyingSemver(\n versions,\n versionRange,\n );\n\n // By default don't use pre-release versions\n if (maxSatisfyingNonPreRelease) {\n return maxSatisfyingNonPreRelease;\n }\n\n // If no satisfying release version is found by default, try pre-release versions\n return maxSatisfyingSemver(versions, versionRange, {\n includePrerelease: true,\n });\n}\n\n/**\n * Parse a version received by some subject attempting to access a snap.\n *\n * @param version - The received version value.\n * @returns `*` if the version is `undefined` or `latest\", otherwise returns\n * the specified version.\n */\nexport function resolveVersion(version?: Json): Json {\n if (version === undefined || version === 'latest') {\n return DEFAULT_REQUESTED_SNAP_VERSION;\n }\n return version;\n}\n\n/**\n * Checks whether a SemVer version range is valid.\n *\n * @param versionRange - A potential version range.\n * @returns `true` if the version range is valid, and `false` otherwise.\n */\nexport function isValidSnapVersionRange(\n versionRange: unknown,\n): versionRange is string {\n return Boolean(\n typeof versionRange === 'string' &&\n validRangeSemver(versionRange, { includePrerelease: true }) !== null,\n );\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,100 @@
1
+ {
2
+ "name": "@metamask/snaps-utils",
3
+ "version": "0.24.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/MetaMask/snaps-monorepo.git"
7
+ },
8
+ "exports": {
9
+ ".": {
10
+ "browser": {
11
+ "default": "./dist/index.browser.js"
12
+ },
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.js"
15
+ },
16
+ "./test-utils": {
17
+ "import": "./dist/test-utils/index.js",
18
+ "require": "./dist/test-utils/index.js"
19
+ }
20
+ },
21
+ "main": "dist/index.js",
22
+ "browser": {
23
+ "./dist/index": "./dist/index.browser.js"
24
+ },
25
+ "typesVersions": {
26
+ "*": {
27
+ "*": [
28
+ "dist/index.d.ts"
29
+ ],
30
+ "test-utils": [
31
+ "dist/test-utils/index.d.ts"
32
+ ]
33
+ }
34
+ },
35
+ "files": [
36
+ "dist/"
37
+ ],
38
+ "scripts": {
39
+ "test": "jest && yarn posttest",
40
+ "posttest": "jest-it-up --margin 0.25",
41
+ "test:ci": "yarn test",
42
+ "lint:eslint": "eslint . --cache --ext js,ts",
43
+ "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
44
+ "lint": "yarn lint:eslint && yarn lint:misc --check",
45
+ "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
46
+ "lint:changelog": "yarn auto-changelog validate",
47
+ "build": "tsc --project tsconfig.build.json",
48
+ "build:clean": "yarn clean && yarn build",
49
+ "clean": "rimraf '*.tsbuildinfo' 'dist/*'",
50
+ "publish:package": "../../scripts/publish-package.sh"
51
+ },
52
+ "dependencies": {
53
+ "@babel/core": "^7.18.6",
54
+ "@babel/types": "^7.18.7",
55
+ "@metamask/snaps-types": "^0.24.0",
56
+ "@metamask/utils": "^3.3.1",
57
+ "@noble/hashes": "^1.1.3",
58
+ "@scure/base": "^1.1.1",
59
+ "cron-parser": "^4.5.0",
60
+ "eth-rpc-errors": "^4.0.3",
61
+ "fast-deep-equal": "^3.1.3",
62
+ "rfdc": "^1.3.0",
63
+ "semver": "^7.3.7",
64
+ "ses": "^0.17.0",
65
+ "superstruct": "^0.16.7"
66
+ },
67
+ "devDependencies": {
68
+ "@lavamoat/allow-scripts": "^2.0.3",
69
+ "@metamask/auto-changelog": "^2.6.0",
70
+ "@metamask/eslint-config": "^9.0.0",
71
+ "@metamask/eslint-config-jest": "^9.0.0",
72
+ "@metamask/eslint-config-nodejs": "^9.0.0",
73
+ "@metamask/eslint-config-typescript": "^9.0.1",
74
+ "@types/jest": "^27.5.1",
75
+ "@types/semver": "^7.3.10",
76
+ "deepmerge": "^4.2.2",
77
+ "eslint": "^7.30.0",
78
+ "eslint-config-prettier": "^8.3.0",
79
+ "eslint-plugin-import": "^2.23.4",
80
+ "eslint-plugin-jest": "^24.4.0",
81
+ "eslint-plugin-jsdoc": "^36.1.0",
82
+ "eslint-plugin-node": "^11.1.0",
83
+ "eslint-plugin-prettier": "^3.4.0",
84
+ "jest": "^29.0.2",
85
+ "jest-it-up": "^2.0.0",
86
+ "memfs": "^3.4.7",
87
+ "prettier": "^2.3.2",
88
+ "prettier-plugin-packagejson": "^2.2.11",
89
+ "rimraf": "^3.0.2",
90
+ "ts-jest": "^29.0.0",
91
+ "typescript": "^4.4.0"
92
+ },
93
+ "engines": {
94
+ "node": ">=16.0.0"
95
+ },
96
+ "publishConfig": {
97
+ "access": "public",
98
+ "registry": "https://registry.npmjs.org/"
99
+ }
100
+ }