@atpassport/client 0.1.5 → 0.1.7
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/README.md +2 -1
- package/dist/index.d.mts +73 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +1 -134
- package/dist/index.mjs +1 -0
- package/package.json +14 -5
package/README.md
CHANGED
|
@@ -25,7 +25,8 @@ import { AtPassport } from '@atpassport/client';
|
|
|
25
25
|
|
|
26
26
|
// 1. Initialize the client
|
|
27
27
|
const passport = new AtPassport({
|
|
28
|
-
callbackUrl: 'https://myapp.com/oauth/login' // Required: the URL to redirect back to
|
|
28
|
+
callbackUrl: 'https://myapp.com/oauth/login', // Required: the URL to redirect back to
|
|
29
|
+
lang: 'en' // Optional: 'en' or 'ja' (defaults to no prefix if omitted)
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
// 2. (Optional) Generate the authentication URL and redirect
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
interface AtPassportOptions {
|
|
2
|
+
callbackUrl: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
lang?: 'en' | 'ja';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Standard UI texts and icons for AtPassport integration components.
|
|
8
|
+
* Useful for building "Login with @passport" buttons and explanation dialogues.
|
|
9
|
+
*/
|
|
10
|
+
declare const AtPassportUI: {
|
|
11
|
+
ja: {
|
|
12
|
+
title: string;
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
en: {
|
|
16
|
+
title: string;
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
iconSvg: string;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the @passport icon SVG string with a custom size.
|
|
22
|
+
*/
|
|
23
|
+
getIconSvg: (size?: number | string) => string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* AtPassport Client
|
|
27
|
+
*/
|
|
28
|
+
declare class AtPassport {
|
|
29
|
+
private readonly baseUrl;
|
|
30
|
+
private readonly callbackUrl;
|
|
31
|
+
private readonly lang?;
|
|
32
|
+
constructor(options: AtPassportOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Generates the URL for handle registration.
|
|
35
|
+
*/
|
|
36
|
+
registerUrl(handle: string, callback: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Generates the URL for identity resolution.
|
|
39
|
+
*/
|
|
40
|
+
resolveUrl(callback: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Generates the authentication URL and state.
|
|
43
|
+
* By saving the state on the app side and verifying it in parseCallback,
|
|
44
|
+
* you can prevent CSRF attacks. Custom parameters will be attached to the callback.
|
|
45
|
+
*/
|
|
46
|
+
generateAuthUrl(customParams?: Record<string, string>): {
|
|
47
|
+
url: string;
|
|
48
|
+
atpstate: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Parses the callback URL returned from AtPassport and extracts parameters.
|
|
52
|
+
* If `expectedState` is provided, it throws an error if the returned state does not match.
|
|
53
|
+
*/
|
|
54
|
+
parseCallback(currentUrl: string, expectedState?: string | null): {
|
|
55
|
+
handle: string | null;
|
|
56
|
+
did: string | null;
|
|
57
|
+
pdsUrl: string | null;
|
|
58
|
+
atpstate: string | null;
|
|
59
|
+
customParams: Record<string, string>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Opens a popup to let user pick a handle.
|
|
63
|
+
* Returns a promise that resolves with the selected handle.
|
|
64
|
+
*/
|
|
65
|
+
pick(): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Attaches the picker to an input element.
|
|
68
|
+
* Automatically fills the input when a handle is picked on focus.
|
|
69
|
+
*/
|
|
70
|
+
decorate(input: HTMLInputElement): void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { AtPassport, type AtPassportOptions, AtPassportUI };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
interface AtPassportOptions {
|
|
2
2
|
callbackUrl: string;
|
|
3
3
|
baseUrl?: string;
|
|
4
|
+
lang?: 'en' | 'ja';
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
7
|
* Standard UI texts and icons for AtPassport integration components.
|
|
7
8
|
* Useful for building "Login with @passport" buttons and explanation dialogues.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
declare const AtPassportUI: {
|
|
10
11
|
ja: {
|
|
11
12
|
title: string;
|
|
12
13
|
description: string;
|
|
@@ -16,13 +17,18 @@ export declare const AtPassportUI: {
|
|
|
16
17
|
description: string;
|
|
17
18
|
};
|
|
18
19
|
iconSvg: string;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the @passport icon SVG string with a custom size.
|
|
22
|
+
*/
|
|
23
|
+
getIconSvg: (size?: number | string) => string;
|
|
19
24
|
};
|
|
20
25
|
/**
|
|
21
26
|
* AtPassport Client
|
|
22
27
|
*/
|
|
23
|
-
|
|
28
|
+
declare class AtPassport {
|
|
24
29
|
private readonly baseUrl;
|
|
25
30
|
private readonly callbackUrl;
|
|
31
|
+
private readonly lang?;
|
|
26
32
|
constructor(options: AtPassportOptions);
|
|
27
33
|
/**
|
|
28
34
|
* Generates the URL for handle registration.
|
|
@@ -63,3 +69,5 @@ export declare class AtPassport {
|
|
|
63
69
|
*/
|
|
64
70
|
decorate(input: HTMLInputElement): void;
|
|
65
71
|
}
|
|
72
|
+
|
|
73
|
+
export { AtPassport, type AtPassportOptions, AtPassportUI };
|
package/dist/index.js
CHANGED
|
@@ -1,134 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AtPassport = exports.AtPassportUI = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Standard UI texts and icons for AtPassport integration components.
|
|
6
|
-
* Useful for building "Login with @passport" buttons and explanation dialogues.
|
|
7
|
-
*/
|
|
8
|
-
exports.AtPassportUI = {
|
|
9
|
-
ja: {
|
|
10
|
-
title: '@passportでログイン',
|
|
11
|
-
description: '@passportは、各atprotoアプリでハンドルを都度入力する手間を省ける共通ハンドルマネージャーです。',
|
|
12
|
-
},
|
|
13
|
-
en: {
|
|
14
|
-
title: 'Login with @passport',
|
|
15
|
-
description: '@passport is a universal handle manager that saves you from typing your handle repeatedly across atproto apps.',
|
|
16
|
-
},
|
|
17
|
-
// Standard icon of @passport
|
|
18
|
-
iconSvg: '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><path d="M0 0 C1.00603271 0.49862549 2.01206543 0.99725098 3.04858398 1.51098633 C9.50354463 4.73352491 15.85776409 8.11600592 22.06640625 11.79296875 C25.22320998 13.17142403 27.27109898 13.31361754 30.6875 12.9375 C33.34692377 11.93078264 33.34692377 11.93078264 35.8125 10.5 C44.39149688 5.80961385 54.93299605 5.65092782 64.4765625 7.46875 C67.30025893 8.44170907 69.47770499 9.75949211 71.75 11.6875 C73.24786697 15.28238073 72.91398387 17.25804838 71.6875 20.9375 C64.45936112 26.17198344 56.15120213 29.72178707 48.125 33.5625 C46.63865234 34.27786029 45.15248876 34.99360317 43.66650391 35.7097168 C40.00468353 37.47292909 36.34028824 39.23070079 32.67462158 40.98590088 C29.85393845 42.33667861 27.03451675 43.69008397 24.21484375 45.04296875 C20.53119481 46.8087824 16.84470945 48.5684786 13.15625 50.32421875 C9.20979647 52.20454542 5.27472121 54.10705419 1.34375 56.01953125 C0.2933252 56.52830811 -0.75709961 57.03708496 -1.83935547 57.5612793 C-3.85101622 58.5360391 -5.86058953 59.51512305 -7.86767578 60.49926758 C-8.7698584 60.9352124 -9.67204102 61.37115723 -10.6015625 61.8203125 C-11.39256348 62.20590332 -12.18356445 62.59149414 -12.99853516 62.98876953 C-18.69655659 65.32497034 -24.93973187 66.1163829 -30.8046875 64.06640625 C-36.77818223 61.29753711 -40.99709022 57.8491842 -45.3125 52.9375 C-45.95574219 52.24914062 -46.59898438 51.56078125 -47.26171875 50.8515625 C-52.60665079 45.01875634 -52.60665079 45.01875634 -53.3125 40.9375 C-52.02153219 40.12389005 -50.72970125 39.31164954 -49.4375 38.5 C-48.71820313 38.04753906 -47.99890625 37.59507813 -47.2578125 37.12890625 C-43.69384751 34.94615661 -41.53339247 34.60454125 -37.3125 34.9375 C-34.4174913 36.34027809 -31.80933835 38.00200329 -29.09375 39.72265625 C-25.47208494 41.30459141 -24.09817419 41.09398281 -20.3125 39.9375 C-16.93903332 38.39431066 -13.6905649 36.65585707 -10.4375 34.875 C-9.11878906 34.16633789 -9.11878906 34.16633789 -7.7734375 33.44335938 C-5.61554476 32.28231926 -3.46222292 31.11357732 -1.3125 29.9375 C-3.633586 26.93434048 -5.90316611 24.24970514 -8.8125 21.8125 C-12.97631948 18.25801995 -17.00199328 14.57130664 -21.01171875 10.84521484 C-24.01392816 8.07156459 -27.09072195 5.45248945 -30.3125 2.9375 C-30.3125 0.625 -30.3125 0.625 -29.3125 -2.0625 C-18.83736309 -7.58575401 -10.05422044 -5.19348714 0 0 Z" fill="currentColor" transform="translate(54.3125,21.0625)"/><path d="M0 0 C1.04328461 -0.00281982 2.08656921 -0.00563965 3.16146851 -0.00854492 C4.31579376 -0.00652069 5.47011902 -0.00449646 6.65942383 -0.00241089 C7.86740631 -0.00416321 9.07538879 -0.00591553 10.31997681 -0.00772095 C13.64221462 -0.01137913 16.96439051 -0.01050604 20.28662491 -0.00734186 C23.75618831 -0.00481787 27.22574899 -0.00715591 30.6953125 -0.00872803 C36.5228727 -0.01054961 42.35042024 -0.00814371 48.17797852 -0.00338745 C54.924568 0.00205515 61.67112727 0.00029249 68.41771603 -0.00521386 C74.20029682 -0.00974531 79.98286849 -0.01039538 85.76545048 -0.00777519 C89.22347064 -0.00621259 92.68147659 -0.00601817 96.13949585 -0.00931168 C99.99250471 -0.01272475 103.84547947 -0.00800012 107.69848633 -0.00241089 C109.42997421 -0.00544724 109.42997421 -0.00544724 111.19644165 -0.00854492 C112.76136856 -0.00431519 112.76136856 -0.00431519 114.35791016 0 C115.27010818 0.00037703 116.18230621 0.00075405 117.12214661 0.0011425 C119.17895508 0.12698364 119.17895508 0.12698364 120.17895508 1.12698364 C120.27769324 3.12497936 120.30867307 5.12655523 120.30395508 7.12698364 C120.30782227 8.76667114 120.30782227 8.76667114 120.31176758 10.43948364 C120.17895508 13.12698364 120.17895508 13.12698364 119.17895508 14.12698364 C117.57438317 14.22515572 115.96548234 14.25330285 114.35791016 14.25396729 C113.31462555 14.25678711 112.27134094 14.25960693 111.19644165 14.26251221 C110.04211639 14.26048798 108.88779114 14.25846375 107.69848633 14.25637817 C106.49050385 14.25813049 105.28252136 14.25988281 104.03793335 14.26168823 C100.71569554 14.26534642 97.39351965 14.26447332 94.07128525 14.26130915 C90.60172184 14.25878516 87.13216116 14.26112319 83.66259766 14.26269531 C77.83503746 14.2645169 72.00748992 14.262111 66.17993164 14.25735474 C59.43334215 14.25191213 52.68678288 14.2536748 45.94019413 14.25918114 C40.15761334 14.26371259 34.37504167 14.26436266 28.59245968 14.26174247 C25.13443951 14.26017987 21.67643357 14.25998546 18.21841431 14.26327896 C14.36540544 14.26669203 10.51243068 14.26196741 6.65942383 14.25637817 C4.92793594 14.25941452 4.92793594 14.25941452 3.16146851 14.26251221 C1.5965416 14.25828247 1.5965416 14.25828247 0 14.25396729 C-0.91219803 14.25359026 -1.82439606 14.25321323 -2.76423645 14.25282478 C-4.82104492 14.12698364 -4.82104492 14.12698364 -5.82104492 13.12698364 C-5.91978308 11.12898793 -5.95076291 9.12741206 -5.94604492 7.12698364 C-5.94862305 6.03385864 -5.95120117 4.94073364 -5.95385742 3.81448364 C-5.73044919 -0.70624765 -4.06710478 0.001681 0 0 Z" fill="currentColor" transform="translate(6.821044921875,97.87301635742188)"/></svg>',
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* AtPassport Client
|
|
22
|
-
*/
|
|
23
|
-
class AtPassport {
|
|
24
|
-
baseUrl;
|
|
25
|
-
callbackUrl;
|
|
26
|
-
constructor(options) {
|
|
27
|
-
this.baseUrl = (options.baseUrl || "https://atpassport.net").replace(/\/$/, "");
|
|
28
|
-
this.callbackUrl = options.callbackUrl;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Generates the URL for handle registration.
|
|
32
|
-
*/
|
|
33
|
-
registerUrl(handle, callback) {
|
|
34
|
-
const url = new URL(`${this.baseUrl}/api/register`);
|
|
35
|
-
url.searchParams.set("handle", handle);
|
|
36
|
-
url.searchParams.set("callbackUrl", callback);
|
|
37
|
-
return url.toString();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Generates the URL for identity resolution.
|
|
41
|
-
*/
|
|
42
|
-
resolveUrl(callback) {
|
|
43
|
-
const url = new URL(`${this.baseUrl}/api/resolve`);
|
|
44
|
-
url.searchParams.set("callbackUrl", callback);
|
|
45
|
-
return url.toString();
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Generates the authentication URL and state.
|
|
49
|
-
* By saving the state on the app side and verifying it in parseCallback,
|
|
50
|
-
* you can prevent CSRF attacks. Custom parameters will be attached to the callback.
|
|
51
|
-
*/
|
|
52
|
-
generateAuthUrl(customParams) {
|
|
53
|
-
const atpstate = crypto.randomUUID(); // Requires browser context or Node.js 19+
|
|
54
|
-
const url = new URL(`${this.baseUrl}/authentication`);
|
|
55
|
-
const callback = new URL(this.callbackUrl);
|
|
56
|
-
if (customParams) {
|
|
57
|
-
for (const [key, value] of Object.entries(customParams)) {
|
|
58
|
-
callback.searchParams.set(key, value);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
url.searchParams.set("callback", callback.toString());
|
|
62
|
-
url.searchParams.set("atpstate", atpstate);
|
|
63
|
-
return { url: url.toString(), atpstate };
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Parses the callback URL returned from AtPassport and extracts parameters.
|
|
67
|
-
* If `expectedState` is provided, it throws an error if the returned state does not match.
|
|
68
|
-
*/
|
|
69
|
-
parseCallback(currentUrl, expectedState) {
|
|
70
|
-
const url = new URL(currentUrl);
|
|
71
|
-
const handle = url.searchParams.get("handle");
|
|
72
|
-
const did = url.searchParams.get("did");
|
|
73
|
-
const pdsUrl = url.searchParams.get("pdsurl");
|
|
74
|
-
const atpstate = url.searchParams.get("atpstate");
|
|
75
|
-
if (expectedState && atpstate !== expectedState) {
|
|
76
|
-
throw new Error("Invalid atpstate: CSRF validation failed.");
|
|
77
|
-
}
|
|
78
|
-
const customParams = {};
|
|
79
|
-
url.searchParams.forEach((value, key) => {
|
|
80
|
-
if (!["handle", "did", "pdsurl", "atpstate"].includes(key)) {
|
|
81
|
-
customParams[key] = value;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return { handle, did, pdsUrl, atpstate, customParams };
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Opens a popup to let user pick a handle.
|
|
88
|
-
* Returns a promise that resolves with the selected handle.
|
|
89
|
-
*/
|
|
90
|
-
async pick() {
|
|
91
|
-
return new Promise((resolve) => {
|
|
92
|
-
const width = 400;
|
|
93
|
-
const height = 500;
|
|
94
|
-
const left = window.screenX + (window.outerWidth - width) / 2;
|
|
95
|
-
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
96
|
-
const pickerUrl = `${this.baseUrl}/picker`;
|
|
97
|
-
const popup = window.open(pickerUrl, 'atpassport:picker', `width=${width},height=${height},left=${left},top=${top}`);
|
|
98
|
-
const handler = (event) => {
|
|
99
|
-
if (event.origin !== new URL(this.baseUrl).origin)
|
|
100
|
-
return;
|
|
101
|
-
if (event.data?.type === 'atpassport:pick') {
|
|
102
|
-
window.removeEventListener('message', handler);
|
|
103
|
-
resolve(event.data.handle);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
window.addEventListener('message', handler);
|
|
107
|
-
// Optional: Check if popup is closed without picking
|
|
108
|
-
const checkClosed = setInterval(() => {
|
|
109
|
-
if (popup?.closed) {
|
|
110
|
-
clearInterval(checkClosed);
|
|
111
|
-
// resolve empty if closed?
|
|
112
|
-
}
|
|
113
|
-
}, 1000);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Attaches the picker to an input element.
|
|
118
|
-
* Automatically fills the input when a handle is picked on focus.
|
|
119
|
-
*/
|
|
120
|
-
decorate(input) {
|
|
121
|
-
input.addEventListener('focus', async () => {
|
|
122
|
-
if (input.value)
|
|
123
|
-
return; // Don't interrupt if already filled
|
|
124
|
-
const handle = await this.pick();
|
|
125
|
-
if (handle) {
|
|
126
|
-
input.value = handle;
|
|
127
|
-
// Trigger change events
|
|
128
|
-
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
129
|
-
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.AtPassport = AtPassport;
|
|
1
|
+
"use strict";var g=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var r in t)g(e,r,{get:t[r],enumerable:!0})},U=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of u(t))!w.call(e,a)&&a!==r&&g(e,a,{get:()=>t[a],enumerable:!(s=d(t,a))||s.enumerable});return e};var m=e=>U(g({},"__esModule",{value:!0}),e);var f={};v(f,{AtPassport:()=>p,AtPassportUI:()=>b});module.exports=m(f);var b={ja:{title:"@passport\u3067\u30ED\u30B0\u30A4\u30F3",description:"@passport\u306F\u3001\u5404atproto\u30A2\u30D7\u30EA\u3067\u30CF\u30F3\u30C9\u30EB\u3092\u90FD\u5EA6\u5165\u529B\u3059\u308B\u624B\u9593\u304C\u7701\u3051\u308B\u5171\u901A\u30CF\u30F3\u30C9\u30EB\u30DE\u30CD\u30FC\u30B8\u30E3\u30FC\u3067\u3059\u3002"},en:{title:"Login with @passport",description:"@passport is a universal handle manager that saves you from typing your handle repeatedly across atproto apps."},iconSvg:'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><path d="M0 0 C1 0.5 2 1 3 1.5 C9.5 4.7 15.9 8.1 22.1 11.8 C25.2 13.2 27.3 13.3 30.7 12.9 C33.3 11.9 33.3 11.9 35.8 10.5 C44.4 5.8 54.9 5.7 64.5 7.5 C67.3 8.4 69.5 9.8 71.8 11.7 C73.2 15.3 72.9 17.3 71.7 20.9 C64.5 26.2 56.2 29.7 48.1 33.6 C46.6 34.3 45.2 35 43.7 35.7 C40 37.5 36.3 39.2 32.7 41 C29.9 42.3 27 43.7 24.2 45 C20.5 46.8 16.8 48.6 13.2 50.3 C9.2 52.2 5.3 54.1 1.3 56 C0.3 56.5 -0.8 57 -1.8 57.6 C-3.9 58.5 -5.9 59.5 -7.9 60.5 C-8.8 60.9 -9.7 61.4 -10.6 61.8 C-11.4 62.2 -12.2 62.6 -13 63 C-18.7 65.3 -24.9 66.1 -30.8 64.1 C-36.8 61.3 -41 57.8 -45.3 52.9 C-46 52.2 -46.6 51.6 -47.3 50.9 C-52.6 45 -52.6 45 -53.3 40.9 C-52 40.1 -50.7 39.3 -49.4 38.5 C-48.7 38 -48 37.6 -47.3 37.1 C-43.7 34.9 -41.5 34.6 -37.3 34.9 C-34.4 36.3 -31.8 38 -29.1 39.7 C-25.5 41.3 -24.1 41.1 -20.3 39.9 C-16.9 38.4 -13.7 36.7 -10.4 34.9 C-9.1 34.2 -9.1 34.2 -7.8 33.4 C-5.6 32.3 -3.5 31.1 -1.3 29.9 C-3.6 26.9 -5.9 24.2 -8.8 21.8 C-13 18.3 -17 14.6 -21 10.8 C-24 8.1 -27.1 5.5 -30.3 2.9 C-30.3 0.6 -30.3 0.6 -29.3 -2.1 C-18.8 -7.6 -10.1 -5.2 0 0 Z" fill="currentColor" transform="translate(54.3,21.1)"/><path d="M0 0 C1 -0 2.1 -0 3.2 -0 C4.3 -0 5.5 -0 6.7 -0 C7.9 -0 9.1 -0 10.3 -0 C13.6 -0 17 -0 20.3 -0 C23.8 -0 27.2 -0 30.7 -0 C36.5 -0 42.4 -0 48.2 -0 C54.9 0 61.7 0 68.4 -0 C74.2 -0 80 -0 85.8 -0 C89.2 -0 92.7 -0 96.1 -0 C100 -0 103.8 -0 107.7 -0 C109.4 -0 109.4 -0 111.2 -0 C112.8 -0 112.8 -0 114.4 0 C115.3 0 116.2 0 117.1 0 C119.2 0.1 119.2 0.1 120.2 1.1 C120.3 3.1 120.3 5.1 120.3 7.1 C120.3 8.8 120.3 8.8 120.3 10.4 C120.2 13.1 120.2 13.1 119.2 14.1 C117.6 14.2 116 14.3 114.4 14.3 C113.3 14.3 112.3 14.3 111.2 14.3 C110 14.3 108.9 14.3 107.7 14.3 C106.5 14.3 105.3 14.3 104 14.3 C100.7 14.3 97.4 14.3 94.1 14.3 C90.6 14.3 87.1 14.3 83.7 14.3 C77.8 14.3 72 14.3 66.2 14.3 C59.4 14.3 52.7 14.3 45.9 14.3 C40.2 14.3 34.4 14.3 28.6 14.3 C25.1 14.3 21.7 14.3 18.2 14.3 C14.4 14.3 10.5 14.3 6.7 14.3 C4.9 14.3 4.9 14.3 3.2 14.3 C1.6 14.3 1.6 14.3 0 14.3 C-0.9 14.3 -1.8 14.3 -2.8 14.3 C-4.8 14.1 -4.8 14.1 -5.8 13.1 C-5.9 11.1 -6 9.1 -5.9 7.1 C-5.9 6 -6 4.9 -6 3.8 C-5.7 -0.7 -4.1 0 0 0 Z" fill="currentColor" transform="translate(6.8,97.9)"/></svg>',getIconSvg:(e=128)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="${e}" height="${e}" viewBox="0 0 128 128"><path d="M0 0 C1 0.5 2 1 3 1.5 C9.5 4.7 15.9 8.1 22.1 11.8 C25.2 13.2 27.3 13.3 30.7 12.9 C33.3 11.9 33.3 11.9 35.8 10.5 C44.4 5.8 54.9 5.7 64.5 7.5 C67.3 8.4 69.5 9.8 71.8 11.7 C73.2 15.3 72.9 17.3 71.7 20.9 C64.5 26.2 56.2 29.7 48.1 33.6 C46.6 34.3 45.2 35 43.7 35.7 C40 37.5 36.3 39.2 32.7 41 C29.9 42.3 27 43.7 24.2 45 C20.5 46.8 16.8 48.6 13.2 50.3 C9.2 52.2 5.3 54.1 1.3 56 C0.3 56.5 -0.8 57 -1.8 57.6 C-3.9 58.5 -5.9 59.5 -7.9 60.5 C-8.8 60.9 -9.7 61.4 -10.6 61.8 C-11.4 62.2 -12.2 62.6 -13 63 C-18.7 65.3 -24.9 66.1 -30.8 64.1 C-36.8 61.3 -41 57.8 -45.3 52.9 C-46 52.2 -46.6 51.6 -47.3 50.9 C-52.6 45 -52.6 45 -53.3 40.9 C-52 40.1 -50.7 39.3 -49.4 38.5 C-48.7 38 -48 37.6 -47.3 37.1 C-43.7 34.9 -41.5 34.6 -37.3 34.9 C-34.4 36.3 -31.8 38 -29.1 39.7 C-25.5 41.3 -24.1 41.1 -20.3 39.9 C-16.9 38.4 -13.7 36.7 -10.4 34.9 C-9.1 34.2 -9.1 34.2 -7.8 33.4 C-5.6 32.3 -3.5 31.1 -1.3 29.9 C-3.6 26.9 -5.9 24.2 -8.8 21.8 C-13 18.3 -17 14.6 -21 10.8 C-24 8.1 -27.1 5.5 -30.3 2.9 C-30.3 0.6 -30.3 0.6 -29.3 -2.1 C-18.8 -7.6 -10.1 -5.2 0 0 Z" fill="currentColor" transform="translate(54.3,21.1)"/><path d="M0 0 C1 -0 2.1 -0 3.2 -0 C4.3 -0 5.5 -0 6.7 -0 C7.9 -0 9.1 -0 10.3 -0 C13.6 -0 17 -0 20.3 -0 C23.8 -0 27.2 -0 30.7 -0 C36.5 -0 42.4 -0 48.2 -0 C54.9 0 61.7 0 68.4 -0 C74.2 -0 80 -0 85.8 -0 C89.2 -0 92.7 -0 96.1 -0 C100 -0 103.8 -0 107.7 -0 C109.4 -0 109.4 -0 111.2 -0 C112.8 -0 112.8 -0 114.4 0 C115.3 0 116.2 0 117.1 0 C119.2 0.1 119.2 0.1 120.2 1.1 C120.3 3.1 120.3 5.1 120.3 7.1 C120.3 8.8 120.3 8.8 120.3 10.4 C120.2 13.1 120.2 13.1 119.2 14.1 C117.6 14.2 116 14.3 114.4 14.3 C113.3 14.3 112.3 14.3 111.2 14.3 C110 14.3 108.9 14.3 107.7 14.3 C106.5 14.3 105.3 14.3 104 14.3 C100.7 14.3 97.4 14.3 94.1 14.3 C90.6 14.3 87.1 14.3 83.7 14.3 C77.8 14.3 72 14.3 66.2 14.3 C59.4 14.3 52.7 14.3 45.9 14.3 C40.2 14.3 34.4 14.3 28.6 14.3 C25.1 14.3 21.7 14.3 18.2 14.3 C14.4 14.3 10.5 14.3 6.7 14.3 C4.9 14.3 4.9 14.3 3.2 14.3 C1.6 14.3 1.6 14.3 0 14.3 C-0.9 14.3 -1.8 14.3 -2.8 14.3 C-4.8 14.1 -4.8 14.1 -5.8 13.1 C-5.9 11.1 -6 9.1 -5.9 7.1 C-5.9 6 -6 4.9 -6 3.8 C-5.7 -0.7 -4.1 0 0 0 Z" fill="currentColor" transform="translate(6.8,97.9)"/></svg>`},p=class{baseUrl;callbackUrl;lang;constructor(t){this.baseUrl=(t.baseUrl||"https://atpassport.net").replace(/\/$/,""),this.callbackUrl=t.callbackUrl,this.lang=t.lang}registerUrl(t,r){let s=new URL(`${this.baseUrl}/api/register`);return s.searchParams.set("handle",t),s.searchParams.set("callbackUrl",r),s.toString()}resolveUrl(t){let r=new URL(`${this.baseUrl}/api/resolve`);return r.searchParams.set("callbackUrl",t),r.toString()}generateAuthUrl(t){let r=crypto.randomUUID(),s=this.lang?`${this.lang}/authentication`:"authentication",a=new URL(`${this.baseUrl}/${s}`),n=new URL(this.callbackUrl);if(t)for(let[i,C]of Object.entries(t))n.searchParams.set(i,C);return a.searchParams.set("callback",n.toString()),a.searchParams.set("atpstate",r),{url:a.toString(),atpstate:r}}parseCallback(t,r){let s=new URL(t),a=s.searchParams.get("handle"),n=s.searchParams.get("did"),i=s.searchParams.get("pdsurl"),C=s.searchParams.get("atpstate");if(r&&C!==r)throw new Error("Invalid atpstate: CSRF validation failed.");let l={};return s.searchParams.forEach((o,c)=>{["handle","did","pdsurl","atpstate"].includes(c)||(l[c]=o)}),{handle:a,did:n,pdsUrl:i,atpstate:C,customParams:l}}async pick(){return new Promise(t=>{let a=window.screenX+(window.outerWidth-400)/2,n=window.screenY+(window.outerHeight-500)/2,i=this.lang?`${this.lang}/picker`:"picker",C=`${this.baseUrl}/${i}`,l=window.open(C,"atpassport:picker",`width=400,height=500,left=${a},top=${n}`),o=h=>{h.origin===new URL(this.baseUrl).origin&&h.data?.type==="atpassport:pick"&&(window.removeEventListener("message",o),t(h.data.handle))};window.addEventListener("message",o);let c=setInterval(()=>{l?.closed&&clearInterval(c)},1e3)})}decorate(t){t.addEventListener("focus",async()=>{if(t.value)return;let r=await this.pick();r&&(t.value=r,t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})))})}};0&&(module.exports={AtPassport,AtPassportUI});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var p={ja:{title:"@passport\u3067\u30ED\u30B0\u30A4\u30F3",description:"@passport\u306F\u3001\u5404atproto\u30A2\u30D7\u30EA\u3067\u30CF\u30F3\u30C9\u30EB\u3092\u90FD\u5EA6\u5165\u529B\u3059\u308B\u624B\u9593\u304C\u7701\u3051\u308B\u5171\u901A\u30CF\u30F3\u30C9\u30EB\u30DE\u30CD\u30FC\u30B8\u30E3\u30FC\u3067\u3059\u3002"},en:{title:"Login with @passport",description:"@passport is a universal handle manager that saves you from typing your handle repeatedly across atproto apps."},iconSvg:'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><path d="M0 0 C1 0.5 2 1 3 1.5 C9.5 4.7 15.9 8.1 22.1 11.8 C25.2 13.2 27.3 13.3 30.7 12.9 C33.3 11.9 33.3 11.9 35.8 10.5 C44.4 5.8 54.9 5.7 64.5 7.5 C67.3 8.4 69.5 9.8 71.8 11.7 C73.2 15.3 72.9 17.3 71.7 20.9 C64.5 26.2 56.2 29.7 48.1 33.6 C46.6 34.3 45.2 35 43.7 35.7 C40 37.5 36.3 39.2 32.7 41 C29.9 42.3 27 43.7 24.2 45 C20.5 46.8 16.8 48.6 13.2 50.3 C9.2 52.2 5.3 54.1 1.3 56 C0.3 56.5 -0.8 57 -1.8 57.6 C-3.9 58.5 -5.9 59.5 -7.9 60.5 C-8.8 60.9 -9.7 61.4 -10.6 61.8 C-11.4 62.2 -12.2 62.6 -13 63 C-18.7 65.3 -24.9 66.1 -30.8 64.1 C-36.8 61.3 -41 57.8 -45.3 52.9 C-46 52.2 -46.6 51.6 -47.3 50.9 C-52.6 45 -52.6 45 -53.3 40.9 C-52 40.1 -50.7 39.3 -49.4 38.5 C-48.7 38 -48 37.6 -47.3 37.1 C-43.7 34.9 -41.5 34.6 -37.3 34.9 C-34.4 36.3 -31.8 38 -29.1 39.7 C-25.5 41.3 -24.1 41.1 -20.3 39.9 C-16.9 38.4 -13.7 36.7 -10.4 34.9 C-9.1 34.2 -9.1 34.2 -7.8 33.4 C-5.6 32.3 -3.5 31.1 -1.3 29.9 C-3.6 26.9 -5.9 24.2 -8.8 21.8 C-13 18.3 -17 14.6 -21 10.8 C-24 8.1 -27.1 5.5 -30.3 2.9 C-30.3 0.6 -30.3 0.6 -29.3 -2.1 C-18.8 -7.6 -10.1 -5.2 0 0 Z" fill="currentColor" transform="translate(54.3,21.1)"/><path d="M0 0 C1 -0 2.1 -0 3.2 -0 C4.3 -0 5.5 -0 6.7 -0 C7.9 -0 9.1 -0 10.3 -0 C13.6 -0 17 -0 20.3 -0 C23.8 -0 27.2 -0 30.7 -0 C36.5 -0 42.4 -0 48.2 -0 C54.9 0 61.7 0 68.4 -0 C74.2 -0 80 -0 85.8 -0 C89.2 -0 92.7 -0 96.1 -0 C100 -0 103.8 -0 107.7 -0 C109.4 -0 109.4 -0 111.2 -0 C112.8 -0 112.8 -0 114.4 0 C115.3 0 116.2 0 117.1 0 C119.2 0.1 119.2 0.1 120.2 1.1 C120.3 3.1 120.3 5.1 120.3 7.1 C120.3 8.8 120.3 8.8 120.3 10.4 C120.2 13.1 120.2 13.1 119.2 14.1 C117.6 14.2 116 14.3 114.4 14.3 C113.3 14.3 112.3 14.3 111.2 14.3 C110 14.3 108.9 14.3 107.7 14.3 C106.5 14.3 105.3 14.3 104 14.3 C100.7 14.3 97.4 14.3 94.1 14.3 C90.6 14.3 87.1 14.3 83.7 14.3 C77.8 14.3 72 14.3 66.2 14.3 C59.4 14.3 52.7 14.3 45.9 14.3 C40.2 14.3 34.4 14.3 28.6 14.3 C25.1 14.3 21.7 14.3 18.2 14.3 C14.4 14.3 10.5 14.3 6.7 14.3 C4.9 14.3 4.9 14.3 3.2 14.3 C1.6 14.3 1.6 14.3 0 14.3 C-0.9 14.3 -1.8 14.3 -2.8 14.3 C-4.8 14.1 -4.8 14.1 -5.8 13.1 C-5.9 11.1 -6 9.1 -5.9 7.1 C-5.9 6 -6 4.9 -6 3.8 C-5.7 -0.7 -4.1 0 0 0 Z" fill="currentColor" transform="translate(6.8,97.9)"/></svg>',getIconSvg:(c=128)=>`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="${c}" height="${c}" viewBox="0 0 128 128"><path d="M0 0 C1 0.5 2 1 3 1.5 C9.5 4.7 15.9 8.1 22.1 11.8 C25.2 13.2 27.3 13.3 30.7 12.9 C33.3 11.9 33.3 11.9 35.8 10.5 C44.4 5.8 54.9 5.7 64.5 7.5 C67.3 8.4 69.5 9.8 71.8 11.7 C73.2 15.3 72.9 17.3 71.7 20.9 C64.5 26.2 56.2 29.7 48.1 33.6 C46.6 34.3 45.2 35 43.7 35.7 C40 37.5 36.3 39.2 32.7 41 C29.9 42.3 27 43.7 24.2 45 C20.5 46.8 16.8 48.6 13.2 50.3 C9.2 52.2 5.3 54.1 1.3 56 C0.3 56.5 -0.8 57 -1.8 57.6 C-3.9 58.5 -5.9 59.5 -7.9 60.5 C-8.8 60.9 -9.7 61.4 -10.6 61.8 C-11.4 62.2 -12.2 62.6 -13 63 C-18.7 65.3 -24.9 66.1 -30.8 64.1 C-36.8 61.3 -41 57.8 -45.3 52.9 C-46 52.2 -46.6 51.6 -47.3 50.9 C-52.6 45 -52.6 45 -53.3 40.9 C-52 40.1 -50.7 39.3 -49.4 38.5 C-48.7 38 -48 37.6 -47.3 37.1 C-43.7 34.9 -41.5 34.6 -37.3 34.9 C-34.4 36.3 -31.8 38 -29.1 39.7 C-25.5 41.3 -24.1 41.1 -20.3 39.9 C-16.9 38.4 -13.7 36.7 -10.4 34.9 C-9.1 34.2 -9.1 34.2 -7.8 33.4 C-5.6 32.3 -3.5 31.1 -1.3 29.9 C-3.6 26.9 -5.9 24.2 -8.8 21.8 C-13 18.3 -17 14.6 -21 10.8 C-24 8.1 -27.1 5.5 -30.3 2.9 C-30.3 0.6 -30.3 0.6 -29.3 -2.1 C-18.8 -7.6 -10.1 -5.2 0 0 Z" fill="currentColor" transform="translate(54.3,21.1)"/><path d="M0 0 C1 -0 2.1 -0 3.2 -0 C4.3 -0 5.5 -0 6.7 -0 C7.9 -0 9.1 -0 10.3 -0 C13.6 -0 17 -0 20.3 -0 C23.8 -0 27.2 -0 30.7 -0 C36.5 -0 42.4 -0 48.2 -0 C54.9 0 61.7 0 68.4 -0 C74.2 -0 80 -0 85.8 -0 C89.2 -0 92.7 -0 96.1 -0 C100 -0 103.8 -0 107.7 -0 C109.4 -0 109.4 -0 111.2 -0 C112.8 -0 112.8 -0 114.4 0 C115.3 0 116.2 0 117.1 0 C119.2 0.1 119.2 0.1 120.2 1.1 C120.3 3.1 120.3 5.1 120.3 7.1 C120.3 8.8 120.3 8.8 120.3 10.4 C120.2 13.1 120.2 13.1 119.2 14.1 C117.6 14.2 116 14.3 114.4 14.3 C113.3 14.3 112.3 14.3 111.2 14.3 C110 14.3 108.9 14.3 107.7 14.3 C106.5 14.3 105.3 14.3 104 14.3 C100.7 14.3 97.4 14.3 94.1 14.3 C90.6 14.3 87.1 14.3 83.7 14.3 C77.8 14.3 72 14.3 66.2 14.3 C59.4 14.3 52.7 14.3 45.9 14.3 C40.2 14.3 34.4 14.3 28.6 14.3 C25.1 14.3 21.7 14.3 18.2 14.3 C14.4 14.3 10.5 14.3 6.7 14.3 C4.9 14.3 4.9 14.3 3.2 14.3 C1.6 14.3 1.6 14.3 0 14.3 C-0.9 14.3 -1.8 14.3 -2.8 14.3 C-4.8 14.1 -4.8 14.1 -5.8 13.1 C-5.9 11.1 -6 9.1 -5.9 7.1 C-5.9 6 -6 4.9 -6 3.8 C-5.7 -0.7 -4.1 0 0 0 Z" fill="currentColor" transform="translate(6.8,97.9)"/></svg>`},g=class{baseUrl;callbackUrl;lang;constructor(t){this.baseUrl=(t.baseUrl||"https://atpassport.net").replace(/\/$/,""),this.callbackUrl=t.callbackUrl,this.lang=t.lang}registerUrl(t,r){let s=new URL(`${this.baseUrl}/api/register`);return s.searchParams.set("handle",t),s.searchParams.set("callbackUrl",r),s.toString()}resolveUrl(t){let r=new URL(`${this.baseUrl}/api/resolve`);return r.searchParams.set("callbackUrl",t),r.toString()}generateAuthUrl(t){let r=crypto.randomUUID(),s=this.lang?`${this.lang}/authentication`:"authentication",a=new URL(`${this.baseUrl}/${s}`),e=new URL(this.callbackUrl);if(t)for(let[C,n]of Object.entries(t))e.searchParams.set(C,n);return a.searchParams.set("callback",e.toString()),a.searchParams.set("atpstate",r),{url:a.toString(),atpstate:r}}parseCallback(t,r){let s=new URL(t),a=s.searchParams.get("handle"),e=s.searchParams.get("did"),C=s.searchParams.get("pdsurl"),n=s.searchParams.get("atpstate");if(r&&n!==r)throw new Error("Invalid atpstate: CSRF validation failed.");let i={};return s.searchParams.forEach((l,o)=>{["handle","did","pdsurl","atpstate"].includes(o)||(i[o]=l)}),{handle:a,did:e,pdsUrl:C,atpstate:n,customParams:i}}async pick(){return new Promise(t=>{let a=window.screenX+(window.outerWidth-400)/2,e=window.screenY+(window.outerHeight-500)/2,C=this.lang?`${this.lang}/picker`:"picker",n=`${this.baseUrl}/${C}`,i=window.open(n,"atpassport:picker",`width=400,height=500,left=${a},top=${e}`),l=h=>{h.origin===new URL(this.baseUrl).origin&&h.data?.type==="atpassport:pick"&&(window.removeEventListener("message",l),t(h.data.handle))};window.addEventListener("message",l);let o=setInterval(()=>{i?.closed&&clearInterval(o)},1e3)})}decorate(t){t.addEventListener("focus",async()=>{if(t.value)return;let r=await this.pick();r&&(t.value=r,t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})))})}};export{g as AtPassport,p as AtPassportUI};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atpassport/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "AtPassport client library for integrating secure handle input assist into applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atproto",
|
|
@@ -9,8 +9,16 @@
|
|
|
9
9
|
],
|
|
10
10
|
"author": "usounds.work",
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"main": "dist/index.js",
|
|
13
|
-
"
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"require": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
14
22
|
"files": [
|
|
15
23
|
"dist",
|
|
16
24
|
"README.md"
|
|
@@ -19,12 +27,13 @@
|
|
|
19
27
|
"access": "public"
|
|
20
28
|
},
|
|
21
29
|
"scripts": {
|
|
22
|
-
"build": "
|
|
23
|
-
"deploy": "npm publish --access public",
|
|
30
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --minify",
|
|
31
|
+
"deploy": "pnpm build && npm publish --access public",
|
|
24
32
|
"test": "vitest run"
|
|
25
33
|
},
|
|
26
34
|
"devDependencies": {
|
|
27
35
|
"@types/node": "^25.5.0",
|
|
36
|
+
"tsup": "^8.5.1",
|
|
28
37
|
"typescript": "^5.0.0",
|
|
29
38
|
"vitest": "^2.0.0"
|
|
30
39
|
}
|