etincidunt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. package/.prettierignore +2 -0
  2. package/.travis.yml +29 -0
  3. package/.vscode/launch.json +24 -0
  4. package/.vscode/settings.json +3 -0
  5. package/demos/ago-node-cli/README.md +29 -0
  6. package/demos/ago-node-cli/ago.js +32 -0
  7. package/demos/ago-node-cli/index.js +11 -0
  8. package/demos/ago-node-cli/lib/item-export-command.js +48 -0
  9. package/demos/ago-node-cli/lib/item-search-command.js +35 -0
  10. package/demos/ago-node-cli/package-lock.json +172 -0
  11. package/demos/ago-node-cli/package.json +30 -0
  12. package/demos/attachments/README.md +5 -0
  13. package/demos/attachments/index.html +164 -0
  14. package/demos/attachments/package-lock.json +182 -0
  15. package/demos/attachments/package.json +18 -0
  16. package/demos/batch-geocoder-node/NYC_Restaurant_Inspection_Results.csv +100 -0
  17. package/demos/batch-geocoder-node/README.md +14 -0
  18. package/demos/batch-geocoder-node/batch-geocode.js +112 -0
  19. package/demos/batch-geocoder-node/config-template.js +18 -0
  20. package/demos/batch-geocoder-node/package-lock.json +109 -0
  21. package/demos/batch-geocoder-node/package.json +37 -0
  22. package/demos/express/README.md +10 -0
  23. package/demos/express/config.json.template +3 -0
  24. package/demos/express/package-lock.json +388 -0
  25. package/demos/express/package.json +18 -0
  26. package/demos/express/server.js +28 -0
  27. package/demos/feature-service-browser/README.md +6 -0
  28. package/demos/feature-service-browser/index.html +122 -0
  29. package/demos/feature-service-browser/package-lock.json +182 -0
  30. package/demos/feature-service-browser/package.json +18 -0
  31. package/demos/geocoder-browser/README.md +10 -0
  32. package/demos/geocoder-browser/config.js.template +1 -0
  33. package/demos/geocoder-browser/index.html +131 -0
  34. package/demos/geocoder-browser/package-lock.json +163 -0
  35. package/demos/geocoder-browser/package.json +19 -0
  36. package/demos/geocoder-browser/post-sign-in.html +25 -0
  37. package/demos/jsapi-integration/README.md +8 -0
  38. package/demos/jsapi-integration/config.js +6 -0
  39. package/demos/jsapi-integration/index.html +79 -0
  40. package/demos/jsapi-integration/package-lock.json +184 -0
  41. package/demos/jsapi-integration/package.json +19 -0
  42. package/demos/oauth2-browser/README.md +12 -0
  43. package/demos/oauth2-browser/authenticate.html +32 -0
  44. package/demos/oauth2-browser/config.js.template +6 -0
  45. package/demos/oauth2-browser/index.html +202 -0
  46. package/demos/oauth2-browser/logo.svg +4 -0
  47. package/demos/oauth2-browser/package-lock.json +163 -0
  48. package/demos/oauth2-browser/package.json +18 -0
  49. package/demos/oauth2-browser/style.css +36 -0
  50. package/demos/vue/.babelrc +6 -0
  51. package/demos/vue/.env.example +8 -0
  52. package/demos/vue/README.md +17 -0
  53. package/demos/vue/index.html +21 -0
  54. package/demos/vue/package-lock.json +7236 -0
  55. package/demos/vue/package.json +39 -0
  56. package/demos/vue/src/assets/logo.svg +29 -0
  57. package/demos/vue/src/components/App.vue +302 -0
  58. package/demos/vue/src/components/Authenticate.vue +68 -0
  59. package/demos/vue/src/components/Loader.vue +216 -0
  60. package/demos/vue/src/main.js +75 -0
  61. package/demos/vue/webpack.config.js +84 -0
  62. package/docs/FAQ.md +28 -0
  63. package/docs/HISTORY.md +62 -0
  64. package/docs/acetate.config.js +214 -0
  65. package/docs/build-typedoc.js +301 -0
  66. package/docs/src/_layout.html +82 -0
  67. package/docs/src/api/_declaration.html +496 -0
  68. package/docs/src/api/_layout.html +127 -0
  69. package/docs/src/api/_package.html +13 -0
  70. package/docs/src/api/index.html +23 -0
  71. package/docs/src/guides/_layout.html +24 -0
  72. package/docs/src/guides/amd-requirejs-dojo.md +40 -0
  73. package/docs/src/guides/babel-and-rollup.md +30 -0
  74. package/docs/src/guides/babel-and-webpack.md +30 -0
  75. package/docs/src/guides/browser-authentication.md +9 -0
  76. package/docs/src/guides/browserify.md +9 -0
  77. package/docs/src/guides/cli-authentication.md +9 -0
  78. package/docs/src/guides/client-server-authentication.md +9 -0
  79. package/docs/src/guides/from-a-cdn.md +36 -0
  80. package/docs/src/guides/index.md +52 -0
  81. package/docs/src/guides/node.md +30 -0
  82. package/docs/src/guides/package-overview.md +8 -0
  83. package/docs/src/guides/server-authentication.md +9 -0
  84. package/docs/src/guides/typescript-and-webpack.md +9 -0
  85. package/docs/src/img/icons.png +0 -0
  86. package/docs/src/img/icons@2x.png +0 -0
  87. package/docs/src/index.html +12 -0
  88. package/docs/src/js/api-search.js +113 -0
  89. package/docs/src/js/index.js +1 -0
  90. package/docs/src/js/nav-toggle.js +41 -0
  91. package/docs/src/sass/_highlight.scss +96 -0
  92. package/docs/src/sass/_icons.scss +157 -0
  93. package/docs/src/sass/style.scss +169 -0
  94. package/jasmine.json +7 -0
  95. package/karma.conf.js +100 -0
  96. package/lerna.json +8 -0
  97. package/notes/README.md +88 -0
  98. package/package.json +91 -0
  99. package/packages/arcgis-rest-auth/README.md +64 -0
  100. package/packages/arcgis-rest-auth/package-lock.json +11 -0
  101. package/packages/arcgis-rest-auth/package.json +51 -0
  102. package/packages/arcgis-rest-auth/src/ApplicationSession.ts +91 -0
  103. package/packages/arcgis-rest-auth/src/UserSession.ts +829 -0
  104. package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +21 -0
  105. package/packages/arcgis-rest-auth/src/fetch-token.ts +55 -0
  106. package/packages/arcgis-rest-auth/src/generate-token.ts +36 -0
  107. package/packages/arcgis-rest-auth/src/index.ts +5 -0
  108. package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +121 -0
  109. package/packages/arcgis-rest-auth/test/UserSession.test.ts +883 -0
  110. package/packages/arcgis-rest-auth/test/fetchToken.test.ts +76 -0
  111. package/packages/arcgis-rest-auth/test/generateToken.test.ts +36 -0
  112. package/packages/arcgis-rest-auth/test/utils.ts +11 -0
  113. package/packages/arcgis-rest-auth/tsconfig.json +6 -0
  114. package/packages/arcgis-rest-common-types/README.md +61 -0
  115. package/packages/arcgis-rest-common-types/package.json +38 -0
  116. package/packages/arcgis-rest-common-types/src/group.ts +51 -0
  117. package/packages/arcgis-rest-common-types/src/index.ts +467 -0
  118. package/packages/arcgis-rest-common-types/src/item.ts +45 -0
  119. package/packages/arcgis-rest-common-types/src/webmap.ts +1225 -0
  120. package/packages/arcgis-rest-common-types/tsconfig.json +11 -0
  121. package/packages/arcgis-rest-feature-service/README.md +70 -0
  122. package/packages/arcgis-rest-feature-service/package-lock.json +11 -0
  123. package/packages/arcgis-rest-feature-service/package.json +50 -0
  124. package/packages/arcgis-rest-feature-service/src/add.ts +82 -0
  125. package/packages/arcgis-rest-feature-service/src/addAttachment.ts +65 -0
  126. package/packages/arcgis-rest-feature-service/src/delete.ts +85 -0
  127. package/packages/arcgis-rest-feature-service/src/deleteAttachments.ts +68 -0
  128. package/packages/arcgis-rest-feature-service/src/getAttachments.ts +64 -0
  129. package/packages/arcgis-rest-feature-service/src/helpers.ts +77 -0
  130. package/packages/arcgis-rest-feature-service/src/index.ts +8 -0
  131. package/packages/arcgis-rest-feature-service/src/query.ts +174 -0
  132. package/packages/arcgis-rest-feature-service/src/update.ts +81 -0
  133. package/packages/arcgis-rest-feature-service/src/updateAttachment.ts +74 -0
  134. package/packages/arcgis-rest-feature-service/test/attachments.test.ts +179 -0
  135. package/packages/arcgis-rest-feature-service/test/features.test.ts +172 -0
  136. package/packages/arcgis-rest-feature-service/test/mocks/feature.ts +220 -0
  137. package/packages/arcgis-rest-feature-service/test/mocks/foo.txt +1 -0
  138. package/packages/arcgis-rest-feature-service/tsconfig.json +6 -0
  139. package/packages/arcgis-rest-geocoder/README.md +73 -0
  140. package/packages/arcgis-rest-geocoder/package-lock.json +11 -0
  141. package/packages/arcgis-rest-geocoder/package.json +52 -0
  142. package/packages/arcgis-rest-geocoder/src/bulk.ts +102 -0
  143. package/packages/arcgis-rest-geocoder/src/geocode.ts +117 -0
  144. package/packages/arcgis-rest-geocoder/src/helpers.ts +81 -0
  145. package/packages/arcgis-rest-geocoder/src/index.ts +4 -0
  146. package/packages/arcgis-rest-geocoder/src/reverse.ts +84 -0
  147. package/packages/arcgis-rest-geocoder/src/suggest.ts +72 -0
  148. package/packages/arcgis-rest-geocoder/test/geocoder.test.ts +510 -0
  149. package/packages/arcgis-rest-geocoder/test/mocks/responses.ts +588 -0
  150. package/packages/arcgis-rest-geocoder/tsconfig.json +6 -0
  151. package/packages/arcgis-rest-groups/README.md +64 -0
  152. package/packages/arcgis-rest-groups/package-lock.json +11 -0
  153. package/packages/arcgis-rest-groups/package.json +52 -0
  154. package/packages/arcgis-rest-groups/src/groups.ts +272 -0
  155. package/packages/arcgis-rest-groups/src/index.ts +1 -0
  156. package/packages/arcgis-rest-groups/test/groups.test.ts +280 -0
  157. package/packages/arcgis-rest-groups/test/mocks/responses.ts +137 -0
  158. package/packages/arcgis-rest-groups/tsconfig.json +6 -0
  159. package/packages/arcgis-rest-items/README.md +66 -0
  160. package/packages/arcgis-rest-items/package-lock.json +11 -0
  161. package/packages/arcgis-rest-items/package.json +52 -0
  162. package/packages/arcgis-rest-items/src/index.ts +1 -0
  163. package/packages/arcgis-rest-items/src/items.ts +498 -0
  164. package/packages/arcgis-rest-items/test/items.test.ts +1153 -0
  165. package/packages/arcgis-rest-items/test/mocks/foo.zip +0 -0
  166. package/packages/arcgis-rest-items/test/mocks/item.ts +30 -0
  167. package/packages/arcgis-rest-items/test/mocks/resources.ts +28 -0
  168. package/packages/arcgis-rest-items/test/mocks/search.ts +60 -0
  169. package/packages/arcgis-rest-items/tsconfig.json +6 -0
  170. package/packages/arcgis-rest-request/README.md +65 -0
  171. package/packages/arcgis-rest-request/package-lock.json +11 -0
  172. package/packages/arcgis-rest-request/package.json +42 -0
  173. package/packages/arcgis-rest-request/src/index.ts +10 -0
  174. package/packages/arcgis-rest-request/src/request.ts +259 -0
  175. package/packages/arcgis-rest-request/src/utils/ArcGISAuthError.ts +67 -0
  176. package/packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts +73 -0
  177. package/packages/arcgis-rest-request/src/utils/ErrorTypes.ts +29 -0
  178. package/packages/arcgis-rest-request/src/utils/check-for-errors.ts +65 -0
  179. package/packages/arcgis-rest-request/src/utils/encode-form-data.ts +29 -0
  180. package/packages/arcgis-rest-request/src/utils/encode-query-string.ts +23 -0
  181. package/packages/arcgis-rest-request/src/utils/get-portal-url.ts +25 -0
  182. package/packages/arcgis-rest-request/src/utils/get-portal.ts +45 -0
  183. package/packages/arcgis-rest-request/src/utils/process-params.ts +99 -0
  184. package/packages/arcgis-rest-request/test/mocks/errors.ts +59 -0
  185. package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +10 -0
  186. package/packages/arcgis-rest-request/test/mocks/portal.ts +109 -0
  187. package/packages/arcgis-rest-request/test/mocks/sharing-rest-info.ts +38 -0
  188. package/packages/arcgis-rest-request/test/mocks/webmap.ts +38 -0
  189. package/packages/arcgis-rest-request/test/request.test.ts +296 -0
  190. package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +167 -0
  191. package/packages/arcgis-rest-request/test/utils/ArcGISRequestError.test.ts +40 -0
  192. package/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +101 -0
  193. package/packages/arcgis-rest-request/test/utils/encode-form-data.test.ts +112 -0
  194. package/packages/arcgis-rest-request/test/utils/get-portal-url.test.ts +34 -0
  195. package/packages/arcgis-rest-request/test/utils/portal.test.ts +94 -0
  196. package/packages/arcgis-rest-request/test/utils/process-params.test.ts +190 -0
  197. package/packages/arcgis-rest-request/tsconfig.json +6 -0
  198. package/packages/arcgis-rest-sharing/README.md +67 -0
  199. package/packages/arcgis-rest-sharing/package-lock.json +11 -0
  200. package/packages/arcgis-rest-sharing/package.json +55 -0
  201. package/packages/arcgis-rest-sharing/src/access.ts +91 -0
  202. package/packages/arcgis-rest-sharing/src/group-sharing.ts +212 -0
  203. package/packages/arcgis-rest-sharing/src/helpers.ts +92 -0
  204. package/packages/arcgis-rest-sharing/src/index.ts +2 -0
  205. package/packages/arcgis-rest-sharing/test/access.test.ts +153 -0
  206. package/packages/arcgis-rest-sharing/test/group-sharing.test.ts +436 -0
  207. package/packages/arcgis-rest-sharing/test/mocks/sharing.ts +15 -0
  208. package/packages/arcgis-rest-sharing/tsconfig.json +6 -0
  209. package/packages/arcgis-rest-users/README.md +71 -0
  210. package/packages/arcgis-rest-users/package-lock.json +11 -0
  211. package/packages/arcgis-rest-users/package.json +51 -0
  212. package/packages/arcgis-rest-users/src/index.ts +1 -0
  213. package/packages/arcgis-rest-users/src/users.ts +70 -0
  214. package/packages/arcgis-rest-users/test/mocks/responses.ts +170 -0
  215. package/packages/arcgis-rest-users/test/users.test.ts +97 -0
  216. package/packages/arcgis-rest-users/tsconfig.json +6 -0
  217. package/support/FormData.d.ts +1 -0
  218. package/support/changelog.js +388 -0
  219. package/support/commit-template.txt +19 -0
  220. package/support/deploy-doc-site.js +16 -0
  221. package/support/publish.sh +40 -0
  222. package/support/test-helpers.js +8 -0
  223. package/tsconfig.json +69 -0
  224. package/tslint.json +14 -0
  225. package/umd-base-profile.js +82 -0
  226. package/umd-production-profile.js +13 -0
@@ -0,0 +1,170 @@
1
+ import { IUser } from "@esri/arcgis-rest-common-types";
2
+
3
+ export const AnonUserResponse: IUser = {
4
+ username: "jsmith",
5
+ fullName: "John Smith",
6
+ firstName: "John",
7
+ lastName: "Smith",
8
+ description: "Senior GIS Analyst for the city of Redlands.",
9
+ tags: ["GIS Analyst", "City of Redlands"],
10
+ culture: "en",
11
+ region: "US",
12
+ units: "metric",
13
+ thumbnail: "myProfile.jpg",
14
+ created: 1258501046000,
15
+ modified: 1290625562000,
16
+ provider: "arcgis"
17
+ };
18
+
19
+ export const GroupMemberUserResponse: IUser = {
20
+ ...AnonUserResponse,
21
+ availableCredits: 479.50998,
22
+ assignedCredits: 500.0,
23
+ preferredView: "Web",
24
+ email: "jsmith33@esri.com",
25
+ idpUsername: "null",
26
+ favGroupId: "829e32cca4dd475a8bb63bb56b16fe3e",
27
+ lastLogin: 1385766284000,
28
+ mfaEnabled: false,
29
+ access: "public",
30
+ storageUsage: 583650,
31
+ storageQuota: 2147483648,
32
+ orgId: "qWAReEOCnD7eTxOe",
33
+ role: "org_publisher",
34
+ privileges: [
35
+ "portal:admin:deleteItems",
36
+ "portal:admin:reassignItems",
37
+ "portal:admin:updateItems",
38
+ "portal:admin:viewItems",
39
+ "portal:admin:viewUsers",
40
+ "portal:user:createGroup",
41
+ "portal:user:createItem",
42
+ "portal:user:joinGroup",
43
+ "portal:user:shareToGroup",
44
+ "portal:user:shareToOrg"
45
+ ],
46
+ roleId: "RDnHQBSBbsJuIkUp",
47
+ level: "2",
48
+ disabled: false,
49
+ groups: [
50
+ {
51
+ id: "t6b",
52
+ title: "Street Maps",
53
+ isInvitationOnly: false,
54
+ owner: "whoknows",
55
+ description:
56
+ "The street map group provides street maps for the city of Redlands.",
57
+ snippet: "City of Redlands maps",
58
+ tags: ["Redlands", "street", "maps"],
59
+ phone: "http://www.esri.com",
60
+ thumbnail: "streets.jpg",
61
+ created: 1258501221000,
62
+ modified: 1272309404000,
63
+ access: "org",
64
+ userMembership: {
65
+ username: "jsmith",
66
+ memberType: "user",
67
+ applications: 0
68
+ },
69
+ protected: false,
70
+ isViewOnly: false,
71
+ isFav: false,
72
+ isOpenData: true,
73
+ autoJoin: false
74
+ }
75
+ ]
76
+ };
77
+
78
+ export const GroupNonMemberUserResponse: IUser = {
79
+ ...GroupMemberUserResponse,
80
+ groups: [
81
+ {
82
+ id: "abc",
83
+ title: "Street Maps",
84
+ isInvitationOnly: false,
85
+ owner: "whoknows",
86
+ description:
87
+ "The street map group provides street maps for the city of Redlands.",
88
+ snippet: "City of Redlands maps",
89
+ tags: ["Redlands", "street", "maps"],
90
+ phone: "http://www.esri.com",
91
+ thumbnail: "streets.jpg",
92
+ created: 1258501221000,
93
+ modified: 1272309404000,
94
+ access: "org",
95
+ userMembership: {
96
+ username: "jsmith",
97
+ memberType: "user",
98
+ applications: 0
99
+ },
100
+ protected: false,
101
+ isViewOnly: false,
102
+ isFav: false,
103
+ isOpenData: true,
104
+ autoJoin: false
105
+ }
106
+ ]
107
+ };
108
+
109
+ export const GroupAdminUserResponse = {
110
+ ...GroupMemberUserResponse,
111
+ groups: [
112
+ {
113
+ id: "t6b",
114
+ title: "Street Maps",
115
+ isInvitationOnly: false,
116
+ owner: "whoknows",
117
+ description:
118
+ "The street map group provides street maps for the city of Redlands.",
119
+ snippet: "City of Redlands maps",
120
+ tags: ["Redlands", "street", "maps"],
121
+ phone: "http://www.esri.com",
122
+ thumbnail: "streets.jpg",
123
+ created: 1258501221000,
124
+ modified: 1272309404000,
125
+ access: "org",
126
+ userMembership: {
127
+ username: "jsmith",
128
+ memberType: "admin",
129
+ applications: 0
130
+ },
131
+ protected: false,
132
+ isViewOnly: false,
133
+ isFav: false,
134
+ isOpenData: true,
135
+ autoJoin: false
136
+ }
137
+ ]
138
+ };
139
+
140
+ export const OrgAdminUserResponse = {
141
+ ...GroupAdminUserResponse,
142
+ role: "org_admin",
143
+ groups: [
144
+ {
145
+ id: "t6b",
146
+ title: "Street Maps",
147
+ isInvitationOnly: false,
148
+ owner: "whoknows",
149
+ description:
150
+ "The street map group provides street maps for the city of Redlands.",
151
+ snippet: "City of Redlands maps",
152
+ tags: ["Redlands", "street", "maps"],
153
+ phone: "http://www.esri.com",
154
+ thumbnail: "streets.jpg",
155
+ created: 1258501221000,
156
+ modified: 1272309404000,
157
+ access: "org",
158
+ userMembership: {
159
+ username: "jsmith",
160
+ memberType: "owner",
161
+ applications: 0
162
+ },
163
+ protected: false,
164
+ isViewOnly: false,
165
+ isFav: false,
166
+ isOpenData: true,
167
+ autoJoin: false
168
+ }
169
+ ]
170
+ };
@@ -0,0 +1,97 @@
1
+ import { getUser } from "../src/index";
2
+
3
+ import {
4
+ AnonUserResponse,
5
+ GroupMemberUserResponse,
6
+ GroupAdminUserResponse
7
+ } from "./mocks/responses";
8
+
9
+ import { encodeParam } from "@esri/arcgis-rest-request";
10
+ import { UserSession } from "@esri/arcgis-rest-auth";
11
+ import * as fetchMock from "fetch-mock";
12
+
13
+ const TOMORROW = (function() {
14
+ const now = new Date();
15
+ now.setDate(now.getDate() + 1);
16
+ return now;
17
+ })();
18
+
19
+ describe("users", () => {
20
+ afterEach(fetchMock.restore);
21
+
22
+ describe("getUser", () => {
23
+ const session = new UserSession({
24
+ username: "c@sey",
25
+ password: "123456",
26
+ portal: "https://myorg.maps.arcgis.com/sharing/rest"
27
+ });
28
+
29
+ fetchMock.postOnce(
30
+ "https://myorg.maps.arcgis.com/sharing/rest/generateToken",
31
+ {
32
+ token: "token",
33
+ expires: TOMORROW.getTime(),
34
+ username: " c@sey"
35
+ }
36
+ );
37
+
38
+ session.refreshSession();
39
+
40
+ it("should make a simple, unauthenticated request for information about a user", done => {
41
+ fetchMock.once("*", AnonUserResponse);
42
+
43
+ getUser("jsmith")
44
+ .then(response => {
45
+ expect(fetchMock.called()).toEqual(true);
46
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
47
+ expect(url).toEqual(
48
+ "https://www.arcgis.com/sharing/rest/community/users/jsmith?f=json"
49
+ );
50
+ expect(options.method).toBe("GET");
51
+ done();
52
+ })
53
+ .catch(e => {
54
+ fail(e);
55
+ });
56
+ });
57
+
58
+ it("should make an authenticated request for information about a user", done => {
59
+ fetchMock.once("*", GroupMemberUserResponse);
60
+
61
+ getUser({ authentication: session })
62
+ .then(response => {
63
+ expect(fetchMock.called()).toEqual(true);
64
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
65
+ expect(url).toEqual(
66
+ "https://myorg.maps.arcgis.com/sharing/rest/community/users/c%40sey?f=json&token=token"
67
+ );
68
+ expect(options.method).toBe("GET");
69
+ done();
70
+ })
71
+ .catch(e => {
72
+ fail(e);
73
+ });
74
+ });
75
+
76
+ it("should make an authenticated request for information about a different user", done => {
77
+ fetchMock.once("*", GroupAdminUserResponse);
78
+
79
+ getUser({
80
+ username: "jsmith",
81
+ authentication: session
82
+ })
83
+ .then(response => {
84
+ expect(fetchMock.called()).toEqual(true);
85
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
86
+ expect(url).toEqual(
87
+ "https://myorg.maps.arcgis.com/sharing/rest/community/users/jsmith?f=json&token=token"
88
+ );
89
+ expect(options.method).toBe("GET");
90
+ done();
91
+ })
92
+ .catch(e => {
93
+ fail(e);
94
+ });
95
+ });
96
+ });
97
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": [
4
+ "src/**/*.ts"
5
+ ]
6
+ }
@@ -0,0 +1 @@
1
+ declare module "isomorphic-form-data";
@@ -0,0 +1,388 @@
1
+ const { spawn, exec, execSync } = require("child_process");
2
+ const { inspect } = require("util");
3
+ const { resolve } = require("path");
4
+ const { writeFile } = require("fs");
5
+ const { stripIndents } = require("common-tags");
6
+ const { format } = require("date-fns");
7
+ const parseChangelog = require("changelog-parser");
8
+ const parseCommit = require("conventional-commits-parser").sync;
9
+ const nunjucks = require("nunjucks");
10
+ const _ = require("lodash");
11
+
12
+ /**
13
+ * The purpose of this file is to parse all commits since the last release tag
14
+ * v*.*.* and update the contents of CHANGELOG.md to prepare for a new release.
15
+ */
16
+
17
+ const repo = "https://github.com/Esri/arcgis-rest-js";
18
+
19
+ function getTags() {
20
+ return new Promise((resolve, reject) => {
21
+ let tags = [];
22
+ const log = spawn("git", ["tag", "-l", "v*", "--sort", "v:refname"]);
23
+
24
+ log.stdout.on("data", data => {
25
+ tags = tags.concat(data.toString().split("\n"));
26
+ });
27
+
28
+ log.on("close", code => {
29
+ resolve(_.compact(tags));
30
+ });
31
+ });
32
+ }
33
+
34
+ function getFirstCommit() {
35
+ return new Promise((resolve, reject) => {
36
+ let commits = [];
37
+ const log = spawn("git", [
38
+ "rev-list",
39
+ "--max-parents=0",
40
+ "HEAD",
41
+ "--reverse"
42
+ ]);
43
+
44
+ log.stdout.on("data", data => {
45
+ commits = commits.concat(data.toString().split("\n"));
46
+ });
47
+
48
+ log.on("close", code => {
49
+ resolve(commits[0]);
50
+ });
51
+ });
52
+ }
53
+
54
+ function getCommitData(from, to) {
55
+ return new Promise((resolve, reject) => {
56
+ const hash = "%H";
57
+ const shortHash = "%h";
58
+ const authorName = "%an";
59
+ const authorEmail = "%ae";
60
+ const date = "%aI";
61
+ const subject = "%s";
62
+ const defaultFormat = {
63
+ hash,
64
+ shortHash,
65
+ date,
66
+ subject,
67
+ author: { name: authorName, email: authorEmail }
68
+ };
69
+
70
+ const cmd = `git log ${from}..${to} --pretty=format:'${JSON.stringify(
71
+ defaultFormat
72
+ )},'`;
73
+
74
+ exec(cmd, (err, stdout, stderr) => {
75
+ if (err) return reject(err);
76
+ if (stderr) return reject(stderr);
77
+ // order commits from most recent to least recent
78
+ const commits = JSON.parse("["+stdout.slice(0, -1).replace(/\\/g, "\\\\")+"]").reverse();
79
+ const today = new Date();
80
+ resolve({
81
+ previousVersion: /v\d\.\d\.\d/.test(from)
82
+ ? from.replace("v", "")
83
+ : from,
84
+ version: to === "HEAD" ? getPackageVersion() : to.replace("v", ""),
85
+ date: format(today, "MMMM Do YYYY"),
86
+ commits
87
+ });
88
+ });
89
+ });
90
+ }
91
+
92
+ function getPackageVersion() {
93
+ return require(resolve(process.cwd(), "./lerna.json")).version;
94
+ }
95
+
96
+ function pairReleases(releases) {
97
+ return Promise.all(
98
+ releases.reduce((pairs, release, idx, allReleases) => {
99
+ const nextRelease = allReleases[idx + 1];
100
+ if (nextRelease) {
101
+ pairs.push([release, nextRelease]);
102
+ }
103
+
104
+ return pairs;
105
+ }, [])
106
+ );
107
+ }
108
+
109
+ function processCommitMessages(releaseData) {
110
+ return releaseData.map(release => {
111
+ release.commits = _(release.commits)
112
+ .map(commit => {
113
+ const parsedCommit = parseCommit(
114
+ execSync(
115
+ `git log ${commit.hash} -n1 --pretty=format:'%B'`
116
+ ).toString(),
117
+ {
118
+ mergePattern: /^Merge pull request #(\d+) from (.*)$/,
119
+ mergeCorrespondence: ["id", "source"],
120
+ noteKeywords: [
121
+ "BREAKING CHANGE",
122
+ "ISSUES CLOSED",
123
+ "AFFECTS PACKAGES"
124
+ ]
125
+ }
126
+ );
127
+
128
+ if (!parsedCommit.type || !parsedCommit.scope) {
129
+ return;
130
+ }
131
+
132
+ Object.assign(commit, parsedCommit);
133
+
134
+ const breaking = commit.notes.findIndex(
135
+ n => n.title === "BREAKING CHANGE"
136
+ );
137
+
138
+ if (breaking >= 0) {
139
+ commit.breakingChanges = commit.notes[breaking].text;
140
+ }
141
+
142
+ const issues = commit.notes.findIndex(n => n.title === "ISSUES CLOSED");
143
+
144
+ if (issues >= 0) {
145
+ const issuesClosed = commit.notes[issues].text
146
+ .replace(/\n.*/gm, "")
147
+ .replace(/\s/g, "")
148
+ .split(",")
149
+ .map(i => i.replace("#", ""));
150
+
151
+ const issuesReferenced = commit.references.map(r => r.issue);
152
+
153
+ commit.relatedIssues = _.uniq(
154
+ issuesClosed.concat(issuesReferenced)
155
+ ).map(i => {
156
+ return {
157
+ issue: i,
158
+ url: `${repo}/issues/${i}`
159
+ };
160
+ });
161
+ }
162
+ return commit;
163
+ })
164
+ .compact()
165
+ .sortBy("type")
166
+ .value();
167
+
168
+ return release;
169
+ });
170
+ }
171
+
172
+ function getPackagesForCommit(commit) {
173
+ const idx = commit.notes.findIndex(note => note.title === "AFFECTS PACKAGES");
174
+ if (idx >= 0) {
175
+ const affectedPackages = commit.notes[idx].text.split("\n");
176
+ return affectedPackages;
177
+ }
178
+ return ["Other Changes"];
179
+ }
180
+
181
+ function findReleasedPackages(releases) {
182
+ return releases.map(release => {
183
+ release.packages = release.commits.reduce((packages, commit) => {
184
+ packages = packages.concat(getPackagesForCommit(commit));
185
+ return _(packages).compact().uniq().sortBy(p => p).value();
186
+ }, []);
187
+ return release;
188
+ });
189
+ }
190
+
191
+ function hasBreakingChanges(commit) {
192
+ return commit.notes.find(n => n.title === "BREAKING CHANGE");
193
+ }
194
+
195
+ function groupCommitsByPackage(releases) {
196
+ return releases.map(release => {
197
+ release.groups = release.packages.reduce((groups, package) => {
198
+ const commitsForPackage = release.commits.filter(commit => {
199
+ return getPackagesForCommit(commit).some(
200
+ commitPackage => commitPackage === package
201
+ );
202
+ });
203
+
204
+ const [breaking, nonBreaking] = _.partition(
205
+ commitsForPackage,
206
+ hasBreakingChanges
207
+ );
208
+
209
+ if (breaking.length === 0) {
210
+ groups[package] = Object.assign(
211
+ {},
212
+ _.groupBy(_.sortBy(nonBreaking, "type"), "type")
213
+ );
214
+ } else {
215
+ groups[package] = Object.assign(
216
+ { breaking },
217
+ _.groupBy(nonBreaking, "type")
218
+ );
219
+ }
220
+
221
+ return groups;
222
+ }, {});
223
+ delete release.commits;
224
+ return release;
225
+ });
226
+ }
227
+
228
+ function getTypeName(type) {
229
+ switch (type) {
230
+ case "feat":
231
+ return "New Features";
232
+ case "fix":
233
+ return "Bug Fixes";
234
+ case "docs":
235
+ return "Documentation";
236
+ case "style":
237
+ return "Code Style";
238
+ case "Refactor":
239
+ return "Refactoring";
240
+ case "perf":
241
+ return "Performance";
242
+ case "test":
243
+ return "Tests";
244
+ case "chore":
245
+ return "Chores";
246
+ case "revert":
247
+ return "Reverts";
248
+ case "breaking":
249
+ return "Breaking Changes";
250
+ case "WIP":
251
+ return "Work In Progress";
252
+ default:
253
+ return "Misc.";
254
+ }
255
+ }
256
+
257
+ const template = stripIndents`
258
+ {%- macro link(repo, shortHash, hash) -%}
259
+ [\`{{ shortHash }}\`]({{repo}}/commit/{{ hash }})
260
+ {%- endmacro %}
261
+
262
+ {%- macro relatedIssues(issues) -%}
263
+ {%- for i in issues -%}
264
+ {{" "}}[#{{i.issue}}]({{i.url}})
265
+ {%- endfor -%}
266
+ {%- endmacro %}
267
+
268
+ {%- for release in releases %}
269
+ ## [{{ release.version }}] - {{ release.date }}
270
+ {% for package, groups in release.groups %}
271
+ ### {{ package }}
272
+
273
+ {% for type, commits in groups -%}
274
+ * {{ getTypeName(type) }}
275
+ {% for c in commits -%}
276
+ {{" "}}* **{{ c.scope }}**: {{ c.subject }} {{link(repo, c.shortHash, c.hash)}}{{relatedIssues(c.relatedIssues)}}
277
+ {% endfor %}
278
+ {%- endfor %}
279
+ {%- endfor %}
280
+ {%- endfor %}
281
+ `;
282
+
283
+ function buildMarkdown(releases) {
284
+ return nunjucks.renderString(template, { releases, getTypeName, repo });
285
+ }
286
+
287
+ logStep = v => {
288
+ console.log(inspect(v, { depth: 7 }));
289
+ return v;
290
+ };
291
+
292
+ const changeLogTemplate = stripIndents`
293
+ # {{title}}
294
+
295
+ {{description}}
296
+ {{newVersion}}
297
+
298
+ {%- for version in oldVersions %}
299
+ ## {{version.title}}
300
+
301
+ {{version.body}}
302
+ {% endfor %}
303
+ {% for link in links -%}
304
+ [{{link.ref}}]: {{link.href}} "{{link.title}}"
305
+ {% endfor -%}
306
+ `;
307
+
308
+ function getReleases() {
309
+ return Promise.all([
310
+ getTags(),
311
+ getFirstCommit()
312
+ ]).then(([releases, firstCommit]) => {
313
+ if (releases.length === 0) {
314
+ return [];
315
+ }
316
+
317
+ releases.unshift(firstCommit);
318
+ releases.push("HEAD");
319
+ return releases;
320
+ });
321
+ }
322
+
323
+ function getChangelogData() {
324
+ return new Promise((resolve, reject) => {
325
+ parseChangelog("CHANGELOG.md", function(error, changelog) {
326
+ if (error) {
327
+ reject(error);
328
+ return;
329
+ }
330
+
331
+ resolve(changelog);
332
+ });
333
+ });
334
+ }
335
+
336
+ function filterReleases(releases) {
337
+ return releases.slice(-2);
338
+ }
339
+
340
+ getReleases()
341
+ .then(releases => filterReleases(releases))
342
+ .then(releases => pairReleases(releases))
343
+ .then(pairs =>
344
+ Promise.all(pairs.map(([from, to]) => getCommitData(from, to)))
345
+ )
346
+ .then(releaseData => processCommitMessages(releaseData))
347
+ .then(releaseData => findReleasedPackages(releaseData))
348
+ .then(releaseData => groupCommitsByPackage(releaseData))
349
+ .then(releaseData => buildMarkdown(releaseData))
350
+ .then(newVersion => {
351
+ return Promise.all([
352
+ getReleases().then(pairReleases),
353
+ getChangelogData(),
354
+ Promise.resolve(newVersion)
355
+ ]);
356
+ })
357
+ .then(([pairs, changelog, newVersion]) => {
358
+ const links = pairs.map(([from, to]) => {
359
+ to = to === "HEAD" ? "v" + getPackageVersion() : to;
360
+ return {
361
+ ref: to.replace("v", ""),
362
+ title: to,
363
+ href: `${repo}/compare/${from}...${to}`
364
+ };
365
+ });
366
+
367
+ if (links.length) {
368
+ links.push({
369
+ ref: "HEAD",
370
+ title: "Unreleased Changes",
371
+ href: `${repo}/compare/${_.last(links).title}...HEAD`
372
+ });
373
+ }
374
+
375
+ const rendered = nunjucks.renderString(changeLogTemplate, {
376
+ title: changelog.title,
377
+ description: changelog.description,
378
+ oldVersions: changelog.versions,
379
+ newVersion: newVersion,
380
+ links,
381
+ repo
382
+ });
383
+
384
+ writeFile("CHANGELOG.md", rendered, function(e) {});
385
+ })
386
+ .catch(error => {
387
+ console.error(error.stack);
388
+ });
@@ -0,0 +1,19 @@
1
+ # Replace `type` the type of chage you are making, `scope` with a single-word
2
+ # general description of the files, classes or methods changed. Finally Replace
3
+ # `message` with your normal commit message.
4
+ type(scope): message
5
+
6
+ # Add an additional description (otpional) below this line
7
+
8
+ # If ou change will affect any Lerna packages uncomment the `AFFECTED PACKAGES:`
9
+ # line below and list the packages, one per line, by package name.
10
+ # AFFECTED PACKAGES:
11
+
12
+ # If your commit makes any breaking changes, uncomment the `BREAKING CHANGES:`
13
+ # line below and add a description of any breaking changes after it.
14
+ # BREAKING CHANGES:
15
+
16
+ # If your commit resolves, closes or references any issues uncomment the
17
+ # `ISSUES CLOSED:` line below and add issue number one the same line comma
18
+ # seperated like #31,#32
19
+ # ISSUES CLOSED:
@@ -0,0 +1,16 @@
1
+ const ghpages = require("gh-pages");
2
+
3
+ ghpages.publish(
4
+ "docs/build",
5
+ {
6
+ branch: "gh-pages",
7
+ repo: "https://github.com/Esri/arcgis-rest-js.git"
8
+ },
9
+ function(err) {
10
+ if (err) {
11
+ console.log("uh oh", err);
12
+ } else {
13
+ console.log("Deployed docs site!");
14
+ }
15
+ }
16
+ );