Skip to content

Commit

Permalink
Merge pull request #15 from coldsurfers/feature/implement-accounts-se…
Browse files Browse the repository at this point in the history
…rver

Accounts server testing
  • Loading branch information
yungblud authored Jan 17, 2024
2 parents 7c7fe71 + abd548a commit f1bd37f
Show file tree
Hide file tree
Showing 38 changed files with 956 additions and 267 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
"name": "@coldsurfers/surfers-common",
"private": true,
"workspaces": {
"packages": ["packages/*"]
"packages": [
"packages/*"
]
},
"scripts": {
"super-install": "yarn install --immutable --force || yarn install --immutable --force"
},
"devDependencies": {
"typescript": "^5.3.3"
}
}
37 changes: 37 additions & 0 deletions packages/accounts-kit/.eslintrc.js
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',
},
}
2 changes: 2 additions & 0 deletions packages/accounts-kit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
.eslintcache
6 changes: 6 additions & 0 deletions packages/accounts-kit/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
36 changes: 36 additions & 0 deletions packages/accounts-kit/package.json
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"
}
}
23 changes: 23 additions & 0 deletions packages/accounts-kit/src/core.ts
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
19 changes: 19 additions & 0 deletions packages/accounts-kit/src/lib/HttpRequest.ts
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
6 changes: 6 additions & 0 deletions packages/accounts-kit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"../../tsconfig.paths.json",
"../../tsconfig.utils.json"
]
}
36 changes: 36 additions & 0 deletions packages/accounts-schema/.eslintrc.js
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',
},
}
2 changes: 2 additions & 0 deletions packages/accounts-schema/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
.eslintcache
6 changes: 6 additions & 0 deletions packages/accounts-schema/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
38 changes: 38 additions & 0 deletions packages/accounts-schema/package.json
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"
}
}
51 changes: 51 additions & 0 deletions packages/accounts-schema/src/index.ts
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
>
Loading

0 comments on commit f1bd37f

Please sign in to comment.