Skip to content

Commit 65c3711

Browse files
authored
fix: use graphs from style and use new moco export api (#225)
* fix: use the correct graph for the moco features * fix: use graph from style * fix: add missing files * fix: use dev urls * fix: use dev urls * chore(release): 3.3.3-beta.0 * chore(release): 3.3.3-beta.1 * chore(release): 3.3.4-beta.0 * fix: improve graph used * fix: improve graph used * chore(release): 3.3.4-beta.1 * chore(release): 3.3.4-beta.2 * chore(release): 3.3.4-beta.3 * chore(release): 3.3.4-beta.4 * fix: improve graph used * chore(release): 3.3.4-beta.5 * fix: always filter the data * chore(release): 3.3.4-beta.6 * fix: remove useless property * chore: add some utils function for backward compatibility * fix: use grphwl types * fix: use grphwl types * test: add test for utils fonctions * chore(release): 3.3.4-beta.7 * test: fix url * chore: fix types export * chore(release): 3.3.4-beta.8 * fix: fix overriding of geometry properties * chore(release): 3.3.4-beta.9 * fix: use uuid * chore(release): 3.3.4-beta.10 * fix: make sure situationId is well set * chore(release): 3.3.4-beta.11 * fix: export types from layers * chore(release): 3.3.4-beta.12 * fix: use varibale sin dev * fix: manage abort error * chore(release): 3.3.4-beta.13 * fix: add getRefreshTimeInMs options * chore(release): 3.3.4-beta.14 * fix: situations gettertreturns the situations loaded * chore(release): 3.3.4-beta.15 * fix: situations gettertreturns the situations loaded * chore(release): 3.3.4-beta.16 * fix: fix rendering * fix: revert change in renderer * chore(release): 3.3.4-beta.17 * fix: revert change in renderer * fix: revert change in renderer * chore(release): 3.3.4-beta.18 * fix: fix loading of situations * chore(release): 3.3.4-beta.19 * chore(release): 3.3.4-beta.20 * fix: simplify moco layer * chore(release): 3.3.4-beta.21 * chore: remove console log * fix: updates types * chore(release): 3.3.4-beta.22 * fix: allow to pass api parameters to the moco layer * fix: allow to pass api parameters to the moco layer * fix: allow to pass api parameters to the moco layer * chore(release): 3.3.4-beta.23 * fix: add apiParameters * chore(release): 3.3.4-beta.24 * chore(release): 3.3.4-beta.25 * chore: updtae libs and read yarn.lock * chore(release): 3.3.4-beta.26 * chore(release): 3.3.4-beta.27 * chore(release): 3.3.4-beta.28 * chore: updtae libs and read yarn.lock * chore(release): 3.3.4-beta.29 * chore(release): 3.3.4-beta.30 * fix: pass reasons * chore(release): 3.3.4-beta.31 * fix: fix tests
1 parent de51cf7 commit 65c3711

28 files changed

+8053
-4658
lines changed

dev.js

Lines changed: 1439 additions & 309 deletions
Large diffs are not rendered by default.

doc/src/components/Esdoc/index.json

Lines changed: 668 additions & 565 deletions
Large diffs are not rendered by default.

doc/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4810,7 +4810,7 @@ mkdirp@^0.5.1:
48104810
minimist "^1.2.6"
48114811

48124812
mobility-toolbox-js@./../build:
4813-
version "3.3.1"
4813+
version "3.3.2"
48144814
dependencies:
48154815
"@geoblocks/ol-maplibre-layer" "^1.0.3"
48164816
"@turf/helpers" "7.2.0"

graphql-codegen-moco.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { CodegenConfig } from '@graphql-codegen/cli';
2+
3+
const config: CodegenConfig = {
4+
// documents: ['src/**/*.tsx'],
5+
generates: {
6+
'./src/types/moco/gql/': {
7+
preset: 'client',
8+
},
9+
},
10+
schema: '../moco3/backend/schema.graphql',
11+
};
12+
export default config;

package.json

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "mobility-toolbox-js",
33
"license": "MIT",
44
"description": "Toolbox for JavaScript applications in the domains of mobility and logistics.",
5-
"version": "3.3.3",
5+
"version": "3.3.4-beta.31",
66
"homepage": "https://mobility-toolbox-js.geops.io/",
77
"exports": {
88
".": "./index.js",
@@ -17,65 +17,69 @@
1717
"@turf/transform-rotate": "7.2.0",
1818
"lodash.debounce": "4.0.8",
1919
"lodash.throttle": "4.1.1",
20-
"uuid": "11.1.0"
20+
"uuid": "13.0.0"
2121
},
2222
"peerDependencies": {
2323
"maplibre-gl": ">=4",
2424
"ol": ">=9"
2525
},
2626
"devDependencies": {
27-
"@babel/preset-env": "^7.28.0",
27+
"@babel/preset-env": "^7.28.3",
2828
"@babel/preset-typescript": "^7.27.1",
2929
"@commitlint/cli": "19.8.1",
3030
"@commitlint/config-conventional": "19.8.1",
3131
"@geops/eslint-config-react": "1.5.0",
32+
"@graphql-codegen/cli": "^6.0.0",
33+
"@graphql-codegen/typescript": "^5.0.0",
34+
"@graphql-codegen/typescript-operations": "^5.0.0",
3235
"@types/geojson": "7946.0.16",
3336
"@types/lodash": "^4.17.20",
3437
"@types/lodash.debounce": "4.0.9",
3538
"@types/lodash.throttle": "4.1.9",
3639
"@types/mapbox-gl": "3.4.1",
3740
"@types/offscreencanvas": "2019.7.3",
3841
"@types/topojson": "3.2.6",
39-
"@types/uuid": "10.0.0",
40-
"@typescript-eslint/eslint-plugin": "8.38.0",
41-
"@typescript-eslint/parser": "8.38.0",
42-
"cypress": "14.5.2",
43-
"esbuild": "0.25.8",
42+
"@types/uuid": "11.0.0",
43+
"@typescript-eslint/eslint-plugin": "8.44.1",
44+
"@typescript-eslint/parser": "8.44.1",
45+
"cypress": "15.3.0",
46+
"esbuild": "0.25.10",
4447
"esdoc": "1.1.0",
4548
"esdoc-ecmascript-proposal-plugin": "1.0.0",
4649
"esdoc-publish-html-plugin": "1.1.2",
4750
"esdoc-standard-plugin": "1.0.0",
4851
"esdoc-typescript-plugin": "1.0.1",
49-
"eslint": "9.31.0",
52+
"eslint": "9.36.0",
5053
"fixpack": "4.0.0",
54+
"graphql": "^16.11.0",
5155
"husky": "9.1.7",
5256
"is-ci": "4.1.0",
53-
"jest": "30.0.5",
57+
"jest": "30.1.3",
5458
"jest-canvas-mock": "2.5.2",
55-
"jest-environment-jsdom": "30.0.5",
59+
"jest-environment-jsdom": "30.1.2",
5660
"jest-fetch-mock": "3.0.3",
5761
"jest-serializer-html": "7.1.0",
5862
"jest-transformer-svg": "2.1.0",
5963
"jest-websocket-mock": "2.5.0",
60-
"lint-staged": "16.1.2",
61-
"maplibre-gl": "5.6.1",
64+
"lint-staged": "16.2.0",
65+
"maplibre-gl": "5.7.3",
6266
"mock-socket": "9.3.1",
63-
"next": "15.4.3",
67+
"next": "15.4.5",
6468
"next-transpile-modules": "10.0.1",
6569
"ol": "10.6.1",
66-
"openapi-typescript": "7.8.0",
70+
"openapi-typescript": "5",
6771
"prettier": "3.6.2",
6872
"raw-loader": "4.0.2",
6973
"sort-json": "2.0.1",
7074
"standard-version": "9.5.0",
71-
"start-server-and-test": "2.0.12",
72-
"stylelint": "16.22.0",
73-
"stylelint-config-recommended-scss": "15.0.1",
74-
"stylelint-config-standard": "38.0.0",
75+
"start-server-and-test": "2.1.2",
76+
"stylelint": "16.24.0",
77+
"stylelint-config-recommended-scss": "16.0.1",
78+
"stylelint-config-standard": "39.0.0",
7579
"stylelint-scss": "6.12.1",
76-
"ts-jest": "^29.4.0",
77-
"typescript": "5.8.3",
78-
"vite": "^7.0.5"
80+
"ts-jest": "^29.4.1",
81+
"typescript": "5.9.2",
82+
"vite": "^7.1.4"
7983
},
8084
"scripts": {
8185
"apidoc": "esdoc && cp apidoc/index.json doc/src/components/Esdoc",
@@ -112,7 +116,7 @@
112116
"test:watch": "yarn test --watchAll",
113117
"tsc": "tsc",
114118
"types:backend": " yarn types:stops && yarn types:routing && yarn types:moco",
115-
"types:moco": "openapi-typescript https://moco.dev.geops.io/api/v1/swagger/?format=openapi --output src/types/moco.d.ts",
119+
"types:moco": "openapi-typescript https://moco.dev.geops.io/api/schema/?format=json --output src/types/moco.d.ts && graphql-codegen --config graphql-codegen-moco.ts",
116120
"types:routing": "openapi-typescript https://developer.geops.io/swagger/routing.json --output src/types/routing.d.ts",
117121
"types:stops": "openapi-typescript https://developer.geops.io/swagger/stops.json --output src/types/stops.d.ts",
118122
"up": "yarn upgrade-interactive --latest"

src/api/HttpAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class HttpAPI {
2424
*
2525
* @private
2626
*/
27-
async fetch<T>(
27+
async fetch<T, V>(
2828
path: string,
29-
params?: object,
29+
params?: V,
3030
config?: RequestInit,
3131
): Promise<T> {
3232
if (!this.url) {

src/api/MocoAPI.ts

Lines changed: 44 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
1-
import { isMocoNotificationNotOutOfDate } from '../common/utils/mocoUtils';
2-
31
import HttpAPI from './HttpAPI';
42

5-
import type { MocoNotification, MocoParameters } from '../types';
3+
import type { MocoExportParameters } from '../types';
4+
import type {
5+
SituationType,
6+
SituationTypeExtendedOffsetPaginated,
7+
} from '../types';
68

79
export interface MocoAPIOptions {
810
apiKey: string;
911
graph?: string;
10-
simplify?: number;
11-
ssoConfig?: string;
12+
tenant?: string;
1213
url?: string;
1314
}
1415

15-
export type MocoParametersExtended = {
16-
apiKey?: string;
17-
date?: Date;
18-
graph?: string;
19-
sso_config?: string;
20-
} & Omit<MocoParameters, 'apiKey' | 'graph' | 'sso_config'>;
21-
2216
/**
2317
* This class provides convenience methods to use to the [geOps MOCO API](https://geops.com/de/solution/disruption-information).
2418
*
2519
* @example
2620
* import { MocoAPI } from 'mobility-toolbox-js/api';
2721
*
2822
* const api = new MocoAPI({
23+
* // publicAt: new Date(),
2924
* // graph: 'osm',
30-
* // url: 'https://moco.geops.io/api/v1',
31-
* // ssoConfig: "geopstest",
25+
* // url: 'https://moco.geops.io/api/v2/',
26+
* // tenant: "geopstest",
3227
* });
3328
*
3429
* const notifications = await api.getNotifications();
@@ -38,69 +33,65 @@ export type MocoParametersExtended = {
3833
* @private
3934
*/
4035
class MocoAPI extends HttpAPI {
41-
graph?: string = 'osm';
42-
43-
simplify?: number = 0; // The backend has 100 as default value, but we use 0 to get the full geometries.
44-
45-
ssoConfig?: string = 'geopstest';
36+
tenant = 'geopstest';
4637

4738
/**
4839
* Constructor
4940
*
5041
* @param {Object} options Options.
5142
*
5243
* @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
53-
* @param {string} [options.url='https://moco.geops.io/api/v1'] Service url.
54-
* @param {string} [options.ssoConfig='geopstest'] SSO config to get notifications from.
44+
* @param {string} [options.url='https://moco.geops.io/api/v2/'] Service url.
45+
* @param {string} [options.tenant='geopstest'] SSO config to get notifications from.
5546
* @param {string} [options.graph='osm'] Graph to use for geometries.
5647
*/
5748
constructor(options: MocoAPIOptions) {
5849
super({
50+
url: options.url || 'https://moco.geops.io/api/v2/',
5951
...options,
60-
apiKey: options.apiKey,
61-
url: options.url || 'https://moco.geops.io/api/v1/',
6252
});
6353

64-
this.ssoConfig = options.ssoConfig || 'geopstest';
65-
this.graph = options.graph || 'osm';
66-
this.simplify = options.simplify || 0;
54+
if (options.tenant) {
55+
this.tenant = options.tenant;
56+
}
6757
}
6858

6959
/**
70-
* Get notifications from the MOCO API.
71-
* Notifications are returned as an array of GeoJSON feature collections.
72-
*
73-
* @param {MocoParameters} params Request parameters.
74-
* @param {FetchOptions} config Options for the fetch request.
75-
* @return {Promise<MocoNotification[]>} An array of GeoJSON feature collections with coordinates in [EPSG:4326](http://epsg.io/4326).
76-
* @public
60+
* Get paginated situations.
7761
*/
78-
async getNotifications(
79-
params: MocoParametersExtended = {},
62+
async export(
63+
params: MocoExportParameters = {},
8064
config: RequestInit = {},
81-
): Promise<MocoNotification[]> {
82-
const apiParams: MocoParametersExtended = { ...params };
83-
delete apiParams.date; // Not used in this method
84-
let notifications = await this.fetch<MocoNotification[]>(
85-
'export/publication/',
65+
): Promise<{ paginatedSituations: SituationTypeExtendedOffsetPaginated }> {
66+
const response = await this.fetch<
67+
{ paginatedSituations: SituationTypeExtendedOffsetPaginated },
68+
MocoExportParameters
69+
>(
70+
`${this.tenant}/export/`,
8671
{
87-
graph: this.graph || 'osm',
88-
simplify: this.simplify || 0,
89-
sso_config: this.ssoConfig || 'geopstest',
90-
...apiParams,
72+
...params,
9173
},
9274
config,
9375
);
9476

95-
// TODO in the future we hope that the date parameter will be used by the API to filter out-of-date notifications.
96-
// For now we filter them out manually.
97-
const date = params?.date;
98-
if (date) {
99-
notifications = notifications.filter((notification) => {
100-
return isMocoNotificationNotOutOfDate(notification, date);
101-
});
102-
}
103-
return notifications;
77+
return response;
78+
}
79+
80+
/**
81+
* Get a situation. Not all parameters are
82+
* relevant, only the text related are useful
83+
* (contentXXX, de, fr, it, en, includeXXX).
84+
*/
85+
async exportById(
86+
id: string,
87+
params: MocoExportParameters = {},
88+
config: RequestInit = {},
89+
): Promise<SituationType> {
90+
const response = await this.fetch<
91+
{ paginatedSituations: SituationTypeExtendedOffsetPaginated },
92+
MocoExportParameters
93+
>(`${this.tenant}/export/${id}/`, params, config);
94+
return response?.paginatedSituations?.results?.[0];
10495
}
10596
}
10697

0 commit comments

Comments
 (0)