@datocms/cma-client 3.1.5 → 3.1.6
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/cjs/generated/Client.js +1 -1
- package/dist/cjs/idUtils.js +66 -0
- package/dist/cjs/idUtils.js.map +1 -0
- package/dist/cjs/index.js +8 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/SchemaTypes.d.ts +27 -27
- package/dist/esm/generated/SimpleSchemaTypes.d.ts +39 -39
- package/dist/esm/idUtils.d.ts +2 -0
- package/dist/esm/idUtils.js +61 -0
- package/dist/esm/idUtils.js.map +1 -0
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/types/generated/SchemaTypes.d.ts +27 -27
- package/dist/types/generated/SimpleSchemaTypes.d.ts +39 -39
- package/dist/types/idUtils.d.ts +2 -0
- package/dist/types/index.d.ts +5 -5
- package/package.json +2 -2
- package/src/generated/Client.ts +1 -1
- package/src/generated/SchemaTypes.ts +39 -27
- package/src/generated/SimpleSchemaTypes.ts +39 -39
- package/src/idUtils.ts +83 -0
- package/src/index.ts +5 -5
- package/dist/cjs/generateId.js +0 -26
- package/dist/cjs/generateId.js.map +0 -1
- package/dist/esm/generateId.d.ts +0 -1
- package/dist/esm/generateId.js +0 -22
- package/dist/esm/generateId.js.map +0 -1
- package/dist/types/generateId.d.ts +0 -1
- package/src/generateId.ts +0 -29
|
@@ -8787,49 +8787,49 @@ export type BuildTrigger = {
|
|
|
8787
8787
|
id: BuildTriggerIdentity;
|
|
8788
8788
|
type: BuildTriggerType;
|
|
8789
8789
|
/**
|
|
8790
|
-
* Name of the
|
|
8790
|
+
* Name of the build trigger
|
|
8791
8791
|
*/
|
|
8792
8792
|
name: string;
|
|
8793
8793
|
/**
|
|
8794
|
-
* The
|
|
8794
|
+
* The type of build trigger
|
|
8795
8795
|
*/
|
|
8796
|
-
adapter:
|
|
8796
|
+
adapter: 'custom' | 'netlify' | 'vercel' | 'circle_ci' | 'gitlab' | 'travis';
|
|
8797
8797
|
/**
|
|
8798
|
-
* Additional
|
|
8798
|
+
* Additional settings for the build trigger. The value depends on the `adapter`.
|
|
8799
8799
|
*/
|
|
8800
8800
|
adapter_settings: {
|
|
8801
8801
|
[k: string]: unknown;
|
|
8802
8802
|
};
|
|
8803
8803
|
/**
|
|
8804
|
-
* Timestamp of the last
|
|
8804
|
+
* Timestamp of the last build
|
|
8805
8805
|
*/
|
|
8806
8806
|
last_build_completed_at: string | null;
|
|
8807
8807
|
/**
|
|
8808
|
-
* Status of last
|
|
8808
|
+
* Status of last build
|
|
8809
8809
|
*/
|
|
8810
8810
|
build_status: string;
|
|
8811
8811
|
/**
|
|
8812
|
-
* Unique token
|
|
8812
|
+
* Unique token for the webhook (it's the same token present in `webhook_url`)
|
|
8813
8813
|
*/
|
|
8814
8814
|
webhook_token?: string;
|
|
8815
8815
|
/**
|
|
8816
|
-
*
|
|
8816
|
+
* The URL of the webhook your service has to call when the build completes to report it's status (success or error)
|
|
8817
8817
|
*/
|
|
8818
8818
|
webhook_url: string;
|
|
8819
8819
|
/**
|
|
8820
|
-
* Status of
|
|
8820
|
+
* Status of Site Search for the frontend
|
|
8821
8821
|
*/
|
|
8822
8822
|
indexing_status: string;
|
|
8823
8823
|
/**
|
|
8824
|
-
*
|
|
8824
|
+
* The public URL of the frontend. If Site Search is enabled (indicated by `indexing_enabled`), this is the starting point from which the website's spidering will start
|
|
8825
8825
|
*/
|
|
8826
8826
|
frontend_url: string | null;
|
|
8827
8827
|
/**
|
|
8828
|
-
*
|
|
8828
|
+
* Wheter an automatic build request to `webhook_url` should be made on scheduled publications/unpublishings
|
|
8829
8829
|
*/
|
|
8830
8830
|
autotrigger_on_scheduled_publications: boolean;
|
|
8831
8831
|
/**
|
|
8832
|
-
*
|
|
8832
|
+
* Wether Site Search is enabled or not. With Site Search, everytime the website is built, DatoCMS will respider it to get updated content
|
|
8833
8833
|
*/
|
|
8834
8834
|
indexing_enabled: boolean;
|
|
8835
8835
|
};
|
|
@@ -8845,49 +8845,49 @@ export type BuildTriggerDestroyTargetSchema = BuildTrigger;
|
|
|
8845
8845
|
*/
|
|
8846
8846
|
export type BuildTriggerAttributes = {
|
|
8847
8847
|
/**
|
|
8848
|
-
* Name of the
|
|
8848
|
+
* Name of the build trigger
|
|
8849
8849
|
*/
|
|
8850
8850
|
name: string;
|
|
8851
8851
|
/**
|
|
8852
|
-
* The
|
|
8852
|
+
* The type of build trigger
|
|
8853
8853
|
*/
|
|
8854
|
-
adapter:
|
|
8854
|
+
adapter: 'custom' | 'netlify' | 'vercel' | 'circle_ci' | 'gitlab' | 'travis';
|
|
8855
8855
|
/**
|
|
8856
|
-
* Additional
|
|
8856
|
+
* Additional settings for the build trigger. The value depends on the `adapter`.
|
|
8857
8857
|
*/
|
|
8858
8858
|
adapter_settings: {
|
|
8859
8859
|
[k: string]: unknown;
|
|
8860
8860
|
};
|
|
8861
8861
|
/**
|
|
8862
|
-
* Timestamp of the last
|
|
8862
|
+
* Timestamp of the last build
|
|
8863
8863
|
*/
|
|
8864
8864
|
last_build_completed_at: string | null;
|
|
8865
8865
|
/**
|
|
8866
|
-
* Status of last
|
|
8866
|
+
* Status of last build
|
|
8867
8867
|
*/
|
|
8868
8868
|
build_status: string;
|
|
8869
8869
|
/**
|
|
8870
|
-
* Unique token
|
|
8870
|
+
* Unique token for the webhook (it's the same token present in `webhook_url`)
|
|
8871
8871
|
*/
|
|
8872
8872
|
webhook_token?: string;
|
|
8873
8873
|
/**
|
|
8874
|
-
*
|
|
8874
|
+
* The URL of the webhook your service has to call when the build completes to report it's status (success or error)
|
|
8875
8875
|
*/
|
|
8876
8876
|
webhook_url: string;
|
|
8877
8877
|
/**
|
|
8878
|
-
* Status of
|
|
8878
|
+
* Status of Site Search for the frontend
|
|
8879
8879
|
*/
|
|
8880
8880
|
indexing_status: string;
|
|
8881
8881
|
/**
|
|
8882
|
-
*
|
|
8882
|
+
* The public URL of the frontend. If Site Search is enabled (indicated by `indexing_enabled`), this is the starting point from which the website's spidering will start
|
|
8883
8883
|
*/
|
|
8884
8884
|
frontend_url: string | null;
|
|
8885
8885
|
/**
|
|
8886
|
-
*
|
|
8886
|
+
* Wheter an automatic build request to `webhook_url` should be made on scheduled publications/unpublishings
|
|
8887
8887
|
*/
|
|
8888
8888
|
autotrigger_on_scheduled_publications: boolean;
|
|
8889
8889
|
/**
|
|
8890
|
-
*
|
|
8890
|
+
* Wether Site Search is enabled or not. With Site Search, everytime the website is built, DatoCMS will respider it to get updated content
|
|
8891
8891
|
*/
|
|
8892
8892
|
indexing_enabled: boolean;
|
|
8893
8893
|
};
|
|
@@ -8899,31 +8899,31 @@ export type BuildTriggerAttributes = {
|
|
|
8899
8899
|
export type BuildTriggerCreateSchema = {
|
|
8900
8900
|
type?: BuildTriggerType;
|
|
8901
8901
|
/**
|
|
8902
|
-
* Name of the
|
|
8902
|
+
* Name of the build trigger
|
|
8903
8903
|
*/
|
|
8904
8904
|
name: string;
|
|
8905
8905
|
/**
|
|
8906
|
-
* Unique token
|
|
8906
|
+
* Unique token for the webhook (it's the same token present in `webhook_url`)
|
|
8907
8907
|
*/
|
|
8908
8908
|
webhook_token?: string;
|
|
8909
8909
|
/**
|
|
8910
|
-
* The
|
|
8910
|
+
* The type of build trigger
|
|
8911
8911
|
*/
|
|
8912
|
-
adapter:
|
|
8912
|
+
adapter: 'custom' | 'netlify' | 'vercel' | 'circle_ci' | 'gitlab' | 'travis';
|
|
8913
8913
|
/**
|
|
8914
|
-
*
|
|
8914
|
+
* Wether Site Search is enabled or not. With Site Search, everytime the website is built, DatoCMS will respider it to get updated content
|
|
8915
8915
|
*/
|
|
8916
8916
|
indexing_enabled: boolean;
|
|
8917
8917
|
/**
|
|
8918
|
-
*
|
|
8918
|
+
* The public URL of the frontend. If Site Search is enabled (indicated by `indexing_enabled`), this is the starting point from which the website's spidering will start
|
|
8919
8919
|
*/
|
|
8920
8920
|
frontend_url: string | null;
|
|
8921
8921
|
/**
|
|
8922
|
-
*
|
|
8922
|
+
* Wheter an automatic build request to `webhook_url` should be made on scheduled publications/unpublishings
|
|
8923
8923
|
*/
|
|
8924
8924
|
autotrigger_on_scheduled_publications: boolean;
|
|
8925
8925
|
/**
|
|
8926
|
-
* Additional
|
|
8926
|
+
* Additional settings for the build trigger. The value depends on the `adapter`.
|
|
8927
8927
|
*/
|
|
8928
8928
|
adapter_settings: {
|
|
8929
8929
|
[k: string]: unknown;
|
|
@@ -8938,27 +8938,27 @@ export type BuildTriggerUpdateSchema = {
|
|
|
8938
8938
|
id?: BuildTriggerIdentity;
|
|
8939
8939
|
type?: BuildTriggerType;
|
|
8940
8940
|
/**
|
|
8941
|
-
* Name of the
|
|
8941
|
+
* Name of the build trigger
|
|
8942
8942
|
*/
|
|
8943
8943
|
name?: string;
|
|
8944
8944
|
/**
|
|
8945
|
-
* The
|
|
8945
|
+
* The type of build trigger
|
|
8946
8946
|
*/
|
|
8947
|
-
adapter?:
|
|
8947
|
+
adapter?: 'custom' | 'netlify' | 'vercel' | 'circle_ci' | 'gitlab' | 'travis';
|
|
8948
8948
|
/**
|
|
8949
|
-
*
|
|
8949
|
+
* Wether Site Search is enabled or not. With Site Search, everytime the website is built, DatoCMS will respider it to get updated content
|
|
8950
8950
|
*/
|
|
8951
8951
|
indexing_enabled?: boolean;
|
|
8952
8952
|
/**
|
|
8953
|
-
*
|
|
8953
|
+
* The public URL of the frontend. If Site Search is enabled (indicated by `indexing_enabled`), this is the starting point from which the website's spidering will start
|
|
8954
8954
|
*/
|
|
8955
8955
|
frontend_url?: string | null;
|
|
8956
8956
|
/**
|
|
8957
|
-
*
|
|
8957
|
+
* Wheter an automatic build request to `webhook_url` should be made on scheduled publications/unpublishings
|
|
8958
8958
|
*/
|
|
8959
8959
|
autotrigger_on_scheduled_publications?: boolean;
|
|
8960
8960
|
/**
|
|
8961
|
-
* Additional
|
|
8961
|
+
* Additional settings for the build trigger. The value depends on the `adapter`.
|
|
8962
8962
|
*/
|
|
8963
8963
|
adapter_settings?: {
|
|
8964
8964
|
[k: string]: unknown;
|
package/src/idUtils.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { v4 } from 'uuid';
|
|
2
|
+
|
|
3
|
+
const decoder = new TextDecoder('utf8');
|
|
4
|
+
|
|
5
|
+
function fromUint8ArrayToUrlSafeBase64(bytes: Uint8Array) {
|
|
6
|
+
const base64 =
|
|
7
|
+
typeof Buffer === 'undefined'
|
|
8
|
+
? btoa(decoder.decode(bytes))
|
|
9
|
+
: Buffer.from(bytes).toString('base64');
|
|
10
|
+
|
|
11
|
+
// Convert to URL-safe format (see RFC 4648, sec. 5)
|
|
12
|
+
return (
|
|
13
|
+
base64
|
|
14
|
+
// Replace + with -
|
|
15
|
+
.replace(/\+/g, '-')
|
|
16
|
+
// Replace / with _
|
|
17
|
+
.replace(/\//g, '_')
|
|
18
|
+
// Drop '==' padding
|
|
19
|
+
.substring(0, 22)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function fromUrlSafeBase64toUint8Array(urlSafeBase64: string): Uint8Array {
|
|
24
|
+
// Convert from URL-safe format (see RFC 4648, sec. 5)
|
|
25
|
+
const base64 = urlSafeBase64
|
|
26
|
+
// Replace - with +
|
|
27
|
+
.replace(/-/g, '+')
|
|
28
|
+
// Replace _ with /
|
|
29
|
+
.replace(/_/g, '/');
|
|
30
|
+
|
|
31
|
+
return typeof Buffer === 'undefined'
|
|
32
|
+
? Uint8Array.from(atob(base64), (c) => c.charCodeAt(0))
|
|
33
|
+
: new Uint8Array(Buffer.from(base64, 'base64'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isValidId(id: string) {
|
|
37
|
+
const bytes = fromUrlSafeBase64toUint8Array(id);
|
|
38
|
+
|
|
39
|
+
// UUIDs are 16 bytes
|
|
40
|
+
if (bytes.length !== 16) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The variant field determines the layout of the UUID
|
|
45
|
+
// (see RFC 4122, sec. 4.1.1)
|
|
46
|
+
|
|
47
|
+
const variant = bytes.at(8)!;
|
|
48
|
+
|
|
49
|
+
// Variant must be the one described in RFC 4122
|
|
50
|
+
if ((variant & 0b11000000) !== 0b10000000) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The version number is in the most significant 4 bits
|
|
55
|
+
// of the time stamp (see RFC 4122, sec. 4.1.3)
|
|
56
|
+
|
|
57
|
+
const version = bytes.at(6)! >> 4;
|
|
58
|
+
|
|
59
|
+
// Version number must be 4 (randomly generated)
|
|
60
|
+
if (version !== 0x4) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function generateId() {
|
|
68
|
+
const bytes = v4(null, new Uint8Array(16));
|
|
69
|
+
|
|
70
|
+
// Here we unset the first bit to ensure [A-Za-f] as the first char.
|
|
71
|
+
//
|
|
72
|
+
// If we didn't do this, we would generate IDs that, once encoded
|
|
73
|
+
// in base64, could start with a '+' or a '/'. This makes them less
|
|
74
|
+
// easy to copy/paste, with bad DX.
|
|
75
|
+
|
|
76
|
+
// This choice is purely aesthetic: definitely non-mandatory!
|
|
77
|
+
|
|
78
|
+
bytes[0] = bytes[0]! & 0x7f;
|
|
79
|
+
|
|
80
|
+
const base64 = fromUint8ArrayToUrlSafeBase64(bytes);
|
|
81
|
+
|
|
82
|
+
return base64;
|
|
83
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { ApiError,
|
|
1
|
+
export { ApiError, LogLevel, TimeoutError } from '@datocms/rest-client-utils';
|
|
2
|
+
export * from './buildBlockRecord';
|
|
3
|
+
export * from './buildClient';
|
|
2
4
|
export { Client } from './generated/Client';
|
|
3
|
-
export * as Resources from './generated/resources';
|
|
4
5
|
export type { ClientConfigOptions } from './generated/Client';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './buildBlockRecord';
|
|
7
|
-
export * from './generateId';
|
|
6
|
+
export * as Resources from './generated/resources';
|
|
8
7
|
export * as SchemaTypes from './generated/SchemaTypes';
|
|
9
8
|
export * as SimpleSchemaTypes from './generated/SimpleSchemaTypes';
|
|
9
|
+
export * from './idUtils';
|
package/dist/cjs/generateId.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateId = void 0;
|
|
4
|
-
var uuid_1 = require("uuid");
|
|
5
|
-
var decoder = new TextDecoder('utf8');
|
|
6
|
-
function toBase64(bytes) {
|
|
7
|
-
if (typeof Buffer !== 'undefined') {
|
|
8
|
-
return Buffer.from(bytes).toString('base64');
|
|
9
|
-
}
|
|
10
|
-
return btoa(decoder.decode(bytes));
|
|
11
|
-
}
|
|
12
|
-
function generateId() {
|
|
13
|
-
var bytes = (0, uuid_1.v4)(null, new Uint8Array(16));
|
|
14
|
-
// unset first bit to ensure [A-Za-f] first char
|
|
15
|
-
bytes[0] = bytes[0] & 0x7f;
|
|
16
|
-
var base64 = toBase64(bytes);
|
|
17
|
-
return (base64
|
|
18
|
-
// Replace + with - (see RFC 4648, sec. 5)
|
|
19
|
-
.replace(/\+/g, '-')
|
|
20
|
-
// Replace / with _ (see RFC 4648, sec. 5)
|
|
21
|
-
.replace(/\//g, '_')
|
|
22
|
-
// Drop '==' padding
|
|
23
|
-
.substring(0, 22));
|
|
24
|
-
}
|
|
25
|
-
exports.generateId = generateId;
|
|
26
|
-
//# sourceMappingURL=generateId.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateId.js","sourceRoot":"","sources":["../../src/generateId.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAC1B,IAAM,OAAO,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AAExC,SAAS,QAAQ,CAAC,KAAiB;IACjC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC9C;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAgB,UAAU;IACxB,IAAM,KAAK,GAAG,IAAA,SAAE,EAAC,IAAI,EAAE,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IAE3C,gDAAgD;IAChD,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC;IAE5B,IAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE/B,OAAO,CACL,MAAM;QACJ,0CAA0C;SACzC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;QACpB,0CAA0C;SACzC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;QACpB,oBAAoB;SACnB,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CACpB,CAAC;AACJ,CAAC;AAjBD,gCAiBC"}
|
package/dist/esm/generateId.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function generateId(): string;
|
package/dist/esm/generateId.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { v4 } from 'uuid';
|
|
2
|
-
var decoder = new TextDecoder('utf8');
|
|
3
|
-
function toBase64(bytes) {
|
|
4
|
-
if (typeof Buffer !== 'undefined') {
|
|
5
|
-
return Buffer.from(bytes).toString('base64');
|
|
6
|
-
}
|
|
7
|
-
return btoa(decoder.decode(bytes));
|
|
8
|
-
}
|
|
9
|
-
export function generateId() {
|
|
10
|
-
var bytes = v4(null, new Uint8Array(16));
|
|
11
|
-
// unset first bit to ensure [A-Za-f] first char
|
|
12
|
-
bytes[0] = bytes[0] & 0x7f;
|
|
13
|
-
var base64 = toBase64(bytes);
|
|
14
|
-
return (base64
|
|
15
|
-
// Replace + with - (see RFC 4648, sec. 5)
|
|
16
|
-
.replace(/\+/g, '-')
|
|
17
|
-
// Replace / with _ (see RFC 4648, sec. 5)
|
|
18
|
-
.replace(/\//g, '_')
|
|
19
|
-
// Drop '==' padding
|
|
20
|
-
.substring(0, 22));
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=generateId.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateId.js","sourceRoot":"","sources":["../../src/generateId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAC1B,IAAM,OAAO,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AAExC,SAAS,QAAQ,CAAC,KAAiB;IACjC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC9C;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,IAAM,KAAK,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IAE3C,gDAAgD;IAChD,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC;IAE5B,IAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE/B,OAAO,CACL,MAAM;QACJ,0CAA0C;SACzC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;QACpB,0CAA0C;SACzC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;QACpB,oBAAoB;SACnB,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CACpB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function generateId(): string;
|
package/src/generateId.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { v4 } from 'uuid';
|
|
2
|
-
const decoder = new TextDecoder('utf8');
|
|
3
|
-
|
|
4
|
-
function toBase64(bytes: Uint8Array) {
|
|
5
|
-
if (typeof Buffer !== 'undefined') {
|
|
6
|
-
return Buffer.from(bytes).toString('base64');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return btoa(decoder.decode(bytes));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function generateId() {
|
|
13
|
-
const bytes = v4(null, new Uint8Array(16));
|
|
14
|
-
|
|
15
|
-
// unset first bit to ensure [A-Za-f] first char
|
|
16
|
-
bytes[0] = bytes[0]! & 0x7f;
|
|
17
|
-
|
|
18
|
-
const base64 = toBase64(bytes);
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
base64
|
|
22
|
-
// Replace + with - (see RFC 4648, sec. 5)
|
|
23
|
-
.replace(/\+/g, '-')
|
|
24
|
-
// Replace / with _ (see RFC 4648, sec. 5)
|
|
25
|
-
.replace(/\//g, '_')
|
|
26
|
-
// Drop '==' padding
|
|
27
|
-
.substring(0, 22)
|
|
28
|
-
);
|
|
29
|
-
}
|