@thirdweb-dev/service-utils 0.2.0-nightly-f7392138-20230714100149 → 0.2.0-nightly-781e26d8-20230714165556

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-f45a96ee.cjs.dev.js');
5
+ var index = require('../../dist/index-ded83ecc.cjs.dev.js');
6
6
  var services = require('../../dist/services-a3f36057.cjs.dev.js');
7
7
 
8
8
  const DEFAULT_CACHE_TTL_SECONDS = 60;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-8a3bbee6.cjs.prod.js');
5
+ var index = require('../../dist/index-bc2b86a5.cjs.prod.js');
6
6
  var services = require('../../dist/services-9e185105.cjs.prod.js');
7
7
 
8
8
  const DEFAULT_CACHE_TTL_SECONDS = 60;
@@ -1,4 +1,4 @@
1
- import { a as authorize } from '../../dist/index-bdbd7887.esm.js';
1
+ import { a as authorize } from '../../dist/index-1125bae0.esm.js';
2
2
  export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
3
3
 
4
4
  const DEFAULT_CACHE_TTL_SECONDS = 60;
@@ -23,10 +23,12 @@ async function fetchKeyMetadataFromApi(clientId, config) {
23
23
  function authorizeClient(authOptions, apiKeyMeta) {
24
24
  const {
25
25
  origin,
26
+ bundleId,
26
27
  secretKeyHash: providedSecretHash
27
28
  } = authOptions;
28
29
  const {
29
30
  domains,
31
+ bundleIds,
30
32
  secretHash
31
33
  } = apiKeyMeta;
32
34
  if (providedSecretHash) {
@@ -76,7 +78,28 @@ function authorizeClient(authOptions, apiKeyMeta) {
76
78
  };
77
79
  }
78
80
 
79
- // FIXME: validate bundle id
81
+ // validate bundleId
82
+ if (bundleId) {
83
+ if (
84
+ // find matching bundle id, or if all bundles allowed
85
+ bundleIds.find(b => {
86
+ if (b === "*") {
87
+ return true;
88
+ }
89
+ return b === bundleId;
90
+ })) {
91
+ return {
92
+ authorized: true,
93
+ apiKeyMeta
94
+ };
95
+ }
96
+ return {
97
+ authorized: false,
98
+ errorMessage: "The bundle is not authorized for this key.",
99
+ errorCode: "BUNDLE_UNAUTHORIZED",
100
+ status: 401
101
+ };
102
+ }
80
103
  return {
81
104
  authorized: false,
82
105
  errorMessage: "The keys are invalid.",
@@ -85,10 +108,10 @@ function authorizeClient(authOptions, apiKeyMeta) {
85
108
  };
86
109
  }
87
110
 
88
- function authorizeService(apikeyMetadata, serviceConfig, authorizationPayload) {
111
+ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
89
112
  const {
90
113
  services
91
- } = apikeyMetadata;
114
+ } = apiKeyMetadata;
92
115
  // const { serviceTargetAddresses, serviceAction } = validations;
93
116
 
94
117
  // validate services
@@ -130,7 +153,7 @@ function authorizeService(apikeyMetadata, serviceConfig, authorizationPayload) {
130
153
  }
131
154
  return {
132
155
  authorized: true,
133
- apiKeyMeta: apikeyMetadata
156
+ apiKeyMeta: apiKeyMetadata
134
157
  };
135
158
  }
136
159
 
@@ -25,10 +25,12 @@ async function fetchKeyMetadataFromApi(clientId, config) {
25
25
  function authorizeClient(authOptions, apiKeyMeta) {
26
26
  const {
27
27
  origin,
28
+ bundleId,
28
29
  secretKeyHash: providedSecretHash
29
30
  } = authOptions;
30
31
  const {
31
32
  domains,
33
+ bundleIds,
32
34
  secretHash
33
35
  } = apiKeyMeta;
34
36
  if (providedSecretHash) {
@@ -78,7 +80,28 @@ function authorizeClient(authOptions, apiKeyMeta) {
78
80
  };
79
81
  }
80
82
 
81
- // FIXME: validate bundle id
83
+ // validate bundleId
84
+ if (bundleId) {
85
+ if (
86
+ // find matching bundle id, or if all bundles allowed
87
+ bundleIds.find(b => {
88
+ if (b === "*") {
89
+ return true;
90
+ }
91
+ return b === bundleId;
92
+ })) {
93
+ return {
94
+ authorized: true,
95
+ apiKeyMeta
96
+ };
97
+ }
98
+ return {
99
+ authorized: false,
100
+ errorMessage: "The bundle is not authorized for this key.",
101
+ errorCode: "BUNDLE_UNAUTHORIZED",
102
+ status: 401
103
+ };
104
+ }
82
105
  return {
83
106
  authorized: false,
84
107
  errorMessage: "The keys are invalid.",
@@ -87,10 +110,10 @@ function authorizeClient(authOptions, apiKeyMeta) {
87
110
  };
88
111
  }
89
112
 
90
- function authorizeService(apikeyMetadata, serviceConfig, authorizationPayload) {
113
+ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
91
114
  const {
92
115
  services
93
- } = apikeyMetadata;
116
+ } = apiKeyMetadata;
94
117
  // const { serviceTargetAddresses, serviceAction } = validations;
95
118
 
96
119
  // validate services
@@ -132,7 +155,7 @@ function authorizeService(apikeyMetadata, serviceConfig, authorizationPayload) {
132
155
  }
133
156
  return {
134
157
  authorized: true,
135
- apiKeyMeta: apikeyMetadata
158
+ apiKeyMeta: apiKeyMetadata
136
159
  };
137
160
  }
138
161
 
@@ -25,10 +25,12 @@ async function fetchKeyMetadataFromApi(clientId, config) {
25
25
  function authorizeClient(authOptions, apiKeyMeta) {
26
26
  const {
27
27
  origin,
28
+ bundleId,
28
29
  secretKeyHash: providedSecretHash
29
30
  } = authOptions;
30
31
  const {
31
32
  domains,
33
+ bundleIds,
32
34
  secretHash
33
35
  } = apiKeyMeta;
34
36
  if (providedSecretHash) {
@@ -78,7 +80,28 @@ function authorizeClient(authOptions, apiKeyMeta) {
78
80
  };
79
81
  }
80
82
 
81
- // FIXME: validate bundle id
83
+ // validate bundleId
84
+ if (bundleId) {
85
+ if (
86
+ // find matching bundle id, or if all bundles allowed
87
+ bundleIds.find(b => {
88
+ if (b === "*") {
89
+ return true;
90
+ }
91
+ return b === bundleId;
92
+ })) {
93
+ return {
94
+ authorized: true,
95
+ apiKeyMeta
96
+ };
97
+ }
98
+ return {
99
+ authorized: false,
100
+ errorMessage: "The bundle is not authorized for this key.",
101
+ errorCode: "BUNDLE_UNAUTHORIZED",
102
+ status: 401
103
+ };
104
+ }
82
105
  return {
83
106
  authorized: false,
84
107
  errorMessage: "The keys are invalid.",
@@ -87,10 +110,10 @@ function authorizeClient(authOptions, apiKeyMeta) {
87
110
  };
88
111
  }
89
112
 
90
- function authorizeService(apikeyMetadata, serviceConfig, authorizationPayload) {
113
+ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
91
114
  const {
92
115
  services
93
- } = apikeyMetadata;
116
+ } = apiKeyMetadata;
94
117
  // const { serviceTargetAddresses, serviceAction } = validations;
95
118
 
96
119
  // validate services
@@ -132,7 +155,7 @@ function authorizeService(apikeyMetadata, serviceConfig, authorizationPayload) {
132
155
  }
133
156
  return {
134
157
  authorized: true,
135
- apiKeyMeta: apikeyMetadata
158
+ apiKeyMeta: apiKeyMetadata
136
159
  };
137
160
  }
138
161
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var node_crypto = require('node:crypto');
6
- var index = require('../../dist/index-f45a96ee.cjs.dev.js');
6
+ var index = require('../../dist/index-ded83ecc.cjs.dev.js');
7
7
  var services = require('../../dist/services-a3f36057.cjs.dev.js');
8
8
 
9
9
  async function authorizeNode(authInput, serviceConfig) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var node_crypto = require('node:crypto');
6
- var index = require('../../dist/index-8a3bbee6.cjs.prod.js');
6
+ var index = require('../../dist/index-bc2b86a5.cjs.prod.js');
7
7
  var services = require('../../dist/services-9e185105.cjs.prod.js');
8
8
 
9
9
  async function authorizeNode(authInput, serviceConfig) {
@@ -1,5 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { a as authorize } from '../../dist/index-bdbd7887.esm.js';
2
+ import { a as authorize } from '../../dist/index-1125bae0.esm.js';
3
3
  export { b as SERVICES, S as SERVICE_DEFINITIONS, a as SERVICE_NAMES, g as getServiceByName } from '../../dist/services-86283509.esm.js';
4
4
 
5
5
  async function authorizeNode(authInput, serviceConfig) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thirdweb-dev/service-utils",
3
- "version": "0.2.0-nightly-f7392138-20230714100149",
3
+ "version": "0.2.0-nightly-781e26d8-20230714165556",
4
4
  "main": "dist/thirdweb-dev-service-utils.cjs.js",
5
5
  "module": "dist/thirdweb-dev-service-utils.esm.js",
6
6
  "exports": {