Skip to content

Commit

Permalink
chore(release): 0.3.0
Browse files Browse the repository at this point in the history
features:
- Handler for fetching the current organization info (activated modules, logos, accent colors)

fix:
- Add base domain to the poi categories icon urls. This fixes image urls pointing to wrong environment.
  • Loading branch information
damian authored and frandieguez committed Sep 16, 2024
1 parent d718373 commit 582b12d
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 6 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 0.3.0 (2022-11-02)

### Added
- Handler for fetching the current organization info (activated modules, logos, accent colors)

### Improvements
- Add base domain to the poi categories icon urls. This fixes image urls pointing to wrong environment.

## 0.2.0 (2022-04-22)

## Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Situm Technologies",
"name": "@situm/sdk-js",
"version": "0.2.0",
"version": "0.3.0",
"description": "A Javascript client to Situm services, supporting Node and browser.",
"repository": "https://github.com/situmtech/situm-sdk-js",
"main": "dist/cjs/situm-sdk.js",
Expand Down
33 changes: 33 additions & 0 deletions src/adapters/OrganizationAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) Situm Technologies. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { Organization } from "../types";

/**
* Adapts the server response to our common Organization object,
* cleaning deprecations, removing redundancies, and more.
*
* @param Organization Not normalized organization
* @param domain Current domain to get the pictures urls
* @returns Organization normalized object
*/
export function getAdapter(
organization: Record<string, unknown>,
domain: string
): Organization {
organization.logoPath = organization?.logoPath
? domain + organization.logoPath
: undefined;
organization.logoLoginPath = organization?.logoLoginPath
? domain + organization.logoLoginPath
: undefined;
organization.logoFaviconPath = organization?.logoFaviconPath
? domain + organization.logoFaviconPath
: undefined;

return organization as Organization;
}
27 changes: 27 additions & 0 deletions src/adapters/PoiCategoryAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) Situm Technologies. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import { PoiCategory } from "../types";

/**
* Adapts the server response to our common PoiCategory object,
* cleaning deprecations, removing redundancies, and more.
*
* @param poiCategory Not normalized POI Category
* @param domain Current domain to get the icon picture url
* @returns POI Category normalized object
*/
export function getAdapter(
poiCategory: PoiCategory,
domain: string
): PoiCategory {
poiCategory.iconUrl = !poiCategory.iconUrl.includes("https")
? domain + poiCategory.iconUrl
: poiCategory.iconUrl;

return poiCategory as PoiCategory;
}
9 changes: 9 additions & 0 deletions src/apiBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ export default class ApiBase {
return this.request<void>("delete", requestInfo);
}

/**
* Gets the current domain
*
* @returns String
*/
getDomain(): string {
return this.configuration.domain;
}

/**
* Wrapper around axios that converts our domain HTTP request parameters
* to the axios request requirements.
Expand Down
30 changes: 27 additions & 3 deletions src/domains/cartography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import { getAdapter as getBuildingAdapter } from "../adapters/BuildingAdapter";
import { getAdapter as getFloorAdapter } from "../adapters/FloorAdapter";
import { getAdapter as getGeofenceAdapter } from "../adapters/GeofenceAdapter";
import { getAdapter as getCurrentOrganizationAdapter } from "../adapters/OrganizationAdapter";
import {
getAdapter as getPoiAdapter,
postAdapter as postPoiAdapter,
ServerPoiGet,
} from "../adapters/PoiAdapter";
import { getAdapter as getPoiCategoryAdapter } from "../adapters/PoiCategoryAdapter";
import ApiBase from "../apiBase";
import type {
Building,
Expand All @@ -25,6 +27,7 @@ import type {
GeofenceForm,
GeofenceSearch,
ID,
Organization,
Paginated,
Paths,
PathSearch,
Expand Down Expand Up @@ -79,6 +82,21 @@ export default class CartographyApi {
.then(getBuildingAdapter);
}

/**
* Returns the user's current organization
*
* @returns Promise<Organization>
*/
getCurrentOrganization(): Promise<Organization> {
return this.apiBase
.get<Organization>({
url: "/api/v1/organizations/current_organization",
})
.then((org) =>
getCurrentOrganizationAdapter(org, this.apiBase.getDomain())
);
}

/**
* Updates a building given its id and the information to update
*
Expand Down Expand Up @@ -382,9 +400,15 @@ export default class CartographyApi {
* @returns Promise<PoiCategory[]>
*/
getPoiCategories(): Promise<PoiCategory[]> {
return this.apiBase.get<PoiCategory[]>({
url: "/api/v1/poi_categories",
});
return this.apiBase
.get<PoiCategory[]>({
url: "/api/v1/poi_categories",
})
.then((poiCategories) =>
poiCategories.map((p) =>
getPoiCategoryAdapter(p, this.apiBase.getDomain())
)
);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,25 @@ export type RealtimePositions = {
features: GeoJSONFeature[];
devicesInfo: Device[];
};

type Colors = {
primary: string;
secondary: string;
success: string;
warning: string;
danger: string;
info: string;
default: string;
};

export type Organization = {
id: UUID;
name: string;
logoPath: string;
logoLoginPath: string;
logoFaviconPath: string;
cookiesMessage: string;
support_email: string;
copyright: string;
colors: Colors;
};
4 changes: 2 additions & 2 deletions test/utils/mockData.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
"nameEn": "Coffee",
"nameEs": "Cafetería",
"code": "situm-coffee",
"iconUrl": "/uploads/poicategory/1/b3d4b884-ed86-4ab5-929d-3e5a40502e56.png",
"iconUrl": "https://dashboard.situm.com/uploads/poicategory/1/b3d4b884-ed86-4ab5-929d-3e5a40502e56.png",
"selectedIconUrl": "/uploads/poicategoryselected/1/fcfb13c6-44e7-4b58-b568-780ef41628f1.png",
"updatedAt": "2017-04-07T13:45:24.940+02:00",
"createdAt": "2016-06-23T09:14:05.701+02:00",
Expand All @@ -354,7 +354,7 @@
"name_en": "Coffee",
"name_es": "Cafetería",
"code": "situm-coffee",
"icon_url": "/uploads/poicategory/1/b3d4b884-ed86-4ab5-929d-3e5a40502e56.png",
"icon_url": "https://dashboard.situm.com/uploads/poicategory/1/b3d4b884-ed86-4ab5-929d-3e5a40502e56.png",
"selected_icon_url": "/uploads/poicategoryselected/1/fcfb13c6-44e7-4b58-b568-780ef41628f1.png",
"updated_at": "2017-04-07T13:45:24.940+02:00",
"created_at": "2016-06-23T09:14:05.701+02:00",
Expand Down

0 comments on commit 582b12d

Please sign in to comment.