@mx-space/api-client 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ import { SayController } from './say'
15
15
  import { SearchController } from './search'
16
16
  import { ServerlessController } from './severless'
17
17
  import { SnippetController } from './snippet'
18
+ import { SubscribeController } from './subscribe'
18
19
  import { TopicController } from './topic'
19
20
  import { UserController } from './user'
20
21
 
@@ -33,6 +34,7 @@ export const allControllers = [
33
34
  SearchController,
34
35
  SnippetController,
35
36
  ServerlessController,
37
+ SubscribeController,
36
38
  UserController,
37
39
  ]
38
40
 
@@ -51,6 +53,7 @@ export const allContollerNames = [
51
53
  'search',
52
54
  'snippet',
53
55
  'serverless',
56
+ 'subscribe',
54
57
  'user',
55
58
 
56
59
  // alias,
@@ -73,6 +76,7 @@ export {
73
76
  SearchController,
74
77
  SnippetController,
75
78
  ServerlessController,
79
+ SubscribeController,
76
80
  UserController,
77
81
  TopicController,
78
82
 
@@ -0,0 +1,47 @@
1
+ import { IRequestAdapter } from '~/interfaces/adapter'
2
+ import { IController } from '~/interfaces/controller'
3
+ import { IRequestHandler } from '~/interfaces/request'
4
+ import { SubscribeType } from '~/models/subscribe'
5
+ import { autoBind } from '~/utils/auto-bind'
6
+
7
+ import { HTTPClient } from '../core'
8
+
9
+ declare module '../core/client' {
10
+ interface HTTPClient<
11
+ T extends IRequestAdapter = IRequestAdapter,
12
+ ResponseWrapper = unknown,
13
+ > {
14
+ subscribe: SubscribeController<ResponseWrapper>
15
+ }
16
+ }
17
+
18
+ export class SubscribeController<ResponseWrapper> implements IController {
19
+ base = 'subscribe'
20
+ name = 'subscribe'
21
+
22
+ constructor(protected client: HTTPClient) {
23
+ autoBind(this)
24
+ }
25
+
26
+ public get proxy(): IRequestHandler<ResponseWrapper> {
27
+ return this.client.proxy(this.base)
28
+ }
29
+
30
+ subscribe(email: string, types: SubscribeType[]) {
31
+ return this.proxy.post<never>({
32
+ params: {
33
+ email,
34
+ types,
35
+ },
36
+ })
37
+ }
38
+
39
+ unsubscribe(email: string, cancelToken: string) {
40
+ return this.proxy.unsubscribe.get<string>({
41
+ params: {
42
+ email,
43
+ cancelToken,
44
+ },
45
+ })
46
+ }
47
+ }