cloudcms-server 3.3.1-beta.9 → 4.0.0-beta.2

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 (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/broadcast/broadcast.js +6 -3
  4. package/broadcast/providers/redis.js +24 -49
  5. package/clients/nrp.js +117 -0
  6. package/clients/redis.js +64 -0
  7. package/d1/index.js +629 -0
  8. package/d1/index.js.works +203 -0
  9. package/d1/package.json +86 -0
  10. package/d1/package.json.works +14 -0
  11. package/duster/helpers/sample/nyt.js +2 -1
  12. package/framework/controllers.js +4 -4
  13. package/index.js +21 -14
  14. package/insight/insight.js +1 -1
  15. package/launchpad/index.js +203 -11
  16. package/launchpad/launchers/cluster.js +103 -110
  17. package/launchpad/launchers/redis.js +70 -0
  18. package/launchpad/launchers/single.js +36 -22
  19. package/locks/locks.js +63 -9
  20. package/locks/providers/cluster.js +3 -1
  21. package/locks/providers/memory.js +10 -7
  22. package/locks/providers/redis.js +62 -82
  23. package/middleware/admin/admin.js +3 -3
  24. package/middleware/authentication/adapters/session.js +11 -8
  25. package/middleware/authentication/authentication.js +28 -16
  26. package/middleware/authentication/authenticators/default.js +5 -2
  27. package/middleware/authentication/authenticators/session.js +5 -2
  28. package/middleware/authentication/providers/saml.js +1 -1
  29. package/middleware/authorization/authorization.js +11 -8
  30. package/middleware/awareness/awareness.js +55 -31
  31. package/middleware/awareness/plugins/editorial.js +4 -4
  32. package/middleware/awareness/providers/abstract-async.js +107 -84
  33. package/middleware/awareness/providers/abstract.js +1 -1
  34. package/middleware/awareness/providers/memory.js +0 -14
  35. package/middleware/awareness/providers/redis.js +186 -279
  36. package/middleware/cache/cache.js +4 -2
  37. package/middleware/cache/providers/redis.js +127 -89
  38. package/middleware/cache/providers/shared-memory.js +3 -3
  39. package/middleware/cloudcms/cloudcms.js +22 -16
  40. package/middleware/form/form.js +3 -3
  41. package/middleware/modules/modules.js +6 -3
  42. package/middleware/proxy/proxy.js +8 -21
  43. package/middleware/stores/stores.js +2 -2
  44. package/middleware/virtual-config/virtual-config.js +11 -8
  45. package/middleware/wcm/wcm.js +4 -4
  46. package/notifications/notifications.js +2 -2
  47. package/package.json +29 -25
  48. package/server/index.js +504 -415
  49. package/server/standalone.js +9 -0
  50. package/temp/clusterlock/index.js +3 -3
  51. package/temp/clusterlock/package.json +1 -1
  52. package/temp/passport-saml/LICENSE +23 -0
  53. package/temp/passport-saml/README.md +406 -0
  54. package/temp/passport-saml/lib/node-saml/algorithms.d.ts +5 -0
  55. package/temp/passport-saml/lib/node-saml/algorithms.js +41 -0
  56. package/temp/passport-saml/lib/node-saml/algorithms.js.map +1 -0
  57. package/temp/passport-saml/lib/node-saml/index.d.ts +3 -0
  58. package/temp/passport-saml/lib/node-saml/index.js +6 -0
  59. package/temp/passport-saml/lib/node-saml/index.js.map +1 -0
  60. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.d.ts +45 -0
  61. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js +86 -0
  62. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js.map +1 -0
  63. package/temp/passport-saml/lib/node-saml/saml-post-signing.d.ts +3 -0
  64. package/temp/passport-saml/lib/node-saml/saml-post-signing.js +15 -0
  65. package/temp/passport-saml/lib/node-saml/saml-post-signing.js.map +1 -0
  66. package/temp/passport-saml/lib/node-saml/saml.d.ts +77 -0
  67. package/temp/passport-saml/lib/node-saml/saml.js +1170 -0
  68. package/temp/passport-saml/lib/node-saml/saml.js.map +1 -0
  69. package/temp/passport-saml/lib/node-saml/types.d.ts +95 -0
  70. package/temp/passport-saml/lib/node-saml/types.js +8 -0
  71. package/temp/passport-saml/lib/node-saml/types.js.map +1 -0
  72. package/temp/passport-saml/lib/node-saml/utility.d.ts +3 -0
  73. package/temp/passport-saml/lib/node-saml/utility.js +19 -0
  74. package/temp/passport-saml/lib/node-saml/utility.js.map +1 -0
  75. package/temp/passport-saml/lib/node-saml/xml.d.ts +21 -0
  76. package/temp/passport-saml/lib/node-saml/xml.js +140 -0
  77. package/temp/passport-saml/lib/node-saml/xml.js.map +1 -0
  78. package/temp/passport-saml/lib/passport-saml/index.d.ts +6 -0
  79. package/temp/passport-saml/lib/passport-saml/index.js +11 -0
  80. package/temp/passport-saml/lib/passport-saml/index.js.map +1 -0
  81. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.d.ts +13 -0
  82. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js +63 -0
  83. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js.map +1 -0
  84. package/temp/passport-saml/lib/passport-saml/strategy.d.ts +20 -0
  85. package/temp/passport-saml/lib/passport-saml/strategy.js +167 -0
  86. package/temp/passport-saml/lib/passport-saml/strategy.js.map +1 -0
  87. package/temp/passport-saml/lib/passport-saml/types.d.ts +51 -0
  88. package/temp/passport-saml/lib/passport-saml/types.js +11 -0
  89. package/temp/passport-saml/lib/passport-saml/types.js.map +1 -0
  90. package/temp/passport-saml/package.json +96 -0
  91. package/util/auth.js +6 -6
  92. package/util/cloudcms.js +106 -118
  93. package/util/proxy-factory.js +159 -268
  94. package/util/redis.js +113 -0
  95. package/util/renditions.js +12 -6
  96. package/util/request.js +12 -6
  97. package/util/util.js +16 -2
  98. package/launchpad/launchers/sticky-cluster.js +0 -43
  99. package/temp/memored/.jshintrc +0 -4
  100. package/temp/memored/README.md +0 -240
  101. package/temp/memored/demo/demo1.js +0 -37
  102. package/temp/memored/demo/demo2.js +0 -32
  103. package/temp/memored/gulpfile.js +0 -8
  104. package/temp/memored/index.js +0 -343
  105. package/temp/memored/package.json +0 -54
  106. package/temp/memored/spec/memored.spec.js +0 -265
  107. package/web/cms/ice.js +0 -109
  108. package/web/cms/preview.js +0 -106
package/util/cloudcms.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var path = require('path');
2
- var fs = require('fs');
2
+ //var fs = require('fs');
3
3
  var util = require("./util");
4
4
 
5
5
  var http = require("http");
@@ -69,26 +69,23 @@ exports = module.exports = function()
69
69
  {
70
70
  if (!repositoryId)
71
71
  {
72
- callback({
72
+ return callback({
73
73
  "message": "Missing repositoryId in ensureContentDirectory()"
74
74
  });
75
- return;
76
75
  }
77
76
 
78
77
  if (!branchId)
79
78
  {
80
- callback({
79
+ return callback({
81
80
  "message": "Missing branchId in ensureContentDirectory()"
82
81
  });
83
- return;
84
82
  }
85
83
 
86
84
  if (!locale)
87
85
  {
88
- callback({
86
+ return callback({
89
87
  "message": "Missing locale in ensureContentDirectory()"
90
88
  });
91
- return;
92
89
  }
93
90
 
94
91
  var contentDirectoryPath = path.join(repositoryId, branchId, nodeId, locale);
@@ -149,21 +146,17 @@ exports = module.exports = function()
149
146
  if (err)
150
147
  {
151
148
  // nothing found
152
- callback({
149
+ return callback({
153
150
  "message": "Nothing cached on disk"
154
151
  });
155
-
156
- return;
157
152
  }
158
153
 
159
154
  if (!cacheInfoString)
160
155
  {
161
156
  // nothing found
162
- callback({
157
+ return callback({
163
158
  "message": "Nothing cached on disk"
164
159
  });
165
-
166
- return;
167
160
  }
168
161
 
169
162
  var invalidate = function () {
@@ -352,18 +345,35 @@ exports = module.exports = function()
352
345
  "err": previousError
353
346
  });
354
347
  }
355
-
356
- contentStore.writeStream(filePath, function(err, tempStream) {
357
-
358
- if (err)
348
+
349
+ var failFast = function(contentStore, filePath, cb) {
350
+ var triggered = false;
351
+
352
+ return function(tempStream, err)
359
353
  {
354
+ // don't allow this to be called twice
355
+ if (triggered) {
356
+ return;
357
+ }
358
+
359
+ triggered = true;
360
+
360
361
  // ensure stream is closed
361
- closeWriteStream(tempStream);
362
-
362
+ if (tempStream) {
363
+ closeWriteStream(tempStream);
364
+ }
365
+
363
366
  // ensure cleanup
364
367
  return safeRemove(contentStore, filePath, function () {
365
368
  cb(err);
366
369
  });
370
+ };
371
+ }(contentStore, filePath, cb);
372
+
373
+ contentStore.writeStream(filePath, function(err, tempStream) {
374
+
375
+ if (err) {
376
+ return failFast(tempStream, err);
367
377
  }
368
378
 
369
379
  var cacheFilePath = toCacheFilePath(filePath);
@@ -375,7 +385,13 @@ exports = module.exports = function()
375
385
  var headers2 = gitana.platform().getDriver().getHttpHeaders();
376
386
  headers["Authorization"] = headers2["Authorization"];
377
387
 
378
- var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT) + uri;
388
+ var agent = http.globalAgent;
389
+ if (process.env.GITANA_PROXY_SCHEME === "https")
390
+ {
391
+ agent = https.globalAgent;
392
+ }
393
+
394
+ var URL = util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH) + uri;
379
395
  request({
380
396
  "method": "GET",
381
397
  "url": URL,
@@ -383,124 +399,86 @@ exports = module.exports = function()
383
399
  "headers": headers,
384
400
  "responseType": "stream"
385
401
  }, function(err, response) {
386
-
402
+
387
403
  if (err) {
388
404
  closeWriteStream(tempStream);
389
405
  return cb(err);
390
406
  }
391
-
407
+
392
408
  if (response.status >= 200 && response.status <= 204)
393
409
  {
394
410
  response.data.pipe(tempStream).on("close", function (err) {
395
-
396
- // TODO: not needed here?
397
- // ensure stream is closed
398
- // closeWriteStream(tempStream);
399
-
400
- if (err)
401
- {
411
+
412
+ if (err) {
402
413
  // some went wrong at disk io level?
403
- return safeRemove(contentStore, filePath, function () {
404
- cb({
405
- "message": "Failed to download: " + JSON.stringify(err)
406
- });
407
- });
414
+ return failFast(tempStream, err);
408
415
  }
409
-
416
+
410
417
  contentStore.existsFile(filePath, function (exists) {
411
-
418
+
412
419
  if (exists) {
413
-
420
+
414
421
  // write cache file
415
422
  var cacheInfo = buildCacheInfo(response);
416
- if (cacheInfo)
417
- {
418
- contentStore.writeFile(cacheFilePath, JSON.stringify(cacheInfo, null, " "), function (err) {
419
-
420
- if (err)
421
- {
422
- // failed to write cache file, thus the whole thing is invalid
423
- safeRemove(contentStore, cacheFilePath, function () {
424
- safeRemove(contentStore, filePath, function () {
425
- cb({
426
- "message": "Failed to write cache file: " + cacheFilePath
427
- });
428
- });
429
- });
430
- }
431
- else
432
- {
433
- cb(null, filePath, cacheInfo);
434
- }
435
-
436
- });
423
+ if (!cacheInfo) {
424
+ return cb(null, filePath, null);
437
425
  }
438
- else
439
- {
426
+
427
+ contentStore.writeFile(cacheFilePath, JSON.stringify(cacheInfo, null, " "), function (err) {
428
+
429
+ if (err) {
430
+ // failed to write cache file, thus the whole thing is invalid
431
+ return safeRemove(contentStore, cacheFilePath, function () {
432
+ failFast(tempStream, {
433
+ "message": "Failed to write cache file: " + cacheFilePath + ", err: " + JSON.stringify(err)
434
+ });
435
+ });
436
+ }
437
+
440
438
  cb(null, filePath, cacheInfo);
441
- }
442
- }
443
- else
444
- {
445
- //process.log("WARN: exists false, " + filePath);
446
-
439
+ });
440
+ } else {
447
441
  // for some reason, file wasn't found
448
442
  // roll back the whole thing
449
443
  safeRemove(contentStore, cacheFilePath, function () {
450
- safeRemove(contentStore, filePath, function () {
451
- cb({
452
- "message": "Failed to verify written cached file: " + filePath
453
- });
444
+ failFast(tempStream, {
445
+ "message": "Failed to verify written cached file: " + filePath
454
446
  });
455
447
  });
456
448
  }
457
449
  });
458
-
450
+
459
451
  }).on("error", function (err) {
460
-
461
- console.log("f2");
462
-
463
- // ensure stream is closed
464
- closeWriteStream(tempStream);
465
-
466
- process.log("Pipe error: " + err);
452
+ failFast(tempStream, err);
467
453
  });
468
454
  }
469
455
  else
470
456
  {
471
457
  // some kind of http error (usually permission denied or invalid_token)
472
-
458
+
473
459
  var body = "";
474
-
460
+
475
461
  response.data.on('data', function (chunk) {
476
462
  body += chunk;
477
463
  });
478
-
479
- response.on('end', function () {
480
-
481
- // ensure stream is closed
482
- closeWriteStream(tempStream);
483
-
464
+
465
+ response.data.on('end', function () {
466
+
484
467
  var afterCleanup = function () {
485
-
468
+
486
469
  // see if it is "invalid_token"
487
470
  // if so, we can automatically retry
488
471
  var isInvalidToken = false;
489
- try
490
- {
472
+ try {
491
473
  var json = JSON.parse(body);
492
- if (json && json.error === "invalid_token")
493
- {
474
+ if (json && json.error === "invalid_token") {
494
475
  isInvalidToken = true;
495
476
  }
496
- }
497
- catch (e)
498
- {
477
+ } catch (e) {
499
478
  // swallow
500
479
  }
501
-
502
- if (isInvalidToken)
503
- {
480
+
481
+ if (isInvalidToken) {
504
482
  // fire for retry
505
483
  return _refreshAccessTokenAndRetry(contentStore, gitana, uri, filePath, attemptCount, maxAttemptsAllowed, {
506
484
  "message": "Unable to load asset from remote store",
@@ -508,16 +486,18 @@ exports = module.exports = function()
508
486
  "body": body
509
487
  }, cb);
510
488
  }
511
-
489
+
512
490
  // otherwise, it's not worth retrying at this time
513
491
  cb({
514
492
  "message": "Unable to load asset from remote store",
515
493
  "code": response.status,
516
494
  "body": body
517
495
  });
518
-
519
496
  };
520
-
497
+
498
+ // ensure stream is closed
499
+ closeWriteStream(tempStream);
500
+
521
501
  // clean things up
522
502
  safeRemove(contentStore, cacheFilePath, function () {
523
503
  safeRemove(contentStore, filePath, function () {
@@ -525,17 +505,27 @@ exports = module.exports = function()
525
505
  });
526
506
  });
527
507
  });
528
-
508
+
529
509
  }
530
-
531
510
  });
511
+ // }).on('error', function (e) {
512
+ // failFast(tempStream, e);
513
+ //
514
+ // }).on('end', function (e) {
515
+ //
516
+ // // ensure stream is closed
517
+ // closeWriteStream(tempStream);
518
+ //
519
+ // }).end();
532
520
 
533
521
  tempStream.on("error", function (e) {
534
522
  process.log("Temp stream errored out");
535
523
  process.log(e);
524
+
525
+ failFast(tempStream, e);
536
526
 
537
527
  // ensure stream is closed
538
- closeWriteStream(tempStream);
528
+ //closeWriteStream(tempStream);
539
529
 
540
530
  });
541
531
  });
@@ -593,8 +583,7 @@ exports = module.exports = function()
593
583
  readFromDisk(contentStore, filePath, function (err, cacheInfo) {
594
584
 
595
585
  if (!err && cacheInfo) {
596
- callback(err, filePath, cacheInfo);
597
- return;
586
+ return callback(err, filePath, cacheInfo);
598
587
  }
599
588
 
600
589
  // either there was an error (in which case things were cleaned up)
@@ -616,13 +605,12 @@ exports = module.exports = function()
616
605
 
617
606
  if (err) {
618
607
  process.log("writeToDisk error, err: " + err.message + ", body: " + err.body);
619
- callback(err);
620
- }
621
- else {
622
- //process.log("Fetched: " + assetPath);
623
- //process.log("Retrieved from server: " + filePath);
624
- callback(null, filePath, cacheInfo);
608
+ return callback(err);
625
609
  }
610
+
611
+ //process.log("Fetched: " + assetPath);
612
+ //process.log("Retrieved from server: " + filePath);
613
+ callback(null, filePath, cacheInfo);
626
614
  });
627
615
  });
628
616
  };
@@ -734,6 +722,7 @@ exports = module.exports = function()
734
722
  writeToDisk(contentStore, gitana, uri, filePath, function (err, filePath, responseHeaders) {
735
723
 
736
724
  if (err) {
725
+
737
726
  if (err.code === 404) {
738
727
  return callback();
739
728
  }
@@ -1057,7 +1046,7 @@ exports = module.exports = function()
1057
1046
  r.download = function(contentStore, gitana, repositoryId, branchId, nodeId, attachmentId, nodePath, locale, forceReload, callback)
1058
1047
  {
1059
1048
  // claim a lock around this node for this server
1060
- _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(releaseLockFn) {
1049
+ _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(err, releaseLockFn) {
1061
1050
 
1062
1051
  // workhorse - pass releaseLockFn back to callback
1063
1052
  downloadNode(contentStore, gitana, repositoryId, branchId, nodeId, attachmentId, nodePath, locale, forceReload, function (err, filePath, cacheInfo) {
@@ -1070,7 +1059,7 @@ exports = module.exports = function()
1070
1059
  r.preview = function(contentStore, gitana, repositoryId, branchId, nodeId, nodePath, attachmentId, locale, previewId, size, mimetype, forceReload, callback)
1071
1060
  {
1072
1061
  // claim a lock around this node for this server
1073
- _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(releaseLockFn) {
1062
+ _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(err, releaseLockFn) {
1074
1063
 
1075
1064
  // workhorse - pass releaseLockFn back to callback
1076
1065
  previewNode(contentStore, gitana, repositoryId, branchId, nodeId, nodePath, attachmentId, locale, previewId, size, mimetype, forceReload, function(err, filePath, cacheInfo) {
@@ -1083,10 +1072,9 @@ exports = module.exports = function()
1083
1072
  r.invalidate = function(contentStore, repositoryId, branchId, nodeId, paths, callback)
1084
1073
  {
1085
1074
  // claim a lock around this node for this server
1086
- _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(releaseLockFn) {
1075
+ _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(err, releaseLockFn) {
1087
1076
 
1088
1077
  invalidateNode(contentStore, repositoryId, branchId, nodeId, function () {
1089
-
1090
1078
  invalidateNodePaths(contentStore, repositoryId, branchId, paths, function() {
1091
1079
 
1092
1080
  // release lock
@@ -1103,7 +1091,7 @@ exports = module.exports = function()
1103
1091
  r.downloadAttachable = function(contentStore, gitana, datastoreTypeId, datastoreId, objectTypeId, objectId, attachmentId, locale, forceReload, callback)
1104
1092
  {
1105
1093
  // claim a lock around this node for this server
1106
- _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(releaseLockFn) {
1094
+ _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(err, releaseLockFn) {
1107
1095
 
1108
1096
  // workhorse - pass releaseLockFn back to callback
1109
1097
  downloadAttachable(contentStore, gitana, datastoreTypeId, datastoreId, objectTypeId, objectId, attachmentId, locale, forceReload, function(err, filePath, cacheInfo) {
@@ -1116,7 +1104,7 @@ exports = module.exports = function()
1116
1104
  r.previewAttachable = function(contentStore, gitana, datastoreTypeId, datastoreId, objectTypeId, objectId, attachmentId, locale, previewId, size, mimetype, forceReload, callback)
1117
1105
  {
1118
1106
  // claim a lock around this node for this server
1119
- _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(releaseLockFn) {
1107
+ _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(err, releaseLockFn) {
1120
1108
 
1121
1109
  // workhorse - pass releaseLockFn back to callback
1122
1110
  previewAttachable(contentStore, gitana, datastoreTypeId, datastoreId, objectTypeId, objectId, attachmentId, locale, previewId, size, mimetype, forceReload, function (err, filePath, cacheInfo) {
@@ -1129,7 +1117,7 @@ exports = module.exports = function()
1129
1117
  r.invalidateAttachable = function(contentStore, datastoreTypeId, datastoreId, objectTypeId, objectId, callback)
1130
1118
  {
1131
1119
  // claim a lock around this node for this server
1132
- _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(releaseLockFn) {
1120
+ _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(err, releaseLockFn) {
1133
1121
 
1134
1122
  // TODO: not implemented
1135
1123
  callback();