Skip to content

Commit af2f40d

Browse files
author
Sertaç Karahoda
committed
Initial commit
0 parents  commit af2f40d

17 files changed

+9373
-0
lines changed

.babelrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"presets": [
3+
"@babel/preset-typescript",
4+
[
5+
"@babel/preset-env",
6+
{
7+
"useBuiltIns": "usage",
8+
"corejs": 3
9+
}
10+
]
11+
],
12+
"plugins": [
13+
"@babel/plugin-transform-typescript",
14+
"@babel/proposal-class-properties"
15+
]
16+
}

.github/workflows/publish.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
on:
2+
release:
3+
types:
4+
- published
5+
6+
name: Publish
7+
8+
env:
9+
VERSION: ${{ github.event.release.tag_name }}
10+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
11+
12+
jobs:
13+
publish:
14+
name: Publish
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: SubscriptionCheckout
19+
uses: actions/checkout@v2
20+
21+
- name: Use Node.js 16
22+
uses: actions/setup-node@v2
23+
with:
24+
node-version: '16.0.0'
25+
registry-url: 'https://registry.npmjs.org'
26+
27+
- uses: actions/cache@v2
28+
with:
29+
path: ~/.npm
30+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
31+
restore-keys: |
32+
${{ runner.os }}-node-
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Build package
38+
run: npm run build
39+
40+
- name: Set version
41+
run: npm version $VERSION --no-git-tag-version
42+
43+
- name: Publish
44+
run: npm publish --access public

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea/
2+
3+
dist/
4+
node_modules/
5+
6+
.DS_Store

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!dist/**

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v16.0.0

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Zeplin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Zeplin JavaScript SDK
2+
[![@latest](https://img.shields.io/npm/v/@zeplin/sdk.svg)](https://www.npmjs.com/package/@zeplin/sdk)
3+
[![@latest](https://img.shields.io/npm/l/@zeplin/sdk.svg)](https://www.npmjs.com/package/@zeplin/sdk)
4+
5+
Official JavaScript interface to the [Zeplin API](https://docs.zeplin.dev). It works in both Node.js and web browser environments.
6+
7+
## Installation
8+
9+
```
10+
npm install @zeplin/sdk
11+
```
12+
13+
or
14+
15+
```
16+
yarn add @zeplin/sdk
17+
```
18+
19+
## Getting started
20+
21+
To get started with the SDK, you can create a personal access token from the web app under [Developer](https://app.zeplin.io/profile/developer) tab in your profile page.
22+
23+
You can use this token to make API calls for your own Zeplin account.
24+
25+
```js
26+
import { ZeplinApi, Configuration } "@zeplin/sdk";
27+
28+
const zeplinClient = new ZeplinApi(new Configuration({ accessToken: "ACCESS_TOKEN" }));
29+
30+
const me = await zeplinClient.getCurrentUser();
31+
32+
```
33+
34+
### OAuth
35+
If you want to build an application for other Zeplin users, you can also create a Zeplin app the [profile page](https://app.zeplin.io/profile/developer).
36+
37+
38+
Check out this [example](./examples/oauth-app) to see how you can implement an OAuth flow using the SDK.
39+
40+
## Usage
41+
42+
The SDK exposes Zeplin API endpoints as methods. These methods are grouped into namespace objects by the type of object they interact with.
43+
44+
For example:
45+
```js
46+
import { ZeplinApi, Configuration, ScreenNoteColorNameEnum } "@zeplin/sdk";
47+
48+
const zeplinClient = new ZeplinApi(new Configuration({ accessToken: "ACCESS_TOKEN" }));
49+
50+
// Get colors in the styleguide
51+
zeplinClient.colors.getStyleguideColors("STYLEGUIDE_ID");
52+
53+
// Add a note on the screen
54+
zeplinClient.screens.createScreenNote("PROJECT_ID", "SCREEN_ID", {
55+
content: "Çaylar filiz! :turkish_tea:",
56+
position: { x: 0.1, y: 0.1 },
57+
color: ScreenNoteColorNameEnum.DEEP_PURPLE
58+
});
59+
60+
// Invite a member to the workspace
61+
zeplinClient.organizations.inviteOrganizationMember("ORGANIZATION_ID", {
62+
handle: "rooolan",
63+
role: "editor"
64+
});
65+
```
66+
67+
Check out the [API documentation](https://docs.zeplin.dev/reference) for complete list of endpoints and groups.
68+
69+
## Examples
70+
71+
- [Command-line app using personal access token](./examples/cli-with-personal-access-token)
72+
- [Simple OAuth application](./examples/oauth-app)
73+
74+
## License
75+
76+
The project is available as open source under the terms of the [MIT License](LICENSE).
77+
78+
## Need help?
79+
80+
Ping us at [email protected] for any feedback or questions. You can also find us in the [Zeplin Developer Slack](https://zpl.io/zeplin-dev-slack) group!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# dependencies
2+
/node_modules
3+
4+
# misc
5+
.DS_Store
6+
7+
# debug
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { ZeplinApi, Configuration } = require("@zeplin/sdk");
2+
3+
const accessToken = process.env.ZEPLIN_ACCESS_TOKEN;
4+
5+
const configuration = new Configuration({ accessToken });
6+
7+
const zeplinApi = new ZeplinApi(configuration);
8+
9+
10+
zeplinApi.users.getCurrentUser()
11+
.then(({ data }) => console.log(JSON.stringify(data, null, 2)));
12+
13+
zeplinApi.projects.getProjects({status: "active" })
14+
.then(({ data }) => console.log(JSON.stringify(data, null, 2)));
15+

examples/cli-with-personal-access-token/package-lock.json

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "personal-access-token-example",
3+
"private": true,
4+
"version": "0.0.0",
5+
"description": "Example for personal access token",
6+
"main": "index.js",
7+
"scripts": {
8+
"start": "node index.js"
9+
},
10+
"license": "MIT",
11+
"dependencies": {
12+
"@zeplin/sdk": "../.."
13+
}
14+
}

examples/oauth-app/app.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const express = require("express");
2+
const { ZeplinApi, Configuration } = require("@zeplin/sdk");
3+
4+
const PORT = 3000;
5+
const CLIENT_ID = "CLIENT_ID";
6+
const CLIENT_SECRET = "CLIENT_SECRET";
7+
const REDIRECT_URI = "http://localhost:3000/oauth/callback";
8+
9+
const app = express();
10+
11+
function htmlPage(content) {
12+
return `<!DOCTYPE html>
13+
<html lang="en">
14+
<head>
15+
<meta charset="utf-8">
16+
<title>Zeplin app</title>
17+
</head>
18+
<body>
19+
${content}
20+
</body>
21+
</html>`
22+
}
23+
24+
app.get("/", (req, res) => {
25+
res.set("Content-Type", "text/html");
26+
res.send(
27+
htmlPage(`<p>
28+
Heyo Zepliner! 🙋<br><br>
29+
Click <a href="/oauth/authorize">here</a> to authorize this app.
30+
</p>`)
31+
);
32+
});
33+
34+
app.get("/oauth/authorize", (req, res) => {
35+
const zeplinClient = new ZeplinApi();
36+
37+
res.redirect(zeplinClient.authorization.getAuthorizationUrl({
38+
clientId: CLIENT_ID,
39+
redirectUri: REDIRECT_URI
40+
}));
41+
});
42+
43+
app.get("/oauth/callback", async (req, res) => {
44+
const authCode = req.query.code;
45+
let zeplinClient = new ZeplinApi();
46+
47+
// Create an access token using the authorization code
48+
const { data: tokenData } = await zeplinClient.authorization.createToken({
49+
code: authCode,
50+
clientId: CLIENT_ID,
51+
redirectUri: REDIRECT_URI,
52+
clientSecret: CLIENT_SECRET
53+
});
54+
55+
// Get current user's details
56+
zeplinClient = new ZeplinApi(new Configuration({ accessToken: tokenData.accessToken }))
57+
const { data: userData } = await zeplinClient.users.getCurrentUser();
58+
59+
res.set("Content-Type", "text/html");
60+
res.send(
61+
htmlPage(`<p>
62+
Welcome back, <strong>${userData.username}</strong>! 🙋
63+
</p>`)
64+
);
65+
});
66+
67+
app.listen(PORT, () => {
68+
console.log(`App listening at http://localhost:${PORT}`);
69+
});

0 commit comments

Comments
 (0)