@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createReoptPushClient } from './chunk-6KPKZ7ZB.js';
|
|
2
|
+
import { createReoptTermsClient } from './chunk-TUKIYH4Q.js';
|
|
3
|
+
import { createReoptEavClient } from './chunk-E457LO5A.js';
|
|
4
|
+
import { createReoptFeedbackClient } from './chunk-K3YVJE6E.js';
|
|
5
|
+
import { createReoptFileClient } from './chunk-YRGLBM6V.js';
|
|
6
|
+
import { createReoptPlansClient } from './chunk-T2WXHAAC.js';
|
|
7
|
+
import { createReoptAiClient } from './chunk-KU2LN5SE.js';
|
|
8
|
+
import './chunk-L4DHB36G.js';
|
|
9
|
+
import './chunk-F7BXBTZI.js';
|
|
10
|
+
import { createReoptAuthClient } from './chunk-PJZB4VP7.js';
|
|
11
|
+
import { createReoptCmsClient } from './chunk-WSEROZVO.js';
|
|
12
|
+
import './chunk-6FLYVNZI.js';
|
|
13
|
+
export { BaseHttpClient } from './chunk-DI6QJPTQ.js';
|
|
14
|
+
import { assertBrowserSafe } from './chunk-J5Y2GSJF.js';
|
|
15
|
+
export { AuthError, AuthUserNotFoundError, AuthUserRecordExistsError, BadRequestError, ConflictError, ContentFilterError, CreditLimitError, DuplicateAuthUserError, ForbiddenError, LimitExceededError, ModelAccessError, ModelNotFoundError, NotFoundError, REOPT_BASE_URLS, RateLimitError, ReoptSDKError, ServerError, ValidationError, isCreditLimitError, isModelAccessError, isReoptSDKError, isValidationError, mapHttpStatusToError, resolveBaseUrl } from './chunk-J5Y2GSJF.js';
|
|
16
|
+
|
|
17
|
+
// src/singleton.ts
|
|
18
|
+
var _instance;
|
|
19
|
+
function createLazySDK(configFactory) {
|
|
20
|
+
let instance;
|
|
21
|
+
function init() {
|
|
22
|
+
if (!instance) instance = createReoptSDK(configFactory());
|
|
23
|
+
return instance;
|
|
24
|
+
}
|
|
25
|
+
return new Proxy({}, {
|
|
26
|
+
get(_target, prop, receiver) {
|
|
27
|
+
return Reflect.get(init(), prop, receiver);
|
|
28
|
+
},
|
|
29
|
+
has(_target, prop) {
|
|
30
|
+
return Reflect.has(init(), prop);
|
|
31
|
+
},
|
|
32
|
+
ownKeys() {
|
|
33
|
+
return Reflect.ownKeys(init());
|
|
34
|
+
},
|
|
35
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
36
|
+
return Reflect.getOwnPropertyDescriptor(init(), prop);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function initReoptSDK(config) {
|
|
41
|
+
const sdk = createReoptSDK(config);
|
|
42
|
+
_instance = sdk;
|
|
43
|
+
return sdk;
|
|
44
|
+
}
|
|
45
|
+
function getReoptSDK() {
|
|
46
|
+
if (_instance) return _instance;
|
|
47
|
+
const clientId = process.env.BRANDAPP_CLIENT_ID;
|
|
48
|
+
const clientSecret = process.env.BRANDAPP_CLIENT_SECRET;
|
|
49
|
+
const brandappId = process.env.BRANDAPP_ID;
|
|
50
|
+
if (clientId && clientSecret && brandappId) {
|
|
51
|
+
_instance = createReoptSDK({ clientId, clientSecret, brandappId });
|
|
52
|
+
return _instance;
|
|
53
|
+
}
|
|
54
|
+
throw new Error(
|
|
55
|
+
"ReoptSDK: No instance available. Call initReoptSDK() first or set BRANDAPP_CLIENT_ID, BRANDAPP_CLIENT_SECRET, and BRANDAPP_ID env vars."
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
function resetSDK() {
|
|
59
|
+
_instance = void 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/index.ts
|
|
63
|
+
function createReoptSDK(config) {
|
|
64
|
+
assertBrowserSafe(config);
|
|
65
|
+
return {
|
|
66
|
+
config: {
|
|
67
|
+
brandappId: config.brandappId,
|
|
68
|
+
debug: config.debug ?? false
|
|
69
|
+
},
|
|
70
|
+
ai: createReoptAiClient(config),
|
|
71
|
+
auth: createReoptAuthClient(config),
|
|
72
|
+
cms: createReoptCmsClient(config),
|
|
73
|
+
eav: createReoptEavClient(config),
|
|
74
|
+
feedback: createReoptFeedbackClient(config),
|
|
75
|
+
files: createReoptFileClient(config),
|
|
76
|
+
plans: createReoptPlansClient(config),
|
|
77
|
+
push: createReoptPushClient(config),
|
|
78
|
+
terms: createReoptTermsClient(config)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { createLazySDK, createReoptSDK, getReoptSDK, initReoptSDK, resetSDK };
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { q as ReoptSDKConfig } from '../config-CtxyJsDR.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Brandapp Plans types.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors the response shape of `/api/v1/brandapp/{brandappId}/plans/*`.
|
|
7
|
+
*/
|
|
8
|
+
/** Prisma `BillingModel` enum. */
|
|
9
|
+
type PlanBillingModel = "recurring" | "usage";
|
|
10
|
+
/** Prisma `PlanInterval` enum. */
|
|
11
|
+
type PlanInterval = "monthly" | "yearly" | "once" | "lifetime";
|
|
12
|
+
/** Prisma `MeterPricingMode` enum. */
|
|
13
|
+
type MeterPricingMode = "flat" | "tiered";
|
|
14
|
+
type PlanMeterTier = {
|
|
15
|
+
/** 이 구간의 상한 수량. `null`이면 마지막(무제한) 구간. */
|
|
16
|
+
upTo: number | null;
|
|
17
|
+
/** 구간 단가 (통화 최소 단위 정수, 예: 원). */
|
|
18
|
+
unitPrice: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* usage 과금 플랜의 사용량 미터.
|
|
22
|
+
*
|
|
23
|
+
* ⚠️ 현재 미터는 **read-only 메타데이터**다 — 사용량 집계·리포팅·청구 백엔드는
|
|
24
|
+
* 아직 구현되지 않았다. 플랜 카탈로그에 "무엇을 얼마에 과금하는지" 표시하는
|
|
25
|
+
* 용도로만 노출된다.
|
|
26
|
+
*/
|
|
27
|
+
type PlanMeter = {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
/** API용 미터 키 (영문 소문자+숫자+언더스코어). */
|
|
31
|
+
key: string;
|
|
32
|
+
/** 단위 레이블 (예: "건", "GB"). */
|
|
33
|
+
unitLabel: string;
|
|
34
|
+
/** 포함 무료 수량. */
|
|
35
|
+
includedQty: number;
|
|
36
|
+
pricingMode: MeterPricingMode | string;
|
|
37
|
+
/** flat 모드 단가 (통화 최소 단위 정수). */
|
|
38
|
+
unitPrice: number;
|
|
39
|
+
/** tiered 모드 구간. flat 모드이거나 미설정이면 `null`. */
|
|
40
|
+
tiers: PlanMeterTier[] | null;
|
|
41
|
+
sortOrder: number;
|
|
42
|
+
};
|
|
43
|
+
type PlanRequiredTerms = {
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
/** Prisma `BrandappTermsType` (termsOfService/privacyPolicy/marketingConsent/custom). */
|
|
47
|
+
type: string;
|
|
48
|
+
};
|
|
49
|
+
type Plan = {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
description: string | null;
|
|
53
|
+
billingModel: PlanBillingModel | string;
|
|
54
|
+
/** 정기 구독 가격 (통화 최소 단위 정수). usage 플랜은 보통 0. */
|
|
55
|
+
priceAmount: number;
|
|
56
|
+
/** ISO 4217 통화 코드 (예: "KRW", "USD"). */
|
|
57
|
+
currency: string;
|
|
58
|
+
interval: PlanInterval | string;
|
|
59
|
+
/** usage 플랜의 기본 요금 (통화 최소 단위 정수). */
|
|
60
|
+
baseFee: number;
|
|
61
|
+
sortOrder: number;
|
|
62
|
+
features: string[];
|
|
63
|
+
/** usage 플랜의 사용량 미터 (read-only). */
|
|
64
|
+
meters: PlanMeter[];
|
|
65
|
+
/** 구독 전에 동의가 필요한 필수 약관. `sdk.terms`로 본문 조회·동의. */
|
|
66
|
+
requiredTerms: PlanRequiredTerms[];
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* 현재 로그인 고객의 구독 플랜 + 엔타이틀먼트.
|
|
70
|
+
*
|
|
71
|
+
* 결제 상태는 이 고객 본인 소유(brandappCustomer) BillingState/PaymentProviderLink에서
|
|
72
|
+
* 읽는다. 원시 결제 식별자(billingKey, 외부 subscription id)는 노출하지 않는다.
|
|
73
|
+
*/
|
|
74
|
+
type CurrentPlan = {
|
|
75
|
+
planId: string;
|
|
76
|
+
planName: string;
|
|
77
|
+
planDescription: string | null;
|
|
78
|
+
priceAmount: number;
|
|
79
|
+
currency: string;
|
|
80
|
+
interval: PlanInterval | string;
|
|
81
|
+
features: string[];
|
|
82
|
+
/** BillingState.status (예: "active", "trialing", "canceled"). null이면 결제 상태 없음. */
|
|
83
|
+
subscriptionStatus: string | null;
|
|
84
|
+
/** ISO-8601 문자열. */
|
|
85
|
+
planStartedAt: string | null;
|
|
86
|
+
/** ISO-8601 문자열. `null`이면 무기한. */
|
|
87
|
+
planExpiresAt: string | null;
|
|
88
|
+
/** 활성 결제 제공자 — "paddle" | "toss" | null. */
|
|
89
|
+
paymentProvider: string | null;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Brandapp Plans client (read-only).
|
|
94
|
+
*
|
|
95
|
+
* Lets a Brandapp read the subscription plans it offers to its own customers,
|
|
96
|
+
* and the signed-in customer's current plan / entitlement.
|
|
97
|
+
*
|
|
98
|
+
* - `list()` — Basic or Bearer. Active plans (catalog).
|
|
99
|
+
* - `getMyPlan(accessToken)` — Bearer. The current customer's plan, or `null`.
|
|
100
|
+
*
|
|
101
|
+
* ⚠️ Starting a subscription (checkout), payment, and cancellation are NOT part
|
|
102
|
+
* of the SDK: they require the Toss/Paddle browser SDK plus host-bound
|
|
103
|
+
* callbacks and are handled by the first-party brandfront flow. Server-side
|
|
104
|
+
* approval, webhooks, and cron stay internal to reopt. usage-model meters are
|
|
105
|
+
* exposed read-only — usage reporting/billing is not implemented yet.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const sdk = createReoptSDK({ clientId, clientSecret, brandappId });
|
|
110
|
+
*
|
|
111
|
+
* // Render the plan catalog (no user context required):
|
|
112
|
+
* const plans = await sdk.plans.list();
|
|
113
|
+
*
|
|
114
|
+
* // After the customer signs in via OAuth:
|
|
115
|
+
* const current = await sdk.plans.getMyPlan(accessToken);
|
|
116
|
+
* if (current?.subscriptionStatus === "active") {
|
|
117
|
+
* // grant entitlement…
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
declare class ReoptPlansClient {
|
|
123
|
+
private readonly http;
|
|
124
|
+
constructor(config: ReoptSDKConfig);
|
|
125
|
+
/**
|
|
126
|
+
* List active plans for this Brandapp (the customer-facing catalog). Works
|
|
127
|
+
* with either Basic Auth (default) or Bearer Auth — pass `accessToken` when
|
|
128
|
+
* calling from a handler that already has the customer's OAuth token to avoid
|
|
129
|
+
* sending app credentials.
|
|
130
|
+
*/
|
|
131
|
+
list(accessToken?: string): Promise<Plan[]>;
|
|
132
|
+
/**
|
|
133
|
+
* Fetch the current plan / entitlement for the OAuth customer represented by
|
|
134
|
+
* `accessToken`. Returns `null` when the customer has no active plan.
|
|
135
|
+
*/
|
|
136
|
+
getMyPlan(accessToken: string): Promise<CurrentPlan | null>;
|
|
137
|
+
}
|
|
138
|
+
declare function createReoptPlansClient(config: ReoptSDKConfig): ReoptPlansClient;
|
|
139
|
+
|
|
140
|
+
export { type CurrentPlan, type MeterPricingMode, type Plan, type PlanBillingModel, type PlanInterval, type PlanMeter, type PlanMeterTier, type PlanRequiredTerms, ReoptPlansClient, createReoptPlansClient };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { q as ReoptSDKConfig } from '../config-CtxyJsDR.js';
|
|
2
|
+
|
|
3
|
+
/** Push provider — native token kind. */
|
|
4
|
+
type PushProvider = "fcm" | "apns";
|
|
5
|
+
/** Device platform. */
|
|
6
|
+
type PushPlatform = "ios" | "android" | "web";
|
|
7
|
+
/** Input for registering a device push token. */
|
|
8
|
+
type RegisterPushTokenInput = {
|
|
9
|
+
/** Provider of the native token. */
|
|
10
|
+
provider: PushProvider;
|
|
11
|
+
/** Native device token (FCM registration token / APNs device token). */
|
|
12
|
+
token: string;
|
|
13
|
+
/** Device platform. */
|
|
14
|
+
platform: PushPlatform;
|
|
15
|
+
/** Optional device identifier (helps re-login/refresh upsert + unregister). */
|
|
16
|
+
deviceId?: string;
|
|
17
|
+
};
|
|
18
|
+
type RegisterPushTokenResult = {
|
|
19
|
+
registered: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Input for unregistering — one of token / deviceId is required. */
|
|
22
|
+
type UnregisterPushTokenInput = {
|
|
23
|
+
token?: string;
|
|
24
|
+
deviceId?: string;
|
|
25
|
+
};
|
|
26
|
+
type UnregisterPushTokenResult = {
|
|
27
|
+
unregistered: boolean;
|
|
28
|
+
};
|
|
29
|
+
/** A device currently registered for the signed-in customer. */
|
|
30
|
+
type RegisteredPushDevice = {
|
|
31
|
+
id: string;
|
|
32
|
+
platform: PushPlatform;
|
|
33
|
+
provider: PushProvider;
|
|
34
|
+
deviceId: string | null;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
lastSeenAt: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Brandapp Push client.
|
|
41
|
+
*
|
|
42
|
+
* Lets a signed-in customer register/unregister their native device push token
|
|
43
|
+
* (FCM/APNs) so the workspace can send them direct push notifications from the
|
|
44
|
+
* reopt Studio send console. All methods require the end-user's OAuth access
|
|
45
|
+
* token — the server resolves the token's linked customer and scopes the token
|
|
46
|
+
* to them (unlinked users get 403 `LINK_REQUIRED`).
|
|
47
|
+
*
|
|
48
|
+
* The native token itself (FCM registration token / APNs device token) is
|
|
49
|
+
* obtained by the host app (React Native / native shell) — this client only
|
|
50
|
+
* registers/unregisters an already-obtained token.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const sdk = createReoptSDK({ clientId, clientSecret, brandappId });
|
|
55
|
+
*
|
|
56
|
+
* // After obtaining a native token in the app:
|
|
57
|
+
* await sdk.push.registerDeviceToken(
|
|
58
|
+
* { provider: "fcm", token: fcmToken, platform: "android", deviceId },
|
|
59
|
+
* accessToken,
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* // On logout:
|
|
63
|
+
* await sdk.push.unregisterDeviceToken({ deviceId }, accessToken);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
declare class ReoptPushClient {
|
|
68
|
+
private readonly http;
|
|
69
|
+
constructor(config: ReoptSDKConfig);
|
|
70
|
+
/** Register (or refresh) the signed-in customer's device push token. */
|
|
71
|
+
registerDeviceToken(input: RegisterPushTokenInput, accessToken: string): Promise<RegisterPushTokenResult>;
|
|
72
|
+
/** Unregister a device token by `token` or `deviceId` (own tokens only). */
|
|
73
|
+
unregisterDeviceToken(input: UnregisterPushTokenInput, accessToken: string): Promise<UnregisterPushTokenResult>;
|
|
74
|
+
/** List the signed-in customer's registered devices (no raw tokens). */
|
|
75
|
+
listDevices(accessToken: string): Promise<RegisteredPushDevice[]>;
|
|
76
|
+
}
|
|
77
|
+
declare function createReoptPushClient(config: ReoptSDKConfig): ReoptPushClient;
|
|
78
|
+
|
|
79
|
+
export { type PushPlatform, type PushProvider, type RegisterPushTokenInput, type RegisterPushTokenResult, type RegisteredPushDevice, ReoptPushClient, type UnregisterPushTokenInput, type UnregisterPushTokenResult, createReoptPushClient };
|