@cavlyn/node-sdk 0.0.0-stage → 1.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/LICENSE +202 -0
- package/README.md +177 -2
- package/dist/builder.d.ts +23 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +81 -0
- package/dist/builder.js.map +1 -0
- package/dist/client.d.ts +66 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +203 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +133 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,178 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Cavlyn Node.js Server SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official server-side library for Node.js and TypeScript to create and manage dynamic deep links and UTM campaigns, parse/decode dynamic links, configure multi-platform store routing, and send server-side attribution events.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Programmatic Dynamic Deep Link CRUD**: Create, list, inspect, update, and delete branded short links from backend services, transactional emails, SMS campaigns, or CRM webhooks.
|
|
8
|
+
- **Programmatic Campaign Creation & Querying**: Create and list UTM attribution campaigns and attach `campaignId` directly to generated deep links.
|
|
9
|
+
- **Automatic App Scoping**: `appId` is inferred automatically from your `X-API-Key` (no need to pass `appId` on every request).
|
|
10
|
+
- **Deep links for mobile apps**: Links open your app through Universal Links and App Links. What happens when the app isn't installed (App Store, Play Store or web) is configured per app in the Cavlyn dashboard, not per link.
|
|
11
|
+
- **Dynamic Link Parsing & Resolution**: Decode short codes or full dynamic link URLs into structured data, parameters, and campaign tokens.
|
|
12
|
+
- **Open Graph Preview Customizer**: Attach custom social share preview cards for WhatsApp, iMessage, Twitter, and Slack.
|
|
13
|
+
- **Server-Side Event Ingestion**: Record offline conversions, purchases, and subscriptions tied to attribution click IDs.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @cavlyn/node-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
### 1. Initialize Client
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { CavlynClient } from '@cavlyn/node-sdk'
|
|
31
|
+
|
|
32
|
+
const cavlyn = new CavlynClient({
|
|
33
|
+
apiKey: process.env.CAVLYN_API_KEY!,
|
|
34
|
+
baseUrl: 'https://api.cavlyn.com', // default; use http://localhost:8080 for local development
|
|
35
|
+
linkDomain: 'https://link.yourdomain.com', // branded short link domain used to build link.url
|
|
36
|
+
// timeoutMs: 30000, // default request timeout
|
|
37
|
+
// appId is optional — inferred automatically from X-API-Key
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
### 2. Create & List UTM Campaigns
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const campaign = await cavlyn.createCampaign({
|
|
47
|
+
name: 'Summer Drop 2026',
|
|
48
|
+
source: 'newsletter',
|
|
49
|
+
medium: 'email',
|
|
50
|
+
campaign: 'summer_promo',
|
|
51
|
+
startsAt: '2026-06-01T00:00:00Z',
|
|
52
|
+
endsAt: '2026-08-31T23:59:59Z',
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const campaigns = await cavlyn.listCampaigns()
|
|
56
|
+
const fetched = await cavlyn.getCampaign(campaign.id)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
### 3. Generate & Manage Dynamic Deep Links
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const link = await cavlyn.createDynamicLink(
|
|
65
|
+
cavlyn.newLink()
|
|
66
|
+
.setDeepPath('/products/summer-jacket')
|
|
67
|
+
.setCustomAlias('summer-sale-2026')
|
|
68
|
+
.setCampaignId(campaign.id)
|
|
69
|
+
.setUtm({
|
|
70
|
+
source: 'newsletter',
|
|
71
|
+
medium: 'email',
|
|
72
|
+
campaign: 'summer_promo',
|
|
73
|
+
})
|
|
74
|
+
.setSocialMetadata({
|
|
75
|
+
ogTitle: 'Summer Jacket - 40% Off Limited Drop',
|
|
76
|
+
ogDescription: 'Shop our top-rated jacket directly in the app with fast shipping.',
|
|
77
|
+
ogImage: 'https://cdn.yourdomain.com/images/jacket.jpg',
|
|
78
|
+
})
|
|
79
|
+
.build()
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
console.log('Dynamic Link URL:', link.url)
|
|
83
|
+
// -> "https://link.yourdomain.com/summer-sale-2026"
|
|
84
|
+
|
|
85
|
+
// List, get, update, or delete existing links
|
|
86
|
+
const allLinks = await cavlyn.listDynamicLinks()
|
|
87
|
+
const single = await cavlyn.getDynamicLink(link.id)
|
|
88
|
+
await cavlyn.updateDynamicLink(link.id, {
|
|
89
|
+
deepPath: '/products/summer-jacket-v2',
|
|
90
|
+
status: 'ACTIVE',
|
|
91
|
+
})
|
|
92
|
+
await cavlyn.deleteDynamicLink(link.id)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### 4. Parse and Resolve a Dynamic Link
|
|
98
|
+
|
|
99
|
+
When your server receives a dynamic link or short code from a webhook, referral code, or partner callback, you can parse it to extract its full context:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
const parsed = await cavlyn.parseDynamicLink('summer-sale-2026')
|
|
103
|
+
|
|
104
|
+
console.log('In-App Deep Path:', parsed.deepPath) // "/products/summer-jacket"
|
|
105
|
+
console.log('UTM Source:', parsed.queryParams.utm_source) // "newsletter"
|
|
106
|
+
console.log('Campaign ID:', parsed.campaignId)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### 5. Track Server-Side Conversions
|
|
112
|
+
|
|
113
|
+
Record conversions that happen off-device (e.g. Stripe checkout webhook, recurring SaaS subscription renewal):
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
await cavlyn.trackEvent({
|
|
117
|
+
eventType: 'CONVERSION',
|
|
118
|
+
clickId: '550e8400-e29b-41d4-a716-446655440000',
|
|
119
|
+
idempotencyKey: 'stripe_evt_1Nxyz', // optional: makes retries safe
|
|
120
|
+
revenue: 89.99,
|
|
121
|
+
currency: 'USD',
|
|
122
|
+
metadata: {
|
|
123
|
+
orderId: 'ORD-98213',
|
|
124
|
+
tier: 'premium_annual',
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Error handling
|
|
132
|
+
|
|
133
|
+
Failed requests throw `CavlynApiError` with the HTTP `status` (`0` for timeouts and network errors). Requests are not retried automatically.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { CavlynApiError } from '@cavlyn/node-sdk'
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
await cavlyn.getDynamicLink(id)
|
|
140
|
+
} catch (err) {
|
|
141
|
+
if (err instanceof CavlynApiError && err.status === 404) {
|
|
142
|
+
// not found
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Requires Node.js 18+ (global `fetch`), or pass your own `fetch` in the config.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## API Reference
|
|
152
|
+
|
|
153
|
+
### `CavlynClient`
|
|
154
|
+
|
|
155
|
+
- `newLink(): DynamicLinkBuilder`
|
|
156
|
+
- `createDynamicLink(params: CreateDynamicLinkParams): Promise<DynamicLink>`
|
|
157
|
+
- `listDynamicLinks(appId?: string): Promise<DynamicLink[]>`
|
|
158
|
+
- `getDynamicLink(linkId: string): Promise<DynamicLink>`
|
|
159
|
+
- `updateDynamicLink(linkId: string, params: UpdateDynamicLinkParams): Promise<DynamicLink>`
|
|
160
|
+
- `deleteDynamicLink(linkId: string): Promise<void>`
|
|
161
|
+
- `createCampaign(params: CreateCampaignParams): Promise<Campaign>`
|
|
162
|
+
- `listCampaigns(appId?: string): Promise<Campaign[]>`
|
|
163
|
+
- `getCampaign(campaignId: string): Promise<Campaign>`
|
|
164
|
+
- `parseDynamicLink(shortCodeOrUrl: string): Promise<ParsedDynamicLink>`
|
|
165
|
+
- `trackEvent(params: TrackServerEventParams): Promise<void>`
|
|
166
|
+
|
|
167
|
+
Events are only attributed when they carry a `linkId` or `clickId`.
|
|
168
|
+
|
|
169
|
+
### `DynamicLinkBuilder`
|
|
170
|
+
|
|
171
|
+
- `setDeepPath(path: string): this`
|
|
172
|
+
- `setCustomAlias(alias: string): this`
|
|
173
|
+
- `setCampaignId(campaignId: string): this`
|
|
174
|
+
- `setUtm(utm: UtmParameters): this`
|
|
175
|
+
- `setQuery(query: string | Record<string, string>): this`
|
|
176
|
+
- `setSocialMetadata(meta: SocialMetadata): this`
|
|
177
|
+
- `setExpiresAt(date: Date | string): this`
|
|
178
|
+
- `build(): CreateDynamicLinkParams`
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CreateDynamicLinkParams, SocialMetadata, UtmParameters } from './types.js';
|
|
2
|
+
/** Converts UTM parameters (or a raw query string) into a query string without a leading "?". */
|
|
3
|
+
export declare function toQueryString(query: string | UtmParameters): string;
|
|
4
|
+
export declare class DynamicLinkBuilder {
|
|
5
|
+
private params;
|
|
6
|
+
/** Sets the in-app route target (e.g. "/products/sneakers-99") */
|
|
7
|
+
setDeepPath(path: string): this;
|
|
8
|
+
/** Sets a custom branded alias/slug (e.g. "vip-discount") */
|
|
9
|
+
setCustomAlias(alias: string): this;
|
|
10
|
+
/** Sets campaign UTM parameters */
|
|
11
|
+
setUtm(utm: UtmParameters): this;
|
|
12
|
+
/** Sets raw query string or query object */
|
|
13
|
+
setQuery(query: string | Record<string, string>): this;
|
|
14
|
+
/** Sets Open Graph and Twitter card preview metadata */
|
|
15
|
+
setSocialMetadata(meta: SocialMetadata): this;
|
|
16
|
+
/** Sets expiration date */
|
|
17
|
+
setExpiresAt(date: Date | string): this;
|
|
18
|
+
/** Sets campaign ID */
|
|
19
|
+
setCampaignId(campaignId: string): this;
|
|
20
|
+
/** Returns the compiled parameters */
|
|
21
|
+
build(): CreateDynamicLinkParams;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAIxF,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,MAAM,CAanE;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAEb;IAED,kEAAkE;IAClE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK/B,6DAA6D;IAC7D,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKnC,mCAAmC;IACnC,MAAM,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI;IAKhC,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAatD,wDAAwD;IACxD,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAK7C,2BAA2B;IAC3B,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI;IAKvC,uBAAuB;IACvB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKvC,sCAAsC;IACtC,KAAK,IAAI,uBAAuB;CAMjC"}
|
package/dist/builder.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicLinkBuilder = void 0;
|
|
4
|
+
exports.toQueryString = toQueryString;
|
|
5
|
+
const UTM_KEYS = ['source', 'medium', 'campaign', 'term', 'content'];
|
|
6
|
+
/** Converts UTM parameters (or a raw query string) into a query string without a leading "?". */
|
|
7
|
+
function toQueryString(query) {
|
|
8
|
+
if (typeof query === 'string') {
|
|
9
|
+
return query.startsWith('?') ? query.slice(1) : query;
|
|
10
|
+
}
|
|
11
|
+
const searchParams = new URLSearchParams();
|
|
12
|
+
for (const key of UTM_KEYS) {
|
|
13
|
+
const value = query[key];
|
|
14
|
+
if (value)
|
|
15
|
+
searchParams.set(`utm_${key}`, value);
|
|
16
|
+
}
|
|
17
|
+
for (const [key, value] of Object.entries(query)) {
|
|
18
|
+
if (!UTM_KEYS.includes(key) && value)
|
|
19
|
+
searchParams.set(key, value);
|
|
20
|
+
}
|
|
21
|
+
return searchParams.toString();
|
|
22
|
+
}
|
|
23
|
+
class DynamicLinkBuilder {
|
|
24
|
+
params = {
|
|
25
|
+
deepPath: '/',
|
|
26
|
+
};
|
|
27
|
+
/** Sets the in-app route target (e.g. "/products/sneakers-99") */
|
|
28
|
+
setDeepPath(path) {
|
|
29
|
+
this.params.deepPath = path.startsWith('/') ? path : `/${path}`;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
/** Sets a custom branded alias/slug (e.g. "vip-discount") */
|
|
33
|
+
setCustomAlias(alias) {
|
|
34
|
+
this.params.customAlias = alias.trim();
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/** Sets campaign UTM parameters */
|
|
38
|
+
setUtm(utm) {
|
|
39
|
+
this.params.deepQuery = toQueryString(utm);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/** Sets raw query string or query object */
|
|
43
|
+
setQuery(query) {
|
|
44
|
+
if (typeof query === 'string') {
|
|
45
|
+
this.params.deepQuery = query.startsWith('?') ? query.slice(1) : query;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const searchParams = new URLSearchParams();
|
|
49
|
+
for (const [k, v] of Object.entries(query)) {
|
|
50
|
+
if (v !== undefined)
|
|
51
|
+
searchParams.set(k, v);
|
|
52
|
+
}
|
|
53
|
+
this.params.deepQuery = searchParams.toString();
|
|
54
|
+
}
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/** Sets Open Graph and Twitter card preview metadata */
|
|
58
|
+
setSocialMetadata(meta) {
|
|
59
|
+
this.params.metadata = meta;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/** Sets expiration date */
|
|
63
|
+
setExpiresAt(date) {
|
|
64
|
+
this.params.expiresAt = date instanceof Date ? date.toISOString() : date;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/** Sets campaign ID */
|
|
68
|
+
setCampaignId(campaignId) {
|
|
69
|
+
this.params.campaignId = campaignId;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/** Returns the compiled parameters */
|
|
73
|
+
build() {
|
|
74
|
+
if (!this.params.deepPath) {
|
|
75
|
+
throw new Error('deepPath is required when building a dynamic link');
|
|
76
|
+
}
|
|
77
|
+
return { ...this.params };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.DynamicLinkBuilder = DynamicLinkBuilder;
|
|
81
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":";;;AAKA,sCAaC;AAhBD,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AAEpE,iGAAiG;AACjG,SAAgB,aAAa,CAAC,KAA6B;IACzD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IACvD,CAAC;IACD,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAA;IAC1C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;QACxB,IAAI,KAAK;YAAE,YAAY,CAAC,GAAG,CAAC,OAAO,GAAG,EAAE,EAAE,KAAK,CAAC,CAAA;IAClD,CAAC;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK;YAAE,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACpE,CAAC;IACD,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAA;AAChC,CAAC;AAED,MAAa,kBAAkB;IACrB,MAAM,GAA4B;QACxC,QAAQ,EAAE,GAAG;KACd,CAAA;IAED,kEAAkE;IAClE,WAAW,CAAC,IAAY;QACtB,IAAI,CAAC,MAAM,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CAAC;IAED,2BAA2B;IAC3B,YAAY,CAAC,IAAmB;QAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;QACxE,OAAO,IAAI,CAAA;IACb,CAAC;IAED,uBAAuB;IACvB,aAAa,CAAC,UAAkB;QAC9B,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,UAAU,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,sCAAsC;IACtC,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;QACtE,CAAC;QACD,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;IAC3B,CAAC;CACF;AA9DD,gDA8DC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DynamicLinkBuilder } from './builder.js';
|
|
2
|
+
import type { Campaign, CreateCampaignParams, CreateDynamicLinkParams, DynamicLink, ParsedDynamicLink, CavlynConfig, TrackServerEventParams, UpdateDynamicLinkParams } from './types.js';
|
|
3
|
+
/** Thrown when the Cavlyn API returns a non-2xx response or the request times out. */
|
|
4
|
+
export declare class CavlynApiError extends Error {
|
|
5
|
+
/** HTTP status code, or 0 when no response was received (timeout / network error) */
|
|
6
|
+
readonly status: number;
|
|
7
|
+
constructor(message: string,
|
|
8
|
+
/** HTTP status code, or 0 when no response was received (timeout / network error) */
|
|
9
|
+
status: number);
|
|
10
|
+
}
|
|
11
|
+
export declare class CavlynClient {
|
|
12
|
+
private readonly timeoutMs;
|
|
13
|
+
private readonly fetchImpl;
|
|
14
|
+
private readonly apiKey;
|
|
15
|
+
private readonly baseUrl;
|
|
16
|
+
private readonly appId?;
|
|
17
|
+
private readonly linkDomain;
|
|
18
|
+
constructor(config: CavlynConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Starts a new fluent DynamicLinkBuilder
|
|
21
|
+
*/
|
|
22
|
+
newLink(): DynamicLinkBuilder;
|
|
23
|
+
/**
|
|
24
|
+
* Creates an intelligent dynamic link via the backend REST API
|
|
25
|
+
*/
|
|
26
|
+
createDynamicLink(params: CreateDynamicLinkParams): Promise<DynamicLink>;
|
|
27
|
+
/**
|
|
28
|
+
* Lists all dynamic links for the API key's app
|
|
29
|
+
*/
|
|
30
|
+
listDynamicLinks(appId?: string): Promise<DynamicLink[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets a single dynamic link by ID
|
|
33
|
+
*/
|
|
34
|
+
getDynamicLink(linkId: string): Promise<DynamicLink>;
|
|
35
|
+
/**
|
|
36
|
+
* Updates an existing dynamic link
|
|
37
|
+
*/
|
|
38
|
+
updateDynamicLink(linkId: string, params: UpdateDynamicLinkParams): Promise<DynamicLink>;
|
|
39
|
+
/**
|
|
40
|
+
* Deletes a dynamic link by ID
|
|
41
|
+
*/
|
|
42
|
+
deleteDynamicLink(linkId: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a UTM campaign via POST /api/v1/campaigns
|
|
45
|
+
*/
|
|
46
|
+
createCampaign(params: CreateCampaignParams): Promise<Campaign>;
|
|
47
|
+
/**
|
|
48
|
+
* Lists all campaigns for the API key's app
|
|
49
|
+
*/
|
|
50
|
+
listCampaigns(appId?: string): Promise<Campaign[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Gets a campaign by ID
|
|
53
|
+
*/
|
|
54
|
+
getCampaign(campaignId: string): Promise<Campaign>;
|
|
55
|
+
/**
|
|
56
|
+
* Parses and resolves an existing dynamic link by short code, slug, or full URL
|
|
57
|
+
*/
|
|
58
|
+
parseDynamicLink(shortCodeOrUrl: string): Promise<ParsedDynamicLink>;
|
|
59
|
+
/**
|
|
60
|
+
* Tracks a server-side conversion or installation event
|
|
61
|
+
*/
|
|
62
|
+
trackEvent(params: TrackServerEventParams): Promise<void>;
|
|
63
|
+
private toDynamicLink;
|
|
64
|
+
private request;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAiB,MAAM,cAAc,CAAA;AAChE,OAAO,KAAK,EACV,QAAQ,EACR,oBAAoB,EACpB,uBAAuB,EACvB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAgBnB,sFAAsF;AACtF,qBAAa,cAAe,SAAQ,KAAK;IAGrC,qFAAqF;IACrF,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAFvB,OAAO,EAAE,MAAM;IACf,qFAAqF;IAC5E,MAAM,EAAE,MAAM;CAK1B;AAKD,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;gBAEvB,MAAM,EAAE,YAAY;IAehC;;OAEG;IACH,OAAO,IAAI,kBAAkB;IAI7B;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC;IAmB9E;;OAEG;IACG,gBAAgB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAO9D;;OAEG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAK1D;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC;IAgB9F;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;OAEG;IACG,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAerE;;OAEG;IACG,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAMxD;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIxD;;OAEG;IACG,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA2B1E;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/D,OAAO,CAAC,aAAa;YAWP,OAAO;CAiCtB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CavlynClient = exports.CavlynApiError = void 0;
|
|
4
|
+
const builder_js_1 = require("./builder.js");
|
|
5
|
+
/** Thrown when the Cavlyn API returns a non-2xx response or the request times out. */
|
|
6
|
+
class CavlynApiError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
constructor(message,
|
|
9
|
+
/** HTTP status code, or 0 when no response was received (timeout / network error) */
|
|
10
|
+
status) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.name = 'CavlynApiError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.CavlynApiError = CavlynApiError;
|
|
17
|
+
const DEFAULT_BASE_URL = 'https://api.cavlyn.com';
|
|
18
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
19
|
+
class CavlynClient {
|
|
20
|
+
timeoutMs;
|
|
21
|
+
fetchImpl;
|
|
22
|
+
apiKey;
|
|
23
|
+
baseUrl;
|
|
24
|
+
appId;
|
|
25
|
+
linkDomain;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
if (!config.apiKey) {
|
|
28
|
+
throw new Error('Cavlyn: apiKey is required to initialize client');
|
|
29
|
+
}
|
|
30
|
+
this.apiKey = config.apiKey;
|
|
31
|
+
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
32
|
+
this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
33
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
34
|
+
if (typeof this.fetchImpl !== 'function') {
|
|
35
|
+
throw new Error('Cavlyn: global fetch is unavailable; use Node.js 18+ or pass config.fetch');
|
|
36
|
+
}
|
|
37
|
+
this.appId = config.appId ?? config.projectId;
|
|
38
|
+
this.linkDomain = (config.linkDomain ?? this.baseUrl).replace(/\/+$/, '');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Starts a new fluent DynamicLinkBuilder
|
|
42
|
+
*/
|
|
43
|
+
newLink() {
|
|
44
|
+
return new builder_js_1.DynamicLinkBuilder();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates an intelligent dynamic link via the backend REST API
|
|
48
|
+
*/
|
|
49
|
+
async createDynamicLink(params) {
|
|
50
|
+
const query = params.deepQuery === undefined ? undefined : (0, builder_js_1.toQueryString)(params.deepQuery);
|
|
51
|
+
const payload = {
|
|
52
|
+
appId: this.appId || undefined,
|
|
53
|
+
customAlias: params.customAlias || undefined,
|
|
54
|
+
deepPath: params.deepPath,
|
|
55
|
+
deepQuery: query || undefined,
|
|
56
|
+
expiresAt: params.expiresAt instanceof Date
|
|
57
|
+
? params.expiresAt.toISOString()
|
|
58
|
+
: params.expiresAt || undefined,
|
|
59
|
+
campaignId: params.campaignId || undefined,
|
|
60
|
+
metadata: params.metadata || undefined,
|
|
61
|
+
};
|
|
62
|
+
const raw = await this.request('POST', '/api/v1/links', payload);
|
|
63
|
+
return this.toDynamicLink(raw);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Lists all dynamic links for the API key's app
|
|
67
|
+
*/
|
|
68
|
+
async listDynamicLinks(appId) {
|
|
69
|
+
const effectiveAppId = appId ?? this.appId;
|
|
70
|
+
const qs = effectiveAppId ? `?appId=${encodeURIComponent(effectiveAppId)}` : '';
|
|
71
|
+
const raw = await this.request('GET', `/api/v1/links${qs}`);
|
|
72
|
+
return raw.map((item) => this.toDynamicLink(item));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Gets a single dynamic link by ID
|
|
76
|
+
*/
|
|
77
|
+
async getDynamicLink(linkId) {
|
|
78
|
+
const raw = await this.request('GET', `/api/v1/links/${encodeURIComponent(linkId)}`);
|
|
79
|
+
return this.toDynamicLink(raw);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Updates an existing dynamic link
|
|
83
|
+
*/
|
|
84
|
+
async updateDynamicLink(linkId, params) {
|
|
85
|
+
const query = params.deepQuery === undefined ? undefined : (0, builder_js_1.toQueryString)(params.deepQuery);
|
|
86
|
+
const payload = {
|
|
87
|
+
customAlias: params.customAlias,
|
|
88
|
+
deepPath: params.deepPath,
|
|
89
|
+
deepQuery: query,
|
|
90
|
+
expiresAt: params.expiresAt instanceof Date ? params.expiresAt.toISOString() : params.expiresAt,
|
|
91
|
+
status: params.status,
|
|
92
|
+
campaignId: params.campaignId,
|
|
93
|
+
metadata: params.metadata,
|
|
94
|
+
};
|
|
95
|
+
const raw = await this.request('PATCH', `/api/v1/links/${encodeURIComponent(linkId)}`, payload);
|
|
96
|
+
return this.toDynamicLink(raw);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Deletes a dynamic link by ID
|
|
100
|
+
*/
|
|
101
|
+
async deleteDynamicLink(linkId) {
|
|
102
|
+
await this.request('DELETE', `/api/v1/links/${encodeURIComponent(linkId)}`);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Creates a UTM campaign via POST /api/v1/campaigns
|
|
106
|
+
*/
|
|
107
|
+
async createCampaign(params) {
|
|
108
|
+
const payload = {
|
|
109
|
+
appId: params.appId ?? this.appId ?? undefined,
|
|
110
|
+
name: params.name,
|
|
111
|
+
source: params.source || undefined,
|
|
112
|
+
medium: params.medium || undefined,
|
|
113
|
+
campaign: params.campaign || undefined,
|
|
114
|
+
term: params.term || undefined,
|
|
115
|
+
content: params.content || undefined,
|
|
116
|
+
startsAt: params.startsAt instanceof Date ? params.startsAt.toISOString() : params.startsAt || undefined,
|
|
117
|
+
endsAt: params.endsAt instanceof Date ? params.endsAt.toISOString() : params.endsAt || undefined,
|
|
118
|
+
};
|
|
119
|
+
return this.request('POST', '/api/v1/campaigns', payload);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Lists all campaigns for the API key's app
|
|
123
|
+
*/
|
|
124
|
+
async listCampaigns(appId) {
|
|
125
|
+
const effectiveAppId = appId ?? this.appId;
|
|
126
|
+
const qs = effectiveAppId ? `?appId=${encodeURIComponent(effectiveAppId)}` : '';
|
|
127
|
+
return this.request('GET', `/api/v1/campaigns${qs}`);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Gets a campaign by ID
|
|
131
|
+
*/
|
|
132
|
+
async getCampaign(campaignId) {
|
|
133
|
+
return this.request('GET', `/api/v1/campaigns/${encodeURIComponent(campaignId)}`);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Parses and resolves an existing dynamic link by short code, slug, or full URL
|
|
137
|
+
*/
|
|
138
|
+
async parseDynamicLink(shortCodeOrUrl) {
|
|
139
|
+
if (!shortCodeOrUrl || !shortCodeOrUrl.trim()) {
|
|
140
|
+
throw new Error('shortCodeOrUrl is required to parse dynamic link');
|
|
141
|
+
}
|
|
142
|
+
const data = await this.request('GET', `/api/v1/links/resolve?code=${encodeURIComponent(shortCodeOrUrl.trim())}`);
|
|
143
|
+
const queryParams = {};
|
|
144
|
+
if (data.deepQuery) {
|
|
145
|
+
const search = new URLSearchParams(data.deepQuery);
|
|
146
|
+
search.forEach((value, key) => {
|
|
147
|
+
queryParams[key] = value;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const resolvedAppId = data.appId ?? data.projectId ?? '';
|
|
151
|
+
return {
|
|
152
|
+
...data,
|
|
153
|
+
appId: resolvedAppId,
|
|
154
|
+
projectId: resolvedAppId,
|
|
155
|
+
queryParams,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Tracks a server-side conversion or installation event
|
|
160
|
+
*/
|
|
161
|
+
async trackEvent(params) {
|
|
162
|
+
const { idempotencyKey, ...body } = params;
|
|
163
|
+
await this.request('POST', '/api/v1/events', body, idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined);
|
|
164
|
+
}
|
|
165
|
+
toDynamicLink(raw) {
|
|
166
|
+
const effectiveSlug = raw.customAlias || raw.shortCode;
|
|
167
|
+
const resolvedAppId = raw.appId ?? raw.projectId ?? '';
|
|
168
|
+
return {
|
|
169
|
+
...raw,
|
|
170
|
+
appId: resolvedAppId,
|
|
171
|
+
projectId: resolvedAppId,
|
|
172
|
+
url: `${this.linkDomain}/${effectiveSlug}`,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async request(method, path, body, extraHeaders) {
|
|
176
|
+
const headers = { 'X-API-Key': this.apiKey, ...extraHeaders };
|
|
177
|
+
if (body !== undefined)
|
|
178
|
+
headers['Content-Type'] = 'application/json';
|
|
179
|
+
let response;
|
|
180
|
+
try {
|
|
181
|
+
response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
182
|
+
method,
|
|
183
|
+
headers,
|
|
184
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
185
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
const reason = err instanceof Error && err.name === 'TimeoutError' ? `timed out after ${this.timeoutMs}ms` : String(err);
|
|
190
|
+
throw new CavlynApiError(`Cavlyn API ${method} ${path} failed: ${reason}`, 0);
|
|
191
|
+
}
|
|
192
|
+
if (!response.ok) {
|
|
193
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
194
|
+
throw new CavlynApiError(`Cavlyn API ${method} ${path} failed (${response.status}): ${errorBody.message ?? response.statusText}`, response.status);
|
|
195
|
+
}
|
|
196
|
+
if (response.status === 204)
|
|
197
|
+
return undefined;
|
|
198
|
+
const text = await response.text();
|
|
199
|
+
return (text ? JSON.parse(text) : undefined);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.CavlynClient = CavlynClient;
|
|
203
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,6CAAgE;AA0BhE,sFAAsF;AACtF,MAAa,cAAe,SAAQ,KAAK;IAI5B;IAHX,YACE,OAAe;IACf,qFAAqF;IAC5E,MAAc;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAA;QAFL,WAAM,GAAN,MAAM,CAAQ;QAGvB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC;CACF;AATD,wCASC;AAED,MAAM,gBAAgB,GAAG,wBAAwB,CAAA;AACjD,MAAM,kBAAkB,GAAG,MAAM,CAAA;AAEjC,MAAa,YAAY;IACN,SAAS,CAAQ;IACjB,SAAS,CAAc;IACvB,MAAM,CAAQ;IACd,OAAO,CAAQ;IACf,KAAK,CAAS;IACd,UAAU,CAAQ;IAEnC,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;QACpE,CAAC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C,IAAI,EAAE,CAAA;QAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAM,CAAA;IACnD,CAAC;CACF;AApND,oCAoNC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CavlynClient, CavlynApiError } from './client.js';
|
|
2
|
+
export { DynamicLinkBuilder } from './builder.js';
|
|
3
|
+
export type { Campaign, CavlynConfig, CreateCampaignParams, CreateDynamicLinkParams, DynamicLink, ParsedDynamicLink, SocialMetadata, TrackServerEventParams, UpdateDynamicLinkParams, UtmParameters, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,YAAY,EACV,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,uBAAuB,EACvB,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,GACd,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicLinkBuilder = exports.CavlynApiError = exports.CavlynClient = void 0;
|
|
4
|
+
var client_js_1 = require("./client.js");
|
|
5
|
+
Object.defineProperty(exports, "CavlynClient", { enumerable: true, get: function () { return client_js_1.CavlynClient; } });
|
|
6
|
+
Object.defineProperty(exports, "CavlynApiError", { enumerable: true, get: function () { return client_js_1.CavlynApiError; } });
|
|
7
|
+
var builder_js_1 = require("./builder.js");
|
|
8
|
+
Object.defineProperty(exports, "DynamicLinkBuilder", { enumerable: true, get: function () { return builder_js_1.DynamicLinkBuilder; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA0D;AAAjD,yGAAA,YAAY,OAAA;AAAE,2GAAA,cAAc,OAAA;AACrC,2CAAiD;AAAxC,gHAAA,kBAAkB,OAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export interface CavlynConfig {
|
|
2
|
+
/** API key created in the Cavlyn dashboard (App -> API Keys) */
|
|
3
|
+
apiKey: string;
|
|
4
|
+
/** Base URL of the API gateway (default: https://api.cavlyn.com) */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Optional app ID (automatically inferred from the API key when omitted) */
|
|
7
|
+
appId?: string;
|
|
8
|
+
/** @deprecated Use appId instead */
|
|
9
|
+
projectId?: string;
|
|
10
|
+
/** Optional domain to prepend to short codes (e.g., https://link.yourbrand.com) */
|
|
11
|
+
linkDomain?: string;
|
|
12
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
/** Custom fetch implementation (default: global fetch, Node.js 18+) */
|
|
15
|
+
fetch?: typeof fetch;
|
|
16
|
+
}
|
|
17
|
+
export interface SocialMetadata {
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
ogTitle?: string;
|
|
21
|
+
ogDescription?: string;
|
|
22
|
+
ogImage?: string;
|
|
23
|
+
twitterTitle?: string;
|
|
24
|
+
twitterDescription?: string;
|
|
25
|
+
twitterImage?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface UtmParameters {
|
|
28
|
+
source?: string;
|
|
29
|
+
medium?: string;
|
|
30
|
+
campaign?: string;
|
|
31
|
+
term?: string;
|
|
32
|
+
content?: string;
|
|
33
|
+
[customParam: string]: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
export interface CreateDynamicLinkParams {
|
|
36
|
+
/** Target in-app deep path (e.g., "/products/123", "/cart", "/welcome") */
|
|
37
|
+
deepPath: string;
|
|
38
|
+
/** Optional query string or UTM parameters */
|
|
39
|
+
deepQuery?: string | UtmParameters;
|
|
40
|
+
/** Custom alias / slug (e.g., "summer-sale"). If omitted, an alphanumeric code is generated */
|
|
41
|
+
customAlias?: string;
|
|
42
|
+
/** Optional expiration date */
|
|
43
|
+
expiresAt?: Date | string;
|
|
44
|
+
/** Optional campaign ID */
|
|
45
|
+
campaignId?: string;
|
|
46
|
+
/** Social Open Graph & Twitter card preview metadata */
|
|
47
|
+
metadata?: SocialMetadata;
|
|
48
|
+
}
|
|
49
|
+
export interface UpdateDynamicLinkParams {
|
|
50
|
+
customAlias?: string;
|
|
51
|
+
deepPath?: string;
|
|
52
|
+
deepQuery?: string | UtmParameters;
|
|
53
|
+
expiresAt?: Date | string;
|
|
54
|
+
status?: 'ACTIVE' | 'DISABLED';
|
|
55
|
+
campaignId?: string;
|
|
56
|
+
metadata?: SocialMetadata;
|
|
57
|
+
}
|
|
58
|
+
export interface DynamicLink {
|
|
59
|
+
id: string;
|
|
60
|
+
appId: string;
|
|
61
|
+
/** @deprecated Alias of appId for backward compatibility */
|
|
62
|
+
projectId: string;
|
|
63
|
+
shortCode: string;
|
|
64
|
+
customAlias?: string;
|
|
65
|
+
deepPath: string;
|
|
66
|
+
deepQuery?: string;
|
|
67
|
+
status: 'ACTIVE' | 'DISABLED';
|
|
68
|
+
expiresAt?: string;
|
|
69
|
+
campaignId?: string;
|
|
70
|
+
metadata?: SocialMetadata;
|
|
71
|
+
/** The full dynamic link URL ready to share (e.g., https://link.brand.com/summer-sale) */
|
|
72
|
+
url: string;
|
|
73
|
+
}
|
|
74
|
+
export interface ParsedDynamicLink {
|
|
75
|
+
id: string;
|
|
76
|
+
appId: string;
|
|
77
|
+
/** @deprecated Alias of appId for backward compatibility */
|
|
78
|
+
projectId: string;
|
|
79
|
+
shortCode: string;
|
|
80
|
+
customAlias?: string;
|
|
81
|
+
deepPath: string;
|
|
82
|
+
deepQuery?: string;
|
|
83
|
+
status: 'ACTIVE' | 'DISABLED';
|
|
84
|
+
expiresAt?: string;
|
|
85
|
+
campaignId?: string;
|
|
86
|
+
metadata?: SocialMetadata;
|
|
87
|
+
/** Parsed query parameters as a key-value record */
|
|
88
|
+
queryParams: Record<string, string>;
|
|
89
|
+
}
|
|
90
|
+
export interface CreateCampaignParams {
|
|
91
|
+
/** Human-readable campaign name */
|
|
92
|
+
name: string;
|
|
93
|
+
/** Optional app ID (inferred from API key if omitted) */
|
|
94
|
+
appId?: string;
|
|
95
|
+
/** UTM source (e.g., "instagram", "newsletter") */
|
|
96
|
+
source?: string;
|
|
97
|
+
/** UTM medium (e.g., "cpc", "email", "social") */
|
|
98
|
+
medium?: string;
|
|
99
|
+
/** UTM campaign slug (e.g., "summer_launch") */
|
|
100
|
+
campaign?: string;
|
|
101
|
+
/** UTM term */
|
|
102
|
+
term?: string;
|
|
103
|
+
/** UTM content */
|
|
104
|
+
content?: string;
|
|
105
|
+
/** Optional campaign start timestamp */
|
|
106
|
+
startsAt?: Date | string;
|
|
107
|
+
/** Optional campaign end timestamp */
|
|
108
|
+
endsAt?: Date | string;
|
|
109
|
+
}
|
|
110
|
+
export interface Campaign {
|
|
111
|
+
id: string;
|
|
112
|
+
appId: string;
|
|
113
|
+
name: string;
|
|
114
|
+
source?: string;
|
|
115
|
+
medium?: string;
|
|
116
|
+
campaign?: string;
|
|
117
|
+
term?: string;
|
|
118
|
+
content?: string;
|
|
119
|
+
startsAt?: string;
|
|
120
|
+
endsAt?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface TrackServerEventParams {
|
|
123
|
+
eventType: 'APP_OPEN' | 'INSTALL' | 'CONVERSION';
|
|
124
|
+
linkId?: string;
|
|
125
|
+
clickId?: string;
|
|
126
|
+
installationId?: string;
|
|
127
|
+
revenue?: number;
|
|
128
|
+
currency?: string;
|
|
129
|
+
metadata?: Record<string, unknown>;
|
|
130
|
+
/** Optional idempotency key (sent as the Idempotency-Key header) so retries are not double counted */
|
|
131
|
+
idempotencyKey?: string;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAA;IACd,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM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A;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,UAAU,GAAG,SAAS,GAAG,YAAY,CAAA;IAChD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,sGAAsG;IACtG,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cavlyn/node-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Server-side Node.js SDK for generating and parsing Cavlyn dynamic links, managing fallbacks, and tracking server events.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"clean": "rm -rf dist",
|
|
10
|
+
"test": "node --test tests/*.test.mjs",
|
|
11
|
+
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"dynamic-links",
|
|
15
|
+
"deep-linking",
|
|
16
|
+
"cavlyn",
|
|
17
|
+
"deferred-deep-linking",
|
|
18
|
+
"attribution",
|
|
19
|
+
"url-shortener"
|
|
20
|
+
],
|
|
21
|
+
"author": "Cavlyn System <dev@cavlyn.com>",
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.4.5",
|
|
25
|
+
"@types/node": "^20.12.7"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.0.0"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/casontek/smart-attribution-system/tree/main/sdk/nodejs#readme",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/casontek/smart-attribution-system.git",
|
|
39
|
+
"directory": "sdk/nodejs"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/casontek/smart-attribution-system/issues"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
}
|
|
47
|
+
}
|