@sasjs/core 4.57.0 → 4.57.2

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/package.json CHANGED
@@ -32,5 +32,5 @@
32
32
  "lint": "npx @sasjs/cli lint",
33
33
  "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
34
34
  },
35
- "version": "4.57.0"
35
+ "version": "4.57.2"
36
36
  }
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  @file
3
3
  @brief Returns the uri of a file or folder
4
- @details The automatic variable _FILESRVC_[fref]_URI is used after assigning
4
+ @details The automatic variable `_FILESRVC_[fref]_URI` is used after assigning
5
5
  a fileref using the filesrvc engine.
6
6
 
7
7
  Usage:
8
8
 
9
- %put %mfv_existfile(/Public/folder/file.txt);
10
- %put %mfv_existfile(/Public/folder);
9
+ %put %mfv_getpathuri(/Public/folder/file.txt);
10
+ %put %mfv_getpathuri(/Public/folder);
11
11
 
12
12
  @param [in] filepath The full path to the file on SAS drive
13
13
  (eg /Public/myfile.txt)
@@ -36,6 +36,8 @@
36
36
  @li password
37
37
  @li authorization_code
38
38
  @li sas_services
39
+ @param [in] force= (YES) Will overwrite (delete / recreate) files by default.
40
+ Set to NO to abort if a file already exists in that location.
39
41
  @param [out] outds= (_null_) Output dataset with the uri of the new file
40
42
 
41
43
  @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
@@ -46,6 +48,7 @@
46
48
  @li mf_getuniquename.sas
47
49
  @li mf_isblank.sas
48
50
  @li mf_mimetype.sas
51
+ @li mfv_getpathuri.sas
49
52
  @li mp_abort.sas
50
53
  @li mp_base64copy.sas
51
54
  @li mv_createfolder.sas
@@ -65,6 +68,7 @@
65
68
  ,grant_type=sas_services
66
69
  ,mdebug=0
67
70
  ,outds=_null_
71
+ ,force=YES
68
72
  );
69
73
  %local dbg;
70
74
  %if &mdebug=1 %then %do;
@@ -86,16 +90,16 @@
86
90
  %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
87
91
  and &grant_type ne sas_services
88
92
  )
89
- ,mac=&sysmacroname
93
+ ,mac=MV_CREATEFILE
90
94
  ,msg=%str(Invalid value for grant_type: &grant_type)
91
95
  )
92
96
 
93
97
  %mp_abort(iftrue=(%mf_isblank(&path)=1 or %length(&path)=1)
94
- ,mac=&sysmacroname
98
+ ,mac=MV_CREATEFILE
95
99
  ,msg=%str(path value must be provided)
96
100
  )
97
101
  %mp_abort(iftrue=(%mf_isblank(&name)=1 or %length(&name)=1)
98
- ,mac=&sysmacroname
102
+ ,mac=MV_CREATEFILE
99
103
  ,msg=%str(name value with length >1 must be provided)
100
104
  )
101
105
 
@@ -118,9 +122,12 @@
118
122
  run;
119
123
  %end;
120
124
 
125
+ options noquotelenmax;
126
+ %local base_uri; /* location of rest apis */
127
+ %let base_uri=%mf_getplatform(VIYARESTAPI);
121
128
 
122
129
  /* create folder if it does not already exist */
123
- %local folderds parenturi;
130
+ %local folderds self_uri;
124
131
  %let folderds=%mf_getuniquename(prefix=folderds);
125
132
  %mv_createfolder(path=&path
126
133
  ,access_token_var=&access_token_var
@@ -133,26 +140,43 @@ data _null_;
133
140
  call symputx('self_uri',self_uri,'l');
134
141
  run;
135
142
 
143
+ /* abort or delete if file already exists */
144
+ %let force=%upcase(&force);
145
+ %local fileuri ;
146
+ %let fileuri=%mfv_getpathuri(&path/&name);
147
+ %mp_abort(iftrue=(%mf_isblank(&fileuri)=0 and &force ne YES)
148
+ ,mac=MV_CREATEFILE
149
+ ,msg=%str(File &path/&name already exists and force=&force)
150
+ )
136
151
 
137
- options noquotelenmax;
138
- %local base_uri; /* location of rest apis */
139
- %let base_uri=%mf_getplatform(VIYARESTAPI);
152
+ %if %mf_isblank(&fileuri)=0 and &force=YES %then %do;
153
+ proc http method="DELETE" url="&base_uri&fileuri" &oauth_bearer;
154
+ headers
155
+ %if &grant_type=authorization_code %then %do;
156
+ "Authorization"="Bearer &&&access_token_var"
157
+ %end;
158
+ "Accept"="*/*";
159
+ run;
160
+ %put &sysmacroname DELETE &base_uri&fileuri
161
+ &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
162
+ %end;
140
163
 
141
- %local url mimetype;
164
+ %local url mimetype ext;
142
165
  %let url=&base_uri/files/files?parentFolderUri=&self_uri;
166
+ %let ext=%upcase(%scan(&name,-1,.));
143
167
 
144
168
  /* fetch job info */
145
169
  %local fname1;
146
170
  %let fname1=%mf_getuniquefileref();
147
171
  proc http method='POST' out=&fname1 &oauth_bearer in=&fref
148
172
  %if "&ctype" = "0" %then %do;
149
- %let mimetype=%mf_mimetype(%scan(&name,-1,.));
173
+ %let mimetype=%mf_mimetype(&ext);
150
174
  ct="&mimetype"
151
175
  %end;
152
176
  %else %do;
153
177
  ct="&ctype"
154
178
  %end;
155
- %if "&mimetype"="text/html" %then %do;
179
+ %if "&ext"="HTML" or "&ext"="CSS" or "&ext"="JS" or "&ext"="SVG" %then %do;
156
180
  url="&url%str(&)typeDefName=file";
157
181
  %end;
158
182
  %else %do;
@@ -165,10 +189,10 @@ proc http method='POST' out=&fname1 &oauth_bearer in=&fref
165
189
  %end;
166
190
  "Content-Disposition"= "&contentdisp filename=""&name""; name=""&name"";";
167
191
  run;
168
- %put &=SYS_PROCHTTP_STATUS_CODE;
169
- %put &=SYS_PROCHTTP_STATUS_PHRASE;
192
+ %if &mdebug=1 %then %put &sysmacroname POST &=url
193
+ &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
170
194
  %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 201)
171
- ,mac=&sysmacroname
195
+ ,mac=MV_CREATEFILE
172
196
  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
173
197
  )
174
198
  %local libref2;
@@ -164,8 +164,9 @@ options noquotelenmax;
164
164
  'Content-Type'='application/vnd.sas.content.folder+json'
165
165
  'Accept'='application/vnd.sas.content.folder+json';
166
166
  run;
167
- %put &=SYS_PROCHTTP_STATUS_CODE;
168
- %put &=SYS_PROCHTTP_STATUS_PHRASE;
167
+ %if &SYS_PROCHTTP_STATUS_CODE ne 200 %then %do;
168
+ %put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
169
+ %end;
169
170
  %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 201)
170
171
  ,mac=&sysmacroname
171
172
  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
@@ -955,12 +955,7 @@ run;
955
955
  libname &libref1 clear;
956
956
  %end;
957
957
 
958
- %put &sysmacroname: Job &name successfully created in &path;
959
- %put &sysmacroname:;
960
- %put &sysmacroname: Check it out here:;
961
- %put &sysmacroname:;%put;
962
- %put &url/SASJobExecution?_PROGRAM=&path/&name;%put;
963
- %put &sysmacroname:;
964
- %put &sysmacroname:;
958
+ %put NOTE: &sysmacroname: Job &name successfully created! Check it out:;
959
+ %put NOTE-;%put NOTE- &url/SASJobExecution?_PROGRAM=&path/&name;%put NOTE-;
965
960
 
966
961
  %mend mv_createwebservice;
@@ -111,13 +111,15 @@ proc http method='GET' out=&fname1a &oauth_bearer
111
111
  headers "Authorization"="Bearer &&&access_token_var";
112
112
  %end;
113
113
  run;
114
- %put &=SYS_PROCHTTP_STATUS_CODE;
114
+ %if &SYS_PROCHTTP_STATUS_CODE ne 200 %then %do;
115
+ %put &=sysmacroname &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
116
+ %end;
115
117
  %local libref1a;
116
118
  %let libref1a=%mf_getuniquelibref();
117
119
  libname &libref1a JSON fileref=&fname1a;
118
120
  %local uri found;
119
121
  %let found=0;
120
- %put Getting object uri from &libref1a..items;
122
+ /* %put Getting object uri from &libref1a..items; */
121
123
  data _null_;
122
124
  length contenttype name $1000;
123
125
  set &libref1a..items;
@@ -90,7 +90,7 @@ run;
90
90
  )
91
91
  %end;
92
92
 
93
- %put &sysmacroname: grab the follow on link ;
93
+ /* grab the follow on link */
94
94
  %local libref1;
95
95
  %let libref1=%mf_getuniquelibref();
96
96
  libname &libref1 JSON fileref=&fname1;
@@ -114,7 +114,7 @@ run;
114
114
  libname &libref1a JSON fileref=&fname1a;
115
115
  %local uri found;
116
116
  %let found=0;
117
- %put Getting object uri from &libref1a..items;
117
+ /* %put Getting object uri from &libref1a..items; */
118
118
  data _null_;
119
119
  length contenttype name $1000;
120
120
  set &libref1a..items;
@@ -1,6 +1,6 @@
1
1
  /**
2
- @file mv_deleteviyafolder.sas
3
- @brief Creates a viya folder if that folder does not already exist
2
+ @file
3
+ @brief Deletes a viya folder
4
4
  @details If not running in Studo 5 +, will expect an oauth token in a global
5
5
  macro variable (default ACCESS_TOKEN).
6
6