@bearei/contracts 0.0.0-stage → 2.0.0-dev.3
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/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +74 -2
- package/README.zh-CN.md +75 -0
- package/dist/index.d.mts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +101 -0
- package/dist/index.mjs +69 -0
- package/package.json +85 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file. The format is based on
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## 2.0.0-dev.3 — 2026-10-27
|
|
8
|
+
|
|
9
|
+
Development snapshot published under the `next` dist-tag to verify the unified release pipeline
|
|
10
|
+
across all Bearei repositories: the artifact is pulled back from the registry, re-verified and
|
|
11
|
+
attached to the GitHub release. It matches the 2.0.0 scope documented below and leaves the
|
|
12
|
+
`latest` dist-tag unchanged.
|
|
13
|
+
|
|
14
|
+
Install it with `yarn add @bearei/contracts@next` or pin `@bearei/contracts@2.0.0-dev.3`.
|
|
15
|
+
|
|
16
|
+
## 2.0.0-dev.2 — 2026-10-27
|
|
17
|
+
|
|
18
|
+
Development snapshot published under the `next` dist-tag to verify the npm trusted publishing
|
|
19
|
+
pipeline. It matches the 2.0.0 scope documented below and leaves the `latest` dist-tag unchanged.
|
|
20
|
+
|
|
21
|
+
Install it with `yarn add @bearei/contracts@next` or pin `@bearei/contracts@2.0.0-dev.2`.
|
|
22
|
+
|
|
23
|
+
## 2.0.0 — 2026-10-26
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- `HTTP_EXCEPTION_CODE` and `HttpExceptionCode`, moved from `@bearei/nest` without changing any
|
|
28
|
+
numeric value.
|
|
29
|
+
- `ApiErrorBody` with the normalized `{code, message, statusCode}` shape.
|
|
30
|
+
- `DEFAULT_PAGE_SIZE`, `MAX_PAGE_SIZE`, `PaginationQuery` and `PaginatedResult<T>`.
|
|
31
|
+
- `RESERVED_REQUEST_HEADER` and `ReservedRequestHeaderName` for the six `x-bearei-*` headers.
|
|
32
|
+
- `LANGUAGE`, `Language`, `ORDER` and `Order`, moved from `@bearei/nest`.
|
|
33
|
+
- Dual ESM and CommonJS builds with matching declaration files.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Bearei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bearei/contracts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Framework-agnostic wire contracts shared by Bearei services, clients and apps. The package has no
|
|
4
|
+
runtime dependencies and ships both ESM and CommonJS builds.
|
|
5
|
+
|
|
6
|
+
English | [中文](./README.zh-CN.md)
|
|
7
|
+
|
|
8
|
+
| Export | Kind | Purpose |
|
|
9
|
+
| ------------------------------------------------------ | ----- | --------------------------------------------------- |
|
|
10
|
+
| `HTTP_EXCEPTION_CODE`, `HttpExceptionCode` | value | Numeric error codes shared by services and clients |
|
|
11
|
+
| `ApiErrorBody` | type | Normalized error body `{code, message, statusCode}` |
|
|
12
|
+
| `DEFAULT_PAGE_SIZE`, `MAX_PAGE_SIZE` | value | Paging limits used by every list endpoint |
|
|
13
|
+
| `PaginationQuery`, `PaginatedResult<T>` | type | Paging request fields and page envelope |
|
|
14
|
+
| `RESERVED_REQUEST_HEADER`, `ReservedRequestHeaderName` | value | Headers set by the gateway or authentication layer |
|
|
15
|
+
| `LANGUAGE`, `Language` | value | Locale values |
|
|
16
|
+
| `ORDER`, `Order` | value | Sort order values |
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
yarn add @bearei/contracts
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import {
|
|
28
|
+
DEFAULT_PAGE_SIZE,
|
|
29
|
+
HTTP_EXCEPTION_CODE,
|
|
30
|
+
RESERVED_REQUEST_HEADER,
|
|
31
|
+
type ApiErrorBody,
|
|
32
|
+
type PaginatedResult
|
|
33
|
+
} from '@bearei/contracts'
|
|
34
|
+
|
|
35
|
+
const error: ApiErrorBody = {
|
|
36
|
+
code: HTTP_EXCEPTION_CODE.NOT_FOUND,
|
|
37
|
+
message: 'Not Found',
|
|
38
|
+
statusCode: 404
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const subject = request.headers[RESERVED_REQUEST_HEADER.SUBJECT]
|
|
42
|
+
const page: PaginatedResult<{id: string}> = {
|
|
43
|
+
page: 1,
|
|
44
|
+
pageSize: DEFAULT_PAGE_SIZE,
|
|
45
|
+
results: [{id: 'a'}]
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Module formats
|
|
50
|
+
|
|
51
|
+
The `exports` map resolves `import` consumers to the ESM build and `require` consumers to the
|
|
52
|
+
CommonJS build. TypeScript picks the matching declaration file (`.d.mts` or `.d.ts`).
|
|
53
|
+
|
|
54
|
+
## Scope
|
|
55
|
+
|
|
56
|
+
Only values and types that both ends of a wire boundary must agree on belong here:
|
|
57
|
+
|
|
58
|
+
- numeric error codes and error response bodies
|
|
59
|
+
- query and response shapes shared by API clients and services
|
|
60
|
+
- reserved request header names
|
|
61
|
+
- cross-project enums such as language and sort order
|
|
62
|
+
|
|
63
|
+
Framework-specific code does not belong here: NestJS decorators, guards and interceptors,
|
|
64
|
+
TypeORM entities, HTTP clients, persistence, and service-only DTOs stay in their own libraries.
|
|
65
|
+
|
|
66
|
+
`HTTP_EXCEPTION_CODE` values are wire contract. Append new codes and never renumber or reuse an
|
|
67
|
+
existing value; renaming a code is also a breaking change for consumers that imported it by name.
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
yarn install
|
|
73
|
+
yarn verify # lint + typecheck + coverage + build
|
|
74
|
+
yarn run pack # pack once and inspect the tarball
|
|
75
|
+
```
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @bearei/contracts
|
|
2
|
+
|
|
3
|
+
Bearei 服务、客户端与应用共享的传输契约,不依赖任何框架。包本身没有运行时依赖,同时提供
|
|
4
|
+
ESM 与 CommonJS 两种产物。
|
|
5
|
+
|
|
6
|
+
[English](./README.md) | 中文
|
|
7
|
+
|
|
8
|
+
| 导出 | 类型 | 用途 |
|
|
9
|
+
| ------------------------------------------------------ | ---- | ---------------------------------------- |
|
|
10
|
+
| `HTTP_EXCEPTION_CODE`、`HttpExceptionCode` | 值 | 服务与客户端共享的数字错误码 |
|
|
11
|
+
| `ApiErrorBody` | 类型 | 统一错误体 `{code, message, statusCode}` |
|
|
12
|
+
| `DEFAULT_PAGE_SIZE`、`MAX_PAGE_SIZE` | 值 | 所有列表接口使用的分页上限 |
|
|
13
|
+
| `PaginationQuery`、`PaginatedResult<T>` | 类型 | 分页请求字段与分页响应信封 |
|
|
14
|
+
| `RESERVED_REQUEST_HEADER`、`ReservedRequestHeaderName` | 值 | 由网关或认证层写入的保留请求头 |
|
|
15
|
+
| `LANGUAGE`、`Language` | 值 | 语言值 |
|
|
16
|
+
| `ORDER`、`Order` | 值 | 排序值 |
|
|
17
|
+
|
|
18
|
+
## 安装
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
yarn add @bearei/contracts
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 使用
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import {
|
|
28
|
+
DEFAULT_PAGE_SIZE,
|
|
29
|
+
HTTP_EXCEPTION_CODE,
|
|
30
|
+
RESERVED_REQUEST_HEADER,
|
|
31
|
+
type ApiErrorBody,
|
|
32
|
+
type PaginatedResult
|
|
33
|
+
} from '@bearei/contracts'
|
|
34
|
+
|
|
35
|
+
const error: ApiErrorBody = {
|
|
36
|
+
code: HTTP_EXCEPTION_CODE.NOT_FOUND,
|
|
37
|
+
message: 'Not Found',
|
|
38
|
+
statusCode: 404
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const subject = request.headers[RESERVED_REQUEST_HEADER.SUBJECT]
|
|
42
|
+
const page: PaginatedResult<{id: string}> = {
|
|
43
|
+
page: 1,
|
|
44
|
+
pageSize: DEFAULT_PAGE_SIZE,
|
|
45
|
+
results: [{id: 'a'}]
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 模块格式
|
|
50
|
+
|
|
51
|
+
`exports` 映射会让 `import` 使用 ESM 产物、`require` 使用 CommonJS 产物;TypeScript 会自动选择
|
|
52
|
+
对应的声明文件(`.d.mts` 或 `.d.ts`)。
|
|
53
|
+
|
|
54
|
+
## 收录范围
|
|
55
|
+
|
|
56
|
+
这里只放传输边界两端必须一致的值与类型:
|
|
57
|
+
|
|
58
|
+
- 数字错误码与错误响应体
|
|
59
|
+
- API 客户端与服务共享的查询、响应结构
|
|
60
|
+
- 保留请求头名称
|
|
61
|
+
- 语言、排序等跨项目枚举
|
|
62
|
+
|
|
63
|
+
框架相关代码不放进这里:NestJS 装饰器、守卫、拦截器,TypeORM 实体,HTTP 客户端,持久化,
|
|
64
|
+
以及仅服务端使用的 DTO 都留在各自的库中。
|
|
65
|
+
|
|
66
|
+
`HTTP_EXCEPTION_CODE` 的数值属于线上契约。只能追加新错误码,不得重新编号或复用已有数值;
|
|
67
|
+
重命名错误码同样会破坏按名称引用它的使用者。
|
|
68
|
+
|
|
69
|
+
## 开发
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
yarn install
|
|
73
|
+
yarn verify # lint + typecheck + 覆盖率 + 构建
|
|
74
|
+
yarn run pack # 打包一次并检查 tarball
|
|
75
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numeric error codes shared by Bearei services and clients.
|
|
3
|
+
* Values are part of the wire contract: append new codes, never renumber or reuse.
|
|
4
|
+
*/
|
|
5
|
+
declare const HTTP_EXCEPTION_CODE: {
|
|
6
|
+
readonly ACCESS_DENIED_FOR_GUEST: 401003;
|
|
7
|
+
readonly APPLE_IAP_TRANSACTION_NOT_COMPLETED: 403004;
|
|
8
|
+
readonly APPLE_IAP_TRANSACTION_UNAUTHORIZED: 401008;
|
|
9
|
+
readonly APPLE_IAP_TRANSACTION_VERIFICATION_FAILED: 403005;
|
|
10
|
+
readonly BAD_GATEWAY: 502000;
|
|
11
|
+
readonly BAD_REQUEST: 400000;
|
|
12
|
+
readonly CONTAINS_INVALID_REQUEST_HEADERS: 400001;
|
|
13
|
+
readonly EMAIL_CODE_INVALID: 401004;
|
|
14
|
+
readonly EMAIL_SENDING_FAILED: 400005;
|
|
15
|
+
readonly EMAIL_SENDING_LIMIT_DAY: 400006;
|
|
16
|
+
readonly EMAIL_SENDING_LIMIT_MINUTE: 400007;
|
|
17
|
+
readonly FORBIDDEN: 403000;
|
|
18
|
+
readonly INTERNAL_SERVER_ERROR: 500000;
|
|
19
|
+
readonly INTERNAL_SERVER_REQUEST_TIMEOUT: 408001;
|
|
20
|
+
readonly INTERNAL_SERVER_SIGNATURE_VERIFICATION_FAILED: 401002;
|
|
21
|
+
readonly INVALID_PAYMENT_CHANNEL: 400008;
|
|
22
|
+
readonly MISSING_SIGN_IN_ENTITY: 400009;
|
|
23
|
+
readonly MISSING_SUBSCRIPTION_USER_ENTITY: 400010;
|
|
24
|
+
readonly NOT_FOUND: 404000;
|
|
25
|
+
readonly NOT_SUBSCRIBED: 403002;
|
|
26
|
+
readonly OR_VALIDATION_PARAMETER_INVALID: 400002;
|
|
27
|
+
readonly PASSWORD_HAS_EXPIRED: 401006;
|
|
28
|
+
readonly PASSWORD_IS_INVALID: 401007;
|
|
29
|
+
readonly PROHIBITED_OPERATIONS: 403001;
|
|
30
|
+
readonly PROHIBITED_RESET_PASSWORD: 403003;
|
|
31
|
+
readonly REQUEST_TIMEOUT: 408000;
|
|
32
|
+
readonly SERVICE_FIELDS_ALREADY_EXISTS: 400003;
|
|
33
|
+
readonly SIGNATURE_STRING_LENGTH_LIMIT: 400004;
|
|
34
|
+
readonly TOKEN_IS_NOT_FOUND: 401001;
|
|
35
|
+
readonly UNAUTHORIZED: 401000;
|
|
36
|
+
readonly UNPROCESSABLE_ENTITY: 422000;
|
|
37
|
+
readonly USER_DEACTIVATED: 401005;
|
|
38
|
+
};
|
|
39
|
+
type HttpExceptionCode = (typeof HTTP_EXCEPTION_CODE)[keyof typeof HTTP_EXCEPTION_CODE];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Normalized error body returned by Bearei HTTP APIs.
|
|
43
|
+
* Services may return codes outside `HTTP_EXCEPTION_CODE`, so `code` stays numeric.
|
|
44
|
+
*/
|
|
45
|
+
interface ApiErrorBody {
|
|
46
|
+
code: number;
|
|
47
|
+
message: string;
|
|
48
|
+
statusCode: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare const RESERVED_REQUEST_HEADER: {
|
|
52
|
+
readonly CLIENT: "x-bearei-client";
|
|
53
|
+
readonly DOMAIN_ID: "x-bearei-domain-id";
|
|
54
|
+
readonly INTERNAL_AUTHORIZATION: "x-bearei-internal-authorization";
|
|
55
|
+
readonly IP: "x-bearei-ip";
|
|
56
|
+
readonly SUBJECT: "x-bearei-subject";
|
|
57
|
+
readonly SUBSCRIPTION: "x-bearei-subscription";
|
|
58
|
+
};
|
|
59
|
+
type ReservedRequestHeaderName = (typeof RESERVED_REQUEST_HEADER)[keyof typeof RESERVED_REQUEST_HEADER];
|
|
60
|
+
|
|
61
|
+
declare const LANGUAGE: {
|
|
62
|
+
readonly EN_US: "EN_US";
|
|
63
|
+
readonly ZH_CN: "ZH_CN";
|
|
64
|
+
};
|
|
65
|
+
type Language = (typeof LANGUAGE)[keyof typeof LANGUAGE];
|
|
66
|
+
|
|
67
|
+
declare const ORDER: {
|
|
68
|
+
readonly ASC: "ASC";
|
|
69
|
+
readonly DESC: "DESC";
|
|
70
|
+
};
|
|
71
|
+
type Order = (typeof ORDER)[keyof typeof ORDER];
|
|
72
|
+
|
|
73
|
+
declare const DEFAULT_PAGE_SIZE = 10;
|
|
74
|
+
declare const MAX_PAGE_SIZE = 1024;
|
|
75
|
+
interface PaginationQuery {
|
|
76
|
+
page?: number;
|
|
77
|
+
pageSize?: number;
|
|
78
|
+
}
|
|
79
|
+
interface PaginatedResult<T> {
|
|
80
|
+
page: number;
|
|
81
|
+
pageSize: number;
|
|
82
|
+
results: T[];
|
|
83
|
+
/** Present only when a total was requested for the first page. */
|
|
84
|
+
total?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { DEFAULT_PAGE_SIZE, HTTP_EXCEPTION_CODE, LANGUAGE, MAX_PAGE_SIZE, ORDER, RESERVED_REQUEST_HEADER };
|
|
88
|
+
export type { ApiErrorBody, HttpExceptionCode, Language, Order, PaginatedResult, PaginationQuery, ReservedRequestHeaderName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numeric error codes shared by Bearei services and clients.
|
|
3
|
+
* Values are part of the wire contract: append new codes, never renumber or reuse.
|
|
4
|
+
*/
|
|
5
|
+
declare const HTTP_EXCEPTION_CODE: {
|
|
6
|
+
readonly ACCESS_DENIED_FOR_GUEST: 401003;
|
|
7
|
+
readonly APPLE_IAP_TRANSACTION_NOT_COMPLETED: 403004;
|
|
8
|
+
readonly APPLE_IAP_TRANSACTION_UNAUTHORIZED: 401008;
|
|
9
|
+
readonly APPLE_IAP_TRANSACTION_VERIFICATION_FAILED: 403005;
|
|
10
|
+
readonly BAD_GATEWAY: 502000;
|
|
11
|
+
readonly BAD_REQUEST: 400000;
|
|
12
|
+
readonly CONTAINS_INVALID_REQUEST_HEADERS: 400001;
|
|
13
|
+
readonly EMAIL_CODE_INVALID: 401004;
|
|
14
|
+
readonly EMAIL_SENDING_FAILED: 400005;
|
|
15
|
+
readonly EMAIL_SENDING_LIMIT_DAY: 400006;
|
|
16
|
+
readonly EMAIL_SENDING_LIMIT_MINUTE: 400007;
|
|
17
|
+
readonly FORBIDDEN: 403000;
|
|
18
|
+
readonly INTERNAL_SERVER_ERROR: 500000;
|
|
19
|
+
readonly INTERNAL_SERVER_REQUEST_TIMEOUT: 408001;
|
|
20
|
+
readonly INTERNAL_SERVER_SIGNATURE_VERIFICATION_FAILED: 401002;
|
|
21
|
+
readonly INVALID_PAYMENT_CHANNEL: 400008;
|
|
22
|
+
readonly MISSING_SIGN_IN_ENTITY: 400009;
|
|
23
|
+
readonly MISSING_SUBSCRIPTION_USER_ENTITY: 400010;
|
|
24
|
+
readonly NOT_FOUND: 404000;
|
|
25
|
+
readonly NOT_SUBSCRIBED: 403002;
|
|
26
|
+
readonly OR_VALIDATION_PARAMETER_INVALID: 400002;
|
|
27
|
+
readonly PASSWORD_HAS_EXPIRED: 401006;
|
|
28
|
+
readonly PASSWORD_IS_INVALID: 401007;
|
|
29
|
+
readonly PROHIBITED_OPERATIONS: 403001;
|
|
30
|
+
readonly PROHIBITED_RESET_PASSWORD: 403003;
|
|
31
|
+
readonly REQUEST_TIMEOUT: 408000;
|
|
32
|
+
readonly SERVICE_FIELDS_ALREADY_EXISTS: 400003;
|
|
33
|
+
readonly SIGNATURE_STRING_LENGTH_LIMIT: 400004;
|
|
34
|
+
readonly TOKEN_IS_NOT_FOUND: 401001;
|
|
35
|
+
readonly UNAUTHORIZED: 401000;
|
|
36
|
+
readonly UNPROCESSABLE_ENTITY: 422000;
|
|
37
|
+
readonly USER_DEACTIVATED: 401005;
|
|
38
|
+
};
|
|
39
|
+
type HttpExceptionCode = (typeof HTTP_EXCEPTION_CODE)[keyof typeof HTTP_EXCEPTION_CODE];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Normalized error body returned by Bearei HTTP APIs.
|
|
43
|
+
* Services may return codes outside `HTTP_EXCEPTION_CODE`, so `code` stays numeric.
|
|
44
|
+
*/
|
|
45
|
+
interface ApiErrorBody {
|
|
46
|
+
code: number;
|
|
47
|
+
message: string;
|
|
48
|
+
statusCode: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare const RESERVED_REQUEST_HEADER: {
|
|
52
|
+
readonly CLIENT: "x-bearei-client";
|
|
53
|
+
readonly DOMAIN_ID: "x-bearei-domain-id";
|
|
54
|
+
readonly INTERNAL_AUTHORIZATION: "x-bearei-internal-authorization";
|
|
55
|
+
readonly IP: "x-bearei-ip";
|
|
56
|
+
readonly SUBJECT: "x-bearei-subject";
|
|
57
|
+
readonly SUBSCRIPTION: "x-bearei-subscription";
|
|
58
|
+
};
|
|
59
|
+
type ReservedRequestHeaderName = (typeof RESERVED_REQUEST_HEADER)[keyof typeof RESERVED_REQUEST_HEADER];
|
|
60
|
+
|
|
61
|
+
declare const LANGUAGE: {
|
|
62
|
+
readonly EN_US: "EN_US";
|
|
63
|
+
readonly ZH_CN: "ZH_CN";
|
|
64
|
+
};
|
|
65
|
+
type Language = (typeof LANGUAGE)[keyof typeof LANGUAGE];
|
|
66
|
+
|
|
67
|
+
declare const ORDER: {
|
|
68
|
+
readonly ASC: "ASC";
|
|
69
|
+
readonly DESC: "DESC";
|
|
70
|
+
};
|
|
71
|
+
type Order = (typeof ORDER)[keyof typeof ORDER];
|
|
72
|
+
|
|
73
|
+
declare const DEFAULT_PAGE_SIZE = 10;
|
|
74
|
+
declare const MAX_PAGE_SIZE = 1024;
|
|
75
|
+
interface PaginationQuery {
|
|
76
|
+
page?: number;
|
|
77
|
+
pageSize?: number;
|
|
78
|
+
}
|
|
79
|
+
interface PaginatedResult<T> {
|
|
80
|
+
page: number;
|
|
81
|
+
pageSize: number;
|
|
82
|
+
results: T[];
|
|
83
|
+
/** Present only when a total was requested for the first page. */
|
|
84
|
+
total?: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { DEFAULT_PAGE_SIZE, HTTP_EXCEPTION_CODE, LANGUAGE, MAX_PAGE_SIZE, ORDER, RESERVED_REQUEST_HEADER };
|
|
88
|
+
export type { ApiErrorBody, HttpExceptionCode, Language, Order, PaginatedResult, PaginationQuery, ReservedRequestHeaderName };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DEFAULT_PAGE_SIZE: () => DEFAULT_PAGE_SIZE,
|
|
24
|
+
HTTP_EXCEPTION_CODE: () => HTTP_EXCEPTION_CODE,
|
|
25
|
+
LANGUAGE: () => LANGUAGE,
|
|
26
|
+
MAX_PAGE_SIZE: () => MAX_PAGE_SIZE,
|
|
27
|
+
ORDER: () => ORDER,
|
|
28
|
+
RESERVED_REQUEST_HEADER: () => RESERVED_REQUEST_HEADER
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/error-code.ts
|
|
33
|
+
var HTTP_EXCEPTION_CODE = {
|
|
34
|
+
ACCESS_DENIED_FOR_GUEST: 401003,
|
|
35
|
+
APPLE_IAP_TRANSACTION_NOT_COMPLETED: 403004,
|
|
36
|
+
APPLE_IAP_TRANSACTION_UNAUTHORIZED: 401008,
|
|
37
|
+
APPLE_IAP_TRANSACTION_VERIFICATION_FAILED: 403005,
|
|
38
|
+
BAD_GATEWAY: 502e3,
|
|
39
|
+
BAD_REQUEST: 4e5,
|
|
40
|
+
CONTAINS_INVALID_REQUEST_HEADERS: 400001,
|
|
41
|
+
EMAIL_CODE_INVALID: 401004,
|
|
42
|
+
EMAIL_SENDING_FAILED: 400005,
|
|
43
|
+
EMAIL_SENDING_LIMIT_DAY: 400006,
|
|
44
|
+
EMAIL_SENDING_LIMIT_MINUTE: 400007,
|
|
45
|
+
FORBIDDEN: 403e3,
|
|
46
|
+
INTERNAL_SERVER_ERROR: 5e5,
|
|
47
|
+
INTERNAL_SERVER_REQUEST_TIMEOUT: 408001,
|
|
48
|
+
INTERNAL_SERVER_SIGNATURE_VERIFICATION_FAILED: 401002,
|
|
49
|
+
INVALID_PAYMENT_CHANNEL: 400008,
|
|
50
|
+
MISSING_SIGN_IN_ENTITY: 400009,
|
|
51
|
+
MISSING_SUBSCRIPTION_USER_ENTITY: 400010,
|
|
52
|
+
NOT_FOUND: 404e3,
|
|
53
|
+
NOT_SUBSCRIBED: 403002,
|
|
54
|
+
OR_VALIDATION_PARAMETER_INVALID: 400002,
|
|
55
|
+
PASSWORD_HAS_EXPIRED: 401006,
|
|
56
|
+
PASSWORD_IS_INVALID: 401007,
|
|
57
|
+
PROHIBITED_OPERATIONS: 403001,
|
|
58
|
+
PROHIBITED_RESET_PASSWORD: 403003,
|
|
59
|
+
REQUEST_TIMEOUT: 408e3,
|
|
60
|
+
SERVICE_FIELDS_ALREADY_EXISTS: 400003,
|
|
61
|
+
SIGNATURE_STRING_LENGTH_LIMIT: 400004,
|
|
62
|
+
TOKEN_IS_NOT_FOUND: 401001,
|
|
63
|
+
UNAUTHORIZED: 401e3,
|
|
64
|
+
UNPROCESSABLE_ENTITY: 422e3,
|
|
65
|
+
USER_DEACTIVATED: 401005
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/header.ts
|
|
69
|
+
var RESERVED_REQUEST_HEADER = {
|
|
70
|
+
CLIENT: "x-bearei-client",
|
|
71
|
+
DOMAIN_ID: "x-bearei-domain-id",
|
|
72
|
+
INTERNAL_AUTHORIZATION: "x-bearei-internal-authorization",
|
|
73
|
+
IP: "x-bearei-ip",
|
|
74
|
+
SUBJECT: "x-bearei-subject",
|
|
75
|
+
SUBSCRIPTION: "x-bearei-subscription"
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/language.ts
|
|
79
|
+
var LANGUAGE = {
|
|
80
|
+
EN_US: "EN_US",
|
|
81
|
+
ZH_CN: "ZH_CN"
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/order.ts
|
|
85
|
+
var ORDER = {
|
|
86
|
+
ASC: "ASC",
|
|
87
|
+
DESC: "DESC"
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/pagination.ts
|
|
91
|
+
var DEFAULT_PAGE_SIZE = 10;
|
|
92
|
+
var MAX_PAGE_SIZE = 1024;
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
DEFAULT_PAGE_SIZE,
|
|
96
|
+
HTTP_EXCEPTION_CODE,
|
|
97
|
+
LANGUAGE,
|
|
98
|
+
MAX_PAGE_SIZE,
|
|
99
|
+
ORDER,
|
|
100
|
+
RESERVED_REQUEST_HEADER
|
|
101
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/error-code.ts
|
|
2
|
+
var HTTP_EXCEPTION_CODE = {
|
|
3
|
+
ACCESS_DENIED_FOR_GUEST: 401003,
|
|
4
|
+
APPLE_IAP_TRANSACTION_NOT_COMPLETED: 403004,
|
|
5
|
+
APPLE_IAP_TRANSACTION_UNAUTHORIZED: 401008,
|
|
6
|
+
APPLE_IAP_TRANSACTION_VERIFICATION_FAILED: 403005,
|
|
7
|
+
BAD_GATEWAY: 502e3,
|
|
8
|
+
BAD_REQUEST: 4e5,
|
|
9
|
+
CONTAINS_INVALID_REQUEST_HEADERS: 400001,
|
|
10
|
+
EMAIL_CODE_INVALID: 401004,
|
|
11
|
+
EMAIL_SENDING_FAILED: 400005,
|
|
12
|
+
EMAIL_SENDING_LIMIT_DAY: 400006,
|
|
13
|
+
EMAIL_SENDING_LIMIT_MINUTE: 400007,
|
|
14
|
+
FORBIDDEN: 403e3,
|
|
15
|
+
INTERNAL_SERVER_ERROR: 5e5,
|
|
16
|
+
INTERNAL_SERVER_REQUEST_TIMEOUT: 408001,
|
|
17
|
+
INTERNAL_SERVER_SIGNATURE_VERIFICATION_FAILED: 401002,
|
|
18
|
+
INVALID_PAYMENT_CHANNEL: 400008,
|
|
19
|
+
MISSING_SIGN_IN_ENTITY: 400009,
|
|
20
|
+
MISSING_SUBSCRIPTION_USER_ENTITY: 400010,
|
|
21
|
+
NOT_FOUND: 404e3,
|
|
22
|
+
NOT_SUBSCRIBED: 403002,
|
|
23
|
+
OR_VALIDATION_PARAMETER_INVALID: 400002,
|
|
24
|
+
PASSWORD_HAS_EXPIRED: 401006,
|
|
25
|
+
PASSWORD_IS_INVALID: 401007,
|
|
26
|
+
PROHIBITED_OPERATIONS: 403001,
|
|
27
|
+
PROHIBITED_RESET_PASSWORD: 403003,
|
|
28
|
+
REQUEST_TIMEOUT: 408e3,
|
|
29
|
+
SERVICE_FIELDS_ALREADY_EXISTS: 400003,
|
|
30
|
+
SIGNATURE_STRING_LENGTH_LIMIT: 400004,
|
|
31
|
+
TOKEN_IS_NOT_FOUND: 401001,
|
|
32
|
+
UNAUTHORIZED: 401e3,
|
|
33
|
+
UNPROCESSABLE_ENTITY: 422e3,
|
|
34
|
+
USER_DEACTIVATED: 401005
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/header.ts
|
|
38
|
+
var RESERVED_REQUEST_HEADER = {
|
|
39
|
+
CLIENT: "x-bearei-client",
|
|
40
|
+
DOMAIN_ID: "x-bearei-domain-id",
|
|
41
|
+
INTERNAL_AUTHORIZATION: "x-bearei-internal-authorization",
|
|
42
|
+
IP: "x-bearei-ip",
|
|
43
|
+
SUBJECT: "x-bearei-subject",
|
|
44
|
+
SUBSCRIPTION: "x-bearei-subscription"
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/language.ts
|
|
48
|
+
var LANGUAGE = {
|
|
49
|
+
EN_US: "EN_US",
|
|
50
|
+
ZH_CN: "ZH_CN"
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/order.ts
|
|
54
|
+
var ORDER = {
|
|
55
|
+
ASC: "ASC",
|
|
56
|
+
DESC: "DESC"
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/pagination.ts
|
|
60
|
+
var DEFAULT_PAGE_SIZE = 10;
|
|
61
|
+
var MAX_PAGE_SIZE = 1024;
|
|
62
|
+
export {
|
|
63
|
+
DEFAULT_PAGE_SIZE,
|
|
64
|
+
HTTP_EXCEPTION_CODE,
|
|
65
|
+
LANGUAGE,
|
|
66
|
+
MAX_PAGE_SIZE,
|
|
67
|
+
ORDER,
|
|
68
|
+
RESERVED_REQUEST_HEADER
|
|
69
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bearei/contracts",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.0-dev.3",
|
|
4
|
+
"description": "Framework-agnostic wire contracts shared by Bearei services, clients and apps",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bearei",
|
|
7
|
+
"contracts",
|
|
8
|
+
"shared",
|
|
9
|
+
"types"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/bear-ei/contracts#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/bear-ei/contracts/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/bear-ei/contracts.git"
|
|
18
|
+
},
|
|
19
|
+
"author": "bearei <bear_ei@outlook.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"module": "./dist/index.mjs",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@bearei/eslint-config": "^2.0.0",
|
|
49
|
+
"@bearei/jest-preset": "^2.0.0",
|
|
50
|
+
"@bearei/tsconfig": "^2.0.0",
|
|
51
|
+
"@types/jest": "^29.5.13",
|
|
52
|
+
"eslint": "^9.37.0",
|
|
53
|
+
"jest": "^29.7.0",
|
|
54
|
+
"prettier": "^3.9.6",
|
|
55
|
+
"ts-jest": "^29.1.0",
|
|
56
|
+
"tsup": "^9.0.0",
|
|
57
|
+
"typescript": "^5.9.3"
|
|
58
|
+
},
|
|
59
|
+
"jest": {
|
|
60
|
+
"preset": "@bearei/jest-preset/nest",
|
|
61
|
+
"rootDir": ".",
|
|
62
|
+
"collectCoverageFrom": [
|
|
63
|
+
"src/**/*.ts",
|
|
64
|
+
"!src/**/*.spec.ts",
|
|
65
|
+
"!src/**/*.interface.ts",
|
|
66
|
+
"!src/index.ts"
|
|
67
|
+
],
|
|
68
|
+
"coverageThreshold": {
|
|
69
|
+
"global": {
|
|
70
|
+
"branches": 90,
|
|
71
|
+
"functions": 90,
|
|
72
|
+
"lines": 90,
|
|
73
|
+
"statements": 90
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "tsup",
|
|
79
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
80
|
+
"pack": "yarn pack -o /tmp/bearei-contracts.tgz && bash .github/scripts/verify-tarball.sh /tmp/bearei-contracts.tgz",
|
|
81
|
+
"prepack": "yarn build",
|
|
82
|
+
"test": "jest",
|
|
83
|
+
"test:coverage": "jest --coverage",
|
|
84
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
85
|
+
"verify": "yarn lint && yarn typecheck && yarn test:coverage && yarn build"
|
|
86
|
+
},
|
|
87
|
+
"packageManager": "yarn@4.18.0"
|
|
6
88
|
}
|