@esri/hub-common 9.21.2 → 9.22.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.
Files changed (61) hide show
  1. package/dist/es2017/content/_fetch.js +87 -0
  2. package/dist/es2017/content/_fetch.js.map +1 -0
  3. package/dist/es2017/content/_internal.js +75 -3
  4. package/dist/es2017/content/_internal.js.map +1 -1
  5. package/dist/es2017/content/compose.js +18 -10
  6. package/dist/es2017/content/compose.js.map +1 -1
  7. package/dist/es2017/content/fetch.js +78 -0
  8. package/dist/es2017/content/fetch.js.map +1 -0
  9. package/dist/es2017/content/index.js +9 -80
  10. package/dist/es2017/content/index.js.map +1 -1
  11. package/dist/es2017/content/slugs.js +63 -0
  12. package/dist/es2017/content/slugs.js.map +1 -0
  13. package/dist/es2017/content/types.js +1 -0
  14. package/dist/es2017/content/types.js.map +1 -0
  15. package/dist/es2017/items/_enrichments.js +176 -0
  16. package/dist/es2017/items/_enrichments.js.map +1 -0
  17. package/dist/esm/content/_fetch.js +102 -0
  18. package/dist/esm/content/_fetch.js.map +1 -0
  19. package/dist/esm/content/_internal.js +75 -3
  20. package/dist/esm/content/_internal.js.map +1 -1
  21. package/dist/esm/content/compose.js +18 -10
  22. package/dist/esm/content/compose.js.map +1 -1
  23. package/dist/esm/content/fetch.js +103 -0
  24. package/dist/esm/content/fetch.js.map +1 -0
  25. package/dist/esm/content/index.js +9 -80
  26. package/dist/esm/content/index.js.map +1 -1
  27. package/dist/esm/content/slugs.js +63 -0
  28. package/dist/esm/content/slugs.js.map +1 -0
  29. package/dist/esm/content/types.js +1 -0
  30. package/dist/esm/content/types.js.map +1 -0
  31. package/dist/esm/items/_enrichments.js +177 -0
  32. package/dist/esm/items/_enrichments.js.map +1 -0
  33. package/dist/node/content/_fetch.js +90 -0
  34. package/dist/node/content/_fetch.js.map +1 -0
  35. package/dist/node/content/_internal.js +76 -4
  36. package/dist/node/content/_internal.js.map +1 -1
  37. package/dist/node/content/compose.js +17 -9
  38. package/dist/node/content/compose.js.map +1 -1
  39. package/dist/node/content/fetch.js +81 -0
  40. package/dist/node/content/fetch.js.map +1 -0
  41. package/dist/node/content/index.js +11 -86
  42. package/dist/node/content/index.js.map +1 -1
  43. package/dist/node/content/slugs.js +70 -0
  44. package/dist/node/content/slugs.js.map +1 -0
  45. package/dist/node/content/types.js +3 -0
  46. package/dist/node/content/types.js.map +1 -0
  47. package/dist/node/items/_enrichments.js +179 -0
  48. package/dist/node/items/_enrichments.js.map +1 -0
  49. package/dist/types/content/_fetch.d.ts +61 -0
  50. package/dist/types/content/_internal.d.ts +76 -0
  51. package/dist/types/content/compose.d.ts +11 -0
  52. package/dist/types/content/fetch.d.ts +23 -0
  53. package/dist/types/content/index.d.ts +4 -41
  54. package/dist/types/content/slugs.d.ts +34 -0
  55. package/dist/types/content/types.d.ts +7 -0
  56. package/dist/types/items/_enrichments.d.ts +24 -0
  57. package/dist/umd/common.umd.js +2082 -850
  58. package/dist/umd/common.umd.js.map +1 -1
  59. package/dist/umd/common.umd.min.js +1 -1
  60. package/dist/umd/common.umd.min.js.map +1 -1
  61. package/package.json +2 -1
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchItemEnrichments = void 0;
4
+ const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
5
+ const arcgis_rest_feature_layer_1 = require("@esri/arcgis-rest-feature-layer");
6
+ const utils_1 = require("../utils");
7
+ const OperationStack_1 = require("../OperationStack");
8
+ // TODO: move these functions here under /items
9
+ const arcgis_rest_portal_2 = require("@esri/arcgis-rest-portal");
10
+ const fast_xml_parser_1 = require("fast-xml-parser");
11
+ function parseMetadataXml(metadataXml) {
12
+ const opts = {
13
+ // options for fastXmlParser to read tag attrs
14
+ ignoreAttributes: false,
15
+ attributeNamePrefix: "@_",
16
+ textNodeName: "#value",
17
+ };
18
+ return fast_xml_parser_1.parse(metadataXml, opts);
19
+ }
20
+ /**
21
+ * Fetch an [item's metadata](https://doc.arcgis.com/en/arcgis-online/manage-data/metadata.htm) from a portal
22
+ * and parse and return it as JSON
23
+ * @param id item id
24
+ * @param requestOptions
25
+ */
26
+ function fetchContentMetadata(id, requestOptions) {
27
+ return arcgis_rest_portal_2.getItemMetadata(id, requestOptions)
28
+ .then((metadataXml) => parseMetadataXml(metadataXml))
29
+ .catch(() => {
30
+ // many items don't have metadata and the request will 404
31
+ // in these cases we don't want to treat it as an error
32
+ // content.metadata === null signals to consumers that
33
+ // we attempted to fetch the metadata, but it doesn't exist
34
+ // TODO: we should probably still throw the error if it's not a 404
35
+ return null;
36
+ });
37
+ }
38
+ const enrichGroupIds = (input) => {
39
+ const { data, stack, requestOptions } = input;
40
+ const opId = stack.start("enrichGroupIds");
41
+ return arcgis_rest_portal_1.getItemGroups(data.item.id, requestOptions)
42
+ .then((response) => {
43
+ const { admin, member, other } = response;
44
+ const groupIds = [...admin, ...member, ...other].map((group) => group.id);
45
+ stack.finish(opId);
46
+ return {
47
+ data: Object.assign(Object.assign({}, data), { groupIds }),
48
+ stack,
49
+ requestOptions,
50
+ };
51
+ })
52
+ .catch((error) => handleEnrichmentError(error, input, opId));
53
+ };
54
+ const enrichMetadata = (input) => {
55
+ const { data, stack, requestOptions } = input;
56
+ const opId = stack.start("enrichMetadata");
57
+ return fetchContentMetadata(data.item.id, requestOptions).then((metadata) => {
58
+ stack.finish(opId);
59
+ return {
60
+ data: Object.assign(Object.assign({}, data), { metadata }),
61
+ stack,
62
+ requestOptions,
63
+ };
64
+ });
65
+ // TODO: currently fetchContentMetadata will never throw, but
66
+ // if we update it to throw for non-404 errors, need to uncomment this:
67
+ // .catch((error) => handleEnrichmentError(error, input, opId));
68
+ };
69
+ const enrichOwnerUser = (input) => {
70
+ const { data, stack, requestOptions } = input;
71
+ const opId = stack.start("enrichOwner");
72
+ // w/o the : any here, I get a compile error about
73
+ // .authentication being incompatible w/ UserSession
74
+ const options = Object.assign({ username: data.item.owner }, requestOptions);
75
+ return arcgis_rest_portal_1.getUser(options)
76
+ .then((ownerUser) => {
77
+ stack.finish(opId);
78
+ return {
79
+ data: Object.assign(Object.assign({}, data), { ownerUser }),
80
+ stack,
81
+ requestOptions,
82
+ };
83
+ })
84
+ .catch((error) => handleEnrichmentError(error, input, opId));
85
+ };
86
+ const enrichData = (input) => {
87
+ const { data, stack, requestOptions } = input;
88
+ const opId = stack.start("enrichData");
89
+ return arcgis_rest_portal_1.getItemData(data.item.id, requestOptions)
90
+ .then((itemData) => {
91
+ stack.finish(opId);
92
+ return { data: Object.assign(Object.assign({}, data), { data: itemData }), stack, requestOptions };
93
+ })
94
+ .catch((error) => handleEnrichmentError(error, input, opId));
95
+ };
96
+ const enrichServer = (input) => {
97
+ const { data, stack, requestOptions } = input;
98
+ const opId = stack.start("enrichServer");
99
+ const url = data.item.url;
100
+ const options = Object.assign(Object.assign({}, requestOptions), { url });
101
+ return arcgis_rest_feature_layer_1.getService(options)
102
+ .then((server) => {
103
+ stack.finish(opId);
104
+ return { data: Object.assign(Object.assign({}, data), { server }), stack, requestOptions };
105
+ })
106
+ .catch((error) => handleEnrichmentError(error, input, opId));
107
+ };
108
+ const enrichLayers = (input) => {
109
+ const { data, stack, requestOptions } = input;
110
+ const opId = stack.start("enrichLayers");
111
+ const url = data.item.url;
112
+ const options = Object.assign(Object.assign({}, requestOptions), { url });
113
+ return (arcgis_rest_feature_layer_1.getAllLayersAndTables(options)
114
+ // merge layers and tables into a single array
115
+ // and filter out any group layers
116
+ .then((response) => {
117
+ const merged = [...response.layers, ...response.tables];
118
+ return merged.filter((layer) => layer.type !== "Group Layer");
119
+ })
120
+ .then((layers) => {
121
+ stack.finish(opId);
122
+ return { data: Object.assign(Object.assign({}, data), { layers }), stack, requestOptions };
123
+ })
124
+ .catch((error) => handleEnrichmentError(error, input, opId)));
125
+ };
126
+ // add the error to the content.errors,
127
+ // log current stack operation as finished with an error
128
+ // and return output that can be piped into the next operation
129
+ const handleEnrichmentError = (error, input, opId) => {
130
+ const { data, stack, requestOptions } = input;
131
+ stack.finish(opId, { error });
132
+ const message = typeof error === "string"
133
+ ? /* istanbul ignore next our tests only throw Error objects */
134
+ error
135
+ : error.message;
136
+ const errors = data.errors || [];
137
+ errors.push({
138
+ // NOTE: for now we just return the message and type "Other"
139
+ // but we could later introspect for HTTP or AGO errors
140
+ // and/or return the status code if available
141
+ type: "Other",
142
+ message,
143
+ });
144
+ return { data: Object.assign(Object.assign({}, data), { errors }), stack, requestOptions };
145
+ };
146
+ const enrichmentOperations = {
147
+ groupIds: enrichGroupIds,
148
+ metadata: enrichMetadata,
149
+ ownerUser: enrichOwnerUser,
150
+ // TOOD: org
151
+ data: enrichData,
152
+ server: enrichServer,
153
+ layers: enrichLayers,
154
+ };
155
+ /**
156
+ * Fetch enrichments for an item
157
+ * @param item
158
+ * @param enrichments the list of enrichments to fetch
159
+ * @param requestOptions
160
+ * @returns an object with the item and enrichments
161
+ * @private
162
+ */
163
+ exports.fetchItemEnrichments = (item, enrichments, requestOptions) => {
164
+ // create a pipeline of enrichment operations
165
+ const operations = enrichments.reduce((ops, enrichment) => {
166
+ const operation = enrichmentOperations[enrichment];
167
+ // only include the enrichments that we know how to fetch
168
+ operation && ops.push(operation);
169
+ return ops;
170
+ }, []);
171
+ const pipeline = utils_1.createOperationPipeline(operations);
172
+ // execute pipeline and return the item and enrichments
173
+ return pipeline({
174
+ data: { item },
175
+ stack: new OperationStack_1.default(),
176
+ requestOptions,
177
+ }).then((output) => output.data);
178
+ };
179
+ //# sourceMappingURL=_enrichments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_enrichments.js","sourceRoot":"","sources":["../../../src/items/_enrichments.ts"],"names":[],"mappings":";;;AAAA,iEAKkC;AAClC,+EAGyC;AAGzC,oCAA8D;AAC9D,sDAA+C;AAC/C,+CAA+C;AAC/C,iEAA2D;AAC3D,qDAAwC;AAoBxC,SAAS,gBAAgB,CAAC,WAAmB;IAC3C,MAAM,IAAI,GAAG;QACX,8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vD,OAAO,QAAQ,CAAC;QACd,IAAI,EAAE,EAAE,IAAI,EAAE;QACd,KAAK,EAAE,IAAI,wBAAc,EAAE;QAC3B,cAAc;KACf,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { IItem } from "@esri/arcgis-rest-portal";
2
+ import { BBox } from "..";
3
+ import { ItemOrServerEnrichment } from "../items/_enrichments";
4
+ import { IHubRequestOptions, IHubGeography } from "../types";
5
+ /**
6
+ * get the default list of enrichments to fetch for content
7
+ * @param item
8
+ * @returns the default list of enrichments to fetch for content
9
+ * @private
10
+ */
11
+ export declare const getContentEnrichments: (item: IItem) => ItemOrServerEnrichment[];
12
+ /**
13
+ * The extent returned by the Hub API
14
+ */
15
+ export interface IHubExtent {
16
+ coordinates?: BBox;
17
+ }
18
+ /**
19
+ * The set of enrichments that we fetch from the Hub API
20
+ */
21
+ export interface IDatasetEnrichments {
22
+ itemId: string;
23
+ layerId?: number;
24
+ slug?: string;
25
+ /**
26
+ * boundary will default to the item extent
27
+ * but can be overwritten by enrichments from the Hub API (inline)
28
+ * or fetched from a location such as /resources/boundary.json
29
+ */
30
+ boundary?: IHubGeography;
31
+ /**
32
+ * Either the item's extent, or the item's
33
+ * layer or server's extent converted to a lat/lng coordinate pair
34
+ */
35
+ extent?: IHubExtent;
36
+ /**
37
+ * The appropriate summary to show for the item, coming from either
38
+ * the item's data (for pages or initiatives) or the item's description
39
+ */
40
+ searchDescription?: string;
41
+ /**
42
+ * Pre-computed field statistics (min, max, average, etc)
43
+ */
44
+ statistics?: any;
45
+ }
46
+ /**
47
+ * fetch enrichment from the Hub API by slug
48
+ * @param slug
49
+ * @param requestOptions
50
+ * @returns enrichments from the Hub API (slug, boundary, statistic, etc)
51
+ * @private
52
+ */
53
+ export declare const fetchHubEnrichmentsBySlug: (slug: string, requestOptions: IHubRequestOptions) => Promise<IDatasetEnrichments>;
54
+ /**
55
+ * fetch enrichment from the Hub API by id
56
+ * @param slug
57
+ * @param requestOptions
58
+ * @returns enrichments from the Hub API (slug, boundary, statistic, etc)
59
+ * @private
60
+ */
61
+ export declare const fetchHubEnrichmentsById: (hubId: string, requestOptions: IHubRequestOptions) => Promise<IDatasetEnrichments>;
@@ -19,6 +19,7 @@ import { IHubAdditionalResource } from "../core/types/IHubAdditionalResource";
19
19
  * @param content original content
20
20
  * @param boundary boundary provenance
21
21
  * @returns
22
+ * @private
22
23
  */
23
24
  export declare const setContentBoundary: (content: IHubContent, boundary: GeographyProvenance) => {
24
25
  boundary: IHubGeography;
@@ -109,18 +110,60 @@ export declare const setContentBoundary: (content: IHubContent, boundary: Geogra
109
110
  spatialReference?: ISpatialReference;
110
111
  properties?: any;
111
112
  };
113
+ /**
114
+ * get a content's boundary based on the item's boundary property
115
+ * @param item
116
+ * @returns
117
+ * @private
118
+ */
112
119
  export declare const getContentBoundary: (item: IItem) => IHubGeography;
120
+ /**
121
+ * Determine if we are in an enterprise environment
122
+ * NOTE: when no request options are provided, the underlying
123
+ * request functions assume that we are online in production
124
+ * so we only want use enterprise logic if isPortal is explicitly defined
125
+ * @param requestOptions
126
+ * @returns
127
+ * @private
128
+ */
113
129
  export declare const isPortal: (requestOptions?: IHubRequestOptions) => boolean;
130
+ /**
131
+ * Determine if we can use the Hub API for an item, i.e.
132
+ * the item is public and we are not in an enterprise environment
133
+ * @param item
134
+ * @param requestOptions
135
+ * @returns
136
+ * @private
137
+ */
138
+ export declare const canUseHubApiForItem: (item: IItem, requestOptions?: IHubRequestOptions) => boolean;
114
139
  /**
115
140
  * Returns whether or not an item is a proxied csv
116
141
  *
117
142
  * @param item
118
143
  * @param requestOptions Hub Request Options (including whether we're in portal)
119
144
  * @returns
145
+ * @private
120
146
  */
121
147
  export declare const isProxiedCSV: (item: IItem, requestOptions?: IHubRequestOptions) => boolean;
148
+ /**
149
+ * Get the relative URL to use for the item in a hub site
150
+ * @param type
151
+ * @param identifier
152
+ * @param typeKeywords
153
+ * @returns
154
+ * @private
155
+ */
122
156
  export declare const getHubRelativeUrl: (type: string, identifier: string, typeKeywords?: string[]) => string;
157
+ /**
158
+ * Is this content type a page?
159
+ * @param type
160
+ * @returns
161
+ * @private
162
+ */
123
163
  export declare const isPageType: (type: string) => boolean;
164
+ /**
165
+ * well known paths to formal metadata values
166
+ */
124
167
  export interface IMetadataPaths {
125
168
  updateFrequency: string;
126
169
  metadataUpdateFrequency: string;
@@ -129,8 +172,24 @@ export interface IMetadataPaths {
129
172
  pubDate: string;
130
173
  createDate: string;
131
174
  }
175
+ /**
176
+ * Get the path to a well known metadata value
177
+ * @param identifier identifier for well known metadata value
178
+ * @returns path to be used like get(metadata, path)
179
+ * @private
180
+ */
132
181
  export declare function getMetadataPath(identifier: keyof IMetadataPaths): string;
182
+ /**
183
+ * Get a well known value from metadata
184
+ * @param metadata
185
+ * @param identifier identifier for well known metadata value
186
+ * @returns
187
+ * @private
188
+ */
133
189
  export declare function getValueFromMetadata(metadata: any, identifier: keyof IMetadataPaths): any;
190
+ /**
191
+ * Date precisions
192
+ */
134
193
  export declare enum DatePrecision {
135
194
  Year = "year",
136
195
  Month = "month",
@@ -147,12 +206,26 @@ export declare enum DatePrecision {
147
206
  *
148
207
  * @param {string} isoString
149
208
  * @return { date: Date, precision: DatePrecision }
209
+ * @private
150
210
  */
151
211
  export declare function parseISODateString(isoString: string): {
152
212
  date: Date;
153
213
  precision: DatePrecision;
154
214
  };
215
+ /**
216
+ * Get the spatial reference from layer or server info
217
+ * @param server
218
+ * @param layer
219
+ * @returns
220
+ * @private
221
+ */
155
222
  export declare const getServerSpatialReference: (server: Partial<IFeatureServiceDefinition>, layer?: ILayerDefinition) => ISpatialReference;
223
+ /**
224
+ * Get the spatial reference as an object for an item
225
+ * @param item
226
+ * @returns spatial reference object
227
+ * @private
228
+ */
156
229
  export declare const getItemSpatialReference: (item: IItem) => ISpatialReference;
157
230
  /**
158
231
  * Data model for additional resources that are extracted
@@ -171,6 +244,7 @@ interface IAGOAdditionalResource {
171
244
  * @param item
172
245
  * @param metadata formal metadata
173
246
  * @returns
247
+ * @private
174
248
  */
175
249
  export declare const getAdditionalResources: (item: IItem, metadata?: any, requestOptions?: IHubRequestOptions) => IHubAdditionalResource[];
176
250
  /**
@@ -181,6 +255,7 @@ export declare const getAdditionalResources: (item: IItem, metadata?: any, reque
181
255
  * @param resource raw additional resource of an item
182
256
  * @param item
183
257
  * @returns
258
+ * @private
184
259
  */
185
260
  export declare const isDataSourceOfItem: (resource: IAGOAdditionalResource, item: IItem) => boolean;
186
261
  /**
@@ -193,6 +268,7 @@ export declare const isDataSourceOfItem: (resource: IAGOAdditionalResource, item
193
268
  * @param item
194
269
  * @param requestOptions IHubRequestOptions, including authentication
195
270
  * @returns
271
+ * @private
196
272
  */
197
273
  export declare const getAdditionalResourceUrl: (resource: IAGOAdditionalResource, item: IItem, requestOptions?: IHubRequestOptions) => string;
198
274
  export {};
@@ -1,6 +1,7 @@
1
1
  import { IItem } from "@esri/arcgis-rest-portal";
2
2
  import { IHubRequestOptions } from "../types";
3
3
  import { IHubContentEnrichments, IHubContent } from "../core";
4
+ import { IHubExtent } from "./_fetch";
4
5
  /**
5
6
  * The possible values for updateFrequency
6
7
  *
@@ -105,6 +106,16 @@ export interface IComposeContentOptions extends IHubContentEnrichments {
105
106
  layerId?: number;
106
107
  slug?: string;
107
108
  requestOptions?: IHubRequestOptions;
109
+ /**
110
+ * Either the item's extent, or the item's
111
+ * layer or server's extent converted to a lat/lng coordinate pair
112
+ */
113
+ extent?: IHubExtent;
114
+ /**
115
+ * The appropriate summary to show for the item, coming from either
116
+ * the item's data (for pages or initiatives) or the item's description
117
+ */
118
+ searchDescription?: string;
108
119
  }
109
120
  /**
110
121
  * Compose a new content object out of an item, enrichments, and context
@@ -0,0 +1,23 @@
1
+ import { ItemOrServerEnrichment } from "../items/_enrichments";
2
+ import { IHubRequestOptions } from "../types";
3
+ interface IFetchItemAndEnrichmentsOptions extends IHubRequestOptions {
4
+ enrichments?: ItemOrServerEnrichment[];
5
+ }
6
+ export interface IFetchContentOptions extends IFetchItemAndEnrichmentsOptions {
7
+ layerId?: number;
8
+ siteOrgKey?: string;
9
+ }
10
+ /**
11
+ * Fetch enriched content from the Portal and Hub APIs.
12
+ * @param identifier content slug or id
13
+ * @param options Request options with additional options to control how the content or enrichments are fetched
14
+ * @returns A content object composed of the backing item and enrichments
15
+ *
16
+ * ```js
17
+ * import { fetchContent } from '@esri/hub-common'
18
+ * // fetch content by slug
19
+ * const content = await fetchContent('my-org::item-name')
20
+ * ```
21
+ */
22
+ export declare const fetchContent: (identifier: string, options?: IFetchContentOptions) => Promise<import("..").IHubContent>;
23
+ export {};
@@ -1,15 +1,12 @@
1
- import { ResourceObject } from "jsonapi-typescript";
2
1
  import { IItem } from "@esri/arcgis-rest-portal";
3
2
  import { HubType, IModel } from "../types";
4
3
  import { IHubContent } from "../core";
4
+ import { DatasetResource } from "./types";
5
5
  export * from "./compose";
6
6
  export * from "./get-family";
7
- /**
8
- * JSONAPI dataset resource returned by the Hub API
9
- */
10
- export declare type DatasetResource = ResourceObject<"dataset", {
11
- [k: string]: any;
12
- }>;
7
+ export * from "./slugs";
8
+ export * from "./fetch";
9
+ export * from "./types";
13
10
  /**
14
11
  * ```js
15
12
  * import { getCategory } from "@esri/hub-common";
@@ -69,40 +66,6 @@ export declare function getTypeCategories(item?: any): string[];
69
66
  * @returns the preferred id for the given content.
70
67
  */
71
68
  export declare function getContentIdentifier(content: IHubContent, site?: IModel): string;
72
- /**
73
- * Parse item ID and layer ID (if any) from dataset record ID
74
- *
75
- * @param datasetId Hub API dataset record id ({itemId}_{layerId} or {itemId})
76
- * @returns A hash with the `itemId` and `layerId` (if any)
77
- */
78
- export declare function parseDatasetId(datasetId: string): {
79
- itemId: string;
80
- layerId?: string;
81
- };
82
- /**
83
- * Determine if an identifier is a Hub API slug
84
- *
85
- * @param identifier Hub API slug ({orgKey}::{title-as-slug} or {title-as-slug})
86
- * or record id ((itemId}_{layerId} or {itemId})
87
- * @returns true if the identifier is valid _and_ is **not** a record id
88
- */
89
- export declare function isSlug(identifier: string): boolean;
90
- /**
91
- * Add a context (prefix) to slug if it doesn't already have one
92
- *
93
- * @param slug Hub API slug (with or without context)
94
- * @param context usually a portal's orgKey
95
- * @returns slug with context ({context}::{slug})
96
- */
97
- export declare function addContextToSlug(slug: string, context: string): string;
98
- /**
99
- * Remove context (prefix) from a slug
100
- *
101
- * @param slug Hub API slug with context
102
- * @param context usually a portal's orgKey
103
- * @returns slug without context
104
- */
105
- export declare function removeContextFromSlug(slug: string, context: string): string;
106
69
  /**
107
70
  * DEPRECATED: Use getFamily() instead.
108
71
  *
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Parse item ID and layer ID (if any) from dataset record ID
3
+ *
4
+ * @param datasetId Hub API dataset record id ({itemId}_{layerId} or {itemId})
5
+ * @returns A hash with the `itemId` and `layerId` (if any)
6
+ */
7
+ export declare function parseDatasetId(datasetId: string): {
8
+ itemId: string;
9
+ layerId?: string;
10
+ };
11
+ /**
12
+ * Determine if an identifier is a Hub API slug
13
+ *
14
+ * @param identifier Hub API slug ({orgKey}::{title-as-slug} or {title-as-slug})
15
+ * or record id ((itemId}_{layerId} or {itemId})
16
+ * @returns true if the identifier is valid _and_ is **not** a record id
17
+ */
18
+ export declare function isSlug(identifier: string): boolean;
19
+ /**
20
+ * Add a context (prefix) to slug if it doesn't already have one
21
+ *
22
+ * @param slug Hub API slug (with or without context)
23
+ * @param context usually a portal's orgKey
24
+ * @returns slug with context ({context}::{slug})
25
+ */
26
+ export declare function addContextToSlug(slug: string, context: string): string;
27
+ /**
28
+ * Remove context (prefix) from a slug
29
+ *
30
+ * @param slug Hub API slug with context
31
+ * @param context usually a portal's orgKey
32
+ * @returns slug without context
33
+ */
34
+ export declare function removeContextFromSlug(slug: string, context: string): string;
@@ -0,0 +1,7 @@
1
+ import { ResourceObject } from "jsonapi-typescript";
2
+ /**
3
+ * JSONAPI dataset resource returned by the Hub API
4
+ */
5
+ export declare type DatasetResource = ResourceObject<"dataset", {
6
+ [k: string]: any;
7
+ }>;
@@ -0,0 +1,24 @@
1
+ import { IItem } from "@esri/arcgis-rest-portal";
2
+ import { IItemEnrichments, IServerEnrichments } from "../core";
3
+ import { IHubRequestOptions } from "../types";
4
+ /**
5
+ * An object containing the item and fetched enrichments
6
+ */
7
+ export interface IItemAndEnrichments extends IItemEnrichments, IServerEnrichments {
8
+ item: IItem;
9
+ }
10
+ /**
11
+ * The name of an enrichment that comes either
12
+ * from the portal API for the item
13
+ * or from the server that the item points to
14
+ */
15
+ export declare type ItemOrServerEnrichment = keyof IItemEnrichments | keyof IServerEnrichments;
16
+ /**
17
+ * Fetch enrichments for an item
18
+ * @param item
19
+ * @param enrichments the list of enrichments to fetch
20
+ * @param requestOptions
21
+ * @returns an object with the item and enrichments
22
+ * @private
23
+ */
24
+ export declare const fetchItemEnrichments: (item: IItem, enrichments: ItemOrServerEnrichment[], requestOptions?: IHubRequestOptions) => Promise<IItemAndEnrichments>;