@prezly/sdk 11.8.1-cjs → 11.9.1

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 (262) hide show
  1. package/dist/Client.cjs +45 -0
  2. package/dist/Client.js +27 -33
  3. package/dist/api/ApiClient.cjs +95 -0
  4. package/dist/api/ApiClient.js +12 -19
  5. package/dist/api/DeferredJobsApiClient.cjs +99 -0
  6. package/dist/api/DeferredJobsApiClient.js +12 -19
  7. package/dist/api/constants.cjs +10 -0
  8. package/dist/api/constants.js +2 -9
  9. package/dist/api/index.cjs +19 -0
  10. package/dist/api/index.js +2 -19
  11. package/dist/endpoints/Accounts/Client.cjs +29 -0
  12. package/dist/endpoints/Accounts/Client.js +6 -13
  13. package/dist/endpoints/Accounts/index.cjs +25 -0
  14. package/dist/endpoints/Accounts/index.js +2 -25
  15. package/dist/endpoints/Accounts/types.cjs +1 -0
  16. package/dist/endpoints/Accounts/types.js +1 -1
  17. package/dist/endpoints/Billing/Client.cjs +19 -0
  18. package/dist/endpoints/Billing/Client.js +4 -11
  19. package/dist/endpoints/Billing/index.cjs +25 -0
  20. package/dist/endpoints/Billing/index.js +2 -25
  21. package/dist/endpoints/Billing/types.cjs +25 -0
  22. package/dist/endpoints/Billing/types.js +6 -15
  23. package/dist/endpoints/CampaignRecipients/Client.cjs +85 -0
  24. package/dist/endpoints/CampaignRecipients/Client.js +12 -19
  25. package/dist/endpoints/CampaignRecipients/index.cjs +37 -0
  26. package/dist/endpoints/CampaignRecipients/index.js +3 -37
  27. package/dist/endpoints/CampaignRecipients/types.cjs +1 -0
  28. package/dist/endpoints/CampaignRecipients/types.js +1 -1
  29. package/dist/endpoints/Campaigns/Client.cjs +92 -0
  30. package/dist/endpoints/Campaigns/Client.js +18 -25
  31. package/dist/endpoints/Campaigns/index.cjs +25 -0
  32. package/dist/endpoints/Campaigns/index.js +2 -25
  33. package/dist/endpoints/Campaigns/types.cjs +1 -0
  34. package/dist/endpoints/Campaigns/types.js +1 -1
  35. package/dist/endpoints/ContactsExports/Client.cjs +98 -0
  36. package/dist/endpoints/ContactsExports/Client.js +8 -15
  37. package/dist/endpoints/ContactsExports/index.cjs +37 -0
  38. package/dist/endpoints/ContactsExports/index.js +3 -37
  39. package/dist/endpoints/ContactsExports/types.cjs +1 -0
  40. package/dist/endpoints/ContactsExports/types.js +1 -1
  41. package/dist/endpoints/Coverage/Client.cjs +109 -0
  42. package/dist/endpoints/Coverage/Client.js +12 -19
  43. package/dist/endpoints/Coverage/index.cjs +25 -0
  44. package/dist/endpoints/Coverage/index.js +2 -25
  45. package/dist/endpoints/Coverage/types.cjs +1 -0
  46. package/dist/endpoints/Coverage/types.js +1 -1
  47. package/dist/endpoints/Jobs/Client.cjs +19 -0
  48. package/dist/endpoints/Jobs/Client.js +4 -11
  49. package/dist/endpoints/Jobs/index.cjs +25 -0
  50. package/dist/endpoints/Jobs/index.js +2 -25
  51. package/dist/endpoints/Jobs/types.cjs +1 -0
  52. package/dist/endpoints/Jobs/types.js +1 -1
  53. package/dist/endpoints/Licenses/Client.cjs +20 -0
  54. package/dist/endpoints/Licenses/Client.js +4 -11
  55. package/dist/endpoints/Licenses/index.cjs +15 -0
  56. package/dist/endpoints/Licenses/index.js +1 -15
  57. package/dist/endpoints/NewsroomCategories/Client.cjs +55 -0
  58. package/dist/endpoints/NewsroomCategories/Client.js +8 -15
  59. package/dist/endpoints/NewsroomCategories/index.cjs +25 -0
  60. package/dist/endpoints/NewsroomCategories/index.js +2 -25
  61. package/dist/endpoints/NewsroomCategories/types.cjs +1 -0
  62. package/dist/endpoints/NewsroomCategories/types.js +1 -1
  63. package/dist/endpoints/NewsroomContacts/Client.cjs +76 -0
  64. package/dist/endpoints/NewsroomContacts/Client.js +11 -18
  65. package/dist/endpoints/NewsroomContacts/index.cjs +25 -0
  66. package/dist/endpoints/NewsroomContacts/index.js +2 -25
  67. package/dist/endpoints/NewsroomContacts/types.cjs +1 -0
  68. package/dist/endpoints/NewsroomContacts/types.js +1 -1
  69. package/dist/endpoints/NewsroomDomains/Client.cjs +48 -0
  70. package/dist/endpoints/NewsroomDomains/Client.js +9 -16
  71. package/dist/endpoints/NewsroomDomains/index.cjs +25 -0
  72. package/dist/endpoints/NewsroomDomains/index.js +2 -25
  73. package/dist/endpoints/NewsroomDomains/types.cjs +1 -0
  74. package/dist/endpoints/NewsroomDomains/types.js +1 -1
  75. package/dist/endpoints/NewsroomGalleries/Client.cjs +82 -0
  76. package/dist/endpoints/NewsroomGalleries/Client.js +13 -20
  77. package/dist/endpoints/NewsroomGalleries/index.cjs +25 -0
  78. package/dist/endpoints/NewsroomGalleries/index.js +2 -25
  79. package/dist/endpoints/NewsroomGalleries/types.cjs +1 -0
  80. package/dist/endpoints/NewsroomGalleries/types.js +1 -1
  81. package/dist/endpoints/NewsroomLanguages/Client.cjs +100 -0
  82. package/dist/endpoints/NewsroomLanguages/Client.js +10 -17
  83. package/dist/endpoints/NewsroomLanguages/index.cjs +25 -0
  84. package/dist/endpoints/NewsroomLanguages/index.js +2 -25
  85. package/dist/endpoints/NewsroomLanguages/lib.cjs +9 -0
  86. package/dist/endpoints/NewsroomLanguages/lib.js +1 -7
  87. package/dist/endpoints/NewsroomLanguages/types.cjs +1 -0
  88. package/dist/endpoints/NewsroomLanguages/types.js +1 -1
  89. package/dist/endpoints/NewsroomPrivacyRequests/Client.cjs +29 -0
  90. package/dist/endpoints/NewsroomPrivacyRequests/Client.js +5 -12
  91. package/dist/endpoints/NewsroomPrivacyRequests/index.cjs +25 -0
  92. package/dist/endpoints/NewsroomPrivacyRequests/index.js +2 -25
  93. package/dist/endpoints/NewsroomPrivacyRequests/types.cjs +1 -0
  94. package/dist/endpoints/NewsroomPrivacyRequests/types.js +1 -1
  95. package/dist/endpoints/NewsroomSubscriptions/Client.cjs +22 -0
  96. package/dist/endpoints/NewsroomSubscriptions/Client.js +4 -11
  97. package/dist/endpoints/NewsroomSubscriptions/index.cjs +25 -0
  98. package/dist/endpoints/NewsroomSubscriptions/index.js +2 -25
  99. package/dist/endpoints/NewsroomSubscriptions/types.cjs +1 -0
  100. package/dist/endpoints/NewsroomSubscriptions/types.js +1 -1
  101. package/dist/endpoints/NewsroomThemes/Client.cjs +43 -0
  102. package/dist/endpoints/NewsroomThemes/Client.js +7 -14
  103. package/dist/endpoints/NewsroomThemes/index.cjs +15 -0
  104. package/dist/endpoints/NewsroomThemes/index.js +1 -15
  105. package/dist/endpoints/NewsroomWebhooks/Client.cjs +49 -0
  106. package/dist/endpoints/NewsroomWebhooks/Client.js +8 -15
  107. package/dist/endpoints/NewsroomWebhooks/index.cjs +25 -0
  108. package/dist/endpoints/NewsroomWebhooks/index.js +2 -25
  109. package/dist/endpoints/NewsroomWebhooks/types.cjs +1 -0
  110. package/dist/endpoints/NewsroomWebhooks/types.js +1 -1
  111. package/dist/endpoints/Newsrooms/Client.cjs +97 -0
  112. package/dist/endpoints/Newsrooms/Client.js +15 -22
  113. package/dist/endpoints/Newsrooms/index.cjs +25 -0
  114. package/dist/endpoints/Newsrooms/index.js +2 -25
  115. package/dist/endpoints/Newsrooms/types.cjs +1 -0
  116. package/dist/endpoints/Newsrooms/types.js +1 -1
  117. package/dist/endpoints/NotificationSubscriptions/Client.cjs +29 -0
  118. package/dist/endpoints/NotificationSubscriptions/Client.js +5 -12
  119. package/dist/endpoints/NotificationSubscriptions/index.cjs +25 -0
  120. package/dist/endpoints/NotificationSubscriptions/index.js +2 -25
  121. package/dist/endpoints/NotificationSubscriptions/types.cjs +1 -0
  122. package/dist/endpoints/NotificationSubscriptions/types.js +1 -1
  123. package/dist/endpoints/SenderAddresses/Client.cjs +44 -0
  124. package/dist/endpoints/SenderAddresses/Client.js +8 -15
  125. package/dist/endpoints/SenderAddresses/index.cjs +25 -0
  126. package/dist/endpoints/SenderAddresses/index.js +2 -25
  127. package/dist/endpoints/SenderAddresses/types.cjs +1 -0
  128. package/dist/endpoints/SenderAddresses/types.js +1 -1
  129. package/dist/endpoints/Signup/Client.cjs +21 -0
  130. package/dist/endpoints/Signup/Client.js +4 -11
  131. package/dist/endpoints/Signup/index.cjs +25 -0
  132. package/dist/endpoints/Signup/index.js +2 -25
  133. package/dist/endpoints/Signup/types.cjs +12 -0
  134. package/dist/endpoints/Signup/types.js +2 -9
  135. package/dist/endpoints/Snippets/Client.cjs +49 -0
  136. package/dist/endpoints/Snippets/Client.js +8 -15
  137. package/dist/endpoints/Snippets/index.cjs +25 -0
  138. package/dist/endpoints/Snippets/index.js +2 -25
  139. package/dist/endpoints/Snippets/types.cjs +1 -0
  140. package/dist/endpoints/Snippets/types.js +1 -1
  141. package/dist/endpoints/Stories/Client.cjs +290 -0
  142. package/dist/endpoints/Stories/Client.d.ts +25 -20
  143. package/dist/endpoints/Stories/Client.js +22 -30
  144. package/dist/endpoints/Stories/index.cjs +35 -0
  145. package/dist/endpoints/Stories/index.js +3 -35
  146. package/dist/endpoints/Stories/scopes.cjs +15 -0
  147. package/dist/endpoints/Stories/scopes.js +4 -11
  148. package/dist/endpoints/Stories/types.cjs +51 -0
  149. package/dist/endpoints/Stories/types.js +2 -10
  150. package/dist/endpoints/Subscriptions/Client.cjs +58 -0
  151. package/dist/endpoints/Subscriptions/Client.js +8 -15
  152. package/dist/endpoints/Subscriptions/index.cjs +25 -0
  153. package/dist/endpoints/Subscriptions/index.js +2 -25
  154. package/dist/endpoints/Subscriptions/types.cjs +15 -0
  155. package/dist/endpoints/Subscriptions/types.js +2 -9
  156. package/dist/endpoints/index.cjs +56 -0
  157. package/dist/endpoints/index.js +24 -56
  158. package/dist/http/ApiError.cjs +21 -0
  159. package/dist/http/ApiError.js +2 -9
  160. package/dist/http/Http.cjs +69 -0
  161. package/dist/http/Http.js +14 -21
  162. package/dist/http/constants.cjs +12 -0
  163. package/dist/http/constants.js +3 -12
  164. package/dist/http/createRequest.cjs +106 -0
  165. package/dist/http/createRequest.js +13 -20
  166. package/dist/http/index.cjs +39 -0
  167. package/dist/http/index.js +4 -39
  168. package/dist/http/lib.cjs +39 -0
  169. package/dist/http/lib.js +6 -16
  170. package/dist/http/types.cjs +25 -0
  171. package/dist/http/types.js +4 -12
  172. package/dist/index.cjs +56 -0
  173. package/dist/index.js +5 -56
  174. package/dist/routing.cjs +38 -0
  175. package/dist/routing.js +2 -9
  176. package/dist/types/Campaign.cjs +69 -0
  177. package/dist/types/Campaign.js +4 -11
  178. package/dist/types/Category.cjs +1 -0
  179. package/dist/types/Category.js +1 -1
  180. package/dist/types/Contact.cjs +82 -0
  181. package/dist/types/Contact.js +2 -9
  182. package/dist/types/ContactDuplicateSuggestion.cjs +17 -0
  183. package/dist/types/ContactDuplicateSuggestion.js +2 -9
  184. package/dist/types/ContactsExport.cjs +17 -0
  185. package/dist/types/ContactsExport.js +2 -9
  186. package/dist/types/ContactsScope.cjs +19 -0
  187. package/dist/types/ContactsScope.js +2 -9
  188. package/dist/types/Country.cjs +1 -0
  189. package/dist/types/Country.js +1 -1
  190. package/dist/types/CoverageEntry.cjs +32 -0
  191. package/dist/types/CoverageEntry.js +2 -9
  192. package/dist/types/Culture.cjs +16 -0
  193. package/dist/types/Culture.js +2 -9
  194. package/dist/types/Currency.cjs +13 -0
  195. package/dist/types/Currency.js +2 -9
  196. package/dist/types/DnsConfigurationInstruction.cjs +1 -0
  197. package/dist/types/DnsConfigurationInstruction.js +1 -1
  198. package/dist/types/EmailRecipient.cjs +18 -0
  199. package/dist/types/EmailRecipient.js +2 -9
  200. package/dist/types/EmailSubscription.cjs +1 -0
  201. package/dist/types/EmailSubscription.js +1 -1
  202. package/dist/types/JobState.cjs +13 -0
  203. package/dist/types/JobState.js +2 -9
  204. package/dist/types/License.cjs +31 -0
  205. package/dist/types/License.js +2 -9
  206. package/dist/types/Newsroom.cjs +30 -0
  207. package/dist/types/Newsroom.js +2 -9
  208. package/dist/types/NewsroomCompanyInformation.cjs +1 -0
  209. package/dist/types/NewsroomCompanyInformation.js +1 -1
  210. package/dist/types/NewsroomContact.cjs +1 -0
  211. package/dist/types/NewsroomContact.js +1 -1
  212. package/dist/types/NewsroomDomain.cjs +24 -0
  213. package/dist/types/NewsroomDomain.js +2 -9
  214. package/dist/types/NewsroomGallery.cjs +16 -0
  215. package/dist/types/NewsroomGallery.js +2 -9
  216. package/dist/types/NewsroomLanguageSettings.cjs +1 -0
  217. package/dist/types/NewsroomLanguageSettings.js +1 -1
  218. package/dist/types/NewsroomTheme.cjs +38 -0
  219. package/dist/types/NewsroomTheme.js +4 -12
  220. package/dist/types/NewsroomWebhook.cjs +20 -0
  221. package/dist/types/NewsroomWebhook.js +2 -9
  222. package/dist/types/NotificationSubscription.cjs +17 -0
  223. package/dist/types/NotificationSubscription.js +2 -9
  224. package/dist/types/Permissions.cjs +18 -0
  225. package/dist/types/Permissions.js +2 -9
  226. package/dist/types/Plan.cjs +18 -0
  227. package/dist/types/Plan.js +2 -9
  228. package/dist/types/PrivacyRequest.cjs +24 -0
  229. package/dist/types/PrivacyRequest.js +2 -9
  230. package/dist/types/SEOSettings.cjs +1 -0
  231. package/dist/types/SEOSettings.js +1 -1
  232. package/dist/types/SenderAddress.cjs +16 -0
  233. package/dist/types/SenderAddress.js +2 -9
  234. package/dist/types/SenderDomain.cjs +18 -0
  235. package/dist/types/SenderDomain.js +2 -9
  236. package/dist/types/Snippet.cjs +1 -0
  237. package/dist/types/Snippet.js +1 -1
  238. package/dist/types/Story.cjs +89 -0
  239. package/dist/types/Story.js +2 -9
  240. package/dist/types/User.cjs +28 -0
  241. package/dist/types/User.js +2 -9
  242. package/dist/types/UserAccount.cjs +1 -0
  243. package/dist/types/UserAccount.js +1 -1
  244. package/dist/types/common/Notification.cjs +18 -0
  245. package/dist/types/common/Notification.js +2 -9
  246. package/dist/types/common/OEmbedInfo.cjs +18 -0
  247. package/dist/types/common/OEmbedInfo.js +2 -9
  248. package/dist/types/common/Pagination.cjs +15 -0
  249. package/dist/types/common/Pagination.js +4 -9
  250. package/dist/types/common/Query.cjs +21 -0
  251. package/dist/types/common/Query.js +3 -9
  252. package/dist/types/common/Utm.cjs +1 -0
  253. package/dist/types/common/Utm.js +1 -1
  254. package/dist/types/common/Warning.cjs +1 -0
  255. package/dist/types/common/Warning.js +1 -1
  256. package/dist/types/common/index.cjs +65 -0
  257. package/dist/types/common/index.js +6 -65
  258. package/dist/types/index.cjs +325 -0
  259. package/dist/types/index.js +33 -325
  260. package/dist/utils.cjs +30 -0
  261. package/dist/utils.js +2 -9
  262. package/package.json +16 -6
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createFakeErrorPayload = createFakeErrorPayload;
7
+ exports.createRequest = createRequest;
8
+ var _ApiError = require("./ApiError.cjs");
9
+ var _constants = require("./constants.cjs");
10
+ var _lib = require("./lib.cjs");
11
+ var _types = require("./types.cjs");
12
+ function extractHeaders(headers) {
13
+ const result = {};
14
+ headers.forEach((value, key) => {
15
+ result[key] = value;
16
+ });
17
+ return result;
18
+ }
19
+ function extractResponse(response) {
20
+ return {
21
+ status: response.status,
22
+ statusText: response.statusText,
23
+ headers: extractHeaders(response.headers)
24
+ };
25
+ }
26
+ function createFakeErrorPayload({
27
+ status,
28
+ statusText
29
+ }) {
30
+ return {
31
+ status: 'error',
32
+ code: status,
33
+ message: `Something went wrong: ${[status, statusText].filter(Boolean).join(' ')}`,
34
+ errors: {
35
+ ':global': [{
36
+ code: status,
37
+ message: statusText
38
+ }]
39
+ }
40
+ };
41
+ }
42
+ async function createRequest(url, {
43
+ headers,
44
+ method,
45
+ payload,
46
+ query
47
+ }) {
48
+ try {
49
+ const urlWithQuery = (0, _lib.createUrlWithQuery)(url, query);
50
+ const response = await fetch(urlWithQuery.href, {
51
+ method,
52
+ headers: {
53
+ Accept: 'application/json',
54
+ 'Content-Type': _constants.CONTENT_TYPE,
55
+ ...headers
56
+ },
57
+ body: payload ? JSON.stringify(payload) : undefined
58
+ });
59
+
60
+ // Fetch correctly throws an error in browser environment,
61
+ // but when running in test environment (Jest), it fails silently
62
+ // and 'response' becomes undefined, hence this extra condition.
63
+ if (!response) {
64
+ throw new Error(_constants.INVALID_URL_ERROR_MESSAGE);
65
+ }
66
+
67
+ // Response code is not between 200 - 299
68
+ if (!response.ok) {
69
+ // Try to parse the response as JSON, if it contains any error messages
70
+ // from backend. If not, fake the error message.
71
+ let responsePayload;
72
+ try {
73
+ responsePayload = await response.json();
74
+ } catch (error) {
75
+ responsePayload = createFakeErrorPayload(response);
76
+ }
77
+ throw new _ApiError.ApiError({
78
+ payload: responsePayload,
79
+ ...extractResponse(response)
80
+ });
81
+ }
82
+ const responsePayload = response.status === _types.HttpCodes.NO_CONTENT ? undefined : await response.json();
83
+ return {
84
+ payload: responsePayload,
85
+ ...extractResponse(response)
86
+ };
87
+ } catch (error) {
88
+ // Fetch throws an error, if there is a connection problem (eg. network is down).
89
+ // We do not have access to response, so we need to fake the error payload.
90
+ // Since we also throw when response is not ok, re-throw the response data if available.
91
+ const {
92
+ status,
93
+ statusText = error.message || _constants.NETWORK_PROBLEM_ERROR_MESSAGE,
94
+ payload: errorPayload
95
+ } = error;
96
+ throw new _ApiError.ApiError({
97
+ payload: errorPayload || createFakeErrorPayload({
98
+ status,
99
+ statusText
100
+ }),
101
+ status,
102
+ statusText,
103
+ headers: error.headers || {}
104
+ });
105
+ }
106
+ }
@@ -1,14 +1,7 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createFakeErrorPayload = createFakeErrorPayload;
7
- exports.createRequest = createRequest;
8
- var _ApiError = require("./ApiError.js");
9
- var _constants = require("./constants.js");
10
- var _lib = require("./lib.js");
11
- var _types = require("./types.js");
1
+ import { ApiError } from "./ApiError.js";
2
+ import { CONTENT_TYPE, INVALID_URL_ERROR_MESSAGE, NETWORK_PROBLEM_ERROR_MESSAGE } from "./constants.js";
3
+ import { createUrlWithQuery } from "./lib.js";
4
+ import { HttpCodes } from "./types.js";
12
5
  function extractHeaders(headers) {
13
6
  const result = {};
14
7
  headers.forEach((value, key) => {
@@ -23,7 +16,7 @@ function extractResponse(response) {
23
16
  headers: extractHeaders(response.headers)
24
17
  };
25
18
  }
26
- function createFakeErrorPayload({
19
+ export function createFakeErrorPayload({
27
20
  status,
28
21
  statusText
29
22
  }) {
@@ -39,19 +32,19 @@ function createFakeErrorPayload({
39
32
  }
40
33
  };
41
34
  }
42
- async function createRequest(url, {
35
+ export async function createRequest(url, {
43
36
  headers,
44
37
  method,
45
38
  payload,
46
39
  query
47
40
  }) {
48
41
  try {
49
- const urlWithQuery = (0, _lib.createUrlWithQuery)(url, query);
42
+ const urlWithQuery = createUrlWithQuery(url, query);
50
43
  const response = await fetch(urlWithQuery.href, {
51
44
  method,
52
45
  headers: {
53
46
  Accept: 'application/json',
54
- 'Content-Type': _constants.CONTENT_TYPE,
47
+ 'Content-Type': CONTENT_TYPE,
55
48
  ...headers
56
49
  },
57
50
  body: payload ? JSON.stringify(payload) : undefined
@@ -61,7 +54,7 @@ async function createRequest(url, {
61
54
  // but when running in test environment (Jest), it fails silently
62
55
  // and 'response' becomes undefined, hence this extra condition.
63
56
  if (!response) {
64
- throw new Error(_constants.INVALID_URL_ERROR_MESSAGE);
57
+ throw new Error(INVALID_URL_ERROR_MESSAGE);
65
58
  }
66
59
 
67
60
  // Response code is not between 200 - 299
@@ -74,12 +67,12 @@ async function createRequest(url, {
74
67
  } catch (error) {
75
68
  responsePayload = createFakeErrorPayload(response);
76
69
  }
77
- throw new _ApiError.ApiError({
70
+ throw new ApiError({
78
71
  payload: responsePayload,
79
72
  ...extractResponse(response)
80
73
  });
81
74
  }
82
- const responsePayload = response.status === _types.HttpCodes.NO_CONTENT ? undefined : await response.json();
75
+ const responsePayload = response.status === HttpCodes.NO_CONTENT ? undefined : await response.json();
83
76
  return {
84
77
  payload: responsePayload,
85
78
  ...extractResponse(response)
@@ -90,10 +83,10 @@ async function createRequest(url, {
90
83
  // Since we also throw when response is not ok, re-throw the response data if available.
91
84
  const {
92
85
  status,
93
- statusText = error.message || _constants.NETWORK_PROBLEM_ERROR_MESSAGE,
86
+ statusText = error.message || NETWORK_PROBLEM_ERROR_MESSAGE,
94
87
  payload: errorPayload
95
88
  } = error;
96
- throw new _ApiError.ApiError({
89
+ throw new ApiError({
97
90
  payload: errorPayload || createFakeErrorPayload({
98
91
  status,
99
92
  statusText
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "ApiError", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _ApiError.ApiError;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Http", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Http.Http;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "isDeferredJobResponse", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _lib.isDeferredJobResponse;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "HttpCodes", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _types.HttpCodes;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "Method", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _types.Method;
34
+ }
35
+ });
36
+ var _ApiError = require("./ApiError.cjs");
37
+ var _Http = require("./Http.cjs");
38
+ var _lib = require("./lib.cjs");
39
+ var _types = require("./types.cjs");
@@ -1,39 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "ApiError", {
7
- enumerable: true,
8
- get: function () {
9
- return _ApiError.ApiError;
10
- }
11
- });
12
- Object.defineProperty(exports, "Http", {
13
- enumerable: true,
14
- get: function () {
15
- return _Http.Http;
16
- }
17
- });
18
- Object.defineProperty(exports, "isDeferredJobResponse", {
19
- enumerable: true,
20
- get: function () {
21
- return _lib.isDeferredJobResponse;
22
- }
23
- });
24
- Object.defineProperty(exports, "HttpCodes", {
25
- enumerable: true,
26
- get: function () {
27
- return _types.HttpCodes;
28
- }
29
- });
30
- Object.defineProperty(exports, "Method", {
31
- enumerable: true,
32
- get: function () {
33
- return _types.Method;
34
- }
35
- });
36
- var _ApiError = require("./ApiError.js");
37
- var _Http = require("./Http.js");
38
- var _lib = require("./lib.js");
39
- var _types = require("./types.js");
1
+ export { ApiError } from "./ApiError.js";
2
+ export { Http } from "./Http.js";
3
+ export { isDeferredJobResponse } from "./lib.js";
4
+ export { HttpCodes, Method } from "./types.js";
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createUrlWithQuery = createUrlWithQuery;
7
+ exports.isDeferredJobResponse = isDeferredJobResponse;
8
+ var _queryString = _interopRequireDefault(require("query-string"));
9
+ var nodeUrl = _interopRequireWildcard(require("url"));
10
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
11
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ const URL = typeof window === 'undefined' ? nodeUrl.URL : window.URL;
14
+ function parseUrlParams(query) {
15
+ return _queryString.default.parse(query, {
16
+ arrayFormat: 'bracket'
17
+ });
18
+ }
19
+ function stringifyUrlParams(params) {
20
+ return _queryString.default.stringify(params, {
21
+ arrayFormat: 'bracket'
22
+ });
23
+ }
24
+ function createUrlWithQuery(url = '', query) {
25
+ const urlWithQuery = new URL(url);
26
+ if (typeof query === 'object' && query !== null) {
27
+ urlWithQuery.search = stringifyUrlParams({
28
+ ...parseUrlParams(urlWithQuery.search),
29
+ ...query
30
+ });
31
+ }
32
+ return urlWithQuery;
33
+ }
34
+ function isObject(value) {
35
+ return value !== null && typeof value === 'object';
36
+ }
37
+ function isDeferredJobResponse(value) {
38
+ return isObject(value) && typeof value.status === 'string' && isObject(value.progress) && typeof value.progress.id === 'string' && Array.isArray(value.progress.links) && value.progress.links.every(link => typeof link === 'string');
39
+ }
package/dist/http/lib.js CHANGED
@@ -1,27 +1,17 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createUrlWithQuery = createUrlWithQuery;
7
- exports.isDeferredJobResponse = isDeferredJobResponse;
8
- var _queryString = _interopRequireDefault(require("query-string"));
9
- var nodeUrl = _interopRequireWildcard(require("url"));
10
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
11
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1
+ import queryString from 'query-string';
2
+ import * as nodeUrl from 'url';
13
3
  const URL = typeof window === 'undefined' ? nodeUrl.URL : window.URL;
14
4
  function parseUrlParams(query) {
15
- return _queryString.default.parse(query, {
5
+ return queryString.parse(query, {
16
6
  arrayFormat: 'bracket'
17
7
  });
18
8
  }
19
9
  function stringifyUrlParams(params) {
20
- return _queryString.default.stringify(params, {
10
+ return queryString.stringify(params, {
21
11
  arrayFormat: 'bracket'
22
12
  });
23
13
  }
24
- function createUrlWithQuery(url = '', query) {
14
+ export function createUrlWithQuery(url = '', query) {
25
15
  const urlWithQuery = new URL(url);
26
16
  if (typeof query === 'object' && query !== null) {
27
17
  urlWithQuery.search = stringifyUrlParams({
@@ -34,6 +24,6 @@ function createUrlWithQuery(url = '', query) {
34
24
  function isObject(value) {
35
25
  return value !== null && typeof value === 'object';
36
26
  }
37
- function isDeferredJobResponse(value) {
27
+ export function isDeferredJobResponse(value) {
38
28
  return isObject(value) && typeof value.status === 'string' && isObject(value.progress) && typeof value.progress.id === 'string' && Array.isArray(value.progress.links) && value.progress.links.every(link => typeof link === 'string');
39
29
  }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Method = exports.HttpCodes = void 0;
7
+ let HttpCodes;
8
+ exports.HttpCodes = HttpCodes;
9
+ (function (HttpCodes) {
10
+ HttpCodes[HttpCodes["ACCEPTED"] = 202] = "ACCEPTED";
11
+ HttpCodes[HttpCodes["NO_CONTENT"] = 204] = "NO_CONTENT";
12
+ HttpCodes[HttpCodes["NOT_FOUND"] = 404] = "NOT_FOUND";
13
+ HttpCodes[HttpCodes["CONFLICT"] = 409] = "CONFLICT";
14
+ HttpCodes[HttpCodes["GONE"] = 410] = "GONE";
15
+ HttpCodes[HttpCodes["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
16
+ })(HttpCodes || (exports.HttpCodes = HttpCodes = {}));
17
+ let Method;
18
+ exports.Method = Method;
19
+ (function (Method) {
20
+ Method["DELETE"] = "DELETE";
21
+ Method["GET"] = "GET";
22
+ Method["PATCH"] = "PATCH";
23
+ Method["POST"] = "POST";
24
+ Method["PUT"] = "PUT";
25
+ })(Method || (exports.Method = Method = {}));
@@ -1,11 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Method = exports.HttpCodes = void 0;
7
- let HttpCodes;
8
- exports.HttpCodes = HttpCodes;
1
+ export let HttpCodes;
9
2
  (function (HttpCodes) {
10
3
  HttpCodes[HttpCodes["ACCEPTED"] = 202] = "ACCEPTED";
11
4
  HttpCodes[HttpCodes["NO_CONTENT"] = 204] = "NO_CONTENT";
@@ -13,13 +6,12 @@ exports.HttpCodes = HttpCodes;
13
6
  HttpCodes[HttpCodes["CONFLICT"] = 409] = "CONFLICT";
14
7
  HttpCodes[HttpCodes["GONE"] = 410] = "GONE";
15
8
  HttpCodes[HttpCodes["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
16
- })(HttpCodes || (exports.HttpCodes = HttpCodes = {}));
17
- let Method;
18
- exports.Method = Method;
9
+ })(HttpCodes || (HttpCodes = {}));
10
+ export let Method;
19
11
  (function (Method) {
20
12
  Method["DELETE"] = "DELETE";
21
13
  Method["GET"] = "GET";
22
14
  Method["PATCH"] = "PATCH";
23
15
  Method["POST"] = "POST";
24
16
  Method["PUT"] = "PUT";
25
- })(Method || (exports.Method = Method = {}));
17
+ })(Method || (Method = {}));
package/dist/index.cjs ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ createPrezlyClient: true,
8
+ ApiError: true
9
+ };
10
+ Object.defineProperty(exports, "createPrezlyClient", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _Client.createClient;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "ApiError", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _index.ApiError;
20
+ }
21
+ });
22
+ var _uploads = require("@prezly/uploads");
23
+ Object.keys(_uploads).forEach(function (key) {
24
+ if (key === "default" || key === "__esModule") return;
25
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
+ Object.defineProperty(exports, key, {
27
+ enumerable: true,
28
+ get: function () {
29
+ return _uploads[key];
30
+ }
31
+ });
32
+ });
33
+ var _Client = require("./Client.cjs");
34
+ var _index = require("./http/index.cjs");
35
+ var _index2 = require("./endpoints/index.cjs");
36
+ Object.keys(_index2).forEach(function (key) {
37
+ if (key === "default" || key === "__esModule") return;
38
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
39
+ Object.defineProperty(exports, key, {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _index2[key];
43
+ }
44
+ });
45
+ });
46
+ var _index3 = require("./types/index.cjs");
47
+ Object.keys(_index3).forEach(function (key) {
48
+ if (key === "default" || key === "__esModule") return;
49
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
50
+ Object.defineProperty(exports, key, {
51
+ enumerable: true,
52
+ get: function () {
53
+ return _index3[key];
54
+ }
55
+ });
56
+ });
package/dist/index.js CHANGED
@@ -1,56 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- createPrezlyClient: true,
8
- ApiError: true
9
- };
10
- Object.defineProperty(exports, "createPrezlyClient", {
11
- enumerable: true,
12
- get: function () {
13
- return _Client.createClient;
14
- }
15
- });
16
- Object.defineProperty(exports, "ApiError", {
17
- enumerable: true,
18
- get: function () {
19
- return _index.ApiError;
20
- }
21
- });
22
- var _uploads = require("@prezly/uploads");
23
- Object.keys(_uploads).forEach(function (key) {
24
- if (key === "default" || key === "__esModule") return;
25
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
- Object.defineProperty(exports, key, {
27
- enumerable: true,
28
- get: function () {
29
- return _uploads[key];
30
- }
31
- });
32
- });
33
- var _Client = require("./Client.js");
34
- var _index = require("./http/index.js");
35
- var _index2 = require("./endpoints/index.js");
36
- Object.keys(_index2).forEach(function (key) {
37
- if (key === "default" || key === "__esModule") return;
38
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
39
- Object.defineProperty(exports, key, {
40
- enumerable: true,
41
- get: function () {
42
- return _index2[key];
43
- }
44
- });
45
- });
46
- var _index3 = require("./types/index.js");
47
- Object.keys(_index3).forEach(function (key) {
48
- if (key === "default" || key === "__esModule") return;
49
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
50
- Object.defineProperty(exports, key, {
51
- enumerable: true,
52
- get: function () {
53
- return _index3[key];
54
- }
55
- });
56
- });
1
+ export * from '@prezly/uploads';
2
+ export { createClient as createPrezlyClient } from "./Client.js";
3
+ export { ApiError } from "./http/index.js";
4
+ export * from "./endpoints/index.js";
5
+ export * from "./types/index.js";
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.routing = void 0;
7
+ const routing = {
8
+ accounts: '/v2/accounts',
9
+ billing: 'v2/billing',
10
+ campaignsUrl: '/v2/campaigns',
11
+ campaignRecipientsUrl: '/v2/campaigns/:campaign_id/recipients',
12
+ contactsExportsUrl: '/v2/contacts/exports',
13
+ coverageUrl: '/v2/coverage',
14
+ jobsUrl: '/v2/jobs',
15
+ licenseUrl: '/v2/licenses',
16
+ licenseUnsubscribeUrl: '/v2/unsubscribe',
17
+ newsroomsUrl: '/v2/newsrooms',
18
+ newsroomCategoriesUrl: '/v2/newsrooms/:newsroom_id/categories',
19
+ newsroomContactsUrl: '/v2/newsrooms/:newsroom_id/contacts',
20
+ newsroomLanguagesUrl: '/v2/newsrooms/:newsroom_id/languages',
21
+ /** @deprecated Please use newsroomSubscribeUrl instead */
22
+ newsroomSubscriptionsUrl: '/v2/newsrooms/:newsroom_id/subscriptions',
23
+ newsroomSubscribeUrl: '/v2/newsrooms/:newsroom_id/subscribe',
24
+ newsroomUnsubscribeUrl: '/v2/newsrooms/:newsroom_id/unsubscribe',
25
+ newsroomThemesUrl: '/v2/newsrooms/:newsroom_id/themes',
26
+ newsroomWebhooksUrl: '/v2/newsrooms/:newsroom_id/webhooks',
27
+ newsroomPrivacyRequestsUrl: '/v2/newsrooms/:newsroom_id/privacy-requests',
28
+ newsroomDomainsUrl: '/v2/newsrooms/:newsroom_id/domains',
29
+ newsroomGalleriesUrl: '/v2/newsrooms/:newsroom_id/galleries',
30
+ notificationSubscriptionsUrl: '/v2/notification-subscriptions',
31
+ senderAddressesUrl: '/v2/sender-addresses',
32
+ signup: '/v2/signup',
33
+ storiesUrl: '/v2/stories',
34
+ storiesSearchUrl: '/v2/stories/search',
35
+ storyCoverageUrl: '/v1/stories/:story_id/reports/coverage',
36
+ snippetsUrl: '/v2/snippets'
37
+ };
38
+ exports.routing = routing;
package/dist/routing.js CHANGED
@@ -1,10 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.routing = void 0;
7
- const routing = {
1
+ export const routing = {
8
2
  accounts: '/v2/accounts',
9
3
  billing: 'v2/billing',
10
4
  campaignsUrl: '/v2/campaigns',
@@ -34,5 +28,4 @@ const routing = {
34
28
  storiesSearchUrl: '/v2/stories/search',
35
29
  storyCoverageUrl: '/v1/stories/:story_id/reports/coverage',
36
30
  snippetsUrl: '/v2/snippets'
37
- };
38
- exports.routing = routing;
31
+ };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Campaign = void 0;
7
+ var _SenderDomain = require("./SenderDomain.cjs");
8
+ let Campaign;
9
+ exports.Campaign = Campaign;
10
+ (function (_Campaign) {
11
+ const SenderDomainVerificationFlow = _Campaign.SenderDomainVerificationFlow = _SenderDomain.SenderDomain.VerificationFlowVersion;
12
+ let LifecycleStatus;
13
+ (function (LifecycleStatus) {
14
+ LifecycleStatus["DRAFT"] = "draft";
15
+ LifecycleStatus["SCHEDULED"] = "scheduled";
16
+ LifecycleStatus["PENDING"] = "pending";
17
+ LifecycleStatus["SENT"] = "sent";
18
+ })(LifecycleStatus || (LifecycleStatus = {}));
19
+ _Campaign.LifecycleStatus = LifecycleStatus;
20
+ let StoryAlignment;
21
+ (function (StoryAlignment) {
22
+ StoryAlignment["CENTER"] = "center";
23
+ StoryAlignment["LEFT"] = "left";
24
+ StoryAlignment["RIGHT"] = "right";
25
+ })(StoryAlignment || (StoryAlignment = {}));
26
+ _Campaign.StoryAlignment = StoryAlignment;
27
+ let StoryAppearance;
28
+ (function (StoryAppearance) {
29
+ StoryAppearance["INTRO"] = "intro";
30
+ StoryAppearance["FULL"] = "full";
31
+ })(StoryAppearance || (StoryAppearance = {}));
32
+ _Campaign.StoryAppearance = StoryAppearance;
33
+ let SenderDomainVerificationStatus;
34
+ (function (SenderDomainVerificationStatus) {
35
+ SenderDomainVerificationStatus["UNKNOWN"] = "unknown";
36
+ SenderDomainVerificationStatus["VALID"] = "valid";
37
+ SenderDomainVerificationStatus["INVALID"] = "invalid";
38
+ SenderDomainVerificationStatus["NOT_APPLICABLE"] = "not-applicable";
39
+ })(SenderDomainVerificationStatus || (SenderDomainVerificationStatus = {}));
40
+ _Campaign.SenderDomainVerificationStatus = SenderDomainVerificationStatus;
41
+ function isDraft(arg) {
42
+ if (typeof arg === 'object') {
43
+ return isDraft(arg.lifecycle_status);
44
+ }
45
+ return arg === LifecycleStatus.DRAFT;
46
+ }
47
+ _Campaign.isDraft = isDraft;
48
+ function isScheduled(arg) {
49
+ if (typeof arg === 'object') {
50
+ return isScheduled(arg.lifecycle_status);
51
+ }
52
+ return arg === LifecycleStatus.SCHEDULED;
53
+ }
54
+ _Campaign.isScheduled = isScheduled;
55
+ function isPending(arg) {
56
+ if (typeof arg === 'object') {
57
+ return isPending(arg.lifecycle_status);
58
+ }
59
+ return arg === LifecycleStatus.PENDING;
60
+ }
61
+ _Campaign.isPending = isPending;
62
+ function isSent(arg) {
63
+ if (typeof arg === 'object') {
64
+ return isSent(arg.lifecycle_status);
65
+ }
66
+ return arg === LifecycleStatus.SENT;
67
+ }
68
+ _Campaign.isSent = isSent;
69
+ })(Campaign || (exports.Campaign = Campaign = {}));