@drawbridge/drawbridge-utils 0.0.21 → 0.0.22

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,10 @@
1
+ // token.js
2
+ import crypto from "crypto";
3
+ var generate = (bytes = 32, encoding = "base64url") => {
4
+ const buf = crypto.randomBytes(bytes);
5
+ return encoding ? buf.toString(encoding) : buf;
6
+ };
7
+
8
+ export {
9
+ generate
10
+ };
@@ -1,9 +1,13 @@
1
+ import {
2
+ generate
3
+ } from "./chunk-HOA2JHXC.js";
4
+
1
5
  // encrypt.js
2
6
  import crypto from "crypto";
3
7
  var ALGORITHM = "aes-256-gcm";
4
8
  var getKey = () => Buffer.from(process.env.ENCRYPT_CONNECTION_SECRET, "hex");
5
9
  var encrypt = (value) => {
6
- const iv = crypto.randomBytes(12);
10
+ const iv = generate(12, null);
7
11
  const cipher = crypto.createCipheriv(ALGORITHM, getKey(), iv);
8
12
  const data = Buffer.concat([
9
13
  cipher.update(JSON.stringify(value), "utf8"),
package/dist/encrypt.cjs CHANGED
@@ -33,12 +33,21 @@ __export(encrypt_exports, {
33
33
  encrypt: () => encrypt
34
34
  });
35
35
  module.exports = __toCommonJS(encrypt_exports);
36
+ var import_crypto2 = __toESM(require("crypto"), 1);
37
+
38
+ // token.js
36
39
  var import_crypto = __toESM(require("crypto"), 1);
40
+ var generate = (bytes = 32, encoding = "base64url") => {
41
+ const buf = import_crypto.default.randomBytes(bytes);
42
+ return encoding ? buf.toString(encoding) : buf;
43
+ };
44
+
45
+ // encrypt.js
37
46
  var ALGORITHM = "aes-256-gcm";
38
47
  var getKey = () => Buffer.from(process.env.ENCRYPT_CONNECTION_SECRET, "hex");
39
48
  var encrypt = (value) => {
40
- const iv = import_crypto.default.randomBytes(12);
41
- const cipher = import_crypto.default.createCipheriv(ALGORITHM, getKey(), iv);
49
+ const iv = generate(12, null);
50
+ const cipher = import_crypto2.default.createCipheriv(ALGORITHM, getKey(), iv);
42
51
  const data = Buffer.concat([
43
52
  cipher.update(JSON.stringify(value), "utf8"),
44
53
  cipher.final()
@@ -49,7 +58,7 @@ var encrypt = (value) => {
49
58
  var decrypt = (value) => {
50
59
  if (typeof value !== "string") return value;
51
60
  const [ivHex, tagHex, dataHex] = value.split(":");
52
- const decipher = import_crypto.default.createDecipheriv(
61
+ const decipher = import_crypto2.default.createDecipheriv(
53
62
  ALGORITHM,
54
63
  getKey(),
55
64
  Buffer.from(ivHex, "hex")
@@ -1,4 +1,5 @@
1
1
  import crypto from 'crypto';
2
+ import { generate } from './token.cjs';
2
3
 
3
4
  const ALGORITHM = 'aes-256-gcm';
4
5
 
@@ -6,7 +7,7 @@ const getKey = () => Buffer.from( process.env.ENCRYPT_CONNECTION_SECRET, 'hex' )
6
7
 
7
8
  const encrypt = ( value ) => {
8
9
 
9
- const iv = crypto.randomBytes( 12 );
10
+ const iv = generate( 12, null );
10
11
  const cipher = crypto.createCipheriv( ALGORITHM, getKey(), iv );
11
12
  const data = Buffer.concat([
12
13
  cipher.update( JSON.stringify( value ), 'utf8' ),
package/dist/encrypt.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import crypto from 'crypto';
2
+ import { generate } from './token.js';
2
3
 
3
4
  const ALGORITHM = 'aes-256-gcm';
4
5
 
@@ -6,7 +7,7 @@ const getKey = () => Buffer.from( process.env.ENCRYPT_CONNECTION_SECRET, 'hex' )
6
7
 
7
8
  const encrypt = ( value ) => {
8
9
 
9
- const iv = crypto.randomBytes( 12 );
10
+ const iv = generate( 12, null );
10
11
  const cipher = crypto.createCipheriv( ALGORITHM, getKey(), iv );
11
12
  const data = Buffer.concat([
12
13
  cipher.update( JSON.stringify( value ), 'utf8' ),
package/dist/encrypt.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  decrypt,
3
3
  encrypt
4
- } from "./chunk-CUUQCM5T.js";
4
+ } from "./chunk-N5EMSZLI.js";
5
+ import "./chunk-HOA2JHXC.js";
5
6
  export {
6
7
  decrypt,
7
8
  encrypt
package/dist/shopify.cjs CHANGED
@@ -37,12 +37,21 @@ __export(shopify_exports, {
37
37
  module.exports = __toCommonJS(shopify_exports);
38
38
 
39
39
  // encrypt.js
40
+ var import_crypto2 = __toESM(require("crypto"), 1);
41
+
42
+ // token.js
40
43
  var import_crypto = __toESM(require("crypto"), 1);
44
+ var generate = (bytes = 32, encoding = "base64url") => {
45
+ const buf = import_crypto.default.randomBytes(bytes);
46
+ return encoding ? buf.toString(encoding) : buf;
47
+ };
48
+
49
+ // encrypt.js
41
50
  var ALGORITHM = "aes-256-gcm";
42
51
  var getKey = () => Buffer.from(process.env.ENCRYPT_CONNECTION_SECRET, "hex");
43
52
  var encrypt = (value) => {
44
- const iv = import_crypto.default.randomBytes(12);
45
- const cipher = import_crypto.default.createCipheriv(ALGORITHM, getKey(), iv);
53
+ const iv = generate(12, null);
54
+ const cipher = import_crypto2.default.createCipheriv(ALGORITHM, getKey(), iv);
46
55
  const data = Buffer.concat([
47
56
  cipher.update(JSON.stringify(value), "utf8"),
48
57
  cipher.final()
@@ -53,7 +62,7 @@ var encrypt = (value) => {
53
62
  var decrypt = (value) => {
54
63
  if (typeof value !== "string") return value;
55
64
  const [ivHex, tagHex, dataHex] = value.split(":");
56
- const decipher = import_crypto.default.createDecipheriv(
65
+ const decipher = import_crypto2.default.createDecipheriv(
57
66
  ALGORITHM,
58
67
  getKey(),
59
68
  Buffer.from(ivHex, "hex")
@@ -1,5 +1,6 @@
1
1
  import { decrypt, encrypt } from './encrypt.cjs';
2
2
  import 'crypto';
3
+ import './token.cjs';
3
4
 
4
5
  const SHOPIFY_ADMIN_API_VERSION = '2025-01';
5
6
  const REFRESH_TOKEN_LIFETIME_MS = 90 * 24 * 60 * 60 * 1000;
package/dist/shopify.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { decrypt, encrypt } from './encrypt.js';
2
2
  import 'crypto';
3
+ import './token.js';
3
4
 
4
5
  const SHOPIFY_ADMIN_API_VERSION = '2025-01';
5
6
  const REFRESH_TOKEN_LIFETIME_MS = 90 * 24 * 60 * 60 * 1000;
package/dist/shopify.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  decrypt,
3
3
  encrypt
4
- } from "./chunk-CUUQCM5T.js";
4
+ } from "./chunk-N5EMSZLI.js";
5
+ import "./chunk-HOA2JHXC.js";
5
6
 
6
7
  // shopify.js
7
8
  var SHOPIFY_ADMIN_API_VERSION = "2025-01";
package/dist/token.cjs ADDED
@@ -0,0 +1,43 @@
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
+ // token.js
30
+ var token_exports = {};
31
+ __export(token_exports, {
32
+ generate: () => generate
33
+ });
34
+ module.exports = __toCommonJS(token_exports);
35
+ var import_crypto = __toESM(require("crypto"), 1);
36
+ var generate = (bytes = 32, encoding = "base64url") => {
37
+ const buf = import_crypto.default.randomBytes(bytes);
38
+ return encoding ? buf.toString(encoding) : buf;
39
+ };
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ generate
43
+ });
@@ -0,0 +1,22 @@
1
+ import crypto from 'crypto';
2
+
3
+ // Cryptographically secure random bytes. Defaults to 32 bytes encoded as
4
+ // base64url — the shape used for unguessable shared secrets (preview tokens,
5
+ // admin tokens, share-link tokens, etc.). Pass `null` (or empty string) as
6
+ // `encoding` to receive the raw Buffer instead — used by encrypt.js for the
7
+ // AES-GCM IV.
8
+ //
9
+ // Usage:
10
+ // const { generate } = require( '@drawbridge/drawbridge-utils/token' );
11
+ // const tokenString = generate(); // 43-char base64url string
12
+ // const iv = generate( 12, null ); // 12-byte Buffer
13
+
14
+ const generate = ( bytes = 32, encoding = 'base64url' ) => {
15
+
16
+ const buf = crypto.randomBytes( bytes );
17
+
18
+ return encoding ? buf.toString( encoding ) : buf;
19
+
20
+ };
21
+
22
+ export { generate };
@@ -0,0 +1,22 @@
1
+ import crypto from 'crypto';
2
+
3
+ // Cryptographically secure random bytes. Defaults to 32 bytes encoded as
4
+ // base64url — the shape used for unguessable shared secrets (preview tokens,
5
+ // admin tokens, share-link tokens, etc.). Pass `null` (or empty string) as
6
+ // `encoding` to receive the raw Buffer instead — used by encrypt.js for the
7
+ // AES-GCM IV.
8
+ //
9
+ // Usage:
10
+ // const { generate } = require( '@drawbridge/drawbridge-utils/token' );
11
+ // const tokenString = generate(); // 43-char base64url string
12
+ // const iv = generate( 12, null ); // 12-byte Buffer
13
+
14
+ const generate = ( bytes = 32, encoding = 'base64url' ) => {
15
+
16
+ const buf = crypto.randomBytes( bytes );
17
+
18
+ return encoding ? buf.toString( encoding ) : buf;
19
+
20
+ };
21
+
22
+ export { generate };
package/dist/token.js ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ generate
3
+ } from "./chunk-HOA2JHXC.js";
4
+ export {
5
+ generate
6
+ };
package/package.json CHANGED
@@ -64,6 +64,11 @@
64
64
  "types": "./dist/slugify.d.ts",
65
65
  "import": "./dist/slugify.js",
66
66
  "require": "./dist/slugify.cjs"
67
+ },
68
+ "./token": {
69
+ "types": "./dist/token.d.ts",
70
+ "import": "./dist/token.js",
71
+ "require": "./dist/token.cjs"
67
72
  }
68
73
  },
69
74
  "files": [
@@ -81,5 +86,5 @@
81
86
  "build": "tsup && npm publish"
82
87
  },
83
88
  "types": "dist/index.d.ts",
84
- "version": "0.0.21"
89
+ "version": "0.0.22"
85
90
  }