@based/server 4.0.1 → 4.0.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.
- package/dist/auth/defaultConfig.d.ts +3 -0
- package/dist/auth/defaultConfig.js +12 -0
- package/dist/auth/defaultConfig.js.map +1 -0
- package/dist/auth/index.d.ts +12 -6
- package/dist/auth/index.js +32 -20
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/parseAuthState.d.ts +2 -1
- package/dist/auth/parseAuthState.js +28 -6
- package/dist/auth/parseAuthState.js.map +1 -1
- package/dist/authorize.d.ts +9 -0
- package/dist/authorize.js +59 -0
- package/dist/authorize.js.map +1 -0
- package/dist/compress.js +3 -0
- package/dist/compress.js.map +1 -1
- package/dist/createSimpleServer.d.ts +20 -10
- package/dist/createSimpleServer.js +64 -53
- package/dist/createSimpleServer.js.map +1 -1
- package/dist/error/errorTypeHandlers.js +31 -12
- package/dist/error/errorTypeHandlers.js.map +1 -1
- package/dist/error/index.d.ts +11 -1
- package/dist/error/index.js +9 -10
- package/dist/error/index.js.map +1 -1
- package/dist/error/types.d.ts +41 -45
- package/dist/error/types.js +3 -1
- package/dist/error/types.js.map +1 -1
- package/dist/functionApi/callFunction.d.ts +3 -0
- package/dist/functionApi/callFunction.js +29 -0
- package/dist/functionApi/callFunction.js.map +1 -0
- package/dist/functionApi/client/index.d.ts +16 -0
- package/dist/functionApi/client/index.js +44 -0
- package/dist/functionApi/client/index.js.map +1 -0
- package/dist/functionApi/client/query.d.ts +11 -0
- package/dist/functionApi/client/query.js +32 -0
- package/dist/functionApi/client/query.js.map +1 -0
- package/dist/functionApi/get.d.ts +3 -0
- package/dist/functionApi/get.js +71 -0
- package/dist/functionApi/get.js.map +1 -0
- package/dist/functionApi/index.d.ts +5 -0
- package/dist/functionApi/index.js +25 -0
- package/dist/functionApi/index.js.map +1 -0
- package/dist/functionApi/observe.d.ts +4 -0
- package/dist/functionApi/observe.js +44 -0
- package/dist/functionApi/observe.js.map +1 -0
- package/dist/functionApi/stream.d.ts +3 -0
- package/dist/functionApi/stream.js +30 -0
- package/dist/functionApi/stream.js.map +1 -0
- package/dist/functions/index.d.ts +16 -8
- package/dist/functions/index.js +39 -10
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/timeout.d.ts +3 -3
- package/dist/functions/timeout.js.map +1 -1
- package/dist/functions/types.d.ts +44 -30
- package/dist/functions/types.js +40 -12
- package/dist/functions/types.js.map +1 -1
- package/dist/incoming/http/authorize.d.ts +2 -2
- package/dist/incoming/http/authorize.js +4 -4
- package/dist/incoming/http/authorize.js.map +1 -1
- package/dist/incoming/http/function.d.ts +3 -4
- package/dist/incoming/http/function.js +30 -35
- package/dist/incoming/http/function.js.map +1 -1
- package/dist/incoming/http/get.d.ts +3 -3
- package/dist/incoming/http/get.js +23 -33
- package/dist/incoming/http/get.js.map +1 -1
- package/dist/incoming/http/index.js +49 -30
- package/dist/incoming/http/index.js.map +1 -1
- package/dist/incoming/http/parseQuery.d.ts +1 -1
- package/dist/incoming/http/parseQuery.js +3 -1
- package/dist/incoming/http/parseQuery.js.map +1 -1
- package/dist/incoming/http/readBody.d.ts +4 -3
- package/dist/incoming/http/readBody.js +32 -8
- package/dist/incoming/http/readBody.js.map +1 -1
- package/dist/incoming/http/streamFunction/DataStream.d.ts +8 -0
- package/dist/incoming/http/streamFunction/DataStream.js +42 -3
- package/dist/incoming/http/streamFunction/DataStream.js.map +1 -1
- package/dist/incoming/http/streamFunction/getExtension.d.ts +1 -1
- package/dist/incoming/http/streamFunction/index.d.ts +3 -3
- package/dist/incoming/http/streamFunction/index.js +6 -87
- package/dist/incoming/http/streamFunction/index.js.map +1 -1
- package/dist/incoming/http/streamFunction/multiPart/index.d.ts +4 -0
- package/dist/incoming/http/streamFunction/multiPart/index.js +66 -0
- package/dist/incoming/http/streamFunction/multiPart/index.js.map +1 -0
- package/dist/incoming/http/streamFunction/multiPart/readFormData.d.ts +12 -0
- package/dist/{network/http/streamFunction/multipartStream.js → incoming/http/streamFunction/multiPart/readFormData.js} +83 -89
- package/dist/incoming/http/streamFunction/multiPart/readFormData.js.map +1 -0
- package/dist/incoming/http/streamFunction/multipartStream.d.ts +3 -4
- package/dist/incoming/http/streamFunction/multipartStream.js +68 -66
- package/dist/incoming/http/streamFunction/multipartStream.js.map +1 -1
- package/dist/incoming/http/streamFunction/stream/createStream.d.ts +6 -0
- package/dist/incoming/http/streamFunction/stream/createStream.js +75 -0
- package/dist/incoming/http/streamFunction/stream/createStream.js.map +1 -0
- package/dist/incoming/http/streamFunction/stream/index.d.ts +4 -0
- package/dist/incoming/http/streamFunction/stream/index.js +70 -0
- package/dist/incoming/http/streamFunction/stream/index.js.map +1 -0
- package/dist/incoming/http/streamFunction/stream.d.ts +1 -1
- package/dist/incoming/index.d.ts +1 -1
- package/dist/incoming/index.js +13 -11
- package/dist/incoming/index.js.map +1 -1
- package/dist/incoming/upgrade.js +18 -9
- package/dist/incoming/upgrade.js.map +1 -1
- package/dist/incoming/ws/auth.d.ts +4 -4
- package/dist/incoming/ws/auth.js +37 -19
- package/dist/incoming/ws/auth.js.map +1 -1
- package/dist/incoming/ws/function.d.ts +2 -3
- package/dist/incoming/ws/function.js +21 -73
- package/dist/incoming/ws/function.js.map +1 -1
- package/dist/incoming/ws/get.d.ts +2 -3
- package/dist/incoming/ws/get.js +33 -54
- package/dist/incoming/ws/get.js.map +1 -1
- package/dist/incoming/ws/index.d.ts +1 -1
- package/dist/incoming/ws/index.js +2 -1
- package/dist/incoming/ws/index.js.map +1 -1
- package/dist/incoming/ws/observable.d.ts +7 -6
- package/dist/incoming/ws/observable.js +25 -49
- package/dist/incoming/ws/observable.js.map +1 -1
- package/dist/incoming/ws/types.d.ts +3 -0
- package/dist/{auth → incoming/ws}/types.js +0 -0
- package/dist/{auth → incoming/ws}/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/installFn.d.ts +4 -0
- package/dist/installFn.js +94 -0
- package/dist/installFn.js.map +1 -0
- package/dist/observable/create.d.ts +1 -1
- package/dist/observable/create.js +5 -1
- package/dist/observable/create.js.map +1 -1
- package/dist/observable/destroy.js +1 -1
- package/dist/observable/destroy.js.map +1 -1
- package/dist/observable/error.d.ts +1 -1
- package/dist/observable/index.d.ts +0 -1
- package/dist/observable/index.js +0 -1
- package/dist/observable/index.js.map +1 -1
- package/dist/observable/send.d.ts +3 -3
- package/dist/observable/send.js +2 -8
- package/dist/observable/send.js.map +1 -1
- package/dist/observable/start/error.d.ts +2 -1
- package/dist/observable/start/error.js +13 -11
- package/dist/observable/start/error.js.map +1 -1
- package/dist/observable/start/index.js +17 -8
- package/dist/observable/start/index.js.map +1 -1
- package/dist/observable/subscribe.d.ts +3 -3
- package/dist/observable/subscribe.js +6 -12
- package/dist/observable/subscribe.js.map +1 -1
- package/dist/observable/types.d.ts +6 -5
- package/dist/observable/unsub.d.ts +1 -1
- package/dist/observable/unsub.js.map +1 -1
- package/dist/observable/verify.d.ts +1 -1
- package/dist/observable/verify.js +1 -1
- package/dist/observable/verify.js.map +1 -1
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.js +11 -1
- package/dist/protocol.js.map +1 -1
- package/dist/security.d.ts +1 -1
- package/dist/security.js +1 -1
- package/dist/security.js.map +1 -1
- package/dist/sendError.d.ts +3 -2
- package/dist/sendError.js +30 -16
- package/dist/sendError.js.map +1 -1
- package/dist/sendHttpResponse.d.ts +1 -1
- package/dist/sendHttpResponse.js +29 -4
- package/dist/sendHttpResponse.js.map +1 -1
- package/dist/server.d.ts +10 -3
- package/dist/server.js +16 -4
- package/dist/server.js.map +1 -1
- package/dist/verifyRoute.d.ts +14 -0
- package/dist/verifyRoute.js +99 -0
- package/dist/verifyRoute.js.map +1 -0
- package/package.json +4 -2
- package/dist/BasedServerClient.d.ts +0 -71
- package/dist/BasedServerClient.js +0 -390
- package/dist/BasedServerClient.js.map +0 -1
- package/dist/Client.d.ts +0 -75
- package/dist/Client.js +0 -277
- package/dist/Client.js.map +0 -1
- package/dist/Params.d.ts +0 -20
- package/dist/Params.js +0 -48
- package/dist/Params.js.map +0 -1
- package/dist/api/index.d.ts +0 -7
- package/dist/api/index.js +0 -173
- package/dist/api/index.js.map +0 -1
- package/dist/auth/authorize.d.ts +0 -2
- package/dist/auth/authorize.js +0 -8
- package/dist/auth/authorize.js.map +0 -1
- package/dist/auth/dummyAuth.d.ts +0 -2
- package/dist/auth/dummyAuth.js +0 -8
- package/dist/auth/dummyAuth.js.map +0 -1
- package/dist/auth/types.d.ts +0 -10
- package/dist/clientContext.d.ts +0 -0
- package/dist/clientContext.js +0 -83
- package/dist/clientContext.js.map +0 -1
- package/dist/closeListener.d.ts +0 -4
- package/dist/closeListener.js +0 -13
- package/dist/closeListener.js.map +0 -1
- package/dist/context.d.ts +0 -54
- package/dist/context.js +0 -18
- package/dist/context.js.map +0 -1
- package/dist/error.d.ts +0 -66
- package/dist/error.js +0 -149
- package/dist/error.js.map +0 -1
- package/dist/findPrefix.d.ts +0 -3
- package/dist/findPrefix.js +0 -20
- package/dist/findPrefix.js.map +0 -1
- package/dist/functions/workerPool.d.ts +0 -0
- package/dist/functions/workerPool.js +0 -5
- package/dist/functions/workerPool.js.map +0 -1
- package/dist/getFromConfig.d.ts +0 -3
- package/dist/getFromConfig.js +0 -50
- package/dist/getFromConfig.js.map +0 -1
- package/dist/handlers/authorize.d.ts +0 -5
- package/dist/handlers/authorize.js +0 -196
- package/dist/handlers/authorize.js.map +0 -1
- package/dist/handlers/bulkUpdate/index.d.ts +0 -5
- package/dist/handlers/bulkUpdate/index.js +0 -26
- package/dist/handlers/bulkUpdate/index.js.map +0 -1
- package/dist/handlers/configuration/index.d.ts +0 -10
- package/dist/handlers/configuration/index.js +0 -74
- package/dist/handlers/configuration/index.js.map +0 -1
- package/dist/handlers/configuration/observable/index.d.ts +0 -46
- package/dist/handlers/configuration/observable/index.js +0 -277
- package/dist/handlers/configuration/observable/index.js.map +0 -1
- package/dist/handlers/configure/index.d.ts +0 -5
- package/dist/handlers/configure/index.js +0 -44
- package/dist/handlers/configure/index.js.map +0 -1
- package/dist/handlers/copy/index.d.ts +0 -8
- package/dist/handlers/copy/index.js +0 -135
- package/dist/handlers/copy/index.js.map +0 -1
- package/dist/handlers/delete/index.d.ts +0 -5
- package/dist/handlers/delete/index.js +0 -34
- package/dist/handlers/delete/index.js.map +0 -1
- package/dist/handlers/digest/index.d.ts +0 -5
- package/dist/handlers/digest/index.js +0 -23
- package/dist/handlers/digest/index.js.map +0 -1
- package/dist/handlers/functions/call.d.ts +0 -6
- package/dist/handlers/functions/call.js +0 -54
- package/dist/handlers/functions/call.js.map +0 -1
- package/dist/handlers/functions/observable/Observable.d.ts +0 -49
- package/dist/handlers/functions/observable/Observable.js +0 -290
- package/dist/handlers/functions/observable/Observable.js.map +0 -1
- package/dist/handlers/functions/observable/SharedObservable.d.ts +0 -45
- package/dist/handlers/functions/observable/SharedObservable.js +0 -291
- package/dist/handlers/functions/observable/SharedObservable.js.map +0 -1
- package/dist/handlers/functions/observable/index.d.ts +0 -14
- package/dist/handlers/functions/observable/index.js +0 -130
- package/dist/handlers/functions/observable/index.js.map +0 -1
- package/dist/handlers/get/index.d.ts +0 -5
- package/dist/handlers/get/index.js +0 -23
- package/dist/handlers/get/index.js.map +0 -1
- package/dist/handlers/getConfig/index.d.ts +0 -5
- package/dist/handlers/getConfig/index.js +0 -38
- package/dist/handlers/getConfig/index.js.map +0 -1
- package/dist/handlers/handleRequests.d.ts +0 -5
- package/dist/handlers/handleRequests.js +0 -78
- package/dist/handlers/handleRequests.js.map +0 -1
- package/dist/handlers/index.d.ts +0 -4
- package/dist/handlers/index.js +0 -49
- package/dist/handlers/index.js.map +0 -1
- package/dist/handlers/messageParser.d.ts +0 -5
- package/dist/handlers/messageParser.js +0 -122
- package/dist/handlers/messageParser.js.map +0 -1
- package/dist/handlers/removeField/index.d.ts +0 -5
- package/dist/handlers/removeField/index.js +0 -42
- package/dist/handlers/removeField/index.js.map +0 -1
- package/dist/handlers/removeType/index.d.ts +0 -5
- package/dist/handlers/removeType/index.js +0 -30
- package/dist/handlers/removeType/index.js.map +0 -1
- package/dist/handlers/rest/file/DataStream.d.ts +0 -7
- package/dist/handlers/rest/file/DataStream.js +0 -17
- package/dist/handlers/rest/file/DataStream.js.map +0 -1
- package/dist/handlers/rest/file/formStream.d.ts +0 -4
- package/dist/handlers/rest/file/formStream.js +0 -188
- package/dist/handlers/rest/file/formStream.js.map +0 -1
- package/dist/handlers/rest/file/getExtenstion.d.ts +0 -2
- package/dist/handlers/rest/file/getExtenstion.js +0 -22
- package/dist/handlers/rest/file/getExtenstion.js.map +0 -1
- package/dist/handlers/rest/file/index.d.ts +0 -4
- package/dist/handlers/rest/file/index.js +0 -53
- package/dist/handlers/rest/file/index.js.map +0 -1
- package/dist/handlers/rest/file/storeFile.d.ts +0 -6
- package/dist/handlers/rest/file/storeFile.js +0 -44
- package/dist/handlers/rest/file/storeFile.js.map +0 -1
- package/dist/handlers/rest/file/stream.d.ts +0 -5
- package/dist/handlers/rest/file/stream.js +0 -104
- package/dist/handlers/rest/file/stream.js.map +0 -1
- package/dist/handlers/rest/file/types.d.ts +0 -9
- package/dist/handlers/rest/file/types.js +0 -3
- package/dist/handlers/rest/file/types.js.map +0 -1
- package/dist/handlers/rest/getReqMessage.d.ts +0 -3
- package/dist/handlers/rest/getReqMessage.js +0 -92
- package/dist/handlers/rest/getReqMessage.js.map +0 -1
- package/dist/handlers/rest/index.d.ts +0 -4
- package/dist/handlers/rest/index.js +0 -121
- package/dist/handlers/rest/index.js.map +0 -1
- package/dist/handlers/rest/invalidReq.d.ts +0 -4
- package/dist/handlers/rest/invalidReq.js +0 -20
- package/dist/handlers/rest/invalidReq.js.map +0 -1
- package/dist/handlers/rest/parseResponse.d.ts +0 -6
- package/dist/handlers/rest/parseResponse.js +0 -230
- package/dist/handlers/rest/parseResponse.js.map +0 -1
- package/dist/handlers/rest/playground/index.d.ts +0 -5
- package/dist/handlers/rest/playground/index.js +0 -308
- package/dist/handlers/rest/playground/index.js.map +0 -1
- package/dist/handlers/rest/readBody.d.ts +0 -3
- package/dist/handlers/rest/readBody.js +0 -45
- package/dist/handlers/rest/readBody.js.map +0 -1
- package/dist/handlers/set/index.d.ts +0 -5
- package/dist/handlers/set/index.js +0 -20
- package/dist/handlers/set/index.js.map +0 -1
- package/dist/handlers/subscription/index.d.ts +0 -32
- package/dist/handlers/subscription/index.js +0 -223
- package/dist/handlers/subscription/index.js.map +0 -1
- package/dist/handlers/token.d.ts +0 -5
- package/dist/handlers/token.js +0 -122
- package/dist/handlers/token.js.map +0 -1
- package/dist/handlers/track/index.d.ts +0 -7
- package/dist/handlers/track/index.js +0 -102
- package/dist/handlers/track/index.js.map +0 -1
- package/dist/handlers/userAuth/index.d.ts +0 -5
- package/dist/handlers/userAuth/index.js +0 -78
- package/dist/handlers/userAuth/index.js.map +0 -1
- package/dist/network/http/authorize.d.ts +0 -3
- package/dist/network/http/authorize.js +0 -28
- package/dist/network/http/authorize.js.map +0 -1
- package/dist/network/http/compress.d.ts +0 -6
- package/dist/network/http/compress.js +0 -56
- package/dist/network/http/compress.js.map +0 -1
- package/dist/network/http/end.d.ts +0 -4
- package/dist/network/http/end.js +0 -19
- package/dist/network/http/end.js.map +0 -1
- package/dist/network/http/function.d.ts +0 -3
- package/dist/network/http/function.js +0 -47
- package/dist/network/http/function.js.map +0 -1
- package/dist/network/http/get.d.ts +0 -3
- package/dist/network/http/get.js +0 -129
- package/dist/network/http/get.js.map +0 -1
- package/dist/network/http/index.d.ts +0 -3
- package/dist/network/http/index.js +0 -122
- package/dist/network/http/index.js.map +0 -1
- package/dist/network/http/readBody.d.ts +0 -3
- package/dist/network/http/readBody.js +0 -112
- package/dist/network/http/readBody.js.map +0 -1
- package/dist/network/http/send.d.ts +0 -5
- package/dist/network/http/send.js +0 -60
- package/dist/network/http/send.js.map +0 -1
- package/dist/network/http/streamFunction/DataStream.d.ts +0 -7
- package/dist/network/http/streamFunction/DataStream.js +0 -19
- package/dist/network/http/streamFunction/DataStream.js.map +0 -1
- package/dist/network/http/streamFunction/getExtension.d.ts +0 -2
- package/dist/network/http/streamFunction/getExtension.js +0 -29
- package/dist/network/http/streamFunction/getExtension.js.map +0 -1
- package/dist/network/http/streamFunction/index.d.ts +0 -3
- package/dist/network/http/streamFunction/index.js +0 -81
- package/dist/network/http/streamFunction/index.js.map +0 -1
- package/dist/network/http/streamFunction/multipartStream.d.ts +0 -12
- package/dist/network/http/streamFunction/multipartStream.js.map +0 -1
- package/dist/network/http/streamFunction/stream.d.ts +0 -5
- package/dist/network/http/streamFunction/stream.js +0 -103
- package/dist/network/http/streamFunction/stream.js.map +0 -1
- package/dist/network/index.d.ts +0 -4
- package/dist/network/index.js +0 -84
- package/dist/network/index.js.map +0 -1
- package/dist/network/message/auth.d.ts +0 -4
- package/dist/network/message/auth.js +0 -32
- package/dist/network/message/auth.js.map +0 -1
- package/dist/network/message/function.d.ts +0 -3
- package/dist/network/message/function.js +0 -67
- package/dist/network/message/function.js.map +0 -1
- package/dist/network/message/get.d.ts +0 -3
- package/dist/network/message/get.js +0 -109
- package/dist/network/message/get.js.map +0 -1
- package/dist/network/message/index.d.ts +0 -3
- package/dist/network/message/index.js +0 -62
- package/dist/network/message/index.js.map +0 -1
- package/dist/network/message/observable.d.ts +0 -5
- package/dist/network/message/observable.js +0 -103
- package/dist/network/message/observable.js.map +0 -1
- package/dist/network/message/send.d.ts +0 -4
- package/dist/network/message/send.js +0 -11
- package/dist/network/message/send.js.map +0 -1
- package/dist/network/upgrade.d.ts +0 -4
- package/dist/network/upgrade.js +0 -49
- package/dist/network/upgrade.js.map +0 -1
- package/dist/network/worker/get.d.ts +0 -0
- package/dist/network/worker/get.js +0 -122
- package/dist/network/worker/get.js.map +0 -1
- package/dist/network/worker/observable.d.ts +0 -0
- package/dist/network/worker/observable.js +0 -120
- package/dist/network/worker/observable.js.map +0 -1
- package/dist/openListener.d.ts +0 -4
- package/dist/openListener.js +0 -13
- package/dist/openListener.js.map +0 -1
- package/dist/secrets.d.ts +0 -9
- package/dist/secrets.js +0 -150
- package/dist/secrets.js.map +0 -1
- package/dist/security/index.d.ts +0 -3
- package/dist/security/index.js +0 -66
- package/dist/security/index.js.map +0 -1
- package/dist/types.d.ts +0 -129
- package/dist/types.js +0 -17
- package/dist/types.js.map +0 -1
- package/dist/upgradeListener.d.ts +0 -4
- package/dist/upgradeListener.js +0 -47
- package/dist/upgradeListener.js.map +0 -1
- package/dist/worker/authorize.d.ts +0 -5
- package/dist/worker/authorize.js +0 -15
- package/dist/worker/authorize.js.map +0 -1
- package/dist/worker/fnMap.d.ts +0 -2
- package/dist/worker/fnMap.js +0 -5
- package/dist/worker/fnMap.js.map +0 -1
- package/dist/worker/functions.d.ts +0 -3
- package/dist/worker/functions.js +0 -8
- package/dist/worker/functions.js.map +0 -1
- package/dist/worker/http/function.d.ts +0 -4
- package/dist/worker/http/function.js +0 -75
- package/dist/worker/http/function.js.map +0 -1
- package/dist/worker/index.d.ts +0 -1
- package/dist/worker/index.js +0 -101
- package/dist/worker/index.js.map +0 -1
- package/dist/worker/observable.d.ts +0 -15
- package/dist/worker/observable.js +0 -110
- package/dist/worker/observable.js.map +0 -1
- package/dist/worker/ws/function.d.ts +0 -3
- package/dist/worker/ws/function.js +0 -42
- package/dist/worker/ws/function.js.map +0 -1
- package/dist/workers/index.d.ts +0 -0
- package/dist/workers/index.js +0 -20
- package/dist/workers/index.js.map +0 -1
- package/dist/workers/workerCode.d.ts +0 -12
- package/dist/workers/workerCode.js +0 -46
- package/dist/workers/workerCode.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultVerifyAuthState = exports.defaultAuthorize = void 0;
|
|
4
|
+
const defaultAuthorize = async () => {
|
|
5
|
+
return true;
|
|
6
|
+
};
|
|
7
|
+
exports.defaultAuthorize = defaultAuthorize;
|
|
8
|
+
const defaultVerifyAuthState = () => {
|
|
9
|
+
return true;
|
|
10
|
+
};
|
|
11
|
+
exports.defaultVerifyAuthState = defaultVerifyAuthState;
|
|
12
|
+
//# sourceMappingURL=defaultConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../../src/auth/defaultConfig.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAc,KAAK,IAAI,EAAE;IACpD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B;AAEM,MAAM,sBAAsB,GAAoB,GAAG,EAAE;IAC1D,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAFY,QAAA,sBAAsB,0BAElC"}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { AuthState } from '../incoming/ws/auth';
|
|
2
1
|
import { BasedServer } from '../server';
|
|
3
|
-
import {
|
|
4
|
-
import { Context, WebSocketSession } from '../context';
|
|
2
|
+
import { Context, AuthState, WebSocketSession, Authorize, AuthorizeConnection, VerifyAuthState } from '@based/functions';
|
|
5
3
|
import parseAuthState from './parseAuthState';
|
|
6
4
|
export { parseAuthState };
|
|
7
|
-
export
|
|
5
|
+
export declare type AuthConfig = {
|
|
6
|
+
authorize?: Authorize;
|
|
7
|
+
authorizeConnection?: AuthorizeConnection;
|
|
8
|
+
verifyAuthState?: VerifyAuthState;
|
|
9
|
+
};
|
|
8
10
|
export declare class BasedAuth {
|
|
9
11
|
server: BasedServer;
|
|
10
|
-
authorize: Authorize;
|
|
11
12
|
authorizeConnection: AuthorizeConnection;
|
|
13
|
+
verifyAuthState: VerifyAuthState;
|
|
14
|
+
authorize: Authorize;
|
|
12
15
|
constructor(server: BasedServer, config?: AuthConfig);
|
|
13
16
|
updateConfig(config: AuthConfig): void;
|
|
14
|
-
|
|
17
|
+
renewAuthState(ctx: Context, authState?: AuthState): void;
|
|
18
|
+
encodeAuthState(authState: AuthState): string;
|
|
19
|
+
decodeAuthState(authState: any): AuthState;
|
|
20
|
+
sendAuthState(ctx: Context<WebSocketSession>, authState: AuthState): void;
|
|
15
21
|
}
|
package/dist/auth/index.js
CHANGED
|
@@ -1,32 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
4
|
};
|
|
19
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
6
|
exports.BasedAuth = exports.parseAuthState = void 0;
|
|
21
7
|
const protocol_1 = require("../protocol");
|
|
22
|
-
const
|
|
8
|
+
const functions_1 = require("@based/functions");
|
|
9
|
+
const defaultConfig_1 = require("./defaultConfig");
|
|
23
10
|
const parseAuthState_1 = __importDefault(require("./parseAuthState"));
|
|
24
11
|
exports.parseAuthState = parseAuthState_1.default;
|
|
25
|
-
__exportStar(require("./types"), exports);
|
|
26
12
|
class BasedAuth {
|
|
27
|
-
constructor(server, config = {
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
constructor(server, config = {}) {
|
|
14
|
+
this.verifyAuthState = defaultConfig_1.defaultVerifyAuthState;
|
|
15
|
+
this.authorize = defaultConfig_1.defaultAuthorize;
|
|
30
16
|
this.server = server;
|
|
31
17
|
this.updateConfig(config);
|
|
32
18
|
}
|
|
@@ -40,8 +26,34 @@ class BasedAuth {
|
|
|
40
26
|
if (config.authorize) {
|
|
41
27
|
this.authorize = config.authorize;
|
|
42
28
|
}
|
|
29
|
+
if (config.verifyAuthState) {
|
|
30
|
+
this.verifyAuthState = config.verifyAuthState;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
renewAuthState(ctx, authState) {
|
|
34
|
+
if (!ctx.session) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!('authState' in ctx.session)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const verified = authState ||
|
|
41
|
+
this.server.auth.verifyAuthState(this.server.client, ctx, ctx.session.authState);
|
|
42
|
+
if (verified === true) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
ctx.session.authState = verified;
|
|
46
|
+
if ((0, functions_1.isWsContext)(ctx)) {
|
|
47
|
+
this.sendAuthState(ctx, verified);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
encodeAuthState(authState) {
|
|
51
|
+
return Buffer.from(JSON.stringify(authState), 'utf8').toString('base64');
|
|
52
|
+
}
|
|
53
|
+
decodeAuthState(authState) {
|
|
54
|
+
return (0, parseAuthState_1.default)(authState);
|
|
43
55
|
}
|
|
44
|
-
|
|
56
|
+
sendAuthState(ctx, authState) {
|
|
45
57
|
ctx.session?.send((0, protocol_1.encodeAuthResponse)((0, protocol_1.valueToBuffer)(authState)), true, false);
|
|
46
58
|
}
|
|
47
59
|
}
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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IAAA,uBAAW,EAAC,GAAG,CAAC,EAAE;YACpB,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;SAClC;IACH,CAAC;IAED,eAAe,CAAC,SAAoB;QAClC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC1E,CAAC;IAED,eAAe,CAAC,SAAc;QAC5B,OAAO,IAAA,wBAAc,EAAC,SAAS,CAAC,CAAA;IAClC,CAAC;IAED,aAAa,CAAC,GAA8B,EAAE,SAAoB;QAChE,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,IAAA,6BAAkB,EAAC,IAAA,wBAAa,EAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;IAC9E,CAAC;CACF;AA/DD,8BA+DC"}
|
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@saulx/utils");
|
|
4
|
+
const { decode } = (0, utils_1.createEncoder)([
|
|
5
|
+
'(',
|
|
6
|
+
')',
|
|
7
|
+
'<',
|
|
8
|
+
'>',
|
|
9
|
+
'@',
|
|
10
|
+
',',
|
|
11
|
+
';',
|
|
12
|
+
':',
|
|
13
|
+
'\\',
|
|
14
|
+
'"',
|
|
15
|
+
'/',
|
|
16
|
+
'[',
|
|
17
|
+
']',
|
|
18
|
+
'?',
|
|
19
|
+
'=',
|
|
20
|
+
'{',
|
|
21
|
+
'}',
|
|
22
|
+
' ',
|
|
23
|
+
], ['0']);
|
|
3
24
|
exports.default = (authState) => {
|
|
4
|
-
if (
|
|
5
|
-
return;
|
|
25
|
+
if (authState === undefined) {
|
|
26
|
+
return {};
|
|
6
27
|
}
|
|
7
28
|
if (typeof authState !== 'string') {
|
|
8
|
-
return
|
|
29
|
+
return { error: 'Invalid token' };
|
|
9
30
|
}
|
|
10
31
|
try {
|
|
11
|
-
return JSON.parse(authState);
|
|
32
|
+
return JSON.parse(Buffer.from(decode(decodeURI(authState)), 'base64').toString('utf8'));
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
return { error: 'Invalid token' };
|
|
12
36
|
}
|
|
13
|
-
catch (err) { }
|
|
14
|
-
return authState;
|
|
15
37
|
};
|
|
16
38
|
//# sourceMappingURL=parseAuthState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseAuthState.js","sourceRoot":"","sources":["../../src/auth/parseAuthState.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"parseAuthState.js","sourceRoot":"","sources":["../../src/auth/parseAuthState.ts"],"names":[],"mappings":";;AACA,wCAA4C;AAE5C,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,qBAAa,EAC9B;IACE,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,IAAI;IACJ,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;CACJ,EACD,CAAC,GAAG,CAAC,CACN,CAAA;AAED,kBAAe,CAAC,SAAc,EAAa,EAAE;IAC3C,IAAI,SAAS,KAAK,SAAS,EAAE;QAC3B,OAAO,EAAE,CAAA;KACV;IACD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAA;KAClC;IACD,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CACf,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CACrE,CAAA;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,CAAA;KAClC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BasedServer } from './server';
|
|
2
|
+
import { BasedRoute } from './functions';
|
|
3
|
+
import { HttpSession, Context, WebSocketSession } from '@based/functions';
|
|
4
|
+
declare type ClientSession = HttpSession | WebSocketSession;
|
|
5
|
+
export declare type IsAuthorizedHandler<S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any> = (route: R, server: BasedServer, ctx: Context<S>, payload: P, id?: number, checksum?: number) => void;
|
|
6
|
+
export declare type AuthErrorHandler<S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any> = (route: R, server: BasedServer, ctx: Context<S>, payload: P, id?: number, checksum?: number, err?: Error) => true | void;
|
|
7
|
+
export declare const defaultAuthError: AuthErrorHandler;
|
|
8
|
+
export declare const authorize: <S extends ClientSession = ClientSession, R extends BasedRoute = BasedRoute, P = any>(route: R, server: BasedServer, ctx: Context<S>, payload: P, isAuthorized: IsAuthorizedHandler<S, R, P>, id?: number, checksum?: number, authError?: AuthErrorHandler<S, R, P>) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authorize = exports.defaultAuthError = void 0;
|
|
4
|
+
const functions_1 = require("./functions");
|
|
5
|
+
const sendError_1 = require("./sendError");
|
|
6
|
+
const error_1 = require("./error");
|
|
7
|
+
const defaultAuthError = (route, server, ctx, payload, id, checksum, err) => {
|
|
8
|
+
const code = err
|
|
9
|
+
? error_1.BasedErrorCode.AuthorizeFunctionError
|
|
10
|
+
: error_1.BasedErrorCode.AuthorizeRejectedError;
|
|
11
|
+
if (id && (0, functions_1.isQueryFunctionRoute)(route)) {
|
|
12
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
13
|
+
route,
|
|
14
|
+
err,
|
|
15
|
+
observableId: id,
|
|
16
|
+
});
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (id) {
|
|
20
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
21
|
+
route,
|
|
22
|
+
err,
|
|
23
|
+
requestId: id,
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
(0, sendError_1.sendError)(server, ctx, code, {
|
|
28
|
+
route,
|
|
29
|
+
err,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.defaultAuthError = defaultAuthError;
|
|
33
|
+
const authorize = (route, server, ctx, payload, isAuthorized, id, checksum, authError = exports.defaultAuthError) => {
|
|
34
|
+
if (!ctx.session) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (route.public === true) {
|
|
38
|
+
isAuthorized(route, server, ctx, payload, id, checksum);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
server.auth
|
|
42
|
+
.authorize(server.client, ctx, route.name, payload)
|
|
43
|
+
.then((ok) => {
|
|
44
|
+
if (!ctx.session || !ok) {
|
|
45
|
+
if (!authError(route, server, ctx, payload, id, checksum)) {
|
|
46
|
+
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum);
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
isAuthorized(route, server, ctx, payload, id, checksum);
|
|
51
|
+
})
|
|
52
|
+
.catch((err) => {
|
|
53
|
+
if (!authError(route, server, ctx, payload, id, checksum, err)) {
|
|
54
|
+
(0, exports.defaultAuthError)(route, server, ctx, payload, id, checksum, err);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.authorize = authorize;
|
|
59
|
+
//# sourceMappingURL=authorize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":";;;AACA,2CAA8D;AAC9D,2CAAuC;AACvC,mCAAwC;AAgCjC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CAAC,CAAC,EAAE,EAAE,EAAE;QACX,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,EAAE,EAAE;YACvB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE;gBACzD,IAAA,wBAAgB,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;aAC5D;YACD,OAAM;SACP;QACD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;IACzD,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE;YAC9D,IAAA,wBAAgB,EAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;SACjE;IACH,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AAvCY,QAAA,SAAS,aAuCrB"}
|
package/dist/compress.js
CHANGED
|
@@ -21,6 +21,9 @@ const compress = async (payload, encoding) => {
|
|
|
21
21
|
if (payload instanceof Buffer && payload.byteLength <= protocol_1.COMPRESS_FROM_BYTES) {
|
|
22
22
|
return { payload };
|
|
23
23
|
}
|
|
24
|
+
if (payload === undefined) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
24
27
|
if (payload.length < COMPRESS_STRING_LEN) {
|
|
25
28
|
return { payload };
|
|
26
29
|
}
|
package/dist/compress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AA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CAAC,OAAO,CAAC,CAAA;SAC/B;QACD,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YAChC,gBAAgB,GAAG,SAAS,CAAA;YAC5B,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;SACpC;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACpC,gBAAgB,GAAG,MAAM,CAAA;YACzB,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAA;SACjC;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAClC,gBAAgB,GAAG,IAAI,CAAA;YACvB,UAAU,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,CAAA;SAC/B;QACD,IAAI,UAAU,EAAE;YACd,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA;SAC3D;KACF;IACD,OAAO,EAAE,OAAO,EAAE,CAAA;AACpB,CAAC,CAAA;AArCY,QAAA,QAAQ,YAqCpB"}
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import { AuthConfig } from './auth';
|
|
2
|
-
import {
|
|
2
|
+
import { BasedFunctionSpec, BasedQueryFunctionSpec, BasedStreamFunctionSpec, BasedSpec } from './functions';
|
|
3
|
+
import { BasedQueryFunction, BasedFunction, Context, Session } from '@based/functions';
|
|
3
4
|
import { BasedServer } from './server';
|
|
4
5
|
export declare type SimpleServerOptions = {
|
|
5
6
|
port?: number;
|
|
6
7
|
key?: string;
|
|
8
|
+
disableRest?: boolean;
|
|
7
9
|
cert?: string;
|
|
8
10
|
auth?: AuthConfig;
|
|
11
|
+
ws?: {
|
|
12
|
+
open: (client: Context<Session>) => void;
|
|
13
|
+
close: (client: Context<Session>) => void;
|
|
14
|
+
};
|
|
15
|
+
install?: (opts: {
|
|
16
|
+
server: BasedServer;
|
|
17
|
+
name: string;
|
|
18
|
+
function?: BasedSpec;
|
|
19
|
+
}) => Promise<null | BasedSpec>;
|
|
20
|
+
uninstall?: (opts: {
|
|
21
|
+
server: BasedServer;
|
|
22
|
+
name: string;
|
|
23
|
+
function: BasedSpec;
|
|
24
|
+
}) => Promise<boolean>;
|
|
9
25
|
functions?: {
|
|
10
|
-
[key: string]: BasedFunction |
|
|
11
|
-
function: BasedFunction;
|
|
12
|
-
});
|
|
26
|
+
[key: string]: BasedFunction | Partial<BasedFunctionSpec | BasedStreamFunctionSpec>;
|
|
13
27
|
};
|
|
14
|
-
|
|
15
|
-
[key: string]:
|
|
16
|
-
function: BasedObservableFunction;
|
|
17
|
-
});
|
|
28
|
+
queryFunctions?: {
|
|
29
|
+
[key: string]: BasedQueryFunction | Partial<BasedQueryFunctionSpec>;
|
|
18
30
|
};
|
|
19
31
|
};
|
|
20
32
|
export declare function createSimpleServer(props: SimpleServerOptions, sharedSocket?: boolean): Promise<BasedServer>;
|
|
21
|
-
export declare function isFunctionSpec(fn: BasedFunction | Partial<BasedFunctionSpec>): fn is Partial<BasedFunctionSpec>;
|
|
22
|
-
export declare function isObsFunctionSpec(fn: BasedObservableFunction | Partial<BasedObservableFunctionSpec>): fn is Partial<BasedObservableFunctionSpec>;
|
|
@@ -1,84 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
6
|
+
exports.createSimpleServer = void 0;
|
|
7
|
+
const functions_1 = require("./functions");
|
|
8
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
4
9
|
const server_1 = require("./server");
|
|
10
|
+
const utils_1 = require("@saulx/utils");
|
|
5
11
|
async function createSimpleServer(props, sharedSocket) {
|
|
6
|
-
const { functions,
|
|
12
|
+
const { functions, queryFunctions } = props;
|
|
7
13
|
const functionStore = {};
|
|
8
14
|
for (const name in functions) {
|
|
9
15
|
if (functions[name]) {
|
|
10
16
|
const fn = functions[name];
|
|
11
|
-
if (
|
|
17
|
+
if ((0, functions_1.isSpec)(fn)) {
|
|
12
18
|
functionStore[name] = {
|
|
13
19
|
function: fn.function,
|
|
14
|
-
path: `/${name}`,
|
|
15
20
|
name,
|
|
16
|
-
observable: false,
|
|
17
21
|
checksum: 1,
|
|
18
|
-
maxPayloadSize:
|
|
19
|
-
rateLimitTokens:
|
|
22
|
+
maxPayloadSize: (0, functions_1.isStreamFunctionSpec)(fn) ? 200e6 : 5e4,
|
|
23
|
+
rateLimitTokens: 10,
|
|
20
24
|
...fn,
|
|
21
25
|
};
|
|
22
26
|
}
|
|
23
|
-
else {
|
|
27
|
+
else if (typeof fn === 'function') {
|
|
24
28
|
functionStore[name] = {
|
|
25
29
|
function: fn,
|
|
26
|
-
path: `/${name}`,
|
|
27
30
|
name,
|
|
28
|
-
observable: false,
|
|
29
31
|
checksum: 1,
|
|
30
|
-
maxPayloadSize:
|
|
32
|
+
maxPayloadSize: 5e4,
|
|
31
33
|
rateLimitTokens: 1,
|
|
32
34
|
};
|
|
33
35
|
}
|
|
36
|
+
else {
|
|
37
|
+
console.error(name, fn, 'Is not a function!');
|
|
38
|
+
}
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
|
-
for (const name in
|
|
37
|
-
if (
|
|
38
|
-
const fn =
|
|
39
|
-
if (
|
|
41
|
+
for (const name in queryFunctions) {
|
|
42
|
+
if (queryFunctions[name]) {
|
|
43
|
+
const fn = queryFunctions[name];
|
|
44
|
+
if ((0, functions_1.isSpec)(fn)) {
|
|
40
45
|
functionStore[name] = {
|
|
41
46
|
checksum: 1,
|
|
42
|
-
|
|
47
|
+
query: true,
|
|
43
48
|
function: fn.function,
|
|
44
|
-
path: `/${name}`,
|
|
45
49
|
name,
|
|
46
|
-
maxPayloadSize:
|
|
47
|
-
rateLimitTokens:
|
|
50
|
+
maxPayloadSize: 5000,
|
|
51
|
+
rateLimitTokens: 1,
|
|
48
52
|
...fn,
|
|
49
53
|
};
|
|
50
54
|
}
|
|
51
|
-
else {
|
|
55
|
+
else if (typeof fn === 'function') {
|
|
52
56
|
functionStore[name] = {
|
|
53
57
|
checksum: 1,
|
|
54
|
-
|
|
58
|
+
query: true,
|
|
55
59
|
function: fn,
|
|
56
60
|
name,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
rateLimitTokens: 5,
|
|
61
|
+
maxPayloadSize: 5000,
|
|
62
|
+
rateLimitTokens: 1,
|
|
60
63
|
};
|
|
61
64
|
}
|
|
65
|
+
else {
|
|
66
|
+
console.error(name, fn, 'Is not a query function!');
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
const properProps = {
|
|
65
71
|
port: props.port,
|
|
66
72
|
auth: props.auth,
|
|
67
73
|
cert: props.cert,
|
|
74
|
+
ws: props.ws,
|
|
75
|
+
disableRest: props.disableRest,
|
|
76
|
+
key: props.key,
|
|
68
77
|
functions: {
|
|
69
78
|
memCacheTimeout: 3e3,
|
|
70
79
|
idleTimeout: 1e3,
|
|
71
|
-
uninstall:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
uninstall: props.uninstall ||
|
|
81
|
+
(async () => {
|
|
82
|
+
return true;
|
|
83
|
+
}),
|
|
84
|
+
install: props.install ||
|
|
85
|
+
(async ({ name }) => {
|
|
86
|
+
if (functionStore[name]) {
|
|
87
|
+
return functionStore[name];
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
82
93
|
route: ({ path, name }) => {
|
|
83
94
|
if (path) {
|
|
84
95
|
for (const name in functionStore) {
|
|
@@ -86,35 +97,35 @@ async function createSimpleServer(props, sharedSocket) {
|
|
|
86
97
|
return functionStore[name];
|
|
87
98
|
}
|
|
88
99
|
}
|
|
100
|
+
if (!name && functionStore[path]) {
|
|
101
|
+
return functionStore[path];
|
|
102
|
+
}
|
|
89
103
|
}
|
|
90
104
|
if (functionStore[name]) {
|
|
91
105
|
return functionStore[name];
|
|
92
106
|
}
|
|
93
|
-
return
|
|
107
|
+
return null;
|
|
94
108
|
},
|
|
95
109
|
},
|
|
96
110
|
};
|
|
97
|
-
console.info('
|
|
111
|
+
console.info(' ', picocolors_1.default.white('Based-server'), `starting with functions`);
|
|
112
|
+
let longestName = 0;
|
|
98
113
|
for (const name in functionStore) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
if (name.length > longestName) {
|
|
115
|
+
longestName = name.length;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
for (const name in functionStore) {
|
|
119
|
+
const obs = (0, functions_1.isQueryFunctionSpec)(functionStore[name])
|
|
120
|
+
? '[query]'
|
|
121
|
+
: (0, functions_1.isStreamFunctionSpec)(functionStore[name])
|
|
122
|
+
? '[stream]'
|
|
123
|
+
: '';
|
|
124
|
+
const pub = functionStore[name].public ? 'public' : 'private';
|
|
125
|
+
console.info(' ', picocolors_1.default.white(name), (0, utils_1.padLeft)('', longestName + 2 - name.length, ' '), picocolors_1.default.gray(pub), (0, utils_1.padLeft)('', 8 - pub.length, ' '), picocolors_1.default.green(obs), (0, utils_1.padLeft)('', 14 - obs.length, ' '), functionStore[name].path || '');
|
|
104
126
|
}
|
|
105
127
|
const basedServer = new server_1.BasedServer(properProps);
|
|
106
128
|
return props.port ? basedServer.start(props.port, sharedSocket) : basedServer;
|
|
107
129
|
}
|
|
108
130
|
exports.createSimpleServer = createSimpleServer;
|
|
109
|
-
// function simpleFuncToNormal(
|
|
110
|
-
// fn: (payload: any, ctx: Context) => any | Partial<BasedFunctionSpec>
|
|
111
|
-
// ): BasedFunctionSpec {}
|
|
112
|
-
function isFunctionSpec(fn) {
|
|
113
|
-
return 'function' in fn || false;
|
|
114
|
-
}
|
|
115
|
-
exports.isFunctionSpec = isFunctionSpec;
|
|
116
|
-
function isObsFunctionSpec(fn) {
|
|
117
|
-
return 'function' in fn || false;
|
|
118
|
-
}
|
|
119
|
-
exports.isObsFunctionSpec = isObsFunctionSpec;
|
|
120
131
|
//# sourceMappingURL=createSimpleServer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSimpleServer.js","sourceRoot":"","sources":["../src/createSimpleServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createSimpleServer.js","sourceRoot":"","sources":["../src/createSimpleServer.ts"],"names":[],"mappings":";;;;;;AACA,2CAQoB;AAOpB,4DAAmC;AACnC,qCAAqD;AACrD,wCAAsC;AAgC/B,KAAK,UAAU,kBAAkB,CACtC,KAA0B,EAC1B,YAAsB;IAEtB,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,KAAK,CAAA;IAE3C,MAAM,aAAa,GAKf,EAAE,CAAA;IAEN,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE;QAC5B,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE;YACnB,MAAM,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;YAC1B,IAAI,IAAA,kBAAM,EAAC,EAAE,CAAC,EAAE;gBACd,aAAa,CAAC,IAAI,CAAC,GAAG;oBACpB,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,IAAI;oBACJ,QAAQ,EAAE,CAAC;oBACX,cAAc,EAAE,IAAA,gCAAoB,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG;oBACtD,eAAe,EAAE,EAAE;oBACnB,GAAG,EAAE;iBACN,CAAA;aACF;iBAAM,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE;gBACnC,aAAa,CAAC,IAAI,CAAC,GAAG;oBACpB,QAAQ,EAAE,EAAE;oBACZ,IAAI;oBACJ,QAAQ,EAAE,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,aAAa,CAAC,IAAI,CAAC,CAAC;YAClD,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAA,gCAAoB,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gBAC3C,CAAC,CAAC,UAAU;gBACZ,CAAC,CAAC,EAAE,CAAA;QACN,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAA;QAC7D,OAAO,CAAC,IAAI,CACV,QAAQ,EACR,oBAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EACtB,IAAA,eAAO,EAAC,EAAE,EAAE,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/C,oBAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EACpB,IAAA,eAAO,EAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,oBAAU,CAAC,KAAK,CAAC,GAAG,CAAC,EACrB,IAAA,eAAO,EAAC,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE,CAC/B,CAAA;KACF;IAED,MAAM,WAAW,GAAG,IAAI,oBAAW,CAAC,WAAW,CAAC,CAAA;IAChD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;AAC/E,CAAC;AAjJD,gDAiJC"}
|
|
@@ -6,6 +6,11 @@ const addName = (payload) => {
|
|
|
6
6
|
return payload.name ? `[${payload.name}] ` : '';
|
|
7
7
|
};
|
|
8
8
|
exports.errorTypeHandlers = {
|
|
9
|
+
[types_1.BasedErrorCode.MissingAuthStateProtocolHeader]: {
|
|
10
|
+
statusCode: 500,
|
|
11
|
+
statusMessage: 'Internal Server Error',
|
|
12
|
+
message: () => '',
|
|
13
|
+
},
|
|
9
14
|
[types_1.BasedErrorCode.RateLimit]: {
|
|
10
15
|
statusCode: 429,
|
|
11
16
|
statusMessage: 'Rate limit',
|
|
@@ -15,7 +20,7 @@ exports.errorTypeHandlers = {
|
|
|
15
20
|
statusCode: 500,
|
|
16
21
|
statusMessage: 'Internal Server Error',
|
|
17
22
|
message: (payload) => {
|
|
18
|
-
if (!payload.err.message) {
|
|
23
|
+
if (typeof payload.err === 'string' || !payload.err.message) {
|
|
19
24
|
return `[${payload.route.name}] ${JSON.stringify(payload.err)}`;
|
|
20
25
|
}
|
|
21
26
|
return (addName(payload.route) +
|
|
@@ -35,44 +40,58 @@ exports.errorTypeHandlers = {
|
|
|
35
40
|
statusCode: 500,
|
|
36
41
|
statusMessage: 'Internal Server Error',
|
|
37
42
|
message: (payload) => {
|
|
38
|
-
if (payload.err &&
|
|
43
|
+
if (payload.err &&
|
|
44
|
+
(typeof payload.err === 'string' ||
|
|
45
|
+
(!payload.err.message && !payload.err.name))) {
|
|
39
46
|
return `[${payload.route.name}] ${JSON.stringify(payload.err)}`;
|
|
40
47
|
}
|
|
41
|
-
return `[${payload.route.name}] ${
|
|
48
|
+
return `[${payload.route.name}] ${typeof payload.err !== 'string' &&
|
|
49
|
+
payload.err.name &&
|
|
50
|
+
payload.err.name !== 'Error'
|
|
42
51
|
? `[${payload.err.name}] `
|
|
43
|
-
: ''}${payload.err
|
|
52
|
+
: ''}${typeof payload.err === 'string'
|
|
53
|
+
? payload.err
|
|
54
|
+
: payload.err.message || ''}`;
|
|
44
55
|
},
|
|
45
56
|
},
|
|
46
57
|
[types_1.BasedErrorCode.FunctionNotFound]: {
|
|
47
58
|
statusCode: 404,
|
|
48
59
|
statusMessage: 'Not Found',
|
|
49
60
|
message: (payload) => {
|
|
50
|
-
return (addName(payload) +
|
|
51
|
-
`Function not found${payload.path ? ` path '${payload.path}'` : ''}`);
|
|
61
|
+
return (addName(payload.route) +
|
|
62
|
+
`Function not found${payload.route.path ? ` path '${payload.route.path}'` : ''}`);
|
|
52
63
|
},
|
|
53
64
|
},
|
|
54
65
|
[types_1.BasedErrorCode.FunctionIsStream]: {
|
|
55
66
|
statusCode: 400,
|
|
56
67
|
statusMessage: 'Incorrect Protocol',
|
|
57
68
|
message: (payload) => {
|
|
58
|
-
return addName(payload) + 'Cannot use stream functions over websockets';
|
|
69
|
+
return (addName(payload.route) + 'Cannot use stream functions over websockets');
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
[types_1.BasedErrorCode.FunctionIsNotStream]: {
|
|
73
|
+
statusCode: 400,
|
|
74
|
+
statusMessage: 'Function is Not Stream',
|
|
75
|
+
message: (payload) => {
|
|
76
|
+
return addName(payload.route) + 'Cannot stream to a normal function';
|
|
59
77
|
},
|
|
60
78
|
},
|
|
61
79
|
[types_1.BasedErrorCode.FunctionIsNotObservable]: {
|
|
62
80
|
statusCode: 400,
|
|
63
81
|
statusMessage: 'Function Is Not Observable',
|
|
64
|
-
message: (payload) => addName(payload) + 'Cannot observe non observable functions',
|
|
82
|
+
message: (payload) => addName(payload.route) + 'Cannot observe non observable functions',
|
|
65
83
|
},
|
|
66
84
|
[types_1.BasedErrorCode.FunctionIsObservable]: {
|
|
67
85
|
statusCode: 400,
|
|
68
86
|
statusMessage: 'Function Is Observable',
|
|
69
|
-
message: (payload) => addName(payload) +
|
|
87
|
+
message: (payload) => addName(payload.route) +
|
|
88
|
+
'Cannot call observable functions as a standard one',
|
|
70
89
|
},
|
|
71
90
|
[types_1.BasedErrorCode.CannotStreamToObservableFunction]: {
|
|
72
91
|
statusCode: 404,
|
|
73
92
|
statusMessage: 'Not Found',
|
|
74
93
|
message: (payload) => {
|
|
75
|
-
return addName(payload) + 'Cannot stream to observable function';
|
|
94
|
+
return addName(payload.route) + 'Cannot stream to observable function';
|
|
76
95
|
},
|
|
77
96
|
},
|
|
78
97
|
[types_1.BasedErrorCode.AuthorizeFunctionError]: {
|
|
@@ -88,7 +107,7 @@ exports.errorTypeHandlers = {
|
|
|
88
107
|
[types_1.BasedErrorCode.InvalidPayload]: {
|
|
89
108
|
statusCode: 400,
|
|
90
109
|
statusMessage: 'Bad Request',
|
|
91
|
-
message: (payload) => addName(payload) + 'Invalid payload',
|
|
110
|
+
message: (payload) => addName(payload.route) + 'Invalid payload',
|
|
92
111
|
},
|
|
93
112
|
[types_1.BasedErrorCode.NoBinaryProtocol]: {
|
|
94
113
|
statusCode: 400,
|
|
@@ -98,7 +117,7 @@ exports.errorTypeHandlers = {
|
|
|
98
117
|
[types_1.BasedErrorCode.PayloadTooLarge]: {
|
|
99
118
|
statusCode: 413,
|
|
100
119
|
statusMessage: 'Payload Too Large',
|
|
101
|
-
message: (payload) => addName(payload) + ' PayloadTooLarge',
|
|
120
|
+
message: (payload) => addName(payload.route) + ' PayloadTooLarge',
|
|
102
121
|
},
|
|
103
122
|
[types_1.BasedErrorCode.ChunkTooLarge]: {
|
|
104
123
|
statusCode: 413,
|