Skip to content

Commit

Permalink
add messaging contract for duck player page
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Jul 31, 2024
1 parent e4a01f6 commit ce63bd8
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "http://json-schema.org/draft-07/schema#"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "./userValues.shared.json"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "http://json-schema.org/draft-07/schema#"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["userValues", "settings", "locale", "env", "platform"],
"properties": {
"userValues": { "$ref": "./userValues.shared.json" },
"settings": {
"type": "object",
"title": "DuckPlayerPageSettings",
"required": ["pip"],
"properties": {
"pip": {
"type": "object",
"required": ["state"],
"properties": {
"state": {
"type": "string",
"enum": ["enabled", "disabled"]
}
}
},
"autoplay": {
"type": "object",
"required": ["state"],
"properties": {
"state": {
"type": "string",
"enum": ["enabled", "disabled"]
}
}
}
}
},
"locale": {
"type": "string"
},
"env": {
"type": "string",
"enum": ["development", "production"]
},
"platform": {
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"enum": ["macos", "windows", "android", "ios"]
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "./userValues.shared.json"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["message"],
"properties": {
"message": {
"type": "string"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["message"],
"properties": {
"message": {
"type": "string"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "./userValues.shared.json"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "./userValues.shared.json"
}
]
}
41 changes: 41 additions & 0 deletions packages/special-pages/messages/duckplayer/userValues.shared.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "UserValues",
"additionalProperties": false,
"required": ["overlayInteracted", "privatePlayerMode"],
"properties": {
"overlayInteracted": {
"type": "boolean"
},
"privatePlayerMode": {
"title": "PrivatePlayerMode",
"oneOf": [
{
"type": "object",
"required": ["enabled"],
"additionalProperties": false,
"properties": {
"enabled": {}
}
},
{
"type": "object",
"required": ["disabled"],
"additionalProperties": false,
"properties": {
"disabled": {}
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["alwaysAsk"],
"properties": {
"alwaysAsk": {}
}
}
]
}
}
}
122 changes: 122 additions & 0 deletions packages/special-pages/types/duckplayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* @module Duckplayer Messages
* @description
*
* These types are auto-generated from schema files.
* scripts/build-types.mjs is responsible for type generation.
* **DO NOT** edit this file directly as your changes will be lost.
*/

export type PrivatePlayerMode =
| {
enabled: unknown;
}
| {
disabled: unknown;
}
| {
alwaysAsk: unknown;
};

/**
* Requests, Notifications and Subscriptions from the Duckplayer feature
*/
export interface DuckplayerMessages {
notifications:
| OpenInfoNotification
| OpenSettingsNotification
| ReportInitExceptionNotification
| ReportPageExceptionNotification;
requests: GetUserValuesRequest | InitialSetupRequest | SetUserValuesRequest;
subscriptions: OnUserValuesChangedSubscription;
}
/**
* Generated from @see "../messages/duckplayer/openInfo.notify.json"
*/
export interface OpenInfoNotification {
method: "openInfo";
}
/**
* Generated from @see "../messages/duckplayer/openSettings.notify.json"
*/
export interface OpenSettingsNotification {
method: "openSettings";
}
/**
* Generated from @see "../messages/duckplayer/reportInitException.notify.json"
*/
export interface ReportInitExceptionNotification {
method: "reportInitException";
params: ReportInitExceptionNotify;
}
export interface ReportInitExceptionNotify {
message: string;
}
/**
* Generated from @see "../messages/duckplayer/reportPageException.notify.json"
*/
export interface ReportPageExceptionNotification {
method: "reportPageException";
params: ReportPageExceptionNotify;
}
export interface ReportPageExceptionNotify {
message: string;
}
/**
* Generated from @see "../messages/duckplayer/getUserValues.request.json"
*/
export interface GetUserValuesRequest {
method: "getUserValues";
result: UserValues;
}
export interface UserValues {
overlayInteracted: boolean;
privatePlayerMode: PrivatePlayerMode;
}
/**
* Generated from @see "../messages/duckplayer/initialSetup.request.json"
*/
export interface InitialSetupRequest {
method: "initialSetup";
result: InitialSetupResponse;
}
export interface InitialSetupResponse {
userValues: UserValues;
settings: DuckPlayerPageSettings;
locale: string;
env: "development" | "production";
platform: {
name: "macos" | "windows" | "android" | "ios";
};
}
export interface DuckPlayerPageSettings {
pip: {
state: "enabled" | "disabled";
};
autoplay?: {
state: "enabled" | "disabled";
};
}
/**
* Generated from @see "../messages/duckplayer/setUserValues.request.json"
*/
export interface SetUserValuesRequest {
method: "setUserValues";
params: UserValues;
result: UserValues;
}
/**
* Generated from @see "../messages/duckplayer/onUserValuesChanged.subscribe.json"
*/
export interface OnUserValuesChangedSubscription {
subscriptionEvent: "onUserValuesChanged";
params: UserValues;
}

declare module "../pages/duckplayer/src/js/index.js" {
export interface DuckplayerPage {
notify: import("@duckduckgo/messaging/lib/shared-types").MessagingBase<DuckplayerMessages>['notify'],
request: import("@duckduckgo/messaging/lib/shared-types").MessagingBase<DuckplayerMessages>['request'],
subscribe: import("@duckduckgo/messaging/lib/shared-types").MessagingBase<DuckplayerMessages>['subscribe']
}
}

0 comments on commit ce63bd8

Please sign in to comment.