diff --git a/README.md b/README.md index 795792b5..f2e452b5 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ const host = "http://0.0.0.0:6002" // or whatever powergate instance you want const pow = createPow({ host }) ``` -Most Powergate APIs require authorization in the form of a Storage Profile auth token. Storage Profiles are created using the `admin` API. Powergate's backend may be configured to secure the `admin` API with an auth token, and in that case, you'll neeed to set the admin auth token on the client as shown below. +Most Powergate APIs require authorization in the form of a user auth token. Users are created using the `admin` API. Powergate's backend may be configured to secure the `admin` API with an auth token, and in that case, you'll neeed to set the admin auth token on the client as shown below. ```typescript import { createPow } from "@textile/powergate-client" @@ -62,14 +62,14 @@ const pow = createPow({ host }) pow.setAdminToken("") async function exampleCode () { - const { authEntry } = await pow.admin.profiles.createStorageProfile() // save this token for later use! - return authEntry?.token + const { user } = await pow.admin.users.create() // save this token for later use! + return user?.token } ``` -The returned auth token is the only thing that gives access to the corresponding Storage Profile at a later time, so be sure to save it securely. +The returned auth token is the only thing that gives access to the corresponding user at a later time, so be sure to save it securely. -A Storage Profile auth token can later be set for the Powergate client so that the client authenticates with the Storage Profile associated with the auth token. +A user auth token can later be set for the Powergate client so that the client authenticates with the user associated with the auth token. ```typescript import { createPow } from "@textile/powergate-client" @@ -78,7 +78,7 @@ const host = "http://0.0.0.0:6002" // or whatever powergate instance you want const pow = createPow({ host }) -const token = "" +const token = "" pow.setToken(token) ``` @@ -94,10 +94,10 @@ const host = "http://0.0.0.0:6002" // or whatever powergate instance you want const pow = createPow({ host }) async function exampleCode() { - // get wallet addresses associated with your storage profile + // get wallet addresses associated with the user const { addressesList } = await pow.wallet.addresses() - // create a new address associated with your storage profile + // create a new address associated with the user const { address } = await pow.wallet.newAddress("my new address") // get build information about the powergate server @@ -130,10 +130,10 @@ async function exampleCode() { // current storage state, and all related Powegate storage jobs const { cidInfosList } = await pow.data.cidInfo(cid) - // retrieve data stored in the storage profile by cid + // retrieve data stored in the user by cid const bytes = await pow.data.get(cid) - // send FIL from an address managed by your storage profile to any other address + // send FIL from an address managed by the user to any other address await pow.wallet.sendFil(addressesList[0].address, "", BigInt(1000)) } ``` diff --git a/package-lock.json b/package-lock.json index c6d84255..c4e6efb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -562,9 +562,9 @@ } }, "@textile/grpc-powergate-client": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@textile/grpc-powergate-client/-/grpc-powergate-client-1.0.0.tgz", - "integrity": "sha512-TO/mlqdFTqFfemaa/pSd1Dwfw1KoqNW9Zz9JL7yo34C13aWbp9BTUY96dwRyEGROkdMmSl6RmAoa27tDgKjnvg==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@textile/grpc-powergate-client/-/grpc-powergate-client-1.1.0.tgz", + "integrity": "sha512-D0cljQsBYqVBlKiVA0/4mCboZutx7OgYo3nbCxJM7r2EsFkosOQaQGLPxDa0N9dwq5jVOaA7iTYEzr0Cpwsq/A==", "requires": { "@improbable-eng/grpc-web": "^0.13.0", "@types/google-protobuf": "^3.7.4", diff --git a/package.json b/package.json index 4c50ab5d..0872681a 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ } }, "dependencies": { - "@textile/grpc-powergate-client": "1.0.0", + "@textile/grpc-powergate-client": "1.1.0", "@textile/grpc-transport": "0.0.3", "ipfs-http-client": "^47.0.1", "it-block": "^2.0.0" diff --git a/src/admin/index.ts b/src/admin/index.ts index 704f2b17..1d135c61 100644 --- a/src/admin/index.ts +++ b/src/admin/index.ts @@ -1,15 +1,15 @@ import { grpc } from "@improbable-eng/grpc-web" import { Config } from "../types" -import { createProfiles, Profiles } from "./profiles" import { createStorageJobs, StorageJobs } from "./storage-jobs" +import { createUsers, Users } from "./users" import { createWallet, Wallet } from "./wallet" -export { Profiles, StorageJobs, Wallet } +export { Users, StorageJobs, Wallet } export interface Admin { /** - * The admin Profiles API. + * The admin Users API. */ - profiles: Profiles + users: Users /** * The admin Wallet API. @@ -27,7 +27,7 @@ export interface Admin { */ export const createAdmin = (config: Config, getMeta: () => grpc.Metadata): Admin => { return { - profiles: createProfiles(config, getMeta), + users: createUsers(config, getMeta), wallet: createWallet(config, getMeta), storageJobs: createStorageJobs(config, getMeta), } diff --git a/src/admin/profiles.ts b/src/admin/profiles.ts deleted file mode 100644 index cdeccd95..00000000 --- a/src/admin/profiles.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { grpc } from "@improbable-eng/grpc-web" -import { - CreateStorageProfileRequest, - CreateStorageProfileResponse, - StorageProfilesRequest, - StorageProfilesResponse, -} from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb" -import { PowergateAdminServiceClient } from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb_service" -import { Config } from "../types" -import { promise } from "../util" - -export interface Profiles { - /** - * Create a new storage profile. - * @returns Information about the new storage profile. - */ - createStorageProfile: () => Promise - - /** - * List all storage profiles. - * @returns A list of all storage profiles. - */ - storageProfiles: () => Promise -} - -/** - * @ignore - */ -export const createProfiles = (config: Config, getMeta: () => grpc.Metadata): Profiles => { - const client = new PowergateAdminServiceClient(config.host, config) - return { - createStorageProfile: () => { - return promise( - (cb) => client.createStorageProfile(new CreateStorageProfileRequest(), getMeta(), cb), - (resp: CreateStorageProfileResponse) => resp.toObject(), - ) - }, - - storageProfiles: () => - promise( - (cb) => client.storageProfiles(new StorageProfilesRequest(), getMeta(), cb), - (resp: StorageProfilesResponse) => resp.toObject(), - ), - } -} diff --git a/src/admin/storage-jobs.ts b/src/admin/storage-jobs.ts index 5215b20b..c5b53eab 100644 --- a/src/admin/storage-jobs.ts +++ b/src/admin/storage-jobs.ts @@ -10,112 +10,109 @@ import { QueuedStorageJobsResponse, StorageJobsSummaryRequest, StorageJobsSummaryResponse, -} from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb" -import { PowergateAdminServiceClient } from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb_service" +} from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb" +import { AdminServiceClient } from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb_service" import { Config } from "../types" import { promise } from "../util" export interface StorageJobs { /** * List queued storgae jobs. - * @param profileId The storage profile id to query or an empty string for all storage profiles. + * @param userId The user id to query or an empty string for all users. * @param cids An optional list of data cids to fileter the results with. * @returns A list of queued storage jobs. */ - queued: (profileId: string, ...cids: string[]) => Promise + queued: (userId: string, ...cids: string[]) => Promise /** * List executing storgae jobs. - * @param profileId The storage profile id to query or an empty string for all storage profiles. + * @param userId The user id to query or an empty string for all users. * @param cids An optional list of data cids to fileter the results with. * @returns A list of executing storage jobs. */ - executing: ( - profileId: string, - ...cids: string[] - ) => Promise + executing: (userId: string, ...cids: string[]) => Promise /** * List the latest final storgae jobs. - * @param profileId The storage profile id to query or an empty string for all storage profiles. + * @param userId The user id to query or an empty string for all users. * @param cids An optional list of data cids to fileter the results with. * @returns A list of the latest final storage jobs. */ latestFinal: ( - profileId: string, + userId: string, ...cids: string[] ) => Promise /** * List the latest successful storgae jobs. - * @param profileId The storage profile id to query or an empty string for all storage profiles. + * @param userId The user id to query or an empty string for all users. * @param cids An optional list of data cids to fileter the results with. * @returns A list of the latest successful storage jobs. */ latestSuccessful: ( - profileId: string, + userId: string, ...cids: string[] ) => Promise /** * Get a summary of all jobs. - * @param profileId The storage profile id to query or an empty string for all storage profiles. + * @param userId The user id to query or an empty string for all users. * @param cids An optional list of data cids to fileter the results with. * @returns A summary of all jobs. */ - summary: (profileId: string, ...cids: string[]) => Promise + summary: (userId: string, ...cids: string[]) => Promise } /** * @ignore */ export const createStorageJobs = (config: Config, getMeta: () => grpc.Metadata): StorageJobs => { - const client = new PowergateAdminServiceClient(config.host, config) + const client = new AdminServiceClient(config.host, config) return { - queued: (profileId: string, ...cids: string[]) => { + queued: (userId: string, ...cids: string[]) => { const req = new QueuedStorageJobsRequest() req.setCidsList(cids) - req.setProfileId(profileId) + req.setUserId(userId) return promise( (cb) => client.queuedStorageJobs(req, getMeta(), cb), (resp: QueuedStorageJobsResponse) => resp.toObject(), ) }, - executing: (profileId: string, ...cids: string[]) => { + executing: (userId: string, ...cids: string[]) => { const req = new ExecutingStorageJobsRequest() req.setCidsList(cids) - req.setProfileId(profileId) + req.setUserId(userId) return promise( (cb) => client.executingStorageJobs(req, getMeta(), cb), (resp: ExecutingStorageJobsResponse) => resp.toObject(), ) }, - latestFinal: (profileId: string, ...cids: string[]) => { + latestFinal: (userId: string, ...cids: string[]) => { const req = new LatestFinalStorageJobsRequest() req.setCidsList(cids) - req.setProfileId(profileId) + req.setUserId(userId) return promise( (cb) => client.latestFinalStorageJobs(req, getMeta(), cb), (resp: LatestFinalStorageJobsResponse) => resp.toObject(), ) }, - latestSuccessful: (profileId: string, ...cids: string[]) => { + latestSuccessful: (userId: string, ...cids: string[]) => { const req = new LatestSuccessfulStorageJobsRequest() req.setCidsList(cids) - req.setProfileId(profileId) + req.setUserId(userId) return promise( (cb) => client.latestSuccessfulStorageJobs(req, getMeta(), cb), (resp: LatestSuccessfulStorageJobsResponse) => resp.toObject(), ) }, - summary: (profileId: string, ...cids: string[]) => { + summary: (userId: string, ...cids: string[]) => { const req = new StorageJobsSummaryRequest() req.setCidsList(cids) - req.setProfileId(profileId) + req.setUserId(userId) return promise( (cb) => client.storageJobsSummary(req, getMeta(), cb), (resp: StorageJobsSummaryResponse) => resp.toObject(), diff --git a/src/admin/users.ts b/src/admin/users.ts new file mode 100644 index 00000000..b4e469cb --- /dev/null +++ b/src/admin/users.ts @@ -0,0 +1,45 @@ +import { grpc } from "@improbable-eng/grpc-web" +import { + CreateUserRequest, + CreateUserResponse, + UsersRequest, + UsersResponse, +} from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb" +import { AdminServiceClient } from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb_service" +import { Config } from "../types" +import { promise } from "../util" + +export interface Users { + /** + * Create a new user. + * @returns Information about the new user. + */ + create: () => Promise + + /** + * List all users. + * @returns A list of all users. + */ + list: () => Promise +} + +/** + * @ignore + */ +export const createUsers = (config: Config, getMeta: () => grpc.Metadata): Users => { + const client = new AdminServiceClient(config.host, config) + return { + create: () => { + return promise( + (cb) => client.createUser(new CreateUserRequest(), getMeta(), cb), + (resp: CreateUserResponse) => resp.toObject(), + ) + }, + + list: () => + promise( + (cb) => client.users(new UsersRequest(), getMeta(), cb), + (resp: UsersResponse) => resp.toObject(), + ), + } +} diff --git a/src/admin/wallet.ts b/src/admin/wallet.ts index 3d97c1db..59f849a6 100644 --- a/src/admin/wallet.ts +++ b/src/admin/wallet.ts @@ -6,8 +6,8 @@ import { NewAddressResponse, SendFilRequest, SendFilResponse, -} from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb" -import { PowergateAdminServiceClient } from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb_service" +} from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb" +import { AdminServiceClient } from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb_service" import { Config } from "../types" import { promise } from "../util" @@ -38,7 +38,7 @@ export interface Wallet { * @ignore */ export const createWallet = (config: Config, getMeta: () => grpc.Metadata): Wallet => { - const client = new PowergateAdminServiceClient(config.host, config) + const client = new AdminServiceClient(config.host, config) return { newAddress: (type: "bls" | "secp256k1" = "bls") => { const req = new NewAddressRequest() diff --git a/src/data/index.ts b/src/data/index.ts index 5df84c2c..7a7040b1 100644 --- a/src/data/index.ts +++ b/src/data/index.ts @@ -9,11 +9,11 @@ import { StageRequest, StageResponse, WatchLogsRequest, -} from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" +} from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" import { - PowergateService, - PowergateServiceClient, -} from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb_service" + UserService, + UserServiceClient, +} from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb_service" import fs from "fs" import ipfsClient from "ipfs-http-client" import block from "it-block" @@ -52,14 +52,14 @@ export interface Data { replaceData: (cid1: string, cid2: string) => Promise /** - * Retrieve data stored in the current Storage Profile. + * Retrieve data stored by the current user. * @param cid The cid of the data to retrieve. * @returns The raw data. */ get: (cid: string) => Promise /** - * Retrieve a folder stored in the current Storage Profile. + * Retrieve a folder stored stored by the current user. * @param cid The root cid of the folder to retrieve. * @param outputPath The location to write the folder to * @param opts Options controlling the behavior of retrieving the folder @@ -90,7 +90,7 @@ export const createData = ( getMeta: () => grpc.Metadata, getHeaders: () => Record, ): Data => { - const client = new PowergateServiceClient(config.host, config) + const client = new UserServiceClient(config.host, config) const ipfs = ipfsClient(config.host) return { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -98,7 +98,7 @@ export const createData = ( // Only process the first input if there are more than one const source: File | undefined = (await normaliseInput(input).next()).value return new Promise(async (resolve, reject) => { - const client = grpc.client(PowergateService.Stage, config) + const client = grpc.client(UserService.Stage, config) client.onMessage((message) => { resolve(message.toObject() as StageResponse.AsObject) }) diff --git a/src/deals/index.ts b/src/deals/index.ts index 4d2ce556..9eb479c7 100644 --- a/src/deals/index.ts +++ b/src/deals/index.ts @@ -5,8 +5,8 @@ import { RetrievalDealRecordsResponse, StorageDealRecordsRequest, StorageDealRecordsResponse, -} from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" -import { PowergateServiceClient } from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb_service" +} from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" +import { UserServiceClient } from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb_service" import { Config } from "../types" import { promise } from "../util" import { DealRecordsOptions } from "./types" @@ -15,14 +15,14 @@ export { DealRecordsOptions } export interface Deals { /** - * List storage deal records for the Storage Profile according to the provided options. + * List storage deal records for the user according to the provided options. * @param opts Options that control the behavior of listing records. * @returns A list of storage deal records. */ storageDealRecords: (opts?: DealRecordsOptions) => Promise /** - * List retrieval deal records for the Storage Profile according to the provided options. + * List retrieval deal records for the user according to the provided options. * @param opts Options that control the behavior of listing records. * @returns A list of retrieval deal records. */ @@ -35,7 +35,7 @@ export interface Deals { * @ignore */ export const createDeals = (config: Config, getMeta: () => grpc.Metadata): Deals => { - const client = new PowergateServiceClient(config.host, config) + const client = new UserServiceClient(config.host, config) return { storageDealRecords: (opts: DealRecordsOptions = {}) => { const req = new StorageDealRecordsRequest() diff --git a/src/index.ts b/src/index.ts index f579d39b..618568fe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ import { BuildInfoRequest, BuildInfoResponse, - StorageProfileIdentifierRequest, - StorageProfileIdentifierResponse, -} from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" -import { PowergateServiceClient } from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb_service" + UserIdentifierRequest, + UserIdentifierResponse, +} from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" +import { UserServiceClient } from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb_service" import { Admin, createAdmin } from "./admin" import { createData, Data, GetFolderOptions, WatchLogsOptions } from "./data" import { createDeals, DealRecordsOptions, Deals } from "./deals" @@ -14,8 +14,8 @@ import { Config } from "./types" import { getTransport, host, promise, useTokens } from "./util" import { createWallet, Wallet } from "./wallet" -export * as adminTypes from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb" -export * as powTypes from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" +export * as adminTypes from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb" +export * as powTypes from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" export { GetFolderOptions, ApplyOptions, WatchLogsOptions, DealRecordsOptions } export { Config } export { Admin, Data, Deals, StorageConfig, StorageJobs, Wallet } @@ -27,7 +27,7 @@ const defaultConfig: Config = { export interface Pow { /** - * Set the active storage profile auth token + * Set the active user auth token * @param t The token to set */ setToken: (t: string) => void @@ -45,10 +45,10 @@ export interface Pow { buildInfo: () => Promise /** - * Get the storage profile ID. - * @returns A Promise containing the storage profile ID. + * Get the user ID. + * @returns A Promise containing the user ID. */ - storageProfileId: () => Promise + userId: () => Promise /** * The host address the client is using @@ -96,7 +96,7 @@ export const createPow = (config?: Partial): Pow => { const { getMeta, getHeaders, setToken, setAdminToken } = useTokens(c.authToken, c.adminToken) - const client = new PowergateServiceClient(c.host, c) + const client = new UserServiceClient(c.host, c) return { host: c.host, @@ -111,11 +111,10 @@ export const createPow = (config?: Partial): Pow => { (resp: BuildInfoResponse) => resp.toObject(), ), - storageProfileId: () => + userId: () => promise( - (cb) => - client.storageProfileIdentifier(new StorageProfileIdentifierRequest(), getMeta(), cb), - (res: StorageProfileIdentifierResponse) => res.toObject(), + (cb) => client.userIdentifier(new UserIdentifierRequest(), getMeta(), cb), + (res: UserIdentifierResponse) => res.toObject(), ), storageConfig: createStorageConfig(c, getMeta), diff --git a/src/integration.spec.ts b/src/integration.spec.ts index 5f8b3ec1..e1b69923 100644 --- a/src/integration.spec.ts +++ b/src/integration.spec.ts @@ -45,32 +45,32 @@ describe("pow", () => { expect(pow.host).equal(host) }) - it("should get profile id", async () => { + it("should get user id", async () => { const pow = newPow() - await expectNewInstance(pow) - const res = await pow.storageProfileId() + await expectNewUser(pow) + const res = await pow.userId() expect(res.id).not.empty }) describe("admin", () => { - describe("profiles", () => { - it("should create profile", async () => { + describe("users", () => { + it("should create user", async () => { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) }) - it("should list profiles", async () => { + it("should list users", async () => { const pow = newPow() - await expectNewInstance(pow) - const res = await pow.admin.profiles.storageProfiles() - expect(res.authEntriesList).length.greaterThan(0) + await expectNewUser(pow) + const res = await pow.admin.users.list() + expect(res.usersList).length.greaterThan(0) }) }) - describe("profile storage jobs", async () => { + describe("user storage jobs", async () => { it("should get executing", async function () { const pow = newPow() - const auth = await expectNewInstance(pow) + const auth = await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -84,7 +84,7 @@ describe("pow", () => { it("should get latest final", async function () { this.timeout(180000) const pow = newPow() - const auth = await expectNewInstance(pow) + const auth = await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -101,7 +101,7 @@ describe("pow", () => { it("should get latest successful", async function () { this.timeout(180000) const pow = newPow() - const auth = await expectNewInstance(pow) + const auth = await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -119,7 +119,7 @@ describe("pow", () => { it("should get queued", async function () { const pow = newPow() - const auth = await expectNewInstance(pow) + const auth = await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -130,7 +130,7 @@ describe("pow", () => { it("should get summary", async function () { const pow = newPow() - const auth = await expectNewInstance(pow) + const auth = await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -152,7 +152,7 @@ describe("pow", () => { it("should get summary", async function () { this.timeout(180000) const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -196,7 +196,7 @@ describe("pow", () => { it("should get cid info", async function () { this.timeout(180000) const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -229,7 +229,7 @@ describe("pow", () => { it("should get", async function () { this.timeout(180000) const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addrs = await expectAddresses(pow, 1) await waitForBalance(pow, addrs[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -241,7 +241,7 @@ describe("pow", () => { it("should get a folder", async () => { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const res = await pow.data.stageFolder("./sample-data") expect(res).length.greaterThan(0) await pow.data.getFolder(res, "./output", { timeout: 10000 }) @@ -250,7 +250,7 @@ describe("pow", () => { it("should replace", async function () { this.timeout(180000) const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addrs = await expectAddresses(pow, 1) await waitForBalance(pow, addrs[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -264,20 +264,20 @@ describe("pow", () => { it("should stage", async () => { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) await expectStage(pow, crypto.randomBytes(1024)) }) it("should stage folder", async () => { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const res = await pow.data.stageFolder("sample-data") expect(res).not.empty }) it("should watch logs", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const cid = await expectStage(pow, crypto.randomBytes(1024)) const jobId = await expectApplyStorageConfig(pow, cid) const event = await new Promise((resolve) => { @@ -292,7 +292,7 @@ describe("pow", () => { it("should get storage deal records", async function () { this.timeout(180000) const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -312,27 +312,27 @@ describe("pow", () => { describe("storage config", () => { it("should get default", async () => { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) await expectDefaultStorageConfig(pow) }) it("should set default", async () => { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const conf = await expectDefaultStorageConfig(pow) await pow.storageConfig.setDefault(conf) }) it("should apply", async () => { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const cid = await expectStage(pow, crypto.randomBytes(1024)) await expectApplyStorageConfig(pow, cid) }) it("should remove", async () => { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const cid = await expectStage(pow, crypto.randomBytes(1024)) const conf = await expectDefaultStorageConfig(pow) conf.cold = { ...conf.cold, enabled: false } @@ -346,7 +346,7 @@ describe("pow", () => { describe("storage jobs", () => { it("should cancel", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -356,7 +356,7 @@ describe("pow", () => { it("should get executing", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -372,7 +372,7 @@ describe("pow", () => { it("should get latest final", async function () { this.timeout(180000) const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -391,7 +391,7 @@ describe("pow", () => { it("should get latest successful", async function () { this.timeout(180000) const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -409,7 +409,7 @@ describe("pow", () => { it("should get queued", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -420,7 +420,7 @@ describe("pow", () => { it("should get storage config for job", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -431,18 +431,18 @@ describe("pow", () => { it("should get storage job", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) const jobId = await expectApplyStorageConfig(pow, cid) const res = await pow.storageJobs.storageJob(jobId) - expect(res.job?.id).equals(jobId) + expect(res.storageJob?.id).equals(jobId) }) it("should get summary", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -461,7 +461,7 @@ describe("pow", () => { it("should watch", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) const cid = await expectStage(pow, crypto.randomBytes(1024)) @@ -473,20 +473,20 @@ describe("pow", () => { describe("wallet", () => { it("should get addresses", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) await expectAddresses(pow, 1) }) it("should get balance", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) await waitForBalance(pow, addressees[0].address) }) it("should create new address", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const res = await pow.wallet.newAddress("new one") expect(res.address).not.empty }) @@ -494,7 +494,7 @@ describe("pow", () => { it("should send fil", async function () { this.timeout(120000) const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) await pow.wallet.newAddress("new one") const addressees = await expectAddresses(pow, 2) await waitForBalance(pow, addressees[0].address) @@ -505,7 +505,7 @@ describe("pow", () => { it("should sign message", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) const res = await pow.wallet.signMessage(addressees[0].address, crypto.randomBytes(1024)) expect(res.signature).not.empty @@ -513,7 +513,7 @@ describe("pow", () => { it("should verify message signature", async function () { const pow = newPow() - await expectNewInstance(pow) + await expectNewUser(pow) const addressees = await expectAddresses(pow, 1) const message = crypto.randomBytes(1024) const res0 = await pow.wallet.signMessage(addressees[0].address, message) @@ -527,14 +527,14 @@ function newPow(): Pow { return createPow({ host }) } -async function expectNewInstance(pow: Pow) { - const res = await pow.admin.profiles.createStorageProfile() - expect(res.authEntry?.id).not.empty - expect(res.authEntry?.token).not.empty +async function expectNewUser(pow: Pow) { + const res = await pow.admin.users.create() + expect(res.user?.id).not.empty + expect(res.user?.token).not.empty // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - pow.setToken(res.authEntry!.token) + pow.setToken(res.user!.token) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return res.authEntry! + return res.user! } async function expectDefaultStorageConfig(pow: Pow) { diff --git a/src/storage-config/index.ts b/src/storage-config/index.ts index c10578c0..192b28ea 100644 --- a/src/storage-config/index.ts +++ b/src/storage-config/index.ts @@ -9,8 +9,8 @@ import { SetDefaultStorageConfigRequest, SetDefaultStorageConfigResponse, StorageConfig as SConfig, -} from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" -import { PowergateServiceClient } from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb_service" +} from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" +import { UserServiceClient } from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb_service" import { Config } from "../types" import { promise } from "../util" import { ApplyOptions } from "./types" @@ -19,13 +19,13 @@ import { coldObjToMessage, hotObjToMessage } from "./util" export { ApplyOptions } export interface StorageConfig { /** - * Get the default storage config associated with the current storage profile. + * Get the default storage config associated with the current user. * @returns The default storage config. */ default: () => Promise /** - * Set the default storage config for this storage profile. + * Set the default storage config for this user. * @param config The new default storage config. */ setDefault: (config: SConfig.AsObject) => Promise @@ -39,7 +39,7 @@ export interface StorageConfig { apply: (cid: string, opts?: ApplyOptions) => Promise /** - * Remove a cid from the storage profile storage. + * Remove a cid from the user storage. * @param cid The cid to remove. */ remove: (cid: string) => Promise @@ -49,7 +49,7 @@ export const createStorageConfig = ( config: Config, getMeta: () => grpc.Metadata, ): StorageConfig => { - const client = new PowergateServiceClient(config.host, config) + const client = new UserServiceClient(config.host, config) return { default: () => promise( diff --git a/src/storage-config/types.ts b/src/storage-config/types.ts index 3d2b71e9..83aeb953 100644 --- a/src/storage-config/types.ts +++ b/src/storage-config/types.ts @@ -1,4 +1,4 @@ -import { StorageConfig } from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" +import { StorageConfig } from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" /** * Options to control the behavior of pushStorageConfig. diff --git a/src/storage-config/util.ts b/src/storage-config/util.ts index 8dc17db6..18cff0e8 100644 --- a/src/storage-config/util.ts +++ b/src/storage-config/util.ts @@ -4,7 +4,7 @@ import { FilRenew, HotConfig, IpfsConfig, -} from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" +} from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" export function coldObjToMessage(obj: ColdConfig.AsObject): ColdConfig { const cold = new ColdConfig() diff --git a/src/storage-jobs/index.ts b/src/storage-jobs/index.ts index 1888a708..14f5724d 100644 --- a/src/storage-jobs/index.ts +++ b/src/storage-jobs/index.ts @@ -4,7 +4,6 @@ import { CancelStorageJobResponse, ExecutingStorageJobsRequest, ExecutingStorageJobsResponse, - Job, LatestFinalStorageJobsRequest, LatestFinalStorageJobsResponse, LatestSuccessfulStorageJobsRequest, @@ -13,13 +12,14 @@ import { QueuedStorageJobsResponse, StorageConfigForJobRequest, StorageConfigForJobResponse, + StorageJob, StorageJobRequest, StorageJobResponse, StorageJobsSummaryRequest, StorageJobsSummaryResponse, WatchStorageJobsRequest, -} from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" -import { PowergateServiceClient } from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb_service" +} from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" +import { UserServiceClient } from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb_service" import { Config } from "../types" import { promise } from "../util" @@ -39,35 +39,35 @@ export interface StorageJobs { storageConfigForJob: (jobId: string) => Promise /** - * Get queued jobs in the storage profile for the specified cids or all cids. + * Get queued jobs in the user for the specified cids or all cids. * @param cids A list of cids to get jobs for, providing no cids means all cids. * @returns An object containing a list of jobs. */ queued: (...cids: string[]) => Promise /** - * Get executing jobs in the storage profile for the specified cids or all cids. + * Get executing jobs in the user for the specified cids or all cids. * @param cids A list of cids to get jobs for, providing no cids means all cids. * @returns An object containing a list of jobs. */ executing: (...cids: string[]) => Promise /** - * Get the latest final jobs in the storage profile for the specified cids or all cids. + * Get the latest final jobs in the user for the specified cids or all cids. * @param cids A list of cids to get jobs for, providing no cids means all cids. * @returns An object containing a list of jobs. */ latestFinal: (...cids: string[]) => Promise /** - * Get latest successful jobs in the storage profile for the specified cids or all cids. + * Get latest successful jobs in the user for the specified cids or all cids. * @param cids A list of cids to get jobs for, providing no cids means all cids. * @returns An object containing a list of jobs. */ latestSuccessful: (...cids: string[]) => Promise /** - * Get a summary of jobs in the storage profile for the specified cids or all cids. + * Get a summary of jobs in the user for the specified cids or all cids. * @param cids A list of cids to get a job summary for, providing no cids means all cids. * @returns An object containing a summary of jobs. */ @@ -79,7 +79,7 @@ export interface StorageJobs { * @param jobs A list of job ids to watch. * @returns A function that can be used to cancel watching. */ - watch: (handler: (event: Job.AsObject) => void, ...jobs: string[]) => () => void + watch: (handler: (event: StorageJob.AsObject) => void, ...jobs: string[]) => () => void /** * Cancel a job. @@ -92,7 +92,7 @@ export interface StorageJobs { * @ignore */ export const createStorageJobs = (config: Config, getMeta: () => grpc.Metadata): StorageJobs => { - const client = new PowergateServiceClient(config.host, config) + const client = new UserServiceClient(config.host, config) return { storageJob: (jobId: string) => { const req = new StorageJobRequest() @@ -157,12 +157,12 @@ export const createStorageJobs = (config: Config, getMeta: () => grpc.Metadata): ) }, - watch: (handler: (event: Job.AsObject) => void, ...jobs: string[]) => { + watch: (handler: (event: StorageJob.AsObject) => void, ...jobs: string[]) => { const req = new WatchStorageJobsRequest() req.setJobIdsList(jobs) const stream = client.watchStorageJobs(req, getMeta()) stream.on("data", (res) => { - const job = res.getJob()?.toObject() + const job = res.getStorageJob()?.toObject() if (job) { handler(job) } diff --git a/src/test-utils.ts b/src/test-utils.ts deleted file mode 100644 index b966352f..00000000 --- a/src/test-utils.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { CreateStorageProfileResponse } from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb" -import { expect } from "chai" -import { Profiles } from "./admin/profiles" - -export async function expectNewInstance( - p: Profiles, - setToken: (t: string) => void, -): Promise { - const res = await p.createStorageProfile() - expect(res.authEntry?.id).not.empty - expect(res.authEntry?.token).not.empty - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - setToken(res.authEntry!.token) - return res -} - -// async function expectAddrs(length: number) { -// const res = await c.addrs() -// expect(res.addrsList).length(length) -// return res.addrsList -// } - -// async function expectNewAddr() { -// const res = await c.newAddr("my addr") -// expect(res.addr).length.greaterThan(0) -// return res.addr -// } - -// async function expectDefaultStorageConfig() { -// const res = await c.defaultStorageConfig() -// expect(res.defaultStorageConfig).not.undefined -// // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -// return res.defaultStorageConfig! -// } - -// async function expectStage(path: string) { -// const buffer = fs.readFileSync(path) -// const res = await c.stage(buffer) -// expect(res.cid).length.greaterThan(0) -// return res.cid -// } - -// async function expectPushStorageConfig(cid: string, opts?: PushStorageConfigOptions) { -// const res = await c.pushStorageConfig(cid, opts) -// expect(res.jobId).length.greaterThan(0) -// return res.jobId -// } - -// function waitForJobStatus(jobId: string, status: JobStatusMap[keyof JobStatusMap]) { -// return new Promise((resolve, reject) => { -// try { -// const cancel = c.watchJobs((job) => { -// if (job.errCause.length > 0) { -// reject(job.errCause) -// } -// if (job.status === JobStatus.JOB_STATUS_CANCELED) { -// reject("job canceled") -// } -// if (job.status === JobStatus.JOB_STATUS_FAILED) { -// reject("job failed") -// } -// if (job.status === status) { -// cancel() -// resolve() -// } -// }, jobId) -// } catch (e) { -// reject(e) -// } -// }) -// } - -// function waitForBalance(address: string, greaterThan: number) { -// return new Promise(async (resolve, reject) => { -// while (true) { -// try { -// const res = await c.info() -// if (!res.info) { -// reject("no balance info returned") -// return -// } -// const info = res.info.balancesList.find((info) => info.addr?.addr === address) -// if (!info) { -// reject("address not in balances list") -// return -// } -// if (info.balance > greaterThan) { -// resolve(info.balance) -// return -// } -// } catch (e) { -// reject(e) -// } -// await new Promise((r) => setTimeout(r, 1000)) -// } -// }) -// } -// }) diff --git a/src/types.ts b/src/types.ts index db757596..a3baa44c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -10,7 +10,7 @@ export interface Config extends grpc.RpcOptions { host: string /** - * A storage profile auth token + * A user auth token */ authToken?: string diff --git a/src/wallet/index.ts b/src/wallet/index.ts index 70fdcfaa..c0706163 100644 --- a/src/wallet/index.ts +++ b/src/wallet/index.ts @@ -12,8 +12,8 @@ import { SignMessageResponse, VerifyMessageRequest, VerifyMessageResponse, -} from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb" -import { PowergateServiceClient } from "@textile/grpc-powergate-client/dist/proto/powergate/v1/powergate_pb_service" +} from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb" +import { UserServiceClient } from "@textile/grpc-powergate-client/dist/powergate/user/v1/user_pb_service" import { Config } from "../types" import { promise } from "../util" @@ -26,10 +26,10 @@ export interface Wallet { balance: (address: string) => Promise /** - * Create a new wallet address associates with the current storage profile. + * Create a new wallet address associates with the current user. * @param name A human readable name for the address. * @param type Address type, defaults to bls. - * @param makeDefault Specify if the new address should become the default address for this Storage Profile, defaults to false. + * @param makeDefault Specify if the new address should become the default address for this user, defaults to false. * @returns Information about the newly created address. */ newAddress: ( @@ -39,13 +39,13 @@ export interface Wallet { ) => Promise /** - * Get all wallet addresses associated with the current storage profile. + * Get all wallet addresses associated with the current user. * @returns A list of wallet addresses. */ addresses: () => Promise /** - * Send FIL from an address associated with the current storage profile to any other address. + * Send FIL from an address associated with the current user to any other address. * @param from The address to send FIL from. * @param to The address to send FIL to. * @param amount The amount of FIL to send. @@ -78,7 +78,7 @@ export interface Wallet { * @ignore */ export const createWallet = (config: Config, getMeta: () => grpc.Metadata): Wallet => { - const client = new PowergateServiceClient(config.host, config) + const client = new UserServiceClient(config.host, config) return { balance: (address: string) => { const req = new BalanceRequest()