@prezly/sdk 19.9.0 → 20.0.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.
Files changed (93) hide show
  1. package/dist/Client.cjs +28 -28
  2. package/dist/Client.d.ts +2 -1
  3. package/dist/Client.js +29 -29
  4. package/dist/api/ApiClient.cjs +36 -34
  5. package/dist/api/ApiClient.d.ts +8 -12
  6. package/dist/api/ApiClient.js +34 -31
  7. package/dist/api/DeferredJobsApiClient.cjs +20 -18
  8. package/dist/api/DeferredJobsApiClient.d.ts +8 -10
  9. package/dist/api/DeferredJobsApiClient.js +18 -15
  10. package/dist/api/constants.cjs +1 -1
  11. package/dist/api/constants.js +1 -1
  12. package/dist/api/index.cjs +4 -4
  13. package/dist/api/index.d.ts +2 -2
  14. package/dist/api/index.js +2 -2
  15. package/dist/endpoints/Accounts/Client.cjs +14 -13
  16. package/dist/endpoints/Accounts/Client.d.ts +6 -7
  17. package/dist/endpoints/Accounts/Client.js +12 -10
  18. package/dist/endpoints/Billing/Client.cjs +11 -11
  19. package/dist/endpoints/Billing/Client.d.ts +5 -6
  20. package/dist/endpoints/Billing/Client.js +9 -8
  21. package/dist/endpoints/CampaignRecipients/Client.cjs +26 -21
  22. package/dist/endpoints/CampaignRecipients/Client.d.ts +13 -14
  23. package/dist/endpoints/CampaignRecipients/Client.js +24 -18
  24. package/dist/endpoints/Campaigns/Client.cjs +38 -29
  25. package/dist/endpoints/Campaigns/Client.d.ts +14 -15
  26. package/dist/endpoints/Campaigns/Client.js +36 -26
  27. package/dist/endpoints/Contacts/Client.cjs +41 -32
  28. package/dist/endpoints/Contacts/Client.d.ts +15 -22
  29. package/dist/endpoints/Contacts/Client.js +39 -29
  30. package/dist/endpoints/ContactsExports/Client.cjs +20 -18
  31. package/dist/endpoints/ContactsExports/Client.d.ts +8 -31
  32. package/dist/endpoints/ContactsExports/Client.js +18 -15
  33. package/dist/endpoints/Coverage/Client.cjs +29 -23
  34. package/dist/endpoints/Coverage/Client.d.ts +12 -13
  35. package/dist/endpoints/Coverage/Client.js +27 -20
  36. package/dist/endpoints/Jobs/Client.cjs +8 -9
  37. package/dist/endpoints/Jobs/Client.d.ts +4 -5
  38. package/dist/endpoints/Jobs/Client.js +6 -6
  39. package/dist/endpoints/Licenses/Client.cjs +8 -9
  40. package/dist/endpoints/Licenses/Client.d.ts +4 -5
  41. package/dist/endpoints/Licenses/Client.js +6 -6
  42. package/dist/endpoints/NewsroomCategories/Client.cjs +20 -17
  43. package/dist/endpoints/NewsroomCategories/Client.d.ts +8 -9
  44. package/dist/endpoints/NewsroomCategories/Client.js +18 -14
  45. package/dist/endpoints/NewsroomContacts/Client.cjs +23 -19
  46. package/dist/endpoints/NewsroomContacts/Client.d.ts +9 -10
  47. package/dist/endpoints/NewsroomContacts/Client.js +21 -16
  48. package/dist/endpoints/NewsroomDomains/Client.cjs +23 -19
  49. package/dist/endpoints/NewsroomDomains/Client.d.ts +9 -10
  50. package/dist/endpoints/NewsroomDomains/Client.js +21 -16
  51. package/dist/endpoints/NewsroomGalleries/Client.cjs +26 -21
  52. package/dist/endpoints/NewsroomGalleries/Client.d.ts +10 -11
  53. package/dist/endpoints/NewsroomGalleries/Client.js +24 -18
  54. package/dist/endpoints/NewsroomHub/Client.cjs +26 -23
  55. package/dist/endpoints/NewsroomHub/Client.d.ts +8 -9
  56. package/dist/endpoints/NewsroomHub/Client.js +25 -21
  57. package/dist/endpoints/NewsroomLanguages/Client.cjs +26 -21
  58. package/dist/endpoints/NewsroomLanguages/Client.d.ts +16 -24
  59. package/dist/endpoints/NewsroomLanguages/Client.js +24 -18
  60. package/dist/endpoints/NewsroomPrivacyRequests/Client.cjs +11 -11
  61. package/dist/endpoints/NewsroomPrivacyRequests/Client.d.ts +5 -6
  62. package/dist/endpoints/NewsroomPrivacyRequests/Client.js +9 -8
  63. package/dist/endpoints/NewsroomSubscriptions/Client.cjs +24 -13
  64. package/dist/endpoints/NewsroomSubscriptions/Client.d.ts +8 -9
  65. package/dist/endpoints/NewsroomSubscriptions/Client.js +23 -11
  66. package/dist/endpoints/NewsroomThemes/Client.cjs +17 -15
  67. package/dist/endpoints/NewsroomThemes/Client.d.ts +7 -8
  68. package/dist/endpoints/NewsroomThemes/Client.js +15 -12
  69. package/dist/endpoints/NewsroomWebhooks/Client.cjs +20 -17
  70. package/dist/endpoints/NewsroomWebhooks/Client.d.ts +8 -9
  71. package/dist/endpoints/NewsroomWebhooks/Client.js +18 -14
  72. package/dist/endpoints/Newsrooms/Client.cjs +35 -27
  73. package/dist/endpoints/Newsrooms/Client.d.ts +13 -14
  74. package/dist/endpoints/Newsrooms/Client.js +33 -24
  75. package/dist/endpoints/NotificationSubscriptions/Client.cjs +11 -11
  76. package/dist/endpoints/NotificationSubscriptions/Client.d.ts +5 -6
  77. package/dist/endpoints/NotificationSubscriptions/Client.js +9 -8
  78. package/dist/endpoints/PricingTables/Client.cjs +11 -11
  79. package/dist/endpoints/PricingTables/Client.d.ts +5 -6
  80. package/dist/endpoints/PricingTables/Client.js +9 -8
  81. package/dist/endpoints/SenderAddresses/Client.cjs +20 -17
  82. package/dist/endpoints/SenderAddresses/Client.d.ts +8 -9
  83. package/dist/endpoints/SenderAddresses/Client.js +18 -14
  84. package/dist/endpoints/Snippets/Client.cjs +20 -17
  85. package/dist/endpoints/Snippets/Client.d.ts +8 -9
  86. package/dist/endpoints/Snippets/Client.js +18 -14
  87. package/dist/endpoints/Stories/Client.cjs +63 -46
  88. package/dist/endpoints/Stories/Client.d.ts +109 -128
  89. package/dist/endpoints/Stories/Client.js +62 -44
  90. package/dist/endpoints/Subscriptions/Client.cjs +20 -17
  91. package/dist/endpoints/Subscriptions/Client.d.ts +8 -9
  92. package/dist/endpoints/Subscriptions/Client.js +18 -14
  93. package/package.json +1 -1
@@ -1,20 +1,16 @@
1
1
  import { routing } from "../../routing.js";
2
2
  import { SortOrder } from "../../types/index.js";
3
- export class Client {
4
- constructor(apiClient) {
5
- this.apiClient = apiClient;
6
- }
7
-
3
+ export function createClient(api) {
8
4
  /**
9
5
  * List Contacts Exports with sorting, and pagination.
10
6
  */
11
- async list(options) {
7
+ async function list(options) {
12
8
  const {
13
9
  limit,
14
10
  offset,
15
11
  sortOrder
16
12
  } = options;
17
- return this.apiClient.get(routing.contactsExportsUrl, {
13
+ return api.get(routing.contactsExportsUrl, {
18
14
  query: {
19
15
  limit,
20
16
  offset,
@@ -26,7 +22,7 @@ export class Client {
26
22
  /**
27
23
  * List Contacts Exports with sorting, pagination, and filtering.
28
24
  */
29
- async search(options) {
25
+ async function search(options) {
30
26
  const {
31
27
  query,
32
28
  limit,
@@ -34,7 +30,7 @@ export class Client {
34
30
  sortOrder
35
31
  } = options;
36
32
  const url = `${routing.contactsExportsUrl}/search`;
37
- return this.apiClient.post(url, {
33
+ return api.post(url, {
38
34
  payload: {
39
35
  limit,
40
36
  offset,
@@ -47,9 +43,9 @@ export class Client {
47
43
  /**
48
44
  * Fetch Contacts Export object by its uuid.
49
45
  */
50
- async get(uuid) {
46
+ async function get(uuid) {
51
47
  const url = `${routing.contactsExportsUrl}/${uuid}`;
52
- const response = await this.apiClient.get(url);
48
+ const response = await api.get(url);
53
49
  return response.export;
54
50
  }
55
51
 
@@ -61,12 +57,12 @@ export class Client {
61
57
  * Otherwise, returns an export with `status: "new"`,
62
58
  * and will notify the user over email when it's done.
63
59
  */
64
- async create(selector) {
60
+ async function create(selector) {
65
61
  const {
66
62
  query,
67
63
  scope
68
64
  } = selector;
69
- const response = await this.apiClient.post(routing.contactsExportsUrl, {
65
+ const response = await api.post(routing.contactsExportsUrl, {
70
66
  payload: {
71
67
  contacts: {
72
68
  query,
@@ -82,11 +78,18 @@ export class Client {
82
78
  * Only works for exports with status = "done"
83
79
  * Fails with Method Not Allowed (405) error for pending and failed exports.
84
80
  */
85
- async download(uuid) {
81
+ async function download(uuid) {
86
82
  const url = `${routing.contactsExportsUrl}/${uuid}/download`;
87
- const response = await this.apiClient.post(url);
83
+ const response = await api.post(url);
88
84
  return {
89
85
  downloadUrl: response.download_url
90
86
  };
91
87
  }
88
+ return {
89
+ list,
90
+ search,
91
+ get,
92
+ create,
93
+ download
94
+ };
92
95
  }
@@ -3,14 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Client = void 0;
6
+ exports.createClient = createClient;
7
7
  var _routing = require("../../routing.cjs");
8
8
  var _index = require("../../types/index.cjs");
9
- class Client {
10
- constructor(apiClient) {
11
- this.apiClient = apiClient;
12
- }
13
- async list(options = {}, scope) {
9
+ function createClient(api) {
10
+ async function list(options = {}, scope) {
14
11
  const {
15
12
  includeDeleted,
16
13
  limit,
@@ -19,7 +16,7 @@ class Client {
19
16
  } = options;
20
17
  // TODO: Switch to `scope` API parameter
21
18
  const url = scope?.story ? _routing.routing.storyCoverageUrl.replace(':story_id', String(scope.story)) : _routing.routing.coverageUrl;
22
- return this.apiClient.get(url, {
19
+ return api.get(url, {
23
20
  query: {
24
21
  include_deleted: includeDeleted ? 'on' : undefined,
25
22
  limit,
@@ -28,7 +25,7 @@ class Client {
28
25
  }
29
26
  });
30
27
  }
31
- async search(options = {}, scope) {
28
+ async function search(options = {}, scope) {
32
29
  const {
33
30
  includeDeleted,
34
31
  query,
@@ -39,7 +36,7 @@ class Client {
39
36
  // TODO: Switch to `scope` API parameter
40
37
  const url = scope?.story ? _routing.routing.storyCoverageUrl.replace(':story_id', String(scope.story)) : _routing.routing.coverageUrl;
41
38
  // TODO: Introduce dedicated Search POST API
42
- return this.apiClient.get(url, {
39
+ return api.get(url, {
43
40
  query: {
44
41
  include_deleted: includeDeleted ? 'on' : undefined,
45
42
  query: _index.Query.stringify(query),
@@ -49,18 +46,18 @@ class Client {
49
46
  }
50
47
  });
51
48
  }
52
- async get(id, includeDeleted = false) {
49
+ async function get(id, includeDeleted = false) {
53
50
  const url = `${_routing.routing.coverageUrl}/${id}`;
54
51
  const {
55
52
  coverage
56
- } = await this.apiClient.get(url, {
53
+ } = await api.get(url, {
57
54
  query: {
58
55
  include_deleted: includeDeleted ? 'on' : undefined
59
56
  }
60
57
  });
61
58
  return coverage;
62
59
  }
63
- async getByExternalReferenceId(externalReferenceId) {
60
+ async function getByExternalReferenceId(externalReferenceId) {
64
61
  const query = JSON.stringify({
65
62
  external_reference_id: {
66
63
  $in: [externalReferenceId]
@@ -68,42 +65,51 @@ class Client {
68
65
  });
69
66
  const {
70
67
  coverage
71
- } = await this.search({
68
+ } = await search({
72
69
  includeDeleted: true,
73
70
  query
74
71
  });
75
72
  return coverage[0] || null;
76
73
  }
77
- async create(payload) {
74
+ async function create(payload) {
78
75
  const {
79
76
  coverage
80
- } = await this.apiClient.post(_routing.routing.coverageUrl, {
77
+ } = await api.post(_routing.routing.coverageUrl, {
81
78
  payload
82
79
  });
83
80
  return coverage;
84
81
  }
85
- async update(id, payload) {
82
+ async function update(id, payload) {
86
83
  const {
87
84
  coverage
88
- } = await this.apiClient.patch(`${_routing.routing.coverageUrl}/${id}`, {
85
+ } = await api.patch(`${_routing.routing.coverageUrl}/${id}`, {
89
86
  payload
90
87
  });
91
88
  return coverage;
92
89
  }
93
- async remove(id) {
94
- return this.apiClient.delete(`${_routing.routing.coverageUrl}/${id}`);
90
+ async function doDelete(id) {
91
+ return api.delete(`${_routing.routing.coverageUrl}/${id}`);
95
92
  }
96
- async bulkRemove(options) {
93
+ async function bulkDelete(options) {
97
94
  const {
98
95
  selection,
99
96
  query
100
97
  } = options;
101
- return this.apiClient.delete(_routing.routing.coverageUrl, {
98
+ return api.delete(_routing.routing.coverageUrl, {
102
99
  payload: {
103
100
  selection,
104
101
  query
105
102
  }
106
103
  });
107
104
  }
108
- }
109
- exports.Client = Client;
105
+ return {
106
+ list,
107
+ search,
108
+ get,
109
+ getByExternalReferenceId,
110
+ create,
111
+ update,
112
+ delete: doDelete,
113
+ bulkDelete
114
+ };
115
+ }
@@ -3,21 +3,20 @@ import type { DeferredJobsApiClient } from '../../api';
3
3
  import type { CoverageEntry, SelectionValue } from '../../types';
4
4
  import type { CreateRequest, ListOptions, ListResponse, Scope, SearchOptions, UpdateRequest } from './types';
5
5
  type CoverageId = CoverageEntry['uuid'] | CoverageEntry['id'];
6
- export declare class Client {
7
- private readonly apiClient;
8
- constructor(apiClient: DeferredJobsApiClient);
9
- list(options?: ListOptions, scope?: Scope): Promise<ListResponse>;
10
- search(options?: SearchOptions, scope?: Scope): Promise<ListResponse>;
11
- get(id: CoverageId, includeDeleted?: boolean): Promise<CoverageEntry>;
12
- getByExternalReferenceId(externalReferenceId: string): Promise<CoverageEntry | null>;
13
- create(payload: CreateRequest): Promise<CoverageEntry>;
14
- update(id: CoverageId, payload: UpdateRequest): Promise<CoverageEntry>;
15
- remove(id: CoverageId): Promise<void>;
16
- bulkRemove(options: Partial<{
6
+ export type Client = ReturnType<typeof createClient>;
7
+ export declare function createClient(api: DeferredJobsApiClient): {
8
+ list: (options?: ListOptions, scope?: Scope) => Promise<ListResponse>;
9
+ search: (options?: SearchOptions, scope?: Scope) => Promise<ListResponse>;
10
+ get: (id: CoverageId, includeDeleted?: boolean) => Promise<CoverageEntry>;
11
+ getByExternalReferenceId: (externalReferenceId: string) => Promise<CoverageEntry | null>;
12
+ create: (payload: CreateRequest) => Promise<CoverageEntry>;
13
+ update: (id: CoverageId, payload: UpdateRequest) => Promise<CoverageEntry>;
14
+ delete: (id: CoverageId) => Promise<void>;
15
+ bulkDelete: (options: Partial<{
17
16
  selection: SelectionValue;
18
17
  query: string;
19
- }>): ProgressPromise<{
18
+ }>) => ProgressPromise<{
20
19
  records_deleted_number: number;
21
20
  }>;
22
- }
21
+ };
23
22
  export {};
@@ -1,10 +1,7 @@
1
1
  import { routing } from "../../routing.js";
2
2
  import { Query, SortOrder } from "../../types/index.js";
3
- export class Client {
4
- constructor(apiClient) {
5
- this.apiClient = apiClient;
6
- }
7
- async list(options = {}, scope) {
3
+ export function createClient(api) {
4
+ async function list(options = {}, scope) {
8
5
  const {
9
6
  includeDeleted,
10
7
  limit,
@@ -13,7 +10,7 @@ export class Client {
13
10
  } = options;
14
11
  // TODO: Switch to `scope` API parameter
15
12
  const url = scope?.story ? routing.storyCoverageUrl.replace(':story_id', String(scope.story)) : routing.coverageUrl;
16
- return this.apiClient.get(url, {
13
+ return api.get(url, {
17
14
  query: {
18
15
  include_deleted: includeDeleted ? 'on' : undefined,
19
16
  limit,
@@ -22,7 +19,7 @@ export class Client {
22
19
  }
23
20
  });
24
21
  }
25
- async search(options = {}, scope) {
22
+ async function search(options = {}, scope) {
26
23
  const {
27
24
  includeDeleted,
28
25
  query,
@@ -33,7 +30,7 @@ export class Client {
33
30
  // TODO: Switch to `scope` API parameter
34
31
  const url = scope?.story ? routing.storyCoverageUrl.replace(':story_id', String(scope.story)) : routing.coverageUrl;
35
32
  // TODO: Introduce dedicated Search POST API
36
- return this.apiClient.get(url, {
33
+ return api.get(url, {
37
34
  query: {
38
35
  include_deleted: includeDeleted ? 'on' : undefined,
39
36
  query: Query.stringify(query),
@@ -43,18 +40,18 @@ export class Client {
43
40
  }
44
41
  });
45
42
  }
46
- async get(id, includeDeleted = false) {
43
+ async function get(id, includeDeleted = false) {
47
44
  const url = `${routing.coverageUrl}/${id}`;
48
45
  const {
49
46
  coverage
50
- } = await this.apiClient.get(url, {
47
+ } = await api.get(url, {
51
48
  query: {
52
49
  include_deleted: includeDeleted ? 'on' : undefined
53
50
  }
54
51
  });
55
52
  return coverage;
56
53
  }
57
- async getByExternalReferenceId(externalReferenceId) {
54
+ async function getByExternalReferenceId(externalReferenceId) {
58
55
  const query = JSON.stringify({
59
56
  external_reference_id: {
60
57
  $in: [externalReferenceId]
@@ -62,41 +59,51 @@ export class Client {
62
59
  });
63
60
  const {
64
61
  coverage
65
- } = await this.search({
62
+ } = await search({
66
63
  includeDeleted: true,
67
64
  query
68
65
  });
69
66
  return coverage[0] || null;
70
67
  }
71
- async create(payload) {
68
+ async function create(payload) {
72
69
  const {
73
70
  coverage
74
- } = await this.apiClient.post(routing.coverageUrl, {
71
+ } = await api.post(routing.coverageUrl, {
75
72
  payload
76
73
  });
77
74
  return coverage;
78
75
  }
79
- async update(id, payload) {
76
+ async function update(id, payload) {
80
77
  const {
81
78
  coverage
82
- } = await this.apiClient.patch(`${routing.coverageUrl}/${id}`, {
79
+ } = await api.patch(`${routing.coverageUrl}/${id}`, {
83
80
  payload
84
81
  });
85
82
  return coverage;
86
83
  }
87
- async remove(id) {
88
- return this.apiClient.delete(`${routing.coverageUrl}/${id}`);
84
+ async function doDelete(id) {
85
+ return api.delete(`${routing.coverageUrl}/${id}`);
89
86
  }
90
- async bulkRemove(options) {
87
+ async function bulkDelete(options) {
91
88
  const {
92
89
  selection,
93
90
  query
94
91
  } = options;
95
- return this.apiClient.delete(routing.coverageUrl, {
92
+ return api.delete(routing.coverageUrl, {
96
93
  payload: {
97
94
  selection,
98
95
  query
99
96
  }
100
97
  });
101
98
  }
99
+ return {
100
+ list,
101
+ search,
102
+ get,
103
+ getByExternalReferenceId,
104
+ create,
105
+ update,
106
+ delete: doDelete,
107
+ bulkDelete
108
+ };
102
109
  }
@@ -3,17 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Client = void 0;
6
+ exports.createClient = createClient;
7
7
  var _routing = require("../../routing.cjs");
8
- class Client {
9
- constructor(apiClient) {
10
- this.apiClient = apiClient;
11
- }
12
- async get(id) {
8
+ function createClient(api) {
9
+ async function get(id) {
13
10
  const {
14
11
  job
15
- } = await this.apiClient.get(`${_routing.routing.jobsUrl}/${id}`);
12
+ } = await api.get(`${_routing.routing.jobsUrl}/${id}`);
16
13
  return job.state;
17
14
  }
18
- }
19
- exports.Client = Client;
15
+ return {
16
+ get
17
+ };
18
+ }
@@ -1,7 +1,6 @@
1
1
  import type { DeferredJobsApiClient } from '../../api';
2
2
  import type { JobState } from '../../types';
3
- export declare class Client {
4
- private readonly apiClient;
5
- constructor(apiClient: DeferredJobsApiClient);
6
- get(id: string): Promise<JobState>;
7
- }
3
+ export type Client = ReturnType<typeof createClient>;
4
+ export declare function createClient(api: DeferredJobsApiClient): {
5
+ get: (id: string) => Promise<JobState>;
6
+ };
@@ -1,12 +1,12 @@
1
1
  import { routing } from "../../routing.js";
2
- export class Client {
3
- constructor(apiClient) {
4
- this.apiClient = apiClient;
5
- }
6
- async get(id) {
2
+ export function createClient(api) {
3
+ async function get(id) {
7
4
  const {
8
5
  job
9
- } = await this.apiClient.get(`${routing.jobsUrl}/${id}`);
6
+ } = await api.get(`${routing.jobsUrl}/${id}`);
10
7
  return job.state;
11
8
  }
9
+ return {
10
+ get
11
+ };
12
12
  }
@@ -3,18 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Client = void 0;
6
+ exports.createClient = createClient;
7
7
  var _routing = require("../../routing.cjs");
8
- class Client {
9
- constructor(apiClient) {
10
- this.apiClient = apiClient;
11
- }
12
- async get() {
8
+ function createClient(api) {
9
+ async function get() {
13
10
  const url = _routing.routing.licenseUrl;
14
11
  const {
15
12
  license
16
- } = await this.apiClient.get(`${url}/self`);
13
+ } = await api.get(`${url}/self`);
17
14
  return license;
18
15
  }
19
- }
20
- exports.Client = Client;
16
+ return {
17
+ get
18
+ };
19
+ }
@@ -1,7 +1,6 @@
1
1
  import type { DeferredJobsApiClient } from '../../api';
2
2
  import type { License } from '../../types';
3
- export declare class Client {
4
- private readonly apiClient;
5
- constructor(apiClient: DeferredJobsApiClient);
6
- get(): Promise<License>;
7
- }
3
+ export type Client = ReturnType<typeof createClient>;
4
+ export declare function createClient(api: DeferredJobsApiClient): {
5
+ get: () => Promise<License>;
6
+ };
@@ -1,13 +1,13 @@
1
1
  import { routing } from "../../routing.js";
2
- export class Client {
3
- constructor(apiClient) {
4
- this.apiClient = apiClient;
5
- }
6
- async get() {
2
+ export function createClient(api) {
3
+ async function get() {
7
4
  const url = routing.licenseUrl;
8
5
  const {
9
6
  license
10
- } = await this.apiClient.get(`${url}/self`);
7
+ } = await api.get(`${url}/self`);
11
8
  return license;
12
9
  }
10
+ return {
11
+ get
12
+ };
13
13
  }
@@ -3,54 +3,57 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Client = void 0;
6
+ exports.createClient = createClient;
7
7
  var _routing = require("../../routing.cjs");
8
8
  var _index = require("../../types/index.cjs");
9
- class Client {
10
- constructor(apiClient) {
11
- this.apiClient = apiClient;
12
- }
13
- async list(newsroomId, {
9
+ function createClient(api) {
10
+ async function list(newsroomId, {
14
11
  sortOrder
15
12
  } = {}) {
16
13
  const url = _routing.routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
17
14
  const {
18
15
  categories
19
- } = await this.apiClient.get(url, {
16
+ } = await api.get(url, {
20
17
  query: {
21
18
  sort: _index.SortOrder.stringify(sortOrder)
22
19
  }
23
20
  });
24
21
  return categories;
25
22
  }
26
- async get(newsroomId, categoryId) {
23
+ async function get(newsroomId, categoryId) {
27
24
  const url = _routing.routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
28
25
  const {
29
26
  category
30
- } = await this.apiClient.get(`${url}/${categoryId}`);
27
+ } = await api.get(`${url}/${categoryId}`);
31
28
  return category;
32
29
  }
33
- async create(newsroomId, payload) {
30
+ async function create(newsroomId, payload) {
34
31
  const url = _routing.routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
35
32
  const {
36
33
  category
37
- } = await this.apiClient.post(url, {
34
+ } = await api.post(url, {
38
35
  payload
39
36
  });
40
37
  return category;
41
38
  }
42
- async update(newsroomId, categoryId, payload) {
39
+ async function update(newsroomId, categoryId, payload) {
43
40
  const url = _routing.routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
44
41
  const {
45
42
  category
46
- } = await this.apiClient.patch(`${url}/${categoryId}`, {
43
+ } = await api.patch(`${url}/${categoryId}`, {
47
44
  payload
48
45
  });
49
46
  return category;
50
47
  }
51
- async remove(newsroomId, categoryId) {
48
+ async function doDelete(newsroomId, categoryId) {
52
49
  const url = _routing.routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
53
- return this.apiClient.delete(`${url}/${categoryId}`);
50
+ return api.delete(`${url}/${categoryId}`);
54
51
  }
55
- }
56
- exports.Client = Client;
52
+ return {
53
+ list,
54
+ get,
55
+ create,
56
+ update,
57
+ delete: doDelete
58
+ };
59
+ }
@@ -2,13 +2,12 @@ import type { DeferredJobsApiClient } from '../../api';
2
2
  import type { Category, Newsroom } from '../../types';
3
3
  import type { ListOptions, CreateRequest, UpdateRequest } from './types';
4
4
  type NewsroomId = Newsroom['uuid'] | Newsroom['id'];
5
- export declare class Client {
6
- private readonly apiClient;
7
- constructor(apiClient: DeferredJobsApiClient);
8
- list(newsroomId: NewsroomId, { sortOrder }?: ListOptions): Promise<Category[]>;
9
- get(newsroomId: NewsroomId, categoryId: Category['id']): Promise<Category>;
10
- create(newsroomId: NewsroomId, payload: CreateRequest): Promise<Category>;
11
- update(newsroomId: NewsroomId, categoryId: Category['id'], payload: UpdateRequest): Promise<Category>;
12
- remove(newsroomId: NewsroomId, categoryId: Category['id']): Promise<void>;
13
- }
5
+ export type Client = ReturnType<typeof createClient>;
6
+ export declare function createClient(api: DeferredJobsApiClient): {
7
+ list: (newsroomId: NewsroomId, { sortOrder }?: ListOptions) => Promise<Category[]>;
8
+ get: (newsroomId: NewsroomId, categoryId: Category['id']) => Promise<Category>;
9
+ create: (newsroomId: NewsroomId, payload: CreateRequest) => Promise<Category>;
10
+ update: (newsroomId: NewsroomId, categoryId: Category['id'], payload: UpdateRequest) => Promise<Category>;
11
+ delete: (newsroomId: NewsroomId, categoryId: Category['id']) => Promise<void>;
12
+ };
14
13
  export {};
@@ -1,49 +1,53 @@
1
1
  import { routing } from "../../routing.js";
2
2
  import { SortOrder } from "../../types/index.js";
3
- export class Client {
4
- constructor(apiClient) {
5
- this.apiClient = apiClient;
6
- }
7
- async list(newsroomId, {
3
+ export function createClient(api) {
4
+ async function list(newsroomId, {
8
5
  sortOrder
9
6
  } = {}) {
10
7
  const url = routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
11
8
  const {
12
9
  categories
13
- } = await this.apiClient.get(url, {
10
+ } = await api.get(url, {
14
11
  query: {
15
12
  sort: SortOrder.stringify(sortOrder)
16
13
  }
17
14
  });
18
15
  return categories;
19
16
  }
20
- async get(newsroomId, categoryId) {
17
+ async function get(newsroomId, categoryId) {
21
18
  const url = routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
22
19
  const {
23
20
  category
24
- } = await this.apiClient.get(`${url}/${categoryId}`);
21
+ } = await api.get(`${url}/${categoryId}`);
25
22
  return category;
26
23
  }
27
- async create(newsroomId, payload) {
24
+ async function create(newsroomId, payload) {
28
25
  const url = routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
29
26
  const {
30
27
  category
31
- } = await this.apiClient.post(url, {
28
+ } = await api.post(url, {
32
29
  payload
33
30
  });
34
31
  return category;
35
32
  }
36
- async update(newsroomId, categoryId, payload) {
33
+ async function update(newsroomId, categoryId, payload) {
37
34
  const url = routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
38
35
  const {
39
36
  category
40
- } = await this.apiClient.patch(`${url}/${categoryId}`, {
37
+ } = await api.patch(`${url}/${categoryId}`, {
41
38
  payload
42
39
  });
43
40
  return category;
44
41
  }
45
- async remove(newsroomId, categoryId) {
42
+ async function doDelete(newsroomId, categoryId) {
46
43
  const url = routing.newsroomCategoriesUrl.replace(':newsroom_id', String(newsroomId));
47
- return this.apiClient.delete(`${url}/${categoryId}`);
44
+ return api.delete(`${url}/${categoryId}`);
48
45
  }
46
+ return {
47
+ list,
48
+ get,
49
+ create,
50
+ update,
51
+ delete: doDelete
52
+ };
49
53
  }