Skip to content

Commit a147b63

Browse files
maximizeITGitHub Copilot
andcommitted
feat: add getinstanceurl to client sdk
Co-authored-by: GitHub Copilot <copilot@noreply.github.com>
1 parent b723aa9 commit a147b63

12 files changed

Lines changed: 190 additions & 82 deletions

File tree

docs/api.md

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,137 +53,166 @@ should be used.</p>
5353
<dt><a href="#getUserContentLocale">getUserContentLocale()</a> ⇒ <code>Promise.&lt;any&gt;</code></dt>
5454
<dd><p>Get the current user&#39;s content locale, fallback to branch default locale</p>
5555
</dd>
56+
<dt><a href="#getInstanceUrl">getInstanceUrl()</a> ⇒ <code>Promise.&lt;string&gt;</code></dt>
57+
<dd><p>Get the Staffbase instance URL / frontend domain.</p>
58+
</dd>
5659
</dl>
5760

5861
<a name="openNativeShareDialog"></a>
5962

6063
## openNativeShareDialog ⇒ <code>Promise.&lt;string&gt;</code>
64+
6165
Open a share dialog on native devices
6266

63-
**Kind**: global constant
67+
**Kind**: global constant
6468

65-
| Param | Type | Description |
66-
| --- | --- | --- |
69+
| Param | Type | Description |
70+
| ------- | ------------------- | -------------------- |
6771
| content | <code>object</code> | the content to share |
6872

69-
**Example**
73+
**Example**
74+
7075
```js
7176
openNativeShareDialog({
72-
image: "https://example.com/test.png",
73-
subject: "The string you would like to use as a subject for the share",
74-
text: "This text is shared",
75-
url: "https://example.com"
76-
})
77+
image: 'https://example.com/test.png',
78+
subject: 'The string you would like to use as a subject for the share',
79+
text: 'This text is shared',
80+
url: 'https://example.com'
81+
});
7782
```
83+
7884
<a name="deviceCanDownload"></a>
7985

8086
## deviceCanDownload() ⇒ <code>Promise.&lt;boolean&gt;</code>
87+
8188
Check if device is able to perform a download.
8289

8390
**Kind**: global function
8491
<a name="isIosDevice"></a>
8592

8693
## isIosDevice() ⇒ <code>Promise.&lt;boolean&gt;</code>
94+
8795
Check if device is using ios.
8896

8997
**Kind**: global function
9098
<a name="isAndroidDevice"></a>
9199

92100
## isAndroidDevice() ⇒ <code>Promise.&lt;boolean&gt;</code>
101+
93102
Check if device is using android.
94103

95104
**Kind**: global function
96105
<a name="getAppVersion"></a>
97106

98107
## getAppVersion() ⇒ <code>Promise.&lt;string&gt;</code>
108+
99109
Get the version of the Staffbase App.
100110

101111
**Kind**: global function
102112
<a name="isNativeApp"></a>
103113

104114
## isNativeApp() ⇒ <code>Promise.&lt;boolean&gt;</code>
115+
105116
Check if app is native.
106117

107118
**Kind**: global function
108119
<a name="isMobileApp"></a>
109120

110121
## isMobileApp() ⇒ <code>Promise.&lt;boolean&gt;</code>
122+
111123
Check if app is mobile.
112124

113125
**Kind**: global function
114126
<a name="openLink"></a>
115127

116128
## openLink(url) ⇒ <code>Promise.&lt;any&gt;</code>
129+
117130
Open a link through the app.
118131

119132
Where Staffbase decides which browser (External/Internal)
120133
should be used.
121134

122-
**Kind**: global function
135+
**Kind**: global function
123136

124-
| Param | Type | Description |
125-
| --- | --- | --- |
126-
| url | <code>string</code> | the url to open in the browser |
137+
| Param | Type | Description |
138+
| ----- | ------------------- | ------------------------------ |
139+
| url | <code>string</code> | the url to open in the browser |
127140

128141
<a name="openLinkExternal"></a>
129142

130143
## openLinkExternal(url) ⇒ <code>Promise.&lt;any&gt;</code>
144+
131145
Open a link explicitly in the external browser.
132146

133-
**Kind**: global function
147+
**Kind**: global function
134148

135-
| Param | Type | Description |
136-
| --- | --- | --- |
137-
| url | <code>string</code> | the url to open in the browser |
149+
| Param | Type | Description |
150+
| ----- | ------------------- | ------------------------------ |
151+
| url | <code>string</code> | the url to open in the browser |
138152

139153
<a name="openLinkInternal"></a>
140154

141155
## openLinkInternal(url) ⇒ <code>Promise.&lt;any&gt;</code>
156+
142157
Open a link explicitly in the internal browser.
143158

144-
**Kind**: global function
159+
**Kind**: global function
145160

146-
| Param | Type | Description |
147-
| --- | --- | --- |
148-
| url | <code>string</code> | the url to open in the browser |
161+
| Param | Type | Description |
162+
| ----- | ------------------- | ------------------------------ |
163+
| url | <code>string</code> | the url to open in the browser |
149164

150165
<a name="getBranchLanguages"></a>
151166

152167
## getBranchLanguages() ⇒ <code>Promise.&lt;any&gt;</code>
168+
153169
Get all enabled content languages configured in the app.
154170

155171
**Kind**: global function
156172
<a name="getBranchDefaultLanguage"></a>
157173

158174
## getBranchDefaultLanguage() ⇒ <code>Promise.&lt;any&gt;</code>
175+
159176
Get the default content language configured in the app.
160177

161178
**Kind**: global function
162179
<a name="getContentLanguages"></a>
163180

164181
## getContentLanguages() ⇒ <code>Promise.&lt;any&gt;</code>
182+
165183
Get all content languages supported by the app.
166184

167185
**Kind**: global function
168186
<a name="getPreferredContentLocale"></a>
169187

170188
## getPreferredContentLocale(content) ⇒ <code>Promise.&lt;string&gt;</code>
189+
171190
Gets the chosen language from a given content object
172191

173-
**Kind**: global function
192+
**Kind**: global function
174193

175-
| Param | Type | Description |
176-
| --- | --- | --- |
194+
| Param | Type | Description |
195+
| ------- | ----------------------------------------- | ------------------------------------- |
177196
| content | <code>object</code> \| <code>array</code> | the content to choose the locale from |
178197

179-
**Example**
198+
**Example**
199+
180200
```js
181201
getPreferredContentLocale(['de_DE', 'en_EN']) // => 'de_DE'
182202
getPreferredContentLocale({'de_DE': {1,'eins'}, 'en_EN': {1: 'one'}}) // => 'de_DE'
183203
```
204+
184205
<a name="getUserContentLocale"></a>
185206

186207
## getUserContentLocale() ⇒ <code>Promise.&lt;any&gt;</code>
208+
187209
Get the current user's content locale, fallback to branch default locale
188210

189211
**Kind**: global function
212+
<a name="getInstanceUrl"></a>
213+
214+
## getInstanceUrl() ⇒ <code>Promise.&lt;string&gt;</code>
215+
216+
Get the Staffbase instance URL / frontend domain.
217+
218+
**Kind**: global function

docs/usage.md

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,26 @@ So the whole interface is asynchronous as well.
5959
Every SDK method returns a promise, which resolves with the requested information or throws an error if something has gone wrong.
6060

6161
```js
62-
PluginSDK.isIosDevice().then(function(isIOS) {
62+
PluginSDK.isIosDevice()
63+
.then(function (isIOS) {
6364
console.log('IOS Device: ', isIOS);
64-
}).catch(function(error) {
65-
console.warn('Something went wrong: ', error)
66-
})
65+
})
66+
.catch(function (error) {
67+
console.warn('Something went wrong: ', error);
68+
});
6769
```
6870

6971
To get multiple informations at once, you can use `Promise.all`.
7072

7173
```js
7274
Promise.all([PluginSDK.isIosDevice(), PluginSDK.isNativeApp()])
73-
.then(function(isIOS, isNative) {
74-
console.log('IOS Device: ', isIOS);
75-
console.log('Native App: ', isNative);
76-
})
77-
.catch(function(error) {
78-
console.warn('Something went wrong: ', error)
79-
})
75+
.then(function (isIOS, isNative) {
76+
console.log('IOS Device: ', isIOS);
77+
console.log('Native App: ', isNative);
78+
})
79+
.catch(function (error) {
80+
console.warn('Something went wrong: ', error);
81+
});
8082
```
8183

8284
### Getting infos from the Staffbase app
@@ -171,8 +173,18 @@ As a developer you can request various informations from the Staffbase app.
171173
```js
172174
// example for user with german content locale in an english app
173175
getUserContentLocale().then(function (locale) {
174-
console.log(locale); // 'de_DE'
175-
})
176+
console.log(locale); // 'de_DE'
177+
});
178+
```
179+
180+
1. `getInstanceUrl` -> string
181+
182+
the URL of the Staffbase instance (frontend domain) the plugin is embedded in
183+
184+
```js
185+
getInstanceUrl().then(function (url) {
186+
console.log(url); // 'https://customer.staffbase.com'
187+
});
176188
```
177189

178190
### Invoking native methods
@@ -184,16 +196,16 @@ With the SDK you can invoke methods, which are in the scope of the native app.
184196
checks a given list of locale tags, or an object with locale tags as keys and returns the matching locale tag as string.
185197

186198
```js
187-
const localesArray = ['de_DE', 'en_US'];
188-
const localesObject = { 'de_DE': {}, 'en_US':{} };
199+
const localesArray = ['de_DE', 'en_US'];
200+
const localesObject = { de_DE: {}, en_US: {} };
189201

190-
getPreferredContentLocale(localesArray).then(function (locale) {
191-
console.log(locale); // 'en_US'
192-
})
202+
getPreferredContentLocale(localesArray).then(function (locale) {
203+
console.log(locale); // 'en_US'
204+
});
193205

194-
getPreferredContentLocale(localesObject).then(function (locale) {
195-
console.log(locale); // 'en_US'
196-
})
206+
getPreferredContentLocale(localesObject).then(function (locale) {
207+
console.log(locale); // 'en_US'
208+
});
197209
```
198210

199211
2. `openLink` {url: string} -> boolean
@@ -202,56 +214,58 @@ With the SDK you can invoke methods, which are in the scope of the native app.
202214
which indicates if the link has been opened. This can be used to call the method in a click event
203215

204216
```js
205-
// internal link
206-
openLink('/settings/password').then(function (opened) {
207-
console.log(opened); // true
208-
})
209-
210-
// external link
211-
openLink('https://staffbase.com').then(function (opened) {
212-
console.log(opened); // true
213-
})
217+
// internal link
218+
openLink('/settings/password').then(function (opened) {
219+
console.log(opened); // true
220+
});
221+
222+
// external link
223+
openLink('https://staffbase.com').then(function (opened) {
224+
console.log(opened); // true
225+
});
214226
```
215227

216228
3. `openLinkExternal` {url: string} -> boolean
217229

218230
open a link in the device browser. Returns a boolean which indicates if the link has been opened. This can be used to call the method in a click event
219231

220232
```js
221-
// external link
222-
openLinkExternal('https://staffbase.com').then(function (opened) {
223-
console.log(opened); // true
224-
})
233+
// external link
234+
openLinkExternal('https://staffbase.com').then(function (opened) {
235+
console.log(opened); // true
236+
});
225237
```
226238

227239
4. `openLinkInternal` {url: string} -> boolean
228240

229241
open a link in the app browser. Returns a boolean which indicates if the link has been opened. This can be used to call the method in a click event
230242

231243
```js
232-
// external link
233-
openLinkInternal('https://staffbase.com').then(function (opened) {
234-
console.log(opened); // true
235-
})
244+
// external link
245+
openLinkInternal('https://staffbase.com').then(function (opened) {
246+
console.log(opened); // true
247+
});
236248
```
237249

238250
5. `openNativeShareDialog` {content: object} -> string
239251

240252
- **native only**
241253
- **version > 4.0.0**
242254

243-
open the native share view to share an object consisting of an image link, subject, text or url.
244-
245-
```js
246-
const contentObject = {image: "https://example.com/test.png",
247-
subject: "The string you would like to use as a subject for the share",
248-
text: "This text is shared",
249-
url: "https://example.com"};
255+
open the native share view to share an object consisting of an image link, subject, text or url.
250256

251-
openNativeShareDialog(contentObject).then(function (opened) {
252-
console.log(opened); // true
253-
})
254-
```
257+
```js
258+
const contentObject = {
259+
image: 'https://example.com/test.png',
260+
subject: 'The string you would like to use as a subject for the share',
261+
text: 'This text is shared',
262+
url: 'https://example.com'
263+
};
264+
265+
openNativeShareDialog(contentObject).then(function (opened) {
266+
console.log(opened); // true
267+
});
268+
```
255269

256270
6. `openNativeFileDialog` -> Blob **!experimental**
257271

@@ -263,7 +277,7 @@ With the SDK you can invoke methods, which are in the scope of the native app.
263277
> Attention! This function is still in development and will have a changed behavior in the future!
264278
265279
```js
266-
openNativeFileDialog().then(function (res) {
267-
console.log('Fileurl: ' + URL.createObjectURL(res)); // blob:d3958f5c-0777-0845-9dcf-2cb28783acaf
268-
})
280+
openNativeFileDialog().then(function (res) {
281+
console.log('Fileurl: ' + URL.createObjectURL(res)); // blob:d3958f5c-0777-0845-9dcf-2cb28783acaf
282+
});
269283
```

0 commit comments

Comments
 (0)