Skip to content

Commit 747b719

Browse files
Update: Documentation and Package Json (#5380)
* updates docs and package json * adds usage docs for SDK * updates contributing docs * updates contributing docs * updates contributing docs * updates contributing docs * updates licence * fixes typo
1 parent 1225968 commit 747b719

File tree

7 files changed

+146
-50
lines changed

7 files changed

+146
-50
lines changed

CLOUD.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Please refer to the [`.env.example` file](./packages/manager/.env.example) in this directory. This will get you started in creating your own `.env` file so you can run the Manager.
66

7-
Your `.env` file should be located in the `packages/manager` directory before your local development server is started.
7+
:rotating_light: Your `.env` file should be located in the `packages/manager` directory before your local development server is started.
88

99
Here are a list of all the required and optional environment variables the Manager uses:
1010

@@ -58,7 +58,7 @@ These are environment variables that can be used for automated testing processes
5858

5959
Once you have a working `.env` file, you can run the following in the root of the project:
6060

61-
`yarn && npx lerna bootstrap --scope linode-manager && npx lerna run start --stream --scope linode-manager`
61+
`yarn up` or `yarn up:manager`
6262

6363
alternatively, with Docker
6464

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The following buzzwords are involved in this project, so please familiarize your
1717
In order to contribute to Linode UI, we recommend the following minimum version numbers:
1818

1919
1. Git v2.19.1
20-
2. Node v8.11.2
20+
2. Node v10.16.0
2121
3. Yarn 1.16.0
2222

2323
You must also have [Lerna](https://lerna.js.org/) installed globally, so please run the following to install the package to your local machine:

GETTING_STARTED.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ To start all projects:
1818
While in the root...
1919
1. Run `yarn` to install all root dependencies.
2020
2. Run `npx lerna bootstrap` to install all package dependencies.
21-
3. Run `npx lerna run start` to start a development server for all projects
22-
* additionally, you can add a `--stream` flag to this command to see the output of the development server.
21+
3. Run `npx lerna run start --parallel` to start a development server for all projects
2322

2423
Alternatively, you can run `yarn up` which runs all previous commands.
2524

@@ -29,9 +28,8 @@ Starting a single project is similar to the previous instructions with the excep
2928

3029
1. Run `yarn` to install all root dependencies.
3130
2. Run `npx lerna bootstrap` to install all package dependencies.
32-
3. Run `npx lerna run start --scope linode-manager` to start a development server for all projects
33-
* additionally, you can add a `--stream` flag to this command to see the output of the development server.
34-
* `linode-manager` is the name located in `packages/manager/package.json`
31+
3. Run `npx lerna run start --scope linode-js-sdk` to start a development server for the JavaScript SDK
32+
* `linode-js-sdk` is the name located in `packages/linode-js-sdk/package.json`
3533

3634
## Helper Scripts
3735

LICENSE

+10-36
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
1-
The following license only applies to source code, defined as any text file
2-
in this repository, not including vector graphics:
1+
Copyright 2019 Linode LLC.
32

4-
Copyright (c) 2016, Linode, LLC
5-
All rights reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
66

7-
Redistribution and use in source and binary forms, with or without
8-
modification, are permitted provided that the following conditions are met:
7+
http://www.apache.org/licenses/LICENSE-2.0
98

10-
1. Redistributions of source code must retain the above copyright notice, this
11-
list of conditions and the following disclaimer.
12-
13-
2. Redistributions in binary form must reproduce the above copyright notice,
14-
this list of conditions and the following disclaimer in the documentation
15-
and/or other materials provided with the distribution.
16-
17-
3. Neither the name of the copyright holder nor the names of its contributors
18-
may be used to endorse or promote products derived from this software without
19-
specific prior written permission.
20-
21-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31-
32-
Other assets (files containing raster and vector graphics) are the proprietary
33-
property of Linode, LLC, and may not be used outside of the context of this
34-
project for any purpose without prior written approval from Linode, LLC.
35-
36-
Some files or assets in this repository are not the intellectual property of
37-
Linode and are included under the terms of the licenses of the owners of that
38-
content. In such cases, such content is accompanied by a LICENSE file in the
39-
same directory explaining the license terms of that content.
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ To get started running Linode UI projects locally, please [see the _Getting Star
2020

2121
If you already have your development environment set up, please read the [contributing guidelines](CONTRIBUTING.md) to get help in making your first PR.
2222

23-
Additionally, you can read our [code conventions](./CODE_CONVENTIONS.md) and [Cloud Manager testing conventions](./TESTING.md) docs for instructions on how write code inline with what we expect.
23+
### I want to contribute to Cloud Manager :heart_eyes:
24+
25+
Along with the contributing guidelines, you can read our [code conventions](./CODE_CONVENTIONS.md) and [Cloud Manager testing conventions](./TESTING.md) docs for instructions on how write code inline with what we expect.
26+
27+
### I want to contribute to the JavaScript SDK :sunglasses:
28+
29+
Amazing! Please check out the documentation in the [SDK directory](./packages/linode-js-sdk/README.md)
2430

2531
## Reaching Out
2632

@@ -34,7 +40,5 @@ action upon feedback.
3440

3541
## License
3642

37-
All code located in this repository is distributed under the terms of the [BSD 3-clause
38-
license](LICENSE). The assets are
39-
not licensed for any purpose without prior written approval from Linode, unless
40-
otherwise noted.
43+
All code located in this repository is distributed under the terms of the [APLv2
44+
license](LICENSE).

packages/linode-js-sdk/README.md

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Linode JavaScript SDK
2+
3+
This directory contains all the code for the client-side wrapper around Linode's APIv4, written in JavaScript
4+
5+
## Installation
6+
7+
To install the project to your app, run
8+
9+
```
10+
$ npm install linode-js-sdk
11+
```
12+
13+
or with yarn
14+
15+
```
16+
$ yarn add linode-js-sdk
17+
```
18+
19+
or with a CDN
20+
21+
```js
22+
<script src="https://unpkg.com/linode-js-sdk/index.js"></script>
23+
```
24+
25+
## Using the SDK
26+
27+
The first step in using the SDK is to authenticate your requests, either with an OAuth Token or Personal Access Token (PAT). Please [see the Linode API docs](https://developers-linode.netlify.com/api/v4/#access-and-authentication) in order to either get an OAuth Token or PAT so that you can authenticate your requests.
28+
29+
Once you have your token, authenticating involves adding headers to each request. This library is built on top of [the Axios HTTP Client](https://github.com/axios/axios), so most features that are built into Axios are fair game here. Here's an example of how to authenticate all of your requests.
30+
31+
```js
32+
/** request.js */
33+
34+
import { baseRequest } from 'linode-js-sdk/lib/request'
35+
36+
/**
37+
* intercepts every request with the following config
38+
* see https://github.com/axios/axios#interceptors for more documentation.
39+
*/
40+
baseRequest.interceptors.request.use(config => {
41+
const myToken = '1234'
42+
43+
return {
44+
...config,
45+
headers: {
46+
...config.headers,
47+
Authorization: `Bearer ${myToken}`
48+
}
49+
};
50+
});
51+
```
52+
53+
```js
54+
/** index.js */
55+
56+
import 'request.js'
57+
import { getAccount } from 'linode-js-sdk/lib/account'
58+
59+
getAccount()
60+
.then(response => {
61+
document.getElementById('root').innerHTML = `<div>${response.data.email}</div>`
62+
})
63+
.catch(e => {
64+
console.error(e)
65+
})
66+
```
67+
68+
## Contributing (To Be Revised for the Public)
69+
70+
The main goal right now is to abstract out all interactions with the API from Cloud Manager and move them into this package. This library will act as a single source for both Cloud Manager and the general public.
71+
72+
Migrating service functions over from Cloud Manager to the JavaScript SDK is relatively straightforward, and involves a few steps.
73+
74+
1. Find a service function you want to move. All of these are located in `/packages/manager/src/services`. For example:
75+
76+
```js
77+
/** packages/manager/src/services/account/account.ts */
78+
79+
/**
80+
* updateAccountInfo
81+
*
82+
* Update your contact or billing information.
83+
*
84+
*/
85+
export const updateAccountInfo = (data: Partial<Linode.Account>) =>
86+
Request<Linode.Account>(
87+
setURL(`${API_ROOT}/account`),
88+
setMethod('PUT'),
89+
setData(data, updateAccountSchema)
90+
).then(response => response.data);
91+
```
92+
93+
2. Since this is an account function, we need to move it to `packages/linode-js-sdk/src/account/account.ts`
94+
95+
3. We also need to make sure that both the Yup Schema and the Type Interfaces are moved over as well.
96+
* The type definition `Linode.Account` will need to be moved to `packages/linode-js-sdk/src/account/types.ts`
97+
* The Yup Schema will need to move to `packages/linode-js-sdk/src/account/account.schema.ts`
98+
99+
4. The final step is removing all this code from Cloud Manager.
100+
* Most of the interfaces for the Linode namespace are located in the `types` directory. In this case, `Linode.Account` is located at `packages/manager/src/types/Account.ts`.
101+
* The schema should be located in the same directory as the service directory for the function you are moving.
102+
103+
After these steps are completed, you'll want to start both the Cloud Manager and Linode JS SDK projects and make sure there are no type errors and that everything is compiling correctly.
104+
105+
## TypeScript
106+
107+
This library comes with TypeScript definitions so no need to write your own or find them elsewhere online. Just import the functions as normal and they should play nicely with TypeScript!

packages/linode-js-sdk/package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
{
22
"name": "linode-js-sdk",
33
"version": "0.2.0",
4+
"homepage": "https://github.com/linode/manager/tree/develop/packages/linode-js-sdk",
5+
"bugs": {
6+
"url": "https://github.com/linode/manager/issues",
7+
"email": "feedback@linode.com"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"directory": "https://github.com/linode/manager/tree/develop/packages/linode-js-sdk"
12+
},
13+
"engines": {
14+
"node": ">= 10.16.0"
15+
},
416
"description": "JavaScript wrapper around the Linode APIv4",
517
"author": "Linode",
618
"license": "MIT",
@@ -27,7 +39,8 @@
2739
"index.js",
2840
"index.d.ts",
2941
"lib/*",
30-
"package.json"
42+
"package.json",
43+
"README.md"
3144
],
3245
"devDependencies": {
3346
"@babel/cli": "^7.5.5",

0 commit comments

Comments
 (0)