├── src ├── types │ ├── index.ts │ ├── common.ts │ └── request.ts ├── constants │ └── api.ts └── utils │ └── request.ts ├── test ├── compiler.js ├── tsconfig.json ├── api.spec.ts └── request.spec.ts ├── .vscode ├── extensions.json └── settings.json ├── .eslintignore ├── .mocharc.json ├── .eslintrc.js ├── .gitignore ├── .prettierrc.js ├── Readme.md ├── package.json ├── main.ts └── tsconfig.json /src/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from './common'; 2 | export * from './request'; 3 | -------------------------------------------------------------------------------- /test/compiler.js: -------------------------------------------------------------------------------- 1 | require('ts-node').register({ 2 | project: './test/tsconfig.json', 3 | }); 4 | -------------------------------------------------------------------------------- /src/types/common.ts: -------------------------------------------------------------------------------- 1 | export interface AfdianApiOpts { 2 | userId: string; 3 | token: string; 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | bin/ 3 | .history/ 4 | **/*.min.js 5 | **/*-min.js 6 | **/*.bundle.js 7 | test 8 | -------------------------------------------------------------------------------- /.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extension": ["ts"], 3 | "spec": ["./test/**/*.spec.ts"], 4 | "require": ["./test/compiler.js"] 5 | } 6 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['alloy', 'alloy/typescript', 'prettier'], 3 | env: { 4 | node: true, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | yarn.lock 2 | pnpm-lock.yaml 3 | .DS_Store 4 | *.log 5 | 6 | .history 7 | .env 8 | node_modules 9 | dist 10 | test/keys.ts 11 | -------------------------------------------------------------------------------- /src/constants/api.ts: -------------------------------------------------------------------------------- 1 | const API_BASE = 'https://afdian.net/api/open'; 2 | 3 | const getUrl = (path: string) => `${API_BASE}/${path}`; 4 | 5 | export default { 6 | ping: getUrl('ping'), 7 | queryOrder: getUrl('query-order'), 8 | querySponsor: getUrl('query-sponsor'), 9 | }; 10 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "eslint.validate": ["javascript", "typescript"], 3 | "editor.codeActionsOnSave": { 4 | "source.fixAll.eslint": true 5 | }, 6 | "editor.formatOnSave": true, 7 | "editor.defaultFormatter": "esbenp.prettier-vscode", 8 | "files.eol": "\n", 9 | "editor.tabSize": 2 10 | } 11 | -------------------------------------------------------------------------------- /test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "outDir": "./compiled", 6 | "strict": true, 7 | "esModuleInterop": true, 8 | "target": "es2021", 9 | "isolatedModules": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "skipLibCheck": true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | // .prettierrc.js 2 | module.exports = { 3 | printWidth: 120, 4 | tabWidth: 2, 5 | useTabs: false, 6 | semi: true, 7 | singleQuote: true, 8 | quoteProps: 'as-needed', 9 | jsxSingleQuote: false, 10 | trailingComma: 'all', 11 | bracketSpacing: true, 12 | jsxBracketSameLine: false, 13 | arrowParens: 'always', 14 | rangeStart: 0, 15 | rangeEnd: Infinity, 16 | requirePragma: false, 17 | insertPragma: false, 18 | proseWrap: 'preserve', 19 | htmlWhitespaceSensitivity: 'css', 20 | vueIndentScriptAndStyle: false, 21 | endOfLine: 'lf', 22 | embeddedLanguageFormatting: 'auto', 23 | }; 24 | -------------------------------------------------------------------------------- /test/api.spec.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import dotEnv from 'dotenv'; 3 | import Afdian from '../main'; 4 | 5 | dotEnv.config(); 6 | 7 | const afdian = new Afdian({ 8 | userId: process.env.AFDIAN_USER_ID || '', 9 | token: process.env.AFDIAN_TOKEN || '', 10 | }); 11 | 12 | describe('API request test', () => { 13 | it('ping', async () => { 14 | const res = await afdian.ping(); 15 | expect(res.ec).to.equal(200); 16 | }); 17 | it('queryOrder', async () => { 18 | const res = await afdian.queryOrder(1); 19 | expect(res.ec).to.equal(200); 20 | }); 21 | it('querySponsor', async () => { 22 | const res = await afdian.querySponsor(1); 23 | expect(res.ec).to.equal(200); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/utils/request.ts: -------------------------------------------------------------------------------- 1 | import { AfdianRequest, AfdianRequestParams, AfdianSignedRequest } from '../types/request'; 2 | import * as crypto from 'crypto'; 3 | 4 | const buildRequest = (userId: string, params?: AfdianRequestParams): AfdianRequest => { 5 | const req = { 6 | user_id: userId, 7 | ts: Math.floor(Date.now() / 1000), 8 | params: JSON.stringify(params || { empty: true }), 9 | }; 10 | return req; 11 | }; 12 | 13 | const signRequest = (token: string, body: AfdianRequest): AfdianSignedRequest => { 14 | const toSign = `${token}params${body.params}ts${body.ts}user_id${body.user_id}`; 15 | const sign = crypto.createHash('md5').update(toSign).digest('hex'); 16 | return { 17 | ...body, 18 | sign, 19 | }; 20 | }; 21 | 22 | export { buildRequest, signRequest }; 23 | -------------------------------------------------------------------------------- /test/request.spec.ts: -------------------------------------------------------------------------------- 1 | import { buildRequest, signRequest } from '../src/utils/request'; 2 | import { expect } from 'chai'; 3 | 4 | const USER_ID = '1e594220c90111ea88b551540055a377'; 5 | 6 | describe('Request utils', () => { 7 | before(function () { 8 | Date.now = () => 1624339905000; 9 | }); 10 | it('Build request body', () => { 11 | expect(buildRequest(USER_ID, { page: 1 })).to.deep.equal({ 12 | user_id: USER_ID, 13 | ts: Date.now() / 1000, 14 | params: JSON.stringify({ page: 1 }), 15 | }); 16 | }); 17 | it('Build request body without params', () => { 18 | expect(buildRequest(USER_ID)).to.deep.equal({ 19 | user_id: USER_ID, 20 | ts: Date.now() / 1000, 21 | params: JSON.stringify({ empty: true }), 22 | }); 23 | }); 24 | it('Sign request', () => { 25 | expect(signRequest('123456', buildRequest(USER_ID, { page: 1 }))).to.deep.equal({ 26 | user_id: USER_ID, 27 | ts: Date.now() / 1000, 28 | params: JSON.stringify({ page: 1 }), 29 | sign: '13836b92b27ac4acb1145bf91bba985a', 30 | }); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # 爱发电 API 2 | 3 | 这是一个爱发电开发者 API 的简易化包装,可以当作一个简单的 SDK 使用。 4 | 5 | 注意:该包仅支持 Node.js,请在服务器端使用。(正确做法也应该是从服务器端请求) 6 | 7 | ## 使用方法 8 | 9 | ### 0x00 安装 10 | 11 | ```bash 12 | npm install afdian-api -S 13 | ``` 14 | 15 | 支持 TypeScript,无需额外安装类型包。 16 | 17 | ### 0x01 引入到项目 18 | 19 | 以下是一个最小化的例子: 20 | 21 | ```js 22 | // esm 23 | import Afdian from 'afdian-api'; 24 | // cjs 25 | const Afdian = require('afdian-api'); 26 | 27 | const afdian = new Afdian({ 28 | token: '', 29 | userId: '', 30 | }); 31 | ``` 32 | 33 | ### 0x02 使用 API 34 | 35 | 所有 API 都经过了基于 `node-fetch` 做的简单包装,方法将直接返回解析后的回包,没有做任何其他处理。 36 | 37 | #### ping 38 | 39 | ping(): Promise\ 40 | 41 | 例子: 42 | 43 | ```js 44 | const res = await afdian.ping(); 45 | ``` 46 | 47 | #### queryOrder 48 | 49 | queryOrder(page: number): Promise\ 50 | 51 | 例子: 52 | 53 | ```js 54 | const res = await afdian.queryOrder(1); 55 | ``` 56 | 57 | #### querySponsor 58 | 59 | querySponsor(page: number): Promise\ 60 | 61 | 例子: 62 | 63 | ```js 64 | const res = await afdian.querySponsor(1); 65 | ``` 66 | 67 | ## License 68 | 69 | MIT 70 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "afdian-api", 3 | "version": "1.0.5", 4 | "description": "爱发电开发者API的简易包装 / A simple wrapper of Afdian APIs", 5 | "main": "./dist/main.js", 6 | "types": "./dist/main.d.ts", 7 | "files": [ 8 | "dist" 9 | ], 10 | "scripts": { 11 | "build": "rimraf -rf ./dist && tsc", 12 | "lint": "eslint --ext .ts *.ts", 13 | "test": "mocha --timeout 10000" 14 | }, 15 | "author": "BackRunner", 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/backrunner/afdian-api.git" 19 | }, 20 | "homepage": "https://github.com/backrunner/afdian-api", 21 | "keywords": [ 22 | "afdian", 23 | "api", 24 | "tool", 25 | "util" 26 | ], 27 | "license": "MIT", 28 | "devDependencies": { 29 | "@types/chai": "^4.3.0", 30 | "@types/mocha": "^9.1.0", 31 | "@types/node": "^16.11.26", 32 | "@types/node-fetch": "^2.6.1", 33 | "@typescript-eslint/eslint-plugin": "^4.33.0", 34 | "@typescript-eslint/parser": "^4.33.0", 35 | "chai": "^4.3.6", 36 | "dotenv": "^16.0.0", 37 | "eslint": "^7.32.0", 38 | "eslint-config-alloy": "^4.5.1", 39 | "eslint-config-prettier": "^8.5.0", 40 | "mocha": "^9.2.2", 41 | "prettier": "^2.6.0", 42 | "rimraf": "^3.0.2", 43 | "ts-node": "^10.7.0", 44 | "typescript": "^4.6.2" 45 | }, 46 | "dependencies": { 47 | "node-fetch": "^2.6.7" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch'; 2 | import api from './src/constants/api'; 3 | import { AfdianApiOpts } from './src/types/common'; 4 | import { 5 | AfdianPingResponse, 6 | AfdianOrderResponse, 7 | AfdianSponsorResponse, 8 | AfdianRequestParams, 9 | } from './src/types/request'; 10 | import { buildRequest, signRequest } from './src/utils/request'; 11 | 12 | class AfdianApi { 13 | private userId: string; 14 | private token: string; 15 | public constructor(opts: AfdianApiOpts) { 16 | const { userId, token } = opts; 17 | if (!userId) { 18 | throw new TypeError('User ID should not be empty.'); 19 | } 20 | if (!token) { 21 | throw new TypeError('Token should not be empty.'); 22 | } 23 | this.userId = userId; 24 | this.token = token; 25 | } 26 | public async ping(): Promise { 27 | const res = await this.send(api.ping); 28 | return await res.json(); 29 | } 30 | public async queryOrder(page: number): Promise { 31 | const res = await this.send(api.queryOrder, { page }); 32 | return await res.json(); 33 | } 34 | public async querySponsor(page: number): Promise { 35 | const res = await this.send(api.querySponsor, { page }); 36 | return await res.json(); 37 | } 38 | private async send(url: string, params?: AfdianRequestParams) { 39 | const signed = signRequest(this.token, buildRequest(this.userId, params)); 40 | return await fetch(url, { 41 | method: 'POST', 42 | headers: { 43 | 'Content-Type': 'application/json', 44 | }, 45 | body: JSON.stringify(signed), 46 | }); 47 | } 48 | } 49 | 50 | export * from './src/types'; 51 | export default AfdianApi; 52 | -------------------------------------------------------------------------------- /src/types/request.ts: -------------------------------------------------------------------------------- 1 | export interface AfdianRequestParams { 2 | page?: number; 3 | } 4 | 5 | export interface AfdianRequest { 6 | user_id: string; 7 | params?: string; 8 | ts: number; 9 | } 10 | 11 | export interface AfdianSignedRequest { 12 | user_id: string; 13 | params?: string; 14 | ts: number; 15 | sign: string; 16 | } 17 | 18 | export interface AfdianPlanInfo { 19 | plan_id: string; 20 | rank: number; 21 | user_id: string; 22 | status: number; 23 | name: string; 24 | pic: string; 25 | desc: string; 26 | price: string; 27 | update_time: number; 28 | pay_month: number; 29 | show_price: string; 30 | independent: number; 31 | permanent: number; 32 | can_buy_hide: number; 33 | need_address: number; 34 | product_type: number; 35 | sale_limit_count: number; 36 | need_invite_code: boolean; 37 | expire_time: number; 38 | sku_processed: unknown[]; 39 | rankType: number; 40 | } 41 | 42 | export interface AfdianSponsorInfo { 43 | sponsor_plans: AfdianPlanInfo[]; 44 | current_plan: AfdianPlanInfo; 45 | all_sum_amount: string; 46 | create_time: number; 47 | first_pay_time: number; 48 | last_pay_time: number; 49 | user: { 50 | user_id: string; 51 | name: string; 52 | avatar: string; 53 | }; 54 | } 55 | 56 | export interface AfdianBasicResponse { 57 | ec: number; 58 | em: string; 59 | data: T; 60 | } 61 | 62 | export type AfdianPingResponse = AfdianBasicResponse<{ 63 | uid: string; 64 | request: { 65 | user_id: string; 66 | params: string; 67 | ts: number; 68 | sign: string; 69 | }; 70 | }>; 71 | 72 | export type AfdianSponsorResponse = AfdianBasicResponse<{ 73 | total_count: number; 74 | total_page: number; 75 | list: AfdianSponsorInfo[]; 76 | }>; 77 | 78 | export interface AfdianOrderInfo { 79 | out_trade_no: string; 80 | user_id: string; 81 | plan_id: string; 82 | month: number; 83 | total_amount: string; 84 | show_amount: string; 85 | status: number; 86 | remark: string; 87 | redeem_id: string; 88 | product_type: number; 89 | discount: string; 90 | sku_detail: unknown[]; 91 | address_person: string; 92 | address_phone: string; 93 | addres_address: string; 94 | } 95 | 96 | export type AfdianOrderResponse = AfdianBasicResponse<{ 97 | list: AfdianOrderInfo[]; 98 | total_count: number; 99 | total_page: number; 100 | }>; 101 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ 22 | // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | 26 | /* Modules */ 27 | "module": "commonjs" /* Specify what module code is generated. */, 28 | // "rootDir": "./", /* Specify the root folder within your source files. */ 29 | "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, 30 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 31 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 32 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 33 | // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ 34 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 35 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 36 | // "resolveJsonModule": true, /* Enable importing .json files */ 37 | // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ 38 | 39 | /* JavaScript Support */ 40 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ 41 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 42 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ 43 | 44 | /* Emit */ 45 | "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */, 46 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 47 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 48 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 49 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ 50 | "outDir": "./dist" /* Specify an output folder for all emitted files. */, 51 | "removeComments": true /* Disable emitting comments. */, 52 | // "noEmit": true, /* Disable emitting files from a compilation. */ 53 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 54 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ 55 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 56 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 59 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 60 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 61 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 62 | // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ 63 | // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ 64 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 65 | // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ 66 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 67 | 68 | /* Interop Constraints */ 69 | "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */, 70 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 71 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, 72 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 73 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 74 | 75 | /* Type Checking */ 76 | "strict": true /* Enable all strict type-checking options. */, 77 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ 78 | // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ 79 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 80 | // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ 81 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 82 | // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ 83 | // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ 84 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 85 | // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ 86 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ 87 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 88 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 89 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 90 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 91 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 92 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ 93 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 94 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 95 | 96 | /* Completeness */ 97 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 98 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 99 | }, 100 | "include": ["main.ts", "src/**/*.ts"], 101 | "exclude": ["test/**/*.ts"] 102 | } 103 | --------------------------------------------------------------------------------