1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "napi_app_account_constant.h"
17 
18 #include "account_log_wrapper.h"
19 #include "app_account_common.h"
20 #include "app_account_constants.h"
21 #include "napi_app_account_common.h"
22 
23 namespace OHOS {
24 namespace AccountJsKit {
ResultCodeInit(napi_env env,napi_value * resultCode)25 static void ResultCodeInit(napi_env env, napi_value *resultCode)
26 {
27     SetNamedProperty(env, (*resultCode), ERR_JS_SUCCESS_V8, "SUCCESS");
28     SetNamedProperty(env, (*resultCode), ERR_JS_ACCOUNT_NOT_EXIST, "ERROR_ACCOUNT_NOT_EXIST");
29     SetNamedProperty(env, (*resultCode), ERR_JS_APP_ACCOUNT_SERVICE_EXCEPTION, "ERROR_APP_ACCOUNT_SERVICE_EXCEPTION");
30     SetNamedProperty(env, (*resultCode), ERR_JS_INVALID_PASSWORD, "ERROR_INVALID_PASSWORD");
31     SetNamedProperty(env, (*resultCode), ERR_JS_INVALID_REQUEST, "ERROR_INVALID_REQUEST");
32     SetNamedProperty(env, (*resultCode), ERR_JS_INVALID_RESPONSE, "ERROR_INVALID_RESPONSE");
33     SetNamedProperty(env, (*resultCode), ERR_JS_NETWORK_EXCEPTION, "ERROR_NETWORK_EXCEPTION");
34     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_AUTHENTICATOR_NOT_EXIST, "ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST");
35     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_CANCELED, "ERROR_OAUTH_CANCELED");
36     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_LIST_TOO_LARGE, "ERROR_OAUTH_LIST_TOO_LARGE");
37     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_SERVICE_EXCEPTION, "ERROR_OAUTH_SERVICE_EXCEPTION");
38     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_SESSION_NOT_EXIST, "ERROR_OAUTH_SESSION_NOT_EXIST");
39     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_TIMEOUT, "ERROR_OAUTH_TIMEOUT");
40     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_TOKEN_NOT_EXIST, "ERROR_OAUTH_TOKEN_NOT_EXIST");
41     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_TOKEN_TOO_MANY, "ERROR_OAUTH_TOKEN_TOO_MANY");
42     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_SERVICE_BUSY, "ERROR_OAUTH_SERVICE_BUSY");
43     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_UNSUPPORT_ACTION, "ERROR_OAUTH_UNSUPPORT_ACTION");
44     SetNamedProperty(env, (*resultCode), ERR_JS_OAUTH_UNSUPPORT_AUTH_TYPE, "ERROR_OAUTH_UNSUPPORT_AUTH_TYPE");
45     SetNamedProperty(env, (*resultCode), ERR_JS_PERMISSION_DENIED_V8, "ERROR_PERMISSION_DENIED");
46 }
Init(napi_env env,napi_value exports)47 napi_value NapiAppAccountConstant::Init(napi_env env, napi_value exports)
48 {
49     napi_value resultCode = nullptr;
50     napi_value constants = nullptr;
51     napi_create_object(env, &resultCode);
52     napi_create_object(env, &constants);
53     ResultCodeInit(env, &resultCode);
54 
55     SetNamedProperty(env, constants, Constants::OAUTH_ACTION_ADD_ACCOUNT_IMPLICITLY,
56         "ACTION_ADD_ACCOUNT_IMPLICITLY");
57     SetNamedProperty(env, constants, Constants::OAUTH_ACTION_AUTHENTICATE, "ACTION_AUTHENTICATE");
58     SetNamedProperty(env, constants, Constants::ACTION_CREATE_ACCOUNT_IMPLICITLY,
59         "ACTION_CREATE_ACCOUNT_IMPLICITLY");
60     SetNamedProperty(env, constants, Constants::ACTION_AUTH, "ACTION_AUTH");
61     SetNamedProperty(env, constants, Constants::ACTION_VERIFY_CREDENTIAL, "ACTION_VERIFY_CREDENTIAL");
62     SetNamedProperty(env, constants, Constants::ACTION_SET_AUTHENTICATOR_PROPERTIES,
63         "ACTION_SET_AUTHENTICATOR_PROPERTIES");
64     SetNamedProperty(env, constants, Constants::KEY_NAME, "KEY_NAME");
65     SetNamedProperty(env, constants, Constants::KEY_OWNER, "KEY_OWNER");
66     SetNamedProperty(env, constants, Constants::KEY_TOKEN, "KEY_TOKEN");
67     SetNamedProperty(env, constants, Constants::KEY_ACTION, "KEY_ACTION");
68     SetNamedProperty(env, constants, Constants::KEY_AUTH_TYPE, "KEY_AUTH_TYPE");
69     SetNamedProperty(env, constants, Constants::KEY_SESSION_ID, "KEY_SESSION_ID");
70     SetNamedProperty(env, constants, Constants::KEY_CALLER_BUNDLE_NAME, "KEY_CALLER_BUNDLE_NAME");
71     SetNamedProperty(env, constants, Constants::KEY_CALLER_PID, "KEY_CALLER_PID");
72     SetNamedProperty(env, constants, Constants::KEY_CALLER_UID, "KEY_CALLER_UID");
73     SetNamedProperty(env, constants, Constants::KEY_REQUIRED_LABELS, "KEY_REQUIRED_LABELS");
74     SetNamedProperty(env, constants, Constants::KEY_BOOLEAN_RESULT, "KEY_BOOLEAN_RESULT");
75 
76     napi_property_descriptor exportFuncs[] = {
77         DECLARE_NAPI_PROPERTY("ResultCode", resultCode),
78         DECLARE_NAPI_PROPERTY("Constants", constants),
79     };
80     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
81 
82     return exports;
83 }
84 }  // namespace AccountJsKit
85 }  // namespace OHOS