@pc-nexus/core 0.5.0-next.9 → 0.8.0-next.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.
- package/index.d.ts +4 -2
- package/index.d.ts.map +1 -1
- package/index.js +4 -2
- package/lib/authorize.d.ts +22 -0
- package/lib/authorize.d.ts.map +1 -0
- package/lib/authorize.js +17 -0
- package/lib/handler.d.ts +6 -0
- package/lib/handler.d.ts.map +1 -0
- package/lib/handler.js +1 -0
- package/lib/i18n/main.d.ts +9 -5
- package/lib/i18n/main.d.ts.map +1 -1
- package/lib/i18n/main.js +44 -31
- package/lib/i18n/translation-loader.d.ts +2 -2
- package/lib/i18n/translation-loader.d.ts.map +1 -1
- package/lib/i18n/types.d.ts +10 -7
- package/lib/i18n/types.d.ts.map +1 -1
- package/lib/i18n/types.js +2 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { EnvironmentType,
|
|
2
|
-
export * from "./lib/
|
|
1
|
+
export { EnvironmentType, NexusError, NexusHttpStatusCode, NexusInnerError, NexusInnerErrorCode, Resolver, type Extension, type EventHandler, type EventHandlerEvent, type NexusAppContext, type ResolverFunction, type Team, type User, type WebhookEventResult, } from "@pc-nexus/internal";
|
|
2
|
+
export * from "./lib/authorize.js";
|
|
3
|
+
export * from "./lib/handler.js";
|
|
4
|
+
export { app } from "./lib/common.js";
|
|
3
5
|
export * from "./lib/i18n/index.js";
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,QAAQ,EACR,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,kBAAkB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,cAAc,qBAAqB,CAAC"}
|
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { EnvironmentType,
|
|
2
|
-
export * from "./lib/
|
|
1
|
+
export { EnvironmentType, NexusError, NexusHttpStatusCode, NexusInnerError, NexusInnerErrorCode, Resolver, } from "@pc-nexus/internal";
|
|
2
|
+
export * from "./lib/authorize.js";
|
|
3
|
+
export * from "./lib/handler.js";
|
|
4
|
+
export { app } from "./lib/common.js";
|
|
3
5
|
export * from "./lib/i18n/index.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface PermissionPoint {
|
|
2
|
+
key: string;
|
|
3
|
+
name: string;
|
|
4
|
+
group: string;
|
|
5
|
+
}
|
|
6
|
+
export type PermissionPointsResult = Record<string, PermissionPoint[]>;
|
|
7
|
+
type PilotType = "product" | "project" | "library" | "space";
|
|
8
|
+
type PrincipalType = "idea" | "ticket" | "workitem" | "testcase" | "page";
|
|
9
|
+
export type ResourceType = PilotType | PrincipalType;
|
|
10
|
+
export interface UserPermission {
|
|
11
|
+
key: string;
|
|
12
|
+
has_permission: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare function getPermissionPoints(): Promise<PermissionPointsResult>;
|
|
15
|
+
declare function getUserPermissions(type: "global", userId?: string): Promise<UserPermission[]>;
|
|
16
|
+
declare function getUserPermissions(type: ResourceType, id: string, userId?: string): Promise<UserPermission[]>;
|
|
17
|
+
export declare const authorize: {
|
|
18
|
+
getPermissionPoints: typeof getPermissionPoints;
|
|
19
|
+
getUserPermissions: typeof getUserPermissions;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=authorize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../src/lib/authorize.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;AAIvE,KAAK,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE7D,KAAK,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;AAE1E,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,aAAa,CAAC;AAErD,MAAM,WAAW,cAAc;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,EAAE,OAAO,CAAC;CAC3B;AASD,iBAAe,mBAAmB,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAIpE;AAED,iBAAe,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;AAC9F,iBAAe,kBAAkB,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;AAQ9G,eAAO,MAAM,SAAS;;;CAGrB,CAAC"}
|
package/lib/authorize.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { invoke } from "@pc-nexus/internal";
|
|
2
|
+
// ── SDK functions ─────────────────────────────────────────────────────────────
|
|
3
|
+
async function getPermissionPoints() {
|
|
4
|
+
const invokeRes = await invoke("authorize", "get-points", {});
|
|
5
|
+
const result = (await invokeRes.json());
|
|
6
|
+
return result.value ?? {};
|
|
7
|
+
}
|
|
8
|
+
async function getUserPermissions(type, idOrUserId, userId) {
|
|
9
|
+
const payload = type === "global" ? { type, user_id: idOrUserId } : { type, id: idOrUserId, user_id: userId };
|
|
10
|
+
const invokeRes = await invoke("authorize", "get-user-permissions", payload);
|
|
11
|
+
const result = (await invokeRes.json());
|
|
12
|
+
return (result.value ?? []).map((p) => ({ key: p.key, has_permission: p.has_permission === 1 }));
|
|
13
|
+
}
|
|
14
|
+
export const authorize = {
|
|
15
|
+
getPermissionPoints,
|
|
16
|
+
getUserPermissions,
|
|
17
|
+
};
|
package/lib/handler.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EventHandler, LifecycleEventPayload, ScheduledEventPayload, SystemEventPayload, WebhookEventResult, WebhookEventPayload } from "@pc-nexus/internal";
|
|
2
|
+
export type SystemEventHandler = EventHandler<SystemEventPayload, void>;
|
|
3
|
+
export type LifecycleEventHandler = EventHandler<LifecycleEventPayload, void>;
|
|
4
|
+
export type WebhookEventHandler = EventHandler<WebhookEventPayload, WebhookEventResult>;
|
|
5
|
+
export type ScheduledEventHandler = EventHandler<ScheduledEventPayload, void>;
|
|
6
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/lib/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACtB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;AAExE,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;AAE9E,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;AAExF,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC"}
|
package/lib/handler.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/i18n/main.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { SupportedLocaleCode, GetTranslationsResult, Translator } from "./types.js";
|
|
2
|
+
declare class I18n {
|
|
3
|
+
#private;
|
|
4
|
+
constructor();
|
|
5
|
+
getTranslations(locale?: SupportedLocaleCode): Promise<GetTranslationsResult>;
|
|
6
|
+
createTranslator(locale?: SupportedLocaleCode): Promise<Translator>;
|
|
7
|
+
}
|
|
8
|
+
export declare const i18n: I18n;
|
|
9
|
+
export {};
|
|
6
10
|
//# sourceMappingURL=main.d.ts.map
|
package/lib/i18n/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/main.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/main.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAuD,qBAAqB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGzI,cAAM,IAAI;;;IAMO,eAAe,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAK7E,gBAAgB,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;CAkDnF;AAED,eAAO,MAAM,IAAI,MAAa,CAAC"}
|
package/lib/i18n/main.js
CHANGED
|
@@ -1,40 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NexusInnerError, NexusInnerErrorCode } from "@pc-nexus/internal";
|
|
2
2
|
import { TranslationLoader } from "./translation-loader.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SUPPORTED_LOCALE_CODES } from "./types.js";
|
|
4
4
|
import _ from "lodash";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
class I18n {
|
|
6
|
+
#translationsGetter;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.#translationsGetter = new TranslationLoader();
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let locale = undefined;
|
|
14
|
-
if (rawLocale) {
|
|
15
|
-
locale = ensureLocale(rawLocale);
|
|
10
|
+
async getTranslations(locale) {
|
|
11
|
+
this.#validateLocale(locale);
|
|
12
|
+
return await this.#translationsGetter.getTranslations(locale);
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
async createTranslator(locale) {
|
|
15
|
+
this.#validateLocale(locale);
|
|
16
|
+
const translationResult = await this.#translationsGetter.getTranslations(locale);
|
|
17
|
+
return {
|
|
18
|
+
translate: (key, params) => {
|
|
19
|
+
return this.#translate(key, translationResult.translations ?? {}, params);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
#translate(key, translations, params) {
|
|
24
|
+
if (!key) {
|
|
25
|
+
throw new NexusInnerError(NexusInnerErrorCode.I18nTranslationKeyRequired, `"key" is required in i18n translate.`);
|
|
26
|
+
}
|
|
27
|
+
let value = _.get(translations, key);
|
|
28
|
+
if (value == null) {
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === "object") {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
if (typeof value !== "string") {
|
|
35
|
+
value = String(value);
|
|
36
|
+
}
|
|
37
|
+
if (!params) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
return value.replace(/\{\{\s*(.*?)\s*\}\}/g, (x, k) => {
|
|
41
|
+
const paramValue = _.get(params, k.trim());
|
|
25
42
|
return paramValue != null ? String(paramValue) : `{{${k}}}`;
|
|
26
43
|
});
|
|
27
44
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
#validateLocale(locale) {
|
|
46
|
+
if (locale) {
|
|
47
|
+
if (!SUPPORTED_LOCALE_CODES.includes(locale)) {
|
|
48
|
+
throw new NexusInnerError(NexusInnerErrorCode.I18nTranslationLocaleInvalid, `locale "${locale}" is not supported`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
34
51
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export const i18n = {
|
|
38
|
-
translate: translate,
|
|
39
|
-
getTranslations: getTranslations,
|
|
40
|
-
};
|
|
52
|
+
}
|
|
53
|
+
export const i18n = new I18n();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SupportedLocaleCode, GetTranslationsResult } from "./types.js";
|
|
2
2
|
export declare class TranslationLoader {
|
|
3
3
|
#private;
|
|
4
4
|
constructor();
|
|
5
5
|
reset(): Promise<void>;
|
|
6
|
-
getTranslations(locale?:
|
|
6
|
+
getTranslations(locale?: SupportedLocaleCode): Promise<GetTranslationsResult>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=translation-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/translation-loader.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"translation-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/translation-loader.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAWrG,qBAAa,iBAAiB;;;IA4Bb,KAAK;IAKL,eAAe,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAa7F"}
|
package/lib/i18n/types.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export declare interface
|
|
4
|
-
locale:
|
|
5
|
-
translations:
|
|
1
|
+
export declare const SUPPORTED_LOCALE_CODES: readonly ["zh-CN", "en-US"];
|
|
2
|
+
export type SupportedLocaleCode = (typeof SUPPORTED_LOCALE_CODES)[number];
|
|
3
|
+
export declare interface GetTranslationsResult {
|
|
4
|
+
locale: SupportedLocaleCode;
|
|
5
|
+
translations: TranslationsResourceContent | null;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
8
|
-
[key: string]: string |
|
|
7
|
+
export interface TranslationsResourceContent {
|
|
8
|
+
[key: string]: string | TranslationsResourceContent;
|
|
9
|
+
}
|
|
10
|
+
export interface Translator {
|
|
11
|
+
translate: (key: string, params?: Record<string, any>) => TranslationsResourceContent | string;
|
|
9
12
|
}
|
|
10
13
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/i18n/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/i18n/types.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,sBAAsB,6BAA8B,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1E,MAAM,CAAC,OAAO,WAAW,qBAAqB;IAC1C,MAAM,EAAE,mBAAmB,CAAC;IAC5B,YAAY,EAAE,2BAA2B,GAAG,IAAI,CAAC;CACpD;AAED,MAAM,WAAW,2BAA2B;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,2BAA2B,CAAC;CACvD;AAED,MAAM,WAAW,UAAU;IACvB,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,2BAA2B,GAAG,MAAM,CAAC;CAClG"}
|
package/lib/i18n/types.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
// 为了方便做类型检查,这里定义了支持的 locale 数组常量,并且避免导出过多内容没有引入 model 中的类型,重复声明了一遍
|
|
2
|
+
export const SUPPORTED_LOCALE_CODES = ["zh-CN", "en-US"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pc-nexus/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-next.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"type": "module",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@pc-nexus/internal": "0.
|
|
32
|
+
"@pc-nexus/internal": "0.8.0-next.0",
|
|
33
33
|
"lodash": "^4.17.21"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {},
|