@contentstack/marketplace-sdk 1.4.0 → 1.4.2

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 (38) hide show
  1. package/CHANGELOG.md +12 -6
  2. package/CODEOWNERS +9 -1
  3. package/LICENSE +1 -1
  4. package/dist/es-modules/contentstack.js +5 -10
  5. package/dist/es-modules/contentstackClient.js +9 -8
  6. package/dist/es-modules/core/Util.js +17 -1
  7. package/dist/es-modules/core/contentstackHTTPClient.js +3 -16
  8. package/dist/es-modules/core/messageHandler.js +126 -0
  9. package/dist/es-modules/entity.js +1 -0
  10. package/dist/es-modules/marketplace/app/hosting/deployment.js +1 -0
  11. package/dist/es-modules/marketplace/app/hosting/index.js +1 -0
  12. package/dist/es-modules/marketplace/app/index.js +15 -14
  13. package/dist/es-modules/marketplace/app/oauth/index.js +7 -6
  14. package/dist/es-modules/marketplace/apprequest/index.js +7 -6
  15. package/dist/es-modules/marketplace/authorization/index.js +7 -6
  16. package/dist/es-modules/marketplace/index.js +5 -4
  17. package/dist/es-modules/marketplace/installation/index.js +14 -13
  18. package/dist/es-modules/marketplace/installation/webhooks/index.js +2 -1
  19. package/dist/es5/contentstack.js +4 -9
  20. package/dist/es5/contentstackClient.js +9 -8
  21. package/dist/es5/core/Util.js +21 -1
  22. package/dist/es5/core/contentstackHTTPClient.js +3 -17
  23. package/dist/es5/core/messageHandler.js +131 -0
  24. package/dist/es5/entity.js +1 -0
  25. package/dist/es5/marketplace/app/hosting/deployment.js +1 -0
  26. package/dist/es5/marketplace/app/hosting/index.js +1 -0
  27. package/dist/es5/marketplace/app/index.js +15 -14
  28. package/dist/es5/marketplace/app/oauth/index.js +7 -6
  29. package/dist/es5/marketplace/apprequest/index.js +7 -6
  30. package/dist/es5/marketplace/authorization/index.js +7 -6
  31. package/dist/es5/marketplace/index.js +5 -4
  32. package/dist/es5/marketplace/installation/index.js +14 -13
  33. package/dist/es5/marketplace/installation/webhooks/index.js +2 -1
  34. package/dist/nativescript/contentstack-marketplace.js +1 -1
  35. package/dist/node/contentstack-marketplace.js +1 -1
  36. package/dist/react-native/contentstack-marketplace.js +1 -1
  37. package/dist/web/contentstack-marketplace.js +1 -1
  38. package/package.json +5 -3
@@ -7,6 +7,7 @@ import cloneDeep from 'lodash/cloneDeep';
7
7
  import error from '../../core/contentstackError';
8
8
  import { deleteEntity, fetch, fetchAll, update } from '../../entity';
9
9
  import { WebHooks } from './webhooks';
10
+ import { MESSAGES, ERROR_MESSAGES } from '../../core/messageHandler.js';
10
11
 
11
12
  /**
12
13
  *
@@ -38,7 +39,7 @@ export function Installation(http, data) {
38
39
  * const client = contentstack.client({ authtoken: 'TOKEN'})
39
40
  *
40
41
  * client.marketplace('organization_uid').installation('installation_uid').fetch()
41
- * .then((installation) => console.log(installation))
42
+ * .then((installation) => console.log('App installation details loaded successfully.'))
42
43
  *
43
44
  */
44
45
  this.fetch = fetch(http, 'data', this.params);
@@ -62,7 +63,7 @@ export function Installation(http, data) {
62
63
  * const installation = client.marketplace('organization_uid').installation('installation_uid')
63
64
  * installation = Object.assign(installation, updateInstallation)
64
65
  * installation.update()
65
- * .then((installation) => console.log(installation))
66
+ * .then((installation) => console.log('App installation details loaded successfully.'))
66
67
  */
67
68
  this.update = update(http, 'data', this.params);
68
69
 
@@ -77,7 +78,7 @@ export function Installation(http, data) {
77
78
  * const client = contentstack.client({ authtoken: 'TOKEN'})
78
79
  *
79
80
  * client.marketplace('organization_uid').installation('installation_uid').uninstall()
80
- * .then((response) => console.log(response))
81
+ * .then((response) => console.log('Installation response received.'))
81
82
  */
82
83
  this.uninstall = deleteEntity(http, false, this.params);
83
84
 
@@ -93,7 +94,7 @@ export function Installation(http, data) {
93
94
  * const client = contentstack.client({ authtoken: 'TOKEN'})
94
95
  *
95
96
  * client.marketplace('organization_uid').installation('installation_uid').configuration()
96
- * .then((response) => console.log(response))
97
+ * .then((response) => console.log('Installation response received.'))
97
98
  */
98
99
  this.configuration = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
99
100
  var param,
@@ -147,7 +148,7 @@ export function Installation(http, data) {
147
148
  * const client = contentstack.client({ authtoken: 'TOKEN'})
148
149
  *
149
150
  * client.marketplace('organization_uid').installation('installation_uid').setConfiguration({<configuration_details>})
150
- * .then((response) => console.log(response))
151
+ * .then((response) => console.log('Installation response received.'))
151
152
  */
152
153
  this.setConfiguration = /*#__PURE__*/function () {
153
154
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(config) {
@@ -200,7 +201,7 @@ export function Installation(http, data) {
200
201
  * const client = contentstack.client({ authtoken: 'TOKEN'})
201
202
  *
202
203
  * client.marketplace('organization_uid').installation('installation_uid').getConfigLocation()
203
- * .then((response) => console.log(response))
204
+ * .then((response) => console.log('Installation response received.'))
204
205
  */
205
206
  this.getConfigLocation = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
206
207
  var headers, response, _t3;
@@ -248,7 +249,7 @@ export function Installation(http, data) {
248
249
  * const client = contentstack.client({ authtoken: 'TOKEN'})
249
250
  *
250
251
  * client.marketplace('organization_uid').installation('installation_uid').serverConfig()
251
- * .then((response) => console.log(response))
252
+ * .then((response) => console.log('Installation response received.'))
252
253
  */
253
254
  this.serverConfig = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
254
255
  var param,
@@ -302,7 +303,7 @@ export function Installation(http, data) {
302
303
  * const client = contentstack.client({ authtoken: 'TOKEN'})
303
304
  *
304
305
  * client.marketplace('organization_uid').installation('installation_uid').setServerConfig({<configuration_details>})
305
- * .then((response) => console.log(response))
306
+ * .then((response) => console.log('Installation response received.'))
306
307
  */
307
308
  this.setServerConfig = /*#__PURE__*/function () {
308
309
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(config) {
@@ -354,7 +355,7 @@ export function Installation(http, data) {
354
355
  * const client = contentstack.client({ authtoken: 'TOKEN'})
355
356
  *
356
357
  * client.marketplace('organization_uid').installation('installation_uid').installationData()
357
- * .then((response) => console.log(response))
358
+ * .then((response) => console.log('Installation response received.'))
358
359
  */
359
360
  this.installationData = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
360
361
  var headers, response, _t6;
@@ -421,7 +422,7 @@ export function Installation(http, data) {
421
422
  * const client = contentstack.client({ authtoken: 'TOKEN'})
422
423
  *
423
424
  * client.marketplace('organization_uid').installation().fetchAll()
424
- * .then((collection) => console.log(collection))
425
+ * .then((collection) => console.log('Installation collection loaded successfully.'))
425
426
  *
426
427
  */
427
428
  this.fetchAll = fetchAll(http, InstallationCollection, params);
@@ -437,7 +438,7 @@ export function Installation(http, data) {
437
438
  * const client = contentstack.client({ authtoken: 'TOKEN'})
438
439
  *
439
440
  * client.marketplace('organization_uid').installation().getInstalledApps()
440
- * .then((collection) => console.log(collection))
441
+ * .then((collection) => console.log('Installation collection loaded successfully.'))
441
442
  *
442
443
  */
443
444
  this.getInstalledApps = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
@@ -491,7 +492,7 @@ export function Installation(http, data) {
491
492
  * const client = contentstack.client({ authtoken: 'TOKEN'})
492
493
  *
493
494
  * client.marketplace('organization_uid').installation().getInstalledUsers()
494
- * .then((collection) => console.log(collection))
495
+ * .then((collection) => console.log('Installation collection loaded successfully.'))
495
496
  *
496
497
  */
497
498
  this.getInstalledUsers = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
@@ -539,7 +540,7 @@ export function Installation(http, data) {
539
540
  * const client = contentstack.client({ authtoken: 'TOKEN'})
540
541
  *
541
542
  * client.marketplace('organization_uid').installation().getInstalledStacks()
542
- * .then((collection) => console.log(collection))
543
+ * .then((collection) => console.log('Installation collection loaded successfully.'))
543
544
  *
544
545
  */
545
546
  this.getInstalledStacks = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
@@ -5,6 +5,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  import cloneDeep from 'lodash/cloneDeep';
7
7
  import error from '../../../core/contentstackError';
8
+ import { MESSAGES, ERROR_MESSAGES } from '../../../core/messageHandler.js';
8
9
 
9
10
  /**
10
11
  *
@@ -35,7 +36,7 @@ export function WebHooks(http, data) {
35
36
  * const client = contentstack.client({ authtoken: 'TOKEN'})
36
37
  *
37
38
  * client.marketplace('organization_uid').installation('installation_uid').webhooks('webhook_uid').listExecutionLogs()
38
- * .then((installation) => console.log(installation))
39
+ * .then((installation) => console.log('Installation webhook details loaded successfully.'))
39
40
  *
40
41
  */
41
42
  this.listExecutionLogs = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
@@ -127,14 +127,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
127
127
  * @prop {function=} params.logHandler - A log handler function to process given log messages & errors.
128
128
  * @example //Set the `logHandler`
129
129
  * import * as contentstack from '@contentstack/management'
130
- * const client = contentstack.client({ logHandler: (level, data) => {
131
- if (level === 'error' && data) {
132
- const title = [data.name, data.message].filter((a) => a).join(' - ')
133
- console.error(`[error] ${title}`)
134
- return
135
- }
136
- console.log(`[${level}] ${data}`)
137
- } })
130
+ * import { logHandler } from '@contentstack/management/core/messageHandler'
131
+ * const client = contentstack.client({ logHandler: logHandler })
138
132
  *
139
133
  * @prop {function=} params.refreshToken - Optional function used to refresh token.
140
134
  * @example // OAuth example
@@ -174,8 +168,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
174
168
  */
175
169
  function client() {
176
170
  var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
171
+ var devHubHost = params.region ? (0, _Util.getRegionEndpoint)(params.region.toLowerCase(), 'developerHub') : (0, _Util.getRegionEndpoint)("na", 'developerHub');
177
172
  var defaultParameter = {
178
- defaultHostName: 'developerhub-api.contentstack.com'
173
+ defaultHostName: devHubHost
179
174
  };
180
175
  var sdkAgent = "contentstack-marketplace-sdk/".concat(_package2["default"].version);
181
176
  var userAgentHeader = (0, _Util2["default"])(sdkAgent, params.application, params.integration, params.feature);
@@ -10,6 +10,7 @@ var _contentstackError = require("./core/contentstackError");
10
10
  var _contentstackError2 = (0, _interopRequireDefault2["default"])(_contentstackError);
11
11
  var _index = require("./marketplace/index.js");
12
12
  var _contentstack = require("./contentstack.js");
13
+ var _messageHandler = require("./core/messageHandler.js");
13
14
  /**
14
15
  * @namespace ContentstackClient
15
16
  */
@@ -30,8 +31,8 @@ function contentstackClient(_ref) {
30
31
  * import * as contentstack from '@contentstack/management'
31
32
  * const client = contentstack.client()
32
33
  *
33
- * client.login({ email: <emailid>, password: <password> })
34
- * .then(() => console.log('Logged in successfully'))
34
+ * client.login({ email: <emailid>, password: <password> })
35
+ * .then(() => console.log(MESSAGES.LOGIN_SUCCESS))
35
36
  *
36
37
  * client.marketplace()
37
38
  */
@@ -71,8 +72,8 @@ function contentstackClient(_ref) {
71
72
  * import * as contentstack from '@contentstack/management'
72
73
  * const client = contentstack.client()
73
74
  *
74
- * client.organization().findAll()
75
- * .then((organization) => console.log(organization))
75
+ * client.organization().findAll()
76
+ * .then((organization) => console.log(MESSAGES.ORGANIZATION_LOADED))
76
77
  *
77
78
  * @example
78
79
  * import * as contentstack from '@contentstack/management'
@@ -98,14 +99,14 @@ function contentstackClient(_ref) {
98
99
  * @example
99
100
  * import * as contentstack from '@contentstack/management'
100
101
  * const client = contentstack.client()
101
- * client.logout()
102
- * .then((response) => console.log(response))
102
+ * client.logout()
103
+ * .then((response) => console.log(MESSAGES.API_RESPONSE_SUCCESS))
103
104
  *
104
105
  * @example
105
106
  * import * as contentstack from '@contentstack/management'
106
107
  * const client = contentstack.client()
107
- * client.logout('AUTHTOKEN')
108
- * .then((response) => console.log(response))
108
+ * client.logout('AUTHTOKEN')
109
+ * .then((response) => console.log(MESSAGES.API_RESPONSE_SUCCESS))
109
110
  * */
110
111
  function logout(authtoken) {
111
112
  http.defaults.versioningStrategy = 'path';
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault3 = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _interopRequireDefault2 = _interopRequireDefault3(require("@babel/runtime/helpers/interopRequireDefault"));
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
8
+ exports.getRegionEndpoint = undefined;
6
9
  exports.isHost = isHost;
7
10
  exports.isNode = isNode;
8
11
  exports.getNodeVersion = getNodeVersion;
9
12
  exports["default"] = getUserAgent;
10
13
  var _os = require("os");
14
+ var _regions = require("../assets/regions.json");
15
+ var _regions2 = (0, _interopRequireDefault2["default"])(_regions);
11
16
  var HOST_REGEX = /^(?!\w+:\/\/)([\w-:]+\.)+([\w-:]+)(?::(\d+))?(?!:)$/;
12
17
  function isHost(host) {
13
18
  return HOST_REGEX.test(host);
@@ -95,4 +100,19 @@ function getUserAgent(sdk, application, integration, feature) {
95
100
  return "".concat(headerParts.filter(function (item) {
96
101
  return item !== '';
97
102
  }).join('; '), ";");
98
- }
103
+ }
104
+ var getRegionEndpoint = exports.getRegionEndpoint = function getRegionEndpoint(region) {
105
+ var _regionData$endpoints;
106
+ var service = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'developerHub';
107
+ var regionData = _regions2["default"].regions.find(function (r) {
108
+ return r.id === region || r.alias.some(function (alias) {
109
+ return alias === region;
110
+ });
111
+ });
112
+ if (!regionData) {
113
+ throw new Error("Invalid region '".concat(region, "' provided. Allowed regions are: ").concat(_regions2["default"].regions.map(function (r) {
114
+ return r.id;
115
+ }).join(', ')));
116
+ }
117
+ return (_regionData$endpoints = regionData.endpoints[service]) === null || _regionData$endpoints === void 0 ? void 0 : _regionData$endpoints.replace(/^https?:\/\//, '');
118
+ };
@@ -18,24 +18,14 @@ var _qs = require("qs");
18
18
  var _qs2 = (0, _interopRequireDefault2["default"])(_qs);
19
19
  var _concurrencyQueue = require("./concurrency-queue");
20
20
  var _Util = require("./Util");
21
- var _region = require("./region");
22
- var _region2 = (0, _interopRequireDefault2["default"])(_region);
21
+ var _messageHandler = require("./messageHandler.js");
23
22
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
24
23
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty3["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
25
24
  function contentstackHttpClient(options) {
26
25
  var defaultConfig = {
27
26
  insecure: false,
28
27
  retryOnError: true,
29
- logHandler: function logHandler(level, data) {
30
- if (level === 'error' && data) {
31
- var title = [data.name, data.message].filter(function (a) {
32
- return a;
33
- }).join(' - ');
34
- console.error("[error] ".concat(title));
35
- return;
36
- }
37
- console.log("[".concat(level, "] ").concat(data));
38
- },
28
+ logHandler: _messageHandler.httpLogHandler,
39
29
  retryCondition: function retryCondition(error) {
40
30
  if (error.response && error.response.status === 429) {
41
31
  return true;
@@ -74,11 +64,7 @@ function contentstackHttpClient(options) {
74
64
  if (config.basePath) {
75
65
  config.basePath = "/".concat(config.basePath.split('/').filter(Boolean).join('/'));
76
66
  }
77
- if (config.region && config.region !== _region2["default"].NA) {
78
- baseUrlPath = "".concat(protocol, "://").concat(config.region, "-").concat(hostname, ":").concat(port).concat(config.basePath);
79
- } else {
80
- baseUrlPath = "".concat(protocol, "://").concat(hostname, ":").concat(port).concat(config.basePath);
81
- }
67
+ baseUrlPath = "".concat(protocol, "://").concat(hostname, ":").concat(port).concat(config.basePath);
82
68
  var baseURL = config.endpoint || baseUrlPath;
83
69
  var axiosOptions = _objectSpread(_objectSpread({
84
70
  // Axios
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ /**
7
+ * Centralized message handler for all console logs and error messages
8
+ * @namespace MessageHandler
9
+ */
10
+
11
+ /**
12
+ * Success messages catalog
13
+ */
14
+ var MESSAGES = exports.MESSAGES = {
15
+ // Authentication
16
+ LOGIN_SUCCESS: 'Login successful.',
17
+ // Organization - Includes org UID, name, metadata
18
+ ORGANIZATION_LOADED: 'Organization details loaded successfully.',
19
+ // API Responses
20
+ API_RESPONSE_SUCCESS: 'API response received successfully.',
21
+ API_RESPONSE_APP_OPERATION: 'API response received for app operation.',
22
+ // Marketplace
23
+ MARKETPLACE_API_RESPONSE: 'Marketplace API response received.',
24
+ MARKETPLACE_ROLES_LOADED: 'Marketplace roles loaded successfully.',
25
+ // Apps - Includes UID, name, description, config
26
+ APP_LOADED: 'App details loaded successfully.',
27
+ APP_COLLECTION_LOADED: 'App collection loaded successfully.',
28
+ APP_REQUEST_RESPONSE: 'App request response received successfully.',
29
+ // Installations - Includes installation UID, app UID, status, config
30
+ INSTALLATION_LOADED: 'App installation details loaded successfully.',
31
+ INSTALLATIONS_LOADED: 'App installation details loaded successfully.',
32
+ INSTALLATION_RESPONSE: 'Installation response received.',
33
+ INSTALLATION_COLLECTION_LOADED: 'Installation collection loaded successfully.',
34
+ INSTALLATION_WEBHOOK_LOADED: 'Installation webhook details loaded successfully.',
35
+ // Authorization - Includes redirect URIs, auth codes (no tokens for security)
36
+ AUTHORIZATION_RESPONSE: 'Authorization response received.',
37
+ // OAuth - WARNING: May contain sensitive values (client_secret)
38
+ OAUTH_CONFIG_LOADED: 'OAuth configuration loaded successfully.',
39
+ OAUTH_SCOPES_LOADED: 'OAuth scopes loaded successfully.',
40
+ // Slack
41
+ SLACK_MESSAGE_SENT: 'Slack message sent successfully.'
42
+ };
43
+
44
+ /**
45
+ * Error messages catalog
46
+ * All errors include: status, statusText, errorMessage, errorCode, errors object, request details
47
+ */
48
+ var ERROR_MESSAGES = exports.ERROR_MESSAGES = {
49
+ // General Request Errors
50
+ REQUEST_FAILED: function REQUEST_FAILED(title) {
51
+ return "Request failed: ".concat(title, ". Review the error details and try again.");
52
+ },
53
+ HTTP_REQUEST_FAILED: function HTTP_REQUEST_FAILED(title) {
54
+ return "HTTP request failed: ".concat(title, ". Verify your request and try again.");
55
+ },
56
+ // App Request Errors - Operations: create, update, fetch, delete, install
57
+ APP_REQUEST_PROCESS_FAILED: 'App request process failed. Check the response details and try again.',
58
+ APP_REQUEST_ERROR: 'App request failed. Check the error details and try again.',
59
+ APP_REQUEST_REVIEW: 'App request failed. Review the error details and try again.',
60
+ APP_REQUEST_FAILED: 'Failed to process app request. Check the response details and try again.',
61
+ APP_OPERATION_ERROR: 'App operation error. Review the error details and try again.',
62
+ APP_REQUEST_RESPONSE_RECEIVED: 'App request response received.',
63
+ // Authorization Errors - Common causes: invalid client_id, unauthorized redirect_uri, expired codes
64
+ AUTHORIZATION_FAILED: 'Failed to process authorization request. Check the response details and try again.',
65
+ AUTHORIZATION_ERROR: 'Authorization failed. Check the error details and try again.',
66
+ AUTHORIZATION_REVIEW: 'Authorization failed. Review the error details and try again.',
67
+ AUTHORIZATION_RESPONSE_RECEIVED: 'Authorization response received.',
68
+ // Deployment Errors - Common causes: build failures, config issues, timeouts
69
+ DEPLOYMENT_FAILED: 'Deployment failed. Check the response details for errors and try again.',
70
+ DEPLOYMENT_ERROR: 'Deployment error occurred. Review the error details and try again.',
71
+ // Hosting Errors - Common causes: invalid config, timeouts, deployment failures
72
+ HOSTING_REQUEST_FAILED: 'Hosting request failed. Check the response details and try again.',
73
+ HOSTING_ERROR: 'Hosting error occurred. Review the error details and try again.',
74
+ HOSTING_REQUEST_ERROR: 'Hosting request error. Review the error details and try again.',
75
+ // OAuth Errors - Common causes: invalid credentials, expired tokens, scope errors
76
+ OAUTH_REQUEST_FAILED: 'OAuth request failed. Check the response details and try again.',
77
+ OAUTH_ERROR: 'OAuth error occurred. Review the error details and try again.',
78
+ // Installation Errors - Operations: fetch, update, uninstall, config
79
+ INSTALLATION_REQUEST_FAILED: 'Installation request failed. Check the response details and try again.',
80
+ INSTALLATION_ERROR: 'Installation error occurred. Review the error details and try again.',
81
+ INSTALLATION_WEBHOOK_FAILED: 'Installation webhook request failed. Check the response details and try again.',
82
+ INSTALLATION_WEBHOOK_ERROR: 'Installation webhook error occurred. Review the error details and try again.',
83
+ // Entity Errors - Operations: create, read, update, delete
84
+ ENTITY_REQUEST_FAILED: 'Entity request failed. Check the response details and try again.',
85
+ ENTITY_ERROR: 'Entity error occurred. Review the error details and try again.',
86
+ // Marketplace Errors
87
+ MARKETPLACE_REQUEST_FAILED: 'Marketplace request failed. Review the error details and try again.',
88
+ // Generic Errors
89
+ GENERIC_ERROR: 'An error occurred. Check the details and try again.'
90
+ };
91
+
92
+ /**
93
+ * Log level constants
94
+ */
95
+ var LOG_LEVELS = exports.LOG_LEVELS = {
96
+ ERROR: 'error',
97
+ INFO: 'info',
98
+ WARN: 'warn'
99
+ };
100
+
101
+ /**
102
+ * Log handler for general operations
103
+ * @param {string} level - Log level (error, info, warn)
104
+ * @param {*} data - Data to log
105
+ */
106
+ var logHandler = exports.logHandler = function logHandler(level, data) {
107
+ if (level === LOG_LEVELS.ERROR && data) {
108
+ var title = [data.name, data.message].filter(function (a) {
109
+ return a;
110
+ }).join(' - ');
111
+ console.error("".concat(ERROR_MESSAGES.REQUEST_FAILED(title)));
112
+ return;
113
+ }
114
+ console.log("".concat(level, ": ").concat(data, ". Check the details for troubleshooting."));
115
+ };
116
+
117
+ /**
118
+ * Log handler for HTTP client operations
119
+ * @param {string} level - Log level (error, info, warn)
120
+ * @param {*} data - Data to log
121
+ */
122
+ var httpLogHandler = exports.httpLogHandler = function httpLogHandler(level, data) {
123
+ if (level === LOG_LEVELS.ERROR && data) {
124
+ var title = [data.name, data.message].filter(function (a) {
125
+ return a;
126
+ }).join(' - ');
127
+ console.error("".concat(ERROR_MESSAGES.HTTP_REQUEST_FAILED(title)));
128
+ return;
129
+ }
130
+ console.log("".concat(level, ": ").concat(data, ". Check the HTTP client logs for more information."));
131
+ };
@@ -19,6 +19,7 @@ var _cloneDeep = require("lodash/cloneDeep");
19
19
  var _cloneDeep2 = (0, _interopRequireDefault2["default"])(_cloneDeep);
20
20
  var _contentstackCollection = require("./contentstackCollection");
21
21
  var _contentstackCollection2 = (0, _interopRequireDefault2["default"])(_contentstackCollection);
22
+ var _messageHandler = require("./core/messageHandler.js");
22
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
23
24
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty3["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
24
25
  var create = exports.create = function create(_ref) {
@@ -19,6 +19,7 @@ var _contentstackCollection = require("../../../contentstackCollection");
19
19
  var _contentstackCollection2 = (0, _interopRequireDefault2["default"])(_contentstackCollection);
20
20
  var _contentstackError = require("../../../core/contentstackError");
21
21
  var _contentstackError2 = (0, _interopRequireDefault2["default"])(_contentstackError);
22
+ var _messageHandler = require("../../../core/messageHandler.js");
22
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
23
24
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty3["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
24
25
  /**
@@ -17,6 +17,7 @@ var _cloneDeep2 = (0, _interopRequireDefault2["default"])(_cloneDeep);
17
17
  var _contentstackError = require("../../../core/contentstackError");
18
18
  var _contentstackError2 = (0, _interopRequireDefault2["default"])(_contentstackError);
19
19
  var _deployment = require("./deployment");
20
+ var _messageHandler = require("../../../core/messageHandler.js");
20
21
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
22
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty3["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
22
23
  /**
@@ -23,6 +23,7 @@ var _installation = require("../installation");
23
23
  var _oauth = require("./oauth");
24
24
  var _contentstackCollection = require("../../contentstackCollection");
25
25
  var _contentstackCollection2 = (0, _interopRequireDefault2["default"])(_contentstackCollection);
26
+ var _messageHandler = require("../../core/messageHandler.js");
26
27
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
28
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty3["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
28
29
  /**
@@ -65,8 +66,8 @@ function App(http, data) {
65
66
  * }
66
67
  * const app = client.marketplace('organization_uid').app('manifest_uid')
67
68
  * app = Object.assign(app, updateApp)
68
- * app.update()
69
- * .then((app) => console.log(app))
69
+ * app.update()
70
+ * .then((app) => console.log('App details loaded successfully.'))
70
71
  *
71
72
  */
72
73
  this.update = (0, _entity.update)(http, undefined, this.params);
@@ -81,8 +82,8 @@ function App(http, data) {
81
82
  * import * as contentstack from '@contentstack/marketplace'
82
83
  * const client = contentstack.client({ authtoken: 'TOKEN'})
83
84
  *
84
- * client.marketplace('organization_uid').app('manifest_uid').fetch()
85
- * .then((app) => console.log(app))
85
+ * client.marketplace('organization_uid').app('manifest_uid').fetch()
86
+ * .then((app) => console.log('App details loaded successfully.'))
86
87
  *
87
88
  */
88
89
  this.fetch = (0, _entity.fetch)(http, 'data', this.params);
@@ -97,8 +98,8 @@ function App(http, data) {
97
98
  * import * as contentstack from '@contentstack/marketplace'
98
99
  * const client = contentstack.client({ authtoken: 'TOKEN'})
99
100
  *
100
- * client.marketplace('organization_uid').app('manifest_uid').delete()
101
- * .then((response) => console.log(response))
101
+ * client.marketplace('organization_uid').app('manifest_uid').delete()
102
+ * .then((response) => console.log('App request response received.'))
102
103
  */
103
104
  this["delete"] = (0, _entity.deleteEntity)(http, false, this.params);
104
105
 
@@ -149,7 +150,7 @@ function App(http, data) {
149
150
  * import * as contentstack from '@contentstack/marketplace'
150
151
  * const client = contentstack.client({ authtoken: 'TOKEN'})
151
152
  * client.marketplace('organization_uid').app('manifest_uid').install({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
152
- * .then((installation) => console.log(installation))
153
+ * .then((installation) => console.log('App installation details loaded successfully.'))
153
154
  */
154
155
  this.install = /*#__PURE__*/function () {
155
156
  var _ref2 = (0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee(_ref) {
@@ -206,7 +207,7 @@ function App(http, data) {
206
207
  * import * as contentstack from '@contentstack/marketplace'
207
208
  * const client = contentstack.client({ authtoken: 'TOKEN'})
208
209
  * client.marketplace('organization_uid').app('manifest_uid').reinstall({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
209
- * .then((reinstallation) => console.log(installation))
210
+ * .then((reinstallation) => console.log('App installation details loaded successfully.'))
210
211
  */
211
212
  this.reinstall = /*#__PURE__*/function () {
212
213
  var _ref4 = (0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee2(_ref3) {
@@ -262,8 +263,8 @@ function App(http, data) {
262
263
  * @example
263
264
  * import * as contentstack from '@contentstack/marketplace'
264
265
  * const client = contentstack.client({ authtoken: 'TOKEN'})
265
- * client.marketplace('organization_uid').app('manifest_uid').install({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
266
- * .then((installation) => console.log(installation))
266
+ * client.marketplace('organization_uid').app('manifest_uid').upgrade({ targetUid: 'STACK_API_KEY', targetType: 'stack' })
267
+ * .then((installation) => console.log('App installation details loaded successfully.'))
267
268
  */
268
269
  this.upgrade = /*#__PURE__*/function () {
269
270
  var _ref6 = (0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee3(_ref5) {
@@ -318,7 +319,7 @@ function App(http, data) {
318
319
  * const client = contentstack.client({ authtoken: 'TOKEN'})
319
320
  *
320
321
  * client.marketplace('organization_uid').app('app_uid').getRequests()
321
- * .then((response) => console.log(response))
322
+ * .then((response) => console.log('API response received for app operation.'))
322
323
  *
323
324
  */
324
325
  this.getRequests = /*#__PURE__*/(0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee4() {
@@ -371,7 +372,7 @@ function App(http, data) {
371
372
  * const client = contentstack.client({ authtoken: 'TOKEN'})
372
373
  *
373
374
  * client.marketplace('organization_uid').app('app_uid').authorize({ responseType, clientId, redirectUri, scope, state })
374
- * .then((response) => console.log(response))
375
+ * .then((response) => console.log('API response received for app operation.'))
375
376
  *
376
377
  */
377
378
  this.authorize = /*#__PURE__*/function () {
@@ -450,7 +451,7 @@ function App(http, data) {
450
451
  * const client = contentstack.client({ authtoken: 'TOKEN'})
451
452
  *
452
453
  * client.marketplace('organization_uid').app('app_uid').listInstallations()
453
- * .then((collection) => console.log(collection))
454
+ * .then((collection) => console.log('App collection loaded successfully.'))
454
455
  *
455
456
  */
456
457
  this.listInstallations = /*#__PURE__*/(0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee6() {
@@ -513,7 +514,7 @@ function App(http, data) {
513
514
  * }
514
515
  *
515
516
  * client.marketplace('organization_uid').app().create(app)
516
- * .then((app) => console.log(app))
517
+ * .then((app) => console.log('App details loaded successfully.'))
517
518
  *
518
519
  */
519
520
  this.create = (0, _entity.create)({
@@ -16,6 +16,7 @@ var _contentstackError = require("../../../core/contentstackError");
16
16
  var _contentstackError2 = (0, _interopRequireDefault2["default"])(_contentstackError);
17
17
  var _cloneDeep = require("lodash/cloneDeep");
18
18
  var _cloneDeep2 = (0, _interopRequireDefault2["default"])(_cloneDeep);
19
+ var _messageHandler = require("../../../core/messageHandler.js");
19
20
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
21
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty3["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
22
  /**
@@ -45,8 +46,8 @@ function Oauth(http, data, params) {
45
46
  * import * as contentstack from '@contentstack/marketplace'
46
47
  * const client = contentstack.client({ authtoken: 'TOKEN'})
47
48
  *
48
- * client.marketplace('organization_uid').app('manifest_uid').oauth().fetch()
49
- * .then((oAuthConfig) => console.log(oAuthConfig))
49
+ * client.marketplace('organization_uid').app('manifest_uid').oauth().fetch()
50
+ * .then((oAuthConfig) => console.log(MESSAGES.OAUTH_CONFIG_LOADED))
50
51
  */
51
52
  this.fetch = /*#__PURE__*/(0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee() {
52
53
  var param,
@@ -108,8 +109,8 @@ function Oauth(http, data, params) {
108
109
  * scopes: ['scope1', 'scope2']
109
110
  * }
110
111
  * }
111
- * client.marketplace('organization_uid').app('manifest_uid').oauth().update({ config })
112
- * .then((oAuthConfig) => console.log(oAuthConfig))
112
+ * client.marketplace('organization_uid').app('manifest_uid').oauth().update({ config })
113
+ * .then((oAuthConfig) => console.log(MESSAGES.OAUTH_CONFIG_LOADED))
113
114
  */
114
115
  this.update = /*#__PURE__*/function () {
115
116
  var _ref3 = (0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee2(_ref2) {
@@ -162,8 +163,8 @@ function Oauth(http, data, params) {
162
163
  * import * as contentstack from '@contentstack/marketplace'
163
164
  * const client = contentstack.client({ authtoken: 'TOKEN'})
164
165
  *
165
- * client.marketplace('organization_uid').app('manifest_uid').oauth().getScopes()
166
- * .then((scopes) => console.log(scopes))
166
+ * client.marketplace('organization_uid').app('manifest_uid').oauth().getScopes()
167
+ * .then((scopes) => console.log(MESSAGES.OAUTH_SCOPES_LOADED))
167
168
  */
168
169
  this.getScopes = /*#__PURE__*/(0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee3() {
169
170
  var headers, response, _t3;