@esri/hub-common 12.4.0 → 12.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,4 +6,5 @@ export * from "./fetchCatalog";
6
6
  export * from "./hubSearch";
7
7
  export * from "./Catalog";
8
8
  export * from "./Collection";
9
+ export * from "./wellKnownCatalog";
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/search/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/search/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,228 @@
1
+ import { getFamilyTypes } from "../content";
2
+ /**
3
+ * Check if i18nScope is defined and not ending with a ".", if so add a "." at the end.
4
+ * e.g. if the i18nScope is 'project.edit', the path is `${i18nScope}catalog.organization`,
5
+ * we will want "project.edit.catalog.organization" instead of "project.editcatalog.organization"
6
+ * @param i18nScope
7
+ * @returns i18nScope with a "." at the end if it is defined
8
+ */
9
+ function dotifyString(i18nScope) {
10
+ if (i18nScope && i18nScope.slice(-1) !== ".") {
11
+ return `${i18nScope}.`;
12
+ }
13
+ }
14
+ /** Get a single catalog based on the name, entity type and optional requests
15
+ * @param i18nScope Translation scope to be interpolated into the catalog
16
+ * @param name Name of the catalog requested
17
+ * @param entityType
18
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
19
+ * @returns An IHubCatalog definition JSON object
20
+ */
21
+ export function getWellKnownCatalog(i18nScope, name, entityType, options) {
22
+ switch (entityType) {
23
+ case "item":
24
+ return getWellknownItemCatalog(i18nScope, name, options);
25
+ /* Add other entity handlers here, e.g. getWellknownEventCatalog */
26
+ default:
27
+ throw new Error(`Wellknown catalog not implemented for "${entityType}"`);
28
+ }
29
+ }
30
+ /**
31
+ * Build an IHubCatalog definition JSON object based on the
32
+ * catalog name, predicates and collections we want to use for each catalog
33
+ * @param i18nScope
34
+ * @param name Catalog name
35
+ * @param predicates Predicates for the catalog
36
+ * @param collections Collections to include for the catalog
37
+ * @returns An IHubCatalog definition JSON object
38
+ */
39
+ function buildCatalog(i18nScope, name, predicates, collections) {
40
+ return {
41
+ schemaVersion: 1,
42
+ title: `{{${i18nScope}catalog.${name}:translate}}`,
43
+ scopes: {
44
+ item: {
45
+ targetEntity: "item",
46
+ filters: [{ predicates }],
47
+ },
48
+ },
49
+ collections,
50
+ };
51
+ }
52
+ /**
53
+ * Check if user is available in the passed options, throw an error if not
54
+ * @param name name of the catalog
55
+ * @param options Options that contains user
56
+ */
57
+ function checkUser(name, options) {
58
+ if (!options || !options.user) {
59
+ throw new Error(`User needed to get "${name}" catalog`);
60
+ }
61
+ }
62
+ /**
63
+ * Get an ITEM catalog based on the name and optional requests
64
+ * @param i18nScope Translation scope to be interpolated into the catalog
65
+ * @param name Name of the catalog requested
66
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
67
+ * @returns An ITEM IHubCatalog definition JSON object
68
+ */
69
+ function getWellknownItemCatalog(i18nScope, name, options) {
70
+ i18nScope = dotifyString(i18nScope);
71
+ let catalog;
72
+ const collections = getWellknownCollections(i18nScope, "item", options === null || options === void 0 ? void 0 : options.collectionNames);
73
+ switch (name) {
74
+ case "myContent":
75
+ checkUser(name, options);
76
+ catalog = buildCatalog(i18nScope, name, [{ owner: options.user.username }], collections);
77
+ break;
78
+ case "favorites":
79
+ checkUser(name, options);
80
+ catalog = buildCatalog(i18nScope, name, [{ group: options.user.favGroupId }], collections);
81
+ break;
82
+ case "organization":
83
+ checkUser(name, options);
84
+ catalog = buildCatalog(i18nScope, name, [{ orgid: options.user.orgId, access: "org" }], collections);
85
+ break;
86
+ case "world":
87
+ catalog = buildCatalog(i18nScope, name, [{ access: "public" }], collections);
88
+ break;
89
+ }
90
+ return catalog;
91
+ }
92
+ /**
93
+ * Get a complete collections map to use to build a collections list
94
+ * @param i18nScope
95
+ * @param entityType
96
+ * @returns an object that contains properties of all the collections
97
+ */
98
+ function getAllCollectionsMap(i18nScope, entityType) {
99
+ return {
100
+ appAndMap: {
101
+ key: "appAndMap",
102
+ label: `{{${i18nScope}collection.appsAndMaps:translate}}`,
103
+ targetEntity: entityType,
104
+ include: [],
105
+ scope: {
106
+ targetEntity: entityType,
107
+ filters: [
108
+ {
109
+ predicates: [
110
+ {
111
+ type: [...getFamilyTypes("app"), ...getFamilyTypes("map")],
112
+ },
113
+ ],
114
+ },
115
+ ],
116
+ },
117
+ },
118
+ dataset: {
119
+ key: "dataset",
120
+ label: `{{${i18nScope}collection.dataset:translate}}`,
121
+ targetEntity: entityType,
122
+ include: [],
123
+ scope: {
124
+ targetEntity: entityType,
125
+ filters: [{ predicates: [{ type: getFamilyTypes("dataset") }] }],
126
+ },
127
+ },
128
+ document: {
129
+ key: "document",
130
+ label: `{{${i18nScope}collection.document:translate}}`,
131
+ targetEntity: entityType,
132
+ include: [],
133
+ scope: {
134
+ targetEntity: entityType,
135
+ filters: [{ predicates: [{ type: getFamilyTypes("document") }] }],
136
+ },
137
+ },
138
+ feedback: {
139
+ key: "feedback",
140
+ label: `{{${i18nScope}collection.feedback:translate}}`,
141
+ targetEntity: entityType,
142
+ include: [],
143
+ scope: {
144
+ targetEntity: entityType,
145
+ filters: [{ predicates: [{ type: getFamilyTypes("feedback") }] }],
146
+ },
147
+ },
148
+ site: {
149
+ key: "site",
150
+ label: `{{${i18nScope}collection.sites:translate}}`,
151
+ targetEntity: entityType,
152
+ include: [],
153
+ scope: {
154
+ targetEntity: entityType,
155
+ filters: [
156
+ {
157
+ predicates: [
158
+ {
159
+ type: getFamilyTypes("site"),
160
+ },
161
+ ],
162
+ },
163
+ ],
164
+ },
165
+ },
166
+ template: {
167
+ key: "template",
168
+ label: `{{${i18nScope}collection.templates:translate}}`,
169
+ targetEntity: entityType,
170
+ include: [],
171
+ scope: {
172
+ targetEntity: entityType,
173
+ filters: [
174
+ {
175
+ predicates: [
176
+ {
177
+ type: getFamilyTypes("template"),
178
+ },
179
+ ],
180
+ },
181
+ ],
182
+ },
183
+ },
184
+ };
185
+ }
186
+ /**
187
+ * Get a list of collection names we want to use to build the default collections if no specific collection names are passed
188
+ * @returns a list of WellKnownCollection definition strings
189
+ */
190
+ function getDefaultCollectionNames() {
191
+ return ["appAndMap", "dataset", "document", "feedback", "site"];
192
+ }
193
+ /**
194
+ * Get a list of collections based on the entity type and an optional
195
+ * list of collection names, will return a list of default collections if none passed
196
+ * @param i18nScope Translation scope to be interpolated into the collections
197
+ * @param entityType
198
+ * @param collectionNames List of names of the requested collections, optional, if passed in,
199
+ * only those collections will be returned
200
+ * @returns A list of IHubCollection definition JSON objects
201
+ */
202
+ export function getWellknownCollections(i18nScope, entityType, collectionNames) {
203
+ i18nScope = dotifyString(i18nScope);
204
+ const allCollectionsMap = getAllCollectionsMap(i18nScope, entityType);
205
+ const defaultCollectionNames = getDefaultCollectionNames();
206
+ // Return a list of collections from the passed collection names or
207
+ // return the default ones if not passed
208
+ const names = (collectionNames === null || collectionNames === void 0 ? void 0 : collectionNames.length) ? collectionNames
209
+ : defaultCollectionNames;
210
+ return names.reduce((accum, name) => {
211
+ if (allCollectionsMap[name]) {
212
+ accum.push(allCollectionsMap[name]);
213
+ }
214
+ return accum;
215
+ }, []);
216
+ }
217
+ /**
218
+ * Get a single collection based on the collection name and entity type
219
+ * @param i18nScope
220
+ * @param entityType
221
+ * @param collectionName Name of the collection requested
222
+ * @returns An IHubCollection definition JSON object
223
+ */
224
+ export function getWellknownCollection(i18nScope, entityType, collectionName) {
225
+ i18nScope = dotifyString(i18nScope);
226
+ return getAllCollectionsMap(i18nScope, entityType)[collectionName];
227
+ }
228
+ //# sourceMappingURL=wellKnownCatalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wellKnownCatalog.js","sourceRoot":"","sources":["../../../src/search/wellKnownCatalog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAoC5C;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,SAAiB;IACrC,IAAI,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QAC5C,OAAO,GAAG,SAAS,GAAG,CAAC;KACxB;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAAiB,EACjB,IAAsB,EACtB,UAAsB,EACtB,OAAqC;IAErC,QAAQ,UAAU,EAAE;QAClB,KAAK,MAAM;YACT,OAAO,uBAAuB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3D,mEAAmE;QACnE;YACE,MAAM,IAAI,KAAK,CAAC,0CAA0C,UAAU,GAAG,CAAC,CAAC;KAC5E;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,YAAY,CACnB,SAAiB,EACjB,IAAsB,EACtB,UAAiB,EACjB,WAA6B;IAE7B,OAAO;QACL,aAAa,EAAE,CAAC;QAChB,KAAK,EAAE,KAAK,SAAS,WAAW,IAAI,cAAc;QAClD,MAAM,EAAE;YACN,IAAI,EAAE;gBACJ,YAAY,EAAE,MAAoB;gBAClC,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC;aAC1B;SACF;QACD,WAAW;KACZ,CAAC;AACJ,CAAC;AAED;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C,MAAM,KAAK,GAAG,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,MAAM,EACnC,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,sBAAsB,CAAC;IAC3B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAClC,IAAI,iBAAiB,CAAC,IAAI,CAAC,EAAE;YAC3B,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;SACrC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAAiB,EACjB,UAAsB,EACtB,cAAmC;IAEnC,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IACpC,OAAO,oBAAoB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,cAAc,CAAC,CAAC;AACrE,CAAC"}
@@ -9,4 +9,5 @@ tslib_1.__exportStar(require("./fetchCatalog"), exports);
9
9
  tslib_1.__exportStar(require("./hubSearch"), exports);
10
10
  tslib_1.__exportStar(require("./Catalog"), exports);
11
11
  tslib_1.__exportStar(require("./Collection"), exports);
12
+ tslib_1.__exportStar(require("./wellKnownCatalog"), exports);
12
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/search/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,kDAAwB;AACxB,iEAAuC;AACvC,oEAA0C;AAC1C,yDAA+B;AAC/B,sDAA4B;AAC5B,oDAA0B;AAC1B,uDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/search/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,kDAAwB;AACxB,iEAAuC;AACvC,oEAA0C;AAC1C,yDAA+B;AAC/B,sDAA4B;AAC5B,oDAA0B;AAC1B,uDAA6B;AAC7B,6DAAmC"}
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWellknownCollection = exports.getWellknownCollections = exports.getWellKnownCatalog = void 0;
4
+ const content_1 = require("../content");
5
+ /**
6
+ * Check if i18nScope is defined and not ending with a ".", if so add a "." at the end.
7
+ * e.g. if the i18nScope is 'project.edit', the path is `${i18nScope}catalog.organization`,
8
+ * we will want "project.edit.catalog.organization" instead of "project.editcatalog.organization"
9
+ * @param i18nScope
10
+ * @returns i18nScope with a "." at the end if it is defined
11
+ */
12
+ function dotifyString(i18nScope) {
13
+ if (i18nScope && i18nScope.slice(-1) !== ".") {
14
+ return `${i18nScope}.`;
15
+ }
16
+ }
17
+ /** Get a single catalog based on the name, entity type and optional requests
18
+ * @param i18nScope Translation scope to be interpolated into the catalog
19
+ * @param name Name of the catalog requested
20
+ * @param entityType
21
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
22
+ * @returns An IHubCatalog definition JSON object
23
+ */
24
+ function getWellKnownCatalog(i18nScope, name, entityType, options) {
25
+ switch (entityType) {
26
+ case "item":
27
+ return getWellknownItemCatalog(i18nScope, name, options);
28
+ /* Add other entity handlers here, e.g. getWellknownEventCatalog */
29
+ default:
30
+ throw new Error(`Wellknown catalog not implemented for "${entityType}"`);
31
+ }
32
+ }
33
+ exports.getWellKnownCatalog = getWellKnownCatalog;
34
+ /**
35
+ * Build an IHubCatalog definition JSON object based on the
36
+ * catalog name, predicates and collections we want to use for each catalog
37
+ * @param i18nScope
38
+ * @param name Catalog name
39
+ * @param predicates Predicates for the catalog
40
+ * @param collections Collections to include for the catalog
41
+ * @returns An IHubCatalog definition JSON object
42
+ */
43
+ function buildCatalog(i18nScope, name, predicates, collections) {
44
+ return {
45
+ schemaVersion: 1,
46
+ title: `{{${i18nScope}catalog.${name}:translate}}`,
47
+ scopes: {
48
+ item: {
49
+ targetEntity: "item",
50
+ filters: [{ predicates }],
51
+ },
52
+ },
53
+ collections,
54
+ };
55
+ }
56
+ /**
57
+ * Check if user is available in the passed options, throw an error if not
58
+ * @param name name of the catalog
59
+ * @param options Options that contains user
60
+ */
61
+ function checkUser(name, options) {
62
+ if (!options || !options.user) {
63
+ throw new Error(`User needed to get "${name}" catalog`);
64
+ }
65
+ }
66
+ /**
67
+ * Get an ITEM catalog based on the name and optional requests
68
+ * @param i18nScope Translation scope to be interpolated into the catalog
69
+ * @param name Name of the catalog requested
70
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
71
+ * @returns An ITEM IHubCatalog definition JSON object
72
+ */
73
+ function getWellknownItemCatalog(i18nScope, name, options) {
74
+ i18nScope = dotifyString(i18nScope);
75
+ let catalog;
76
+ const collections = getWellknownCollections(i18nScope, "item", options === null || options === void 0 ? void 0 : options.collectionNames);
77
+ switch (name) {
78
+ case "myContent":
79
+ checkUser(name, options);
80
+ catalog = buildCatalog(i18nScope, name, [{ owner: options.user.username }], collections);
81
+ break;
82
+ case "favorites":
83
+ checkUser(name, options);
84
+ catalog = buildCatalog(i18nScope, name, [{ group: options.user.favGroupId }], collections);
85
+ break;
86
+ case "organization":
87
+ checkUser(name, options);
88
+ catalog = buildCatalog(i18nScope, name, [{ orgid: options.user.orgId, access: "org" }], collections);
89
+ break;
90
+ case "world":
91
+ catalog = buildCatalog(i18nScope, name, [{ access: "public" }], collections);
92
+ break;
93
+ }
94
+ return catalog;
95
+ }
96
+ /**
97
+ * Get a complete collections map to use to build a collections list
98
+ * @param i18nScope
99
+ * @param entityType
100
+ * @returns an object that contains properties of all the collections
101
+ */
102
+ function getAllCollectionsMap(i18nScope, entityType) {
103
+ return {
104
+ appAndMap: {
105
+ key: "appAndMap",
106
+ label: `{{${i18nScope}collection.appsAndMaps:translate}}`,
107
+ targetEntity: entityType,
108
+ include: [],
109
+ scope: {
110
+ targetEntity: entityType,
111
+ filters: [
112
+ {
113
+ predicates: [
114
+ {
115
+ type: [...content_1.getFamilyTypes("app"), ...content_1.getFamilyTypes("map")],
116
+ },
117
+ ],
118
+ },
119
+ ],
120
+ },
121
+ },
122
+ dataset: {
123
+ key: "dataset",
124
+ label: `{{${i18nScope}collection.dataset:translate}}`,
125
+ targetEntity: entityType,
126
+ include: [],
127
+ scope: {
128
+ targetEntity: entityType,
129
+ filters: [{ predicates: [{ type: content_1.getFamilyTypes("dataset") }] }],
130
+ },
131
+ },
132
+ document: {
133
+ key: "document",
134
+ label: `{{${i18nScope}collection.document:translate}}`,
135
+ targetEntity: entityType,
136
+ include: [],
137
+ scope: {
138
+ targetEntity: entityType,
139
+ filters: [{ predicates: [{ type: content_1.getFamilyTypes("document") }] }],
140
+ },
141
+ },
142
+ feedback: {
143
+ key: "feedback",
144
+ label: `{{${i18nScope}collection.feedback:translate}}`,
145
+ targetEntity: entityType,
146
+ include: [],
147
+ scope: {
148
+ targetEntity: entityType,
149
+ filters: [{ predicates: [{ type: content_1.getFamilyTypes("feedback") }] }],
150
+ },
151
+ },
152
+ site: {
153
+ key: "site",
154
+ label: `{{${i18nScope}collection.sites:translate}}`,
155
+ targetEntity: entityType,
156
+ include: [],
157
+ scope: {
158
+ targetEntity: entityType,
159
+ filters: [
160
+ {
161
+ predicates: [
162
+ {
163
+ type: content_1.getFamilyTypes("site"),
164
+ },
165
+ ],
166
+ },
167
+ ],
168
+ },
169
+ },
170
+ template: {
171
+ key: "template",
172
+ label: `{{${i18nScope}collection.templates:translate}}`,
173
+ targetEntity: entityType,
174
+ include: [],
175
+ scope: {
176
+ targetEntity: entityType,
177
+ filters: [
178
+ {
179
+ predicates: [
180
+ {
181
+ type: content_1.getFamilyTypes("template"),
182
+ },
183
+ ],
184
+ },
185
+ ],
186
+ },
187
+ },
188
+ };
189
+ }
190
+ /**
191
+ * Get a list of collection names we want to use to build the default collections if no specific collection names are passed
192
+ * @returns a list of WellKnownCollection definition strings
193
+ */
194
+ function getDefaultCollectionNames() {
195
+ return ["appAndMap", "dataset", "document", "feedback", "site"];
196
+ }
197
+ /**
198
+ * Get a list of collections based on the entity type and an optional
199
+ * list of collection names, will return a list of default collections if none passed
200
+ * @param i18nScope Translation scope to be interpolated into the collections
201
+ * @param entityType
202
+ * @param collectionNames List of names of the requested collections, optional, if passed in,
203
+ * only those collections will be returned
204
+ * @returns A list of IHubCollection definition JSON objects
205
+ */
206
+ function getWellknownCollections(i18nScope, entityType, collectionNames) {
207
+ i18nScope = dotifyString(i18nScope);
208
+ const allCollectionsMap = getAllCollectionsMap(i18nScope, entityType);
209
+ const defaultCollectionNames = getDefaultCollectionNames();
210
+ // Return a list of collections from the passed collection names or
211
+ // return the default ones if not passed
212
+ const names = (collectionNames === null || collectionNames === void 0 ? void 0 : collectionNames.length) ? collectionNames
213
+ : defaultCollectionNames;
214
+ return names.reduce((accum, name) => {
215
+ if (allCollectionsMap[name]) {
216
+ accum.push(allCollectionsMap[name]);
217
+ }
218
+ return accum;
219
+ }, []);
220
+ }
221
+ exports.getWellknownCollections = getWellknownCollections;
222
+ /**
223
+ * Get a single collection based on the collection name and entity type
224
+ * @param i18nScope
225
+ * @param entityType
226
+ * @param collectionName Name of the collection requested
227
+ * @returns An IHubCollection definition JSON object
228
+ */
229
+ function getWellknownCollection(i18nScope, entityType, collectionName) {
230
+ i18nScope = dotifyString(i18nScope);
231
+ return getAllCollectionsMap(i18nScope, entityType)[collectionName];
232
+ }
233
+ exports.getWellknownCollection = getWellknownCollection;
234
+ //# sourceMappingURL=wellKnownCatalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wellKnownCatalog.js","sourceRoot":"","sources":["../../../src/search/wellKnownCatalog.ts"],"names":[],"mappings":";;;AACA,wCAA4C;AAoC5C;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,SAAiB;IACrC,IAAI,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QAC5C,OAAO,GAAG,SAAS,GAAG,CAAC;KACxB;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC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PD,wDAOC"}
@@ -6,3 +6,4 @@ export * from "./fetchCatalog";
6
6
  export * from "./hubSearch";
7
7
  export * from "./Catalog";
8
8
  export * from "./Collection";
9
+ export * from "./wellKnownCatalog";
@@ -0,0 +1,50 @@
1
+ import { IUser } from "@esri/arcgis-rest-types";
2
+ import { HubFamily } from "../types";
3
+ import { EntityType, IHubCatalog, IHubCollection } from "./types";
4
+ /**
5
+ * This is used to determine what IHubCatalog definition JSON object
6
+ * can be created
7
+ */
8
+ export declare type WellKnownCatalog = "myContent" | "myGroup" | "favorites" | "organization" | "world";
9
+ /**
10
+ * This is used to determine what IHubCollection definition JSON object
11
+ * can be created. We use HubFamily here to define most of the collections
12
+ * to ensure consistency
13
+ */
14
+ export declare type WellKnownCollection = Exclude<HubFamily, "app" | "map"> | "appAndMap" | "solution";
15
+ /**
16
+ * A list of optional arguments to pass into getWellKnownCatalog
17
+ * user is the owner of the entity
18
+ * collectionNames is a list of names of the collections, only those collections
19
+ * in the catalog will be returned
20
+ */
21
+ export interface IGetWellKnownCatalogOptions {
22
+ user?: IUser;
23
+ collectionNames?: WellKnownCollection[];
24
+ }
25
+ /** Get a single catalog based on the name, entity type and optional requests
26
+ * @param i18nScope Translation scope to be interpolated into the catalog
27
+ * @param name Name of the catalog requested
28
+ * @param entityType
29
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
30
+ * @returns An IHubCatalog definition JSON object
31
+ */
32
+ export declare function getWellKnownCatalog(i18nScope: string, name: WellKnownCatalog, entityType: EntityType, options?: IGetWellKnownCatalogOptions): IHubCatalog;
33
+ /**
34
+ * Get a list of collections based on the entity type and an optional
35
+ * list of collection names, will return a list of default collections if none passed
36
+ * @param i18nScope Translation scope to be interpolated into the collections
37
+ * @param entityType
38
+ * @param collectionNames List of names of the requested collections, optional, if passed in,
39
+ * only those collections will be returned
40
+ * @returns A list of IHubCollection definition JSON objects
41
+ */
42
+ export declare function getWellknownCollections(i18nScope: string, entityType: EntityType, collectionNames?: WellKnownCollection[]): IHubCollection[];
43
+ /**
44
+ * Get a single collection based on the collection name and entity type
45
+ * @param i18nScope
46
+ * @param entityType
47
+ * @param collectionName Name of the collection requested
48
+ * @returns An IHubCollection definition JSON object
49
+ */
50
+ export declare function getWellknownCollection(i18nScope: string, entityType: EntityType, collectionName: WellKnownCollection): IHubCollection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/hub-common",
3
- "version": "12.4.0",
3
+ "version": "12.5.0",
4
4
  "description": "Common TypeScript types and utility functions for @esri/hub.js.",
5
5
  "main": "dist/node/index.js",
6
6
  "module": "dist/esm/index.js",