From 2953593c734c63f1b569cfca2a00b7fe5d8d128e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BD=81=EF=BD=99=EF=BD=95=EF=BD=8D=EF=BD=89=C2=A0=20?= =?UTF-8?q?=EF=BD=99=EF=BD=95?= Date: Mon, 23 Jan 2017 21:17:54 -0800 Subject: [PATCH] Remove bookmark folderId; add parentFolderObjectId Auditors: @diracdeltas Fix #47 --- client/sync.js | 3 ++ lib/api.proto | 4 +- lib/api.proto.js | 75 ++++++++++++++++++++++------------ test/client/recordUtil.js | 4 +- yarn.lock | 86 +++++++++++++++++++++++---------------- 5 files changed, 107 insertions(+), 65 deletions(-) diff --git a/client/sync.js b/client/sync.js index df16b47..f4ff087 100644 --- a/client/sync.js +++ b/client/sync.js @@ -114,6 +114,9 @@ const startSync = (requester) => { // Workaround #17 record.deviceId = new Uint8Array(record.deviceId) record.objectId = new Uint8Array(record.objectId) + if (record.bookmark && record.bookmark.parentFolderObjectId) { + record.bookmark.parentFolderObjectId = new Uint8Array(record.bookmark.parentFolderObjectId) + } logSync(`sending record: ${JSON.stringify(record)}`) requester.put(proto.categories[category], requester.encrypt(record)) }) diff --git a/lib/api.proto b/lib/api.proto index 35322a4..59569ac 100644 --- a/lib/api.proto +++ b/lib/api.proto @@ -42,8 +42,8 @@ message SyncRecord { message Bookmark { Site site = 1; bool isFolder = 2; - uint32 folderId = 3; - uint32 parentFolderId = 4; + bytes parentFolderObjectId = 3; + int32 index = 4; } message SiteSetting { string hostPattern = 1; diff --git a/lib/api.proto.js b/lib/api.proto.js index 9a7563f..9e9feff 100644 --- a/lib/api.proto.js +++ b/lib/api.proto.js @@ -190,6 +190,8 @@ * @returns {api.Credentials} Credentials */ Credentials.fromObject = function fromObject(object) { + if (object instanceof $root.api.Credentials) + return object; var message = new $root.api.Credentials(); if (object.aws !== undefined && object.aws !== null) message.aws = $types[0].fromObject(object.aws); @@ -404,6 +406,8 @@ * @returns {api.Credentials.Aws} Aws */ Aws.fromObject = function fromObject(object) { + if (object instanceof $root.api.Credentials.Aws) + return object; var message = new $root.api.Credentials.Aws(); if (object.accessKeyId !== undefined && object.accessKeyId !== null) message.accessKeyId = String(object.accessKeyId); @@ -621,6 +625,8 @@ * @returns {api.Credentials.S3Post} S3Post */ S3Post.fromObject = function fromObject(object) { + if (object instanceof $root.api.Credentials.S3Post) + return object; var message = new $root.api.Credentials.S3Post(); if (object.AWSAccessKeyId !== undefined && object.AWSAccessKeyId !== null) message.AWSAccessKeyId = String(object.AWSAccessKeyId); @@ -827,6 +833,8 @@ * @returns {api.SecretboxRecord} SecretboxRecord */ SecretboxRecord.fromObject = function fromObject(object) { + if (object instanceof $root.api.SecretboxRecord) + return object; var message = new $root.api.SecretboxRecord(); if (object.encryptedData !== undefined && object.encryptedData !== null) if (typeof object.encryptedData === "string") @@ -1129,6 +1137,8 @@ * @returns {api.SyncRecord} SyncRecord */ SyncRecord.fromObject = function fromObject(object) { + if (object instanceof $root.api.SyncRecord) + return object; var message = new $root.api.SyncRecord(); switch (object.action) { case "CREATE": @@ -1408,6 +1418,8 @@ * @returns {api.SyncRecord.Site} Site */ Site.fromObject = function fromObject(object) { + if (object instanceof $root.api.SyncRecord.Site) + return object; var message = new $root.api.SyncRecord.Site(); if (object.location !== undefined && object.location !== null) message.location = String(object.location); @@ -1537,16 +1549,16 @@ Bookmark.prototype.isFolder = false; /** - * Bookmark folderId. - * @type {number} + * Bookmark parentFolderObjectId. + * @type {Uint8Array} */ - Bookmark.prototype.folderId = 0; + Bookmark.prototype.parentFolderObjectId = $util.newBuffer([]); /** - * Bookmark parentFolderId. + * Bookmark index. * @type {number} */ - Bookmark.prototype.parentFolderId = 0; + Bookmark.prototype.index = 0; // Lazily resolved type references var $types = { @@ -1575,10 +1587,10 @@ $types[0].encode(message.site, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); if (message.isFolder !== undefined && message.hasOwnProperty("isFolder")) writer.uint32(/* id 2, wireType 0 =*/16).bool(message.isFolder); - if (message.folderId !== undefined && message.hasOwnProperty("folderId")) - writer.uint32(/* id 3, wireType 0 =*/24).uint32(message.folderId); - if (message.parentFolderId !== undefined && message.hasOwnProperty("parentFolderId")) - writer.uint32(/* id 4, wireType 0 =*/32).uint32(message.parentFolderId); + if (message.parentFolderObjectId && message.hasOwnProperty("parentFolderObjectId")) + writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.parentFolderObjectId); + if (message.index !== undefined && message.hasOwnProperty("index")) + writer.uint32(/* id 4, wireType 0 =*/32).int32(message.index); return writer; }; @@ -1612,10 +1624,10 @@ message.isFolder = reader.bool(); break; case 3: - message.folderId = reader.uint32(); + message.parentFolderObjectId = reader.bytes(); break; case 4: - message.parentFolderId = reader.uint32(); + message.index = reader.int32(); break; default: reader.skipType(tag & 7); @@ -1650,12 +1662,12 @@ if (message.isFolder !== undefined) if (typeof message.isFolder !== "boolean") return "isFolder: boolean expected"; - if (message.folderId !== undefined) - if (!$util.isInteger(message.folderId)) - return "folderId: integer expected"; - if (message.parentFolderId !== undefined) - if (!$util.isInteger(message.parentFolderId)) - return "parentFolderId: integer expected"; + if (message.parentFolderObjectId !== undefined) + if (!(message.parentFolderObjectId && typeof message.parentFolderObjectId.length === "number" || $util.isString(message.parentFolderObjectId))) + return "parentFolderObjectId: buffer expected"; + if (message.index !== undefined) + if (!$util.isInteger(message.index)) + return "index: integer expected"; return null; }; @@ -1665,15 +1677,20 @@ * @returns {api.SyncRecord.Bookmark} Bookmark */ Bookmark.fromObject = function fromObject(object) { + if (object instanceof $root.api.SyncRecord.Bookmark) + return object; var message = new $root.api.SyncRecord.Bookmark(); if (object.site !== undefined && object.site !== null) message.site = $types[0].fromObject(object.site); if (object.isFolder !== undefined && object.isFolder !== null) message.isFolder = Boolean(object.isFolder); - if (object.folderId !== undefined && object.folderId !== null) - message.folderId = object.folderId >>> 0; - if (object.parentFolderId !== undefined && object.parentFolderId !== null) - message.parentFolderId = object.parentFolderId >>> 0; + if (object.parentFolderObjectId !== undefined && object.parentFolderObjectId !== null) + if (typeof object.parentFolderObjectId === "string") + $util.base64.decode(object.parentFolderObjectId, message.parentFolderObjectId = $util.newBuffer($util.base64.length(object.parentFolderObjectId)), 0); + else if (object.parentFolderObjectId && object.parentFolderObjectId.length) + message.parentFolderObjectId = object.parentFolderObjectId; + if (object.index !== undefined && object.index !== null) + message.index = object.index | 0; return message; }; @@ -1698,17 +1715,17 @@ if (options.defaults) { object.site = null; object.isFolder = false; - object.folderId = 0; - object.parentFolderId = 0; + object.parentFolderObjectId = options.bytes === String ? "" : []; + object.index = 0; } if (message.site !== undefined && message.site !== null && message.hasOwnProperty("site")) object.site = $types[0].toObject(message.site, options); if (message.isFolder !== undefined && message.isFolder !== null && message.hasOwnProperty("isFolder")) object.isFolder = message.isFolder; - if (message.folderId !== undefined && message.folderId !== null && message.hasOwnProperty("folderId")) - object.folderId = message.folderId; - if (message.parentFolderId !== undefined && message.parentFolderId !== null && message.hasOwnProperty("parentFolderId")) - object.parentFolderId = message.parentFolderId; + if (message.parentFolderObjectId !== undefined && message.parentFolderObjectId !== null && message.hasOwnProperty("parentFolderObjectId")) + object.parentFolderObjectId = options.bytes === String ? $util.base64.encode(message.parentFolderObjectId, 0, message.parentFolderObjectId.length) : options.bytes === Array ? Array.prototype.slice.call(message.parentFolderObjectId) : message.parentFolderObjectId; + if (message.index !== undefined && message.index !== null && message.hasOwnProperty("index")) + object.index = message.index; return object; }; @@ -2018,6 +2035,8 @@ * @returns {api.SyncRecord.SiteSetting} SiteSetting */ SiteSetting.fromObject = function fromObject(object) { + if (object instanceof $root.api.SyncRecord.SiteSetting) + return object; var message = new $root.api.SyncRecord.SiteSetting(); if (object.hostPattern !== undefined && object.hostPattern !== null) message.hostPattern = String(object.hostPattern); @@ -2294,6 +2313,8 @@ * @returns {api.SyncRecord.Device} Device */ Device.fromObject = function fromObject(object) { + if (object instanceof $root.api.SyncRecord.Device) + return object; var message = new $root.api.SyncRecord.Device(); if (object.name !== undefined && object.name !== null) message.name = String(object.name); diff --git a/test/client/recordUtil.js b/test/client/recordUtil.js index 24a3187..6c7e468 100644 --- a/test/client/recordUtil.js +++ b/test/client/recordUtil.js @@ -402,9 +402,9 @@ test('recordUtil.syncRecordAsJS()', (t) => { const bookmark = serializer.api.SyncRecord.Bookmark.create({ site, + index: 1, isFolder: false, - folderId: 0, - parentFolderId: 0 + parentFolderObjectId: testHelper.newUuid() }) conversionEquals({ objectData: 'bookmark', bookmark }) diff --git a/yarn.lock b/yarn.lock index 6b439bd..f19fec8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -97,12 +97,12 @@ agent-base@2: semver "~5.0.1" ajv-keywords@^1.0.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.0.tgz#c11e6859eafff83e0dafc416929472eca946aa2c" + version "1.5.1" + resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c" ajv@^4.7.0: - version "4.10.4" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.10.4.tgz#c0974dd00b3464984892d6010aa9c2c945933254" + version "4.11.2" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.2.tgz#f166c3c11cbc6cb9dcc102a5bcfe5b72c95287e6" dependencies: co "^4.6.0" json-stable-stringify "^1.0.1" @@ -268,8 +268,8 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" aws-sdk@^2.7.7: - version "2.7.23" - resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.7.23.tgz#8bd1e54c3195fad4c4fb380bdbea5a019dd09b3a" + version "2.7.27" + resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.7.27.tgz#6fc4793c166172a0f95af7dce177244cb471c50a" dependencies: buffer "4.9.1" crypto-browserify "1.0.9" @@ -290,12 +290,12 @@ aws4@^1.2.1: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.5.0.tgz#0a29ffb79c31c9e712eeb087e8e7a64b4a56d755" babel-code-frame@^6.16.0: - version "6.20.0" - resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.20.0.tgz#b968f839090f9a8bc6d41938fb96cb84f7387b26" + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4" dependencies: chalk "^1.1.0" esutils "^2.0.2" - js-tokens "^2.0.0" + js-tokens "^3.0.0" balanced-match@^0.4.1: version "0.4.2" @@ -1064,8 +1064,8 @@ electron-stream@^4.0.0: stream-read "^1.1.2" electron@^1.4.4: - version "1.4.14" - resolved "https://registry.yarnpkg.com/electron/-/electron-1.4.14.tgz#e374b76ccdc432bccad9bb3ce1add453bf5648b4" + version "1.4.15" + resolved "https://registry.yarnpkg.com/electron/-/electron-1.4.15.tgz#eaccafe3f55ade02a746b706ac14b43db6c7ccf8" dependencies: electron-download "^3.0.1" extract-zip "^1.0.3" @@ -1102,8 +1102,8 @@ error-ex@^1.2.0: is-arrayish "^0.2.1" es-abstract@^1.5.0: - version "1.6.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.6.1.tgz#bb8a2064120abcf928a086ea3d9043114285ec99" + version "1.7.0" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.7.0.tgz#dfade774e01bfcd97f96180298c449c8623fb94c" dependencies: es-to-primitive "^1.1.1" function-bind "^1.1.0" @@ -1796,7 +1796,7 @@ htmlescape@^1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/htmlescape/-/htmlescape-1.1.1.tgz#3a03edc2214bca3b66424a3e7959349509cb0351" -http-errors@~1.5.0: +http-errors@~1.5.0, http-errors@~1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.5.1.tgz#788c0d2c1de2c81b9e6e8c01843b6b97eb920750" dependencies: @@ -2027,7 +2027,7 @@ is-path-inside@^1.0.0: is-posix-bracket@^0.1.0: version "0.1.1" - resolved "http://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" + resolved "https://registry.yarnpkg.com/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" is-primitive@^2.0.0: version "2.0.0" @@ -2131,9 +2131,9 @@ joi@^6.9.1: moment "2.x.x" topo "1.x.x" -js-tokens@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-2.0.0.tgz#79903f5563ee778cc1162e6dcf1a0027c97f9cb5" +js-tokens@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.0.tgz#a2f2a969caae142fb3cd56228358c89366957bd1" js-yaml@3.x, js-yaml@^3.5.1: version "3.7.0" @@ -2522,8 +2522,8 @@ mute-stream@0.0.5: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0" nan@^2.0.7, nan@^2.3.0: - version "2.5.0" - resolved "https://registry.yarnpkg.com/nan/-/nan-2.5.0.tgz#aa8f1e34531d807e9e27755b234b4a6ec0c152a8" + version "2.5.1" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.5.1.tgz#d5b01691253326a97a2bbee9e61c55d8d60351e2" natural-compare@^1.4.0: version "1.4.0" @@ -2904,8 +2904,8 @@ progress@^1.1.8: resolved "https://registry.yarnpkg.com/progress/-/progress-1.1.8.tgz#e260c78f6161cdd9b0e56cc3e0a85de17c7a57be" protobufjs@~6.5.0: - version "6.5.0" - resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.5.0.tgz#c5733589f328092dcc45daa425a0447d5d2aaf44" + version "6.5.3" + resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.5.3.tgz#08d189da90397070de9fcd634919ddbae36025de" dependencies: "@protobufjs/aspromise" "^1.0.5" "@protobufjs/base64" "^1.0.5" @@ -3292,14 +3292,32 @@ send@0.14.1: range-parser "~1.2.0" statuses "~1.3.0" +send@0.14.2: + version "0.14.2" + resolved "https://registry.yarnpkg.com/send/-/send-0.14.2.tgz#39b0438b3f510be5dc6f667a11f71689368cdeef" + dependencies: + debug "~2.2.0" + depd "~1.1.0" + destroy "~1.0.4" + encodeurl "~1.0.1" + escape-html "~1.0.3" + etag "~1.7.0" + fresh "0.3.0" + http-errors "~1.5.1" + mime "1.3.4" + ms "0.7.2" + on-finished "~2.3.0" + range-parser "~1.2.0" + statuses "~1.3.1" + serve-static@~1.11.1: - version "1.11.1" - resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.11.1.tgz#d6cce7693505f733c759de57befc1af76c0f0805" + version "1.11.2" + resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.11.2.tgz#2cf9889bd4435a320cc36895c9aa57bd662e6ac7" dependencies: encodeurl "~1.0.1" escape-html "~1.0.3" parseurl "~1.3.1" - send "0.14.1" + send "0.14.2" server-destroy@^1.0.1: version "1.0.1" @@ -3469,7 +3487,7 @@ standard@^8.5.0: eslint-plugin-standard "~2.0.1" standard-engine "~5.2.0" -"statuses@>= 1.3.1 < 2", statuses@~1.3.0: +"statuses@>= 1.3.1 < 2", statuses@~1.3.0, statuses@~1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e" @@ -3494,8 +3512,8 @@ stream-combiner@~0.0.4: duplexer "~0.1.1" stream-http@^2.0.0: - version "2.6.2" - resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-2.6.2.tgz#bdfe40d2ee9262eb6bf2255bb3ad0ec0cdd6526d" + version "2.6.3" + resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-2.6.3.tgz#4c3ddbf9635968ea2cfd4e48d43de5def2625ac3" dependencies: builtin-status-codes "^3.0.0" inherits "^2.0.1" @@ -3607,8 +3625,8 @@ subarg@^1.0.0: minimist "^1.1.0" subcommand@^2.0.3: - version "2.0.4" - resolved "https://registry.yarnpkg.com/subcommand/-/subcommand-2.0.4.tgz#71cd54bd83a78a0b266296cda3f9428e91d66b14" + version "2.1.0" + resolved "https://registry.yarnpkg.com/subcommand/-/subcommand-2.1.0.tgz#5e4ceca5a3779e3365b1511e05f866877302f760" dependencies: cliclopts "^1.1.0" debug "^2.1.3" @@ -3862,7 +3880,7 @@ uglify-js@^2.6: uglify-js@mishoo/UglifyJS2#harmony: version "2.7.5" - resolved "https://codeload.github.com/mishoo/UglifyJS2/tar.gz/962b1f3d409934e1c1603c730d574ce56eaa2a58" + resolved "https://codeload.github.com/mishoo/UglifyJS2/tar.gz/52ce9a333c78ba372a995f56c3b0352a7b08f6e8" dependencies: async "~0.2.6" source-map "~0.5.1" @@ -3879,7 +3897,7 @@ uid-number@~0.0.6: umd@^3.0.0: version "3.0.1" - resolved "https://registry.yarnpkg.com/umd/-/umd-3.0.1.tgz#8ae556e11011f63c2596708a8837259f01b3d60e" + resolved "http://registry.npmjs.org/umd/-/umd-3.0.1.tgz#8ae556e11011f63c2596708a8837259f01b3d60e" undefsafe@0.0.3: version "0.0.3" @@ -3999,8 +4017,8 @@ window-size@0.1.0: resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d" winston@^2.3.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/winston/-/winston-2.3.0.tgz#207faaab6fccf3fe493743dd2b03dbafc7ceb78c" + version "2.3.1" + resolved "https://registry.yarnpkg.com/winston/-/winston-2.3.1.tgz#0b48420d978c01804cf0230b648861598225a119" dependencies: async "~1.0.0" colors "1.0.x"