Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/fix orgs #121

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.


## 4.6.1

### Added
**js-upload-api**: Public helper `fetchToken()`

### Fix
**js-upload-api**: Upload config checks now pass when a token is used instead of creds

## 4.6.0

### Added
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",
"version": "4.6.1",
"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",
"version": "4.6.1",
"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",
"@graphistry/client-api": "^4.6.1",
"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",
"version": "4.6.1",
"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",
"@graphistry/js-upload-api": "^4.6.1",
"shallowequal": "1.1.0"
},
"peerDependencies": {
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",
"version": "4.6.1",
"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",
"version": "4.6.1",
"private": true,
"dependencies": {
"@graphistry/client-api-react": "^4.6.0",
"@graphistry/client-api-react": "^4.6.1",
"@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",
"version": "4.6.1",
"private": true,
"dependencies": {
"@craco/craco": "^6.4.2",
"@graphistry/client-api-react": "^4.6.0",
"@graphistry/client-api-react": "^4.6.1",
"@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",
"version": "4.6.1",
"repository": {
"type": "git",
"url": "git+https://github.com/graphistry/graphistry-js.git"
Expand Down
38 changes: 35 additions & 3 deletions projects/js-upload-api/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,47 @@ export class Client {
return tok;
}

private authTokenValid(): boolean {
/**
*
* @param username
* @param password
* @param org
* @param protocol
* @param host
* @returns Promise for the authentication token
*
* Helper to fetch a token for a given user
*
*/
public async fetchToken(
username: string, password: string, org?: string, protocol = 'https', host = 'hub.graphistry.com'
): Promise<string> {
return (await this.postToApi(
'api/v2/auth/token/generate',
{
username: username,
password: password,
...(org ? {org_name: org} : {}),
},
this.getBaseHeaders(),
`${protocol}://${host}/`
)).token;
}

/**
*
* @returns Whether the current token is valid
*
*/
public authTokenValid(): boolean {
const out = !!this._token;
return out;
}

private async postToApi(url: string, data: any, headers: any): Promise<any> { // eslint-disable-line @typescript-eslint/no-explicit-any
private async postToApi(url: string, data: any, headers: any, baseUrl?: string): Promise<any> { // eslint-disable-line @typescript-eslint/no-explicit-any
const resolvedFetch = this.fetch;
console.debug('postToApi', {url, data, headers});
const response = await resolvedFetch(this.getBaseUrl() + url, { // change this
const response = await resolvedFetch((baseUrl ?? this.getBaseUrl()) + url, { // change this
method: 'POST',
headers,
body:
Expand Down
4 changes: 2 additions & 2 deletions projects/js-upload-api/src/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ export class Dataset {
throw new Error('No client provided');
}

if (!client.isServerConfigured()) {
throw new Error('Client is not configured');
if (!client.authTokenValid() && !client.isServerConfigured()) {
throw new Error('Client is not configured, set token or creds');
}
console.debug('Uploading dataset', {nodeFiles: this.nodeFiles, edgeFiles: this.edgeFiles});

Expand Down
4 changes: 2 additions & 2 deletions projects/js-upload-api/src/Privacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ export class Privacy {
if (!client) {
throw new Error('No client provided');
}
if (!client.isServerConfigured()) {
throw new Error('Client is not configured');
if (!client.authTokenValid() && !client.isServerConfigured()) {
throw new Error('Client is not configured, set token or creds');
}

const opts = {
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",
"version": "4.6.1",
"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",
"@graphistry/node-api": "^4.6.1",
"apache-arrow": "^11.0.0"
}
}
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.

4 changes: 2 additions & 2 deletions projects/node-api-test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphistry/node-api-test",
"version": "4.6.0",
"version": "4.6.1",
"description": "",
"main": "src/index.js",
"type": "module",
Expand All @@ -16,7 +16,7 @@
"author": "Graphistry, Inc.",
"license": "Apache-2.0",
"dependencies": {
"@graphistry/node-api": "^4.6.0",
"@graphistry/node-api": "^4.6.1",
"apache-arrow": "^11.0.0"
}
}
39 changes: 38 additions & 1 deletion projects/node-api-test/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ if (false) {
console.info(`View dataset ${dataset.datasetID} at ${dataset.datasetURL}`);
console.info(`Dataset using node file ${nodesFile.fileID}, edge file ${edgesFile.fileID}`);

} else {
} else if (false) {

//convert edges to apache-arrow table
const edgesArr = tableFromArrays(edges);
Expand Down Expand Up @@ -258,4 +258,41 @@ if (false) {

await dataset.privacy(client);

} else {

//use token & org

const edgesArr = tableFromArrays(edges);
const nodesArr = tableFromArrays(nodes);
const client1 = new Client();
const tok = await client1.fetchToken(user, password, org, protocol, host);
console.info('-------------------token------------------', tok);
const client = new Client(undefined, undefined, org, protocol, host);
client.setToken(tok);

function arrToUint8Array(arr) {
const ui8 = tableToIPC(arr, 'file');
return ui8;
}
const edgesFile = new EdgeFile(arrToUint8Array(edgesArr), 'arrow');
const nodesFile = new NodeFile(arrToUint8Array(nodesArr), 'arrow'); // optional
await Promise.all([edgesFile.upload(client), nodesFile.upload(client)]);

console.info('--------- Files uploaded --------------');

const dataset = new Dataset({
node_encodings: { bindings: { node: 'n' } },
edge_encodings: { bindings: { source: 's', destination: 'd' } },
metadata: {},
name: 'testdata',
}, edgesFile, nodesFile);
await dataset.upload(client);

console.info('--------- Dataset uploaded --------------');

console.info(`View dataset ${dataset.datasetID} at ${dataset.datasetURL}`);
console.info(`Dataset using node file ${nodesFile.fileID}, edge file ${edgesFile.fileID}`);

await dataset.privacy(client, 'private');

}
2 changes: 1 addition & 1 deletion projects/node-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/node-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphistry/node-api",
"version": "4.6.0",
"version": "4.6.1",
"repository": {
"type": "git",
"url": "git+https://github.com/graphistry/graphistry-js.git"
Expand Down Expand Up @@ -74,7 +74,7 @@
"typescript": "^4.6.4"
},
"dependencies": {
"@graphistry/js-upload-api": "^4.6.0",
"@graphistry/js-upload-api": "^4.6.1",
"node-fetch-commonjs": "^3.2.4"
}
}