@linkforty/mobile-sdk-react-native 1.1.0 → 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 +13 -0
- package/dist/LinkFortySDK.d.ts +25 -1
- package/dist/LinkFortySDK.d.ts.map +1 -1
- package/dist/LinkFortySDK.js +78 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/LinkFortySDK.ts +93 -0
- package/src/index.ts +2 -0
- package/src/types.ts +42 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
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
|
+
|
|
15
|
+
## [1.1.1] - 2026-02-12
|
|
16
|
+
### Added
|
|
17
|
+
- `CreateLinkResult` type — returns `url` (full shareable URL), `shortCode`, and `linkId`
|
|
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
|
|
20
|
+
|
|
8
21
|
## [1.1.0] - 2026-02-11
|
|
9
22
|
|
|
10
23
|
### Added
|
package/dist/LinkFortySDK.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LinkFortySDK - Main SDK class for LinkForty deep linking and attribution
|
|
3
3
|
*/
|
|
4
|
-
import type { LinkFortyConfig, DeepLinkData, DeferredDeepLinkCallback, DeepLinkCallback } from './types';
|
|
4
|
+
import type { LinkFortyConfig, DeepLinkData, DeferredDeepLinkCallback, DeepLinkCallback, CreateLinkOptions, CreateLinkResult } from './types';
|
|
5
5
|
export declare class LinkFortySDK {
|
|
6
6
|
private config;
|
|
7
7
|
private deepLinkHandler;
|
|
@@ -30,6 +30,30 @@ export declare class LinkFortySDK {
|
|
|
30
30
|
* Track in-app event
|
|
31
31
|
*/
|
|
32
32
|
trackEvent(name: string, properties?: Record<string, any>): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new short link via the LinkForty API.
|
|
35
|
+
*
|
|
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.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
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
|
|
49
|
+
* const result = await LinkFortySDK.createLink({
|
|
50
|
+
* templateId: 'uuid-of-template',
|
|
51
|
+
* templateSlug: 'ToQs',
|
|
52
|
+
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
createLink(options: CreateLinkOptions): Promise<CreateLinkResult>;
|
|
33
57
|
/**
|
|
34
58
|
* Get install ID
|
|
35
59
|
*/
|
|
@@ -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,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;IAiClD;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAQpD;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,IAAI;IAW5D;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI;IAwB5C;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC/E;;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"}
|
|
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;IAiClD;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAQpD;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,IAAI;IAW5D;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI;IAwB5C;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC/E;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,UAAU,CAAC,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
|
@@ -123,6 +123,84 @@ export class LinkFortySDK {
|
|
|
123
123
|
console.error('[LinkForty] Failed to track event:', error);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a new short link via the LinkForty API.
|
|
128
|
+
*
|
|
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.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
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
|
|
142
|
+
* const result = await LinkFortySDK.createLink({
|
|
143
|
+
* templateId: 'uuid-of-template',
|
|
144
|
+
* templateSlug: 'ToQs',
|
|
145
|
+
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
async createLink(options) {
|
|
150
|
+
if (!this.config) {
|
|
151
|
+
throw new Error('SDK not initialized. Call init() first.');
|
|
152
|
+
}
|
|
153
|
+
if (!this.config.apiKey) {
|
|
154
|
+
throw new Error('API key required to create links. Pass apiKey in init().');
|
|
155
|
+
}
|
|
156
|
+
const body = {};
|
|
157
|
+
if (options.templateId) {
|
|
158
|
+
body.templateId = options.templateId;
|
|
159
|
+
}
|
|
160
|
+
if (options.deepLinkParameters) {
|
|
161
|
+
body.deepLinkParameters = options.deepLinkParameters;
|
|
162
|
+
}
|
|
163
|
+
if (options.title) {
|
|
164
|
+
body.title = options.title;
|
|
165
|
+
}
|
|
166
|
+
if (options.description) {
|
|
167
|
+
body.description = options.description;
|
|
168
|
+
}
|
|
169
|
+
if (options.customCode) {
|
|
170
|
+
body.customCode = options.customCode;
|
|
171
|
+
}
|
|
172
|
+
if (options.utmParameters) {
|
|
173
|
+
body.utmParameters = options.utmParameters;
|
|
174
|
+
}
|
|
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, {
|
|
179
|
+
method: 'POST',
|
|
180
|
+
body: JSON.stringify(body),
|
|
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
|
|
191
|
+
const shortCode = response.short_code;
|
|
192
|
+
const url = options.templateSlug
|
|
193
|
+
? `${this.config.baseUrl}/${options.templateSlug}/${shortCode}`
|
|
194
|
+
: `${this.config.baseUrl}/${shortCode}`;
|
|
195
|
+
if (this.config.debug) {
|
|
196
|
+
console.log('[LinkForty] Created link:', url);
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
url,
|
|
200
|
+
shortCode,
|
|
201
|
+
linkId: response.id,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
126
204
|
/**
|
|
127
205
|
* Get install ID
|
|
128
206
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export { default } from './LinkFortySDK';
|
|
|
9
9
|
export { LinkFortySDK } from './LinkFortySDK';
|
|
10
10
|
export { FingerprintCollector } from './FingerprintCollector';
|
|
11
11
|
export { DeepLinkHandler } from './DeepLinkHandler';
|
|
12
|
-
export type { LinkFortyConfig, DeviceFingerprint, DeepLinkData, InstallAttributionResponse, EventData, DeferredDeepLinkCallback, DeepLinkCallback, ResolveFunction, } from './types';
|
|
12
|
+
export type { LinkFortyConfig, DeviceFingerprint, DeepLinkData, InstallAttributionResponse, EventData, DeferredDeepLinkCallback, DeepLinkCallback, ResolveFunction, CreateLinkOptions, CreateLinkResult, } from './types';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAC1B,SAAS,EACT,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,0BAA0B,EAC1B,SAAS,EACT,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,SAAS,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -113,4 +113,44 @@ export type DeepLinkCallback = (url: string, deepLinkData: DeepLinkData | null)
|
|
|
113
113
|
* before the server can process the redirect.
|
|
114
114
|
*/
|
|
115
115
|
export type ResolveFunction = (path: string) => Promise<DeepLinkData | null>;
|
|
116
|
+
/**
|
|
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.
|
|
122
|
+
*/
|
|
123
|
+
export interface CreateLinkOptions {
|
|
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;
|
|
128
|
+
/** Custom parameters embedded in the link (e.g., { route: 'VIDEO_VIEWER', id: '...' }) */
|
|
129
|
+
deepLinkParameters?: Record<string, string>;
|
|
130
|
+
/** Link title (for internal reference) */
|
|
131
|
+
title?: string;
|
|
132
|
+
/** Link description */
|
|
133
|
+
description?: string;
|
|
134
|
+
/** Custom short code (auto-generated if omitted) */
|
|
135
|
+
customCode?: string;
|
|
136
|
+
/** UTM parameters */
|
|
137
|
+
utmParameters?: {
|
|
138
|
+
source?: string;
|
|
139
|
+
medium?: string;
|
|
140
|
+
campaign?: string;
|
|
141
|
+
term?: string;
|
|
142
|
+
content?: string;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Result of creating a short link
|
|
147
|
+
*/
|
|
148
|
+
export interface CreateLinkResult {
|
|
149
|
+
/** Full shareable URL (e.g., 'https://go.example.com/tmpl/abc123') */
|
|
150
|
+
url: string;
|
|
151
|
+
/** The generated short code */
|
|
152
|
+
shortCode: string;
|
|
153
|
+
/** Link UUID */
|
|
154
|
+
linkId: string;
|
|
155
|
+
}
|
|
116
156
|
//# sourceMappingURL=types.d.ts.map
|
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;I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C;IACpB,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0FAA0F;IAC1F,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB;IACrB,aAAa,CAAC,EAAE;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,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
|
@@ -11,6 +11,8 @@ import type {
|
|
|
11
11
|
DeepLinkData,
|
|
12
12
|
DeferredDeepLinkCallback,
|
|
13
13
|
DeepLinkCallback,
|
|
14
|
+
CreateLinkOptions,
|
|
15
|
+
CreateLinkResult,
|
|
14
16
|
} from './types';
|
|
15
17
|
|
|
16
18
|
const STORAGE_KEYS = {
|
|
@@ -151,6 +153,97 @@ export class LinkFortySDK {
|
|
|
151
153
|
}
|
|
152
154
|
}
|
|
153
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Create a new short link via the LinkForty API.
|
|
158
|
+
*
|
|
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.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
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
|
|
172
|
+
* const result = await LinkFortySDK.createLink({
|
|
173
|
+
* templateId: 'uuid-of-template',
|
|
174
|
+
* templateSlug: 'ToQs',
|
|
175
|
+
* deepLinkParameters: { route: 'VIDEO_VIEWER', id: 'video-uuid' },
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
async createLink(options: CreateLinkOptions): Promise<CreateLinkResult> {
|
|
180
|
+
if (!this.config) {
|
|
181
|
+
throw new Error('SDK not initialized. Call init() first.');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!this.config.apiKey) {
|
|
185
|
+
throw new Error('API key required to create links. Pass apiKey in init().');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const body: Record<string, unknown> = {};
|
|
189
|
+
|
|
190
|
+
if (options.templateId) {
|
|
191
|
+
body.templateId = options.templateId;
|
|
192
|
+
}
|
|
193
|
+
if (options.deepLinkParameters) {
|
|
194
|
+
body.deepLinkParameters = options.deepLinkParameters;
|
|
195
|
+
}
|
|
196
|
+
if (options.title) {
|
|
197
|
+
body.title = options.title;
|
|
198
|
+
}
|
|
199
|
+
if (options.description) {
|
|
200
|
+
body.description = options.description;
|
|
201
|
+
}
|
|
202
|
+
if (options.customCode) {
|
|
203
|
+
body.customCode = options.customCode;
|
|
204
|
+
}
|
|
205
|
+
if (options.utmParameters) {
|
|
206
|
+
body.utmParameters = options.utmParameters;
|
|
207
|
+
}
|
|
208
|
+
|
|
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,
|
|
215
|
+
{
|
|
216
|
+
method: 'POST',
|
|
217
|
+
body: JSON.stringify(body),
|
|
218
|
+
},
|
|
219
|
+
);
|
|
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
|
|
231
|
+
const shortCode = response.short_code;
|
|
232
|
+
const url = options.templateSlug
|
|
233
|
+
? `${this.config.baseUrl}/${options.templateSlug}/${shortCode}`
|
|
234
|
+
: `${this.config.baseUrl}/${shortCode}`;
|
|
235
|
+
|
|
236
|
+
if (this.config.debug) {
|
|
237
|
+
console.log('[LinkForty] Created link:', url);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
url,
|
|
242
|
+
shortCode,
|
|
243
|
+
linkId: response.id,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
154
247
|
/**
|
|
155
248
|
* Get install ID
|
|
156
249
|
*/
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -121,3 +121,45 @@ export type DeepLinkCallback = (url: string, deepLinkData: DeepLinkData | null)
|
|
|
121
121
|
* before the server can process the redirect.
|
|
122
122
|
*/
|
|
123
123
|
export type ResolveFunction = (path: string) => Promise<DeepLinkData | null>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
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.
|
|
131
|
+
*/
|
|
132
|
+
export interface CreateLinkOptions {
|
|
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;
|
|
137
|
+
/** Custom parameters embedded in the link (e.g., { route: 'VIDEO_VIEWER', id: '...' }) */
|
|
138
|
+
deepLinkParameters?: Record<string, string>;
|
|
139
|
+
/** Link title (for internal reference) */
|
|
140
|
+
title?: string;
|
|
141
|
+
/** Link description */
|
|
142
|
+
description?: string;
|
|
143
|
+
/** Custom short code (auto-generated if omitted) */
|
|
144
|
+
customCode?: string;
|
|
145
|
+
/** UTM parameters */
|
|
146
|
+
utmParameters?: {
|
|
147
|
+
source?: string;
|
|
148
|
+
medium?: string;
|
|
149
|
+
campaign?: string;
|
|
150
|
+
term?: string;
|
|
151
|
+
content?: string;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Result of creating a short link
|
|
157
|
+
*/
|
|
158
|
+
export interface CreateLinkResult {
|
|
159
|
+
/** Full shareable URL (e.g., 'https://go.example.com/tmpl/abc123') */
|
|
160
|
+
url: string;
|
|
161
|
+
/** The generated short code */
|
|
162
|
+
shortCode: string;
|
|
163
|
+
/** Link UUID */
|
|
164
|
+
linkId: string;
|
|
165
|
+
}
|