@placeos/ts-client 4.7.9 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  import { HttpJsonOptions } from '../http/interfaces';
2
- import { SignageMediaQueryOptions, SignageMetrics } from './interfaces';
2
+ import { SignageMediaQueryOptions, SignageMetrics, SignagePluginQueryOptions } from './interfaces';
3
3
  import { SignageMedia } from './media.class';
4
4
  import { SignagePlaylist, SignagePlaylistMedia } from './playlist.class';
5
+ import { SignagePlugin } from './plugin.class';
5
6
  /**
6
7
  * Get the data for a signage item
7
8
  * @param id ID of the signage item to retrieve
@@ -104,3 +105,32 @@ export declare function approveSignagePlaylist(id: string): import('rxjs').Obser
104
105
  * @param form_data New list of media IDs for the playlist
105
106
  */
106
107
  export declare function updateSignagePlaylistMedia(id: string, form_data: string[]): import('rxjs').Observable<SignagePlaylistMedia>;
108
+ /**
109
+ * Query the available signage plugins
110
+ * @param query_params Query parameters to add the to request URL
111
+ */
112
+ export declare function querySignagePlugins(query_params?: SignagePluginQueryOptions): import('..').QueryResponse<SignagePlugin>;
113
+ /**
114
+ * Get the data for a signage plugin
115
+ * @param id ID of the signage plugin to retrieve
116
+ * @param query_params Query parameters to add the to request URL
117
+ */
118
+ export declare function showSignagePlugin(id: string, query_params?: SignagePluginQueryOptions): import('rxjs').Observable<SignagePlugin>;
119
+ /**
120
+ * Update the signage plugin in the database
121
+ * @param id ID of the signage plugin
122
+ * @param form_data New values for the signage plugin
123
+ * @param method HTTP verb to use on request. Defaults to `patch`
124
+ */
125
+ export declare function updateSignagePlugin(id: string, form_data: Partial<SignagePlugin>, method?: 'put' | 'patch'): import('rxjs').Observable<SignagePlugin>;
126
+ /**
127
+ * Add a new signage plugin to the database
128
+ * @param form_data Signage plugin data
129
+ */
130
+ export declare function addSignagePlugin(form_data: Partial<SignagePlugin>): import('rxjs').Observable<SignagePlugin>;
131
+ /**
132
+ * Remove a signage plugin from the database
133
+ * @param id ID of the signage plugin
134
+ * @param query_params Query parameters to add the to request URL
135
+ */
136
+ export declare function removeSignagePlugin(id: string, query_params?: Record<string, any>): import('rxjs').Observable<import('../utilities/types').HashMap<any>>;
@@ -17,3 +17,6 @@ export interface SignagePlaylistRevisionsOptions {
17
17
  /** Maximum number of revisions to return */
18
18
  limit?: number;
19
19
  }
20
+ /** Allowable query parameters for signage plugins index endpoint */
21
+ export interface SignagePluginQueryOptions extends PlaceResourceQueryOptions {
22
+ }
@@ -1,4 +1,5 @@
1
- export type MediaType = 'unknown' | 'image' | 'video' | 'audio' | 'plugin' | 'webpage' | 'externalimage';
1
+ import { HashMap } from '../utilities/types';
2
+ export type MediaType = 'unknown' | 'image' | 'video' | 'audio' | 'plugin' | 'webpage' | 'externalimage' | 'external_image';
2
3
  export declare enum MediaAnimation {
3
4
  Default = 0,
4
5
  Cut = 1,
@@ -25,6 +26,8 @@ export declare class SignageMedia {
25
26
  readonly media_uri: string;
26
27
  readonly media_id: string;
27
28
  readonly thumbnail_id: string;
29
+ readonly plugin_id: string;
30
+ readonly plugin_params: HashMap;
28
31
  readonly play_count: number;
29
32
  readonly valid_from?: number;
30
33
  readonly valid_until?: number;
@@ -0,0 +1,16 @@
1
+ import { HashMap } from '../utilities/types';
2
+ export type SignagePlaybackType = 'static' | 'interactive' | 'playsthrough';
3
+ export declare class SignagePlugin {
4
+ readonly id: string;
5
+ readonly created_at: number;
6
+ readonly updated_at: number;
7
+ readonly name: string;
8
+ readonly description: string;
9
+ readonly uri: string;
10
+ readonly playback_type: SignagePlaybackType;
11
+ readonly authority_id: string;
12
+ readonly enabled: boolean;
13
+ readonly params: HashMap;
14
+ readonly defaults: HashMap;
15
+ constructor(data?: Partial<SignagePlugin>);
16
+ }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.9",
2
+ "version": "4.8.0",
3
3
  "license": "MIT",
4
4
  "name": "@placeos/ts-client",
5
5
  "author": "Alex Sorafumo <alex@place.tech>",
package/src/api.ts CHANGED
@@ -363,37 +363,48 @@ export { PlaceZone } from './zones/zone';
363
363
  export {
364
364
  addSignageMedia,
365
365
  addSignagePlaylist,
366
+ addSignagePlugin,
366
367
  approveSignagePlaylist,
367
368
  listSignagePlaylistMedia,
368
369
  listSignagePlaylistMediaRevisions,
369
370
  mediaThumbnail,
370
371
  querySignageMedia,
371
372
  querySignagePlaylists,
373
+ querySignagePlugins,
372
374
  removeSignageMedia,
373
375
  removeSignagePlaylist,
376
+ removeSignagePlugin,
374
377
  showSignage,
375
378
  showSignageMedia,
376
379
  showSignageMetrics,
377
380
  showSignagePlaylist,
381
+ showSignagePlugin,
378
382
  updateSignageMedia,
379
383
  updateSignagePlaylist,
380
384
  updateSignagePlaylistMedia,
385
+ updateSignagePlugin,
381
386
  } from './signage/functions';
382
387
  export type {
383
388
  SignageMediaQueryOptions,
384
389
  SignageMetrics,
385
390
  SignagePlaylistQueryOptions,
386
391
  SignagePlaylistRevisionsOptions,
392
+ SignagePluginQueryOptions,
387
393
  } from './signage/interfaces';
388
394
  export {
389
395
  MediaAnimation,
390
396
  SignageMedia,
391
397
  type MediaOrientation,
398
+ type MediaType,
392
399
  } from './signage/media.class';
393
400
  export {
394
401
  SignagePlaylist,
395
402
  SignagePlaylistMedia,
396
403
  } from './signage/playlist.class';
404
+ export {
405
+ SignagePlugin,
406
+ type SignagePlaybackType,
407
+ } from './signage/plugin.class';
397
408
 
398
409
  export { addAnswer, queryAnswers } from './staff/answers/functions';
399
410
  export type { AnswerQueryOptions } from './staff/answers/interfaces';
@@ -90,6 +90,25 @@ const _online_observer = _online.asObservable();
90
90
 
91
91
  let _failed_count = 0;
92
92
 
93
+ /**
94
+ * @private
95
+ * Resolve a URL against the authority's domain if it is a relative path.
96
+ * If the URL is already absolute (starts with http:// or https://), return as-is.
97
+ * If the URL is relative (starts with /), prepend the protocol and authority domain.
98
+ */
99
+ function resolveAuthorityUrl(url: string): string {
100
+ if (!url || url.startsWith('http://') || url.startsWith('https://')) {
101
+ return url;
102
+ }
103
+ const domain = _authority?.domain;
104
+ if (domain) {
105
+ const secure =
106
+ _options.secure || window.location?.protocol.indexOf('https') >= 0;
107
+ return `${secure ? 'https:' : 'http:'}//${domain}${url}`;
108
+ }
109
+ return url;
110
+ }
111
+
93
112
  /** API Endpoint for the retrieved version of PlaceOS */
94
113
  export function apiEndpoint(): string {
95
114
  const secure =
@@ -398,7 +417,9 @@ export function authorise(
398
417
  * Logout and clear user credentials for the application
399
418
  */
400
419
  export function logout(): void {
401
- const url = _authority ? _authority.logout_url : '/logout';
420
+ const url = resolveAuthorityUrl(
421
+ _authority ? _authority.logout_url : '/logout',
422
+ );
402
423
  fetch(url, {
403
424
  method: 'GET',
404
425
  redirect: 'manual',
@@ -582,10 +603,12 @@ export function sendToLogin(api_authority: PlaceAuthority): void {
582
603
  /* istanbul ignore else */
583
604
  if (_options.handle_login !== false && !_redirecting) {
584
605
  log('Auth', 'Redirecting to login page...');
585
- // Redirect to login form
586
- const url = api_authority!.login_url?.replace(
587
- '{{url}}',
588
- encodeURIComponent(window.location?.href),
606
+ // Redirect to login form, resolving relative URLs against the authority domain
607
+ const url = resolveAuthorityUrl(
608
+ api_authority!.login_url?.replace(
609
+ '{{url}}',
610
+ encodeURIComponent(window.location?.href),
611
+ ),
589
612
  );
590
613
  setTimeout(() => window.location?.assign(url), 300);
591
614
  _redirecting = true;
@@ -2,9 +2,14 @@ import { create, query, remove, show, update } from '../api';
2
2
  import { apiEndpoint } from '../auth';
3
3
  import { HttpJsonOptions } from '../http/interfaces';
4
4
  import { task } from '../resources/functions';
5
- import { SignageMediaQueryOptions, SignageMetrics } from './interfaces';
5
+ import {
6
+ SignageMediaQueryOptions,
7
+ SignageMetrics,
8
+ SignagePluginQueryOptions,
9
+ } from './interfaces';
6
10
  import { SignageMedia } from './media.class';
7
11
  import { SignagePlaylist, SignagePlaylistMedia } from './playlist.class';
12
+ import { SignagePlugin } from './plugin.class';
8
13
 
9
14
  /**
10
15
  * @private
@@ -282,3 +287,86 @@ export function updateSignagePlaylistMedia(id: string, form_data: string[]) {
282
287
  new SignagePlaylistMedia(value),
283
288
  });
284
289
  }
290
+
291
+ /**
292
+ * @private
293
+ */
294
+ const PLUGINS_PATH = 'signage/plugins';
295
+
296
+ /** Convert raw server data to a signage plugin object */
297
+ function processPlugin(item: Partial<SignagePlugin>) {
298
+ return new SignagePlugin(item);
299
+ }
300
+
301
+ /**
302
+ * Query the available signage plugins
303
+ * @param query_params Query parameters to add the to request URL
304
+ */
305
+ export function querySignagePlugins(
306
+ query_params: SignagePluginQueryOptions = {},
307
+ ) {
308
+ return query({ query_params, fn: processPlugin, path: PLUGINS_PATH });
309
+ }
310
+
311
+ /**
312
+ * Get the data for a signage plugin
313
+ * @param id ID of the signage plugin to retrieve
314
+ * @param query_params Query parameters to add the to request URL
315
+ */
316
+ export function showSignagePlugin(
317
+ id: string,
318
+ query_params: SignagePluginQueryOptions = {},
319
+ ) {
320
+ return show({
321
+ id,
322
+ query_params,
323
+ fn: processPlugin,
324
+ path: PLUGINS_PATH,
325
+ });
326
+ }
327
+
328
+ /**
329
+ * Update the signage plugin in the database
330
+ * @param id ID of the signage plugin
331
+ * @param form_data New values for the signage plugin
332
+ * @param method HTTP verb to use on request. Defaults to `patch`
333
+ */
334
+ export function updateSignagePlugin(
335
+ id: string,
336
+ form_data: Partial<SignagePlugin>,
337
+ method: 'put' | 'patch' = 'patch',
338
+ ) {
339
+ return update({
340
+ id,
341
+ form_data,
342
+ query_params: {},
343
+ method,
344
+ fn: processPlugin,
345
+ path: PLUGINS_PATH,
346
+ });
347
+ }
348
+
349
+ /**
350
+ * Add a new signage plugin to the database
351
+ * @param form_data Signage plugin data
352
+ */
353
+ export function addSignagePlugin(form_data: Partial<SignagePlugin>) {
354
+ return create({
355
+ form_data,
356
+ query_params: {},
357
+ fn: processPlugin,
358
+ path: PLUGINS_PATH,
359
+ });
360
+ }
361
+
362
+ /**
363
+ * Remove a signage plugin from the database
364
+ * @param id ID of the signage plugin
365
+ * @param query_params Query parameters to add the to request URL
366
+ */
367
+ export function removeSignagePlugin(
368
+ id: string,
369
+ query_params: Record<string, any> = {},
370
+ ) {
371
+ return remove({ id, query_params, path: PLUGINS_PATH });
372
+ }
@@ -20,3 +20,6 @@ export interface SignagePlaylistRevisionsOptions {
20
20
  /** Maximum number of revisions to return */
21
21
  limit?: number;
22
22
  }
23
+
24
+ /** Allowable query parameters for signage plugins index endpoint */
25
+ export interface SignagePluginQueryOptions extends PlaceResourceQueryOptions {}
@@ -1,4 +1,5 @@
1
1
  import { getUnixTime } from 'date-fns';
2
+ import { HashMap } from '../utilities/types';
2
3
 
3
4
  export type MediaType =
4
5
  | 'unknown'
@@ -7,7 +8,8 @@ export type MediaType =
7
8
  | 'audio'
8
9
  | 'plugin'
9
10
  | 'webpage'
10
- | 'externalimage';
11
+ | 'externalimage'
12
+ | 'external_image';
11
13
 
12
14
  export enum MediaAnimation {
13
15
  Default = 0,
@@ -41,6 +43,8 @@ export class SignageMedia {
41
43
  public readonly media_uri: string;
42
44
  public readonly media_id: string;
43
45
  public readonly thumbnail_id: string;
46
+ public readonly plugin_id: string;
47
+ public readonly plugin_params: HashMap;
44
48
  public readonly play_count: number;
45
49
  public readonly valid_from?: number;
46
50
  public readonly valid_until?: number;
@@ -71,6 +75,8 @@ export class SignageMedia {
71
75
  this.media_uri = data.media_uri || '';
72
76
  this.media_id = data.media_id || '';
73
77
  this.thumbnail_id = data.thumbnail_id || '';
78
+ this.plugin_id = data.plugin_id || '';
79
+ this.plugin_params = data.plugin_params || {};
74
80
  this.play_count = data.play_count || 0;
75
81
  this.valid_from = data.valid_from;
76
82
  this.valid_until = data.valid_until;
@@ -0,0 +1,31 @@
1
+ import { HashMap } from '../utilities/types';
2
+
3
+ export type SignagePlaybackType = 'static' | 'interactive' | 'playsthrough';
4
+
5
+ export class SignagePlugin {
6
+ public readonly id: string;
7
+ public readonly created_at: number;
8
+ public readonly updated_at: number;
9
+ public readonly name: string;
10
+ public readonly description: string;
11
+ public readonly uri: string;
12
+ public readonly playback_type: SignagePlaybackType;
13
+ public readonly authority_id: string;
14
+ public readonly enabled: boolean;
15
+ public readonly params: HashMap;
16
+ public readonly defaults: HashMap;
17
+
18
+ constructor(data: Partial<SignagePlugin> = {}) {
19
+ this.id = data.id || '';
20
+ this.created_at = data.created_at || 0;
21
+ this.updated_at = data.updated_at || 0;
22
+ this.name = data.name || '';
23
+ this.description = data.description || '';
24
+ this.uri = data.uri || '';
25
+ this.playback_type = data.playback_type || 'static';
26
+ this.authority_id = data.authority_id || '';
27
+ this.enabled = data.enabled ?? true;
28
+ this.params = data.params || {};
29
+ this.defaults = data.defaults || {};
30
+ }
31
+ }