@enonic-types/lib-admin 0.1.0

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.
Files changed (3) hide show
  1. package/README.md +81 -0
  2. package/admin.d.ts +79 -0
  3. package/package.json +36 -0
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Enonic XP lib-admin TS types
2
+
3
+ > TypeScript definitions for `lib-admin` library of Enonic XP
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i --save-dev @enonic/lib-admin
9
+ ```
10
+
11
+ ## Use
12
+
13
+ Add the corresponding types to your `tsconfig.json` file that is used for application's server-side TypeScript code.
14
+
15
+ `tsconfig.json`
16
+
17
+ ```json
18
+ {
19
+ "compilerOptions": {
20
+ "types": [
21
+ "@enonic-types/lib-admin"
22
+ ]
23
+ }
24
+ }
25
+ ```
26
+
27
+ ### Require and custom imports
28
+
29
+ To make `require` work out of box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP global
30
+ objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
31
+
32
+ `tsconfig.json`
33
+
34
+ ```diff
35
+ {
36
+ "compilerOptions": {
37
+ "types": [
38
+ + "@enonic-types/global"
39
+ "@enonic-types/lib-admin"
40
+ ]
41
+ }
42
+ }
43
+ ```
44
+
45
+ `example.ts`
46
+
47
+ ```ts
48
+ const {getBaseUri, getAssetsUri, getHomeToolUrl, HomeToolUrlType} = require('/lib/xp/admin');
49
+ ```
50
+
51
+ More detailed explanation on how it works and how to type custom import function can be
52
+ found [here](https://github.com/enonic/xp/tree/master/modules/lib/typescript/README.md).
53
+
54
+ ### ES6-style import
55
+
56
+ If you are planning to use `import` in your code and transpile it with the default `tsc` TypeScript compiler, you'll need to add proper
57
+ types mapping to your configuration.
58
+
59
+ `tsconfig.json`
60
+
61
+ ```diff
62
+ {
63
+ "compilerOptions": {
64
+ "types": [
65
+ "@enonic-types/lib-admin"
66
+ ]
67
+ + "baseUrl": "./",
68
+ + "paths": {
69
+ + "/lib/xp/admin": ["node_modules/@enonic-types/lib-admin"],
70
+ + }
71
+ }
72
+ }
73
+ ```
74
+
75
+ `example.ts`
76
+
77
+ ```ts
78
+ import {getBaseUri, getAssetsUri, getHomeToolUrl, HomeToolUrlType} from '/lib/xp/admin';
79
+ ```
80
+
81
+ Setting `baseUrl` and `paths` will allow the `tsc` to keep the valid paths in the resulting JavaScript files.
package/admin.d.ts ADDED
@@ -0,0 +1,79 @@
1
+ declare global {
2
+ interface XpLibraries {
3
+ '/lib/xp/admin': typeof import('./admin');
4
+ }
5
+ }
6
+ /**
7
+ * Returns the admin base uri.
8
+ *
9
+ * @returns {string} Admin base uri.
10
+ */
11
+ export declare function getBaseUri(): string;
12
+ /**
13
+ * Returns the admin assets uri.
14
+ *
15
+ * @returns {string} Assets uri.
16
+ */
17
+ export declare function getAssetsUri(): string;
18
+ /**
19
+ * Returns the preferred locale based on the current HTTP request, or the server default locale if none is specified.
20
+ *
21
+ * @returns {string} Current locale.
22
+ */
23
+ export declare function getLocale(): string;
24
+ /**
25
+ * Returns the list of preferred locales based on the current HTTP request, or the server default locale if none is specified.
26
+ *
27
+ * @returns {string[]} Current locales in order of preference.
28
+ */
29
+ export declare function getLocales(): string[];
30
+ /**
31
+ * Returns all i18n phrases.
32
+ *
33
+ * @returns {object} JSON object with phrases.
34
+ */
35
+ export declare function getPhrases(): string;
36
+ /**
37
+ * Returns the URL for launcher panel.
38
+ *
39
+ * @returns {string} URL.
40
+ */
41
+ export declare function getLauncherUrl(): string;
42
+ /**
43
+ * Returns the URL for launcher javascript.
44
+ *
45
+ * @returns {string} Path.
46
+ */
47
+ export declare function getLauncherPath(): string;
48
+ /**
49
+ * Returns the URL for an admin tool of specific application.
50
+ * @param {string} application Full application name (f.ex, 'com.enonic.app')
51
+ * @param {string} tool Name of the tool inside an app (f.ex, 'main')
52
+ *
53
+ * @returns {string} URL.
54
+ */
55
+ export declare function getToolUrl(application: string, tool: string): string;
56
+ /**
57
+ * Returns the URL for the Home admin tool.
58
+ * @param {object} [params] Parameter object
59
+ * @param {string} [params.type=server] URL type. Either `server` (server-relative URL) or `absolute`.
60
+ *
61
+ * @returns {string} URL.
62
+ */
63
+ export declare function getHomeToolUrl(params: GetHomeToolUrlParams): string;
64
+ export interface GetHomeToolUrlParams {
65
+ type: HomeToolUrlType;
66
+ }
67
+ export declare type HomeToolUrlType = 'server' | 'absolute';
68
+ /**
69
+ * Returns installation name.
70
+ *
71
+ * @returns {string} Installation name.
72
+ */
73
+ export declare function getInstallation(): string;
74
+ /**
75
+ * Returns version of XP installation.
76
+ *
77
+ * @returns {string} Version.
78
+ */
79
+ export declare function getVersion(): string;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@enonic-types/lib-admin",
3
+ "version": "0.1.0",
4
+ "description": "Type definitions for lib-admin.",
5
+ "types": "admin.d.ts",
6
+ "files": [
7
+ "admin.d.ts"
8
+ ],
9
+ "scripts": {
10
+ "pre": "npm run --prefix ../ pre",
11
+ "packlist": "npx npm-packlist"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/enonic/xp.git#master"
16
+ },
17
+ "keywords": [
18
+ "enonic",
19
+ "enonic-xp",
20
+ "lib-admin",
21
+ "admin",
22
+ "types",
23
+ "typescript"
24
+ ],
25
+ "contributors": [
26
+ "Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
27
+ ],
28
+ "license": "Apache-2.0",
29
+ "bugs": {
30
+ "url": "https://github.com/enonic/xp/issues"
31
+ },
32
+ "homepage": "https://github.com/enonic/xp/tree/master#readme",
33
+ "publishConfig": {
34
+ "access": "public"
35
+ }
36
+ }