@or-sdk/files 0.20.1-createfilespackage.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.
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
54
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
55
+ if (ar || !(i in from)) {
56
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
57
+ ar[i] = from[i];
58
+ }
59
+ }
60
+ return to.concat(ar || Array.prototype.slice.call(from));
61
+ };
62
+ Object.defineProperty(exports, "__esModule", { value: true });
63
+ exports.Files = void 0;
64
+ var base_1 = require("@or-sdk/base");
65
+ var constants_1 = require("./constants");
66
+ var Files = (function (_super) {
67
+ __extends(Files, _super);
68
+ function Files(params) {
69
+ var token = params.token, discoveryUrl = params.discoveryUrl, accountId = params.accountId, serviceUrl = params.serviceUrl;
70
+ return _super.call(this, {
71
+ token: token,
72
+ discoveryUrl: discoveryUrl,
73
+ accountId: accountId,
74
+ serviceUrl: serviceUrl,
75
+ serviceKey: constants_1.SERVICE_KEY,
76
+ }) || this;
77
+ }
78
+ Files.prototype.getFolderSize = function (key) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ var size;
81
+ return __generator(this, function (_a) {
82
+ switch (_a.label) {
83
+ case 0: return [4, this.callApi({
84
+ method: 'GET',
85
+ route: 'api/folder',
86
+ params: { key: key },
87
+ })];
88
+ case 1:
89
+ size = (_a.sent()).size;
90
+ return [2, size];
91
+ }
92
+ });
93
+ });
94
+ };
95
+ Files.prototype.getItemsList = function (isPublic, prefix) {
96
+ return __awaiter(this, void 0, void 0, function () {
97
+ var nextToken, totalItems, queryParams, _a, items, nextTokenResponse;
98
+ return __generator(this, function (_b) {
99
+ switch (_b.label) {
100
+ case 0:
101
+ nextToken = null;
102
+ totalItems = [];
103
+ _b.label = 1;
104
+ case 1:
105
+ queryParams = { isPublic: isPublic, prefix: prefix };
106
+ if (nextToken)
107
+ queryParams.nextToken = nextToken;
108
+ return [4, this.callApi({ method: 'GET', route: 'api/files', params: queryParams })];
109
+ case 2:
110
+ _a = _b.sent(), items = _a.items, nextTokenResponse = _a.nextTokenResponse;
111
+ totalItems = __spreadArray(__spreadArray([], totalItems, true), items, true);
112
+ nextToken = nextTokenResponse;
113
+ _b.label = 3;
114
+ case 3:
115
+ if (nextToken) return [3, 1];
116
+ _b.label = 4;
117
+ case 4: return [2, totalItems];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ Files.prototype.createFolder = function (folderName) {
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ var e_1;
125
+ return __generator(this, function (_a) {
126
+ switch (_a.label) {
127
+ case 0:
128
+ _a.trys.push([0, 2, , 3]);
129
+ return [4, this.callApi({ method: 'post', route: 'api/files', data: { key: folderName + '/' } })];
130
+ case 1:
131
+ _a.sent();
132
+ return [3, 3];
133
+ case 2:
134
+ e_1 = _a.sent();
135
+ console.log(e_1);
136
+ return [3, 3];
137
+ case 3: return [2];
138
+ }
139
+ });
140
+ });
141
+ };
142
+ return Files;
143
+ }(base_1.Base));
144
+ exports.Files = Files;
145
+ //# sourceMappingURL=Files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Files.js","sourceRoot":"","sources":["../../src/Files.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAoC;AAEpC,yCAA0C;AAS1C;IAA2B,yBAAI;IAO7B,eAAY,MAAmB;QACrB,IAAA,KAAK,GAA0C,MAAM,MAAhD,EAAE,YAAY,GAA4B,MAAM,aAAlC,EAAE,SAAS,GAAiB,MAAM,UAAvB,EAAE,UAAU,GAAK,MAAM,WAAX,CAAY;eAE9D,kBAAM;YACJ,KAAK,OAAA;YACL,YAAY,cAAA;YACZ,SAAS,WAAA;YACT,UAAU,YAAA;YACV,UAAU,EAAE,uBAAW;SACxB,CAAC;IACJ,CAAC;IAMK,6BAAa,GAAnB,UAAqB,GAAW;;;;;4BACb,WAAM,IAAI,CAAC,OAAO,CAAC;4BAClC,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,YAAY;4BACnB,MAAM,EAAE,EAAE,GAAG,KAAA,EAAE;yBAChB,CAAC,EAAA;;wBAJM,IAAI,GAAK,CAAA,SAIf,CAAA,KAJU;wBAMZ,WAAO,IAAI,EAAA;;;;KACZ;IACK,4BAAY,GAAlB,UAAoB,QAAiB,EAAE,MAAc;;;;;;wBAC/C,SAAS,GAAkB,IAAI,CAAC;wBAChC,UAAU,GAAe,EAAE,CAAC;;;wBAGxB,WAAW,GAAY,EAAE,QAAQ,UAAA,EAAE,MAAM,QAAA,EAAE,CAAC;wBAClD,IAAI,SAAS;4BAAE,WAAW,CAAC,SAAS,GAAG,SAAS,CAAC;wBAEQ,WAAM,IAAI,CAAC,OAAO,CAAC,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAC,CAAC,EAAA;;wBAA/H,KAAmD,SAA4E,EAA9H,KAAK,WAAA,EAAE,iBAAiB,uBAAA;wBAC/B,UAAU,mCAAO,UAAU,SAAK,KAAK,OAAC,CAAC;wBAEvC,SAAS,GAAG,iBAAiB,CAAC;;;4BACvB,SAAS;;4BAElB,WAAO,UAAU,EAAC;;;;KACnB;IAEK,4BAAY,GAAlB,UAAoB,UAAkB;;;;;;;wBAElC,WAAM,IAAI,CAAC,OAAO,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,GAAG,EAAG,UAAU,GAAG,GAAG,EAAE,EAAE,CAAC,EAAA;;wBAA3F,SAA2F,CAAA;;;;wBAE3F,OAAO,CAAC,GAAG,CAAC,GAAC,CAAC,CAAA;;;;;;KAEjB;IACH,YAAC;AAAD,CAAC,AAxDD,CAA2B,WAAI,GAwD9B;AAxDY,sBAAK"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SERVICE_KEY = void 0;
4
+ exports.SERVICE_KEY = 'files-api';
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,WAAW,CAAC"}
@@ -0,0 +1,21 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Files = void 0;
18
+ var Files_1 = require("./Files");
19
+ Object.defineProperty(exports, "Files", { enumerable: true, get: function () { return Files_1.Files; } });
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Base } from '@or-sdk/base';
11
+ import { SERVICE_KEY } from './constants';
12
+ export class Files extends Base {
13
+ constructor(params) {
14
+ const { token, discoveryUrl, accountId, serviceUrl } = params;
15
+ super({
16
+ token,
17
+ discoveryUrl,
18
+ accountId,
19
+ serviceUrl,
20
+ serviceKey: SERVICE_KEY,
21
+ });
22
+ }
23
+ getFolderSize(key) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const { size } = yield this.callApi({
26
+ method: 'GET',
27
+ route: 'api/folder',
28
+ params: { key },
29
+ });
30
+ return size;
31
+ });
32
+ }
33
+ getItemsList(isPublic, prefix) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ let nextToken = null;
36
+ let totalItems = [];
37
+ do {
38
+ const queryParams = { isPublic, prefix };
39
+ if (nextToken)
40
+ queryParams.nextToken = nextToken;
41
+ const { items, nextTokenResponse } = yield this.callApi({ method: 'GET', route: 'api/files', params: queryParams });
42
+ totalItems = [...totalItems, ...items];
43
+ nextToken = nextTokenResponse;
44
+ } while (nextToken);
45
+ return totalItems;
46
+ });
47
+ }
48
+ createFolder(folderName) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ try {
51
+ yield this.callApi({ method: 'post', route: 'api/files', data: { key: folderName + '/' } });
52
+ }
53
+ catch (e) {
54
+ console.log(e);
55
+ }
56
+ });
57
+ }
58
+ }
59
+ //# sourceMappingURL=Files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Files.js","sourceRoot":"","sources":["../../src/Files.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAS1C,MAAM,OAAO,KAAM,SAAQ,IAAI;IAO7B,YAAY,MAAmB;QAC7B,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;QAE9D,KAAK,CAAC;YACJ,KAAK;YACL,YAAY;YACZ,SAAS;YACT,UAAU;YACV,UAAU,EAAE,WAAW;SACxB,CAAC,CAAC;IACL,CAAC;IAMK,aAAa,CAAE,GAAW;;YAC9B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;gBAClC,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,YAAY;gBACnB,MAAM,EAAE,EAAE,GAAG,EAAE;aAChB,CAAC,CAAA;YAEF,OAAO,IAAI,CAAA;QACb,CAAC;KAAA;IACK,YAAY,CAAE,QAAiB,EAAE,MAAc;;YACnD,IAAI,SAAS,GAAkB,IAAI,CAAC;YACpC,IAAI,UAAU,GAAe,EAAE,CAAC;YAEhC,GAAG;gBACD,MAAM,WAAW,GAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;gBAClD,IAAI,SAAS;oBAAE,WAAW,CAAC,SAAS,GAAG,SAAS,CAAC;gBAEjD,MAAM,EAAC,KAAK,EAAE,iBAAiB,EAAC,GAAyB,MAAM,IAAI,CAAC,OAAO,CAAC,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAC,CAAC,CAAC;gBACtI,UAAU,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,KAAK,CAAC,CAAC;gBAEvC,SAAS,GAAG,iBAAiB,CAAC;aAC/B,QAAQ,SAAS,EAAE;YAEpB,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;IAEK,YAAY,CAAE,UAAkB;;YACpC,IAAI;gBACF,MAAM,IAAI,CAAC,OAAO,CAAC,EAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,GAAG,EAAG,UAAU,GAAG,GAAG,EAAE,EAAE,CAAC,CAAA;aAC5F;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;aACf;QACH,CAAC;KAAA;CACF"}
@@ -0,0 +1,2 @@
1
+ export const SERVICE_KEY = 'files-api';
2
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { Files } from './Files';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { Base } from '@or-sdk/base';
2
+ import { FilesConfig, FileItem } from './types';
3
+ export declare class Files extends Base {
4
+ constructor(params: FilesConfig);
5
+ getFolderSize(key: string): Promise<number>;
6
+ getItemsList(isPublic: boolean, prefix: string): Promise<FileItem[]>;
7
+ createFolder(folderName: string): Promise<void>;
8
+ }
@@ -0,0 +1 @@
1
+ export declare const SERVICE_KEY = "files-api";
@@ -0,0 +1,2 @@
1
+ export { Files } from './Files';
2
+ export * from './types';
@@ -0,0 +1,28 @@
1
+ import { Token } from '@or-sdk/base';
2
+ export declare type FilesConfig = {
3
+ token: Token;
4
+ discoveryUrl?: string;
5
+ accountId?: string;
6
+ serviceUrl?: string;
7
+ };
8
+ export declare type LsQuery = {
9
+ isPublic: boolean;
10
+ prefix: string;
11
+ nextToken?: string;
12
+ };
13
+ export declare type FileItem = {
14
+ key: string;
15
+ size?: number;
16
+ };
17
+ export declare type FilesPageState = {
18
+ filesInstance: any;
19
+ userToken: string;
20
+ discoveryUrl: string;
21
+ serviceUrl: string;
22
+ accountId: string;
23
+ items: FileItem[];
24
+ };
25
+ export declare type getItemsListResponse = {
26
+ items: FileItem[];
27
+ nextTokenResponse: string | null;
28
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "version": "0.20.1-createfilespackage.0",
3
+ "name": "@or-sdk/files",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "build": "npm run clean && concurrently \"npm run build:cjs\" \"npm run build:esm\" \"npm run build:types\"",
9
+ "build:watch": "concurrently -r --hide 1,2 \"npm run build:watch:cjs\" \"npm run build:watch:esm\" \"npm run build:watch:types\"",
10
+ "build:cjs": "tsc --project tsconfig.json",
11
+ "build:watch:cjs": "tsc --project tsconfig.json -w",
12
+ "build:esm": "tsc --project tsconfig.esm.json",
13
+ "build:watch:esm": "tsc --project tsconfig.esm.json -w",
14
+ "build:types": "tsc --project tsconfig.types.json",
15
+ "build:watch:types": "tsc --project tsconfig.types.json -w",
16
+ "clean": "rm -rf ./dist"
17
+ },
18
+ "devDependencies": {
19
+ "concurrently": "^6.4.0",
20
+ "typescript": "^4.4.4"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "dependencies": {
26
+ "@or-sdk/base": "^0.20.1-createfilespackage.0"
27
+ },
28
+ "gitHead": "64b4356c7b747020f554242be7c3885b2f651ad3"
29
+ }
package/src/Files.ts ADDED
@@ -0,0 +1,68 @@
1
+ import { Base } from '@or-sdk/base';
2
+ import { FilesConfig, LsQuery, FileItem, getItemsListResponse } from './types';
3
+ import { SERVICE_KEY } from './constants';
4
+
5
+ /**
6
+ * OneReach Files service client
7
+ * ## Installation:
8
+ * ```
9
+ * $ npm i @or-sdk/files
10
+ * ```
11
+ */
12
+ export class Files extends Base {
13
+ /**
14
+ * ```typescript
15
+ * import { Files } from '@or-sdk/files'
16
+ * const files = new Files({token: 'my-account-token-string', discoveryUrl: 'http://example.tables/endpoint'});
17
+ * ```
18
+ */
19
+ constructor(params: FilesConfig) {
20
+ const { token, discoveryUrl, accountId, serviceUrl } = params;
21
+
22
+ super({
23
+ token,
24
+ discoveryUrl,
25
+ accountId,
26
+ serviceUrl,
27
+ serviceKey: SERVICE_KEY,
28
+ });
29
+ }
30
+
31
+ /**
32
+ * Get folder size
33
+ * @param key the name of folder
34
+ */
35
+ async getFolderSize (key: string): Promise<number> {
36
+ const { size } = await this.callApi({
37
+ method: 'GET',
38
+ route: 'api/folder',
39
+ params: { key },
40
+ })
41
+
42
+ return size
43
+ }
44
+ async getItemsList (isPublic: boolean, prefix: string): Promise<FileItem[]> {
45
+ let nextToken: null | string = null;
46
+ let totalItems: FileItem[] = [];
47
+
48
+ do {
49
+ const queryParams :LsQuery = { isPublic, prefix };
50
+ if (nextToken) queryParams.nextToken = nextToken;
51
+
52
+ const {items, nextTokenResponse}: getItemsListResponse = await this.callApi({method: 'GET', route: 'api/files', params: queryParams});
53
+ totalItems = [...totalItems, ...items];
54
+
55
+ nextToken = nextTokenResponse;
56
+ } while (nextToken);
57
+
58
+ return totalItems;
59
+ }
60
+
61
+ async createFolder (folderName: string) {
62
+ try {
63
+ await this.callApi({method: 'post', route: 'api/files', data: { key : folderName + '/' } })
64
+ } catch (e) {
65
+ console.log(e)
66
+ }
67
+ }
68
+ }
@@ -0,0 +1 @@
1
+ export const SERVICE_KEY = 'files-api';
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Files } from './Files';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { Token } from '@or-sdk/base';
2
+
3
+ export type FilesConfig = {
4
+ /**
5
+ * token
6
+ */
7
+ token: Token;
8
+ /**
9
+ * Url of OneReach service discovery api
10
+ */
11
+ discoveryUrl?: string;
12
+ /**
13
+ * Account ID for cross-account requests (super admin only)
14
+ */
15
+ accountId?: string;
16
+ /**
17
+ * Direct service url, can be used to avoid discovery api call
18
+ */
19
+ serviceUrl?: string;
20
+ };
21
+
22
+ export type LsQuery = {
23
+ isPublic: boolean,
24
+ prefix: string,
25
+ nextToken?: string
26
+ }
27
+
28
+ export type FileItem = {
29
+ key: string,
30
+ size?: number
31
+ }
32
+
33
+ export type FilesPageState = {
34
+ filesInstance: any,
35
+ userToken: string,
36
+ discoveryUrl: string,
37
+ serviceUrl: string,
38
+ accountId: string,
39
+ items: FileItem[]
40
+ }
41
+ export type getItemsListResponse = {
42
+ items: FileItem[],
43
+ nextTokenResponse: string | null
44
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ES6",
5
+ "target": "es6",
6
+ "outDir": "./dist/esm/",
7
+ "rootDir": "./src"
8
+ }
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs/",
5
+ "rootDir": "./src"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/types/",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true
8
+ }
9
+ }