recur-tw 0.6.1 → 0.7.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.
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+
7
+ // src/server/types.ts
8
+ var RecurAPIError = class extends Error {
9
+ constructor(error, statusCode) {
10
+ super(error.message);
11
+ __publicField(this, "type");
12
+ __publicField(this, "code");
13
+ __publicField(this, "statusCode");
14
+ this.name = "RecurAPIError";
15
+ this.type = error.type;
16
+ this.code = error.code;
17
+ this.statusCode = statusCode;
18
+ }
19
+ };
20
+
21
+ // src/server/resources/portal.ts
22
+ var PortalSessions = class {
23
+ constructor(config) {
24
+ __publicField(this, "config");
25
+ this.config = config;
26
+ }
27
+ /**
28
+ * Create a portal session for a customer
29
+ *
30
+ * @param params - Portal session creation parameters
31
+ * @returns The created portal session with URL
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const session = await recur.portal.sessions.create({
36
+ * customer: 'cus_xxx',
37
+ * returnUrl: 'https://myapp.com/account',
38
+ * });
39
+ *
40
+ * // Redirect the customer to the portal
41
+ * redirect(session.url);
42
+ * ```
43
+ */
44
+ async create(params) {
45
+ const baseUrl = this.config.baseUrl || "https://api.recur.tw";
46
+ const response = await fetch(`${baseUrl}/v1/portal/sessions`, {
47
+ method: "POST",
48
+ headers: {
49
+ "Authorization": `Bearer ${this.config.secretKey}`,
50
+ "Content-Type": "application/json"
51
+ },
52
+ body: JSON.stringify({
53
+ customerId: params.customer,
54
+ returnUrl: params.returnUrl,
55
+ configurationId: params.configuration,
56
+ locale: params.locale
57
+ })
58
+ });
59
+ const data = await response.json();
60
+ if (!response.ok) {
61
+ const error = data.error;
62
+ throw new RecurAPIError(error, response.status);
63
+ }
64
+ return {
65
+ id: data.id,
66
+ object: "portal.session",
67
+ url: data.url,
68
+ customer: data.customerId,
69
+ returnUrl: data.returnUrl,
70
+ status: data.status,
71
+ expiresAt: data.expiresAt,
72
+ accessedAt: data.accessedAt,
73
+ createdAt: data.createdAt
74
+ };
75
+ }
76
+ };
77
+ var Portal = class {
78
+ constructor(config) {
79
+ __publicField(this, "sessions");
80
+ this.sessions = new PortalSessions(config);
81
+ }
82
+ };
83
+
84
+ // src/server/recur.ts
85
+ var Recur = class {
86
+ /**
87
+ * Create a new Recur client
88
+ *
89
+ * @param secretKey - Your Recur secret API key (sk_test_xxx or sk_live_xxx)
90
+ * @param options - Additional configuration options
91
+ */
92
+ constructor(secretKey, options) {
93
+ __publicField(this, "config");
94
+ /**
95
+ * Portal resource for managing customer portal sessions
96
+ */
97
+ __publicField(this, "portal");
98
+ if (!secretKey) {
99
+ throw new Error(
100
+ "Recur: secretKey is required. Get your API key from your organization settings."
101
+ );
102
+ }
103
+ if (!secretKey.startsWith("sk_")) {
104
+ throw new Error(
105
+ 'Recur: Invalid API key format. Secret keys should start with "sk_". Use your secret key (sk_xxx), not your publishable key (pk_xxx).'
106
+ );
107
+ }
108
+ this.config = {
109
+ secretKey,
110
+ baseUrl: options?.baseUrl || "https://api.recur.tw"
111
+ };
112
+ this.portal = new Portal(this.config);
113
+ }
114
+ };
115
+
116
+ exports.Recur = Recur;
117
+ exports.RecurAPIError = RecurAPIError;
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Recur Server SDK Types
3
+ */
4
+ interface RecurConfig {
5
+ /**
6
+ * Secret API key for authentication
7
+ * Get this from your organization settings
8
+ *
9
+ * @example 'sk_test_abc123...' or 'sk_live_xyz789...'
10
+ */
11
+ secretKey: string;
12
+ /**
13
+ * Base URL for API calls
14
+ * Defaults to 'https://api.recur.tw'
15
+ */
16
+ baseUrl?: string;
17
+ }
18
+ interface PortalSessionCreateParams {
19
+ /**
20
+ * The ID of the customer to create a portal session for
21
+ */
22
+ customer: string;
23
+ /**
24
+ * The URL to redirect the customer to when they exit the portal
25
+ * If not provided, uses the default return URL from portal configuration
26
+ */
27
+ returnUrl?: string;
28
+ /**
29
+ * The ID of a specific portal configuration to use
30
+ * If not provided, uses the default configuration
31
+ */
32
+ configuration?: string;
33
+ /**
34
+ * Preferred locale for the portal
35
+ */
36
+ locale?: 'zh-TW' | 'en';
37
+ }
38
+ interface PortalSession {
39
+ /**
40
+ * Unique identifier for the portal session
41
+ */
42
+ id: string;
43
+ /**
44
+ * String representing the object's type
45
+ */
46
+ object: 'portal.session';
47
+ /**
48
+ * The URL to redirect the customer to access the portal
49
+ */
50
+ url: string;
51
+ /**
52
+ * The ID of the customer for this session
53
+ */
54
+ customer: string;
55
+ /**
56
+ * The URL to redirect the customer when they exit the portal
57
+ */
58
+ returnUrl: string;
59
+ /**
60
+ * The status of the session
61
+ */
62
+ status: 'active' | 'expired';
63
+ /**
64
+ * Time at which the session expires (ISO 8601)
65
+ */
66
+ expiresAt: string;
67
+ /**
68
+ * Time at which the session was last accessed (ISO 8601), or null
69
+ */
70
+ accessedAt: string | null;
71
+ /**
72
+ * Time at which the session was created (ISO 8601)
73
+ */
74
+ createdAt: string;
75
+ }
76
+ interface RecurError {
77
+ type: 'authentication_error' | 'invalid_request_error' | 'api_error';
78
+ code: string;
79
+ message: string;
80
+ details?: unknown;
81
+ }
82
+ declare class RecurAPIError extends Error {
83
+ readonly type: string;
84
+ readonly code: string;
85
+ readonly statusCode: number;
86
+ constructor(error: RecurError, statusCode: number);
87
+ }
88
+
89
+ /**
90
+ * Portal Sessions Resource
91
+ *
92
+ * Create portal sessions to allow customers to manage their subscriptions
93
+ */
94
+
95
+ declare class PortalSessions {
96
+ private config;
97
+ constructor(config: RecurConfig);
98
+ /**
99
+ * Create a portal session for a customer
100
+ *
101
+ * @param params - Portal session creation parameters
102
+ * @returns The created portal session with URL
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const session = await recur.portal.sessions.create({
107
+ * customer: 'cus_xxx',
108
+ * returnUrl: 'https://myapp.com/account',
109
+ * });
110
+ *
111
+ * // Redirect the customer to the portal
112
+ * redirect(session.url);
113
+ * ```
114
+ */
115
+ create(params: PortalSessionCreateParams): Promise<PortalSession>;
116
+ }
117
+ declare class Portal {
118
+ readonly sessions: PortalSessions;
119
+ constructor(config: RecurConfig);
120
+ }
121
+
122
+ /**
123
+ * Recur Server SDK
124
+ *
125
+ * Server-side SDK for interacting with the Recur API
126
+ * Use this in your backend (API routes, server actions, etc.)
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * import { Recur } from 'recur-tw/server';
131
+ *
132
+ * const recur = new Recur(process.env.RECUR_SECRET_KEY!);
133
+ *
134
+ * // Create a portal session
135
+ * const session = await recur.portal.sessions.create({
136
+ * customer: 'cus_xxx',
137
+ * returnUrl: 'https://myapp.com/account',
138
+ * });
139
+ * ```
140
+ */
141
+
142
+ declare class Recur {
143
+ private config;
144
+ /**
145
+ * Portal resource for managing customer portal sessions
146
+ */
147
+ readonly portal: Portal;
148
+ /**
149
+ * Create a new Recur client
150
+ *
151
+ * @param secretKey - Your Recur secret API key (sk_test_xxx or sk_live_xxx)
152
+ * @param options - Additional configuration options
153
+ */
154
+ constructor(secretKey: string, options?: Omit<RecurConfig, 'secretKey'>);
155
+ }
156
+
157
+ export { type PortalSession, type PortalSessionCreateParams, Recur, RecurAPIError, type RecurConfig, type RecurError };
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Recur Server SDK Types
3
+ */
4
+ interface RecurConfig {
5
+ /**
6
+ * Secret API key for authentication
7
+ * Get this from your organization settings
8
+ *
9
+ * @example 'sk_test_abc123...' or 'sk_live_xyz789...'
10
+ */
11
+ secretKey: string;
12
+ /**
13
+ * Base URL for API calls
14
+ * Defaults to 'https://api.recur.tw'
15
+ */
16
+ baseUrl?: string;
17
+ }
18
+ interface PortalSessionCreateParams {
19
+ /**
20
+ * The ID of the customer to create a portal session for
21
+ */
22
+ customer: string;
23
+ /**
24
+ * The URL to redirect the customer to when they exit the portal
25
+ * If not provided, uses the default return URL from portal configuration
26
+ */
27
+ returnUrl?: string;
28
+ /**
29
+ * The ID of a specific portal configuration to use
30
+ * If not provided, uses the default configuration
31
+ */
32
+ configuration?: string;
33
+ /**
34
+ * Preferred locale for the portal
35
+ */
36
+ locale?: 'zh-TW' | 'en';
37
+ }
38
+ interface PortalSession {
39
+ /**
40
+ * Unique identifier for the portal session
41
+ */
42
+ id: string;
43
+ /**
44
+ * String representing the object's type
45
+ */
46
+ object: 'portal.session';
47
+ /**
48
+ * The URL to redirect the customer to access the portal
49
+ */
50
+ url: string;
51
+ /**
52
+ * The ID of the customer for this session
53
+ */
54
+ customer: string;
55
+ /**
56
+ * The URL to redirect the customer when they exit the portal
57
+ */
58
+ returnUrl: string;
59
+ /**
60
+ * The status of the session
61
+ */
62
+ status: 'active' | 'expired';
63
+ /**
64
+ * Time at which the session expires (ISO 8601)
65
+ */
66
+ expiresAt: string;
67
+ /**
68
+ * Time at which the session was last accessed (ISO 8601), or null
69
+ */
70
+ accessedAt: string | null;
71
+ /**
72
+ * Time at which the session was created (ISO 8601)
73
+ */
74
+ createdAt: string;
75
+ }
76
+ interface RecurError {
77
+ type: 'authentication_error' | 'invalid_request_error' | 'api_error';
78
+ code: string;
79
+ message: string;
80
+ details?: unknown;
81
+ }
82
+ declare class RecurAPIError extends Error {
83
+ readonly type: string;
84
+ readonly code: string;
85
+ readonly statusCode: number;
86
+ constructor(error: RecurError, statusCode: number);
87
+ }
88
+
89
+ /**
90
+ * Portal Sessions Resource
91
+ *
92
+ * Create portal sessions to allow customers to manage their subscriptions
93
+ */
94
+
95
+ declare class PortalSessions {
96
+ private config;
97
+ constructor(config: RecurConfig);
98
+ /**
99
+ * Create a portal session for a customer
100
+ *
101
+ * @param params - Portal session creation parameters
102
+ * @returns The created portal session with URL
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const session = await recur.portal.sessions.create({
107
+ * customer: 'cus_xxx',
108
+ * returnUrl: 'https://myapp.com/account',
109
+ * });
110
+ *
111
+ * // Redirect the customer to the portal
112
+ * redirect(session.url);
113
+ * ```
114
+ */
115
+ create(params: PortalSessionCreateParams): Promise<PortalSession>;
116
+ }
117
+ declare class Portal {
118
+ readonly sessions: PortalSessions;
119
+ constructor(config: RecurConfig);
120
+ }
121
+
122
+ /**
123
+ * Recur Server SDK
124
+ *
125
+ * Server-side SDK for interacting with the Recur API
126
+ * Use this in your backend (API routes, server actions, etc.)
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * import { Recur } from 'recur-tw/server';
131
+ *
132
+ * const recur = new Recur(process.env.RECUR_SECRET_KEY!);
133
+ *
134
+ * // Create a portal session
135
+ * const session = await recur.portal.sessions.create({
136
+ * customer: 'cus_xxx',
137
+ * returnUrl: 'https://myapp.com/account',
138
+ * });
139
+ * ```
140
+ */
141
+
142
+ declare class Recur {
143
+ private config;
144
+ /**
145
+ * Portal resource for managing customer portal sessions
146
+ */
147
+ readonly portal: Portal;
148
+ /**
149
+ * Create a new Recur client
150
+ *
151
+ * @param secretKey - Your Recur secret API key (sk_test_xxx or sk_live_xxx)
152
+ * @param options - Additional configuration options
153
+ */
154
+ constructor(secretKey: string, options?: Omit<RecurConfig, 'secretKey'>);
155
+ }
156
+
157
+ export { type PortalSession, type PortalSessionCreateParams, Recur, RecurAPIError, type RecurConfig, type RecurError };
package/dist/server.js ADDED
@@ -0,0 +1,114 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ // src/server/types.ts
6
+ var RecurAPIError = class extends Error {
7
+ constructor(error, statusCode) {
8
+ super(error.message);
9
+ __publicField(this, "type");
10
+ __publicField(this, "code");
11
+ __publicField(this, "statusCode");
12
+ this.name = "RecurAPIError";
13
+ this.type = error.type;
14
+ this.code = error.code;
15
+ this.statusCode = statusCode;
16
+ }
17
+ };
18
+
19
+ // src/server/resources/portal.ts
20
+ var PortalSessions = class {
21
+ constructor(config) {
22
+ __publicField(this, "config");
23
+ this.config = config;
24
+ }
25
+ /**
26
+ * Create a portal session for a customer
27
+ *
28
+ * @param params - Portal session creation parameters
29
+ * @returns The created portal session with URL
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const session = await recur.portal.sessions.create({
34
+ * customer: 'cus_xxx',
35
+ * returnUrl: 'https://myapp.com/account',
36
+ * });
37
+ *
38
+ * // Redirect the customer to the portal
39
+ * redirect(session.url);
40
+ * ```
41
+ */
42
+ async create(params) {
43
+ const baseUrl = this.config.baseUrl || "https://api.recur.tw";
44
+ const response = await fetch(`${baseUrl}/v1/portal/sessions`, {
45
+ method: "POST",
46
+ headers: {
47
+ "Authorization": `Bearer ${this.config.secretKey}`,
48
+ "Content-Type": "application/json"
49
+ },
50
+ body: JSON.stringify({
51
+ customerId: params.customer,
52
+ returnUrl: params.returnUrl,
53
+ configurationId: params.configuration,
54
+ locale: params.locale
55
+ })
56
+ });
57
+ const data = await response.json();
58
+ if (!response.ok) {
59
+ const error = data.error;
60
+ throw new RecurAPIError(error, response.status);
61
+ }
62
+ return {
63
+ id: data.id,
64
+ object: "portal.session",
65
+ url: data.url,
66
+ customer: data.customerId,
67
+ returnUrl: data.returnUrl,
68
+ status: data.status,
69
+ expiresAt: data.expiresAt,
70
+ accessedAt: data.accessedAt,
71
+ createdAt: data.createdAt
72
+ };
73
+ }
74
+ };
75
+ var Portal = class {
76
+ constructor(config) {
77
+ __publicField(this, "sessions");
78
+ this.sessions = new PortalSessions(config);
79
+ }
80
+ };
81
+
82
+ // src/server/recur.ts
83
+ var Recur = class {
84
+ /**
85
+ * Create a new Recur client
86
+ *
87
+ * @param secretKey - Your Recur secret API key (sk_test_xxx or sk_live_xxx)
88
+ * @param options - Additional configuration options
89
+ */
90
+ constructor(secretKey, options) {
91
+ __publicField(this, "config");
92
+ /**
93
+ * Portal resource for managing customer portal sessions
94
+ */
95
+ __publicField(this, "portal");
96
+ if (!secretKey) {
97
+ throw new Error(
98
+ "Recur: secretKey is required. Get your API key from your organization settings."
99
+ );
100
+ }
101
+ if (!secretKey.startsWith("sk_")) {
102
+ throw new Error(
103
+ 'Recur: Invalid API key format. Secret keys should start with "sk_". Use your secret key (sk_xxx), not your publishable key (pk_xxx).'
104
+ );
105
+ }
106
+ this.config = {
107
+ secretKey,
108
+ baseUrl: options?.baseUrl || "https://api.recur.tw"
109
+ };
110
+ this.portal = new Portal(this.config);
111
+ }
112
+ };
113
+
114
+ export { Recur, RecurAPIError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recur-tw",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "React & Vanilla JS SDK for embedding subscription checkout flows (Taiwan / PAYUNi)",
5
5
  "type": "module",
6
6
  "private": false,
@@ -45,6 +45,11 @@
45
45
  "import": "./dist/index.js",
46
46
  "require": "./dist/index.cjs"
47
47
  },
48
+ "./server": {
49
+ "types": "./dist/server.d.ts",
50
+ "import": "./dist/server.js",
51
+ "require": "./dist/server.cjs"
52
+ },
48
53
  "./vanilla": "./dist/recur.umd.js",
49
54
  "./package.json": "./package.json"
50
55
  },
@@ -82,8 +87,8 @@
82
87
  "eslint-plugin-react": "^7.37.5",
83
88
  "eslint-plugin-react-hooks": "^7.0.1",
84
89
  "postcss": "^8.5.6",
85
- "react": "^19.1.1",
86
- "react-dom": "^19.1.1",
90
+ "react": "^19.2.1",
91
+ "react-dom": "^19.2.1",
87
92
  "tailwindcss": "^4.1.11",
88
93
  "tsup": "^8.3.5",
89
94
  "typescript": "^5.9.2",