@drawbridge/drawbridge-utils 0.0.3 → 0.0.5

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