cozy-client 32.4.1 → 32.7.0
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/dist/CozyClient.js +1 -1
- package/dist/helpers.js +32 -1
- package/dist/helpers.spec.js +78 -0
- package/dist/index.js +7 -0
- package/dist/types.js +22 -0
- package/package.json +3 -3
- package/types/helpers.d.ts +3 -0
- package/types/index.d.ts +1 -1
- package/types/types.d.ts +40 -0
package/dist/CozyClient.js
CHANGED
|
@@ -2571,7 +2571,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2571
2571
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2572
2572
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2573
2573
|
|
|
2574
|
-
CozyClient.version = "32.
|
|
2574
|
+
CozyClient.version = "32.7.0";
|
|
2575
2575
|
|
|
2576
2576
|
_microee.default.mixin(CozyClient);
|
|
2577
2577
|
|
package/dist/helpers.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.rootCozyUrl = exports.InvalidCozyUrlError = exports.InvalidProtocolError = exports.generateWebLink = exports.dehydrate = void 0;
|
|
8
|
+
exports.rootCozyUrl = exports.InvalidCozyUrlError = exports.InvalidProtocolError = exports.deconstructCozyWebLinkWithSlug = exports.generateWebLink = exports.dehydrate = void 0;
|
|
9
9
|
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
|
|
@@ -29,6 +29,8 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
29
29
|
|
|
30
30
|
var _associations = require("./associations");
|
|
31
31
|
|
|
32
|
+
var _types = require("./types");
|
|
33
|
+
|
|
32
34
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
33
35
|
|
|
34
36
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -124,9 +126,38 @@ var generateWebLink = function generateWebLink(_ref3) {
|
|
|
124
126
|
|
|
125
127
|
return url.toString();
|
|
126
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* Deconstruct the given link in order to retrieve useful data like Cozy's name, domain, or slug
|
|
131
|
+
*
|
|
132
|
+
* The given link MUST contain a slug
|
|
133
|
+
*
|
|
134
|
+
* @param {string} webLink - link to deconstruct. It should be a link from a Cozy and containing a slug
|
|
135
|
+
* @param {SubdomainType} [subDomainType=flat] - whether the cozy is using flat or nested subdomains.
|
|
136
|
+
* @returns {CozyLinkData} Deconstructed link
|
|
137
|
+
*/
|
|
138
|
+
|
|
127
139
|
|
|
128
140
|
exports.generateWebLink = generateWebLink;
|
|
129
141
|
|
|
142
|
+
var deconstructCozyWebLinkWithSlug = function deconstructCozyWebLinkWithSlug(webLink) {
|
|
143
|
+
var subDomainType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flat';
|
|
144
|
+
var url = new URL(webLink);
|
|
145
|
+
var slug = subDomainType === 'nested' ? url.host.split('.')[0] : url.host.split('.')[0].split('-')[1];
|
|
146
|
+
var cozyName = subDomainType === 'nested' ? url.host.split('.')[1] : url.host.split('.')[0].split('-')[0];
|
|
147
|
+
var cozyBaseDomain = url.host.split('.').slice(subDomainType === 'nested' ? 2 : 1).join('.');
|
|
148
|
+
return {
|
|
149
|
+
cozyBaseDomain: cozyBaseDomain,
|
|
150
|
+
cozyName: cozyName,
|
|
151
|
+
pathname: url.pathname,
|
|
152
|
+
hash: url.hash,
|
|
153
|
+
protocol: url.protocol,
|
|
154
|
+
searchParams: url.searchParams.toString(),
|
|
155
|
+
slug: slug
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
exports.deconstructCozyWebLinkWithSlug = deconstructCozyWebLinkWithSlug;
|
|
160
|
+
|
|
130
161
|
var InvalidProtocolError = /*#__PURE__*/function (_Error) {
|
|
131
162
|
(0, _inherits2.default)(InvalidProtocolError, _Error);
|
|
132
163
|
|
package/dist/helpers.spec.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { enableFetchMocks, disableFetchMocks } from 'jest-fetch-mock'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
deconstructCozyWebLinkWithSlug,
|
|
4
5
|
dehydrate,
|
|
5
6
|
generateWebLink,
|
|
6
7
|
rootCozyUrl,
|
|
@@ -150,6 +151,83 @@ describe('generateWebLink', () => {
|
|
|
150
151
|
})
|
|
151
152
|
})
|
|
152
153
|
|
|
154
|
+
describe('deconstructWebLink', () => {
|
|
155
|
+
it.each([
|
|
156
|
+
[
|
|
157
|
+
'https://claude-notes.mycozy.cloud',
|
|
158
|
+
'flat',
|
|
159
|
+
{
|
|
160
|
+
protocol: 'https:',
|
|
161
|
+
cozyName: 'claude',
|
|
162
|
+
cozyBaseDomain: 'mycozy.cloud',
|
|
163
|
+
pathname: '/',
|
|
164
|
+
hash: '',
|
|
165
|
+
searchParams: '',
|
|
166
|
+
slug: 'notes'
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
'http://alice-drive.cozy.tools:8080',
|
|
171
|
+
'flat',
|
|
172
|
+
{
|
|
173
|
+
protocol: 'http:',
|
|
174
|
+
cozyName: 'alice',
|
|
175
|
+
cozyBaseDomain: 'cozy.tools:8080',
|
|
176
|
+
pathname: '/',
|
|
177
|
+
hash: '',
|
|
178
|
+
searchParams: '',
|
|
179
|
+
slug: 'drive'
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
[
|
|
183
|
+
'https://photo.claude.custome-domain.fr',
|
|
184
|
+
'nested',
|
|
185
|
+
{
|
|
186
|
+
protocol: 'https:',
|
|
187
|
+
cozyName: 'claude',
|
|
188
|
+
cozyBaseDomain: 'custome-domain.fr',
|
|
189
|
+
pathname: '/',
|
|
190
|
+
hash: '',
|
|
191
|
+
searchParams: '',
|
|
192
|
+
slug: 'photo'
|
|
193
|
+
}
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
'http://drive.cozy.tools:8080/#/folder/SOME_FOLDER_ID',
|
|
197
|
+
'nested',
|
|
198
|
+
{
|
|
199
|
+
protocol: 'http:',
|
|
200
|
+
cozyName: 'cozy',
|
|
201
|
+
cozyBaseDomain: 'tools:8080',
|
|
202
|
+
pathname: '/',
|
|
203
|
+
hash: '#/folder/SOME_FOLDER_ID',
|
|
204
|
+
searchParams: '',
|
|
205
|
+
slug: 'drive'
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
[
|
|
209
|
+
'http://notes.cozy.tools:8080/public/?id=SOME_FOLDER_ID&sharecode=SOME_SHARECODE',
|
|
210
|
+
'nested',
|
|
211
|
+
{
|
|
212
|
+
protocol: 'http:',
|
|
213
|
+
cozyName: 'cozy',
|
|
214
|
+
cozyBaseDomain: 'tools:8080',
|
|
215
|
+
pathname: '/public/',
|
|
216
|
+
hash: '',
|
|
217
|
+
searchParams: 'id=SOME_FOLDER_ID&sharecode=SOME_SHARECODE',
|
|
218
|
+
slug: 'notes'
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
])(
|
|
222
|
+
'should deconstruct %p link with %p subdomain type',
|
|
223
|
+
(link, subdomainType, result) => {
|
|
224
|
+
expect(deconstructCozyWebLinkWithSlug(link, subdomainType)).toEqual(
|
|
225
|
+
result
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
})
|
|
230
|
+
|
|
153
231
|
describe('rootCozyUrl', () => {
|
|
154
232
|
beforeAll(() => {
|
|
155
233
|
enableFetchMocks()
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ var _exportNames = {
|
|
|
26
26
|
isReferencedById: true,
|
|
27
27
|
getReferencedBy: true,
|
|
28
28
|
getReferencedById: true,
|
|
29
|
+
deconstructCozyWebLinkWithSlug: true,
|
|
29
30
|
dehydrate: true,
|
|
30
31
|
generateWebLink: true,
|
|
31
32
|
rootCozyUrl: true,
|
|
@@ -163,6 +164,12 @@ Object.defineProperty(exports, "getReferencedById", {
|
|
|
163
164
|
return _helpers.getReferencedById;
|
|
164
165
|
}
|
|
165
166
|
});
|
|
167
|
+
Object.defineProperty(exports, "deconstructCozyWebLinkWithSlug", {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
get: function get() {
|
|
170
|
+
return _helpers2.deconstructCozyWebLinkWithSlug;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
166
173
|
Object.defineProperty(exports, "dehydrate", {
|
|
167
174
|
enumerable: true,
|
|
168
175
|
get: function get() {
|
package/dist/types.js
CHANGED
|
@@ -388,5 +388,27 @@ var _dsl = require("./queries/dsl");
|
|
|
388
388
|
* @property {string} [codeVerifier]
|
|
389
389
|
* @property {string} [codeChallenge]
|
|
390
390
|
*/
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Subdomain type for a Cozy. Can be flat or nested subdomains
|
|
394
|
+
*
|
|
395
|
+
* Example of 'flat' domain: https://claude-notes.somedomain.fr
|
|
396
|
+
* Example of 'nested' domain: https://notes.claude.somedomain.fr
|
|
397
|
+
*
|
|
398
|
+
* @typedef {'flat'|'nested'} SubdomainType
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Represents the different parts of a deconstructed Cozy link
|
|
403
|
+
*
|
|
404
|
+
* @typedef {object} CozyLinkData
|
|
405
|
+
* @property {string} cozyBaseDomain - The Cozy's domain (i.e. 'mycozy.cloud')
|
|
406
|
+
* @property {string} cozyName - The Cozy's name (i.e. 'claude')
|
|
407
|
+
* @property {string} [hash] - The link's path (i.e. '#/folder/SOME_FOLDER_ID')
|
|
408
|
+
* @property {string} [pathname] - The link's path (i.e. '/public/')
|
|
409
|
+
* @property {string} protocol - The link's protocol (i.e. 'https')
|
|
410
|
+
* @property {string} [searchParams] - The link's searchParams (i.e. 'id=SOME_FOLDER_ID&sharecode=SOME_SHARECODE')
|
|
411
|
+
* @property {string} slug - The link's slug (i.e. 'drive' or 'notes)
|
|
412
|
+
*/
|
|
391
413
|
var _default = {};
|
|
392
414
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "32.
|
|
3
|
+
"version": "32.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@types/jest": "^26.0.20",
|
|
19
19
|
"@types/lodash": "^4.14.170",
|
|
20
20
|
"btoa": "^1.2.1",
|
|
21
|
-
"cozy-stack-client": "^32.
|
|
21
|
+
"cozy-stack-client": "^32.7.0",
|
|
22
22
|
"json-stable-stringify": "^1.0.1",
|
|
23
23
|
"lodash": "^4.17.13",
|
|
24
24
|
"microee": "^0.0.6",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
74
74
|
},
|
|
75
75
|
"sideEffects": false,
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "5a537132658593452f3f47fdb517e902a041ad5b"
|
|
77
77
|
}
|
package/types/helpers.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export function generateWebLink({ cozyUrl, searchParams: searchParamsOption, pat
|
|
|
7
7
|
slug: string;
|
|
8
8
|
subDomainType: string;
|
|
9
9
|
}): string;
|
|
10
|
+
export function deconstructCozyWebLinkWithSlug(webLink: string, subDomainType?: SubdomainType): CozyLinkData;
|
|
10
11
|
export class InvalidProtocolError extends Error {
|
|
11
12
|
constructor(url: any);
|
|
12
13
|
url: any;
|
|
@@ -16,3 +17,5 @@ export class InvalidCozyUrlError extends Error {
|
|
|
16
17
|
url: any;
|
|
17
18
|
}
|
|
18
19
|
export function rootCozyUrl(url: URL): Promise<URL>;
|
|
20
|
+
import { SubdomainType } from "./types";
|
|
21
|
+
import { CozyLinkData } from "./types";
|
package/types/index.d.ts
CHANGED
|
@@ -19,6 +19,6 @@ export { manifest, models };
|
|
|
19
19
|
export { QueryDefinition, Q, Mutations, MutationTypes, getDoctypeFromOperation } from "./queries/dsl";
|
|
20
20
|
export { Association, HasMany, HasOne, HasOneInPlace, HasManyInPlace, HasManyTriggers } from "./associations";
|
|
21
21
|
export { isReferencedBy, isReferencedById, getReferencedBy, getReferencedById } from "./associations/helpers";
|
|
22
|
-
export { dehydrate, generateWebLink, rootCozyUrl, InvalidCozyUrlError, InvalidProtocolError } from "./helpers";
|
|
22
|
+
export { deconstructCozyWebLinkWithSlug, dehydrate, generateWebLink, rootCozyUrl, InvalidCozyUrlError, InvalidProtocolError } from "./helpers";
|
|
23
23
|
export { cancelable, isQueryLoading, hasQueryBeenLoaded } from "./utils";
|
|
24
24
|
export { queryConnect, queryConnectFlat, withClient } from "./hoc";
|
package/types/types.d.ts
CHANGED
|
@@ -482,4 +482,44 @@ export type PKCECodes = {
|
|
|
482
482
|
codeVerifier?: string;
|
|
483
483
|
codeChallenge?: string;
|
|
484
484
|
};
|
|
485
|
+
/**
|
|
486
|
+
* Subdomain type for a Cozy. Can be flat or nested subdomains
|
|
487
|
+
*
|
|
488
|
+
* Example of 'flat' domain: https://claude-notes.somedomain.fr
|
|
489
|
+
* Example of 'nested' domain: https://notes.claude.somedomain.fr
|
|
490
|
+
*/
|
|
491
|
+
export type SubdomainType = "flat" | "nested";
|
|
492
|
+
/**
|
|
493
|
+
* Represents the different parts of a deconstructed Cozy link
|
|
494
|
+
*/
|
|
495
|
+
export type CozyLinkData = {
|
|
496
|
+
/**
|
|
497
|
+
* - The Cozy's domain (i.e. 'mycozy.cloud')
|
|
498
|
+
*/
|
|
499
|
+
cozyBaseDomain: string;
|
|
500
|
+
/**
|
|
501
|
+
* - The Cozy's name (i.e. 'claude')
|
|
502
|
+
*/
|
|
503
|
+
cozyName: string;
|
|
504
|
+
/**
|
|
505
|
+
* - The link's path (i.e. '#/folder/SOME_FOLDER_ID')
|
|
506
|
+
*/
|
|
507
|
+
hash?: string;
|
|
508
|
+
/**
|
|
509
|
+
* - The link's path (i.e. '/public/')
|
|
510
|
+
*/
|
|
511
|
+
pathname?: string;
|
|
512
|
+
/**
|
|
513
|
+
* - The link's protocol (i.e. 'https')
|
|
514
|
+
*/
|
|
515
|
+
protocol: string;
|
|
516
|
+
/**
|
|
517
|
+
* - The link's searchParams (i.e. 'id=SOME_FOLDER_ID&sharecode=SOME_SHARECODE')
|
|
518
|
+
*/
|
|
519
|
+
searchParams?: string;
|
|
520
|
+
/**
|
|
521
|
+
* - The link's slug (i.e. 'drive' or 'notes)
|
|
522
|
+
*/
|
|
523
|
+
slug: string;
|
|
524
|
+
};
|
|
485
525
|
import { QueryDefinition } from "./queries/dsl";
|