@thirdweb-dev/service-utils 0.2.0-nightly-781e26d8-20230714165556 → 0.2.0-nightly-ddb3dabe-20230714192407

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-ded83ecc.cjs.dev.js');
5
+ var index = require('../../dist/index-c32e136a.cjs.dev.js');
6
6
  var services = require('../../dist/services-a3f36057.cjs.dev.js');
7
7
 
8
8
  const DEFAULT_CACHE_TTL_SECONDS = 60;
@@ -93,7 +93,8 @@ async function extractAuthorizationData(authInput) {
93
93
  clientId,
94
94
  origin,
95
95
  bundleId,
96
- secretKeyHash
96
+ secretKeyHash,
97
+ targetAddress: authInput.targetAddress
97
98
  };
98
99
  }
99
100
  async function hashSecretKey(secretKey) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../dist/index-bc2b86a5.cjs.prod.js');
5
+ var index = require('../../dist/index-175beb0e.cjs.prod.js');
6
6
  var services = require('../../dist/services-9e185105.cjs.prod.js');
7
7
 
8
8
  const DEFAULT_CACHE_TTL_SECONDS = 60;
@@ -93,7 +93,8 @@ async function extractAuthorizationData(authInput) {
93
93
  clientId,
94
94
  origin,
95
95
  bundleId,
96
- secretKeyHash
96
+ secretKeyHash,
97
+ targetAddress: authInput.targetAddress
97
98
  };
98
99
  }
99
100
  async function hashSecretKey(secretKey) {
@@ -1,4 +1,4 @@
1
- import { a as authorize } from '../../dist/index-1125bae0.esm.js';
1
+ import { a as authorize } from '../../dist/index-5476722b.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;
@@ -89,7 +89,8 @@ async function extractAuthorizationData(authInput) {
89
89
  clientId,
90
90
  origin,
91
91
  bundleId,
92
- secretKeyHash
92
+ secretKeyHash,
93
+ targetAddress: authInput.targetAddress
93
94
  };
94
95
  }
95
96
  async function hashSecretKey(secretKey) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/cf-worker","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAkB,iBAAiB,EAAE,uBAAoB;AAGrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mCAAgC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAsB;AAEnD,oCAAiC;AAEjC,KAAK,mBAAmB,GAAG,iBAAiB,GAAG;IAC7C,OAAO,EAAE,WAAW,CAAC;IACrB,GAAG,EAAE,gBAAgB,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,KAAK,SAAS,GAAG,aAAa,GAAG;IAC/B,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAEF,wBAAsB,eAAe,CACnC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CA0C9B;AAmED,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,mBAIpD;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/cf-worker","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAkB,iBAAiB,EAAE,uBAAoB;AAGrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mCAAgC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAsB;AAEnD,oCAAiC;AAEjC,KAAK,mBAAmB,GAAG,iBAAiB,GAAG;IAC7C,OAAO,EAAE,WAAW,CAAC;IACrB,GAAG,EAAE,gBAAgB,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAIF,KAAK,SAAS,GAAG,aAAa,GAAG;IAC/B,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAEF,wBAAsB,eAAe,CACnC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CA0C9B;AAoED,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,mBAIpD;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
@@ -6,7 +6,7 @@ export type AuthorizationInput = {
6
6
  origin: string | null;
7
7
  bundleId: string | null;
8
8
  secretKeyHash: string | null;
9
- targetAddress?: string;
9
+ targetAddress?: string | string[];
10
10
  };
11
11
  type CacheOptions = {
12
12
  get: (clientId: string) => Promise<string | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/core/authorize","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,iBAAiB,EAElB,kBAAe;AAGhB,OAAO,EAAE,mBAAmB,EAAE,mBAAgB;AAE9C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,YAAY,GAAG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EAChC,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CAoH9B"}
@@ -1,5 +1,5 @@
1
1
  export type CoreAuthInput = {
2
2
  clientId?: string;
3
- targetAddress?: string;
3
+ targetAddress?: string | string[];
4
4
  };
5
5
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"../../../../src/core","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAE1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"../../../../src/core","sources":["types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAE1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/node","sources":["index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAuB,eAAe,EAAE,MAAM,WAAW,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,mCAA0B;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAoB;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mCAAgC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAsB;AAEnD,oCAAiC;AAEjC,KAAK,iBAAiB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG;IACtC,GAAG,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF,wBAAsB,aAAa,CACjC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,iBAAiB,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAsB9B;AAaD,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,SAAS,GACnB,kBAAkB,CA+DpB;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/node","sources":["index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAuB,eAAe,EAAE,MAAM,WAAW,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,mCAA0B;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAoB;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mCAAgC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAsB;AAEnD,oCAAiC;AAEjC,KAAK,iBAAiB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG;IACtC,GAAG,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF,wBAAsB,aAAa,CACjC,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,iBAAiB,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAsB9B;AAaD,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,SAAS,GACnB,kBAAkB,CAgEpB;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,UAE9C;AAED,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,UAEpE"}
@@ -9,7 +9,7 @@ async function fetchKeyMetadataFromApi(clientId, config) {
9
9
  const url = new URL(`${apiUrl}/v1/keys/use`);
10
10
  url.searchParams.set("clientId", clientId);
11
11
  url.searchParams.set("scope", serviceScope);
12
- const response = await fetch(url.href, {
12
+ const response = await fetch(url.toString(), {
13
13
  method: "GET",
14
14
  headers: {
15
15
  "x-service-api-key": serviceApiKey,
@@ -114,8 +114,6 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
114
114
  const {
115
115
  services
116
116
  } = apiKeyMetadata;
117
- // const { serviceTargetAddresses, serviceAction } = validations;
118
-
119
117
  // validate services
120
118
  const service = services.find(srv => srv.name === serviceConfig.serviceScope);
121
119
  if (!service) {
@@ -143,11 +141,12 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
143
141
  // validate service target addresses
144
142
  // the service has to pass in the target address for this to be validated
145
143
  if (authorizationPayload?.targetAddress) {
146
- const isTargetAddressAllowed = service.targetAddresses.includes(authorizationPayload.targetAddress);
147
- if (!isTargetAddressAllowed) {
144
+ const checkedAddresses = Array.isArray(authorizationPayload.targetAddress) ? authorizationPayload.targetAddress : [authorizationPayload.targetAddress];
145
+ const allAllowed = service.targetAddresses.includes("*");
146
+ if (!allAllowed && checkedAddresses.some(ta => !service.targetAddresses.includes(ta))) {
148
147
  return {
149
148
  authorized: false,
150
- errorMessage: `The service "${serviceConfig.serviceScope}" target address "${authorizationPayload.targetAddress}" is not authorized for this key.`,
149
+ errorMessage: `The service "${serviceConfig.serviceScope}" target address is not authorized for this key.`,
151
150
  errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
152
151
  status: 403
153
152
  };
@@ -7,7 +7,7 @@ async function fetchKeyMetadataFromApi(clientId, config) {
7
7
  const url = new URL(`${apiUrl}/v1/keys/use`);
8
8
  url.searchParams.set("clientId", clientId);
9
9
  url.searchParams.set("scope", serviceScope);
10
- const response = await fetch(url.href, {
10
+ const response = await fetch(url.toString(), {
11
11
  method: "GET",
12
12
  headers: {
13
13
  "x-service-api-key": serviceApiKey,
@@ -112,8 +112,6 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
112
112
  const {
113
113
  services
114
114
  } = apiKeyMetadata;
115
- // const { serviceTargetAddresses, serviceAction } = validations;
116
-
117
115
  // validate services
118
116
  const service = services.find(srv => srv.name === serviceConfig.serviceScope);
119
117
  if (!service) {
@@ -141,11 +139,12 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
141
139
  // validate service target addresses
142
140
  // the service has to pass in the target address for this to be validated
143
141
  if (authorizationPayload?.targetAddress) {
144
- const isTargetAddressAllowed = service.targetAddresses.includes(authorizationPayload.targetAddress);
145
- if (!isTargetAddressAllowed) {
142
+ const checkedAddresses = Array.isArray(authorizationPayload.targetAddress) ? authorizationPayload.targetAddress : [authorizationPayload.targetAddress];
143
+ const allAllowed = service.targetAddresses.includes("*");
144
+ if (!allAllowed && checkedAddresses.some(ta => !service.targetAddresses.includes(ta))) {
146
145
  return {
147
146
  authorized: false,
148
- errorMessage: `The service "${serviceConfig.serviceScope}" target address "${authorizationPayload.targetAddress}" is not authorized for this key.`,
147
+ errorMessage: `The service "${serviceConfig.serviceScope}" target address is not authorized for this key.`,
149
148
  errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
150
149
  status: 403
151
150
  };
@@ -9,7 +9,7 @@ async function fetchKeyMetadataFromApi(clientId, config) {
9
9
  const url = new URL(`${apiUrl}/v1/keys/use`);
10
10
  url.searchParams.set("clientId", clientId);
11
11
  url.searchParams.set("scope", serviceScope);
12
- const response = await fetch(url.href, {
12
+ const response = await fetch(url.toString(), {
13
13
  method: "GET",
14
14
  headers: {
15
15
  "x-service-api-key": serviceApiKey,
@@ -114,8 +114,6 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
114
114
  const {
115
115
  services
116
116
  } = apiKeyMetadata;
117
- // const { serviceTargetAddresses, serviceAction } = validations;
118
-
119
117
  // validate services
120
118
  const service = services.find(srv => srv.name === serviceConfig.serviceScope);
121
119
  if (!service) {
@@ -143,11 +141,12 @@ function authorizeService(apiKeyMetadata, serviceConfig, authorizationPayload) {
143
141
  // validate service target addresses
144
142
  // the service has to pass in the target address for this to be validated
145
143
  if (authorizationPayload?.targetAddress) {
146
- const isTargetAddressAllowed = service.targetAddresses.includes(authorizationPayload.targetAddress);
147
- if (!isTargetAddressAllowed) {
144
+ const checkedAddresses = Array.isArray(authorizationPayload.targetAddress) ? authorizationPayload.targetAddress : [authorizationPayload.targetAddress];
145
+ const allAllowed = service.targetAddresses.includes("*");
146
+ if (!allAllowed && checkedAddresses.some(ta => !service.targetAddresses.includes(ta))) {
148
147
  return {
149
148
  authorized: false,
150
- errorMessage: `The service "${serviceConfig.serviceScope}" target address "${authorizationPayload.targetAddress}" is not authorized for this key.`,
149
+ errorMessage: `The service "${serviceConfig.serviceScope}" target address is not authorized for this key.`,
151
150
  errorCode: "SERVICE_TARGET_ADDRESS_UNAUTHORIZED",
152
151
  status: 403
153
152
  };
@@ -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-ded83ecc.cjs.dev.js');
6
+ var index = require('../../dist/index-c32e136a.cjs.dev.js');
7
7
  var services = require('../../dist/services-a3f36057.cjs.dev.js');
8
8
 
9
9
  async function authorizeNode(authInput, serviceConfig) {
@@ -93,7 +93,8 @@ function extractAuthorizationData(authInput) {
93
93
  secretKey,
94
94
  clientId,
95
95
  origin,
96
- bundleId
96
+ bundleId,
97
+ targetAddress: authInput.targetAddress
97
98
  };
98
99
  }
99
100
  function hashSecretKey(secretKey) {
@@ -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-bc2b86a5.cjs.prod.js');
6
+ var index = require('../../dist/index-175beb0e.cjs.prod.js');
7
7
  var services = require('../../dist/services-9e185105.cjs.prod.js');
8
8
 
9
9
  async function authorizeNode(authInput, serviceConfig) {
@@ -93,7 +93,8 @@ function extractAuthorizationData(authInput) {
93
93
  secretKey,
94
94
  clientId,
95
95
  origin,
96
- bundleId
96
+ bundleId,
97
+ targetAddress: authInput.targetAddress
97
98
  };
98
99
  }
99
100
  function hashSecretKey(secretKey) {
@@ -1,5 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { a as authorize } from '../../dist/index-1125bae0.esm.js';
2
+ import { a as authorize } from '../../dist/index-5476722b.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) {
@@ -89,7 +89,8 @@ function extractAuthorizationData(authInput) {
89
89
  secretKey,
90
90
  clientId,
91
91
  origin,
92
- bundleId
92
+ bundleId,
93
+ targetAddress: authInput.targetAddress
93
94
  };
94
95
  }
95
96
  function hashSecretKey(secretKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thirdweb-dev/service-utils",
3
- "version": "0.2.0-nightly-781e26d8-20230714165556",
3
+ "version": "0.2.0-nightly-ddb3dabe-20230714192407",
4
4
  "main": "dist/thirdweb-dev-service-utils.cjs.js",
5
5
  "module": "dist/thirdweb-dev-service-utils.esm.js",
6
6
  "exports": {