diff --git a/.changeset/perfect-coats-cry.md b/.changeset/perfect-coats-cry.md new file mode 100644 index 00000000..f6697f59 --- /dev/null +++ b/.changeset/perfect-coats-cry.md @@ -0,0 +1,5 @@ +--- +'@apollo/explorer': minor +--- + +Add optional config for inviteToken and accountId diff --git a/src/embeddedExplorer/EmbeddedExplorer.ts b/src/embeddedExplorer/EmbeddedExplorer.ts index d88e2a45..bdccf38a 100644 --- a/src/embeddedExplorer/EmbeddedExplorer.ts +++ b/src/embeddedExplorer/EmbeddedExplorer.ts @@ -29,6 +29,13 @@ export interface BaseEmbeddableExplorerOptions { // optional. defaults to `return fetch(url, fetchOptions)` handleRequest?: HandleRequest; + // If this object has values for `inviteToken` and `accountId`, + // any users who can see your embeddable Explorer are automatically + // invited to the account your graph is under with the role specified by the `inviteToken`. + autoInviteOptions?: { + accountId: string; + inviteToken: string; + }; } interface EmbeddableExplorerOptionsWithSchema @@ -70,6 +77,7 @@ export class EmbeddedExplorer { updateSchemaInEmbed: this.updateSchemaInEmbed.bind(this), schema: 'schema' in this.options ? this.options.schema : undefined, graphRef: 'graphRef' in this.options ? this.options.graphRef : undefined, + autoInviteOptions: this.options.autoInviteOptions, }); } diff --git a/src/embeddedExplorer/setupEmbedRelay.ts b/src/embeddedExplorer/setupEmbedRelay.ts index d38456e1..c637b681 100644 --- a/src/embeddedExplorer/setupEmbedRelay.ts +++ b/src/embeddedExplorer/setupEmbedRelay.ts @@ -23,6 +23,7 @@ export function setupEmbedRelay({ updateSchemaInEmbed, schema, graphRef, + autoInviteOptions, }: { endpointUrl: string; handleRequest: HandleRequest; @@ -34,6 +35,10 @@ export function setupEmbedRelay({ }) => void; schema?: string | IntrospectionQuery | undefined; graphRef?: string | undefined; + autoInviteOptions?: { + accountId: string; + inviteToken: string; + }; }) { // Callback definition const onPostMessageReceived = (event: IncomingEmbedMessage) => { @@ -44,6 +49,8 @@ export function setupEmbedRelay({ message: { name: HANDSHAKE_RESPONSE, graphRef, + inviteToken: autoInviteOptions?.inviteToken, + accountId: autoInviteOptions?.accountId, }, embeddedIFrameElement: embeddedExplorerIFrameElement, embedUrl: EMBEDDABLE_EXPLORER_URL, diff --git a/src/helpers/postMessageRelayHelpers.ts b/src/helpers/postMessageRelayHelpers.ts index 3df33403..fbe49bc1 100644 --- a/src/helpers/postMessageRelayHelpers.ts +++ b/src/helpers/postMessageRelayHelpers.ts @@ -60,6 +60,8 @@ export type OutgoingEmbedMessage = | { name: typeof HANDSHAKE_RESPONSE; graphRef?: string; + inviteToken?: string; + accountId?: string; } | { name: typeof PARTIAL_AUTHENTICATION_TOKEN_RESPONSE;