@yhgale/shared 0.1.0 → 0.1.2

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 (123) hide show
  1. package/dist/chunk-DWPSHK7F.js +68 -0
  2. package/dist/chunk-Y75EVVGQ.js +108 -0
  3. package/dist/errors/index.d.ts +29 -10
  4. package/dist/errors/index.js +24 -52
  5. package/dist/index.d.ts +472 -14
  6. package/dist/index.js +2295 -14
  7. package/dist/react/index.d.ts +2 -1
  8. package/dist/react/index.js +0 -4
  9. package/dist/types/index.d.ts +705 -10
  10. package/dist/types/index.js +12 -10
  11. package/package.json +20 -39
  12. package/dist/__tests__/aiGuide.spec.d.ts +0 -2
  13. package/dist/__tests__/aiGuide.spec.d.ts.map +0 -1
  14. package/dist/__tests__/aiGuide.spec.js +0 -93
  15. package/dist/__tests__/aiGuide.spec.js.map +0 -1
  16. package/dist/__tests__/aiNavigation.spec.d.ts +0 -2
  17. package/dist/__tests__/aiNavigation.spec.d.ts.map +0 -1
  18. package/dist/__tests__/aiNavigation.spec.js +0 -20
  19. package/dist/__tests__/aiNavigation.spec.js.map +0 -1
  20. package/dist/__tests__/keys.spec.d.ts +0 -2
  21. package/dist/__tests__/keys.spec.d.ts.map +0 -1
  22. package/dist/__tests__/keys.spec.js +0 -29
  23. package/dist/__tests__/keys.spec.js.map +0 -1
  24. package/dist/aiGuide.d.ts +0 -50
  25. package/dist/aiGuide.d.ts.map +0 -1
  26. package/dist/aiGuide.js +0 -123
  27. package/dist/aiGuide.js.map +0 -1
  28. package/dist/aiNavigation.d.ts +0 -7
  29. package/dist/aiNavigation.d.ts.map +0 -1
  30. package/dist/aiNavigation.js +0 -34
  31. package/dist/aiNavigation.js.map +0 -1
  32. package/dist/defaults.d.ts +0 -19
  33. package/dist/defaults.d.ts.map +0 -1
  34. package/dist/defaults.js +0 -45
  35. package/dist/defaults.js.map +0 -1
  36. package/dist/domain.d.ts +0 -27
  37. package/dist/domain.d.ts.map +0 -1
  38. package/dist/domain.js +0 -77
  39. package/dist/domain.js.map +0 -1
  40. package/dist/email/defaults.d.ts +0 -13
  41. package/dist/email/defaults.d.ts.map +0 -1
  42. package/dist/email/defaults.js +0 -52
  43. package/dist/email/defaults.js.map +0 -1
  44. package/dist/email/markdown.d.ts +0 -6
  45. package/dist/email/markdown.d.ts.map +0 -1
  46. package/dist/email/markdown.js +0 -14
  47. package/dist/email/markdown.js.map +0 -1
  48. package/dist/email/slugs.d.ts +0 -17
  49. package/dist/email/slugs.d.ts.map +0 -1
  50. package/dist/email/slugs.js +0 -28
  51. package/dist/email/slugs.js.map +0 -1
  52. package/dist/errors/fapi.d.ts +0 -18
  53. package/dist/errors/fapi.d.ts.map +0 -1
  54. package/dist/errors/fapi.js +0 -62
  55. package/dist/errors/fapi.js.map +0 -1
  56. package/dist/errors/index.d.ts.map +0 -1
  57. package/dist/errors/index.js.map +0 -1
  58. package/dist/index.d.ts.map +0 -1
  59. package/dist/index.js.map +0 -1
  60. package/dist/keys.d.ts +0 -35
  61. package/dist/keys.d.ts.map +0 -1
  62. package/dist/keys.js +0 -128
  63. package/dist/keys.js.map +0 -1
  64. package/dist/oauth/catalog.d.ts +0 -141
  65. package/dist/oauth/catalog.d.ts.map +0 -1
  66. package/dist/oauth/catalog.js +0 -166
  67. package/dist/oauth/catalog.js.map +0 -1
  68. package/dist/oauth/china.d.ts +0 -7
  69. package/dist/oauth/china.d.ts.map +0 -1
  70. package/dist/oauth/china.js +0 -487
  71. package/dist/oauth/china.js.map +0 -1
  72. package/dist/oauth/gitee.d.ts +0 -21
  73. package/dist/oauth/gitee.d.ts.map +0 -1
  74. package/dist/oauth/gitee.js +0 -156
  75. package/dist/oauth/gitee.js.map +0 -1
  76. package/dist/oauth/github.d.ts +0 -21
  77. package/dist/oauth/github.d.ts.map +0 -1
  78. package/dist/oauth/github.js +0 -140
  79. package/dist/oauth/github.js.map +0 -1
  80. package/dist/oauth/google.d.ts +0 -17
  81. package/dist/oauth/google.d.ts.map +0 -1
  82. package/dist/oauth/google.js +0 -108
  83. package/dist/oauth/google.js.map +0 -1
  84. package/dist/oauth/index.d.ts +0 -28
  85. package/dist/oauth/index.d.ts.map +0 -1
  86. package/dist/oauth/index.js +0 -53
  87. package/dist/oauth/index.js.map +0 -1
  88. package/dist/oauth/microsoft.d.ts +0 -17
  89. package/dist/oauth/microsoft.d.ts.map +0 -1
  90. package/dist/oauth/microsoft.js +0 -118
  91. package/dist/oauth/microsoft.js.map +0 -1
  92. package/dist/oauth/wechat.d.ts +0 -4
  93. package/dist/oauth/wechat.d.ts.map +0 -1
  94. package/dist/oauth/wechat.js +0 -161
  95. package/dist/oauth/wechat.js.map +0 -1
  96. package/dist/oauth/wecom.d.ts +0 -4
  97. package/dist/oauth/wecom.d.ts.map +0 -1
  98. package/dist/oauth/wecom.js +0 -250
  99. package/dist/oauth/wecom.js.map +0 -1
  100. package/dist/parsers.d.ts +0 -44
  101. package/dist/parsers.d.ts.map +0 -1
  102. package/dist/parsers.js +0 -188
  103. package/dist/parsers.js.map +0 -1
  104. package/dist/react/index.d.ts.map +0 -1
  105. package/dist/react/index.js.map +0 -1
  106. package/dist/types/authConfig.d.ts +0 -70
  107. package/dist/types/authConfig.d.ts.map +0 -1
  108. package/dist/types/authConfig.js +0 -49
  109. package/dist/types/authConfig.js.map +0 -1
  110. package/dist/types/captcha.d.ts +0 -36
  111. package/dist/types/captcha.d.ts.map +0 -1
  112. package/dist/types/captcha.js +0 -13
  113. package/dist/types/captcha.js.map +0 -1
  114. package/dist/types/fapi.d.ts +0 -506
  115. package/dist/types/fapi.d.ts.map +0 -1
  116. package/dist/types/fapi.js +0 -24
  117. package/dist/types/fapi.js.map +0 -1
  118. package/dist/types/index.d.ts.map +0 -1
  119. package/dist/types/index.js.map +0 -1
  120. package/dist/types/oauthProviders.d.ts +0 -86
  121. package/dist/types/oauthProviders.d.ts.map +0 -1
  122. package/dist/types/oauthProviders.js +0 -15
  123. package/dist/types/oauthProviders.js.map +0 -1
@@ -0,0 +1,68 @@
1
+ // src/types/authConfig.ts
2
+ var DEFAULT_AUTH_CONFIG = {
3
+ signUp: { enabled: true },
4
+ firstFactor: ["emailAddress", "username"],
5
+ secondFactor: [],
6
+ identificationStrategies: ["emailAddress"],
7
+ singleSessionMode: false,
8
+ requireSecondFactor: false,
9
+ clientTrustEnabled: false,
10
+ deviceTrustDays: 30,
11
+ passwordPolicy: { minLength: 8, requiredCharacterClasses: 0, rejectCompromised: false },
12
+ avatar: { uploadEnabled: false },
13
+ attributes: {
14
+ emailAddress: { enabled: true, required: true },
15
+ password: { enabled: true, required: true },
16
+ passkey: { enabled: false, required: false }
17
+ },
18
+ accountPortal: {
19
+ paths: {
20
+ signIn: "/sign-in",
21
+ signUp: "/sign-up",
22
+ userProfile: "/user",
23
+ organizationProfile: "/organizations",
24
+ createOrganization: "/organizations",
25
+ unauthorizedSignIn: "/unauthorized-sign-in"
26
+ },
27
+ redirects: {
28
+ afterSignUpFallback: "",
29
+ afterSignInFallback: "",
30
+ logoLink: ""
31
+ },
32
+ appearance: {
33
+ mode: "auto",
34
+ light: {
35
+ primaryColor: "#6C47FF",
36
+ backgroundColor: "#FFFFFF"
37
+ },
38
+ dark: {
39
+ primaryColor: "#6C47FF",
40
+ backgroundColor: "#1F1F23"
41
+ }
42
+ }
43
+ }
44
+ };
45
+
46
+ // src/types/captcha.ts
47
+ var DEFAULT_CAPTCHA_SETTINGS = {
48
+ provider: "none",
49
+ publicKey: null,
50
+ secretKey: null,
51
+ widgetType: "smart",
52
+ protectedFlows: [],
53
+ oauthBypass: true,
54
+ testBypassToken: null
55
+ };
56
+
57
+ // src/types/index.ts
58
+ var UUID_V7_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
59
+ function isUuidV7(value) {
60
+ return UUID_V7_REGEX.test(value);
61
+ }
62
+
63
+ export {
64
+ DEFAULT_AUTH_CONFIG,
65
+ DEFAULT_CAPTCHA_SETTINGS,
66
+ UUID_V7_REGEX,
67
+ isUuidV7
68
+ };
@@ -0,0 +1,108 @@
1
+ // src/errors/fapi.ts
2
+ function isFapiErrorEnvelope(v) {
3
+ if (typeof v !== "object" || v === null) return false;
4
+ const errs = v.errors;
5
+ return Array.isArray(errs) && errs.length > 0 && typeof errs[0] === "object";
6
+ }
7
+ function fapiErrorToGaleError(status, body) {
8
+ if (isFapiErrorEnvelope(body)) {
9
+ const [first, ...rest] = body.errors;
10
+ if (!first) {
11
+ return new GaleError({
12
+ code: "gale_unknown_error",
13
+ message: "fapi returned empty errors[]",
14
+ status
15
+ });
16
+ }
17
+ const meta = { ...first.meta ?? {} };
18
+ if (rest.length > 0) meta["additional"] = rest;
19
+ return new GaleError({
20
+ code: first.code,
21
+ message: first.message,
22
+ longMessage: first.longMessage,
23
+ meta,
24
+ status
25
+ });
26
+ }
27
+ const message = typeof body === "object" && body !== null && "message" in body && typeof body.message === "string" ? body.message : `fapi http ${status}`;
28
+ return new GaleError({
29
+ code: status === 401 ? "gale_unauthorized" : "gale_http_error",
30
+ message,
31
+ status,
32
+ meta: { rawBody: body }
33
+ });
34
+ }
35
+ function networkErrorToGaleError(cause) {
36
+ const message = cause instanceof Error ? cause.message : "network request failed";
37
+ return new GaleError({
38
+ code: "gale_network_error",
39
+ message,
40
+ status: 0,
41
+ meta: cause instanceof Error ? { name: cause.name } : void 0
42
+ });
43
+ }
44
+
45
+ // src/errors/index.ts
46
+ var GaleError = class extends Error {
47
+ code;
48
+ status;
49
+ longMessage;
50
+ meta;
51
+ constructor(payload) {
52
+ super(payload.message);
53
+ this.name = "GaleError";
54
+ this.code = payload.code;
55
+ this.status = payload.status ?? 500;
56
+ this.longMessage = payload.longMessage;
57
+ this.meta = payload.meta;
58
+ }
59
+ };
60
+ var GaleValidationError = class extends GaleError {
61
+ constructor(payload) {
62
+ super({ ...payload, status: 422 });
63
+ this.name = "GaleValidationError";
64
+ }
65
+ };
66
+ var GaleAuthError = class extends GaleError {
67
+ constructor(payload) {
68
+ super({ ...payload, status: 401 });
69
+ this.name = "GaleAuthError";
70
+ }
71
+ };
72
+ var GalePermissionError = class extends GaleError {
73
+ constructor(payload) {
74
+ super({ ...payload, status: 403 });
75
+ this.name = "GalePermissionError";
76
+ }
77
+ };
78
+ var GaleNotFoundError = class extends GaleError {
79
+ constructor(payload) {
80
+ super({ ...payload, status: 404 });
81
+ this.name = "GaleNotFoundError";
82
+ }
83
+ };
84
+ var GaleConflictError = class extends GaleError {
85
+ constructor(payload) {
86
+ super({ ...payload, status: 409 });
87
+ this.name = "GaleConflictError";
88
+ }
89
+ };
90
+ var GaleRateLimitError = class extends GaleError {
91
+ constructor(payload) {
92
+ super({ ...payload, status: 429 });
93
+ this.name = "GaleRateLimitError";
94
+ }
95
+ };
96
+
97
+ export {
98
+ isFapiErrorEnvelope,
99
+ fapiErrorToGaleError,
100
+ networkErrorToGaleError,
101
+ GaleError,
102
+ GaleValidationError,
103
+ GaleAuthError,
104
+ GalePermissionError,
105
+ GaleNotFoundError,
106
+ GaleConflictError,
107
+ GaleRateLimitError
108
+ };
@@ -1,10 +1,29 @@
1
- export interface GaleErrorPayload {
1
+ import { FapiErrorEnvelope } from '../types/index.js';
2
+ export { FapiErrorPayload } from '../types/index.js';
3
+
4
+ /**
5
+ * 把 fapi 错误响应规范化成 `GaleError`(来自 `@yhgale/shared`)。
6
+ *
7
+ * fapi envelope: { errors: [{ code, message, longMessage?, meta? }, ...] }
8
+ *
9
+ * 设计取舍:
10
+ * - 多个 error 时取第一个作为 `.code/.message`,其余放到 `.meta.additional`
11
+ * - 透传 HTTP status,便于调用方区分 401 / 422 / 429 / 5xx
12
+ * - 网络层 / JSON 解析失败 → `gale_network_error`
13
+ */
14
+
15
+ declare function isFapiErrorEnvelope(v: unknown): v is FapiErrorEnvelope;
16
+ declare function fapiErrorToGaleError(status: number, body: unknown): GaleError;
17
+ /** 网络层错误(fetch reject / dns / cors)封装 */
18
+ declare function networkErrorToGaleError(cause: unknown): GaleError;
19
+
20
+ interface GaleErrorPayload {
2
21
  code: string;
3
22
  message: string;
4
23
  longMessage?: string;
5
24
  meta?: Record<string, unknown>;
6
25
  }
7
- export declare class GaleError extends Error {
26
+ declare class GaleError extends Error {
8
27
  readonly code: string;
9
28
  readonly status: number;
10
29
  readonly longMessage?: string;
@@ -13,23 +32,23 @@ export declare class GaleError extends Error {
13
32
  status?: number;
14
33
  });
15
34
  }
16
- export declare class GaleValidationError extends GaleError {
35
+ declare class GaleValidationError extends GaleError {
17
36
  constructor(payload: GaleErrorPayload);
18
37
  }
19
- export declare class GaleAuthError extends GaleError {
38
+ declare class GaleAuthError extends GaleError {
20
39
  constructor(payload: GaleErrorPayload);
21
40
  }
22
- export declare class GalePermissionError extends GaleError {
41
+ declare class GalePermissionError extends GaleError {
23
42
  constructor(payload: GaleErrorPayload);
24
43
  }
25
- export declare class GaleNotFoundError extends GaleError {
44
+ declare class GaleNotFoundError extends GaleError {
26
45
  constructor(payload: GaleErrorPayload);
27
46
  }
28
- export declare class GaleConflictError extends GaleError {
47
+ declare class GaleConflictError extends GaleError {
29
48
  constructor(payload: GaleErrorPayload);
30
49
  }
31
- export declare class GaleRateLimitError extends GaleError {
50
+ declare class GaleRateLimitError extends GaleError {
32
51
  constructor(payload: GaleErrorPayload);
33
52
  }
34
- export * from './fapi';
35
- //# sourceMappingURL=index.d.ts.map
53
+
54
+ export { GaleAuthError, GaleConflictError, GaleError, type GaleErrorPayload, GaleNotFoundError, GalePermissionError, GaleRateLimitError, GaleValidationError, fapiErrorToGaleError, isFapiErrorEnvelope, networkErrorToGaleError };
@@ -1,52 +1,24 @@
1
- export class GaleError extends Error {
2
- code;
3
- status;
4
- longMessage;
5
- meta;
6
- constructor(payload) {
7
- super(payload.message);
8
- this.name = 'GaleError';
9
- this.code = payload.code;
10
- this.status = payload.status ?? 500;
11
- this.longMessage = payload.longMessage;
12
- this.meta = payload.meta;
13
- }
14
- }
15
- export class GaleValidationError extends GaleError {
16
- constructor(payload) {
17
- super({ ...payload, status: 422 });
18
- this.name = 'GaleValidationError';
19
- }
20
- }
21
- export class GaleAuthError extends GaleError {
22
- constructor(payload) {
23
- super({ ...payload, status: 401 });
24
- this.name = 'GaleAuthError';
25
- }
26
- }
27
- export class GalePermissionError extends GaleError {
28
- constructor(payload) {
29
- super({ ...payload, status: 403 });
30
- this.name = 'GalePermissionError';
31
- }
32
- }
33
- export class GaleNotFoundError extends GaleError {
34
- constructor(payload) {
35
- super({ ...payload, status: 404 });
36
- this.name = 'GaleNotFoundError';
37
- }
38
- }
39
- export class GaleConflictError extends GaleError {
40
- constructor(payload) {
41
- super({ ...payload, status: 409 });
42
- this.name = 'GaleConflictError';
43
- }
44
- }
45
- export class GaleRateLimitError extends GaleError {
46
- constructor(payload) {
47
- super({ ...payload, status: 429 });
48
- this.name = 'GaleRateLimitError';
49
- }
50
- }
51
- export * from './fapi';
52
- //# sourceMappingURL=index.js.map
1
+ import {
2
+ GaleAuthError,
3
+ GaleConflictError,
4
+ GaleError,
5
+ GaleNotFoundError,
6
+ GalePermissionError,
7
+ GaleRateLimitError,
8
+ GaleValidationError,
9
+ fapiErrorToGaleError,
10
+ isFapiErrorEnvelope,
11
+ networkErrorToGaleError
12
+ } from "../chunk-Y75EVVGQ.js";
13
+ export {
14
+ GaleAuthError,
15
+ GaleConflictError,
16
+ GaleError,
17
+ GaleNotFoundError,
18
+ GalePermissionError,
19
+ GaleRateLimitError,
20
+ GaleValidationError,
21
+ fapiErrorToGaleError,
22
+ isFapiErrorEnvelope,
23
+ networkErrorToGaleError
24
+ };