@drawbridge/drawbridge-utils 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // encrypt.js
30
+ var encrypt_exports = {};
31
+ __export(encrypt_exports, {
32
+ decrypt: () => decrypt,
33
+ encrypt: () => encrypt
34
+ });
35
+ module.exports = __toCommonJS(encrypt_exports);
36
+ var import_crypto = __toESM(require("crypto"), 1);
37
+ var ALGORITHM = "aes-256-gcm";
38
+ var getKey = () => Buffer.from(process.env.ENCRYPTION_KEY, "hex");
39
+ var encrypt = (value) => {
40
+ const iv = import_crypto.default.randomBytes(12);
41
+ const cipher = import_crypto.default.createCipheriv(ALGORITHM, getKey(), iv);
42
+ const data = Buffer.concat([
43
+ cipher.update(JSON.stringify(value), "utf8"),
44
+ cipher.final()
45
+ ]);
46
+ const tag = cipher.getAuthTag();
47
+ return [iv, tag, data].map((b) => b.toString("hex")).join(":");
48
+ };
49
+ var decrypt = (value) => {
50
+ if (typeof value !== "string") return value;
51
+ const [ivHex, tagHex, dataHex] = value.split(":");
52
+ const decipher = import_crypto.default.createDecipheriv(
53
+ ALGORITHM,
54
+ getKey(),
55
+ Buffer.from(ivHex, "hex")
56
+ );
57
+ decipher.setAuthTag(Buffer.from(tagHex, "hex"));
58
+ const result = Buffer.concat([
59
+ decipher.update(Buffer.from(dataHex, "hex")),
60
+ decipher.final()
61
+ ]);
62
+ return JSON.parse(result.toString("utf8"));
63
+ };
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ decrypt,
67
+ encrypt
68
+ });
@@ -1,4 +1,4 @@
1
- const crypto = require( 'crypto' );
1
+ import crypto from 'crypto';
2
2
 
3
3
  const ALGORITHM = 'aes-256-gcm';
4
4
 
@@ -40,7 +40,4 @@ const decrypt = ( value ) => {
40
40
 
41
41
  };
42
42
 
43
- module.exports = {
44
- decrypt,
45
- encrypt
46
- };
43
+ export { decrypt, encrypt };
package/dist/encrypt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- const crypto = require( 'crypto' );
1
+ import crypto from 'crypto';
2
2
 
3
3
  const ALGORITHM = 'aes-256-gcm';
4
4
 
@@ -40,7 +40,4 @@ const decrypt = ( value ) => {
40
40
 
41
41
  };
42
42
 
43
- module.exports = {
44
- decrypt,
45
- encrypt
46
- };
43
+ export { decrypt, encrypt };
package/dist/encrypt.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // encrypt.js
2
- var crypto = require("crypto");
2
+ import crypto from "crypto";
3
3
  var ALGORITHM = "aes-256-gcm";
4
4
  var getKey = () => Buffer.from(process.env.ENCRYPTION_KEY, "hex");
5
5
  var encrypt = (value) => {
@@ -27,7 +27,7 @@ var decrypt = (value) => {
27
27
  ]);
28
28
  return JSON.parse(result.toString("utf8"));
29
29
  };
30
- module.exports = {
30
+ export {
31
31
  decrypt,
32
32
  encrypt
33
33
  };
package/dist/index.cjs ADDED
@@ -0,0 +1,407 @@
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, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[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
+ // index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ bytesToGB: () => bytesToGB,
23
+ bytesToMB: () => bytesToMB,
24
+ capitalize: () => capitalize,
25
+ constants: () => constants,
26
+ currencies: () => currencies,
27
+ currency: () => currency,
28
+ expiredPaymentMethod: () => expiredPaymentMethod,
29
+ formatCurrency: () => formatCurrency,
30
+ formatDateString: () => formatDateString,
31
+ formatNumber: () => formatNumber,
32
+ getPlanFeature: () => getPlanFeature,
33
+ gigabyte: () => gigabyte,
34
+ infinite: () => infinite,
35
+ isInfinite: () => isInfinite,
36
+ megabyte: () => megabyte,
37
+ percentage: () => percentage,
38
+ reducers: () => reducers,
39
+ regex: () => regex,
40
+ shareUrls: () => shareUrls,
41
+ urlRoot: () => urlRoot
42
+ });
43
+ module.exports = __toCommonJS(index_exports);
44
+ var import_currency_codes = require("currency-codes");
45
+
46
+ // lib/constants.js
47
+ var font = {
48
+ family: "Roboto Flex",
49
+ transform: "none",
50
+ weight: "regular"
51
+ };
52
+ var constants_default = {
53
+ action: {
54
+ usage: {
55
+ actions: 0
56
+ }
57
+ },
58
+ brand: {
59
+ style: {
60
+ body: font,
61
+ heading: font
62
+ },
63
+ totals: {
64
+ campaigns: 0
65
+ }
66
+ },
67
+ campaign: {
68
+ agreements: {
69
+ marketing: {
70
+ enabled: false,
71
+ label: "I agree to the marketing terms and conditions",
72
+ link: null
73
+ },
74
+ terms: {
75
+ enabled: false,
76
+ label: "I agree to the terms and conditions",
77
+ link: null
78
+ }
79
+ },
80
+ defaults: {
81
+ active: "Enter",
82
+ confirmation: "Submission was successful",
83
+ inactive: "Submissions are closed",
84
+ email: "You were selected"
85
+ },
86
+ notifications: {
87
+ draw: {
88
+ subject: "You have been selected",
89
+ body: "Thanks for being part of our giveaway"
90
+ }
91
+ },
92
+ settings: {
93
+ submissionLeadPrimaryKey: "email",
94
+ submissionEntryMaximum: 1,
95
+ submissionEntryFilter: "campaign",
96
+ submissionEntryHighscore: false,
97
+ submissionEntryLimit: 1
98
+ },
99
+ status: "drafted",
100
+ totals: {
101
+ advertisements: 0,
102
+ affiliates: 0,
103
+ draws: 0,
104
+ exports: 0,
105
+ entries: 0,
106
+ fields: 2,
107
+ integrations: 1,
108
+ leads: 0,
109
+ links: 0,
110
+ pages: 0,
111
+ prizes: 0,
112
+ ranges: 0,
113
+ submissions: 0
114
+ },
115
+ type: "giveaway"
116
+ },
117
+ draw: {
118
+ status: "qualified",
119
+ totals: {
120
+ notifications: 0
121
+ }
122
+ },
123
+ member: {
124
+ status: "pending"
125
+ },
126
+ organization: {
127
+ errors: [],
128
+ totals: {
129
+ affiliates: 0,
130
+ brands: 0,
131
+ campaigns: 0,
132
+ leads: 0,
133
+ draws: 0,
134
+ entries: 0,
135
+ invitations: 0,
136
+ invoices: 0,
137
+ members: 0,
138
+ ranges: 0,
139
+ pages: 0,
140
+ prizes: 0,
141
+ storage: 0,
142
+ submissions: 0,
143
+ subscriptions: 0,
144
+ usage: 0
145
+ }
146
+ },
147
+ page: {
148
+ domains: [],
149
+ status: "drafted",
150
+ totals: {
151
+ leads: 0,
152
+ entries: 0,
153
+ submissions: 0
154
+ }
155
+ },
156
+ prize: {
157
+ inventory: 0,
158
+ remaining: 0,
159
+ shipping: false,
160
+ status: "drafted",
161
+ totals: {
162
+ draws: 0
163
+ }
164
+ },
165
+ range: {
166
+ totals: {
167
+ leads: 0,
168
+ entries: 0,
169
+ submissions: 0
170
+ }
171
+ },
172
+ referrer: {
173
+ totals: {
174
+ originizations: 0,
175
+ subscriptions: 0,
176
+ users: 0
177
+ }
178
+ },
179
+ template: {
180
+ page: {
181
+ style: {
182
+ body: font,
183
+ heading: font
184
+ }
185
+ }
186
+ },
187
+ usage: {
188
+ totals: {
189
+ actions: 0,
190
+ affiliates: 0,
191
+ brands: 0,
192
+ campaigns: 0,
193
+ connections: 0,
194
+ entries: 0,
195
+ files: 0,
196
+ members: 0,
197
+ orders: 0,
198
+ pages: 0,
199
+ revenue: 0,
200
+ storage: 0,
201
+ submissions: 0,
202
+ workflows: 0
203
+ }
204
+ },
205
+ user: {
206
+ access: {
207
+ ai: false
208
+ },
209
+ image: null,
210
+ totals: {
211
+ inbox: 0,
212
+ invitations: 0,
213
+ messages: 0,
214
+ methods: 0,
215
+ organizations: 1,
216
+ teams: 0
217
+ }
218
+ }
219
+ };
220
+
221
+ // index.js
222
+ var constants = constants_default;
223
+ var infinite = 1e300;
224
+ var isInfinite = (value) => value === infinite;
225
+ var megabyte = 1024 * 1024;
226
+ var gigabyte = megabyte * 1024;
227
+ var urlRoot = (string) => (string == null ? void 0 : string.includes("https")) ? "https://" : "http://";
228
+ var bytesToGB = (bytes) => {
229
+ const divide = 1024 * 1024 * 1024;
230
+ return bytes ? Number(bytes) / divide : 0;
231
+ };
232
+ var bytesToMB = (bytes) => {
233
+ const divide = 1024 * 1024;
234
+ return bytes ? Number(bytes) / divide : 0;
235
+ };
236
+ var capitalize = (string) => {
237
+ var _a;
238
+ return ((_a = string == null ? void 0 : string.charAt(0)) == null ? void 0 : _a.toUpperCase()) + (string == null ? void 0 : string.slice(1));
239
+ };
240
+ var expiredPaymentMethod = (card) => {
241
+ const currentDate = /* @__PURE__ */ new Date();
242
+ const year = currentDate.getFullYear();
243
+ const month = (/* @__PURE__ */ new Date()).getMonth();
244
+ const expired = [
245
+ (card == null ? void 0 : card.year) < year,
246
+ (card == null ? void 0 : card.year) === year && (card == null ? void 0 : card.month) <= month
247
+ ].filter(Boolean);
248
+ return Boolean(expired == null ? void 0 : expired.length);
249
+ };
250
+ var formatCurrency = ({
251
+ code: code2 = "USD",
252
+ digits = 2,
253
+ display = "standard",
254
+ locale,
255
+ value = 0
256
+ }) => {
257
+ var _a;
258
+ const resolvedLocale = locale || (typeof navigator !== "undefined" ? navigator == null ? void 0 : navigator.language : null) || "en-US";
259
+ const options = {
260
+ currency: code2,
261
+ minimumFractionDigits: digits,
262
+ maximumFractionDigits: digits,
263
+ style: "currency"
264
+ };
265
+ if (display === "parts") {
266
+ options.currencyDisplay = "narrowSymbol";
267
+ const parts = new Intl.NumberFormat(resolvedLocale, options).formatToParts(value);
268
+ const symbol = ((_a = parts.find((p) => p.type === "currency")) == null ? void 0 : _a.value) || "";
269
+ const number = parts.filter((p) => p.type !== "currency" && p.type !== "literal").map((p) => p.value).join("");
270
+ return symbol + number + " " + code2;
271
+ }
272
+ ;
273
+ return new Intl.NumberFormat(resolvedLocale, options).format(value);
274
+ };
275
+ var formatDateString = ({
276
+ date,
277
+ locale,
278
+ time = false,
279
+ options = {
280
+ day: "numeric",
281
+ month: "long",
282
+ weekday: "long",
283
+ year: "numeric"
284
+ }
285
+ }) => {
286
+ const resolved = time ? { ...options, hour: "numeric", minute: "2-digit" } : options;
287
+ return new Date(date).toLocaleString(
288
+ locale,
289
+ resolved
290
+ );
291
+ };
292
+ var formatNumber = (number, digits = 0) => {
293
+ return Number(number).toLocaleString("en", {
294
+ minimumFractionDigits: digits,
295
+ maximumFractionDigits: digits
296
+ });
297
+ };
298
+ var getPlanFeature = (plan, key) => {
299
+ var _a, _b, _c, _d;
300
+ const error = (_b = ((_a = plan == null ? void 0 : plan.features) == null ? void 0 : _a.denied) || {}) == null ? void 0 : _b[key];
301
+ const feature = (_d = ((_c = plan == null ? void 0 : plan.features) == null ? void 0 : _c.granted) || {}) == null ? void 0 : _d[key];
302
+ const granted = Boolean(feature);
303
+ return {
304
+ granted,
305
+ message: granted ? feature : error
306
+ };
307
+ };
308
+ var percentage = (value1, value2, decimals = 1) => ((value1 || 0) / (value2 || 0) * 100 || 0).toFixed(decimals);
309
+ var reducers = {
310
+ fields: (data2 = [], callback = () => ({})) => data2.reduce(
311
+ (accumulator, field) => {
312
+ const type = field == null ? void 0 : field.type;
313
+ if (!accumulator[type]) return accumulator;
314
+ accumulator[type].items.push({
315
+ ...field,
316
+ ...callback(field)
317
+ });
318
+ accumulator[type].keys.push(field == null ? void 0 : field.slug);
319
+ return accumulator;
320
+ },
321
+ {
322
+ additional: {
323
+ items: [],
324
+ keys: []
325
+ },
326
+ lead: {
327
+ items: [],
328
+ keys: []
329
+ }
330
+ }
331
+ )
332
+ };
333
+ var regex = {
334
+ domain: /^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/,
335
+ protocols: /^(https?:\/\/)?(www\.)?/,
336
+ url: /^(https:\/\/)/
337
+ };
338
+ var shareUrls = ({
339
+ formUri,
340
+ organization,
341
+ page
342
+ }) => {
343
+ var _a;
344
+ const resolvedFormUri = formUri || (typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.APP_CLIENT_FORM_URI : void 0);
345
+ const preface = urlRoot(resolvedFormUri);
346
+ const base = resolvedFormUri;
347
+ const qr = preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId) + "?qr=1";
348
+ const short = preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId);
349
+ const url = preface + (organization == null ? void 0 : organization.subdomain) + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.slug);
350
+ const clients = [
351
+ base,
352
+ qr,
353
+ short,
354
+ url
355
+ ];
356
+ const urls = {
357
+ qr,
358
+ short,
359
+ url
360
+ };
361
+ if ((organization == null ? void 0 : organization.subdomain) && (page == null ? void 0 : page.shortId)) {
362
+ clients.push(preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId));
363
+ clients.push(preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId) + "?qr=1");
364
+ clients.push(preface + organization.subdomain + "." + (base == null ? void 0 : base.replace(preface, "")));
365
+ clients.push(preface + organization.subdomain + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId));
366
+ }
367
+ ;
368
+ if ((organization == null ? void 0 : organization.shortId) && (page == null ? void 0 : page.slug) && (page == null ? void 0 : page.shortId)) {
369
+ clients.push(preface + organization.shortId + "." + (base == null ? void 0 : base.replace(preface, "")));
370
+ clients.push(preface + organization.shortId + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.slug));
371
+ clients.push(preface + organization.shortId + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId));
372
+ }
373
+ ;
374
+ return {
375
+ clients,
376
+ urls
377
+ };
378
+ };
379
+ var currencies = import_currency_codes.data.map((item) => ({
380
+ ...item,
381
+ key: item.currency,
382
+ value: item.code
383
+ }));
384
+ var currency = (val) => (0, import_currency_codes.code)(val);
385
+ // Annotate the CommonJS export names for ESM import in node:
386
+ 0 && (module.exports = {
387
+ bytesToGB,
388
+ bytesToMB,
389
+ capitalize,
390
+ constants,
391
+ currencies,
392
+ currency,
393
+ expiredPaymentMethod,
394
+ formatCurrency,
395
+ formatDateString,
396
+ formatNumber,
397
+ getPlanFeature,
398
+ gigabyte,
399
+ infinite,
400
+ isInfinite,
401
+ megabyte,
402
+ percentage,
403
+ reducers,
404
+ regex,
405
+ shareUrls,
406
+ urlRoot
407
+ });