Skip to content

Commit

Permalink
Merge pull request #110 from Itheum/stg
Browse files Browse the repository at this point in the history
v2.7.0 ready for main
  • Loading branch information
newbreedofgeek authored Feb 26, 2024
2 parents 32d7f6f + c2c7184 commit 0cbf9e3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itheum/sdk-mx-data-nft",
"version": "2.6.3",
"version": "2.7.0",
"description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
26 changes: 25 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export function validateSpecificParamsViewData(params: {
fwdHeaderMapLookup?: any;
nestedIdxToStream?: number | undefined;
_fwdHeaderMapLookupMustContainBearerAuthHeader?: boolean | undefined;
asDeputyOnAppointerAddr?: string | undefined;
_mandatoryParamsList: string[]; // a pure JS fallback way to validate mandatory params, as typescript rules for mandatory can be bypassed by client app
}): {
allPassed: boolean;
Expand Down Expand Up @@ -390,6 +391,28 @@ export function validateSpecificParamsViewData(params: {
}
}

// asDeputyOnAppointerAddr test
let asDeputyOnAppointerAddrIsValid = true;

if (
params.asDeputyOnAppointerAddr !== undefined ||
params._mandatoryParamsList.includes('asDeputyOnAppointerAddr')
) {
asDeputyOnAppointerAddrIsValid = false;

if (
params.asDeputyOnAppointerAddr !== undefined &&
typeof params.asDeputyOnAppointerAddr === 'string' &&
params.asDeputyOnAppointerAddr.trim() !== '' &&
params.asDeputyOnAppointerAddr.length > 10
) {
asDeputyOnAppointerAddrIsValid = true;
} else {
validationMessages +=
'[asDeputyOnAppointerAddr needs to be a multiversx smart contract address in an string. e.g. erd1qqqqqqqqqqqqqpgqd2y9zvaehkn4arsjwxp8vs3rjmdwyffafsxsgjkdw8]';
}
}

if (
!signedMessageValid ||
!signableMessageValid ||
Expand All @@ -399,7 +422,8 @@ export function validateSpecificParamsViewData(params: {
!fwdHeaderMapLookupIsValid ||
!mvxNativeAuthMaxExpirySecondsValid ||
!mvxNativeAuthOriginsIsValid ||
!nestedIdxToStreamValid
!nestedIdxToStreamValid ||
!asDeputyOnAppointerAddrIsValid
) {
allPassed = false;
}
Expand Down
14 changes: 14 additions & 0 deletions src/datanft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class DataNft implements DataNftType {
* @param fwdHeaderKeys [optional] Forward only selected headers to the Origin Data Stream server. Has priority over fwdAllHeaders param. A comma separated lowercase string with less than 5 items. e.g. cookie,authorization
* @param fwdHeaderMapLookup [optional] Used with fwdHeaderKeys to set a front-end client side lookup map of headers the SDK uses to setup the forward. e.g. { cookie : "xyz", authorization : "Bearer zxy" }. Note that these are case-sensitive and need to match fwdHeaderKeys exactly.
* @param nestedIdxToStream [optional] If you are accessing a "nested stream", this is the index of the nested item you want drill into and fetch
* @param asDeputyOnAppointerAddr [optional] Put caller in the "deputy persona" of this deputy appointer address (which should be a smart contract that holds the Data NFT Id)
*/
async viewData(p: {
signedMessage: string;
Expand All @@ -313,6 +314,7 @@ export class DataNft implements DataNftType {
[key: string]: any;
};
nestedIdxToStream?: number;
asDeputyOnAppointerAddr?: string;
}): Promise<ViewDataReturnType> {
DataNft.ensureNetworkConfigSet();
if (!this.dataMarshal) {
Expand All @@ -334,6 +336,7 @@ export class DataNft implements DataNftType {
fwdHeaderKeys: p.fwdHeaderKeys,
fwdHeaderMapLookup: p.fwdHeaderMapLookup,
nestedIdxToStream: p.nestedIdxToStream,
asDeputyOnAppointerAddr: p.asDeputyOnAppointerAddr,
_mandatoryParamsList: ['signedMessage', 'signableMessage']
});

Expand Down Expand Up @@ -409,6 +412,10 @@ export class DataNft implements DataNftType {
});
}
}

if (typeof p.asDeputyOnAppointerAddr !== 'undefined') {
url += `&asDeputyOnAppointerAddr=${p.asDeputyOnAppointerAddr}`;
}
// E: append optional params...

const response = await fetch(url, fetchConfig);
Expand Down Expand Up @@ -451,6 +458,7 @@ export class DataNft implements DataNftType {
* @param fwdAllHeaders [optional] Forward all request headers to the Origin Data Stream server.
* @param stream [optional] Instead of auto-downloading if possible, request if data should always be streamed or not.i.e true=stream, false/undefined=default behavior
* @param nestedIdxToStream [optional] If you are accessing a "nested stream", this is the index of the nested item you want drill into and fetch
* @param asDeputyOnAppointerAddr [optional] Put caller in the "deputy persona" of this deputy appointer address (which should be a smart contract that holds the Data NFT Id)
*/
async viewDataViaMVXNativeAuth(p: {
mvxNativeAuthOrigins: string[];
Expand All @@ -462,6 +470,7 @@ export class DataNft implements DataNftType {
fwdAllHeaders?: boolean;
stream?: boolean;
nestedIdxToStream?: number;
asDeputyOnAppointerAddr?: string;
}): Promise<ViewDataReturnType> {
try {
// S: run any format specific validation
Expand All @@ -473,6 +482,7 @@ export class DataNft implements DataNftType {
fwdAllHeaders: p.fwdAllHeaders,
stream: p.stream,
nestedIdxToStream: p.nestedIdxToStream,
asDeputyOnAppointerAddr: p.asDeputyOnAppointerAddr,
_fwdHeaderMapLookupMustContainBearerAuthHeader: true,
_mandatoryParamsList: [
'mvxNativeAuthOrigins',
Expand Down Expand Up @@ -570,6 +580,10 @@ export class DataNft implements DataNftType {
});
}
}

if (typeof p.asDeputyOnAppointerAddr !== 'undefined') {
url += `&asDeputyOnAppointerAddr=${p.asDeputyOnAppointerAddr}`;
}
// E: append optional params...

const response = await fetch(url, fetchConfig);
Expand Down

0 comments on commit 0cbf9e3

Please sign in to comment.