@hygraph/app-sdk 0.0.4-alpha.1 → 0.0.4
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.
- package/dist/app-sdk.cjs.development.js.map +1 -1
- package/dist/app-sdk.cjs.production.min.js.map +1 -1
- package/dist/app-sdk.esm.js.map +1 -1
- package/dist/app-sdk.umd.development.js.map +1 -1
- package/dist/app-sdk.umd.production.min.js.map +1 -1
- package/dist/base.d.ts +21 -0
- package/package.json +2 -2
- package/src/base.ts +21 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-sdk.cjs.development.js","sources":["../src/base.ts","../src/field.ts","../src/type-helpers/appInstallation.ts","../src/index.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIA;IACaA,sBAAsB,GAAG,CACpC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS;AAGX,WAAYC,mBAAmB;EAC7BA,sCAAe;EACfA,oCAAa;EACbA,kCAAW;AACb,CAAC,EAJWA,2BAAmB,KAAnBA,2BAAmB;;ICvBlBC,kBAAkB,GAAG;E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-sdk.cjs.development.js","sources":["../src/base.ts","../src/field.ts","../src/type-helpers/appInstallation.ts","../src/index.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIA;IACaA,sBAAsB,GAAG,CACpC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS;AAGX,WAAYC,mBAAmB;EAC7BA,sCAAe;EACfA,oCAAa;EACbA,kCAAW;AACb,CAAC,EAJWA,2BAAmB,KAAnBA,2BAAmB;;ICvBlBC,kBAAkB,GAAG;EAChCC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE,UAAU;EACpBC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,UAAU;EACpBC,IAAI,EAAE,M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B,iCAClBD,CAAC;YAEL,IAAIrC,KAAK,EACPgB,OAAO,CAACC,IAAI,WACFb,GAAG,yBACXkC,iBAAiB,CAClB;YACH,IAAI,YAAY,IAAID,CAAC,IAAI,OAAOA,CAAC,CAACE,UAAU,KAAK,SAAS,EAAE;cAC1DF,CAAC,CAACE,UAAU,GACRJ,MAAM,CAAC;gBAAET,MAAM,EAAE,MAAM;gBAAED,KAAK,EAAE;eAAQ,CAAC,GACzCU,MAAM,CAAC;gBAAET,MAAM,EAAE,MAAM;gBAAED,KAAK,EAAE;eAAQ,CAAC;;YAE/CxB,OAAO,CAACZ,WAAW,CAACiD,iBAAiB,CAAC,CAAC;WACxC,CAAC;UAEF,IAAItC,KAAK,EAAEgB,OAAO,CAACC,IAAI,WAASb,GAAG,mBAAgB;UACnDH,OAAO,CAACZ,WAAW,CAAC+C,cAAc,CAAC,CAAC;UACpC9B,OAAO,CAAC;YAAE0B,MAAM,EAAE,IAAI;YAAE1C,KAAK,EAAED,WAAW,CAAC+C,cAAc;WAAG,CAAC;SAC9D,MAAM;UACL,IAAIpC,KAAK,EACPgB,OAAO,CAACC,IAAI,WACFb,GAAG,sCACX4B,MAAM,CACP;UACH1B,OAAO,CAAC;YAAE0B,MAAM,EAAE;WAAc,CAAC;;OAEpC,CAAC;KACH,MAAM;MACL,IAAIhC,KAAK,EAAEgB,OAAO,CAACN,KAAK,yCAAyC;MACjEH,MAAM,CAAC;QACLG,KAAK,EAAE,sBAAsB;QAC7BC,OAAO,EACL;OACH,CAAC;;GAEL,CACF;AACH;AAEA,YAAe;EAAEZ,IAAI,EAAJA;CAAM;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-sdk.cjs.production.min.js","sources":["../src/base.ts","../src/index.ts","../src/type-helpers/appInstallation.ts","../src/field.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n"],"names":["ExtensionPermission","reservedExtensionProps","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","_ref$onProps","onProps","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded","COMPLETED","DISABLED","PENDING","FieldRenderer","ListRenderer","TableRenderer","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION"],"mappings":"6SA6BYA,EAxBCC,EAAyB,CACpC,UACA,SACA,QACA,QACA,SACA,MACA,WACA,YACA,kBACA,OACA,OACA,SACA,YACA,aACA,WACA,UACA,YACA,WACA,UACA,UACA,YAGUD,EAAAA,8BAAAA,+CAEVA,cACAA,iFCgBF,SAASE,EAAYC,GACnB,IAAMC,EAAwB,GAe9B,OAdAC,OAAOC,KAAKH,GAAOI,SAAQ,SAACC,GAEtBP,EAAuBQ,SAASD,KAIlCA,EAAIE,WAAW,MACfT,EAAuBQ,SAASD,EAAIG,QAAQ,MAAO,KAEnDP,EAAiBI,EAAIG,QAAQ,MAAO,KAAOR,EAAMK,GAEjDJ,EAAiBI,GAAOL,EAAMK,OAG3BJ,WAGOQ,SACdC,IAAAA,MAAKC,IACLC,QAAAA,aAAU,eACLC,IAALC,IAMA,OAAO,IAAIC,SACT,SAACC,EAASC,GACR,GACoB,oBAAXC,aACuB,IAAvBA,OAAOC,YAEd,OAAOF,EAAO,CACZG,MAAO,kBACPC,QACE,qEAIN,IAAMP,EACJD,GAC4B,oBAApBS,iBACN,IAAIA,gBAAgBJ,OAAOK,SAASC,QAAQC,IAAI,gBAEpD,IAAKX,EAGH,OAFIJ,GACFgB,QAAQN,4DACHH,EAAO,CACZG,MAAO,cACPC,QAAS,8DAGTX,GAAOgB,QAAQC,aAAab,6BAA8BA,GAE9Dc,EAAKC,OAAO,CACVC,IAAKhB,EACLiB,IAAKb,OAAOK,SAASS,KAAKC,WAC1BC,WAAY,CACVC,OAAO,EACPC,QAAQ,EACRC,QAAS,QAEXrC,MAAO,CACLsC,YAAa,CACXC,KAAM,oBAIiB,IAAlBrB,OAAOsB,QAGhBF,EAFiDpB,OAAOsB,OAAhDF,aAEIxB,GAAK2B,MAAK,SAACC,GACrB,IAAe,IAAXA,EAAiB,CACnB,MAKIxB,OAAOsB,OAJAG,IAAT/B,QACagC,IACbC,OACGC,SAGDpC,GACFgB,QAAQC,aAAab,2BAA6BgC,GACpDH,GAAc,SAACI,OAIRC,IACDD,KAEArC,GACFgB,QAAQC,aACEb,uBACRkC,GAEA,eAAgBD,GAA6B,kBAAjBA,EAAEE,YAE5BJ,EADJE,EAAEE,WACS,CAAEb,OAAQ,OAAQD,MAAO,QACzB,CAAEC,OAAQ,OAAQD,MAAO,SAEtCvB,EAAQb,EAAYiD,OAGlBtC,GAAOgB,QAAQC,aAAab,mBAChCF,EAAQb,EAAY+C,IACpB9B,EAAQ,CAAE0B,OAAQ,KAAM1C,MAAOD,EAAY+C,UAEvCpC,GACFgB,QAAQC,aACEb,oCACR4B,GAEJ1B,EAAQ,CAAE0B,OAAQ,mBAIlBhC,GAAOgB,QAAQN,+CACnBH,EAAO,CACLG,MAAO,uBACPC,QACE,sEAOZ,MAAe,CAAEZ,KAAAA,iCC9KoB,CACnCyC,UAAW,YACXC,SAAU,WACVC,QAAS,yCCkB0B,CACnCC,cAAe,gBACfC,aAAc,eACdC,cAAe,4CApBiB,CAChCC,OAAQ,SACRC,SAAU,WACVC,IAAK,MACLC,MAAO,QACPC,QAAS,UACTC,KAAM,OACNC,SAAU,WACVC,KAAM,OACNC,SAAU,WACVC,MAAO,QACPC,YAAa,cACbC,SAAU,WACVC,MAAO,QACPC,MAAO"}
|
|
1
|
+
{"version":3,"file":"app-sdk.cjs.production.min.js","sources":["../src/base.ts","../src/index.ts","../src/type-helpers/appInstallation.ts","../src/field.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n"],"names":["ExtensionPermission","reservedExtensionProps","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","_ref$onProps","onProps","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded","COMPLETED","DISABLED","PENDING","FieldRenderer","ListRenderer","TableRenderer","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION"],"mappings":"6SA6BYA,EAxBCC,EAAyB,CACpC,UACA,SACA,QACA,QACA,SACA,MACA,WACA,YACA,kBACA,OACA,OACA,SACA,YACA,aACA,WACA,UACA,YACA,WACA,UACA,UACA,YAGUD,EAAAA,8BAAAA,+CAEVA,cACAA,iFCgBF,SAASE,EAAYC,GACnB,IAAMC,EAAwB,GAe9B,OAdAC,OAAOC,KAAKH,GAAOI,SAAQ,SAACC,GAEtBP,EAAuBQ,SAASD,KAIlCA,EAAIE,WAAW,MACfT,EAAuBQ,SAASD,EAAIG,QAAQ,MAAO,KAEnDP,EAAiBI,EAAIG,QAAQ,MAAO,KAAOR,EAAMK,GAEjDJ,EAAiBI,GAAOL,EAAMK,OAG3BJ,WAGOQ,SACdC,IAAAA,MAAKC,IACLC,QAAAA,aAAU,eACLC,IAALC,IAMA,OAAO,IAAIC,SACT,SAACC,EAASC,GACR,GACoB,oBAAXC,aACuB,IAAvBA,OAAOC,YAEd,OAAOF,EAAO,CACZG,MAAO,kBACPC,QACE,qEAIN,IAAMP,EACJD,GAC4B,oBAApBS,iBACN,IAAIA,gBAAgBJ,OAAOK,SAASC,QAAQC,IAAI,gBAEpD,IAAKX,EAGH,OAFIJ,GACFgB,QAAQN,4DACHH,EAAO,CACZG,MAAO,cACPC,QAAS,8DAGTX,GAAOgB,QAAQC,aAAab,6BAA8BA,GAE9Dc,EAAKC,OAAO,CACVC,IAAKhB,EACLiB,IAAKb,OAAOK,SAASS,KAAKC,WAC1BC,WAAY,CACVC,OAAO,EACPC,QAAQ,EACRC,QAAS,QAEXrC,MAAO,CACLsC,YAAa,CACXC,KAAM,oBAIiB,IAAlBrB,OAAOsB,QAGhBF,EAFiDpB,OAAOsB,OAAhDF,aAEIxB,GAAK2B,MAAK,SAACC,GACrB,IAAe,IAAXA,EAAiB,CACnB,MAKIxB,OAAOsB,OAJAG,IAAT/B,QACagC,IACbC,OACGC,SAGDpC,GACFgB,QAAQC,aAAab,2BAA6BgC,GACpDH,GAAc,SAACI,OAIRC,IACDD,KAEArC,GACFgB,QAAQC,aACEb,uBACRkC,GAEA,eAAgBD,GAA6B,kBAAjBA,EAAEE,YAE5BJ,EADJE,EAAEE,WACS,CAAEb,OAAQ,OAAQD,MAAO,QACzB,CAAEC,OAAQ,OAAQD,MAAO,SAEtCvB,EAAQb,EAAYiD,OAGlBtC,GAAOgB,QAAQC,aAAab,mBAChCF,EAAQb,EAAY+C,IACpB9B,EAAQ,CAAE0B,OAAQ,KAAM1C,MAAOD,EAAY+C,UAEvCpC,GACFgB,QAAQC,aACEb,oCACR4B,GAEJ1B,EAAQ,CAAE0B,OAAQ,mBAIlBhC,GAAOgB,QAAQN,+CACnBH,EAAO,CACLG,MAAO,uBACPC,QACE,sEAOZ,MAAe,CAAEZ,KAAAA,iCC9KoB,CACnCyC,UAAW,YACXC,SAAU,WACVC,QAAS,yCCkB0B,CACnCC,cAAe,gBACfC,aAAc,eACdC,cAAe,4CApBiB,CAChCC,OAAQ,SACRC,SAAU,WACVC,IAAK,MACLC,MAAO,QACPC,QAAS,UACTC,KAAM,OACNC,SAAU,WACVC,KAAM,OACNC,SAAU,WACVC,MAAO,QACPC,YAAa,cACbC,SAAU,WACVC,MAAO,QACPC,MAAO"}
|
package/dist/app-sdk.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-sdk.esm.js","sources":["../src/base.ts","../src/field.ts","../src/type-helpers/appInstallation.ts","../src/index.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;AAIA;IACaA,sBAAsB,GAAG,CACpC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS;IAGCC;AAAZ,WAAYA,mBAAmB;EAC7BA,sCAAe;EACfA,oCAAa;EACbA,kCAAW;AACb,CAAC,EAJWA,mBAAmB,KAAnBA,mBAAmB;;ICvBlBC,kBAAkB,GAAG;EAChCC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE,UAAU;EACpBC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,UAAU;EACpBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE,OAAO;EACdC,WAAW,EAAE,aAAa;EAC1BC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;CACC;AAEV,IAAaC,qBAAqB,GAAG;EACnCC,aAAa,EAAE,eAAe;EAC9BC,YAAY,EAAE,cAAc;EAC5BC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AAM;gBAAED,KAAK,EAAE;eAAQ,CAAC,GACzCU,MAAM,CAAC;gBAAET,MAAM,EAAE,MAAM;gBAAED,KAAK,EAAE;eAAQ,CAAC;;YAE/CxB,OAAO,CAACZ,WAAW,CAACiD,iBAAiB,CAAC,CAAC;WACxC,CAAC;UAEF,IAAItC,KAAK,EAAEgB,OAAO,CAACC,IAAI,WAASb,GAAG,mBAAgB;UACnDH,OAAO,CAACZ,WAAW,CAAC+C,cAAc,CAAC,CAAC;UACpC9B,OAAO,CAAC;YAAE0B,MAAM,EAAE,IAAI;YAAE1C,KAAK,EAAED,WAAW,CAAC+C,cAAc;WAAG,CAAC;SAC9D,MAAM;UACL,IAAIpC,KAAK,EACPgB,OAAO,CAACC,IAAI,WACFb,GAAG,sCACX4B,MAAM,CACP;UACH1B,OAAO,CAAC;YAAE0B,MAAM,EAAE;WAAc,CAAC;;OAEpC,CAAC;KACH,MAAM;MACL,IAAIhC,KAAK,EAAEgB,OAAO,CAACN,KAAK,yCAAyC;MACjEH,MAAM,CAAC;QACLG,KAAK,EAAE,sBAAsB;QAC7BC,OAAO,EACL;OACH,CAAC;;GAEL,CACF;AACH;AAEA,YAAe;EAAEZ,IAAI,EAAJA;CAAM;;;;;"}
|
|
1
|
+
{"version":3,"file":"app-sdk.esm.js","sources":["../src/base.ts","../src/field.ts","../src/type-helpers/appInstallation.ts","../src/index.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;AAIA;IACaA,sBAAsB,GAAG,CACpC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS;IAGCC;AAAZ,WAAYA,mBAAmB;EAC7BA,sCAAe;EACfA,oCAAa;EACbA,kCAAW;AACb,CAAC,EAJWA,mBAAmB,KAAnBA,mBAAmB;;ICvBlBC,kBAAkB,GAAG;EAChCC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE,UAAU;EACpBC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,UAAU;EACpBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE,OAAO;EACdC,WAAW,EAAE,aAAa;EAC1BC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;CACC;AAEV,IAAaC,qBAAqB,GAAG;EACnCC,aAAa,EAAE,eAAe;EAC9BC,YAAY,EAAE,cAAc;EAC5BC,aAAa,EAAE;CACP;;ICzBGC,qBAAqB,GAAG;EACnCC,SAAS,EAAE,WAAW;EACtBC,QAAQ,EAAE,UAAU;EACpBC,OAAO,EAAE;CACD;;;;ACNV,AAgDA,SAASC,WAAW,CAACC,KAAU;EAC7B,IAAMC,gBAAgB,GAAQ,EAAE;EAChCC,M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EAAEgB,OAAO,CAACC,IAAI,WAASb,GAAG,mBAAgB;UACnDH,OAAO,CAACZ,WAAW,CAAC+C,cAAc,CAAC,CAAC;UACpC9B,OAAO,CAAC;YAAE0B,MAAM,EAAE,IAAI;YAAE1C,KAAK,EAAED,WAAW,CAAC+C,cAAc;WAAG,CAAC;SAC9D,MAAM;UACL,IAAIpC,KAAK,EACPgB,OAAO,CAACC,IAAI,WACFb,GAAG,sCACX4B,MAAM,CACP;UACH1B,OAAO,CAAC;YAAE0B,MAAM,EAAE;WAAc,CAAC;;OAEpC,CAAC;KACH,MAAM;MACL,IAAIhC,KAAK,EAAEgB,OAAO,CAACN,KAAK,yCAAyC;MACjEH,MAAM,CAAC;QACLG,KAAK,EAAE,sBAAsB;QAC7BC,OAAO,EACL;OACH,CAAC;;GAEL,CACF;AACH;AAEA,YAAe;EAAEZ,IAAI,EAAJA;CAAM;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-sdk.umd.development.js","sources":["../src/base.ts","../src/field.ts","../src/type-helpers/appInstallation.ts","../src/index.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;;;;;;;EAIA;MACaA,sBAAsB,GAAG,CACpC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WA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AM;QACL,IAAIhC,KAAK,EAAEgB,OAAO,CAACN,KAAK,yCAAyC;QACjEH,MAAM,CAAC;UACLG,KAAK,EAAE,sBAAsB;UAC7BC,OAAO,EACL;SACH,CAAC;;KAEL,CACF;EACH;AAEA,cAAe;IAAEZ,IAAI,EAAJA;GAAM;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"app-sdk.umd.development.js","sources":["../src/base.ts","../src/field.ts","../src/type-helpers/appInstallation.ts","../src/index.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n"],"names":["reservedExtensionProps","ExtensionPermission","FieldExtensionType","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION","FieldExtensionFeature","FieldRenderer","ListRenderer","TableRenderer","AppInstallationStatus","COMPLETED","DISABLED","PENDING","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","onProps","undefined","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded"],"mappings":";;;;;;;;;;;;;;;;;;;;;EAIA;MACaA,sBAAsB,GAAG,CACpC,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS;EAGX,WAAYC,mBAAmB;IAC7BA,sCAAe;IACfA,oCAAa;IACbA,kCAAW;EACb,CAAC,EAJWA,2BAAmB,KA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GAAM;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-sdk.umd.production.min.js","sources":["../src/base.ts","../src/index.ts","../src/type-helpers/appInstallation.ts","../src/field.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n"],"names":["ExtensionPermission","reservedExtensionProps","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","_ref$onProps","onProps","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded","COMPLETED","DISABLED","PENDING","FieldRenderer","ListRenderer","TableRenderer","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION"],"mappings":"weA6BYA,EAxBCC,EAAyB,CACpC,UACA,SACA,QACA,QACA,SACA,MACA,WACA,YACA,kBACA,OACA,OACA,SACA,YACA,aACA,WACA,UACA,YACA,WACA,UACA,UACA,YAGUD,EAAAA,wBAAAA,yCAEVA,cACAA,iFCgBF,SAASE,EAAYC,GACnB,IAAMC,EAAwB,GAe9B,OAdAC,OAAOC,KAAKH,GAAOI,SAAQ,SAACC,GAEtBP,EAAuBQ,SAASD,KAIlCA,EAAIE,WAAW,MACfT,EAAuBQ,SAASD,EAAIG,QAAQ,MAAO,KAEnDP,EAAiBI,EAAIG,QAAQ,MAAO,KAAOR,EAAMK,GAEjDJ,EAAiBI,GAAOL,EAAMK,OAG3BJ,WAGOQ,SACdC,IAAAA,MAAKC,IACLC,QAAAA,aAAU,eACLC,IAALC,IAMA,OAAO,IAAIC,SACT,SAACC,EAASC,GACR,GACoB,oBAAXC,aACuB,IAAvBA,OAAOC,YAEd,OAAOF,EAAO,CACZG,MAAO,kBACPC,QACE,qEAIN,IAAMP,EACJD,GAC4B,oBAApBS,iBACN,IAAIA,gBAAgBJ,OAAOK,SAASC,QAAQC,IAAI,gBAEpD,IAAKX,EAGH,OAFIJ,GACFgB,QAAQN,4DACHH,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3,"file":"app-sdk.umd.production.min.js","sources":["../src/base.ts","../src/index.ts","../src/type-helpers/appInstallation.ts","../src/field.ts"],"sourcesContent":["import type { ShowToast } from './type-helpers/toast';\nimport type { OpenDialog } from './type-helpers/dialog';\nimport type { OpenAssetPicker } from './type-helpers/openAssetPicker';\n\n// see https://github.com/krakenjs/zoid/blob/master/src/component/props.js#L53\nexport const reservedExtensionProps = [\n 'timeout',\n 'window',\n 'close',\n 'focus',\n 'resize',\n 'uid',\n 'cspNonce',\n 'getParent',\n 'getParentDomain',\n 'hide',\n 'show',\n 'export',\n 'onDisplay',\n 'onRendered',\n 'onRender',\n 'onClose',\n 'onDestroy',\n 'onResize',\n 'onFocus',\n 'onError',\n 'onProps',\n];\n\nexport enum ExtensionPermission {\n INPUT = 'INPUT',\n FORM = 'FORM',\n API = 'API',\n}\n\ntype ConfigVariableName = string;\n\ntype ConfigVariableSettings = {\n type: 'string' | 'number' | 'boolean';\n displayName?: string;\n description?: string;\n required?: boolean;\n defaultValue?: any;\n};\n\nexport type ConfigFields = Record<ConfigVariableName, ConfigVariableSettings>;\n\nexport type ConfigValue = Record<\n string,\n boolean | number | string | undefined | null\n>;\n\nexport type FieldConfig = {\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n};\n\nexport type FormSidebarConfig = { sidebarConfig: ConfigValue };\n\nexport type Project = {\n id: string;\n name: string;\n mgmtApi: string;\n mgmtToken: string;\n};\n\nexport type Environment = {\n id: string;\n name: string;\n endpoint: string;\n authToken: string;\n};\n\nexport type User = {\n id: string;\n};\n\nexport type Context = {\n /**\n * The project that the app is running in\n */\n project: Project;\n /**\n * The environment that the app is running in\n */\n environment: Environment;\n /**\n * The user that is currently logged in\n * Available only to apps that have read User permission\n *\n * Intended to be used to fetch user's permissions and roles\n * from the management API using the user's ID.\n *\n * @example\n * ```graphql\n * query user_query($id: ID!) {\n * viewer {\n * ... on AppTokenViewer {\n * id\n * user(id: $id) {\n * permissions\n * roles {\n * name\n * isDefault\n * }\n * }\n * }\n * }\n * }\n * ```\n */\n user?: User;\n};\n\nexport interface ExtensionPropsBase {\n context: Context;\n openDialog: OpenDialog;\n showToast: ShowToast;\n openAssetPicker: OpenAssetPicker;\n redirectParent: (location: string | Location) => Promise<void>;\n historyReplace: (url: string | HistoryCallback) => Promise<void>;\n historyPush: (url: string | HistoryCallback) => Promise<void>;\n}\n\nexport interface ExtensionDialogProps extends ExtensionPropsBase {\n onCloseDialog: (value: any) => void;\n}\n\ntype HistoryCallback = (href: Location['href']) => string;\n","import zoid from '@graphcms/zoid/lib/zoid.js';\n\nimport { ExtensionDialogProps, reservedExtensionProps } from './base';\nexport { ExtensionDialogProps, reservedExtensionProps } from './base';\nimport type { FieldExtensionProps } from './field';\nimport type { FormSidebarExtensionProps } from './formSidebar';\nexport * from './base';\nexport type {\n FormState,\n FieldState,\n FieldSubscription,\n Subscriber,\n FormSubscription,\n Form,\n} from './type-helpers/form';\n\nexport type {\n VisibilityTypes,\n SetFieldsVisibility,\n VisibilityMap,\n} from './type-helpers/visibility';\n\nexport type { FieldExtensionProps } from './field';\nexport type { AppProps } from './app';\nexport type { FormSidebarExtensionProps } from './formSidebar';\nexport { FieldExtensionFeature, FieldExtensionType } from './field';\nexport * from './type-helpers/appInstallation';\n\nexport type ExtensionProps =\n | FieldExtensionProps\n | FormSidebarExtensionProps\n | ExtensionDialogProps;\n\ntype Xprops = {\n onProps: (props: Record<string, any>) => void;\n onConnected: (uid: string) => Promise<unknown>;\n resize: (size: {\n height: 'auto' | 'full' | number;\n width: 'auto' | '100%' | number;\n }) => unknown;\n} & ExtensionProps;\n\ndeclare global {\n interface Window {\n xprops: Xprops;\n }\n}\n\nfunction handleProps(props: any) {\n const transformedProps: any = {};\n Object.keys(props).forEach((key: string) => {\n // do not pass down zoid props to the extension\n if (reservedExtensionProps.includes(key)) return;\n\n // transform props that were prefixed with '_' to bypass zoid reverved props\n if (\n key.startsWith('_') &&\n reservedExtensionProps.includes(key.replace(/^_/g, ''))\n ) {\n transformedProps[key.replace(/^_/g, '')] = props[key];\n } else {\n transformedProps[key] = props[key];\n }\n });\n return transformedProps;\n}\n\nexport function init({\n debug,\n onProps = () => undefined,\n uid: givenUid,\n}: {\n onProps: (props: any) => unknown;\n debug?: boolean;\n uid?: string;\n}) {\n return new Promise<{ status: 'ok'; props: any } | { status: 'validation' }>(\n (resolve, reject) => {\n if (\n typeof window === 'undefined' ||\n typeof window.postMessage === 'undefined'\n ) {\n return reject({\n error: 'unsupported_env',\n message:\n 'Unsupported environment: Not in a browser supporting PostMessage',\n });\n }\n\n const uid =\n givenUid ||\n (typeof URLSearchParams !== 'undefined' &&\n new URLSearchParams(window.location.search).get('extensionUid'));\n\n if (!uid) {\n if (debug)\n console.error(`[UIX] no uid found in init params or extension URL`);\n return reject({\n error: 'missing_uid',\n message: 'Missing UID: no UID found in init params or extension URL',\n });\n }\n if (debug) console.info(`[UIX:${uid}] initializing with uid ${uid}`);\n\n zoid.create({\n tag: uid,\n url: window.location.href.toString(),\n autoResize: {\n width: false,\n height: true,\n element: 'html',\n },\n props: {\n onConnected: {\n type: 'function',\n },\n },\n });\n if (typeof window.xprops !== 'undefined') {\n const { onConnected, onProps: initialOnProps } = window.xprops;\n\n onConnected(uid).then((status) => {\n if (status === true) {\n const {\n onProps: onParentProps,\n onConnected: _nevermind,\n resize,\n ...extensionProps\n } = window.xprops;\n\n if (debug)\n console.info(`[UIX:${uid}] initial shared props`, extensionProps);\n onParentProps((p: Xprops) => {\n const {\n onProps: onParentProps,\n onConnected,\n ...newExtensionProps\n } = p;\n\n if (debug)\n console.info(\n `[UIX:${uid}] new shared props`,\n newExtensionProps\n );\n if ('isExpanded' in p && typeof p.isExpanded === 'boolean') {\n p.isExpanded\n ? resize({ height: 'full', width: '100%' })\n : resize({ height: 'auto', width: '100%' });\n }\n onProps(handleProps(newExtensionProps));\n });\n\n if (debug) console.info(`[UIX:${uid}] initialized`);\n onProps(handleProps(extensionProps));\n resolve({ status: 'ok', props: handleProps(extensionProps) });\n } else {\n if (debug)\n console.info(\n `[UIX:${uid}] sdk renderer returned status:`,\n status\n );\n resolve({ status: 'validation' });\n }\n });\n } else {\n if (debug) console.error(`[UIX] no shared props from host found`);\n reject({\n error: 'failed_communication',\n message:\n 'No communication established with host, please check your URL',\n });\n }\n }\n );\n}\n\nexport default { init };\n","import type { ConfigValue } from '../base';\n\nexport const AppInstallationStatus = {\n COMPLETED: 'COMPLETED',\n DISABLED: 'DISABLED',\n PENDING: 'PENDING',\n} as const;\n\nexport type AppInstallation = {\n id: string;\n config: ConfigValue;\n status: keyof typeof AppInstallationStatus;\n};\n","import type { Form } from './type-helpers/form';\nimport type { ExtensionPropsBase, ConfigValue } from './base';\nimport type { Model } from './type-helpers/model';\nimport type { AppInstallation } from './type-helpers/appInstallation';\nimport type { Field } from './type-helpers/field';\n\nexport const FieldExtensionType = {\n STRING: 'STRING',\n RICHTEXT: 'RICHTEXT',\n INT: 'INT',\n FLOAT: 'FLOAT',\n BOOLEAN: 'BOOLEAN',\n JSON: 'JSON',\n DATETIME: 'DATETIME',\n DATE: 'DATE',\n LOCATION: 'LOCATION',\n COLOR: 'COLOR',\n ENUMERATION: 'ENUMERATION',\n RELATION: 'RELATION',\n ASSET: 'ASSET',\n UNION: 'UNION',\n} as const;\n\nexport const FieldExtensionFeature = {\n FieldRenderer: 'FieldRenderer',\n ListRenderer: 'ListRenderer',\n TableRenderer: 'TableRenderer',\n} as const;\n\nexport interface FieldExtensionProps extends ExtensionPropsBase {\n extension: {\n config: ConfigValue;\n tableConfig: ConfigValue;\n fieldConfig: ConfigValue;\n id: string;\n };\n\n isExpanded: boolean;\n expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => unknown;\n\n // name of the field in the form (may differ from the field apiId, ie. for localized fields)\n name: string;\n\n // current locale on localized field\n locale: string | undefined;\n\n // current entry id, null for new entries;\n entryId: string | null;\n\n isTableCell: boolean;\n\n isReadOnly: boolean | undefined;\n\n value: any;\n\n onBlur: (event?: FocusEvent) => Promise<void>;\n\n onChange: (event: InputEvent | any) => Promise<void>;\n\n onFocus: (event?: FocusEvent) => Promise<void>;\n\n // @see https://final-form.org/docs/react-final-form/types/FieldRenderProps\n meta: {\n active: boolean;\n error: any;\n touched: boolean;\n };\n\n form: Form;\n field: Field;\n model: Model;\n installation: AppInstallation;\n}\n"],"names":["ExtensionPermission","reservedExtensionProps","handleProps","props","transformedProps","Object","keys","forEach","key","includes","startsWith","replace","init","debug","_ref$onProps","onProps","givenUid","uid","Promise","resolve","reject","window","postMessage","error","message","URLSearchParams","location","search","get","console","info","zoid","create","tag","url","href","toString","autoResize","width","height","element","onConnected","type","xprops","then","status","onParentProps","_nevermind","resize","extensionProps","p","newExtensionProps","isExpanded","COMPLETED","DISABLED","PENDING","FieldRenderer","ListRenderer","TableRenderer","STRING","RICHTEXT","INT","FLOAT","BOOLEAN","JSON","DATETIME","DATE","LOCATION","COLOR","ENUMERATION","RELATION","ASSET","UNION"],"mappings":"weA6BYA,EAxBCC,EAAyB,CACpC,UACA,SACA,QACA,QACA,SACA,MACA,WACA,YACA,kBACA,OACA,OACA,SACA,YACA,aACA,WACA,UACA,YACA,WACA,UACA,UACA,YAGUD,EAAAA,wBAAAA,yCAEVA,cACAA,iFCgBF,SAASE,EAAYC,GACnB,IAAMC,EAAwB,GAe9B,OAdAC,OAAOC,KAAKH,GAAOI,SAAQ,SAACC,GAEtBP,EAAuBQ,SAASD,KAIlCA,EAAIE,WAAW,MACfT,EAAuBQ,SAASD,EAAIG,QAAQ,MAAO,KAEnDP,EAAiBI,EAAIG,QAAQ,MAAO,KAAOR,EAAMK,GAEjDJ,EAAiBI,GAAOL,EAAMK,OAG3BJ,WAGOQ,SACdC,IAAAA,MAAKC,IACLC,QAAAA,aAAU,eACLC,IAALC,IAMA,OAAO,IAAIC,SACT,SAACC,EAASC,GACR,GACoB,oBAAXC,aACuB,IAAvBA,OAAOC,YAEd,OAAOF,EAAO,CACZG,MAAO,kBACPC,QACE,qEAIN,IAAMP,EACJD,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M,OACNC,SAAU,WACVC,KAAM,OACNC,SAAU,WACVC,MAAO,QACPC,YAAa,cACbC,SAAU,WACVC,MAAO,QACPC,MAAO"}
|
package/dist/base.d.ts
CHANGED
|
@@ -51,6 +51,27 @@ export declare type Context = {
|
|
|
51
51
|
/**
|
|
52
52
|
* The user that is currently logged in
|
|
53
53
|
* Available only to apps that have read User permission
|
|
54
|
+
*
|
|
55
|
+
* Intended to be used to fetch user's permissions and roles
|
|
56
|
+
* from the management API using the user's ID.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```graphql
|
|
60
|
+
* query user_query($id: ID!) {
|
|
61
|
+
* viewer {
|
|
62
|
+
* ... on AppTokenViewer {
|
|
63
|
+
* id
|
|
64
|
+
* user(id: $id) {
|
|
65
|
+
* permissions
|
|
66
|
+
* roles {
|
|
67
|
+
* name
|
|
68
|
+
* isDefault
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
54
75
|
*/
|
|
55
76
|
user?: User;
|
|
56
77
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hygraph/app-sdk",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.0.4
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"author": "Hygraph",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"tslib": "^2.3.0",
|
|
38
38
|
"typescript": "^4.3.5"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "9ab3d452f4e651239e4825ead748263e09abadd5"
|
|
41
41
|
}
|
package/src/base.ts
CHANGED
|
@@ -87,6 +87,27 @@ export type Context = {
|
|
|
87
87
|
/**
|
|
88
88
|
* The user that is currently logged in
|
|
89
89
|
* Available only to apps that have read User permission
|
|
90
|
+
*
|
|
91
|
+
* Intended to be used to fetch user's permissions and roles
|
|
92
|
+
* from the management API using the user's ID.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```graphql
|
|
96
|
+
* query user_query($id: ID!) {
|
|
97
|
+
* viewer {
|
|
98
|
+
* ... on AppTokenViewer {
|
|
99
|
+
* id
|
|
100
|
+
* user(id: $id) {
|
|
101
|
+
* permissions
|
|
102
|
+
* roles {
|
|
103
|
+
* name
|
|
104
|
+
* isDefault
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
90
111
|
*/
|
|
91
112
|
user?: User;
|
|
92
113
|
};
|