From 89e0088058d31dd89a7226fe8f011ff2e99f3cd1 Mon Sep 17 00:00:00 2001 From: TechQuery Date: Sun, 24 Dec 2023 01:31:24 +0800 Subject: [PATCH] [add] GitHub Issue forms & repository settings [add] VS Code extensions configuration [optimize] simplify some Type & Logic details --- .github/ISSUE_TEMPLATE/developer-bug.yaml | 187 ++++++++++++++++++ .../ISSUE_TEMPLATE/feature-enhancement.yaml | 35 ++++ .github/settings.yml | 85 ++++++++ .vscode/extensions.json | 15 ++ package.json | 2 +- src/Lark.ts | 32 +-- src/module/BITable/type.ts | 10 +- src/module/InstantMessenger/type/message.ts | 9 +- src/module/SpreadSheet/index.ts | 11 +- src/module/SpreadSheet/type.ts | 10 +- src/module/index.ts | 1 + src/type.ts | 15 +- 12 files changed, 358 insertions(+), 54 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/developer-bug.yaml create mode 100644 .github/ISSUE_TEMPLATE/feature-enhancement.yaml create mode 100644 .github/settings.yml create mode 100644 .vscode/extensions.json diff --git a/.github/ISSUE_TEMPLATE/developer-bug.yaml b/.github/ISSUE_TEMPLATE/developer-bug.yaml new file mode 100644 index 0000000..97bcf13 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/developer-bug.yaml @@ -0,0 +1,187 @@ +name: 🐛 Developer Bug report +description: File a Code bug/issue +title: +labels: + - bug +body: + - type: checkboxes + attributes: + label: Is there an existing issue for this? + description: Please search to see if an issue already exists for the bug you encountered. + options: + - label: I have searched the existing issues + required: true + + - type: textarea + attributes: + label: Current Behavior + description: A concise description of what you're experiencing. + validations: + required: true + + - type: textarea + attributes: + label: Expected Behavior + description: A concise description of what you expected to happen. + validations: + required: true + + - type: textarea + attributes: + label: Steps To Reproduce + description: Steps to reproduce the behavior. + placeholder: | + 1. In this environment... + 2. With this config... + 3. Run '...' + 4. See error... + validations: + required: true + + - type: dropdown + id: system + attributes: + label: On which operating system are you experiencing the problem? + multiple: true + options: + - BSD + - Linux + - Windows + - MacOS + - iOS + - Android + validations: + required: true + + - type: input + id: system-version + attributes: + label: The version of your Operation System + validations: + required: true + + - type: dropdown + id: subsystem + attributes: + label: What subsystem is the problem related to? + multiple: true + options: + - Docker + - WSL + - WINE + + - type: input + id: subsystem-version + attributes: + label: The version of your Sub-system + + - type: dropdown + id: Web-browser + attributes: + label: What browsers are you seeing the problem on? + multiple: true + options: + - Firefox + - Chrome + - Safari + - Microsoft Edge + - Opera + - Brave + - Arc Browser + - UC Browser + validations: + required: true + + - type: input + id: Web-browser-version + attributes: + label: The version of your Web browser + validations: + required: true + + - type: dropdown + id: network-region + attributes: + label: What network region are you in? + multiple: true + options: + - Global + - China mainland + validations: + required: true + + - type: dropdown + id: cli + attributes: + label: Which command line terminal are you using? + multiple: true + options: + - Shell + - CMD + - Powershell + validations: + required: true + + - type: input + id: cli-version + attributes: + label: The version of your Command-line Terminal + + - type: dropdown + id: JavaScript-runtime + attributes: + label: Which JavaScript runtime are you using? + multiple: true + options: + - Node.js + - Bun + - Deno + validations: + required: true + + - type: input + id: JavaScript-runtime-version + attributes: + label: The version of your JavaScript runtime + validations: + required: true + + - type: dropdown + id: JavaScript-package-manager + attributes: + label: Which JavaScript package manager are you using? + multiple: true + options: + - npm + - Yarn + - pnpm + - Bun + validations: + required: true + + - type: input + id: JavaScript-package-manager-version + attributes: + label: The version of your JavaScript package manager + validations: + required: true + + - type: dropdown + id: development_environment + attributes: + label: Which development environment are you using? + multiple: true + options: + - Local + - Gitpod + - GitHub Codespaces + validations: + required: true + + - type: textarea + attributes: + label: Anything else? + description: | + Links? References? Anything that will give us more context about the issue you are encountering! + + Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in. diff --git a/.github/ISSUE_TEMPLATE/feature-enhancement.yaml b/.github/ISSUE_TEMPLATE/feature-enhancement.yaml new file mode 100644 index 0000000..53a6a50 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-enhancement.yaml @@ -0,0 +1,35 @@ +name: ✨ Feature/Enhancement +description: Request a new feature or enhancement +title: <title> +labels: + - enhancement +body: + - type: checkboxes + attributes: + label: Is there an existing feature request for this? + description: Please search to see if a feature request already exists for the enhancement you are proposing. + options: + - label: I have searched the existing feature requests + required: true + + - type: textarea + attributes: + label: Description + description: | + A detailed description of the new feature or enhancement you are proposing. Additionally, provide any relevant + links, references, or attachments to offer more context about the proposal. You can also attach images or other + files by clicking this area to highlight it and then dragging files in. + + Tip: You can attach images or other files by clicking this area to highlight it and then dragging files in. + validations: + required: true + + - type: textarea + attributes: + label: Use Case + description: Provide a use case or scenario where this feature or enhancement would be beneficial. + + - type: textarea + attributes: + label: Proposed Solution + description: If you have a specific solution in mind, please describe it here. diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..72e1ca6 --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,85 @@ +# These settings are synced to GitHub by https://probot.github.io/apps/settings/ + +repository: + allow_merge_commit: false + + delete_branch_on_merge: true + + enable_vulnerability_alerts: true + +labels: + - name: bug + color: '#d73a4a' + description: Something isn't working + + - name: documentation + color: '#0075ca' + description: Improvements or additions to documentation + + - name: duplicate + color: '#cfd3d7' + description: This issue or pull request already exists + + - name: enhancement + color: '#a2eeef' + description: Some improvements + + - name: feature + color: '#16b33f' + description: New feature or request + + - name: good first issue + color: '#7057ff' + description: Good for newcomers + + - name: help wanted + color: '#008672' + description: Extra attention is needed + + - name: invalid + color: '#e4e669' + description: This doesn't seem right + + - name: question + color: '#d876e3' + description: Further information is requested + + - name: wontfix + color: '#ffffff' + description: This will not be worked on + +branches: + - name: main + # https://docs.github.com/en/rest/reference/repos#update-branch-protection + protection: + # Required. Require at least one approving review on a pull request, before merging. Set to null to disable. + required_pull_request_reviews: + # The number of approvals required. (1-6) + required_approving_review_count: 1 + # Dismiss approved reviews automatically when a new commit is pushed. + dismiss_stale_reviews: true + # Blocks merge until code owners have reviewed. + require_code_owner_reviews: true + # Specify which users and teams can dismiss pull request reviews. + # Pass an empty dismissal_restrictions object to disable. + # User and team dismissal_restrictions are only available for organization-owned repositories. + # Omit this parameter for personal repositories. + dismissal_restrictions: + # users: [] + # teams: [] + # Required. Require status checks to pass before merging. Set to null to disable + required_status_checks: + # Required. Require branches to be up to date before merging. + strict: true + # Required. The list of status checks to require in order to merge into this branch + contexts: [] + # Required. Enforce all configured restrictions for administrators. + # Set to true to enforce required status checks for repository administrators. + # Set to null to disable. + enforce_admins: true + # Prevent merge commits from being pushed to matching branches + required_linear_history: true + # Required. Restrict who can push to this branch. + # Team and user restrictions are only available for organization-owned repositories. + # Set to null to disable. + restrictions: null diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..affda41 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,15 @@ +{ + "recommendations": [ + "yzhang.markdown-all-in-one", + "redhat.vscode-yaml", + "akamud.vscode-caniuse", + "visualstudioexptteam.intellicode-api-usage-examples", + "pflannery.vscode-versionlens", + "christian-kohler.npm-intellisense", + "esbenp.prettier-vscode", + "rangav.vscode-thunder-client", + "eamodio.gitlens", + "github.vscode-pull-request-github", + "github.vscode-github-actions" + ] +} diff --git a/package.json b/package.json index 98ec9ae..6b081be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mobx-lark", - "version": "1.1.0-rc.0", + "version": "1.1.0", "license": "LGPL-3.0", "author": "shiy2008@gmail.com", "description": "Unofficial TypeScript SDK for FeiShu/Lark API, which is based on MobX-RESTful.", diff --git a/src/Lark.ts b/src/Lark.ts index 60ddc20..3c821fd 100644 --- a/src/Lark.ts +++ b/src/Lark.ts @@ -1,4 +1,4 @@ -import { Context, HTTPClient, HTTPError, makeFormData, request } from 'koajax'; +import { Context, HTTPClient, makeFormData } from 'koajax'; import { buildURLData, cache, Second } from 'web-utility'; import { @@ -113,7 +113,7 @@ export class LarkApp implements LarkAppOption { async getUserMeta(code: string) { await this.getAccessToken(); - const { body } = await this.client.post<UserMeta>( + const { body } = await this.client.post<LarkData<UserMeta>>( 'authen/v1/access_token', { grant_type: 'authorization_code', code } ); @@ -126,7 +126,8 @@ export class LarkApp implements LarkAppOption { getJSTicket = cache(async clean => { await this.getAccessToken(); - const { body } = await this.client.post<JSTicket>('jssdk/ticket/get'); + const { body } = + await this.client.post<LarkData<JSTicket>>('jssdk/ticket/get'); const { expire_in, ticket } = body!.data!; setTimeout(clean, expire_in * Second); @@ -155,32 +156,19 @@ export class LarkApp implements LarkAppOption { parent_type: UploadTargetType, parent_node: string ) { - const token = await this.getAccessToken(); + await this.getAccessToken(); - const body = makeFormData({ + const form = makeFormData({ file, file_name: file.name, size: file.size, parent_type, parent_node }); - const { response } = request<LarkData<{ file_token: string }>>({ - method: 'POST', - path: this.client.baseURI + 'drive/v1/medias/upload_all', - headers: { Authorization: `Bearer ${token}` }, - body - }); - const res = await response; - - if (res.status < 300) return res.body!.data!.file_token; + const { body } = await this.client.post< + LarkData<{ file_token: string }> + >('drive/v1/medias/upload_all', form); - const error = res.body as unknown as Blob; - - const raw = new TextDecoder().decode(await error.arrayBuffer()); - - throw new HTTPError(res.statusText, { - ...res, - body: JSON.parse(raw) - }); + return body!.data!.file_token; } } diff --git a/src/module/BITable/type.ts b/src/module/BITable/type.ts index d578aa2..5c8c9b9 100644 --- a/src/module/BITable/type.ts +++ b/src/module/BITable/type.ts @@ -1,14 +1,10 @@ -import { LarkData, LarkPageData, LocaleUser } from '../../type'; +import { LarkData, LocaleUser } from '../../type'; export interface RevisionTable { name: string; revision: number; } -export type BITableMeta = LarkData<{ - app: { app_token: string } & RevisionTable; -}>; - export interface BITable extends RevisionTable { table_id: string; } @@ -111,7 +107,3 @@ export interface TableRecord<T extends TableRecordFields> export type TableRecordData<T extends TableRecordFields> = LarkData<{ record: TableRecord<T>; }>; - -export type TableRecordList<D extends TableRecordFields = {}> = LarkPageData< - TableRecord<D> ->; diff --git a/src/module/InstantMessenger/type/message.ts b/src/module/InstantMessenger/type/message.ts index 31c7eaa..5898fdf 100644 --- a/src/module/InstantMessenger/type/message.ts +++ b/src/module/InstantMessenger/type/message.ts @@ -29,12 +29,13 @@ export interface ImageTag { export type RichTextTag = TextTag | LinkTag | AtTag | ImageTag; -export type RichTextMessage = { - [key: I18nKey]: { +export type RichTextMessage = Record< + I18nKey, + { title: string; content: RichTextTag[][]; - }; -}; + } +>; export interface UserCardMessage { type: 'share_user'; diff --git a/src/module/SpreadSheet/index.ts b/src/module/SpreadSheet/index.ts index 709e614..f95c2c1 100644 --- a/src/module/SpreadSheet/index.ts +++ b/src/module/SpreadSheet/index.ts @@ -1,8 +1,9 @@ -import { buildURLData, objectFrom } from 'web-utility'; import * as MobX from 'mobx'; -import { DataObject, NewData, ListModel, toggle } from 'mobx-restful'; +import { DataObject, ListModel, NewData, toggle } from 'mobx-restful'; +import { buildURLData, objectFrom } from 'web-utility'; -import { SpreadSheetMeta, SheetMeta, SheetRangeData } from './type'; +import { LarkData } from '../../type'; +import { SheetMeta, SpreadSheetMeta, SpreadSheetRange } from './type'; export * from './type'; @@ -35,7 +36,7 @@ export abstract class SpreadSheetModel< async getMeta() { if (this.meta) return this.meta; - const { body } = await this.client.get<SpreadSheetMeta>( + const { body } = await this.client.get<LarkData<SpreadSheetMeta>>( `${this.baseURI}/metainfo` ), { sheetId } = this; @@ -63,7 +64,7 @@ export abstract class SpreadSheetModel< const startColumn = String.fromCharCode(startColumnNumber), endColumn = String.fromCharCode(endColumnNumber); - const { body } = await this.client.get<SheetRangeData>( + const { body } = await this.client.get<LarkData<SpreadSheetRange>>( `${this.baseURI}/values/${ this.sheetId }!${startColumn}${startRow}:${endColumn}${endRow}?${buildURLData({ diff --git a/src/module/SpreadSheet/type.ts b/src/module/SpreadSheet/type.ts index 630ea38..0fab7dc 100644 --- a/src/module/SpreadSheet/type.ts +++ b/src/module/SpreadSheet/type.ts @@ -1,18 +1,16 @@ -import { LarkData } from '../../type'; - export type SheetMeta = Record<'sheetId' | 'title', string> & Record< `${'row' | 'column'}Count` | `frozen${'Row' | 'Col'}Count` | 'index', number >; -export type SpreadSheetMeta = LarkData<{ +export interface SpreadSheetMeta { spreadsheetToken: string; properties: { title: string; } & Record<'revision' | 'ownerUser' | 'sheetCount', number>; sheets: SheetMeta[]; -}>; +} export interface SheetCellMedia { type: 'url'; @@ -23,11 +21,11 @@ export interface SheetCellMedia { export type SheetCellValue = string | number | SheetCellMedia[] | null; -export type SheetRangeData = LarkData<{ +export interface SpreadSheetRange { revision: number; spreadsheetToken: string; valueRange: Record<'revision' | 'majorDimension', string> & { range: `${string}!${string}:${string}`; values: SheetCellValue[][]; }; -}>; +} diff --git a/src/module/index.ts b/src/module/index.ts index 9f50a78..326bf5f 100644 --- a/src/module/index.ts +++ b/src/module/index.ts @@ -1,4 +1,5 @@ export * from './base'; export * from './InstantMessenger'; +export * from './Task'; export * from './SpreadSheet'; export * from './BITable'; diff --git a/src/type.ts b/src/type.ts index b0e2083..aa5d63a 100644 --- a/src/type.ts +++ b/src/type.ts @@ -34,8 +34,8 @@ export type UserIdType = `${'open' | 'union' | 'user'}_id`; export type LocaleUser = Record<`${'' | 'en_'}name` | 'email', string>; -export type UserMeta = LarkData< - { token_type: 'Bearer' } & LocaleUser & +export interface UserMeta + extends LocaleUser, Record< | `avatar_${'url' | 'thumb' | 'middle' | 'big'}` | UserIdType @@ -43,14 +43,15 @@ export type UserMeta = LarkData< | 'tenant_key' | `${'access' | 'refresh'}_token`, string - > & - Record<`${'' | 'refresh_'}expires_in`, number> ->; + >, + Record<`${'' | 'refresh_'}expires_in`, number> { + token_type: 'Bearer'; +} -export type JSTicket = LarkData<{ +export interface JSTicket { expire_in: number; ticket: string; -}>; +} export type I18nKey = `${string}_${string}`;