@drawbridge/drawbridge-utils 0.0.53 → 0.0.55

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/dist/plans.cjs ADDED
@@ -0,0 +1,349 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all2) => {
6
+ for (var name in all2)
7
+ __defProp(target, name, { get: all2[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // lib/plans.js
20
+ var plans_exports = {};
21
+ __export(plans_exports, {
22
+ conversionRate: () => conversionRate,
23
+ free: () => free,
24
+ plans: () => plans
25
+ });
26
+ module.exports = __toCommonJS(plans_exports);
27
+
28
+ // lib/features.js
29
+ var page = {
30
+ qrcode: {
31
+ key: "page:qrcode",
32
+ error: "Plan does not include qrcodes",
33
+ feature: "Page qrcode management"
34
+ },
35
+ shortcode: {
36
+ key: "page:shortcode",
37
+ error: "Plan does not include shortcodes",
38
+ feature: "Page shortcode management"
39
+ },
40
+ slug: {
41
+ key: "page:slug",
42
+ error: "Plan does not include url customization",
43
+ feature: "Page slug customization"
44
+ }
45
+ };
46
+ var fields = {
47
+ additional: {
48
+ key: "campaign:fields:additional",
49
+ error: "Plan does not include additional fields",
50
+ feature: "Campaign additional fields"
51
+ },
52
+ lead: {
53
+ key: "campaign:fields:lead",
54
+ error: "Plan does not include lead fields",
55
+ feature: "Campaign lead fields"
56
+ }
57
+ };
58
+ var field = {
59
+ email: {
60
+ key: "campaign:field:email",
61
+ error: "Plan does not include email field",
62
+ feature: "Campaign email field"
63
+ },
64
+ name: {
65
+ key: "campaign:field:name",
66
+ error: "Plan does not include name field",
67
+ feature: "Campaign name field"
68
+ },
69
+ number: {
70
+ key: "campaign:field:name",
71
+ error: "Plan does not include number field",
72
+ feature: "Campaign number field"
73
+ },
74
+ phone: {
75
+ key: "campaign:field:phone",
76
+ error: "Plan does not include phone field",
77
+ feature: "Campaign phone field"
78
+ },
79
+ select: {
80
+ key: "campaign:field:select",
81
+ error: "Plan does not include dropdown field",
82
+ feature: "Campaign dropdown field"
83
+ },
84
+ text: {
85
+ key: "campaign:field:text",
86
+ error: "Plan does not include short text field",
87
+ feature: "Campaign short text field"
88
+ },
89
+ textarea: {
90
+ key: "campaign:field:textarea",
91
+ error: "Plan does not include long text field",
92
+ feature: "Campaign long text field"
93
+ }
94
+ };
95
+ var connection = {
96
+ mailchimp: {
97
+ key: "organization:connection:mailchimp",
98
+ error: "Plan does not include Mailchimp connection",
99
+ feature: "Mailchimp connection"
100
+ },
101
+ sendgrid: {
102
+ key: "organization:connection:sendgrid",
103
+ error: "Plan does not include SendGrid connection",
104
+ feature: "SendGrid connection"
105
+ },
106
+ shopify: {
107
+ key: "organization:connection:shopify",
108
+ error: "Plan does not include Shopify connection",
109
+ feature: "Shopify connection"
110
+ },
111
+ twilio: {
112
+ key: "organization:connection:twilio",
113
+ error: "Plan does not include Twilio connection",
114
+ feature: "Twilio connection"
115
+ },
116
+ webhook: {
117
+ key: "organization:connection:webhook",
118
+ error: "Plan does not include Webhook connection",
119
+ feature: "Webhook connection"
120
+ }
121
+ };
122
+ var organization = {
123
+ advertisements: {
124
+ key: "organization:advertisements",
125
+ error: "Your plan does not include advertisements",
126
+ feature: "Organization advertisement management"
127
+ },
128
+ affiliates: {
129
+ key: "organization:affiliates",
130
+ error: "Your plan does not include affiliates",
131
+ feature: "Organization affiliates management"
132
+ },
133
+ analytics: {
134
+ key: "organization:analytics",
135
+ error: "Your plan does not include analytics",
136
+ feature: "Organization analytics management"
137
+ },
138
+ brands: {
139
+ key: "organization:brands",
140
+ error: "Your plan does not include brands",
141
+ feature: "Organization brands management"
142
+ },
143
+ members: {
144
+ key: "organization:members",
145
+ error: "Your plan does not include team members",
146
+ feature: "Organization members management"
147
+ },
148
+ reports: {
149
+ key: "organization:report",
150
+ error: "Plan does not include report generation",
151
+ feature: "Organization report generation"
152
+ },
153
+ subdomain: {
154
+ key: "organization:subdomain",
155
+ error: "Plan does not include subdomain customization",
156
+ feature: "Organization subdomain customization"
157
+ }
158
+ };
159
+
160
+ // index.js
161
+ var import_currency_codes = require("currency-codes");
162
+ var import_nanoid = require("nanoid");
163
+ var nanoid = (0, import_nanoid.customAlphabet)("0123456789abcdefghijklmnopqrstuvwxyz", 8);
164
+ var infinite = 1e300;
165
+ var megabyte = 1024 * 1024;
166
+ var gigabyte = megabyte * 1024;
167
+ var currencies = import_currency_codes.data.map((item) => ({
168
+ ...item,
169
+ key: item.currency,
170
+ value: item.code
171
+ }));
172
+
173
+ // lib/plans.js
174
+ var featuresFor = (array = []) => Object.values({
175
+ ...connection,
176
+ ...organization,
177
+ ...fields,
178
+ ...field,
179
+ ...page
180
+ }).reduce(
181
+ (accumulator, { key, error, feature }) => {
182
+ if (array.includes(key)) {
183
+ accumulator.granted[key] = feature;
184
+ } else {
185
+ accumulator.denied[key] = error;
186
+ }
187
+ return accumulator;
188
+ },
189
+ { denied: {}, granted: {} }
190
+ );
191
+ var all = {
192
+ features: (array = []) => featuresFor([
193
+ connection.mailchimp.key,
194
+ connection.sendgrid.key,
195
+ connection.shopify.key,
196
+ connection.twilio.key,
197
+ connection.webhook.key,
198
+ organization.affiliates.key,
199
+ organization.brands.key,
200
+ fields.additional.key,
201
+ fields.lead.key,
202
+ field.email.key,
203
+ field.name.key,
204
+ field.number.key,
205
+ field.phone.key,
206
+ field.select.key,
207
+ field.text.key,
208
+ field.textarea.key,
209
+ page.qrcode.key,
210
+ page.shortcode.key,
211
+ ...array
212
+ ]),
213
+ limits: ({ actions, members = infinite, storage }) => ({
214
+ campaign: {
215
+ advertisements: infinite,
216
+ links: infinite,
217
+ fields: infinite,
218
+ pages: infinite
219
+ },
220
+ organization: {
221
+ actions,
222
+ affiliates: infinite,
223
+ brands: infinite,
224
+ campaigns: infinite,
225
+ members,
226
+ storage
227
+ }
228
+ })
229
+ };
230
+ var free = {
231
+ conversion: 3,
232
+ features: all.features(),
233
+ limits: all.limits({
234
+ actions: 200,
235
+ members: 0,
236
+ storage: gigabyte * 5
237
+ }),
238
+ title: "Free"
239
+ };
240
+ var plans = {
241
+ DB00002: {
242
+ features: all.features([organization.members.key]),
243
+ limits: all.limits({ actions: 5e3, members: 3, storage: gigabyte * 10 }),
244
+ marketing: {
245
+ description: "Tools to fine-tune campaigns and improve lead quality.",
246
+ features: [],
247
+ limits: [
248
+ ["Actions per month", "5,000"],
249
+ ["Affiliates", "Unlimited"],
250
+ ["Brands", "Unlimited"],
251
+ ["Campaigns", "Unlimited"],
252
+ ["Pages", "Unlimited"],
253
+ ["Members", "3"],
254
+ ["Storage", "10GB"]
255
+ ]
256
+ },
257
+ overages: { actions: "2.5" },
258
+ title: "Starter",
259
+ conversion: 2
260
+ },
261
+ DB00003: {
262
+ features: all.features([
263
+ organization.advertisements.key,
264
+ organization.analytics.key,
265
+ organization.members.key,
266
+ organization.subdomain.key,
267
+ page.slug.key
268
+ ]),
269
+ limits: all.limits({ actions: 15e3, members: 5, storage: gigabyte * 20 }),
270
+ marketing: {
271
+ description: "Expand your reach and grow your lead pipeline.",
272
+ features: [],
273
+ limits: [
274
+ ["Actions per month", "15,000"],
275
+ ["Affiliates", "Unlimited"],
276
+ ["Brands", "Unlimited"],
277
+ ["Campaigns", "Unlimited"],
278
+ ["Pages", "Unlimited"],
279
+ ["Members", "5"],
280
+ ["Storage", "20GB"]
281
+ ]
282
+ },
283
+ overages: { actions: "2" },
284
+ title: "Pro",
285
+ conversion: 1.5
286
+ },
287
+ DB00004: {
288
+ features: all.features([
289
+ organization.advertisements.key,
290
+ organization.analytics.key,
291
+ organization.members.key,
292
+ organization.subdomain.key,
293
+ page.slug.key
294
+ ]),
295
+ limits: all.limits({ actions: 4e4, members: 10, storage: gigabyte * 50 }),
296
+ marketing: {
297
+ description: "Accelerate acquisition with more power and flexibility.",
298
+ features: [],
299
+ limits: [
300
+ ["Actions per month", "40,000"],
301
+ ["Affiliates", "Unlimited"],
302
+ ["Brands", "Unlimited"],
303
+ ["Campaigns", "Unlimited"],
304
+ ["Pages", "Unlimited"],
305
+ ["Members", "10"],
306
+ ["Storage", "50GB"]
307
+ ]
308
+ },
309
+ overages: { actions: "1.85" },
310
+ title: "Premium",
311
+ conversion: 1
312
+ },
313
+ DB00005: {
314
+ features: all.features([
315
+ organization.advertisements.key,
316
+ organization.analytics.key,
317
+ organization.members.key,
318
+ organization.subdomain.key,
319
+ page.slug.key
320
+ ]),
321
+ limits: all.limits({ actions: 1e5, members: infinite, storage: gigabyte * 100 }),
322
+ marketing: {
323
+ description: "Built for brands focused on results.",
324
+ features: [],
325
+ limits: [
326
+ ["Actions per month", "100,000"],
327
+ ["Affiliates", "Unlimited"],
328
+ ["Brands", "Unlimited"],
329
+ ["Campaigns", "Unlimited"],
330
+ ["Pages", "Unlimited"],
331
+ ["Members", "Unlimited"],
332
+ ["Storage", "100GB"]
333
+ ]
334
+ },
335
+ overages: { actions: "1.5" },
336
+ title: "Elite",
337
+ conversion: 0.5
338
+ }
339
+ };
340
+ var conversionRate = (subscription) => {
341
+ var _a;
342
+ return (subscription == null ? void 0 : subscription.conversion) ?? ((_a = plans[subscription == null ? void 0 : subscription.plan]) == null ? void 0 : _a.conversion) ?? free.conversion;
343
+ };
344
+ // Annotate the CommonJS export names for ESM import in node:
345
+ 0 && (module.exports = {
346
+ conversionRate,
347
+ free,
348
+ plans
349
+ });
@@ -0,0 +1,192 @@
1
+ import { organization, page, connection, fields, field } from './features.cjs';
2
+ import { infinite, gigabyte } from './index.cjs';
3
+ import 'currency-codes';
4
+ import 'nanoid';
5
+
6
+ const featuresFor = ( array = [] ) => Object.values({
7
+ ...connection,
8
+ ...organization,
9
+ ...fields,
10
+ ...field,
11
+ ...page
12
+ }).reduce(
13
+ ( accumulator, { key, error, feature } ) => {
14
+
15
+ if( array.includes( key ) ){
16
+
17
+ accumulator.granted[ key ] = feature;
18
+
19
+ } else {
20
+
21
+ accumulator.denied[ key ] = error;
22
+
23
+ }
24
+
25
+ return accumulator;
26
+
27
+ },
28
+ { denied : {}, granted : {} }
29
+ );
30
+
31
+ const all = {
32
+ features : ( array = [] ) => featuresFor([
33
+ connection.mailchimp.key,
34
+ connection.sendgrid.key,
35
+ connection.shopify.key,
36
+ connection.twilio.key,
37
+ connection.webhook.key,
38
+ organization.affiliates.key,
39
+ organization.brands.key,
40
+ fields.additional.key,
41
+ fields.lead.key,
42
+ field.email.key,
43
+ field.name.key,
44
+ field.number.key,
45
+ field.phone.key,
46
+ field.select.key,
47
+ field.text.key,
48
+ field.textarea.key,
49
+ page.qrcode.key,
50
+ page.shortcode.key,
51
+ ...array
52
+ ]),
53
+ limits : ({ actions, members = infinite, storage }) => ({
54
+ campaign : {
55
+ advertisements : infinite,
56
+ links : infinite,
57
+ fields : infinite,
58
+ pages : infinite
59
+ },
60
+ organization : {
61
+ actions,
62
+ affiliates : infinite,
63
+ brands : infinite,
64
+ campaigns : infinite,
65
+ members,
66
+ storage
67
+ }
68
+ })
69
+ };
70
+
71
+ const free = {
72
+ conversion : 3,
73
+ features : all.features(),
74
+ limits : all.limits({
75
+ actions : 200,
76
+ members : 0,
77
+ storage : gigabyte * 5
78
+ }),
79
+ title : 'Free'
80
+ };
81
+
82
+ const plans = {
83
+ DB00002 : {
84
+ features : all.features([ organization.members.key ]),
85
+ limits : all.limits({ actions : 5000, members : 3, storage : gigabyte * 10 }),
86
+ marketing : {
87
+ description : 'Tools to fine-tune campaigns and improve lead quality.',
88
+ features : [],
89
+ limits : [
90
+ [ 'Actions per month', '5,000' ],
91
+ [ 'Affiliates', 'Unlimited' ],
92
+ [ 'Brands', 'Unlimited' ],
93
+ [ 'Campaigns', 'Unlimited' ],
94
+ [ 'Pages', 'Unlimited' ],
95
+ [ 'Members', '3' ],
96
+ [ 'Storage', '10GB' ]
97
+ ]
98
+ },
99
+ overages : { actions : '2.5' },
100
+ title : 'Starter',
101
+ conversion : 2
102
+ },
103
+ DB00003 : {
104
+ features : all.features([
105
+ organization.advertisements.key,
106
+ organization.analytics.key,
107
+ organization.members.key,
108
+ organization.subdomain.key,
109
+ page.slug.key
110
+ ]),
111
+ limits : all.limits({ actions : 15000, members : 5, storage : gigabyte * 20 }),
112
+ marketing : {
113
+ description : 'Expand your reach and grow your lead pipeline.',
114
+ features : [],
115
+ limits : [
116
+ [ 'Actions per month', '15,000' ],
117
+ [ 'Affiliates', 'Unlimited' ],
118
+ [ 'Brands', 'Unlimited' ],
119
+ [ 'Campaigns', 'Unlimited' ],
120
+ [ 'Pages', 'Unlimited' ],
121
+ [ 'Members', '5' ],
122
+ [ 'Storage', '20GB' ]
123
+ ]
124
+ },
125
+ overages : { actions : '2' },
126
+ title : 'Pro',
127
+ conversion : 1.5
128
+ },
129
+ DB00004 : {
130
+ features : all.features([
131
+ organization.advertisements.key,
132
+ organization.analytics.key,
133
+ organization.members.key,
134
+ organization.subdomain.key,
135
+ page.slug.key
136
+ ]),
137
+ limits : all.limits({ actions : 40000, members : 10, storage : gigabyte * 50 }),
138
+ marketing : {
139
+ description : 'Accelerate acquisition with more power and flexibility.',
140
+ features : [],
141
+ limits : [
142
+ [ 'Actions per month', '40,000' ],
143
+ [ 'Affiliates', 'Unlimited' ],
144
+ [ 'Brands', 'Unlimited' ],
145
+ [ 'Campaigns', 'Unlimited' ],
146
+ [ 'Pages', 'Unlimited' ],
147
+ [ 'Members', '10' ],
148
+ [ 'Storage', '50GB' ]
149
+ ]
150
+ },
151
+ overages : { actions : '1.85' },
152
+ title : 'Premium',
153
+ conversion : 1
154
+ },
155
+ DB00005 : {
156
+ features : all.features([
157
+ organization.advertisements.key,
158
+ organization.analytics.key,
159
+ organization.members.key,
160
+ organization.subdomain.key,
161
+ page.slug.key
162
+ ]),
163
+ limits : all.limits({ actions : 100000, members : infinite, storage : gigabyte * 100 }),
164
+ marketing : {
165
+ description : 'Built for brands focused on results.',
166
+ features : [],
167
+ limits : [
168
+ [ 'Actions per month', '100,000' ],
169
+ [ 'Affiliates', 'Unlimited' ],
170
+ [ 'Brands', 'Unlimited' ],
171
+ [ 'Campaigns', 'Unlimited' ],
172
+ [ 'Pages', 'Unlimited' ],
173
+ [ 'Members', 'Unlimited' ],
174
+ [ 'Storage', '100GB' ]
175
+ ]
176
+ },
177
+ overages : { actions : '1.5' },
178
+ title : 'Elite',
179
+ conversion : 0.5
180
+ }
181
+ };
182
+
183
+ // Resolve the conversion-fee percentage for an order's owning org.
184
+ // Precedence: explicit per-subscription override (admin/negotiated) →
185
+ // the plan's catalog default → the free-org rate. `subscription` is null
186
+ // for free orgs (they have no subscription doc).
187
+ const conversionRate = ( subscription ) =>
188
+ subscription?.conversion
189
+ ?? plans[ subscription?.plan ]?.conversion
190
+ ?? free.conversion;
191
+
192
+ export { conversionRate, free, plans };