@kwiz/node 1.0.41 → 1.0.42
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/storage/blob-storage.d.ts +8 -0
- package/dist/storage/blob-storage.js +110 -0
- package/dist/storage/blob-storage.js.map +1 -0
- package/dist/storage/exports-index.d.ts +1 -0
- package/dist/storage/exports-index.js +1 -0
- package/dist/storage/exports-index.js.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { apiResultType } from "@kwiz/common";
|
|
2
|
+
export declare function ConfigureBlobStorage(config: {
|
|
3
|
+
connectionString: string;
|
|
4
|
+
}): void;
|
|
5
|
+
export declare function GetBlobAsString(container: string, name: string): Promise<apiResultType<string>>;
|
|
6
|
+
export declare function GetBlobAsJSON<Type>(container: string, name: string): Promise<apiResultType<Type>>;
|
|
7
|
+
export declare function GetBlobAsBuffer(container: string, name: string): Promise<apiResultType<Buffer<ArrayBuffer>>>;
|
|
8
|
+
export declare function SaveBlob(container: string, name: string, content: string | ArrayBuffer): Promise<apiResultType<string>>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ConfigureBlobStorage = ConfigureBlobStorage;
|
|
13
|
+
exports.GetBlobAsString = GetBlobAsString;
|
|
14
|
+
exports.GetBlobAsJSON = GetBlobAsJSON;
|
|
15
|
+
exports.GetBlobAsBuffer = GetBlobAsBuffer;
|
|
16
|
+
exports.SaveBlob = SaveBlob;
|
|
17
|
+
const storage_blob_1 = require("@azure/storage-blob");
|
|
18
|
+
const common_1 = require("@kwiz/common");
|
|
19
|
+
var connectionString = null;
|
|
20
|
+
function ConfigureBlobStorage(config) {
|
|
21
|
+
connectionString = config.connectionString;
|
|
22
|
+
}
|
|
23
|
+
function GetBlobAsString(container, name) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return GetBlob(container, name, "string");
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function GetBlobAsJSON(container, name) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
try {
|
|
31
|
+
const res = yield GetBlob(container, name, "string");
|
|
32
|
+
if (res.success === true)
|
|
33
|
+
return { success: true, value: (0, common_1.jsonParse)(res.value) };
|
|
34
|
+
else
|
|
35
|
+
return res;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
return { success: false, error: (0, common_1.GetError)(e) };
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function GetBlobAsBuffer(container, name) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return GetBlob(container, name, "buffer");
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function SaveBlob(container, name, content) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
try {
|
|
50
|
+
const blobServiceClient = getBlobClient();
|
|
51
|
+
const containerClient = blobServiceClient.getContainerClient(container);
|
|
52
|
+
// const createContainerResponse = await containerClient.create();
|
|
53
|
+
// if (isNotEmptyString(createContainerResponse.errorCode))
|
|
54
|
+
// throw Error(createContainerResponse.errorCode);
|
|
55
|
+
//return { success: true, value: createContainerResponse.requestId };
|
|
56
|
+
const blockBlobClient = containerClient.getBlockBlobClient(name);
|
|
57
|
+
const uploadBlobResponse = yield blockBlobClient.upload(content, (0, common_1.isString)(content) ? content.length : content.byteLength);
|
|
58
|
+
if ((0, common_1.isNotEmptyString)(uploadBlobResponse.errorCode))
|
|
59
|
+
throw Error(uploadBlobResponse.errorCode);
|
|
60
|
+
return { success: true, value: uploadBlobResponse.requestId };
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
return { success: false, error: (0, common_1.GetError)(e) };
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function getBlobClient() {
|
|
68
|
+
if ((0, common_1.isNullOrEmptyString)(connectionString))
|
|
69
|
+
throw Error("Call ConfigureTableStorage first");
|
|
70
|
+
return storage_blob_1.BlobServiceClient.fromConnectionString(connectionString);
|
|
71
|
+
}
|
|
72
|
+
function GetBlob(container, name, as) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
try {
|
|
75
|
+
const blobServiceClient = getBlobClient();
|
|
76
|
+
const containerClient = blobServiceClient.getContainerClient(container);
|
|
77
|
+
const blobClient = containerClient.getBlobClient(name);
|
|
78
|
+
const downloaded = yield blobClient.download();
|
|
79
|
+
const asValue = yield (as === "string"
|
|
80
|
+
? streamToString(downloaded.readableStreamBody)
|
|
81
|
+
: streamToBuffer(downloaded.readableStreamBody));
|
|
82
|
+
return { success: true, value: asValue };
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return { success: false, error: (0, common_1.GetError)(e) };
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function streamToBuffer(stream) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const result = yield new Promise((resolve, reject) => {
|
|
92
|
+
const chunks = [];
|
|
93
|
+
stream.on("data", (data) => {
|
|
94
|
+
chunks.push(Buffer.isBuffer(data) ? data : Buffer.from(data));
|
|
95
|
+
});
|
|
96
|
+
stream.on("end", () => {
|
|
97
|
+
resolve(Buffer.concat(chunks));
|
|
98
|
+
});
|
|
99
|
+
stream.on("error", reject);
|
|
100
|
+
});
|
|
101
|
+
return result;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function streamToString(stream) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const result = yield streamToBuffer(stream);
|
|
107
|
+
return result.toString();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=blob-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-storage.js","sourceRoot":"","sources":["../../src/storage/blob-storage.ts"],"names":[],"mappings":";;;;;;;;;;;AAIA,oDAEC;AAED,0CAEC;AAED,sCAUC;AAED,0CAEC;AAED,4BAkBC;AA9CD,sDAAwD;AACxD,yCAAmH;AAEnH,IAAI,gBAAgB,GAAW,IAAI,CAAC;AACpC,SAAgB,oBAAoB,CAAC,MAAqC;IACtE,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAC/C,CAAC;AAED,SAAsB,eAAe,CAAC,SAAiB,EAAE,IAAY;;QACjE,OAAO,OAAO,CAAS,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;CAAA;AAED,SAAsB,aAAa,CAAO,SAAiB,EAAE,IAAY;;QACrE,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,OAAO,CAAS,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7D,IAAI,GAAG,CAAC,OAAO,KAAK,IAAI;gBACpB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAA,kBAAS,EAAO,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;;gBAE5D,OAAO,GAAG,CAAC;QACnB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,EAAE,OAAO,EAAE,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AE,CAAC,KAAK,EAAE,GAAG,EAAE;gBAClB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;CAAA;AACD,SAAe,cAAc,CAAC,MAA6B;;QACvD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;CAAA"}
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./blob-storage"), exports);
|
|
17
18
|
__exportStar(require("./common"), exports);
|
|
18
19
|
__exportStar(require("./odata"), exports);
|
|
19
20
|
__exportStar(require("./table-storage"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports-index.js","sourceRoot":"","sources":["../../src/storage/exports-index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,kDAAgC"}
|
|
1
|
+
{"version":3,"file":"exports-index.js","sourceRoot":"","sources":["../../src/storage/exports-index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,2CAAyB;AACzB,0CAAwB;AACxB,kDAAgC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kwiz/node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.42",
|
|
4
4
|
"description": "KWIZ utilities and helpers for node applications",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -73,14 +73,15 @@
|
|
|
73
73
|
"typescript": "^5.3.3"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"nodemailer": "^8.0.1",
|
|
77
|
-
"@jsforce/jsforce-node": "^3.10.14",
|
|
78
76
|
"@azure/data-tables": "^13.2.2",
|
|
79
77
|
"@azure/msal-node": "^2.6.4",
|
|
78
|
+
"@azure/storage-blob": "^12.31.0",
|
|
79
|
+
"@jsforce/jsforce-node": "^3.10.14",
|
|
80
80
|
"@kwiz/common": "^1.0.199",
|
|
81
81
|
"axios": "^1.6.7",
|
|
82
82
|
"esbuild": "^0.19.12",
|
|
83
83
|
"get-tsconfig": "^4.7.2",
|
|
84
|
+
"nodemailer": "^8.0.1",
|
|
84
85
|
"resolve-pkg-maps": "^1.0.0"
|
|
85
86
|
},
|
|
86
87
|
"peerDependencies": {
|