Skip to content

Commit

Permalink
Merge pull request #128 from sima-land/69-conventional-cookie
Browse files Browse the repository at this point in the history
#69 Сбор кук на сервере работает некорректно
  • Loading branch information
krutoo committed Mar 29, 2024
2 parents 63d5cd6 + ed3c3c2 commit 34dafb1
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 183 deletions.
19 changes: 0 additions & 19 deletions docs/docs/utils/axios.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,6 @@ const middleware = logMiddleware({
client.use(middleware);
```

### "Прозрачные" cookie

На сервере бывает необходимо выполнить HTTP-запрос к публичным API от имени пользователя.

Пакет предоставляет функцию для создания промежуточного слоя,
накапливающего cookie из ответов на исходящие запросы в ответ express-приложения.

```ts
import { create } from 'middleware-axios';
import { createCookieStore } from '@sima-land/isomorph/http';
import { cookieMiddleware } from '@sima-land/isomorph/utils/axios';

const client = create();
const cookieStore = createCookieStore();

// при запросе cookie из хранилища будут автоматически добавлены в заголовки
client.use(cookieMiddleware(cookieStore));
```

## Sauce

Пакет предоставляет функцию `sauce` позволяющую сделать возвращаемые из методов экземпляра `AxiosInstance` промисы "безопасными".
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"whatwg-fetch": "^3.6.17"
},
"dependencies": {
"@humanwhocodes/env": "^2.2.2",
"@humanwhocodes/env": "^3.0.2",
"@krutoo/fetch-tools": "^0.0.12",
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/exporter-prometheus": "^0.38.0",
Expand Down
2 changes: 2 additions & 0 deletions src/config/source.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { ConfigSource, Dictionary } from './types';

// @ts-expect-error: https://github.com/humanwhocodes/env/issues/133 (@todo разобраться и убрать)
import { Env } from '@humanwhocodes/env';

declare const __ISOMORPH_ENV__: unknown;
Expand Down
1 change: 1 addition & 0 deletions src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-expect-error: https://github.com/humanwhocodes/env/issues/133 (@todo разобраться и убрать)
import type { Env } from '@humanwhocodes/env';

/** Источник конфигурации. */
Expand Down
5 changes: 2 additions & 3 deletions src/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ export type {
FailLogData,
LogHandler,
LogHandlerFactory,
CookieStore,
EitherResponse,
ResponseDone,
ResponseFail,
ResponseErrorInit,
} from './types';
export { configureFetch, applyMiddleware, createCookieStore } from '@krutoo/fetch-tools';
export { log, cookie, defaultHeaders, validateStatus } from '@krutoo/fetch-tools/middleware';
export { configureFetch, applyMiddleware } from '@krutoo/fetch-tools';
export { log, defaultHeaders, validateStatus } from '@krutoo/fetch-tools/middleware';
export { StatusError, ResponseError } from './errors';
export { FetchUtil } from './utils';
2 changes: 1 addition & 1 deletion src/http/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LogLevel } from '../log';

export type { Handler, Enhancer, Middleware, CookieStore } from '@krutoo/fetch-tools';
export type { Handler, Enhancer, Middleware } from '@krutoo/fetch-tools';

export type {
LogData,
Expand Down
10 changes: 0 additions & 10 deletions src/preset/bun-handler/providers/cookie-store.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/preset/node-handler/providers/cookie-store.ts

This file was deleted.

5 changes: 1 addition & 4 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { ExpressHandlerContext } from './preset/node/types';
import type { SpecificExtras } from './preset/server/utils/specific-extras';
import type { CreateAxiosDefaults } from 'axios';
import type { AxiosInstanceWrapper, Middleware as AxiosMiddleware } from 'middleware-axios';
import type { CookieStore, Handler, LogHandler, LogHandlerFactory, Middleware } from './http';
import type { Handler, LogHandler, LogHandlerFactory, Middleware } from './http';
import type { HttpApiHostPool } from './preset/isomorphic/utils/http-api-host-pool';
import type {
ServerHandlerContext,
Expand Down Expand Up @@ -79,9 +79,6 @@ export const KnownToken = {
/** Токен AbortController для функции fetch. */
abortController: createToken<AbortController>('fetch/abort-controller'),

/** Токен хранилища cookie. */
cookieStore: createToken<CookieStore>('fetch/cookie-store'),

/** Токен списка промежуточных слоев для функции fetch. */
middleware: createToken<Middleware[]>('fetch/middleware'),

Expand Down
1 change: 0 additions & 1 deletion src/utils/axios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ export {
type LogMiddlewareHandlerInit,
logMiddleware,
} from './middleware/log';
export { cookieMiddleware } from './middleware/cookie';
94 changes: 0 additions & 94 deletions src/utils/axios/middleware/__test__/cookie.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/utils/axios/middleware/cookie.ts

This file was deleted.

1 change: 0 additions & 1 deletion tsconfig.bun.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"types": ["bun-types", "jest"]
},
"include": ["./src"],
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"skipLibCheck": true,
"jsx": "react-jsx",
"isolatedModules": true,
"moduleResolution": "node"
"module": "NodeNext"
},
"include": ["./src"],
"exclude": ["node_modules", "./src/preset/bun/**/*"]
Expand Down
1 change: 0 additions & 1 deletion tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"outDir": "./dist/types",
"declaration": true,
"sourceMap": false,
Expand Down

0 comments on commit 34dafb1

Please sign in to comment.