@esri/hub-common 12.4.0 → 12.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,226 @@
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
+ return i18nScope && i18nScope.slice(-1) !== "." ? `${i18nScope}.` : "";
11
+ }
12
+ /** Get a single catalog based on the name, entity type and optional requests
13
+ * @param i18nScope Translation scope to be interpolated into the catalog
14
+ * @param name Name of the catalog requested
15
+ * @param entityType
16
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
17
+ * @returns An IHubCatalog definition JSON object
18
+ */
19
+ export function getWellKnownCatalog(i18nScope, name, entityType, options) {
20
+ switch (entityType) {
21
+ case "item":
22
+ return getWellknownItemCatalog(i18nScope, name, options);
23
+ /* Add other entity handlers here, e.g. getWellknownEventCatalog */
24
+ default:
25
+ throw new Error(`Wellknown catalog not implemented for "${entityType}"`);
26
+ }
27
+ }
28
+ /**
29
+ * Build an IHubCatalog definition JSON object based on the
30
+ * catalog name, predicates and collections we want to use for each catalog
31
+ * @param i18nScope
32
+ * @param name Catalog name
33
+ * @param predicates Predicates for the catalog
34
+ * @param collections Collections to include for the catalog
35
+ * @returns An IHubCatalog definition JSON object
36
+ */
37
+ function buildCatalog(i18nScope, name, predicates, collections) {
38
+ return {
39
+ schemaVersion: 1,
40
+ title: `{{${i18nScope}catalog.${name}:translate}}`,
41
+ scopes: {
42
+ item: {
43
+ targetEntity: "item",
44
+ filters: [{ predicates }],
45
+ },
46
+ },
47
+ collections,
48
+ };
49
+ }
50
+ /**
51
+ * Check if user is available in the passed options, throw an error if not
52
+ * @param name name of the catalog
53
+ * @param options Options that contains user
54
+ */
55
+ function checkUser(name, options) {
56
+ if (!options || !options.user) {
57
+ throw new Error(`User needed to get "${name}" catalog`);
58
+ }
59
+ }
60
+ /**
61
+ * Get an ITEM catalog based on the name and optional requests
62
+ * @param i18nScope Translation scope to be interpolated into the catalog
63
+ * @param name Name of the catalog requested
64
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
65
+ * @returns An ITEM IHubCatalog definition JSON object
66
+ */
67
+ function getWellknownItemCatalog(i18nScope, name, options) {
68
+ i18nScope = dotifyString(i18nScope);
69
+ let catalog;
70
+ const collections = getWellknownCollections(i18nScope, "item", options === null || options === void 0 ? void 0 : options.collectionNames);
71
+ switch (name) {
72
+ case "myContent":
73
+ checkUser(name, options);
74
+ catalog = buildCatalog(i18nScope, name, [{ owner: options.user.username }], collections);
75
+ break;
76
+ case "favorites":
77
+ checkUser(name, options);
78
+ catalog = buildCatalog(i18nScope, name, [{ group: options.user.favGroupId }], collections);
79
+ break;
80
+ case "organization":
81
+ checkUser(name, options);
82
+ catalog = buildCatalog(i18nScope, name, [{ orgid: options.user.orgId, access: "org" }], collections);
83
+ break;
84
+ case "world":
85
+ catalog = buildCatalog(i18nScope, name, [{ access: "public" }], collections);
86
+ break;
87
+ }
88
+ return catalog;
89
+ }
90
+ /**
91
+ * Get a complete collections map to use to build a collections list
92
+ * @param i18nScope
93
+ * @param entityType
94
+ * @returns an object that contains properties of all the collections
95
+ */
96
+ function getAllCollectionsMap(i18nScope, entityType) {
97
+ return {
98
+ appAndMap: {
99
+ key: "appAndMap",
100
+ label: `{{${i18nScope}collection.appsAndMaps:translate}}`,
101
+ targetEntity: entityType,
102
+ include: [],
103
+ scope: {
104
+ targetEntity: entityType,
105
+ filters: [
106
+ {
107
+ predicates: [
108
+ {
109
+ type: [...getFamilyTypes("app"), ...getFamilyTypes("map")],
110
+ },
111
+ ],
112
+ },
113
+ ],
114
+ },
115
+ },
116
+ dataset: {
117
+ key: "dataset",
118
+ label: `{{${i18nScope}collection.dataset:translate}}`,
119
+ targetEntity: entityType,
120
+ include: [],
121
+ scope: {
122
+ targetEntity: entityType,
123
+ filters: [{ predicates: [{ type: getFamilyTypes("dataset") }] }],
124
+ },
125
+ },
126
+ document: {
127
+ key: "document",
128
+ label: `{{${i18nScope}collection.documents:translate}}`,
129
+ targetEntity: entityType,
130
+ include: [],
131
+ scope: {
132
+ targetEntity: entityType,
133
+ filters: [{ predicates: [{ type: getFamilyTypes("document") }] }],
134
+ },
135
+ },
136
+ feedback: {
137
+ key: "feedback",
138
+ label: `{{${i18nScope}collection.feedback:translate}}`,
139
+ targetEntity: entityType,
140
+ include: [],
141
+ scope: {
142
+ targetEntity: entityType,
143
+ filters: [{ predicates: [{ type: getFamilyTypes("feedback") }] }],
144
+ },
145
+ },
146
+ site: {
147
+ key: "site",
148
+ label: `{{${i18nScope}collection.sites:translate}}`,
149
+ targetEntity: entityType,
150
+ include: [],
151
+ scope: {
152
+ targetEntity: entityType,
153
+ filters: [
154
+ {
155
+ predicates: [
156
+ {
157
+ type: getFamilyTypes("site"),
158
+ },
159
+ ],
160
+ },
161
+ ],
162
+ },
163
+ },
164
+ template: {
165
+ key: "template",
166
+ label: `{{${i18nScope}collection.templates:translate}}`,
167
+ targetEntity: entityType,
168
+ include: [],
169
+ scope: {
170
+ targetEntity: entityType,
171
+ filters: [
172
+ {
173
+ predicates: [
174
+ {
175
+ type: getFamilyTypes("template"),
176
+ },
177
+ ],
178
+ },
179
+ ],
180
+ },
181
+ },
182
+ };
183
+ }
184
+ /**
185
+ * Get a list of collection names we want to use to build the default collections if no specific collection names are passed
186
+ * @returns a list of WellKnownCollection definition strings
187
+ */
188
+ function getDefaultCollectionNames() {
189
+ return ["appAndMap", "dataset", "document", "feedback", "site"];
190
+ }
191
+ /**
192
+ * Get a list of collections based on the entity type and an optional
193
+ * list of collection names, will return a list of default collections if none passed
194
+ * @param i18nScope Translation scope to be interpolated into the collections
195
+ * @param entityType
196
+ * @param collectionNames List of names of the requested collections, optional, if passed in,
197
+ * only those collections will be returned
198
+ * @returns A list of IHubCollection definition JSON objects
199
+ */
200
+ export function getWellknownCollections(i18nScope, entityType, collectionNames) {
201
+ i18nScope = dotifyString(i18nScope);
202
+ const allCollectionsMap = getAllCollectionsMap(i18nScope, entityType);
203
+ const defaultCollectionNames = getDefaultCollectionNames();
204
+ // Return a list of collections from the passed collection names or
205
+ // return the default ones if not passed
206
+ const names = (collectionNames === null || collectionNames === void 0 ? void 0 : collectionNames.length) ? collectionNames
207
+ : defaultCollectionNames;
208
+ return names.reduce((accum, name) => {
209
+ if (allCollectionsMap[name]) {
210
+ accum.push(allCollectionsMap[name]);
211
+ }
212
+ return accum;
213
+ }, []);
214
+ }
215
+ /**
216
+ * Get a single collection based on the collection name and entity type
217
+ * @param i18nScope
218
+ * @param entityType
219
+ * @param collectionName Name of the collection requested
220
+ * @returns An IHubCollection definition JSON object
221
+ */
222
+ export function getWellknownCollection(i18nScope, entityType, collectionName) {
223
+ i18nScope = dotifyString(i18nScope);
224
+ return getAllCollectionsMap(i18nScope, entityType)[collectionName];
225
+ }
226
+ //# 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,OAAO,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACzE,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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C;IACxC,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,232 @@
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
+ return i18nScope && i18nScope.slice(-1) !== "." ? `${i18nScope}.` : "";
14
+ }
15
+ /** Get a single catalog based on the name, entity type and optional requests
16
+ * @param i18nScope Translation scope to be interpolated into the catalog
17
+ * @param name Name of the catalog requested
18
+ * @param entityType
19
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
20
+ * @returns An IHubCatalog definition JSON object
21
+ */
22
+ function getWellKnownCatalog(i18nScope, name, entityType, options) {
23
+ switch (entityType) {
24
+ case "item":
25
+ return getWellknownItemCatalog(i18nScope, name, options);
26
+ /* Add other entity handlers here, e.g. getWellknownEventCatalog */
27
+ default:
28
+ throw new Error(`Wellknown catalog not implemented for "${entityType}"`);
29
+ }
30
+ }
31
+ exports.getWellKnownCatalog = getWellKnownCatalog;
32
+ /**
33
+ * Build an IHubCatalog definition JSON object based on the
34
+ * catalog name, predicates and collections we want to use for each catalog
35
+ * @param i18nScope
36
+ * @param name Catalog name
37
+ * @param predicates Predicates for the catalog
38
+ * @param collections Collections to include for the catalog
39
+ * @returns An IHubCatalog definition JSON object
40
+ */
41
+ function buildCatalog(i18nScope, name, predicates, collections) {
42
+ return {
43
+ schemaVersion: 1,
44
+ title: `{{${i18nScope}catalog.${name}:translate}}`,
45
+ scopes: {
46
+ item: {
47
+ targetEntity: "item",
48
+ filters: [{ predicates }],
49
+ },
50
+ },
51
+ collections,
52
+ };
53
+ }
54
+ /**
55
+ * Check if user is available in the passed options, throw an error if not
56
+ * @param name name of the catalog
57
+ * @param options Options that contains user
58
+ */
59
+ function checkUser(name, options) {
60
+ if (!options || !options.user) {
61
+ throw new Error(`User needed to get "${name}" catalog`);
62
+ }
63
+ }
64
+ /**
65
+ * Get an ITEM catalog based on the name and optional requests
66
+ * @param i18nScope Translation scope to be interpolated into the catalog
67
+ * @param name Name of the catalog requested
68
+ * @param options An opitional IGetWellKnownCatalogOptions definition JSON object
69
+ * @returns An ITEM IHubCatalog definition JSON object
70
+ */
71
+ function getWellknownItemCatalog(i18nScope, name, options) {
72
+ i18nScope = dotifyString(i18nScope);
73
+ let catalog;
74
+ const collections = getWellknownCollections(i18nScope, "item", options === null || options === void 0 ? void 0 : options.collectionNames);
75
+ switch (name) {
76
+ case "myContent":
77
+ checkUser(name, options);
78
+ catalog = buildCatalog(i18nScope, name, [{ owner: options.user.username }], collections);
79
+ break;
80
+ case "favorites":
81
+ checkUser(name, options);
82
+ catalog = buildCatalog(i18nScope, name, [{ group: options.user.favGroupId }], collections);
83
+ break;
84
+ case "organization":
85
+ checkUser(name, options);
86
+ catalog = buildCatalog(i18nScope, name, [{ orgid: options.user.orgId, access: "org" }], collections);
87
+ break;
88
+ case "world":
89
+ catalog = buildCatalog(i18nScope, name, [{ access: "public" }], collections);
90
+ break;
91
+ }
92
+ return catalog;
93
+ }
94
+ /**
95
+ * Get a complete collections map to use to build a collections list
96
+ * @param i18nScope
97
+ * @param entityType
98
+ * @returns an object that contains properties of all the collections
99
+ */
100
+ function getAllCollectionsMap(i18nScope, entityType) {
101
+ return {
102
+ appAndMap: {
103
+ key: "appAndMap",
104
+ label: `{{${i18nScope}collection.appsAndMaps:translate}}`,
105
+ targetEntity: entityType,
106
+ include: [],
107
+ scope: {
108
+ targetEntity: entityType,
109
+ filters: [
110
+ {
111
+ predicates: [
112
+ {
113
+ type: [...content_1.getFamilyTypes("app"), ...content_1.getFamilyTypes("map")],
114
+ },
115
+ ],
116
+ },
117
+ ],
118
+ },
119
+ },
120
+ dataset: {
121
+ key: "dataset",
122
+ label: `{{${i18nScope}collection.dataset:translate}}`,
123
+ targetEntity: entityType,
124
+ include: [],
125
+ scope: {
126
+ targetEntity: entityType,
127
+ filters: [{ predicates: [{ type: content_1.getFamilyTypes("dataset") }] }],
128
+ },
129
+ },
130
+ document: {
131
+ key: "document",
132
+ label: `{{${i18nScope}collection.documents:translate}}`,
133
+ targetEntity: entityType,
134
+ include: [],
135
+ scope: {
136
+ targetEntity: entityType,
137
+ filters: [{ predicates: [{ type: content_1.getFamilyTypes("document") }] }],
138
+ },
139
+ },
140
+ feedback: {
141
+ key: "feedback",
142
+ label: `{{${i18nScope}collection.feedback:translate}}`,
143
+ targetEntity: entityType,
144
+ include: [],
145
+ scope: {
146
+ targetEntity: entityType,
147
+ filters: [{ predicates: [{ type: content_1.getFamilyTypes("feedback") }] }],
148
+ },
149
+ },
150
+ site: {
151
+ key: "site",
152
+ label: `{{${i18nScope}collection.sites:translate}}`,
153
+ targetEntity: entityType,
154
+ include: [],
155
+ scope: {
156
+ targetEntity: entityType,
157
+ filters: [
158
+ {
159
+ predicates: [
160
+ {
161
+ type: content_1.getFamilyTypes("site"),
162
+ },
163
+ ],
164
+ },
165
+ ],
166
+ },
167
+ },
168
+ template: {
169
+ key: "template",
170
+ label: `{{${i18nScope}collection.templates:translate}}`,
171
+ targetEntity: entityType,
172
+ include: [],
173
+ scope: {
174
+ targetEntity: entityType,
175
+ filters: [
176
+ {
177
+ predicates: [
178
+ {
179
+ type: content_1.getFamilyTypes("template"),
180
+ },
181
+ ],
182
+ },
183
+ ],
184
+ },
185
+ },
186
+ };
187
+ }
188
+ /**
189
+ * Get a list of collection names we want to use to build the default collections if no specific collection names are passed
190
+ * @returns a list of WellKnownCollection definition strings
191
+ */
192
+ function getDefaultCollectionNames() {
193
+ return ["appAndMap", "dataset", "document", "feedback", "site"];
194
+ }
195
+ /**
196
+ * Get a list of collections based on the entity type and an optional
197
+ * list of collection names, will return a list of default collections if none passed
198
+ * @param i18nScope Translation scope to be interpolated into the collections
199
+ * @param entityType
200
+ * @param collectionNames List of names of the requested collections, optional, if passed in,
201
+ * only those collections will be returned
202
+ * @returns A list of IHubCollection definition JSON objects
203
+ */
204
+ function getWellknownCollections(i18nScope, entityType, collectionNames) {
205
+ i18nScope = dotifyString(i18nScope);
206
+ const allCollectionsMap = getAllCollectionsMap(i18nScope, entityType);
207
+ const defaultCollectionNames = getDefaultCollectionNames();
208
+ // Return a list of collections from the passed collection names or
209
+ // return the default ones if not passed
210
+ const names = (collectionNames === null || collectionNames === void 0 ? void 0 : collectionNames.length) ? collectionNames
211
+ : defaultCollectionNames;
212
+ return names.reduce((accum, name) => {
213
+ if (allCollectionsMap[name]) {
214
+ accum.push(allCollectionsMap[name]);
215
+ }
216
+ return accum;
217
+ }, []);
218
+ }
219
+ exports.getWellknownCollections = getWellknownCollections;
220
+ /**
221
+ * Get a single collection based on the collection name and entity type
222
+ * @param i18nScope
223
+ * @param entityType
224
+ * @param collectionName Name of the collection requested
225
+ * @returns An IHubCollection definition JSON object
226
+ */
227
+ function getWellknownCollection(i18nScope, entityType, collectionName) {
228
+ i18nScope = dotifyString(i18nScope);
229
+ return getAllCollectionsMap(i18nScope, entityType)[collectionName];
230
+ }
231
+ exports.getWellknownCollection = getWellknownCollection;
232
+ //# 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,OAAO,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACzE,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,m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rE,CAAC;AAPD,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.1",
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",