@design-sdk/figma-url 0.0.5 → 0.0.9
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/dist/index.js +0 -1
- package/dist/lib/access-check.d.ts +8 -0
- package/dist/lib/access-check.js +39 -0
- package/dist/lib/analyze-url.d.ts +8 -1
- package/dist/lib/analyze-url.js +38 -2
- package/dist/lib/compare-url.d.ts +1 -0
- package/dist/lib/compare-url.js +19 -0
- package/dist/lib/constants.js +0 -1
- package/dist/lib/embed-url.js +1 -2
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +2 -1
- package/dist/lib/parse-url.js +0 -1
- package/dist/lib/target-node-config.js +0 -1
- package/package.json +10 -4
package/dist/index.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* e.g.
|
|
3
|
+
*
|
|
4
|
+
* - **ok**: (public file) - https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/grida?node-id=1545%3A247
|
|
5
|
+
* - **not found**: (private file) - https://www.figma.com/file/8R57Uv5Siu1ZhhGkVIyyQg/private-file-api-demo?node-id=2%3A2
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare function isPublic(url: string): Promise<boolean>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
///
|
|
3
|
+
/// simple functions to check if file is accessible by public.
|
|
4
|
+
///
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.isPublic = void 0;
|
|
16
|
+
const analyze_url_1 = require("./analyze-url");
|
|
17
|
+
/**
|
|
18
|
+
* e.g.
|
|
19
|
+
*
|
|
20
|
+
* - **ok**: (public file) - https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/grida?node-id=1545%3A247
|
|
21
|
+
* - **not found**: (private file) - https://www.figma.com/file/8R57Uv5Siu1ZhhGkVIyyQg/private-file-api-demo?node-id=2%3A2
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
function isPublic(url) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const type = (0, analyze_url_1.analyze)(url);
|
|
27
|
+
if (type == analyze_url_1.FigmaUrlType.embed || analyze_url_1.FigmaUrlType.file || analyze_url_1.FigmaUrlType.node) {
|
|
28
|
+
try {
|
|
29
|
+
const res = yield fetch(url);
|
|
30
|
+
return res.status == 200;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.isPublic = isPublic;
|
|
@@ -16,4 +16,11 @@ export declare enum FigmaUrlType {
|
|
|
16
16
|
*/
|
|
17
17
|
empty = "empty"
|
|
18
18
|
}
|
|
19
|
-
export declare
|
|
19
|
+
export declare enum FigmaFileOrNodeIdType {
|
|
20
|
+
nodeid = "nodeid",
|
|
21
|
+
maybe_nodeid = "maybe_nodeid",
|
|
22
|
+
fileid = "fileid",
|
|
23
|
+
maybe_fileid = "maybe_fileid"
|
|
24
|
+
}
|
|
25
|
+
export declare type FigmaInputAnalysisResult = FigmaUrlType | FigmaFileOrNodeIdType;
|
|
26
|
+
export declare function analyze(url: string): FigmaInputAnalysisResult;
|
package/dist/lib/analyze-url.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.analyze = exports.FigmaUrlType = void 0;
|
|
3
|
+
exports.analyze = exports.FigmaFileOrNodeIdType = exports.FigmaUrlType = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
var FigmaUrlType;
|
|
6
6
|
(function (FigmaUrlType) {
|
|
@@ -21,6 +21,13 @@ var FigmaUrlType;
|
|
|
21
21
|
*/
|
|
22
22
|
FigmaUrlType["empty"] = "empty";
|
|
23
23
|
})(FigmaUrlType = exports.FigmaUrlType || (exports.FigmaUrlType = {}));
|
|
24
|
+
var FigmaFileOrNodeIdType;
|
|
25
|
+
(function (FigmaFileOrNodeIdType) {
|
|
26
|
+
FigmaFileOrNodeIdType["nodeid"] = "nodeid";
|
|
27
|
+
FigmaFileOrNodeIdType["maybe_nodeid"] = "maybe_nodeid";
|
|
28
|
+
FigmaFileOrNodeIdType["fileid"] = "fileid";
|
|
29
|
+
FigmaFileOrNodeIdType["maybe_fileid"] = "maybe_fileid";
|
|
30
|
+
})(FigmaFileOrNodeIdType = exports.FigmaFileOrNodeIdType || (exports.FigmaFileOrNodeIdType = {}));
|
|
24
31
|
function analyze(url) {
|
|
25
32
|
var _a;
|
|
26
33
|
if (!url) {
|
|
@@ -33,6 +40,36 @@ function analyze(url) {
|
|
|
33
40
|
_u = new URL(url);
|
|
34
41
|
}
|
|
35
42
|
catch (_) {
|
|
43
|
+
const maybeidlike = url;
|
|
44
|
+
if (maybeidlike.length > 0) {
|
|
45
|
+
if (maybeidlike.includes(":") || maybeidlike.includes("%3A")) {
|
|
46
|
+
let _target = maybeidlike;
|
|
47
|
+
// "%3A" is ":" as in url encoding
|
|
48
|
+
if (_target.includes("%3A")) {
|
|
49
|
+
// decode value, assuming it is url encoded
|
|
50
|
+
_target = decodeURI(_target);
|
|
51
|
+
}
|
|
52
|
+
// 2. run regex
|
|
53
|
+
if (_target.match(/[0-9]+:[0-9]+/) !== null) {
|
|
54
|
+
return FigmaFileOrNodeIdType.maybe_nodeid;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// e.g. kLzb7R9xYuuphfX4TssVNe
|
|
58
|
+
// e.g. 4hqwYFw6FKw1njvzEl3VUh
|
|
59
|
+
// fileid is 22 chars at this point.
|
|
60
|
+
else if (maybeidlike.length >= 22) {
|
|
61
|
+
const _taget = decodeURI(maybeidlike);
|
|
62
|
+
// figma file id does not contain special characters. it's like mongodb id
|
|
63
|
+
if (_taget.match(/[a-zA-Z0-9]/) !== null) {
|
|
64
|
+
if (_taget.length == 22) {
|
|
65
|
+
return FigmaFileOrNodeIdType.fileid;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return FigmaFileOrNodeIdType.maybe_fileid;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
36
73
|
throw `this url cannot be analyzed. this is not a valid url string - "${url}"`;
|
|
37
74
|
}
|
|
38
75
|
//
|
|
@@ -60,4 +97,3 @@ function analyze(url) {
|
|
|
60
97
|
}
|
|
61
98
|
}
|
|
62
99
|
exports.analyze = analyze;
|
|
63
|
-
//# sourceMappingURL=analyze-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isSameDesignUrl(url1: string, url2: string): boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSameDesignUrl = void 0;
|
|
4
|
+
const analyze_url_1 = require("./analyze-url");
|
|
5
|
+
const parse_url_1 = require("./parse-url");
|
|
6
|
+
function isSameDesignUrl(url1, url2) {
|
|
7
|
+
const analysis = (0, analyze_url_1.analyze)(url1);
|
|
8
|
+
switch (analysis) {
|
|
9
|
+
case analyze_url_1.FigmaUrlType.embed:
|
|
10
|
+
case analyze_url_1.FigmaUrlType.empty:
|
|
11
|
+
case analyze_url_1.FigmaUrlType.file:
|
|
12
|
+
return false;
|
|
13
|
+
case analyze_url_1.FigmaUrlType.node:
|
|
14
|
+
const parsed = (0, parse_url_1.parseFileAndNodeId)(url1);
|
|
15
|
+
const _this_parsed = (0, parse_url_1.parseFileAndNodeId)(url2);
|
|
16
|
+
return (_this_parsed.file === parsed.file && _this_parsed.node === parsed.node);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.isSameDesignUrl = isSameDesignUrl;
|
package/dist/lib/constants.js
CHANGED
|
@@ -28,4 +28,3 @@ exports.__FIGMA_DEMO_DEFAULT_FILE_ID = "Y0Gh77AqBoHH7dG1GtK3xF";
|
|
|
28
28
|
exports.__FIGMA_DEMO_DEFAULT_FILE_URL = "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/";
|
|
29
29
|
exports.__FIGMA_DEMO_DEFAULT_FILE_NODE_URL = "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=264%3A49";
|
|
30
30
|
// ======================================================================================================
|
|
31
|
-
//# sourceMappingURL=constants.js.map
|
package/dist/lib/embed-url.js
CHANGED
|
@@ -10,7 +10,7 @@ const constants_1 = require("./constants");
|
|
|
10
10
|
*/
|
|
11
11
|
function embed(src) {
|
|
12
12
|
const url = builEmbedableSourceUrl(src);
|
|
13
|
-
const urltype = analyze_url_1.analyze(url);
|
|
13
|
+
const urltype = (0, analyze_url_1.analyze)(url);
|
|
14
14
|
switch (urltype) {
|
|
15
15
|
case analyze_url_1.FigmaUrlType.embed:
|
|
16
16
|
return url;
|
|
@@ -54,4 +54,3 @@ function builEmbedableSourceUrl(src) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
exports.builEmbedableSourceUrl = builEmbedableSourceUrl;
|
|
57
|
-
//# sourceMappingURL=embed-url.js.map
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.js
CHANGED
|
@@ -12,7 +12,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./embed-url"), exports);
|
|
14
14
|
__exportStar(require("./parse-url"), exports);
|
|
15
|
+
__exportStar(require("./access-check"), exports);
|
|
15
16
|
__exportStar(require("./analyze-url"), exports);
|
|
16
17
|
__exportStar(require("./target-node-config"), exports);
|
|
17
18
|
__exportStar(require("./constants"), exports);
|
|
18
|
-
|
|
19
|
+
__exportStar(require("./compare-url"), exports);
|
package/dist/lib/parse-url.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@design-sdk/figma-url",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Figma url utils for sharing & embeding and url inspection",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
6
|
+
"private": false,
|
|
7
7
|
"homepage": "https://github.com/gridaco/design-sdk",
|
|
8
8
|
"repository": "https://github.com/gridaco/design-sdk",
|
|
9
|
+
"authors": [
|
|
10
|
+
"grida.co",
|
|
11
|
+
"softmarshmallow <universe@grida.co>"
|
|
12
|
+
],
|
|
9
13
|
"scripts": {
|
|
10
|
-
"
|
|
14
|
+
"clean": "rimraf dist",
|
|
15
|
+
"build": "yarn clean && tsc",
|
|
11
16
|
"test": "jest"
|
|
12
17
|
},
|
|
13
18
|
"files": [
|
|
@@ -20,5 +25,6 @@
|
|
|
20
25
|
],
|
|
21
26
|
"publishConfig": {
|
|
22
27
|
"access": "public"
|
|
23
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "5cdc27b424066458a502861333d83ebc1960e586"
|
|
24
30
|
}
|