ClientSDK.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var semver = require('semver');
  3. function compatible(compatibleSDK) {
  4. return function (clientSDK) {
  5. if (typeof clientSDK === 'string') {
  6. clientSDK = fromString(clientSDK);
  7. }
  8. // REST API, or custom SDK
  9. if (!clientSDK) {
  10. return true;
  11. }
  12. const clientVersion = clientSDK.version;
  13. const compatiblityVersion = compatibleSDK[clientSDK.sdk];
  14. return semver.satisfies(clientVersion, compatiblityVersion);
  15. };
  16. }
  17. function supportsForwardDelete(clientSDK) {
  18. return compatible({
  19. js: '>=1.9.0'
  20. })(clientSDK);
  21. }
  22. function fromString(version) {
  23. const versionRE = /([-a-zA-Z]+)([0-9\.]+)/;
  24. const match = version.toLowerCase().match(versionRE);
  25. if (match && match.length === 3) {
  26. return {
  27. sdk: match[1],
  28. version: match[2]
  29. };
  30. }
  31. return undefined;
  32. }
  33. module.exports = {
  34. compatible,
  35. supportsForwardDelete,
  36. fromString
  37. };
  38. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJzZW12ZXIiLCJyZXF1aXJlIiwiY29tcGF0aWJsZSIsImNvbXBhdGlibGVTREsiLCJjbGllbnRTREsiLCJmcm9tU3RyaW5nIiwiY2xpZW50VmVyc2lvbiIsInZlcnNpb24iLCJjb21wYXRpYmxpdHlWZXJzaW9uIiwic2RrIiwic2F0aXNmaWVzIiwic3VwcG9ydHNGb3J3YXJkRGVsZXRlIiwianMiLCJ2ZXJzaW9uUkUiLCJtYXRjaCIsInRvTG93ZXJDYXNlIiwibGVuZ3RoIiwidW5kZWZpbmVkIiwibW9kdWxlIiwiZXhwb3J0cyJdLCJzb3VyY2VzIjpbIi4uL3NyYy9DbGllbnRTREsuanMiXSwic291cmNlc0NvbnRlbnQiOlsidmFyIHNlbXZlciA9IHJlcXVpcmUoJ3NlbXZlcicpO1xuXG5mdW5jdGlvbiBjb21wYXRpYmxlKGNvbXBh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