render-lab-tasks-figma 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- render_lab_tasks_figma-0.1.0/.gitignore +11 -0
- render_lab_tasks_figma-0.1.0/LICENSE +21 -0
- render_lab_tasks_figma-0.1.0/PKG-INFO +67 -0
- render_lab_tasks_figma-0.1.0/README.md +54 -0
- render_lab_tasks_figma-0.1.0/pyproject.toml +22 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/__init__.py +1 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/_app.py +3 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/client.py +164 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/export_frame.py +18 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/get_components.py +18 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/get_file.py +18 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/get_file_nodes.py +18 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/get_styles.py +18 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/get_versions.py +18 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/list_comments.py +18 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/post_comment.py +18 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/py.typed +0 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/retry.py +3 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/tasks.py +29 -0
- render_lab_tasks_figma-0.1.0/src/render_lab_tasks_figma/types.py +97 -0
- render_lab_tasks_figma-0.1.0/tests/test_contracts.py +8 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Render Lab
|
|
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.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: render-lab-tasks-figma
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: figma tasks for Render Workflows
|
|
5
|
+
Project-URL: Repository, https://github.com/render-lab/render-tasks-python
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Requires-Dist: httpx<0.29,>=0.28
|
|
10
|
+
Requires-Dist: render-lab-tasks-core<0.2,>=0.1.0
|
|
11
|
+
Requires-Dist: render==1.0.1
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# render-lab-tasks-figma
|
|
15
|
+
|
|
16
|
+
Python port of all 8 registered tasks in the pinned TypeScript pack at
|
|
17
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
18
|
+
|
|
19
|
+
From the repository, install this pack and its supporting core together:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install render-lab-tasks-figma==0.1.0
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Import task definitions from `render_lab_tasks_figma.tasks`. Combine its `app` with
|
|
26
|
+
other pack apps using `Workflows.from_workflows(...)` and call tasks with
|
|
27
|
+
`await ctx.run(task, input)`. Package roots do not register tasks. JSON fields
|
|
28
|
+
retain the TS spelling; Python functions use snake_case.
|
|
29
|
+
|
|
30
|
+
## Tasks
|
|
31
|
+
|
|
32
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `figma.exportFrame` | `export_frame` |
|
|
35
|
+
| `figma.getComponents` | `get_components` |
|
|
36
|
+
| `figma.getFile` | `get_file` |
|
|
37
|
+
| `figma.getFileNodes` | `get_file_nodes` |
|
|
38
|
+
| `figma.getStyles` | `get_styles` |
|
|
39
|
+
| `figma.getVersions` | `get_versions` |
|
|
40
|
+
| `figma.listComments` | `list_comments` |
|
|
41
|
+
| `figma.postComment` | `post_comment` |
|
|
42
|
+
|
|
43
|
+
## Dependencies and retries
|
|
44
|
+
|
|
45
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
46
|
+
module exports typed `Port`, `Deps`, and `Client` classes (also vendor-named aliases).
|
|
47
|
+
Inject a fake port, or pass a caller-owned `httpx.AsyncClient` to `Client` for custom
|
|
48
|
+
transport/configuration. Default dependencies close their HTTP clients after the
|
|
49
|
+
operation. Credentials resolve at first use. HTTP and SDK retries are disabled;
|
|
50
|
+
`retry.py` owns durable retry settings. DTO types live in `.types`.
|
|
51
|
+
|
|
52
|
+
## Environment
|
|
53
|
+
|
|
54
|
+
| Variable | Contract |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `FIGMA_TOKEN` | Required on API calls. |
|
|
57
|
+
|
|
58
|
+
## Verification and limitations
|
|
59
|
+
|
|
60
|
+
Lists preserve the TS single-response behavior, including missing-node filtering and requested-node order. Image exports return URLs, not image bytes.
|
|
61
|
+
|
|
62
|
+
Shared JSON fixtures compare the Python task output with the actual pinned TS
|
|
63
|
+
implementation. REST fixtures also compare HTTP requests; HubSpot and Linear
|
|
64
|
+
fixtures compare source SDK arguments with HTTP payloads/GraphQL variables.
|
|
65
|
+
No live vendor calls were made for this batch. Registered-task parity does not
|
|
66
|
+
claim live readiness or all supporting TS exports. See the root verification
|
|
67
|
+
tracker and docs/porting-batches.md. Licensed under MIT.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# render-lab-tasks-figma
|
|
2
|
+
|
|
3
|
+
Python port of all 8 registered tasks in the pinned TypeScript pack at
|
|
4
|
+
`45f9c2d44bd28e01ae9813e0d2ff56ee6c533816`. Python 3.12+.
|
|
5
|
+
|
|
6
|
+
From the repository, install this pack and its supporting core together:
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pip install render-lab-tasks-figma==0.1.0
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Import task definitions from `render_lab_tasks_figma.tasks`. Combine its `app` with
|
|
13
|
+
other pack apps using `Workflows.from_workflows(...)` and call tasks with
|
|
14
|
+
`await ctx.run(task, input)`. Package roots do not register tasks. JSON fields
|
|
15
|
+
retain the TS spelling; Python functions use snake_case.
|
|
16
|
+
|
|
17
|
+
## Tasks
|
|
18
|
+
|
|
19
|
+
| Registered name | Python export (also exposes `_impl`) |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `figma.exportFrame` | `export_frame` |
|
|
22
|
+
| `figma.getComponents` | `get_components` |
|
|
23
|
+
| `figma.getFile` | `get_file` |
|
|
24
|
+
| `figma.getFileNodes` | `get_file_nodes` |
|
|
25
|
+
| `figma.getStyles` | `get_styles` |
|
|
26
|
+
| `figma.getVersions` | `get_versions` |
|
|
27
|
+
| `figma.listComments` | `list_comments` |
|
|
28
|
+
| `figma.postComment` | `post_comment` |
|
|
29
|
+
|
|
30
|
+
## Dependencies and retries
|
|
31
|
+
|
|
32
|
+
Raw implementations accept context first and keyword-only `deps`. The `.client`
|
|
33
|
+
module exports typed `Port`, `Deps`, and `Client` classes (also vendor-named aliases).
|
|
34
|
+
Inject a fake port, or pass a caller-owned `httpx.AsyncClient` to `Client` for custom
|
|
35
|
+
transport/configuration. Default dependencies close their HTTP clients after the
|
|
36
|
+
operation. Credentials resolve at first use. HTTP and SDK retries are disabled;
|
|
37
|
+
`retry.py` owns durable retry settings. DTO types live in `.types`.
|
|
38
|
+
|
|
39
|
+
## Environment
|
|
40
|
+
|
|
41
|
+
| Variable | Contract |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `FIGMA_TOKEN` | Required on API calls. |
|
|
44
|
+
|
|
45
|
+
## Verification and limitations
|
|
46
|
+
|
|
47
|
+
Lists preserve the TS single-response behavior, including missing-node filtering and requested-node order. Image exports return URLs, not image bytes.
|
|
48
|
+
|
|
49
|
+
Shared JSON fixtures compare the Python task output with the actual pinned TS
|
|
50
|
+
implementation. REST fixtures also compare HTTP requests; HubSpot and Linear
|
|
51
|
+
fixtures compare source SDK arguments with HTTP payloads/GraphQL variables.
|
|
52
|
+
No live vendor calls were made for this batch. Registered-task parity does not
|
|
53
|
+
claim live readiness or all supporting TS exports. See the root verification
|
|
54
|
+
tracker and docs/porting-batches.md. Licensed under MIT.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "render-lab-tasks-figma"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "figma tasks for Render Workflows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
dependencies = ["render==1.0.1", "httpx>=0.28,<0.29", "render-lab-tasks-core>=0.1.0,<0.2"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Repository = "https://github.com/render-lab/render-tasks-python"
|
|
17
|
+
|
|
18
|
+
[tool.uv.sources]
|
|
19
|
+
render-lab-tasks-core = { workspace = true }
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.wheel]
|
|
22
|
+
packages = ["src/render_lab_tasks_figma"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Import .tasks explicitly to register durable tasks."""
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""Injected vendor interface and one-attempt async HTTP adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from collections.abc import AsyncIterator, Mapping
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from typing import Any, Protocol
|
|
10
|
+
|
|
11
|
+
import httpx
|
|
12
|
+
from render_lab_tasks_core.http import HttpClient, enc, nullish, query, required
|
|
13
|
+
|
|
14
|
+
from . import types as t
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def to_comment(raw: Mapping[str, Any]) -> dict[str, Any]:
|
|
18
|
+
return {
|
|
19
|
+
"id": nullish(raw.get("id"), ""),
|
|
20
|
+
"message": nullish(raw.get("message"), ""),
|
|
21
|
+
"user": nullish((raw.get("user") or {}).get("handle"), ""),
|
|
22
|
+
"createdAt": nullish(raw.get("created_at"), ""),
|
|
23
|
+
"resolved": raw.get("resolved_at") is not None,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Port(Protocol):
|
|
28
|
+
async def export_frame(self, input: t.ExportFrameInput) -> t.ExportFrameResult: ...
|
|
29
|
+
async def get_components(self, input: t.GetComponentsInput) -> list[t.FigmaComponent]: ...
|
|
30
|
+
async def get_file(self, input: t.GetFileInput) -> t.FigmaFile: ...
|
|
31
|
+
async def get_file_nodes(self, input: t.GetFileNodesInput) -> t.GetFileNodesResult: ...
|
|
32
|
+
async def get_styles(self, input: t.GetStylesInput) -> list[t.FigmaStyle]: ...
|
|
33
|
+
async def get_versions(self, input: t.GetVersionsInput) -> list[t.FigmaVersion]: ...
|
|
34
|
+
async def list_comments(self, input: t.ListCommentsInput) -> list[t.FigmaComment]: ...
|
|
35
|
+
async def post_comment(self, input: t.PostCommentInput) -> t.FigmaComment: ...
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class Deps:
|
|
40
|
+
figma: Port
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Client:
|
|
44
|
+
def __init__(self, http: httpx.AsyncClient, env: Mapping[str, str] | None = None) -> None:
|
|
45
|
+
self.env = os.environ if env is None else env
|
|
46
|
+
self.http = HttpClient(
|
|
47
|
+
http,
|
|
48
|
+
"https://api.figma.com/v1",
|
|
49
|
+
auth=lambda: {"X-Figma-Token": required(self.env, "FIGMA_TOKEN")},
|
|
50
|
+
label="Figma API",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
async def get_file(self, input: t.GetFileInput) -> Any:
|
|
54
|
+
data = await self.http.call(f"/files/{enc(input['fileKey'])}")
|
|
55
|
+
return {
|
|
56
|
+
**{k: nullish(data.get(k), "") for k in ("name", "lastModified", "version")},
|
|
57
|
+
"documentName": nullish((data.get("document") or {}).get("name"), ""),
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async def export_frame(self, input: t.ExportFrameInput) -> Any:
|
|
61
|
+
format = nullish(input.get("format"), "png")
|
|
62
|
+
scale = nullish(input.get("scale"), 1)
|
|
63
|
+
data = await self.http.call(
|
|
64
|
+
f"/images/{enc(input['fileKey'])}?"
|
|
65
|
+
+ query({"ids": input["nodeId"], "format": format, "scale": scale})
|
|
66
|
+
)
|
|
67
|
+
if (data or {}).get("err"):
|
|
68
|
+
raise RuntimeError(f"Figma image export failed: {data['err']}")
|
|
69
|
+
url = ((data or {}).get("images") or {}).get(input["nodeId"])
|
|
70
|
+
if not url:
|
|
71
|
+
raise RuntimeError(f"Figma image export returned no url for node {input['nodeId']}")
|
|
72
|
+
return {"nodeId": input["nodeId"], "url": url, "format": format}
|
|
73
|
+
|
|
74
|
+
async def list_comments(self, input: t.ListCommentsInput) -> Any:
|
|
75
|
+
data = await self.http.call(f"/files/{enc(input['fileKey'])}/comments")
|
|
76
|
+
rows = (data or {}).get("comments")
|
|
77
|
+
return [to_comment(row) for row in rows] if isinstance(rows, list) else []
|
|
78
|
+
|
|
79
|
+
async def post_comment(self, input: t.PostCommentInput) -> Any:
|
|
80
|
+
body: dict[str, Any] = {"message": input["message"]}
|
|
81
|
+
if "clientMeta" in input:
|
|
82
|
+
body["client_meta"] = input["clientMeta"]
|
|
83
|
+
data = await self.http.call(
|
|
84
|
+
f"/files/{enc(input['fileKey'])}/comments", method="POST", body=body
|
|
85
|
+
)
|
|
86
|
+
return to_comment(data or {})
|
|
87
|
+
|
|
88
|
+
async def get_file_nodes(self, input: t.GetFileNodesInput) -> Any:
|
|
89
|
+
data = await self.http.call(
|
|
90
|
+
f"/files/{enc(input['fileKey'])}/nodes?" + query({"ids": ",".join(input["ids"])})
|
|
91
|
+
)
|
|
92
|
+
nodes = (data or {}).get("nodes") or {}
|
|
93
|
+
result = []
|
|
94
|
+
for id in input["ids"]:
|
|
95
|
+
doc = (nodes.get(id) or {}).get("document")
|
|
96
|
+
if doc is not None:
|
|
97
|
+
result.append({k: nullish(doc.get(k), "") for k in ("id", "name", "type")})
|
|
98
|
+
return {"nodes": result}
|
|
99
|
+
|
|
100
|
+
async def get_components(self, input: t.GetComponentsInput) -> Any:
|
|
101
|
+
data = await self.http.call(f"/files/{enc(input['fileKey'])}/components")
|
|
102
|
+
rows = ((data or {}).get("meta") or {}).get("components")
|
|
103
|
+
return (
|
|
104
|
+
[
|
|
105
|
+
{
|
|
106
|
+
"key": nullish(r.get("key"), ""),
|
|
107
|
+
"name": nullish(r.get("name"), ""),
|
|
108
|
+
"nodeId": nullish(r.get("node_id"), ""),
|
|
109
|
+
"description": nullish(r.get("description"), ""),
|
|
110
|
+
}
|
|
111
|
+
for r in rows
|
|
112
|
+
]
|
|
113
|
+
if isinstance(rows, list)
|
|
114
|
+
else []
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
async def get_styles(self, input: t.GetStylesInput) -> Any:
|
|
118
|
+
data = await self.http.call(f"/files/{enc(input['fileKey'])}/styles")
|
|
119
|
+
rows = ((data or {}).get("meta") or {}).get("styles")
|
|
120
|
+
return (
|
|
121
|
+
[
|
|
122
|
+
{
|
|
123
|
+
"key": nullish(r.get("key"), ""),
|
|
124
|
+
"name": nullish(r.get("name"), ""),
|
|
125
|
+
"styleType": nullish(r.get("style_type"), ""),
|
|
126
|
+
}
|
|
127
|
+
for r in rows
|
|
128
|
+
]
|
|
129
|
+
if isinstance(rows, list)
|
|
130
|
+
else []
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
async def get_versions(self, input: t.GetVersionsInput) -> Any:
|
|
134
|
+
data = await self.http.call(f"/files/{enc(input['fileKey'])}/versions")
|
|
135
|
+
rows = (data or {}).get("versions")
|
|
136
|
+
return (
|
|
137
|
+
[
|
|
138
|
+
{
|
|
139
|
+
"id": nullish(r.get("id"), ""),
|
|
140
|
+
"label": nullish(r.get("label"), ""),
|
|
141
|
+
"createdAt": nullish(r.get("created_at"), ""),
|
|
142
|
+
"user": nullish((r.get("user") or {}).get("handle"), ""),
|
|
143
|
+
}
|
|
144
|
+
for r in rows
|
|
145
|
+
]
|
|
146
|
+
if isinstance(rows, list)
|
|
147
|
+
else []
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@asynccontextmanager
|
|
152
|
+
async def dependencies(deps: Deps | None) -> AsyncIterator[Deps]:
|
|
153
|
+
if deps is not None:
|
|
154
|
+
yield deps
|
|
155
|
+
else:
|
|
156
|
+
async with httpx.AsyncClient(
|
|
157
|
+
timeout=30, transport=httpx.AsyncHTTPTransport(retries=0)
|
|
158
|
+
) as http:
|
|
159
|
+
yield Deps(figma=Client(http))
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
FigmaPort = Port
|
|
163
|
+
FigmaClient = Client
|
|
164
|
+
FigmaDeps = Deps
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import FIGMA_RETRY
|
|
6
|
+
from .types import ExportFrameInput, ExportFrameResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def export_frame_impl(
|
|
10
|
+
ctx: TaskContext, input: ExportFrameInput, *, deps: Deps | None = None
|
|
11
|
+
) -> ExportFrameResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.figma.export_frame(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="figma.exportFrame", retry=FIGMA_RETRY)
|
|
17
|
+
async def export_frame(ctx: TaskContext, input: ExportFrameInput) -> ExportFrameResult:
|
|
18
|
+
return await export_frame_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import FIGMA_RETRY
|
|
6
|
+
from .types import FigmaComponent, GetComponentsInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_components_impl(
|
|
10
|
+
ctx: TaskContext, input: GetComponentsInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[FigmaComponent]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.figma.get_components(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="figma.getComponents", retry=FIGMA_RETRY)
|
|
17
|
+
async def get_components(ctx: TaskContext, input: GetComponentsInput) -> list[FigmaComponent]:
|
|
18
|
+
return await get_components_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import FIGMA_RETRY
|
|
6
|
+
from .types import FigmaFile, GetFileInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_file_impl(
|
|
10
|
+
ctx: TaskContext, input: GetFileInput, *, deps: Deps | None = None
|
|
11
|
+
) -> FigmaFile:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.figma.get_file(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="figma.getFile", retry=FIGMA_RETRY)
|
|
17
|
+
async def get_file(ctx: TaskContext, input: GetFileInput) -> FigmaFile:
|
|
18
|
+
return await get_file_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import FIGMA_RETRY
|
|
6
|
+
from .types import GetFileNodesInput, GetFileNodesResult
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_file_nodes_impl(
|
|
10
|
+
ctx: TaskContext, input: GetFileNodesInput, *, deps: Deps | None = None
|
|
11
|
+
) -> GetFileNodesResult:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.figma.get_file_nodes(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="figma.getFileNodes", retry=FIGMA_RETRY)
|
|
17
|
+
async def get_file_nodes(ctx: TaskContext, input: GetFileNodesInput) -> GetFileNodesResult:
|
|
18
|
+
return await get_file_nodes_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import FIGMA_RETRY
|
|
6
|
+
from .types import FigmaStyle, GetStylesInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_styles_impl(
|
|
10
|
+
ctx: TaskContext, input: GetStylesInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[FigmaStyle]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.figma.get_styles(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="figma.getStyles", retry=FIGMA_RETRY)
|
|
17
|
+
async def get_styles(ctx: TaskContext, input: GetStylesInput) -> list[FigmaStyle]:
|
|
18
|
+
return await get_styles_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import FIGMA_RETRY
|
|
6
|
+
from .types import FigmaVersion, GetVersionsInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def get_versions_impl(
|
|
10
|
+
ctx: TaskContext, input: GetVersionsInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[FigmaVersion]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.figma.get_versions(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="figma.getVersions", retry=FIGMA_RETRY)
|
|
17
|
+
async def get_versions(ctx: TaskContext, input: GetVersionsInput) -> list[FigmaVersion]:
|
|
18
|
+
return await get_versions_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import FIGMA_RETRY
|
|
6
|
+
from .types import FigmaComment, ListCommentsInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def list_comments_impl(
|
|
10
|
+
ctx: TaskContext, input: ListCommentsInput, *, deps: Deps | None = None
|
|
11
|
+
) -> list[FigmaComment]:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.figma.list_comments(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="figma.listComments", retry=FIGMA_RETRY)
|
|
17
|
+
async def list_comments(ctx: TaskContext, input: ListCommentsInput) -> list[FigmaComment]:
|
|
18
|
+
return await list_comments_impl(ctx, input)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from render import TaskContext
|
|
2
|
+
|
|
3
|
+
from ._app import app
|
|
4
|
+
from .client import Deps, dependencies
|
|
5
|
+
from .retry import FIGMA_RETRY
|
|
6
|
+
from .types import FigmaComment, PostCommentInput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def post_comment_impl(
|
|
10
|
+
ctx: TaskContext, input: PostCommentInput, *, deps: Deps | None = None
|
|
11
|
+
) -> FigmaComment:
|
|
12
|
+
async with dependencies(deps) as resolved:
|
|
13
|
+
return await resolved.figma.post_comment(input)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.task(name="figma.postComment", retry=FIGMA_RETRY)
|
|
17
|
+
async def post_comment(ctx: TaskContext, input: PostCommentInput) -> FigmaComment:
|
|
18
|
+
return await post_comment_impl(ctx, input)
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from ._app import app
|
|
2
|
+
from .export_frame import export_frame, export_frame_impl
|
|
3
|
+
from .get_components import get_components, get_components_impl
|
|
4
|
+
from .get_file import get_file, get_file_impl
|
|
5
|
+
from .get_file_nodes import get_file_nodes, get_file_nodes_impl
|
|
6
|
+
from .get_styles import get_styles, get_styles_impl
|
|
7
|
+
from .get_versions import get_versions, get_versions_impl
|
|
8
|
+
from .list_comments import list_comments, list_comments_impl
|
|
9
|
+
from .post_comment import post_comment, post_comment_impl
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"app",
|
|
13
|
+
"export_frame",
|
|
14
|
+
"export_frame_impl",
|
|
15
|
+
"get_components",
|
|
16
|
+
"get_components_impl",
|
|
17
|
+
"get_file",
|
|
18
|
+
"get_file_impl",
|
|
19
|
+
"get_file_nodes",
|
|
20
|
+
"get_file_nodes_impl",
|
|
21
|
+
"get_styles",
|
|
22
|
+
"get_styles_impl",
|
|
23
|
+
"get_versions",
|
|
24
|
+
"get_versions_impl",
|
|
25
|
+
"list_comments",
|
|
26
|
+
"list_comments_impl",
|
|
27
|
+
"post_comment",
|
|
28
|
+
"post_comment_impl",
|
|
29
|
+
]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""JSON contracts ported from the pinned TypeScript pack."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Literal, NotRequired, TypedDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FigmaFile(TypedDict):
|
|
9
|
+
name: str
|
|
10
|
+
lastModified: str
|
|
11
|
+
version: str
|
|
12
|
+
documentName: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class GetFileInput(TypedDict):
|
|
16
|
+
fileKey: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ExportFrameInput(TypedDict):
|
|
20
|
+
fileKey: str
|
|
21
|
+
nodeId: str
|
|
22
|
+
format: NotRequired[Literal["png"] | Literal["svg"] | Literal["jpg"] | Literal["pdf"]]
|
|
23
|
+
scale: NotRequired[float]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ExportFrameResult(TypedDict):
|
|
27
|
+
nodeId: str
|
|
28
|
+
url: str
|
|
29
|
+
format: str
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ListCommentsInput(TypedDict):
|
|
33
|
+
fileKey: str
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class FigmaComment(TypedDict):
|
|
37
|
+
id: str
|
|
38
|
+
message: str
|
|
39
|
+
user: str
|
|
40
|
+
createdAt: str
|
|
41
|
+
resolved: bool
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
type FigmaClientMeta = dict[str, Any]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class PostCommentInput(TypedDict):
|
|
48
|
+
fileKey: str
|
|
49
|
+
message: str
|
|
50
|
+
clientMeta: NotRequired[FigmaClientMeta]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class FigmaNode(TypedDict):
|
|
54
|
+
id: str
|
|
55
|
+
name: str
|
|
56
|
+
type: str
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class GetFileNodesInput(TypedDict):
|
|
60
|
+
fileKey: str
|
|
61
|
+
ids: list[str]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class GetFileNodesResult(TypedDict):
|
|
65
|
+
nodes: list[FigmaNode]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class GetComponentsInput(TypedDict):
|
|
69
|
+
fileKey: str
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class FigmaComponent(TypedDict):
|
|
73
|
+
key: str
|
|
74
|
+
name: str
|
|
75
|
+
nodeId: str
|
|
76
|
+
description: str
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class GetStylesInput(TypedDict):
|
|
80
|
+
fileKey: str
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class FigmaStyle(TypedDict):
|
|
84
|
+
key: str
|
|
85
|
+
name: str
|
|
86
|
+
styleType: str
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class GetVersionsInput(TypedDict):
|
|
90
|
+
fileKey: str
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class FigmaVersion(TypedDict):
|
|
94
|
+
id: str
|
|
95
|
+
label: str
|
|
96
|
+
createdAt: str
|
|
97
|
+
user: str
|