@sitecore/sc-contenthub-webclient-sdk 0.9.7 → 1.0.6

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 (103) hide show
  1. package/README.md +21 -0
  2. package/dist/base-types.d.ts +5 -2
  3. package/dist/caches/entity-definition-cache.d.ts +14 -1
  4. package/dist/caches/entity-definition-cache.js +35 -0
  5. package/dist/clients/aggregates-client.d.ts +19 -0
  6. package/dist/clients/aggregates-client.js +35 -0
  7. package/dist/clients/api-client.d.ts +0 -1
  8. package/dist/clients/api-client.js +7 -9
  9. package/dist/clients/content-hub-client.d.ts +13 -1
  10. package/dist/clients/content-hub-client.js +8 -0
  11. package/dist/clients/entity-definitions-client.js +7 -6
  12. package/dist/clients/internal-client.js +12 -2
  13. package/dist/clients/permissions-client.d.ts +16 -0
  14. package/dist/clients/permissions-client.js +53 -0
  15. package/dist/clients/raw-client.d.ts +1 -1
  16. package/dist/clients/request-message.d.ts +1 -1
  17. package/dist/clients/schema-querying.js +2 -2
  18. package/dist/clients/search-client.d.ts +9 -0
  19. package/dist/clients/search-client.js +11 -0
  20. package/dist/clients/upload-client.d.ts +21 -0
  21. package/dist/clients/upload-client.js +98 -0
  22. package/dist/clients/version-checker.d.ts +32 -0
  23. package/dist/clients/version-checker.js +60 -0
  24. package/dist/constants/api.d.ts +14 -0
  25. package/dist/constants/api.js +15 -1
  26. package/dist/constants/defaults.d.ts +3 -0
  27. package/dist/constants/defaults.js +4 -1
  28. package/dist/contracts/base/data-type.d.ts +1 -2
  29. package/dist/contracts/base/entity-base.d.ts +6 -0
  30. package/dist/contracts/base/entity-base.js +13 -0
  31. package/dist/contracts/base/entity-construction-args.d.ts +2 -0
  32. package/dist/contracts/base/entity-construction-args.js +1 -0
  33. package/dist/contracts/base/entity-definition.js +1 -1
  34. package/dist/contracts/base/entity.d.ts +26 -0
  35. package/dist/contracts/base/entity.js +19 -1
  36. package/dist/contracts/base/member-group.js +3 -0
  37. package/dist/contracts/base/property-definitions/string-property-definition.js +1 -1
  38. package/dist/contracts/base/related-path.d.ts +12 -0
  39. package/dist/contracts/base/related-path.js +2 -0
  40. package/dist/contracts/base/relation-definition.d.ts +5 -0
  41. package/dist/contracts/base/relation-definition.js +4 -0
  42. package/dist/contracts/base/rendition.d.ts +1 -1
  43. package/dist/contracts/base/string-content-type.d.ts +4 -4
  44. package/dist/contracts/base/string-content-type.js +4 -4
  45. package/dist/contracts/upload/upload-source.d.ts +5 -0
  46. package/dist/contracts/upload/upload-source.js +2 -0
  47. package/dist/converters/all-facet-values-children-converter.d.ts +21 -0
  48. package/dist/converters/all-facet-values-children-converter.js +45 -0
  49. package/dist/dirty-value-calculator.js +1 -5
  50. package/dist/error-messages.d.ts +1 -0
  51. package/dist/error-messages.js +1 -0
  52. package/dist/link-helper.d.ts +14 -0
  53. package/dist/link-helper.js +31 -0
  54. package/dist/link.d.ts +1 -1
  55. package/dist/link.js +3 -3
  56. package/dist/mappers/entity-mapper.d.ts +1 -0
  57. package/dist/mappers/entity-mapper.js +10 -0
  58. package/dist/mappers/filter-operator-mapper.d.ts +5 -0
  59. package/dist/mappers/filter-operator-mapper.js +14 -0
  60. package/dist/mappers/property-mapper.js +2 -11
  61. package/dist/mappers/related-path-mapper.d.ts +5 -0
  62. package/dist/mappers/related-path-mapper.js +30 -0
  63. package/dist/models/aggregate-resources/aggregate-resource.d.ts +14 -0
  64. package/dist/models/aggregate-resources/aggregate-resource.js +53 -0
  65. package/dist/models/aggregate-resources/aggregated-entity-resource.d.ts +11 -0
  66. package/dist/models/aggregate-resources/aggregated-entity-resource.js +30 -0
  67. package/dist/models/entity-resource.d.ts +3 -0
  68. package/dist/models/entity-resource.js +12 -0
  69. package/dist/models/pages/page-resource.d.ts +2 -2
  70. package/dist/models/pages/page-resource.js +1 -1
  71. package/dist/models/policies/policy-resource.js +2 -2
  72. package/dist/models/property-definition-resource.js +1 -1
  73. package/dist/models/search/all-facet-values-response.d.ts +12 -0
  74. package/dist/models/search/all-facet-values-response.js +41 -0
  75. package/dist/models/search/all-facets-request.d.ts +16 -0
  76. package/dist/models/search/all-facets-request.js +51 -0
  77. package/dist/models/search/grouped-view-response-resource.js +1 -1
  78. package/dist/models/search/search-request.d.ts +2 -3
  79. package/dist/models/search/search-response.d.ts +3 -2
  80. package/dist/models/search/search-response.js +4 -2
  81. package/dist/models/upload/array-buffer-upload-source.d.ts +0 -0
  82. package/dist/models/upload/array-buffer-upload-source.js +16 -0
  83. package/dist/models/upload/create-upload-response.d.ts +5 -0
  84. package/dist/models/upload/create-upload-response.js +31 -0
  85. package/dist/models/upload/http-upload-source.d.ts +11 -0
  86. package/dist/models/upload/http-upload-source.js +34 -0
  87. package/dist/models/upload/local-upload-source.d.ts +10 -0
  88. package/dist/models/upload/local-upload-source.js +49 -0
  89. package/dist/models/upload/upload-action.d.ts +6 -0
  90. package/dist/models/upload/upload-action.js +37 -0
  91. package/dist/models/upload/upload-configuration.d.ts +6 -0
  92. package/dist/models/upload/upload-configuration.js +37 -0
  93. package/dist/models/upload/upload-request-wrapper.d.ts +8 -0
  94. package/dist/models/upload/upload-request-wrapper.js +39 -0
  95. package/dist/models/upload/upload-request.d.ts +10 -0
  96. package/dist/models/upload/upload-request.js +18 -0
  97. package/dist/models/user-entity-permissions-resource.d.ts +14 -0
  98. package/dist/models/user-entity-permissions-resource.js +69 -0
  99. package/dist/models/versionining/compatibility.d.ts +17 -0
  100. package/dist/models/versionining/compatibility.js +21 -0
  101. package/dist/utilities/array-utilities.d.ts +1 -0
  102. package/dist/utilities/array-utilities.js +15 -0
  103. package/package.json +6 -10
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Sitecore Content Hub WebClient JS SDK
2
+
3
+ Sitecore Content Hub WebClient JS SDK, which is a lightweight JS client for Sitecore Content Hub.
4
+
5
+ ## Internal resources
6
+
7
+ - [Backlog](https://stylelabs.atlassian.net/secure/RapidBoard.jspa?rapidView=347&projectKey=ONSJSSDK&view=planning.nodetail&issueLimit=100)
8
+ - Slack: #ch-devex-questions
9
+
10
+ ## Release process
11
+
12
+ There are currently three build configurations that are specified in `bitbucket-pipelines.yml`
13
+
14
+ - A basic build runs each time a pull request is created or updated. This is to ensure that all unit tests are passing before committing any code to `master`.
15
+ - Once a pull request has been completed and the code is merged to `master`, an internal build is triggered automatically.
16
+ - Public releases can be created by tagging a commit with the following: `release-<major>.<minor>.<patch>` (e.g `release-1.0.0`). Upon a successful build all artifacts are pushed to the public channels.
17
+
18
+ ## Documentation
19
+
20
+ - [Stylelabs.M.Docs reporitory](https://bitbucket.org/stylelabsdev/stylelabs.m.docs/src/master/docfx-website/content/4.0.x/integrations/javascript-sdk/)
21
+ *NOTE: There are multiple paths for various versions that need to be updated independently.*
@@ -48,9 +48,12 @@ export declare type WritableKeysOf<T> = {
48
48
  }, P, never>;
49
49
  }[keyof T];
50
50
  export declare type WritablePart<T> = Pick<T, WritableKeysOf<T>>;
51
- export declare type JsonValue = string | number | boolean | {
51
+ export declare type JsonArray = Array<JsonValue>;
52
+ export declare type JsonObject = {
52
53
  [key: string]: JsonValue;
53
- } | Array<JsonValue> | null;
54
+ };
55
+ export declare type JsonValue = string | number | boolean | JsonObject | JsonArray | null;
54
56
  export declare type Object_Unknown = Record<string, unknown>;
55
57
  export declare type EmptyObject = Omit<Record<any, never>, keyof any>;
58
+ export declare type ReadableUploadSource = ArrayBuffer;
56
59
  export {};
@@ -1,10 +1,11 @@
1
- import { Nullable } from "../base-types";
1
+ import { Nullable, NullableResultPromise } from "../base-types";
2
2
  import { IEntityDefinition } from "../contracts/base";
3
3
  /**
4
4
  * Caches definition in memory.
5
5
  */
6
6
  export declare class EntityDefinitionCache {
7
7
  private readonly _allCacheKey;
8
+ private readonly _promiseKeyPrefix;
8
9
  private readonly _map;
9
10
  constructor();
10
11
  /**
@@ -12,12 +13,24 @@ export declare class EntityDefinitionCache {
12
13
  * @param definition - The entity definition
13
14
  */
14
15
  load(definition: IEntityDefinition): void;
16
+ /**
17
+ * Load the specified definition into the cache asynchronously.
18
+ * @param key - The definition name or definition id
19
+ * @param promise - A promise resolving to the definition
20
+ */
21
+ loadAsync(key: string | number, promise: NullableResultPromise<IEntityDefinition>): Promise<void>;
15
22
  /**
16
23
  * Retrieve the definition with specified name or id from the cache.
17
24
  * @param key - The definition name or definition id
18
25
  * @returns The cached definition or null
19
26
  */
20
27
  get(key: string | number): Nullable<IEntityDefinition>;
28
+ /**
29
+ * Retrieve the definition with specified name or id from the cache asynchronously.
30
+ * @param key - The definition name or definition id
31
+ * @returns A promise resolving to the cached definition or null
32
+ */
33
+ getAsync(key: string | number): Nullable<NullableResultPromise<IEntityDefinition>>;
21
34
  /**
22
35
  * Loads all definitions into the cache.
23
36
  * @param definitions - An array of entity definitions
@@ -11,6 +11,7 @@ const guard_1 = __importDefault(require("../guard"));
11
11
  class EntityDefinitionCache {
12
12
  constructor() {
13
13
  this._allCacheKey = "__ALL__";
14
+ this._promiseKeyPrefix = "PROMISE__";
14
15
  this._map = new Map();
15
16
  this._map = new Map();
16
17
  }
@@ -24,6 +25,22 @@ class EntityDefinitionCache {
24
25
  this._map.set(this.getCacheKey(definition.name), definition);
25
26
  this._map.set(definition.id.toString(), definition);
26
27
  }
28
+ /**
29
+ * Load the specified definition into the cache asynchronously.
30
+ * @param key - The definition name or definition id
31
+ * @param promise - A promise resolving to the definition
32
+ */
33
+ loadAsync(key, promise) {
34
+ this.validateKey(key);
35
+ guard_1.default.notNullOrUndefined(promise);
36
+ this._map.set(`${this._promiseKeyPrefix}${this.getCacheKey(key.toString())}`, promise);
37
+ const loadPromise = promise.then(definition => {
38
+ if (definition) {
39
+ this.load(definition);
40
+ }
41
+ });
42
+ return loadPromise;
43
+ }
27
44
  /**
28
45
  * Retrieve the definition with specified name or id from the cache.
29
46
  * @param key - The definition name or definition id
@@ -34,6 +51,24 @@ class EntityDefinitionCache {
34
51
  const res = this._map.get(this.getCacheKey(key.toString())) || null;
35
52
  return res;
36
53
  }
54
+ /**
55
+ * Retrieve the definition with specified name or id from the cache asynchronously.
56
+ * @param key - The definition name or definition id
57
+ * @returns A promise resolving to the cached definition or null
58
+ */
59
+ getAsync(key) {
60
+ this.validateKey(key);
61
+ const promise = (this._map.get(`${this._promiseKeyPrefix}${this.getCacheKey(key.toString())}`) ||
62
+ null);
63
+ if (promise != null) {
64
+ return promise;
65
+ }
66
+ const definition = (this.get(this.getCacheKey(key.toString())) || null);
67
+ if (definition != null) {
68
+ return Promise.resolve(definition);
69
+ }
70
+ return null;
71
+ }
37
72
  /**
38
73
  * Loads all definitions into the cache.
39
74
  * @param definitions - An array of entity definitions
@@ -0,0 +1,19 @@
1
+ import CultureInfo from "../culture-info";
2
+ import { AggregateResource } from "../models/aggregate-resources/aggregate-resource";
3
+ import { IExtendedContentHubClient } from "./extended-client";
4
+ export interface IAggregateClient {
5
+ /**
6
+ * Method for getting the specified aggregate for the specified entity.
7
+ * @param name - The name of the aggregate
8
+ * @param id - The entity id to get the aggregate for
9
+ * @param culture - The user culture
10
+ * @param loadPermissions - Flag for loading permissions
11
+ * @returns An aggregate resource
12
+ */
13
+ getAsync(name: string, id: number, culture?: CultureInfo, loadPermissions?: boolean): Promise<AggregateResource>;
14
+ }
15
+ export declare class AggregateClient implements IAggregateClient {
16
+ private readonly _client;
17
+ constructor(client: IExtendedContentHubClient);
18
+ getAsync(name: string, id: number, culture?: CultureInfo, loadPermissions?: boolean): Promise<AggregateResource>;
19
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AggregateClient = void 0;
16
+ const ta_json_1 = require("ta-json");
17
+ const guard_1 = __importDefault(require("../guard"));
18
+ const aggregate_resource_1 = require("../models/aggregate-resources/aggregate-resource");
19
+ const response_handler_1 = require("./response-handler");
20
+ class AggregateClient {
21
+ constructor(client) {
22
+ guard_1.default.notNull(client);
23
+ this._client = client;
24
+ }
25
+ getAsync(name, id, culture, loadPermissions) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ guard_1.default.stringNotNullOrEmpty(name);
28
+ const link = yield this._client.linkHelper.aggregateToLinkAsync(name, id, culture, loadPermissions);
29
+ const response = yield this._client.raw.getAsync(link.href);
30
+ response_handler_1.ResponseHandler.handleErrors(response);
31
+ return ta_json_1.TaJson.deserialize(response.content, aggregate_resource_1.AggregateResource);
32
+ });
33
+ }
34
+ }
35
+ exports.AggregateClient = AggregateClient;
@@ -52,5 +52,4 @@ export declare class ApiClient implements IApiClient {
52
52
  * @returns The API information.
53
53
  */
54
54
  private fetchApiInfoAsync;
55
- private static isDebugVersion;
56
55
  }
@@ -22,6 +22,8 @@ const not_supported_error_1 = require("../errors/not-supported-error");
22
22
  const fileversion_1 = require("../fileversion");
23
23
  const guard_1 = __importDefault(require("../guard"));
24
24
  const api_resource_mapper_1 = require("../mappers/api-resource-mapper");
25
+ const compatibility_1 = require("../models/versionining/compatibility");
26
+ const response_handler_1 = require("./response-handler");
25
27
  class ApiClient {
26
28
  constructor(client) {
27
29
  guard_1.default.notNullOrUndefined(client);
@@ -70,6 +72,7 @@ class ApiClient {
70
72
  const headers = {};
71
73
  headers[api_1.HEADERS.apiVersion] = "2";
72
74
  const response = yield this._client.raw.getAsync(api_1.API_ROOT, headers);
75
+ response_handler_1.ResponseHandler.handleErrors(response);
73
76
  let resource;
74
77
  try {
75
78
  resource = ta_json_1.TaJson.deserialize(response && response.content, api_info_resource_1.ApiInfoResource);
@@ -85,14 +88,12 @@ class ApiClient {
85
88
  }
86
89
  const sdkVersion = new fileversion_1.FileVersion(3, 0, 0); //TODO Load this from somewhere
87
90
  const serverVersion = resource.fileVersion;
88
- if (!this.disableCompatibilityChecks &&
89
- !ApiClient.isDebugVersion(serverVersion) &&
90
- !ApiClient.isDebugVersion(sdkVersion)) {
91
- if (sdkVersion.smallerThan(resource.minimumSdkVersion)) {
91
+ if (!this.disableCompatibilityChecks) {
92
+ const compatibilityResult = this._client.versionChecker.getCompatibility(serverVersion, sdkVersion, resource.minimumSdkVersion);
93
+ if (compatibilityResult == compatibility_1.Compatibility.SdkOld) {
92
94
  throw new not_supported_error_1.NotSupportedError(string_format_1.default(error_messages_1.default.ContentHubClient.IncompatibleMinimumVersion, sdkVersion, serverVersion, resource.minimumSdkVersion));
93
95
  }
94
- if (sdkVersion.major > serverVersion.major ||
95
- (sdkVersion.major === serverVersion.major && sdkVersion.minor > serverVersion.minor)) {
96
+ if (compatibilityResult == compatibility_1.Compatibility.SdkNew) {
96
97
  throw new not_supported_error_1.NotSupportedError(string_format_1.default(error_messages_1.default.ContentHubClient.IncompatibleVersion, sdkVersion, serverVersion));
97
98
  }
98
99
  }
@@ -100,8 +101,5 @@ class ApiClient {
100
101
  return apiInfo;
101
102
  });
102
103
  }
103
- static isDebugVersion(version) {
104
- return version.major <= 1;
105
- }
106
104
  }
107
105
  exports.ApiClient = ApiClient;
@@ -1,4 +1,4 @@
1
- import URI = require("urijs");
1
+ /// <reference types="urijs" />
2
2
  import OAuthPasswordGrant from "../authentication/oauth-password-grant";
3
3
  import OAuthRefreshTokenGrant from "../authentication/oauth-refreshtoken-grant";
4
4
  import { Nullable } from "../base-types";
@@ -9,6 +9,7 @@ import { ILinkHelper } from "../link-helper";
9
9
  import { ILogger } from "../logging/logger";
10
10
  import { EntityDefinitionMapper } from "../mappers/entity-definition-mapper";
11
11
  import { EntityMapper } from "../mappers/entity-mapper";
12
+ import { IAggregateClient } from "./aggregates-client";
12
13
  import { IApiClient } from "./api-client";
13
14
  import { ICommandsClient } from "./commands-client";
14
15
  import { ICultureClient } from "./culture-client";
@@ -19,18 +20,22 @@ import { IInternalClient } from "./internal-client";
19
20
  import { INotificationsClient } from "./notifications-client";
20
21
  import { IOptionListClient } from "./option-list-client";
21
22
  import { IPagesClient } from "./pages-client";
23
+ import { IPermissionsClient } from "./permissions-client";
22
24
  import { IPoliciesClient } from "./policies-client";
23
25
  import { IQueryingClient } from "./querying-client";
24
26
  import { IRawClient } from "./raw-client";
25
27
  import { ISearchClient } from "./search-client";
26
28
  import { ISettingsClient } from "./settings-client";
29
+ import { IUploadClient } from "./upload-client";
27
30
  import { IUsersClient } from "./users-client";
31
+ import { IVersionChecker } from "./version-checker";
28
32
  /**
29
33
  * Client for the Content Hub.
30
34
  */
31
35
  export interface IContentHubClient {
32
36
  logger: ILogger;
33
37
  readonly api: IApiClient;
38
+ readonly aggregates: IAggregateClient;
34
39
  readonly commands: ICommandsClient;
35
40
  readonly cultures: ICultureClient;
36
41
  readonly entities: IEntitiesClient;
@@ -43,6 +48,9 @@ export interface IContentHubClient {
43
48
  readonly settings: ISettingsClient;
44
49
  readonly users: IUsersClient;
45
50
  readonly pages: IPagesClient;
51
+ readonly permissions: IPermissionsClient;
52
+ readonly uploads: IUploadClient;
53
+ readonly versionChecker: IVersionChecker;
46
54
  readonly entityFactory: IEntityFactory;
47
55
  readonly optionListFactory: IOptionListFactory;
48
56
  }
@@ -51,6 +59,7 @@ export declare class ContentHubClient implements IExtendedContentHubClient {
51
59
  baseUri: URI;
52
60
  readonly internalClient: IInternalClient;
53
61
  readonly api: IApiClient;
62
+ readonly aggregates: IAggregateClient;
54
63
  readonly commands: ICommandsClient;
55
64
  readonly cultures: ICultureClient;
56
65
  readonly entities: IEntitiesClient;
@@ -63,6 +72,9 @@ export declare class ContentHubClient implements IExtendedContentHubClient {
63
72
  readonly settings: ISettingsClient;
64
73
  readonly users: IUsersClient;
65
74
  readonly pages: IPagesClient;
75
+ readonly permissions: IPermissionsClient;
76
+ readonly uploads: IUploadClient;
77
+ readonly versionChecker: IVersionChecker;
66
78
  readonly search: ISearchClient;
67
79
  readonly entityFactory: IEntityFactory;
68
80
  readonly optionListFactory: IOptionListFactory;
@@ -13,6 +13,7 @@ const null_logger_1 = __importDefault(require("../logging/null-logger"));
13
13
  const entity_definition_mapper_1 = require("../mappers/entity-definition-mapper");
14
14
  const entity_mapper_1 = require("../mappers/entity-mapper");
15
15
  const typed_entity_creator_1 = require("../mappers/typed-entity-creator");
16
+ const aggregates_client_1 = require("./aggregates-client");
16
17
  const api_client_1 = require("./api-client");
17
18
  const commands_client_1 = require("./commands-client");
18
19
  const culture_client_1 = require("./culture-client");
@@ -23,12 +24,15 @@ const internal_client_1 = require("./internal-client");
23
24
  const notifications_client_1 = require("./notifications-client");
24
25
  const option_list_client_1 = require("./option-list-client");
25
26
  const pages_client_1 = require("./pages-client");
27
+ const permissions_client_1 = require("./permissions-client");
26
28
  const policies_client_1 = require("./policies-client");
27
29
  const querying_client_1 = require("./querying-client");
28
30
  const raw_client_1 = require("./raw-client");
29
31
  const search_client_1 = require("./search-client");
30
32
  const settings_client_1 = require("./settings-client");
33
+ const upload_client_1 = require("./upload-client");
31
34
  const users_client_1 = require("./users-client");
35
+ const version_checker_1 = require("./version-checker");
32
36
  class ContentHubClient {
33
37
  constructor(baseUri, oauthGrant, logger = new null_logger_1.default()) {
34
38
  this.impersonatedUsername = null;
@@ -39,6 +43,7 @@ class ContentHubClient {
39
43
  this.logger = logger;
40
44
  this.internalClient = new internal_client_1.InternalClient(baseUri, oauthGrant);
41
45
  this.api = new api_client_1.ApiClient(this);
46
+ this.aggregates = new aggregates_client_1.AggregateClient(this);
42
47
  this.commands = new commands_client_1.CommandsClient(this);
43
48
  this.entities = new entities_client_1.EntitiesClient(this);
44
49
  this.entityDefinitions = new entity_definitions_client_1.EntityDefinitionsClient(this);
@@ -52,6 +57,8 @@ class ContentHubClient {
52
57
  this.search = new search_client_1.SearchClient(this);
53
58
  this.settings = new settings_client_1.SettingsClient(this);
54
59
  this.users = new users_client_1.UsersClient(this);
60
+ this.permissions = new permissions_client_1.PermissionsClient(this);
61
+ this.uploads = new upload_client_1.UploadClient(this);
55
62
  const cultureLoader = new culture_loader_1.CultureLoader(this);
56
63
  this.cultures = new culture_client_1.CultureClient(cultureLoader);
57
64
  this.relationFactory = new relation_factory_1.RelationFactory(this);
@@ -61,6 +68,7 @@ class ContentHubClient {
61
68
  this.entityMapper = new entity_mapper_1.EntityMapper(this);
62
69
  this.entityDefinitionMapper = new entity_definition_mapper_1.EntityDefinitionMapper(this);
63
70
  this.linkHelper = new link_helper_1.LinkHelper(this);
71
+ this.versionChecker = new version_checker_1.VersionChecker(this.api);
64
72
  }
65
73
  }
66
74
  exports.ContentHubClient = ContentHubClient;
@@ -33,7 +33,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  exports.EntityDefinitionsClient = void 0;
35
35
  const HttpStatus = __importStar(require("http-status-codes"));
36
- const lodash_1 = require("lodash");
37
36
  const ta_json_1 = require("ta-json");
38
37
  const entity_definition_cache_1 = require("../caches/entity-definition-cache");
39
38
  const entity_definition_id_iterator_1 = require("../contracts/querying/entity-definition-id-iterator");
@@ -45,6 +44,7 @@ const guard_1 = __importDefault(require("../guard"));
45
44
  const entity_definition_collection_resource_1 = require("../models/entity-definition-collection-resource");
46
45
  const entity_definition_resource_1 = require("../models/entity-definition-resource");
47
46
  const type_guards_1 = require("../type-guards");
47
+ const array_utilities_1 = require("../utilities/array-utilities");
48
48
  const response_handler_1 = require("./response-handler");
49
49
  class EntityDefinitionsClient {
50
50
  constructor(client) {
@@ -77,11 +77,12 @@ class EntityDefinitionsClient {
77
77
  getCachedAsync(param) {
78
78
  return __awaiter(this, void 0, void 0, function* () {
79
79
  guard_1.default.notNullOrUndefined(param);
80
- let definition = this._cache.get(param);
81
- if (!definition) {
82
- definition = yield this.getAsync(param);
80
+ let definitionPromise = this._cache.getAsync(param);
81
+ if (!definitionPromise) {
82
+ definitionPromise = this.getAsync(param);
83
+ this._cache.loadAsync(param, definitionPromise);
83
84
  }
84
- return definition;
85
+ return definitionPromise;
85
86
  });
86
87
  }
87
88
  getNameAsync(id) {
@@ -313,7 +314,7 @@ class EntityDefinitionsClient {
313
314
  }
314
315
  const resources = [];
315
316
  // We need to batch this or the backend will refuse to respond.
316
- const batches = lodash_1.chunk(definitionsToFetch, EntityDefinitionsClient._batchSize);
317
+ const batches = array_utilities_1.chunk(definitionsToFetch, EntityDefinitionsClient._batchSize);
317
318
  for (const definitionBatch of batches) {
318
319
  const link = yield linkFactory(definitionBatch, EntityDefinitionsClient._batchSize, true);
319
320
  const response = yield this._client.raw.getAsync(link.href);
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.InternalClient = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const axios_extensions_1 = require("axios-extensions");
18
+ const https_1 = __importDefault(require("https"));
18
19
  const ta_json_1 = require("ta-json");
19
20
  const oauth_password_grant_1 = __importDefault(require("../authentication/oauth-password-grant"));
20
21
  const oauth_refreshtoken_grant_1 = __importDefault(require("../authentication/oauth-refreshtoken-grant"));
@@ -33,10 +34,19 @@ class InternalClient {
33
34
  guard_1.default.notNull(oauthGrant);
34
35
  const baseUrl = typeof baseUri === "string" ? baseUri : baseUri.href();
35
36
  guard_1.default.stringNotNullOrEmpty(baseUrl);
36
- this._client = axios_1.default.create({
37
+ const createClientParameters = {
37
38
  baseURL: baseUrl,
38
39
  adapter: axios_extensions_1.throttleAdapterEnhancer(axios_extensions_1.cacheAdapterEnhancer(axios_1.default.defaults.adapter, { enabledByDefault: false })),
39
- });
40
+ };
41
+ // This setting should be added to the .env file for connecting to a server using a self signed certificate
42
+ if (typeof process !== "undefined" && process != null) {
43
+ if (process.env.IGNORE_HTTPS_ERRORS === "true") {
44
+ createClientParameters.httpsAgent = new https_1.default.Agent({
45
+ rejectUnauthorized: false,
46
+ });
47
+ }
48
+ }
49
+ this._client = axios_1.default.create(createClientParameters);
40
50
  if (oauthGrant instanceof oauth_password_grant_1.default) {
41
51
  this._passwordGrant = oauthGrant;
42
52
  }
@@ -0,0 +1,16 @@
1
+ import { Nullable, NullableResultPromise } from "../base-types";
2
+ import { IExtendedContentHubClient } from "./extended-client";
3
+ export interface IPermissionsClient {
4
+ /**
5
+ * Gets the specified entity permissions.
6
+ *
7
+ * @param id - The id of the entity
8
+ * @param userId - The id of the user
9
+ */
10
+ getPermissionsAsync(id: number, userId?: Nullable<number>): NullableResultPromise<Array<string>>;
11
+ }
12
+ export declare class PermissionsClient implements IPermissionsClient {
13
+ protected readonly _client: IExtendedContentHubClient;
14
+ constructor(client: IExtendedContentHubClient);
15
+ getPermissionsAsync(id: number, userId?: number): NullableResultPromise<Array<string>>;
16
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PermissionsClient = void 0;
16
+ const ta_json_1 = require("ta-json");
17
+ const response_handler_1 = require("../clients/response-handler");
18
+ const guard_1 = __importDefault(require("../guard"));
19
+ const permissions_resource_1 = require("../models/permissions-resource");
20
+ const user_entity_permissions_resource_1 = require("../models/user-entity-permissions-resource");
21
+ class PermissionsClient {
22
+ constructor(client) {
23
+ this._client = client;
24
+ }
25
+ getPermissionsAsync(id, userId) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ guard_1.default.validId(id);
28
+ let link;
29
+ if (userId != null) {
30
+ guard_1.default.validId(userId);
31
+ link = yield this._client.linkHelper.explainUserPermissionsForEntityToLinkAsync(id, userId);
32
+ }
33
+ else {
34
+ link = yield this._client.linkHelper.permissionsForEntityToLinkAsync(id);
35
+ }
36
+ const response = yield this._client.raw.getAsync(link.href);
37
+ if (response.statusCode === 404) {
38
+ return [];
39
+ }
40
+ response_handler_1.ResponseHandler.handleErrors(response);
41
+ if (userId != null) {
42
+ const resource = ta_json_1.TaJson.deserialize(response.content, user_entity_permissions_resource_1.UserEntityPermissionsResource);
43
+ const permissions = resource.permissions.map(p => p.permission);
44
+ return permissions != null && permissions.length > 0 ? permissions : [];
45
+ }
46
+ else {
47
+ const resource = ta_json_1.TaJson.deserialize(response.content, permissions_resource_1.PermissionsResource);
48
+ return resource.permissions || [];
49
+ }
50
+ });
51
+ }
52
+ }
53
+ exports.PermissionsClient = PermissionsClient;
@@ -1,4 +1,4 @@
1
- import URI = require("urijs");
1
+ import URI from "urijs";
2
2
  import { MapStringTo } from "../base-types";
3
3
  import { IExtendedContentHubClient } from "./extended-client";
4
4
  import { RequestMessage } from "./request-message";
@@ -1,4 +1,4 @@
1
- import URI = require("urijs");
1
+ import URI from "urijs";
2
2
  import { MapStringTo } from "../base-types";
3
3
  import { HttpMethod } from "../http-method";
4
4
  /**
@@ -14,13 +14,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SchemaQuerying = void 0;
16
16
  const ta_json_1 = require("ta-json");
17
+ const urijs_1 = __importDefault(require("urijs"));
17
18
  const URITemplate_1 = __importDefault(require("urijs/src/URITemplate"));
18
19
  const api_1 = require("../constants/api");
19
20
  const query_request_1 = require("../contracts/querying/query-request");
20
21
  const guard_1 = __importDefault(require("../guard"));
21
22
  const query_result_resource_1 = require("../models/query-result-resource");
22
23
  const response_handler_1 = require("./response-handler");
23
- const URI = require("urijs");
24
24
  class SchemaQuerying {
25
25
  constructor(client) {
26
26
  guard_1.default.notNullOrUndefined(client);
@@ -39,7 +39,7 @@ class SchemaQuerying {
39
39
  uri = uriTemplate.expand({});
40
40
  }
41
41
  else {
42
- uri = new URI(queryEndpoint.href);
42
+ uri = new urijs_1.default(queryEndpoint.href);
43
43
  }
44
44
  const queryRequest = new query_request_1.QueryRequest({
45
45
  query: query,
@@ -1,3 +1,5 @@
1
+ import { AllFacetValuesResponse } from "../models/search/all-facet-values-response";
2
+ import { AllFacetsRequest } from "../models/search/all-facets-request";
1
3
  import { SearchRequest } from "../models/search/search-request";
2
4
  import { SearchResponse } from "../models/search/search-response";
3
5
  import { IExtendedContentHubClient } from "./extended-client";
@@ -8,9 +10,16 @@ export interface ISearchClient {
8
10
  * @returns The search response.
9
11
  */
10
12
  searchAsync(searchRequest: SearchRequest): Promise<SearchResponse>;
13
+ /**
14
+ * Send a {@link AllFacetsRequest}.
15
+ * @param allFacetsRequest - The all facets search request
16
+ * @returns The search response.
17
+ */
18
+ allFacetsAsync(allFacetsRequest: AllFacetsRequest): Promise<AllFacetValuesResponse>;
11
19
  }
12
20
  export declare class SearchClient implements ISearchClient {
13
21
  private readonly _client;
14
22
  constructor(client: IExtendedContentHubClient);
15
23
  searchAsync(searchRequest: SearchRequest): Promise<SearchResponse>;
24
+ allFacetsAsync(allFacetsRequest: AllFacetsRequest): Promise<AllFacetValuesResponse>;
16
25
  }
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SearchClient = void 0;
16
16
  const ta_json_1 = require("ta-json");
17
17
  const guard_1 = __importDefault(require("../guard"));
18
+ const all_facet_values_response_1 = require("../models/search/all-facet-values-response");
18
19
  const search_response_1 = require("../models/search/search-response");
19
20
  const response_handler_1 = require("./response-handler");
20
21
  class SearchClient {
@@ -32,5 +33,15 @@ class SearchClient {
32
33
  return searchResponse;
33
34
  });
34
35
  }
36
+ allFacetsAsync(allFacetsRequest) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ guard_1.default.notNullOrUndefined(allFacetsRequest);
39
+ const allFacetsLink = yield this._client.linkHelper.allFacetsAsync();
40
+ const response = yield this._client.raw.postAsync(allFacetsLink.href, ta_json_1.TaJson.serialize(allFacetsRequest));
41
+ response_handler_1.ResponseHandler.handleErrors(response);
42
+ const allFacetsResponse = ta_json_1.TaJson.deserialize(response.content, all_facet_values_response_1.AllFacetValuesResponse);
43
+ return allFacetsResponse;
44
+ });
45
+ }
35
46
  }
36
47
  exports.SearchClient = SearchClient;
@@ -0,0 +1,21 @@
1
+ import { UploadRequest } from "../models/upload/upload-request";
2
+ import { IExtendedContentHubClient } from "./extended-client";
3
+ import { ResponseMessage } from "./response-message";
4
+ /**
5
+ * Client for uploading files (packages).
6
+ */
7
+ export interface IUploadClient {
8
+ /**
9
+ * Attempts to upload the specified file.
10
+ * @param request - Describes the file upload.
11
+ * @returns The response of the file upload request.
12
+ */
13
+ uploadAsync(request: UploadRequest): Promise<ResponseMessage>;
14
+ }
15
+ export declare class UploadClient implements IUploadClient {
16
+ private client;
17
+ constructor(client: IExtendedContentHubClient);
18
+ uploadAsync(request: UploadRequest): Promise<ResponseMessage>;
19
+ private uploadFileAsync;
20
+ private uploadChunkAsync;
21
+ }