Skip to content

Commit

Permalink
Merge branch 'develop' into d-david
Browse files Browse the repository at this point in the history
  • Loading branch information
damienen authored Feb 22, 2024
2 parents 3fdfa6d + c4ae779 commit 7f5e2b0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: lts/*
node-version: '18.x'
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npx ci
Expand Down
11 changes: 3 additions & 8 deletions package-lock.json

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

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 7f5e2b0

Please sign in to comment.