nitrogen 0.2.24 → 0.29.4
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.
- package/README.md +15 -109
- package/lib/Logger.d.ts +10 -0
- package/lib/Logger.js +56 -0
- package/lib/autolinking/Autolinking.d.ts +8 -0
- package/lib/autolinking/Autolinking.js +1 -0
- package/lib/autolinking/android/createCMakeExtension.d.ts +6 -0
- package/lib/autolinking/android/createCMakeExtension.js +106 -0
- package/lib/autolinking/android/createGradleExtension.d.ts +5 -0
- package/lib/autolinking/android/createGradleExtension.js +36 -0
- package/lib/autolinking/android/createHybridObjectInitializer.d.ts +2 -0
- package/lib/autolinking/android/createHybridObjectInitializer.js +159 -0
- package/lib/autolinking/createAndroidAutolinking.d.ts +11 -0
- package/lib/autolinking/createAndroidAutolinking.js +13 -0
- package/lib/autolinking/createIOSAutolinking.d.ts +5 -0
- package/lib/autolinking/createIOSAutolinking.js +19 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.d.ts +9 -0
- package/lib/autolinking/ios/createHybridObjectInitializer.js +97 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.d.ts +5 -0
- package/lib/autolinking/ios/createPodspecRubyExtension.js +69 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.d.ts +2 -0
- package/lib/autolinking/ios/createSwiftCxxBridge.js +117 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.d.ts +3 -0
- package/lib/autolinking/ios/createSwiftUmbrellaHeader.js +74 -0
- package/lib/config/NitroConfig.d.ts +52 -0
- package/lib/config/NitroConfig.js +112 -0
- package/lib/config/NitroUserConfig.d.ts +22 -0
- package/lib/config/NitroUserConfig.js +88 -0
- package/lib/config/getConfig.d.ts +2 -0
- package/lib/config/getConfig.js +84 -0
- package/lib/createGitAttributes.d.ts +1 -0
- package/lib/createGitAttributes.js +11 -0
- package/lib/createPlatformSpec.d.ts +4 -0
- package/lib/createPlatformSpec.js +127 -0
- package/lib/getFiles.d.ts +1 -0
- package/lib/getFiles.js +28 -0
- package/lib/getPlatformSpecs.d.ts +17 -0
- package/lib/getPlatformSpecs.js +153 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +113 -10
- package/lib/init.d.ts +1 -0
- package/lib/init.js +123 -0
- package/lib/nitrogen.d.ts +11 -0
- package/lib/nitrogen.js +165 -0
- package/lib/prettifyDirectory.d.ts +1 -0
- package/lib/prettifyDirectory.js +27 -0
- package/lib/syntax/BridgedType.d.ts +41 -0
- package/lib/syntax/BridgedType.js +1 -0
- package/lib/syntax/CodeNode.d.ts +23 -0
- package/lib/syntax/CodeNode.js +1 -0
- package/lib/syntax/HybridObjectSpec.d.ts +13 -0
- package/lib/syntax/HybridObjectSpec.js +1 -0
- package/lib/syntax/Method.d.ts +41 -0
- package/lib/syntax/Method.js +108 -0
- package/lib/syntax/Parameter.d.ts +15 -0
- package/lib/syntax/Parameter.js +65 -0
- package/lib/syntax/Property.d.ts +50 -0
- package/lib/syntax/Property.js +147 -0
- package/lib/syntax/SourceFile.d.ts +70 -0
- package/lib/syntax/SourceFile.js +7 -0
- package/lib/syntax/c++/CppEnum.d.ts +6 -0
- package/lib/syntax/c++/CppEnum.js +110 -0
- package/lib/syntax/c++/CppHybridObject.d.ts +3 -0
- package/lib/syntax/c++/CppHybridObject.js +146 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/c++/CppHybridObjectRegistration.js +18 -0
- package/lib/syntax/c++/CppStruct.d.ts +3 -0
- package/lib/syntax/c++/CppStruct.js +108 -0
- package/lib/syntax/c++/CppUnion.d.ts +6 -0
- package/lib/syntax/c++/CppUnion.js +88 -0
- package/lib/syntax/c++/getForwardDeclaration.d.ts +3 -0
- package/lib/syntax/c++/getForwardDeclaration.js +14 -0
- package/lib/syntax/c++/includeNitroHeader.d.ts +7 -0
- package/lib/syntax/c++/includeNitroHeader.js +34 -0
- package/lib/syntax/createType.d.ts +15 -0
- package/lib/syntax/createType.js +303 -0
- package/lib/syntax/getAllTypes.d.ts +3 -0
- package/lib/syntax/getAllTypes.js +11 -0
- package/lib/syntax/getCustomTypeConfig.d.ts +8 -0
- package/lib/syntax/getCustomTypeConfig.js +53 -0
- package/lib/syntax/getHybridObjectName.d.ts +36 -0
- package/lib/syntax/getHybridObjectName.js +10 -0
- package/lib/syntax/getInterfaceProperties.d.ts +4 -0
- package/lib/syntax/getInterfaceProperties.js +9 -0
- package/lib/syntax/getReferencedTypes.d.ts +2 -0
- package/lib/syntax/getReferencedTypes.js +47 -0
- package/lib/syntax/helpers.d.ts +13 -0
- package/lib/syntax/helpers.js +53 -0
- package/lib/syntax/isCoreType.d.ts +9 -0
- package/lib/syntax/isCoreType.js +47 -0
- package/lib/syntax/kotlin/FbjniHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/FbjniHybridObject.js +261 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.d.ts +8 -0
- package/lib/syntax/kotlin/JNINativeRegistrations.js +7 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.d.ts +7 -0
- package/lib/syntax/kotlin/KotlinBoxedPrimitive.js +17 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.d.ts +19 -0
- package/lib/syntax/kotlin/KotlinCxxBridgedType.js +893 -0
- package/lib/syntax/kotlin/KotlinEnum.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinEnum.js +113 -0
- package/lib/syntax/kotlin/KotlinFunction.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinFunction.js +256 -0
- package/lib/syntax/kotlin/KotlinHybridObject.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinHybridObject.js +177 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.d.ts +17 -0
- package/lib/syntax/kotlin/KotlinHybridObjectRegistration.js +26 -0
- package/lib/syntax/kotlin/KotlinStruct.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinStruct.js +172 -0
- package/lib/syntax/kotlin/KotlinVariant.d.ts +3 -0
- package/lib/syntax/kotlin/KotlinVariant.js +191 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.d.ts +21 -0
- package/lib/syntax/swift/SwiftCxxBridgedType.js +819 -0
- package/lib/syntax/swift/SwiftCxxTypeHelper.d.ts +17 -0
- package/lib/syntax/swift/SwiftCxxTypeHelper.js +613 -0
- package/lib/syntax/swift/SwiftEnum.d.ts +3 -0
- package/lib/syntax/swift/SwiftEnum.js +52 -0
- package/lib/syntax/swift/SwiftFunction.d.ts +3 -0
- package/lib/syntax/swift/SwiftFunction.js +83 -0
- package/lib/syntax/swift/SwiftHybridObject.d.ts +3 -0
- package/lib/syntax/swift/SwiftHybridObject.js +103 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.d.ts +11 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.js +451 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +19 -0
- package/lib/syntax/swift/SwiftHybridObjectRegistration.js +42 -0
- package/lib/syntax/swift/SwiftStruct.d.ts +3 -0
- package/lib/syntax/swift/SwiftStruct.js +75 -0
- package/lib/syntax/swift/SwiftVariant.d.ts +3 -0
- package/lib/syntax/swift/SwiftVariant.js +58 -0
- package/lib/syntax/types/ArrayBufferType.d.ts +10 -0
- package/lib/syntax/types/ArrayBufferType.js +37 -0
- package/lib/syntax/types/ArrayType.d.ts +12 -0
- package/lib/syntax/types/ArrayType.js +52 -0
- package/lib/syntax/types/BigIntType.d.ts +10 -0
- package/lib/syntax/types/BigIntType.js +27 -0
- package/lib/syntax/types/BooleanType.d.ts +10 -0
- package/lib/syntax/types/BooleanType.js +27 -0
- package/lib/syntax/types/CustomType.d.ts +14 -0
- package/lib/syntax/types/CustomType.js +36 -0
- package/lib/syntax/types/DateType.d.ts +10 -0
- package/lib/syntax/types/DateType.js +35 -0
- package/lib/syntax/types/EnumType.d.ts +23 -0
- package/lib/syntax/types/EnumType.js +101 -0
- package/lib/syntax/types/ErrorType.d.ts +11 -0
- package/lib/syntax/types/ErrorType.js +37 -0
- package/lib/syntax/types/FunctionType.d.ts +29 -0
- package/lib/syntax/types/FunctionType.js +147 -0
- package/lib/syntax/types/HybridObjectBaseType.d.ts +11 -0
- package/lib/syntax/types/HybridObjectBaseType.js +38 -0
- package/lib/syntax/types/HybridObjectType.d.ts +23 -0
- package/lib/syntax/types/HybridObjectType.js +131 -0
- package/lib/syntax/types/MapType.d.ts +10 -0
- package/lib/syntax/types/MapType.js +37 -0
- package/lib/syntax/types/NamedWrappingType.d.ts +14 -0
- package/lib/syntax/types/NamedWrappingType.js +27 -0
- package/lib/syntax/types/NullType.d.ts +10 -0
- package/lib/syntax/types/NullType.js +23 -0
- package/lib/syntax/types/NumberType.d.ts +10 -0
- package/lib/syntax/types/NumberType.js +27 -0
- package/lib/syntax/types/OptionalType.d.ts +13 -0
- package/lib/syntax/types/OptionalType.js +59 -0
- package/lib/syntax/types/PromiseType.d.ts +16 -0
- package/lib/syntax/types/PromiseType.js +62 -0
- package/lib/syntax/types/RecordType.d.ts +13 -0
- package/lib/syntax/types/RecordType.js +47 -0
- package/lib/syntax/types/ResultWrappingType.d.ts +13 -0
- package/lib/syntax/types/ResultWrappingType.js +44 -0
- package/lib/syntax/types/StringType.d.ts +10 -0
- package/lib/syntax/types/StringType.js +35 -0
- package/lib/syntax/types/StructType.d.ts +14 -0
- package/lib/syntax/types/StructType.js +61 -0
- package/lib/syntax/types/TupleType.d.ts +12 -0
- package/lib/syntax/types/TupleType.js +39 -0
- package/lib/syntax/types/Type.d.ts +55 -0
- package/lib/syntax/types/Type.js +1 -0
- package/lib/syntax/types/VariantType.d.ts +19 -0
- package/lib/syntax/types/VariantType.js +75 -0
- package/lib/syntax/types/VoidType.d.ts +10 -0
- package/lib/syntax/types/VoidType.js +27 -0
- package/lib/syntax/types/getTypeAs.d.ts +2 -0
- package/lib/syntax/types/getTypeAs.js +12 -0
- package/lib/utils.d.ts +22 -0
- package/lib/utils.js +126 -0
- package/lib/views/CppHybridViewComponent.d.ts +14 -0
- package/lib/views/CppHybridViewComponent.js +254 -0
- package/lib/views/createHostComponentJs.d.ts +3 -0
- package/lib/views/createHostComponentJs.js +27 -0
- package/lib/views/kotlin/KotlinHybridViewManager.d.ts +3 -0
- package/lib/views/kotlin/KotlinHybridViewManager.js +229 -0
- package/lib/views/swift/SwiftHybridViewManager.d.ts +3 -0
- package/lib/views/swift/SwiftHybridViewManager.js +131 -0
- package/lib/writeFile.d.ts +5 -0
- package/lib/writeFile.js +19 -0
- package/package.json +58 -29
- package/src/Logger.ts +63 -0
- package/src/autolinking/Autolinking.ts +9 -0
- package/src/autolinking/android/createCMakeExtension.ts +123 -0
- package/src/autolinking/android/createGradleExtension.ts +43 -0
- package/src/autolinking/android/createHybridObjectInitializer.ts +174 -0
- package/src/autolinking/createAndroidAutolinking.ts +28 -0
- package/src/autolinking/createIOSAutolinking.ts +24 -0
- package/src/autolinking/ios/createHybridObjectInitializer.ts +112 -0
- package/src/autolinking/ios/createPodspecRubyExtension.ts +76 -0
- package/src/autolinking/ios/createSwiftCxxBridge.ts +137 -0
- package/src/autolinking/ios/createSwiftUmbrellaHeader.ts +90 -0
- package/src/config/NitroConfig.ts +139 -0
- package/src/config/NitroUserConfig.ts +105 -0
- package/src/config/getConfig.ts +91 -0
- package/src/createGitAttributes.ts +15 -0
- package/src/createPlatformSpec.ts +176 -0
- package/src/getFiles.ts +31 -0
- package/src/getPlatformSpecs.ts +202 -0
- package/src/index.ts +146 -0
- package/src/init.ts +186 -0
- package/src/nitrogen.ts +246 -0
- package/src/prettifyDirectory.ts +32 -0
- package/src/syntax/BridgedType.ts +59 -0
- package/src/syntax/CodeNode.ts +24 -0
- package/src/syntax/HybridObjectSpec.ts +14 -0
- package/src/syntax/Method.ts +154 -0
- package/src/syntax/Parameter.ts +81 -0
- package/src/syntax/Property.ts +203 -0
- package/src/syntax/SourceFile.ts +80 -0
- package/src/syntax/c++/CppEnum.ts +128 -0
- package/src/syntax/c++/CppHybridObject.ts +165 -0
- package/src/syntax/c++/CppHybridObjectRegistration.ts +39 -0
- package/src/syntax/c++/CppStruct.ts +129 -0
- package/src/syntax/c++/CppUnion.ts +105 -0
- package/src/syntax/c++/getForwardDeclaration.ts +19 -0
- package/src/syntax/c++/includeNitroHeader.ts +40 -0
- package/src/syntax/createType.ts +365 -0
- package/src/syntax/getAllTypes.ts +18 -0
- package/src/syntax/getCustomTypeConfig.ts +71 -0
- package/src/syntax/getHybridObjectName.ts +48 -0
- package/src/syntax/getInterfaceProperties.ts +21 -0
- package/src/syntax/getReferencedTypes.ts +57 -0
- package/src/syntax/helpers.ts +79 -0
- package/src/syntax/isCoreType.ts +60 -0
- package/src/syntax/kotlin/FbjniHybridObject.ts +313 -0
- package/src/syntax/kotlin/JNINativeRegistrations.ts +19 -0
- package/src/syntax/kotlin/KotlinBoxedPrimitive.ts +19 -0
- package/src/syntax/kotlin/KotlinCxxBridgedType.ts +942 -0
- package/src/syntax/kotlin/KotlinEnum.ts +130 -0
- package/src/syntax/kotlin/KotlinFunction.ts +277 -0
- package/src/syntax/kotlin/KotlinHybridObject.ts +205 -0
- package/src/syntax/kotlin/KotlinHybridObjectRegistration.ts +51 -0
- package/src/syntax/kotlin/KotlinStruct.ts +198 -0
- package/src/syntax/kotlin/KotlinVariant.ts +212 -0
- package/src/syntax/swift/SwiftCxxBridgedType.ts +874 -0
- package/src/syntax/swift/SwiftCxxTypeHelper.ts +674 -0
- package/src/syntax/swift/SwiftEnum.ts +65 -0
- package/src/syntax/swift/SwiftFunction.ts +91 -0
- package/src/syntax/swift/SwiftHybridObject.ts +121 -0
- package/src/syntax/swift/SwiftHybridObjectBridge.ts +522 -0
- package/src/syntax/swift/SwiftHybridObjectRegistration.ts +75 -0
- package/src/syntax/swift/SwiftStruct.ts +85 -0
- package/src/syntax/swift/SwiftVariant.ts +67 -0
- package/src/syntax/types/ArrayBufferType.ts +49 -0
- package/src/syntax/types/ArrayType.ts +62 -0
- package/src/syntax/types/BigIntType.ts +35 -0
- package/src/syntax/types/BooleanType.ts +35 -0
- package/src/syntax/types/CustomType.ts +47 -0
- package/src/syntax/types/DateType.ts +43 -0
- package/src/syntax/types/EnumType.ts +130 -0
- package/src/syntax/types/ErrorType.ts +44 -0
- package/src/syntax/types/FunctionType.ts +167 -0
- package/src/syntax/types/HybridObjectBaseType.ts +54 -0
- package/src/syntax/types/HybridObjectType.ts +198 -0
- package/src/syntax/types/MapType.ts +49 -0
- package/src/syntax/types/NamedWrappingType.ts +33 -0
- package/src/syntax/types/NullType.ts +30 -0
- package/src/syntax/types/NumberType.ts +34 -0
- package/src/syntax/types/OptionalType.ts +66 -0
- package/src/syntax/types/PromiseType.ts +72 -0
- package/src/syntax/types/RecordType.ts +56 -0
- package/src/syntax/types/ResultWrappingType.ts +53 -0
- package/src/syntax/types/StringType.ts +44 -0
- package/src/syntax/types/StructType.ts +83 -0
- package/src/syntax/types/TupleType.ts +53 -0
- package/src/syntax/types/Type.ts +82 -0
- package/src/syntax/types/VariantType.ts +92 -0
- package/src/syntax/types/VoidType.ts +34 -0
- package/src/syntax/types/getTypeAs.ts +15 -0
- package/src/utils.ts +162 -0
- package/src/views/CppHybridViewComponent.ts +301 -0
- package/src/views/createHostComponentJs.ts +34 -0
- package/src/views/kotlin/KotlinHybridViewManager.ts +258 -0
- package/src/views/swift/SwiftHybridViewManager.ts +153 -0
- package/src/writeFile.ts +27 -0
- package/.jshintignore +0 -6
- package/.jshintrc +0 -3
- package/.npmignore +0 -3
- package/.travis.yml +0 -13
- package/LICENSE +0 -13
- package/browser/nitrogen-min.js +0 -3
- package/browser/nitrogen.js +0 -6369
- package/lib/apiKey.js +0 -67
- package/lib/blob.js +0 -57
- package/lib/commandManager.js +0 -350
- package/lib/device.js +0 -19
- package/lib/memoryStore.js +0 -24
- package/lib/message.js +0 -298
- package/lib/permission.js +0 -121
- package/lib/principal.js +0 -330
- package/lib/service.js +0 -347
- package/lib/session.js +0 -494
- package/lib/user.js +0 -20
- package/publish +0 -2
- package/scripts/build-documentation +0 -4
- package/scripts/build-module +0 -27
- package/scripts/module.js +0 -12
- package/scripts/postamble.js +0 -1
- package/scripts/preamble.js +0 -2
- package/scripts/run-test-server +0 -9
- package/test/config.js +0 -12
- package/test/fixtures/images/image.jpg +0 -0
- package/test/fixtures/images/motion0.jpg +0 -0
- package/test/fixtures/images/motion1.jpg +0 -0
- package/test/fixtures/images/motion2.jpg +0 -0
- package/test/fixtures/index.js +0 -76
- package/test/main.js +0 -5
- package/test/memoryStore.js +0 -22
- package/test/mocha.opts +0 -3
- package/test/units/apiKey.js +0 -46
- package/test/units/blob.js +0 -35
- package/test/units/commandManager.js +0 -67
- package/test/units/device.js +0 -26
- package/test/units/heartbeat.js +0 -28
- package/test/units/message.js +0 -79
- package/test/units/permissions.js +0 -43
- package/test/units/principal.js +0 -116
- package/test/units/service.js +0 -92
- package/test/units/session.js +0 -97
- package/test/units/user.js +0 -48
- package/yuidoc.json +0 -8
package/lib/message.js
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Message object is the core of the Nitrogen framework. Applications, devices, and
|
|
3
|
-
* services use Messages to communicate with and issue commands to each other. All messages
|
|
4
|
-
* that don't begin with an unscore are checked against a schema chosen by the messages 'type'
|
|
5
|
-
* and 'schema_version' fields such that a message of a given type is known to conform to a
|
|
6
|
-
* particular structure. This enables sharing between differing devices and applications. For
|
|
7
|
-
* custom message types, an application may use an unscore prefix (eg. '_myMessage') with any
|
|
8
|
-
* schema that they'd like. This supports communication between principals of the same
|
|
9
|
-
* organization over a private schema. That said, it is strongly encouraged to use standard
|
|
10
|
-
* schemas wherever possible.
|
|
11
|
-
*
|
|
12
|
-
* Messages have a sender principal (referred to as 'from') and a receiver principal (referred
|
|
13
|
-
* to as 'to'). These fields are used to route messages to their receiver.
|
|
14
|
-
*
|
|
15
|
-
* Message types are divided into two main classes: data and commands. Data messages carry
|
|
16
|
-
* information, typically the output of a device's operation. For example, a message typed
|
|
17
|
-
* 'image' contains an image url in its body in its 'url' property.
|
|
18
|
-
*
|
|
19
|
-
* The second class of messages are commands. Command messages are sent from one principal to
|
|
20
|
-
* another to request an operation on the receiving principal. For example, a message of the
|
|
21
|
-
* type 'cameraCommand' contains a command that directs the operation of a camera principal.
|
|
22
|
-
*
|
|
23
|
-
* @class Message
|
|
24
|
-
* @namespace nitrogen
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
function Message(json) {
|
|
28
|
-
this.ts = new Date();
|
|
29
|
-
this.body = {};
|
|
30
|
-
|
|
31
|
-
for(var key in json) {
|
|
32
|
-
if(json.hasOwnProperty(key)) {
|
|
33
|
-
if (key === 'ts' || key === 'expires' || key === 'index_until')
|
|
34
|
-
this[key] = new Date(Date.parse(json[key]));
|
|
35
|
-
else
|
|
36
|
-
this[key] = json[key];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Find messages filtered by the passed query and limited to and sorted by the passed options.
|
|
43
|
-
*
|
|
44
|
-
* @method find
|
|
45
|
-
* @async
|
|
46
|
-
* @param {Object} session The session with a Nitrogen service to make this request under.
|
|
47
|
-
* @param {Object} query A query filter for the messages you want to find defined using MongoDB query format.
|
|
48
|
-
* @param {Object} options Options for the query: 'limit': maximum number of results to be returned. 'sort': The field that the results should be sorted on, 'dir': The direction that the results should be sorted. 'skip': The number of results that should be skipped before pulling results.
|
|
49
|
-
* @param {Function} callback Callback function of the form f(err, messages).
|
|
50
|
-
**/
|
|
51
|
-
|
|
52
|
-
Message.find = function(session, query, options, callback) {
|
|
53
|
-
if (!session) return callback('no session passed to Message.find');
|
|
54
|
-
if (!callback || typeof(callback) !== 'function') return callback('no callback passed to Message.find.');
|
|
55
|
-
if (!query) query = {};
|
|
56
|
-
if (!options) options = {};
|
|
57
|
-
|
|
58
|
-
var messageUrl = session.service.config.endpoints.messages;
|
|
59
|
-
session.get({
|
|
60
|
-
url: messageUrl,
|
|
61
|
-
query: query,
|
|
62
|
-
queryOptions: options,
|
|
63
|
-
json: true
|
|
64
|
-
}, function(err, resp, body) {
|
|
65
|
-
if (err) return callback(err);
|
|
66
|
-
|
|
67
|
-
var messages = body.messages.map(function(message) {
|
|
68
|
-
return new Message(message);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
callback(null, messages);
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Returns true if the message is of the passed type.
|
|
77
|
-
*
|
|
78
|
-
* @method is
|
|
79
|
-
* @param {String} type Message type to compare against.
|
|
80
|
-
* @returns {Boolean} Returns true if the message is of the passed type.
|
|
81
|
-
**/
|
|
82
|
-
|
|
83
|
-
Message.prototype.is = function(type) {
|
|
84
|
-
return this.type === type;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Returns true if the message is from the passed principal.
|
|
89
|
-
*
|
|
90
|
-
* @method isFrom
|
|
91
|
-
* @param {String} principalId Principal id to compare against.
|
|
92
|
-
* @returns {Boolean} Returns true if the message is from the passed principal id.
|
|
93
|
-
**/
|
|
94
|
-
|
|
95
|
-
Message.prototype.isFrom = function(principal) {
|
|
96
|
-
return this.from === principal.id;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Returns true if the message is in response to the passed message.
|
|
101
|
-
*
|
|
102
|
-
* @method isResponseTo
|
|
103
|
-
* @param {String} type Message to compare against.
|
|
104
|
-
* @returns {Boolean} Returns true if the message is in response to the passed message.
|
|
105
|
-
**/
|
|
106
|
-
|
|
107
|
-
Message.prototype.isResponseTo = function(otherMessage) {
|
|
108
|
-
return otherMessage.id && this.response_to && this.response_to.indexOf(otherMessage.id) !== -1;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Returns true if the message is of the passed type.
|
|
113
|
-
*
|
|
114
|
-
* @method isTo
|
|
115
|
-
* @param {String} principalId Principal id to compare against.
|
|
116
|
-
* @returns {Boolean} Returns true if the message is of the passed type.
|
|
117
|
-
**/
|
|
118
|
-
|
|
119
|
-
Message.prototype.isTo = function(principal) {
|
|
120
|
-
return this.to === principal.id;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Removes a set of messages specified by passed filter. Used by the internal service principal to
|
|
125
|
-
* to cleanup expired messages etc.
|
|
126
|
-
*
|
|
127
|
-
* @method remove
|
|
128
|
-
* @async
|
|
129
|
-
* @static
|
|
130
|
-
* @private
|
|
131
|
-
* @param {Object} session An open session with a Nitrogen service.
|
|
132
|
-
* @param {Object} query A query filter for the messages you want to remove.
|
|
133
|
-
* @param {Function} callback Callback function of the form f(err, removedCount).
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
Message.remove = function(session, query, callback) {
|
|
137
|
-
session.remove({
|
|
138
|
-
url: session.service.config.endpoints.messages,
|
|
139
|
-
query: query,
|
|
140
|
-
json: true
|
|
141
|
-
}, function(err, resp, body) {
|
|
142
|
-
if (err) return callback(err);
|
|
143
|
-
if (resp.statusCode != 200) return callback(resp.statusCode);
|
|
144
|
-
|
|
145
|
-
callback(null, body.removed);
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Remove this message. Used by the internal service principal for cleanup.
|
|
151
|
-
*
|
|
152
|
-
* @method remove
|
|
153
|
-
* @async
|
|
154
|
-
* @private
|
|
155
|
-
* @param {Object} session An open session with a Nitrogen service.
|
|
156
|
-
* @param {Function} callback Callback function of the form f(err, removedCount).
|
|
157
|
-
**/
|
|
158
|
-
|
|
159
|
-
Message.prototype.remove = function(session, callback) {
|
|
160
|
-
Message.remove(session, { "_id": this.id }, callback || function() {});
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Send this message.
|
|
165
|
-
*
|
|
166
|
-
* @method send
|
|
167
|
-
* @async
|
|
168
|
-
* @param {Object} session An open session with a Nitrogen service.
|
|
169
|
-
* @param {Function} callback Callback function of the form f(err, sentMessages).
|
|
170
|
-
**/
|
|
171
|
-
|
|
172
|
-
Message.prototype.send = function(session, callback) {
|
|
173
|
-
Message.sendMany(session, [this], callback || function() {});
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Send multiple messages.
|
|
178
|
-
*
|
|
179
|
-
* @method sendMany
|
|
180
|
-
* @async
|
|
181
|
-
* @param {Object} session An open session with a Nitrogen service.
|
|
182
|
-
* @param {Array} messages An array of messages to send.
|
|
183
|
-
* @param {Function} callback Callback function of the form f(err, sentMessages).
|
|
184
|
-
**/
|
|
185
|
-
|
|
186
|
-
Message.sendMany = function(session, messages, callback) {
|
|
187
|
-
if (!session) return callback('session required for Message.sendMany');
|
|
188
|
-
|
|
189
|
-
var self = this;
|
|
190
|
-
|
|
191
|
-
Message.queuedMessages.push({
|
|
192
|
-
session: session,
|
|
193
|
-
messages: messages,
|
|
194
|
-
callback: callback
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
Message.setupSendTimeout();
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
// TODO: there is an efficiency opportunity here to combine messages sent over the same session into one request.
|
|
201
|
-
//
|
|
202
|
-
// Challenges:
|
|
203
|
-
// - Would need to do accounting around callbacks to make sure they are all called with the right messages.
|
|
204
|
-
// - How do you handle the case where there is a 400 in one of the blocks but not in another.
|
|
205
|
-
|
|
206
|
-
Message.backoffMillis = 1;
|
|
207
|
-
|
|
208
|
-
Message.sendQueue = function() {
|
|
209
|
-
Message.sendTimeout = null;
|
|
210
|
-
|
|
211
|
-
var context = Message.queuedMessages[0];
|
|
212
|
-
Message.queuedMessages = Message.queuedMessages.slice(1);
|
|
213
|
-
|
|
214
|
-
context.session.post({ url: context.session.service.config.endpoints.messages, json: context.messages }, function(err, resp, body) {
|
|
215
|
-
if (resp && resp.statusCode !== 200) {
|
|
216
|
-
err = err || body.message || resp.statusCode;
|
|
217
|
-
|
|
218
|
-
// bad request responses are fatal, otherwise requeue and try again.
|
|
219
|
-
if (resp.statusCode !== 400)
|
|
220
|
-
Message.queuedMessages.unshift(context);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (err) {
|
|
224
|
-
Message.backoffMillis *= 4;
|
|
225
|
-
Message.backoffMillis = Math.min((64 + Math.random()) * 1000, Message.backoffMillis)
|
|
226
|
-
} else {
|
|
227
|
-
Message.backoffMillis = 1;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// if we still have messages in the queue after all of this, set up the next process.
|
|
231
|
-
if (Message.queuedMessages.length) {
|
|
232
|
-
Message.setupSendTimeout();
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (err) {
|
|
236
|
-
context.session.log.error('sending message failed with error: ' + JSON.stringify(err));
|
|
237
|
-
if (context.callback) context.callback(err);
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
var sentMessages = [];
|
|
242
|
-
body.messages.forEach(function(messageJson) {
|
|
243
|
-
sentMessages.push(new Message(messageJson));
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
if (context.callback) context.callback(null, sentMessages);
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
Message.setupSendTimeout = function() {
|
|
251
|
-
var self = this;
|
|
252
|
-
|
|
253
|
-
if (!Message.sendTimeout) {
|
|
254
|
-
Message.sendTimeout = setTimeout(function() { self.sendQueue(); }, Message.backoffMillis);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
Message.queuedMessages = [];
|
|
259
|
-
Message.sendTimeout = null;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Returns true if the message expired.
|
|
263
|
-
*
|
|
264
|
-
* @method expired
|
|
265
|
-
* @returns {Boolean} Returns true if the message is expired.
|
|
266
|
-
**/
|
|
267
|
-
|
|
268
|
-
Message.prototype.expired = function() {
|
|
269
|
-
return this.millisToExpiration() < 0;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Returns the number of milliseconds before this message expires.
|
|
274
|
-
*
|
|
275
|
-
* @method millisToExpiration
|
|
276
|
-
* @returns {Number} Number of milliseconds before this message expires.
|
|
277
|
-
**/
|
|
278
|
-
|
|
279
|
-
Message.prototype.millisToExpiration = function() {
|
|
280
|
-
return this.expires - new Date().getTime();
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Returns the number of milliseconds before the timestamp for this message. Used to calculate
|
|
285
|
-
* time to execution for command messages.
|
|
286
|
-
*
|
|
287
|
-
* @method millisToTimestamp
|
|
288
|
-
* @returns {Number} Number of milliseconds before the timestamp for this message.
|
|
289
|
-
**/
|
|
290
|
-
|
|
291
|
-
Message.prototype.millisToTimestamp = function() {
|
|
292
|
-
return this.ts - new Date().getTime();
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
Message.NEVER_EXPIRE = new Date(Date.UTC(2500, 0, 1));
|
|
296
|
-
Message.INDEX_FOREVER = new Date(Date.UTC(2500, 0, 1));
|
|
297
|
-
|
|
298
|
-
module.exports = Message;
|
package/lib/permission.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A permission in Nitrogen is a grant that has been made to principal(s) for a particular set of actions on another principal.
|
|
3
|
-
*
|
|
4
|
-
* A permission has the following properties:
|
|
5
|
-
* issued_to: The principal id that this permission is granted to. If missing, this permission applies to all principals.
|
|
6
|
-
* principal_for: The principal this permission is for. For instance, if you were granting subscription access for a lamp to a user,
|
|
7
|
-
* in this scenario the lamp would be the principal_for.
|
|
8
|
-
* action: The action that this permission is relevant for. Valid values include:
|
|
9
|
-
* 'admin': issued_to is authorized to perform administrative operations on principal_for.
|
|
10
|
-
* 'send': issued_to is authorized to send messages to principal_for.
|
|
11
|
-
* 'subscribe': issued_to is authorized to subscribe to messages from principal_for.
|
|
12
|
-
* 'view': issued_to is authorized to see principal_for in searches.
|
|
13
|
-
* authorized: Boolean declaring if matches to this permission authorizes or forbids it.
|
|
14
|
-
* priority: The priority this principal has in relation to other permissions. Permissions are walked in priority order and the first
|
|
15
|
-
* match is used to determine if the action is authorized.
|
|
16
|
-
* filter: An object that specifies additional filters that should be applied to a relevant object at authorization time. For example,
|
|
17
|
-
* { type: "ip" } would be used to limit matches with this permission to only messages with the type 'ip'.
|
|
18
|
-
* expires: An expiration date for this permission. After this expiration date, the permission will be disregarded and eventually removed
|
|
19
|
-
* from the system.
|
|
20
|
-
* @class Permission
|
|
21
|
-
* @namespace nitrogen
|
|
22
|
-
**/
|
|
23
|
-
|
|
24
|
-
function Permission(json) {
|
|
25
|
-
for(var key in json) {
|
|
26
|
-
if(json.hasOwnProperty(key)) {
|
|
27
|
-
this[key] = json[key];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a permission with the Nitrogen service.
|
|
34
|
-
*
|
|
35
|
-
* @method create
|
|
36
|
-
* @async
|
|
37
|
-
* @param {Object} session An open session with a Nitrogen service.
|
|
38
|
-
* @param {Function} callback Callback function of the form f(err, permission).
|
|
39
|
-
**/
|
|
40
|
-
|
|
41
|
-
Permission.prototype.create = function(session, callback) {
|
|
42
|
-
session.post({ url: session.service.config.endpoints.permissions, json: this }, function(err, resp, body) {
|
|
43
|
-
if (err) return callback(err);
|
|
44
|
-
if (resp.statusCode != 200) return callback(body);
|
|
45
|
-
|
|
46
|
-
if (callback) callback(null, new Permission(body.permission));
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Find permissions filtered by the passed query and limited to and sorted by the
|
|
52
|
-
* passed options.
|
|
53
|
-
*
|
|
54
|
-
* @method find
|
|
55
|
-
* @async
|
|
56
|
-
* @param {Object} session An open session with a Nitrogen service.
|
|
57
|
-
* @param {Object} query A query using MongoDB query format.
|
|
58
|
-
* @param {Object} options Options for the query: 'limit': maximum number of results to be returned. 'sort': The field that the results should be sorted on, 'dir': The direction that the results should be sorted. 'skip': The number of results that should be skipped before pulling results.
|
|
59
|
-
* @param {Function} callback Callback function of the form f(err, permissions).
|
|
60
|
-
**/
|
|
61
|
-
|
|
62
|
-
Permission.find = function(session, query, options, callback) {
|
|
63
|
-
if (!session) return callback(new Error("session required for find"));
|
|
64
|
-
if (!callback || typeof callback !== 'function') return callback(new Error('callback required for find.'));
|
|
65
|
-
|
|
66
|
-
session.get({
|
|
67
|
-
url: session.service.config.endpoints.permissions,
|
|
68
|
-
query: query,
|
|
69
|
-
queryOptions: options,
|
|
70
|
-
json: true
|
|
71
|
-
}, function(err, resp, body) {
|
|
72
|
-
if (err) return callback(err);
|
|
73
|
-
|
|
74
|
-
var permissions = body.permissions.map(function(permission) {
|
|
75
|
-
return new Permission(permission);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
callback(null, permissions);
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Delete this permission from the service.
|
|
84
|
-
*
|
|
85
|
-
* @method remove
|
|
86
|
-
* @async
|
|
87
|
-
* @param {Object} session An open session with a Nitrogen service.
|
|
88
|
-
* @param {Function} callback Callback function of the form f(err).
|
|
89
|
-
**/
|
|
90
|
-
|
|
91
|
-
Permission.prototype.remove = function(session, callback) {
|
|
92
|
-
var self = this;
|
|
93
|
-
|
|
94
|
-
session.remove({ url: session.service.config.endpoints.permissions + "/" + this.id }, function(err) {
|
|
95
|
-
return callback(err);
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Save this permission to the service.
|
|
101
|
-
*
|
|
102
|
-
* @method save
|
|
103
|
-
* @async
|
|
104
|
-
* @param {Object} session An open session with a Nitrogen service.
|
|
105
|
-
* @param {Function} callback Callback function of the form f(err, permission).
|
|
106
|
-
**/
|
|
107
|
-
|
|
108
|
-
Permission.prototype.save = function(session, callback) {
|
|
109
|
-
if (!this.id) return callback("Permission must have id to be saved.");
|
|
110
|
-
|
|
111
|
-
session.put({ url: session.service.config.endpoints.permissions + "/" + this.id, json: this }, function(err, resp, body) {
|
|
112
|
-
if (err) return callback(err);
|
|
113
|
-
if (resp.statusCode != 200) return callback(body, null);
|
|
114
|
-
|
|
115
|
-
if (callback) callback(null, new Permission(body.permission));
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
Permission.NORMAL_PRIORITY = 10000000;
|
|
120
|
-
|
|
121
|
-
module.exports = Permission;
|