@sneekin/ui 0.4.1 → 1.0.0

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 CHANGED
@@ -18,12 +18,12 @@ React 17 or newer, as a peer dependency.
18
18
  ## Use it
19
19
 
20
20
  ```tsx
21
- import { SneekOtpLogin, createFetchHandlers } from '@sneekin/ui';
21
+ import { SneekLogin, createFetchHandlers } from '@sneekin/ui';
22
22
 
23
23
  export function Login() {
24
24
  return (
25
- <SneekOtpLogin
26
- {...createFetchHandlers({ baseUrl: '/api/auth' })}
25
+ <SneekLogin
26
+ {...createFetchHandlers()}
27
27
  onSuccess={(session) => router.push('/app')}
28
28
  />
29
29
  );
@@ -34,23 +34,41 @@ export function Login() {
34
34
 
35
35
  | Route | Body | Returns |
36
36
  | --- | --- | --- |
37
- | `POST {baseUrl}/request-otp` | `{ identifier }` | `{ requestId, channels, expiresInSeconds }` |
38
- | `POST {baseUrl}/verify-otp` | `{ requestId, code }` | whatever your session payload is |
37
+ | `POST /api/auth/request` | `{ identifier }` | `{ requestId, channel?, maskedIdentifier?, expiresAt? }` |
38
+ | `POST /api/auth/verify` | `{ requestId, code }` | whatever your session payload is |
39
+
40
+ Point them elsewhere with `createFetchHandlers({ requestUrl, verifyUrl })`.
39
41
 
40
42
  Your server holds the Sneek API key and calls Sneek. The browser never sees it.
41
43
 
44
+ ## You never pick the channel
45
+
46
+ Ask Sneek to verify a person; **Sneek decides how**. The channel comes from the
47
+ `authChannels` bitmask on your application — SMS, WhatsApp, email, and push and
48
+ QR-scan as they land — and can change without a front-end release.
49
+
50
+ `channel` and `maskedIdentifier` come back on the request response for **display
51
+ only**. The card uses them to say what actually happened:
52
+
53
+ ```
54
+ Sent via WhatsApp to +91***29
55
+ ```
56
+
57
+ If your backend does not forward them, the card falls back to `Sent to <what the
58
+ visitor typed>` and nothing else changes. Neither field is ever an input.
59
+
42
60
  ## Theming
43
61
 
44
62
  It follows the system colour scheme out of the box. Pin it if you prefer:
45
63
 
46
64
  ```tsx
47
- <SneekOtpLogin theme="dark" {...handlers} />
65
+ <SneekLogin theme="dark" {...handlers} />
48
66
  ```
49
67
 
50
68
  Override the single accent colour — everything else derives from it:
51
69
 
52
70
  ```tsx
53
- <SneekOtpLogin accentColor="#7c3aed" {...handlers} />
71
+ <SneekLogin accentColor="#7c3aed" {...handlers} />
54
72
  ```
55
73
 
56
74
  The code entry step shows the destination with an inline way to change it,
@@ -66,13 +84,13 @@ itself if the visitor pastes a full international number (anything
66
84
  starting with `+`):
67
85
 
68
86
  ```tsx
69
- <SneekOtpLogin defaultCountry="GB" {...handlers} />
87
+ <SneekLogin defaultCountry="GB" {...handlers} />
70
88
  ```
71
89
 
72
90
  Lock the field to just one identifier — no chip, no toggle:
73
91
 
74
92
  ```tsx
75
- <SneekOtpLogin identifierMode="email" {...handlers} />
93
+ <SneekLogin identifierMode="email" {...handlers} />
76
94
  ```
77
95
 
78
96
  `identifierMode` is `'both' | 'phone' | 'email'`, default `'both'`.
@@ -80,7 +98,7 @@ Lock the field to just one identifier — no chip, no toggle:
80
98
  Swap the mark, drop the sub-heading, or remove the Sneek line:
81
99
 
82
100
  ```tsx
83
- <SneekOtpLogin
101
+ <SneekLogin
84
102
  logo={<MyLogo />}
85
103
  subtitle={null}
86
104
  showBranding={false}
@@ -89,18 +107,20 @@ Swap the mark, drop the sub-heading, or remove the Sneek line:
89
107
  ```
90
108
 
91
109
  For anything further, `className` and `style` land on the outer card, and every
92
- control carries a stable class (`.sneek-otp-input`, `.sneek-otp-button`,
93
- `.sneek-otp-link`) you can target.
110
+ control carries a stable class (`.sneek-login-input`, `.sneek-login-button`,
111
+ `.sneek-login-link`) you can target.
94
112
 
95
113
  ## Props
96
114
 
97
115
  | Prop | Type | Default |
98
116
  | --- | --- | --- |
99
- | `requestOtp` | `(identifier) => Promise<RequestOtpResult>` | — (required) |
100
- | `verifyOtp` | `(requestId, code) => Promise<TResult>` | — (required) |
117
+ | `requestVerification` | `(identifier) => Promise<VerificationRequest>` | — (required) |
118
+ | `verify` | `({ requestId, code }) => Promise<TResult>` | — (required) |
101
119
  | `onSuccess` | `(result: TResult) => void` | — |
120
+ | `onError` | `(error: unknown) => void` | — |
102
121
  | `title` | `string` | `'Sign in'` |
103
- | `subtitle` | `ReactNode \| null` | `'We will send you a one-time code.'` |
122
+ | `verifyTitle` | `string` | `'Enter the code'` |
123
+ | `subtitle` | `ReactNode \| null` | `'Enter your email or phone to continue.'` |
104
124
  | `identifierMode` | `'both' \| 'phone' \| 'email'` | `'both'` |
105
125
  | `defaultCountry` | ISO 3166-1 alpha-2, e.g. `'GB'` | `'IN'` (India) |
106
126
  | `identifierLabel` | `string` | `'Mobile number'` / `'Email address'`, per mode |
@@ -117,13 +137,17 @@ If the card does not suit you, use the hook and render whatever you like. It
117
137
  holds the whole state machine — step, busy flags, errors, resend:
118
138
 
119
139
  ```tsx
120
- import { useSneekOtp, createFetchHandlers } from '@sneekin/ui';
140
+ import { useSneekLogin, createFetchHandlers } from '@sneekin/ui';
121
141
 
122
- const otp = useSneekOtp(createFetchHandlers({ baseUrl: '/api/auth' }));
123
- // otp.step, otp.identifier, otp.code, otp.error,
124
- // otp.sendOtp(), otp.verify(), otp.resend(), otp.back()
142
+ const login = useSneekLogin(createFetchHandlers());
143
+ // login.step, login.identifier, login.code, login.error,
144
+ // login.channel, login.maskedIdentifier,
145
+ // login.startVerification(), login.submitCode(), login.resend(), login.back()
125
146
  ```
126
147
 
148
+ `channelLabel(login.channel)` turns the raw channel into something readable
149
+ (`whatsapp` → `WhatsApp`) if you write your own status line.
150
+
127
151
  ## License
128
152
 
129
153
  UNLICENSED — © Abblor Tech Pvt Ltd.
@@ -1,8 +1,8 @@
1
1
  import { type CSSProperties, type ReactNode } from 'react';
2
- import { type SneekOtpHandlers } from './use-sneek-otp';
2
+ import { type SneekLoginHandlers } from './use-sneek-login.js';
3
3
  export type SneekTheme = 'auto' | 'light' | 'dark';
4
4
  export type SneekIdentifierMode = 'phone' | 'email' | 'both';
5
- export interface SneekOtpLoginProps<TResult = unknown> extends SneekOtpHandlers<TResult> {
5
+ export interface SneekLoginProps<TResult = unknown> extends SneekLoginHandlers<TResult> {
6
6
  /** Heading above the form. @default 'Sign in' */
7
7
  title?: string;
8
8
  /** Heading once the code has been sent. @default 'Enter the code' */
@@ -55,10 +55,10 @@ export interface SneekOtpLoginProps<TResult = unknown> extends SneekOtpHandlers<
55
55
  *
56
56
  * @example
57
57
  * ```tsx
58
- * <SneekOtpLogin
59
- * {...createFetchHandlers({ baseUrl: '/api/auth' })}
58
+ * <SneekLogin
59
+ * {...createFetchHandlers()}
60
60
  * onSuccess={(session) => router.push('/app')}
61
61
  * />
62
62
  * ```
63
63
  */
64
- export declare function SneekOtpLogin<TResult = unknown>(props: SneekOtpLoginProps<TResult>): ReactNode;
64
+ export declare function SneekLogin<TResult = unknown>(props: SneekLoginProps<TResult>): ReactNode;
@@ -1,4 +1,4 @@
1
- import { type Country } from './countries';
1
+ import { type Country } from './countries.js';
2
2
  export interface CountryPickerProps {
3
3
  country: Country;
4
4
  onSelect: (country: Country) => void;
@@ -1,15 +1,16 @@
1
- import type { RequestOtpResult } from './state';
1
+ import type { VerificationRequest } from './state.js';
2
2
  export interface FetchHandlerOptions {
3
3
  /**
4
- * Partner backend endpoint that sends an OTP. Receives `{ identifier }`,
5
- * must return `{ requestId, channels?, expiresInSeconds? }`.
6
- * @default '/api/auth/request-otp'
4
+ * Partner backend endpoint that starts a verification. Receives
5
+ * `{ identifier }`, must return
6
+ * `{ requestId, channel?, maskedIdentifier?, expiresAt? }`.
7
+ * @default '/api/auth/request'
7
8
  */
8
9
  requestUrl?: string;
9
10
  /**
10
- * Partner backend endpoint that verifies an OTP. Receives
11
+ * Partner backend endpoint that completes a verification. Receives
11
12
  * `{ requestId, code }`, returns whatever your app needs (session, token…).
12
- * @default '/api/auth/verify-otp'
13
+ * @default '/api/auth/verify'
13
14
  */
14
15
  verifyUrl?: string;
15
16
  /** Extra headers (e.g. CSRF token) to send on both requests. */
@@ -18,12 +19,12 @@ export interface FetchHandlerOptions {
18
19
  credentials?: RequestCredentials;
19
20
  }
20
21
  /**
21
- * Build {@link SneekOtpHandlers} that POST to your own backend endpoints.
22
+ * Build {@link SneekLoginHandlers} that POST to your own backend endpoints.
22
23
  * Those endpoints call the Sneek API server-side with your secret key.
23
24
  */
24
25
  export declare function createFetchHandlers<TResult = unknown>(options?: FetchHandlerOptions): {
25
- requestOtp: (identifier: string) => Promise<RequestOtpResult>;
26
- verifyOtp: (input: {
26
+ requestVerification: (identifier: string) => Promise<VerificationRequest>;
27
+ verify: (input: {
27
28
  requestId: string;
28
29
  code: string;
29
30
  }) => Promise<TResult>;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { useSneekOtp, type SneekOtpHandlers, type UseSneekOtp, } from './use-sneek-otp';
2
- export { SneekOtpLogin, type SneekOtpLoginProps, type SneekTheme, type SneekIdentifierMode, } from './component';
3
- export { SNEEK_ACCENT_DARK, SNEEK_ACCENT_LIGHT, } from './theme';
4
- export { COUNTRIES, DEFAULT_COUNTRY_ISO2, flagEmoji, countryByIso2, countryByDialPrefix, detectCountryFromLocale, type Country, } from './countries';
5
- export { createFetchHandlers, type FetchHandlerOptions, } from './fetch-handlers';
6
- export { otpReducer, initialOtpState, formatChannels, type SneekChannel, type SneekOtpStep, type SneekOtpStatus, type SneekOtpState, type SneekOtpAction, type RequestOtpResult, } from './state';
1
+ export { useSneekLogin, type SneekLoginHandlers, type UseSneekLogin, } from './use-sneek-login.js';
2
+ export { SneekLogin, type SneekLoginProps, type SneekTheme, type SneekIdentifierMode, } from './component.js';
3
+ export { SNEEK_ACCENT_DARK, SNEEK_ACCENT_LIGHT, } from './theme.js';
4
+ export { COUNTRIES, DEFAULT_COUNTRY_ISO2, flagEmoji, countryByIso2, countryByDialPrefix, detectCountryFromLocale, type Country, } from './countries.js';
5
+ export { createFetchHandlers, type FetchHandlerOptions, } from './fetch-handlers.js';
6
+ export { loginReducer, initialLoginState, channelLabel, type SneekChannel, type SneekLoginStep, type SneekLoginStatus, type SneekLoginState, type SneekLoginAction, type VerificationRequest, } from './state.js';