@linkforty/mobile-sdk-react-native 1.1.1 → 1.1.2
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 +6 -2
- package/dist/LinkFortySDK.d.ts +9 -2
- package/dist/LinkFortySDK.d.ts.map +1 -1
- package/dist/LinkFortySDK.js +29 -7
- package/dist/types.d.ts +9 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/LinkFortySDK.ts +32 -8
- package/src/types.ts +9 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,12 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.1.2] - 2026-02-12
|
|
11
|
+
### Added
|
|
12
|
+
- `createLink()` method for creating short links programmatically from mobile apps via the LinkForty API
|
|
13
|
+
- `CreateLinkOptions` type — accepts optional `templateId`, `templateSlug`, `deepLinkParameters`, `title`, `description`, `customCode`, and `utmParameters`
|
|
14
|
+
|
|
10
15
|
## [1.1.1] - 2026-02-12
|
|
11
16
|
### Added
|
|
12
|
-
- `createLink()` method for creating short links programmatically from mobile apps via the LinkForty API (`POST /api/links`)
|
|
13
|
-
- `CreateLinkOptions` type — accepts `templateId`, `templateSlug`, optional `deepLinkParameters`, `title`, `description`, `customCode`, and `utmParameters`
|
|
14
17
|
- `CreateLinkResult` type — returns `url` (full shareable URL), `shortCode`, and `linkId`
|
|
15
18
|
- Exported `CreateLinkOptions` and `CreateLinkResult` types from package entry point
|
|
19
|
+
- Simplified link creation: when `templateId` is omitted, the SDK calls `POST /api/sdk/v1/links` which auto-selects the organization's default template — mobile apps no longer need to know template IDs or slugs
|
|
16
20
|
|
|
17
21
|
## [1.1.0] - 2026-02-11
|
|
18
22
|
|
package/dist/LinkFortySDK.d.ts
CHANGED
|
@@ -34,16 +34,23 @@ export declare class LinkFortySDK {
|
|
|
34
34
|
* Create a new short link via the LinkForty API.
|
|
35
35
|
*
|
|
36
36
|
* Requires an API key to be configured in the SDK init options.
|
|
37
|
+
* When `templateId` is omitted, uses the SDK endpoint which auto-selects
|
|
38
|
+
* the organization's default template and returns the full URL.
|
|
37
39
|
*
|
|
38
40
|
* @example
|
|
39
41
|
* ```ts
|
|
42
|
+
* // Simple — server auto-selects template
|
|
43
|
+
* const result = await LinkFortySDK.createLink({
|
|
44
|
+
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
45
|
+
* title: 'My Video',
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Explicit — specify template
|
|
40
49
|
* const result = await LinkFortySDK.createLink({
|
|
41
50
|
* templateId: 'uuid-of-template',
|
|
42
51
|
* templateSlug: 'ToQs',
|
|
43
52
|
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
44
|
-
* title: 'My Video',
|
|
45
53
|
* });
|
|
46
|
-
* // result.url → 'https://go.example.com/ToQs/abc123'
|
|
47
54
|
* ```
|
|
48
55
|
*/
|
|
49
56
|
createLink(options: CreateLinkOptions): Promise<CreateLinkResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkFortySDK.d.ts","sourceRoot":"","sources":["../src/LinkFortySDK.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EACV,eAAe,EAEf,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAQjB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAgC;IAC9C,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,wBAAwB,CAAyC;IACzE,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,WAAW,CAAkB;IAErC;;OAEG;IACG,IAAI,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA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,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAoEvE;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAa5C;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAchC;;OAEG;YACW,aAAa;IAW3B;;OAEG;YACW,aAAa;IA+F3B;;OAEG;YACW,eAAe;IAI7B;;OAEG;YACW,UAAU;CA+BzB;;AAGD,wBAAkC"}
|
package/dist/LinkFortySDK.js
CHANGED
|
@@ -127,16 +127,23 @@ export class LinkFortySDK {
|
|
|
127
127
|
* Create a new short link via the LinkForty API.
|
|
128
128
|
*
|
|
129
129
|
* Requires an API key to be configured in the SDK init options.
|
|
130
|
+
* When `templateId` is omitted, uses the SDK endpoint which auto-selects
|
|
131
|
+
* the organization's default template and returns the full URL.
|
|
130
132
|
*
|
|
131
133
|
* @example
|
|
132
134
|
* ```ts
|
|
135
|
+
* // Simple — server auto-selects template
|
|
136
|
+
* const result = await LinkFortySDK.createLink({
|
|
137
|
+
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
138
|
+
* title: 'My Video',
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* // Explicit — specify template
|
|
133
142
|
* const result = await LinkFortySDK.createLink({
|
|
134
143
|
* templateId: 'uuid-of-template',
|
|
135
144
|
* templateSlug: 'ToQs',
|
|
136
145
|
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
137
|
-
* title: 'My Video',
|
|
138
146
|
* });
|
|
139
|
-
* // result.url → 'https://go.example.com/ToQs/abc123'
|
|
140
147
|
* ```
|
|
141
148
|
*/
|
|
142
149
|
async createLink(options) {
|
|
@@ -146,9 +153,10 @@ export class LinkFortySDK {
|
|
|
146
153
|
if (!this.config.apiKey) {
|
|
147
154
|
throw new Error('API key required to create links. Pass apiKey in init().');
|
|
148
155
|
}
|
|
149
|
-
const body = {
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
const body = {};
|
|
157
|
+
if (options.templateId) {
|
|
158
|
+
body.templateId = options.templateId;
|
|
159
|
+
}
|
|
152
160
|
if (options.deepLinkParameters) {
|
|
153
161
|
body.deepLinkParameters = options.deepLinkParameters;
|
|
154
162
|
}
|
|
@@ -164,12 +172,26 @@ export class LinkFortySDK {
|
|
|
164
172
|
if (options.utmParameters) {
|
|
165
173
|
body.utmParameters = options.utmParameters;
|
|
166
174
|
}
|
|
167
|
-
|
|
175
|
+
// Use the simplified SDK endpoint when no templateId is provided
|
|
176
|
+
const useSimplifiedEndpoint = !options.templateId;
|
|
177
|
+
const endpoint = useSimplifiedEndpoint ? '/api/sdk/v1/links' : '/api/links';
|
|
178
|
+
const response = await this.apiRequest(endpoint, {
|
|
168
179
|
method: 'POST',
|
|
169
180
|
body: JSON.stringify(body),
|
|
170
181
|
});
|
|
182
|
+
// The SDK endpoint returns { url, shortCode, linkId } directly
|
|
183
|
+
if (useSimplifiedEndpoint && response.url) {
|
|
184
|
+
return {
|
|
185
|
+
url: response.url,
|
|
186
|
+
shortCode: response.shortCode || response.short_code,
|
|
187
|
+
linkId: response.linkId || response.id,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// The dashboard endpoint returns { id, short_code, ... } — build URL from parts
|
|
171
191
|
const shortCode = response.short_code;
|
|
172
|
-
const url =
|
|
192
|
+
const url = options.templateSlug
|
|
193
|
+
? `${this.config.baseUrl}/${options.templateSlug}/${shortCode}`
|
|
194
|
+
: `${this.config.baseUrl}/${shortCode}`;
|
|
173
195
|
if (this.config.debug) {
|
|
174
196
|
console.log('[LinkForty] Created link:', url);
|
|
175
197
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -114,13 +114,17 @@ export type DeepLinkCallback = (url: string, deepLinkData: DeepLinkData | null)
|
|
|
114
114
|
*/
|
|
115
115
|
export type ResolveFunction = (path: string) => Promise<DeepLinkData | null>;
|
|
116
116
|
/**
|
|
117
|
-
* Options for creating a new short link via the LinkForty API
|
|
117
|
+
* Options for creating a new short link via the LinkForty API.
|
|
118
|
+
*
|
|
119
|
+
* When `templateId` and `templateSlug` are omitted the SDK uses
|
|
120
|
+
* `POST /api/sdk/v1/links` which auto-selects the organization's
|
|
121
|
+
* default template and returns the full URL server-side.
|
|
118
122
|
*/
|
|
119
123
|
export interface CreateLinkOptions {
|
|
120
|
-
/** Template ID (UUID) —
|
|
121
|
-
templateId
|
|
122
|
-
/** Template slug —
|
|
123
|
-
templateSlug
|
|
124
|
+
/** Template ID (UUID) — optional; auto-selected when omitted */
|
|
125
|
+
templateId?: string;
|
|
126
|
+
/** Template slug — only needed when templateId is provided (for URL construction) */
|
|
127
|
+
templateSlug?: string;
|
|
124
128
|
/** Custom parameters embedded in the link (e.g., { route: 'VIDEO_VIEWER', id: '...' }) */
|
|
125
129
|
deepLinkParameters?: Record<string, string>;
|
|
126
130
|
/** Link title (for internal reference) */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,8EAA8E;IAC9E,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,gBAAgB,EAAE,MAAM,CAAC;IACz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B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
package/package.json
CHANGED
package/src/LinkFortySDK.ts
CHANGED
|
@@ -157,16 +157,23 @@ export class LinkFortySDK {
|
|
|
157
157
|
* Create a new short link via the LinkForty API.
|
|
158
158
|
*
|
|
159
159
|
* Requires an API key to be configured in the SDK init options.
|
|
160
|
+
* When `templateId` is omitted, uses the SDK endpoint which auto-selects
|
|
161
|
+
* the organization's default template and returns the full URL.
|
|
160
162
|
*
|
|
161
163
|
* @example
|
|
162
164
|
* ```ts
|
|
165
|
+
* // Simple — server auto-selects template
|
|
166
|
+
* const result = await LinkFortySDK.createLink({
|
|
167
|
+
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
168
|
+
* title: 'My Video',
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* // Explicit — specify template
|
|
163
172
|
* const result = await LinkFortySDK.createLink({
|
|
164
173
|
* templateId: 'uuid-of-template',
|
|
165
174
|
* templateSlug: 'ToQs',
|
|
166
175
|
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
167
|
-
* title: 'My Video',
|
|
168
176
|
* });
|
|
169
|
-
* // result.url → 'https://go.example.com/ToQs/abc123'
|
|
170
177
|
* ```
|
|
171
178
|
*/
|
|
172
179
|
async createLink(options: CreateLinkOptions): Promise<CreateLinkResult> {
|
|
@@ -178,10 +185,11 @@ export class LinkFortySDK {
|
|
|
178
185
|
throw new Error('API key required to create links. Pass apiKey in init().');
|
|
179
186
|
}
|
|
180
187
|
|
|
181
|
-
const body: Record<string, unknown> = {
|
|
182
|
-
templateId: options.templateId,
|
|
183
|
-
};
|
|
188
|
+
const body: Record<string, unknown> = {};
|
|
184
189
|
|
|
190
|
+
if (options.templateId) {
|
|
191
|
+
body.templateId = options.templateId;
|
|
192
|
+
}
|
|
185
193
|
if (options.deepLinkParameters) {
|
|
186
194
|
body.deepLinkParameters = options.deepLinkParameters;
|
|
187
195
|
}
|
|
@@ -198,16 +206,32 @@ export class LinkFortySDK {
|
|
|
198
206
|
body.utmParameters = options.utmParameters;
|
|
199
207
|
}
|
|
200
208
|
|
|
201
|
-
|
|
202
|
-
|
|
209
|
+
// Use the simplified SDK endpoint when no templateId is provided
|
|
210
|
+
const useSimplifiedEndpoint = !options.templateId;
|
|
211
|
+
const endpoint = useSimplifiedEndpoint ? '/api/sdk/v1/links' : '/api/links';
|
|
212
|
+
|
|
213
|
+
const response = await this.apiRequest<{ id: string; short_code: string; url?: string; shortCode?: string; linkId?: string }>(
|
|
214
|
+
endpoint,
|
|
203
215
|
{
|
|
204
216
|
method: 'POST',
|
|
205
217
|
body: JSON.stringify(body),
|
|
206
218
|
},
|
|
207
219
|
);
|
|
208
220
|
|
|
221
|
+
// The SDK endpoint returns { url, shortCode, linkId } directly
|
|
222
|
+
if (useSimplifiedEndpoint && response.url) {
|
|
223
|
+
return {
|
|
224
|
+
url: response.url,
|
|
225
|
+
shortCode: response.shortCode || response.short_code,
|
|
226
|
+
linkId: response.linkId || response.id,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// The dashboard endpoint returns { id, short_code, ... } — build URL from parts
|
|
209
231
|
const shortCode = response.short_code;
|
|
210
|
-
const url =
|
|
232
|
+
const url = options.templateSlug
|
|
233
|
+
? `${this.config.baseUrl}/${options.templateSlug}/${shortCode}`
|
|
234
|
+
: `${this.config.baseUrl}/${shortCode}`;
|
|
211
235
|
|
|
212
236
|
if (this.config.debug) {
|
|
213
237
|
console.log('[LinkForty] Created link:', url);
|
package/src/types.ts
CHANGED
|
@@ -123,13 +123,17 @@ export type DeepLinkCallback = (url: string, deepLinkData: DeepLinkData | null)
|
|
|
123
123
|
export type ResolveFunction = (path: string) => Promise<DeepLinkData | null>;
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
* Options for creating a new short link via the LinkForty API
|
|
126
|
+
* Options for creating a new short link via the LinkForty API.
|
|
127
|
+
*
|
|
128
|
+
* When `templateId` and `templateSlug` are omitted the SDK uses
|
|
129
|
+
* `POST /api/sdk/v1/links` which auto-selects the organization's
|
|
130
|
+
* default template and returns the full URL server-side.
|
|
127
131
|
*/
|
|
128
132
|
export interface CreateLinkOptions {
|
|
129
|
-
/** Template ID (UUID) —
|
|
130
|
-
templateId
|
|
131
|
-
/** Template slug —
|
|
132
|
-
templateSlug
|
|
133
|
+
/** Template ID (UUID) — optional; auto-selected when omitted */
|
|
134
|
+
templateId?: string;
|
|
135
|
+
/** Template slug — only needed when templateId is provided (for URL construction) */
|
|
136
|
+
templateSlug?: string;
|
|
133
137
|
/** Custom parameters embedded in the link (e.g., { route: 'VIDEO_VIEWER', id: '...' }) */
|
|
134
138
|
deepLinkParameters?: Record<string, string>;
|
|
135
139
|
/** Link title (for internal reference) */
|