Skip to content

Commit

Permalink
Move the geo APIs to account
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienLavocat committed Jun 19, 2024
1 parent 146fcbf commit 2c3364f
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 78 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ npm install @dolbyio/dolbyio-rest-apis-client
## Create a publish token

```ts
import { streaming } from '@dolbyio/dolbyio-rest-apis-client'
import { streaming } from '@dolbyio/dolbyio-rest-apis-client';

const API_KEY = process.env.DOLBYIO_API_SECRET;;
const API_KEY = process.env.DOLBYIO_API_SECRET;

const publishToken = await streaming.publishToken.create(API_KEY, {
label: 'My token',
Expand Down
62 changes: 60 additions & 2 deletions src/streaming/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sendGet, sendPut } from './internal/httpHelpers';
import { sendGet, sendPost, sendPut } from './internal/httpHelpers';
import * as Urls from '../urls';
import { AccountGeoCascade } from './types/account';
import { AccountGeoCascade, GeoRestrictions } from './types/account';

/**
* Gets account wide geo cascade settings.
Expand Down Expand Up @@ -49,3 +49,61 @@ export const updateGeoCascade = async (apiSecret: string, settings: AccountGeoCa

return await sendPut<AccountGeoCascade>(options);
};

/**
* Gets the account geo restrictions.
*
* If a Token (either Publish or Subscribe) does not define any geo restrictions, the account wide rules are used.
*
* @link https://docs.dolby.io/streaming-apis/reference/geo_geo
*
* @param apiSecret The API Secret used to authenticate this request.
*
* @returns A {@link GeoRestrictions} object through a {@link Promise}.
*/
export const readGeoRestrictions = async (apiSecret: string): Promise<GeoRestrictions> => {
const options = {
hostname: Urls.getRtsHostname(),
path: '/api/geo/account',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${apiSecret}`,
},
};

return await sendGet<GeoRestrictions>(options);
};

/**
* Updates the account geo restrictions.
*
* @link https://docs.dolby.io/streaming-apis/reference/geo_updategeo
*
* @param apiSecret The API Secret used to authenticate this request.
* @param allowedCountries The list of allowed countries. An empty array [] removes all rules.
* @param deniedCountries The list of denied countries. An empty array [] removes all rules.
*
* @returns A {@link GeoRestrictions} object through a {@link Promise}.
*/
export const updateGeoRestrictions = async (
apiSecret: string,
allowedCountries: string[] | null = null,
deniedCountries: string[] | null = null
): Promise<GeoRestrictions> => {
const body = {};
if (allowedCountries) body['updateAllowedCountries'] = allowedCountries;
if (deniedCountries) body['updateDeniedCountries'] = deniedCountries;

const options = {
hostname: Urls.getRtsHostname(),
path: '/api/geo/account',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${apiSecret}`,
},
body: JSON.stringify(body),
};

return await sendPost<GeoRestrictions>(options);
};
61 changes: 0 additions & 61 deletions src/streaming/geo.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/streaming/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export * as cluster from './cluster';
*/
export * as transcoders from './transcoders';
export * as director from './director';
export * as geo from './geo';
export * as publishToken from './publishToken';
export * as recordFiles from './recordFiles';
export * as stream from './stream';
Expand Down
10 changes: 10 additions & 0 deletions src/streaming/types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ export interface AccountGeoCascade {
*/
clusters?: string[];
}

/**
* Represents the geo restrictions rules.
*/
export interface GeoRestrictions {
/** List of allowed countries. */
allowedCountries: string[];
/** List of restricted countries. */
deniedCountries: string[];
}
9 changes: 0 additions & 9 deletions src/streaming/types/geo.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/streaming/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './account';
export * from './cluster';
export * from './director';
export * from './geo';
export * from './publishToken';
export * from './recordFiles';
export * from './stream';
Expand Down
49 changes: 47 additions & 2 deletions src/streaming/types/publishToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ export interface PublishToken {
deniedCountries: string[];
/** Cluster to route specified streams to. */
originCluster: string;
/** Does the publish token require authentication to subscribe to the specified streams */
/** Does the publish token require authentication to subscribe to the specified streams. */
subscribeRequiresAuth: boolean;
/** Is the publish token allowed to record the specified streams */
/** Is the publish token allowed to record the specified streams. */
record: boolean;
/**
* Is the publish token allowed to create clips the specified streams.
* @beta
* @remarks Live clipping is currently in Beta phase.
*/
clip: boolean;
/** Is multisource enabled or not. */
multisource: boolean;
/** Is low latency mode for RTMP ingest enabled or not. */
Expand All @@ -77,6 +83,17 @@ export interface PublishToken {
srtPassphrase?: string;
/** Geo cascade settings for cascading stream to other clusters. */
geoCascade: PublishTokenGeoCascade;
/**
* List of endpoints to restream the stream.
* @beta
* @remarks Restream is currently in Beta phase.
*/
restream: {
/** The endpoint to restream media */
url: string;
/** Secret key for restreaming endpoint. */
key: string;
}[];
/**
* Token effective settings for properties that use account default settings.
* Value for each property will either be token or account level settings.
Expand Down Expand Up @@ -145,6 +162,23 @@ export interface UpdatePublishToken {
displaySrtPassphrase?: boolean;
/** Update the geo cascading rules for this publish token. */
updateGeoCascade?: PublishTokenGeoCascade;
/**
* Allow or disallow to create clips of the specified streams.
* @beta
* @remarks Live clipping is currently in Beta phase.
*/
clip?: boolean;
/**
* List of endpoints to restream media.
* @beta
* @remarks Restream is currently in Beta phase.
*/
updateRestream?: {
/** The endpoint to restream the stream */
url: string;
/** Secret key for restreaming endpoint. */
key: string;
}[];
}

/** Represents the information to create a publish token. */
Expand Down Expand Up @@ -243,6 +277,17 @@ export interface CreatePublishToken {
* @remarks Live clipping is currently in Beta phase.
*/
clip?: boolean;
/**
* List of endpoints to restream the stream.
* @beta
* @remarks Restream is currently in Beta phase.
*/
restream?: {
/** The endpoint to restream media */
url: string;
/** Secret key for restreaming endpoint. */
key: string;
}[];
}

/**
Expand Down

0 comments on commit 2c3364f

Please sign in to comment.