@osaas/client-web 0.2.0
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 -0
- package/README.md +43 -0
- package/lib/bucket.d.ts +11 -0
- package/lib/bucket.d.ts.map +1 -0
- package/lib/bucket.js +133 -0
- package/lib/bucket.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/publish.d.ts +16 -0
- package/lib/publish.d.ts.map +1 -0
- package/lib/publish.js +31 -0
- package/lib/publish.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Eyevinn Technology Open Source Software Center
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @osaas/client-web
|
|
2
|
+
|
|
3
|
+
SDK for static website publishing in Open Source Cloud
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Prerequisites
|
|
8
|
+
|
|
9
|
+
- An account on [Eyevinn Open Source Cloud](www.osaas.io)
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install --save @osaas/client-web
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Example code
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import { Context, Log } from '@osaas/client-core';
|
|
19
|
+
import { publish } from '@osaas/client-web';
|
|
20
|
+
|
|
21
|
+
async function main() {
|
|
22
|
+
const ctx = new Context();
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const ctx = new Context({ environment });
|
|
26
|
+
await publish('www', '/Users/birme/Code/eyevinn/www/dist', ctx, {
|
|
27
|
+
sync: true
|
|
28
|
+
});
|
|
29
|
+
} catch (err) {
|
|
30
|
+
Log().error(err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## About Open Source Cloud
|
|
38
|
+
|
|
39
|
+
Open Source Cloud reduces the barrier to get started with open source without having to host it on your own infrastructure.
|
|
40
|
+
|
|
41
|
+
Start building software solutions based on open and detachable ready-to-run cloud components with Open Source Cloud. Full code transparency, never locked in and a business model that contributes back to the open source community. Offering a wide range of components from media and more to help you build the best solution for you and your users.
|
|
42
|
+
|
|
43
|
+
www.osaas.io
|
package/lib/bucket.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context } from '@osaas/client-core';
|
|
2
|
+
export interface Bucket {
|
|
3
|
+
name: string;
|
|
4
|
+
endpoint: string;
|
|
5
|
+
accessKeyId: string;
|
|
6
|
+
secretAccessKey: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function createStorageBucket(name: string, ctx: Context): Promise<Bucket>;
|
|
9
|
+
export declare function removeBucketContents(bucket: Bucket): Promise<void>;
|
|
10
|
+
export declare function uploadFile(source: string, dest: string, bucket: Bucket): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=bucket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bucket.d.ts","sourceRoot":"","sources":["../src/bucket.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAIR,MAAM,oBAAoB,CAAC;AAa5B,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB;AA0BD,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,MAAM,CAAC,CAoCjB;AAED,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,iBA6BxD;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAiBf"}
|
package/lib/bucket.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.uploadFile = exports.removeBucketContents = exports.createStorageBucket = void 0;
|
|
30
|
+
const client_core_1 = require("@osaas/client-core");
|
|
31
|
+
const client_services_1 = require("@osaas/client-services");
|
|
32
|
+
const crypto_1 = require("crypto");
|
|
33
|
+
const fs_1 = require("fs");
|
|
34
|
+
const Minio = __importStar(require("minio"));
|
|
35
|
+
const mime_1 = __importDefault(require("mime"));
|
|
36
|
+
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
|
|
37
|
+
function createPublicBucketPolicy(name) {
|
|
38
|
+
return {
|
|
39
|
+
Statement: [
|
|
40
|
+
{
|
|
41
|
+
Action: ['s3:GetBucketLocation', 's3:ListBucket'],
|
|
42
|
+
Effect: 'Allow',
|
|
43
|
+
Principal: {
|
|
44
|
+
AWS: ['*']
|
|
45
|
+
},
|
|
46
|
+
Resource: [`arn:aws:s3:::${name}`]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
Action: ['s3:GetObject'],
|
|
50
|
+
Effect: 'Allow',
|
|
51
|
+
Principal: {
|
|
52
|
+
AWS: ['*']
|
|
53
|
+
},
|
|
54
|
+
Resource: [`arn:aws:s3:::${name}/*`]
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
Version: '2012-10-17'
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async function createStorageBucket(name, ctx) {
|
|
61
|
+
const sat = await ctx.getServiceAccessToken('minio-minio');
|
|
62
|
+
let instance = await (0, client_core_1.getInstance)(ctx, 'minio-minio', name, sat);
|
|
63
|
+
if (!instance) {
|
|
64
|
+
const rootPassword = (0, crypto_1.randomBytes)(16).toString('hex');
|
|
65
|
+
const config = {
|
|
66
|
+
name,
|
|
67
|
+
RootUser: 'root',
|
|
68
|
+
RootPassword: rootPassword
|
|
69
|
+
};
|
|
70
|
+
const newInstance = await (0, client_services_1.createMinioMinioInstance)(ctx, config);
|
|
71
|
+
if (!newInstance) {
|
|
72
|
+
throw new Error('Failed to create new Minio instance');
|
|
73
|
+
}
|
|
74
|
+
instance = newInstance;
|
|
75
|
+
await (0, client_core_1.waitForInstanceReady)('minio-minio', name, ctx);
|
|
76
|
+
await delay(2000);
|
|
77
|
+
const minioClient = new Minio.Client({
|
|
78
|
+
endPoint: new URL(instance.url).hostname,
|
|
79
|
+
accessKey: 'root',
|
|
80
|
+
secretKey: instance.RootPassword || ''
|
|
81
|
+
});
|
|
82
|
+
await minioClient.makeBucket(name);
|
|
83
|
+
await minioClient.setBucketPolicy(name, JSON.stringify(createPublicBucketPolicy(name)));
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
name: instance.name,
|
|
87
|
+
endpoint: instance.url,
|
|
88
|
+
accessKeyId: 'root',
|
|
89
|
+
secretAccessKey: instance.RootPassword || ''
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
exports.createStorageBucket = createStorageBucket;
|
|
93
|
+
async function removeBucketContents(bucket) {
|
|
94
|
+
(0, client_core_1.Log)().debug(`Removing contents on bucket ${bucket.name}`);
|
|
95
|
+
const minioClient = new Minio.Client({
|
|
96
|
+
endPoint: new URL(bucket.endpoint).hostname,
|
|
97
|
+
accessKey: bucket.accessKeyId,
|
|
98
|
+
secretKey: bucket.secretAccessKey
|
|
99
|
+
});
|
|
100
|
+
const p = new Promise((resolve, reject) => {
|
|
101
|
+
const stream = minioClient.listObjects(bucket.name, '', true);
|
|
102
|
+
const objectsToDelete = [];
|
|
103
|
+
stream.on('data', (obj) => {
|
|
104
|
+
if (obj.name) {
|
|
105
|
+
objectsToDelete.push(obj.name);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
stream.on('end', () => {
|
|
109
|
+
resolve(objectsToDelete);
|
|
110
|
+
});
|
|
111
|
+
stream.on('error', (err) => {
|
|
112
|
+
reject(err);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
const objectsToDelete = await p;
|
|
116
|
+
(0, client_core_1.Log)().debug(`Deleting ${objectsToDelete.length} objects`);
|
|
117
|
+
await minioClient.removeObjects(bucket.name, objectsToDelete);
|
|
118
|
+
}
|
|
119
|
+
exports.removeBucketContents = removeBucketContents;
|
|
120
|
+
async function uploadFile(source, dest, bucket) {
|
|
121
|
+
(0, client_core_1.Log)().debug(`Uploading ${source} to ${bucket.name}/${dest}`);
|
|
122
|
+
const fileStream = (0, fs_1.createReadStream)(source);
|
|
123
|
+
const stats = await (0, fs_1.statSync)(source);
|
|
124
|
+
const metadata = { 'Content-Type': mime_1.default.getType(source) };
|
|
125
|
+
const minioClient = new Minio.Client({
|
|
126
|
+
endPoint: new URL(bucket.endpoint).hostname,
|
|
127
|
+
accessKey: bucket.accessKeyId,
|
|
128
|
+
secretKey: bucket.secretAccessKey
|
|
129
|
+
});
|
|
130
|
+
await minioClient.putObject(bucket.name, dest, fileStream, stats.size, metadata);
|
|
131
|
+
}
|
|
132
|
+
exports.uploadFile = uploadFile;
|
|
133
|
+
//# sourceMappingURL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AAG,IAAA,qBAAgB,EAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,MAAM,IAAA,aAAQ,EAAC,MAAM,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,EAAE,cAAc,EAAE,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;IAC1D,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC;QACnC,QAAQ,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ;QAC3C,SAAS,EAAE,MAAM,CAAC,WAAW;QAC7B,SAAS,EAAE,MAAM,CAAC,eAAe;KAClC,CAAC,CAAC;IACH,MAAM,WAAW,CAAC,SAAS,CACzB,MAAM,CAAC,IAAI,EACX,IAAI,EACJ,UAAU,EACV,KAAK,CAAC,IAAI,EACV,QAAQ,CACT,CAAC;AACJ,CAAC;AArBD,gCAqBC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @module @osaas/client-web */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.publish = void 0;
|
|
5
|
+
var publish_1 = require("./publish");
|
|
6
|
+
Object.defineProperty(exports, "publish", { enumerable: true, get: function () { return publish_1.publish; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,gCAAgC;;;AAEhC,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
|
package/lib/publish.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context } from '@osaas/client-core';
|
|
2
|
+
import { Bucket } from './bucket';
|
|
3
|
+
export interface PublishOpts {
|
|
4
|
+
sync?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface Website {
|
|
7
|
+
name: string;
|
|
8
|
+
url: string;
|
|
9
|
+
bucket: Bucket;
|
|
10
|
+
}
|
|
11
|
+
export declare function publish(name: string, dir: string, ctx: Context, opts?: PublishOpts): Promise<{
|
|
12
|
+
name: string;
|
|
13
|
+
url: string;
|
|
14
|
+
bucket: Bucket;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=publish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAuB,MAAM,oBAAoB,CAAC;AAClE,OAAO,EACL,MAAM,EAIP,MAAM,UAAU,CAAC;AAKlB,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,OAAO,EACZ,IAAI,CAAC,EAAE,WAAW;;;;GAuBnB"}
|
package/lib/publish.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.publish = void 0;
|
|
4
|
+
const client_core_1 = require("@osaas/client-core");
|
|
5
|
+
const bucket_1 = require("./bucket");
|
|
6
|
+
const promises_1 = require("fs/promises");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
async function publish(name, dir, ctx, opts) {
|
|
10
|
+
if (!(0, client_core_1.isValidInstanceName)(name)) {
|
|
11
|
+
throw new Error(`Invalid website identifier (lowercase letters and numbers allowed): ${name}`);
|
|
12
|
+
}
|
|
13
|
+
const sync = opts?.sync || false;
|
|
14
|
+
const bucket = await (0, bucket_1.createStorageBucket)(name, ctx);
|
|
15
|
+
if (sync) {
|
|
16
|
+
await (0, bucket_1.removeBucketContents)(bucket);
|
|
17
|
+
}
|
|
18
|
+
const files = await (0, promises_1.readdir)(dir, { recursive: true });
|
|
19
|
+
for (const file of files.filter((f) => f !== '.git')) {
|
|
20
|
+
if (!(0, fs_1.statSync)((0, path_1.join)(dir, file)).isDirectory()) {
|
|
21
|
+
await (0, bucket_1.uploadFile)((0, path_1.join)(dir, file), file, bucket);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
name,
|
|
26
|
+
url: bucket.endpoint + '/' + bucket.name + '/index.html',
|
|
27
|
+
bucket
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.publish = publish;
|
|
31
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":";;;AAAA,oDAAkE;AAClE,qCAKkB;AAClB,0CAAsC;AACtC,+BAA4B;AAC5B,2BAA8B;AAYvB,KAAK,UAAU,OAAO,CAC3B,IAAY,EACZ,GAAW,EACX,GAAY,EACZ,IAAkB;IAElB,IAAI,CAAC,IAAA,iCAAmB,EAAC,IAAI,CAAC,EAAE;QAC9B,MAAM,IAAI,KAAK,CACb,uEAAuE,IAAI,EAAE,CAC9E,CAAC;KACH;IACD,MAAM,IAAI,GAAG,IAAI,EAAE,IAAI,IAAI,KAAK,CAAC;IACjC,MAAM,MAAM,GAAG,MAAM,IAAA,4BAAmB,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACpD,IAAI,IAAI,EAAE;QACR,MAAM,IAAA,6BAAoB,EAAC,MAAM,CAAC,CAAC;KACpC;IACD,MAAM,KAAK,GAAG,MAAM,IAAA,kBAAO,EAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,EAAE;QACpD,IAAI,CAAC,IAAA,aAAQ,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE;YAC5C,MAAM,IAAA,mBAAU,EAAC,IAAA,WAAI,EAAC,GAAG,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;SACjD;KACF;IACD,OAAO;QACL,IAAI;QACJ,GAAG,EAAE,MAAM,CAAC,QAAQ,GAAG,GAAG,GAAG,MAAM,CAAC,IAAI,GAAG,aAAa;QACxD,MAAM;KACP,CAAC;AACJ,CAAC;AA3BD,0BA2BC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@osaas/client-web",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Open Source Cloud Client SDK web library",
|
|
5
|
+
"author": "Eyevinn Open Source Cloud <osc@eyevinn.se>",
|
|
6
|
+
"homepage": "https://www.osaas.io",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"types": "lib/index.d.ts",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/EyevinnOSC/client-ts.git"
|
|
13
|
+
},
|
|
14
|
+
"directories": {
|
|
15
|
+
"lib": "lib"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"lint": "eslint .",
|
|
23
|
+
"pretty": "prettier --check --ignore-unknown .",
|
|
24
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
25
|
+
"test": "jest --passWithNoTests"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@osaas/client-core": "^0.15.0",
|
|
29
|
+
"@osaas/client-services": "^0.5.0",
|
|
30
|
+
"chalk": "4.1.2",
|
|
31
|
+
"mime": "^3.0.0",
|
|
32
|
+
"minio": "^8.0.2"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "64eb9dfb6763ccf84b34a36f7ae3adf7963a58de"
|
|
38
|
+
}
|