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

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 +85 -88
  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 +4 -4
  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,
@@ -393,18 +409,10 @@ exports = module.exports = function()
393
409
  {
394
410
  response.data.pipe(tempStream).on("close", function (err) {
395
411
 
396
- // TODO: not needed here?
397
- // ensure stream is closed
398
- // closeWriteStream(tempStream);
399
-
400
412
  if (err)
401
413
  {
402
414
  // 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
- });
415
+ return failFast(tempStream, err);
408
416
  }
409
417
 
410
418
  contentStore.existsFile(filePath, function (exists) {
@@ -413,57 +421,39 @@ exports = module.exports = function()
413
421
 
414
422
  // write cache file
415
423
  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
- });
424
+ if (!cacheInfo) {
425
+ return cb(null, filePath, null);
426
+ }
427
+
428
+ contentStore.writeFile(cacheFilePath, JSON.stringify(cacheInfo, null, " "), function (err) {
429
+
430
+ if (err)
431
+ {
432
+ // failed to write cache file, thus the whole thing is invalid
433
+ return safeRemove(contentStore, cacheFilePath, function () {
434
+ failFast(tempStream, {
435
+ "message": "Failed to write cache file: " + cacheFilePath + ", err: " + JSON.stringify(err)
429
436
  });
430
- }
431
- else
432
- {
433
- cb(null, filePath, cacheInfo);
434
- }
437
+ });
438
+ }
435
439
 
436
- });
437
- }
438
- else
439
- {
440
440
  cb(null, filePath, cacheInfo);
441
- }
441
+ });
442
442
  }
443
443
  else
444
444
  {
445
- //process.log("WARN: exists false, " + filePath);
446
-
447
445
  // for some reason, file wasn't found
448
446
  // roll back the whole thing
449
447
  safeRemove(contentStore, cacheFilePath, function () {
450
- safeRemove(contentStore, filePath, function () {
451
- cb({
452
- "message": "Failed to verify written cached file: " + filePath
453
- });
448
+ failFast(tempStream, {
449
+ "message": "Failed to verify written cached file: " + filePath
454
450
  });
455
451
  });
456
452
  }
457
453
  });
458
454
 
459
455
  }).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);
456
+ failFast(tempStream, err);
467
457
  });
468
458
  }
469
459
  else
@@ -477,10 +467,7 @@ exports = module.exports = function()
477
467
  });
478
468
 
479
469
  response.on('end', function () {
480
-
481
- // ensure stream is closed
482
- closeWriteStream(tempStream);
483
-
470
+
484
471
  var afterCleanup = function () {
485
472
 
486
473
  // see if it is "invalid_token"
@@ -515,9 +502,11 @@ exports = module.exports = function()
515
502
  "code": response.status,
516
503
  "body": body
517
504
  });
518
-
519
505
  };
520
-
506
+
507
+ // ensure stream is closed
508
+ closeWriteStream(tempStream);
509
+
521
510
  // clean things up
522
511
  safeRemove(contentStore, cacheFilePath, function () {
523
512
  safeRemove(contentStore, filePath, function () {
@@ -528,14 +517,24 @@ exports = module.exports = function()
528
517
 
529
518
  }
530
519
 
531
- });
520
+ }).on('error', function (e) {
521
+ failFast(tempStream, e);
522
+
523
+ }).on('end', function (e) {
524
+
525
+ // ensure stream is closed
526
+ closeWriteStream(tempStream);
527
+
528
+ }).end();
532
529
 
533
530
  tempStream.on("error", function (e) {
534
531
  process.log("Temp stream errored out");
535
532
  process.log(e);
533
+
534
+ failFast(tempStream, e);
536
535
 
537
536
  // ensure stream is closed
538
- closeWriteStream(tempStream);
537
+ //closeWriteStream(tempStream);
539
538
 
540
539
  });
541
540
  });
@@ -593,8 +592,7 @@ exports = module.exports = function()
593
592
  readFromDisk(contentStore, filePath, function (err, cacheInfo) {
594
593
 
595
594
  if (!err && cacheInfo) {
596
- callback(err, filePath, cacheInfo);
597
- return;
595
+ return callback(err, filePath, cacheInfo);
598
596
  }
599
597
 
600
598
  // either there was an error (in which case things were cleaned up)
@@ -616,13 +614,12 @@ exports = module.exports = function()
616
614
 
617
615
  if (err) {
618
616
  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);
617
+ return callback(err);
625
618
  }
619
+
620
+ //process.log("Fetched: " + assetPath);
621
+ //process.log("Retrieved from server: " + filePath);
622
+ callback(null, filePath, cacheInfo);
626
623
  });
627
624
  });
628
625
  };
@@ -734,6 +731,7 @@ exports = module.exports = function()
734
731
  writeToDisk(contentStore, gitana, uri, filePath, function (err, filePath, responseHeaders) {
735
732
 
736
733
  if (err) {
734
+
737
735
  if (err.code === 404) {
738
736
  return callback();
739
737
  }
@@ -1057,7 +1055,7 @@ exports = module.exports = function()
1057
1055
  r.download = function(contentStore, gitana, repositoryId, branchId, nodeId, attachmentId, nodePath, locale, forceReload, callback)
1058
1056
  {
1059
1057
  // claim a lock around this node for this server
1060
- _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(releaseLockFn) {
1058
+ _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(err, releaseLockFn) {
1061
1059
 
1062
1060
  // workhorse - pass releaseLockFn back to callback
1063
1061
  downloadNode(contentStore, gitana, repositoryId, branchId, nodeId, attachmentId, nodePath, locale, forceReload, function (err, filePath, cacheInfo) {
@@ -1070,7 +1068,7 @@ exports = module.exports = function()
1070
1068
  r.preview = function(contentStore, gitana, repositoryId, branchId, nodeId, nodePath, attachmentId, locale, previewId, size, mimetype, forceReload, callback)
1071
1069
  {
1072
1070
  // claim a lock around this node for this server
1073
- _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(releaseLockFn) {
1071
+ _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(err, releaseLockFn) {
1074
1072
 
1075
1073
  // workhorse - pass releaseLockFn back to callback
1076
1074
  previewNode(contentStore, gitana, repositoryId, branchId, nodeId, nodePath, attachmentId, locale, previewId, size, mimetype, forceReload, function(err, filePath, cacheInfo) {
@@ -1083,10 +1081,9 @@ exports = module.exports = function()
1083
1081
  r.invalidate = function(contentStore, repositoryId, branchId, nodeId, paths, callback)
1084
1082
  {
1085
1083
  // claim a lock around this node for this server
1086
- _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(releaseLockFn) {
1084
+ _LOCK(contentStore, _lock_identifier(repositoryId, branchId, nodeId), function(err, releaseLockFn) {
1087
1085
 
1088
1086
  invalidateNode(contentStore, repositoryId, branchId, nodeId, function () {
1089
-
1090
1087
  invalidateNodePaths(contentStore, repositoryId, branchId, paths, function() {
1091
1088
 
1092
1089
  // release lock
@@ -1103,7 +1100,7 @@ exports = module.exports = function()
1103
1100
  r.downloadAttachable = function(contentStore, gitana, datastoreTypeId, datastoreId, objectTypeId, objectId, attachmentId, locale, forceReload, callback)
1104
1101
  {
1105
1102
  // claim a lock around this node for this server
1106
- _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(releaseLockFn) {
1103
+ _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(err, releaseLockFn) {
1107
1104
 
1108
1105
  // workhorse - pass releaseLockFn back to callback
1109
1106
  downloadAttachable(contentStore, gitana, datastoreTypeId, datastoreId, objectTypeId, objectId, attachmentId, locale, forceReload, function(err, filePath, cacheInfo) {
@@ -1116,7 +1113,7 @@ exports = module.exports = function()
1116
1113
  r.previewAttachable = function(contentStore, gitana, datastoreTypeId, datastoreId, objectTypeId, objectId, attachmentId, locale, previewId, size, mimetype, forceReload, callback)
1117
1114
  {
1118
1115
  // claim a lock around this node for this server
1119
- _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(releaseLockFn) {
1116
+ _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(err, releaseLockFn) {
1120
1117
 
1121
1118
  // workhorse - pass releaseLockFn back to callback
1122
1119
  previewAttachable(contentStore, gitana, datastoreTypeId, datastoreId, objectTypeId, objectId, attachmentId, locale, previewId, size, mimetype, forceReload, function (err, filePath, cacheInfo) {
@@ -1129,7 +1126,7 @@ exports = module.exports = function()
1129
1126
  r.invalidateAttachable = function(contentStore, datastoreTypeId, datastoreId, objectTypeId, objectId, callback)
1130
1127
  {
1131
1128
  // claim a lock around this node for this server
1132
- _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(releaseLockFn) {
1129
+ _LOCK(contentStore, _lock_identifier(datastoreId, objectId), function(err, releaseLockFn) {
1133
1130
 
1134
1131
  // TODO: not implemented
1135
1132
  callback();