diff --git a/src/base-apis.js b/src/base-apis.js index 0906a5840..83cd35b16 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 Vector Creations Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,6 +17,8 @@ limitations under the License. */ "use strict"; +import { SERVICE_TYPES } from './service-types'; + /** * This is an internal module. MatrixBaseApis is currently only meant to be used * by {@link client~MatrixClient}. @@ -26,6 +29,17 @@ limitations under the License. const httpApi = require("./http-api"); const utils = require("./utils"); +function termsUrlForService(serviceType, baseUrl) { + switch (serviceType) { + case SERVICE_TYPES.IS: + return baseUrl + httpApi.PREFIX_IDENTITY_V2 + '/terms'; + case SERVICE_TYPES.IM: + return baseUrl + '/_matrix/integrations/v1/terms'; + default: + throw new Error('Unsupported service type'); + } +} + /** * Low-level wrappers for the Matrix APIs * @@ -1855,6 +1869,25 @@ MatrixBaseApis.prototype.getThirdpartyUser = function(protocol, params) { return this._http.authedRequest(undefined, "GET", path, params, undefined); }; +MatrixBaseApis.prototype.getTerms = function(serviceType, baseUrl) { + const url = termsUrlForService(serviceType, baseUrl); + return this._http.requestOtherUrl( + undefined, 'GET', url, + ); +}; + +MatrixBaseApis.prototype.agreeToTerms = function( + serviceType, baseUrl, accessToken, termsUrls, +) { + const url = termsUrlForService(serviceType, baseUrl); + const headers = { + Authorization: "Bearer " + accessToken, + }; + return this._http.requestOtherUrl( + undefined, 'POST', url, null, { user_accepts: termsUrls }, { headers }, + ); +}; + /** * MatrixBaseApis object */ diff --git a/src/http-api.js b/src/http-api.js index 5731a3e34..374c00644 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -1,5 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -46,10 +47,15 @@ module.exports.PREFIX_R0 = "/_matrix/client/r0"; module.exports.PREFIX_UNSTABLE = "/_matrix/client/unstable"; /** - * URI path for the identity API + * URI path for v1 of the the identity API */ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1"; +/** + * URI path for the v2 identity API + */ +module.exports.PREFIX_IDENTITY_V2 = "/_matrix/identity/v2"; + /** * URI path for the media repo API */ diff --git a/src/matrix.js b/src/matrix.js index 0460927ff..244b10f24 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 Vector Creations Ltd +Copyright 2019 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -76,6 +77,7 @@ module.exports.InteractiveAuth = require("./interactive-auth"); /** The {@link module:auto-discovery|AutoDiscovery} class. */ module.exports.AutoDiscovery = require("./autodiscovery").AutoDiscovery; +module.exports.SERVICE_TYPES = require('./service-types').SERVICE_TYPES; module.exports.MemoryCryptoStore = require("./crypto/store/memory-crypto-store").default; diff --git a/src/service-types.js b/src/service-types.js new file mode 100644 index 000000000..0803b9247 --- /dev/null +++ b/src/service-types.js @@ -0,0 +1,20 @@ +/* +Copyright 2019 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +export const SERVICE_TYPES = Object.freeze({ + IS: 'SERVICE_TYPE_IS', // An Identity Service + IM: 'SERVICE_TYPE_IM', // An Integration Manager +});