feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
# @coze-foundation/enterprise-store-adapter
|
||||
|
||||
store for enterprise
|
||||
|
||||
## Overview
|
||||
|
||||
This package is part of the Coze Studio monorepo and provides state management functionality. It includes hook, store.
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Installation
|
||||
|
||||
Add this package to your `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@coze-foundation/enterprise-store-adapter": "workspace:*"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
rush update
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```typescript
|
||||
import { /* exported functions/components */ } from '@coze-foundation/enterprise-store-adapter';
|
||||
|
||||
// Example usage
|
||||
// TODO: Add specific usage examples
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Hook
|
||||
- Store
|
||||
|
||||
## API Reference
|
||||
|
||||
### Exports
|
||||
|
||||
- `PERSONAL_ENTERPRISE_ID`
|
||||
- `useEnterpriseStore`
|
||||
- `useEnterpriseList`
|
||||
- `useCheckEnterpriseExist`
|
||||
- `useCurrentEnterpriseInfo,
|
||||
useCurrentEnterpriseId,
|
||||
useIsCurrentPersonalEnterprise,
|
||||
useCurrentEnterpriseRoles,
|
||||
useIsEnterpriseLevel,
|
||||
useIsTeamLevel,
|
||||
useIsCurrentEnterpriseInit,
|
||||
CurrentEnterpriseInfoProps,`
|
||||
- `switchEnterprise`
|
||||
- `isPersonalEnterprise`
|
||||
|
||||
|
||||
For detailed API documentation, please refer to the TypeScript definitions.
|
||||
|
||||
## Development
|
||||
|
||||
This package is built with:
|
||||
|
||||
- TypeScript
|
||||
- Modern JavaScript
|
||||
- Vitest for testing
|
||||
- ESLint for code quality
|
||||
|
||||
## Contributing
|
||||
|
||||
This package is part of the Coze Studio monorepo. Please follow the monorepo contribution guidelines.
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
|
||||
import { useEnterpriseStore } from '../../src/stores/enterprise';
|
||||
import { useCheckEnterpriseExist } from '../../src/hooks/use-check-enterprise-exist';
|
||||
|
||||
// Mock the enterprise store
|
||||
vi.mock('../../src/stores/enterprise', () => ({
|
||||
useEnterpriseStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('useCheckEnterpriseExist', () => {
|
||||
const mockIsEnterpriseExist = true;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
isEnterpriseExist: mockIsEnterpriseExist,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should return enterprise exist status and check function', () => {
|
||||
const { result } = renderHook(() => useCheckEnterpriseExist());
|
||||
|
||||
expect(result.current).toEqual({
|
||||
checkEnterpriseExist: expect.any(Function),
|
||||
checkEnterpriseExistLoading: false,
|
||||
isEnterpriseExist: mockIsEnterpriseExist,
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false when enterprise does not exist', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
isEnterpriseExist: false,
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useCheckEnterpriseExist());
|
||||
|
||||
expect(result.current.isEnterpriseExist).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
import { Level } from '@coze-arch/bot-api/pat_permission_api';
|
||||
|
||||
import { useEnterpriseStore } from '../../src/stores/enterprise';
|
||||
import {
|
||||
useCurrentEnterpriseInfo,
|
||||
useCurrentEnterpriseId,
|
||||
useIsCurrentPersonalEnterprise,
|
||||
useCurrentEnterpriseRoles,
|
||||
useIsEnterpriseLevel,
|
||||
useIsTeamLevel,
|
||||
useIsCurrentEnterpriseInit,
|
||||
} from '../../src/hooks/use-current-enterprise-info';
|
||||
import { PERSONAL_ENTERPRISE_ID } from '../../src/constants';
|
||||
|
||||
// Mock the enterprise store
|
||||
vi.mock('../../src/stores/enterprise', () => ({
|
||||
useEnterpriseStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('useCurrentEnterpriseInfo and related hooks', () => {
|
||||
const mockCurrentEnterprise = {
|
||||
id: 'enterprise-1',
|
||||
name: 'Enterprise 1',
|
||||
enterprise_role_type_list: ['admin'],
|
||||
level: Level.enterprise,
|
||||
default_organization_id: 'org-1',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
currentEnterprise: mockCurrentEnterprise,
|
||||
enterpriseId: mockCurrentEnterprise.id,
|
||||
isInit: true,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
describe('useCurrentEnterpriseInfo', () => {
|
||||
it('should return null for personal enterprise', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
enterpriseId: PERSONAL_ENTERPRISE_ID,
|
||||
currentEnterprise: null,
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useCurrentEnterpriseInfo());
|
||||
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null when enterprise is null', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
enterpriseId: 'enterprise-1',
|
||||
currentEnterprise: null,
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useCurrentEnterpriseInfo());
|
||||
|
||||
expect(result.current).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('useCurrentEnterpriseId', () => {
|
||||
it('should return current enterprise id', () => {
|
||||
const { result } = renderHook(() => useCurrentEnterpriseId());
|
||||
|
||||
expect(result.current).toBe(mockCurrentEnterprise.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useIsCurrentPersonalEnterprise', () => {
|
||||
it('should return true for personal enterprise', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
enterpriseId: PERSONAL_ENTERPRISE_ID,
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useIsCurrentPersonalEnterprise());
|
||||
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for ersonal enterprise', () => {
|
||||
const { result } = renderHook(() => useIsCurrentPersonalEnterprise());
|
||||
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useCurrentEnterpriseRoles', () => {
|
||||
it('should return empty array for personal enterprise', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
enterpriseId: PERSONAL_ENTERPRISE_ID,
|
||||
currentEnterprise: null,
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useCurrentEnterpriseRoles());
|
||||
|
||||
expect(result.current).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return empty array when enterprise roles are undefined', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
enterpriseId: 'enterprise-1',
|
||||
currentEnterprise: {
|
||||
...mockCurrentEnterprise,
|
||||
enterprise_role_type_list: undefined,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useCurrentEnterpriseRoles());
|
||||
|
||||
expect(result.current).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useIsEnterpriseLevel', () => {
|
||||
it('should return false for non-enterprise level', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
currentEnterprise: { ...mockCurrentEnterprise, level: Level.team },
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useIsEnterpriseLevel());
|
||||
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when enterprise info is null', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
currentEnterprise: null,
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useIsEnterpriseLevel());
|
||||
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useIsTeamLevel', () => {
|
||||
it('should return false for non-team level', () => {
|
||||
const { result } = renderHook(() => useIsTeamLevel());
|
||||
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when enterprise info is null', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
currentEnterprise: null,
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useIsTeamLevel());
|
||||
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useIsCurrentEnterpriseInit', () => {
|
||||
it('should return false when enterprise is not initialized', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
isCurrentEnterpriseInit: false,
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useIsCurrentEnterpriseInit());
|
||||
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { renderHook } from '@testing-library/react-hooks';
|
||||
|
||||
import { useEnterpriseStore } from '../../src/stores/enterprise';
|
||||
import { useEnterpriseList } from '../../src/hooks/use-enterprise-list';
|
||||
|
||||
// Mock the enterprise store
|
||||
vi.mock('../../src/stores/enterprise', () => ({
|
||||
useEnterpriseStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('useEnterpriseList', () => {
|
||||
const mockEnterpriseList = [
|
||||
{ id: 'enterprise-1', name: 'Enterprise 1' },
|
||||
{ id: 'enterprise-2', name: 'Enterprise 2' },
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
enterpriseList: {
|
||||
enterprise_info_list: mockEnterpriseList,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should return enterprise list from store', () => {
|
||||
const { result } = renderHook(() => useEnterpriseList());
|
||||
|
||||
expect(result.current).toEqual(mockEnterpriseList);
|
||||
});
|
||||
|
||||
it('should return empty array when store has no enterprise list', () => {
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
enterpriseList: {},
|
||||
}),
|
||||
);
|
||||
|
||||
const { result } = renderHook(() => useEnterpriseList());
|
||||
|
||||
expect(result.current).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
import { isPersonalEnterprise } from '../../src/utils/personal';
|
||||
import { PERSONAL_ENTERPRISE_ID } from '../../src/constants';
|
||||
|
||||
describe('isPersonalEnterprise', () => {
|
||||
it('should return true for personal enterprise id', () => {
|
||||
expect(isPersonalEnterprise(PERSONAL_ENTERPRISE_ID)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for non-personal enterprise id', () => {
|
||||
expect(isPersonalEnterprise('enterprise-1')).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
import { switchEnterprise } from '../../src/utils/switch-enterprise';
|
||||
import { useEnterpriseStore } from '../../src/stores/enterprise';
|
||||
|
||||
// Mock the enterprise store
|
||||
vi.mock('../../src/stores/enterprise', () => ({
|
||||
useEnterpriseStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('switchEnterprise', () => {
|
||||
const mockSetCurrentEnterprise = vi.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
(useEnterpriseStore as any).mockImplementation((selector: any) =>
|
||||
selector({
|
||||
setCurrentEnterprise: mockSetCurrentEnterprise,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should switch to the specified enterprise', () => {
|
||||
const enterpriseId = 'enterprise-1';
|
||||
switchEnterprise(enterpriseId);
|
||||
|
||||
expect(mockSetCurrentEnterprise).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["./dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "@coze-foundation/enterprise-store-adapter",
|
||||
"version": "0.0.1",
|
||||
"description": "store for enterprise",
|
||||
"license": "Apache-2.0",
|
||||
"author": "sunzhiyuan.evan@bytedance.com",
|
||||
"maintainers": [],
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-arch/bot-api": "workspace:*",
|
||||
"@coze-arch/idl": "workspace:*",
|
||||
"@coze-foundation/local-storage": "workspace:*",
|
||||
"ahooks": "^3.7.8",
|
||||
"classnames": "^2.3.2",
|
||||
"immer": "^10.0.3",
|
||||
"zustand": "^4.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/bot-typings": "workspace:*",
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"stylelint": "^15.11.0",
|
||||
"vite": "^4.3.9",
|
||||
"vite-plugin-svgr": "~3.3.0",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const PERSONAL_ENTERPRISE_ID = 'personal';
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
|
||||
*/
|
||||
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { useShallow } from 'zustand/react/shallow';
|
||||
|
||||
import { useEnterpriseStore } from '../stores/enterprise';
|
||||
export const useCheckEnterpriseExist = () => {
|
||||
const { isEnterpriseExist } = useEnterpriseStore(
|
||||
useShallow(store => ({
|
||||
isEnterpriseExist: store.isEnterpriseExist,
|
||||
})),
|
||||
);
|
||||
const checkEnterpriseExist = useCallback(() => {
|
||||
console.log('checkEnterpriseExist');
|
||||
}, []);
|
||||
|
||||
return {
|
||||
checkEnterpriseExist,
|
||||
checkEnterpriseExistLoading: false,
|
||||
isEnterpriseExist,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
|
||||
*/
|
||||
import { type GetEnterpriseResponseData } from '@coze-arch/bot-api/pat_permission_api';
|
||||
|
||||
import { useEnterpriseStore } from '../stores/enterprise';
|
||||
|
||||
export interface CurrentEnterpriseInfoProps extends GetEnterpriseResponseData {
|
||||
organization_id: string | undefined;
|
||||
}
|
||||
/**
|
||||
* 获取当前企业信息。
|
||||
* 如果当前企业为个人版,则返回null。
|
||||
* 否则,返回当前企业信息,包括企业信息和组织ID。
|
||||
* @example
|
||||
* const { organization_id, enterprise_id } = useCurrentEnterpriseInfo();
|
||||
* @returns {(GetEnterpriseResponseData & { organization_id: string | undefined }) | null} 当前企业信息或null
|
||||
*/
|
||||
export const useCurrentEnterpriseInfo: () => CurrentEnterpriseInfoProps | null =
|
||||
() => null;
|
||||
|
||||
/**
|
||||
* 获取当前企业ID。
|
||||
* 如果当前企业类型为个人版,则返回约定的字符串。
|
||||
* 否则,返回当前企业的ID。
|
||||
* @returns {string} 当前企业ID
|
||||
*/
|
||||
export const useCurrentEnterpriseId = () =>
|
||||
useEnterpriseStore(store => store.enterpriseId);
|
||||
|
||||
/**
|
||||
* 检查当前企业是否为个人版。
|
||||
* @returns {boolean} 如果当前企业为个人版,则返回true,否则返回false。
|
||||
*/
|
||||
export const useIsCurrentPersonalEnterprise = () => true;
|
||||
|
||||
/**
|
||||
* 获取当前企业的角色列表。
|
||||
* 如果当前企业类型为个人版,则返回空数组。
|
||||
* 否则,返回当前企业的角色类型列表,如果列表不存在,则返回空数组。
|
||||
* @returns {Array} 当前企业的角色列表
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const useCurrentEnterpriseRoles = (): any[] => [];
|
||||
|
||||
/** 是否是企业版 */
|
||||
export const useIsEnterpriseLevel = () => false;
|
||||
|
||||
/** 是否是团队版 */
|
||||
export const useIsTeamLevel = () => false;
|
||||
|
||||
export const useIsCurrentEnterpriseInit = () =>
|
||||
useEnterpriseStore(store => store.isCurrentEnterpriseInit);
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
|
||||
*/
|
||||
|
||||
import { useEnterpriseStore } from '../stores/enterprise';
|
||||
/**
|
||||
* 获取企业列表的hook。
|
||||
* 从企业store中获取企业列表,并返回企业信息列表。
|
||||
* @returns {Array} 企业信息列表
|
||||
*/
|
||||
export const useEnterpriseList = () => {
|
||||
const list = useEnterpriseStore(store => store.enterpriseList);
|
||||
|
||||
return list?.enterprise_info_list ?? [];
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
|
||||
*/
|
||||
|
||||
export { PERSONAL_ENTERPRISE_ID } from './constants';
|
||||
export { useEnterpriseStore } from './stores/enterprise';
|
||||
|
||||
export { useEnterpriseList } from './hooks/use-enterprise-list';
|
||||
export { useCheckEnterpriseExist } from './hooks/use-check-enterprise-exist';
|
||||
export {
|
||||
useCurrentEnterpriseInfo,
|
||||
useCurrentEnterpriseId,
|
||||
useIsCurrentPersonalEnterprise,
|
||||
useCurrentEnterpriseRoles,
|
||||
useIsEnterpriseLevel,
|
||||
useIsTeamLevel,
|
||||
useIsCurrentEnterpriseInit,
|
||||
CurrentEnterpriseInfoProps,
|
||||
} from './hooks/use-current-enterprise-info';
|
||||
|
||||
// 工具方法
|
||||
export { switchEnterprise } from './utils/switch-enterprise';
|
||||
export { isPersonalEnterprise } from './utils/personal';
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
|
||||
*/
|
||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
import { devtools } from 'zustand/middleware';
|
||||
import { create } from 'zustand';
|
||||
import {
|
||||
type GetEnterpriseResponseData,
|
||||
type ListEnterpriseResponseData,
|
||||
} from '@coze-arch/bot-api/pat_permission_api';
|
||||
|
||||
import { PERSONAL_ENTERPRISE_ID } from '../constants';
|
||||
|
||||
interface EnterpriseStoreState {
|
||||
currentEnterprise?: GetEnterpriseResponseData;
|
||||
isCurrentEnterpriseInit: boolean;
|
||||
enterpriseList?: ListEnterpriseResponseData;
|
||||
isEnterpriseListInit: boolean;
|
||||
enterpriseId: string;
|
||||
isEnterpriseExist: boolean;
|
||||
}
|
||||
|
||||
interface EnterpriseStoreAction {
|
||||
setEnterprise: (enterpriseInfo: GetEnterpriseResponseData) => void;
|
||||
updateEnterpriseByImmer: (
|
||||
update: (enterpriseInfo: GetEnterpriseResponseData) => void,
|
||||
) => void;
|
||||
setEnterpriseList: (enterpriseList: ListEnterpriseResponseData) => void;
|
||||
setIsCurrentEnterpriseInit: (isInit: boolean) => void;
|
||||
setIsEnterpriseListInit: (isInit: boolean) => void;
|
||||
setEnterpriseId: (enterpriseId: string) => void;
|
||||
clearEnterprise: () => void;
|
||||
fetchEnterprise: (enterpriseId: string) => Promise<void>;
|
||||
setIsEnterpriseExist: (isExist: boolean) => void;
|
||||
}
|
||||
|
||||
export const defaultState: EnterpriseStoreState = {
|
||||
isCurrentEnterpriseInit: true,
|
||||
isEnterpriseListInit: true,
|
||||
enterpriseId: PERSONAL_ENTERPRISE_ID,
|
||||
isEnterpriseExist: true,
|
||||
};
|
||||
|
||||
export const useEnterpriseStore = create<
|
||||
EnterpriseStoreState & EnterpriseStoreAction
|
||||
>()(
|
||||
// @ts-expect-error skip
|
||||
devtools(
|
||||
() => ({
|
||||
...defaultState,
|
||||
setEnterprise: (_: GetEnterpriseResponseData) => {},
|
||||
updateEnterpriseByImmer: (
|
||||
_: (enterpriseInfo: GetEnterpriseResponseData) => void,
|
||||
) => {},
|
||||
clearEnterprise: () => {},
|
||||
setEnterpriseId: (_: string) => {},
|
||||
setIsCurrentEnterpriseInit: (_: boolean) => {},
|
||||
setIsEnterpriseListInit: (_: boolean) => {},
|
||||
setEnterpriseList: (_: ListEnterpriseResponseData) => {},
|
||||
setIsEnterpriseExist: (_: boolean) => {},
|
||||
// 获取企业信息,可连续调用,不存在异步竞争问题。
|
||||
fetchEnterprise: (_: string) => {},
|
||||
}),
|
||||
{
|
||||
enabled: IS_DEV_MODE,
|
||||
name: 'botStudio.enterpriseStore',
|
||||
},
|
||||
),
|
||||
);
|
||||
19
frontend/packages/foundation/enterprise-store-adapter/src/typings.d.ts
vendored
Normal file
19
frontend/packages/foundation/enterprise-store-adapter/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
|
||||
declare const IS_DEV_MODE: boolean;
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
|
||||
*/
|
||||
|
||||
import { PERSONAL_ENTERPRISE_ID } from '../constants';
|
||||
|
||||
// 检查企业是否为个人版
|
||||
export const isPersonalEnterprise = (enterpriseId?: string) =>
|
||||
enterpriseId === PERSONAL_ENTERPRISE_ID;
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 切换企业
|
||||
* @param {string} enterpriseId - 企业ID
|
||||
*/
|
||||
export const switchEnterprise = (_: string) => Promise.resolve();
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler",
|
||||
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../arch/bot-api/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-typings/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/idl/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/eslint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/stylelint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/ts-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/vitest-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../local-storage/tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"exclude": ["**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["__tests__", "vitest.config.ts", "stories"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||
Reference in New Issue
Block a user