kintone-plugin-ide 0.3.0 → 0.3.1
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/LICENSE +21 -21
- package/README.md +123 -123
- package/dist/index.js +1 -1
- package/dist/kintone-plugin-ide.iife.js +1 -1
- package/package.json +59 -59
- package/src/build/build.js +87 -87
- package/src/build/http-plugin.js +32 -32
- package/src/build/transformers.js +168 -168
- package/src/build/vfs-plugin.js +60 -60
- package/src/config.js +58 -58
- package/src/deps.js +41 -41
- package/src/ide/actions/misc.js +74 -74
- package/src/ide/actions/npm.js +103 -103
- package/src/ide/actions/release.js +57 -57
- package/src/ide/actions/save.js +54 -54
- package/src/ide/actions/zip.js +59 -59
- package/src/ide/commands.js +96 -96
- package/src/ide/css.js +50 -50
- package/src/ide/dialog.js +51 -51
- package/src/ide/editor.js +155 -155
- package/src/ide/index.js +94 -94
- package/src/ide/layout.js +89 -89
- package/src/ide/sample.js +168 -168
- package/src/ide/state.js +58 -58
- package/src/ide/terminal.js +57 -57
- package/src/ide/tree.js +224 -224
- package/src/ide/workspace-fs.js +173 -173
- package/src/index.js +48 -48
- package/src/kintone/api.js +24 -24
- package/src/kintone/plugin.js +37 -37
- package/src/npm/registry.js +32 -32
- package/src/npm/vendor.js +69 -69
- package/src/packer/packer.js +50 -50
- package/src/util/bytes.js +15 -15
- package/src/util/dom.js +15 -15
- package/src/util/idb.js +18 -18
- package/src/util/path.js +14 -14
- package/src/util/settings.js +5 -5
- package/types/index.d.ts +49 -49
package/src/npm/registry.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { CONFIG } from '../config.js';
|
|
2
|
-
|
|
3
|
-
// "@scope/name/sub/path" → { name: "@scope/name", sub: "/sub/path" }
|
|
4
|
-
export function parseSpecifier(spec) {
|
|
5
|
-
const parts = spec.split('/');
|
|
6
|
-
const n = spec.startsWith('@') ? 2 : 1;
|
|
7
|
-
return { name: parts.slice(0, n).join('/'), sub: parts.length > n ? '/' + parts.slice(n).join('/') : '' };
|
|
8
|
-
}
|
|
9
|
-
// "dayjs@^1.11" / "@kintone/rest-api-client" → { name, range }
|
|
10
|
-
export function parseInstallArg(arg) {
|
|
11
|
-
const at = arg.lastIndexOf('@');
|
|
12
|
-
return at > 0 ? { name: arg.slice(0, at), range: arg.slice(at + 1) } : { name: arg, range: '' };
|
|
13
|
-
}
|
|
14
|
-
export function readPackageJson(files) {
|
|
15
|
-
if (!files.has('package.json')) return { name: 'kintone-plugin', private: true, dependencies: {} };
|
|
16
|
-
try { const j = JSON.parse(files.get('package.json')); j.dependencies ??= {}; return j; } catch (e) { throw new Error('package.json がJSONとして読めません: ' + e.message); }
|
|
17
|
-
}
|
|
18
|
-
export async function registryInfo(name, tag = 'latest') {
|
|
19
|
-
const res = await fetch(`${CONFIG.CDN.registry}/${name.replace('/', '%2f')}/${encodeURIComponent(tag)}`);
|
|
20
|
-
if (res.status === 404) throw new Error(`npm に ${name}${tag !== 'latest' ? '@' + tag : ''} が見つかりません`);
|
|
21
|
-
if (!res.ok) throw new Error(`npm registry: ${res.status}`);
|
|
22
|
-
return res.json();
|
|
23
|
-
}
|
|
24
|
-
// dist-tag か完全なバージョンなら registry に聞いて "^x.y.z" にする。範囲指定(^1.2 など)はそのまま
|
|
25
|
-
export async function resolveRange(name, range) {
|
|
26
|
-
if (range && /[\^~><=*x| ]/.test(range)) return range;
|
|
27
|
-
const { version } = await registryInfo(name, range || 'latest');
|
|
28
|
-
return range ? version : `^${version}`;
|
|
29
|
-
}
|
|
30
|
-
// shared: 依存を抱え込まない版(esm.sh が分けたモジュールを URL で共有する)
|
|
31
|
-
export const npmUrl = (name, range, sub = '', { shared = false } = {}) =>
|
|
32
|
-
`${CONFIG.CDN.npm}/${name}${range ? '@' + range : ''}${sub}${/\.css$/.test(sub) ? '' : shared ? '?target=es2020' : '?target=es2020&bundle'}`;
|
|
1
|
+
import { CONFIG } from '../config.js';
|
|
2
|
+
|
|
3
|
+
// "@scope/name/sub/path" → { name: "@scope/name", sub: "/sub/path" }
|
|
4
|
+
export function parseSpecifier(spec) {
|
|
5
|
+
const parts = spec.split('/');
|
|
6
|
+
const n = spec.startsWith('@') ? 2 : 1;
|
|
7
|
+
return { name: parts.slice(0, n).join('/'), sub: parts.length > n ? '/' + parts.slice(n).join('/') : '' };
|
|
8
|
+
}
|
|
9
|
+
// "dayjs@^1.11" / "@kintone/rest-api-client" → { name, range }
|
|
10
|
+
export function parseInstallArg(arg) {
|
|
11
|
+
const at = arg.lastIndexOf('@');
|
|
12
|
+
return at > 0 ? { name: arg.slice(0, at), range: arg.slice(at + 1) } : { name: arg, range: '' };
|
|
13
|
+
}
|
|
14
|
+
export function readPackageJson(files) {
|
|
15
|
+
if (!files.has('package.json')) return { name: 'kintone-plugin', private: true, dependencies: {} };
|
|
16
|
+
try { const j = JSON.parse(files.get('package.json')); j.dependencies ??= {}; return j; } catch (e) { throw new Error('package.json がJSONとして読めません: ' + e.message); }
|
|
17
|
+
}
|
|
18
|
+
export async function registryInfo(name, tag = 'latest') {
|
|
19
|
+
const res = await fetch(`${CONFIG.CDN.registry}/${name.replace('/', '%2f')}/${encodeURIComponent(tag)}`);
|
|
20
|
+
if (res.status === 404) throw new Error(`npm に ${name}${tag !== 'latest' ? '@' + tag : ''} が見つかりません`);
|
|
21
|
+
if (!res.ok) throw new Error(`npm registry: ${res.status}`);
|
|
22
|
+
return res.json();
|
|
23
|
+
}
|
|
24
|
+
// dist-tag か完全なバージョンなら registry に聞いて "^x.y.z" にする。範囲指定(^1.2 など)はそのまま
|
|
25
|
+
export async function resolveRange(name, range) {
|
|
26
|
+
if (range && /[\^~><=*x| ]/.test(range)) return range;
|
|
27
|
+
const { version } = await registryInfo(name, range || 'latest');
|
|
28
|
+
return range ? version : `^${version}`;
|
|
29
|
+
}
|
|
30
|
+
// shared: 依存を抱え込まない版(esm.sh が分けたモジュールを URL で共有する)
|
|
31
|
+
export const npmUrl = (name, range, sub = '', { shared = false } = {}) =>
|
|
32
|
+
`${CONFIG.CDN.npm}/${name}${range ? '@' + range : ''}${sub}${/\.css$/.test(sub) ? '' : shared ? '?target=es2020' : '?target=es2020&bundle'}`;
|
package/src/npm/vendor.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
// npm のパッケージを esm.sh から取ってきて、1ファイルの ES モジュールにして node_modules/ に置く。
|
|
2
|
-
// node_modules/<name>/package.json { name, version, module: "index.mjs" }
|
|
3
|
-
// node_modules/<name>/index.mjs 本体(依存も全部入り)
|
|
4
|
-
// node_modules/<name>/<sub>.mjs "dayjs/plugin/utc" のようなサブパス(使った時に取ってくる)
|
|
5
|
-
// 取ってきたものは IndexedDB に name@version 単位でキャッシュするので、2回目からは通信しない。
|
|
6
|
-
import { NODE_MODULES, SHARED_RUNTIMES } from '../config.js';
|
|
7
|
-
import { loadEsbuild } from '../deps.js';
|
|
8
|
-
import { httpPlugin } from '../build/http-plugin.js';
|
|
9
|
-
import { idbGet, idbSet } from '../util/idb.js';
|
|
10
|
-
import { npmUrl } from './registry.js';
|
|
11
|
-
|
|
12
|
-
export const pkgDir = (name) => `${NODE_MODULES}${name}/`;
|
|
13
|
-
export const subFile = (name, sub) => `${pkgDir(name)}${sub.slice(1)}${/\.(css|mjs|js)$/.test(sub) ? '' : '.mjs'}`;
|
|
14
|
-
|
|
15
|
-
// range("^1.11.0")を esm.sh に解決させて、実際のバージョンを知る
|
|
16
|
-
async function exactVersion(name, range) {
|
|
17
|
-
const res = await fetch(npmUrl(name, range));
|
|
18
|
-
if (!res.ok) throw new Error(`${name}@${range || 'latest'} を取得できません (${res.status})`);
|
|
19
|
-
const text = await res.text();
|
|
20
|
-
const m = text.match(new RegExp(`/${name.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')}@([^/]+)/`));
|
|
21
|
-
return m ? m[1] : range;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function bundle(url, log) {
|
|
25
|
-
const es = await loadEsbuild();
|
|
26
|
-
const r = await es.build({
|
|
27
|
-
entryPoints: [url], bundle: true, write: false, format: 'esm', target: 'es2020',
|
|
28
|
-
logLevel: 'silent', legalComments: 'inline', plugins: [httpPlugin(log)],
|
|
29
|
-
});
|
|
30
|
-
return r.outputFiles[0].text;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// → [[path, text], ...]
|
|
34
|
-
export async function fetchPackage(name, range, log, { force = false } = {}) {
|
|
35
|
-
const version = await exactVersion(name, range);
|
|
36
|
-
if (SHARED_RUNTIMES.test(name)) {
|
|
37
|
-
// 印だけ置く。中身はビルドの時に esm.sh から分割されたまま読み、ブラウザにキャッシュする
|
|
38
|
-
return { version, entries: [[`${pkgDir(name)}package.json`, JSON.stringify({ name, version, _range: range, _from: `esm.sh/${name}@${version}`, _note: 'ランタイムを共有するパッケージなので、ここには置かずビルド時に esm.sh から読みます' }, null, 2) + '\n']] };
|
|
39
|
-
}
|
|
40
|
-
const key = `npm:${name}@${version}`;
|
|
41
|
-
let main = force ? undefined : await idbGet(key);
|
|
42
|
-
if (main === undefined) {
|
|
43
|
-
log.info(`${name}@${version} を取得しています...`);
|
|
44
|
-
main = await bundle(npmUrl(name, version), log);
|
|
45
|
-
await idbSet(key, main);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
version,
|
|
49
|
-
entries: [
|
|
50
|
-
[`${pkgDir(name)}package.json`, JSON.stringify({ name, version, type: 'module', module: 'index.mjs', _range: range, _from: `esm.sh/${name}@${version}` }, null, 2) + '\n'],
|
|
51
|
-
[`${pkgDir(name)}index.mjs`, main],
|
|
52
|
-
],
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function fetchSubpath(name, version, sub, log) {
|
|
57
|
-
const key = `npm:${name}@${version}${sub}`;
|
|
58
|
-
let text = await idbGet(key);
|
|
59
|
-
if (text === undefined) {
|
|
60
|
-
log.info(`${name}${sub} を取得しています...`);
|
|
61
|
-
if (/\.css$/.test(sub)) {
|
|
62
|
-
const res = await fetch(npmUrl(name, version, sub));
|
|
63
|
-
if (!res.ok) throw new Error(`${name}${sub} を取得できません (${res.status})`);
|
|
64
|
-
text = await res.text();
|
|
65
|
-
} else text = await bundle(npmUrl(name, version, sub), log);
|
|
66
|
-
await idbSet(key, text);
|
|
67
|
-
}
|
|
68
|
-
return [subFile(name, sub), text];
|
|
69
|
-
}
|
|
1
|
+
// npm のパッケージを esm.sh から取ってきて、1ファイルの ES モジュールにして node_modules/ に置く。
|
|
2
|
+
// node_modules/<name>/package.json { name, version, module: "index.mjs" }
|
|
3
|
+
// node_modules/<name>/index.mjs 本体(依存も全部入り)
|
|
4
|
+
// node_modules/<name>/<sub>.mjs "dayjs/plugin/utc" のようなサブパス(使った時に取ってくる)
|
|
5
|
+
// 取ってきたものは IndexedDB に name@version 単位でキャッシュするので、2回目からは通信しない。
|
|
6
|
+
import { NODE_MODULES, SHARED_RUNTIMES } from '../config.js';
|
|
7
|
+
import { loadEsbuild } from '../deps.js';
|
|
8
|
+
import { httpPlugin } from '../build/http-plugin.js';
|
|
9
|
+
import { idbGet, idbSet } from '../util/idb.js';
|
|
10
|
+
import { npmUrl } from './registry.js';
|
|
11
|
+
|
|
12
|
+
export const pkgDir = (name) => `${NODE_MODULES}${name}/`;
|
|
13
|
+
export const subFile = (name, sub) => `${pkgDir(name)}${sub.slice(1)}${/\.(css|mjs|js)$/.test(sub) ? '' : '.mjs'}`;
|
|
14
|
+
|
|
15
|
+
// range("^1.11.0")を esm.sh に解決させて、実際のバージョンを知る
|
|
16
|
+
async function exactVersion(name, range) {
|
|
17
|
+
const res = await fetch(npmUrl(name, range));
|
|
18
|
+
if (!res.ok) throw new Error(`${name}@${range || 'latest'} を取得できません (${res.status})`);
|
|
19
|
+
const text = await res.text();
|
|
20
|
+
const m = text.match(new RegExp(`/${name.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')}@([^/]+)/`));
|
|
21
|
+
return m ? m[1] : range;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function bundle(url, log) {
|
|
25
|
+
const es = await loadEsbuild();
|
|
26
|
+
const r = await es.build({
|
|
27
|
+
entryPoints: [url], bundle: true, write: false, format: 'esm', target: 'es2020',
|
|
28
|
+
logLevel: 'silent', legalComments: 'inline', plugins: [httpPlugin(log)],
|
|
29
|
+
});
|
|
30
|
+
return r.outputFiles[0].text;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// → [[path, text], ...]
|
|
34
|
+
export async function fetchPackage(name, range, log, { force = false } = {}) {
|
|
35
|
+
const version = await exactVersion(name, range);
|
|
36
|
+
if (SHARED_RUNTIMES.test(name)) {
|
|
37
|
+
// 印だけ置く。中身はビルドの時に esm.sh から分割されたまま読み、ブラウザにキャッシュする
|
|
38
|
+
return { version, entries: [[`${pkgDir(name)}package.json`, JSON.stringify({ name, version, _range: range, _from: `esm.sh/${name}@${version}`, _note: 'ランタイムを共有するパッケージなので、ここには置かずビルド時に esm.sh から読みます' }, null, 2) + '\n']] };
|
|
39
|
+
}
|
|
40
|
+
const key = `npm:${name}@${version}`;
|
|
41
|
+
let main = force ? undefined : await idbGet(key);
|
|
42
|
+
if (main === undefined) {
|
|
43
|
+
log.info(`${name}@${version} を取得しています...`);
|
|
44
|
+
main = await bundle(npmUrl(name, version), log);
|
|
45
|
+
await idbSet(key, main);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
version,
|
|
49
|
+
entries: [
|
|
50
|
+
[`${pkgDir(name)}package.json`, JSON.stringify({ name, version, type: 'module', module: 'index.mjs', _range: range, _from: `esm.sh/${name}@${version}` }, null, 2) + '\n'],
|
|
51
|
+
[`${pkgDir(name)}index.mjs`, main],
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function fetchSubpath(name, version, sub, log) {
|
|
57
|
+
const key = `npm:${name}@${version}${sub}`;
|
|
58
|
+
let text = await idbGet(key);
|
|
59
|
+
if (text === undefined) {
|
|
60
|
+
log.info(`${name}${sub} を取得しています...`);
|
|
61
|
+
if (/\.css$/.test(sub)) {
|
|
62
|
+
const res = await fetch(npmUrl(name, version, sub));
|
|
63
|
+
if (!res.ok) throw new Error(`${name}${sub} を取得できません (${res.status})`);
|
|
64
|
+
text = await res.text();
|
|
65
|
+
} else text = await bundle(npmUrl(name, version, sub), log);
|
|
66
|
+
await idbSet(key, text);
|
|
67
|
+
}
|
|
68
|
+
return [subFile(name, sub), text];
|
|
69
|
+
}
|
package/src/packer/packer.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// パッケージング(Web Crypto + fflate)― 公式パッカーとバイト単位で一致することを確認済み
|
|
2
|
-
import { zipSync, unzipSync } from 'fflate';
|
|
3
|
-
import { b64, unb64 } from '../util/bytes.js';
|
|
4
|
-
|
|
5
|
-
const ALG = { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-1' };
|
|
6
|
-
const RSA_ALG = new Uint8Array([0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00]);
|
|
7
|
-
const derLen = (n) => (n < 128 ? [n] : n < 256 ? [0x81, n] : [0x82, n >> 8, n & 255]);
|
|
8
|
-
const cat = (...a) => { const o = new Uint8Array(a.reduce((s, x) => s + x.length, 0)); let i = 0; for (const x of a) { o.set(x, i); i += x.length; } return o; };
|
|
9
|
-
const pemBody = (pem) => unb64(pem.replace(/-----[^-]+-----|\s/g, ''));
|
|
10
|
-
const toPem = (der, label) => `-----BEGIN ${label}-----\n${b64(der).match(/.{1,64}/g).join('\n')}\n-----END ${label}-----\n`;
|
|
11
|
-
// .ppk は PKCS#1。Web Crypto は PKCS#8 しか読めないので包む / 剥がす
|
|
12
|
-
const p1to8 = (p1) => {
|
|
13
|
-
const body = cat(new Uint8Array([0x02, 0x01, 0x00]), RSA_ALG, cat(new Uint8Array([0x04, ...derLen(p1.length)]), p1));
|
|
14
|
-
return cat(new Uint8Array([0x30, ...derLen(body.length)]), body);
|
|
15
|
-
};
|
|
16
|
-
const p8to1 = (p8) => {
|
|
17
|
-
let i = 0;
|
|
18
|
-
const len = () => { let l = p8[i++]; if (l & 0x80) { const n = l & 0x7f; l = 0; for (let k = 0; k < n; k++) l = (l << 8) | p8[i++]; } return l; };
|
|
19
|
-
const skip = () => { i++; const l = len(); i += l; };
|
|
20
|
-
i++; len(); skip(); skip(); i++; const l = len();
|
|
21
|
-
return p8.slice(i, i + l);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export async function generateKey() {
|
|
25
|
-
const kp = await crypto.subtle.generateKey({ ...ALG, modulusLength: 1024, publicExponent: new Uint8Array([1, 0, 1]) }, true, ['sign', 'verify']);
|
|
26
|
-
return toPem(p8to1(new Uint8Array(await crypto.subtle.exportKey('pkcs8', kp.privateKey))), 'RSA PRIVATE KEY');
|
|
27
|
-
}
|
|
28
|
-
export async function idFromSpki(spki) {
|
|
29
|
-
const hex = [...new Uint8Array(await crypto.subtle.digest('SHA-256', spki))].map((b) => b.toString(16).padStart(2, '0')).join('').slice(0, 32);
|
|
30
|
-
return hex.replace(/[0-9a-f]/g, (c) => 'abcdefghijklmnop'['0123456789abcdef'.indexOf(c)]);
|
|
31
|
-
}
|
|
32
|
-
export async function pack(contentsZip, ppk) {
|
|
33
|
-
const key = await crypto.subtle.importKey('pkcs8', p1to8(pemBody(ppk)), ALG, true, ['sign']);
|
|
34
|
-
const signature = new Uint8Array(await crypto.subtle.sign(ALG, key, contentsZip));
|
|
35
|
-
const jwk = await crypto.subtle.exportKey('jwk', key);
|
|
36
|
-
const pub = await crypto.subtle.importKey('jwk', { kty: 'RSA', n: jwk.n, e: jwk.e, alg: 'RS1', ext: true }, ALG, true, ['verify']);
|
|
37
|
-
const spki = new Uint8Array(await crypto.subtle.exportKey('spki', pub));
|
|
38
|
-
return { id: await idFromSpki(spki), plugin: zipSync({ 'contents.zip': contentsZip, PUBKEY: spki, SIGNATURE: signature }) };
|
|
39
|
-
}
|
|
40
|
-
// プラグインzip の署名を検証して中身を取り出す(import 用)。プラグインでなければ null
|
|
41
|
-
export async function unpack(pluginZip) {
|
|
42
|
-
const outer = unzipSync(pluginZip);
|
|
43
|
-
if (!outer['contents.zip']) return null;
|
|
44
|
-
let verified = false;
|
|
45
|
-
if (outer.PUBKEY && outer.SIGNATURE) {
|
|
46
|
-
const pub = await crypto.subtle.importKey('spki', outer.PUBKEY, ALG, false, ['verify']);
|
|
47
|
-
verified = await crypto.subtle.verify(ALG, pub, outer.SIGNATURE, outer['contents.zip']);
|
|
48
|
-
}
|
|
49
|
-
return { contents: unzipSync(outer['contents.zip']), verified, id: outer.PUBKEY ? await idFromSpki(outer.PUBKEY) : null };
|
|
50
|
-
}
|
|
1
|
+
// パッケージング(Web Crypto + fflate)― 公式パッカーとバイト単位で一致することを確認済み
|
|
2
|
+
import { zipSync, unzipSync } from 'fflate';
|
|
3
|
+
import { b64, unb64 } from '../util/bytes.js';
|
|
4
|
+
|
|
5
|
+
const ALG = { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-1' };
|
|
6
|
+
const RSA_ALG = new Uint8Array([0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00]);
|
|
7
|
+
const derLen = (n) => (n < 128 ? [n] : n < 256 ? [0x81, n] : [0x82, n >> 8, n & 255]);
|
|
8
|
+
const cat = (...a) => { const o = new Uint8Array(a.reduce((s, x) => s + x.length, 0)); let i = 0; for (const x of a) { o.set(x, i); i += x.length; } return o; };
|
|
9
|
+
const pemBody = (pem) => unb64(pem.replace(/-----[^-]+-----|\s/g, ''));
|
|
10
|
+
const toPem = (der, label) => `-----BEGIN ${label}-----\n${b64(der).match(/.{1,64}/g).join('\n')}\n-----END ${label}-----\n`;
|
|
11
|
+
// .ppk は PKCS#1。Web Crypto は PKCS#8 しか読めないので包む / 剥がす
|
|
12
|
+
const p1to8 = (p1) => {
|
|
13
|
+
const body = cat(new Uint8Array([0x02, 0x01, 0x00]), RSA_ALG, cat(new Uint8Array([0x04, ...derLen(p1.length)]), p1));
|
|
14
|
+
return cat(new Uint8Array([0x30, ...derLen(body.length)]), body);
|
|
15
|
+
};
|
|
16
|
+
const p8to1 = (p8) => {
|
|
17
|
+
let i = 0;
|
|
18
|
+
const len = () => { let l = p8[i++]; if (l & 0x80) { const n = l & 0x7f; l = 0; for (let k = 0; k < n; k++) l = (l << 8) | p8[i++]; } return l; };
|
|
19
|
+
const skip = () => { i++; const l = len(); i += l; };
|
|
20
|
+
i++; len(); skip(); skip(); i++; const l = len();
|
|
21
|
+
return p8.slice(i, i + l);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export async function generateKey() {
|
|
25
|
+
const kp = await crypto.subtle.generateKey({ ...ALG, modulusLength: 1024, publicExponent: new Uint8Array([1, 0, 1]) }, true, ['sign', 'verify']);
|
|
26
|
+
return toPem(p8to1(new Uint8Array(await crypto.subtle.exportKey('pkcs8', kp.privateKey))), 'RSA PRIVATE KEY');
|
|
27
|
+
}
|
|
28
|
+
export async function idFromSpki(spki) {
|
|
29
|
+
const hex = [...new Uint8Array(await crypto.subtle.digest('SHA-256', spki))].map((b) => b.toString(16).padStart(2, '0')).join('').slice(0, 32);
|
|
30
|
+
return hex.replace(/[0-9a-f]/g, (c) => 'abcdefghijklmnop'['0123456789abcdef'.indexOf(c)]);
|
|
31
|
+
}
|
|
32
|
+
export async function pack(contentsZip, ppk) {
|
|
33
|
+
const key = await crypto.subtle.importKey('pkcs8', p1to8(pemBody(ppk)), ALG, true, ['sign']);
|
|
34
|
+
const signature = new Uint8Array(await crypto.subtle.sign(ALG, key, contentsZip));
|
|
35
|
+
const jwk = await crypto.subtle.exportKey('jwk', key);
|
|
36
|
+
const pub = await crypto.subtle.importKey('jwk', { kty: 'RSA', n: jwk.n, e: jwk.e, alg: 'RS1', ext: true }, ALG, true, ['verify']);
|
|
37
|
+
const spki = new Uint8Array(await crypto.subtle.exportKey('spki', pub));
|
|
38
|
+
return { id: await idFromSpki(spki), plugin: zipSync({ 'contents.zip': contentsZip, PUBKEY: spki, SIGNATURE: signature }) };
|
|
39
|
+
}
|
|
40
|
+
// プラグインzip の署名を検証して中身を取り出す(import 用)。プラグインでなければ null
|
|
41
|
+
export async function unpack(pluginZip) {
|
|
42
|
+
const outer = unzipSync(pluginZip);
|
|
43
|
+
if (!outer['contents.zip']) return null;
|
|
44
|
+
let verified = false;
|
|
45
|
+
if (outer.PUBKEY && outer.SIGNATURE) {
|
|
46
|
+
const pub = await crypto.subtle.importKey('spki', outer.PUBKEY, ALG, false, ['verify']);
|
|
47
|
+
verified = await crypto.subtle.verify(ALG, pub, outer.SIGNATURE, outer['contents.zip']);
|
|
48
|
+
}
|
|
49
|
+
return { contents: unzipSync(outer['contents.zip']), verified, id: outer.PUBKEY ? await idFromSpki(outer.PUBKEY) : null };
|
|
50
|
+
}
|
package/src/util/bytes.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { BINARY_PREFIX } from '../config.js';
|
|
2
|
-
|
|
3
|
-
export const enc = new TextEncoder();
|
|
4
|
-
export const dec = new TextDecoder();
|
|
5
|
-
export const b64 = (u8) => { let s = ''; for (let i = 0; i < u8.length; i += 0x8000) s += String.fromCharCode(...u8.subarray(i, i + 0x8000)); return btoa(s); };
|
|
6
|
-
export const unb64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
|
|
7
|
-
export const isBinary = (text) => text.startsWith(BINARY_PREFIX);
|
|
8
|
-
export const toBytes = (text) => (isBinary(text) ? unb64(text.slice(BINARY_PREFIX.length)) : enc.encode(text));
|
|
9
|
-
export const looksBinary = (u8) => {
|
|
10
|
-
const n = Math.min(u8.length, 4000);
|
|
11
|
-
for (let i = 0; i < n; i++) if (u8[i] === 0) return true;
|
|
12
|
-
try { new TextDecoder('utf-8', { fatal: true }).decode(u8.subarray(0, n)); return false; } catch { return true; }
|
|
13
|
-
};
|
|
14
|
-
export const fromBytes = (u8) => (looksBinary(u8) ? BINARY_PREFIX + b64(u8) : dec.decode(u8));
|
|
15
|
-
export const kb = (n) => `${(n / 1024).toFixed(1)} KB`;
|
|
1
|
+
import { BINARY_PREFIX } from '../config.js';
|
|
2
|
+
|
|
3
|
+
export const enc = new TextEncoder();
|
|
4
|
+
export const dec = new TextDecoder();
|
|
5
|
+
export const b64 = (u8) => { let s = ''; for (let i = 0; i < u8.length; i += 0x8000) s += String.fromCharCode(...u8.subarray(i, i + 0x8000)); return btoa(s); };
|
|
6
|
+
export const unb64 = (s) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
|
|
7
|
+
export const isBinary = (text) => text.startsWith(BINARY_PREFIX);
|
|
8
|
+
export const toBytes = (text) => (isBinary(text) ? unb64(text.slice(BINARY_PREFIX.length)) : enc.encode(text));
|
|
9
|
+
export const looksBinary = (u8) => {
|
|
10
|
+
const n = Math.min(u8.length, 4000);
|
|
11
|
+
for (let i = 0; i < n; i++) if (u8[i] === 0) return true;
|
|
12
|
+
try { new TextDecoder('utf-8', { fatal: true }).decode(u8.subarray(0, n)); return false; } catch { return true; }
|
|
13
|
+
};
|
|
14
|
+
export const fromBytes = (u8) => (looksBinary(u8) ? BINARY_PREFIX + b64(u8) : dec.decode(u8));
|
|
15
|
+
export const kb = (n) => `${(n / 1024).toFixed(1)} KB`;
|
package/src/util/dom.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export const el = (tag, attrs = {}, ...children) => {
|
|
2
|
-
const e = Object.assign(document.createElement(tag), attrs);
|
|
3
|
-
for (const c of children) if (c != null) e.append(c);
|
|
4
|
-
return e;
|
|
5
|
-
};
|
|
6
|
-
export function downloadBlob(bytes, name, type = 'application/zip') {
|
|
7
|
-
const url = URL.createObjectURL(new Blob([bytes], { type }));
|
|
8
|
-
el('a', { href: url, download: name }).click();
|
|
9
|
-
setTimeout(() => URL.revokeObjectURL(url), 10000);
|
|
10
|
-
}
|
|
11
|
-
export const pickFile = (accept) => new Promise((resolve) => {
|
|
12
|
-
const input = el('input', { type: 'file', accept });
|
|
13
|
-
input.onchange = () => resolve(input.files[0] || null);
|
|
14
|
-
input.click();
|
|
15
|
-
});
|
|
1
|
+
export const el = (tag, attrs = {}, ...children) => {
|
|
2
|
+
const e = Object.assign(document.createElement(tag), attrs);
|
|
3
|
+
for (const c of children) if (c != null) e.append(c);
|
|
4
|
+
return e;
|
|
5
|
+
};
|
|
6
|
+
export function downloadBlob(bytes, name, type = 'application/zip') {
|
|
7
|
+
const url = URL.createObjectURL(new Blob([bytes], { type }));
|
|
8
|
+
el('a', { href: url, download: name }).click();
|
|
9
|
+
setTimeout(() => URL.revokeObjectURL(url), 10000);
|
|
10
|
+
}
|
|
11
|
+
export const pickFile = (accept) => new Promise((resolve) => {
|
|
12
|
+
const input = el('input', { type: 'file', accept });
|
|
13
|
+
input.onchange = () => resolve(input.files[0] || null);
|
|
14
|
+
input.click();
|
|
15
|
+
});
|
package/src/util/idb.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
// 小さな IndexedDB の key-value(npm のパッケージのキャッシュに使う)
|
|
2
|
-
const open = () => new Promise((resolve, reject) => {
|
|
3
|
-
const r = indexedDB.open('kintone-plugin-ide', 1);
|
|
4
|
-
r.onupgradeneeded = () => r.result.createObjectStore('kv');
|
|
5
|
-
r.onsuccess = () => resolve(r.result);
|
|
6
|
-
r.onerror = () => reject(r.error);
|
|
7
|
-
});
|
|
8
|
-
const tx = async (mode, fn) => {
|
|
9
|
-
const db = await open();
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
const t = db.transaction('kv', mode);
|
|
12
|
-
const req = fn(t.objectStore('kv'));
|
|
13
|
-
t.oncomplete = () => { resolve(req && req.result); db.close(); };
|
|
14
|
-
t.onerror = () => { reject(t.error); db.close(); };
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
export const idbGet = (key) => tx('readonly', (s) => s.get(key)).catch(() => undefined);
|
|
18
|
-
export const idbSet = (key, value) => tx('readwrite', (s) => s.put(value, key)).catch(() => {});
|
|
1
|
+
// 小さな IndexedDB の key-value(npm のパッケージのキャッシュに使う)
|
|
2
|
+
const open = () => new Promise((resolve, reject) => {
|
|
3
|
+
const r = indexedDB.open('kintone-plugin-ide', 1);
|
|
4
|
+
r.onupgradeneeded = () => r.result.createObjectStore('kv');
|
|
5
|
+
r.onsuccess = () => resolve(r.result);
|
|
6
|
+
r.onerror = () => reject(r.error);
|
|
7
|
+
});
|
|
8
|
+
const tx = async (mode, fn) => {
|
|
9
|
+
const db = await open();
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const t = db.transaction('kv', mode);
|
|
12
|
+
const req = fn(t.objectStore('kv'));
|
|
13
|
+
t.oncomplete = () => { resolve(req && req.result); db.close(); };
|
|
14
|
+
t.onerror = () => { reject(t.error); db.close(); };
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export const idbGet = (key) => tx('readonly', (s) => s.get(key)).catch(() => undefined);
|
|
18
|
+
export const idbSet = (key, value) => tx('readwrite', (s) => s.put(value, key)).catch(() => {});
|
package/src/util/path.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { NODE_MODULES } from '../config.js';
|
|
2
|
-
|
|
3
|
-
export const dirname = (p) => p.split('/').slice(0, -1).join('/');
|
|
4
|
-
export const normalize = (p) => {
|
|
5
|
-
const out = [];
|
|
6
|
-
for (const s of String(p).split('/')) { if (!s || s === '.') continue; if (s === '..') out.pop(); else out.push(s); }
|
|
7
|
-
return out.join('/');
|
|
8
|
-
};
|
|
9
|
-
export const ext = (p) => p.split('.').pop().toLowerCase();
|
|
10
|
-
export const langOf = (p) => ({ ts: 'typescript', tsx: 'typescript', mts: 'typescript', js: 'javascript', jsx: 'javascript', mjs: 'javascript', json: 'json', css: 'css', html: 'html', md: 'markdown', svelte: 'svelte', vue: 'vue', scss: 'scss', sass: 'sass', less: 'less', yaml: 'yaml', yml: 'yaml' })[ext(p)] || 'plaintext';
|
|
11
|
-
// node_modules の中は npm が置くもの。レコードには保存しない
|
|
12
|
-
export const isVendor = (p) => p === 'node_modules' || p.startsWith(NODE_MODULES);
|
|
13
|
-
export const asDir = (p) => normalize(p) + '/';
|
|
14
|
-
export const safeName = (s) => String(s).replace(/[\\/:*?"<>|]/g, '_');
|
|
1
|
+
import { NODE_MODULES } from '../config.js';
|
|
2
|
+
|
|
3
|
+
export const dirname = (p) => p.split('/').slice(0, -1).join('/');
|
|
4
|
+
export const normalize = (p) => {
|
|
5
|
+
const out = [];
|
|
6
|
+
for (const s of String(p).split('/')) { if (!s || s === '.') continue; if (s === '..') out.pop(); else out.push(s); }
|
|
7
|
+
return out.join('/');
|
|
8
|
+
};
|
|
9
|
+
export const ext = (p) => p.split('.').pop().toLowerCase();
|
|
10
|
+
export const langOf = (p) => ({ ts: 'typescript', tsx: 'typescript', mts: 'typescript', js: 'javascript', jsx: 'javascript', mjs: 'javascript', json: 'json', css: 'css', html: 'html', md: 'markdown', svelte: 'svelte', vue: 'vue', scss: 'scss', sass: 'sass', less: 'less', yaml: 'yaml', yml: 'yaml' })[ext(p)] || 'plaintext';
|
|
11
|
+
// node_modules の中は npm が置くもの。レコードには保存しない
|
|
12
|
+
export const isVendor = (p) => p === 'node_modules' || p.startsWith(NODE_MODULES);
|
|
13
|
+
export const asDir = (p) => normalize(p) + '/';
|
|
14
|
+
export const safeName = (s) => String(s).replace(/[\\/:*?"<>|]/g, '_');
|
package/src/util/settings.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SETTINGS_KEY } from '../config.js';
|
|
2
|
-
|
|
3
|
-
const DEFAULTS = { prod: false, watch: false, typecheck: true, format: false };
|
|
4
|
-
export const loadSettings = () => { try { return { ...DEFAULTS, ...JSON.parse(localStorage.getItem(SETTINGS_KEY) || '{}') }; } catch { return { ...DEFAULTS }; } };
|
|
5
|
-
export const saveSettings = (s) => { try { localStorage.setItem(SETTINGS_KEY, JSON.stringify(s)); } catch {} };
|
|
1
|
+
import { SETTINGS_KEY } from '../config.js';
|
|
2
|
+
|
|
3
|
+
const DEFAULTS = { prod: false, watch: false, typecheck: true, format: false };
|
|
4
|
+
export const loadSettings = () => { try { return { ...DEFAULTS, ...JSON.parse(localStorage.getItem(SETTINGS_KEY) || '{}') }; } catch { return { ...DEFAULTS }; } };
|
|
5
|
+
export const saveSettings = (s) => { try { localStorage.setItem(SETTINGS_KEY, JSON.stringify(s)); } catch {} };
|
package/types/index.d.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
export interface FieldCodes {
|
|
2
|
-
/** 添付ファイル: ソース一式の zip(既定: source_zip) */
|
|
3
|
-
source?: string;
|
|
4
|
-
/** 添付ファイル: 秘密鍵 .ppk(既定: private_key) */
|
|
5
|
-
key?: string;
|
|
6
|
-
/** 添付ファイル: 作ったプラグイン(既定: plugin_zip) */
|
|
7
|
-
zip?: string;
|
|
8
|
-
/** 文字列(1行): プラグインID(既定: plugin_id) */
|
|
9
|
-
id?: string;
|
|
10
|
-
/** 数値: テスト用アプリのID(既定: test_app) */
|
|
11
|
-
testApp?: string;
|
|
12
|
-
/** 前の版のサブテーブル(移行用) */
|
|
13
|
-
legacy?: { files?: string; path?: string; content?: string } | null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface SetupOptions {
|
|
17
|
-
/** インストールしてよい kintone のホスト名(例: 'example.cybozu.com')。入っていない環境ではインストールしない */
|
|
18
|
-
installHosts?: string[];
|
|
19
|
-
/** アプリのフィールドコード */
|
|
20
|
-
fields?: FieldCodes;
|
|
21
|
-
/** エディタのテーマ(modern-monaco / Shiki のテーマ名) */
|
|
22
|
-
theme?: string;
|
|
23
|
-
/** 外部ライブラリの URL を差し替える(社内に置いたものを使う場合など) */
|
|
24
|
-
cdn?: Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface IDEHandle {
|
|
28
|
-
open(): Promise<unknown>;
|
|
29
|
-
config: unknown;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** 詳細画面に「IDEで開く」を出す。カスタマイズから1回呼ぶ */
|
|
33
|
-
export function setup(options?: SetupOptions): IDEHandle;
|
|
34
|
-
export function configure(options?: SetupOptions): unknown;
|
|
35
|
-
export function openIDE(): Promise<unknown>;
|
|
36
|
-
|
|
37
|
-
/** files: パス → 中身(バイナリは "base64:..." )。manifest.json に従ってビルドし contents.zip を作る */
|
|
38
|
-
export function buildPlugin(
|
|
39
|
-
files: Map<string, string>,
|
|
40
|
-
log: { info(t: string): void; ok(t: string): void; warn(t: string): void; error(t: string): void },
|
|
41
|
-
options?: { prod?: boolean },
|
|
42
|
-
): Promise<{ manifest: any; contentsZip: Uint8Array; outputs: Map<string, Uint8Array> }>;
|
|
43
|
-
|
|
44
|
-
/** 1024bit RSA の秘密鍵(.ppk、PKCS#1 PEM)を作る */
|
|
45
|
-
export function generateKey(): Promise<string>;
|
|
46
|
-
/** contents.zip に署名してプラグインの zip を作る */
|
|
47
|
-
export function pack(contentsZip: Uint8Array, ppk: string): Promise<{ id: string; plugin: Uint8Array }>;
|
|
48
|
-
/** プラグインの zip の署名を確かめて中身を取り出す */
|
|
49
|
-
export function unpack(pluginZip: Uint8Array): Promise<{ contents: Record<string, Uint8Array>; verified: boolean; id: string | null } | null>;
|
|
1
|
+
export interface FieldCodes {
|
|
2
|
+
/** 添付ファイル: ソース一式の zip(既定: source_zip) */
|
|
3
|
+
source?: string;
|
|
4
|
+
/** 添付ファイル: 秘密鍵 .ppk(既定: private_key) */
|
|
5
|
+
key?: string;
|
|
6
|
+
/** 添付ファイル: 作ったプラグイン(既定: plugin_zip) */
|
|
7
|
+
zip?: string;
|
|
8
|
+
/** 文字列(1行): プラグインID(既定: plugin_id) */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** 数値: テスト用アプリのID(既定: test_app) */
|
|
11
|
+
testApp?: string;
|
|
12
|
+
/** 前の版のサブテーブル(移行用) */
|
|
13
|
+
legacy?: { files?: string; path?: string; content?: string } | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SetupOptions {
|
|
17
|
+
/** インストールしてよい kintone のホスト名(例: 'example.cybozu.com')。入っていない環境ではインストールしない */
|
|
18
|
+
installHosts?: string[];
|
|
19
|
+
/** アプリのフィールドコード */
|
|
20
|
+
fields?: FieldCodes;
|
|
21
|
+
/** エディタのテーマ(modern-monaco / Shiki のテーマ名) */
|
|
22
|
+
theme?: string;
|
|
23
|
+
/** 外部ライブラリの URL を差し替える(社内に置いたものを使う場合など) */
|
|
24
|
+
cdn?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IDEHandle {
|
|
28
|
+
open(): Promise<unknown>;
|
|
29
|
+
config: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 詳細画面に「IDEで開く」を出す。カスタマイズから1回呼ぶ */
|
|
33
|
+
export function setup(options?: SetupOptions): IDEHandle;
|
|
34
|
+
export function configure(options?: SetupOptions): unknown;
|
|
35
|
+
export function openIDE(): Promise<unknown>;
|
|
36
|
+
|
|
37
|
+
/** files: パス → 中身(バイナリは "base64:..." )。manifest.json に従ってビルドし contents.zip を作る */
|
|
38
|
+
export function buildPlugin(
|
|
39
|
+
files: Map<string, string>,
|
|
40
|
+
log: { info(t: string): void; ok(t: string): void; warn(t: string): void; error(t: string): void },
|
|
41
|
+
options?: { prod?: boolean },
|
|
42
|
+
): Promise<{ manifest: any; contentsZip: Uint8Array; outputs: Map<string, Uint8Array> }>;
|
|
43
|
+
|
|
44
|
+
/** 1024bit RSA の秘密鍵(.ppk、PKCS#1 PEM)を作る */
|
|
45
|
+
export function generateKey(): Promise<string>;
|
|
46
|
+
/** contents.zip に署名してプラグインの zip を作る */
|
|
47
|
+
export function pack(contentsZip: Uint8Array, ppk: string): Promise<{ id: string; plugin: Uint8Array }>;
|
|
48
|
+
/** プラグインの zip の署名を確かめて中身を取り出す */
|
|
49
|
+
export function unpack(pluginZip: Uint8Array): Promise<{ contents: Record<string, Uint8Array>; verified: boolean; id: string | null } | null>;
|