Commit 6e49454d authored by jan.koester's avatar jan.koester
Browse files

test

parent 35e8471d
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for bindings/CMakeLists.txt: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
# ============================================================
#  Node.js binding
# ============================================================
set(NODE_MODULE_MINIMUM_ABI 83)
set(NODE_MODULE_MINIMUM_ABI 115)

include("${CMAKE_SOURCE_DIR}/cmake/nodejs.cmake")

+3 −0
Changes for bindings/nodejs/index.d.ts: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ export declare class Client {
    /** Check whether a GPO exists by ID. Returns true if it exists. */
    gpoExists(gpoId: string): boolean;

    /** Add a new GPO. Returns the new GPO ID (UUID). Requires clientSession auth. */
    gpoAdd(gpoId: string, name: string, desc: string, gpoDefault: boolean, members: string[]): string;

    /** Change the current user's password. */
    changeUserPw(oldPassword: string, newPassword: string): void;
}
+32 −0
Changes for bindings/nodejs/nodesjs.cpp: 32 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -261,6 +261,7 @@ namespace authdb_nds {
            NODE_SET_PROTOTYPE_METHOD(tpl, "remSession",     RemSession);
            NODE_SET_PROTOTYPE_METHOD(tpl, "gpoCheck",       GPOCheck);
            NODE_SET_PROTOTYPE_METHOD(tpl, "gpoExists",      GPOExists);
            NODE_SET_PROTOTYPE_METHOD(tpl, "gpoAdd",          GPOAdd);
            NODE_SET_PROTOTYPE_METHOD(tpl, "changeUserPw",   ChangeUserPw);

            constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked());
@@ -482,6 +483,37 @@ namespace authdb_nds {
            }
        }

        /* -- gpoAdd(gpoId: string, name: string, desc: string, gpoDefault: boolean, members: string[]) : string -- */
        static void GPOAdd(const FunctionCallbackInfo<Value>& args) {
            Isolate* isolate = args.GetIsolate();
            Local<Context> context = isolate->GetCurrentContext();
            if (args.Length() < 5 || !args[0]->IsString() || !args[1]->IsString()
                || !args[2]->IsString() || !args[3]->IsBoolean() || !args[4]->IsArray()) {
                isolate->ThrowException(Exception::TypeError(
                    String::NewFromUtf8(isolate, "gpoAdd requires (gpoId, name, desc, gpoDefault, members[])").ToLocalChecked()));
                return;
            }
            AuthDBClientJS* self = ObjectWrap::Unwrap<AuthDBClientJS>(args.This());
            try {
                uuid::uuid gpoid(V8ToString(isolate, args[0]).c_str());
                std::string name = V8ToString(isolate, args[1]);
                std::string desc = V8ToString(isolate, args[2]);
                bool gpoDefault = args[3]->BooleanValue(isolate);
                Local<v8::Array> arr = Local<v8::Array>::Cast(args[4]);
                std::vector<std::string> members;
                for (uint32_t i = 0; i < arr->Length(); ++i) {
                    Local<Value> el = arr->Get(context, i).ToLocalChecked();
                    members.push_back(V8ToString(isolate, el));
                }
                std::string gpoId = self->_client.GPOadd(gpoid, name, desc, gpoDefault, members);
                args.GetReturnValue().Set(
                    String::NewFromUtf8(isolate, gpoId.c_str()).ToLocalChecked());
            } catch (const std::exception& e) {
                isolate->ThrowException(Exception::Error(
                    String::NewFromUtf8(isolate, e.what()).ToLocalChecked()));
            }
        }

        /* -- changeUserPw(oldPw: string, newPw: string) -- */
        static void ChangeUserPw(const FunctionCallbackInfo<Value>& args) {
            Isolate* isolate = args.GetIsolate();
+1 −1
Changes for bindings/nodejs/package.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
{
  "name": "authdb-client",
  "version": "0.1.0",
  "version": "0.1.1",
  "description": "Native Node.js client bindings for AuthDB – an authentication database with JSON REST API",
  "main": "index.js",
  "types": "index.d.ts",
Loading