@drawbridge/drawbridge-utils 0.0.20 → 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.
- package/dist/chunk-HOA2JHXC.js +10 -0
- package/dist/{chunk-CUUQCM5T.js → chunk-N5EMSZLI.js} +5 -1
- package/dist/encrypt.cjs +12 -3
- package/dist/encrypt.d.cts +2 -1
- package/dist/encrypt.d.ts +2 -1
- package/dist/encrypt.js +2 -1
- package/dist/shopify.cjs +16 -5
- package/dist/shopify.d.cts +4 -3
- package/dist/shopify.d.ts +4 -3
- package/dist/shopify.js +5 -3
- package/dist/token.cjs +43 -0
- package/dist/token.d.cts +22 -0
- package/dist/token.d.ts +22 -0
- package/dist/token.js +6 -0
- package/package.json +6 -1
|
@@ -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 =
|
|
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 =
|
|
41
|
-
const cipher =
|
|
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 =
|
|
61
|
+
const decipher = import_crypto2.default.createDecipheriv(
|
|
53
62
|
ALGORITHM,
|
|
54
63
|
getKey(),
|
|
55
64
|
Buffer.from(ivHex, "hex")
|
package/dist/encrypt.d.cts
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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
package/dist/shopify.cjs
CHANGED
|
@@ -30,18 +30,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var shopify_exports = {};
|
|
31
31
|
__export(shopify_exports, {
|
|
32
32
|
getAdminToken: () => getAdminToken,
|
|
33
|
+
ping: () => ping,
|
|
33
34
|
refreshAdminToken: () => refreshAdminToken,
|
|
34
35
|
resolveConnectionSettings: () => resolveConnectionSettings
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(shopify_exports);
|
|
37
38
|
|
|
38
39
|
// encrypt.js
|
|
40
|
+
var import_crypto2 = __toESM(require("crypto"), 1);
|
|
41
|
+
|
|
42
|
+
// token.js
|
|
39
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
|
|
40
50
|
var ALGORITHM = "aes-256-gcm";
|
|
41
51
|
var getKey = () => Buffer.from(process.env.ENCRYPT_CONNECTION_SECRET, "hex");
|
|
42
52
|
var encrypt = (value) => {
|
|
43
|
-
const iv =
|
|
44
|
-
const cipher =
|
|
53
|
+
const iv = generate(12, null);
|
|
54
|
+
const cipher = import_crypto2.default.createCipheriv(ALGORITHM, getKey(), iv);
|
|
45
55
|
const data = Buffer.concat([
|
|
46
56
|
cipher.update(JSON.stringify(value), "utf8"),
|
|
47
57
|
cipher.final()
|
|
@@ -52,7 +62,7 @@ var encrypt = (value) => {
|
|
|
52
62
|
var decrypt = (value) => {
|
|
53
63
|
if (typeof value !== "string") return value;
|
|
54
64
|
const [ivHex, tagHex, dataHex] = value.split(":");
|
|
55
|
-
const decipher =
|
|
65
|
+
const decipher = import_crypto2.default.createDecipheriv(
|
|
56
66
|
ALGORITHM,
|
|
57
67
|
getKey(),
|
|
58
68
|
Buffer.from(ivHex, "hex")
|
|
@@ -85,7 +95,7 @@ var shopifyOAuthFetch = async (url, body) => {
|
|
|
85
95
|
}
|
|
86
96
|
return response.json();
|
|
87
97
|
};
|
|
88
|
-
var
|
|
98
|
+
var ping = async ({ adminAccessToken, domain }) => {
|
|
89
99
|
const response = await fetch(
|
|
90
100
|
`https://${domain}/admin/api/${SHOPIFY_ADMIN_API_VERSION}/shop.json`,
|
|
91
101
|
{
|
|
@@ -146,7 +156,7 @@ var refreshAdminToken = async ({ connection, controller }) => {
|
|
|
146
156
|
const expiresIn = data.expires_in;
|
|
147
157
|
const tokenExpiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1e3) : null;
|
|
148
158
|
const refreshTokenExpiresAt = new Date(Date.now() + REFRESH_TOKEN_LIFETIME_MS);
|
|
149
|
-
await
|
|
159
|
+
await ping({ adminAccessToken, domain });
|
|
150
160
|
await controller.update({
|
|
151
161
|
collection: "credential",
|
|
152
162
|
data: {
|
|
@@ -187,6 +197,7 @@ var getAdminToken = async ({ connection, controller }) => {
|
|
|
187
197
|
// Annotate the CommonJS export names for ESM import in node:
|
|
188
198
|
0 && (module.exports = {
|
|
189
199
|
getAdminToken,
|
|
200
|
+
ping,
|
|
190
201
|
refreshAdminToken,
|
|
191
202
|
resolveConnectionSettings
|
|
192
203
|
});
|
package/dist/shopify.d.cts
CHANGED
|
@@ -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;
|
|
@@ -30,7 +31,7 @@ const shopifyOAuthFetch = async ( url, body ) => {
|
|
|
30
31
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
const
|
|
34
|
+
const ping = async ({ adminAccessToken, domain }) => {
|
|
34
35
|
|
|
35
36
|
const response = await fetch(
|
|
36
37
|
`https://${ domain }/admin/api/${ SHOPIFY_ADMIN_API_VERSION }/shop.json`,
|
|
@@ -114,7 +115,7 @@ const refreshAdminToken = async ({ connection, controller }) => {
|
|
|
114
115
|
const tokenExpiresAt = expiresIn ? new Date( Date.now() + ( expiresIn * 1000 ) ) : null;
|
|
115
116
|
const refreshTokenExpiresAt = new Date( Date.now() + REFRESH_TOKEN_LIFETIME_MS );
|
|
116
117
|
|
|
117
|
-
await
|
|
118
|
+
await ping({ adminAccessToken, domain });
|
|
118
119
|
|
|
119
120
|
await controller.update({
|
|
120
121
|
collection : 'credential',
|
|
@@ -165,4 +166,4 @@ const getAdminToken = async ({ connection, controller }) => {
|
|
|
165
166
|
|
|
166
167
|
};
|
|
167
168
|
|
|
168
|
-
export { getAdminToken, refreshAdminToken, resolveConnectionSettings };
|
|
169
|
+
export { getAdminToken, ping, refreshAdminToken, resolveConnectionSettings };
|
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;
|
|
@@ -30,7 +31,7 @@ const shopifyOAuthFetch = async ( url, body ) => {
|
|
|
30
31
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
const
|
|
34
|
+
const ping = async ({ adminAccessToken, domain }) => {
|
|
34
35
|
|
|
35
36
|
const response = await fetch(
|
|
36
37
|
`https://${ domain }/admin/api/${ SHOPIFY_ADMIN_API_VERSION }/shop.json`,
|
|
@@ -114,7 +115,7 @@ const refreshAdminToken = async ({ connection, controller }) => {
|
|
|
114
115
|
const tokenExpiresAt = expiresIn ? new Date( Date.now() + ( expiresIn * 1000 ) ) : null;
|
|
115
116
|
const refreshTokenExpiresAt = new Date( Date.now() + REFRESH_TOKEN_LIFETIME_MS );
|
|
116
117
|
|
|
117
|
-
await
|
|
118
|
+
await ping({ adminAccessToken, domain });
|
|
118
119
|
|
|
119
120
|
await controller.update({
|
|
120
121
|
collection : 'credential',
|
|
@@ -165,4 +166,4 @@ const getAdminToken = async ({ connection, controller }) => {
|
|
|
165
166
|
|
|
166
167
|
};
|
|
167
168
|
|
|
168
|
-
export { getAdminToken, refreshAdminToken, resolveConnectionSettings };
|
|
169
|
+
export { getAdminToken, ping, refreshAdminToken, resolveConnectionSettings };
|
package/dist/shopify.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
decrypt,
|
|
3
3
|
encrypt
|
|
4
|
-
} from "./chunk-
|
|
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";
|
|
@@ -23,7 +24,7 @@ var shopifyOAuthFetch = async (url, body) => {
|
|
|
23
24
|
}
|
|
24
25
|
return response.json();
|
|
25
26
|
};
|
|
26
|
-
var
|
|
27
|
+
var ping = async ({ adminAccessToken, domain }) => {
|
|
27
28
|
const response = await fetch(
|
|
28
29
|
`https://${domain}/admin/api/${SHOPIFY_ADMIN_API_VERSION}/shop.json`,
|
|
29
30
|
{
|
|
@@ -84,7 +85,7 @@ var refreshAdminToken = async ({ connection, controller }) => {
|
|
|
84
85
|
const expiresIn = data.expires_in;
|
|
85
86
|
const tokenExpiresAt = expiresIn ? new Date(Date.now() + expiresIn * 1e3) : null;
|
|
86
87
|
const refreshTokenExpiresAt = new Date(Date.now() + REFRESH_TOKEN_LIFETIME_MS);
|
|
87
|
-
await
|
|
88
|
+
await ping({ adminAccessToken, domain });
|
|
88
89
|
await controller.update({
|
|
89
90
|
collection: "credential",
|
|
90
91
|
data: {
|
|
@@ -124,6 +125,7 @@ var getAdminToken = async ({ connection, controller }) => {
|
|
|
124
125
|
};
|
|
125
126
|
export {
|
|
126
127
|
getAdminToken,
|
|
128
|
+
ping,
|
|
127
129
|
refreshAdminToken,
|
|
128
130
|
resolveConnectionSettings
|
|
129
131
|
};
|
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
|
+
});
|
package/dist/token.d.cts
ADDED
|
@@ -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.d.ts
ADDED
|
@@ -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
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.
|
|
89
|
+
"version": "0.0.22"
|
|
85
90
|
}
|