@fleekhq/space-client
Advanced tools
Comparing version 1.1.4 to 1.1.5
import grpcWeb, { ClientReadableStream } from 'grpc-web'; | ||
import { SpaceApiClient } from './definitions/SpaceServiceClientPb'; | ||
import { OpenFilePayload, CreateBucketPayload, AddItemsPayload, CreateFolderPayload, BackupKeysByPassphrasePayload, RecoverKeysByPassphrasePayload, ToggleFusePayload, GetFuseDriveStatusPayload, ListDirectoriesPayload, ListDirectoryPayload, ToggleBucketBackupPayload, ShareBucketPayload, JoinBucketPayload, ReadNotificationPayload, GetNotificationsPayload, RestoreKeyPairViaMnemonicPayload, GetSharedWithMeFilesPayload, ShareFilesViaPublicKeyPayload, GeneratePublicFileLinkPayload, TestKeysPassphrasePayload, SetNotificationsLastSeenAtPayload, HandleFilesInvitationPayload, OpenPublicFilePayload, SearchFilesPayload, GetSharedByMeFilesPayload } from './types'; | ||
import { TextileEventResponse, ListDirectoriesResponse, ToggleBucketBackupResponse, OpenFileResponse, CreateBucketResponse, AddItemsResponse, CreateFolderResponse, BackupKeysByPassphraseResponse, RecoverKeysByPassphraseResponse, FuseDriveResponse, FileEventResponse, ListBucketsResponse, ListDirectoryResponse, ShareBucketResponse, JoinBucketResponse, GetPublicKeyResponse, NotificationEventResponse, ReadNotificationResponse, GetNotificationsResponse, HandleFilesInvitationResponse, DeleteKeyPairResponse, GetUsageInfoResponse, GetStoredMnemonicResponse, RestoreKeyPairViaMnemonicResponse, GetSharedWithMeFilesResponse, ShareFilesViaPublicKeyResponse, GetAPISessionTokensResponse, GetRecentlySharedWithResponse, GeneratePublicFileLinkResponse, TestKeysPassphraseResponse, SetNotificationsLastSeenAtResponse, GenerateKeyPairResponse, OpenPublicFileResponse, SearchFilesResponse, GetSharedByMeFilesResponse } from './definitions/space_pb'; | ||
import { OpenFilePayload, CreateBucketPayload, AddItemsPayload, CreateFolderPayload, BackupKeysByPassphrasePayload, RecoverKeysByPassphrasePayload, ToggleFusePayload, GetFuseDriveStatusPayload, ListDirectoriesPayload, ListDirectoryPayload, ToggleBucketBackupPayload, ShareBucketPayload, JoinBucketPayload, ReadNotificationPayload, GetNotificationsPayload, RestoreKeyPairViaMnemonicPayload, GetSharedWithMeFilesPayload, ShareFilesViaPublicKeyPayload, GeneratePublicFileLinkPayload, TestKeysPassphrasePayload, SetNotificationsLastSeenAtPayload, HandleFilesInvitationPayload, OpenPublicFilePayload, SearchFilesPayload, InitializeMasterAppPayload, GetSharedByMeFilesPayload } from './types'; | ||
import { TextileEventResponse, ListDirectoriesResponse, ToggleBucketBackupResponse, OpenFileResponse, CreateBucketResponse, AddItemsResponse, CreateFolderResponse, BackupKeysByPassphraseResponse, RecoverKeysByPassphraseResponse, FuseDriveResponse, FileEventResponse, ListBucketsResponse, ListDirectoryResponse, ShareBucketResponse, JoinBucketResponse, GetPublicKeyResponse, NotificationEventResponse, ReadNotificationResponse, GetNotificationsResponse, HandleFilesInvitationResponse, DeleteKeyPairResponse, GetUsageInfoResponse, GetStoredMnemonicResponse, RestoreKeyPairViaMnemonicResponse, GetSharedWithMeFilesResponse, ShareFilesViaPublicKeyResponse, GetAPISessionTokensResponse, GetRecentlySharedWithResponse, GeneratePublicFileLinkResponse, TestKeysPassphraseResponse, SetNotificationsLastSeenAtResponse, GenerateKeyPairResponse, OpenPublicFileResponse, SearchFilesResponse, InitializeMasterAppTokenResponse, GetSharedByMeFilesResponse } from './definitions/space_pb'; | ||
export interface SpaceClientOpts { | ||
@@ -66,4 +66,5 @@ url: string; | ||
searchFiles(payload: SearchFilesPayload, metadata?: grpcWeb.Metadata): Promise<SearchFilesResponse>; | ||
initializeMasterAppToken(payload: InitializeMasterAppPayload, metadata?: grpcWeb.Metadata): Promise<InitializeMasterAppTokenResponse>; | ||
getSharedByMeFiles(payload: GetSharedByMeFilesPayload, metadata?: grpcWeb.Metadata): Promise<GetSharedByMeFilesResponse>; | ||
} | ||
export default SpaceClient; |
@@ -504,2 +504,14 @@ "use strict"; | ||
} | ||
initializeMasterAppToken(payload, metadata = {}) { | ||
return new Promise((resolve, reject) => { | ||
const request = new space_pb_1.InitializeMasterAppTokenRequest(); | ||
this.instance.initializeMasterAppToken(request, metadata, (err, res) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(res); | ||
}); | ||
}); | ||
} | ||
getSharedByMeFiles(payload, metadata = {}) { | ||
@@ -506,0 +518,0 @@ return new Promise((resolve, reject) => { |
@@ -142,2 +142,8 @@ /** | ||
searchFiles(request: space_pb.SearchFilesRequest, metadata: grpcWeb.Metadata | null, callback: (err: grpcWeb.Error, response: space_pb.SearchFilesResponse) => void): grpcWeb.ClientReadableStream<space_pb.SearchFilesResponse>; | ||
methodInfoInitializeMasterAppToken: grpcWeb.AbstractClientBase.MethodInfo<space_pb.InitializeMasterAppTokenRequest, space_pb.InitializeMasterAppTokenResponse>; | ||
initializeMasterAppToken(request: space_pb.InitializeMasterAppTokenRequest, metadata: grpcWeb.Metadata | null): Promise<space_pb.InitializeMasterAppTokenResponse>; | ||
initializeMasterAppToken(request: space_pb.InitializeMasterAppTokenRequest, metadata: grpcWeb.Metadata | null, callback: (err: grpcWeb.Error, response: space_pb.InitializeMasterAppTokenResponse) => void): grpcWeb.ClientReadableStream<space_pb.InitializeMasterAppTokenResponse>; | ||
methodInfoGenerateAppToken: grpcWeb.AbstractClientBase.MethodInfo<space_pb.GenerateAppTokenRequest, space_pb.GenerateAppTokenResponse>; | ||
generateAppToken(request: space_pb.GenerateAppTokenRequest, metadata: grpcWeb.Metadata | null): Promise<space_pb.GenerateAppTokenResponse>; | ||
generateAppToken(request: space_pb.GenerateAppTokenRequest, metadata: grpcWeb.Metadata | null, callback: (err: grpcWeb.Error, response: space_pb.GenerateAppTokenResponse) => void): grpcWeb.ClientReadableStream<space_pb.GenerateAppTokenResponse>; | ||
} |
@@ -158,2 +158,8 @@ "use strict"; | ||
}, space_pb.SearchFilesResponse.deserializeBinary); | ||
this.methodInfoInitializeMasterAppToken = new grpcWeb.AbstractClientBase.MethodInfo(space_pb.InitializeMasterAppTokenResponse, (request) => { | ||
return request.serializeBinary(); | ||
}, space_pb.InitializeMasterAppTokenResponse.deserializeBinary); | ||
this.methodInfoGenerateAppToken = new grpcWeb.AbstractClientBase.MethodInfo(space_pb.GenerateAppTokenResponse, (request) => { | ||
return request.serializeBinary(); | ||
}, space_pb.GenerateAppTokenResponse.deserializeBinary); | ||
if (!options) | ||
@@ -481,4 +487,20 @@ options = {}; | ||
} | ||
initializeMasterAppToken(request, metadata, callback) { | ||
if (callback !== undefined) { | ||
return this.client_.rpcCall(this.hostname_ + | ||
'/space.SpaceApi/InitializeMasterAppToken', request, metadata || {}, this.methodInfoInitializeMasterAppToken, callback); | ||
} | ||
return this.client_.unaryCall(this.hostname_ + | ||
'/space.SpaceApi/InitializeMasterAppToken', request, metadata || {}, this.methodInfoInitializeMasterAppToken); | ||
} | ||
generateAppToken(request, metadata, callback) { | ||
if (callback !== undefined) { | ||
return this.client_.rpcCall(this.hostname_ + | ||
'/space.SpaceApi/GenerateAppToken', request, metadata || {}, this.methodInfoGenerateAppToken, callback); | ||
} | ||
return this.client_.unaryCall(this.hostname_ + | ||
'/space.SpaceApi/GenerateAppToken', request, metadata || {}, this.methodInfoGenerateAppToken); | ||
} | ||
} | ||
exports.SpaceApiClient = SpaceApiClient; | ||
//# sourceMappingURL=SpaceServiceClientPb.js.map |
import { Empty } from 'google-protobuf/google/protobuf/empty_pb'; | ||
import { SpaceApiClient } from './definitions/SpaceServiceClientPb'; | ||
import { ListDirectoriesRequest, ToggleBucketBackupRequest, OpenFileRequest, CreateBucketRequest, AddItemsRequest, CreateFolderRequest, BackupKeysByPassphraseRequest, RecoverKeysByPassphraseRequest, ToggleFuseRequest, ListBucketsRequest, ListDirectoryRequest, ShareBucketRequest, JoinBucketRequest, ThreadInfo, GetPublicKeyRequest, ReadNotificationRequest, GetNotificationsRequest, HandleFilesInvitationRequest, DeleteKeyPairRequest, DeleteAccountRequest, GetUsageInfoRequest, GetStoredMnemonicRequest, RestoreKeyPairViaMnemonicRequest, GetSharedWithMeFilesRequest, ShareFilesViaPublicKeyRequest, GetAPISessionTokensRequest, GetRecentlySharedWithRequest, GeneratePublicFileLinkRequest, TestKeysPassphraseRequest, SetNotificationsLastSeenAtRequest, GenerateKeyPairRequest, FullPath, OpenPublicFileRequest, SearchFilesRequest, GetSharedByMeFilesRequest, } from './definitions/space_pb'; | ||
import { ListDirectoriesRequest, ToggleBucketBackupRequest, OpenFileRequest, CreateBucketRequest, AddItemsRequest, CreateFolderRequest, BackupKeysByPassphraseRequest, RecoverKeysByPassphraseRequest, ToggleFuseRequest, ListBucketsRequest, ListDirectoryRequest, ShareBucketRequest, JoinBucketRequest, ThreadInfo, GetPublicKeyRequest, ReadNotificationRequest, GetNotificationsRequest, HandleFilesInvitationRequest, DeleteKeyPairRequest, DeleteAccountRequest, GetUsageInfoRequest, GetStoredMnemonicRequest, RestoreKeyPairViaMnemonicRequest, GetSharedWithMeFilesRequest, ShareFilesViaPublicKeyRequest, GetAPISessionTokensRequest, GetRecentlySharedWithRequest, GeneratePublicFileLinkRequest, TestKeysPassphraseRequest, SetNotificationsLastSeenAtRequest, GenerateKeyPairRequest, FullPath, OpenPublicFileRequest, SearchFilesRequest, InitializeMasterAppTokenRequest, GetSharedByMeFilesRequest, } from './definitions/space_pb'; | ||
var DEFAULT_BUCKET = 'personal'; | ||
@@ -571,2 +571,16 @@ var SpaceClient = /** @class */ (function () { | ||
}; | ||
SpaceClient.prototype.initializeMasterAppToken = function (payload, metadata) { | ||
var _this = this; | ||
if (metadata === void 0) { metadata = {}; } | ||
return new Promise(function (resolve, reject) { | ||
var request = new InitializeMasterAppTokenRequest(); | ||
_this.instance.initializeMasterAppToken(request, metadata, function (err, res) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(res); | ||
}); | ||
}); | ||
}; | ||
SpaceClient.prototype.getSharedByMeFiles = function (payload, metadata) { | ||
@@ -573,0 +587,0 @@ var _this = this; |
@@ -136,2 +136,8 @@ /** | ||
}, space_pb.SearchFilesResponse.deserializeBinary); | ||
this.methodInfoInitializeMasterAppToken = new grpcWeb.AbstractClientBase.MethodInfo(space_pb.InitializeMasterAppTokenResponse, function (request) { | ||
return request.serializeBinary(); | ||
}, space_pb.InitializeMasterAppTokenResponse.deserializeBinary); | ||
this.methodInfoGenerateAppToken = new grpcWeb.AbstractClientBase.MethodInfo(space_pb.GenerateAppTokenResponse, function (request) { | ||
return request.serializeBinary(); | ||
}, space_pb.GenerateAppTokenResponse.deserializeBinary); | ||
if (!options) | ||
@@ -459,2 +465,18 @@ options = {}; | ||
}; | ||
SpaceApiClient.prototype.initializeMasterAppToken = function (request, metadata, callback) { | ||
if (callback !== undefined) { | ||
return this.client_.rpcCall(this.hostname_ + | ||
'/space.SpaceApi/InitializeMasterAppToken', request, metadata || {}, this.methodInfoInitializeMasterAppToken, callback); | ||
} | ||
return this.client_.unaryCall(this.hostname_ + | ||
'/space.SpaceApi/InitializeMasterAppToken', request, metadata || {}, this.methodInfoInitializeMasterAppToken); | ||
}; | ||
SpaceApiClient.prototype.generateAppToken = function (request, metadata, callback) { | ||
if (callback !== undefined) { | ||
return this.client_.rpcCall(this.hostname_ + | ||
'/space.SpaceApi/GenerateAppToken', request, metadata || {}, this.methodInfoGenerateAppToken, callback); | ||
} | ||
return this.client_.unaryCall(this.hostname_ + | ||
'/space.SpaceApi/GenerateAppToken', request, metadata || {}, this.methodInfoGenerateAppToken); | ||
}; | ||
return SpaceApiClient; | ||
@@ -461,0 +483,0 @@ }()); |
@@ -100,2 +100,4 @@ export interface ListDirectoryPayload { | ||
} | ||
export interface InitializeMasterAppPayload { | ||
} | ||
export interface GetSharedByMeFilesPayload { | ||
@@ -102,0 +104,0 @@ seek: string; |
{ | ||
"name": "@fleekhq/space-client", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/esm/index.js", |
@@ -10,3 +10,3 @@ ![Publish Action Status](https://github.com/FleekHQ/space-client/workflows/Publish/badge.svg?branch=master) | ||
#### Initialaze client | ||
#### Initialize client | ||
> Before initialize the client you need to have the [space-daemon](https://github.com/FleekHQ/space-daemon) up and running. You can find the daemon installation docs [here](https://github.com/FleekHQ/space-daemon#installation) | ||
@@ -142,2 +142,31 @@ | ||
### App Token Authorization | ||
Space Daemon uses a token mechanism to prevent unauthorized clients from calling its methods, as otherwise user keys and files would be exposed. | ||
When using a fresh instance of the daemon where no tokens have been generated, it is possible to call the `InitializeMasterAppToken` method, which generates a fully authorized token (it has permission to call any space-daemon method). This token must be sent through the metadata argument on each subsequent call, otherwise the daemon will return an authorization error. | ||
If you want to grant third-party apps access to a subset of methods after the master token was already generated, space-daemon provides the `GenerateAppToken` method. (WIP. will soon be implemented). | ||
#### App Token Authorization Example | ||
```javascript | ||
const initializeMasterAppTokenRes = await client.initializeMasterAppToken(); | ||
const token = initializeMasterAppTokenRes.getApptoken(); | ||
// token should be stored for later usage... | ||
// The authorized call | ||
await client.openFile( | ||
{path: "some/path"}, | ||
{ | ||
metadata: { | ||
authorization: `AppToken ${token}`, | ||
}, | ||
}, | ||
) | ||
``` | ||
### Space Client API methods | ||
#### class SpaceClient(opts) | ||
@@ -344,7 +373,7 @@ | ||
}); | ||
stream.on('data', (data) => { | ||
console.log('data: ', data); | ||
}); | ||
stream.on('error', (error) => { | ||
@@ -529,3 +558,3 @@ console.error('error: ', error); | ||
}); | ||
console.log(res.getFusedrivemounted()); | ||
@@ -554,3 +583,3 @@ }; | ||
const res = await client.getFuseDriveStatus({}); | ||
console.log(res.getFusedrivemounted()); | ||
@@ -580,3 +609,3 @@ }; | ||
example: | ||
example: | ||
```js | ||
@@ -617,3 +646,3 @@ const subscribeStream = client.subscribe(); | ||
const buckets = res.getBucketsList(); | ||
buckets.forEach((bucket) => { | ||
@@ -652,3 +681,3 @@ console.log('key:', bucket.getKey()); | ||
const threadInfo = res.getThreadinfo(); | ||
console.log('key:', threadInfo.getKey()); | ||
@@ -831,3 +860,3 @@ console.log('addresses:', threadInfo.getAddressesList()); | ||
const asyncFunc = async () => { | ||
await client.handleFilesInvitation({ invitationID: '123-123-123', accept: true }); | ||
@@ -907,3 +936,3 @@ ... | ||
Fetches account storage usage info such as amount of space used locally and in Space, alongside bandwith quotas and limits. | ||
Fetches account storage usage info such as amount of space used locally and in Space, alongside bandwith quotas and limits. | ||
@@ -948,3 +977,3 @@ ```js | ||
Get the stored mnemonic seed. | ||
Get the stored mnemonic seed. | ||
@@ -1275,3 +1304,3 @@ ```js | ||
const res = await client.searchFiles({ query: 'filename' }); | ||
const entriesList = res.getEntriesList(); | ||
@@ -1339,2 +1368,30 @@ | ||
#### .initializeMasterAppToken() | ||
Initializes the daemon with a master app token. This token is required in following requests otherwise they will fail with an unauthorized error. If the daemon already has a master app token, this call will throw. | ||
```js | ||
client | ||
.initializeMasterAppToken() | ||
.then((res) => { | ||
const token = res.getApptoken(); | ||
console.log('token:', token); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
/* Or using Async/Await */ | ||
const asyncFunc = async () => { | ||
const res = await client.initializeMasterAppToken(); | ||
const token = res.getApptoken(); | ||
... | ||
}; | ||
``` | ||
#### .getSharedByMeFiles({ seek: string, limit: number }) | ||
@@ -1341,0 +1398,0 @@ |
@@ -30,2 +30,3 @@ import grpcWeb, { ClientReadableStream } from 'grpc-web'; | ||
SearchFilesPayload, | ||
InitializeMasterAppPayload, | ||
GetSharedByMeFilesPayload, | ||
@@ -104,2 +105,4 @@ } from './types'; | ||
SearchFilesResponse, | ||
InitializeMasterAppTokenResponse, | ||
InitializeMasterAppTokenRequest, | ||
GetSharedByMeFilesRequest, | ||
@@ -975,2 +978,24 @@ GetSharedByMeFilesResponse, | ||
initializeMasterAppToken( | ||
payload: InitializeMasterAppPayload, | ||
metadata: grpcWeb.Metadata = {}, | ||
): Promise<InitializeMasterAppTokenResponse> { | ||
return new Promise((resolve, reject) => { | ||
const request = new InitializeMasterAppTokenRequest(); | ||
this.instance.initializeMasterAppToken( | ||
request, | ||
metadata, | ||
(err: grpcWeb.Error, res: InitializeMasterAppTokenResponse) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(res); | ||
}, | ||
); | ||
}); | ||
} | ||
getSharedByMeFiles( | ||
@@ -977,0 +1002,0 @@ payload: GetSharedByMeFilesPayload, |
@@ -1595,3 +1595,83 @@ /** | ||
methodInfoInitializeMasterAppToken = new grpcWeb.AbstractClientBase.MethodInfo( | ||
space_pb.InitializeMasterAppTokenResponse, | ||
(request: space_pb.InitializeMasterAppTokenRequest) => { | ||
return request.serializeBinary(); | ||
}, | ||
space_pb.InitializeMasterAppTokenResponse.deserializeBinary | ||
); | ||
initializeMasterAppToken( | ||
request: space_pb.InitializeMasterAppTokenRequest, | ||
metadata: grpcWeb.Metadata | null): Promise<space_pb.InitializeMasterAppTokenResponse>; | ||
initializeMasterAppToken( | ||
request: space_pb.InitializeMasterAppTokenRequest, | ||
metadata: grpcWeb.Metadata | null, | ||
callback: (err: grpcWeb.Error, | ||
response: space_pb.InitializeMasterAppTokenResponse) => void): grpcWeb.ClientReadableStream<space_pb.InitializeMasterAppTokenResponse>; | ||
initializeMasterAppToken( | ||
request: space_pb.InitializeMasterAppTokenRequest, | ||
metadata: grpcWeb.Metadata | null, | ||
callback?: (err: grpcWeb.Error, | ||
response: space_pb.InitializeMasterAppTokenResponse) => void) { | ||
if (callback !== undefined) { | ||
return this.client_.rpcCall( | ||
this.hostname_ + | ||
'/space.SpaceApi/InitializeMasterAppToken', | ||
request, | ||
metadata || {}, | ||
this.methodInfoInitializeMasterAppToken, | ||
callback); | ||
} | ||
return this.client_.unaryCall( | ||
this.hostname_ + | ||
'/space.SpaceApi/InitializeMasterAppToken', | ||
request, | ||
metadata || {}, | ||
this.methodInfoInitializeMasterAppToken); | ||
} | ||
methodInfoGenerateAppToken = new grpcWeb.AbstractClientBase.MethodInfo( | ||
space_pb.GenerateAppTokenResponse, | ||
(request: space_pb.GenerateAppTokenRequest) => { | ||
return request.serializeBinary(); | ||
}, | ||
space_pb.GenerateAppTokenResponse.deserializeBinary | ||
); | ||
generateAppToken( | ||
request: space_pb.GenerateAppTokenRequest, | ||
metadata: grpcWeb.Metadata | null): Promise<space_pb.GenerateAppTokenResponse>; | ||
generateAppToken( | ||
request: space_pb.GenerateAppTokenRequest, | ||
metadata: grpcWeb.Metadata | null, | ||
callback: (err: grpcWeb.Error, | ||
response: space_pb.GenerateAppTokenResponse) => void): grpcWeb.ClientReadableStream<space_pb.GenerateAppTokenResponse>; | ||
generateAppToken( | ||
request: space_pb.GenerateAppTokenRequest, | ||
metadata: grpcWeb.Metadata | null, | ||
callback?: (err: grpcWeb.Error, | ||
response: space_pb.GenerateAppTokenResponse) => void) { | ||
if (callback !== undefined) { | ||
return this.client_.rpcCall( | ||
this.hostname_ + | ||
'/space.SpaceApi/GenerateAppToken', | ||
request, | ||
metadata || {}, | ||
this.methodInfoGenerateAppToken, | ||
callback); | ||
} | ||
return this.client_.unaryCall( | ||
this.hostname_ + | ||
'/space.SpaceApi/GenerateAppToken', | ||
request, | ||
metadata || {}, | ||
this.methodInfoGenerateAppToken); | ||
} | ||
} | ||
@@ -129,2 +129,4 @@ export interface ListDirectoryPayload { | ||
export interface InitializeMasterAppPayload {} | ||
export interface GetSharedByMeFilesPayload { | ||
@@ -131,0 +133,0 @@ seek: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2742589
51329
1460