Skip to content

Commit

Permalink
Merge pull request #35 from wireapp/kj/wir-12-switch-from-wire-api-v2…
Browse files Browse the repository at this point in the history
…-to-wire-api-v5

fix(API access): Update API from v2 to v5 and add API Version as env
  • Loading branch information
LennardZieglerCONPORT authored Jun 26, 2024
2 parents a4906c9 + ac0c2a6 commit d008b61
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 28 deletions.
1 change: 1 addition & 0 deletions .env.localhost
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BASE_URL=
WIRE_API_BASE_URL=
WIRE_API_VERISON=
WIRE_API_AUTHORIZATION_ENDPOINT=
CLIENT_ID=
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ value: https://outlook.integrations.zinfra.io
- name: WIRE_API_BASE_URL
value: https://staging-nginz-https.zinfra.io
- name: WIRE_API_VERSION
value: v5
- name: WIRE_AUTHORIZATION_ENDPOINT
value: https://wire-webapp-qa.zinfra.io/auth
Expand All @@ -22,10 +25,13 @@ value: e30a9b94-8e0d-4b15-8a1a-236f68729cdd
window.config = {
addInBaseUrl: "${BASE_URL}",
apiBaseUrl: "${WIRE_API_BASE_URL}",
apiVersion: "${WIRE_API_VERSION}",
authorizeUrl: "${WIRE_AUTHORIZATION_ENDPOINT}",
clientId: "${CLIENT_ID}",
};
```
## API Version
The WIRE_API_VERSION environment variable can be optionally set to define the API version for the application. If not explicitly set, the default value of 'v5' will be used.

## Local Storage
- isLoggedIn
Expand Down
1 change: 1 addition & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -euo pipefail

if [ -z ${BASE_URL:-} ]; then echo "BASE_URL is unset"; exit 1; fi
if [ -z ${WIRE_API_BASE_URL:-} ]; then echo "WIRE_API_BASE_URL is unset"; exit 1; fi
if [ -z ${WIRE_API_VERSION:-} ]; then echo "WIRE_API_VERSION is unset, defaulting to v5"; fi
if [ -z ${WIRE_AUTHORIZATION_ENDPOINT:-} ]; then echo "WIRE_AUTHORIZATION_ENDPOINT is unset"; exit 1; fi
if [ -z ${CLIENT_ID:-} ]; then echo "CLIENT_ID is unset"; exit 1; fi
#if [ -z ${SUPPORT_URL:-} ]; then echo "SUPPORT_URL is unset"; exit 1; fi
Expand Down
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"build": "webpack --mode production",
"build:dev": "webpack --mode development",
"dev-server": "webpack serve --mode development",
"dev-server-local": "webpack serve --mode development --host localhost --allowed-hosts all",
"lint": "office-addin-lint check",
"lint:fix": "office-addin-lint fix",
"prettier": "office-addin-lint prettier",
Expand Down Expand Up @@ -70,7 +71,7 @@
"ts-loader": "^9.4.2",
"typescript": "^5.0.4",
"webpack": "^5.82.0",
"webpack-cli": "^5.1.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "4.15.0"
},
"prettier": "office-addin-prettier-config",
Expand Down
8 changes: 4 additions & 4 deletions src/calendarIntegration/createEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function createEvent(name: string): Promise<EventResult> {

const payload = {
access: ["invite", "code"],
access_role_v2: ["guest", "non_team_member", "team_member", "service"],
access_role: ["guest", "non_team_member", "team_member", "service"],
conversation_role: "wire_member",
name: name,
protocol: "proteus",
Expand All @@ -21,10 +21,9 @@ export async function createEvent(name: string): Promise<EventResult> {
managed: false,
teamid: teamId,
},
users: [],
};

const response = await fetchWithAuthorizeDialog(new URL("/v2/conversations", config.apiBaseUrl), {
const response = await fetchWithAuthorizeDialog(new URL(`${config.apiVersion}/conversations`, config.apiBaseUrl), {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -36,12 +35,13 @@ export async function createEvent(name: string): Promise<EventResult> {
const conversationId = (await response.json()).id;

const responseLink: any = await fetchWithAuthorizeDialog(
new URL(`/conversations/${conversationId}/code`, config.apiBaseUrl),
new URL(`${config.apiVersion}/conversations/${conversationId}/code`, config.apiBaseUrl),
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ password: null}),
}
).then((r) => r.json());

Expand Down
2 changes: 1 addition & 1 deletion src/calendarIntegration/getSelf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fetchWithAuthorizeDialog } from "../wireAuthorize/wireAuthorize";
import { SelfUser } from "../types/SelfUser";

export async function getSelf(): Promise<SelfUser> {
const response = await fetchWithAuthorizeDialog(new URL("/self", config.apiBaseUrl), {
const response = await fetchWithAuthorizeDialog(new URL(`${config.apiVersion}/self`, config.apiBaseUrl), {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down
2 changes: 1 addition & 1 deletion src/calendarIntegration/isOutlookCalIntegrationEnabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fetchWithAuthorizeDialog } from "../wireAuthorize/wireAuthorize";

export async function isOutlookCalIntegrationEnabled() {
try {
const response = await fetchWithAuthorizeDialog(new URL("/feature-configs", config.apiBaseUrl), {
const response = await fetchWithAuthorizeDialog(new URL(`${config.apiVersion}/feature-configs`, config.apiBaseUrl), {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down
2 changes: 1 addition & 1 deletion src/callback/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function sendMessageToParent(authResult: AuthResult): void {
async function exchangeCodeForTokens(code: string, codeVerifier: string): Promise<AuthResult> {
const clientId = config.clientId;
const redirectUri = new URL("/callback.html", config.addInBaseUrl);
const tokenEndpoint = new URL("/oauth/token", config.apiBaseUrl);
const tokenEndpoint = new URL(`${config.apiVersion}/oauth/token`, config.apiBaseUrl);

const body = getRequestBody(code, clientId, redirectUri, codeVerifier);

Expand Down
1 change: 1 addition & 0 deletions src/config.js.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
window.config = {
addInBaseUrl: "${BASE_URL}",
apiBaseUrl: "${WIRE_API_BASE_URL}",
apiVersion: "${WIRE_API_VERSION}",
authorizeUrl: "${WIRE_AUTHORIZATION_ENDPOINT}",
clientId: "${CLIENT_ID}",
};
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ interface Window {
config: {
addInBaseUrl: string;
apiBaseUrl: string;
apiVersion: number;
authorizeUrl: string;
clientId: string;
};
Expand Down
4 changes: 2 additions & 2 deletions src/wireAuthorize/wireAuthorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function refreshTokenExchange(): Promise<boolean> {
data.append("refresh_token", refreshToken);
data.append("client_id", config.clientId);

const response = await fetch(new URL("/oauth/token", config.apiBaseUrl), {
const response = await fetch(new URL(`${config.apiVersion}/oauth/token`, config.apiBaseUrl), {
method: "POST",
headers: {
Accept: "application/json",
Expand Down Expand Up @@ -163,7 +163,7 @@ export async function revokeOauthToken(): Promise<boolean> {
client_id: config.clientId,
}

const response = await fetch(new URL("/oauth/revoke", config.apiBaseUrl), {
const response = await fetch(new URL(`${config.apiVersion}/oauth/revoke`, config.apiBaseUrl), {
method: "POST",
headers: {
Accept: "application/json",
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function replaceEnvPlaceholders(content, outputPath) {
.toString()
.replace(/\${BASE_URL}/g, process.env.BASE_URL)
.replace(/\${WIRE_API_BASE_URL}/g, process.env.WIRE_API_BASE_URL)
.replace(/\${WIRE_API_VERSION}/g, process.env.WIRE_API_VERSION ? process.env.WIRE_API_VERSION : "v5")
.replace(/\${WIRE_AUTHORIZATION_ENDPOINT}/g, process.env.WIRE_AUTHORIZATION_ENDPOINT)
.replace(/\${CLIENT_ID}/g, process.env.CLIENT_ID);
}
Expand Down

0 comments on commit d008b61

Please sign in to comment.