387 lines
7.6 KiB
TypeScript
387 lines
7.6 KiB
TypeScript
namespace _wiki_js_cli.logic
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export async function login(
|
|
options : {
|
|
username ?: string;
|
|
password ?: string;
|
|
} = {}
|
|
) : Promise<void>
|
|
{
|
|
options = Object.assign(
|
|
{
|
|
"username": _wiki_js_cli.conf.get().login.username,
|
|
"password": _wiki_js_cli.conf.get().login.password,
|
|
},
|
|
options
|
|
);
|
|
await _wiki_js_cli.api.call_login_local(
|
|
options.username,
|
|
options.password
|
|
);
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function initialize(
|
|
admin_email_address : string,
|
|
admin_password : string,
|
|
options : {
|
|
site_url ?: string;
|
|
allow_telemetry ?: boolean;
|
|
} = {}
|
|
) : Promise<void>
|
|
{
|
|
options = Object.assign(
|
|
{
|
|
"site_url": "http://localhost:3000",
|
|
"allow_telemetry": false,
|
|
},
|
|
options
|
|
);
|
|
await _wiki_js_cli.api.call_finalize(
|
|
admin_email_address,
|
|
admin_password,
|
|
options.site_url,
|
|
options.allow_telemetry
|
|
);
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function email_settings_set(
|
|
smtp_host : string,
|
|
smtp_port : int,
|
|
smtp_username : string,
|
|
smtp_password : string,
|
|
sender_name : string,
|
|
sender_email_address : string,
|
|
options : {
|
|
} = {}
|
|
) : Promise<void>
|
|
{
|
|
options = Object.assign(
|
|
{
|
|
},
|
|
options
|
|
);
|
|
const result = await _wiki_js_cli.api.call_email_settings_set(
|
|
{
|
|
"sender_name": sender_name,
|
|
"sender_email_address": sender_email_address,
|
|
"smtp_host": smtp_host,
|
|
"smtp_port": smtp_port,
|
|
"secure": true,
|
|
"verify_ssl": true,
|
|
"smtp_username": smtp_username,
|
|
"smtp_password": smtp_password,
|
|
"name": "",
|
|
"use_dkim": false,
|
|
"dkim_domain_name": "",
|
|
"dkim_key_selector": "",
|
|
"dkim_private_key": "",
|
|
}
|
|
);
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function locale_add(
|
|
locale_code : string
|
|
) : Promise<void>
|
|
{
|
|
_wiki_js_cli.api.call_locale_download(
|
|
locale_code
|
|
);
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function group_identify(
|
|
name : string
|
|
) : Promise<int>
|
|
{
|
|
const data = await _wiki_js_cli.api.call_group_list(
|
|
name
|
|
);
|
|
const hits : Array<any> = (
|
|
data["groups"]["list"]
|
|
.filter(
|
|
(entry) => (entry["name"] === name)
|
|
)
|
|
);
|
|
if (hits.length !== 1) {
|
|
return Promise.reject(new Error("not found or ambiguous"));
|
|
}
|
|
else {
|
|
return Promise.resolve(hits[0]["id"]);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* returns the ID of the generated group
|
|
*/
|
|
export async function group_add(
|
|
name : string,
|
|
options : {
|
|
permissions_general ?: Array<
|
|
string
|
|
>;
|
|
permissions_specific ?: Array<
|
|
{
|
|
id : string;
|
|
path : string;
|
|
roles : Array<
|
|
string
|
|
>;
|
|
match : string;
|
|
deny : boolean;
|
|
locales : Array<
|
|
string
|
|
>;
|
|
}
|
|
>;
|
|
} = {}
|
|
) : Promise<int>
|
|
{
|
|
options = Object.assign(
|
|
{
|
|
"permissions_general": [],
|
|
"permissions_specific": [],
|
|
},
|
|
options
|
|
);
|
|
const result_1 = await _wiki_js_cli.api.call_group_create(
|
|
name
|
|
);
|
|
const id : int = result_1["groups"]["create"]["group"]["id"];
|
|
const result_2 = await _wiki_js_cli.api.call_group_update(
|
|
id,
|
|
name,
|
|
options.permissions_general,
|
|
options.permissions_specific
|
|
);
|
|
return Promise.resolve(id);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function group_modify(
|
|
id : int,
|
|
options : {
|
|
permissions_general ?: Array<
|
|
string
|
|
>;
|
|
permissions_specific ?: Array<
|
|
{
|
|
id : string;
|
|
path : string;
|
|
roles : Array<
|
|
string
|
|
>;
|
|
match : string;
|
|
deny : boolean;
|
|
locales : Array<
|
|
string
|
|
>;
|
|
}
|
|
>;
|
|
} = {}
|
|
) : Promise<void>
|
|
{
|
|
options = Object.assign(
|
|
{
|
|
"permissions_general": [],
|
|
"permissions_specific": [],
|
|
},
|
|
options
|
|
);
|
|
const result = await _wiki_js_cli.api.call_group_update(
|
|
id,
|
|
name,
|
|
options.permissions_general,
|
|
options.permissions_specific
|
|
);
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function authentication_strategy_list(
|
|
) : Promise<Array<any>>
|
|
{
|
|
const result = await _wiki_js_cli.api.call_authentication_strategy_list(
|
|
);
|
|
return Promise.resolve(result);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function authentication_strategy_add(
|
|
strategy : {
|
|
key:string;
|
|
name:string;
|
|
client_id:string;
|
|
client_secret:string;
|
|
authorization_url:string;
|
|
token_url:string;
|
|
user_info_url:string;
|
|
group_assignments:Array<string>;
|
|
}
|
|
) : Promise<void>
|
|
{
|
|
const current = await _wiki_js_cli.api.call_authentication_strategy_list(
|
|
);
|
|
const result = await _wiki_js_cli.api.call_authentication_strategy_set(
|
|
(
|
|
(
|
|
current
|
|
.map(
|
|
(entry) => ({
|
|
"key": entry["key"],
|
|
"strategyKey": entry["strategy"]["key"],
|
|
"displayName": entry["displayName"],
|
|
"order": entry["order"],
|
|
"isEnabled": entry["isEnabled"],
|
|
"config": (
|
|
entry["config"]
|
|
.map(
|
|
(item) => ({
|
|
"key": item["key"],
|
|
"value": JSON.stringify({"v": JSON.parse(item["value"])["value"]}),
|
|
})
|
|
)
|
|
),
|
|
"selfRegistration": entry["selfRegistration"],
|
|
"domainWhitelist": entry["domainWhitelist"],
|
|
"autoEnrollGroups": entry["autoEnrollGroups"],
|
|
})
|
|
)
|
|
)
|
|
.concat(
|
|
[
|
|
{
|
|
"key": strategy.key,
|
|
"strategyKey": "oauth2",
|
|
"displayName": strategy.name,
|
|
"order": (
|
|
(
|
|
current
|
|
.map(x => x["order"])
|
|
.reduce((x,y) => (((x === null) || (x < y)) ? y : x), null)
|
|
)
|
|
+
|
|
1
|
|
),
|
|
"isEnabled": true,
|
|
"config": [
|
|
{
|
|
"key": "clientId",
|
|
"value": JSON.stringify({"v": strategy.client_id}),
|
|
},
|
|
{
|
|
"key": "clientSecret",
|
|
"value": JSON.stringify({"v": strategy.client_secret}),
|
|
},
|
|
{
|
|
"key": "authorizationURL",
|
|
"value": JSON.stringify({"v": strategy.authorization_url}),
|
|
},
|
|
{
|
|
"key": "tokenURL",
|
|
"value": JSON.stringify({"v": strategy.token_url}),
|
|
},
|
|
{
|
|
"key": "userInfoURL",
|
|
"value": JSON.stringify({"v": strategy.user_info_url}),
|
|
},
|
|
{
|
|
"key": "userIdClaim",
|
|
"value": JSON.stringify({"v": "id"}),
|
|
},
|
|
{
|
|
"key": "displayNameClaim",
|
|
"value": JSON.stringify({"v": "name"}),
|
|
},
|
|
{
|
|
"key": "emailClaim",
|
|
"value": JSON.stringify({"v": "email"}),
|
|
},
|
|
{
|
|
"key": "mapGroups",
|
|
"value": JSON.stringify({"v": false}),
|
|
},
|
|
{
|
|
"key": "groupsClaim",
|
|
"value": JSON.stringify({"v": "groups"}),
|
|
},
|
|
{
|
|
"key": "logoutURL",
|
|
"value": JSON.stringify({"v": ""}),
|
|
},
|
|
{
|
|
"key": "scope",
|
|
"value": JSON.stringify({"v": "openid profile email"}),
|
|
},
|
|
{
|
|
"key": "useQueryStringForAccessToken",
|
|
"value": JSON.stringify({"v": false}),
|
|
},
|
|
{
|
|
"key": "enableCSRFProtection",
|
|
"value": JSON.stringify({"v": true}),
|
|
}
|
|
],
|
|
"selfRegistration": true,
|
|
"domainWhitelist": [],
|
|
"autoEnrollGroups": await Promise.all(
|
|
strategy.group_assignments
|
|
.map(x => group_identify(x))
|
|
),
|
|
},
|
|
]
|
|
)
|
|
)
|
|
);
|
|
return Promise.resolve(undefined);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function theming_set(
|
|
options : {
|
|
dark_mode ?: boolean;
|
|
toc_position ?: ("left" | "right" | "off");
|
|
} = {}
|
|
) : Promise<void>
|
|
{
|
|
options = Object.assign(
|
|
{
|
|
"dark_mode": false,
|
|
"toc_position": "left",
|
|
},
|
|
options
|
|
);
|
|
const result = await _wiki_js_cli.api.call_theming_set(
|
|
options.dark_mode,
|
|
options.toc_position
|
|
);
|
|
return Promise.resolve(result);
|
|
}
|
|
|
|
}
|