diff --git a/CHANGELOG.md b/CHANGELOG.md index a6ce72b..c2311a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lerna.json b/lerna.json index e228a07..f315cb6 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "4.6.0", + "version": "4.6.1", "packages": [ "projects/client-api", "projects/client-api-react", diff --git a/projects/client-api-react/package-lock.json b/projects/client-api-react/package-lock.json index 2986c88..406f0f3 100644 --- a/projects/client-api-react/package-lock.json +++ b/projects/client-api-react/package-lock.json @@ -1,6 +1,6 @@ { "name": "@graphistry/client-api-react", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/projects/client-api-react/package.json b/projects/client-api-react/package.json index 0f9102c..5b07b75 100644 --- a/projects/client-api-react/package.json +++ b/projects/client-api-react/package.json @@ -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" @@ -69,7 +69,7 @@ "author": "Graphistry, Inc ", "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", diff --git a/projects/client-api/package-lock.json b/projects/client-api/package-lock.json index dc115d5..a0f1cd0 100644 --- a/projects/client-api/package-lock.json +++ b/projects/client-api/package-lock.json @@ -1,6 +1,6 @@ { "name": "@graphistry/client-api", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/projects/client-api/package.json b/projects/client-api/package.json index 9d2bd0c..11bb397 100644 --- a/projects/client-api/package.json +++ b/projects/client-api/package.json @@ -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": { @@ -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": { diff --git a/projects/cra-template/package-lock.json b/projects/cra-template/package-lock.json index 3b441db..d8c2601 100644 --- a/projects/cra-template/package-lock.json +++ b/projects/cra-template/package-lock.json @@ -1,6 +1,6 @@ { "name": "@graphistry/cra-template", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/projects/cra-template/package.json b/projects/cra-template/package.json index 4c02698..f6a442a 100644 --- a/projects/cra-template/package.json +++ b/projects/cra-template/package.json @@ -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", diff --git a/projects/cra-test-18/package-lock.json b/projects/cra-test-18/package-lock.json index 8230166..c5d5df5 100644 --- a/projects/cra-test-18/package-lock.json +++ b/projects/cra-test-18/package-lock.json @@ -1,6 +1,6 @@ { "name": "test18", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/projects/cra-test-18/package.json b/projects/cra-test-18/package.json index d4fa16e..48a4948 100644 --- a/projects/cra-test-18/package.json +++ b/projects/cra-test-18/package.json @@ -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", diff --git a/projects/cra-test/package-lock.json b/projects/cra-test/package-lock.json index 3a8d9ca..7100d3e 100644 --- a/projects/cra-test/package-lock.json +++ b/projects/cra-test/package-lock.json @@ -1,6 +1,6 @@ { "name": "@graphistry/client-react-app-cra-test", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/projects/cra-test/package.json b/projects/cra-test/package.json index 18b160e..5ddc301 100644 --- a/projects/cra-test/package.json +++ b/projects/cra-test/package.json @@ -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", diff --git a/projects/js-upload-api/package-lock.json b/projects/js-upload-api/package-lock.json index b87dc59..2f39b5d 100644 --- a/projects/js-upload-api/package-lock.json +++ b/projects/js-upload-api/package-lock.json @@ -1,6 +1,6 @@ { "name": "@graphistry/js-upload-api", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/projects/js-upload-api/package.json b/projects/js-upload-api/package.json index 93c4da7..4c225c9 100644 --- a/projects/js-upload-api/package.json +++ b/projects/js-upload-api/package.json @@ -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" diff --git a/projects/js-upload-api/src/Client.ts b/projects/js-upload-api/src/Client.ts index 76b82d4..1070db8 100644 --- a/projects/js-upload-api/src/Client.ts +++ b/projects/js-upload-api/src/Client.ts @@ -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 { + 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 { // eslint-disable-line @typescript-eslint/no-explicit-any + private async postToApi(url: string, data: any, headers: any, baseUrl?: string): Promise { // 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: diff --git a/projects/js-upload-api/src/Dataset.ts b/projects/js-upload-api/src/Dataset.ts index 653af73..789b8f4 100644 --- a/projects/js-upload-api/src/Dataset.ts +++ b/projects/js-upload-api/src/Dataset.ts @@ -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}); diff --git a/projects/js-upload-api/src/Privacy.ts b/projects/js-upload-api/src/Privacy.ts index 75f7fb3..b7374ae 100644 --- a/projects/js-upload-api/src/Privacy.ts +++ b/projects/js-upload-api/src/Privacy.ts @@ -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 = { diff --git a/projects/node-api-test-cjs/package-lock.json b/projects/node-api-test-cjs/package-lock.json index e68c942..5983000 100644 --- a/projects/node-api-test-cjs/package-lock.json +++ b/projects/node-api-test-cjs/package-lock.json @@ -1,6 +1,6 @@ { "name": "@graphistry/node-api-test", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/projects/node-api-test-cjs/package.json b/projects/node-api-test-cjs/package.json index 2469fde..2ac6ade 100644 --- a/projects/node-api-test-cjs/package.json +++ b/projects/node-api-test-cjs/package.json @@ -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", @@ -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" } } diff --git a/projects/node-api-test/package-lock.json b/projects/node-api-test/package-lock.json index 354ca41..e5ed6c3 100644 --- a/projects/node-api-test/package-lock.json +++ b/projects/node-api-test/package-lock.json @@ -1,6 +1,6 @@ { "name": "@graphistry/node-api-test", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/projects/node-api-test/package.json b/projects/node-api-test/package.json index 83e1dde..d1e7e96 100644 --- a/projects/node-api-test/package.json +++ b/projects/node-api-test/package.json @@ -1,6 +1,6 @@ { "name": "@graphistry/node-api-test", - "version": "4.6.0", + "version": "4.6.1", "description": "", "main": "src/index.js", "type": "module", @@ -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" } } diff --git a/projects/node-api-test/src/index.js b/projects/node-api-test/src/index.js index 25f79dc..b2ba251 100644 --- a/projects/node-api-test/src/index.js +++ b/projects/node-api-test/src/index.js @@ -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); @@ -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'); + } \ No newline at end of file diff --git a/projects/node-api/package-lock.json b/projects/node-api/package-lock.json index 7b0d477..2e657b3 100644 --- a/projects/node-api/package-lock.json +++ b/projects/node-api/package-lock.json @@ -1,6 +1,6 @@ { "name": "@graphistry/node-api", - "version": "4.6.0", + "version": "4.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/projects/node-api/package.json b/projects/node-api/package.json index dab1560..621b072 100644 --- a/projects/node-api/package.json +++ b/projects/node-api/package.json @@ -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" @@ -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" } }