Skip to content

Commit

Permalink
Merge pull request #120 from graphistry/dev/orgs
Browse files Browse the repository at this point in the history
Dev/orgs
  • Loading branch information
lmeyerov authored Apr 1, 2023
2 parents 19f42f1 + d04cba3 commit 6ce5e64
Show file tree
Hide file tree
Showing 28 changed files with 130 additions and 51 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## Development
## 4.6.0

### Added

- **js-upload-api**: CommonJS support with output binaries at `dist/cjs`
- **node-api**: CommonJS support with output binaries at `dist/cjs`
- **all**: Optional orgs login

### Docs

- **all**: Arrow uploads and login modes

## 4.5.0 - 2023-03-23

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "4.6.0-alpha.1",
"version": "4.6.0",
"packages": [
"projects/client-api",
"projects/client-api-react",
Expand Down
2 changes: 1 addition & 1 deletion projects/client-api-react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions projects/client-api-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphistry/client-api-react",
"version": "4.6.0-alpha.1",
"version": "4.6.0",
"repository": {
"type": "git",
"url": "git+https://github.com/graphistry/graphistry-js.git"
Expand Down Expand Up @@ -69,7 +69,7 @@
"author": "Graphistry, Inc <https://graphistry.com>",
"license": "ISC",
"dependencies": {
"@graphistry/client-api": "^4.6.0-alpha.1",
"@graphistry/client-api": "^4.6.0",
"crypto-browserify": "3.12.0",
"prop-types": ">=15.6.0",
"shallowequal": "1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion projects/client-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions projects/client-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphistry/client-api",
"version": "4.6.0-alpha.1",
"version": "4.6.0",
"description": "Client-side API for interacting with a Graphistry embedded visualization.",
"jsnext:main": "dist/index.js",
"config": {
Expand Down Expand Up @@ -85,7 +85,7 @@
"@graphistry/falcor-json-graph": "^2.9.10",
"@graphistry/falcor-model-rxjs": "2.11.0",
"@graphistry/falcor-socket-datasource": "2.11.3",
"@graphistry/js-upload-api": "^4.6.0-alpha.1",
"@graphistry/js-upload-api": "^4.6.0",
"shallowequal": "1.1.0"
},
"peerDependencies": {
Expand Down
8 changes: 6 additions & 2 deletions projects/client-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Client extends ClientBase {
* @constructor
* @param {string} username - Graphistry server username
* @param {string} password - Graphistry server password
* @param {string} org - Graphistry organization (optional)
* @param {string} [protocol='https'] - 'http' or 'https' for client->server upload communication
* @param {string} [host='hub.graphistry.com'] - Graphistry server hostname
* @param {clientProtocolHostname} clientProtocolHostname - Override URL base path shown in browsers. By default uses protocol/host combo, e.g., https://hub.graphistry.com
Expand All @@ -39,13 +40,16 @@ export class Client extends ClientBase {
* ```
*/
constructor(
username, password,
username, password, org = undefined,
protocol = 'https', host = 'hub.graphistry.com',
clientProtocolHostname,
version
) {
console.debug('new client', { username }, { password }, { protocol }, { host }, { clientProtocolHostname }, { version });
super(username, password, protocol, host, clientProtocolHostname, window.fetch.bind(window), version, '@graphistry/client-api');
super(
username, password, org,
protocol, host, clientProtocolHostname,
window.fetch.bind(window), version, '@graphistry/client-api');
}
}

Expand Down
2 changes: 1 addition & 1 deletion projects/cra-template/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/cra-template/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphistry/cra-template",
"version": "4.6.0-alpha.1",
"version": "4.6.0",
"private": true,
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion projects/cra-test-18/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions projects/cra-test-18/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "test18",
"version": "4.6.0-alpha.1",
"version": "4.6.0",
"private": true,
"dependencies": {
"@graphistry/client-api-react": "^4.6.0-alpha.1",
"@graphistry/client-api-react": "^4.6.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
2 changes: 1 addition & 1 deletion projects/cra-test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions projects/cra-test/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@graphistry/client-react-app-cra-test",
"version": "4.6.0-alpha.1",
"version": "4.6.0",
"private": true,
"dependencies": {
"@craco/craco": "^6.4.2",
"@graphistry/client-api-react": "^4.6.0-alpha.1",
"@graphistry/client-api-react": "^4.6.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.2.0",
Expand Down
2 changes: 1 addition & 1 deletion projects/js-upload-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/js-upload-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphistry/js-upload-api",
"version": "4.6.0-alpha.1",
"version": "4.6.0",
"repository": {
"type": "git",
"url": "git+https://github.com/graphistry/graphistry-js.git"
Expand Down
24 changes: 21 additions & 3 deletions projects/js-upload-api/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
*
* <br>
*
* @example **Authenticate against Graphistry Hub**
* @example **Authenticate against Graphistry Hub for a personal account**
* ```javascript
* import { Client } from '@graphistry/node-api';
* const client = new Client('my_username', 'my_password');
* ```
*
* <br>
*
* @example **Authenticate against an org in Graphistry Hub**
* ```javascript
* import { Client } from '@graphistry/node-api';
* const client = new Client('my_username', 'my_password', 'my_org');
* ```
*
* <br>
*
* @example **Authenticate against a private Graphistry server**
* ```javascript
Expand Down Expand Up @@ -66,6 +74,7 @@ export class Client {
public readonly clientProtocolHostname: string;
public readonly agent: string;
public readonly version?: string;
public readonly org?: string;


private _getAuthTokenPromise?: Promise<string>; // undefined if not configured
Expand All @@ -80,12 +89,16 @@ export class Client {
*
* @param username The username to authenticate with.
* @param password The password to authenticate with.
* @param org The organization to use (optional)
* @param protocol The protocol to use for the server during uploads: 'http' or 'https'.
* @param host The hostname of the server during uploads: defaults to 'hub.graphistry.com'
* @param clientProtocolHostname Base path to use inside the browser and when sharing public URLs: defaults to '{protocol}://{host}'
* @param fetch The fetch implementation to use
* @param version The version of the client library
* @param agent The agent name to use when communicating with the server
*/
constructor (
username: string, password: string,
username: string, password: string, org?: string,
protocol = 'https', host = 'hub.graphistry.com',
clientProtocolHostname?: string,
fetch?: any, // eslint-disable-line @typescript-eslint/no-explicit-any
Expand All @@ -94,6 +107,7 @@ export class Client {
) {
this.username = username;
this._password = password;
this.org = org;
this.protocol = protocol;
this.host = host;
this.fetch = fetch;
Expand Down Expand Up @@ -201,7 +215,11 @@ export class Client {

const response = await this.postToApi(
'api/v2/auth/token/generate',
{ username: this.username, password: this._password },
{
username: this.username,
password: this._password,
...(this.org ? {org_name: this.org} : {}),
},
this.getBaseHeaders(),
)

Expand Down
20 changes: 19 additions & 1 deletion projects/js-upload-api/src/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ import { Mode, ModeAction, Privacy } from './Privacy.js';
*
* <br>
*
* @example **Create a dataset using Arrow**
* ```javascript
* import { tableFromArrays, tableToIPC, Table } from 'apache-arrow';
* import { EdgeFile } from '@graphistry/node-api';
*
* //columnar data is fastest; column per attribute; reuse across datasets
* const edgesJSON = {'s': ['a1', 'b2'], 'd': ['b2', 'c3']};
* const edgesTable: Table = tableFromArrays(edgesJSON);
* const edgesUint8: Uint8Array = tableToIPC(edgesArr, 'file');
* const edgesFile = new EdgeFile(edgesUint8, 'arrow');
* ```
*
* <br>
*
* @example **Add files after the Dataset is instantiated but before it has been uploaded**
* ```javascript
* import { Dataset } from '@graphistry/node-api';
Expand Down Expand Up @@ -315,7 +329,11 @@ export class Dataset {
node_files: this.nodeFiles.map((file) => file.fileID),
edge_files: this.edgeFiles.map((file) => file.fileID),
};
const bindings = { ...fileBindings, ...this.bindings };
const bindings = {
...(client.org ? { org_name: client.org } : {}),
...fileBindings,
...this.bindings
};
await this.createDataset(client, bindings);

return this;
Expand Down
8 changes: 7 additions & 1 deletion projects/js-upload-api/src/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ export class File {
}
console.debug('Creating file');

const fileJsonResults = await client.post('api/v2/files/', {file_type: this.fileFormat, ...this.createOpts});
const fileJsonResults = await client.post(
'api/v2/files/',
{
file_type: this.fileFormat,
...(client.org ? { org_name: client.org } : {}),
...this.createOpts
});
console.debug('File creation response:', fileJsonResults);
this._fileCreateResponse = fileJsonResults;
this._fileID = fileJsonResults.file_id;
Expand Down
2 changes: 1 addition & 1 deletion projects/node-api-test-cjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions projects/node-api-test-cjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphistry/node-api-test-cjs",
"version": "4.6.0-alpha.1",
"version": "4.6.0",
"description": "",
"main": "src/index.js",
"type": "commonjs",
Expand All @@ -16,7 +16,7 @@
"author": "Graphistry, Inc.",
"license": "Apache-2.0",
"dependencies": {
"@graphistry/node-api": "^4.6.0-alpha.1",
"@graphistry/node-api": "^4.6.0",
"apache-arrow": "^11.0.0"
}
}
14 changes: 8 additions & 6 deletions projects/node-api-test-cjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ if (!user) { throw new Error('GRAPHISTRY_USER environment variable not set'); }
const password = process.env.GRAPHISTRY_PASSWORD;
if (!password) { throw new Error('GRAPHISTRY_PASSWORD environment variable not set'); }

const org = process.env.GRAPHISTRY_ORG;

const protocol = process.env.GRAPHISTRY_PROTOCOL || 'https';
const host = process.env.GRAPHISTRY_HOST || 'hub.graphistry.com';

Expand All @@ -48,7 +50,7 @@ async function go() {

if (false) {

const client = new Client(user, password, protocol, host);
const client = new Client(user, password, org, protocol, host);

const edgesFile = new EdgeFile(edges);
const nodesFile = new NodeFile(nodes); // optional
Expand All @@ -67,7 +69,7 @@ if (false) {

} else if (false) {

const client = new Client(user, password, protocol, host);
const client = new Client(user, password, org, protocol, host);

const edgesFile = new EdgeFile(edges);
const nodesFile = new NodeFile(nodes); // optional
Expand All @@ -85,7 +87,7 @@ if (false) {

} else if (false) {

const client = new Client(user, password, protocol, host);
const client = new Client(user, password, org, protocol, host);

const edgesFile = new EdgeFile(
edgesRows,
Expand Down Expand Up @@ -186,7 +188,7 @@ if (false) {

} else if (false) {

const client = new Client(user, password, protocol, host);
const client = new Client(user, password, org, protocol, host);
const edgesFile = new EdgeFile(edges);
const nodesFile = new NodeFile(nodes); // optional

Expand All @@ -210,7 +212,7 @@ if (false) {
//convert edges to apache-arrow table
const edgesArr = tableFromArrays(edges);
const nodesArr = tableFromArrays(nodes);
const client = new Client(user, password, protocol, host);
const client = new Client(user, password, org, protocol, host);

function arrToUint8Array(arr) {
const ui8 = tableToIPC(arr, 'file');
Expand All @@ -237,7 +239,7 @@ if (false) {
//convert edges to apache-arrow table
const edgesArr = tableFromArrays(edges);
const nodesArr = tableFromArrays(nodes);
const client = new Client(user, password, protocol, host);
const client = new Client(user, password, org, protocol, host);

function arrToUint8Array(arr) {
const ui8 = tableToIPC(arr, 'file');
Expand Down
2 changes: 1 addition & 1 deletion projects/node-api-test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ce5e64

Please sign in to comment.