-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from coldsurfers/feature/implement-accounts-se…
…rver Accounts server testing
- Loading branch information
Showing
38 changed files
with
956 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'coldsurfers', // for nodejs-typescript, or 'coldsurfers/nodejs-typescript' | ||
], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: ['.eslintrc.{js,cjs}'], | ||
parserOptions: { | ||
sourceType: 'script', | ||
}, | ||
}, | ||
], | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
rules: { | ||
'import/no-unresolved': 'off', | ||
'react/jsx-filename-extension': 'off', | ||
'react/jsx-props-no-spreading': 'off', | ||
'react/prop-types': [0], | ||
'no-bitwise': 'off', | ||
camelcase: 'off', | ||
'no-param-reassign': 'off', | ||
'no-await-in-loop': 'off', | ||
'no-return-await': 'off', | ||
'react/no-array-index-key': 'off', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
.eslintcache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@coldsurfers/accounts-kit", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"source": "src/", | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js" | ||
} | ||
}, | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"@coldsurfers/accounts-schema": "1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@coldsurfers/accounts-schema": "1.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.62.0", | ||
"@typescript-eslint/parser": "^5.62.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-coldsurfers": "^1.1.3", | ||
"eslint-config-prettier": "^8.10.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"prettier": "^2.8.1", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
import { | ||
PostAccountsSignInCtrlBodySchemaType, | ||
PostAccountsSignInCtrlResponseSchemaType, | ||
} from '@coldsurfers/accounts-schema' | ||
import HttpRequest from './lib/HttpRequest' | ||
|
||
class AccountsKit { | ||
// eslint-disable-next-line no-useless-constructor, no-empty-function | ||
constructor() {} | ||
|
||
async fetchSignIn( | ||
body: PostAccountsSignInCtrlBodySchemaType | ||
): Promise<PostAccountsSignInCtrlResponseSchemaType> { | ||
const res = await new HttpRequest().request('/accounts/signin', { | ||
body: JSON.stringify(body), | ||
method: 'POST', | ||
}) | ||
return (await res.json()) as PostAccountsSignInCtrlResponseSchemaType | ||
} | ||
} | ||
|
||
export default AccountsKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class HttpRequest { | ||
private host: string = | ||
process.env.NODE_ENV === 'development' | ||
? 'http://0.0.0.0:8008' | ||
: 'https://api.accounts.coldsurf.io/v1' | ||
|
||
// eslint-disable-next-line no-undef | ||
async request(path: string, init?: RequestInit) { | ||
return await fetch(`${this.host}${path}`, { | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
...init, | ||
}) | ||
} | ||
} | ||
|
||
export default HttpRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": [ | ||
"../../tsconfig.paths.json", | ||
"../../tsconfig.utils.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'coldsurfers', // for nodejs-typescript, or 'coldsurfers/nodejs-typescript' | ||
], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: ['.eslintrc.{js,cjs}'], | ||
parserOptions: { | ||
sourceType: 'script', | ||
}, | ||
}, | ||
], | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
rules: { | ||
'react/jsx-filename-extension': 'off', | ||
'react/jsx-props-no-spreading': 'off', | ||
'react/prop-types': [0], | ||
'no-bitwise': 'off', | ||
camelcase: 'off', | ||
'no-param-reassign': 'off', | ||
'no-await-in-loop': 'off', | ||
'no-return-await': 'off', | ||
'react/no-array-index-key': 'off', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
.eslintcache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@coldsurfers/accounts-schema", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"source": "src/", | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js" | ||
} | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "rm -rf dist && tsc --project ./tsconfig.build.json" | ||
}, | ||
"peerDependencies": { | ||
"zod": "^3.22.4" | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^5.62.0", | ||
"@typescript-eslint/parser": "^5.62.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-coldsurfers": "^1.1.3", | ||
"eslint-config-prettier": "^8.10.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"prettier": "^2.8.1", | ||
"zod": "^3.22.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { z } from 'zod' | ||
|
||
/** serialize */ | ||
export const StaffSerializedSchema = z.object({ | ||
id: z.string(), | ||
created_at: z.string(), | ||
is_staff: z.boolean(), | ||
is_authorized: z.boolean(), | ||
}) | ||
|
||
export type StaffSerializedSchemaType = z.infer<typeof StaffSerializedSchema> | ||
|
||
export const AccountSerializedSchema = z.object({ | ||
id: z.string(), | ||
email: z.string().email(), | ||
username: z.string(), | ||
created_at: z.string(), | ||
staff: StaffSerializedSchema.optional(), | ||
}) | ||
|
||
export type AccountSerializedSchemaType = z.infer< | ||
typeof AccountSerializedSchema | ||
> | ||
|
||
export const AuthTokenSerializedSchema = z.object({ | ||
access_token: z.string(), | ||
refresh_token: z.string(), | ||
}) | ||
|
||
export type AuthTokenSerializedSchemaType = z.infer< | ||
typeof AuthTokenSerializedSchema | ||
> | ||
|
||
/** API */ | ||
export const PostAccountsSignInCtrlBodySchema = z.object({ | ||
provider: z.string(), | ||
access_token: z.string(), | ||
}) | ||
|
||
export type PostAccountsSignInCtrlBodySchemaType = z.infer< | ||
typeof PostAccountsSignInCtrlBodySchema | ||
> | ||
|
||
export const PostAccountsSignInCtrlResponseSchema = z.object({ | ||
account: AccountSerializedSchema, | ||
auth_token: AuthTokenSerializedSchema, | ||
}) | ||
|
||
export type PostAccountsSignInCtrlResponseSchemaType = z.infer< | ||
typeof PostAccountsSignInCtrlResponseSchema | ||
> |
Oops, something went wrong.