@skyway-sdk/token
Version:
The official Next Generation JavaScript SDK for SkyWay
172 lines • 6.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.appScopeSchema = exports.memberActions = void 0;
const zod_1 = require("zod");
const sfu_1 = require("./sfu");
const publicationActions = [
'write',
'create',
'delete',
'updateMetadata',
'enable',
'disable',
];
const publicationScopeSchema = zod_1.z
.object({
/**
* 以下を複数指定可能
* - write: すべて可能
* - create: publish(publish時に publication が作成される)
* - delete: unpublish(unpublish時に publication が削除される)
* - updateMetadata: metadata の編集
* - enable: enable
* - disable: disable
*/
actions: zod_1.z.array(
// 型補完のため enum で定義しておく
zod_1.z
.enum(publicationActions)
.refine((arg) => {
return typeof arg === 'string'; // バリデーションとしては publicationAction 以外の文字列も許容する
})),
})
.passthrough();
const subscriptionActions = ['write', 'create', 'delete'];
const subscriptionScopeSchema = zod_1.z
.object({
/**
* 以下を複数指定可能
* - write: すべて可能
* - create: subscribe(subscribe時に subscription が作成される)
* - delete: unsubscribe(unsubscribe時に subscription が削除される)
*/
actions: zod_1.z.array(
// 型補完のため enum で定義しておく
zod_1.z
.enum(subscriptionActions)
.refine((arg) => {
return typeof arg === 'string'; // バリデーションとしては subscriptionAction 以外の文字列も許容する
})),
})
.passthrough();
exports.memberActions = [
'write',
'create',
'delete',
'updateMetadata',
'signal',
];
const memberScopeSchemaBase = zod_1.z
.object({
/**
* id (id または name のどちらかが必須 *)
* - id で対象の member を指定
* - '*' を指定することで、すべての member を指定
*/
id: zod_1.z.string().optional(),
/**
* name (id または name のどちらかが必須 *)
* - name で対象の channel を指定
* - '*' を指定することで、すべての member を指定
*/
name: zod_1.z.string().optional(),
})
.refine((arg) => arg.id !== undefined || arg.name !== undefined, {
message: 'Either id or name is required.',
});
const memberScopeSchema = zod_1.z.intersection(memberScopeSchemaBase, zod_1.z
.object({
/**
* 以下を複数指定可能
* - write: すべて可能
* - create: 入室(入室時に member が作成される)
* - delete: 退室(入室時に member が削除される)
* - signal: シグナリング情報のやり取り (p2p通信を利用する際に必須)
* - updateMetadata: metadata の編集
*/
actions: zod_1.z.array(
// 型補完のため enum で定義しておく
zod_1.z
.enum(exports.memberActions)
.refine((arg) => {
return typeof arg === 'string'; // バリデーションとしては memberAction 以外の文字列も許容する
})),
/**publication リソースに関するオブジェクトを指定*/
publication: publicationScopeSchema.optional(),
/**subscription リソースに関するオブジェクトを指定*/
subscription: subscriptionScopeSchema.optional(),
})
.passthrough());
const channelActions = [
'write',
'read',
'create',
'delete',
'updateMetadata',
];
const channelScopeSchemaBase = zod_1.z
.object({
/**
* id (id または name のどちらかが必須 *)
* - id で対象の member を指定
* - '*' を指定することで、すべての member を指定
*/
id: zod_1.z.string().optional(),
/**
* name (id または name のどちらかが必須 *)
* - name で対象の channel を指定
* - '*' を指定することで、すべての member を指定
*/
name: zod_1.z.string().optional(),
})
.refine((arg) => arg.id !== undefined || arg.name !== undefined, {
message: 'Either id or name is required.',
});
const channelScopeSchema = zod_1.z.intersection(channelScopeSchemaBase, zod_1.z
.object({
/**
* 以下を複数指定可能
* - write: すべて可能
* - read: 参照
* - create: 作成
* - delete: 削除
* - updateMetadata: metadata の編集
*/
actions: zod_1.z.array(
// 型補完のため enum で定義しておく
zod_1.z
.enum(channelActions)
.refine((arg) => {
return typeof arg === 'string'; // バリデーションとしては channelAction 以外の文字列も許容する
})),
/**member リソースに関するオブジェクトを配列で指定 */
members: zod_1.z.array(memberScopeSchema),
/**sfuBot リソースに関するオブジェクトを配列で指定 */
sfuBots: zod_1.z.array(sfu_1.sfuScopeSchema).optional(),
})
.passthrough());
const appActions = ['read'];
/**@internal */
exports.appScopeSchema = zod_1.z
.object({
/**アプリケーションIDを指定 */
id: zod_1.z.string(),
/**AnalyticsDashboardへのデータ送信をするかどうかの設定 */
analytics: zod_1.z.boolean().optional(),
/**アプリケーション自体に関する権限。現在は'read'固定 */
actions: zod_1.z
.array(
// 型補完のため enum で定義しておく
zod_1.z
.enum(appActions)
.refine((arg) => {
return typeof arg === 'string'; // バリデーションとしては AppAction 以外の文字列も許容する
}))
.optional(),
/**channelリソースに関するオブジェクトを配列で指定*/
channels: zod_1.z.array(channelScopeSchema).optional(),
/**falseの場合はTurnサーバを経由してメディア通信を行いません。 */
turn: zod_1.z.boolean().optional(),
})
.passthrough();
//# sourceMappingURL=v1-2.js.map