@sb1/ffe-core 102.0.4 → 102.0.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-core",
3
- "version": "102.0.4",
3
+ "version": "102.0.6",
4
4
  "description": "Rammeverk for Felles Front End",
5
5
  "license": "MIT",
6
6
  "author": "SpareBank 1",
@@ -37,13 +37,13 @@
37
37
  "build-colors": "./scripts/build-colors.cjs"
38
38
  },
39
39
  "devDependencies": {
40
- "@sb1/ffe-buildtool": "^102.0.4",
40
+ "@sb1/ffe-buildtool": "^102.0.6",
41
41
  "case": "^1.6.3",
42
42
  "less": "^4.9.1",
43
- "postcss": "^8.5.29"
43
+ "postcss": "^8.5.31"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "cfdc90c038d41f1bf4451c5960253fed4713d8ea"
48
+ "gitHead": "512d8c1ca541c7b67397056b2a2f8efe9e099377"
49
49
  }
@@ -1,4 +1,3 @@
1
- import axios from 'axios';
2
1
  import {
3
2
  GetLocalVariablesResponse,
4
3
  PostVariablesRequestBody,
@@ -13,29 +12,39 @@ export default class FigmaApi {
13
12
  this.token = token;
14
13
  }
15
14
 
16
- async getLocalVariables(fileKey: string) {
17
- const resp = await axios.request<GetLocalVariablesResponse>({
18
- url: `${this.baseUrl}/v1/files/${fileKey}/variables/local`,
15
+ private async request<T>(path: string, init: RequestInit = {}) {
16
+ const resp = await fetch(`${this.baseUrl}${path}`, {
17
+ ...init,
19
18
  headers: {
20
19
  Accept: '*/*',
21
20
  'X-Figma-Token': this.token,
21
+ ...init.headers,
22
22
  },
23
23
  });
24
24
 
25
- return resp.data;
25
+ if (!resp.ok) {
26
+ throw new Error(
27
+ `Figma API ${init.method ?? 'GET'} ${path} failed: ${resp.status} ${await resp.text()}`,
28
+ );
29
+ }
30
+
31
+ return (await resp.json()) as T;
32
+ }
33
+
34
+ async getLocalVariables(fileKey: string) {
35
+ return this.request<GetLocalVariablesResponse>(
36
+ `/v1/files/${fileKey}/variables/local`,
37
+ );
26
38
  }
27
39
 
28
40
  async postVariables(fileKey: string, payload: PostVariablesRequestBody) {
29
- const resp = await axios.request<PostVariablesResponse>({
30
- url: `${this.baseUrl}/v1/files/${fileKey}/variables`,
31
- method: 'POST',
32
- headers: {
33
- Accept: '*/*',
34
- 'X-Figma-Token': this.token,
41
+ return this.request<PostVariablesResponse>(
42
+ `/v1/files/${fileKey}/variables`,
43
+ {
44
+ method: 'POST',
45
+ headers: { 'Content-Type': 'application/json' },
46
+ body: JSON.stringify(payload),
35
47
  },
36
- data: payload,
37
- });
38
-
39
- return resp.data;
48
+ );
40
49
  }
41
50
  }
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
  import * as fs from 'fs';
3
2
 
4
3
  import FigmaApi from './figma_api';
@@ -17,6 +16,12 @@ import { tokenFilesFromLocalVariables } from './token_export';
17
16
  */
18
17
 
19
18
  async function main() {
19
+ try {
20
+ process.loadEnvFile();
21
+ } catch {
22
+ // .env is optional, the variables can also be set in the environment
23
+ }
24
+
20
25
  if (!process.env.PERSONAL_ACCESS_TOKEN || !process.env.FILE_KEY) {
21
26
  throw new Error(
22
27
  'PERSONAL_ACCESS_TOKEN and FILE_KEY environemnt variables are required',