• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jumpinjackie / mapguide-react-layout / 15160437878

21 May 2025 11:00AM UTC coverage: 21.631% (-42.6%) from 64.24%
15160437878

Pull #1552

github

web-flow
Merge 8b7153d9e into 236e2ea07
Pull Request #1552: Feature/package updates 2505

839 of 1165 branches covered (72.02%)

11 of 151 new or added lines in 25 files covered. (7.28%)

1332 existing lines in 50 files now uncovered.

4794 of 22163 relevant lines covered (21.63%)

6.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.48
/src/api/builders/mapagent.ts
1
import { MgError } from '../error';
1✔
2
import { deArrayify } from './deArrayify';
1✔
3
import { DEFAULT_LOCALE } from "../i18n";
1✔
4
import { RequestBuilder, ICreateRuntimeMapOptions, IQueryMapFeaturesOptions, IDescribeRuntimeMapOptions } from '../request-builder';
1✔
5
import { RuntimeMap } from '../contracts/runtime-map';
6
import { QueryMapFeaturesResponse } from '../contracts/query';
7
import { ResourceIdentifier, ResourceBase, SiteVersionResponse } from '../contracts/common';
8

9
const MG_MAPAGENT_ERROR_CODE = 559;
1✔
10

11
/**
12
 * Indicates if the given response is an error response
13
 *
14
 * @export
15
 * @param {Response} response
16
 * @returns {boolean}
17
 */
18
export function isErrorResponse(response: Response): boolean {
1✔
19
    return !response.ok || response.status === MG_MAPAGENT_ERROR_CODE;
×
UNCOV
20
}
×
21

22
/**
23
 * Encodes the given object for a POST submission
24
 *
25
 * @export
26
 * @param {*} data
27
 * @returns {string}
28
 */
29
export function serialize(data: any, uppercase: boolean = true): string {
1✔
30
    return Object.keys(data).map((keyName) => {
×
31
        return encodeURIComponent(uppercase ? keyName.toUpperCase() : keyName) + '=' + encodeURIComponent(data[keyName])
×
UNCOV
32
    }).join('&');
×
UNCOV
33
}
×
34

35
/**
36
 * The mapagent client
37
 *
38
 * @export
39
 * @class MapAgentRequestBuilder
40
 * @extends {RequestBuilder}
41
 */
42
export class MapAgentRequestBuilder extends RequestBuilder {
1✔
43
    private locale: string;
44
    constructor(agentUri: string, locale: string = DEFAULT_LOCALE) {
1✔
45
        super(agentUri);
×
46
        this.locale = locale;
×
UNCOV
47
    }
×
48

49
    public async get<T>(url: string): Promise<T> {
1✔
50
        const response = await fetch(url, {
×
UNCOV
51
            headers: {
×
UNCOV
52
                'Accept': 'application/json',
×
UNCOV
53
                'Content-Type': 'application/json'
×
UNCOV
54
            } as any,
×
UNCOV
55
            method: "GET"
×
UNCOV
56
        });
×
57
        if (isErrorResponse(response)) {
×
58
            throw new MgError(response.statusText);
×
UNCOV
59
        } else {
×
60
            const json = await response.json();
×
61
            return deArrayify(json) as T;
×
UNCOV
62
        }
×
UNCOV
63
    }
×
64

65
    public async post<T>(url: string, data: any): Promise<T> {
1✔
66
        if (!data.format) {
×
67
            data.format = "application/json";
×
UNCOV
68
        }
×
69
        //const form = new FormData();
70
        //for (const key in data) {
71
        //    form.append(key.toUpperCase(), data[key]);
72
        //}
73
        const response = await fetch(url, {
×
UNCOV
74
            headers: {
×
UNCOV
75
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
×
UNCOV
76
            } as any,
×
UNCOV
77
            method: "POST",
×
UNCOV
78
            body: serialize(data) //form
×
UNCOV
79
        });
×
80
        if (isErrorResponse(response)) {
×
81
            throw new MgError(response.statusText);
×
UNCOV
82
        } else {
×
83
            const json = await response.json();
×
84
            return deArrayify(json) as T;
×
UNCOV
85
        }
×
UNCOV
86
    }
×
87

88
    private stringifyGetUrl(options: any): string {
1✔
89
        if (!options.version) {
×
90
            options.version = "1.0.0";
×
UNCOV
91
        }
×
92
        if (!options.locale) {
×
93
            options.locale = this.locale;
×
UNCOV
94
        }
×
95
        if (!options.format) {
×
96
            options.format = "application/json";
×
UNCOV
97
        }
×
98
        let url = this.agentUri;
×
99
        let bFirst = true;
×
100
        for (const key in options) {
×
101
            if (bFirst) {
×
102
                url += `?${key.toUpperCase()}=${options[key]}`;
×
103
                bFirst = false;
×
UNCOV
104
            } else {
×
105
                url += `&${key.toUpperCase()}=${options[key]}`;
×
UNCOV
106
            }
×
UNCOV
107
        }
×
108
        return url;
×
UNCOV
109
    }
×
110

111
    public async createSession(username: string, password: string): Promise<string> {
1✔
112
        const url = this.agentUri;
×
113
        const data = { operation: "CREATESESSION", version: "1.0.0", USERNAME: username, PASSWORD: password };
×
114
        const response = await fetch(url, {
×
UNCOV
115
            headers: {
×
UNCOV
116
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
×
UNCOV
117
            } as any,
×
UNCOV
118
            method: "POST",
×
UNCOV
119
            body: serialize(data) //form
×
UNCOV
120
        });
×
121
        if (isErrorResponse(response)) {
×
122
            throw new MgError(response.statusText);
×
UNCOV
123
        } else {
×
124
            return await response.text();
×
UNCOV
125
        }
×
UNCOV
126
    }
×
127

128
    public async getServerSessionTimeout(session: string): Promise<number> {
1✔
129
        const url = this.agentUri;
×
130
        const data = { operation: "GETSESSIONTIMEOUT", version: "1.0.0", SESSION: session };
×
131
        const response = await fetch(url, {
×
UNCOV
132
            headers: {
×
UNCOV
133
                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
×
UNCOV
134
            } as any,
×
UNCOV
135
            method: "POST",
×
UNCOV
136
            body: serialize(data) //form
×
UNCOV
137
        });
×
138
        if (isErrorResponse(response)) {
×
139
            throw new MgError(response.statusText);
×
UNCOV
140
        } else {
×
141
            const val = await response.text();
×
142
            return parseInt(val, 10);
×
UNCOV
143
        }
×
UNCOV
144
    }
×
145

146
    public getResource<T extends ResourceBase>(resourceId: ResourceIdentifier, args?: any): Promise<T> {
1✔
147
        if (args != null) {
×
148
            const p1 = { operation: "GETRESOURCECONTENT", resourceId: resourceId };
×
149
            const url = this.stringifyGetUrl({ ...args, ...p1 });
×
150
            return this.get<T>(url);
×
UNCOV
151
        } else {
×
152
            const url = this.stringifyGetUrl({ operation: "GETRESOURCE", resourceId: resourceId });
×
153
            return this.get<T>(url);
×
UNCOV
154
        }
×
UNCOV
155
    }
×
156

157
    public getSiteVersion(): Promise<SiteVersionResponse> {
1✔
158
        const p1 = { operation: "GETSITEVERSION", version: "1.0.0", username: "Anonymous" };
×
159
        const url = this.stringifyGetUrl({ ...p1 });
×
160
        return this.get<SiteVersionResponse>(url);
×
UNCOV
161
    }
×
162

163
    public createRuntimeMap(options: ICreateRuntimeMapOptions): Promise<RuntimeMap> {
1✔
164
        const p1 = { operation: "CREATERUNTIMEMAP", version: "3.0.0" };
×
165
        const url = this.stringifyGetUrl({ ...options, ...p1 });
×
166
        return this.get<RuntimeMap>(url);
×
UNCOV
167
    }
×
168

169
    public createRuntimeMap_v4(options: ICreateRuntimeMapOptions): Promise<RuntimeMap> {
1✔
170
        const p1 = { operation: "CREATERUNTIMEMAP", version: "4.0.0" };
×
171
        const url = this.stringifyGetUrl({ ...options, ...p1 });
×
172
        return this.get<RuntimeMap>(url);
×
UNCOV
173
    }
×
174

175
    public queryMapFeatures(options: IQueryMapFeaturesOptions): Promise<QueryMapFeaturesResponse> {
1✔
176
        const p1 = { operation: "QUERYMAPFEATURES", version: "2.6.0" };
×
177
        return this.post<QueryMapFeaturesResponse>(this.agentUri, { ...options, ...p1 });
×
UNCOV
178
    }
×
179

180
    public queryMapFeatures_v4(options: IQueryMapFeaturesOptions): Promise<QueryMapFeaturesResponse> {
1✔
181
        const p1 = { operation: "QUERYMAPFEATURES", version: "4.0.0" };
×
182
        return this.post<QueryMapFeaturesResponse>(this.agentUri, { ...options, ...p1 });
×
UNCOV
183
    }
×
184

185
    public describeRuntimeMap(options: IDescribeRuntimeMapOptions): Promise<RuntimeMap> {
1✔
186
        const p1 = { operation: "DESCRIBERUNTIMEMAP", version: "3.0.0" };
×
187
        const url = this.stringifyGetUrl({ ...options, ...p1 });
×
188
        return this.get<RuntimeMap>(url);
×
UNCOV
189
    }
×
190

191
    public describeRuntimeMap_v4(options: IDescribeRuntimeMapOptions): Promise<RuntimeMap> {
1✔
192
        const p1 = { operation: "DESCRIBERUNTIMEMAP", version: "4.0.0" };
×
193
        const url = this.stringifyGetUrl({ ...options, ...p1 });
×
194
        return this.get<RuntimeMap>(url);
×
UNCOV
195
    }
×
196

197
    public getTileTemplateUrl(resourceId: string, groupName: string, xPlaceholder: string, yPlaceholder: string, zPlaceholder: string, isXYZ: boolean): string {
1✔
198
        if (isXYZ)
×
199
            return`${this.agentUri}?OPERATION=GETTILEIMAGE&VERSION=1.2.0&USERNAME=Anonymous&MAPDEFINITION=${resourceId}&BASEMAPLAYERGROUPNAME=${groupName}&TILECOL=${yPlaceholder}&TILEROW=${xPlaceholder}&SCALEINDEX=${zPlaceholder}`;
×
200
        else
201
            return`${this.agentUri}?OPERATION=GETTILEIMAGE&VERSION=1.2.0&USERNAME=Anonymous&MAPDEFINITION=${resourceId}&BASEMAPLAYERGROUPNAME=${groupName}&TILECOL=${xPlaceholder}&TILEROW=${yPlaceholder}&SCALEINDEX=${zPlaceholder}`;
×
UNCOV
202
    }
×
203
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc