@sap-ux/axios-extension 1.1.0 → 1.2.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.
@@ -0,0 +1,48 @@
1
+ import { AdtService } from './adt-service';
2
+ import type { AdtCategory, ArchiveFileNodeType, ArchiveFileContentType } from '../../types';
3
+ /**
4
+ * FileStoreService implements ADT requests to obtain the content
5
+ * of deployed archive.
6
+ */
7
+ export declare class FileStoreService extends AdtService {
8
+ /**
9
+ * @see AdtService.getAdtCatagory()
10
+ */
11
+ private static adtCategory;
12
+ /**
13
+ * Get ADT scheme ID.
14
+ *
15
+ * @returns AdtCategory
16
+ */
17
+ static getAdtCatagory(): AdtCategory;
18
+ /**
19
+ * If target `path` is a file, the file content is returned as string type.
20
+ * If target `path` is a folder, files and folders in this folder are returned as an array
21
+ * of ArchiveFileNode objects.
22
+ *
23
+ * @see ArchiveFileNode
24
+ * @param type
25
+ * Specifies if input `path` refers to a file or a folder. When starting exploring
26
+ * the file structure from the root, type should be set to `folder`. The type information
27
+ * of files and folders inside root folder can be found in the returned `ArchiveFileNode` entries.
28
+ * @param appName Deployed Fiori app name
29
+ * @param path
30
+ * Default value is empty string. In this case the output would be folder structure information of the root folder.
31
+ * Otherwise provide path to a folder or a file in the deployed archive. E.g. `/webapp/index.html`.
32
+ * @returns Folder content (ArchiveFileNode[]) | file content (string)
33
+ */
34
+ getAppArchiveContent<T extends ArchiveFileNodeType>(type: T, appName: string, path?: string): Promise<ArchiveFileContentType<T>>;
35
+ /**
36
+ * Parse response data from ADT service. If the content is XML document of
37
+ * folder structure, this method returns a list of `ArchiveFileNode` object. If the content
38
+ * is text string, this method returns the text cotent.
39
+ *
40
+ * @see ArchiveFileNode
41
+ * @param appName Deployed Fiori app name
42
+ * @param responseData Response from ADT service
43
+ * @param type Reponse data is the file content or folder content.
44
+ * @returns Folder content (ArchiveFileNode[]) | file content (string)
45
+ */
46
+ private parseArchiveContentResponse;
47
+ }
48
+ //# sourceMappingURL=filestore-service.d.ts.map
@@ -0,0 +1,119 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.FileStoreService = void 0;
16
+ const adt_service_1 = require("./adt-service");
17
+ const fast_xml_parser_1 = __importDefault(require("fast-xml-parser"));
18
+ /**
19
+ * FileStoreService implements ADT requests to obtain the content
20
+ * of deployed archive.
21
+ */
22
+ class FileStoreService extends adt_service_1.AdtService {
23
+ /**
24
+ * Get ADT scheme ID.
25
+ *
26
+ * @returns AdtCategory
27
+ */
28
+ static getAdtCatagory() {
29
+ return FileStoreService.adtCategory;
30
+ }
31
+ /**
32
+ * If target `path` is a file, the file content is returned as string type.
33
+ * If target `path` is a folder, files and folders in this folder are returned as an array
34
+ * of ArchiveFileNode objects.
35
+ *
36
+ * @see ArchiveFileNode
37
+ * @param type
38
+ * Specifies if input `path` refers to a file or a folder. When starting exploring
39
+ * the file structure from the root, type should be set to `folder`. The type information
40
+ * of files and folders inside root folder can be found in the returned `ArchiveFileNode` entries.
41
+ * @param appName Deployed Fiori app name
42
+ * @param path
43
+ * Default value is empty string. In this case the output would be folder structure information of the root folder.
44
+ * Otherwise provide path to a folder or a file in the deployed archive. E.g. `/webapp/index.html`.
45
+ * @returns Folder content (ArchiveFileNode[]) | file content (string)
46
+ */
47
+ getAppArchiveContent(type, appName, path = '') {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const contentType = type === 'folder' ? 'application/atom+xml' : 'application/octet-stream';
50
+ const config = {
51
+ headers: {
52
+ Accept: 'application/xml',
53
+ 'Content-Type': contentType
54
+ }
55
+ };
56
+ if (path && !path.startsWith('/')) {
57
+ throw new Error('Input argument "path" needs to start with /');
58
+ }
59
+ const encodedFullPath = encodeURIComponent(`${appName}${path}`);
60
+ const response = yield this.get(`/${encodedFullPath}/content`, config);
61
+ return this.parseArchiveContentResponse(appName, response.data, type);
62
+ });
63
+ }
64
+ /**
65
+ * Parse response data from ADT service. If the content is XML document of
66
+ * folder structure, this method returns a list of `ArchiveFileNode` object. If the content
67
+ * is text string, this method returns the text cotent.
68
+ *
69
+ * @see ArchiveFileNode
70
+ * @param appName Deployed Fiori app name
71
+ * @param responseData Response from ADT service
72
+ * @param type Reponse data is the file content or folder content.
73
+ * @returns Folder content (ArchiveFileNode[]) | file content (string)
74
+ */
75
+ parseArchiveContentResponse(appName, responseData, type) {
76
+ // File content that is not xml data.
77
+ if (type === 'file') {
78
+ return responseData;
79
+ }
80
+ // A list of file/folder items in the response data as xml string.
81
+ if (fast_xml_parser_1.default.validate(responseData) !== true) {
82
+ throw new Error('Invalid XML content');
83
+ }
84
+ const options = {
85
+ attributeNamePrefix: '',
86
+ ignoreAttributes: false,
87
+ ignoreNameSpace: true,
88
+ parseAttributeValue: true
89
+ };
90
+ const obj = fast_xml_parser_1.default.getTraversalObj(responseData, options);
91
+ const parsed = fast_xml_parser_1.default.convertToJson(obj, options);
92
+ let fileNodeArray = [];
93
+ if (parsed === null || parsed === void 0 ? void 0 : parsed.feed) {
94
+ if (Array.isArray(parsed.feed.entry)) {
95
+ fileNodeArray = parsed.feed.entry;
96
+ }
97
+ else {
98
+ fileNodeArray = [parsed.feed.entry];
99
+ }
100
+ }
101
+ return fileNodeArray.map((fileNode) => {
102
+ const exposedFileNode = {
103
+ basename: fileNode.title.split('/').pop(),
104
+ path: fileNode.title.substring(appName.length),
105
+ type: fileNode.category.term
106
+ };
107
+ return exposedFileNode;
108
+ });
109
+ }
110
+ }
111
+ exports.FileStoreService = FileStoreService;
112
+ /**
113
+ * @see AdtService.getAdtCatagory()
114
+ */
115
+ FileStoreService.adtCategory = {
116
+ scheme: 'http://www.sap.com/adt/categories/filestore',
117
+ term: 'filestore-ui5-bsp'
118
+ };
119
+ //# sourceMappingURL=filestore-service.js.map
@@ -3,4 +3,5 @@ export { AtoService } from './ato-service';
3
3
  export { TransportChecksService } from './transportcheck-service';
4
4
  export { TransportRequestService, NewUi5ObjectRequestParams } from './transportrequest-service';
5
5
  export { ListPackageService } from './list-package-service';
6
+ export { FileStoreService } from './filestore-service';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ListPackageService = exports.TransportRequestService = exports.TransportChecksService = exports.AtoService = exports.AdtService = void 0;
3
+ exports.FileStoreService = exports.ListPackageService = exports.TransportRequestService = exports.TransportChecksService = exports.AtoService = exports.AdtService = void 0;
4
4
  var adt_service_1 = require("./adt-service");
5
5
  Object.defineProperty(exports, "AdtService", { enumerable: true, get: function () { return adt_service_1.AdtService; } });
6
6
  var ato_service_1 = require("./ato-service");
@@ -11,4 +11,6 @@ var transportrequest_service_1 = require("./transportrequest-service");
11
11
  Object.defineProperty(exports, "TransportRequestService", { enumerable: true, get: function () { return transportrequest_service_1.TransportRequestService; } });
12
12
  var list_package_service_1 = require("./list-package-service");
13
13
  Object.defineProperty(exports, "ListPackageService", { enumerable: true, get: function () { return list_package_service_1.ListPackageService; } });
14
+ var filestore_service_1 = require("./filestore-service");
15
+ Object.defineProperty(exports, "FileStoreService", { enumerable: true, get: function () { return filestore_service_1.FileStoreService; } });
14
16
  //# sourceMappingURL=index.js.map
@@ -5,5 +5,5 @@ export { AppIndex, AppIndexService } from './app-index-service';
5
5
  export * from './message';
6
6
  export * from './catalog';
7
7
  export * from './adt-catalog';
8
- export { TenantType } from './types';
8
+ export { TenantType, ArchiveFileNode } from './types';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -8,4 +8,32 @@ export interface PackageInfo {
8
8
  type: string;
9
9
  name: string;
10
10
  }
11
+ /**
12
+ * This type is used internally for the list of `ArchiveFileNode`
13
+ * returned from ADT rest api. Each `ArchiveFileNode` provides
14
+ * metadata information of a file/folder in the archived Fiori app.
15
+ * It should not be exposed for public use via axios-extension.
16
+ */
17
+ export interface AdtFileNode {
18
+ base: string;
19
+ author: string;
20
+ category: {
21
+ term: 'folder' | 'file';
22
+ };
23
+ content: {
24
+ type: string;
25
+ src: string;
26
+ };
27
+ contributor: string;
28
+ id: string;
29
+ link: {
30
+ href: string;
31
+ ref: 'appindex' | 'self' | 'execute';
32
+ type?: string;
33
+ }[];
34
+ summary: {
35
+ type: 'text';
36
+ };
37
+ title: string;
38
+ }
11
39
  //# sourceMappingURL=adt-internal-types.d.ts.map
@@ -79,4 +79,23 @@ export interface AtoSettings {
79
79
  }
80
80
  export type AdtTransportStatus = 'S' | 'E';
81
81
  export declare const LocalPackageText: string[];
82
+ export interface ArchiveFileNode {
83
+ /**
84
+ * file or folder name only
85
+ */
86
+ basename: string;
87
+ /**
88
+ * Path to the file or folder. Ready to be passed to the `path`
89
+ * argument of FileStoreService.getAppArchiveContent() method.
90
+ *
91
+ * @see FileStoreService.getAppArchiveContent
92
+ */
93
+ path: string;
94
+ /**
95
+ * 'file' | 'folder'
96
+ */
97
+ type: ArchiveFileNodeType;
98
+ }
99
+ export type ArchiveFileNodeType = 'file' | 'folder';
100
+ export type ArchiveFileContentType<T> = T extends 'file' ? string : T extends 'folder' ? ArchiveFileNode[] : never;
82
101
  //# sourceMappingURL=adt-types.d.ts.map
@@ -42,7 +42,7 @@ class Cookies {
42
42
  addCookie(cookieString) {
43
43
  var _a;
44
44
  const cookie = cookieString.split(';');
45
- const [key, ...values] = (_a = cookie[0]) === null || _a === void 0 ? void 0 : _a.split('=');
45
+ const [key, ...values] = ((_a = cookie[0]) === null || _a === void 0 ? void 0 : _a.split('=')) || [];
46
46
  const value = values === null || values === void 0 ? void 0 : values.join('='); // Account for embedded '=' in the value
47
47
  if (key && cookieString.indexOf('Max-Age=0') >= 0) {
48
48
  delete this.cookies[key];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/axios-extension",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Extension of the Axios module adding convinience methods to interact with SAP systems especially with OData services.",
5
5
  "repository": {
6
6
  "type": "git",