Code Monkey home page Code Monkey logo

hub.js's Introduction

npm version build status Coverage Status apache licensed

@esri/hub.js

compact, modular JavaScript wrappers for ArcGIS Hub that run in Node.js and modern browsers.

Table of Contents

API Reference

The documentation is published at http://esri.github.io/hub.js/ (source code here).

Instructions

You can install dependencies by cloning the repository and running:

npm install

Note: This project uses volta to manage node/npm versions. We strongly suggest you do, too :)

Afterward, for a list of all available commands run npm run.

Some useful commands include:

  • npm test runs all the tests and confirms the API is functioning as expected.
  • There is also a Debug Node Tests configuration in the .vscode/launch.json which will run the Node tests in the VS Code debugger.
  • npm run test:chrome:debug runs all the tests in a browser, and will re-run when changes are made. Note: in some situations, spies/stubs will fail on subsequent test runs. We are not certain why this occurs, but the resolution is to stop/start the test runner.
  • npm run docs:serve will run the documentation site locally at http://localhost:3000
  • npm run build will run the ESM and CJS build for all the packages

Packages

Deprecated Packages

Design Philosophy

hub.js is designed as a set of data manipulation functions, not persistent objects with behavior. You should not use new in conjunction with this library. Just include the modules your application needs and use them to hide lower-level abstractions for making API calls for hub related things. Your application should manage the state of the data you receive from these methods.

This project builds on the packages in arcgis-rest-js, so if you want even lower-level access, you can also use them directly.

Why Not Objects?

Persistent objects often introduce memory leaks in JavaScript applications. As soon as you instantiate a new object, you need to consider its lifespan. If you happen to assign that object inside a closure or somewhere else long-lived, you might end up with references that cannot be destroyed by the garbage collector. Creating clean separation between functions-that-fetch-or-manipulate-data and application-state-as-a-javascript-object helps to avoid this problem.

We are aiming for functional equivalence to hub-py so that the objects and capabilities are familiar, not necessarily to make the APIs identical.

More about Javascript Memory Leaks

Frequently Asked Questions

Issues

If something isn't working the way you expected, please take a look at previously logged issues first. Have you found a new bug? Want to request a new feature? We'd love to hear from you.

If you're looking for help you can also post issues on GIS Stackexchange.

Versioning

For transparency into the release cycle and in striving to maintain backward compatibility, @esri/hub.js is maintained under Semantic Versioning guidelines and will adhere to these rules whenever possible.

For more information on SemVer, please visit http://semver.org/.

Contributing

Release Process

See the release process document.

Recommended Extensions

To assist you in your development efforts, we have recommended certain extensions for VScode. On editor load, you should see a pop up in the bottom right that will direct you to the download point.

If you have another useful extension that you'd like to recommend, add an entry to the recommendations array in extensions.json (hint: hitting cmd+i while in the array will bring up a list of all your installed extensions). Submit a PR with your changes through the normal process.

License

Copyright ยฉ 2018-2019 Esri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's LICENSE file.

hub.js's People

Contributors

abp6318 avatar ajturner avatar benstoltz avatar brittneyjb avatar dbouwman avatar drewdaemon avatar drspacemanphd avatar haoliangyu avatar jeromesteve202 avatar jgravois avatar joppa27 avatar jordantsanz avatar jpurush avatar juliannaeapicella avatar juliannemarik avatar markhamshofner avatar marvinperry avatar miketschudi avatar mjuniper avatar pranavkulkarni avatar rgwozdz avatar rweber-esri avatar sansth1010 avatar semantic-release-bot avatar sonofflynn89 avatar tannerjt avatar tomwayson avatar trescube avatar velveetachef avatar vivzhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hub.js's Issues

searchAnnotations should handle user request errors and maybe pass auth along to request for users

This line sends an unauthenticated request:

const getUserInfo = users.map(name => getUser(name));

I think that will only work for public user accounts. Other user accounts prob return 403.

Also https://github.com/Esri/arcgis-rest-js/pull/243/files is blowing up my https app. Generally it would be a good idea to handle errors for each user request so we still return annos and whatever users are visible. Makes me pine for allSettled.

crud/search shouldn't require adding "/0" to the annotationsUrl

from @ajturner:

Currently, searchAnnotations requires the Feature layer url:

arcgisHub.searchAnnotations({url: annotationsUrl + "/0"}).then( response => {});

This is unnecessarily complex for developers and exposes the implementation of annotations. Instead, it should default to the Org annotations, or build the right feature layer.

arcgisHub.searchAnnotations({org: '...'})

arcgisHub.getAnnotationServiceUrl("...").then(
  annotationsUrl => {
    arcgisHub.searchAnnotations({url: annotationsUrl}).then( response =>  {});
 }
);

Suggested changes to guide pages

A few suggested changes for the initiative guide pages:

  • initiatives not be under Getting Started, but should have their own top-level entry in the TOC like "Working with Initiatives" image
  • "Using the Initiatives "Coarse-Grained API" should just be "Create an Initiative", we can splain' there are 2 APIs (coarse and fine grained) in the description
  • all the code snippets use fetchInitiative() and need to be updated to getInitiative()

We should add a "Using ES Modules" section under getting started like https://esri.github.io/arcgis-rest-js/guides/babel-and-webpack/ or https://esri.github.io/arcgis-rest-js/guides/babel-and-rollup/ - also, those 2 pages should just be combined into 1 "From ES Modules" why be hyper specific about what transpiler and bundler people use?

Getting Started: Add more/better information about linked initiative

Improving the Getting Started experience by:

  • Removing "abc123" and add something like , like this the code does not run and the user knows they have to replace it with something
  • Give an example of an initiative ID, e.g. a public initiative, or maybe even set up and link to a public one that is intended for the demo
  • Give guidance on how to find initiative ID (e.g. open initiative, copy item id from URL)
  • As the initiative linked for the demo needs to be public (otherwise not accessible), mention the sharing settings as a precondition so that the demo works.

To what extent are we consistent w/ the python API?

While it would be nice to mirror the Hub.py API, Python and JS are different languages, used in different contexts. For JS that runs in a browser, there is a real cost to adding bits that don't get used (like CRUD operations that won't get used in a read-only site), and potential memory leaks left around by objects that aren't destroyed. In those scenarios it's preferable to compose your application out of dependencies that expose stateless functions - like https://github.com/Esri/arcgis-rest-js/

If we need to mirror the Hub.py API, then maybe we just add a top level package to this repo that consumes the the libraries that expose stateless functions and exposes a hateful stateful API (const hub = new Hub(myCommunityOrgUrl)) that does all the things.

addAnnotations: Specify required fields

When adding annotations, some fields seem to be required:

  • target
  • author
  • description
  • created_at (?)

First 3 are in the example, but last one is just throwing an error when not specified. We are using the latest npm packages (last release).

query annotations

Since annotations are backed by a feature service this will wrap queryFeatures(). Events will work the same way and I previously proposed searchEvents(eventServiceUrl, queryParams). That raises few questions.

Do we use the search or query prefix? The former is consistent w/ Hub.py, the latter w/ arcgis-rest-js. I think it's more important to be consistent w/ Hub.py.

Do we pass the url as the first param? So: searchAnnotations(annotationServiceUrl, queryParams). Or do we follow the pattern of just passing opts that is used by the the current implementation?

createAnnotations: locked fields

A number of fields seem to be 'locked' on the AGOL service when a new annotation service is created. This did not happen before (about 2 weeks ago), maybe just an issue with the current release:

image

It seems those fields are not populated correctly which causes the query (fetching the annotation service to be displayed in the SceneView) to fail (e.g. no author specified). author cannot be assigned anymore as shown in the example as a string (https://esri.github.io/hub.js/api/annotations/addAnnotations/).

Consistent method prefix (fetch/lookup/get/search)

Currently, there are multiple synonymous method prefixes that conceptually mean the same:

fetch vs. get vs. lookup vs. search

For the developer user - can we choose one that applies to all "READ" type operations, even if the implementation requires more complex operations. For example, can fetchInitiative and lookupSiteUrlByInitiative become getInitiative and getInitiativeSite?

Annotations should not require the service URL or layer id

Currently, searchAnnotations requires the Feature layer url:

arcgisHub.searchAnnotations({url: annotationsUrl + "/0"}).then( response => {});

This is unnecessarily complex for developers and exposes the implementation of annotations. Instead, it should default to the Org annotations, or build the right feature layer.

arcgisHub.searchAnnotations({org: '...'})

arcgisHub.getAnnotationServiceUrl("...").then(
  annotationsUrl => {
    arcgisHub.searchAnnotations({url: annotationsUrl}).then( response =>  {});
  }
);

createAnnotationService: add options

The createAnnotationService function only allows to add orgId and authentication (correct?). I would have expected to see more like activateInitiative where a name can be specified as well as a group.

We expect to have the annotation service also being analyzed/retrieved through ArcGIS Online in a first version of Urban, so it would be good to being able to give it a proper name.

hook up coveralls

need to stash a couple encrypted environment variables for Travis

Add fn to get (everything but) the kitchen sink for a Hub

Apps that are related to a Hub (and/or a specific initiative) would like a single (or few) fn call(s) that they can make to get all the information they will need to provide a seamless experience that is integrated with the initative/Hub.

As a rough cut of what such function could look like, I propose taking an initativeId as a string and returning the JSON proposed in https://devtopia.esri.com/Beijing-R-D-Center/ExperienceBuilder/pull/182/files#diff-d31e367decde8d27039b2d23659be3c2R73

As seen here:

https://devtopia.esri.com/Beijing-R-D-Center/ExperienceBuilder/blob/88f6c5d42d5efa401107eeeea1577bde068d071d/design/spec/hub.md#example-hub-configuration

I'm open to suggestion on that. For one thing, we should probably also include an array of indicators: [{....}] under the initiative. Also, we may find that this naturally decomposes into at least 2 fns, one for getting the info specific to initiative, and one for getting the "Hub" info.

Notice how I've artfully dodged the question of what to name these fns, I'll leave that as an exercise for the reader. ๐Ÿ˜‰

update newly created social users:

After Esri/arcgis-rest-js#240 lands, we'll want to add fn here (in the fabled @esri/hub-auth package) that wraps beginOAuth2 and before returning the session will:

  • fetch the user record
  • see if they've just been created
  • sets their access level to pubilc
  • tags them w/ the hub org
  • adds them to the hubRole:participant

Relevant code: https://github.com/ArcGIS/opendata-ui/blob/cfbcc8541de10ca67311375a59745e12c1cb5d3f/packages/opendata-ui/app/components/od-sign-in-modal/component.js#L93-L102

stateful hub package

An uber package that will make it easier to use the stateless libraries.

Example:

import Hub from '@esri/hub'; // the only import you'll ever need

const config = { orgId : 'awefa' };
const hub = new Hub(config);`
hub.signIn(); // uses @esri/hub-auth and @esri/arcigs-auth under the hood
.then(() => {
  hub.getInitative('3ef'`); // uses @esri/hub-initiatives under the hood
  hub.getAnnotations({ // use @esri/hub-annotations, look ma, no url!
    where: "status='pending"
  });
  // hub.getEvents({...});
  // hub.getEventDetails(123456);
  // and so on
});

This should also help align w/ the python API #13.

tsc errors at the end of lerna bootstrap (during prepare) on a freshly cloned repo

lerna ERR! execute Error occured with '@esri/hub-annotations' while running 'npm run prepare'
lerna ERR! npm run prepare [@esri/hub-annotations] Output from stdout:

> @esri/[email protected] prepare /Users/tom/code/hub.js/packages/annotations
> npm run build


> @esri/[email protected] build /Users/tom/code/hub.js/packages/annotations
> npm run build:node && npm run build:umd && npm run build:esm


> @esri/[email protected] build:node /Users/tom/code/hub.js/packages/annotations
> tsc --module commonjs --outDir ./dist/node

src/search.ts(46,14): error TS2339: Property 'features' does not exist on type 'IQueryFeaturesResponse | IQueryResponse'.
  Property 'features' does not exist on type 'IQueryResponse'.
src/search.ts(46,40): error TS7006: Parameter 'comment' implicitly has an 'any' type.

searchAnnotations crashes when there are annotations with an empty author field

Repro:

  • add an annotation anonymously (results in empty author field)
  • run searchAnnotations(...)
  • a request is made to https://www.arcgis.com/sharing/rest/community/users/?f=json which fails with message: "You do not have permissions to access this resource or perform this operation."
  • this throws an error which is not handled

Adding search option where: "author <> ''" solves the problem, but like this, we cannot fetch the anonymous comments.

searchAnnotations does not return geometry

Repro:

  • run searchAnnotations({ url, authentication, returnGeometry: true })
  • request to the server is correct (returnGeometry: true) and returns the geometry
  • returned data object does not contain the geometries

Annotation CRUD should not need adds: updates: deletes

It's odd that addAnnotations requires adds: [] - which seems redundant to the actual name. This is because the function is a thin wrapper to feature service, but unnecessary for these focused functions.

arcgisHub.addAnnotations({url: annotationsUrl + "/0", adds: [
              {attributes: {description: "Test Anonymous", target: "none", author: "Hamilton"}}
            ]}).then( response => {
              console.log("addAnnotations", response);
          });

should become

arcgisHub.addAnnotations({url: annotationsUrl, annotations: [
              {attributes: {description: "Test Anonymous", target: "none", author: "Hamilton"}}
            ]}).then( response => {
              console.log("addAnnotations", response);
          });

@esri/telemetry integration

Call https://www.npmjs.com/package/@esri/telemetry .logEvent() if an instance of Telemetry is provided.

This probably makes the most sense after #75 since we'll probably want something like this:

import Hub from '@esri/hub';
import Telemetry from '@esri/telemetry';

const telemetryConfig = { /* base telemetry config here */ };
const hubConfig = { orgId : 'awefa', telemetry: { /* hub specific telemetry config here */ } };
const hub = new Hub(hubConfig);
hub.teletmetry = new Telemetry(telemetryConfig);
hub.signIn()
.then(() => {
  hub.getInitative('3ef'`); // calls hub.telemtry.logEvent() after calling @esri/hub-initative getInitiative()
});

The hub specific telemetry config might map hub.js packages/functions to categories/actions.

Also, having it as a property would expose telemetry to so that the app can use it for non-hub specific things like:

// after transitioning to a route
hub.telemetry.logPageView(options);

add searchInitiatives()

A thin wrapper around searchItems() and should at least support the params listed in #13 (comment)

This will underpin the fetchOrgInitiatives(orgId) fn also listed in ^^^, which probably can be included in the same PR.

With those two and the existing fetchInitiative(), we'll have functional parity w/ Hub.py for initiatives.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.