@reopt-ai/brandapp-sdk 3.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/CHANGELOG.md +574 -0
- package/LICENSE +21 -0
- package/README.md +468 -0
- package/dist/ai/index.d.ts +314 -0
- package/dist/ai/index.js +7 -0
- package/dist/ai-provider/index.d.ts +196 -0
- package/dist/ai-provider/index.js +703 -0
- package/dist/auth/index.d.ts +76 -0
- package/dist/auth/index.js +40 -0
- package/dist/better-auth/client.d.ts +29 -0
- package/dist/better-auth/client.js +10 -0
- package/dist/better-auth/index.d.ts +82 -0
- package/dist/better-auth/index.js +145 -0
- package/dist/chunk-6FLYVNZI.js +32 -0
- package/dist/chunk-6KPKZ7ZB.js +49 -0
- package/dist/chunk-DI6QJPTQ.js +449 -0
- package/dist/chunk-E457LO5A.js +599 -0
- package/dist/chunk-F7BXBTZI.js +54 -0
- package/dist/chunk-J5Y2GSJF.js +443 -0
- package/dist/chunk-K3YVJE6E.js +96 -0
- package/dist/chunk-KU2LN5SE.js +350 -0
- package/dist/chunk-L4DHB36G.js +75 -0
- package/dist/chunk-PJZB4VP7.js +63 -0
- package/dist/chunk-REIKXSMY.js +7 -0
- package/dist/chunk-T2WXHAAC.js +54 -0
- package/dist/chunk-TUKIYH4Q.js +112 -0
- package/dist/chunk-WSEROZVO.js +81 -0
- package/dist/chunk-YRGLBM6V.js +157 -0
- package/dist/client-BkcO-0C2.d.ts +216 -0
- package/dist/client-CN5_tNOC.d.ts +147 -0
- package/dist/client-DttyeM_h.d.ts +102 -0
- package/dist/cms/index.d.ts +137 -0
- package/dist/cms/index.js +101 -0
- package/dist/config-CtxyJsDR.d.ts +397 -0
- package/dist/dev/index.d.ts +509 -0
- package/dist/dev/index.js +3071 -0
- package/dist/eav/coerce.d.ts +42 -0
- package/dist/eav/coerce.js +65 -0
- package/dist/eav/index.d.ts +214 -0
- package/dist/eav/index.js +147 -0
- package/dist/eav/migrate.d.ts +236 -0
- package/dist/eav/migrate.js +219 -0
- package/dist/eav/schema.d.ts +260 -0
- package/dist/eav/schema.js +656 -0
- package/dist/errors-5hd5ZR-M.d.ts +158 -0
- package/dist/feedback/index.d.ts +132 -0
- package/dist/feedback/index.js +5 -0
- package/dist/files/index.d.ts +54 -0
- package/dist/files/index.js +31 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.js +84 -0
- package/dist/plans/index.d.ts +140 -0
- package/dist/plans/index.js +5 -0
- package/dist/push/index.d.ts +79 -0
- package/dist/push/index.js +5 -0
- package/dist/react/hooks.d.ts +376 -0
- package/dist/react/hooks.js +421 -0
- package/dist/terms/index.d.ts +79 -0
- package/dist/terms/index.js +5 -0
- package/dist/testing/index.d.ts +154 -0
- package/dist/testing/index.js +81 -0
- package/dist/typed-client-BxOVIiMU.d.ts +40 -0
- package/dist/types-6E3ZLL9X.d.ts +24 -0
- package/dist/types-DskYLVb8.d.ts +104 -0
- package/dist/types-ckmDDW3N.d.ts +129 -0
- package/dist/webhooks/index.d.ts +140 -0
- package/dist/webhooks/index.js +142 -0
- package/docs/api-reference.md +557 -0
- package/docs/cms.md +318 -0
- package/docs/dev-server.md +164 -0
- package/docs/environment.md +211 -0
- package/docs/errors.md +290 -0
- package/docs/files.md +272 -0
- package/docs/migration.md +315 -0
- package/docs/testing.md +163 -0
- package/package.json +173 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export { L as LinkCurrentUserResult, R as ReoptAuthClient, U as UserInfoClaims, c as createReoptAuthClient } from '../client-DttyeM_h.js';
|
|
2
|
+
import '../config-CtxyJsDR.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 세션 쿠키 검증 — apps/id의 Better Auth `/api/auth/get-session`을 호출해
|
|
6
|
+
* 외부 마케팅 사이트가 `.reopt.ai` 서브도메인 쿠키 세션을 인식할 수 있게 한다.
|
|
7
|
+
*
|
|
8
|
+
* Better Auth 서버는 cross-subdomain cookie(`domain: ".reopt.ai"`)로 세션을
|
|
9
|
+
* 자동 공유하므로, 외부 사이트가 같은 부모 도메인 아래에 있으면 별도 OAuth 흐름
|
|
10
|
+
* 없이 현재 요청의 `cookie` 헤더만 forward하면 된다.
|
|
11
|
+
*
|
|
12
|
+
* @example Server Component / API route
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { cookies } from "next/headers";
|
|
15
|
+
* import { getSessionFromCookies } from "@reopt-ai/brandapp-sdk/auth";
|
|
16
|
+
*
|
|
17
|
+
* export default async function Page() {
|
|
18
|
+
* const cookieHeader = (await cookies())
|
|
19
|
+
* .getAll()
|
|
20
|
+
* .map((c) => `${c.name}=${c.value}`)
|
|
21
|
+
* .join("; ");
|
|
22
|
+
* const session = await getSessionFromCookies(cookieHeader, {
|
|
23
|
+
* idServerUrl: "https://id.reopt.ai",
|
|
24
|
+
* });
|
|
25
|
+
* return session ? <Dashboard user={session.user} /> : <SignIn />;
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ⚡ 성능 — 이 함수는 호출마다 id 서버로 1회 네트워크 검증을 한다(`no-store`).
|
|
30
|
+
* 한 요청에서 layout·page·여러 서버 컴포넌트가 반복 호출하면 그만큼 왕복이
|
|
31
|
+
* 늘어난다. Next.js App Router라면 `React.cache`로 감싸 요청 단위로 dedupe하라:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { cache } from "react";
|
|
35
|
+
* export const getReoptSession = cache((cookieHeader: string | null) =>
|
|
36
|
+
* getSessionFromCookies(cookieHeader, { idServerUrl: "https://id.reopt.ai" }),
|
|
37
|
+
* );
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
type Session = {
|
|
41
|
+
user: {
|
|
42
|
+
id: string;
|
|
43
|
+
email: string;
|
|
44
|
+
name: string;
|
|
45
|
+
image: string | null;
|
|
46
|
+
emailVerified?: boolean;
|
|
47
|
+
};
|
|
48
|
+
session: {
|
|
49
|
+
id: string;
|
|
50
|
+
expiresAt: string;
|
|
51
|
+
/** Optional — Better Auth가 환경에 따라 포함하거나 빼는 필드들. */
|
|
52
|
+
userId?: string;
|
|
53
|
+
token?: string;
|
|
54
|
+
ipAddress?: string | null;
|
|
55
|
+
userAgent?: string | null;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
type GetSessionOptions = {
|
|
59
|
+
/** Better Auth handler가 마운트된 URL. e.g. "https://id.reopt.ai". */
|
|
60
|
+
idServerUrl: string;
|
|
61
|
+
/** 기본 `/api/auth/get-session`. 다른 path에 mount된 경우 override. */
|
|
62
|
+
path?: string;
|
|
63
|
+
/** Optional fetch override (테스트/SSR proxy 용). 기본 `globalThis.fetch`. */
|
|
64
|
+
fetch?: typeof fetch;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* `Cookie` 헤더에 있는 reopt 세션을 id 서버에 위임 검증. 인증되지 않았거나
|
|
68
|
+
* id 서버가 응답하지 않으면 `null`. Edge runtime / Node 둘 다에서 동작.
|
|
69
|
+
*/
|
|
70
|
+
declare function getSessionFromCookies(cookieHeader: string | null | undefined, opts: GetSessionOptions): Promise<Session | null>;
|
|
71
|
+
/**
|
|
72
|
+
* 편의 wrapper — `Request` 객체에서 `cookie` 헤더를 꺼내 검증.
|
|
73
|
+
*/
|
|
74
|
+
declare function verifySession(request: Request, opts: GetSessionOptions): Promise<Session | null>;
|
|
75
|
+
|
|
76
|
+
export { type GetSessionOptions, type Session, getSessionFromCookies, verifySession };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export { ReoptAuthClient, createReoptAuthClient } from '../chunk-PJZB4VP7.js';
|
|
2
|
+
import '../chunk-DI6QJPTQ.js';
|
|
3
|
+
import '../chunk-J5Y2GSJF.js';
|
|
4
|
+
|
|
5
|
+
// src/auth/session.ts
|
|
6
|
+
async function getSessionFromCookies(cookieHeader, opts) {
|
|
7
|
+
if (!cookieHeader) return null;
|
|
8
|
+
const path = opts.path ?? "/api/auth/get-session";
|
|
9
|
+
const url = new URL(path, opts.idServerUrl).toString();
|
|
10
|
+
const fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
11
|
+
let res;
|
|
12
|
+
try {
|
|
13
|
+
res = await fetchImpl(url, {
|
|
14
|
+
method: "GET",
|
|
15
|
+
headers: { cookie: cookieHeader, accept: "application/json" },
|
|
16
|
+
cache: "no-store",
|
|
17
|
+
credentials: "include"
|
|
18
|
+
});
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (!res.ok) return null;
|
|
23
|
+
let body;
|
|
24
|
+
try {
|
|
25
|
+
body = await res.json();
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (!body || typeof body !== "object") return null;
|
|
30
|
+
const session = body;
|
|
31
|
+
if (!session.user || typeof session.user.id !== "string") return null;
|
|
32
|
+
return session;
|
|
33
|
+
}
|
|
34
|
+
async function verifySession(request, opts) {
|
|
35
|
+
return getSessionFromCookies(request.headers.get("cookie"), opts);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { getSessionFromCookies, verifySession };
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { genericOAuthClient } from 'better-auth/client/plugins';
|
|
2
|
+
export { b as REOPT_PROVIDER_ID } from '../types-6E3ZLL9X.js';
|
|
3
|
+
|
|
4
|
+
type GenericOAuthClientPlugin = ReturnType<typeof genericOAuthClient>;
|
|
5
|
+
/**
|
|
6
|
+
* Reopt OAuth Client Plugin
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createReoptOAuthClient, REOPT_PROVIDER_ID } from "@reopt-ai/brandapp-sdk/better-auth/client";
|
|
11
|
+
*
|
|
12
|
+
* const authClient = createAuthClient({
|
|
13
|
+
* plugins: [createReoptOAuthClient()],
|
|
14
|
+
* // ⚡ 탭 포커스마다 /api/auth/get-session을 재요청하는 better-auth 기본
|
|
15
|
+
* // 동작(refetchOnWindowFocus: true)을 끈다. 세션은 cross-subdomain 쿠키로
|
|
16
|
+
* // 공유되고 로그인/로그아웃은 명시적 전환·브로드캐스트로 동기화되므로
|
|
17
|
+
* // focus 단위 재검증은 불필요한 요청 폭주만 만든다.
|
|
18
|
+
* sessionOptions: { refetchOnWindowFocus: false },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* authClient.signIn.oauth2({
|
|
22
|
+
* providerId: REOPT_PROVIDER_ID,
|
|
23
|
+
* callbackURL: "/dashboard",
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function createReoptOAuthClient(): GenericOAuthClientPlugin;
|
|
28
|
+
|
|
29
|
+
export { createReoptOAuthClient };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { REOPT_PROVIDER_ID } from '../chunk-REIKXSMY.js';
|
|
2
|
+
import { genericOAuthClient } from 'better-auth/client/plugins';
|
|
3
|
+
|
|
4
|
+
function createReoptOAuthClient() {
|
|
5
|
+
return genericOAuthClient();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { createReoptOAuthClient };
|
|
9
|
+
//# sourceMappingURL=client.js.map
|
|
10
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AdapterFactory } from 'better-auth/adapters';
|
|
2
|
+
import { BetterAuthOptions, BetterAuthPlugin } from 'better-auth';
|
|
3
|
+
import { q as ReoptSDKConfig } from '../config-CtxyJsDR.js';
|
|
4
|
+
export { R as REOPT_BASE_URLS } from '../config-CtxyJsDR.js';
|
|
5
|
+
export { A as AdapterOperation, a as AdapterRequestBody, R as REOPT_DEFAULT_SCOPES, b as REOPT_PROVIDER_ID } from '../types-6E3ZLL9X.js';
|
|
6
|
+
export { A as AuthError, R as RateLimitError, g as ReoptSDKError, S as ServerError, k as isReoptSDKError } from '../errors-5hd5ZR-M.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Reopt Better Auth Remote Database Adapter
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createReoptAdapter } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
14
|
+
*
|
|
15
|
+
* export const auth = betterAuth({
|
|
16
|
+
* database: createReoptAdapter({
|
|
17
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
18
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
19
|
+
* }),
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function createReoptAdapter(config: ReoptSDKConfig): AdapterFactory<BetterAuthOptions>;
|
|
24
|
+
|
|
25
|
+
type ReoptOAuthOptions = ReoptSDKConfig & {
|
|
26
|
+
/** Additional OAuth scopes */
|
|
27
|
+
additionalScopes?: string[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Reopt OAuth Login Plugin
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { createReoptOAuth } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
35
|
+
*
|
|
36
|
+
* export const auth = betterAuth({
|
|
37
|
+
* plugins: [
|
|
38
|
+
* createReoptOAuth({
|
|
39
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
40
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
41
|
+
* }),
|
|
42
|
+
* ],
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
declare function createReoptOAuth(options: ReoptOAuthOptions): BetterAuthPlugin;
|
|
47
|
+
|
|
48
|
+
type ReoptBetterAuthOptions = ReoptSDKConfig & {
|
|
49
|
+
/** Additional OAuth scopes */
|
|
50
|
+
additionalScopes?: string[];
|
|
51
|
+
};
|
|
52
|
+
type ReoptBetterAuthBundle = {
|
|
53
|
+
database: AdapterFactory<BetterAuthOptions>;
|
|
54
|
+
oauth: BetterAuthPlugin;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Config 한 번으로 adapter + OAuth plugin을 함께 생성
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { createReoptBetterAuth } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
62
|
+
*
|
|
63
|
+
* const reopt = createReoptBetterAuth({
|
|
64
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
65
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* export const auth = betterAuth({
|
|
69
|
+
* database: reopt.database,
|
|
70
|
+
* // ⚡ 세션 쿠키 캐시 권장 — reopt 어댑터는 세션 읽기를 매번 reopt API로
|
|
71
|
+
* // 네트워크 위임한다(findOne "session"). cookieCache를 켜면 better-auth가
|
|
72
|
+
* // 서명된 쿠키에서 세션을 읽어 maxAge(초) 동안 어댑터/네트워크 호출을
|
|
73
|
+
* // 생략한다. (트레이드오프: 세션 강제 무효화가 maxAge 만큼 지연.)
|
|
74
|
+
* // secret이 설정돼 있어야 쿠키 서명이 동작한다.
|
|
75
|
+
* session: { cookieCache: { enabled: true, maxAge: 300 } },
|
|
76
|
+
* plugins: [reopt.oauth, nextCookies()], // nextCookies() must be last
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare function createReoptBetterAuth(options: ReoptBetterAuthOptions): ReoptBetterAuthBundle;
|
|
81
|
+
|
|
82
|
+
export { type ReoptBetterAuthOptions, type ReoptOAuthOptions, ReoptSDKConfig, createReoptAdapter, createReoptBetterAuth, createReoptOAuth };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { REOPT_PROVIDER_ID, REOPT_DEFAULT_SCOPES } from '../chunk-REIKXSMY.js';
|
|
2
|
+
export { REOPT_DEFAULT_SCOPES, REOPT_PROVIDER_ID } from '../chunk-REIKXSMY.js';
|
|
3
|
+
import { BaseHttpClient } from '../chunk-DI6QJPTQ.js';
|
|
4
|
+
import { resolveIdBaseUrl } from '../chunk-J5Y2GSJF.js';
|
|
5
|
+
export { AuthError, REOPT_BASE_URLS, RateLimitError, ReoptSDKError, ServerError, isReoptSDKError } from '../chunk-J5Y2GSJF.js';
|
|
6
|
+
import { createAdapterFactory } from 'better-auth/adapters';
|
|
7
|
+
import { genericOAuth } from 'better-auth/plugins';
|
|
8
|
+
|
|
9
|
+
function assertServerRuntime() {
|
|
10
|
+
if (typeof window !== "undefined") {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"[@reopt-ai/brandapp-sdk] createReoptAdapter() must be called on the server. It uses clientSecret \u2014 exposing it to the browser is a security risk. Move this call behind a server-only module (e.g. a Next.js route handler, server action, or file marked with 'use server')."
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function createReoptAdapter(config) {
|
|
17
|
+
assertServerRuntime();
|
|
18
|
+
const http = new BaseHttpClient(
|
|
19
|
+
config,
|
|
20
|
+
`/api/v1/brandapp/${config.brandappId}/auth/adapter`
|
|
21
|
+
);
|
|
22
|
+
async function request(body) {
|
|
23
|
+
const json = await http.fetch("POST", "", body);
|
|
24
|
+
return json.data;
|
|
25
|
+
}
|
|
26
|
+
return createAdapterFactory({
|
|
27
|
+
config: {
|
|
28
|
+
adapterId: "reopt-brandapp",
|
|
29
|
+
adapterName: "Reopt Brandapp Adapter",
|
|
30
|
+
supportsUUIDs: true,
|
|
31
|
+
supportsArrays: true,
|
|
32
|
+
debugLogs: false,
|
|
33
|
+
usePlural: false
|
|
34
|
+
},
|
|
35
|
+
adapter: () => {
|
|
36
|
+
return {
|
|
37
|
+
async create({ model, data, select }) {
|
|
38
|
+
return request({
|
|
39
|
+
operation: "create",
|
|
40
|
+
model,
|
|
41
|
+
data,
|
|
42
|
+
select
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
async findOne({ model, where, select }) {
|
|
46
|
+
return request({
|
|
47
|
+
operation: "findOne",
|
|
48
|
+
model,
|
|
49
|
+
where,
|
|
50
|
+
select
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
async findMany({ model, where, limit, offset, sortBy }) {
|
|
54
|
+
return request({
|
|
55
|
+
operation: "findMany",
|
|
56
|
+
model,
|
|
57
|
+
where,
|
|
58
|
+
limit,
|
|
59
|
+
offset,
|
|
60
|
+
sortBy
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
async count({ model, where }) {
|
|
64
|
+
return request({
|
|
65
|
+
operation: "count",
|
|
66
|
+
model,
|
|
67
|
+
where
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
async update({ model, where, update }) {
|
|
71
|
+
return request({
|
|
72
|
+
operation: "update",
|
|
73
|
+
model,
|
|
74
|
+
where,
|
|
75
|
+
update
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
async updateMany({ model, where, update }) {
|
|
79
|
+
return request({
|
|
80
|
+
operation: "updateMany",
|
|
81
|
+
model,
|
|
82
|
+
where,
|
|
83
|
+
update
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
async delete({ model, where }) {
|
|
87
|
+
await request({
|
|
88
|
+
operation: "delete",
|
|
89
|
+
model,
|
|
90
|
+
where
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
async deleteMany({ model, where }) {
|
|
94
|
+
return request({
|
|
95
|
+
operation: "deleteMany",
|
|
96
|
+
model,
|
|
97
|
+
where
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function createReoptOAuth(options) {
|
|
105
|
+
if (typeof window !== "undefined") {
|
|
106
|
+
throw new Error(
|
|
107
|
+
"[@reopt-ai/brandapp-sdk] createReoptOAuth() must be called on the server. It uses clientSecret \u2014 exposing it to the browser is a security risk. For client-side OAuth sign-in, use createReoptOAuthClient() from '@reopt-ai/brandapp-sdk/better-auth/client' instead."
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (!options.clientId || !options.clientSecret) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
"[@reopt-ai/brandapp-sdk] createReoptOAuth() requires clientId and clientSecret."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const idBaseUrl = resolveIdBaseUrl(options);
|
|
116
|
+
return genericOAuth({
|
|
117
|
+
config: [
|
|
118
|
+
{
|
|
119
|
+
providerId: REOPT_PROVIDER_ID,
|
|
120
|
+
discoveryUrl: `${idBaseUrl}/api/auth/.well-known/openid-configuration`,
|
|
121
|
+
clientId: options.clientId,
|
|
122
|
+
clientSecret: options.clientSecret,
|
|
123
|
+
scopes: Array.from(
|
|
124
|
+
/* @__PURE__ */ new Set([
|
|
125
|
+
...REOPT_DEFAULT_SCOPES,
|
|
126
|
+
...options.additionalScopes ?? []
|
|
127
|
+
])
|
|
128
|
+
),
|
|
129
|
+
pkce: true
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/better-auth/helper.ts
|
|
136
|
+
function createReoptBetterAuth(options) {
|
|
137
|
+
return {
|
|
138
|
+
database: createReoptAdapter(options),
|
|
139
|
+
oauth: createReoptOAuth(options)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { createReoptAdapter, createReoptBetterAuth, createReoptOAuth };
|
|
144
|
+
//# sourceMappingURL=index.js.map
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ReoptSDKError } from './chunk-J5Y2GSJF.js';
|
|
2
|
+
|
|
3
|
+
// src/core/query.ts
|
|
4
|
+
var MAX_QUERY_STRING_LENGTH = 7500;
|
|
5
|
+
function buildQuery(params) {
|
|
6
|
+
const entries = Object.entries(params).filter(
|
|
7
|
+
([, v]) => v !== void 0 && v !== null
|
|
8
|
+
);
|
|
9
|
+
if (entries.length === 0) return "";
|
|
10
|
+
const qs = "?" + entries.map(([k, v]) => {
|
|
11
|
+
const value = typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
12
|
+
return `${k}=${encodeURIComponent(value)}`;
|
|
13
|
+
}).join("&");
|
|
14
|
+
if (qs.length > MAX_QUERY_STRING_LENGTH) {
|
|
15
|
+
throw new ReoptSDKError(
|
|
16
|
+
`Query string is too large (${qs.length} chars, limit ${MAX_QUERY_STRING_LENGTH}). Reduce the number of filters or the size of filter values.`,
|
|
17
|
+
0,
|
|
18
|
+
"QUERY_TOO_LARGE",
|
|
19
|
+
void 0,
|
|
20
|
+
{
|
|
21
|
+
cause: "GET \uC694\uCCAD\uC758 \uCFFC\uB9AC\uC2A4\uD2B8\uB9C1\uC774 \uC11C\uBC84/\uD504\uB85D\uC2DC\uC758 URL \uAE38\uC774 \uD55C\uB3C4(\uD1B5\uC0C1 8KB)\uB97C \uCD08\uACFC\uD560 \uC704\uD5D8\uC774 \uC788\uC74C",
|
|
22
|
+
fix: "filters \uAC1C\uC218\uB97C \uC904\uC774\uAC70\uB098, \uD070 value(\uC608: \uAE34 contains \uBB38\uC790\uC5F4)\uB97C \uBD84\uB9AC/\uCD95\uC18C. \uB300\uB7C9 \uC870\uAC74\uC740 \uC5EC\uB7EC \uBC88 \uB098\uB220 \uC870\uD68C",
|
|
23
|
+
doc: "docs/errors.md#query_too_large"
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return qs;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { buildQuery };
|
|
31
|
+
//# sourceMappingURL=chunk-6FLYVNZI.js.map
|
|
32
|
+
//# sourceMappingURL=chunk-6FLYVNZI.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BaseHttpClient } from './chunk-DI6QJPTQ.js';
|
|
2
|
+
|
|
3
|
+
// src/push/client.ts
|
|
4
|
+
var ReoptPushClient = class {
|
|
5
|
+
http;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.http = new BaseHttpClient(
|
|
8
|
+
config,
|
|
9
|
+
`/api/v1/brandapp/${config.brandappId}/push`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
/** Register (or refresh) the signed-in customer's device push token. */
|
|
13
|
+
async registerDeviceToken(input, accessToken) {
|
|
14
|
+
const body = await this.http.fetch(
|
|
15
|
+
"POST",
|
|
16
|
+
"/me/tokens",
|
|
17
|
+
input,
|
|
18
|
+
{ bearerToken: accessToken }
|
|
19
|
+
);
|
|
20
|
+
return body.data;
|
|
21
|
+
}
|
|
22
|
+
/** Unregister a device token by `token` or `deviceId` (own tokens only). */
|
|
23
|
+
async unregisterDeviceToken(input, accessToken) {
|
|
24
|
+
const body = await this.http.fetch(
|
|
25
|
+
"DELETE",
|
|
26
|
+
"/me/tokens",
|
|
27
|
+
input,
|
|
28
|
+
{ bearerToken: accessToken }
|
|
29
|
+
);
|
|
30
|
+
return body.data;
|
|
31
|
+
}
|
|
32
|
+
/** List the signed-in customer's registered devices (no raw tokens). */
|
|
33
|
+
async listDevices(accessToken) {
|
|
34
|
+
const body = await this.http.fetch(
|
|
35
|
+
"GET",
|
|
36
|
+
"/me/tokens",
|
|
37
|
+
void 0,
|
|
38
|
+
{ bearerToken: accessToken }
|
|
39
|
+
);
|
|
40
|
+
return body.data;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
function createReoptPushClient(config) {
|
|
44
|
+
return new ReoptPushClient(config);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { ReoptPushClient, createReoptPushClient };
|
|
48
|
+
//# sourceMappingURL=chunk-6KPKZ7ZB.js.map
|
|
49
|
+
//# sourceMappingURL=chunk-6KPKZ7ZB.js.map
|