apaas-oapi-client 0.1.36 → 0.1.38

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/src/index.ts CHANGED
@@ -2,6 +2,33 @@ import dayjs from 'dayjs';
2
2
  import axios, { AxiosInstance, AxiosError } from 'axios';
3
3
  import { LoggerLevel } from './logger';
4
4
  import { functionLimiter } from './limiter';
5
+ import {
6
+ FIELD_TYPES,
7
+ SYSTEM_FIELDS,
8
+ LANGUAGE_CODES,
9
+ SCHEMA_GUIDELINES,
10
+ CREATE_OBJECT_EXAMPLE,
11
+ UPDATE_OBJECT_ADD_FIELD_EXAMPLE,
12
+ UPDATE_OBJECT_REPLACE_FIELD_EXAMPLE,
13
+ UPDATE_OBJECT_REMOVE_FIELD_EXAMPLE,
14
+ UPDATE_OBJECT_SETTINGS_EXAMPLE,
15
+ getSystemFields,
16
+ getCustomFieldTypes,
17
+ getFieldType,
18
+ isSystemField,
19
+ createMultilingualText,
20
+ extractMultilingualText,
21
+ type FieldTypeMetadata,
22
+ type MultilingualText,
23
+ type ObjectSettings,
24
+ type FieldTypeDefinition,
25
+ type EncryptType,
26
+ type FieldOperator,
27
+ type CreateFieldDefinition,
28
+ type UpdateFieldDefinition,
29
+ type CreateObjectDefinition,
30
+ type UpdateObjectDefinition
31
+ } from './field-types';
5
32
 
6
33
  /**
7
34
  * 批量操作结果
@@ -2410,10 +2437,258 @@ class Client {
2410
2437
  }
2411
2438
  }
2412
2439
  };
2440
+
2441
+ /**
2442
+ * 数据对象结构管理模块(Schema)
2443
+ */
2444
+ public schema = {
2445
+ /**
2446
+ * 批量创建数据对象(表)
2447
+ * @description 批量创建一个或多个数据对象
2448
+ * @param params 请求参数 { objects: Array }
2449
+ * @returns 接口返回结果
2450
+ */
2451
+ create: async (params: {
2452
+ objects: Array<{
2453
+ api_name: string;
2454
+ label: {
2455
+ zh_cn: string;
2456
+ en_us: string;
2457
+ };
2458
+ settings?: {
2459
+ allow_search_fields?: string[];
2460
+ display_name?: string;
2461
+ search_layout?: string[];
2462
+ };
2463
+ fields: Array<{
2464
+ api_name: string;
2465
+ label: {
2466
+ zh_cn: string;
2467
+ en_us: string;
2468
+ };
2469
+ type: {
2470
+ name: string;
2471
+ settings?: any;
2472
+ };
2473
+ encrypt_type?: string | null;
2474
+ }>;
2475
+ }>;
2476
+ }): Promise<any> => {
2477
+ const { objects } = params;
2478
+ await this.ensureTokenValid();
2479
+
2480
+ const url = `/v1/namespaces/${this.namespace}/objects/batch_create`;
2481
+
2482
+ this.log(LoggerLevel.info, `[schema.create] Creating ${objects.length} object(s)`);
2483
+ this.log(LoggerLevel.trace, `[schema.create] Request URL: ${this.axiosInstance.defaults.baseURL}${url}`);
2484
+ this.log(LoggerLevel.trace, `[schema.create] Request Body: ${JSON.stringify({ objects }, null, 2)}`);
2485
+
2486
+ const res = await this.axiosInstance.post(
2487
+ url,
2488
+ { objects },
2489
+ {
2490
+ headers: {
2491
+ Authorization: `${this.accessToken}`,
2492
+ 'Content-Type': 'application/json'
2493
+ }
2494
+ }
2495
+ );
2496
+
2497
+ this.log(LoggerLevel.debug, `[schema.create] Objects created: code=${res.data.code}`);
2498
+ this.log(LoggerLevel.trace, `[schema.create] Response: ${JSON.stringify(res.data)}`);
2499
+
2500
+ return res.data;
2501
+ },
2502
+
2503
+ /**
2504
+ * 批量更新数据对象(表)
2505
+ * @description 批量更新一个或多个数据对象的配置
2506
+ * @param params 请求参数 { objects: Array }
2507
+ * @returns 接口返回结果
2508
+ * @example
2509
+ * ```typescript
2510
+ * // 添加新字段
2511
+ * await client.schema.update({
2512
+ * objects: [{
2513
+ * api_name: 'my_object',
2514
+ * fields: [{
2515
+ * operator: 'add',
2516
+ * api_name: 'new_field',
2517
+ * label: { zh_cn: '新字段', en_us: 'New Field' },
2518
+ * type: { name: 'text', settings: { required: false } },
2519
+ * encrypt_type: 'none'
2520
+ * }]
2521
+ * }]
2522
+ * });
2523
+ *
2524
+ * // 修改现有字段
2525
+ * await client.schema.update({
2526
+ * objects: [{
2527
+ * api_name: 'my_object',
2528
+ * fields: [{
2529
+ * operator: 'replace',
2530
+ * api_name: 'existing_field',
2531
+ * label: { zh_cn: '新标签', en_us: 'New Label' }
2532
+ * }]
2533
+ * }]
2534
+ * });
2535
+ *
2536
+ * // 删除字段
2537
+ * await client.schema.update({
2538
+ * objects: [{
2539
+ * api_name: 'my_object',
2540
+ * fields: [{
2541
+ * operator: 'remove',
2542
+ * api_name: 'field_to_delete'
2543
+ * }]
2544
+ * }]
2545
+ * });
2546
+ * ```
2547
+ */
2548
+ update: async (params: {
2549
+ objects: Array<{
2550
+ api_name: string;
2551
+ label?: {
2552
+ zh_cn: string;
2553
+ en_us: string;
2554
+ };
2555
+ settings?: {
2556
+ allow_search_fields?: string[];
2557
+ display_name?: string;
2558
+ search_layout?: string[];
2559
+ };
2560
+ fields?: Array<{
2561
+ /** 操作类型:add=添加字段, replace=修改字段, remove=删除字段 */
2562
+ operator: 'add' | 'replace' | 'remove';
2563
+ /** 字段 API 名称 */
2564
+ api_name: string;
2565
+ /** 字段标签(可选,operator=add 和 replace 时使用) */
2566
+ label?: {
2567
+ zh_cn: string;
2568
+ en_us: string;
2569
+ };
2570
+ /** 字段类型(可选,operator=add 和 replace 时使用) */
2571
+ type?: {
2572
+ name: string;
2573
+ settings?: any;
2574
+ };
2575
+ /** 加密类型(可选) */
2576
+ encrypt_type?: string | null;
2577
+ }>;
2578
+ }>;
2579
+ }): Promise<any> => {
2580
+ const { objects } = params;
2581
+ await this.ensureTokenValid();
2582
+
2583
+ const url = `/v1/namespaces/${this.namespace}/objects/batch_update`;
2584
+
2585
+ this.log(LoggerLevel.info, `[schema.update] Updating ${objects.length} object(s)`);
2586
+ this.log(LoggerLevel.trace, `[schema.update] Request URL: ${this.axiosInstance.defaults.baseURL}${url}`);
2587
+ this.log(LoggerLevel.trace, `[schema.update] Request Body: ${JSON.stringify({ objects }, null, 2)}`);
2588
+
2589
+ const res = await this.axiosInstance.post(
2590
+ url,
2591
+ { objects },
2592
+ {
2593
+ headers: {
2594
+ Authorization: `${this.accessToken}`,
2595
+ 'Content-Type': 'application/json'
2596
+ }
2597
+ }
2598
+ );
2599
+
2600
+ this.log(LoggerLevel.debug, `[schema.update] Objects updated: code=${res.data.code}`);
2601
+ this.log(LoggerLevel.trace, `[schema.update] Response: ${JSON.stringify(res.data)}`);
2602
+
2603
+ return res.data;
2604
+ },
2605
+
2606
+ /**
2607
+ * 批量删除数据对象(表)
2608
+ * @description 批量删除一个或多个数据对象
2609
+ * @param params 请求参数 { api_names: string[] }
2610
+ * @returns 接口返回结果
2611
+ * @example
2612
+ * ```typescript
2613
+ * // 删除单个对象
2614
+ * await client.schema.delete({ api_names: ['object_abc'] });
2615
+ *
2616
+ * // 删除多个对象
2617
+ * await client.schema.delete({ api_names: ['object_abc', 'object_def'] });
2618
+ * ```
2619
+ */
2620
+ delete: async (params: { api_names: string[] }): Promise<any> => {
2621
+ const { api_names } = params;
2622
+ await this.ensureTokenValid();
2623
+
2624
+ const url = `/v1/namespaces/${this.namespace}/objects/batch_delete`;
2625
+
2626
+ this.log(LoggerLevel.info, `[schema.delete] Deleting ${api_names.length} object(s): ${api_names.join(', ')}`);
2627
+
2628
+ // 直接传递字符串数组
2629
+ const requestBody = {
2630
+ api_names
2631
+ };
2632
+
2633
+ this.log(LoggerLevel.trace, `[schema.delete] Request URL: ${this.axiosInstance.defaults.baseURL}${url}`);
2634
+ this.log(LoggerLevel.trace, `[schema.delete] Request Body: ${JSON.stringify(requestBody, null, 2)}`);
2635
+
2636
+ const res = await this.axiosInstance.post(
2637
+ url,
2638
+ requestBody,
2639
+ {
2640
+ headers: {
2641
+ Authorization: `${this.accessToken}`,
2642
+ 'Content-Type': 'application/json'
2643
+ }
2644
+ }
2645
+ );
2646
+
2647
+ this.log(LoggerLevel.debug, `[schema.delete] Objects deleted: code=${res.data.code}`);
2648
+ this.log(LoggerLevel.trace, `[schema.delete] Response: ${JSON.stringify(res.data)}`);
2649
+
2650
+ return res.data;
2651
+ }
2652
+ };
2413
2653
  }
2414
2654
 
2415
2655
  export const apaas = {
2416
2656
  Client
2417
2657
  };
2418
2658
 
2419
- export type { BatchResult, RetryOptions };
2659
+ export type {
2660
+ BatchResult,
2661
+ RetryOptions,
2662
+ FieldTypeMetadata,
2663
+ // Schema operation types
2664
+ MultilingualText,
2665
+ ObjectSettings,
2666
+ FieldTypeDefinition,
2667
+ EncryptType,
2668
+ FieldOperator,
2669
+ CreateFieldDefinition,
2670
+ UpdateFieldDefinition,
2671
+ CreateObjectDefinition,
2672
+ UpdateObjectDefinition
2673
+ };
2674
+
2675
+ export {
2676
+ // Field type definitions and metadata
2677
+ FIELD_TYPES,
2678
+ SYSTEM_FIELDS,
2679
+ LANGUAGE_CODES,
2680
+ // Schema guidelines and examples
2681
+ SCHEMA_GUIDELINES,
2682
+ CREATE_OBJECT_EXAMPLE,
2683
+ UPDATE_OBJECT_ADD_FIELD_EXAMPLE,
2684
+ UPDATE_OBJECT_REPLACE_FIELD_EXAMPLE,
2685
+ UPDATE_OBJECT_REMOVE_FIELD_EXAMPLE,
2686
+ UPDATE_OBJECT_SETTINGS_EXAMPLE,
2687
+ // Helper functions
2688
+ getSystemFields,
2689
+ getCustomFieldTypes,
2690
+ getFieldType,
2691
+ isSystemField,
2692
+ createMultilingualText,
2693
+ extractMultilingualText
2694
+ };
package/.env DELETED
@@ -1,5 +0,0 @@
1
- CLIENT_APP_ID=c_fc919c38b7ab41a5ab36
2
- CLIENT_APP_SECRET=cad5106b819a43f286fb46a51b6ea2c8
3
-
4
- LARK_APP_ID=cli_a77cb9cd64b81013
5
- LARK_APP_SECRET=AEq56P8ntETGxNucLHTgbdLR2kNkXRNd
@@ -1,36 +0,0 @@
1
- name: Node.js CI & Publish
2
-
3
- on:
4
- push:
5
- branches: [main]
6
-
7
- jobs:
8
- build-test-publish:
9
- runs-on: ubuntu-latest
10
-
11
- strategy:
12
- matrix:
13
- node-version: [22.x]
14
-
15
- steps:
16
- - uses: actions/checkout@v3
17
-
18
- - name: Use Node.js ${{ matrix.node-version }}
19
- uses: actions/setup-node@v3
20
- with:
21
- node-version: ${{ matrix.node-version }}
22
- registry-url: 'https://registry.npmjs.org/'
23
-
24
- - name: Install dependencies
25
- run: npm install
26
-
27
- - name: Build
28
- run: npm run build
29
-
30
- - name: Run Tests
31
- run: npm test
32
-
33
- - name: Publish to npm
34
- run: npm publish --access public
35
- env:
36
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}