7.2.2 • Published 3 years ago
@forcloud/client v7.2.2
@forcloud/client
Usage
import { creatAuthToken } from "@forcloud/auth"
import { Client, uploadFile } from "@forcloud/client"
const authToken = createAuthToken(API_KEY, {
path: "on/$yyyy/$mm/$dd",
expiresIn: "1h",
})
const client = new Client({ authToken, apiOrigin })
const uploadResult = await uploadFile({
client,
file,
onProgress(e) {
console.log(e)
},
})Design Strategy
- Separate auth and client: Keep
@forcloud/authseparate from@forcloud/clientbecause once we've developed a component, we don't need to import@forcloud/clientexplicitly anymore. authTokenoption always provided on Component: When a Component is created that uses Portive, it needs to takeauthTokenas part of its arguments. It is not necessary to takeapiOriginbecause that is only required if you aren't hitting the production endpoint. When an end-developer uses the Component, they will likely never be hitting a non-production endpoint.- Don't pass in Client to Component: Because
authTokenis the only necessary argument, we don't ask the Component user to pass in a Client. It's an unnecessary extra step. - Do have a
Clientobject though. That being said, we do have aClientobject that needs to be created. We have this because it helps the Component developer in these ways:- It's obvious what options should be passed in to the Component. It is all the options on the
Clientobject. For example, it takesauthTokenbut taking anapiOriginas optional and perhaps apathas optional will be really helpful as well. - By forcing the Component developer to create a Client object, it will be more likely that the Component developer will create the Client object during the initialization phase and then all the options will be passed properly whenever an API call is made. For example, let's say we have the
uploadFilecall but also acollaboratecall. We don't want to introduce an error like forgetting to pass theapiOrigintocollaborateeven though we've passed it through touploadFile. After using the options to create a newClient, we don't have to worry about forgetting to pass through correct options through.
- It's obvious what options should be passed in to the Component. It is all the options on the