Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions projects/developer/src/lib/api/developerErrorMessage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ const API_ERROR_CODES = [
'github_account_taken',
'github_account_mismatch',
'production_apps_unavailable',
'application_not_dev',
'user_not_found',
'cannot_allow_owner',
'allowed_user_limit_reached',
'owner_only',
'production_review_pending',
'production_application_linked',
'production_review_conflict',
'production_requires_sign_in',
'profile_not_found',
'review_not_found',
'redirect_not_allowed',
];

describe('developerErrorMessage', () => {
Expand Down
15 changes: 12 additions & 3 deletions projects/developer/src/lib/api/developerErrorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,25 @@ const DEVELOPER_ERROR_MESSAGES = {
'This GitHub account is already connected to another Trakt account.',
github_account_mismatch:
'Your Trakt account is connected to a different GitHub account. Use Switch GitHub account to change it.',
dev_redirect_not_local:
'Development apps can only redirect to localhost, 127.0.0.1 or [::1].',
production_apps_unavailable:
'Production apps are currently unavailable. Contact support@trakt.tv if you need one.',
'Create a Development app first, then request Production access from its page.',
application_not_dev: 'Only development apps have a sign-in list.',
user_not_found: 'No Trakt account has that username.',
cannot_allow_owner: 'You own this app, so you can always sign in to it.',
allowed_user_limit_reached:
'This app already has 16 people who can sign in. Remove someone to add another.',
owner_only: 'Only the app owner can do this.',
production_review_pending: 'A review is already waiting for this app.',
production_application_linked:
'Delete the Production app first, then delete this Development app.',
production_review_conflict:
'Another request was just sent for this app. Reload to see it.',
production_requires_sign_in:
'This Production app already supports sign-in. Choose PKCE or device code.',
profile_not_found: 'This app has no app information yet.',
review_not_found: 'This app has no review yet.',
redirect_not_allowed:
'Production redirect URIs must use https:// on a domain you control. Localhost and custom app schemes only work on Development apps.',
} as const;

type DeveloperErrorCode = keyof typeof DEVELOPER_ERROR_MESSAGES;
Expand Down
92 changes: 55 additions & 37 deletions projects/developer/src/lib/features/apps/ApplicationForm.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import type { ApplicationFormProps } from "./ApplicationFormProps.ts";
import { nonLocalRedirectUris } from "./nonLocalRedirectUris.ts";
import { parseApplication } from "./parseApplication.ts";
import RedirectUriWarning from "./RedirectUriWarning.svelte";
import { unsafeRedirectUris } from "./unsafeRedirectUris.ts";
Expand All @@ -22,9 +21,17 @@
let origins = $state(initial?.origins.join("\n") ?? "");
let dev = $state(initial?.dev ?? true);
let error = $state("");
const unsafeRedirects = $derived(dev ? [] : unsafeRedirectUris(redirects));
const nonLocalRedirects = $derived(
dev ? nonLocalRedirectUris(redirects) : [],
const readOnly = initial?.app_type === "production_read_only";
const redirectsOptional =
readOnly || (!!initial && !initial.dev && !initial.redirect_uri.trim());
const enforceProductionRedirects = $derived(
!dev && (!initial || redirects !== initial.redirect_uri),
);
const blockedRedirects = $derived(
enforceProductionRedirects ? unsafeRedirectUris(redirects) : [],
);
const unsafeRedirects = $derived(
dev || enforceProductionRedirects ? [] : unsafeRedirectUris(redirects),
);

function submit(event: SubmitEvent) {
Expand All @@ -36,6 +43,8 @@
redirects,
originsText: origins,
dev,
enforceProductionRedirects,
redirectsOptional,
});
error = "";
onSave(input);
Expand Down Expand Up @@ -80,8 +89,8 @@
/>
<strong class="type-title">Development</strong>
<small class="type-hint"
>Only you and people you add can sign in. Redirect URIs must point
to localhost.</small
>Only you and up to 16 people you add can sign in. Any redirect URI
works for testing.</small
></label
><label
class="type-option"
Expand All @@ -98,40 +107,42 @@
<strong class="type-title">Production</strong>
{#if productionAvailable}<small class="type-hint"
>Anyone with a Trakt account can sign in. Redirect URIs must use
https://.</small
https:// on a domain you control.</small
Comment thread
seferturan marked this conversation as resolved.
Resolved
>{:else}<small class="type-hint"
>Currently unavailable. Contact <a href="mailto:support@trakt.tv"
>support@trakt.tv</a
> if you need a production app.</small
>Start in Development, then request Production access from your
app's page. You'll get a separate Production app.</small
>{/if}</label
>
</fieldset>{/if}
<label
>Redirect URIs <span
>{dev
? "One per line. Development apps accept localhost, 127.0.0.1 or [::1] only."
: "One per line. Use https:// only; on mobile, back it with Universal Links or verified App Links."}</span
><textarea
bind:value={redirects}
required
rows="4"
placeholder={dev
? "http://localhost:5173/callback"
: "https://example.com/callback"}
spellcheck="false"
class:is-invalid={nonLocalRedirects.length > 0}
aria-invalid={nonLocalRedirects.length > 0}
aria-describedby={nonLocalRedirects.length > 0
? "redirect-error"
: undefined}></textarea>{#if nonLocalRedirects.length > 0}<span
class="field-error"
id="redirect-error"
>Development apps can only redirect to localhost. Remove {nonLocalRedirects.join(
", ",
)}.</span
>{/if}</label
>
<RedirectUriWarning uris={unsafeRedirects} />
{#if readOnly}<p class="read-only-redirects">
Read-only Production apps need no redirect URI: nobody signs in to them.
</p>{:else}<label
>Redirect URIs <span
>{dev
? "One per line. Any redirect URI works for testing: localhost, https, or a custom app scheme."
: redirectsOptional
? "Optional for device-code sign-in. Use public https:// URLs if you add any."
: "One per line. https:// on a domain you control. Localhost and custom app schemes only work on Development apps; on mobile, use Universal Links or verified App Links."}</span
><textarea
bind:value={redirects}
required={!redirectsOptional}
rows="4"
placeholder={dev
? "http://localhost:5173/callback"
: "https://example.com/callback"}
spellcheck="false"
class:is-invalid={blockedRedirects.length > 0}
aria-invalid={blockedRedirects.length > 0}
aria-describedby={blockedRedirects.length > 0
? "redirect-error"
: undefined}></textarea>{#if blockedRedirects.length > 0}<span
class="field-error"
id="redirect-error"
>Production redirect URIs must use https:// on a domain you control.
Change {blockedRedirects.join(", ")}.</span
>{/if}</label
>
<RedirectUriWarning uris={unsafeRedirects} />{/if}

<label
>Allowed origins <span
Expand All @@ -154,7 +165,7 @@
<button
class="primary"
type="submit"
disabled={nonLocalRedirects.length > 0}
disabled={blockedRedirects.length > 0}
>{busy ? "Saving…" : app ? "Save changes" : "Create app"}</button
><button type="button" onclick={onCancel}>Cancel</button>
</div>
Expand Down Expand Up @@ -188,6 +199,13 @@
line-height: 1.6;
}

.read-only-redirects {
margin: 0;
color: var(--color-muted);
font-size: 13px;
line-height: 1.6;
}

.creating-as {
margin: 0;
padding: 12px 16px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { z } from 'zod';
import type { applicationProfileSchema } from './applicationProfileSchema.ts';

export type ApplicationProfile = z.infer<typeof applicationProfileSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<script lang="ts">
import type { ApplicationProfileInput } from "./ApplicationProfileInput.ts";
import { formatDate } from "./formatDate.ts";
import { isWebUrl } from "./isWebUrl.ts";
import { profileUsageLabel } from "./profileUsageLabel.ts";

const {
profile,
updated,
}: {
profile: ApplicationProfileInput;
updated?: { at: string; by: string };
} = $props();
</script>

{#snippet links(urls: string[])}
<ul class="links">
{#each urls as url (url)}<li>
{#if isWebUrl(url)}
<a class="link" href={url} target="_blank" rel="noopener noreferrer"
>{url}</a
>
{:else}
{url}
{/if}
</li>{/each}
</ul>
{/snippet}

<dl class="trakt-application-profile-card">
<dt class="term">What it does</dt>
<dd class="detail summary">{profile.summary}</dd>
<dt class="term">Open source</dt>
<dd class="detail">{profile.open_source ? "Yes" : "No"}</dd>
<dt class="term">Links</dt>
<dd class="detail">{@render links(profile.product_links)}</dd>
<dt class="term">Privacy policy</dt>
<dd class="detail">{@render links([profile.privacy_url])}</dd>
<dt class="term">Trakt notice</dt>
<dd class="detail">{@render links(profile.notice_links)}</dd>
<dt class="term">Expected users</dt>
<dd class="detail">{profile.expected_mau.toLocaleString()} a month</dd>
<dt class="term">Uses Trakt for</dt>
<dd class="detail">{profileUsageLabel(profile)}</dd>
<dt class="term">Movie and show data</dt>
<dd class="detail">{profile.other_data_sources ?? "Only Trakt"}</dd>
<dt class="term">Syncs with</dt>
<dd class="detail">{profile.other_sync_services ?? "Only Trakt"}</dd>
{#if updated}<dt class="term">Updated</dt>
<dd class="detail">{formatDate(updated.at)} by @{updated.by}</dd>{/if}
</dl>

<style lang="scss">
.trakt-application-profile-card {
display: grid;
grid-template-columns: max-content minmax(0, 1fr);
gap: var(--gap-s) var(--gap-l);
margin: 0;
font-size: 13px;

.term {
color: var(--color-muted);
font-size: var(--ni-12);
}

.detail {
margin: 0;
overflow-wrap: anywhere;
}

.summary {
white-space: pre-wrap;
line-height: 1.6;
}

.links {
display: grid;
gap: var(--gap-xxs);
margin: 0;
padding: 0;
list-style: none;
}

.link {
color: var(--color-info);
}

@media (max-width: 640px) {
grid-template-columns: 1fr;

.detail {
margin-block-end: var(--gap-s);
}
}
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { ProductionSignIn } from './ProductionSignIn.ts';

export type ApplicationProfileDraft = {
summary: string;
openSource: boolean;
productLinks: string;
privacyUrl: string;
noticeLinks: string;
expectedMau: string;
signIn: ProductionSignIn;
writesUserData: boolean;
usesOtherData: boolean;
otherDataSources: string;
syncsElsewhere: boolean;
otherSyncServices: string;
};
Loading
Loading